public static List <GameSnapshot> GetGameSnapShots(string csvText) { IList <RawEntry> entries = CsvImporter.GetEntries(csvText); List <GameSnapshot> snapshots = GameSnapshot.Factory(entries); return(snapshots); }
public static List <GameSnapshot> Factory(IList <RawEntry> entries) { var snapshots = new List <GameSnapshot>(); if (entries.Count == 0) { return(snapshots); } var expandedEntries = entries.Select(e => e).ToList(); expandedEntries.Add(expandedEntries.LastOrDefault()); //For making the last one count as if no change... for (int i = 1; i < expandedEntries.Count; i++) { var entry = expandedEntries[i - 1]; var nextEntry = expandedEntries[i]; var currTimeLeft = GetTotalTimeLeft(entry.Quarter, entry.TimeLeft); var nextTimeLeft = GetTotalTimeLeft(nextEntry.Quarter, nextEntry.TimeLeft); TimeSpan?elapsed = currTimeLeft - nextTimeLeft; var nextDiff = nextEntry.TeamScore - nextEntry.OponentScore; var currDiff = entry.TeamScore - entry.OponentScore; int snapshotScoreDiff = nextDiff - currDiff; var currScore = nextEntry.TeamScore - entry.TeamScore; var currOponentScore = nextEntry.OponentScore - entry.OponentScore; var snapshot = new GameSnapshot(entry.PlayerNumbers, entry.Quarter, entry.TimeLeft, currScore, currOponentScore, elapsed, snapshotScoreDiff: snapshotScoreDiff); snapshots.Add(snapshot); } return(snapshots); }