2018-09-12 14:14:51 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
import json
|
|
|
|
import random
|
|
|
|
import sys
|
|
|
|
|
|
|
|
random.seed(0)
|
|
|
|
|
|
|
|
columns = [
|
2018-09-12 20:26:51 +00:00
|
|
|
('column0', lambda: 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX'),
|
|
|
|
('column1', lambda: random.choice([
|
|
|
|
'notification-interval-longer', 'notification-interval-short', 'control'])),
|
|
|
|
('column2', lambda: random.choice([True, False])),
|
|
|
|
('column3', lambda: random.randint(0, 4)),
|
|
|
|
('column4', lambda: random.randint(0, 4)),
|
|
|
|
('column5', lambda: random.randint(0, 4)),
|
|
|
|
('column6', lambda: random.randint(0, 4)),
|
|
|
|
('column7', lambda: random.randint(0, 4))
|
2018-09-12 14:14:51 +00:00
|
|
|
]
|
|
|
|
|
2018-09-12 20:26:51 +00:00
|
|
|
N_ROWS = 91746 # the output JSON size will be ~15 MB/10k rows
|
|
|
|
|
|
|
|
|
|
|
|
class StreamDict(dict):
|
|
|
|
"""
|
|
|
|
To serialize to JSON, we create an iterable object that inherits from a
|
|
|
|
known supported object type: dict.
|
|
|
|
"""
|
|
|
|
def __init__(self, generator):
|
|
|
|
self.generator = generator
|
|
|
|
|
|
|
|
def items(self):
|
|
|
|
for i in range(N_ROWS):
|
|
|
|
yield i, self.generator()
|
2018-09-12 14:14:51 +00:00
|
|
|
|
2018-09-12 20:26:51 +00:00
|
|
|
def __len__(self):
|
|
|
|
return 1
|
|
|
|
|
|
|
|
|
|
|
|
data = {}
|
2018-09-12 14:14:51 +00:00
|
|
|
for name, generator in columns:
|
2018-09-12 20:26:51 +00:00
|
|
|
data[name] = StreamDict(generator)
|
2018-09-12 14:14:51 +00:00
|
|
|
|
2018-09-12 20:26:51 +00:00
|
|
|
|
|
|
|
print("Content-Type: application/json")
|
|
|
|
print()
|
2018-09-12 14:14:51 +00:00
|
|
|
json.dump(data, sys.stdout)
|