[longomatch] Add stats for timers



commit 895cac97da79f1c0abf4ab1bb89b1bd7e0880b02
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Sat Nov 29 20:44:06 2014 +0100

    Add stats for timers

 LongoMatch.Core/LongoMatch.Core.csproj |    1 +
 LongoMatch.Core/Makefile.am            |    1 +
 LongoMatch.Core/Stats/ProjectStats.cs  |   13 +++++
 LongoMatch.Core/Stats/TimerStats.cs    |   85 ++++++++++++++++++++++++++++++++
 4 files changed, 100 insertions(+), 0 deletions(-)
---
diff --git a/LongoMatch.Core/LongoMatch.Core.csproj b/LongoMatch.Core/LongoMatch.Core.csproj
index c06b63e..070a6ab 100644
--- a/LongoMatch.Core/LongoMatch.Core.csproj
+++ b/LongoMatch.Core/LongoMatch.Core.csproj
@@ -134,6 +134,7 @@
     <Compile Include="Stats\TeamStats.cs" />
     <Compile Include="Stats\PlayerEventTypeStats.cs" />
     <Compile Include="Stats\PlayerStats.cs" />
+    <Compile Include="Stats\TimerStats.cs" />
   </ItemGroup>
   <ItemGroup>
     <Folder Include="Common\" />
diff --git a/LongoMatch.Core/Makefile.am b/LongoMatch.Core/Makefile.am
index c116131..f8d54d3 100644
--- a/LongoMatch.Core/Makefile.am
+++ b/LongoMatch.Core/Makefile.am
@@ -67,6 +67,7 @@ SOURCES = Common/Area.cs \
        Stats/Stat.cs \
        Stats/SubCategoryStat.cs \
        Stats/TeamStats.cs \
+       Stats/TimerStats.cs \
        Store/Coordinates.cs \
        Store/DashboardButton.cs \
        Store/Drawables/Angle.cs \
diff --git a/LongoMatch.Core/Stats/ProjectStats.cs b/LongoMatch.Core/Stats/ProjectStats.cs
index 948b185..8a087ee 100644
--- a/LongoMatch.Core/Stats/ProjectStats.cs
+++ b/LongoMatch.Core/Stats/ProjectStats.cs
@@ -49,6 +49,11 @@ namespace LongoMatch.Core.Stats
                        protected set;
                }
 
+               public List<TimerStats> TimersStats {
+                       get;
+                       protected set;
+               }
+
                public TeamStats HomeTeamStats {
                        get;
                        set;
@@ -89,6 +94,11 @@ namespace LongoMatch.Core.Stats
                                }
                        }
 
+                       TimersStats = new List<TimerStats> ();
+                       foreach (Timer t in project.Timers) {
+                               TimersStats.Add (new TimerStats (project, t));
+                       }
+
                        HomeTeamStats = new TeamStats (project, filter, Team.LOCAL);
                        AwayTeamStats = new TeamStats (project, filter, Team.VISITOR);
                        UpdateStats ();
@@ -99,6 +109,9 @@ namespace LongoMatch.Core.Stats
                        foreach (EventTypeStats e in EventTypeStats) {
                                e.Update ();
                        }
+                       foreach (TimerStats st in TimersStats) {
+                               st.Update ();
+                       }
                        HomeTeamStats.Update ();
                        AwayTeamStats.Update ();
                }
diff --git a/LongoMatch.Core/Stats/TimerStats.cs b/LongoMatch.Core/Stats/TimerStats.cs
new file mode 100644
index 0000000..27efa2a
--- /dev/null
+++ b/LongoMatch.Core/Stats/TimerStats.cs
@@ -0,0 +1,85 @@
+//
+//  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;
+
+namespace LongoMatch.Core.Stats
+{
+       public class TimerStats
+       {
+               Timer timer;
+               Project project;
+
+               public TimerStats (Project project, Timer timer)
+               {
+                       this.timer = timer;
+                       Name = timer.Name;
+                       if (timer.Team == Team.LOCAL) {
+                               TeamImage = project.LocalTeamTemplate.Shield;
+                       } else if (timer.Team == Team.VISITOR) {
+                               TeamImage = project.VisitorTeamTemplate.Shield;
+                       }
+               }
+
+               public string Name {
+                       get;
+                       set;
+               }
+
+               public Image TeamImage {
+                       get;
+                       set;
+               }
+
+               public int Count {
+                       get;
+                       set;
+               }
+
+               public Time TotalDuration {
+                       get;
+                       set;
+               }
+
+               public Time AverageDuration {
+                       get;
+                       set;
+               }
+
+               public Time MinDuration {
+                       get;
+                       set;
+               }
+
+               public Time MaxDuration {
+                       get;
+                       set;
+               }
+
+               public void Update () {
+                       Count = timer.Nodes.Count;
+                       TotalDuration = new Time (timer.Nodes.Sum (n => n.Duration.MSeconds));
+                       AverageDuration = new Time ((int) timer.Nodes.Average (n => n.Duration.MSeconds));
+                       MinDuration = timer.Nodes.Min (n => n.Duration);
+                       MaxDuration = timer.Nodes.Max (n => n.Duration);
+               }
+       }
+}
+


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