-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
62 lines (49 loc) · 1.75 KB
/
main.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
54
55
56
57
58
59
60
61
62
import csv
import os
import time
import traceback
from tqdm import trange
from simulations import SIMULATION_02, SIMULATION_01
from telegram_bot import telegram_bot_send_message
def main(n_sims):
telegram_bot_send_message(f"Starting Simulations!")
try:
for i in trange(n_sims):
t_start_sim_1 = time.time()
# Takes between 1 and 3 minutes to complete
SIMULATION_01(60, 180)
t_end_sim_1 = time.time()
t_start_sim_2 = time.time()
# Takes between 1 and 3 minutes to complete, beta dist
SIMULATION_02(60, 180)
t_end_sim_2 = time.time()
log_data(i, t_end_sim_1 - t_start_sim_1,
t_end_sim_2 - t_start_sim_2,
file="./results/results.csv")
if i % 10 == 0:
telegram_bot_send_message(
f"Completed iteration {i} of {n_sims}"
)
except:
traceback.print_exc()
telegram_bot_send_message(f"Error in Simulations!")
telegram_bot_send_message(f"TRACEBACK : {traceback.format_exc()}")
else:
telegram_bot_send_message(f"Completed Simulations!")
def log_data(i, sim1_time, sim2_time, file):
header = ["i", "sim1_time", "sim2_time", "delta"]
row = [i, sim1_time, sim2_time, sim1_time - sim2_time]
automkdir(file)
if os.path.exists(file):
header = False
with open(file, 'a', newline='') as logfile:
writer = csv.writer(logfile)
if header:
writer.writerow(header)
writer.writerow(row)
pass
def automkdir(filename):
"""Automatically makes the folders needed"""
os.makedirs(os.path.dirname(filename), exist_ok=True)
if __name__ == '__main__':
main(10)