Ejemplo n.º 1
0
        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();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Guarda todos los partidos ya jugados de primera y segunda division
        /// </summary>
        /// <param name="j">Jornada a procesar</param>
        private static void _loadAndSaveJourneyResult(Journey j)
        {
            int journey = j.number_journey;
            int season  = j.season;

            // Cargamos toda la informacion de quinielista
            FixtureRequester fr = new FixtureRequester()
            {
                QuinielaFixtureURL = "https://www.quinielista.es/ayudas/module_help_other_upcoming.asp?num_jornada=" + journey + "&num_temporada=" + season
            };

            fr.LoadFixtures();
            List <Fixture> fixtures = fr.GetFixtures();

            // Cogemos solo los nombres de los equipos y nos quedamos con los partidos utiles (Primera y segunda division ya jugados)
            var teams       = Teams.TeamsNames.Select(x => x.Key);
            var utilMatches = fixtures.Where(a => a.Result != QuinielaResult.VOID && teams.Contains(a.HomeTeam) && teams.Contains(a.AwayTeam));

            try
            {
                // Abrimos la conexion
                SQLiteConnection conexion = new SQLiteConnection("../../../db/quineagle.db");
                conexion.BeginTransaction();

                // Construimos la query para insertar
                List <Journey> journeys = new List <Journey>();
                string         consulta = "INSERT INTO t_match (id_homeTeam,id_awayTeam,result,id_journey) VALUES ";
                foreach (var f in utilMatches)
                {
                    consulta += "( (SELECT id_team from t_team where name = '" + f.HomeTeam + "'), "
                                + "  (SELECT id_team from t_team where name = '" + f.AwayTeam + "'), "
                                + "'" + _parseResult(f.Result) + "',"
                                + "(SELECT id_journey from t_journey where number_journey = '" + j.number_journey + "' and season = '" + j.season + "')),";
                    Log.Debug($"Jornada {j.number_journey}: {f.HomeTeam} - {f.AwayTeam} : {f.Result}");
                }
                consulta = consulta.TrimEnd(',');

                // Si hay algun partido, lo insertamos
                if (utilMatches.Count() > 0)
                {
                    //SQLiteCommand cmd = new SQLiteCommand(consulta, conexion);
                    Log.Info($"{conexion.Execute(consulta)} rows inserted");
                    conexion.Commit();
                }

                // Cerramos la conexion
                conexion.Close();
            }catch (Exception e)
            {
                Log.Error($"ERROR: {e.Message}");
            }
        }