udata 8.0.1.dev28859__py2.py3-none-any.whl → 8.0.1.dev28882__py2.py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- udata/api/__init__.py +0 -1
- udata/core/metrics/commands.py +18 -3
- udata/core/spatial/api.py +1 -6
- udata/core/spatial/models.py +7 -2
- udata/core/spatial/tasks.py +7 -0
- udata/core/spatial/tests/test_api.py +26 -0
- udata/static/chunks/{11.ae54612e36c6d46f85db.js → 11.7266fef2dddc1db403d9.js} +3 -3
- udata/static/chunks/{11.ae54612e36c6d46f85db.js.map → 11.7266fef2dddc1db403d9.js.map} +1 -1
- udata/static/chunks/{13.d8ccb992a49875966313.js → 13.91b177d7d531fd55cf5d.js} +2 -2
- udata/static/chunks/{13.d8ccb992a49875966313.js.map → 13.91b177d7d531fd55cf5d.js.map} +1 -1
- udata/static/chunks/{16.4565605e68bab129a471.js → 16.e866757bab9f6b0a3f1b.js} +2 -2
- udata/static/chunks/{16.4565605e68bab129a471.js.map → 16.e866757bab9f6b0a3f1b.js.map} +1 -1
- udata/static/chunks/{19.f993a75d5bfe2382548d.js → 19.619b83ac597516dcd03e.js} +3 -3
- udata/static/chunks/{19.f993a75d5bfe2382548d.js.map → 19.619b83ac597516dcd03e.js.map} +1 -1
- udata/static/chunks/{5.ada3202d02917ce0edea.js → 5.3dc97ea195d251881552.js} +3 -3
- udata/static/chunks/{5.ada3202d02917ce0edea.js.map → 5.3dc97ea195d251881552.js.map} +1 -1
- udata/static/chunks/{6.cad898a38692eda28965.js → 6.f84539bd4c419b36cc19.js} +3 -3
- udata/static/chunks/{6.cad898a38692eda28965.js.map → 6.f84539bd4c419b36cc19.js.map} +1 -1
- udata/static/chunks/{9.d5b992e9ef51921aeb57.js → 9.07503e7f7ec02919f696.js} +2 -2
- udata/static/chunks/{9.d5b992e9ef51921aeb57.js.map → 9.07503e7f7ec02919f696.js.map} +1 -1
- udata/static/common.js +1 -1
- udata/static/common.js.map +1 -1
- udata/tasks.py +1 -0
- {udata-8.0.1.dev28859.dist-info → udata-8.0.1.dev28882.dist-info}/METADATA +3 -2
- {udata-8.0.1.dev28859.dist-info → udata-8.0.1.dev28882.dist-info}/RECORD +29 -29
- udata/core/metrics/api.py +0 -10
- {udata-8.0.1.dev28859.dist-info → udata-8.0.1.dev28882.dist-info}/LICENSE +0 -0
- {udata-8.0.1.dev28859.dist-info → udata-8.0.1.dev28882.dist-info}/WHEEL +0 -0
- {udata-8.0.1.dev28859.dist-info → udata-8.0.1.dev28882.dist-info}/entry_points.txt +0 -0
- {udata-8.0.1.dev28859.dist-info → udata-8.0.1.dev28882.dist-info}/top_level.txt +0 -0
udata/api/__init__.py
CHANGED
|
@@ -321,7 +321,6 @@ def init_app(app):
|
|
|
321
321
|
# Load all core APIs
|
|
322
322
|
import udata.core.activity.api # noqa
|
|
323
323
|
import udata.core.spatial.api # noqa
|
|
324
|
-
import udata.core.metrics.api # noqa
|
|
325
324
|
import udata.core.user.api # noqa
|
|
326
325
|
import udata.core.dataset.api # noqa
|
|
327
326
|
import udata.core.dataset.apiv2 # noqa
|
udata/core/metrics/commands.py
CHANGED
|
@@ -5,7 +5,7 @@ import click
|
|
|
5
5
|
from flask import current_app
|
|
6
6
|
|
|
7
7
|
from udata.commands import cli, success
|
|
8
|
-
from udata.models import User, Dataset, Reuse, Organization, Site
|
|
8
|
+
from udata.models import User, Dataset, Reuse, Organization, Site, GeoZone
|
|
9
9
|
|
|
10
10
|
log = logging.getLogger(__name__)
|
|
11
11
|
|
|
@@ -24,11 +24,12 @@ def grp():
|
|
|
24
24
|
help='Compute datasets metrics')
|
|
25
25
|
@click.option('-r', '--reuses', is_flag=True, help='Compute reuses metrics')
|
|
26
26
|
@click.option('-u', '--users', is_flag=True, help='Compute users metrics')
|
|
27
|
+
@click.option('-g', '--geozones', is_flag=True, help='Compute geo levels metrics')
|
|
27
28
|
@click.option('--drop', is_flag=True, help='Clear old metrics before computing new ones')
|
|
28
29
|
def update(site=False, organizations=False, users=False, datasets=False,
|
|
29
|
-
reuses=False, drop=False):
|
|
30
|
+
reuses=False, geozones = False, drop=False):
|
|
30
31
|
'''Update all metrics for the current date'''
|
|
31
|
-
do_all = not any((site, organizations, users, datasets, reuses))
|
|
32
|
+
do_all = not any((site, organizations, users, datasets, reuses, geozones))
|
|
32
33
|
|
|
33
34
|
if do_all or site:
|
|
34
35
|
log.info('Update site metrics')
|
|
@@ -114,4 +115,18 @@ def update(site=False, organizations=False, users=False, datasets=False,
|
|
|
114
115
|
except Exception as e:
|
|
115
116
|
log.info(f'Error during update: {e}')
|
|
116
117
|
continue
|
|
118
|
+
|
|
119
|
+
if do_all or geozones:
|
|
120
|
+
log.info('Update GeoZone metrics')
|
|
121
|
+
all_geozones = GeoZone.objects.timeout(False)
|
|
122
|
+
with click.progressbar(all_geozones, length=GeoZone.objects.count()) as geozones_bar:
|
|
123
|
+
for geozone in geozones_bar:
|
|
124
|
+
try:
|
|
125
|
+
if drop:
|
|
126
|
+
geozone.metrics.clear()
|
|
127
|
+
geozone.count_datasets()
|
|
128
|
+
except Exception as e:
|
|
129
|
+
log.info(f'Error during update: {e}')
|
|
130
|
+
continue
|
|
131
|
+
|
|
117
132
|
success('All metrics have been updated')
|
udata/core/spatial/api.py
CHANGED
|
@@ -162,11 +162,6 @@ class SpatialCoverageAPI(API):
|
|
|
162
162
|
features = []
|
|
163
163
|
|
|
164
164
|
for zone in GeoZone.objects(level=level.id):
|
|
165
|
-
# fetch nested levels IDs
|
|
166
|
-
ids = []
|
|
167
|
-
ids.append(zone.id)
|
|
168
|
-
# Count datasets in zone
|
|
169
|
-
nb_datasets = Dataset.objects(spatial__zones__in=ids).count()
|
|
170
165
|
features.append({
|
|
171
166
|
'id': zone.id,
|
|
172
167
|
'type': 'Feature',
|
|
@@ -174,7 +169,7 @@ class SpatialCoverageAPI(API):
|
|
|
174
169
|
'name': _(zone.name),
|
|
175
170
|
'code': zone.code,
|
|
176
171
|
'uri': zone.uri,
|
|
177
|
-
'datasets':
|
|
172
|
+
'datasets': zone.metrics.get('datasets', 0)
|
|
178
173
|
}
|
|
179
174
|
})
|
|
180
175
|
|
udata/core/spatial/models.py
CHANGED
|
@@ -3,6 +3,7 @@ from werkzeug.local import LocalProxy
|
|
|
3
3
|
from werkzeug.utils import cached_property
|
|
4
4
|
|
|
5
5
|
from udata.app import cache
|
|
6
|
+
from udata.core.metrics.models import WithMetrics
|
|
6
7
|
from udata.uris import endpoint_for
|
|
7
8
|
from udata.i18n import _, get_locale, language
|
|
8
9
|
from udata.mongo import db
|
|
@@ -21,7 +22,6 @@ class GeoLevel(db.Document):
|
|
|
21
22
|
max_value=ADMIN_LEVEL_MAX,
|
|
22
23
|
default=100)
|
|
23
24
|
|
|
24
|
-
|
|
25
25
|
class GeoZoneQuerySet(db.BaseQuerySet):
|
|
26
26
|
|
|
27
27
|
def resolve(self, geoid, id_only=False):
|
|
@@ -40,7 +40,7 @@ class GeoZoneQuerySet(db.BaseQuerySet):
|
|
|
40
40
|
return result.id if id_only and result else result
|
|
41
41
|
|
|
42
42
|
|
|
43
|
-
class GeoZone(db.Document):
|
|
43
|
+
class GeoZone(WithMetrics, db.Document):
|
|
44
44
|
SEPARATOR = ':'
|
|
45
45
|
|
|
46
46
|
id = db.StringField(primary_key=True)
|
|
@@ -101,6 +101,11 @@ class GeoZone(db.Document):
|
|
|
101
101
|
def external_url(self):
|
|
102
102
|
return endpoint_for('territories.territory', territory=self, _external=True)
|
|
103
103
|
|
|
104
|
+
def count_datasets(self):
|
|
105
|
+
from udata.models import Dataset
|
|
106
|
+
self.metrics['datasets'] = Dataset.objects(spatial__zones=self.id).visible().count()
|
|
107
|
+
self.save()
|
|
108
|
+
|
|
104
109
|
def toGeoJSON(self):
|
|
105
110
|
return {
|
|
106
111
|
'id': self.id,
|
|
@@ -10,6 +10,7 @@ from udata.core.dataset.factories import DatasetFactory
|
|
|
10
10
|
from udata.core.spatial.factories import (
|
|
11
11
|
SpatialCoverageFactory, GeoZoneFactory, GeoLevelFactory
|
|
12
12
|
)
|
|
13
|
+
from udata.core.spatial.tasks import compute_geozones_metrics
|
|
13
14
|
|
|
14
15
|
|
|
15
16
|
class SpatialApiTest(APITestCase):
|
|
@@ -229,6 +230,31 @@ class SpatialApiTest(APITestCase):
|
|
|
229
230
|
'features': [],
|
|
230
231
|
})
|
|
231
232
|
|
|
233
|
+
def test_coverage_datasets_count(self):
|
|
234
|
+
GeoLevelFactory(id='fr:commune')
|
|
235
|
+
paris = GeoZoneFactory(
|
|
236
|
+
id='fr:commune:75056', level='fr:commune',
|
|
237
|
+
name='Paris', code='75056')
|
|
238
|
+
arles = GeoZoneFactory(
|
|
239
|
+
id='fr:commune:13004', level='fr:commune',
|
|
240
|
+
name='Arles', code='13004')
|
|
241
|
+
|
|
242
|
+
for _ in range(3):
|
|
243
|
+
DatasetFactory(
|
|
244
|
+
spatial=SpatialCoverageFactory(zones=[paris.id]))
|
|
245
|
+
for _ in range(2):
|
|
246
|
+
DatasetFactory(
|
|
247
|
+
spatial=SpatialCoverageFactory(zones=[arles.id]))
|
|
248
|
+
|
|
249
|
+
compute_geozones_metrics()
|
|
250
|
+
|
|
251
|
+
response = self.get(url_for('api.spatial_coverage', level='fr:commune'))
|
|
252
|
+
self.assert200(response)
|
|
253
|
+
self.assertEqual(response.json['features'][0]['id'], 'fr:commune:13004')
|
|
254
|
+
self.assertEqual(response.json['features'][0]['properties']['datasets'], 2)
|
|
255
|
+
self.assertEqual(response.json['features'][1]['id'], 'fr:commune:75056')
|
|
256
|
+
self.assertEqual(response.json['features'][1]['properties']['datasets'], 3)
|
|
257
|
+
|
|
232
258
|
|
|
233
259
|
class SpatialTerritoriesApiTest(APITestCase):
|
|
234
260
|
modules = []
|