0001-add-a-geojson-export-of-visualization-data-fixes-151.patch
bijoe/engine.py | ||
---|---|---|
27 | 27 |
psycopg2.extensions.register_type(psycopg2.extensions.UNICODEARRAY) |
28 | 28 | |
29 | 29 | |
30 |
def cast_point(value, cur): |
|
31 |
if value is None: |
|
32 |
return None |
|
33 |
return schemas.Point._make(map(float, value[1:-1].split(','))) |
|
34 | ||
35 | ||
36 |
POINT = psycopg2.extensions.new_type((600,), "POINT", cast_point) |
|
37 |
psycopg2.extensions.register_type(POINT) |
|
38 | ||
39 |
POINT_ARRAY = psycopg2.extensions.new_array_type((1017,), "POINT[]", POINT) |
|
40 |
psycopg2.extensions.register_type(POINT_ARRAY) |
|
41 | ||
42 | ||
30 | 43 |
def to_tuple(cur, values): |
31 | 44 |
return cur.mogrify(', '.join(['%s'] * len(values)), values) |
32 | 45 |
bijoe/schemas.py | ||
---|---|---|
22 | 22 | |
23 | 23 |
from .relative_time import RelativeDate |
24 | 24 | |
25 |
Point = collections.namedtuple('Point', ['x', 'y']) |
|
25 | 26 | |
26 | 27 |
TYPE_MAP = { |
27 | 28 |
'duration': datetime.timedelta, |
... | ... | |
29 | 30 |
'integer': int, |
30 | 31 |
'decimal': decimal.Decimal, |
31 | 32 |
'percent': float, |
33 |
'point': Point, |
|
32 | 34 |
} |
33 | 35 | |
34 | 36 |
bijoe/settings.py | ||
---|---|---|
57 | 57 |
'xstatic.pkg.chartnew_js', |
58 | 58 |
'django_select2', |
59 | 59 |
'gadjo', |
60 |
'rest_framework', |
|
60 | 61 |
'bijoe', |
61 | 62 |
'bijoe.visualization', |
62 | 63 |
) |
bijoe/visualization/forms.py | ||
---|---|---|
192 | 192 |
required=False) |
193 | 193 | |
194 | 194 |
# measures |
195 |
choices = [(measure.name, measure.label) for measure in cube.measures] |
|
195 |
choices = [(measure.name, measure.label) |
|
196 |
for measure in cube.measures if measure.type != 'point'] |
|
196 | 197 |
self.base_fields['measure'] = forms.ChoiceField( |
197 | 198 |
label=_('Measure'), choices=choices) |
198 | 199 |
bijoe/visualization/urls.py | ||
---|---|---|
31 | 31 |
url(r'warehouse/(?P<warehouse>[^/]*)/(?P<cube>[^/]*)/save/$', |
32 | 32 |
views.create_visualization, name='create-visualization'), |
33 | 33 |
url(r'(?P<pk>\d+)/$', views.visualization, name='visualization'), |
34 |
url(r'(?P<pk>\d+)/geojson/$', views.visualization_geojson, name='visualization-geojson'), |
|
34 | 35 |
url(r'(?P<pk>\d+)/iframe/$', views.visualization_iframe, name='visualization-iframe'), |
35 | 36 |
url(r'(?P<pk>\d+)/rename/$', views.rename_visualization, name='rename-visualization'), |
36 | 37 |
url(r'(?P<pk>\d+)/delete/$', views.visualization, name='delete-visualization'), |
bijoe/visualization/views.py | ||
---|---|---|
27 | 27 |
from django.core.exceptions import PermissionDenied |
28 | 28 |
from django.views.decorators.clickjacking import xframe_options_exempt |
29 | 29 | |
30 |
from rest_framework import generics |
|
31 |
from rest_framework.response import Response |
|
32 | ||
30 | 33 |
from ..utils import get_warehouses |
31 | 34 |
from ..engine import Engine |
32 | 35 |
from . import models, forms, signature |
... | ... | |
230 | 233 |
class CubeIframeView(CubeView): |
231 | 234 |
template_name = 'bijoe/cube_raw.html' |
232 | 235 | |
236 | ||
237 |
class VisualizationGeoJSONView(generics.GenericAPIView): |
|
238 |
permission_classes = () |
|
239 |
queryset = models.Visualization.objects.all() |
|
240 | ||
241 |
def get(self, request, pk, format=None): |
|
242 |
instance = self.get_object() |
|
243 |
visualization = Visualization.from_json(instance.parameters, request=request) |
|
244 |
visualization.measure = visualization.cube.measures['geolocation'] |
|
245 |
drilldown = visualization.drilldown |
|
246 |
geojson = [] |
|
247 |
for row in visualization.data(): |
|
248 |
properties = {} |
|
249 |
for dim in row[:len(drilldown)]: |
|
250 |
properties[dim['label']] = dim['value'] |
|
251 |
geojson.append({ |
|
252 |
'type': 'Feature', |
|
253 |
'geometry': { |
|
254 |
'type': 'Multipoint', |
|
255 |
'coordinates': row[len(drilldown)]['value'] or [], |
|
256 |
}, |
|
257 |
'properties': properties, |
|
258 |
}) |
|
259 |
return Response(geojson) |
|
260 | ||
261 | ||
233 | 262 |
warehouse = WarehouseView.as_view() |
234 | 263 |
cube = CubeView.as_view() |
235 | 264 |
cube_iframe = xframe_options_exempt(CubeIframeView.as_view()) |
... | ... | |
240 | 269 |
rename_visualization = RenameVisualization.as_view() |
241 | 270 |
visualization = VisualizationView.as_view() |
242 | 271 |
visualization_iframe = xframe_options_exempt(VisualizationIframeView.as_view()) |
272 |
visualization_geojson = VisualizationGeoJSONView.as_view() |
|
243 | 273 | |
244 | 274 |
cube_iframe.mellon_no_passive = True |
245 | 275 |
visualization_iframe.mellon_no_passive = True |
setup.py | ||
---|---|---|
94 | 94 |
include_package_data=True, |
95 | 95 |
install_requires=['requests', 'django', 'psycopg2', 'isodate', 'Django-Select2<5', |
96 | 96 |
'XStatic-ChartNew.js', 'gadjo', 'django-jsonfield<1.0.0', |
97 |
'python-dateutil'], |
|
97 |
'python-dateutil', 'djangorestframework<3.4'],
|
|
98 | 98 |
scripts=['bijoe-ctl'], |
99 | 99 |
cmdclass={ |
100 | 100 |
'sdist': eo_sdist, |
101 |
- |