-
Notifications
You must be signed in to change notification settings - Fork 27
/
reports.py
148 lines (131 loc) · 4.18 KB
/
reports.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
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'
id = 'collections'
select_related = ['created_by', 'organization', 'user']
verbose_fields = [
'mnemonic',
'name',
'collection_type',
'public_access',
'created_by.username',
'created_at',
'parent_resource_type',
'parent_resource',
'canonical_url',
'custom_validation_schema'
]
VERBOSE_HEADERS = [
"ID",
"Name",
"Collection Type",
"Public Access",
"Created By",
"Created At",
"Owner Type",
"Owner",
"Canonical URL",
"Validation Schema"
]
@property
def retired(self):
return self.NA
class CollectionVersionReport(AbstractReport):
queryset = Collection.objects.exclude(version=HEAD)
name = 'Collection Versions'
id = 'collection_versions'
note = 'Excludes HEAD versions'
select_related = ['created_by']
verbose_fields = [
'version',
'versioned_object_url',
'created_by.username',
'created_at',
'released'
]
VERBOSE_HEADERS = [
"Version",
"Collection URL",
"Created By",
"Created At",
"Released"
]
@property
def retired(self):
return self.NA
class ExpansionReport(AbstractReport):
queryset = Expansion.objects.filter()
name = 'Expansions'
id = 'expansions'
verbose = False
@property
def retired(self):
return self.NA
class ReferenceReport(AbstractReport):
queryset = CollectionReference.objects.filter()
name = 'References'
id = 'references'
grouped_label = "New References"
verbose = False
grouped = True
GROUPED_HEADERS = [
"Reference Type",
"Static during Period",
"Dynamic during Period",
"Subtotal during Period",
"Total as of Report Date"
]
@property
def retired(self):
return self.NA
def get_cascaded_queryset(self):
return self.queryset.exclude(cascade__isnull=True).exclude(cascade__in=['', 'none', False])
def get_concepts_queryset(self):
return self.queryset.filter(reference_type='concepts').exclude(cascade__isnull=False)
def get_mappings_queryset(self):
return self.queryset.filter(reference_type='mappings').exclude(cascade__isnull=False)
@property
def grouped_queryset(self):
if not self.queryset.exists():
return []
concepts_queryset = self.get_concepts_queryset()
mappings_queryset = self.get_mappings_queryset()
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()
overall_report = self.get_overall_report_instance()
overall_concepts = overall_report.get_concepts_queryset()
overall_mappings = overall_report.get_mappings_queryset()
cascade_count = self.get_cascaded_queryset().count()
overall_cascade_count = overall_report.get_cascaded_queryset().count()
return [
[
'Concepts only',
total_static_concepts,
total_concepts - total_static_concepts,
total_concepts,
overall_concepts.count()
],
[
'Mappings only',
total_static_mappings,
total_mappings - total_static_mappings,
total_mappings,
overall_mappings.count()
],
[
'Cascade',
self.NA,
cascade_count,
cascade_count,
overall_cascade_count
],
]
@staticmethod
def to_grouped_stat_csv_row(obj):
return [*obj]