Skip to content

Instantly share code, notes, and snippets.

@orf
Last active April 23, 2017 18:24
Show Gist options
  • Save orf/a63091f93154844bfd8d32a510945da3 to your computer and use it in GitHub Desktop.
Save orf/a63091f93154844bfd8d32a510945da3 to your computer and use it in GitHub Desktop.
x = open('test.csv', 'w')
stream_labels = list(Stream.objects.order_by('label').values_list('label', flat=True))
x.write('Timestamp,' + ','.join(stream_labels) + '\n')
for timestamp in Data.objects.values_list('timestamp', flat=True):
data_values = Data.objects.filter(timestamp=timestamp, stream__label__in=stream_labels).order_by('stream__label).values_list('data', flat=True)
x.write(str(timestamp) + ',' + ','.join(data_values) + '\n')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment