forked from elastic/rally-eventdata-track
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_data_file.py
executable file
·43 lines (35 loc) · 1022 Bytes
/
generate_data_file.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
import sys
import getopt
import json
from eventdata.parameter_sources.randomevent import RandomEvent
raw_mode = False
documents_to_generate = 1000000
try:
options, remainder = getopt.getopt(
sys.argv[1:],
'c:r',
['count=',
'raw',
])
except getopt.GetoptError as err:
print('ERROR:', err)
sys.exit(1)
for opt, arg in options:
if opt in ('-c', '--count'):
if arg.isdigit():
documents_to_generate = int(arg)
if documents_to_generate < 1:
print("ERROR: -c/--count must be followed by a positive integer.")
sys.exit(0)
else:
print("ERROR: -c/--count must be followed by a positive integer.")
sys.exit(0)
elif opt in ('-r', '--raw'):
raw_mode = True
randomevent = RandomEvent({})
for k in range(documents_to_generate):
evt, idx, typ = randomevent.generate_event()
if raw_mode:
print(evt['message'])
else:
print(json.dumps(evt))