[longomatch] WIP



commit 25f3264b948b56149b8a4a367a129d99e76e8395
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Fri Dec 16 02:48:34 2011 +0100

    WIP

 LongoMatch.Addins.COE/ExcelExporter.cs             |  277 ++++++++++++++++++++
 LongoMatch.Addins.COE/LongoMatch.Addins.COE.mdp    |   11 +-
 LongoMatch.Addins.COE/Main.cs                      |   46 ++++
 LongoMatch.GUI/Gui/Component/CategoryProperties.cs |    1 +
 .../LongoMatch.Gui.Dialog.EditCategoryDialog.cs    |    2 +-
 .../gtk-gui/LongoMatch.Gui.MainWindow.cs           |    4 +-
 LongoMatch.GUI/gtk-gui/gui.stetic                  |    4 +-
 LongoMatch.GUI/gtk-gui/objects.xml                 |   16 +-
 8 files changed, 346 insertions(+), 15 deletions(-)
---
diff --git a/LongoMatch.Addins.COE/ExcelExporter.cs b/LongoMatch.Addins.COE/ExcelExporter.cs
new file mode 100644
index 0000000..763a84c
--- /dev/null
+++ b/LongoMatch.Addins.COE/ExcelExporter.cs
@@ -0,0 +1,277 @@
+// 
+//  Copyright (C) 2011 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.IO;
+using System.Drawing;
+using Mono.Addins;
+using Mono.Unix;
+
+using OfficeOpenXml;
+
+using LongoMatch;
+using LongoMatch.Addins.ExtensionPoints;
+using LongoMatch.Interfaces;
+using LongoMatch.Store;
+using OfficeOpenXml.Style;
+using LongoMatch.Common;
+
+[Extension]
+public class ExcelExporter:IExportProject
+{
+	public string GetMenuEntryName () {
+		Log.Information("Registering new export entry");
+		return Catalog.GetString("Export project to Excel file");
+	}
+	
+	public string GetMenuEntryShortName () {
+		return "EPPLUSExport";
+	}
+	
+	public void ExportProject (Project project, string filename) {
+		EPPLUSExporter exporter = new EPPLUSExporter(project, filename);
+		exporter.Export();
+	}
+}
+
+public class EPPLUSExporter {
+	
+	Project project;
+	string filename;
+	ExcelPackage package;
+	ExcelWorksheet ws;
+	int duration;
+	
+	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() {
+		FileInfo newFile = new FileInfo(filename);
+		if (newFile.Exists)
+		{
+			newFile.Delete();  // ensures we create a new workbook
+			newFile = new FileInfo(filename);
+		}
+		
+		using (package = new ExcelPackage(newFile)) {
+			ws = CreateSheet(package, "LongoMatch");
+			FillSheet(ws);
+			Console.WriteLine ("Saving");
+			package.Save();
+		}
+	}
+	
+	ExcelWorksheet CreateSheet(ExcelPackage p, string sheetName)
+	{
+		p.Workbook.Worksheets.Add(sheetName);
+		ExcelWorksheet ws = p.Workbook.Worksheets[1];
+		ws.Name = sheetName; //Setting Sheet's name
+		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;
+	}
+	
+	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.VerticalAlignment = ExcelVerticalAlignment.Center;
+				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.Name);
+					row++;
+					SetSubcatentriesHeaders(ws, row, project.VisitorTeamTemplate.Name);
+					
+				}
+				/*	
+			    else if (subcat is PlayerSubCategory) {
+					if ((subcat as PlayerSubCategory).Contains(Team.LOCAL)) {
+						row++;
+						SetSubcatentriesHeaders(ws, row, project.LocalTeamTemplate.Name);
+					}
+					if ((subcat as PlayerSubCategory).Contains(Team.VISITOR)) {
+						row++;
+						SetSubcatentriesHeaders(ws, row, project.VisitorTeamTemplate.Name);
+					}
+				} 
+				*/
+				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;
+				object val = ws.Cells[catRow , time].Value;
+				if (val is int)
+					ws.Cells[catRow, time].Value = ((int)val) + 1;
+				else
+					ws.Cells[catRow, time].Value =  1;
+				
+				/* Add the tags stats */
+				foreach (StringTag tag in play.Tags.Tags) {
+					int subcatRow = subCatsDict[tag.SubCategory];
+					subcatRow += tag.SubCategory.ElementsDesc().IndexOf(tag.Value);
+					/* FIXME: add +1 to the previous results */
+					ws.Cells[subcatRow, time].Value = 1;
+				}
+				
+				/* Add the teams stats */
+				foreach (TeamTag tag in play.Teams.Tags) {
+					int subcatRow = subCatsDict[tag.SubCategory];
+					if (tag.Value == Team.LOCAL) {
+						ws.Cells[subcatRow + 1, time].Value = 1;
+					} else if (tag.Value == Team.VISITOR) {
+						ws.Cells[subcatRow + 2, time].Value = 1;
+					}
+					/* FIXME: add +1 to the previous results */
+				}
+			}
+		}
+		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 fb89974..f391a3a 100644
--- a/LongoMatch.Addins.COE/LongoMatch.Addins.COE.mdp
+++ b/LongoMatch.Addins.COE/LongoMatch.Addins.COE.mdp
@@ -2,23 +2,30 @@
   <Configurations active="Release">
     <Configuration name="Debug" ctype="DotNetProjectConfiguration">
       <Output directory="../bin" assembly="LongoMatch.Addins.COE" />
-      <Build debugmode="True" target="Library" />
+      <Build debugmode="True" target="Exe" />
       <Execution consolepause="False" runwithwarnings="True" runtime="MsNet" />
       <CodeGeneration compiler="Mcs" warninglevel="4" optimize="False" unsafecodeallowed="False" generateoverflowchecks="False" definesymbols="DEBUG" generatexmldocumentation="False" ctype="CSharpCompilerParameters" />
     </Configuration>
     <Configuration name="Release" ctype="DotNetProjectConfiguration">
       <Output directory="../bin" assembly="LongoMatch.Addins.COE" />
-      <Build debugmode="False" target="Library" />
+      <Build debugmode="False" target="Exe" />
       <Execution consolepause="False" runwithwarnings="True" runtime="MsNet" />
       <CodeGeneration compiler="Mcs" warninglevel="4" optimize="False" unsafecodeallowed="False" generateoverflowchecks="False" generatexmldocumentation="False" ctype="CSharpCompilerParameters" />
     </Configuration>
   </Configurations>
   <Contents>
     <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="Main.cs" />
   </Contents>
   <References>
     <ProjectReference type="Gac" localcopy="True" refto="Mono.Addins, Version=0.6.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756" />
     <ProjectReference type="Project" localcopy="True" refto="LongoMatch.Addins" />
     <ProjectReference type="Project" localcopy="True" refto="LongoMatch.Core" />
+    <ProjectReference type="Gac" localcopy="True" refto="Mono.Posix, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756" />
+    <ProjectReference type="Project" localcopy="True" refto="LongoMatch.Services" />
+    <ProjectReference specificVersion="False" type="Assembly" localcopy="True" refto="../../epplus/trunk/ExcelPackage/bin/Debug/EPPlus.dll" />
+    <ProjectReference type="Gac" localcopy="True" refto="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
   </References>
 </Project>
\ No newline at end of file
diff --git a/LongoMatch.Addins.COE/Main.cs b/LongoMatch.Addins.COE/Main.cs
new file mode 100644
index 0000000..db048af
--- /dev/null
+++ b/LongoMatch.Addins.COE/Main.cs
@@ -0,0 +1,46 @@
+// 
+//  Copyright (C) 2011 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.IO;
+
+
+using OfficeOpenXml;
+using LongoMatch.Services;
+using LongoMatch.DB;
+using LongoMatch;
+using LongoMatch.Common;
+using LongoMatch.Store;
+
+namespace LongoMatch.Addins.COE
+{
+class MainClass
+	{
+		
+		public static void Main(string[] args)
+		{
+			/* Start DB services */
+			Core.Init();
+			var db = new DataBase(Path.Combine(Config.DBDir(),Constants.DB_FILE));
+			Project p = db.GetProject(db.GetAllProjects()[0].UUID);
+			
+			ExcelExporter ee = new ExcelExporter();
+			ee.ExportProject(p, "/home/andoni/test.xls");
+		}
+	}
+}
+
diff --git a/LongoMatch.GUI/Gui/Component/CategoryProperties.cs b/LongoMatch.GUI/Gui/Component/CategoryProperties.cs
index 6b47906..081299b 100644
--- a/LongoMatch.GUI/Gui/Component/CategoryProperties.cs
+++ b/LongoMatch.GUI/Gui/Component/CategoryProperties.cs
@@ -61,6 +61,7 @@ namespace LongoMatch.Gui.Component
 				subcategoriesTemplates = value;
 			}
 		}
+
 		public List<PlayerSubCategory> PlayerSubcategories{
 			set{
 				LoadSubcategories(value);
diff --git a/LongoMatch.GUI/gtk-gui/LongoMatch.Gui.Dialog.EditCategoryDialog.cs b/LongoMatch.GUI/gtk-gui/LongoMatch.Gui.Dialog.EditCategoryDialog.cs
index 3f86b79..f357ffa 100644
--- a/LongoMatch.GUI/gtk-gui/LongoMatch.Gui.Dialog.EditCategoryDialog.cs
+++ b/LongoMatch.GUI/gtk-gui/LongoMatch.Gui.Dialog.EditCategoryDialog.cs
@@ -49,7 +49,7 @@ namespace LongoMatch.Gui.Dialog
 				this.Child.ShowAll ();
 			}
 			this.DefaultWidth = 522;
-			this.DefaultHeight = 280;
+			this.DefaultHeight = 538;
 			this.Show ();
 		}
 	}
diff --git a/LongoMatch.GUI/gtk-gui/LongoMatch.Gui.MainWindow.cs b/LongoMatch.GUI/gtk-gui/LongoMatch.Gui.MainWindow.cs
index e64da81..fef6ef6 100644
--- a/LongoMatch.GUI/gtk-gui/LongoMatch.Gui.MainWindow.cs
+++ b/LongoMatch.GUI/gtk-gui/LongoMatch.Gui.MainWindow.cs
@@ -143,12 +143,12 @@ namespace LongoMatch.Gui
 			this.ImportProjectAction.ShortLabel = global::Mono.Unix.Catalog.GetString ("_Import Project");
 			w1.Add (this.ImportProjectAction, "<Control>i");
 			this.ManualTaggingViewAction = new global::Gtk.RadioAction ("ManualTaggingViewAction", global::Mono.Unix.Catalog.GetString ("Manual tagging view"), null, null, 0);
-			this.ManualTaggingViewAction.Group = this.TimelineViewAction.Group;
+			this.ManualTaggingViewAction.Group = this.TaggingViewAction.Group;
 			this.ManualTaggingViewAction.Sensitive = false;
 			this.ManualTaggingViewAction.ShortLabel = global::Mono.Unix.Catalog.GetString ("Free Capture Mode");
 			w1.Add (this.ManualTaggingViewAction, "<Control>f");
 			this.GameUnitsViewAction = new global::Gtk.RadioAction ("GameUnitsViewAction", global::Mono.Unix.Catalog.GetString ("Game units view"), null, null, 0);
-			this.GameUnitsViewAction.Group = this.TimelineViewAction.Group;
+			this.GameUnitsViewAction.Group = this.TaggingViewAction.Group;
 			this.GameUnitsViewAction.Sensitive = false;
 			this.GameUnitsViewAction.ShortLabel = global::Mono.Unix.Catalog.GetString ("Game units view");
 			w1.Add (this.GameUnitsViewAction, null);
diff --git a/LongoMatch.GUI/gtk-gui/gui.stetic b/LongoMatch.GUI/gtk-gui/gui.stetic
index 61763ed..c6ce990 100644
--- a/LongoMatch.GUI/gtk-gui/gui.stetic
+++ b/LongoMatch.GUI/gtk-gui/gui.stetic
@@ -2121,7 +2121,7 @@
       </widget>
     </child>
   </widget>
-  <widget class="Gtk.Bin" id="LongoMatch.Gui.Component.CategoryProperties" design-size="516 392">
+  <widget class="Gtk.Bin" id="LongoMatch.Gui.Component.CategoryProperties" design-size="516 487">
     <property name="MemberName" />
     <child>
       <widget class="Gtk.VBox" id="vbox2">
@@ -4950,7 +4950,7 @@ Show-&gt;&lt;b&gt; S&lt;/b&gt;
       </widget>
     </child>
   </widget>
-  <widget class="Gtk.Dialog" id="LongoMatch.Gui.Dialog.EditCategoryDialog" design-size="522 280">
+  <widget class="Gtk.Dialog" id="LongoMatch.Gui.Dialog.EditCategoryDialog" design-size="522 538">
     <property name="MemberName" />
     <property name="Title" translatable="yes">Category Details</property>
     <property name="Icon">resource:longomatch.png</property>
diff --git a/LongoMatch.GUI/gtk-gui/objects.xml b/LongoMatch.GUI/gtk-gui/objects.xml
index e900893..2c8a75a 100644
--- a/LongoMatch.GUI/gtk-gui/objects.xml
+++ b/LongoMatch.GUI/gtk-gui/objects.xml
@@ -318,14 +318,6 @@
       </itemgroup>
     </signals>
   </object>
-  <object type="LongoMatch.Gui.Component.CategoryProperties" palette-category="LongoMatch" allow-children="false" base-type="Gtk.Bin">
-    <itemgroups />
-    <signals>
-      <itemgroup label="CategoryProperties Signals">
-        <signal name="HotKeyChanged" />
-      </itemgroup>
-    </signals>
-  </object>
   <object type="LongoMatch.Gui.Component.PlayerProperties" palette-category="General" allow-children="false" base-type="Gtk.Widget">
     <itemgroups />
     <signals />
@@ -344,4 +336,12 @@
       </itemgroup>
     </signals>
   </object>
+  <object type="LongoMatch.Gui.Component.CategoryProperties" palette-category="LongoMatch" allow-children="false" base-type="Gtk.Bin">
+    <itemgroups />
+    <signals>
+      <itemgroup label="CategoryProperties Signals">
+        <signal name="HotKeyChanged" />
+      </itemgroup>
+    </signals>
+  </object>
 </objects>
\ No newline at end of file



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