/// <summary> /// Load user avgs section partial view /// </summary> /// <returns></returns> public IActionResult UserAvgsSection() { UserTestAvgs wtc = new UserTestAvgs(); List <UserTestAvgs> tests = wtc.GetUserTestAvgs(HomeController._database); //Prepare data points List <LoadtimeAvgGraph> loadtime = new List <LoadtimeAvgGraph>(); List <SpeedAvgGraph> speed = new List <SpeedAvgGraph>(); List <ScoreAvgGraph> score = new List <ScoreAvgGraph>(); UserPlotKey upk = new UserPlotKey(); List <UserPlotKey> keys = upk.GetPlotKeys(HomeController._database); int i = 0; foreach (UserTestAvgs avg in tests) { if (i < keys.Count) { avg.userKey = keys[i]; } loadtime.Add(new LoadtimeAvgGraph(avg.key, avg.loadtime)); speed.Add(new SpeedAvgGraph(avg.key, avg.speed)); score.Add(new ScoreAvgGraph(avg.key, avg.score)); i++; } ViewBag.Loadtime = JsonConvert.SerializeObject(loadtime); ViewBag.Speed = JsonConvert.SerializeObject(speed); ViewBag.Score = JsonConvert.SerializeObject(score); return(PartialView(tests)); }
/// <summary> /// Load user time plot partial views /// </summary> /// <param name="city"></param> /// <param name="state"></param> /// <param name="provider"></param> /// <returns></returns> public IActionResult UserTimePlotSection(string city, string state, string provider) { UserTimePlot utp = new UserTimePlot(); List <UserTimePlot> tests = utp.GetUserTestsOrdered(HomeController._database); //Prepare datapoints List <SpeedTimePlotGraph> speed1 = new List <SpeedTimePlotGraph>(); List <SpeedTimePlotGraph> speed2 = new List <SpeedTimePlotGraph>(); List <SpeedTimePlotGraph> speed3 = new List <SpeedTimePlotGraph>(); List <SpeedTimePlotGraph> speed4 = new List <SpeedTimePlotGraph>(); List <SpeedTimePlotGraph> speed5 = new List <SpeedTimePlotGraph>(); List <LoadtimePlotGraph> loadtime6 = new List <LoadtimePlotGraph>(); List <LoadtimePlotGraph> loadtime7 = new List <LoadtimePlotGraph>(); List <LoadtimePlotGraph> loadtime8 = new List <LoadtimePlotGraph>(); List <LoadtimePlotGraph> loadtime9 = new List <LoadtimePlotGraph>(); List <LoadtimePlotGraph> loadtime10 = new List <LoadtimePlotGraph>(); UserPlotKey upk = new UserPlotKey(); List <UserPlotKey> keys = upk.GetPlotKeys(HomeController._database); //Loop through tests and only get those from the top 5 for (int i = 0; i < tests.Count; i++) { //Hack version to allow 2 models at once-- not the best coding practice, but for the scope of project ok UserTimePlot plot = tests[i]; if (i < keys.Count) { plot.key = keys[i]; } if (plot.rank < 6) { //Convert to date to fit JavaScript format long longDate = ToJsonDate(plot.date); switch (plot.rank) { case 1: speed1.Add(new SpeedTimePlotGraph(longDate, plot.speed)); loadtime6.Add(new LoadtimePlotGraph(longDate, plot.loadtime.Seconds)); break; case 2: speed2.Add(new SpeedTimePlotGraph(longDate, plot.speed)); loadtime7.Add(new LoadtimePlotGraph(longDate, plot.loadtime.Seconds)); break; case 3: speed3.Add(new SpeedTimePlotGraph(longDate, plot.speed)); loadtime8.Add(new LoadtimePlotGraph(longDate, plot.loadtime.Seconds)); break; case 4: speed4.Add(new SpeedTimePlotGraph(longDate, plot.speed)); loadtime9.Add(new LoadtimePlotGraph(longDate, plot.loadtime.Seconds)); break; case 5: speed5.Add(new SpeedTimePlotGraph(longDate, plot.speed)); loadtime10.Add(new LoadtimePlotGraph(longDate, plot.loadtime.Seconds)); break; } } } //load speed datapoints ViewBag.Speed1 = JsonConvert.SerializeObject(speed1); ViewBag.Speed2 = JsonConvert.SerializeObject(speed2); ViewBag.Speed3 = JsonConvert.SerializeObject(speed3); ViewBag.Speed4 = JsonConvert.SerializeObject(speed4); ViewBag.Speed5 = JsonConvert.SerializeObject(speed5); //load loadtime datapoints ViewBag.Loadtime6 = JsonConvert.SerializeObject(loadtime6); ViewBag.Loadtime7 = JsonConvert.SerializeObject(loadtime7); ViewBag.Loadtime8 = JsonConvert.SerializeObject(loadtime8); ViewBag.Loadtime9 = JsonConvert.SerializeObject(loadtime9); ViewBag.Loadtime10 = JsonConvert.SerializeObject(loadtime10); return(PartialView(tests)); }