[longomatch] Enable back player stats



commit 40623b70c10526b01f7049fb831314ba1a238267
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Tue Nov 11 13:26:40 2014 +0100

    Enable back player stats

 LongoMatch.Core/LongoMatch.Core.csproj             |    4 +-
 LongoMatch.Core/Makefile.am                        |    4 +-
 LongoMatch.Core/Stats/EventTypeStats.cs            |    1 -
 LongoMatch.Core/Stats/PlayerEventTypeStats.cs      |   86 ++++++++++++++++++++
 LongoMatch.Core/Stats/PlayerStats.cs               |   61 ++++++++++++++
 LongoMatch.Core/Stats/ProjectStats.cs              |   44 ++++++++---
 LongoMatch.Core/Stats/TeamStats.cs                 |   62 ++++++++++++++
 LongoMatch.GUI.Multimedia/gtk-gui/gui.stetic       |    2 -
 .../Gui/Component/PlaysCoordinatesTagger.cs        |   18 +++-
 .../Gui/Component/Stats/PlayerCategoriesViewer.cs  |   19 +++--
 .../Gui/Component/Stats/PlayerCategoryViewer.cs    |    2 +-
 .../Gui/Component/Stats/PlayersViewer.cs           |   22 +++---
 12 files changed, 285 insertions(+), 40 deletions(-)
---
diff --git a/LongoMatch.Core/LongoMatch.Core.csproj b/LongoMatch.Core/LongoMatch.Core.csproj
index 5974cea..c06b63e 100644
--- a/LongoMatch.Core/LongoMatch.Core.csproj
+++ b/LongoMatch.Core/LongoMatch.Core.csproj
@@ -72,7 +72,6 @@
     <Compile Include="Stats\ProjectStats.cs" />
     <Compile Include="Stats\PercentualStat.cs" />
     <Compile Include="Stats\Stat.cs" />
-    <Compile Include="Stats\PlayersStats.cs" />
     <Compile Include="Common\EventsFilter.cs" />
     <Compile Include="Interfaces\Multimedia\IRemuxer.cs" />
     <Compile Include="Interfaces\Multimedia\IVideoConverter.cs" />
@@ -132,6 +131,9 @@
     <Compile Include="Common\Hotkeys.cs" />
     <Compile Include="Common\Keyboard.cs" />
     <Compile Include="Store\Playlists\PlaylistVideo.cs" />
+    <Compile Include="Stats\TeamStats.cs" />
+    <Compile Include="Stats\PlayerEventTypeStats.cs" />
+    <Compile Include="Stats\PlayerStats.cs" />
   </ItemGroup>
   <ItemGroup>
     <Folder Include="Common\" />
diff --git a/LongoMatch.Core/Makefile.am b/LongoMatch.Core/Makefile.am
index 8563ed9..c116131 100644
--- a/LongoMatch.Core/Makefile.am
+++ b/LongoMatch.Core/Makefile.am
@@ -61,10 +61,12 @@ SOURCES = Common/Area.cs \
        Interfaces/Multimedia/IVideoEditor.cs \
        Stats/EventTypeStats.cs \
        Stats/PercentualStat.cs \
-       Stats/PlayersStats.cs \
+       Stats/PlayerEventTypeStats.cs \
+       Stats/PlayerStats.cs \
        Stats/ProjectStats.cs \
        Stats/Stat.cs \
        Stats/SubCategoryStat.cs \
+       Stats/TeamStats.cs \
        Store/Coordinates.cs \
        Store/DashboardButton.cs \
        Store/Drawables/Angle.cs \
diff --git a/LongoMatch.Core/Stats/EventTypeStats.cs b/LongoMatch.Core/Stats/EventTypeStats.cs
index d7bf33b..56f5a48 100644
--- a/LongoMatch.Core/Stats/EventTypeStats.cs
+++ b/LongoMatch.Core/Stats/EventTypeStats.cs
@@ -18,7 +18,6 @@
 using System;
 using System.Linq;
 using System.Collections.Generic;
-using LongoMatch.Core.Interfaces;
 using LongoMatch.Core.Store;
 using LongoMatch.Core.Common;
 
diff --git a/LongoMatch.Core/Stats/PlayerEventTypeStats.cs b/LongoMatch.Core/Stats/PlayerEventTypeStats.cs
new file mode 100644
index 0000000..c213650
--- /dev/null
+++ b/LongoMatch.Core/Stats/PlayerEventTypeStats.cs
@@ -0,0 +1,86 @@
+//
+//  Copyright (C) 2014 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.Linq;
+using LongoMatch.Core.Store;
+using LongoMatch.Core.Common;
+using System.Collections.Generic;
+
+namespace LongoMatch.Core.Stats
+{
+       public class PlayerEventTypeStats
+       {
+               EventsFilter filter;
+               Player player;
+               List<TimelineEvent> events;
+               
+               public PlayerEventTypeStats (Project project, EventsFilter filter, Player player, 
AnalysisEventType evType)
+               {
+                       this.filter = filter;
+                       this.player = player;
+                       this.EventType = evType;
+               }
+               
+               public int TotalCount {
+                       get;
+                       set;
+               }
+
+               public AnalysisEventType EventType {
+                       get;
+                       set;
+               }
+
+               public void Update ()
+               {
+                       events = filter.VisiblePlays.Where (e => e.Players.Contains (player) && e.EventType 
== EventType).ToList();
+                       TotalCount = events.Count;
+                       SubcategoriesStats = new List<SubCategoryStat> ();
+                       var tagsByGroup = EventType.TagsByGroup;
+                       foreach (string grp in tagsByGroup.Keys) {
+                               SubCategoryStat substat = new SubCategoryStat (grp);
+                               foreach (Tag t in tagsByGroup[grp]) {
+                                       int count, localTeamCount, visitorTeamCount;
+                                       count = events.Count (e => e.Tags.Contains (t));
+                                       PercentualStat pStat = new PercentualStat (t.Value, count, 0, 0, 
events.Count);
+                                       substat.OptionStats.Add (pStat);
+                               }
+                               SubcategoriesStats.Add (substat);
+                       }
+               }
+               
+               public List<SubCategoryStat> SubcategoriesStats {
+                       get;
+                       protected set;
+               }
+
+               public List<Coordinates> GetFieldCoordinates (FieldPositionType pos)
+               {
+                       switch (pos) {
+                       case FieldPositionType.Field:
+                               return events.Where (e => e.FieldPosition != null).Select (e => 
e.FieldPosition).ToList ();
+                       case FieldPositionType.HalfField:
+                               return events.Where (e => e.HalfFieldPosition != null).Select (e => 
e.HalfFieldPosition).ToList ();
+                       default:
+                               return events.Where (e => e.GoalPosition != null).Select (e => 
e.GoalPosition).ToList ();
+                       }
+               }
+
+       }
+}
+
diff --git a/LongoMatch.Core/Stats/PlayerStats.cs b/LongoMatch.Core/Stats/PlayerStats.cs
new file mode 100644
index 0000000..5f70842
--- /dev/null
+++ b/LongoMatch.Core/Stats/PlayerStats.cs
@@ -0,0 +1,61 @@
+//
+//  Copyright (C) 2014 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 LongoMatch.Core.Common;
+using LongoMatch.Core.Store;
+using System.Collections.Generic;
+
+namespace LongoMatch.Core.Stats
+{
+       public class PlayerStats
+       {
+               Project project;
+               EventsFilter filter;
+
+               public PlayerStats (Project project, EventsFilter filter, Player player)
+               {
+                       this.project = project;
+                       this.filter = filter;
+                       this.Player = player;
+                       PlayerEventStats = new List<PlayerEventTypeStats> ();
+                       foreach (EventType evtType in project.EventTypes) {
+                               if (evtType is AnalysisEventType) {
+                                       PlayerEventStats.Add (new PlayerEventTypeStats (project, filter, 
player, evtType as AnalysisEventType));
+                               }
+                       }
+               }
+
+               public Player Player {
+                       get;
+                       set;
+               }
+
+               public List<PlayerEventTypeStats> PlayerEventStats {
+                       get;
+                       set;
+               }
+
+               public void Update ()
+               {
+                       foreach (PlayerEventTypeStats stats in PlayerEventStats) {
+                               stats.Update ();
+                       }
+               }
+       }
+}
+
diff --git a/LongoMatch.Core/Stats/ProjectStats.cs b/LongoMatch.Core/Stats/ProjectStats.cs
index 5d1bfcf..67d6769 100644
--- a/LongoMatch.Core/Stats/ProjectStats.cs
+++ b/LongoMatch.Core/Stats/ProjectStats.cs
@@ -16,13 +16,10 @@
 //  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
 // 
 using System;
-using System.Collections.Generic;
 using System.Linq;
-
+using System.Collections.Generic;
 using LongoMatch.Core.Common;
-using LongoMatch.Core.Interfaces;
 using LongoMatch.Core.Store;
-using LongoMatch.Core.Store.Templates;
 
 namespace LongoMatch.Core.Stats
 {
@@ -30,18 +27,18 @@ namespace LongoMatch.Core.Stats
        {
                EventsFilter filter;
                Project project;
-               
+
                public ProjectStats (Project project)
                {
                        this.project = project;
                        filter = new EventsFilter (project);
                        CreateStats ();
                }
-               
+
                public void Dispose ()
                {
                }
-               
+
                public Project Project {
                        get;
                        protected set;
@@ -51,29 +48,54 @@ namespace LongoMatch.Core.Stats
                        get;
                        protected set;
                }
+
+               public TeamStats HomeTeamStats {
+                       get;
+                       set;
+               }
                
+               public TeamStats AwayTeamStats {
+                       get;
+                       set;
+               }
+
                public EventsFilter Filter {
                        set {
                                filter = value;
                                UpdateStats ();
                        }
                }
-               
-               public void CreateStats () {
+
+               public PlayerStats GetPlayerStats (Player p)
+               {
+                       if (project.LocalTeamTemplate.List.Contains (p)) {
+                               return HomeTeamStats.PlayersStats.FirstOrDefault (ps => ps.Player == p);
+                       } else {
+                               return AwayTeamStats.PlayersStats.FirstOrDefault (ps => ps.Player == p);
+                       }
+               }
+ 
+               public void CreateStats ()
+               {
                        EventTypeStats = new List <EventTypeStats> ();
                        
                        foreach (EventType evt in project.EventTypes) {
                                EventTypeStats evstats = new EventTypeStats (project, filter, evt);
-                               evstats.Update ();
                                EventTypeStats.Add (evstats);
                        }
+
+                       HomeTeamStats = new TeamStats (project, filter, Team.LOCAL);
+                       AwayTeamStats = new TeamStats (project, filter, Team.VISITOR);
+                       UpdateStats ();
                }
 
                public void UpdateStats ()
                {
                        foreach (EventTypeStats e in EventTypeStats) {
-                               e.Update();
+                               e.Update ();
                        }
+                       HomeTeamStats.Update ();
+                       AwayTeamStats.Update ();
                }
        }
 }
diff --git a/LongoMatch.Core/Stats/TeamStats.cs b/LongoMatch.Core/Stats/TeamStats.cs
new file mode 100644
index 0000000..4e5dfb6
--- /dev/null
+++ b/LongoMatch.Core/Stats/TeamStats.cs
@@ -0,0 +1,62 @@
+//
+//  Copyright (C) 2014 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 LongoMatch.Core.Store;
+using LongoMatch.Core.Store.Templates;
+using LongoMatch.Core.Common;
+using System.Collections.Generic;
+
+namespace LongoMatch.Core.Stats
+{
+       public class TeamStats
+       {
+               Project project;
+               TeamTemplate template;
+               Team team;
+               EventsFilter filter;
+               
+               public TeamStats (Project project, EventsFilter filter, Team team)
+               {
+                       this.project = project;
+                       this.filter = filter;
+                       this.team = team;
+                       if (team == Team.LOCAL) {
+                               this.template = project.LocalTeamTemplate;
+                       } else {
+                               this.template = project.VisitorTeamTemplate;
+                       }
+                       PlayersStats = new List<PlayerStats> ();
+                       foreach (Player p in this.template.List) {
+                               PlayersStats.Add (new PlayerStats (project, filter, p));
+                       }
+               }
+
+               public List<PlayerStats> PlayersStats {
+                       get;
+                       set;
+               }
+                               
+               public void Update ()
+               {
+                       foreach (PlayerStats stats in PlayersStats) {
+                               stats.Update ();
+                       }
+               }
+       }
+}
+
diff --git a/LongoMatch.GUI.Multimedia/gtk-gui/gui.stetic b/LongoMatch.GUI.Multimedia/gtk-gui/gui.stetic
index 2c8fe83..7c9bbf9 100644
--- a/LongoMatch.GUI.Multimedia/gtk-gui/gui.stetic
+++ b/LongoMatch.GUI.Multimedia/gtk-gui/gui.stetic
@@ -100,7 +100,6 @@
                             <property name="MemberName" />
                             <property name="Visible">False</property>
                             <property name="Events">ButtonPressMask</property>
-                            <property name="Visible">False</property>
                             <property name="Ready">False</property>
                           </widget>
                           <packing>
@@ -458,7 +457,6 @@
             <property name="MemberName" />
             <property name="Visible">False</property>
             <property name="Events">ButtonPressMask</property>
-            <property name="Visible">False</property>
             <property name="Ready">False</property>
           </widget>
           <packing>
diff --git a/LongoMatch.GUI/Gui/Component/PlaysCoordinatesTagger.cs 
b/LongoMatch.GUI/Gui/Component/PlaysCoordinatesTagger.cs
index 60af50b..d16c4eb 100644
--- a/LongoMatch.GUI/Gui/Component/PlaysCoordinatesTagger.cs
+++ b/LongoMatch.GUI/Gui/Component/PlaysCoordinatesTagger.cs
@@ -52,9 +52,18 @@ namespace LongoMatch.Gui.Component
                {
                        Visible = false;
                        
-                       UpdateTags (stats, team, FieldPositionType.Field, field);
-                       UpdateTags (stats, team, FieldPositionType.HalfField, hfield);
-                       UpdateTags (stats, team, FieldPositionType.Goal, goal);
+                       UpdateTags (stats.GetFieldCoordinates (team, FieldPositionType.Field), field);
+                       UpdateTags (stats.GetFieldCoordinates (team, FieldPositionType.HalfField), hfield);
+                       UpdateTags (stats.GetFieldCoordinates (team, FieldPositionType.Goal), goal);
+               }
+               
+               public void LoadStats (PlayerEventTypeStats stats, Team team)
+               {
+                       Visible = false;
+                       
+                       UpdateTags (stats.GetFieldCoordinates (FieldPositionType.Field), field);
+                       UpdateTags (stats.GetFieldCoordinates (FieldPositionType.HalfField), hfield);
+                       UpdateTags (stats.GetFieldCoordinates (FieldPositionType.Goal), goal);
                }
                
                public void LoadPlay (TimelineEvent play) {
@@ -75,9 +84,8 @@ namespace LongoMatch.Gui.Component
                        }
                }
                
-               void UpdateTags (EventTypeStats stats, Team team, FieldPositionType field, CoordinatesTagger 
tagger)
+               void UpdateTags (List<Coordinates> coords, CoordinatesTagger tagger)
                {
-                       List<Coordinates> coords = stats.GetFieldCoordinates (team, field);
                        if (coords.Count > 0) {
                                Visible = true;
                        }
diff --git a/LongoMatch.GUI/Gui/Component/Stats/PlayerCategoriesViewer.cs 
b/LongoMatch.GUI/Gui/Component/Stats/PlayerCategoriesViewer.cs
index c6c328f..e775bc7 100644
--- a/LongoMatch.GUI/Gui/Component/Stats/PlayerCategoriesViewer.cs
+++ b/LongoMatch.GUI/Gui/Component/Stats/PlayerCategoriesViewer.cs
@@ -26,6 +26,7 @@ namespace LongoMatch.Gui.Component.Stats
        public partial class PlayerCategoriesViewer : Gtk.Bin
        {
                ListStore store;
+               Project project;
                ProjectStats pstats;
                
                public PlayerCategoriesViewer ()
@@ -43,20 +44,24 @@ namespace LongoMatch.Gui.Component.Stats
                public void LoadStats (ProjectStats pstats, Project project) {
                        categoryviewer.LoadBackgrounds (project);
                        this.pstats = pstats;
-                       ReloadStats();
+                       this.project = project;
+                       ReloadStats (project.LocalTeamTemplate.List[0]);
                }
                
-               public void ReloadStats () {
+               public void ReloadStats (Player player) {
+                       PlayerStats playerStats;
                        TreeIter iter;
                        TreePath selected = null;
                        
+                       playerStats = pstats.GetPlayerStats (player);
+
                        treeview.Selection.GetSelected (out iter);
                        if (store.IterIsValid (iter))
                                selected = store.GetPath (iter);
                        
                        store.Clear();
-                       foreach (EventTypeStats cstats in pstats.EventTypeStats) {
-                               store.AppendValues (cstats, cstats.Name);
+                       foreach (PlayerEventTypeStats petats in playerStats.PlayerEventStats) {
+                               store.AppendValues (petats, petats.EventType.Name);
                        }
                        
                        /* Keep the selected category for when we reload the stats changing players */
@@ -66,16 +71,16 @@ namespace LongoMatch.Gui.Component.Stats
                                store.GetIterFirst(out iter);
                        }
                        treeview.Selection.SelectIter(iter);
-                       categoryviewer.LoadStats (store.GetValue (iter, 0) as EventTypeStats);
+                       categoryviewer.LoadStats (store.GetValue (iter, 0) as PlayerEventTypeStats);
                }
                
                void HandleCursorChanged (object sender, EventArgs e)
                {
-                       EventTypeStats stats;
+                       PlayerEventTypeStats stats;
                        TreeIter iter;
                        
                        treeview.Selection.GetSelected(out iter);
-                       stats = store.GetValue(iter, 0) as EventTypeStats;
+                       stats = store.GetValue(iter, 0) as PlayerEventTypeStats;
                        categoryviewer.LoadStats (stats);
                }       
        }
diff --git a/LongoMatch.GUI/Gui/Component/Stats/PlayerCategoryViewer.cs 
b/LongoMatch.GUI/Gui/Component/Stats/PlayerCategoryViewer.cs
index 4d02cfb..910b56a 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 (EventTypeStats stats) {
+               public void LoadStats (PlayerEventTypeStats stats) {
                        tagger.LoadStats (stats, Team.BOTH);
                        
                        foreach (Widget child in vbox1.AllChildren) {
diff --git a/LongoMatch.GUI/Gui/Component/Stats/PlayersViewer.cs 
b/LongoMatch.GUI/Gui/Component/Stats/PlayersViewer.cs
index aa252f3..2b99ebd 100644
--- a/LongoMatch.GUI/Gui/Component/Stats/PlayersViewer.cs
+++ b/LongoMatch.GUI/Gui/Component/Stats/PlayersViewer.cs
@@ -47,22 +47,24 @@ namespace LongoMatch.Gui.Component.Stats
                }
                
                public void LoadProject (Project project, ProjectStats stats) {
-                       TreeIter first;
+                       TreePath path;
                        
                        store.Clear();
                        pstats = stats;
-                       filter = new EventsFilter (project);
-                       pstats.Filter = filter;
                        categoriesviewer.LoadStats (pstats, project);
                        AddTeam (project.LocalTeamTemplate, project.Dashboard);
                        AddTeam (project.VisitorTeamTemplate, project.Dashboard);
-                       filter.Update();
-                       store.GetIter (out first, new TreePath ("0:0"));
-                       treeview1.Selection.SelectIter (first);
+                       path = new TreePath ("0:0");
+                       treeview1.ExpandAll ();
+                       treeview1.SetCursor (path, null, false);
                }
                
-               void AddTeam (TeamTemplate tpl, Dashboard cats) {
-                       store.AppendValues (tpl.TeamName, null);
+               void AddTeam (TeamTemplate tpl, Dashboard cats)
+               {
+                       TreeIter iter = store.AppendValues (tpl.TeamName, null);
+                       foreach (Player p in tpl.List) {
+                               store.AppendValues (iter, p.Name, p);
+                       }
                }
                
                void HandleCursorChanged (object sender, EventArgs e)
@@ -72,9 +74,7 @@ namespace LongoMatch.Gui.Component.Stats
                        treeview1.Selection.GetSelected(out iter);
                        current = store.GetValue(iter, 1) as Player;
                        if (current != null) {
-                               filter.Update();
-                               pstats.UpdateStats ();
-                               categoriesviewer.ReloadStats ();
+                               categoriesviewer.ReloadStats (current);
                        }
                }
        }


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