grandlyon: move close demands computation to shared module
This commit is contained in:
parent
8c47b080fa
commit
3d84814fd5
|
@ -0,0 +1,41 @@
|
|||
from pyproj import Proj, transform, Geod
|
||||
|
||||
from qommon import misc
|
||||
from qommon.storage import Contains
|
||||
from wcs.wf.geolocate import GeolocateWorkflowStatusItem
|
||||
|
||||
geod = Geod(ellps='WGS84')
|
||||
|
||||
def get_coords(context):
|
||||
coords = context.get('form_var_carte')
|
||||
if coords:
|
||||
lat, lon = coords.split(';')
|
||||
return {'lat': float(lat), 'lon': float(lon)}
|
||||
if 'form_var_numero' in context:
|
||||
geolocate = GeolocateWorkflowStatusItem()
|
||||
geolocate.method = 'address_string'
|
||||
geolocate.address_string = '[form_var_numero] [form_var_voie], [form_var_commune], France'
|
||||
return geolocate.geolocate_address_string(None)
|
||||
return None
|
||||
|
||||
def get_close_demands(formdef, coords):
|
||||
applied_filters = ['wf-%s' % x.id for x in formdef.workflow.get_not_endpoint_status()]
|
||||
formdatas = formdef.data_class().select([Contains('status', applied_filters)])
|
||||
counter = 0
|
||||
for formdata in formdatas:
|
||||
if not formdata.geolocations:
|
||||
continue
|
||||
formdata_coords = misc.normalize_geolocation(formdata.geolocations['base'])
|
||||
|
||||
distance = geod.inv(formdata_coords['lon'], formdata_coords['lat'],
|
||||
coords['lon'], coords['lat'])[2]
|
||||
formdata._distance = distance
|
||||
formdata._coords = formdata_coords
|
||||
if distance < 750:
|
||||
counter += 1
|
||||
formdata.counter = counter
|
||||
yield formdata
|
||||
|
||||
if __name__ == '__builtin__':
|
||||
coords = get_coords(vars())
|
||||
result = get_close_demands(form_objects.formdef, coords)
|
|
@ -1,37 +1,13 @@
|
|||
import inspect
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
|
||||
from pyproj import Proj, transform, Geod
|
||||
if os.path.dirname(__file__) not in sys.path:
|
||||
sys.path.append(os.path.dirname(__file__))
|
||||
|
||||
from qommon import misc
|
||||
from qommon.storage import Contains
|
||||
from wcs.wf.geolocate import GeolocateWorkflowStatusItem
|
||||
|
||||
geod = Geod(ellps='WGS84')
|
||||
|
||||
result = False
|
||||
coords = vars().get('form_var_carte')
|
||||
if not coords and 'form_var_numero' in vars():
|
||||
geolocate = GeolocateWorkflowStatusItem()
|
||||
geolocate.method = 'address_string'
|
||||
geolocate.address_string = '[form_var_numero] [form_var_voie], [form_var_commune], France'
|
||||
coords = geolocate.geolocate_address_string(None)
|
||||
coords = '%(lat)s;%(lon)s' % coords
|
||||
import close_demands
|
||||
|
||||
coords = close_demands.get_coords(vars())
|
||||
if coords:
|
||||
formdef = form_objects.formdef
|
||||
|
||||
lat, lon = coords.split(';')
|
||||
lat, lon = float(lat), float(lon)
|
||||
|
||||
applied_filters = ['wf-%s' % x.id for x in formdef.workflow.get_not_endpoint_status()]
|
||||
formdatas = formdef.data_class().select([Contains('status', applied_filters)])
|
||||
for formdata in formdatas:
|
||||
if not formdata.geolocations:
|
||||
continue
|
||||
coords = misc.normalize_geolocation(formdata.geolocations['base'])
|
||||
|
||||
distance = geod.inv(coords['lon'], coords['lat'], lon, lat)[2]
|
||||
if distance < 750:
|
||||
result = True
|
||||
break
|
||||
result = any(close_demands.get_close_demands(form_objects.formdef, coords))
|
||||
else:
|
||||
result = False
|
||||
|
|
|
@ -1,59 +1,39 @@
|
|||
import inspect
|
||||
import os
|
||||
import sys
|
||||
|
||||
if os.path.dirname(__file__) not in sys.path:
|
||||
sys.path.append(os.path.dirname(__file__))
|
||||
|
||||
import json
|
||||
import time
|
||||
|
||||
from pyproj import Proj, transform, Geod
|
||||
|
||||
from qommon import misc
|
||||
from qommon.storage import Contains
|
||||
from qommon.form import MapWidget
|
||||
from wcs.wf.geolocate import GeolocateWorkflowStatusItem
|
||||
|
||||
geod = Geod(ellps='WGS84')
|
||||
|
||||
result = ''
|
||||
|
||||
coords = vars().get('form_var_carte')
|
||||
|
||||
if not coords and 'form_var_numero' in vars():
|
||||
geolocate = GeolocateWorkflowStatusItem()
|
||||
geolocate.method = 'address_string'
|
||||
geolocate.address_string = '[form_var_numero] [form_var_voie], [form_var_commune], France'
|
||||
coords = geolocate.geolocate_address_string(None)
|
||||
coords = '%(lat)s;%(lon)s' % coords
|
||||
import close_demands
|
||||
|
||||
coords = close_demands.get_coords(vars())
|
||||
if coords:
|
||||
map_widget = MapWidget('geo', readonly=True, value='%(lat)s;%(lon)s' % coords, initial_zoom=16)
|
||||
formdef = form_objects.formdef
|
||||
|
||||
lat, lon = coords.split(';')
|
||||
lat, lon = float(lat), float(lon)
|
||||
map_widget = MapWidget('geo', readonly=True, value=coords,
|
||||
initial_zoom=16)
|
||||
|
||||
features = []
|
||||
applied_filters = ['wf-%s' % x.id for x in formdef.workflow.get_not_endpoint_status()]
|
||||
formdatas = formdef.data_class().select([Contains('status', applied_filters)])
|
||||
for formdata in formdatas:
|
||||
if not formdata.geolocations:
|
||||
continue
|
||||
coords = misc.normalize_geolocation(formdata.geolocations['base'])
|
||||
|
||||
distance = geod.inv(coords['lon'], coords['lat'], lon, lat)[2]
|
||||
if distance < 750:
|
||||
feature = {
|
||||
'type': 'Feature',
|
||||
'properties': {},
|
||||
'geometry': {
|
||||
'type': 'Point',
|
||||
'coordinates': [coords['lon'], coords['lat']],
|
||||
}
|
||||
for formdata in close_demands.get_close_demands(formdef, coords):
|
||||
feature = {
|
||||
'type': 'Feature',
|
||||
'properties': {},
|
||||
'geometry': {
|
||||
'type': 'Point',
|
||||
'coordinates': [formdata._coords['lon'], formdata._coords['lat']],
|
||||
}
|
||||
for field in formdef.fields:
|
||||
if field.varname in ('numero', 'voie', 'commune', 'message', 'type_probleme'):
|
||||
feature['properties'][field.varname] = formdata.data.get(field.id)
|
||||
feature['properties']['datetime'] = time.strftime('%d/%m/%Y %H:%M', formdata.receipt_time)
|
||||
feature['properties']['reference'] = '%s:%s' % (formdef.url_name, formdata.id)
|
||||
features.append(feature)
|
||||
}
|
||||
for field in formdef.fields:
|
||||
if field.varname in ('numero', 'voie', 'commune', 'message', 'type_probleme'):
|
||||
feature['properties'][field.varname] = formdata.data.get(field.id)
|
||||
feature['properties']['datetime'] = time.strftime('%d/%m/%Y %H:%M', formdata.receipt_time)
|
||||
feature['properties']['reference'] = '%s:%s' % (formdef.url_name, formdata.id)
|
||||
feature['properties']['id'] = formdata.id
|
||||
feature['properties']['counter'] = formdata.counter
|
||||
features.append(feature)
|
||||
|
||||
result = '''
|
||||
<link href="%s/static/css/combo.map.css" type="text/css" media="all" rel="stylesheet">
|
||||
|
|
Loading…
Reference in New Issue