Esempio n. 1
0
        //Я понимаю, что весь код связанный с json нечитабелен, но json в
        //источнике минифицирован, поэтому я просто не знал, что делать
        public static void ParseLine(int ID = -1)
        {
            if (lastLNParseTime.AddSeconds(5) > DateTime.Now)
            {
                return;
            }

            Debug.Log("Проверяю страницу \"Линия\"");
            jsonFormats.ValueLN[] results;
            try
            {
                string url    = "https://1xstavka.ru/LineFeed/Get1x2_VZip?sports=8&count=50&mode=4&country=1&partner=51&getEmpty=true";
                string strRes = Utilites.GetHTML(url);

                JavaScriptSerializer serializer = new JavaScriptSerializer();
                var obj = serializer.Deserialize <jsonFormats.LineRootObj>(strRes);

                if (obj == null || obj.Value == null)
                {
                    return;
                }

                results = obj?.Value;
            }
            catch (Exception e)
            {
                Debug.LogException(e);
                return;
            }

            for (int i = 0; i < results.Length; i++)
            {
                jsonFormats.ValueLN result = results[i];
                int  id = result.N;
                Game game;

                result.E = RebuidE_array(result.E);
                if (result.E == null)
                {
                    continue;
                }

                bool containsGame;
                lock (Program.gamesLocker)
                {
                    containsGame = Program.games.ContainsKey(id);
                    game         = containsGame ? Program.games[id] : new Game();

                    game.league        = result.L;
                    game.startTimeUNIX = result.S;
                    game.updTimeUNIX   = Utilites.NowUNIX();

                    if (result.E.Length < 10)
                    {
                        continue;
                    }

                    game.totalF  = result.E[8].P;
                    game.TkfMore = result.E[8].C;
                    game.TkfLess = result.E[9].C;

                    game.teams[0].name = result.O1;
                    game.teams[1].name = result.O2;

                    game.teams[0].kf = result.E[0].C;
                    game.teams[1].kf = result.E[2].C;

                    Program.games[id] = game;
                }
                if (game.startTimeUNIX < Utilites.NowUNIX() + 301)
                {
                    if (game.teams[0].kf > 0 && game.teams[0].kf <= 1.6)
                    {
                        game.favTeam = 0;
                    }
                    else if (game.teams[1].kf > 0 && game.teams[1].kf <= 1.6)
                    {
                        game.favTeam = 1;
                    }

                    if (result.E.Length > 13 && game.favTeam > -1)
                    {
                        game.iTotalF = result.E[12 + game.favTeam].P;
                    }

                    //Алгоритм, который проверяет и удаляет игру в конце
                    if (!game.deleteFuncIsActivated)
                    {
                        Task task = new Task
                        {
                            GameID   = id,
                            TimeUNIX = game.startTimeUNIX + 3660, //61 min
                            Func     = Algorithms.CheckOnTheEnd
                        };
                        TasksMgr.AddTask(task);
                        game.deleteFuncIsActivated = true;
                    }/*
                      * if (!game.algoritms[0].actived)
                      * {
                      * Task task = new Task
                      * {
                      *     GameID = id,
                      *     TimeUNIX = game.startTimeUNIX + 600, //10 min
                      *     Func = Algorithms.FirstAlg
                      * };
                      * TasksMgr.AddTask(task);
                      * game.algoritms[0].actived = true;
                      * }*/
                    if (!game.algoritms[1].actived)
                    {
                        Task task = new Task
                        {
                            GameID   = id,
                            TimeUNIX = game.startTimeUNIX + 300, //5 min
                            Func     = Algorithms.SecondAlg
                        };
                        TasksMgr.AddTask(task);
                        game.algoritms[1].actived = true;
                    }/*
                      * if (!game.algoritms[2].actived && game.favTeam >= 0)
                      * {
                      * Task task = new Task
                      * {
                      *     GameID = id,
                      *     TimeUNIX = game.startTimeUNIX + 1800, //30 min
                      *     Func = Algorithms.ThirdAlg
                      * };
                      * TasksMgr.AddTask(task);
                      * game.algoritms[2].actived = true;
                      * }*/
                }
                else if (!containsGame)
                {
                    int  rand = (int)(new Random().NextDouble() * 150);
                    Task task = new Task
                    {
                        GameID   = id,
                        TimeUNIX = game.startTimeUNIX - 300 + rand,
                        Func     = ParseLine
                    };
                    TasksMgr.AddTask(task);
                }
            }
            //
            if (results != null && results.Length > 0)
            {
                lastLNParseTime = DateTime.Now;
            }
        }
Esempio n. 2
0
        public static void CheckOnTheEnd(int id)
        {
            Parser.ParseEndGameResults(id);

            lock (Program.gamesLocker)
            {
                Game game = Program.games[id];

                //if game wasn't finished
                if (!game.isFinished)
                {
                    TasksMgr.AddTask(new Task
                    {
                        TimeUNIX = Utilites.NowUNIX() + 30,
                        Func     = CheckOnTheEnd,
                        GameID   = id
                    });
                    return;
                }
                //смайлы в Telegram
                string yes = Encoding.UTF8.GetString(new byte[] { 0xE2, 0x9C, 0x85 });
                string not = Encoding.UTF8.GetString(new byte[] { 0xE2, 0x9D, 0x8E });

                string   text;
                double   goals;
                Algoritm algoritm;
                //First algoritm
                algoritm = game.algoritms[0];
                if (algoritm.sendedTotal > 0)
                {
                    text  = algoritm.messageText + " ";
                    goals = game.teams[0].allGoals + game.teams[1].allGoals;

                    if ((algoritm.tMore && goals > algoritm.sendedTotal) ||
                        (!algoritm.tMore && goals < algoritm.sendedTotal))
                    {
                        text += yes;
                    }
                    else
                    {
                        text += not;
                    }

                    text += " " + goals;

                    Debug.Log("Редактирую сообщения");

                    foreach (Message message in algoritm.messages)
                    {
                        Telegram.EditMessage(text, message.chatID, message.msgID);
                    }
                }

                //Second algoritm
                algoritm = game.algoritms[1];
                if (algoritm.sendedTotal > 0)
                {
                    text  = algoritm.messageText + " ";
                    goals = game.teams[0].goals1T + game.teams[1].goals1T;

                    if ((algoritm.tMore && goals > algoritm.sendedTotal) ||
                        (!algoritm.tMore && goals < algoritm.sendedTotal))
                    {
                        text += yes;
                    }
                    else
                    {
                        text += not;
                    }

                    text += " " + goals;

                    foreach (Message message in algoritm.messages)
                    {
                        Telegram.EditMessage(text, message.chatID, message.msgID);
                    }
                }

                //Third algoritm
                algoritm = game.algoritms[2];
                if (algoritm.sendedTotal > 0)
                {
                    text  = algoritm.messageText + " ";
                    goals = game.teams[game.favTeam - 1].goals1T;

                    if (goals > algoritm.sendedTotal)
                    {
                        text += yes;
                    }
                    else
                    {
                        text += not;
                    }

                    text += " " + goals;

                    foreach (Message message in algoritm.messages)
                    {
                        Telegram.EditMessage(text, message.chatID, message.msgID);
                    }
                }


                Program.games.Remove(id);
            }
        }
Esempio n. 3
0
        public static void SecondAlg(int id)
        {
            Parser.ParseLive();
            lock (Program.gamesLocker)
            {
                Game game = Program.games[id];

                if (game.gameTime > 1200) //20 min
                {
                    return;
                }

                bool ret = false;
                if (game.updTimeUNIX + 30 > Utilites.NowUNIX() && game.totalF * game.totalL > 0)
                {
                    string team1 = game.teams[0].name;
                    string team2 = game.teams[1].name;

                    Debug.Log("Проверка игры \"" + team1 + " - " + team2 + "\" на \"Тотал в 1 тайме\"");

                    if (game.teams[0].kf * game.teams[1].kf > 0)
                    {
                        team1 += " (" + game.teams[0].kf + ")";
                        team2 += " (" + game.teams[1].kf + ")";
                    }

                    double totalF     = Math.Round(game.totalF / 2);
                    double totalL     = Math.Round(game.totalL / 2);
                    double deltaTotal = totalL - totalF;
                    string recomend   = "";
                    if (deltaTotal >= 5)
                    {
                        recomend = "ТБ " + totalL + " - " + game.TkfLess;
                        Program.games[id].algoritms[1].sendedTotal = totalL;
                        Program.games[id].algoritms[1].tMore       = false;
                    }
                    else if (deltaTotal <= -4)
                    {
                        recomend = "ТМ " + totalL + " - " + game.TkfMore;
                        Program.games[id].algoritms[1].sendedTotal = totalL;
                        Program.games[id].algoritms[1].tMore       = true;
                    }

                    //Calculating rate
                    //
                    double rate = game.teams[0].goals1T + game.teams[1].goals1T;
                    //оставить 2 знака после запятой ииии 1800=30*60 из уравнения клиента
                    rate -= Math.Round(game.totalF * game.gameTime / 1800, 2);

                    string text = "#Signal_" + Params.LastSignalNumer
                                  + "\nАлгоритм - \"Тотал в 1 тайме\""
                                  + "\nЛига - \"" + game.league + "\""
                                  + "\nКоманда - \"" + team1 + " - " + team2 + "\""
                                  + "\nВремя - \"" + TimeSpan.FromSeconds(game.gameTime).ToString("mm\\:ss") + "\""
                                  + "\nСчёт - \"" + game.teams[0].goals1T + ":" + game.teams[1].goals1T + "\""
                                  + "\n"
                                  + "\nНачальный тотал -  \"" + totalF + "\""
                                  + "\n"
                                  + "\nТемп -  \"" + rate + "\""
                                  + "\nСейчас тотал -  \"" + totalL + "\""
                                  + "\nРазница тотала - \"" + deltaTotal + "\""
                                  + "\nРекомендую - \"" + recomend + "\"";

                    if (recomend.Length > 0)
                    {
                        ret = Telegram.SendMessagesFromAlgorithms(text, 2, id);
                    }
                }
                if (!ret)
                {
                    TasksMgr.AddTask(new Task
                    {
                        TimeUNIX = Utilites.NowUNIX() + 25,
                        Func     = SecondAlg,
                        GameID   = id
                    });
                }
                else //if signal was succesful sended to anybody
                {
                    Params.LastSignalNumer++;
                }
            }
        }
Esempio n. 4
0
        public static void ThirdAlg(int id)
        {
            Parser.ParseLive();
            lock (Program.gamesLocker)
            {
                Game game = Program.games[id];
                if (game.gameTime < 1800)
                {
                    TasksMgr.AddTask(new Task
                    {
                        TimeUNIX = Utilites.NowUNIX() + 1800 - game.gameTime,
                        Func     = ThirdAlg,
                        GameID   = id
                    });
                    return;
                }
                if (game.updTimeUNIX + 10 < Utilites.NowUNIX())
                {
                    TasksMgr.AddTask(new Task
                    {
                        TimeUNIX = Utilites.NowUNIX() + 5,
                        Func     = ThirdAlg,
                        GameID   = id
                    });
                    return;
                }

                if (game.gameTime > 1810 && game.favTeam > -1 && game.iTotalF * game.iTotalL > 0)
                {
                    string team1 = game.teams[0].name;
                    string team2 = game.teams[1].name;

                    Debug.Log("Проверка игры \"" + team1 + " - " + team2 + "\" на \"Индивидуальный тотал Фаворита\"");

                    if (game.teams[0].kf * game.teams[1].kf > 0)
                    {
                        team1 += " (" + game.teams[0].kf + ")";
                        team2 += " (" + game.teams[1].kf + ")";
                    }

                    double totalMF = Math.Round(game.iTotalF / 2);
                    double totalML = Math.Round(game.iTotalL / 2);

                    double favGoalsAim = totalMF - 4;
                    double realGoals   = game.teams[game.favTeam].goals1T;

                    double totalL = game.iTotalL;

                    string favTeam  = game.teams[game.favTeam].name;
                    string recomend = "ТБ " + game.iTotalL + " - " + game.iTkfLess;

                    Program.games[id].algoritms[2].sendedTotal = game.iTotalL;
                    Program.games[id].algoritms[2].tMore       = true;

                    string text = "#Signal_" + Params.LastSignalNumer
                                  + "\nАлгоритм - \"Индивидуальный тотал Фаворита\""
                                  + "\nЛига - \"" + game.league + "\""
                                  + "\nКоманда - \"" + team1 + " - " + team2 + "\""
                                  + "\nВремя - \"" + TimeSpan.FromSeconds(game.gameTime).ToString("mm\\:ss") + "\""
                                  + "\nСчёт - \"" + game.teams[0].goals1T + ":" + game.teams[1].goals1T + "\""
                                  + "\n"
                                  + "\nНачальный тотал -  \"" + totalMF + "\""
                                  + "\n"
                                  + "\nСейчас тотал -  \"" + totalML + "\""
                                  + "\nФаворит - \"" + favTeam + "\""
                                  + "\nРекомендую - \"" + recomend + "\"";
                    if (realGoals <= favGoalsAim && totalL < totalMF + realGoals)
                    {
                        if (Telegram.SendMessagesFromAlgorithms(text, 3, id))
                        {
                            Params.LastSignalNumer++;
                        }
                    }
                }
            }
        }