-
Notifications
You must be signed in to change notification settings - Fork 1
/
generate_customers.py
53 lines (46 loc) · 1.82 KB
/
generate_customers.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
43
44
45
46
47
48
49
50
51
52
53
"""
IDE: PyCharm
Project: buds-climatehack
Author: mosc5
Filename: generate_customers.py
Date: 13.11.2021
"""
import random
import datetime
import json
def generate_customers(amount: int, random_seed: int, input_file, output_file):
"""
Generates a JSON-file with customer names, start times, starting locations and destinations
:param amount: number of customers
:param random_seed: random seed for reproduction
:param input_file: filename as string, "input.json" is pulled from data directory
:param output_file: filename as string, "output.json" will get saved in data directory
"""
random.seed(random_seed)
customer_list = []
loc_list = []
with open('data/' + input_file) as f:
data = json.load(f)
for point in data:
loc_list.append(point['name'])
for counter in range(amount):
clock_time = datetime.time(hour=random.randrange(24), minute=random.randrange(60), second=random.randrange(60))
time = datetime.datetime.combine(datetime.date(2021, 11, 13), clock_time)
signal = time - datetime.timedelta(minutes=random.randrange(1, 61))
name = "customer" + str(counter)
start = random.choice(loc_list)
destination = random.choice(loc_list)
while start == destination:
destination = random.choice(loc_list)
customer_dict = {
'name': name,
'signal_time': str(signal),
'starting_time': str(time),
'starting_point': start,
'destination': destination
}
customer_list.append(customer_dict)
with open('data/' + output_file, "w+", encoding="utf8") as json_file:
json.dump(customer_list, json_file, indent=2, ensure_ascii=False)
if __name__ == '__main__':
generate_customers(5, 0, 'points.json', 'customers.json')