-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgenerate_test_data.py
56 lines (50 loc) · 1.72 KB
/
generate_test_data.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
import pymysql
import config
import time
import datetime
import random
connection = pymysql.connect(
host=config.MySql.host,
port=config.MySql.port,
user=config.MySql.user,
password=config.MySql.password,
db=config.MySql.db,
charset='utf8mb4',
cursorclass=pymysql.cursors.DictCursor
)
month = 1
day = 1
hour = 0
currentDateTime = datetime.datetime.now()
currentDate = currentDateTime.date()
currentYear = currentDate.strftime("%Y")
while month != 13:
while day != 31:
while hour != 24:
try:
cursor = connection.cursor()
mmonth = month
dday = day
hhour = hour
if len(str(month)) == 1: mmonth = "0" + str(month)
if len(str(day)) == 1: dday = "0" + str(day)
if len(str(hour)) == 1: hhour = "0" + str(hour)
final_date = f"{ currentYear }-{ mmonth }-{ dday } { hhour }:13:06"
final_date = datetime.datetime.strptime(final_date, "%Y-%m-%d %H:%M:%S")
cursor.execute("INSERT INTO `data` (`number`, `temperature`, `weight`, `humidity`, `measured`) VALUES (0, %s, %s, %s, '%s')" % (
round(random.uniform(20.0, 30.0), 2),
round(random.uniform(20.0, 30.0), 2),
round(random.uniform(40.0, 90.0), 2),
final_date))
connection.commit()
print("Generated data for ", final_date, ".")
hour += 1
except ValueError:
day = 1
hour = 0
month += 1
hour = 0
day += 1
day = 1
hour = 0
month += 1