[longomatch] Start enabling stats again



commit b5ebd517f16b353202ed0aa549a82d45a453c13f
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Mon Sep 8 11:29:22 2014 +0200

    Start enabling stats again

 LongoMatch.Core/Stats/CategoryStats.cs             |   93 -----------
 LongoMatch.Core/Stats/PercentualStat.cs            |    3 +-
 LongoMatch.Core/Stats/ProjectStats.cs              |  173 +++++---------------
 LongoMatch.Core/Stats/Stat.cs                      |    6 +-
 .../Gui/Component/PlaysCoordinatesTagger.cs        |    2 +-
 .../Gui/Component/Stats/CategoriesViewer.cs        |   16 +-
 .../Gui/Component/Stats/CategoryViewer.cs          |   17 +-
 LongoMatch.GUI/Gui/Component/Stats/GameViewer.cs   |   12 +-
 .../Gui/Component/Stats/PlayerCategoriesViewer.cs  |    8 +-
 .../Gui/Component/Stats/PlayerCategoryViewer.cs    |    2 +-
 ...ongoMatch.Gui.Component.Stats.CategoryViewer.cs |    2 +-
 LongoMatch.GUI/gtk-gui/gui.stetic                  |    1 -
 12 files changed, 74 insertions(+), 261 deletions(-)
---
diff --git a/LongoMatch.Core/Stats/PercentualStat.cs b/LongoMatch.Core/Stats/PercentualStat.cs
index 6e65540..8eb79bf 100644
--- a/LongoMatch.Core/Stats/PercentualStat.cs
+++ b/LongoMatch.Core/Stats/PercentualStat.cs
@@ -25,8 +25,7 @@ namespace LongoMatch.Core.Stats
        {
                int parentTotal;
                
-               public PercentualStat (string name, int totalCount, int localTeamCount,
-                       int visitorTeamCount, int parentTotal): base (name, totalCount, localTeamCount, 
visitorTeamCount)
+               public PercentualStat (int parentTotal)
                {
                        this.parentTotal = parentTotal;
                }
diff --git a/LongoMatch.Core/Stats/ProjectStats.cs b/LongoMatch.Core/Stats/ProjectStats.cs
index 962adf5..7754853 100644
--- a/LongoMatch.Core/Stats/ProjectStats.cs
+++ b/LongoMatch.Core/Stats/ProjectStats.cs
@@ -28,87 +28,29 @@ namespace LongoMatch.Core.Stats
 {
        public class ProjectStats: IDisposable
        {
-               List<CategoryStats> catStats;
+               List<EventTypeStats> catStats;
                EventsFilter filter;
                Project project;
                
                public ProjectStats (Project project)
                {
-                       catStats = new List<CategoryStats>();
+                       catStats = new List<EventTypeStats>();
                        this.project = project;
-                       
-                       ProjectName = project.Description.Title;
-                       Date = project.Description.MatchDate;
-                       LocalTeam = project.LocalTeamTemplate.TeamName;
-                       VisitorTeam = project.VisitorTeamTemplate.TeamName;
-                       Competition = project.Description.Competition;
-                       Season = project.Description.Season;
-                       Results = String.Format("{0}-{1}", project.Description.LocalGoals, 
project.Description.VisitorGoals);
-                       UpdateStats ();
-                       UpdateGameUnitsStats ();
-               }
-               
-               public void Dispose () {
-                       if (HalfField != null)
-                               HalfField.Dispose ();
-                       if (Field != null)
-                               Field.Dispose ();
-                       if (Goal != null)
-                               Goal.Dispose ();
-                       catStats.Clear ();
-               }
-               
-               public string ProjectName {
-                       set;
-                       get;
-               }
-               
-               public string Competition {
-                       get;
-                       set;
-               }
-               
-               public string Season {
-                       get;
-                       set;
+                       CreateStats ();
                }
                
-               public string LocalTeam {
-                       get;
-                       set;
-               }
-               
-               public string VisitorTeam {
-                       get;
-                       set;
+               public void Dispose ()
+               {
                }
                
-               public DateTime Date {
+               public Project Project {
                        get;
-                       set;
+                       protected set;
                }
-               
-               public string Results {
+
+               public List<EventTypeStats> EventTypeStats {
                        get;
-                       set;
-               }
-               
-               public Image Field {
-                       get; set;
-               }
-               
-               public Image HalfField {
-                       get; set;
-               }
-               
-               public Image Goal {
-                       get; set;
-               }
-       
-               public List<CategoryStats> CategoriesStats {
-                       get {
-                               return catStats;
-                       }
+                       protected set;
                }
                
                public EventsFilter Filter {
@@ -118,69 +60,40 @@ namespace LongoMatch.Core.Stats
                        }
                }
                
-               void UpdateGameUnitsStats () {
-               }
-               
-               void CountPlaysInTeam (List<TimelineEvent> plays, out int localTeamCount, out int 
visitorTeamCount) {
-                       localTeamCount = plays.Where(p => p.Team == Team.LOCAL || p.Team == 
Team.BOTH).Count();
-                       visitorTeamCount = plays.Where(p => p.Team == Team.VISITOR || p.Team == 
Team.BOTH).Count();
-               }
-
-               public void UpdateStats () {
-                       catStats.Clear();
-                       
-                       Field = project.Dashboard.FieldBackground;
-                       HalfField = project.Dashboard.HalfFieldBackground;
-                       Goal = project.Dashboard.GoalBackground;
+               public void CreateStats () {
+                       EventTypeStats = new List <EventTypeStats> ();
                        
-                       foreach (AnalysisEventType evt in project.EventTypes.OfType<AnalysisEventType> ()) {
-//                             CategoryStats stats;
-//                             List<Event> plays, homePlays, awayPlays, untagged;
-//                             int localTeamCount, visitorTeamCount;
-//                             
-//                             plays = project.PlaysInCategory (cat);
-//                             if (filter != null) {
-//                                     plays = plays.Where(p => filter.IsVisible (p)).ToList();
-//                             }
-//                             homePlays =plays.Where(p => p.Team == Team.LOCAL || p.Team == 
Team.BOTH).ToList();
-//                             awayPlays =plays.Where(p => p.Team == Team.VISITOR || p.Team == 
Team.BOTH).ToList();
-//                             
-//                             /* Get the plays where the team is not tagged but we have at least one player 
from a team tagged */
-//                             untagged = plays.Where (p=> p.Team ==  Team.NONE).ToList();
-//                             homePlays.AddRange (untagged.Where (p => p.Players.Where (pt => 
project.LocalTeamTemplate.List.Contains(pt)).Count() != 0).ToList());
-//                             awayPlays.AddRange (untagged.Where (p => p.Players.Where (pt => 
project.VisitorTeamTemplate.List.Contains(pt)).Count() != 0).ToList());
-//                             
-//                             stats = new CategoryStats(cat, plays.Count, homePlays.Count(), 
awayPlays.Count());
-//                             
-//                             /* Fill zonal tagging stats */
-//                             stats.FieldCoordinates = plays.Select (p => p.FieldPosition).Where(p =>p != 
null).ToList();
-//                             stats.HalfFieldCoordinates = plays.Select (p => p.HalfFieldPosition).Where(p 
=>p != null).ToList();
-//                             stats.GoalCoordinates = plays.Select (p => p.GoalPosition).Where(p =>p != 
null).ToList();
-//                             stats.HomeFieldCoordinates = homePlays.Select (p => p.FieldPosition).Where(p 
=>p != null).ToList();
-//                             stats.HomeHalfFieldCoordinates = homePlays.Select (p => 
p.HalfFieldPosition).Where(p =>p != null).ToList();
-//                             stats.HomeGoalCoordinates = homePlays.Select (p => p.GoalPosition).Where(p 
=>p != null).ToList();
-//                             stats.AwayFieldCoordinates = awayPlays.Select (p => p.FieldPosition).Where(p 
=>p != null).ToList();
-//                             stats.AwayHalfFieldCoordinates = awayPlays.Select (p => 
p.HalfFieldPosition).Where(p =>p != null).ToList();
-//                             stats.AwayGoalCoordinates = awayPlays.Select (p => p.GoalPosition).Where(p 
=>p != null).ToList();
-//                             catStats.Add (stats);
+                       foreach (EventType evt in project.EventTypes) {
+                               EventTypeStats evstats = new EventTypeStats (project, filter, evt);
+                               evstats.Update ();
                        }
                }
-               
-               void GetSubcategoryStats (List<TimelineEvent> subcatPlays, SubCategoryStat subcatStat, string 
desc,
-                       int totalCount, out int localTeamCount, out int visitorTeamCount)
+
+               public void UpdateStats ()
                {
-                       int count;
-                       
-                       count = subcatPlays.Count(); 
-                       CountPlaysInTeam(subcatPlays, out localTeamCount, out visitorTeamCount);
-                       PercentualStat pStat = new PercentualStat(desc, count, localTeamCount,
-                               visitorTeamCount, totalCount);
-                       subcatStat.AddOptionStat(pStat);
+                       foreach (EventTypeStats e in EventTypeStats) {
+                               e.Update();
+                       }
                }
-               
-               void GetPlayersStats (Project project, List<TimelineEvent> subcatPlays, string optionName,
-                       SubCategoryStat subcatStat, EventType cat)
-               {
+
+//             void GetSubcategoryStats (List<TimelineEvent> 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(totalCount);
+//                     pStat.Name = desc;
+//                     pStat.TotalCount = count;
+//                     pStat.LocalTeamCount = localTeamCount;
+//                     pStat.VisitorTeamCount = visitorTeamCount;
+//                     subcatStat.AddOptionStat(pStat);
+//             }
+//             
+//             void GetPlayersStats (Project project, List<TimelineEvent> subcatPlays, string optionName,
+//                     SubCategoryStat subcatStat, EventType cat)
+//             {
 //                     foreach (SubCategory subcat in cat.SubCategories) {
 //                             Dictionary<Player, int> localPlayerCount = new Dictionary<Player, int>();
 //                             Dictionary<Player, int> visitorPlayerCount = new Dictionary<Player, int>();
@@ -204,12 +117,8 @@ namespace LongoMatch.Core.Stats
 //                                     subcatStat.AddPlayersStats(optionName, subcat.Name, Team.VISITOR, 
visitorPlayerCount);
 //                             }
 //                     }
-               }
-               
-               int GetPlayerCount(List<TimelineEvent> plays, Player player)
-               {
-                       return plays.Where(p => p.Players.Contains(player)).Count();
-               }
+//             }
+//             
        }
 }
 
diff --git a/LongoMatch.Core/Stats/Stat.cs b/LongoMatch.Core/Stats/Stat.cs
index 4538b8c..4b6bf3e 100644
--- a/LongoMatch.Core/Stats/Stat.cs
+++ b/LongoMatch.Core/Stats/Stat.cs
@@ -21,12 +21,8 @@ namespace LongoMatch.Core.Stats
 {
        public class Stat
        {
-               public Stat (string name, int totalCount, int localTeamCount, int visitorTeamCount)
+               public Stat ()
                {
-                       Name = name;
-                       TotalCount = totalCount;
-                       LocalTeamCount = localTeamCount;
-                       VisitorTeamCount = visitorTeamCount;
                }
                
                public string Name {
diff --git a/LongoMatch.GUI/Gui/Component/PlaysCoordinatesTagger.cs 
b/LongoMatch.GUI/Gui/Component/PlaysCoordinatesTagger.cs
index 19a8a38..5782733 100644
--- a/LongoMatch.GUI/Gui/Component/PlaysCoordinatesTagger.cs
+++ b/LongoMatch.GUI/Gui/Component/PlaysCoordinatesTagger.cs
@@ -46,7 +46,7 @@ namespace LongoMatch.Gui.Component
                        goal.Tagger.Background = project.GetBackground (FieldPositionType.Goal);
                }
                
-               public void LoadStats (CategoryStats stats) {
+               public void LoadStats (EventTypeStats stats) {
                }
                
                public void LoadPlay (TimelineEvent play) {
diff --git a/LongoMatch.GUI/Gui/Component/Stats/CategoriesViewer.cs 
b/LongoMatch.GUI/Gui/Component/Stats/CategoriesViewer.cs
index 2aba506..58c835f 100644
--- a/LongoMatch.GUI/Gui/Component/Stats/CategoriesViewer.cs
+++ b/LongoMatch.GUI/Gui/Component/Stats/CategoriesViewer.cs
@@ -43,8 +43,8 @@ namespace LongoMatch.Gui.Component.Stats
                }
                
                public void LoadStats (ProjectStats pstats, Project project) {
-                       categoryviewer1.HomeName = pstats.LocalTeam;
-                       categoryviewer1.AwayName = pstats.VisitorTeam;
+                       //categoryviewer1.HomeName = pstats.LocalTeam;
+                       //categoryviewer1.AwayName = pstats.VisitorTeam;
                        categoryviewer1.LoadBackgrounds (project);
                        this.pstats = pstats;
                        ReloadStats();
@@ -59,9 +59,9 @@ namespace LongoMatch.Gui.Component.Stats
                                selected = store.GetPath (iter);
                        
                        store.Clear();
-                       foreach (CategoryStats cstats in pstats.CategoriesStats) {
-                               store.AppendValues (cstats, cstats.Name);
-                       }
+                       //foreach (EventTypeStats cstats in pstats.CategoriesStats) {
+                       //      store.AppendValues (cstats, cstats.Name);
+                       //}
                        
                        /* Keep the selected category for when we reload the stats changing players */
                        if (selected != null) {
@@ -70,16 +70,16 @@ namespace LongoMatch.Gui.Component.Stats
                                store.GetIterFirst(out iter);
                        }
                        treeview.Selection.SelectIter(iter);
-                       categoryviewer1.LoadStats (store.GetValue (iter, 0) as CategoryStats);
+                       categoryviewer1.LoadStats (store.GetValue (iter, 0) as EventTypeStats);
                }
                
                void HandleCursorChanged (object sender, EventArgs e)
                {
-                       CategoryStats stats;
+                       EventTypeStats stats;
                        TreeIter iter;
                        
                        treeview.Selection.GetSelected(out iter);
-                       stats = store.GetValue(iter, 0) as CategoryStats;
+                       stats = store.GetValue(iter, 0) as EventTypeStats;
                        categoryviewer1.LoadStats (stats);
                }
        }
diff --git a/LongoMatch.GUI/Gui/Component/Stats/CategoryViewer.cs 
b/LongoMatch.GUI/Gui/Component/Stats/CategoryViewer.cs
index 683fcb9..b2c2b7a 100644
--- a/LongoMatch.GUI/Gui/Component/Stats/CategoryViewer.cs
+++ b/LongoMatch.GUI/Gui/Component/Stats/CategoryViewer.cs
@@ -46,21 +46,24 @@ namespace LongoMatch.Gui.Component.Stats
                        awaytagger.LoadBackgrounds (project);
                }
 
-               public void LoadStats (CategoryStats stats) {
+               public void LoadStats (EventTypeStats stats) {
                        homeLabel.Text = HomeName;
                        awayLabel.Text = AwayName;
                        
                        alltagger.LoadStats (stats);
-                       allframe.Visible = stats.FieldCoordinates.Count + stats.HalfFieldCoordinates.Count +
-                           stats.GoalCoordinates.Count != 0;
+                       allframe.Visible = true;
+//                     allframe.Visible = stats.FieldCoordinates.Count + stats.HalfFieldCoordinates.Count +
+//                         stats.GoalCoordinates.Count != 0;
                        
                        hometagger.LoadStats (stats);
-                       homeframe.Visible = stats.HomeFieldCoordinates.Count + 
stats.HomeHalfFieldCoordinates.Count +
-                           stats.HomeGoalCoordinates.Count != 0;
+                       hometagger.Visible = true;
+//                     homeframe.Visible = stats.HomeFieldCoordinates.Count + 
stats.HomeHalfFieldCoordinates.Count +
+//                         stats.HomeGoalCoordinates.Count != 0;
                            
                        awaytagger.LoadStats (stats);
-                       awayframe.Visible = stats.AwayFieldCoordinates.Count + 
stats.AwayHalfFieldCoordinates.Count +
-                           stats.AwayGoalCoordinates.Count != 0;
+                       awaytagger.Visible = true;
+//                     awayframe.Visible = stats.AwayFieldCoordinates.Count + 
stats.AwayHalfFieldCoordinates.Count +
+//                         stats.AwayGoalCoordinates.Count != 0;
                        
                        foreach (Widget child in vbox1.AllChildren) {
                                if (child is SubCategoryViewer || child is HSeparator)
diff --git a/LongoMatch.GUI/Gui/Component/Stats/GameViewer.cs 
b/LongoMatch.GUI/Gui/Component/Stats/GameViewer.cs
index 946bb89..1fec4f2 100644
--- a/LongoMatch.GUI/Gui/Component/Stats/GameViewer.cs
+++ b/LongoMatch.GUI/Gui/Component/Stats/GameViewer.cs
@@ -68,8 +68,8 @@ namespace LongoMatch.Gui.Component
                
                void UpdateGui () {
                
-                       homelabel.Text = stats.LocalTeam;
-                       awaylabel.Text = stats.VisitorTeam;
+                       homelabel.Text = stats.Project.Description.LocalName;;
+                       awaylabel.Text = stats.Project.Description.VisitorName;
                        GetMaxSize(out catsMaxSize, out subcatsMaxSize);
                        if (project.LocalTeamTemplate.Shield != null)
                                homeimage.Pixbuf = project.LocalTeamTemplate.Shield.Value;
@@ -78,14 +78,14 @@ namespace LongoMatch.Gui.Component
                        
                        subcats = new List<Widget>();
                        cats = new List<Widget>();
-                       foreach (CategoryStats cstats in stats.CategoriesStats) {
+                       foreach (EventTypeStats cstats in stats.EventTypeStats) {
                                AddCategory (cstats);
                        }                       
                        mainbox.ShowAll();
                        UpdateSubcatsVisibility ();
                }
                
-               void AddCategory (CategoryStats cstats) {
+               void AddCategory (EventTypeStats cstats) {
                        Widget w = new StatsWidget (cstats, null, null, catsMaxSize);
                        cats.Add (w);
                        cstatsbox.PackStart(w, false, true, 0);
@@ -96,7 +96,7 @@ namespace LongoMatch.Gui.Component
                        cstatsbox.PackStart (new HSeparator (), false, false, 0);
                }
                
-               void AddSubcategory (SubCategoryStat sstats, CategoryStats parent) {
+               void AddSubcategory (SubCategoryStat sstats, EventTypeStats parent) {
                        foreach (PercentualStat ostats in sstats.OptionStats) {
                                StatsWidget w = new StatsWidget (ostats, parent, sstats, subcatsMaxSize);
                                subcats.Add (w);
@@ -109,7 +109,7 @@ namespace LongoMatch.Gui.Component
                        
                        normal = full = 0;
                        
-                       foreach (CategoryStats cstat in stats.CategoriesStats) {
+                       foreach (EventTypeStats cstat in stats.EventTypeStats) {
                                int width, height;
                                layout.SetMarkup (String.Format("<b>{0}</b>", GLib.Markup.EscapeText 
(cstat.Name)));
                                layout.GetPixelSize (out width, out height);
diff --git a/LongoMatch.GUI/Gui/Component/Stats/PlayerCategoriesViewer.cs 
b/LongoMatch.GUI/Gui/Component/Stats/PlayerCategoriesViewer.cs
index 5e3557a..c6c328f 100644
--- a/LongoMatch.GUI/Gui/Component/Stats/PlayerCategoriesViewer.cs
+++ b/LongoMatch.GUI/Gui/Component/Stats/PlayerCategoriesViewer.cs
@@ -55,7 +55,7 @@ namespace LongoMatch.Gui.Component.Stats
                                selected = store.GetPath (iter);
                        
                        store.Clear();
-                       foreach (CategoryStats cstats in pstats.CategoriesStats) {
+                       foreach (EventTypeStats cstats in pstats.EventTypeStats) {
                                store.AppendValues (cstats, cstats.Name);
                        }
                        
@@ -66,16 +66,16 @@ namespace LongoMatch.Gui.Component.Stats
                                store.GetIterFirst(out iter);
                        }
                        treeview.Selection.SelectIter(iter);
-                       categoryviewer.LoadStats (store.GetValue (iter, 0) as CategoryStats);
+                       categoryviewer.LoadStats (store.GetValue (iter, 0) as EventTypeStats);
                }
                
                void HandleCursorChanged (object sender, EventArgs e)
                {
-                       CategoryStats stats;
+                       EventTypeStats stats;
                        TreeIter iter;
                        
                        treeview.Selection.GetSelected(out iter);
-                       stats = store.GetValue(iter, 0) as CategoryStats;
+                       stats = store.GetValue(iter, 0) as EventTypeStats;
                        categoryviewer.LoadStats (stats);
                }       
        }
diff --git a/LongoMatch.GUI/Gui/Component/Stats/PlayerCategoryViewer.cs 
b/LongoMatch.GUI/Gui/Component/Stats/PlayerCategoryViewer.cs
index 756ed7a..29d83f4 100644
--- a/LongoMatch.GUI/Gui/Component/Stats/PlayerCategoryViewer.cs
+++ b/LongoMatch.GUI/Gui/Component/Stats/PlayerCategoryViewer.cs
@@ -38,7 +38,7 @@ namespace LongoMatch.Gui.Component.Stats
                        tagger.LoadBackgrounds (project);
                }
 
-               public void LoadStats (CategoryStats stats) {
+               public void LoadStats (EventTypeStats stats) {
                        tagger.LoadStats (stats);
                        
                        foreach (Widget child in vbox1.AllChildren) {
diff --git a/LongoMatch.GUI/gtk-gui/LongoMatch.Gui.Component.Stats.CategoryViewer.cs 
b/LongoMatch.GUI/gtk-gui/LongoMatch.Gui.Component.Stats.CategoryViewer.cs
index 5aa5c26..b1e599a 100644
--- a/LongoMatch.GUI/gtk-gui/LongoMatch.Gui.Component.Stats.CategoryViewer.cs
+++ b/LongoMatch.GUI/gtk-gui/LongoMatch.Gui.Component.Stats.CategoryViewer.cs
@@ -42,7 +42,7 @@ namespace LongoMatch.Gui.Component.Stats
                        this.notebook1 = new global::Gtk.Notebook ();
                        this.notebook1.CanFocus = true;
                        this.notebook1.Name = "notebook1";
-                       this.notebook1.CurrentPage = 1;
+                       this.notebook1.CurrentPage = 0;
                        // Container child notebook1.Gtk.Notebook+NotebookChild
                        this.vbox1 = new global::Gtk.VBox ();
                        this.vbox1.Name = "vbox1";
diff --git a/LongoMatch.GUI/gtk-gui/gui.stetic b/LongoMatch.GUI/gtk-gui/gui.stetic
index 161a94c..56231c2 100644
--- a/LongoMatch.GUI/gtk-gui/gui.stetic
+++ b/LongoMatch.GUI/gtk-gui/gui.stetic
@@ -2995,7 +2995,6 @@ Hotkeys with a single key are also allowed with Ctrl+key.</property>
                             <property name="Tooltip" translatable="yes">Angle tool</property>
                             <property name="CanFocus">True</property>
                             <property name="Label" translatable="yes" />
-                            <property name="Active">True</property>
                             <property name="DrawIndicator">False</property>
                             <property name="HasLabel">False</property>
                             <property name="UseUnderline">True</property>


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