-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OpenConceptLab/ocl_issues#1633 | Monthly usage report refactoring and…
… using CSV format
- Loading branch information
1 parent
961a6d1
commit d38f1d4
Showing
15 changed files
with
498 additions
and
437 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
from core.collections.models import Collection, Expansion, CollectionReference | ||
from core.common.constants import HEAD | ||
from core.reports.models import AbstractReport | ||
|
||
|
||
class CollectionReport(AbstractReport): | ||
queryset = Collection.objects.filter(version=HEAD) | ||
name = 'Collections' | ||
select_related = ['created_by', 'organization', 'user'] | ||
verbose_fields = [ | ||
'mnemonic', | ||
'name', | ||
'created_by.username', | ||
'created_at', | ||
'parent_resource_type', | ||
'parent_resource', | ||
'canonical_url', | ||
'custom_validation_schema' | ||
] | ||
VERBOSE_HEADERS = [ | ||
"ID", | ||
"Name", | ||
"Created By", | ||
"Created At", | ||
"Owner Type", | ||
"Owner", | ||
"Canonical URL", | ||
"Validation Schema" | ||
] | ||
|
||
|
||
class CollectionVersionReport(AbstractReport): | ||
queryset = Collection.objects.exclude(version=HEAD) | ||
name = 'Collection Versions' | ||
select_related = ['created_by', 'organization', 'user'] | ||
verbose_fields = [ | ||
'version', | ||
'mnemonic', | ||
'name', | ||
'created_by.username', | ||
'created_at', | ||
'parent_resource_type', | ||
'parent_resource', | ||
'custom_validation_schema' | ||
] | ||
VERBOSE_HEADERS = [ | ||
"Version", | ||
"ID", | ||
"Name", | ||
"Created By", | ||
"Created At", | ||
"Owner Type", | ||
"Owner", | ||
"Validation Schema" | ||
] | ||
|
||
|
||
class ExpansionReport(AbstractReport): | ||
queryset = Expansion.objects.filter() | ||
name = 'Expansions' | ||
verbose = False | ||
|
||
|
||
class ReferenceReport(AbstractReport): | ||
queryset = CollectionReference.objects.filter() | ||
name = 'References' | ||
grouped_label = "New References" | ||
verbose = False | ||
grouped = True | ||
GROUPED_HEADERS = ["Resource Type", "Static", "Dynamic", "Total"] | ||
|
||
@property | ||
def grouped_queryset(self): | ||
if not self.queryset.exists(): | ||
return [] | ||
concepts_queryset = self.queryset.filter(reference_type='concepts') | ||
mappings_queryset = self.queryset.filter(reference_type='mappings') | ||
total_concepts = concepts_queryset.count() | ||
total_mappings = mappings_queryset.count() | ||
static_criteria = CollectionReference.get_static_references_criteria() | ||
total_static_concepts = concepts_queryset.filter(static_criteria).count() | ||
total_static_mappings = mappings_queryset.filter(static_criteria).count() | ||
return [ | ||
[ | ||
'Concepts', | ||
total_static_concepts, | ||
total_concepts - total_static_concepts, | ||
total_concepts | ||
], | ||
[ | ||
'Mappings', | ||
total_static_mappings, | ||
total_mappings - total_static_mappings, | ||
total_mappings | ||
] | ||
] | ||
|
||
@staticmethod | ||
def to_grouped_stat_csv_row(obj): | ||
return [*obj] | ||
|
||
@property | ||
def retired(self): | ||
return 0 | ||
|
||
@property | ||
def active(self): | ||
return self.count |
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,16 @@ | ||
from django.db.models import F | ||
|
||
from core.reports.models import AbstractReport | ||
from core.concepts.models import Concept | ||
|
||
|
||
class ConceptReport(AbstractReport): | ||
queryset = Concept.objects.filter(id=F('versioned_object_id')) | ||
name = 'Concepts' | ||
verbose = False | ||
|
||
|
||
class ConceptVersionReport(AbstractReport): | ||
queryset = Concept.objects.exclude(id=F('versioned_object_id')).exclude(is_latest_version=True) | ||
name = 'Concept Versions' | ||
verbose = 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,38 @@ | ||
from django.db.models import F, Count | ||
|
||
from core.reports.models import AbstractReport | ||
from core.mappings.models import Mapping | ||
|
||
|
||
class MappingReport(AbstractReport): | ||
queryset = Mapping.objects.filter(id=F('versioned_object_id')) | ||
name = 'Mappings' | ||
grouped_label = "New Mappings Grouped by Target Source" | ||
verbose = False | ||
grouped = True | ||
GROUPED_HEADERS = ["Target Source ID", "Count"] | ||
|
||
@property | ||
def grouped_queryset(self): | ||
from core.sources.models import Source | ||
return Source.objects.values( | ||
'id', 'mnemonic' | ||
).filter( | ||
mappings_to__id=F('mappings_to__versioned_object_id'), | ||
mappings_to__created_at__gte=self.start_date, | ||
mappings_to__created_at__lte=self.end_date | ||
).annotate( | ||
count=Count('mappings_to__id') | ||
).order_by('-count').values_list( | ||
'mnemonic', 'count' | ||
) | ||
|
||
@staticmethod | ||
def to_grouped_stat_csv_row(obj): | ||
return [*obj] | ||
|
||
|
||
class MappingVersionReport(AbstractReport): | ||
queryset = Mapping.objects.exclude(id=F('versioned_object_id')).exclude(is_latest_version=True) | ||
name = 'Mapping Versions' | ||
verbose = 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,10 @@ | ||
from core.reports.models import AbstractReport | ||
from core.orgs.models import Organization | ||
|
||
|
||
class OrganizationReport(AbstractReport): | ||
queryset = Organization.objects.filter() | ||
name = 'Organizations' | ||
select_related = ['created_by'] | ||
verbose_fields = ['mnemonic', 'name', 'created_by.username', 'created_at'] | ||
VERBOSE_HEADERS = ["ID", "Name", "Created By", "Created At"] |
Oops, something went wrong.