This repository has been archived by the owner on Sep 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
22/03/Hotfix/2 Production Update See merge request fairdata/fairdata-metax!164
- Loading branch information
Showing
19 changed files
with
371 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/metax_api/management/commands/create_statistic_report.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import logging | ||
|
||
from django.core.management.base import BaseCommand | ||
from django.db.models import Sum | ||
from django.db.models.expressions import RawSQL | ||
|
||
from metax_api.models import File, CatalogRecordV2, OrganizationStatistics, ProjectStatistics | ||
from metax_api.api.rest.base.views import FileViewSet | ||
from metax_api.services import FileService, StatisticService | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
class Command(BaseCommand): | ||
def handle(self, *args, **options): | ||
|
||
logger.info("Creating statistic summary") | ||
|
||
OrganizationStatistics.objects.all().delete() | ||
ProjectStatistics.objects.all().delete() | ||
|
||
|
||
ida_projects = File.objects.all().values("project_identifier").distinct() | ||
for project in ida_projects: | ||
project_id = project["project_identifier"] | ||
ret = StatisticService.count_files([project_id], include_pids=True) | ||
count = ret[0]["count"] | ||
size = ret[0]["byte_size"] | ||
file_pids = ret[1] | ||
|
||
if len(file_pids) == 0: | ||
catalog_records = "" | ||
else: | ||
catalog_records = FileService.get_identifiers(file_pids, "noparams", True, get_pids=True).data | ||
|
||
stat = ProjectStatistics(project_id, count, size, catalog_records) | ||
stat.save() | ||
|
||
|
||
organizations = CatalogRecordV2.objects.all().order_by().values("metadata_provider_org").distinct() | ||
|
||
for org in organizations: | ||
org_id = org["metadata_provider_org"] | ||
ret = StatisticService.count_datasets(metadata_provider_org=org_id) | ||
stat = OrganizationStatistics(org_id, ret["count"], ret["ida_byte_size"]) | ||
stat.save() | ||
|
||
logger.info("Statistic summary created") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
from django.db import migrations | ||
|
||
import logging | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
def update_vrk_datasets(apps, schema_editor): | ||
|
||
logger.info("Updating organization info of catalog records by Väestörekisterikeskus") | ||
|
||
CatalogRecord = apps.get_model('metax_api', 'CatalogRecord') | ||
new_name_fi = "Digi- ja väestötietovirasto" | ||
new_name_en = "Digital and Population Data Services Agency" | ||
new_name_sv = "Myndigheten för digitalisering och befolkningsdata" | ||
description_suffix_fi = "\n\nAineiston luojaorganisaation aikaisempi nimi: Väestörekisterikeskus." | ||
description_suffix_en = "\n\nPrevious name of dataset creator organization: Population Register Center." | ||
|
||
# Catalog Records by Väestörekisterikeskus | ||
# Getting these from the database using Django filters would have | ||
# been too complicated, so instead they are hardcoded | ||
cr_ids = [ | ||
"a3610de8-73fa-4e25-a89b-320549c71f0a", | ||
"b77c91cf-a437-4d01-b2ec-efb08605d559", | ||
"7787c312-3973-4e16-a032-7b89a0257739" | ||
] | ||
|
||
crs = CatalogRecord.objects.filter(identifier__in = cr_ids) | ||
logger.info(f"Found {len(crs)} catalog records to update") | ||
for cr in crs: | ||
cr_json = cr.research_dataset | ||
logger.info(f"Updating catalog record: {cr}") | ||
cr_json["creator"][0]["name"]["en"] = new_name_en | ||
cr_json["creator"][0]["name"]["fi"] = new_name_fi | ||
cr_json["creator"][0]["name"]["sv"] = new_name_sv | ||
if description_suffix_en not in cr_json["description"]["en"]: | ||
cr_json["description"]["en"] += description_suffix_en | ||
if description_suffix_fi not in cr_json["description"]["fi"]: | ||
cr_json["description"]["fi"] += description_suffix_fi | ||
cr.save() | ||
|
||
|
||
def revert(apps, schema_editor): | ||
pass | ||
|
||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('metax_api', '0046_replace_dataset_owner'), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(update_vrk_datasets, revert), | ||
] |
30 changes: 30 additions & 0 deletions
30
src/metax_api/migrations/0048_organizationstatistics_projectstatistics.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Generated by Django 3.2.10 on 2021-12-31 07:43 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('metax_api', '0047_update_vrk_datasets'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='OrganizationStatistics', | ||
fields=[ | ||
('organization', models.CharField(max_length=200, primary_key=True, serialize=False)), | ||
('count', models.IntegerField()), | ||
('byte_size', models.IntegerField()), | ||
], | ||
), | ||
migrations.CreateModel( | ||
name='ProjectStatistics', | ||
fields=[ | ||
('project_identifier', models.CharField(max_length=200, primary_key=True, serialize=False)), | ||
('count', models.IntegerField()), | ||
('byte_size', models.IntegerField()), | ||
('published_datasets', models.TextField()), | ||
], | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# This file is part of the Metax API service | ||
# | ||
# Copyright 2017-2018 Ministry of Education and Culture, Finland | ||
# | ||
# :author: CSC - IT Center for Science Ltd., Espoo Finland <[email protected]> | ||
# :license: MIT | ||
|
||
import logging | ||
|
||
from django.db import models | ||
|
||
_logger = logging.getLogger(__name__) | ||
|
||
class OrganizationStatistics(models.Model): | ||
organization = models.CharField(primary_key=True, max_length=200) | ||
count = models.IntegerField() | ||
byte_size = models.IntegerField() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# This file is part of the Metax API service | ||
# | ||
# Copyright 2017-2018 Ministry of Education and Culture, Finland | ||
# | ||
# :author: CSC - IT Center for Science Ltd., Espoo Finland <[email protected]> | ||
# :license: MIT | ||
|
||
import logging | ||
|
||
from django.db import models | ||
|
||
_logger = logging.getLogger(__name__) | ||
|
||
class ProjectStatistics(models.Model): | ||
project_identifier = models.CharField(primary_key=True, max_length=200) | ||
count = models.IntegerField() | ||
byte_size = models.IntegerField() | ||
published_datasets = models.TextField() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.