Skip to content

Commit 36c23bb

Browse files
committed
strip string values imported from C5 tables; force materialized views computation for manually imported batches
1 parent 9835e5e commit 36c23bb

4 files changed

Lines changed: 19 additions & 5 deletions

File tree

apps/logs/logic/custom_import.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from core.models import UL_ORG_ADMIN
1010
from logs.logic.data_import import import_counter_records
11+
from logs.logic.materialized_reports import sync_materialized_reports_for_import_batch
1112
from nigiri.counter5 import CounterRecord
1213
from logs.models import ImportBatch, ManualDataUpload, Metric, OrganizationPlatform
1314

@@ -163,6 +164,7 @@ def import_custom_data(mdu: ManualDataUpload, user) -> dict:
163164
OrganizationPlatform.objects.get_or_create(platform=mdu.platform, organization=mdu.organization)
164165
mdu.import_batch = import_batch
165166
mdu.mark_processed()
167+
sync_materialized_reports_for_import_batch(import_batch)
166168
# the following could be used to debug the speed of this code chunk
167169
# qs = connection.queries
168170
# qs.sort(key=lambda x: -float(x['time']))

apps/logs/logic/materialized_reports.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@ def sync_materialized_reports():
2222
create_materialized_accesslogs(mat_rt)
2323

2424

25+
def sync_materialized_reports_for_import_batch(ib: ImportBatch):
26+
"""
27+
Create AccessLogs for all materialized report types for one import batch
28+
"""
29+
for mat_rt in ReportType.objects.filter(
30+
materialization_spec__isnull=False, materialization_spec__base_report_type=ib.report_type
31+
):
32+
create_materialized_accesslogs_for_importbatches(mat_rt, [ib])
33+
34+
2535
def create_materialized_accesslogs(rt: ReportType, batch_size=None) -> int:
2636
"""
2737
Given an input materialized report type, it creates all the missing accesslogs. It detects

apps/nigiri/counter5.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,10 +238,10 @@ def _fd_to_records(self, infile) -> typing.Generator[CounterRecord, None, None]:
238238
header = {}
239239
reader = csv.reader(infile, dialect=dialect)
240240
for header_line in reader:
241-
if not header_line[0]:
241+
if not header_line[0].strip():
242242
# we break on empty line - it means end of header and start of data
243243
break
244-
header[header_line[0]] = header_line[1]
244+
header[header_line[0].strip()] = header_line[1].strip()
245245
report_type = header.get('Report_ID')
246246
if not report_type or report_type not in self.report_type_to_dimensions:
247247
raise ValueError(f'Unsupported report type: {report_type}')
@@ -258,13 +258,15 @@ def _fd_to_records(self, infile) -> typing.Generator[CounterRecord, None, None]:
258258
monthly_values = {}
259259
title_ids = {}
260260
for key, value in record.items():
261-
if not value.strip():
261+
key = key.strip()
262+
value = value.strip()
263+
if not value:
262264
continue
263265
month = parse_counter_month(key)
264266
if month:
265267
monthly_values[month] = int(value)
266268
else:
267-
if not key.strip() or key in self.ignored_columns:
269+
if not key or key in self.ignored_columns:
268270
pass
269271
elif key in self.column_map:
270272
implicit_dimensions[self.column_map[key]] = value

config/settings/devel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from .base import *
44

55
DATABASES['default']['NAME'] = 'celus'
6-
DATABASES['default']['PORT'] = 5434
6+
DATABASES['default']['PORT'] = 5432
77
ALLOWED_HOSTS = ['*']
88

99
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'

0 commit comments

Comments
 (0)