-
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.
data_quality: Create rewrite_quality_data command
Update settings and add app.py to make this into a django app
- Loading branch information
1 parent
fc9cf57
commit 292793c
Showing
3 changed files
with
40 additions
and
0 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
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