public async void LoadStryktipsCoupon() { CanExecuteStryktipset = false; await Task.Run(() => { _acoupon = _resourceAccess.GetStryktipsCoupon(); CanExecuteStryktipset = true; Stryktipsstring = _acoupon.ToString(); }); Console.WriteLine("Hämtat"); }
public StryktipsMatches GetStryktipsCoupon() { Uri jsonUri = new Uri("http://aivu.se/hemsida/strykt/api/stryktipset"); string jsonString = ""; using (WebClient wc = new WebClient()) { jsonString = wc.DownloadString(jsonUri); } StryktipsMatches stryktipsCoupon = JsonConvert.DeserializeObject <StryktipsMatches>(jsonString); return(stryktipsCoupon); }
public StryktipsCoupon EvaluateStryktipset(StryktipsMatches stryktipsMatches) { int COUPONGPRICE = 128; int WHOLEGUARDS = 0; int HALFGUARDS = 7; var stryktipsCoupon = new StryktipsCoupon(stryktipsMatches); stryktipsCoupon = GenerateCouponMarks(stryktipsCoupon, COUPONGPRICE); //foreach (var match in stryktipsMatches.matches.match) //{ // var result = EvaluateMatch(match); //} //Lista med tecken List <string> l = new List <string>(); //Stryktipsraden List <string> r = new List <string> { "", "", "", "", "", "", "", "", "", "", "", "", "" }; //Lägg in det tecknet med högst spelfördelning i tipsraden och lägg in övriga tecken i en lista foreach (var match in stryktipsMatches.matches.match) { int home = match.HomeWin; int draw = match.Draw; int away = match.AwayWin; if (home > draw && home > away) { r[Convert.ToInt32(match.Id) - 1] = "1"; l.Add((draw + "").PadLeft(3, '0') + "-" + match.Id + "-d"); l.Add((away + "").PadLeft(3, '0') + "-" + match.Id + "-a"); } else if (draw > away) { r[Convert.ToInt32(match.Id) - 1] = "X"; l.Add((home + "").PadLeft(3, '0') + "-" + match.Id + "-h"); l.Add((away + "").PadLeft(3, '0') + "-" + match.Id + "-a"); } else { r[Convert.ToInt32(match.Id) - 1] = "2"; l.Add((home + "").PadLeft(3, '0') + "-" + match.Id + "-h"); l.Add((draw + "").PadLeft(3, '0') + "-" + match.Id + "-d"); } } //Sortera listan så lägst fördelning hamnar först l.Sort((a, b) => a.CompareTo(b)); int num = 0; //Lägg in de lägst spelfördelade tecken i tipsraden foreach (string s in l) { int sum = r[0].Count() * r[1].Count() * r[2].Count() * r[3].Count() * r[4].Count() * r[5].Count() * r[6].Count() * r[7].Count() * r[8].Count() * r[9].Count() * r[10].Count() * r[11].Count() * r[12].Count(); string[] arr = s.Split('-'); int match = Convert.ToInt32(arr[1]) - 1; string sign = arr[2].Equals("h") ? "1" : arr[2].Equals("d") ? "X" : "2"; r[match] = r[match] + sign; sum = r[0].Count() * r[1].Count() * r[2].Count() * r[3].Count() * r[4].Count() * r[5].Count() * r[6].Count() * r[7].Count() * r[8].Count() * r[9].Count() * r[10].Count() * r[11].Count() * r[12].Count(); //Om insatsen är högre än 135kr, ta bort senaste inlagda tecknet if (sum > 135) { r[match] = r[match].Replace(sign, ""); } num++; } return(stryktipsCoupon); }