// Get the result of a match public async Task <HttpResponseMessage> Get(int id) { MatchResultViewModel item = await this.matchViewRepository.Get(id); if (item == null) { return(Request.CreateResponse(HttpStatusCode.NotFound)); } return(Request.CreateResponse(HttpStatusCode.OK, item)); }
public async Task <ActionResult <MatchResultViewModel> > ReportMatch([FromBody] MatchResultViewModel reportMatch, CancellationToken ct = default(CancellationToken)) { reportMatch = await this._supervisor.ReportMatchAsync(reportMatch, ct); if (reportMatch == null) { return(BadRequest(Errors.AddErrorToModelState(ErrorCodes.MatchResult, ErrorDescriptions.MatchResulFailure, ModelState))); } return(new JsonResult(reportMatch)); }
public static void ExportToConsole(MatchResultViewModel vm) { var sortedVM = from player in vm.PlayerResults where player.FinishPosition != 0 orderby player.FinishPosition select player; Console.WriteLine($"{"Pos.",-8}{"Name",-24}{"Grid",-8}{"Tyres",-10}" + $"{"Best",-16}{"Time",-16}{"Penalty",-8}{"Points",8}"); foreach (var player in sortedVM) { Console.WriteLine($"{player.FinishPosition,-8}{player.Name,-24}{player.GridPosition,-8}{player.TyreStintsString,-10}" + $"{player.FastestLapString,-16}{player.FinishTimeString,-16}{player.PenaltyString,-8}{player.Point,8}"); } }
private static void StartListener() { UdpClient listener = new UdpClient(listenPort); IPAddress ip = IPAddress.Parse(ipString); IPEndPoint groupEP = new IPEndPoint(ip, listenPort); ResultVM = new MatchResultViewModel(); var p = new Packet(); var sp = new SessionPacket(); int sTick = -1; int pTick = -1; bool isQualiStated = false; bool isRaceStated = false; bool isPlayerStated = false; bool isRacing = true; try { Console.WriteLine($"{DateTime.Now:t} Waiting for broadcast on {ipString}:{listenPort}"); while (true) { byte[] bytes = listener.Receive(ref groupEP); p.LoadBytes(bytes); if (p.PacketType == PacketType.FinalClassification) // once when Qualifying/Race is finished { if (!isRacing && !isQualiStated) { isQualiStated = true; ResultVM.LoadQualiData(bytes); Console.WriteLine($"{DateTime.Now:t} Qualifying time has been recorded."); } else if (isRacing && !isRaceStated) { isRaceStated = true; ResultVM.LoadRaceData(bytes); Console.WriteLine($"{DateTime.Now:t} Players in race : {ResultVM.NumberOfPlayers}"); DataExport.ExportToExcel(ResultVM); DataExport.ExportToConsole(ResultVM); Console.WriteLine($"{DateTime.Now:t} Race result has been exported to Excel file."); } } else if (p.PacketType == PacketType.Session) { sTick = (sTick + 1) % 60; // 2 times per sec; check once per 30s if (sTick != 0) { continue; } sp.LoadBytes(bytes); // SessionType.ShortQualifying actually = 7 ??? if ((int)sp.SessionTypeMode == 7 || sp.SessionTypeMode == SessionPacket.SessionType.OneShotQualifying) { if (isRacing) // First detection of quali session { Console.WriteLine($"{DateTime.Now:t} Current session : Qualifying"); isRacing = false; } } else if (sp.SessionTypeMode == SessionPacket.SessionType.Race || sp.SessionTypeMode == SessionPacket.SessionType.Race2) { if (!isRacing) // First detection of race session { Console.WriteLine($"{DateTime.Now:t} Current session : Race"); isRacing = true; } } } #region refresh name (enabled) else if (p.PacketType == PacketType.Participants) { pTick = (pTick + 1) % 6; // once every 5s; check once per 30s if (pTick != 0) { continue; } ResultVM.LoadParticipantData(bytes); if (!isPlayerStated) { Console.WriteLine($"{DateTime.Now:t} Player names have been recorded."); isPlayerStated = true; } } #endregion // Console.WriteLine($"Received broadcast from {groupEP} :"); } } catch (SocketException e) { Console.WriteLine($"{DateTime.Now:T} {e}"); } finally { listener.Close(); } }
public static void ExportToExcel(MatchResultViewModel vm) { #region initialize workbook and set font colors string templatePath = @"template.xlsx"; string filePath = $"{DateTime.Now:yyyyMMdd-HHmm}.xlsx"; var stream = File.OpenRead(templatePath); IWorkbook workbook = new XSSFWorkbook(stream); ISheet sheet = workbook.GetSheetAt(0); stream.Close(); //var whiteFont = workbook.CreateFont(); //whiteFont.FontName = "Segoe UI Symbol"; //whiteFont.FontHeightInPoints = 11; //whiteFont.Color = 0; //var redFont = workbook.CreateFont(); //redFont.FontName = "Segoe UI Symbol"; //redFont.FontHeightInPoints = 11; //redFont.Color = 2; //var greenFont = workbook.CreateFont(); //greenFont.FontName = "Segoe UI Symbol"; //greenFont.FontHeightInPoints = 11; //greenFont.Color = 3; //var purpleFont = workbook.CreateFont(); //purpleFont.FontName = "Titillium Web SemiBold"; //purpleFont.FontHeightInPoints = 11; //purpleFont.Color = 20; #endregion for (int i = 0; i < 22; i++) { var player = vm.PlayerResults[i]; if (player.FinishPosition == 0) { continue; } // driver does not exist #region write data to workbook IRow row = sheet.GetRow(player.FinishPosition); if (player.Name.Length > 0) { row.GetCell(1).SetCellValue(player.Name); } row.GetCell(2).SetCellValue(player.QualiTimeString); row.GetCell(3).SetCellValue(player.GridPosition); int positionGained = player.GridPosition - player.FinishPosition; var cellGrid = row.GetCell(4); var cellPosGained = row.GetCell(5); if (positionGained > 0) { cellGrid.SetCellValue("▲"); cellPosGained.SetCellValue(positionGained); } else if (positionGained < 0) { cellGrid.SetCellValue("▼"); cellPosGained.SetCellValue(-positionGained); } else { cellPosGained.SetCellValue(0); } row.GetCell(6).SetCellValue(player.TyreStintsString); row.GetCell(7).SetCellValue(player.FastestLapString); //if (item.BestLapTimeSeconds == fastestLapOfTheRace) //{ // row.GetCell(7).CellStyle.SetFont(purpleFont); //} row.GetCell(8).SetCellValue(player.FinishTimeString); row.GetCell(9).SetCellValue(player.PenaltyString); row.GetCell(10).SetCellValue(player.Point); #endregion } #region export to Excel file var outputStream = File.Create(filePath); workbook.Write(outputStream); outputStream.Close(); #endregion }
public void TearDown() { model = null; }
public void SetUp() { model = new MatchResultViewModel(); }
public ActionResult Edit(MatchResultViewModel model) { if (ModelState.IsValid) { try { model.MapMvps(); // Should validation methods go into the view model? model.ValidateFixture(); model.ValidatePlayerStats(); // I'm not particularly happy using transactions within a controller but at present, // because saving a match result seems to require the use of several services rather // than one, I can't think of a better way to do it // EFCachingProvider doesn't support TransactionScope out of the box so changed source with the following https://gist.github.com/797390 using (TransactionScope scope = new TransactionScope()) { Fixture fixtureToUpdate = fixtureService.Get(model.FixtureId); fixtureToUpdate = model.MapToFixture(fixtureToUpdate); // Save fixtures matchResultService.SaveMatchResult(fixtureToUpdate, membershipService.GetLoggedInUser(), model.ForfeitingTeamId); // Save all player stats including fixture, season, league and career stats matchResultService.SaveMatchStats(model.HasPlayerStats, model.HomePlayerStats, fixtureToUpdate.HomeTeamLeague, fixtureToUpdate); matchResultService.SaveMatchStats(model.HasPlayerStats, model.AwayPlayerStats, fixtureToUpdate.AwayTeamLeague, fixtureToUpdate); scope.Complete(); } SuccessMessage(FormMessages.SaveSuccess); // I really dislike doing this, but it's an easy win so I'll turn a blind eye for now if (membershipService.IsSiteAdmin(membershipService.GetLoggedInUserName())) { return(RedirectToAction("Index", "Fixtures", new { area = "Admin" })); } return(RedirectToAction("Index")); } catch (MatchResultScoresSameException) { ErrorMessage(FormMessages.MatchResultScoresSame); } catch (MatchResultZeroTeamScoreException) { ErrorMessage(FormMessages.MatchResultZeroTeamScore); } catch (MatchResultMaxPlayersExceededException) { ErrorMessage(FormMessages.MatchResultMaxPlayersExceeded); } catch (MatchResultLessThanFivePlayersEachTeamException) { ErrorMessage(FormMessages.MatchResultFivePlayersEachTeam); } catch (MatchResultSumOfScoresDoesNotMatchTotalException) { ErrorMessage(FormMessages.MatchResultSumScoreDoesNotMatch); } catch (MatchResultNoMvpException) { ErrorMessage(FormMessages.MatchResultNoMvp); } catch (MatchResultNoStatsMoreThanZeroPlayersException) { ErrorMessage(FormMessages.MatchResultNoStatsZeroPlayers); } } return(View(model)); }