static void Main(string[] args) { InitializeLog4net(); // Cargamos la configuracion Log.Info("Cargando configuracion"); Configuration configuration = JsonConvert.DeserializeObject <Configuration>(File.ReadAllText(@"./Configuration.json")); // Cargamos nombres de equipos Log.Info("Cargando nombres de equipos de 'TeamsNames.json'"); var jObject = JObject.Parse(File.ReadAllText(@"./TeamsNames.json")); var jToken = jObject.GetValue("TeamsNames"); Teams.TeamsNames = (Dictionary <string, List <string> >)jToken.ToObject(typeof(Dictionary <string, List <string> >)); Log.Info($"Se han cargado {Teams.TeamsNames.Values.Sum(x => x.Count) } nombres de equipos"); QuinEagleCalculator qc = new QuinEagleCalculator() { configuration = configuration }; qc.Configure(); // Cargamos los emparejamientos Log.Info("Cargando Emparejamientos"); FixtureRequester fr = new FixtureRequester() { QuinielaFixtureURL = configuration.QuinielaFixtureURL }; fr.LoadFixtures(); var fixtures = fr.GetFixtures(); fr.PrintFixtures(); List <Fixture> predictions = new List <Fixture>(); fixtures.ForEach(a => { QuinielaResult qr = QuinielaResult.VOID; Fixture f = new Fixture() { AwayTeam = a.AwayTeam, HomeTeam = a.HomeTeam }; f.Probability = qc.GetResult(a, out qr); f.Result = qr; predictions.Add(f); }); qc.SetMaxDoubleBets(ref predictions); predictions.ForEach(a => Log.Info(a.ToString())); Log.Info($"Media calculada = {predictions.Select( a => a.Probability ).Average()}%"); Console.ReadKey(); }
/// <param name="args"></param> public static void Main(string[] args) { // Log4Net InitializeLog4net(); // Cargamos la configuracion Log.Info("Cargando configuracion"); Configuration configuration = JsonConvert.DeserializeObject <Configuration>(File.ReadAllText(@"./Configuration.json")); // Cargamos nombres de equipos Log.Info("Cargando nombres de equipos de 'TeamsNames.json'"); var jObject = JObject.Parse(File.ReadAllText(@"./TeamsNames.json")); var jToken = jObject.GetValue("TeamsNames"); Teams.TeamsNames = (Dictionary <string, List <string> >)jToken.ToObject(typeof(Dictionary <string, List <string> >)); Log.Info($"Se han cargado {Teams.TeamsNames.Values.Sum(x => x.Count) } nombres de equipos"); QuinEagleCalculator qc = new QuinEagleCalculator() { configuration = configuration }; qc.Configure(); // Cargamos todos los partidos en una lista List <Match> matches = _getMatchesStoredDB(qc); // Seleccionamos todas las jornadas y años que tenemos partidos //List<JourneyDateClassification> journeys = matches.Select(a => new JourneyDateClassification(){ journey = a.Journey, season = a.season }) // .Distinct(new JourneyDateClassification.DistinctJourneyDateClassificationComparer()) // .ToList(); // Cogemos todas las clasificaciones y las almacenamos para estas jornadas de estos años //Dictionary<int, Dictionary<LeagueEnum, LeagueTable>> classifications = _getClassifications(journeys, configuration); List <Match> predictions = new List <Match>(); matches.ForEach(m => { Match match = m.Clone(); QuinielaResult qr = QuinielaResult.VOID; match.fixture.Probability = qc.GetResult(m.fixture, out qr); match.fixture.Result = qr; predictions.Add(match); }); /* * int aciertos = matches.Where(a => predictions.Any( * b => b.fixture.AwayTeam == a.fixture.AwayTeam && * b.fixture.HomeTeam == a.fixture.HomeTeam && * b.fixture.Journey == a.fixture.Journey && * (b.fixture.Result & a.fixture.Result) != QuinielaResult.VOID)).Count(); */ var aciertos = predictions.Where(a => matches.Any( b => b.fixture.AwayTeam == a.fixture.AwayTeam && b.fixture.HomeTeam == a.fixture.HomeTeam && b.fixture.Journey == a.fixture.Journey && (b.fixture.Result & a.fixture.Result) != QuinielaResult.VOID)).ToList(); Log.Info("TOTALES"); Log.Info(matches.Count); Log.Info($"1: {matches.Count( a => a.fixture.Result == QuinielaResult.ONE )} || {( float )matches.Count( a => a.fixture.Result == QuinielaResult.ONE ) / ( float )matches.Count * 100f } %"); Log.Info($"X: {matches.Count( a => a.fixture.Result == QuinielaResult.X )} || {( float )matches.Count( a => a.fixture.Result == QuinielaResult.X ) / ( float )matches.Count * 100f } %"); Log.Info($"2: {matches.Count( a => a.fixture.Result == QuinielaResult.TWO )} || {( float )matches.Count( a => a.fixture.Result == QuinielaResult.TWO ) / ( float )matches.Count * 100f } %"); Log.Info("---------------"); Log.Info("PREDICCIONES"); Log.Info($"1: {predictions.Count( a => a.fixture.Result == QuinielaResult.ONE )} || {( float )predictions.Count( a => a.fixture.Result == QuinielaResult.ONE ) / ( float )predictions.Count * 100f } %"); Log.Info($"X: {predictions.Count( a => a.fixture.Result == QuinielaResult.X )} || {( float )predictions.Count( a => a.fixture.Result == QuinielaResult.X ) / ( float )predictions.Count * 100f } %"); Log.Info($"2: {predictions.Count( a => a.fixture.Result == QuinielaResult.TWO )} || {( float )predictions.Count( a => a.fixture.Result == QuinielaResult.TWO ) / ( float )predictions.Count * 100f } %"); Log.Info("---------------"); Log.Info($"Aciertos {aciertos.Count} de {predictions.Count}"); Log.Info($"Total: {(float)aciertos.Count / (float)predictions.Count * 100f} %"); Log.Info("Aciertos por prediccion"); Log.Info($"1: {aciertos.Count( a => a.fixture.Result == QuinielaResult.ONE )} || {( float )aciertos.Count( a => a.fixture.Result == QuinielaResult.ONE ) / ( float )aciertos.Count * 100f } %"); Log.Info($"X: {aciertos.Count( a => a.fixture.Result == QuinielaResult.X )} || {( float )aciertos.Count( a => a.fixture.Result == QuinielaResult.X ) / ( float )aciertos.Count * 100f } %"); Log.Info($"2: {aciertos.Count( a => a.fixture.Result == QuinielaResult.TWO )} || {( float )aciertos.Count( a => a.fixture.Result == QuinielaResult.TWO ) / ( float )aciertos.Count * 100f } %"); Log.Info("---------------"); Log.Info("Aciertos por predicciones"); Log.Info($"1: {aciertos.Count( a => a.fixture.Result == QuinielaResult.ONE )} aciertos de {predictions.Count(a => (a.fixture.Result & QuinielaResult.ONE) != QuinielaResult.VOID)} predicciones || {( float )aciertos.Count( a => a.fixture.Result == QuinielaResult.ONE ) / ( float )predictions.Count( a => ( a.fixture.Result & QuinielaResult.ONE ) != QuinielaResult.VOID ) * 100f } %"); Log.Info($"X: {aciertos.Count( a => a.fixture.Result == QuinielaResult.X )} aciertos de {predictions.Count( a => ( a.fixture.Result & QuinielaResult.X ) != QuinielaResult.VOID )} predicciones || {( float )aciertos.Count( a => a.fixture.Result == QuinielaResult.X ) / ( float )predictions.Count( a => ( a.fixture.Result & QuinielaResult.X ) != QuinielaResult.VOID ) * 100f } %"); Log.Info($"2: {aciertos.Count( a => a.fixture.Result == QuinielaResult.TWO )} aciertos de {predictions.Count( a => ( a.fixture.Result & QuinielaResult.TWO ) != QuinielaResult.VOID )} predicciones || {( float )aciertos.Count( a => a.fixture.Result == QuinielaResult.TWO ) / ( float )predictions.Count( a => ( a.fixture.Result & QuinielaResult.TWO ) != QuinielaResult.VOID ) * 100f } %"); Log.Info("---------------"); Log.Info("Predicciones por resultado real"); Log.Info($"1: {predictions.Count( a => (a.fixture.Result & QuinielaResult.ONE) != QuinielaResult.VOID)} predicciones de {matches.Count( a => a.fixture.Result == QuinielaResult.ONE )} resultados reales || {( float )predictions.Count( a => a.fixture.Result == QuinielaResult.ONE ) / ( float )matches.Count( a => a.fixture.Result == QuinielaResult.ONE ) * 100f } %"); Log.Info($"X: {predictions.Count( a => ( a.fixture.Result & QuinielaResult.X ) != QuinielaResult.VOID )} predicciones de {matches.Count( a => a.fixture.Result == QuinielaResult.X )} resultados reales || {( float )predictions.Count( a => a.fixture.Result == QuinielaResult.X ) / ( float )matches.Count( a => a.fixture.Result == QuinielaResult.X ) * 100f } %"); Log.Info($"2: {predictions.Count( a => ( a.fixture.Result & QuinielaResult.TWO ) != QuinielaResult.VOID )} predicciones de {matches.Count( a => a.fixture.Result == QuinielaResult.TWO )} resultados reales || {( float )predictions.Count( a => a.fixture.Result == QuinielaResult.TWO ) / ( float )matches.Count( a => a.fixture.Result == QuinielaResult.TWO ) * 100f } %"); Log.Debug("---------------"); Log.Debug("Valores de 1s"); var Puntos1 = predictions.Where(a => matches.Any(b => b.fixture.AwayTeam == a.fixture.AwayTeam && b.fixture.HomeTeam == a.fixture.HomeTeam && b.fixture.Journey == a.fixture.Journey && b.fixture.Result == QuinielaResult.ONE)).ToList();; Puntos1.ForEach(a => Log.Debug(a.fixture.Probability)); Log.Debug("---------------"); Log.Debug("Valores de Xs"); var PuntosX = predictions.Where(a => matches.Any(b => b.fixture.AwayTeam == a.fixture.AwayTeam && b.fixture.HomeTeam == a.fixture.HomeTeam && b.fixture.Journey == a.fixture.Journey && b.fixture.Result == QuinielaResult.X)).ToList();; PuntosX.ForEach(a => Log.Debug(a.fixture.Probability)); Log.Debug("---------------"); Log.Debug("Valores de 2s"); var Puntos2 = predictions.Where(a => matches.Any(b => b.fixture.AwayTeam == a.fixture.AwayTeam && b.fixture.HomeTeam == a.fixture.HomeTeam && b.fixture.Journey == a.fixture.Journey && b.fixture.Result == QuinielaResult.TWO)).ToList();; Puntos2.ForEach(a => Log.Debug(a.fixture.Probability)); Console.ReadKey(); }
/// <summary> /// Carga todos los partidos de BBDD /// </summary> /// <returns>Lista de partidos almacenados</returns> private static List <Match> _getMatchesStoredDB(QuinEagleCalculator qc) { List <Match> matches = new List <Match>(); //SQLiteConnection conexion = new SQLiteConnection("Data Source=../../../db/quineagle.db;Version=3;New=True;Compress=True;"); SQLiteConnection conexion = new SQLiteConnection("../../../db/quineagle.db"); //conexion.Open(); conexion.BeginTransaction(); /* * string consulta = " select t.name, t2.name, m.result, j.number_journey, j.season " + * " from t_match m " + * "join t_team t " + * "on (m.id_hometeam = t.id_team) " + * "join t_team t2 " + * "on (m.id_awayteam = t2.id_team) " + * "join t_journey j " + * "on (j.id_journey = m.id_journey)"; */ string consulta = "select t.name as hometeam, t2.name as awayteam, m.result as result, j.number_journey as journey, j.season as season, j.first_div as first_div, j.second_div as second_div" + " from t_match m " + "join t_team t " + "on (m.id_hometeam = t.id_team) " + "join t_team t2 " + "on (m.id_awayteam = t2.id_team) " + "join t_journey j " + "on (j.id_journey = m.id_journey) where j.number_journey > 4"; //SQLiteCommand cmd = new SQLiteCommand(consulta, conexion); var data = conexion.ExecuteReader(consulta); //SQLiteDataReader data = cmd.ExecuteReader(); Log.Info($"Partidos encontrados a contrastar:"); Log.Info($"--------------------------------"); // Leemos los datos de forma repetitiva //while (data.Read()) foreach (var readerItem in data) { //Log.Info(string.Join(";", readerItem.Fields.Select(e => e + ":" + readerItem[e]))); Match m = new Match() { fixture = new Fixture() { HomeTeam = Convert.ToString(readerItem["hometeam"]), AwayTeam = Convert.ToString(readerItem["awayteam"]), Result = EnumUtility.GetEnumValueFromDescription <QuinielaResult>(Convert.ToString(readerItem["result"])) }, journey = new Journey() { first_div = Convert.ToInt32(readerItem["first_div"]), second_div = Convert.ToInt32(readerItem["second_div"]), id_journey = Convert.ToInt32(readerItem["id_journey"]), number_journey = Convert.ToInt32(readerItem["number_journey"]), season = Convert.ToInt32(readerItem["season"]) } }; // Ahora tenemos que averiguar si es de primera o de segunda if (qc.GetLeague(m.fixture.HomeTeam) == LeagueEnum.PRIMERA) { m.fixture.Journey = m.journey.first_div; } else { m.fixture.Journey = m.journey.second_div; } Log.Debug($"{m.fixture.HomeTeam} - {m.fixture.AwayTeam}: {EnumUtility.GetDescriptionFromEnumValue(m.fixture.Result)} (Temporada:{m.journey.season - 1}/{m.journey.season} Jornada:{m.fixture.Journey})"); matches.Add(m); } conexion.Close(); return(matches); }