48 lines
1.1 KiB
Python
48 lines
1.1 KiB
Python
import json
|
|
import math
|
|
|
|
from sqlalchemy import text
|
|
|
|
|
|
def wind(session):
|
|
query2 = text('''
|
|
SELECT city_name, wind_speed
|
|
FROM tem_now_analyse
|
|
''')
|
|
data = session.execute(query2).fetchall()
|
|
|
|
color_map = {
|
|
0: "#065aab",
|
|
2: "#06c8ab",
|
|
1: "#0696ab",
|
|
3: "#0656bb",
|
|
4: "#9796cb",
|
|
}
|
|
|
|
info_map = {}
|
|
for row in data:
|
|
if math.ceil(row[1]) not in info_map:
|
|
info_map[math.ceil(row[1])] = []
|
|
info_map[math.ceil(row[1])].append([row[0], row[1]])
|
|
|
|
data1 = []
|
|
for k, v in info_map.items():
|
|
data1.append(
|
|
{
|
|
"value": len(v),
|
|
"name": f"{k} m/s",
|
|
"degree": [i[0] for i in v],
|
|
"detail": [i[1] for i in v],
|
|
"color": color_map.get(k, "#065aab"),
|
|
}
|
|
)
|
|
|
|
# Serialize the list of dictionaries to JSON
|
|
data = json.dumps(data1, ensure_ascii=False, indent=4)
|
|
|
|
# 将 JSON 数据写入 JavaScript 文件
|
|
with open('data.js', 'a', encoding='utf-8') as js_file:
|
|
js_file.write('const Chart33_Data = ')
|
|
js_file.write(data)
|
|
js_file.write("\n\n")
|