Skip to content

Commit bc503d0

Browse files
authored
Merge pull request #8 from jsTron/develop
Refactor to use three period logs
2 parents caf0ee2 + f106c47 commit bc503d0

4 files changed

Lines changed: 89 additions & 167 deletions

File tree

ReboundLogParser/ReboundLogParser/MainForm.cs

Lines changed: 79 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ public partial class MainForm : Form
2727
private List<ComboBox> _homePlayerBoxes;
2828
private List<ComboBox> _awayPlayerBoxes;
2929
private List<Match> _parsedLogs = new List<Match>();
30-
private Match _match;
3130

3231
public MainForm()
3332
{
@@ -124,6 +123,7 @@ private bool LoadAndParseLogFiles(List<string> fileNames = null)
124123
{
125124
bool success = false;
126125
fileNames = fileNames ?? new List<string>();
126+
_parsedLogs.Clear();
127127
foreach (var fileName in fileNames)
128128
{
129129
success = ParseJson(fileName);
@@ -184,10 +184,10 @@ private void PopulateDataGrid()
184184

185185
private bool ParseJson(string fileName)
186186
{
187-
_match = null;
187+
Match parsedPeriod = null;
188188
try
189189
{
190-
_match = JsonConvert.DeserializeObject<Match>(File.ReadAllText(fileName));
190+
parsedPeriod = JsonConvert.DeserializeObject<Match>(File.ReadAllText(fileName));
191191
}
192192
catch (JsonReaderException jex)
193193
{
@@ -200,43 +200,70 @@ private bool ParseJson(string fileName)
200200
return false;
201201
}
202202

203-
_parsedLogs.Add(_match);
203+
_parsedLogs.Add(parsedPeriod);
204204

205205
return true;
206206
}
207207

208208
private bool TabulateSelectedLogs()
209209
{
210210
_parsedLogs.Sort(delegate (Match m1, Match m2) { return m1.CurrentPeriod.CompareTo(m2.CurrentPeriod); });
211-
foreach (Match o1 in _parsedLogs)
211+
Match period3 = _parsedLogs.Last();
212+
213+
foreach (Player player in period3.Players)
212214
{
213-
_overTime = CheckOvertime(o1);
214-
_homeScore += o1.Score.Home;
215-
_awayScore += o1.Score.Away;
216-
_period = int.Parse(o1.CurrentPeriod);
217-
_currentPeriod = o1.CurrentPeriod;
218-
foreach (Player player in o1.Players)
215+
// Get and store period player stat sums
216+
var sums = new List<PlayerStatSums>();
217+
foreach (Match m in _parsedLogs)
219218
{
220-
var isHomeTeam = player.Team == "home";
221-
var teamToBuild = isHomeTeam ? _homeTeamPlayers : _awayTeamPlayers;
222-
if (PlayerExists(player, teamToBuild))
219+
var playerSum = new PlayerStatSums();
220+
playerSum.GameUserId = player.GameUserId;
221+
playerSum.CurrentPeriod = m.CurrentPeriod;
222+
try
223223
{
224-
for (int p = 0; p < teamToBuild.Count; p++)
225-
{
226-
if (teamToBuild[p].PlayerName == player.Username)
227-
{
228-
teamToBuild[p].addValues(player);
229-
}
230-
}
224+
playerSum.StatSum = SumPlayerStats(m.Players.Single(p => p.GameUserId.Equals(player.GameUserId)));
225+
}
226+
catch
227+
{
228+
continue;
231229
}
232-
else
230+
231+
sums.Add(playerSum);
232+
}
233+
234+
int periodsPlayed = 1;
235+
if (sums.Count > 1)
236+
{
237+
for (int i = 1; i < sums.Count; i++)
233238
{
234-
teamToBuild.Add(new stats(player));
239+
if (!sums[i].StatSum.Equals(sums[i - 1].StatSum))
240+
{
241+
periodsPlayed++;
242+
}
235243
}
236244
}
237-
_homeTeamPlayers.Sort(delegate (stats c1, stats c2) { return c1.PlayerName.CompareTo(c2.PlayerName); });
238-
_awayTeamPlayers.Sort(delegate (stats c1, stats c2) { return c1.PlayerName.CompareTo(c2.PlayerName); });
245+
else
246+
{
247+
periodsPlayed = 1;
248+
}
249+
250+
// Save player periods played
251+
player.Stats.GamesPlayed = periodsPlayed;
252+
}
253+
254+
_overTime = CheckOvertime(period3);
255+
_homeScore += period3.Score.Home;
256+
_awayScore += period3.Score.Away;
257+
_period = int.Parse(period3.CurrentPeriod);
258+
_currentPeriod = period3.CurrentPeriod;
259+
foreach (Player player in period3.Players)
260+
{
261+
var isHomeTeam = player.Team == "home";
262+
var teamToBuild = isHomeTeam ? _homeTeamPlayers : _awayTeamPlayers;
263+
teamToBuild.Add(new stats(player));
239264
}
265+
_homeTeamPlayers.Sort(delegate (stats c1, stats c2) { return c1.PlayerName.CompareTo(c2.PlayerName); });
266+
_awayTeamPlayers.Sort(delegate (stats c1, stats c2) { return c1.PlayerName.CompareTo(c2.PlayerName); });
240267

241268
return true;
242269
}
@@ -289,17 +316,34 @@ private bool CheckOvertime(Match statsObject)
289316
return returnBool;
290317
}
291318

292-
static bool PlayerExists(Player passedPlayer, List<stats> playerArray)
319+
public double SumPlayerStats(Player player)
293320
{
294-
bool returnValue = false;
295-
for (int j = 0; j < playerArray.Count; j++)
296-
{
297-
if (playerArray[j].PlayerName == passedPlayer.Username)
298-
{
299-
returnValue = true;
300-
}
301-
}
302-
return returnValue;
321+
double sum = player.Stats.Assists +
322+
player.Stats.Blocks +
323+
player.Stats.ConcededGoals +
324+
player.Stats.ContributedGoals +
325+
player.Stats.FaceoffsLost +
326+
player.Stats.FaceoffsWon +
327+
player.Stats.GamesPlayed +
328+
player.Stats.GameWinningGoals +
329+
player.Stats.Goals +
330+
player.Stats.Losses +
331+
player.Stats.OvertimeLosses +
332+
player.Stats.OvertimeWins +
333+
player.Stats.Passes +
334+
player.Stats.PossessionTimeSec +
335+
player.Stats.PostHits +
336+
player.Stats.PrimaryAssists +
337+
player.Stats.Saves +
338+
player.Stats.Score +
339+
player.Stats.SecondaryAssists +
340+
player.Stats.Shots +
341+
player.Stats.Shutouts +
342+
player.Stats.ShutoutsAgainst +
343+
player.Stats.Takeaways +
344+
player.Stats.Turnovers +
345+
player.Stats.Wins;
346+
return sum;
303347
}
304348

305349
private async void TeamPlayersLoadButton_Click(object sender, EventArgs e)

ReboundLogParser/ReboundLogParser/Match.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,11 @@ public class Stats
8282
[JsonProperty("overtime_losses")]
8383
public double OvertimeLosses { get; set; }
8484
}
85+
86+
public class PlayerStatSums
87+
{
88+
public string GameUserId { get; set; }
89+
public string CurrentPeriod { get; set; }
90+
public double StatSum { get; set; }
91+
}
8592
}

ReboundLogParser/ReboundLogParser/Properties/AssemblyInfo.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
[assembly: AssemblyConfiguration("")]
1111
[assembly: AssemblyCompany("")]
1212
[assembly: AssemblyProduct("ReboundLogParser")]
13-
[assembly: AssemblyCopyright("Copyright © 2022")]
13+
[assembly: AssemblyCopyright("Copyright © 2023")]
1414
[assembly: AssemblyTrademark("")]
1515
[assembly: AssemblyCulture("")]
1616

@@ -32,5 +32,5 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("6.1.0.0")]
36-
[assembly: AssemblyFileVersion("6.1.0.0")]
35+
[assembly: AssemblyVersion("6.3.0.0")]
36+
[assembly: AssemblyFileVersion("6.3.0.0")]

ReboundLogParser/ReboundLogParser/stats.cs

Lines changed: 0 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -164,135 +164,6 @@ public stats(Player player)
164164
}
165165
}
166166

167-
public void addValues(Player player)
168-
{
169-
try
170-
{
171-
Goals += player.Stats.Goals;
172-
}
173-
catch
174-
{
175-
Goals += 0;
176-
}
177-
178-
try
179-
{
180-
Primary_assists += player.Stats.PrimaryAssists;
181-
}
182-
catch
183-
{
184-
Primary_assists += 0;
185-
}
186-
187-
try
188-
{
189-
Sec_assists += player.Stats.SecondaryAssists;
190-
}
191-
catch
192-
{
193-
Sec_assists += 0;
194-
}
195-
196-
try
197-
{
198-
Shots += player.Stats.Shots;
199-
}
200-
catch
201-
{
202-
Shots += 0;
203-
}
204-
205-
try
206-
{
207-
Saves += player.Stats.Saves;
208-
}
209-
catch
210-
{
211-
Saves += 0;
212-
}
213-
214-
try
215-
{
216-
Faceoffs_won += player.Stats.FaceoffsWon;
217-
}
218-
catch
219-
{
220-
Faceoffs_won += 0;
221-
}
222-
223-
try
224-
{
225-
Faceoffs_lost += player.Stats.FaceoffsLost;
226-
}
227-
catch
228-
{
229-
Faceoffs_lost += 0;
230-
}
231-
232-
try
233-
{
234-
Takeaways += player.Stats.Takeaways;
235-
}
236-
catch
237-
{
238-
Takeaways += 0;
239-
}
240-
241-
try
242-
{
243-
Turnovers += player.Stats.Turnovers;
244-
}
245-
catch
246-
{
247-
Turnovers += 0;
248-
}
249-
250-
try
251-
{
252-
Post_hits += player.Stats.PostHits;
253-
}
254-
catch
255-
{
256-
Post_hits += 0;
257-
}
258-
259-
try
260-
{
261-
Passes += player.Stats.Passes;
262-
}
263-
catch
264-
{
265-
Passes += 0;
266-
}
267-
268-
try
269-
{
270-
Blocks += player.Stats.Blocks;
271-
}
272-
catch
273-
{
274-
Blocks += 0;
275-
}
276-
277-
try
278-
{
279-
GW_Goals += player.Stats.GameWinningGoals;
280-
}
281-
catch
282-
{
283-
GW_Goals += 0;
284-
}
285-
286-
try
287-
{
288-
Possession_Time += player.Stats.PossessionTimeSec;
289-
}
290-
catch
291-
{
292-
Possession_Time += 0;
293-
}
294-
}
295-
296167
public double GetPropertyValueByEnum(StatsEnum enumValue)
297168
{
298169
Dictionary<StatsEnum, object> kvp = new Dictionary<StatsEnum, object>()

0 commit comments

Comments
 (0)