[longomatch] Add players stats
- From: Andoni Morales Alastruey <amorales src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [longomatch] Add players stats
- Date: Fri, 27 Jan 2012 22:07:30 +0000 (UTC)
commit e55035d8fb312959aa0d5d8a3ebc2555acef5836
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date: Thu Jan 26 08:00:35 2012 +0100
Add players stats
LongoMatch.Core/LongoMatch.Core.mdp | 1 +
LongoMatch.Core/Stats/CategoryStats.cs | 1 +
LongoMatch.Core/Stats/PlayersStats.cs | 44 ++++++++++++++++
LongoMatch.Core/Stats/ProjectStats.cs | 81 ++++++++++++++++++++++--------
LongoMatch.Core/Stats/SubCategoryStat.cs | 38 ++++++++++++++
5 files changed, 143 insertions(+), 22 deletions(-)
---
diff --git a/LongoMatch.Core/LongoMatch.Core.mdp b/LongoMatch.Core/LongoMatch.Core.mdp
index f2a9ce3..698b899 100644
--- a/LongoMatch.Core/LongoMatch.Core.mdp
+++ b/LongoMatch.Core/LongoMatch.Core.mdp
@@ -95,6 +95,7 @@
<File subtype="Code" buildaction="Compile" name="Stats/PercentualStat.cs" />
<File subtype="Code" buildaction="Compile" name="Stats/Stat.cs" />
<File subtype="Code" buildaction="Compile" name="Stats/SubCategoryStat.cs" />
+ <File subtype="Code" buildaction="Compile" name="Stats/PlayersStats.cs" />
</Contents>
<References>
<ProjectReference type="Gac" localcopy="True" refto="System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
diff --git a/LongoMatch.Core/Stats/CategoryStats.cs b/LongoMatch.Core/Stats/CategoryStats.cs
index 89d9e6b..4b9a2fa 100644
--- a/LongoMatch.Core/Stats/CategoryStats.cs
+++ b/LongoMatch.Core/Stats/CategoryStats.cs
@@ -41,6 +41,7 @@ namespace LongoMatch.Stats
public void AddSubcatStat (SubCategoryStat subcatStat) {
subcatStats.Add(subcatStat);
}
+
}
}
diff --git a/LongoMatch.Core/Stats/PlayersStats.cs b/LongoMatch.Core/Stats/PlayersStats.cs
new file mode 100644
index 0000000..5be1fc5
--- /dev/null
+++ b/LongoMatch.Core/Stats/PlayersStats.cs
@@ -0,0 +1,44 @@
+//
+// Copyright (C) 2012 Andoni Morales Alastruey
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+using System;
+using System.Collections.Generic;
+
+using LongoMatch.Store;
+
+namespace LongoMatch.Stats
+{
+ public class PlayersStats
+ {
+ public PlayersStats (string name, Dictionary<Player, int> playersStats)
+ {
+ Players = playersStats;
+ Name = name;
+ }
+
+ public string Name {
+ get;
+ set;
+ }
+
+ public Dictionary<Player, int> Players {
+ get;
+ set;
+ }
+ }
+}
+
diff --git a/LongoMatch.Core/Stats/ProjectStats.cs b/LongoMatch.Core/Stats/ProjectStats.cs
index d26503c..75eecef 100644
--- a/LongoMatch.Core/Stats/ProjectStats.cs
+++ b/LongoMatch.Core/Stats/ProjectStats.cs
@@ -34,7 +34,6 @@ namespace LongoMatch.Stats
{
catStats = new List<CategoryStats>();
- UpdateStats (project);
ProjectName = project.Description.Title;
Date = project.Description.MatchDate;
@@ -42,6 +41,8 @@ namespace LongoMatch.Stats
VisitorTeam = project.VisitorTeamTemplate.TeamName;
Competition = project.Description.Competition;
Season = project.Description.Season;
+
+ UpdateStats (project);
}
public string ProjectName {
@@ -110,19 +111,13 @@ namespace LongoMatch.Stats
if (subcat is TagSubCategory) {
foreach (string option in subcat.ElementsDesc()) {
List<Play> subcatPlays;
- int count;
StringTag tag;
- tag = new StringTag();
- tag.SubCategory = subcat;
- tag.Value = option;
-
+ tag = new StringTag{SubCategory=subcat, Value=option};
subcatPlays = plays.Where(p => p.Tags.Tags.Contains(tag)).ToList();
- count = subcatPlays.Count();
- CountPlaysInTeam(subcatPlays, out localTeamCount, out visitorTeamCount);
- PercentualStat pStat = new PercentualStat(option, count, localTeamCount,
- visitorTeamCount, stats.TotalCount);
- subcatStat.AddOptionStat(pStat);
+ GetSubcategoryStats(subcatPlays, subcatStat, option,
+ stats.TotalCount, out localTeamCount, out visitorTeamCount);
+ GetPlayersStats(project, subcatPlays, option, subcatStat, cat);
}
}
@@ -133,24 +128,66 @@ namespace LongoMatch.Stats
foreach (Team team in teams) {
List<Play> subcatPlays;
- int count;
TeamTag tag;
- tag = new TeamTag();
- tag.SubCategory = subcat;
- tag.Value = team;
-
+ tag = new TeamTag{SubCategory=subcat, Value=team};
subcatPlays = plays.Where(p => p.Teams.Tags.Contains(tag)).ToList();
- count = subcatPlays.Count();
- CountPlaysInTeam(subcatPlays, out localTeamCount, out visitorTeamCount);
- PercentualStat pStat = new PercentualStat(team.ToString(), count, localTeamCount,
- visitorTeamCount, stats.TotalCount);
- subcatStat.AddOptionStat(pStat);
+ GetSubcategoryStats(subcatPlays, subcatStat, team.ToString(),
+ stats.TotalCount, out localTeamCount, out visitorTeamCount);
}
- }
+ }
+ }
+ }
+ }
+
+ void GetSubcategoryStats (List<Play> subcatPlays, SubCategoryStat subcatStat, string desc,
+ int totalCount, out int localTeamCount, out int visitorTeamCount)
+ {
+ int count;
+
+ count = subcatPlays.Count();
+ CountPlaysInTeam(subcatPlays, out localTeamCount, out visitorTeamCount);
+ PercentualStat pStat = new PercentualStat(desc, count, localTeamCount,
+ visitorTeamCount, totalCount);
+ subcatStat.AddOptionStat(pStat);
+ }
+
+ void GetPlayersStats (Project project, List<Play> subcatPlays, string optionName,
+ SubCategoryStat subcatStat, Category cat)
+ {
+ foreach (ISubCategory subcat in cat.SubCategories) {
+ PlayerSubCategory playerSubcat;
+ Dictionary<Player, int> localPlayerCount = new Dictionary<Player, int>();
+ Dictionary<Player, int> visitorPlayerCount = new Dictionary<Player, int>();
+
+ if (!(subcat is PlayerSubCategory))
+ continue;
+
+ playerSubcat = subcat as PlayerSubCategory;
+
+ if (playerSubcat.Contains(Team.LOCAL) || playerSubcat.Contains(Team.BOTH)){
+ foreach (Player player in project.LocalTeamTemplate) {
+ localPlayerCount.Add(player, GetPlayerCount(subcatPlays, player, subcat as PlayerSubCategory));
+ }
+ subcatStat.AddPlayersStats(optionName, subcat.Name, Team.LOCAL, localPlayerCount);
+ }
+
+ if (playerSubcat.Contains(Team.VISITOR) || playerSubcat.Contains(Team.BOTH)){
+ foreach (Player player in project.VisitorTeamTemplate) {
+ visitorPlayerCount.Add(player, GetPlayerCount(subcatPlays, player, subcat as PlayerSubCategory));
+ }
+ subcatStat.AddPlayersStats(optionName, subcat.Name, Team.VISITOR, visitorPlayerCount);
}
}
}
+
+ int GetPlayerCount(List<Play> plays, Player player, PlayerSubCategory subcat)
+ {
+ PlayerTag tag;
+
+ tag = new PlayerTag{SubCategory=subcat, Value=player};
+ return plays.Where(p => p.Players.Contains(tag)).Count();
+ }
}
}
diff --git a/LongoMatch.Core/Stats/SubCategoryStat.cs b/LongoMatch.Core/Stats/SubCategoryStat.cs
index d1b090c..ccfd341 100644
--- a/LongoMatch.Core/Stats/SubCategoryStat.cs
+++ b/LongoMatch.Core/Stats/SubCategoryStat.cs
@@ -18,6 +18,7 @@
using System;
using System.Collections.Generic;
+using LongoMatch.Common;
using LongoMatch.Interfaces;
using LongoMatch.Store;
@@ -27,11 +28,16 @@ namespace LongoMatch.Stats
{
List<PercentualStat> optionStats;
+ Dictionary<string, List<PlayersStats>> localPlayersStats;
+ Dictionary<string, List<PlayersStats>> visitorPlayersStats;
public SubCategoryStat (string name)
{
Name = name;
optionStats = new List<PercentualStat>();
+ localPlayersStats = new Dictionary<string, List<PlayersStats>>();
+ visitorPlayersStats = new Dictionary<string, List<PlayersStats>>();
+
}
public string Name {
@@ -45,9 +51,41 @@ namespace LongoMatch.Stats
}
}
+ public Dictionary<string, List<PlayersStats>> LocalPlayersStats {
+ get {
+ return localPlayersStats;
+ }
+ }
+
+ public Dictionary<string, List<PlayersStats>> VisitorPlayersStats {
+ get {
+ return visitorPlayersStats;
+ }
+ }
+
public void AddOptionStat (PercentualStat stat) {
optionStats.Add(stat);
}
+
+ public void AddPlayersStats (string optionName, string playerSubcatName, Team team,
+ Dictionary<Player, int> playersCount)
+ {
+ Dictionary<string, List<PlayersStats>> playersStats;
+
+ if (team == Team.LOCAL)
+ playersStats = localPlayersStats;
+ else
+ playersStats = visitorPlayersStats;
+
+ PlayersStats stats = new PlayersStats(playerSubcatName, playersCount);
+ if (playersStats.ContainsKey(optionName)) {
+ playersStats[optionName].Add(stats);
+ } else{
+ List<PlayersStats> list = new List<PlayersStats>();
+ list.Add(stats);
+ playersStats.Add(optionName, list);
+ }
+ }
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]