Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Metrics break down #2459

Closed
wants to merge 305 commits into from
Closed
Show file tree
Hide file tree
Changes from 250 commits
Commits
Show all changes
305 commits
Select commit Hold shift + click to select a range
313ae1c
iteritems
abulte May 30, 2018
7c0ef68
Remove empty lines at beginning of py files
abulte May 30, 2018
797e055
StringIO
abulte May 30, 2018
03fc41b
WIP test_auth_api
abulte May 30, 2018
b664dcc
WIP
noirbizarre Jun 20, 2018
d66a4e5
WIP rebase
noirbizarre Jun 20, 2018
f045628
Cast dict items and keys
abulte Jun 20, 2018
6703bf7
Metaclass syntax
noirbizarre Jun 20, 2018
d14506d
__unicode__ -> __str__
abulte Jun 20, 2018
4de3ac0
Python CSV/utf8
noirbizarre Jun 20, 2018
871e802
Make harvest tests pass
noirbizarre Jun 20, 2018
604904a
Fix badge test
noirbizarre Jun 20, 2018
3ded27c
Fix test_tasks_routing.py
noirbizarre Jun 20, 2018
a3bf10f
xrange -> range
abulte Jun 21, 2018
045a3f7
fix test_create_with_file_chunks
abulte Jun 21, 2018
c02e90b
fix test_datasets_api \o/
abulte Jun 21, 2018
fbbf458
Fix some dict keys []
abulte Jun 21, 2018
7436729
Fix search tests
noirbizarre Jun 21, 2018
ab6823c
fix enum=VALIDATION_STATES
abulte Jun 21, 2018
69aaa4b
Fix storages tests
noirbizarre Jun 21, 2018
c41b88a
Fix tags tests
noirbizarre Jun 21, 2018
720b24c
Fix uris idna handling
noirbizarre Jun 21, 2018
07fe9ed
Update safe_unicode to output str
noirbizarre Jun 21, 2018
da95a8d
Fix auth test authorization encoding
noirbizarre Jun 21, 2018
77accb5
Fix test_warn_but_ignore_invalid_plugins
abulte Jun 21, 2018
065bbb7
Fix forms tests
abulte Jun 21, 2018
74e2989
Fix test_organization_frontend tests
abulte Jun 21, 2018
9b2d8db
Fix test_frontend_filters
abulte Jun 21, 2018
06cda10
Doc quickfixes
abulte Jun 21, 2018
84505d7
Migrate circle
abulte Jun 21, 2018
4bb716f
Bump 2.0.0 and build py3 branch on Circle
abulte Jun 21, 2018
7e680f0
Fix harvester CSV
abulte Jun 21, 2018
ff57db0
mock_use_standalone_module
abulte Jun 21, 2018
45285d0
Flush CI cache
abulte Jun 21, 2018
d814690
Merge branch 'py3' of github.com:opendatateam/udata into py3
abulte Jun 21, 2018
85e7c09
python3.6 binary
abulte Jun 21, 2018
3ec8e90
Use virtualenv
abulte Jun 21, 2018
75a1d5c
python3.6 -> python3 on most inv tasks
abulte Jun 22, 2018
ec589bb
python3 binary everywhere except virtualenv creation
abulte Jun 22, 2018
0afd86d
Publish py3 branch
abulte Jun 22, 2018
e1e430d
Ensure the Python 3 version is not installable with Python 2
noirbizarre Jun 23, 2018
56319c3
python binary
abulte Jun 25, 2018
be31185
Merge branch 'master' into py3
abulte Jun 25, 2018
0c1f9fe
flake8 max-line-length = 100
abulte Jun 25, 2018
82bd9ca
Fix pkgutil SourceLoader changes in Python 3
noirbizarre Jun 27, 2018
9d74198
Fix urllib.quote
abulte Jul 2, 2018
ab69bef
Merge master
noirbizarre Aug 2, 2018
93a2501
Switch from msgpack to msgpack-python
noirbizarre Aug 2, 2018
8067423
Flush CircleCI cache
noirbizarre Aug 2, 2018
63689ff
Merge pull request #1814 from noirbizarre/py3-merge
noirbizarre Aug 2, 2018
9763d92
Merge branch 'master' into py3-merge-master
noirbizarre Aug 28, 2018
a5ab56f
Post merge python 3 fixes
noirbizarre Aug 28, 2018
038397a
Merge pull request #1859 from noirbizarre/py3-merge-master
noirbizarre Aug 28, 2018
b240e0f
Try building against lighter and newer docker images
noirbizarre Aug 20, 2018
15af777
Try using node image and ghr
noirbizarre Aug 20, 2018
0f71940
In-memory mongo
noirbizarre Aug 21, 2018
248c988
Merge pull request #1860 from opendatateam/py3-alpine
noirbizarre Aug 28, 2018
2714752
Merge branch 'master' into py3
noirbizarre Aug 29, 2018
32297fd
Fix assets manifest py3 compat
noirbizarre Aug 30, 2018
49565a5
Merge branch 'master' into py3
abulte Sep 3, 2018
d8240ec
Merge branch 'master' into py3
noirbizarre Sep 14, 2018
8239dc7
Merge branch 'master' into py3
abulte Nov 6, 2018
282dbae
Remove pyliblzma
abulte Nov 6, 2018
87d2e3e
Remove py2 headers
abulte Nov 6, 2018
a049ba7
py3 fixes
abulte Nov 6, 2018
17fc7c9
Drop legacy JS migrations
noirbizarre Nov 15, 2018
401020b
WIP
noirbizarre Nov 15, 2018
776bc20
WIP
noirbizarre Nov 15, 2018
aeade57
WIP
noirbizarre Nov 16, 2018
a8ebb03
WIP
noirbizarre Nov 16, 2018
659f9f4
WIP
noirbizarre Nov 28, 2018
03bc40a
Flush cache
noirbizarre Nov 28, 2018
32c43c4
Upgrade pip during build
noirbizarre Nov 28, 2018
917b35e
Introduce RollbackError
noirbizarre Nov 28, 2018
dc3188b
Improve Record
noirbizarre Nov 29, 2018
b5933a6
Refactor
noirbizarre Nov 29, 2018
674f187
More cosmetics
noirbizarre Dec 5, 2018
ad037b8
Fixes and refactor
noirbizarre Jan 7, 2019
cd96b96
Added changelog
noirbizarre Jan 7, 2019
e442f14
Pin faulty har-validator dependency
noirbizarre Jan 7, 2019
cd8e806
Post review fixes
noirbizarre Jan 9, 2019
7e15c97
Merge pull request #1956 from noirbizarre/data-migrations-v2
noirbizarre Jan 9, 2019
ad8134f
Merge branch 'master' into py3
noirbizarre Feb 1, 2019
13707a2
Merge branch 'master' into py3
noirbizarre Feb 27, 2019
3f7f65a
Use assertEqual instead of assertEquals (deprecation warning)
noirbizarre Mar 4, 2019
71a9f22
Use validators.DataRequired() instead of validators.required() (depre…
noirbizarre Mar 4, 2019
dedb8f8
Use babel.numbers.format_decimal() instead of babel.numbers.format_nu…
noirbizarre Mar 4, 2019
78b73ab
Migrate from deprecated flask-restplus decorators
noirbizarre Mar 4, 2019
bc01f47
Replace csrf_enabled=False by meta={'csrf'=False}
noirbizarre Mar 4, 2019
07adcb6
Merge pull request #2054 from noirbizarre/py3-deprecation-warnings
noirbizarre Mar 4, 2019
222ca1f
Merge branch 'master' into py3
noirbizarre Mar 27, 2019
26f8a2f
Fix ModelField.process
noirbizarre Apr 1, 2019
371537a
Merge branch 'master' into py3
noirbizarre Jul 15, 2019
6ec32c0
Post merge fixes for Python 3 compatibility
noirbizarre Jul 15, 2019
47d8c05
Remove pytest warnings by declaring custom markers
noirbizarre Jul 15, 2019
684f1e6
Remove last warnings on which we have control
noirbizarre Jul 15, 2019
eca7e81
Merge branch 'master' into py3
noirbizarre Aug 14, 2019
ba0163b
Update ModelSearchAdapter metaclass for py3
noirbizarre Aug 14, 2019
d59c304
Fix apidoc for Py3
noirbizarre Sep 3, 2019
b0b7a7b
Merge branch 'master' into py3
noirbizarre Sep 23, 2019
97ba10a
Prevent ensurepip call as it has been removed from all python docker …
noirbizarre Sep 23, 2019
5e34cd4
Remove duplicated max-line-length parameter in setup.cfg
noirbizarre Sep 23, 2019
869a30d
Install/upgrade setuptools and flush cache
noirbizarre Sep 23, 2019
e545093
Rely on virtualenv instead of venv
noirbizarre Sep 24, 2019
a61e15e
Merge pull request #2321 from noirbizarre/fix-pip-py3-build
noirbizarre Sep 24, 2019
e345528
Improve hooks handling: handle None, marked as safe...
noirbizarre Apr 15, 2019
4672879
Make dataset_recommandations use the new hook syntax
noirbizarre Apr 15, 2019
caa00f3
Adapt settings loading to Python 3
noirbizarre Apr 15, 2019
932cbd1
context as hooks and snippets parameters
noirbizarre Sep 24, 2019
794738a
Handle multiple registeration by hook
noirbizarre Sep 25, 2019
6835223
Conditionnal hook
noirbizarre Sep 25, 2019
f20d690
Test params
noirbizarre Sep 25, 2019
086f690
Added hooks documentation
noirbizarre Sep 25, 2019
fd8d8f0
Header and footer snippets as hooks
noirbizarre Oct 2, 2019
e9ef928
CHANGELOG
noirbizarre Sep 24, 2019
dd8dec6
Merge pull request #2323 from noirbizarre/hooks
noirbizarre Oct 2, 2019
4983dff
Upgrade to Pillow 6.1.0 (fix #2224)
noirbizarre Jul 15, 2019
62560ff
Upgrade to requests-mock 1.6.0 (fix #2118)
noirbizarre Jul 15, 2019
0423a81
Upgrade Celery/redis stask (fix #2167, fix #2202, fix #2104, fix #209…
noirbizarre Jul 16, 2019
41ad3d3
Twine as dev dependency, drop deprecated readme-renderer
noirbizarre Oct 2, 2019
f9b529c
Upgrade to Pillow 6.2.0 (fix ##2333)
noirbizarre Oct 2, 2019
d4fa3ba
Upgrade mocking libs
noirbizarre Oct 2, 2019
1735c16
Safe upgrades (fix #2269, fix #2271, fix #2281, fix #2282, fix #2270,…
noirbizarre Oct 2, 2019
1da4067
Upgrade to requests 2.22.0 and drop transitive urllib3 dependency (fi…
noirbizarre Oct 2, 2019
e7edcd6
Upgrade html2text (fix #2328)
noirbizarre Oct 2, 2019
c1a94fe
Upgrade Faker and FactoryBoy (fix #2135, fix #2314)
noirbizarre Oct 2, 2019
455fba4
Upgrade to Flask 1.0.4 (1.1.x needs testing)
noirbizarre Oct 2, 2019
9dac033
Cleanup the dev tasks
noirbizarre Oct 2, 2019
ada90da
Advertise Python 3.7 compatibility
noirbizarre Oct 2, 2019
9253129
Merge pull request #2335 from noirbizarre/py3-updates
noirbizarre Oct 2, 2019
b668278
Switch to Mongo 3.6
noirbizarre Oct 2, 2019
da67117
Upgrade mongo-related dependencies (fix #2212, fix #2286)
noirbizarre Oct 2, 2019
b60a382
Backward compatibility on Resource.save()
noirbizarre Oct 2, 2019
c3c9034
Update udata/core/dataset/models.py
noirbizarre Oct 7, 2019
bca89e2
Merge pull request #2336 from noirbizarre/py3-mongo-update
noirbizarre Oct 7, 2019
afdd12d
Switch from `commonmark` to `mistune` as marjdown renderer.
noirbizarre Jul 12, 2019
4a1371a
Proper <script type="application/ld+json"> and mdstrip behavior
noirbizarre Oct 8, 2019
c6c585e
JS Markdown rendering fixes
noirbizarre Oct 9, 2019
b012373
Rename helpers/commonmark into helpers/markdown for consistency
noirbizarre Oct 9, 2019
bb9b51b
Improved JSON-LD script embedding
noirbizarre Oct 10, 2019
db2d66a
Changelog
noirbizarre Oct 10, 2019
9e87fe4
Upgrade makrdown-it to latest version
noirbizarre Oct 10, 2019
b70d092
fixed role modal default
Dec 18, 2019
c729d5b
Merge branch 'master' of https://github.com/opendatateam/udata
Dec 26, 2019
a3054c6
Merge branch 'master' of https://github.com/opendatateam/udata
Dec 26, 2019
811163d
Merge branch 'master' of https://github.com/opendatateam/udata
Dec 27, 2019
5100fbf
Merge branch 'master' of https://github.com/opendatateam/udata
Jan 6, 2020
e54e9bd
Merge branch 'master' into py3
Jan 6, 2020
b099b26
fix requirements
Jan 6, 2020
5ffe41e
Install twine on circle/publish
abulte Jan 6, 2020
9e623ae
replace return by yield in fixture
Jan 6, 2020
d970f26
Configure Renovate for tests deps (#2408)
renovate[bot] Jan 7, 2020
50a9224
trigger build
abulte Jan 7, 2020
012d3d1
Update dependency httpretty to v0.9.7
renovate-bot Jan 7, 2020
3e052a3
Merge branch 'master' into py3
abulte Jan 7, 2020
eafc631
Reconfigure renovate (#2413)
abulte Jan 7, 2020
52ab3cd
Merge branch 'mistune' of https://github.com/noirbizarre/udata into n…
abulte Jan 7, 2020
96b23da
Merge branch 'noirbizarre-mistune' into py3
abulte Jan 7, 2020
7b358af
Update dependency pytest-mock to v2
renovate-bot Jan 7, 2020
d7b5686
Update install.pip
quaxsze Jan 7, 2020
c86a902
Update dependency Flask-Caching to v1.8.0
renovate-bot Jan 7, 2020
43aab1c
Remove unused pyyaml dep
abulte Jan 8, 2020
fbcc6d5
remove 3.6 ref in docs
abulte Jan 8, 2020
e4acee5
Remove future dep and dangling imports
abulte Jan 8, 2020
54956c6
[renovate] 5 PRs per houx max
abulte Jan 8, 2020
d0a34bf
Update dependency Jinja2 to v2.10.3
renovate-bot Jan 8, 2020
c1e7df1
Update dependency cryptography to v2.8
renovate-bot Jan 8, 2020
5629af5
Update dependency jsonschema to v3.2.0
renovate-bot Jan 8, 2020
5fc6dbe
Fix theme import on python3.7 w/ editable installations
abulte Jan 8, 2020
05f9c99
Update dependency lxml to v4.4.2
renovate-bot Jan 8, 2020
d37eb93
Update dependency python-dateutil to v2.8.1
renovate-bot Jan 8, 2020
2567d43
Update dependency pytz to v2019.3
renovate-bot Jan 8, 2020
717c295
Update dependency simplejson to v3.17.0
renovate-bot Jan 8, 2020
883d9cc
Update dependency msgpack to v0.6.2
renovate-bot Jan 9, 2020
fa57646
[renovate] enabled masterIssueApproval
abulte Jan 9, 2020
122561e
Update dependency voluptuous to v0.11.7
renovate-bot Jan 9, 2020
1adb4f4
Update dependency Faker to v3
renovate-bot Jan 9, 2020
8512658
Update dependency pillow to v7
renovate-bot Jan 9, 2020
2d086fc
Update dependency pymongo to v3.10.1
renovate-bot Jan 9, 2020
02fb875
Form fields: do not translate label.text as it should already be tran…
quaxsze Jan 10, 2020
8e11559
Update dependency click to v7 (#2439)
renovate[bot] Jan 10, 2020
d6a78be
Update dependency redis to v3.3.11 (#2433)
renovate[bot] Jan 10, 2020
16f95c5
Update dependency Babel to v2.8.0 (#2414)
renovate[bot] Jan 10, 2020
53d4ce9
Fix geozone/logos load, require py3.7 (#2446)
abulte Jan 10, 2020
e5aa366
Fix geologos load
abulte Jan 10, 2020
e3a17c8
Update dependency flask-restplus to v0.13.0 (#2423)
renovate[bot] Jan 14, 2020
16bf6ca
fixed bleach for ftp
Jan 15, 2020
eace274
Fixed markdown error on FTP links (#2448)
quaxsze Jan 16, 2020
4dce9dc
Merge branch 'py3' of github.com:opendatateam/udata into py3
Jan 16, 2020
fbd3df7
Display link's text only to avoid KeyError (#2451)
quaxsze Jan 22, 2020
67778d2
Merge branch 'master' into py3
quaxsze Jan 22, 2020
193efd1
Merge branch 'master' into py3
quaxsze Jan 22, 2020
02681ea
Merge branch 'py3' of github.com:opendatateam/udata into py3
Jan 22, 2020
dc411f8
fix basestring type to str
Jan 22, 2020
b3468c7
change way of reading request's result for terms (#2454)
quaxsze Jan 29, 2020
0a1ed04
Added conn alias (#2455)
quaxsze Feb 18, 2020
af872aa
stating to breakdown
Mar 3, 2020
0097f3a
breakdown in progress
Mar 4, 2020
9ccf9cb
turning to signals
Mar 9, 2020
5cd9e26
readapt search
Mar 9, 2020
ccf6cf4
more signals
Mar 10, 2020
45d3c72
more
Mar 11, 2020
d080b84
removed reuse metrics file
Mar 11, 2020
605c261
Merge branch 'master' of github.com:opendatateam/udata
Mar 11, 2020
1da5c14
Merge branch 'master' into metricsBreakDown
Mar 11, 2020
a72c685
fix merge
Mar 11, 2020
568676e
removed metric model
Mar 11, 2020
80a759a
removed old tests
Mar 11, 2020
66fae91
modified command
Mar 13, 2020
63a72e8
removed graphs from client side
Mar 13, 2020
a156f75
started fixing tests
Mar 16, 2020
b5d3f8d
fixed transfert tests
Mar 17, 2020
878c14e
Fixed CSV metrics
Mar 17, 2020
083baa5
fixed tests
Mar 17, 2020
cb4c502
Merge branch 'master' into metricsBreakDown
quaxsze Mar 17, 2020
2d01658
removed code for other PR
Mar 17, 2020
2c817ae
Merge branch 'metricsBreakDown' of github.com:quaxsze/udata into metr…
Mar 17, 2020
53c0bcc
Update udata/core/dataset/models.py
quaxsze Mar 18, 2020
ef9bdd8
fixes
Mar 18, 2020
c4c315c
Merge branch 'metricsBreakDown' of github.com:quaxsze/udata into metr…
Mar 18, 2020
98ca216
fix test
Mar 18, 2020
2487ddc
fix2\ test
Mar 18, 2020
8cf438b
add drop option to metrics command
Mar 19, 2020
7faa72c
Merge branch 'master' into metricsBreakDown
quaxsze Mar 19, 2020
d28e320
small improvements
Mar 19, 2020
726ac7c
adding keys
Mar 20, 2020
b746f8b
fix mac metrics in search
Mar 20, 2020
0c70b64
removed unused code
Mar 20, 2020
0ea760c
added test for public service
Mar 20, 2020
7339c08
various fixes
Mar 24, 2020
b54648d
Merge branch 'master' into metricsBreakDown
quaxsze Mar 24, 2020
3b6201a
Merge branch 'master' into metricsBreakDown
quaxsze Mar 24, 2020
9c365e9
add site signal for metrics
Mar 27, 2020
87356c2
Merge branch 'metricsBreakDown' of github.com:quaxsze/udata into metr…
Mar 27, 2020
c71c38d
Update udata/core/metrics/tasks.py
quaxsze Apr 2, 2020
5a003e9
Update udata/core/metrics/tasks.py
quaxsze Apr 2, 2020
a650dcd
Update udata/core/reuse/models.py
quaxsze Apr 2, 2020
7247ab5
Update udata/core/organization/models.py
quaxsze Apr 2, 2020
c2cb91b
various improvements
Apr 6, 2020
914a77b
Merge branch 'metricsBreakDown' of github.com:quaxsze/udata into metr…
Apr 6, 2020
80d0949
add views metric keys to resource and community ones
Apr 10, 2020
6fb471e
Merge branch 'master' into metricsBreakDown
quaxsze Apr 10, 2020
26debec
add branch to publish
Apr 17, 2020
f865c34
fix branch to publish
Apr 17, 2020
6cf66d7
clear cache circle
Apr 17, 2020
1482885
replaced py3 by current branch
Apr 17, 2020
887257b
replaced py3 by current branch bis
Apr 17, 2020
509a07c
removed charts on site in admin
Apr 22, 2020
d28cdc6
add various tests
Apr 22, 2020
9f1ea9f
added try catch in metric command
Apr 22, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

## Current (in progress)

### Breaking changes

- Full metrics refactoring [2459](https://github.com/opendatateam/udata/pull/2459)
quaxsze marked this conversation as resolved.
Show resolved Hide resolved

### New features

- Nothing yet

## 2.0.1 (2020-03-24)
Expand Down
6 changes: 0 additions & 6 deletions docs/adapting-settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -640,12 +640,6 @@ The cache type, which can be adjusted to your needs (_ex:_ `null`, `memcached`)
A prefix used for cache keys to avoid conflicts with other middleware.
It also allows you to use the same backend with different instances.

### USE_METRICS

**default**: `True`

This activates metrics, this is deactivated for tests

## Flask-FS options

udata use Flask-FS as storage abstraction.
Expand Down
92 changes: 0 additions & 92 deletions js/components/dashboard/graphs.vue

This file was deleted.

3 changes: 1 addition & 2 deletions js/front/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ import Vue from 'vue';

import ActivityTimeline from 'components/activities/timeline.vue';
import SmallBox from 'components/containers/small-box.vue';
import DashboardGraphs from 'components/dashboard/graphs.vue';


new Vue({
mixins: [FrontMixin],
components: {ActivityTimeline, DashboardGraphs, SmallBox},
components: {ActivityTimeline, SmallBox},
});
3 changes: 1 addition & 2 deletions js/front/organization/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import Vue from 'vue';
import FollowButton from 'components/buttons/follow.vue';
import DetailsModal from './details-modal.vue';
import ActivityTimeline from 'components/activities/timeline.vue';
import DashboardGraphs from 'components/dashboard/graphs.vue';
import Tab from 'components/tab';
import Tabset from 'components/tabs.vue';

Expand All @@ -25,7 +24,7 @@ import MembershipRequest from './membership-request.vue';

new Vue({
mixins: [FrontMixin],
components: {FollowButton, Tab, Tabset, ActivityTimeline, DashboardGraphs, SmallBox},
components: {FollowButton, Tab, Tabset, ActivityTimeline, SmallBox},
data() {
return {
organization: this.extractOrganization(),
Expand Down
4 changes: 0 additions & 4 deletions js/views/dataset.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@
<div class="row">
<resource-list :dataset="dataset" class="col-xs-12"></resource-list>
</div>
<div class="row">
<chart-widget id="trafic" class="col-xs-12" :title="_('Audience')"
:metrics="metrics" x="date" :y="y"></chart-widget>
</div>

<div class="row">
<reuse-list id="reuses" class="col-xs-12" :reuses="reuses"></reuse-list>
Expand Down
9 changes: 0 additions & 9 deletions js/views/organization.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,6 @@
<members :org="org" class="col-xs-12 col-md-6"></members>
</div>

<div class="row">
<chart id="trafic-widget" class="col-xs-12"
:title="charts.traffic.title" :default="charts.traffic.default"
:metrics="metrics"
x="date" :y="charts.traffic.y"
>
</chart>
</div>

<div class="row">
<dataset-list id="datasets-widget" class="col-xs-12" :datasets="datasets"
:downloads="downloads">
Expand Down
5 changes: 3 additions & 2 deletions udata/core/dataset/api_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@
'last_modified': fields.ISODateTime(
attribute='modified', readonly=True,
description='The resource last modification date'),
'metrics': fields.Raw(description='The resource metrics', readonly=True),
'metrics': fields.Raw(
description='The resource metrics', readonly=True),
'extras': fields.Raw(description='Extra attributes as key-value pairs'),
'preview_url': fields.String(description='An optional preview URL to be '
'loaded as a standalone page (ie. iframe or '
Expand Down Expand Up @@ -161,7 +162,7 @@
description=('Next expected update date, you will be notified '
'once that date is reached.')),
'extras': fields.Raw(description='Extras attributes as key-value pairs'),
'metrics': fields.Raw(description='The dataset metrics'),
'metrics': fields.Raw(attribute=lambda o: o.get_metrics(), description='The dataset metrics'),
'organization': fields.Nested(
org_ref_fields, allow_null=True,
description='The producer organization'),
Expand Down
41 changes: 4 additions & 37 deletions udata/core/dataset/metrics.py
Original file line number Diff line number Diff line change
@@ -1,42 +1,9 @@
from udata.core.metrics import Metric
from udata.i18n import lazy_gettext as _
from udata.models import Dataset, Reuse
from udata.models import Reuse

from udata.core.issues.metrics import IssuesMetric
from udata.core.discussions.metrics import DiscussionsMetric
from udata.core.followers.metrics import FollowersMetric


__all__ = (
'DatasetReuses', 'DatasetIssuesMetric', 'DatasetFollowers',
'DatasetDiscussionsMetric'
)


class DatasetReuses(Metric):
model = Dataset
name = 'reuses'
display_name = _('Reuses')

def get_value(self):
return Reuse.objects(datasets=self.target).visible().count()


@Reuse.on_update.connect
@Reuse.on_create.connect
@Reuse.on_update.connect
@Reuse.on_delete.connect
def update_dataset_reuses_metric(reuse, **kwargs):
for dataset in reuse.datasets:
metric = DatasetReuses(dataset)
metric.trigger_update()


class DatasetIssuesMetric(IssuesMetric):
model = Dataset


class DatasetDiscussionsMetric(DiscussionsMetric):
model = Dataset


class DatasetFollowers(FollowersMetric):
model = Dataset
dataset.count_reuses()
40 changes: 39 additions & 1 deletion udata/core/dataset/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from mongoengine.fields import DateTimeField
from stringdist import rdlevenshtein
from werkzeug import cached_property
from elasticsearch_dsl import Integer, Object

from udata.frontend.markdown import mdstrip
from udata.models import db, WithMetrics, BadgeMixin, SpatialCoverage
Expand Down Expand Up @@ -394,6 +395,20 @@ def __str__(self):
PIVOTAL_DATA: _('Pivotal data'),
}

__search_metrics__ = Object(properties={
'reuses': Integer(),
'followers': Integer(),
'views': Integer(),
})

__metrics_keys__ = [
'discussions',
'issues',
'reuses',
'followers',
'views',
]

meta = {
'indexes': [
'-created_at',
Expand Down Expand Up @@ -439,7 +454,6 @@ def post_save(cls, sender, document, **kwargs):
resource_id=kwargs['resource_added'])

def clean(self):
super(Dataset, self).clean()
if self.frequency in LEGACY_FREQUENCIES:
self.frequency = LEGACY_FREQUENCIES[self.frequency]

Expand Down Expand Up @@ -679,6 +693,30 @@ def json_ld(self):

return result

@property
def views_count(self):
return self.metrics.get('views', 0)

def count_discussions(self):
from udata.models import Discussion
self.metrics['discussions'] = Discussion.objects(subject=self, closed=None).count()
self.save()

def count_issues(self):
from udata.models import Issue
self.metrics['issues'] = Issue.objects(subject=self, closed=None).count()
self.save()

def count_reuses(self):
from udata.models import Reuse
self.metrics['reuses'] = Reuse.objects(datasets=self).visible().count()
self.save()

def count_followers(self):
from udata.models import Follow
self.metrics['followers'] = Follow.objects(until=None).followers(self).count()
self.save()


pre_save.connect(Dataset.pre_save, sender=Dataset)
post_save.connect(Dataset.post_save, sender=Dataset)
Expand Down
10 changes: 4 additions & 6 deletions udata/core/dataset/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
Dataset, Organization, License, User, GeoZone, RESOURCE_TYPES
)
from udata.search import (
ModelSearchAdapter, i18n_analyzer, metrics_mapping_for, register,
ModelSearchAdapter, i18n_analyzer, register,
lazy_config
)
from udata.search.analysis import simple
Expand All @@ -21,8 +21,6 @@
)
from udata.utils import to_iso_datetime

# Metrics are require for dataset search
from . import metrics # noqa

__all__ = ('DatasetSearch', )

Expand All @@ -33,11 +31,11 @@


def max_reuses():
return max(current_site.metrics.get('max_dataset_reuses'), 10)
return max(current_site.get_metrics()['max_dataset_reuses'], 10)


def max_followers():
return max(current_site.metrics.get('max_dataset_followers'), 10)
return max(current_site.get_metrics()['max_dataset_followers'], 10)


def granularity_labelizer(value):
Expand Down Expand Up @@ -98,7 +96,7 @@ class Meta:
payloads=False)
created = Date(format='date_hour_minute_second')
last_modified = Date(format='date_hour_minute_second')
metrics = metrics_mapping_for(Dataset)
metrics = Dataset.__search_metrics__
featured = Boolean()
temporal_coverage = Nested(multi=False, properties={
'start': Long(),
Expand Down
4 changes: 1 addition & 3 deletions udata/core/dataset/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from udata.frontend import csv
from udata.harvest.models import HarvestJob
from udata.i18n import lazy_gettext as _
from udata.models import (Follow, Issue, Discussion, Activity, Metrics, Topic,
from udata.models import (Follow, Issue, Discussion, Activity, Topic,
Organization)
from udata.tasks import job

Expand Down Expand Up @@ -42,8 +42,6 @@ def purge_datasets(self):
Discussion.objects(subject=dataset).delete()
# Remove activity
Activity.objects(related_to=dataset).delete()
# Remove metrics
Metrics.objects(object_id=dataset.id).delete()
# Remove topics' related dataset
for topic in Topic.objects(datasets=dataset):
datasets = topic.datasets
Expand Down