-
Notifications
You must be signed in to change notification settings - Fork 0
/
upload_example.py
76 lines (65 loc) · 1.99 KB
/
upload_example.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
import uuid
from datetime import datetime
import random
import requests
from loguru import logger
API_TX = "http://127.0.0.1:4000/bems/upload"
AMIS = ["Carlab_BEMS", "SGESC_C_BEMS", "SGESC_D_BEMS", "ABRI_BEMS"]
def generate_detail(field):
pv = float("%.3f" % random.uniform(-5, 5))
ess = float("%.3f" % random.uniform(-5, 5))
ev = float("%.3f" % random.uniform(-5, 5))
building = float("%.3f" % random.uniform(-1, 5))
grid = float("%.3f" % (pv + ess + ev + building + random.uniform(-1, 1)))
data_type = {
"bems_homepage_information": {
"id": str(uuid.uuid4()),
"field": field,
"grid": grid,
"pv": pv,
"building": building,
"ess": ess,
"ev": ev,
"updated_at": datetime.today().isoformat(),
},
"bems_ess_display": {
"id": str(uuid.uuid4()),
"field": field,
"cluster": 1,
"power_display": ess,
"updated_at": datetime.today().isoformat(),
},
"bems_ev_display": {
"id": str(uuid.uuid4()),
"field": field,
"cluster": 1,
"power": ev,
"updated_at": datetime.today().isoformat(),
},
"bems_pv_display": {
"id": str(uuid.uuid4()),
"field": field,
"cluster": 1,
"pac": pv,
"updated_at": datetime.today().isoformat(),
},
"bems_wt_display": {
"id": str(uuid.uuid4()),
"field": field,
"cluster": 1,
"wind_grid_power": float("%.3f" % random.uniform(-5, 5)),
"updated_at": datetime.today().isoformat(),
},
}
return data_type
def generate_data():
data = {}
for ami in AMIS:
data[ami] = generate_detail(ami)
return data
def main():
data = generate_data()
response = requests.post(API_TX, json=data)
logger.info(response.text)
if __name__ == "__main__":
main()