public async Task <bool> BetItem(BetItem model) { var httpClient = new HttpClient(); baseUrl = "http://tradewithme.azurewebsites.net/api/Bet/CreateBet"; if (!string.IsNullOrEmpty(Settings.AuthLoginToken)) { httpClient.BaseAddress = new Uri(baseUrl); httpClient.DefaultRequestHeaders.Accept.Clear(); httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); // Add the Authorization header with the AccessToken. httpClient.DefaultRequestHeaders.Add("Authorization", "Bearer " + Settings.AuthLoginToken); try { var json = JsonConvert.SerializeObject(model); HttpContent httpContent = new StringContent(json); httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json"); var result = await httpClient.PostAsync(baseUrl, httpContent); return(true); } catch (Exception) { return(false); } } return(false); }
private void CustomListview_ItemTapped(object sender, ItemTappedEventArgs e) { string source = e.Item.GetType().Name; switch (source) { case "HomeItem": if (e.Item != null) { var vm = BindingContext as HomeViewModel; // ItemClickCommand?.Execute(e.Item); HomeItem homeItem = e.Item as HomeItem; vm.ShowExtraButtton(homeItem); SelectedItem = null; } break; case "TradeItem": if (e.Item != null) { var vm = BindingContext as MyTradeViewModel; // ItemClickCommand?.Execute(e.Item); TradeItem tradeItem = e.Item as TradeItem; vm.ShowExtraButtton(tradeItem); SelectedItem = null; } break; case "BetItem": if (e.Item != null) { try { var vm = BindingContext as NotifyInViewModel; // ItemClickCommand?.Execute(e.Item); BetItem betItem = e.Item as BetItem; vm.ShowExtraButtton(betItem); SelectedItem = null; } catch (Exception) { var vm = BindingContext as NotifyOutViewModel; // ItemClickCommand?.Execute(e.Item); BetItem betItem = e.Item as BetItem; vm.ShowExtraButtton(betItem); SelectedItem = null; } } break; } }
public override int Parse() { betItems.Clear(); //string fullName = "Yabo-NBA.json"; //System.IO.StreamReader sr1 = new StreamReader(fullName); //string nextLine = sr1.ReadToEnd(); JObject mObj = JObject.Parse(html); JToken eg = mObj["eg"]; JToken es = eg["es"]; JToken game = es[0]; JToken po = game["p-o"]; int index = 0; foreach (JToken baseJ in po)//遍历数组 { var n = baseJ["n"]; Config.WriteString("Items", string.Format("I{0}", index), n.ToString(), configFile); var itemIndex = GetBetItemIndex(n.ToString()); if (itemIndex < 0) { continue; } var playerIndex = GetPlayerIndex(n.ToString()); var itemName = effectItems[itemIndex]; for (int i = 0; i < effectItems.Count; i++) { if (itemName.ToString() == effectItems[i]) { JToken array = baseJ["o"]; foreach (JToken eI in array)//遍历数组 { BetItem b = new BetItem(); b.webID = webID; b.type = BetType.BT_SOLO; b.compare = GetBetCompare(eI[0].ToString()); b.pID1 = playerIndex; b.pName1 = playerNames[playerIndex]; b.handicap = GetBetHandicap(eI[0].ToString()); b.odds1 = GetBetOdds(eI[2].ToString()); b.itemID = itemIndex; betItems.Add(b); } } } index++; } return(betItems.Count); }
public List <BetItem> ParseOneGame(string data) { try { JObject mObj = JObject.Parse(data); int id = Convert.ToInt32(mObj["live"]); string name = mObj["name"].ToString(); var teams = name.Split('-'); int sex = Convert.ToInt32(mObj["ordNo"]); JToken mChild = mObj["children"]; int itemIndex = 0; betItems.Clear(); foreach (JToken baseJ in mChild)//遍历数组 { var live = baseJ["live"]; var itemName = baseJ["name"]; Config.WriteString("Items", string.Format("I{0}", itemIndex), itemName.ToString(), configFile); for (int i = 0; i < effectItems.Count; i++) { if (itemName.ToString() == effectItems[i]) { var effectItem = baseJ["children"]; foreach (JToken eI in effectItem)//遍历数组 { var playerNameToken = eI["name"]; BetItem b = new BetItem(); b.compare = GetBetCompare(playerNameToken.ToString()); b.pID1 = GetPlayerIndex(playerNameToken.ToString()); b.pName1 = playerNames[b.pID1]; b.handicap = GetBetHandicap(playerNameToken.ToString()); b.odds1 = Convert.ToDouble(eI["odds"]); b.itemID = i; betItems.Add(b); } } } itemIndex++; } return(betItems); } catch (Exception e) { MessageBox.Show(e.Message); } return(null); }
public void ShowResult(List <BetWinPair> pair) { if (list.InvokeRequired) { list.Invoke(new ShowResultHandler(ShowResult), pair); } else { ShowLog(string.Format("分析完毕,打水个数:{0}", pair.Count)); if (DynamicData.bFresh) { ClearList(); listPairs.Clear(); } listPairs.AddRange(pair); this.list.BeginUpdate(); //数据更新,UI暂时挂起,直到EndUpdate绘制控件,可以有效避免闪烁并大大提高加载速度 for (int i = 0; i < pair.Count; i++) //添加10行数据 { BetItem p1 = pair[i].b1; BetItem p2 = pair[i].b2; ListViewItem lvi = new ListViewItem(); lvi.Text = (index++).ToString(); lvi.SubItems.Add(StaticData.webNames[(int)p1.webID] + "|" + StaticData.webNames[(int)p2.webID]); lvi.SubItems.Add(p1.gameName); lvi.SubItems.Add(p1.leagueName1); lvi.SubItems.Add(p1.pName1 + "(" + p1.pAbbr1 + ")"); lvi.SubItems.Add(p1.pName2 + "(" + p1.pAbbr2 + ")"); lvi.SubItems.Add(p1.odds1.ToString() + "|" + p1.odds2.ToString()); lvi.SubItems.Add(p2.odds1.ToString() + "|" + p2.odds2.ToString()); lvi.SubItems.Add(p1.time.ToString()); lvi.SubItems.Add(DateTime.Now.ToString()); lvi.SubItems.Add(string.Format("{0}%", (pair[i].profit * 100).ToString("F2"))); this.list.Items.Add(lvi); } if (list.Items.Count > 0) { list.Items[list.Items.Count - 1].EnsureVisible(); } this.list.EndUpdate(); //结束数据处理,UI界面一次性绘制。 } }
private async Task ExecuteBetCommand() { bool isBetSucess = false; if (IsBusy) { return; } IsBusy = true; betCommand.ChangeCanExecute(); try { var data = new BetItem { Newprice = this.Price, itemref = this.ItemRef }; isBetSucess = await itrade.BetItem(data); } catch (Exception ex) { isBetSucess = false; } finally { IsBusy = false; betCommand.ChangeCanExecute(); } if (isBetSucess) { await Application.Current.MainPage.DisplayAlert("Feedback", "You Have successufuly bet", "Ok"); await Application.Current.MainPage.Navigation.PushModalAsync(new TradeMainPage()); } else { await Application.Current.MainPage.DisplayAlert("Bet Error", "Bet Error! please try Again", "Ok"); } }
public async Task <bool> SaveBetAsync(string roomId, BetItem bet) { var room = LoadRoomById(roomId); var user = LoadUserById(bet.UserId); if (room == null || user == null || room.Status != Status.Full) { return(false); } if (bet.Amount < user.Points) { var bets = room.Bets.ToList(); bets.Add(bet); room.Bets = bets.ToArray(); user.Points = user.Points - (bet.Amount ?? 0); var firebase = new FirebaseClient(fbPath, new FirebaseOptions() { AuthTokenAsyncFactory = () => Task.FromResult(token) }); await firebase .Child(rootUser) .Child(user.Name) .PutAsync(user); await firebase .Child(rootRoom) .Child(room.Name) .PutAsync(room); return(true); } return(false); }
private void Test() { List <BetItem> total = new List <BetItem>(); BetItem b1 = new BetItem(); b1.webID = WebID.WID_188; b1.sportID = SportID.SID_ESPORT; b1.type = BetType.BT_TEAM; b1.gameName = "SB联赛"; b1.pID1 = 3; b1.pID2 = 5; b1.pName1 = "SB战队"; b1.pName1 = "NB战队"; b1.odds1 = 2.2; b1.odds2 = 1.95; b1.handicap = 0; BetItem b2 = new BetItem(); b2.webID = WebID.WID_IM; b2.sportID = SportID.SID_ESPORT; b2.type = BetType.BT_TEAM; b2.gameName = "SB联赛"; b2.pID1 = 3; b2.pID2 = 5; b2.pName1 = "SB战队"; b2.pName2 = "NB战队"; b2.odds1 = 2.1; b2.odds2 = 2; b2.handicap = 0; total.Add(b1); total.Add(b2); var pair = BaseParser.ParseBetWin(total); ShowResult(pair); }
protected void CollectOneMatch(string matchIndex) { Uri uri = new Uri(baseuri, string.Format("Matches/{0}/Betting", matchIndex)); WebRequest getRequest = WebRequest.Create(uri); string matchAlias = gameType.ToString() + "-" + matchIndex; AveragedNonWeightedBetItemManager mgr = new AveragedNonWeightedBetItemManager(); Guid matchGuid = Guid.NewGuid(); string team1 = "", team2 = "", dateStr = ""; WebResponse response = GBCommon.GetResponseWithRetries(getRequest, GBCommon.DefaultRetries); using (Stream stream = response.GetResponseStream()) { using (StreamReader reader = new StreamReader(stream)) { HtmlDocument doc = new HtmlDocument(); doc.Load(reader); if (null == doc.DocumentNode) { throw new WebException(matchAlias + ": Error when parsing the root node"); } HtmlNode bodyNode = doc.DocumentNode.SelectSingleNode("//body"); if (null == bodyNode) { throw new WebException(matchAlias + ": Error when parsing the body node"); } var scripts = bodyNode.SelectNodes("//script[@type='text/javascript']"); string pattern = @"matchHeader.load.*\d+,\d+,\'([A-Za-z0-9\. ]+)\',\'([A-Za-z0-9\. ]+)\',\'([0-9:/ ]+)\'"; foreach (var script in scripts) { Match match = Regex.Match(script.InnerText, pattern); if (match.Success) { team1 = match.Groups[1].Value.Replace(' ', '_'); team2 = match.Groups[2].Value.Replace(' ', '_'); dateStr = match.Groups[3].Value; } } if (string.IsNullOrEmpty(dateStr) || string.IsNullOrEmpty(team1) || string.IsNullOrEmpty(team2)) { throw new ApplicationException(matchAlias + ": No match time or team name is found"); } var bookMakerNameNodes = bodyNode.SelectNodes("//div[@id='ThreeWay-OrdinaryTime']//a[@class='bm-name']"); if (null == bookMakerNameNodes) { throw new ApplicationException(matchAlias + ": No target odds found"); } foreach (var bookMakerNameNode in bookMakerNameNodes) { var node = bookMakerNameNode.ParentNode.ParentNode; string bookMaker = node.ChildNodes[1].SelectSingleNode(".//a[@class='bm-name']").InnerText; string win = node.ChildNodes[3].SelectSingleNode(".//a/span").InnerText.Trim(); string draw = node.ChildNodes[5].SelectSingleNode(".//a/span").InnerText.Trim(); string lose = node.ChildNodes[7].SelectSingleNode(".//a/span").InnerText.Trim(); BetItem bet = new BetItem( matchGuid.ToString(), matchIndex, gameType, new System.Collections.Generic.List <Team>() { new Team(team1, teamType), new Team(team2, teamType) }, new ThreeWayOdds(Convert.ToDouble(win), Convert.ToDouble(lose), Convert.ToDouble(draw)), false, DateTime.UtcNow, Convert.ToDateTime(dateStr), bookMaker ); mgr.CurrentBets.Add(bet); } string fileName = GBCommon.ConstructRecordFileName(gameType, team1, team2, dateStr); if (File.Exists(fileName)) { File.Delete(fileName); } GBCommon.LogInfo("{0}: Collected {1}", DateTime.Now, fileName); mgr.Serialize(fileName); } } }
public override int Parse() { if (string.IsNullOrEmpty(html)) { return(0); } JObject main = JObject.Parse(html); JToken data = main["data"]; JToken today = main["today"]; foreach (var record in today) { try { string title = record[37].ToString(); string gameName = GetGameID(title); int gameIndex = GetGameIndex(gameName); string team1_name = record[38].ToString(); string team2_name = record[39].ToString(); if (gameIndex == INVALID_INDEX) { continue; } if (team1_name.Contains('(') && team2_name.Contains(')')) { continue; } string gameLeague = GetGameLeague(title); int team1_index = GetTeamIndex(gameIndex, team1_name); int team2_index = GetTeamIndex(gameIndex, team2_name); double odds1 = Convert.ToDouble(record[17].ToString()); double odds2 = Convert.ToDouble(record[18].ToString()); if (odds1 < 0 || odds2 < 0) { continue; } //时间 var monthDay = record[56]; string date = null; string strTime = null; DateTime gameTime; if (monthDay != null) { var strMonthDay = monthDay.ToString().Split('/'); var month = strMonthDay[0].Trim(); var day = strMonthDay[1].Trim(); date = DateTime.Now.Year + "-" + month + "-" + day; } var time = record[53]; if (time != null) { strTime = time.ToString() + ":00"; } string dateTime = date + " " + strTime; gameTime = Convert.ToDateTime(dateTime); //bo // listRecords.Add(record.ToString()); //} //foreach(var match in matches) //{ BetItem b = new BetItem(); b.webID = webID; b.sportID = sportID; b.type = BetType.BT_TEAM; b.pID1 = team1_index; b.pID2 = team2_index; b.pName1 = team1_name; b.pName2 = team2_name; b.pAbbr1 = team1_name; b.pAbbr2 = team2_name; b.odds1 = odds1; b.odds2 = odds2; b.gameID = gameIndex; b.gameName = gameStaticNames[gameIndex]; b.leagueName1 = gameLeague; b.leagueName2 = gameLeague; b.bo = 1; b.time = gameTime; betItems.Add(b); if (betItems.Count == 37) { int a = 0; } } catch (Exception e) { DebugLog error = new DebugLog(); error.webID = webID; error.level = ErrorLevel.EL_WARNING; error.message = betItems.Count + ":" + e.Message; ShowLog(error); } } foreach (var record in data) { try { string title = record[37].ToString(); string gameName = GetGameID(title); int gameIndex = GetGameIndex(gameName); string team1_name = record[38].ToString(); string team2_name = record[39].ToString(); if (gameIndex == INVALID_INDEX) { continue; } if (team1_name.Contains('(') && team2_name.Contains(')')) { continue; } string gameLeague = GetGameLeague(title); int team1_index = GetTeamIndex(gameIndex, team1_name); int team2_index = GetTeamIndex(gameIndex, team2_name); double odds1 = Convert.ToDouble(record[17].ToString()); double odds2 = Convert.ToDouble(record[18].ToString()); if (odds1 < 0 || odds2 < 0) { continue; } //时间 var monthDay = record[56]; string date = null; string strTime = null; DateTime gameTime; if (monthDay != null) { var strMonthDay = monthDay.ToString().Split('/'); var month = strMonthDay[0].Trim(); var day = strMonthDay[1].Trim(); date = DateTime.Now.Year + "-" + month + "-" + day; } var time = record[53]; if (time != null) { strTime = time.ToString() + ":00"; } string dateTime = date + " " + strTime; gameTime = Convert.ToDateTime(dateTime); //bo // listRecords.Add(record.ToString()); //} //foreach(var match in matches) //{ BetItem b = new BetItem(); b.webID = webID; b.sportID = sportID; b.type = BetType.BT_TEAM; b.pID1 = team1_index; b.pID2 = team2_index; b.pName1 = team1_name; b.pName2 = team2_name; b.pAbbr1 = team1_name; b.pAbbr2 = team2_name; b.odds1 = odds1; b.odds2 = odds2; b.gameID = gameIndex; b.gameName = gameStaticNames[gameIndex]; b.leagueName1 = gameLeague; b.leagueName2 = gameLeague; b.bo = 1; b.time = gameTime; betItems.Add(b); if (betItems.Count == 37) { int a = 0; } } catch (Exception e) { DebugLog error = new DebugLog(); error.webID = webID; error.level = ErrorLevel.EL_WARNING; error.message = betItems.Count + ":" + e.Message; ShowLog(error); } } return(betItems.Count); }
public override int Parse() { if (string.IsNullOrEmpty(html)) { return(0); } JObject main = JObject.Parse(html); JArray array = JArray.Parse(main["Value"].ToString()); foreach (var record in array) { try { var gameId = record["SSI"].ToString(); var league = record["L"].ToString(); var gameIndex = GetGameIndex(gameId); if (gameIndex == INVALID_INDEX) { continue; } var bo = 1; var timeStamp = Convert.ToInt64(record["S"]); var gameTime = new DateTime(1970, 1, 1, 8, 0, 0).AddSeconds(timeStamp); var oddsMarket = JArray.Parse(record["E"].ToString()); if (oddsMarket.Count != 2) { continue; } var team1_abbr = record["O1E"].ToString().Trim(); var team2_abbr = record["O2E"].ToString().Trim(); var team1_name = record["O1E"].ToString().Trim(); var team2_name = record["O2E"].ToString().Trim(); var team1_index = GetTeamIndex(gameIndex, team1_name); var team2_index = GetTeamIndex(gameIndex, team2_name); var odd1 = Convert.ToDouble(oddsMarket[0]["C"]); var odd2 = Convert.ToDouble(oddsMarket[1]["C"]); var betLimit1 = 0; var betLimit2 = 0; BetItem b = new BetItem(); b.webID = webID; b.sportID = sportID; b.type = BetType.BT_TEAM; b.pID1 = team1_index; b.pID2 = team2_index; b.pName1 = team1_name; b.pName2 = team2_name; b.pAbbr1 = team1_abbr; b.pAbbr2 = team2_abbr; b.odds1 = odd1; b.odds2 = odd2; b.gameID = gameIndex; b.gameName = gameStaticNames[gameIndex]; b.leagueName1 = league; b.leagueName2 = league; b.handicap = 0; b.time = gameTime; b.bo = bo; b.betLimit1 = (int)betLimit1; b.betLimit2 = (int)betLimit2; betItems.Add(b); } catch (Exception e) { DebugLog error = new DebugLog(); error.webID = webID; error.level = ErrorLevel.EL_WARNING; error.message = e.Message; ShowLog(error); } } return(betItems.Count); }
public override int Parse() { if (string.IsNullOrEmpty(html)) { return(0); } JObject main = JObject.Parse(html); JToken n_ot = main["n-ot"]; if (n_ot == null) { return(0); } if (n_ot["egs"] == null) { return(0); } JArray egs = JArray.Parse(n_ot["egs"].ToString()); foreach (var eg in egs) { try { var c = eg["c"]; var n = c["n"]; var leagueName = GetLeague1Name(n.ToString()); var gameName = GetGameID(n.ToString()); if (gameName == INVALID_VALUE) { continue; } var bo = GetBO(n.ToString()); var gameIndex = GetGameIndex(gameName); var es = JArray.Parse(eg["es"].ToString()); foreach (var esSingle in es) { var i = esSingle["i"]; var team1_name = i[0].ToString().Trim(); var team2_name = i[1].ToString().Trim(); var team1_index = GetTeamIndex(gameIndex, team1_name); var team2_index = GetTeamIndex(gameIndex, team2_name); var monthDay = i[4]; string date = null; string strTime = null; DateTime gameTime; if (monthDay != null) { var strMonthDay = monthDay.ToString().Split('/'); var month = strMonthDay[1].Trim(); var day = strMonthDay[0].Trim(); date = DateTime.Now.Year + "-" + month + "-" + day; } var time = i[5]; if (time != null) { strTime = i[5].ToString() + ":00"; } string dateTime = date + " " + strTime; gameTime = Convert.ToDateTime(dateTime); var o = esSingle["o"]; var ml = o["ml"]; var ah = o["ah"]; //胜负盘 if (ml != null) { var odds1 = Convert.ToDouble(ml[1]); var odds2 = Convert.ToDouble(ml[3]); BetItem b = new BetItem(); b.sportID = sportID; b.webID = webID; b.type = BetType.BT_TEAM; b.pID1 = team1_index; b.pID2 = team2_index; b.pName1 = team1_name; b.pName2 = team2_name; b.pAbbr1 = team1_name; b.pAbbr2 = team2_name; b.odds1 = odds1; b.odds2 = odds2; b.gameID = gameIndex; b.handicap = 0; b.gameName = gameStaticNames[gameIndex]; b.leagueName1 = leagueName; b.time = gameTime; b.bo = bo; betItems.Add(b); } //让分盘 if (ah != null) { JArray array = JArray.Parse(ah.ToString()); int ahNum = array.Count / 8; for (int k = 0; k < ahNum; k++) { var odds1 = Convert.ToDouble(ah[k * 8 + 5]); var odds2 = Convert.ToDouble(ah[k * 8 + 7]); BetItem b = new BetItem(); b.sportID = sportID; b.webID = webID; b.type = BetType.BT_TEAM; b.pID1 = team1_index; b.pID2 = team2_index; b.pName1 = team1_name; b.pName2 = team2_name; b.pAbbr1 = team1_name; b.pAbbr2 = team2_name; b.odds1 = odds1; b.odds2 = odds2; b.gameID = gameIndex; b.handicap = Convert.ToDouble(ah[k * 8 + 1]); b.gameName = gameStaticNames[gameIndex]; b.leagueName1 = leagueName; b.time = gameTime; b.bo = bo; betItems.Add(b); } } if (betItems.Count == 25) { int a = 1; } } } catch (Exception e) { DebugLog error = new DebugLog(); error.webID = webID; error.level = ErrorLevel.EL_WARNING; error.message = e.Message; ShowLog("解析第" + betItems.Count + "个Error:" + error.message); } } return(betItems.Count); }
public override int Parse() { if (string.IsNullOrEmpty(html)) { return(0); } JObject mObj = JObject.Parse(html); JToken d = mObj["d"]; foreach (var b1 in d) { var gameIndex = GetGameIndex(b1[8].ToString()); if (gameIndex == INVALID_INDEX) { continue; } var leagueName1 = b1[5][1].ToString(); var leagueName2 = b1[1][1].ToString(); //IniUtil.WriteString("Game", string.Format("G{0}", index),gameName, configFile); foreach (var b2 in b1[10]) { try { var team1_name = b2[5][0].ToString().Trim(); var team2_name = b2[6][0].ToString().Trim(); var europeTime = DateTime.Parse(b2[7].ToString()); var chinaMatchTime = europeTime.AddHours(8); var localTime = DateTime.Now; //比赛已经开始 if (DateTime.Compare(localTime, chinaMatchTime) > 0) { continue; } //赔率不正常,封盘的比赛 int x = Convert.ToInt32(b2[35]); if (x == 1) { continue; } //bo int bo = GetBO(b2[33].ToString()); double betValue = 0.0; if (bo % 2 == 0) { var winhandcap = b2[28].ToString(); int v = Convert.ToInt32(winhandcap.Split('-')[1]); if (winhandcap.Contains("A")) { betValue = -v / 10.0f; } else if (winhandcap.Contains("B")) { betValue = v / 10.0f; } } var team1_abbr = b2[37].ToString(); var team2_abbr = b2[38].ToString(); //if(Convert.ToInt32(b2[50].ToString()) == 0 && Convert.ToInt32(b2[52].ToString()) == 0) //{ // continue; //} var team1_index = GetTeamIndex(gameIndex, team1_name); var team2_index = GetTeamIndex(gameIndex, team2_name); JArray b2_10 = JArray.Parse(b2[10].ToString()); JToken b2_10_0 = b2_10[0]; JToken b2_10_0_6 = b2_10_0[6]; JToken b2_10_0_6_4 = b2_10_0_6[4]; JToken b2_10_0_6_7 = b2_10_0_6[7]; var odds1 = Convert.ToDouble(b2_10_0_6_4); var odds2 = Convert.ToDouble(b2_10_0_6_7); BetItem b = new BetItem(); b.webID = webID; b.sportID = sportID; b.type = BetType.BT_TEAM; b.pID1 = team1_index; b.pID2 = team2_index; b.pName1 = team1_name; b.pName2 = team2_name; b.pAbbr1 = team1_abbr; b.pAbbr2 = team2_abbr; b.odds1 = odds1; b.odds2 = odds2; b.gameID = gameIndex; b.gameName = gameStaticNames[gameIndex]; b.leagueName1 = leagueName1; b.leagueName2 = leagueName2; b.handicap = betValue; b.time = chinaMatchTime; b.bo = bo; betItems.Add(b); if (betItems.Count == 81) { int a = 1; } } catch (Exception e) { DebugLog error = new DebugLog(); error.webID = webID; error.level = ErrorLevel.EL_WARNING; error.message = e.Message; ShowLog("解析第" + betItems.Count + "个Error:" + error.message); } } } ShowLog(string.Format("页面解析成功,解析个数:{0}!", betItems.Count)); return(betItems.Count); }
/// <summary> /// 同一个PK,可以多次下注 /// </summary> public void SaveBets(int pkId, int userId, List <Bet> bets, bool?isSynced) { using (var db = new RacingDbContext()) { int?agentUserId = null; // 报表使用 int?generalAgentUserId = null; // 报表使用 var user = db.User .Include(nameof(User.ParentUser)) .Include(nameof(User.UserRoles)) .Where(u => u.UserId == userId).First(); // 下注用户是会员 if (user.UserRoles.First().RoleId == RoleConst.Role_Id_Member) { agentUserId = user.ParentUserId; generalAgentUserId = db.User.Where(u => u.UserId == user.ParentUser.ParentUserId).First().UserId; } // 下注用户是代理 else if (user.UserRoles.First().RoleId == RoleConst.Role_Id_Agent) { agentUserId = user.UserId; generalAgentUserId = user.ParentUserId; } // 下注用户是代理 else if (user.UserRoles.First().RoleId == RoleConst.Role_Id_General_Agent) { agentUserId = user.UserId; generalAgentUserId = user.UserId; } bets.ForEach(b => { b.PKId = pkId; b.UserId = userId; b.CreateTime = DateTime.Now; b.AgentUserId = agentUserId; b.GeneralAgentUserId = generalAgentUserId; b.BetItems = new List <BetItem> { new BetItem { Rank = b.Rank, Num = b.Num, Amount = b.Amount, CreateTime = DateTime.Now, OrderNo = b.OrderNo, IsSynced = isSynced } }; }); var dbBets = db.Bet.Where(b => b.PKId == pkId && b.UserId == userId).ToList(); if (dbBets.Count == 0) { // 第一次添加 db.Bet.AddRange(bets); } else { // 追加投注 foreach (var dbBet in dbBets) { var newBet = bets.Where(b => b.Rank == dbBet.Rank && b.Num == dbBet.Num).FirstOrDefault(); if (newBet != null) { // 追加投注 dbBet.Amount += newBet.Amount; // 追加投注条目 var betItem = new BetItem { BetId = dbBet.BetId, Rank = newBet.Rank, Num = newBet.Num, Amount = newBet.Amount, CreateTime = DateTime.Now, OrderNo = newBet.OrderNo, IsSynced = isSynced }; db.BetItem.Add(betItem); } } // 新投注 foreach (var bet in bets) { var dbBet = dbBets.Where(b => b.Rank == bet.Rank && b.Num == bet.Num).FirstOrDefault(); if (dbBet == null) { db.Bet.Add(bet);// 新投注 } } } db.SaveChanges(); } }
public override int Parse() { //string fullName = "D:\\1.json"; // System.IO.StreamReader sr1 = new StreamReader(fullName); // html = sr1.ReadToEnd(); if (string.IsNullOrEmpty(html)) { return(0); } JObject main = JObject.Parse(html); JToken data = main["data"]; dateTime = data["next"].ToString(); JToken matches = data["matches"]; JToken records = data["records"]; foreach (var record in records) { try { string recordId = record.ToString(); JToken match = matches[recordId]; // listRecords.Add(record.ToString()); //} //foreach(var match in matches) //{ var bo = int.Parse(match["BO"].ToString()); var gameId = match["Cid"].ToString(); var league = match["LeagueName"].ToString(); var gameIndex = GetGameIndex(gameId); if (gameIndex == INVALID_INDEX) { continue; } //过滤掉延期的比赛 if (!Boolean.Parse(match["Visible"].ToString())) { continue; } //teams var team1_name = match["HomeTeamName"].ToString().Trim(); var team2_name = match["AwayTeamName"].ToString().Trim(); var team1_index = GetTeamIndex(gameIndex, team1_name); var team2_index = GetTeamIndex(gameIndex, team2_name); var timestamp = Convert.ToInt64(match["StartTimeInt"].ToString()); var time = new DateTime(1970, 1, 1, 8, 0, 0).AddSeconds(timestamp); //odds JToken match_winner = match["match_winner"]; if (match_winner != null) { JArray match_winner_records = JArray.Parse(match_winner["records"].ToString()); if (match_winner_records.Count == 0) { continue; } JToken match_winner_records_array_0 = match_winner_records[0]; JArray match_winner_records_array_0_0_data = JArray.Parse(match_winner_records_array_0["data"].ToString()); foreach (var market in match_winner_records_array_0_0_data) { string match_winner_data = market.ToString(); JToken odds = match_winner["markets"][match_winner_data]["odds"]; if (odds["left"] == null) { continue; } JArray leftArray = JArray.Parse(odds["left"].ToString()); JArray rightArray = JArray.Parse(odds["right"].ToString()); if (leftArray.Count == 0 || rightArray.Count == 0) { continue; } string left = leftArray[0].ToString(); string right = rightArray[0].ToString(); JToken odd_lists = match_winner["odd_lists"]; if (odd_lists != null) { var odd1 = Convert.ToDouble(odd_lists[left]["Value"]); var odd2 = Convert.ToDouble(odd_lists[right]["Value"]); //过滤掉不可见的赔率 if (!Boolean.Parse(odd_lists[left]["Visible"].ToString())) { continue; } BetItem b = new BetItem(); b.webID = webID; b.sportID = sportID; b.type = BetType.BT_TEAM; b.pID1 = team1_index; b.pID2 = team2_index; b.pName1 = team1_name; b.pName2 = team2_name; b.pAbbr1 = team1_name; b.pAbbr2 = team2_name; b.odds1 = odd1; b.odds2 = odd2; b.gameID = gameIndex; b.gameName = gameStaticNames[gameIndex]; b.leagueName1 = league; b.leagueName2 = league; b.bo = bo; b.time = time; betItems.Add(b); if (betItems.Count == 37) { int a = 0; } } } } } catch (Exception e) { DebugLog error = new DebugLog(); error.webID = webID; error.level = ErrorLevel.EL_WARNING; error.message = betItems.Count + ":" + e.Message; ShowLog(error); } //ShowLog(string.Format("页面解析成功,解析个数:{0}!", betItems.Count)); } return(betItems.Count); }
public override int Parse() { if (string.IsNullOrEmpty(html)) { return(0); } dicLeagues = new Dictionary <int, string>(); var main = JObject.Parse(html); var data = main["Data"]; var lg = data["LG"]; foreach (var league in lg) { foreach (JToken child in league.Children()) { int leagueId = Convert.ToInt32(child["LeagueID"].ToString()); string leagueName = child["LN"].ToString(); dicLeagues.Add(leagueId, leagueName); } } if (data["MH"] == null) { throw new Exception("MH:为空"); } var mh = JArray.Parse(data["MH"].ToString()); foreach (var match in mh) { var m = JArray.Parse(match["M"].ToString()); var leagueId = Convert.ToInt32(m[2].ToString()); if (dicLeagues.ContainsKey(leagueId)) { try { var title = dicLeagues[leagueId]; var titleArray = title.Split('-'); var gameId = titleArray[0].Trim(); var league = titleArray[1].Trim(); var gameIndex = GetGameIndex(gameId); if (gameIndex == INVALID_INDEX) { continue; } var team1_abbr = m[4].ToString().Trim(); var team2_abbr = m[6].ToString().Trim(); var team1_name = m[4].ToString().Trim(); var team2_name = m[6].ToString().Trim(); var team1_index = GetTeamIndex(gameIndex, team1_name); var team2_index = GetTeamIndex(gameIndex, team2_name); var timeFormat = m[7].ToString(); var gameTime = GetGameTime(timeFormat); var mk = match["MK"]; if (mk != null) { var seriesWin = mk["16"]; if (seriesWin != null) { var oddsArray = JArray.Parse(seriesWin.ToString()); var oddsCell = oddsArray[0]; var odds1 = Convert.ToDouble(oddsCell[1]); var odds2 = Convert.ToDouble(oddsCell[2]); BetItem b = new BetItem(); b.webID = webID; b.sportID = sportID; b.type = BetType.BT_TEAM; b.pID1 = team1_index; b.pID2 = team2_index; b.pName1 = team1_name; b.pName2 = team2_name; b.pAbbr1 = team1_abbr; b.pAbbr2 = team2_abbr; b.odds1 = odds1; b.odds2 = odds2; b.gameID = gameIndex; b.gameName = gameStaticNames[gameIndex]; b.leagueName1 = league; b.leagueName2 = league; b.handicap = 0; b.time = gameTime; b.bo = 0; b.betLimit1 = 0; b.betLimit2 = 0; betItems.Add(b); } var handicapWin = mk["1"]; if (handicapWin != null) { var oddsArray = JArray.Parse(seriesWin.ToString()); var oddsCell = oddsArray[0]; var odds1 = Convert.ToDouble(oddsCell[1]); var odds2 = Convert.ToDouble(oddsCell[2]); var handicap = Convert.ToDouble(oddsCell[3]); BetItem b = new BetItem(); b.webID = webID; b.sportID = sportID; b.type = BetType.BT_TEAM; b.pID1 = team1_index; b.pID2 = team2_index; b.pName1 = team1_name; b.pName2 = team2_name; b.pAbbr1 = team1_abbr; b.pAbbr2 = team2_abbr; b.odds1 = odds1; b.odds2 = odds2; b.gameID = gameIndex; b.gameName = gameStaticNames[gameIndex]; b.leagueName1 = league; b.leagueName2 = league; b.handicap = handicap; b.time = gameTime; b.bo = 0; b.betLimit1 = 0; b.betLimit2 = 0; betItems.Add(b); } } } catch (Exception e) { DebugLog error = new DebugLog(); error.webID = webID; error.level = ErrorLevel.EL_WARNING; error.message = e.Message; ShowLog(error); } } } return(betItems.Count); }
public override int Parse() { try { if (string.IsNullOrEmpty(html)) { return(0); } JObject main = JObject.Parse(html); var infos = main["info"]; foreach (var info in infos) { try { var title = info["Title"].ToString(); var status = info["Status"].ToString(); if (title.Contains("时时乐") || title.Contains("英雄乐") || title.Contains("三分乐") || status == "进行中") { continue; } //锁住了 if (info["IsLock"] != null && int.Parse(info["IsLock"].ToString()) == 1) { continue; } var leagueName = info["League"].ToString(); var gameTime = GetGameTime(info["StartAt"].ToString()); var gameName = GetGameID(info["Category"].ToString()); if (gameName == INVALID_VALUE) { continue; } var bo = GetBO(info["Title"].ToString()); var gameIndex = GetGameIndex(gameName); if (gameIndex == INVALID_INDEX) { continue; } var player = JArray.Parse(info["Player"].ToString()); if (player.Count == 0) { continue; } var team_name1 = player[0]["Name"].ToString().Trim(); var team_name2 = player[1]["Name"].ToString().Trim(); var team_abbr1 = player[0]["Code"].ToString().Trim(); var team_abbr2 = player[1]["Code"].ToString().Trim(); var team_id1 = GetTeamIndex(gameIndex, team_name1); var team_id2 = GetTeamIndex(gameIndex, team_name2); var bet = JArray.Parse(info["Bet"].ToString()); if (bet == null || bet.Count == 0 || (bet[0]["Name"] != null && bet[0]["Name"].ToString() != "比赛获胜")) { continue; } var items = bet[0]["Items"]; //第二个锁住了 var isLock = bet[0]["IsLock"]; if (isLock != null && int.Parse(isLock.ToString()) == 1) { continue; } var odds1 = Convert.ToDouble(items[0]["Odds"].ToString()); var odds2 = Convert.ToDouble(items[1]["Odds"].ToString()); var team_final_abbr1 = items[0]["Name"].ToString().Trim(); var team_final_abbr2 = items[1]["Name"].ToString().Trim(); if (team_abbr1 == team_final_abbr2 && team_abbr2 == team_final_abbr1) { var odds3 = odds1; odds1 = odds2; odds2 = odds3; } BetItem b = new BetItem(); b.sportID = sportID; b.webID = webID; b.type = BetType.BT_TEAM; b.pID1 = team_id1; b.pID2 = team_id2; b.pName1 = team_name1; b.pName2 = team_name2; b.pAbbr1 = team_abbr1; b.pAbbr2 = team_abbr2; b.odds1 = odds1; b.odds2 = odds2; b.gameID = gameIndex; b.leagueName1 = leagueName; b.handicap = 0; b.gameName = gameStaticNames[gameIndex]; b.time = gameTime; b.bo = bo; betItems.Add(b); if (betItems.Count == 18) { int a = 1; } } catch (Exception e) { DebugLog error = new DebugLog(); error.webID = webID; error.level = ErrorLevel.EL_WARNING; error.message = e.Message; ShowLog("解析第" + betItems.Count + "个Error:" + error.message); } } } catch (Exception e) { DebugLog error = new DebugLog(); error.webID = webID; error.level = ErrorLevel.EL_WARNING; error.message = e.Message; ShowLog("解析第" + betItems.Count + "个Error:" + error.message); } return(betItems.Count); }
public bool SaveBet(string roomId, BetItem bet) { return(SaveBetAsync(roomId, bet).Result); }
public override int Parse() { //string fullName = "D:\\1.json"; // System.IO.StreamReader sr1 = new StreamReader(fullName); // html = sr1.ReadToEnd(); if (string.IsNullOrEmpty(html)) { return(0); } JObject main = JObject.Parse(html); JArray n = JArray.Parse(main["n"].ToString()); JToken n0 = n[0]; JArray data = JArray.Parse(n0[2].ToString()); foreach (var record in data) { try { string title = record[1].ToString(); string gameId = GetGameID(title); string league = GetLeague1Name(title); int gameIndex = GetGameIndex(gameId); if (gameIndex == INVALID_INDEX) { continue; } var matches = record[2].ToArray(); foreach (var match in matches) { string team_name1 = match[1].ToString(); string team_name2 = match[2].ToString(); if (team_name1 == "Nemiga") { int ax = 1; } if (team_name1.Contains("击杀数") || team_name2.Contains("击杀数") || team_name2.Contains("Kills") || team_name1.Contains("Kills")) { continue; } int team_index1 = GetTeamIndex(gameIndex, team_name1); int team_index2 = GetTeamIndex(gameIndex, team_name2); long timeStamp1000 = Convert.ToInt64(match[4].ToString()); long timeStamp = timeStamp1000 / 1000; DateTime time = new DateTime(1970, 1, 1, 8, 0, 0).AddSeconds(timeStamp); int bo = Convert.ToInt32(match[7]); var oddsString = match[8]; int index = 0; JToken[] oddsItem = null; if (oddsString[index.ToString()] == null) { continue; } oddsItem = oddsString[index.ToString()].ToArray(); var oddsPair = oddsItem[0].ToArray(); var odds1 = Convert.ToDouble(oddsPair[1]); var odds2 = Convert.ToDouble(oddsPair[0]); var betLimit = Convert.ToInt32(oddsPair[5]); BetItem b = new BetItem(); b.webID = webID; b.sportID = sportID; b.type = BetType.BT_TEAM; b.pID1 = team_index1; b.pID2 = team_index2; b.pName1 = team_name1; b.pName2 = team_name2; b.pAbbr1 = team_name1; b.pAbbr2 = team_name2; b.odds1 = odds1; b.odds2 = odds2; b.gameID = gameIndex; b.gameName = gameStaticNames[gameIndex]; b.leagueName1 = league; b.leagueName2 = league; b.bo = bo; b.time = time; betItems.Add(b); if (betItems.Count == 36) { int a = 0; } // index++; //do //{ //} //while (true); } } catch (Exception e) { DebugLog error = new DebugLog(); error.webID = webID; error.level = ErrorLevel.EL_WARNING; error.message = betItems.Count + ":" + e.Message; ShowLog(error); } } //foreach (var record in main) //{ // try // { // string recordId = record.ToString(); // // listRecords.Add(record.ToString()); // //} // //foreach(var match in matches) // //{ // var bo = int.Parse(match["BO"].ToString()); // var gameId = match["Cid"].ToString(); // var league = match["LeagueName"].ToString(); // var gameIndex = GetGameIndex(gameId); // if (gameIndex == INVALID_INDEX) // { // continue; // } // //过滤掉延期的比赛 // //if (Boolean.Parse(match["live_show"].ToString())) // //{ // // continue; // //} // //teams // var team1_name = match["HomeTeamName"].ToString().Trim(); // var team2_name = match["AwayTeamName"].ToString().Trim(); // var team1_index = GetTeamIndex(gameIndex, team1_name); // var team2_index = GetTeamIndex(gameIndex, team2_name); // var timestamp = Convert.ToInt64(match["StartTimeInt"].ToString()); // var time = new DateTime(1970, 1, 1, 8, 0, 0).AddSeconds(timestamp); // //odds // JToken match_winner = match["match_winner"]; // if (match_winner != null) // { // JArray match_winner_records = JArray.Parse(match_winner["records"].ToString()); // if(match_winner_records.Count == 0) // { // continue; // } // JToken match_winner_records_array_0 = match_winner_records[0]; // JArray match_winner_records_array_0_0_data = JArray.Parse(match_winner_records_array_0["data"].ToString()); // foreach (var market in match_winner_records_array_0_0_data) // { // string match_winner_data = market.ToString(); // JToken odds = match_winner["markets"][match_winner_data]["odds"]; // if (odds["left"] == null) // { // continue; // } // JArray leftArray = JArray.Parse(odds["left"].ToString()); // JArray rightArray = JArray.Parse(odds["right"].ToString()); // string left = leftArray[0].ToString(); // string right = rightArray[0].ToString(); // JToken odd_lists = match_winner["odd_lists"]; // if (odd_lists != null) // { // var odd1 = Convert.ToDouble(odd_lists[left]["Value"]); // var odd2 = Convert.ToDouble(odd_lists[right]["Value"]); // BetItem b = new BetItem(); // b.webID = webID; // b.sportID = sportID; // b.type = BetType.BT_TEAM; // b.pID1 = team1_index; // b.pID2 = team2_index; // b.pName1 = team1_name; // b.pName2 = team2_name; // b.pAbbr1 = team1_name; // b.pAbbr2 = team2_name; // b.odds1 = odd1; // b.odds2 = odd2; // b.gameID = gameIndex; // b.gameName = gameStaticNames[gameIndex]; // b.leagueName1 = league; // b.leagueName2 = league; // b.bo = bo; // b.time = time; // betItems.Add(b); // if (betItems.Count == 9) // { // int a = 0; // } // } // } // } // } // catch (Exception e) // { // DebugLog error = new DebugLog(); // error.webID = webID; // error.level = ErrorLevel.EL_WARNING; // error.message = betItems.Count + ":" + e.Message; // ShowLog(error); // } // //ShowLog(string.Format("页面解析成功,解析个数:{0}!", betItems.Count)); //} return(betItems.Count); }
public override int Parse() { string postQueryString = "requestString="; Dictionary <string, BTI_MATCH_INFO> listMatchItemIDs = new Dictionary <string, BTI_MATCH_INFO>(); if (string.IsNullOrEmpty(html)) { return(0); } JArray main = JArray.Parse(html); JArray matches = JArray.Parse(main[2].ToString()); foreach (var match in matches) { //string team1_name = match[1].ToString(); //string team2_name = match[2].ToString(); string gameLeague; int gameIndex; DateTime time = Convert.ToDateTime(match[4].ToString()).AddHours(8); string title = match[11].ToString(); if (GetGameIndexAndLeague(title, out gameIndex, out gameLeague)) { JArray matchItemArray = JArray.Parse(match[5].ToString()); if (matchItemArray != null) { foreach (var matchItems in matchItemArray) { string matchItemId = matchItems[0].ToString(); postQueryString += matchItemId + "%40"; listMatchItemIDs.Add(matchItemId, new BTI_MATCH_INFO(matchItemId, time, gameIndex, gameLeague)); } } } } postQueryString = postQueryString.Substring(0, postQueryString.Length - 3); //寻求赔率页面 int nTryCount = 0; string uri = "https://jbosports.btisports.io/pagemethods.aspx/UpdateAsianSkinEvents"; RequestOptions op = new RequestOptions(uri); op.Method = "POST"; op.Accept = "*/*"; op.XHRParams = postQueryString; op.WebHeader.Add("requesttarget: AJAXService"); op.ContentType = "application/x-www-form-urlencoded"; //获取网页 string oddsHTML = RequestAction(op); while (string.IsNullOrEmpty(oddsHTML) && nTryCount < MAX_TRY_COUNT) { oddsHTML = RequestAction(op); nTryCount++; } if (nTryCount == MAX_TRY_COUNT) { ShowLog("赔率页面抓取失败!"); oddsHTML = ""; return(0); } else { if (string.IsNullOrEmpty(oddsHTML)) { return(0); } JArray matchItems = JArray.Parse(oddsHTML); foreach (var matchItem in matchItems) { try { string curMap = matchItem[6].ToString(); if (curMap != "Full Time") { continue; } string matchItemId = matchItem[0].ToString(); int gameIndex = listMatchItemIDs[matchItemId].gameIndex; string gameLeague = listMatchItemIDs[matchItemId].gameLeague; DateTime gameTime = listMatchItemIDs[matchItemId].matchTime; string team1_name = matchItem[4].ToString(); string team2_name = matchItem[5].ToString(); int team1_index = GetTeamIndex(gameIndex, team1_name); int team2_index = GetTeamIndex(gameIndex, team2_name); JArray oddsArray = JArray.Parse(matchItem[2].ToString()); if (oddsArray != null && oddsArray.Count > 0) { JArray oddsArray1 = JArray.Parse(oddsArray[0].ToString()); if (oddsArray1 != null && oddsArray1.Count > 0) { for (int i = 1; i < 3; i++) { double handicap = 0; var tmpOdds = oddsArray1[i].ToString(); if (string.IsNullOrEmpty(tmpOdds)) { continue; } JArray oddsArray2 = JArray.Parse(tmpOdds); if (oddsArray2 != null && oddsArray2.Count > 0) { string odds1String = null; string odds2String = null; if (oddsArray2.Count == 10) { odds1String = oddsArray2[1].ToString(); odds2String = oddsArray2[5].ToString(); } else if (oddsArray2.Count == 8) { handicap = Convert.ToDouble(oddsArray2[1].ToString()); odds1String = oddsArray2[2].ToString(); odds2String = oddsArray2[4].ToString(); } else { continue; } if (odds1String == "0" || odds2String == "0") { continue; } double odds1 = GetOdds(int.Parse(odds1String)); double odds2 = GetOdds(int.Parse(odds2String)); BetItem b = new BetItem(); b.webID = webID; b.sportID = sportID; b.type = BetType.BT_TEAM; b.pID1 = team1_index; b.pID2 = team2_index; b.pName1 = team1_name; b.pName2 = team2_name; b.pAbbr1 = team1_name; b.pAbbr2 = team2_name; b.odds1 = odds1; b.odds2 = odds2; b.gameID = gameIndex; b.gameName = gameStaticNames[gameIndex]; b.leagueName1 = gameLeague; b.leagueName2 = gameLeague; b.bo = 1; b.handicap = handicap; b.time = gameTime; betItems.Add(b); if (betItems.Count == 1) { int a = 0; } } else { continue; } } } } else { continue; } } catch (Exception e) { DebugLog error = new DebugLog(); error.webID = webID; error.level = ErrorLevel.EL_WARNING; error.message = betItems.Count + ":" + e.Message; ShowLog(error); } } } return(betItems.Count); }
public override int Parse() { int pageNum = 0; try { if (string.IsNullOrEmpty(html)) { return(0); } JObject main = JObject.Parse(html); var results = JArray.Parse(main["result"].ToString()); pageNum = results.Count; foreach (var result in results) { try { //odds var odds = result["odds"]; //过虑胜负平 if (odds == null || odds.Count() != 2) { continue; } var status = result["status"]; if (status != null && Convert.ToInt32(status.ToString()) == 2) { continue; } var odds1 = Convert.ToDouble(odds[0]["odds"].ToString()); var odds2 = Convert.ToDouble(odds[1]["odds"].ToString()); var leagueName = result["tournament_name"].ToString(); var gameTime = GetGameTime(result["start_time"].ToString()); var gameName = GetGameID(result["game_name"].ToString()); var bo = GetBO(result["round"].ToString()); var gameIndex = GetGameIndex(gameName); if (gameIndex >= gameStaticNames.Count || gameIndex < 0) { continue; } //bo var round = result["round"]; //betlimit var betLimit1 = Convert.ToInt32(odds[0]["bet_limit"][1]); var betLimit2 = Convert.ToInt32(odds[1]["bet_limit"][1]); //team var team = result["team"]; var team_name1 = odds[0]["name"].ToString(); var team_name2 = odds[1]["name"].ToString(); var team_short_name1 = team_name1; //Trim(); var team_short_name2 = team_name2; //Trim(); var team_id1 = GetTeamIndex(gameIndex, team_name1); var team_id2 = GetTeamIndex(gameIndex, team_name2); BetItem b = new BetItem(); b.sportID = sportID; b.webID = webID; b.type = BetType.BT_TEAM; b.pID1 = team_id1; b.pID2 = team_id2; b.pName1 = team_name1; b.pName2 = team_name2; b.pAbbr1 = team_short_name1; b.pAbbr2 = team_short_name2; b.odds1 = odds1; b.odds2 = odds2; b.bo = bo; b.betLimit1 = betLimit1; b.betLimit2 = betLimit2; b.gameID = gameIndex; b.handicap = 0; b.gameName = gameStaticNames[gameIndex]; b.time = gameTime; b.leagueName1 = leagueName; betItems.Add(b); if (betItems.Count == 1) { int a = 1; } } catch (Exception e) { DebugLog error = new DebugLog(); error.webID = webID; error.level = ErrorLevel.EL_WARNING; error.message = e.Message; ShowLog("解析第" + betItems.Count + "个Error:" + error.message); } } } catch (Exception e) { DebugLog error = new DebugLog(); error.webID = webID; error.level = ErrorLevel.EL_WARNING; error.message = e.Message; ShowLog("解析第" + betItems.Count + "个Error:" + error.message); } return(pageNum); }
public override int Parse() { //string fullName = "D:\\1.json"; // System.IO.StreamReader sr1 = new StreamReader(fullName); // html = sr1.ReadToEnd(); if (string.IsNullOrEmpty(html)) { return(0); } JObject main = JObject.Parse(html); JArray n = JArray.Parse(main["n"].ToString()); JToken n0 = n[0]; JArray data = JArray.Parse(n0[2].ToString()); foreach (var record in data) { try { string title = record[1].ToString(); string gameId = GetGameID(title); string league = GetLeague1Name(title); int gameIndex = GetGameIndex(gameId); if (gameIndex == INVALID_INDEX) { continue; } var matches = record[2].ToArray(); foreach (var match in matches) { string team_name1 = match[1].ToString(); string team_name2 = match[2].ToString(); if (team_name1.Contains("击杀数") || team_name2.Contains("击杀数") || team_name2.Contains("Kills") || team_name1.Contains("Kills")) { continue; } int team_index1 = GetTeamIndex(gameIndex, team_name1); int team_index2 = GetTeamIndex(gameIndex, team_name2); long timeStamp1000 = Convert.ToInt64(match[4].ToString()); long timeStamp = timeStamp1000 / 1000; DateTime time = new DateTime(1970, 1, 1, 8, 0, 0).AddSeconds(timeStamp); int bo = Convert.ToInt32(match[7]); var oddsString = match[8]; int index = 0; JToken[] oddsItem = null; if (oddsString[index.ToString()] == null) { continue; } oddsItem = oddsString[index.ToString()].ToArray(); var oddsPair = oddsItem[0].ToArray(); var odds1 = Convert.ToDouble(oddsPair[1]); var odds2 = Convert.ToDouble(oddsPair[0]); var betLimit = Convert.ToInt32(oddsPair[5]); BetItem b = new BetItem(); b.webID = webID; b.sportID = sportID; b.type = BetType.BT_TEAM; b.pID1 = team_index1; b.pID2 = team_index2; b.pName1 = team_name1; b.pName2 = team_name2; b.pAbbr1 = team_name1; b.pAbbr2 = team_name2; b.odds1 = odds1; b.odds2 = odds2; b.gameID = gameIndex; b.gameName = gameStaticNames[gameIndex]; b.leagueName1 = league; b.leagueName2 = league; b.bo = bo; b.time = time; betItems.Add(b); if (betItems.Count == 36) { int a = 0; } // index++; //do //{ //} //while (true); } } catch (Exception e) { DebugLog error = new DebugLog(); error.webID = webID; error.level = ErrorLevel.EL_WARNING; error.message = betItems.Count + ":" + e.Message; ShowLog(error); } } return(betItems.Count); }
public static void Report() { foreach (string folder in Directory.GetDirectories(GBCommon.DataFolder)) { GameType gameType = (GameType)Enum.Parse(typeof(GameType), folder.Remove(0, GBCommon.DataFolder.Length).TrimStart('\\')); DateTime continuationStartDate = GBCommon.ReadContinuationDate(GBCommon.ConstructReportContinuationFileName(gameType)); DateTime latest = continuationStartDate; var files = new DirectoryInfo(folder).GetFiles("*.json", SearchOption.TopDirectoryOnly).Where(file => file.LastWriteTime > continuationStartDate + TimeSpan.FromSeconds(1)); foreach (var file in files) { AveragedNonWeightedBetItemManager mgr = new AveragedNonWeightedBetItemManager(); mgr.Deserialize(file.FullName, OddsType.ThreeWay); if (mgr.CurrentBets.Count < 1) { throw new FileLoadException(string.Format("Record file {0} not valid", file.Name)); } BetItem firstBet = mgr.CurrentBets[0]; Stake bestStake = mgr.BestStake(firstBet.GameName, firstBet.GameType, firstBet.Odds.Type); string output = bestStake.ROI.ToString("p2") + " " + bestStake.BetItem.MatchDate.ToShortDateString() + " " + bestStake.BetItem.Teams[0].Name + " " + bestStake.BetItem.Teams[1].Name + " " + bestStake.BetItem.BookMaker.Replace(' ', '_') + " " + bestStake.BetItem.Odds.Type.ToString() + " " + bestStake.Decision; GBCommon.Report(output, gameType); if (file.LastWriteTime > latest) { latest = file.LastWriteTime; } // If the game stake exists, delete the old one var deleteStakeResponse = GBCommon.SendRequest( "{\"BetItem.GameName\": \"" + bestStake.BetItem.GameName + "\"}", ConfigurationManager.AppSettings["datastore"], ConfigurationManager.AppSettings["apikey"], ConfigurationManager.AppSettings["passwd"], "application/json", "DELETE" ); using (StreamReader streamReader = new StreamReader(deleteStakeResponse.GetResponseStream())) { var text = streamReader.ReadToEnd(); Console.WriteLine(text); } // Add the new stake var addStakeResponse = GBCommon.SendRequest( JsonConvert.SerializeObject(bestStake), ConfigurationManager.AppSettings["datastore"], ConfigurationManager.AppSettings["apikey"], ConfigurationManager.AppSettings["passwd"], "application/json", "PUT" ); using (StreamReader streamReader = new StreamReader(addStakeResponse.GetResponseStream())) { var text = streamReader.ReadToEnd(); Console.WriteLine(text); } } if (latest > continuationStartDate) { GBCommon.WriteContinuationDate(GBCommon.ConstructReportContinuationFileName(gameType), latest); } } GBCommon.LogInfo("Reporting Completed."); }
public override int Parse() { if (string.IsNullOrEmpty(html)) { return(0); } html = html.Substring(7, html.Length - 8); JArray main = JArray.Parse(html); JArray esport = JArray.Parse(main[0].ToString()); foreach (var leagueCell in esport) { var title = leagueCell[3].ToString(); var titleArray = title.Split('-'); var gameId = titleArray[0].Trim(); var league = titleArray[1].Trim(); var gameIndex = GetGameIndex(gameId); if (gameIndex == INVALID_INDEX) { continue; } var matchCell = JArray.Parse(leagueCell[5].ToString()); foreach (var record in matchCell) { try { var team1_abbr = record[1].ToString().Trim(); var team2_abbr = record[2].ToString().Trim(); var team1_name = record[1].ToString().Trim(); var team2_name = record[2].ToString().Trim(); var team1_index = GetTeamIndex(gameIndex, team1_name); var team2_index = GetTeamIndex(gameIndex, team2_name); var timeString = record[3].ToString(); timeString = System.Text.RegularExpressions.Regex.Replace(timeString, @"[^0-9]+", ""); var timeStamp = Convert.ToInt64(timeString) / 1000; var gameTime = new DateTime(1970, 1, 1, 8, 0, 0).AddSeconds(timeStamp); var oddsCell = JArray.Parse(record[27].ToString())[0]; var odds1Cell = JArray.Parse(oddsCell[8][0].ToString()); var odds2Cell = JArray.Parse(oddsCell[8][1].ToString()); if (Convert.ToInt32(oddsCell[1].ToString()) != 20) { continue; } if (odds1Cell.Count != 2 || odds2Cell.Count != 2 || odds1Cell[0].ToString() != "h" || odds2Cell[0].ToString() != "a") { continue; } var odds1Format = odds1Cell[1].ToString(); var odds2Format = odds2Cell[1].ToString(); var odds1 = Convert.ToDouble(odds1Format); var odds2 = Convert.ToDouble(odds2Format); if (odds1 < 0) { odds1 = (1 / (-odds1)) + 1; } else { odds1 += 1; } if (odds2 < 0) { odds2 = (1 / (-odds2)) + 1; } else { odds2 += 1; } BetItem b = new BetItem(); b.webID = webID; b.sportID = sportID; b.type = BetType.BT_TEAM; b.pID1 = team1_index; b.pID2 = team2_index; b.pName1 = team1_name; b.pName2 = team2_name; b.pAbbr1 = team1_abbr; b.pAbbr2 = team2_abbr; b.odds1 = odds1; b.odds2 = odds2; b.gameID = gameIndex; b.gameName = gameStaticNames[gameIndex]; b.leagueName1 = league; b.leagueName2 = league; b.handicap = 0; b.time = gameTime; b.bo = 0; b.betLimit1 = 0; b.betLimit2 = 0; betItems.Add(b); } catch (Exception e) { DebugLog error = new DebugLog(); error.webID = webID; error.level = ErrorLevel.EL_WARNING; error.message = e.Message; ShowLog(error); } } } return(betItems.Count); }
public static List <BetWinPair> ParseBetWin(List <BetItem> bs) { List <BetWinPair> listPair = new List <BetWinPair>(); if (bs.Count < 2) { return(listPair); } for (int i = 0; i < bs.Count; i++) { BetItem b1 = bs[i]; for (int j = i + 1; j < bs.Count; j++) { BetItem b2 = bs[j]; //过滤同一个网站 if (b1.webID == b2.webID) { continue; } //过滤不同的体育项目 if (b1.sportID != b2.sportID) { continue; } //过滤不同的类型 if (b1.type != b2.type) { continue; } //过滤没有注册的teamID if (b1.pID1 == INVALID_INDEX || b1.pID2 == INVALID_INDEX || b2.pID1 == INVALID_INDEX || b2.pID2 == INVALID_INDEX) { continue; } //过滤bo不同的 //if(b1.bo != b2.bo) //{ // continue; //} //时间不能相差太多 TimeSpan timeSpan = b1.time - b2.time; if (timeSpan.TotalHours > 4 || timeSpan.TotalHours < -4) { continue; } if (b1.type == BetType.BT_TEAM) { double odd1 = 0.0f; double odd2 = 0.0f; double odd3 = 0.0f; double odd4 = 0.0f; if (b1.gameID == b2.gameID) { if ((b1.pID1 == b2.pID1) && (b1.pID2 == b2.pID2)) { odd1 = b1.odds1; odd2 = b2.odds2; odd3 = b1.odds2; odd4 = b2.odds1; //B1让B2分 if (b1.handicap >= b2.handicap) { if (CanMustWin(odd1, odd2)) { BetWinPair pair = new BetWinPair(); pair.b1 = b1; pair.b2 = b2; pair.orderForward = true; pair.odds1 = odd1; pair.odds2 = odd2; pair.pName1 = b1.pName1; pair.pName2 = b2.pName2; pair.pAbbr1 = b1.pAbbr1; pair.pAbbr2 = b2.pAbbr2; pair.betLimit1 = b1.betLimit1; pair.betLimit2 = b2.betLimit2; pair.handicap1 = b1.handicap; pair.handicap2 = -b2.handicap; pair.profit = GetProfit(pair.odds1, pair.odds2); listPair.Add(pair); } } if (b1.handicap <= b2.handicap) { if (CanMustWin(odd3, odd4)) { BetWinPair pair = new BetWinPair(); pair.b1 = b1; pair.b2 = b2; pair.orderForward = false; pair.odds1 = odd3; pair.odds2 = odd4; pair.pName1 = b1.pName2; pair.pName2 = b2.pName1; pair.pAbbr1 = b1.pAbbr2; pair.pAbbr2 = b2.pAbbr1; pair.betLimit1 = b1.betLimit2; pair.betLimit2 = b2.betLimit1; pair.handicap1 = -b1.handicap; pair.handicap2 = b2.handicap; pair.profit = GetProfit(pair.odds1, pair.odds2); listPair.Add(pair); } } } else if ((b1.pID1 == b2.pID2) && (b1.pID2 == b2.pID1)) { odd1 = b1.odds1; odd2 = b2.odds1; odd3 = b1.odds2; odd4 = b2.odds2; double tmpHandicap = -b2.handicap; if (b1.handicap >= tmpHandicap) { if (CanMustWin(odd1, odd2)) { BetWinPair pair = new BetWinPair(); pair.b1 = b1; pair.b2 = b2; pair.orderForward = true; pair.odds1 = odd1; pair.odds2 = odd2; pair.pName1 = b1.pName1; pair.pName2 = b2.pName1; pair.pAbbr1 = b1.pAbbr1; pair.pAbbr2 = b2.pAbbr1; pair.betLimit1 = b1.betLimit1; pair.betLimit2 = b2.betLimit1; pair.handicap1 = b1.handicap; pair.handicap2 = b2.handicap; pair.profit = GetProfit(pair.odds1, pair.odds2); listPair.Add(pair); } } if (b1.handicap <= tmpHandicap) { if (CanMustWin(odd3, odd4)) { BetWinPair pair = new BetWinPair(); pair.b1 = b1; pair.b2 = b2; pair.orderForward = false; pair.odds1 = odd3; pair.odds2 = odd4; pair.pName1 = b1.pName2; pair.pName2 = b2.pName2; pair.pAbbr1 = b1.pAbbr2; pair.pAbbr2 = b2.pAbbr2; pair.betLimit1 = b1.betLimit2; pair.betLimit2 = b2.betLimit2; pair.handicap1 = -b1.handicap; pair.handicap2 = -b2.handicap; pair.profit = GetProfit(pair.odds1, pair.odds2); listPair.Add(pair); } } } } } else if (b1.type == BetType.BT_SOLO) { if (b1.itemID == b2.itemID && b1.pID1 == b2.pID1) { if ((b1.compare == BetCompare.Larger && b2.compare == BetCompare.Smaller && b1.handicap <= b2.handicap) || (b1.compare == BetCompare.Smaller && b2.compare == BetCompare.Larger && b1.handicap >= b2.handicap)) { if (CanMustWin(b1.odds1, b2.odds1)) { BetWinPair pair = new BetWinPair(); pair.b1 = b1; pair.b2 = b2; listPair.Add(pair); } } } } } } return(listPair); }
public override int Parse() { if (string.IsNullOrEmpty(html)) { return(0); } //JObject main = JObject.Parse(html); JArray array = JArray.Parse(html); foreach (var record in array) { try { var gameId = record["game_name"].ToString(); var league = record["competition_name"].ToString(); var gameIndex = GetGameIndex(gameId); if (gameIndex == INVALID_INDEX) { continue; } var bo = 1; var gameTime = Convert.ToDateTime(record["start_datetime"].ToString()); JToken team1 = record["home"]; JToken team2 = record["away"]; var team1_abbr = team1["team_name"].ToString().Trim(); var team2_abbr = team2["team_name"].ToString().Trim(); var team1_name = team1["team_name"].ToString().Trim(); var team2_name = team2["team_name"].ToString().Trim(); var team1_index = GetTeamIndex(gameIndex, team1_name); var team2_index = GetTeamIndex(gameIndex, team2_name); JArray oddsMarket = JArray.Parse(record["markets"].ToString()); foreach (var odds in oddsMarket) { double handicap = 0; JArray selection = JArray.Parse(odds["selection"].ToString()); var bet_type_name = odds["bet_type_name"].ToString(); if (bet_type_name == "WIN") { handicap = 0; } else if (bet_type_name == "AH") { handicap = Convert.ToDouble(selection[0]["handicap"].ToString()); } else if (bet_type_name == "1X2") { if (selection.Count > 2) { continue; } handicap = 0; } else { continue; } JToken odds1Market = selection[0]; JToken odds2Market = selection[1]; var odd1 = Convert.ToDouble(odds1Market["euro_odds"]); var odd2 = Convert.ToDouble(odds2Market["euro_odds"]); var betLimit1 = Convert.ToDouble(odds["max_bet_amount"]); var betLimit2 = betLimit1; BetItem b = new BetItem(); b.webID = webID; b.sportID = sportID; b.type = BetType.BT_TEAM; b.pID1 = team1_index; b.pID2 = team2_index; b.pName1 = team1_name; b.pName2 = team2_name; b.pAbbr1 = team1_abbr; b.pAbbr2 = team2_abbr; b.odds1 = odd1; b.odds2 = odd2; b.gameID = gameIndex; b.gameName = gameStaticNames[gameIndex]; b.leagueName1 = league; b.leagueName2 = league; b.handicap = handicap; b.time = gameTime; b.bo = bo; b.betLimit1 = (int)betLimit1; b.betLimit2 = (int)betLimit2; betItems.Add(b); } } catch (Exception e) { DebugLog error = new DebugLog(); error.webID = webID; error.level = ErrorLevel.EL_WARNING; error.message = e.Message; ShowLog(error); } } return(betItems.Count); }
public override int Parse() { try { if (string.IsNullOrEmpty(html)) { return(0); } JObject main = JObject.Parse(html); JToken data = main["data"]; int size = Convert.ToInt32(data["size"]); JToken records = data["records"]; foreach (var record in records) { var id = record["id"].ToString(); var gameId = record["gameId"].ToString(); var league = record["league"]["name"].ToString(); var gameIndex = GetGameIndex(gameId); var bo = Convert.ToInt32(record["bo"].ToString()); //过滤掉进行中的比赛 if (record["status"].ToString() == "ongoing") { continue; } //time var gameTime = Convert.ToDateTime(record["startTime"].ToString()); //teams JToken teams = record["teams"]; var team1_abbr = teams[0]["abbr"].ToString().Trim(); var team2_abbr = teams[1]["abbr"].ToString().Trim(); var team1_name = teams[0]["name"].ToString().Trim(); var team2_name = teams[1]["name"].ToString().Trim(); var team1_index = GetTeamIndex(gameIndex, team1_name); var team2_index = GetTeamIndex(gameIndex, team2_name); JToken odds = record["odds"]; if (odds != null) { JToken groupName = odds["groupName"]; JToken betOptions = odds["betOptions"]; var markValue = odds["markValue"]; var switchStatus = odds["switchStatus"]; if (bo != 1) { //非BO1,不是胜负盘过滤 if (!groupName.ToString().Contains("全场获胜")) { continue; } } else { //BO1,不是胜负盘或者地图一过滤 if (!(groupName.ToString().Contains("全场获胜") || groupName.ToString().Contains("地图一获胜"))) { continue; } } //未开盘 if (!Convert.ToBoolean(switchStatus.ToString())) { continue; } double handicap = 0.0; if (markValue != null) { handicap = Convert.ToDouble(markValue.ToString()); } if (betOptions != null) { var odd1 = Convert.ToDouble(betOptions[0]["odd"]); var odd2 = Convert.ToDouble(betOptions[1]["odd"]); var betLimit1 = Convert.ToDouble(betOptions[0]["userSingleBetProfitLimit"]) / (odd1 - 1.0f); var betLimit2 = Convert.ToDouble(betOptions[1]["userSingleBetProfitLimit"]) / (odd2 - 1.0f); BetItem b = new BetItem(); b.webID = webID; b.sportID = sportID; b.type = BetType.BT_TEAM; b.pID1 = team1_index; b.pID2 = team2_index; b.pName1 = team1_name; b.pName2 = team2_name; b.pAbbr1 = team1_abbr; b.pAbbr2 = team2_abbr; b.odds1 = odd1; b.odds2 = odd2; b.gameID = gameIndex; b.gameName = gameStaticNames[gameIndex]; b.leagueName1 = league; b.leagueName2 = league; b.handicap = handicap; b.time = gameTime; b.bo = bo; b.betLimit1 = (int)betLimit1; b.betLimit2 = (int)betLimit2; betItems.Add(b); } } } } catch (Exception e) { DebugLog error = new DebugLog(); error.webID = webID; error.level = ErrorLevel.EL_WARNING; error.message = e.Message; ShowLog(error); } return(betItems.Count); }