Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implementing customized exports for PDK data types.
- Loading branch information
1 parent
1a73796
commit 011d026
Showing
5 changed files
with
99 additions
and
19 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 |
---|---|---|
@@ -1,6 +1,56 @@ | ||
import calendar | ||
import csv | ||
import json | ||
import tempfile | ||
|
||
from ..models import DataPoint, install_supports_jsonfield | ||
|
||
def extract_secondary_identifier(properties): | ||
if 'event_name' in properties: | ||
return properties['event_name'] | ||
|
||
return None | ||
|
||
def compile_report(generator, sources): | ||
filename = tempfile.gettempdir() + '/pdk_' + generator + '.txt' | ||
|
||
with open(filename, 'w') as outfile: | ||
writer = csv.writer(outfile, delimiter='\t') | ||
|
||
writer.writerow([ | ||
'Source', | ||
'Created Timestamp', | ||
'Created Date', | ||
'Event Name', | ||
'Event Properties' | ||
]) | ||
|
||
for source in sources: | ||
points = DataPoint.objects.filter(source=source, generator_identifier=generator).order_by('created') # pylint: disable=no-member,line-too-long | ||
|
||
index = 0 | ||
count = points.count() | ||
|
||
while index < count: | ||
for point in points[index:(index + 5000)]: | ||
row = [] | ||
|
||
row.append(point.source) | ||
row.append(calendar.timegm(point.created.utctimetuple())) | ||
row.append(point.created.isoformat()) | ||
|
||
properties = {} | ||
|
||
if install_supports_jsonfield(): | ||
properties = point.properties | ||
else: | ||
properties = json.loads(point.properties) | ||
|
||
row.append(properties['event_name']) | ||
row.append(json.dumps(properties['event_details'])) | ||
|
||
writer.writerow(row) | ||
|
||
index += 5000 | ||
|
||
return filename |
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