def getMatchInLastSeasons(self, request, context): print("request: getMatchInLastSeasons") matchlist = match_pb2.MatchList() for game in DBController.getAllData(as_dataframe=False): _match = matchlist.list.add() _match.league = game.league _match.date = game.date.isoformat() _match.round = game.round _match.home_team_name = game.home_team_name _match.away_team_name = game.away_team_name _match.home_team_rank = game.home_team_rank _match.away_team_rank = game.away_team_rank _match.home_team_scored = game.home_team_scored _match.away_team_scored = game.away_team_scored _match.home_team_received = game.home_team_received _match.away_team_received = game.away_team_received _match.home_att = game.home_att _match.away_att = game.away_att _match.home_def = game.home_def _match.away_def = game.away_def _match.home_mid = game.home_mid _match.away_mid = game.away_mid _match.home_odds_n = game.home_odds_n _match.draw_odds_n = game.draw_odds_n _match.away_odds_n = game.away_odds_n _match.result = game.result _match.home_odds_nn = game.home_odds_nn _match.draw_odds_nn = game.draw_odds_nn _match.away_odds_nn = game.away_odds_nn break return matchlist
def predict(league): """ @param league: string that represent the league (can be 'all') @return: list of predictions DTOs """ predictions = [] #region Data all_data = DBController.getAllData(as_dataframe=True) upcoming_games = DBController.getUpcomingGames(league, as_dataframe=True) x, y = data_preprocessor.train_preprocess(all_data) to_predict = data_preprocessor.prediction_preprocess(upcoming_games) #endregion #region ANN for i in range(0, AVG): ann = NeuralNet(x.shape[1]) ann.train(x, y, EPOC) predictions.append(ann.predict(to_predict)) #endregion #region Calculate avg of predictions lines = predictions[0].shape[0] columns = predictions[0].shape[1] avgPrediction = np.zeros((lines, columns)) for line in range(lines): for cell in range(columns): sum = 0 for prediction in predictions: sum = sum + prediction[line, cell] avgPrediction[line, cell] = sum / AVG #endregion #region Converting avgPrediction to pandas DataFrame y_pred, indexes = apply_indexes(avgPrediction, upcoming_games) details = upcoming_games.iloc[indexes] details = details[[ 'league', 'date', 'home_team_name', 'away_team_name', 'home_odds_nn', 'draw_odds_nn', 'away_odds_nn' ]] final = pd.concat([details, y_pred], axis=1, sort=False) prediction_dtos = [] for row in final.shape[0]: prediction_dtos.append( Prediction( final.loc[row, 'leauge'], final.loc[row, 'date'], final.loc[row, 'home_team_name'], final.loc[row, 'away_team_name'], final.loc[row, 'home_odds_nn'], final.loc[row, 'draw_odds_nn'], final.loc[row, 'away_odds_nn'], final.loc[row, 'pred_1'], final.loc[row, 'pred_2'], final.loc[row, 'pred_x'], calc_exp(predictions=[ final.loc[row, 'pred_1'], final.loc[row, 'pred_x'], final.loc[row, 'pred_2'] ], odds=[ final.loc[row, 'home_odds_nn'], final.loc[row, 'draw_odds_nn'], final.loc[row, 'away_odds_nn'] ]), final.loc[row, 'result'])) return prediction_dtos