-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_simulator.py
78 lines (46 loc) · 1.48 KB
/
data_simulator.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import csv
import random
import time
import pyfiglet
import colored
import datetime
# print ("Today's date: = %s-%s-%s" % (e.day, e.month, e.year))
# print ("The time is now: = %s:%s:%s" % (e.hour, e.minute, e.second))
W = '\033[0m'
R = '\033[31m'
total_1 = 1000
total_2 = 1000
total_3 = 1000
spliter = "-------------------------------------------------------------------------"
def ban():
print(f"""{colored.stylize(pyfiglet.figlet_format("sensor data (live)"), colored.fg(28))}
{spliter}""" + W)
ban()
print(R + " "*5, "Date", " "*14, "Temp", " "*5, "Hum", " "*4, "Gas", " "*4 + W)
print('')
field_names = ["Date", "price", "humidity", "Gas"]
id = 0
with open("data.csv", 'w') as csv_file:
csv_writer = csv.DictWriter(csv_file, fieldnames=field_names)
csv_writer.writeheader()
while True:
e = datetime.datetime.now()
a = e.strftime("%H%M%S")
a = int(a)
id += 1
with open("data.csv", 'a') as csv_file:
csv_writer = csv.DictWriter(csv_file, fieldnames=field_names)
x_value = a
info = {
"Date": id,
"price": total_1,
"humidity": total_2,
"Gas": total_3
}
csv_writer.writerow(info)
print(x_value, " "*5, total_1, " "*5, total_2, " "*3, total_3)
# x_value += 1
total_1 = total_1 + random.randint(-6, 8)
total_2 = total_2 + random.randint(-5, 6)
total_3 = total_3 + random.randint(-4, 10)
time.sleep(1)