-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Put grade analsysis in one place and refactored the analysis of how a…
… team got its grade into separate classes.
- Loading branch information
Showing
9 changed files
with
157 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,29 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace ScoreParser { | ||
public class Games { | ||
private readonly ITeamManager _teamManager; | ||
|
||
public Games(ITeamManager teamManager) { | ||
_teamManager = teamManager; | ||
} | ||
|
||
private List<Game> games = new List<Game>(); | ||
|
||
public int Count { | ||
get { return games.Count; } | ||
} | ||
|
||
public void AddMultiple(string[] lines) { | ||
foreach (string gameDescription in lines) { | ||
Game game = new Game(_teamManager); | ||
game.InitFromGameDescription(gameDescription); | ||
games.Add(game); | ||
} | ||
} | ||
|
||
public IEnumerable<Game> GetGames() { | ||
return games; | ||
} | ||
} | ||
using System.Collections.Generic; | ||
|
||
namespace ScoreParser { | ||
public class GameManager : IGameManager { | ||
private readonly ITeamManager _teamManager; | ||
|
||
public GameManager(ITeamManager teamManager) { | ||
_teamManager = teamManager; | ||
} | ||
|
||
private List<Game> games = new List<Game>(); | ||
|
||
public int Count { | ||
get { return games.Count; } | ||
} | ||
|
||
public void AddMultiple(string[] lines) { | ||
foreach (string gameDescription in lines) { | ||
Game game = new Game(_teamManager); | ||
game.InitFromGameDescription(gameDescription); | ||
games.Add(game); | ||
} | ||
} | ||
|
||
public IEnumerable<Game> GetGames() { | ||
return games; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
namespace ScoreParser { | ||
public static class Grader { | ||
|
||
public static int GradeTeamInGame(Team team, Game game) { | ||
if (game.IsTie) | ||
return 0; | ||
|
||
if (team == game.Winner) | ||
return game.Loser.Wins; | ||
|
||
return -1*game.Winner.Losses; | ||
} | ||
|
||
public static TeamAnalysis GetTeamGradeAnalysis(Team team) { | ||
TeamAnalysis analysis = new TeamAnalysis(); | ||
int cumGrade = 0; | ||
foreach (Game game in team.GetGames()) { | ||
TeamGameAnalysis teamGameAnalysis = new TeamGameAnalysis(team, game); | ||
cumGrade += teamGameAnalysis.GameGrade; | ||
teamGameAnalysis.CumulativeGrade = cumGrade; | ||
analysis.AddTeamGameAnalysis(teamGameAnalysis); | ||
} | ||
return analysis; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace ScoreParser { | ||
public interface IGameManager { | ||
int Count { get; } | ||
void AddMultiple(string[] lines); | ||
IEnumerable<Game> GetGames(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace ScoreParser { | ||
public class TeamAnalysis { | ||
private List<TeamGameAnalysis> _teamGameAnalyses = new List<TeamGameAnalysis>(); | ||
|
||
public void AddTeamGameAnalysis(TeamGameAnalysis teamGameAnalysis) { | ||
_teamGameAnalyses.Add(teamGameAnalysis); | ||
} | ||
|
||
public IEnumerable<TeamGameAnalysis> GetGameAnalyses() { | ||
return _teamGameAnalyses; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
namespace ScoreParser { | ||
public class TeamGameAnalysis { | ||
public Game Game { get; private set; } | ||
public Team Team { get; private set; } | ||
public Team OtherTeam { get; private set; } | ||
public string RelationshipToOtherTeam { get; private set; } | ||
public int GameGrade { get; private set; } | ||
public int CumulativeGrade { get; set; } | ||
|
||
public TeamGameAnalysis(Team team, Game game) { | ||
Team = team; | ||
Game = game; | ||
|
||
if (team == game.Winner) { | ||
OtherTeam = game.Loser; | ||
RelationshipToOtherTeam = "defeated"; | ||
} | ||
else { | ||
OtherTeam = game.Winner; | ||
RelationshipToOtherTeam = "lost to"; | ||
} | ||
|
||
if (game.IsTie) { | ||
RelationshipToOtherTeam = "tied"; | ||
} | ||
|
||
GameGrade = Grader.GradeTeamInGame(team, game); | ||
} | ||
|
||
} | ||
} |