Exemplo n.º 1
0
        public void RunModel()
        {
            if (!InitialModelDataLoadComplete)
            {
                const string message = "LoadModelData() must be called before RunModel()";
                Logger.Error(message);
                throw new Exception(message);
            }

            // clear periodMarkets each time
            PeriodMarkets.Clear();
            string saveFile = GetSaveFullFileName();

            _analyticaNfl.IsTeamMode = IsTeamMode;
            Dictionary <int, List <Market> > result = _analyticaNfl.RunModel(ModelData, PeriodMarkets, Started, saveFile);


            //TODO move game total seconds to config
            //TODO move check to util method

            if (!ModelData.ContainsKey(NflModelDataKeys.Egt))
            {
                ModelData.Add(NflModelDataKeys.Egt, new Dictionary <string, double>());
                ModelData[NflModelDataKeys.Egt].Add("S", 3600);
            }

            if (!ModelData[NflModelDataKeys.Egt].ContainsKey("S"))
            {
                ModelData[NflModelDataKeys.Egt].Add("S", 3600);
            }

            _distributorNfl.SendMarkets(result, GameId, Description, ModelData[NflModelDataKeys.Egt]);
            ModelUpdateRequired = false;
        }
Exemplo n.º 2
0
        public static ModelData BsonToModelData(this BsonDocument bson)
        {
            var modelData = new ModelData();

            foreach (var bi in bson)
            {
                if (bi.Value.IsBsonArray)
                {
                    modelData.Add(bi.Name, bi.Value[0].ToString());
                }
                else
                {
                    modelData.Add(bi.Name, bi.Value.ToString());
                }
            }

            return(modelData);
        }
Exemplo n.º 3
0
        private async Task <List <ModelData> > GetSubDataList(string table, string query, Type dataType)
        {
            var resultData = new List <ModelData>();
            var result     = await SqlSugarClient.Queryable(table, table).Where(query).ToListAsync();

            var subProps = dataType.GetProperties();

            foreach (var item in result)
            {
                var modelData = new ModelData();
                foreach (var subprop in subProps)
                {
                    modelData.Add(subprop.Name, subprop.GetValue(subprop)?.ToString() ?? "");
                }
                resultData.Add(modelData);
            }
            return(resultData);
        }
Exemplo n.º 4
0
        public async Task <ModelData> ModelToData <T>(T model)
        {
            var modelType = typeof(T);

            var props = modelType.GetProperties();

            var modelData = new ModelData();

            foreach (var prop in props)
            {
                //if (prop.CustomAttributes.Any(x => x.AttributeType == typeof(ModelType)))
                //{
                //    object[] attrs = prop.GetCustomAttributes(true);
                //    List<ModelData> ModelDataList = null;
                //    foreach (object attr in attrs)
                //    {
                //        ModelType modelTypeAttr = attr as ModelType;
                //        if (modelTypeAttr != null)
                //        {
                //            string propName = prop.Name;
                //            string mtName = modelTypeAttr.Name;

                //            if (modelTypeAttr.ControlName == "dynamicgroup")
                //            {
                //                ModelDataList = await GetSubDataList(modelTypeAttr.DataSourceTable, modelTypeAttr.DataSourceQuery, prop.PropertyType.GenericTypeArguments[0]);
                //            }
                //        }
                //    }
                //    modelData.Add(prop.Name, ModelDataList);
                //}
                //else
                //{
                //    modelData.Add(prop.Name, prop.GetValue(model));
                //}
                modelData.Add(prop.Name, prop.GetValue(model));
            }

            return(modelData);
        }
Exemplo n.º 5
0
        public void RunModel()
        {
            if (!InitialModelDataLoadComplete)
            {
                const string message = "LoadModelData() must be called before RunModel()";
                Logger.Error(message);
                throw new Exception(message);
            }

            // clear periodMarkets each time
            PeriodMarkets.Clear();
            string saveFile = GetSaveFullFileName();

            _analyticaNcaabb.IsTeamMode = IsTeamMode;

            Stopwatch stopwatch = Stopwatch.StartNew();
            Dictionary <int, List <Market> > result = _analyticaNcaabb.RunModel(ModelData, PeriodMarkets, Started, saveFile);

            Logger.Info($"{GameId} ({Description}) RunModel() runtime = {stopwatch.Elapsed.Seconds,4} sec");

            stopwatch = Stopwatch.StartNew();
            if (!ModelData.ContainsKey(NcaabbModelDataKeys.Egt))
            {
                ModelData.Add(NcaabbModelDataKeys.Egt, new Dictionary <string, double>());
                ModelData[NcaabbModelDataKeys.Egt].Add("S", 2400);
            }

            if (!ModelData[NcaabbModelDataKeys.Egt].ContainsKey("S"))
            {
                ModelData[NcaabbModelDataKeys.Egt].Add("S", 2400);
            }

            _distributorNcaabb.SendMarkets(result, GameId, Description, ModelData[NcaabbModelDataKeys.Egt]);
            Logger.Info($"{GameId} ({Description}) SendMarkets() runtime = {stopwatch.Elapsed.Seconds,4} sec");

            ModelUpdateRequired = false;
        }
Exemplo n.º 6
0
        public void RunModel()
        {
            if (!InitialModelDataLoadComplete)
            {
                const string message = "LoadModelData() must be called before RunModel()";
                Logger.Error(message);
                throw new Exception(message);
            }

            // clear periodMarkets each time
            PeriodMarkets.Clear();
            string saveFile = GetSaveFullFileName();

            _analyticaNba.IsTeamMode = IsTeamMode;

            Stopwatch stopwatch = Stopwatch.StartNew();
            Dictionary <int, List <Market> > result = _analyticaNba.RunModel(ModelData, PeriodMarkets, Started, saveFile);

            Logger.Info($"{GameId} ({Description}) RunModel() runtime = {stopwatch.Elapsed.Seconds,4} sec");

            // todo this code does not belong here
            stopwatch = Stopwatch.StartNew();
            if (!ModelData.ContainsKey(NbaModelDataKeys.Egt))
            {
                ModelData.Add(NbaModelDataKeys.Egt, new Dictionary <string, double>());
                ModelData[NbaModelDataKeys.Egt].Add("S", GameTimeSeconds);
            }

            if (!ModelData[NbaModelDataKeys.Egt].ContainsKey("S"))
            {
                ModelData[NbaModelDataKeys.Egt].Add("S", GameTimeSeconds);
            }

            if (IsTeamMode)
            {
                _distributorNba.SendMarkets(result, GameId, Description, ModelData[NbaModelDataKeys.Egt]);
            }
            else
            {
                /*
                 * //format results
                 * //todo move to utils
                 * if (result.Count > 0)
                 * {
                 *  foreach (Market market in result[1])
                 *  {
                 *      string[] playerStr = market.Player.Split('_');
                 *      string side = playerStr[0];
                 *      int number = ToInt16(playerStr[1]);
                 *      switch (side)
                 *
                 * {
                 *                 case "away":
                 *              NbaPlayer playerA = AwayTeam.PlayerList.Find(x => x.Number == number);
                 *
                 *              if (market.MarketRunnerList[0].Price.IsNotEqualToZero() && market.MarketRunnerList[0].Price.IsNotEqualTo(1))
                 *              {
                 *                  if (playerA.Stats != null && market.Tp != null && !playerA.Stats.ContainsKey(market.Tp))
                 *                  {
                 *                      playerA.Stats.Add(market.Tp, new OddsAndStats());
                 *                      playerA.Side = side;
                 *                      playerA.comp_id = Convert.ToString(GameId);
                 *                      playerA.team = Convert.ToString(AwayTeam.TeamId);
                 *                      //playerA.player_id = Convert.ToString(playerA.PlayerId);
                 *                      playerA.player = playerA.FullName;
                 *                  }
                 *
                 *               playerA.Stats[market.Tp].odds.Add(market);
                 *              }
                 *
                 *              break;
                 *
                 *          case "home":
                 *              Player playerH = HomeTeam.PlayerList.Find(x => x.Number == number);
                 *
                 *              if (market.MarketRunnerList[0].Price.IsNotEqualToZero() && market.MarketRunnerList[0].Price.IsNotEqualTo(1))
                 *              {
                 *
                 *                  if (playerH.Stats != null && market.Tp != null && !playerH.Stats.ContainsKey(market.Tp))
                 *                  {
                 *                      playerH.Stats.Add(market.Tp, new OddsAndStats());
                 *                      playerH.Side = side;
                 *                      playerH.comp_id = Convert.ToString(GameId);
                 *                      //  playerH.player_id = Convert.ToString(playerH.PlayerId);
                 *                      playerH.team = Convert.ToString(HomeTeam.TeamId);
                 *                      playerH.player = playerH.FullName;
                 *                  }
                 *
                 *                  playerH.Stats[market.Tp].odds.Add(market);
                 *              }
                 *
                 *              break;
                 *      }
                 *  }
                 * }
                 *
                 * List<Player> playersMessages = new List<Player>();
                 * //add stats template to fill in missing elements
                 * List<string> types = new List<string>{ "P", "R", "A", "S", "B", "T", "F3M", "F3A", "F2M", "F2A", "FTM", "FTA" };
                 *
                 * foreach (Player player in HomeTeam.PlayerList)
                 * {
                 *  foreach (KeyValuePair<string, OddsAndStats> playerStatMarket in player.Stats)
                 *  {
                 *      playerStatMarket.Value.MainMarket =
                 *       playerStatMarket.Value.odds.OrderBy(v => v.Weight).First();
                 * }
                 *
                 *
                 *  //check for missing stats and fill them in
                 *  foreach (string type in types)
                 *  {
                 *     if (!player.Stats.ContainsKey(type))
                 *      {
                 *          //add new market
                 *          Market market = new Market
                 *          {
                 *              Tp = type,
                 *              Target = 0
                 *          };
                 *
                 *
                 *          market.MarketRunnerList.Add(new MarketRunner
                 *          {
                 *              Total = 0,
                 *              Price = 0,
                 *              Side = "U"
                 *          });
                 *
                 *          market.MarketRunnerList.Add(new MarketRunner
                 *          {
                 *              Total = 0,
                 *              Price = 0.0,
                 *              Side = "O"
                 *          });
                 *          OddsAndStats os = new OddsAndStats
                 *          {
                 *              MainMarket = market
                 *          };
                 *          player.Stats.Add(type, os);
                 *
                 *      }
                 *  }
                 *
                 *  if (player.comp_id != null && player.Stats.Count != 0)
                 *  {
                 *      playersMessages.Add(player);
                 *  }
                 * }
                 *
                 * foreach (Player player in AwayTeam.PlayerList)
                 * {
                 *  foreach (KeyValuePair<string, OddsAndStats> playerStatMarket in player.Stats)
                 *  {
                 *      playerStatMarket.Value.MainMarket =
                 *          playerStatMarket.Value.odds.OrderBy(v => v.Weight).First();
                 *  }
                 *
                 *
                 * //        //check for missing stats and fill them in
                 *  foreach (string type in types)
                 *  {
                 *      if (!player.Stats.ContainsKey(type))
                 *      {
                 *          //add new market
                 *          Market market = new Market
                 *          {
                 *              Tp = type,
                 *              Target = 0
                 *          };
                 *
                 *
                 *          market.MarketRunnerList.Add(new MarketRunner
                 *          {
                 *              Total = 0,
                 *              Price = 0,
                 *              Side = "U"
                 *          });
                 *
                 *          market.MarketRunnerList.Add(new MarketRunner
                 *          {
                 *              Total = 0,
                 *              Price = 0.0,
                 *              Side = "O"
                 *          });
                 *          OddsAndStats os = new OddsAndStats
                 *         {
                 *              MainMarket = market
                 *          };
                 *          player.Stats.Add(type, os);
                 *
                 *      }
                 *  }
                 *
                 *  if (player.comp_id != null && player.Stats.Count != 0)
                 *  {
                 *      playersMessages.Add(player);
                 *  }
                 * }
                 *
                 * Dictionary<string, List<Player>> playersMessage = new Dictionary<string, List<Player>>
                 * {
                 *  ["players"] = playersMessages
                 * };
                 * string messageStr = JsonConvert.SerializeObject(playersMessage);
                 * _distributorNba.SendPlayerMarkets(messageStr, GameId, Description);
                 */
            }

            Logger.Info($"{GameId} ({Description}) SendMarkets() runtime = {stopwatch.Elapsed.Seconds,4} sec");

            ModelUpdateRequired = false;
        }