diff --git a/Pipfile b/Pipfile index d602658c..bba08a7c 100644 --- a/Pipfile +++ b/Pipfile @@ -60,6 +60,6 @@ python_version = "3.8" isort = "isort api -c --skip migrations" flake8 = "flake8 --filename \"*.py\" --extend-exclude \"server,api/migrations,api/views/__init__.py,authentification,api/apps.py\"" wait_for_db = "python manage.py wait_for_db" -test = "python manage.py test api.tests roles.tests members.tests" +test = "python manage.py test api.tests roles.tests members.tests metrics.tests" migrate = "python manage.py migrate" collectstatic = "python manage.py collectstatic --noinput" diff --git a/backend/api/urls.py b/backend/api/urls.py index 8face475..eef0a90e 100644 --- a/backend/api/urls.py +++ b/backend/api/urls.py @@ -2,7 +2,7 @@ from django.urls import include, path from .views import (annotation, auto_labeling, comment, example, example_state, export_dataset, health, import_dataset, import_export, - label, project, statistics, tag, task, user) + label, project, tag, task, user) from .views.tasks import category, relation, span, text urlpatterns_project = [ @@ -26,26 +26,6 @@ urlpatterns_project = [ view=export_dataset.DownloadAPI.as_view(), name='download-dataset' ), - path( - route='progress', - view=statistics.ProgressAPI.as_view(), - name='progress' - ), - path( - route='member-progress', - view=statistics.MemberProgressAPI.as_view(), - name='member_progress' - ), - path( - route='category-distribution', - view=statistics.CategoryTypeDistribution.as_view(), - name='category_distribution' - ), - path( - route='span-distribution', - view=statistics.SpanTypeDistribution.as_view(), - name='span_distribution' - ), path( route='category-types', view=label.CategoryTypeList.as_view(), diff --git a/backend/app/settings.py b/backend/app/settings.py index dee11d8b..e6027214 100644 --- a/backend/app/settings.py +++ b/backend/app/settings.py @@ -54,6 +54,7 @@ INSTALLED_APPS = [ 'api.apps.ApiConfig', 'roles.apps.RolesConfig', 'members.apps.MembersConfig', + 'metrics.apps.MetricsConfig', 'rest_framework', 'rest_framework.authtoken', 'django_filters', diff --git a/backend/app/urls.py b/backend/app/urls.py index bb9b8dc1..86f5231a 100644 --- a/backend/app/urls.py +++ b/backend/app/urls.py @@ -43,6 +43,7 @@ urlpatterns += [ path('v1/', include('api.urls')), path('v1/', include('roles.urls')), path('v1/projects//', include('members.urls')), + path('v1/projects//metrics/', include('metrics.urls')), path('swagger/', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'), re_path('', TemplateView.as_view(template_name='index.html')), ] diff --git a/backend/metrics/__init__.py b/backend/metrics/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/backend/metrics/admin.py b/backend/metrics/admin.py new file mode 100644 index 00000000..e69de29b diff --git a/backend/metrics/apps.py b/backend/metrics/apps.py new file mode 100644 index 00000000..515fb841 --- /dev/null +++ b/backend/metrics/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class MetricsConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'metrics' diff --git a/backend/metrics/migrations/__init__.py b/backend/metrics/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/backend/metrics/models.py b/backend/metrics/models.py new file mode 100644 index 00000000..e69de29b diff --git a/backend/api/tests/api/test_statistics.py b/backend/metrics/tests.py similarity index 93% rename from backend/api/tests/api/test_statistics.py rename to backend/metrics/tests.py index ca8e8dc3..abb262fa 100644 --- a/backend/api/tests/api/test_statistics.py +++ b/backend/metrics/tests.py @@ -2,8 +2,8 @@ from model_mommy import mommy from rest_framework import status from rest_framework.reverse import reverse -from ...models import DOCUMENT_CLASSIFICATION -from .utils import CRUDMixin, make_doc, make_label, prepare_project +from api.tests.api.utils import CRUDMixin, prepare_project, make_doc, make_label +from api.models import DOCUMENT_CLASSIFICATION class TestMemberProgress(CRUDMixin): diff --git a/backend/metrics/urls.py b/backend/metrics/urls.py new file mode 100644 index 00000000..de6b2e18 --- /dev/null +++ b/backend/metrics/urls.py @@ -0,0 +1,26 @@ +from django.urls import path + +from .views import ProgressAPI, MemberProgressAPI, CategoryTypeDistribution, SpanTypeDistribution + +urlpatterns = [ + path( + route='progress', + view=ProgressAPI.as_view(), + name='progress' + ), + path( + route='member-progress', + view=MemberProgressAPI.as_view(), + name='member_progress' + ), + path( + route='category-distribution', + view=CategoryTypeDistribution.as_view(), + name='category_distribution' + ), + path( + route='span-distribution', + view=SpanTypeDistribution.as_view(), + name='span_distribution' + ), +] diff --git a/backend/api/views/statistics.py b/backend/metrics/views.py similarity index 93% rename from backend/api/views/statistics.py rename to backend/metrics/views.py index 89da3c89..d6628e8b 100644 --- a/backend/api/views/statistics.py +++ b/backend/metrics/views.py @@ -6,11 +6,9 @@ from rest_framework.permissions import IsAuthenticated from rest_framework.response import Response from rest_framework.views import APIView +from api.models import Example, ExampleState, Project, Annotation, Label, Category, CategoryType, Span, SpanType from members.permissions import IsInProjectReadOnlyOrAdmin -from ..models import (Annotation, Category, CategoryType, Example, - ExampleState, Label, Project, Span, SpanType) - class ProgressAPI(APIView): permission_classes = [IsAuthenticated & IsInProjectReadOnlyOrAdmin]