[longomatch] Export team stats by player in the excel
- From: Andoni Morales Alastruey <amorales src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [longomatch] Export team stats by player in the excel
- Date: Fri, 27 Jan 2012 22:07:35 +0000 (UTC)
commit 330e3e0e4a2e80da3553a31c9822b312fc20648b
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date: Thu Jan 26 08:01:12 2012 +0100
Export team stats by player in the excel
LongoMatch.Addins.COE/ExcelExporter.cs | 14 ++-
LongoMatch.Addins.COE/LongoMatch.Addins.COE.mdp | 3 +-
LongoMatch.Addins.COE/ProjectStatsSheet.cs | 3 +-
LongoMatch.Addins.COE/TeamStatsSheet.cs | 142 ++++++++++++++++++++
.../{TeamStatsSheets.cs => TimelineSheet.cs} | 9 +-
5 files changed, 157 insertions(+), 14 deletions(-)
---
diff --git a/LongoMatch.Addins.COE/ExcelExporter.cs b/LongoMatch.Addins.COE/ExcelExporter.cs
index addcbe2..901fdf7 100644
--- a/LongoMatch.Addins.COE/ExcelExporter.cs
+++ b/LongoMatch.Addins.COE/ExcelExporter.cs
@@ -88,21 +88,27 @@ public class EPPLUSExporter {
}
using (package = new ExcelPackage(newFile)) {
- TeamStatsSheets teamStats;
+ TimelineSheet timeline;
+ TeamStatsSheet teamStats;
+ ProjectStats stats = new ProjectStats(project);
ws = CreateSheet(package, Catalog.GetString("Project statistics"));
var statsSheet = new ProjectStatsSheet(ws, project);
- statsSheet.Fill();
+ statsSheet.Fill(stats);
ws = CreateSheet(package, project.LocalTeamTemplate.TeamName +
"(" + Catalog.GetString("Local Team") + ")");
- teamStats = new TeamStatsSheets(ws, project, Team.LOCAL);
+ teamStats = new TeamStatsSheet(ws, stats, Team.LOCAL);
teamStats.Fill();
ws = CreateSheet(package, project.VisitorTeamTemplate.TeamName +
"(" + Catalog.GetString("Visitor Team") + ")");
- teamStats = new TeamStatsSheets(ws, project, Team.VISITOR);
+ teamStats = new TeamStatsSheet(ws, stats, Team.VISITOR);
teamStats.Fill();
+
+ ws = CreateSheet(package, Catalog.GetString("Timeline"));
+ timeline = new TimelineSheet(ws, project);
+ timeline.Fill();
package.Save();
}
}
diff --git a/LongoMatch.Addins.COE/LongoMatch.Addins.COE.mdp b/LongoMatch.Addins.COE/LongoMatch.Addins.COE.mdp
index cdeb6c3..b555029 100644
--- a/LongoMatch.Addins.COE/LongoMatch.Addins.COE.mdp
+++ b/LongoMatch.Addins.COE/LongoMatch.Addins.COE.mdp
@@ -18,7 +18,8 @@
<File subtype="Code" buildaction="Compile" name="ExcelExporter.cs" />
<File subtype="Code" buildaction="Compile" name="Assembly.cs" />
<File subtype="Code" buildaction="Compile" name="ProjectStatsSheet.cs" />
- <File subtype="Code" buildaction="Compile" name="TeamStatsSheets.cs" />
+ <File subtype="Code" buildaction="Compile" name="TimelineSheet.cs" />
+ <File subtype="Code" buildaction="Compile" name="TeamStatsSheet.cs" />
</Contents>
<References>
<ProjectReference type="Gac" localcopy="True" refto="Mono.Addins, Version=0.6.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756" />
diff --git a/LongoMatch.Addins.COE/ProjectStatsSheet.cs b/LongoMatch.Addins.COE/ProjectStatsSheet.cs
index 388c8f1..d0d9b0e 100644
--- a/LongoMatch.Addins.COE/ProjectStatsSheet.cs
+++ b/LongoMatch.Addins.COE/ProjectStatsSheet.cs
@@ -35,10 +35,9 @@ public class ProjectStatsSheet
this.ws = ws;
}
- public void Fill() {
+ public void Fill(ProjectStats stats) {
int row = 1;
- ProjectStats stats = new ProjectStats(project);
row = FillMatchDescription (ws, row, stats);
row += 3;
row = FillTeamsData (ws, row, stats);
diff --git a/LongoMatch.Addins.COE/TeamStatsSheet.cs b/LongoMatch.Addins.COE/TeamStatsSheet.cs
new file mode 100644
index 0000000..64d7d93
--- /dev/null
+++ b/LongoMatch.Addins.COE/TeamStatsSheet.cs
@@ -0,0 +1,142 @@
+//
+// 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 System.Drawing;
+using Mono.Unix;
+
+using OfficeOpenXml;
+using OfficeOpenXml.Style;
+
+using LongoMatch.Common;
+using LongoMatch.Interfaces;
+using LongoMatch.Stats;
+using LongoMatch.Store;
+
+public class TeamStatsSheet
+{
+ ExcelWorksheet ws;
+ ProjectStats stats;
+ Team team;
+ Dictionary<Player, int> playerRow;
+
+ public TeamStatsSheet (ExcelWorksheet ws, ProjectStats stats, Team team)
+ {
+ this.ws = ws;
+ this.stats = stats;
+ this.team = team;
+ playerRow = new Dictionary<Player, int>();
+ }
+
+ public void Fill() {
+ FillStats(ws);
+ }
+
+ void FillStats (ExcelWorksheet ws) {
+ int categoryColumn = 2;
+ foreach (CategoryStats catStats in stats.CategoriesStats) {
+ int subcategoryWidth = 0;
+ int subcategoryColumn = categoryColumn;
+
+ foreach (SubCategoryStat subcatStats in catStats.SubcategoriesStats){
+ Dictionary<string, List<PlayersStats>> playersStats;
+ int optionColumn = subcategoryColumn;
+ int optionWidth = 0;
+ int statsWidth;
+
+ if (team == Team.LOCAL)
+ playersStats = subcatStats.LocalPlayersStats;
+ else
+ playersStats = subcatStats.VisitorPlayersStats;
+
+ foreach (string option in playersStats.Keys) {
+ List<PlayersStats> pStatsList = playersStats[option];
+ if (pStatsList.Count > 1) {
+ FillPlayerStatsSubcat(pStatsList, optionColumn);
+ }
+ statsWidth = 0;
+ foreach (PlayersStats pStats in pStatsList) {
+ foreach (Player player in pStats.Players.Keys) {
+ FillPlayersStats (player, pStats.Players[player], optionColumn + statsWidth);
+ }
+ statsWidth += 1;
+ }
+ FillOptionName(option, optionColumn, statsWidth);
+ optionWidth += statsWidth + 1;
+ optionColumn += statsWidth + 1;
+ }
+ optionWidth -= 1;
+ FillSubcategoryName(subcatStats.Name, subcategoryColumn, optionWidth);
+ subcategoryWidth += optionWidth + 1;
+ subcategoryColumn += subcategoryWidth;
+ }
+ subcategoryWidth -= 1;
+ FillCategoryName(catStats.Name, categoryColumn, subcategoryWidth);
+ categoryColumn += subcategoryWidth + 1;
+ }
+ }
+
+ void SetTitleAndColor (int row, int column, int width, string title, Color color) {
+ ws.Cells[row, column].Value = title;
+ ws.Cells[row, column].Style.Fill.PatternType = ExcelFillStyle.Solid;
+ ws.Cells[row, column].Style.Fill.BackgroundColor.SetColor(color);
+ ws.Cells[row, column, row, column + width - 1].Merge = true;
+ }
+
+ void FillOptionName(string name, int column, int width) {
+ if (width <= 0)
+ return;
+ SetTitleAndColor(3, column, width, name, Color.IndianRed);
+ ws.Column(column + width).Width = 2;
+ for (int i=column; i <= column + width - 1; i++)
+ ws.Column(i).AutoFit();
+ }
+
+ void FillSubcategoryName(string name, int column, int width) {
+ if (width <= 0)
+ return;
+ SetTitleAndColor(2, column, width, name, Color.MediumVioletRed);
+ }
+
+ void FillCategoryName(string name, int column, int width) {
+ if (width <= 0)
+ return;
+ SetTitleAndColor(1, column, width, name, Color.OrangeRed);
+ }
+
+ void FillPlayersStats(Player player, int count, int column) {
+ ws.Cells[GetPlayerRow(player), column].Value = count;
+ }
+
+ void FillPlayerStatsSubcat(List<PlayersStats> list, int column) {
+ int i = 0;
+ foreach (PlayersStats pStats in list) {
+ SetTitleAndColor(4, column + i, 1, pStats.Name, Color.PaleVioletRed);
+ i++;
+ }
+ }
+
+ int GetPlayerRow (Player player) {
+ if (!playerRow.ContainsKey(player)) {
+ int row = playerRow.Count + 5;
+ playerRow.Add(player, row);
+ ws.Cells[row, 1].Value = player.Name;
+ }
+ return playerRow[player];
+ }
+}
diff --git a/LongoMatch.Addins.COE/TeamStatsSheets.cs b/LongoMatch.Addins.COE/TimelineSheet.cs
similarity index 96%
rename from LongoMatch.Addins.COE/TeamStatsSheets.cs
rename to LongoMatch.Addins.COE/TimelineSheet.cs
index c542bf3..aef3113 100644
--- a/LongoMatch.Addins.COE/TeamStatsSheets.cs
+++ b/LongoMatch.Addins.COE/TimelineSheet.cs
@@ -28,20 +28,18 @@ using LongoMatch.Interfaces;
using LongoMatch.Stats;
using LongoMatch.Store;
-public class TeamStatsSheets
+public class TimelineSheet
{
Project project;
ExcelWorksheet ws;
- Team team;
int duration;
const int TIMELINE_START = 6;
- public TeamStatsSheets (ExcelWorksheet ws, Project project, Team team)
+ public TimelineSheet (ExcelWorksheet ws, Project project)
{
this.project = project;
this.ws = ws;
- this.team = team;
duration = (int) (project.Description.File.Length / 1000 / 60);
}
@@ -181,9 +179,6 @@ public class TeamStatsSheets
int time;
int catRow;
- if (!(play.Team == team || play.Team == Team.BOTH))
- continue;
-
/* Add the category's overal stats */
catRow = catsDict[ca];
time = TIMELINE_START + play.Start.Seconds / 60;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]