[longomatch] Add game units stats in the excel



commit ab06c9aae687245db3438ca720d9fd0b98566320
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Mon Feb 6 03:06:27 2012 +0100

    Add game units stats in the excel

 LongoMatch.Addins.COE/ExcelExporter.cs          |    6 ++
 LongoMatch.Addins.COE/GameUnitsStatsSheet.cs    |  105 +++++++++++++++++++++++
 LongoMatch.Addins.COE/LongoMatch.Addins.COE.mdp |    1 +
 LongoMatch.Addins.COE/ProjectStatsSheet.cs      |    3 +
 LongoMatch.Addins.COE/TeamStatsSheet.cs         |    3 +
 LongoMatch.Addins.COE/TimelineSheet.cs          |   25 ++----
 6 files changed, 126 insertions(+), 17 deletions(-)
---
diff --git a/LongoMatch.Addins.COE/ExcelExporter.cs b/LongoMatch.Addins.COE/ExcelExporter.cs
index 901fdf7..ffe7d2b 100644
--- a/LongoMatch.Addins.COE/ExcelExporter.cs
+++ b/LongoMatch.Addins.COE/ExcelExporter.cs
@@ -90,6 +90,7 @@ public class EPPLUSExporter {
 		using (package = new ExcelPackage(newFile)) {
 			TimelineSheet timeline;
 			TeamStatsSheet teamStats;
+			GameUnitsStatsSheet gu;
 			ProjectStats stats = new ProjectStats(project);
 			
 			ws = CreateSheet(package, Catalog.GetString("Project statistics"));
@@ -109,6 +110,11 @@ public class EPPLUSExporter {
 			ws = CreateSheet(package, Catalog.GetString("Timeline"));
 			timeline = new TimelineSheet(ws, project);
 			timeline.Fill();
+			
+			ws = CreateSheet(package, Catalog.GetString("Game units"));
+			gu = new GameUnitsStatsSheet(ws, stats);
+			gu.Fill();
+			
 			package.Save();
 		}
 	}
diff --git a/LongoMatch.Addins.COE/GameUnitsStatsSheet.cs b/LongoMatch.Addins.COE/GameUnitsStatsSheet.cs
new file mode 100644
index 0000000..5214f6f
--- /dev/null
+++ b/LongoMatch.Addins.COE/GameUnitsStatsSheet.cs
@@ -0,0 +1,105 @@
+// 
+//  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.Stats;
+using LongoMatch.Store;
+
+public class GameUnitsStatsSheet
+{
+	ProjectStats stats;
+	ExcelWorksheet ws;
+	
+	public GameUnitsStatsSheet (ExcelWorksheet ws, ProjectStats stats)
+	{
+		this.stats = stats;
+		this.ws = ws;
+	}
+	
+	public void Fill() {
+		int row = 1;
+		
+		row = FillGameUnitsStats (stats.GameUnitsStats, row);
+		row = FillFirstLevelGameUnitsStats (stats.GameUnitsStats, row);
+	}
+	
+	void SetColoredHeader (string title, int row, int column, int width=1) {
+		ws.Cells[row, column].Value = title;
+		ws.Cells[row, column].Style.Fill.PatternType =  ExcelFillStyle.Solid;	
+		ws.Cells[row, column].Style.Fill.BackgroundColor.SetColor(Color.CadetBlue);
+		if (width > 1) {
+		 ws.Cells[row, column, row, column + width - 1].Merge = true;	
+		}
+	}
+	
+	int FillHeaders (int row) {
+		SetColoredHeader(Catalog.GetString("Name"), 1, 1);
+		SetColoredHeader(Catalog.GetString("Count"), 1, 2);
+		SetColoredHeader(Catalog.GetString("Total Time"), 1, 3, 2);
+		SetColoredHeader(Catalog.GetString("Played Time"), 1, 5, 2);
+		SetColoredHeader(Catalog.GetString("Paused Time"), 1, 7, 2);
+		for (int i=3; i<9; i++) {
+			SetColoredHeader(Catalog.GetString("Average"), 2, i);
+			i++;
+			SetColoredHeader(Catalog.GetString("Deviation"), 2, i);
+		}
+		row += 2;
+		return row;
+	}
+	
+	int FillGameUnitsStats (GameUnitsStats stats, int row) {
+		row = FillHeaders(row);
+		
+		Dictionary<GameUnit, GameUnitStatsNode> gameUnitsNodes  = stats.GameUnitNodes;
+		foreach (GameUnit gu in gameUnitsNodes.Keys) {
+			row = FillStats (gu.Name, gameUnitsNodes[gu], row);
+		}
+		return row;
+	}
+	
+	int FillStats (string name, GameUnitStatsNode guStats, int row) {
+		ws.Cells[row, 1].Value = name;
+		ws.Cells[row, 2].Value = guStats.Count;
+		ws.Cells[row, 3].Value = guStats.AverageDuration / (float)1000;
+		ws.Cells[row, 4].Value = guStats.DurationTimeStdDeviation / 1000;
+		ws.Cells[row, 5].Value = guStats.AveragePlayingTime / (float)1000;
+		ws.Cells[row, 6].Value = guStats.PlayingTimeStdDeviation / 1000;
+		ws.Cells[row, 7].Value = guStats.AveragePausedTime / (float)1000;
+		ws.Cells[row, 8].Value = guStats.PausedTimeStdDeviation / 1000;
+		row ++;
+		return row;
+	}
+	
+	int FillFirstLevelGameUnitsStats (GameUnitsStats stats, int row) {
+		int i=1;
+		
+		row += 2;
+		stats.GameNode.Sort((a, b) => (a.Node.Start - b.Node.Start).MSeconds);
+		
+		foreach (GameUnitStatsNode node in stats.GameNode){
+			row = FillStats (node.Name + " " + i, node, row);
+			i++;
+		}
+		return row;
+	}
+}
diff --git a/LongoMatch.Addins.COE/LongoMatch.Addins.COE.mdp b/LongoMatch.Addins.COE/LongoMatch.Addins.COE.mdp
index b555029..dc7163b 100644
--- a/LongoMatch.Addins.COE/LongoMatch.Addins.COE.mdp
+++ b/LongoMatch.Addins.COE/LongoMatch.Addins.COE.mdp
@@ -20,6 +20,7 @@
     <File subtype="Code" buildaction="Compile" name="ProjectStatsSheet.cs" />
     <File subtype="Code" buildaction="Compile" name="TimelineSheet.cs" />
     <File subtype="Code" buildaction="Compile" name="TeamStatsSheet.cs" />
+    <File subtype="Code" buildaction="Compile" name="GameUnitsStatsSheet.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 d0d9b0e..05a1701 100644
--- a/LongoMatch.Addins.COE/ProjectStatsSheet.cs
+++ b/LongoMatch.Addins.COE/ProjectStatsSheet.cs
@@ -63,6 +63,9 @@ public class ProjectStatsSheet
 		row = FillInfoData (ws, row, Catalog.GetString("Date"), stats.Date.ToShortDateString());
 		row = FillInfoData (ws, row, Catalog.GetString("Competition"), stats.Competition);
 		row = FillInfoData (ws, row, Catalog.GetString("Season"), stats.Season);
+		row = FillInfoData (ws, row, Catalog.GetString("Local team"), stats.LocalTeam);
+		row = FillInfoData (ws, row, Catalog.GetString("Visitor team"), stats.VisitorTeam);
+		row = FillInfoData (ws, row, Catalog.GetString("Result"), stats.Results);
 		return row;
 	}
 	
diff --git a/LongoMatch.Addins.COE/TeamStatsSheet.cs b/LongoMatch.Addins.COE/TeamStatsSheet.cs
index 64d7d93..73cad89 100644
--- a/LongoMatch.Addins.COE/TeamStatsSheet.cs
+++ b/LongoMatch.Addins.COE/TeamStatsSheet.cs
@@ -64,6 +64,9 @@ public class TeamStatsSheet
 				else 
 					playersStats = subcatStats.VisitorPlayersStats;
 				
+				if (playersStats.Count == 0)
+					continue;
+				
 				foreach (string option in playersStats.Keys) {
 					List<PlayersStats> pStatsList = playersStats[option];
 					if (pStatsList.Count > 1) {
diff --git a/LongoMatch.Addins.COE/TimelineSheet.cs b/LongoMatch.Addins.COE/TimelineSheet.cs
index aef3113..d566653 100644
--- a/LongoMatch.Addins.COE/TimelineSheet.cs
+++ b/LongoMatch.Addins.COE/TimelineSheet.cs
@@ -112,13 +112,13 @@ public class TimelineSheet
 			cols.Dispose();
 			
 			foreach (TimelineNode unit in gu) {
-				int start, stop;
+				float start, stop;
 				
-				start = TIMELINE_START + unit.Start.Seconds / 60;
-				stop = TIMELINE_START + unit.Stop.Seconds / 60;
+				start = TIMELINE_START + unit.Start.Seconds / (float) 60;
+				stop = TIMELINE_START + unit.Stop.Seconds / (float) 60;
 				
-				ws.Cells[row, start].Value = stop - start;
-				cols = ws.Cells[row, start, row, stop];
+				ws.Cells[row, (int) start].Value = stop - start;
+				cols = ws.Cells[row, (int)start, row, (int)stop];
 				cols.Style.Fill.PatternType =  ExcelFillStyle.Solid;	
 				cols.Style.Fill.BackgroundColor.SetColor(Color.Green);
 			}
@@ -150,21 +150,12 @@ public class TimelineSheet
 				
 				row++;
 				SetColoredHeaders(ws, row, subcat.Name, 3, 5, Color.DeepSkyBlue, false);
-				
 				subCatsDict.Add(subcat, row);
-				/*if (subcat is TeamSubCategory) {
-					row++;
-					SetSubcatentriesHeaders(ws, row, project.LocalTeamTemplate.TeamName);
+				
+				foreach (string s in subcat.ElementsDesc()) {
 					row++;
-					SetSubcatentriesHeaders(ws, row, project.VisitorTeamTemplate.TeamName);
-					
+					SetSubcatentriesHeaders(ws, row, s);
 				}
-				else if (subcat is PlayerSubCategory) { */
-					foreach (string s in subcat.ElementsDesc()) {
-						row++;
-						SetSubcatentriesHeaders(ws, row, s);
-					}
-				//}
 			}
 			row++;
 		}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]