public CrmodStatParser(ILogger logger) { TeamOne = new MatchTeamStatDTO(); TeamTwo = new MatchTeamStatDTO(); log = logger; MatchResults = new MatchResultDTO(); PlayersNotLoggedIn = new Dictionary <string, int>(); }
public async Task <HttpResponseMessage> Post(MatchResultDTO matchResult) { if (matchResult != null) { // create a score for home and one for away // first, get the match ID Match match = await matchRepository.GetMatchByPlayers(matchResult.HomePlayerId, matchResult.AwayPlayerId); if (match != null) { // if we found the match, we verify if it has already been played, if it s the case, // only the admin can change the value then if (match.Played && !this.userTool.isUserInRole(AuthenticationRoles.AdministratorRole)) { return(Request.CreateErrorResponse(HttpStatusCode.Forbidden, "Only the administrator can modify a match already played.")); } // found the match, now update the scores and save them Score homeScore = new Score(); homeScore.MatchId = match.Id; homeScore.TeamPlayerId = matchResult.HomePlayerId; homeScore.Location = Location.Home; homeScore.Goals = matchResult.ScoreHome; var resultUpdateHome = await scoreRepository.UpdateFromMatchResult(homeScore); Score awayScore = new Score(); awayScore.MatchId = match.Id; awayScore.TeamPlayerId = matchResult.AwayPlayerId; awayScore.Location = Location.Away; awayScore.Goals = matchResult.ScoreAway; var resultUpdateAway = await scoreRepository.UpdateFromMatchResult(awayScore); if (resultUpdateHome && resultUpdateAway) { // also set the match to 'played' match.Played = true; match.Date = matchResult.Date; await matchRepository.Update(match.Id, match); } else { return(createErrorResponseWithMessage("There was a problem adding the score")); } } else { return(createErrorResponseWithMessage("There is no match with this criteria")); } } else { return(createErrorResponseWithMessage("Result is empty")); } return(Request.CreateResponse(HttpStatusCode.OK)); }
/// <summary> /// This method begings the parsing process. /// </summary> /// <param name="fileName"></param> /// <param name="fileToParse"></param> public void StartParsing(string fileName, string fileToParse) { try { logger.Info("Creating Match...."); MatchResults = new MatchResultDTO(); // for uniqueness, make matchId the filename. MatchResults.MatchId = fileName; // Set match date. // many of the database queries rely on this date format. Don't change unless you want smoke to do more work. MatchResults.MatchDate = DateTime.ParseExact(fileName.Split('-')[0], "yyyyMMddHHmmss", System.Globalization.CultureInfo.InvariantCulture); // read the whole file var text = File.ReadAllText(fileToParse); // we save the whole text file to the database in case we have to go back and reprocess matches. // For instance, if sometime in the future we want to move to a Cassandra database for easier querying we could process // each match text and store in the Cassandra database. MatchResults.MatchText = text; // persist match and log contents before parsing as a backup of raw data // if something goes terribly wrong during processing, the initial match data and raw file contents are persisted for reprocessing. logger.Info("Saving Match before parse...."); SaveMatchBeforeParsing(fileName, text); // Here is where we beging parsing the stat file. SplitMatchStats(text); ProcessMatchInfo(); ProcessTeamStats(); ProcessPlayerStats(); ProcessQuadStats(); ProcessBadStats(); ProcessEfficiencyStats(); ProcessKillStats(); // Do persistence // Save all stats PersistMatchData(); // Once the file has been parsed, we move the file to a "processed" directory File.Move(fileToParse, ProcessedDirectory + "/" + fileName + DateTime.Now.Ticks + ".processed"); } catch (Exception ex) { /* if something bad happens during parsing this catch block will catch the exception * and move the file to an error directory. */ File.Move(fileToParse, ErrorDirectory + "/" + fileName + DateTime.Now.Ticks + ".error"); logger.Error("Exception during processing: " + ex.ToString()); } }
public async Task <IndexResponse> PostMatch(MatchResultDTO match) { var asyncIndexResponse = await client.IndexDocumentAsync(match); if (asyncIndexResponse.IsValid) { await DiscordLogger.PostMessageToDiscordAsync($"New match posted: Match date: '{match.MatchDate}' with '{match.MatchMVP}' as the MVP!"); return(asyncIndexResponse); } else { await DiscordLogger.PostMessageToDiscordAsync($"Match data: '{match.Id}' could NOT posted to elastic"); return(asyncIndexResponse); } }
private static MatchModel mapToMatchModel(MatchResultDTO dataToMap) { var match = new MatchModel(); match.Id = dataToMap.Id; match.MatchDate = dataToMap.MatchDate; match.MapName = dataToMap.MapName; match.MatchTimeLimit = dataToMap.MatchTimeLimit; match.MatchType = dataToMap.MatchType; match.MatchMVP = dataToMap.MatchMVP; foreach (var team in dataToMap.ListOfTeams) { match.ListOfTeams.Add(team.Value); if (team.Value.TeamVerdict.Equals("win")) { match.Winner = team.Value.TeamColor; match.WinnerScore = team.Value.TeamTotalFrags; } else if (team.Value.TeamVerdict.Equals("lose")) { match.LoserScore = team.Value.TeamTotalFrags; } else { match.Winner = "tie"; } } foreach (var player in dataToMap.ListOfPlayers) { match.ListOfPlayers.Add(player.Value); } return(match); }