-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
34 changed files
with
488 additions
and
70 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
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
Empty file.
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,32 @@ | ||
import django_filters.rest_framework | ||
from rest_framework import filters, generics | ||
import db.models as db | ||
from api.dashboard import serializers | ||
from api.dashboard.permissions import ReadOnly | ||
|
||
|
||
class Publishers(generics.ListAPIView): | ||
serializer_class = serializers.PublishersSerializer | ||
permission_classes = [ReadOnly] | ||
|
||
filter_backends = ( | ||
filters.SearchFilter, | ||
django_filters.rest_framework.DjangoFilterBackend, | ||
filters.OrderingFilter, | ||
) | ||
|
||
search_fields = ("^data__name",) | ||
filterset_fields = ["name", "prefix"] | ||
|
||
ordering_fields = ["data__name"] | ||
|
||
def get_queryset(self): | ||
return db.Publisher.objects.filter(getter_run=db.GetterRun.objects.last()) | ||
|
||
|
||
class Sources(generics.ListAPIView): | ||
serializer_class = serializers.SourcesSerializer | ||
# pagination_class = CurrentLatestGrantsPaginator | ||
|
||
def get_queryset(self): | ||
return db.SourceFile.objects.filter(getter_run=db.GetterRun.objects.last()) |
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,14 @@ | ||
from rest_framework import permissions | ||
|
||
|
||
class ReadOnly(permissions.BasePermission): | ||
""" | ||
Always read-only even if authenticated | ||
""" | ||
|
||
def has_object_permission(self, request, view, obj): | ||
# we'll always allow GET, HEAD or OPTIONS requests. | ||
if request.method in permissions.SAFE_METHODS: | ||
return True | ||
|
||
return False |
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,36 @@ | ||
from rest_framework import serializers | ||
|
||
import db.models as db | ||
|
||
|
||
class SourcesSerializer(serializers.ModelSerializer): | ||
id = serializers.JSONField(source="data.identifier") | ||
datagetter_data = serializers.JSONField() | ||
modified = serializers.JSONField(source="data.modified") | ||
grants = serializers.IntegerField() | ||
distribution = serializers.JSONField(source="get_distribution") | ||
quality = serializers.JSONField() | ||
|
||
class Meta: | ||
model = db.SourceFile | ||
fields = ( | ||
"id", | ||
"datagetter_data", | ||
"grants", | ||
"distribution", | ||
"modified", | ||
"quality", | ||
) | ||
|
||
|
||
class PublishersSerializer(serializers.ModelSerializer): | ||
name = serializers.JSONField(source="data.name") | ||
logo = serializers.JSONField(source="data.logo") | ||
prefix = serializers.JSONField(source="data.prefix") | ||
website = serializers.JSONField(source="data.website") | ||
|
||
files = SourcesSerializer(source="get_sourcefiles", many=True) | ||
|
||
class Meta: | ||
model = db.Publisher | ||
fields = ("name", "logo", "prefix", "website", "files") |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from lib360dataquality.cove.threesixtygiving import ( | ||
USEFULNESS_TEST_CLASS, | ||
common_checks_360, | ||
) | ||
from lib360dataquality.cove.schema import Schema360 | ||
|
||
schema = Schema360() | ||
|
||
|
||
def create(grants): | ||
"""grants: grants json""" | ||
|
||
result = {} | ||
|
||
common_checks_360(result, "/", grants, schema, test_classes=[USEFULNESS_TEST_CLASS]) | ||
|
||
return result |
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,5 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class AdditionalDataConfig(AppConfig): | ||
name = "data_quality" |
34 changes: 34 additions & 0 deletions
34
datastore/data_quality/management/commands/rewrite_quality_data.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,34 @@ | ||
from django.core.management.base import BaseCommand | ||
|
||
from data_quality import quality_data | ||
import db.models as db | ||
|
||
|
||
class Command(BaseCommand): | ||
help = ( | ||
"Reloads the additional data on grant data specified by datagetter id or latest" | ||
) | ||
|
||
def add_arguments(self, parser): | ||
parser.add_argument( | ||
type=str, | ||
action="store", | ||
dest="getter_run", | ||
help="The datagetter run id or latest", | ||
) | ||
|
||
def handle(self, *args, **options): | ||
|
||
if "latest" in options["getter_run"]: | ||
source_files = db.Latest.objects.get( | ||
series=db.Latest.CURRENT | ||
).sourcefile_set.all() | ||
else: | ||
source_files = db.SourceFile.object.filter(getter_run=options["getter_run"]) | ||
|
||
for source_file in source_files: | ||
grants_list = { | ||
"grants": list(source_file.grant_set.values_list("data", flat=True)) | ||
} | ||
source_file.quality = quality_data.create(grants_list) | ||
source_file.save() |
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,44 @@ | ||
from lib360dataquality.cove.threesixtygiving import ( | ||
USEFULNESS_TEST_CLASS, | ||
TEST_CLASSES, | ||
common_checks_360, | ||
) | ||
from lib360dataquality.cove.schema import Schema360 | ||
from tempfile import TemporaryDirectory | ||
|
||
schema = Schema360() | ||
|
||
|
||
def create(grants): | ||
"""grants: grants json""" | ||
|
||
cove_results = {"file_type": "json"} | ||
|
||
with TemporaryDirectory() as tempdir: | ||
common_checks_360( | ||
cove_results, tempdir, grants, schema, test_classes=[USEFULNESS_TEST_CLASS] | ||
) | ||
|
||
# We don't quite want the result as-is | ||
# our format is: | ||
# { | ||
# "TestClassName": { "heading": "text", "count": n }, | ||
# "TestTwoClassName": { "count": 0 }, | ||
# } | ||
# We only get results when a quality test finds an issue, so to provide a count 0 | ||
# value we template out all the expected results from all the available tests. | ||
|
||
quality_results = {} | ||
|
||
# Create the template | ||
for available_test in TEST_CLASSES[USEFULNESS_TEST_CLASS]: | ||
quality_results[available_test.__name__] = {"count": 0} | ||
|
||
# Update with the results | ||
for test in cove_results["usefulness_checks"]: | ||
quality_results[test[0]["type"]] = { | ||
"heading": test[0]["heading"], | ||
"count": test[0]["count"], | ||
} | ||
|
||
return quality_results |
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,51 @@ | ||
from django.core.management.base import BaseCommand, CommandError | ||
|
||
from db.models import GetterRun | ||
|
||
|
||
class Command(BaseCommand): | ||
help = "Archive the getter run by the specified getter run ids. Archiving deletes grant data but not the metadata (SourceFiles, Publishers)" | ||
|
||
def add_arguments(self, parser): | ||
parser.add_argument( | ||
type=int, | ||
nargs="*", | ||
action="store", | ||
dest="getter_run_ids", | ||
help="The datagetter run ids", | ||
) | ||
|
||
parser.add_argument( | ||
"--no-prompt", | ||
action="store_true", | ||
help="Don't prompt for archiving", | ||
) | ||
|
||
parser.add_argument( | ||
"--oldest", | ||
action="store_true", | ||
help="Archives the oldest getter run", | ||
) | ||
|
||
def handle(self, *args, **options): | ||
if options.get("oldest"): | ||
to_delete = GetterRun.objects.order_by("datetime").first() | ||
options["getter_run_ids"] = [to_delete.pk] | ||
|
||
if len(options["getter_run_ids"]) == 0: | ||
raise CommandError("No datagetter data specified") | ||
|
||
for run in options["getter_run_ids"]: | ||
try: | ||
confirm = "n" | ||
getter_run = GetterRun.objects.get(pk=run) | ||
|
||
if not options["no_prompt"]: | ||
confirm = input("Confirm delete grant data '%s' y/n: " % run) | ||
|
||
if "y" in confirm or "Y" in confirm or options["no_prompt"]: | ||
getter_run.archive_run() | ||
print("Archived %s" % run) | ||
|
||
except GetterRun.DoesNotExist: | ||
raise CommandError("Run id '%s' doesn't exist " % run) |
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.