parent
							
								
									429b216306
								
							
						
					
					
						commit
						528e5d426a
					
				
				 4 changed files with 279 additions and 32 deletions
			
			
		@ -1,2 +1,100 @@ | 
				
			|||||||
from orm_db import * | 
					from db import * | 
				
			||||||
 | 
					import json | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def general_red_index(_real_red, _forecast_data): | 
				
			||||||
 | 
					    index_list = [] | 
				
			||||||
 | 
					    for _red in _forecast_data.keys(): | 
				
			||||||
 | 
					        if _red in _real_red: | 
				
			||||||
 | 
					            index_list.append(_forecast_data.keys().index(_red) + 1) | 
				
			||||||
 | 
					    index_group = [0, 0, 0] | 
				
			||||||
 | 
					    for index in index_group: | 
				
			||||||
 | 
					        if 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 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': real_red, | 
				
			||||||
 | 
					                'real_red_index_history': history_index_list, | 
				
			||||||
 | 
					                'real_red_index_group_history': history_index_group, | 
				
			||||||
 | 
					                'real_red_index_last': last_index_list, | 
				
			||||||
 | 
					                'real_red_index_group_last': last_index_group | 
				
			||||||
 | 
					            } | 
				
			||||||
 | 
					            db_red_update(_id, red_date_id, update_data) | 
				
			||||||
 | 
					            # 插入 IndexGroup index_group | 
				
			||||||
 | 
					            db_index_insert_index_group({'type': 'history', 'index_group': json.dumps(history_index_group)}) | 
				
			||||||
 | 
					            db_index_insert_index_group({'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: | 
				
			||||||
 | 
					            print(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'])) | 
				
			||||||
 | 
					            print(prv_index) | 
				
			||||||
 | 
					            print(post_index) | 
				
			||||||
 | 
					            print(history_index) | 
				
			||||||
 | 
					            update_data = { | 
				
			||||||
 | 
					                'real_blue': real_blue, | 
				
			||||||
 | 
					                'prv_index': prv_index, | 
				
			||||||
 | 
					                'post_index': post_index, | 
				
			||||||
 | 
					                'history_index': history_index | 
				
			||||||
 | 
					            } | 
				
			||||||
 | 
					            print(update_data) | 
				
			||||||
 | 
					            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(): | 
				
			||||||
 | 
					    pass | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if __name__ == "__main__": | 
				
			||||||
 | 
					    update_real_data() | 
				
			||||||
 | 
					    general_forecast_data() | 
				
			||||||
 | 
				
			|||||||
					Loading…
					
					
				
		Reference in new issue