[longomatch] Add overal stats and sheets per team in the Excel



commit a44651d30c722d5607a3070754957b31c8111a9e
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Sun Jan 15 23:52:37 2012 +0100

    Add overal stats and sheets per team in the Excel

 LongoMatch.Addins.COE/ExcelExporter.cs          |  205 ++------------------
 LongoMatch.Addins.COE/LongoMatch.Addins.COE.mdp |    2 +
 LongoMatch.Addins.COE/Main.cs                   |    2 +-
 LongoMatch.Addins.COE/ProjectStatsSheet.cs      |  130 +++++++++++++
 LongoMatch.Addins.COE/TeamStatsSheets.cs        |  226 +++++++++++++++++++++++
 5 files changed, 380 insertions(+), 185 deletions(-)
---
diff --git a/LongoMatch.Addins.COE/ExcelExporter.cs b/LongoMatch.Addins.COE/ExcelExporter.cs
index 81dd84e..addcbe2 100644
--- a/LongoMatch.Addins.COE/ExcelExporter.cs
+++ b/LongoMatch.Addins.COE/ExcelExporter.cs
@@ -30,6 +30,7 @@ using LongoMatch.Addins.ExtensionPoints;
 using LongoMatch.Interfaces;
 using LongoMatch.Interfaces.GUI;
 using LongoMatch.Store;
+using LongoMatch.Stats;
 using LongoMatch.Common;
 
 [Extension]
@@ -51,7 +52,7 @@ public class ExcelExporter:IExportProject
 		if (filename == null)
 			return;
 		
-		System.IO.Path.ChangeExtension(filename, ".xlsx");
+		filename = System.IO.Path.ChangeExtension(filename, ".xlsx");
 		
 		try {
 			EPPLUSExporter exporter = new EPPLUSExporter(project, filename);
@@ -70,14 +71,12 @@ public class EPPLUSExporter {
 	string filename;
 	ExcelPackage package;
 	ExcelWorksheet ws;
-	int duration;
+	int sheetCount = 0;
 	
-	const int TIMELINE_START = 6;
 
 	public EPPLUSExporter(Project project, string filename) {
 		this.project = project;
 		this.filename = filename;
-		duration = (int) (project.Description.File.Length / 1000 / 60);
 	}
 	
 	public void Export() {
@@ -89,195 +88,33 @@ public class EPPLUSExporter {
 		}
 		
 		using (package = new ExcelPackage(newFile)) {
-			ws = CreateSheet(package, "LongoMatch");
-			FillSheet(ws);
-			Console.WriteLine ("Saving");
+			TeamStatsSheets teamStats;
+			
+			ws = CreateSheet(package, Catalog.GetString("Project statistics"));
+			var statsSheet = new ProjectStatsSheet(ws, project);
+			statsSheet.Fill();
+			
+			ws = CreateSheet(package, project.LocalTeamTemplate.TeamName +
+				"(" + Catalog.GetString("Local Team") + ")");
+			teamStats = new TeamStatsSheets(ws, project, Team.LOCAL);
+			teamStats.Fill();
+			
+			ws = CreateSheet(package, project.VisitorTeamTemplate.TeamName +
+				"(" + Catalog.GetString("Visitor Team") + ")");
+			teamStats = new TeamStatsSheets(ws, project, Team.VISITOR);
+			teamStats.Fill();
 			package.Save();
 		}
 	}
 	
 	ExcelWorksheet CreateSheet(ExcelPackage p, string sheetName)
 	{
+		sheetCount ++;
 		p.Workbook.Worksheets.Add(sheetName);
-		ExcelWorksheet ws = p.Workbook.Worksheets[1];
-		ws.Name = sheetName; //Setting Sheet's name
+		ExcelWorksheet ws = p.Workbook.Worksheets[sheetCount];
+		ws.Name = sheetName;
 		return ws;
 	}
 	
-	void FillSheet(ExcelWorksheet ws) {
-		int row = 1;
-		
-		for (int i = 0; i < TIMELINE_START; i++)
-			ws.Column(i).Width = 10;
-		for (int i=0; i<duration; i++)
-			ws.Column(TIMELINE_START + i).Width = 2;
-		
-		row = FillTimeline(ws, row);
-		row = FillGameUnits(ws, row);
-		row = FillCategories(ws, row);
-	}
-	
-	void SetColoredHeaders (ExcelWorksheet ws, int row, string name, int startCol,
-		int stopCol, Color color, bool withSum)
-	{
-		ws.Cells[row,startCol].Value = name;
-		if (withSum) {
-			ws.Cells[row,stopCol].Formula = String.Format("Sum({0})",
-				new ExcelAddress(row, TIMELINE_START, row, TIMELINE_START +duration).Address);
-		}
-		ExcelRange cols = ws.Cells[row, startCol, row, stopCol];
-		cols.Style.Fill.PatternType = ExcelFillStyle.Solid;
-		cols.Style.Fill.BackgroundColor.SetColor(color);
-		cols.Dispose();
-	}
-		
-	void SetHeader (ExcelWorksheet ws, int row, string title) {
-		ws.Cells[row, 1].Value = title;
-		ws.Cells[row, 1].Style.Fill.PatternType =  ExcelFillStyle.Solid;	
-		ws.Cells[row, 1].Style.Fill.BackgroundColor.SetColor(Color.Yellow);
-		ws.Cells[row, 1, row, 3].Merge = true;
-	}
-	
-	void SetCellValue (ExcelWorksheet ws, int row, int time, int val) {
-		object prevVal = ws.Cells[row , time].Value;
-		if (prevVal is int)
-			ws.Cells[row, time].Value = ((int)prevVal) + val;
-		else
-			ws.Cells[row, time].Value =  val;
-		ws.Cells[row, time].Style.Fill.PatternType =  ExcelFillStyle.Solid;	
-		ws.Cells[row, time].Style.Fill.BackgroundColor.SetColor(Color.Red);
-	}
-	
-	int FillTimeline(ExcelWorksheet ws, int row) {
-		SetHeader(ws, row, Catalog.GetString("Timeline"));
-		
-		for (int i=0; i < duration; i+=5) {
-			ws.Cells[row, TIMELINE_START + i].Value = i;
-		}
-		row++;
-		return row;
-	}
-	
-	int FillGameUnits(ExcelWorksheet ws, int row) {
-		SetHeader(ws, row, Catalog.GetString("Game Units"));
-		ws.Cells[row, 5].Value = Catalog.GetString("Duration (min)");
-		row ++;
-		
-		foreach (GameUnit gu in project.GameUnits) {
-			ExcelRange cols;
-			
-			SetColoredHeaders(ws, row, gu.Name, 3, 5, Color.DeepSkyBlue, true);
-			cols = ws.Cells[row, TIMELINE_START, row, duration];
-			cols.Style.Fill.PatternType = ExcelFillStyle.Solid;
-			cols.Style.Fill.BackgroundColor.SetColor(Color.Red);
-			cols.Dispose();
-			
-			foreach (TimelineNode unit in gu) {
-				int start, stop;
-				
-				start = TIMELINE_START + unit.Start.Seconds / 60;
-				stop = TIMELINE_START + unit.Stop.Seconds / 60;
-				
-				ws.Cells[row, start].Value = stop - start;
-				cols = ws.Cells[row, start, row, stop];
-				cols.Style.Fill.PatternType =  ExcelFillStyle.Solid;	
-				cols.Style.Fill.BackgroundColor.SetColor(Color.Green);
-			}
-			row ++;
-		}
-		return row;
-	}
-	
-	void SetSubcatHeaders (ExcelWorksheet ws, int row, string name)
-	{
-		SetColoredHeaders(ws, row, name, 2, 5, Color.BlueViolet, true);
-	}
-	
-	void SetSubcatentriesHeaders (ExcelWorksheet ws, int row, string name)
-	{
-		SetColoredHeaders(ws, row, name, 4, 5, Color.Cyan, true);
-	}
-	
-	int FillCategoriesDescription(ExcelWorksheet ws, int row, List<Category> categories,
-		Dictionary<Category, int> catsDict, Dictionary<ISubCategory, int> subCatsDict)
-	{
-		foreach (Category ca in categories) {
-			SetSubcatHeaders(ws, row, ca.Name);
-			catsDict.Add(ca, row);
-			
-			foreach (var subcat in ca.SubCategories) {
-				if (subcat is PlayerSubCategory)
-				continue;
-				
-				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);
-					row++;
-					SetSubcatentriesHeaders(ws, row, project.VisitorTeamTemplate.TeamName);
-					
-				}
-				else if (subcat is TagSubCategory) {
-					foreach (string s in subcat.ElementsDesc()) {
-						row++;
-						SetSubcatentriesHeaders(ws, row, s);
-					}
-				}
-			}
-			row++;
-		}
-		return row;
-	}
-	
-	int FillCategoriesData(ExcelWorksheet ws, int row, List<Category> categories,
-		Dictionary<Category, int> catsDict, Dictionary<ISubCategory, int> subCatsDict)
-	{
-		foreach (Category ca in project.Categories) {
-			foreach (Play play in project.PlaysInCategory(ca)) {
-				int time;
-				int catRow;
-				
-				/* Add the category's overal stats */
-				catRow = catsDict[ca];
-				time = TIMELINE_START + play.Start.Seconds / 60;
-				SetCellValue(ws, catRow, time, 1);
-				
-				/* Add the tags stats */
-				foreach (StringTag tag in play.Tags.Tags) {
-					int subcatRow = subCatsDict[tag.SubCategory];
-					subcatRow += tag.SubCategory.ElementsDesc().IndexOf(tag.Value);
-					SetCellValue(ws, subcatRow, time, 1);
-				}
-				
-				/* Add the teams stats */
-				foreach (TeamTag tag in play.Teams.Tags) {
-					int subcatRow = subCatsDict[tag.SubCategory];
-					if (tag.Value == Team.LOCAL) {
-						SetCellValue(ws, subcatRow + 1, time, 1);
-					} else if (tag.Value == Team.VISITOR) {
-						SetCellValue(ws, subcatRow + 2, time, 1);
-					}
-				}
-			}
-		}
-		return row;
-	}
-	
-	int FillCategories(ExcelWorksheet ws, int row) {
-		Dictionary<Category, int> catsDict = new Dictionary<Category, int>();
-		Dictionary<ISubCategory, int>  subCatsDict = new Dictionary<ISubCategory, int>();
-		
-		
-		SetHeader(ws, row, Catalog.GetString("Categories"));
-		ws.Cells[row, 5].Value = Catalog.GetString("Count");
-		row ++;
-		
-		row = FillCategoriesDescription(ws, row, project.Categories, catsDict, subCatsDict);
-		row = FillCategoriesData(ws, row, project.Categories, catsDict, subCatsDict);
-		return row;
-	}
 }
 
diff --git a/LongoMatch.Addins.COE/LongoMatch.Addins.COE.mdp b/LongoMatch.Addins.COE/LongoMatch.Addins.COE.mdp
index 3cca818..cdeb6c3 100644
--- a/LongoMatch.Addins.COE/LongoMatch.Addins.COE.mdp
+++ b/LongoMatch.Addins.COE/LongoMatch.Addins.COE.mdp
@@ -17,6 +17,8 @@
     <File subtype="Code" buildaction="Compile" name="GameUnitsEnabler.cs" />
     <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" />
   </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/Main.cs b/LongoMatch.Addins.COE/Main.cs
index db048af..0ae7c1e 100644
--- a/LongoMatch.Addins.COE/Main.cs
+++ b/LongoMatch.Addins.COE/Main.cs
@@ -39,7 +39,7 @@ class MainClass
 			Project p = db.GetProject(db.GetAllProjects()[0].UUID);
 			
 			ExcelExporter ee = new ExcelExporter();
-			ee.ExportProject(p, "/home/andoni/test.xls");
+			ee.ExportProject(p,  "/home/andoni/test.xls");
 		}
 	}
 }
diff --git a/LongoMatch.Addins.COE/ProjectStatsSheet.cs b/LongoMatch.Addins.COE/ProjectStatsSheet.cs
new file mode 100644
index 0000000..388c8f1
--- /dev/null
+++ b/LongoMatch.Addins.COE/ProjectStatsSheet.cs
@@ -0,0 +1,130 @@
+// 
+//  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.Drawing;
+using Mono.Unix;
+using OfficeOpenXml;
+using OfficeOpenXml.Style;
+
+using LongoMatch.Stats;
+using LongoMatch.Store;
+
+public class ProjectStatsSheet
+{
+	Project project;
+	ExcelWorksheet ws;
+	
+	public ProjectStatsSheet (ExcelWorksheet ws, Project project)
+	{
+		this.project = project;
+		this.ws = ws;
+	}
+	
+	public void Fill() {
+		int row = 1;
+		
+		ProjectStats stats = new ProjectStats(project);
+		row = FillMatchDescription (ws, row, stats);
+		row += 3;
+		row = FillTeamsData (ws, row, stats);
+		row = FillOverallStats(ws, row, stats);
+	}
+	
+	int FillInfoData (ExcelWorksheet ws, int row, string desc, string val) {
+		ExcelRange cols = ws.Cells[row, 2, row, 5];
+		cols.Style.Fill.PatternType = ExcelFillStyle.Solid;
+		cols.Style.Fill.BackgroundColor.SetColor(Color.Yellow);
+		cols.Dispose();
+		
+		ws.Cells[row, 2].Value = desc;
+		ws.Cells[row, 2, row, 3].Merge = true;
+		ws.Cells[row, 4].Value = val;
+		ws.Cells[row, 4, row, 5].Merge = true;
+		row++;
+		return row;
+	}
+	
+	int FillMatchDescription (ExcelWorksheet ws, int row, ProjectStats stats) {
+		row = FillInfoData (ws, row, Catalog.GetString("Project"), stats.ProjectName);
+		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);
+		return row;
+	}
+	
+	int FillTeamsData (ExcelWorksheet ws, int row, ProjectStats stats) {
+		ExcelRange cols = ws.Cells[row, 6, row, 10];
+		cols.Style.Fill.PatternType = ExcelFillStyle.Solid;
+		cols.Style.Fill.BackgroundColor.SetColor(Color.Red);
+		cols.Dispose();
+		
+		ws.Cells[row, 6].Value = Catalog.GetString("Total");
+		ws.Cells[row, 7].Value = stats.LocalTeam; 
+		ws.Cells[row, 9].Value = stats.VisitorTeam; 
+		ws.Cells[row, 7, row, 8].Merge = true;
+		ws.Cells[row, 9, row, 10].Merge = true;
+		row++;
+		return row;
+		
+	}
+	
+	int FillOverallStats (ExcelWorksheet ws, int row, ProjectStats stats) {
+		
+		foreach (CategoryStats catStat in stats.CategoriesStats) {
+			SetSubcatHeaders(ws, row, catStat.Name);
+			ws.Cells[row, 6].Value = catStat.TotalCount;
+			ws.Cells[row, 7].Value = catStat.LocalTeamCount;
+			ws.Cells[row, 9].Value = catStat.VisitorTeamCount;
+			row++;
+			
+			foreach (SubCategoryStat subcatStat in catStat.SubcategoriesStats) {
+				SetColoredHeaders(ws, row, subcatStat.Name, 3, 5, Color.DeepSkyBlue);
+				row++;
+				
+				foreach (PercentualStat pStat in subcatStat.OptionStats)  {
+					SetSubcatentriesHeaders(ws, row, pStat.Name);
+					ws.Cells[row, 6].Value = pStat.TotalCount;
+					ws.Cells[row, 7].Value = pStat.LocalTeamCount;
+					ws.Cells[row, 9].Value = pStat.VisitorTeamCount;
+					row++;
+				}
+			}
+		}
+		return row;
+	}
+	
+	void SetColoredHeaders (ExcelWorksheet ws, int row, string name, int startCol,
+		int stopCol, Color color)
+	{
+		ws.Cells[row,startCol].Value = name;
+		ExcelRange cols = ws.Cells[row, startCol, row, stopCol];
+		cols.Style.Fill.PatternType = ExcelFillStyle.Solid;
+		cols.Style.Fill.BackgroundColor.SetColor(color);
+		cols.Dispose();
+	}
+	
+	void SetSubcatHeaders (ExcelWorksheet ws, int row, string name)
+	{
+		SetColoredHeaders(ws, row, name, 2, 5, Color.BlueViolet);
+	}
+	
+	void SetSubcatentriesHeaders (ExcelWorksheet ws, int row, string name)
+	{
+		SetColoredHeaders(ws, row, name, 4, 5, Color.Cyan);
+	}
+}
diff --git a/LongoMatch.Addins.COE/TeamStatsSheets.cs b/LongoMatch.Addins.COE/TeamStatsSheets.cs
new file mode 100644
index 0000000..c542bf3
--- /dev/null
+++ b/LongoMatch.Addins.COE/TeamStatsSheets.cs
@@ -0,0 +1,226 @@
+// 
+//  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 TeamStatsSheets
+{
+	Project project;
+	ExcelWorksheet ws;
+	Team team;
+	int duration;
+	
+	const int TIMELINE_START = 6;
+	
+	public TeamStatsSheets (ExcelWorksheet ws, Project project, Team team)
+	{
+		this.project = project;
+		this.ws = ws;
+		this.team = team;
+		duration = (int) (project.Description.File.Length / 1000 / 60);
+	}
+	
+	public void Fill() {
+		int row = 1;
+		
+		for (int i = 0; i < TIMELINE_START; i++)
+			ws.Column(i).Width = 10;
+		for (int i=0; i<duration; i++)
+			ws.Column(TIMELINE_START + i).Width = 2;
+		
+		row = FillTimeline(ws, row);
+		row = FillGameUnits(ws, row);
+		row = FillCategories(ws, row);
+	}
+	
+	void SetColoredHeaders (ExcelWorksheet ws, int row, string name, int startCol,
+		int stopCol, Color color, bool withSum)
+	{
+		ws.Cells[row,startCol].Value = name;
+		if (withSum) {
+			ws.Cells[row,stopCol].Formula = String.Format("Sum({0})",
+				new ExcelAddress(row, TIMELINE_START, row, TIMELINE_START +duration).Address);
+		}
+		ExcelRange cols = ws.Cells[row, startCol, row, stopCol];
+		cols.Style.Fill.PatternType = ExcelFillStyle.Solid;
+		cols.Style.Fill.BackgroundColor.SetColor(color);
+		cols.Dispose();
+	}
+		
+	void SetHeader (ExcelWorksheet ws, int row, string title) {
+		ws.Cells[row, 1].Value = title;
+		ws.Cells[row, 1].Style.Fill.PatternType =  ExcelFillStyle.Solid;	
+		ws.Cells[row, 1].Style.Fill.BackgroundColor.SetColor(Color.Yellow);
+		ws.Cells[row, 1, row, 3].Merge = true;
+	}
+	
+	void SetCellValue (ExcelWorksheet ws, int row, int time, int val) {
+		object prevVal = ws.Cells[row , time].Value;
+		if (prevVal is int)
+			ws.Cells[row, time].Value = ((int)prevVal) + val;
+		else
+			ws.Cells[row, time].Value =  val;
+		ws.Cells[row, time].Style.Fill.PatternType =  ExcelFillStyle.Solid;	
+		ws.Cells[row, time].Style.Fill.BackgroundColor.SetColor(Color.Red);
+	}
+	
+	int FillTimeline(ExcelWorksheet ws, int row) {
+		SetHeader(ws, row, Catalog.GetString("Timeline"));
+		
+		for (int i=0; i < duration; i+=5) {
+			ws.Cells[row, TIMELINE_START + i].Value = i;
+		}
+		row++;
+		return row;
+	}
+	
+	int FillGameUnits(ExcelWorksheet ws, int row) {
+		SetHeader(ws, row, Catalog.GetString("Game Units"));
+		ws.Cells[row, 5].Value = Catalog.GetString("Duration (min)");
+		row ++;
+		
+		foreach (GameUnit gu in project.GameUnits) {
+			ExcelRange cols;
+			
+			SetColoredHeaders(ws, row, gu.Name, 3, 5, Color.DeepSkyBlue, true);
+			cols = ws.Cells[row, TIMELINE_START, row, duration];
+			cols.Style.Fill.PatternType = ExcelFillStyle.Solid;
+			cols.Style.Fill.BackgroundColor.SetColor(Color.Red);
+			cols.Dispose();
+			
+			foreach (TimelineNode unit in gu) {
+				int start, stop;
+				
+				start = TIMELINE_START + unit.Start.Seconds / 60;
+				stop = TIMELINE_START + unit.Stop.Seconds / 60;
+				
+				ws.Cells[row, start].Value = stop - start;
+				cols = ws.Cells[row, start, row, stop];
+				cols.Style.Fill.PatternType =  ExcelFillStyle.Solid;	
+				cols.Style.Fill.BackgroundColor.SetColor(Color.Green);
+			}
+			row ++;
+		}
+		return row;
+	}
+	
+	void SetSubcatHeaders (ExcelWorksheet ws, int row, string name)
+	{
+		SetColoredHeaders(ws, row, name, 2, 5, Color.BlueViolet, true);
+	}
+	
+	void SetSubcatentriesHeaders (ExcelWorksheet ws, int row, string name)
+	{
+		SetColoredHeaders(ws, row, name, 4, 5, Color.Cyan, true);
+	}
+	
+	int FillCategoriesDescription(ExcelWorksheet ws, int row, List<Category> categories,
+		Dictionary<Category, int> catsDict, Dictionary<ISubCategory, int> subCatsDict)
+	{
+		foreach (Category ca in categories) {
+			SetSubcatHeaders(ws, row, ca.Name);
+			catsDict.Add(ca, row);
+			
+			foreach (var subcat in ca.SubCategories) {
+				if (!(subcat is TagSubCategory))
+				continue;
+				
+				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);
+					row++;
+					SetSubcatentriesHeaders(ws, row, project.VisitorTeamTemplate.TeamName);
+					
+				}
+				else if (subcat is PlayerSubCategory) { */
+					foreach (string s in subcat.ElementsDesc()) {
+						row++;
+						SetSubcatentriesHeaders(ws, row, s);
+					}
+				//}
+			}
+			row++;
+		}
+		return row;
+	}
+	
+	int FillCategoriesData(ExcelWorksheet ws, int row, List<Category> categories,
+		Dictionary<Category, int> catsDict, Dictionary<ISubCategory, int> subCatsDict)
+	{
+		foreach (Category ca in project.Categories) {
+			foreach (Play play in project.PlaysInCategory(ca)) {
+				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;
+				SetCellValue(ws, catRow, time, 1);
+				
+				/* Add the tags stats */
+				foreach (StringTag tag in play.Tags.Tags) {
+					int subcatRow = subCatsDict[tag.SubCategory];
+					subcatRow += tag.SubCategory.ElementsDesc().IndexOf(tag.Value);
+					SetCellValue(ws, subcatRow, time, 1);
+				}
+				
+				/* Add the teams stats */
+				foreach (TeamTag tag in play.Teams.Tags) {
+					int subcatRow = subCatsDict[tag.SubCategory];
+					if (tag.Value == Team.LOCAL) {
+						SetCellValue(ws, subcatRow + 1, time, 1);
+					} else if (tag.Value == Team.VISITOR) {
+						SetCellValue(ws, subcatRow + 2, time, 1);
+					}
+				}
+			}
+		}
+		return row;
+	}
+	
+	int FillCategories(ExcelWorksheet ws, int row) {
+		Dictionary<Category, int> catsDict = new Dictionary<Category, int>();
+		Dictionary<ISubCategory, int>  subCatsDict = new Dictionary<ISubCategory, int>();
+		
+		
+		SetHeader(ws, row, Catalog.GetString("Categories"));
+		ws.Cells[row, 5].Value = Catalog.GetString("Count");
+		row ++;
+		
+		row = FillCategoriesDescription(ws, row, project.Categories, catsDict, subCatsDict);
+		row = FillCategoriesData(ws, row, project.Categories, catsDict, subCatsDict);
+		return row;
+	}
+}



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