def get_signal_history(): dthour = request.args.get('datetime') du = DateUtil() specific_hour_dt = du.parse_time_string(dthour) predictions = [] coins = generate_coins(specific_hour_dt) coininfo = CoinInfo() for coin in coins: earliest_date = dbconn.get_earliest_date_in_db(coin) print(coin.name, "earliest date", earliest_date) one_day_before = specific_hour_dt + timedelta(days=-1) coin.loadtime = one_day_before.strftime("%Y-%m-%d") print("checking pred in DB for ", coin, "at", specific_hour_dt) tsfrom = (specific_hour_dt + timedelta(hours=-1)).strftime("%Y-%m-%d %H:00:00") tsto = specific_hour_dt.strftime("%Y-%m-%d %H:00:00") print(tsfrom, tsto) pred = dbconn.check_prediction_in_db(coin, tsfrom, tsto) print("pred:", pred) if pred is None: coininfo.do_prepare(coin, specific_hour_dt) predictions = do_predict(coin, predictions, specific_hour_dt) else: predictions.append(pred) return jsonify({'predictions': predictions})
def update_signal_recalculate(): dthour = request.args.get('datetime') du = DateUtil() specific_hour_dt = du.parse_time_string(dthour) predictions = [] coins = generate_coins(specific_hour_dt) for coin in coins: earliest_date = dbconn.get_earliest_date_in_db(coin) print(coin.name, "earliest date", earliest_date) one_day_before = specific_hour_dt + timedelta(days=-1) coin.loadtime = one_day_before.strftime("%Y-%m-%d") print("checking pred in DB for ", coin, "at", specific_hour_dt) tsfrom = (specific_hour_dt + timedelta(hours=-1)).strftime("%Y-%m-%d %H:00:00") tsto = specific_hour_dt.strftime("%Y-%m-%d %H:00:00") print(tsfrom, tsto) do_prepare(coin, specific_hour_dt) predictions = do_predict(coin, predictions, specific_hour_dt) return jsonify({'predictions': predictions})
def fill_past_signals(): predictions = [] coins = generate_coins(datetime.now()) coininfo = CoinInfo() du = DateUtil() for coin in coins: earliest_date = dbconn.get_earliest_date_in_db(coin) print(coin.name, "earliest date", earliest_date) start_datetime = du.parse_time_string( du.round_datetime_down(earliest_date)) last_round_hour = du.parse_time_string(du.last_round_hour()) #adding 24 hours to have earlier data in the past for prediction curr_datetime = start_datetime + timedelta(hours=+24) while (curr_datetime < last_round_hour): coin.reset_data_frames() one_day_before = curr_datetime + timedelta(days=-1) coin.loadtime = one_day_before.strftime("%Y-%m-%d") curr_datetime = curr_datetime + timedelta(hours=+1) print("checking pred in DB for ", coin, "at", curr_datetime) tsfrom = (curr_datetime + timedelta(hours=-1)).strftime("%Y-%m-%d %H:00:00") tsto = curr_datetime.strftime("%Y-%m-%d %H:00:00") print(tsfrom, tsto) pred = dbconn.check_prediction_in_db(coin, tsfrom, tsto) print("pred:", pred) if pred is None: coininfo.do_prepare(coin, curr_datetime) predictions = do_predict(coin, predictions, curr_datetime) else: predictions.append(pred) return jsonify({'predictions': predictions})
def get_signal(): predictions = [] try: du = DateUtil() last_round_hour = du.parse_time_string(du.last_round_hour()) coins = generate_coins(last_round_hour) for coin in coins: pred = dbconn.check_prediction_in_db_last_hour(coin) if pred is None: do_prepare(coin, last_round_hour) predictions = do_predict(coin, predictions, last_round_hour) else: predictions.append(pred) return jsonify({'predictions': predictions}) except Exception as e: print("Exception: ", e) return jsonify({'exception': predictions})