You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
115 lines
4.6 KiB
115 lines
4.6 KiB
from db import * |
|
from blue_forecast import forecast_blue |
|
from red_forecast import red_forecast |
|
import json |
|
|
|
|
|
def general_red_index(_real_red, _forecast_data): |
|
index_list = [] |
|
data_list = list(_forecast_data.keys()) |
|
for _red in data_list: |
|
if _red in _real_red: |
|
index_list.append(data_list.index(_red) + 1) |
|
index_group = [0, 0, 0] |
|
for index in index_list: |
|
if 1 <= index <= 11: |
|
index_group[0] += 1 |
|
elif 11 < index <= 22: |
|
index_group[1] += 1 |
|
elif 22 < index <= 33: |
|
index_group[2] += 1 |
|
else: |
|
print(f'索引值存在错误{index_list}') |
|
return index_list, index_group |
|
|
|
|
|
def general_blue_index(_real_blue, _forecast_data): |
|
return list(_forecast_data.keys()).index(_real_blue) + 1 |
|
|
|
|
|
def insert_index_group(_date_id, _type, _index_group): |
|
if _date_id not in db_index_get_last_date_id(_type): |
|
_data = { |
|
'dateId': _date_id, |
|
'type': _type, |
|
'index_group': _index_group |
|
} |
|
result = db_index_insert_index_group(_data) |
|
if result > 0: |
|
print(f'插入index_group成功 {_index_group}') |
|
else: |
|
print('插入index_group失败') |
|
|
|
|
|
def update_real_data(): |
|
new_history_date_id, old_history_date_id = db_history_get_last_open_id() |
|
blue_date_id = db_blue_get_last_one_open_id() |
|
red_date_id = db_red_get_last_one_open_id() |
|
all_data = db_history_get_all_data() |
|
# 如果 历史里面有新数据: 需要计算真实的index,然后预测新数据 |
|
# 如果 历史记录中是老数据: 需要预测新数据 |
|
if red_date_id == old_history_date_id: |
|
# 插入 RedForecastAll real_red, real_red_index, real_red_index_group |
|
real_red = json.loads(all_data[-1]['red']) |
|
forecast_red_data = db_red_get_data_by_date_id(red_date_id) |
|
for data in forecast_red_data: |
|
_id = data['id'] |
|
history_index_list, history_index_group = general_red_index(real_red, json.loads(data['history'])) |
|
last_index_list, last_index_group = general_red_index(real_red, json.loads(data['last'])) |
|
update_data = { |
|
'real_red': json.dumps(real_red), |
|
'real_red_index_history': json.dumps(history_index_list), |
|
'real_red_index_group_history': json.dumps(history_index_group), |
|
'real_red_index_last': json.dumps(last_index_list), |
|
'real_red_index_group_last': json.dumps(last_index_group) |
|
} |
|
db_red_update(_id, red_date_id, update_data) |
|
# 插入 IndexGroup index_group |
|
insert_index_group( |
|
{'dateId': red_date_id, 'type': 'history', 'index_group': json.dumps(history_index_group)}) |
|
insert_index_group({'dateId': red_date_id, 'type': 'last', 'index_group': json.dumps(last_index_group)}) |
|
|
|
if blue_date_id['five'] == old_history_date_id: |
|
# 插入 real_blue, prv_index, post_index, history_index |
|
real_blue = all_data[-1]['blue'] |
|
forecast_blue_data = db_blue_get_data_by_date_id(blue_date_id['five'], 5) |
|
for data in forecast_blue_data: |
|
_id = data['id'] |
|
prv_index = general_blue_index(real_blue, json.loads(data['prv'])) |
|
post_index = general_blue_index(real_blue, json.loads(data['post'])) |
|
history_index = general_blue_index(real_blue, json.loads(data['history'])) |
|
update_data = { |
|
'real_blue': real_blue, |
|
'prv_index': prv_index, |
|
'post_index': post_index, |
|
'history_index': history_index |
|
} |
|
db_blue_update(blue_date_id['five'], update_data, _id, 5) |
|
|
|
if blue_date_id['three'] == old_history_date_id: |
|
real_blue = all_data[-1]['blue'] |
|
forecast_blue_data = db_blue_get_data_by_date_id(blue_date_id['three'], 3) |
|
for data in forecast_blue_data: |
|
_id = data['id'] |
|
prv_index = general_blue_index(real_blue, json.loads(data['prv'])) |
|
post_index = general_blue_index(real_blue, json.loads(data['post'])) |
|
history_index = general_blue_index(real_blue, json.loads(data['history'])) |
|
update_data = { |
|
'real_blue': real_blue, |
|
'prv_index': prv_index, |
|
'post_index': post_index, |
|
'history_index': history_index |
|
} |
|
db_blue_update(blue_date_id['three'], update_data, _id, 3) |
|
|
|
|
|
# 插入预测数据 |
|
def general_forecast_data(): |
|
forecast_blue() |
|
red_forecast() |
|
|
|
|
|
if __name__ == "__main__": |
|
# update_real_data() |
|
# general_forecast_data() |
|
pass
|
|
|