-
Notifications
You must be signed in to change notification settings - Fork 27
/
reports.py
174 lines (154 loc) · 5.16 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
from django.db import models
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"
summary_label = "Summary of References"
verbose = False
grouped = True
GROUPED_HEADERS = [
"Reference Type",
"Static during Period",
"Dynamic during Period",
"Subtotal during Period",
"Total as of Report Date"
]
SUMMARY_HEADERS = [
"Created during Period -- with canonical URL",
"Created during Period -- no canonical URL",
"Subtotal Created during Period",
"Active as of Report Date -- with canonical URL",
"Active as of Report Date -- no canonical URL",
"Total as of Report Date"
]
def to_summary_row(self):
base_queryset = CollectionReference.objects.filter()
queryset = self.queryset
return [
queryset.filter(system__contains=':').count(),
queryset.exclude(system__contains=':').count(),
queryset.count(),
base_queryset.filter(system__contains=':').count(),
base_queryset.exclude(system__contains=':').count(),
base_queryset.count()
]
@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').filter(
models.Q(cascade__in=['', 'none', False]) | models.Q(cascade__isnull=True))
def get_mappings_queryset(self):
return self.queryset.filter(reference_type='mappings').filter(
models.Q(cascade__in=['', 'none', False]) | models.Q(cascade__isnull=True))
@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]