红球的写的差不多了

main
roger_home_pc 1 year ago
parent f95623ec06
commit 429b216306
  1. 23
      orm/db.py
  2. 44
      orm/red_forecast.py

@ -73,21 +73,32 @@ def db_blue_insert(_data, _num):
print(e) print(e)
def db_red_index(_mode): def db_red_get_index():
try: try:
if _mode == 'last': index_stmt = select(RedForecastAll.real_red_index_group)
index_stmt = select(RedForecastAll.last_random_index_group)
else:
index_stmt = select(RedForecastAll.history_random_index_group)
index_result = db_session.execute(index_stmt).scalars() index_result = db_session.execute(index_stmt).scalars()
index_result_list = [] index_result_list = []
for index in index_result: for index in index_result:
index_result_list.append(json.loads(index)) if index is not None:
index_result_list.append(json.loads(index))
return index_result_list return index_result_list
except Exception as e: except Exception as e:
print(e) print(e)
def db_red_insert(_data):
try:
insert_stmt = insert(RedForecastAll).values(_data)
insert_result = db_session.execute(insert_stmt).rowcount
if insert_result > 0:
db_session.commit()
else:
db_session.rollback()
return insert_result
except Exception as e:
print(e)
def history_scalar(_scalar): def history_scalar(_scalar):
_data = dict() _data = dict()
_data['id'] = _scalar.id _data['id'] = _scalar.id

@ -64,6 +64,7 @@ def get_random_index():
random_low = random.randint(1, 6 - random_high) random_low = random.randint(1, 6 - random_high)
random_middle = 6 - random_high - random_low random_middle = 6 - random_high - random_low
print('分布区间(高概率区,中概率区,低概率区):', random_high, random_middle, random_low) print('分布区间(高概率区,中概率区,低概率区):', random_high, random_middle, random_low)
red_index_group = [int(random_high), int(random_middle), int(random_low)]
high_red_index_list = [(n[0] - 1) for n in new_num(1, 11, random_high)[0:random_high]] high_red_index_list = [(n[0] - 1) for n in new_num(1, 11, random_high)[0:random_high]]
middle_red_index_list = [(n[0] - 1) for n in new_num(12, 22, random_middle)[0:random_middle]] middle_red_index_list = [(n[0] - 1) for n in new_num(12, 22, random_middle)[0:random_middle]]
low_red_index_list = [(n[0] - 1) for n in new_num(23, 33, random_low)[0:random_low]] low_red_index_list = [(n[0] - 1) for n in new_num(23, 33, random_low)[0:random_low]]
@ -71,17 +72,19 @@ def get_random_index():
print(middle_red_index_list) print(middle_red_index_list)
print(low_red_index_list) print(low_red_index_list)
red_index_list = sorted(high_red_index_list + middle_red_index_list + low_red_index_list) red_index_list = sorted(high_red_index_list + middle_red_index_list + low_red_index_list)
red_index_list = [int(n) for n in red_index_list]
print(f"排序后结果") print(f"排序后结果")
print(red_index_list) print(red_index_list)
return red_index_list return red_index_group, red_index_list
def get_index_from_db(_mode): def get_index_from_db():
index_list = db_red_index(_mode) index_list = db_red_get_index()
print(index_list)
def get_forecast_red(_red_data): def get_forecast_red(_red_data):
index_list = get_random_index() index_group, index_list = get_random_index()
forecast_red_list = [] forecast_red_list = []
_red_data_list = list(_red_data.items()) _red_data_list = list(_red_data.items())
for i in index_list: for i in index_list:
@ -89,19 +92,42 @@ def get_forecast_red(_red_data):
forecast_red_list = sorted(forecast_red_list) forecast_red_list = sorted(forecast_red_list)
print('随机红球推荐:') print('随机红球推荐:')
print(forecast_red_list) print(forecast_red_list)
return forecast_red_list return {'forecast': forecast_red_list, 'group': index_group, 'index': index_list}
def get_forecast_red_by_db_index(_red_data, _mode='history'): def get_forecast_red_by_db_index(_red_data, _mode='history'):
pass pass
def insert_red_data(_all_data, _history, _history_random, _last, _last_random):
print(_history_random)
print(_last_random)
_insert_data = dict()
_insert_data['dateId'] = _all_data[-1]['dateId']
_insert_data['history'] = json.dumps(_history)
_insert_data['history_random'] = json.dumps(_history_random['forecast'])
_insert_data['history_random_index'] = json.dumps(_history_random['index'])
_insert_data['history_random_index_group'] = json.dumps(_history_random['group'])
_insert_data['last'] = json.dumps(_last)
_insert_data['last_random'] = json.dumps(_last_random['forecast'])
_insert_data['last_random_index'] = json.dumps(_last_random['index'])
_insert_data['last_random_index_group'] = json.dumps(_last_random['group'])
print(_insert_data)
result = db_red_insert(_insert_data)
if result > 0:
print(f"输入数据成功,插入{result}条数据")
else:
print("数据插入失败")
if __name__ == "__main__": if __name__ == "__main__":
all_data = get_all_data() all_data = get_all_data()
all_red_delta = get_all_red_delta(all_data) history_red_delta = get_all_red_delta(all_data)
# print(all_red_delta) # print(all_red_delta)
last_red_delta = get_last_red_delta(get_all_red_in_last(all_data)) last_red_delta = get_last_red_delta(get_all_red_in_last(all_data))
# print(last_red_delta) # print(last_red_delta)
print_data([all_red_delta, last_red_delta]) print_data([history_red_delta, last_red_delta])
forecast_red_history = get_forecast_red(all_red_delta) forecast_red_history_data = get_forecast_red(history_red_delta)
forecast_red_last = get_forecast_red(last_red_delta) forecast_red_last_data = get_forecast_red(last_red_delta)
insert_red_data(all_data, history_red_delta, forecast_red_history_data, last_red_delta, forecast_red_last_data)
get_index_from_db()

Loading…
Cancel
Save