[gbrainy] Games statistics tool



commit b4ad8292ed0e53d887f910d88609ac70b0c25d7b
Author: Jordi Mas <jmas softcatala org>
Date:   Sat Mar 26 13:13:19 2011 +0100

    Games statistics tool

 configure.ac             |    1 +
 tools/Defines.cs.in      |   31 ++++++++++
 tools/GamesStatistics.cs |  137 ++++++++++++++++++++++++++++++++++++++++++++++
 tools/Makefile.am        |   22 ++++++--
 4 files changed, 186 insertions(+), 5 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 30465a9..9df44a1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -204,6 +204,7 @@ tests/Makefile
 data/Makefile
 data/gbrainy.pc
 help/Makefile
+tools/Defines.cs
 ])
 
 echo "GNOME enabled:		${enable_gnome}"
diff --git a/tools/Defines.cs.in b/tools/Defines.cs.in
new file mode 100644
index 0000000..bbee559
--- /dev/null
+++ b/tools/Defines.cs.in
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2011 Jordi Mas i Hernàndez <jmas softcatala org>
+ *
+ * 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+using System;
+
+public static class Defines
+{
+	public const string VERSION = "@VERSION@";
+	public const string DATA_DIR = "@prefix@/share/games/gbrainy/";
+	public const string BUILD_TIME = "@BUILD_TIME@";
+
+	public const string VERBAL_ANALOGIES = "verbal_analogies.xml";
+	public const string GAME_ASSEMBLY = "gbrainy.Games.dll";
+	public const string GAMES_FILE = "games.xml";
+}
diff --git a/tools/GamesStatistics.cs b/tools/GamesStatistics.cs
new file mode 100644
index 0000000..5134f9b
--- /dev/null
+++ b/tools/GamesStatistics.cs
@@ -0,0 +1,137 @@
+/*
+ * Copyright (C) 2011 Jordi Mas i Hernàndez <jmas softcatala org>
+ *
+ * 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+
+using System;
+using System.Text;
+using System.IO;
+using System.Collections.Generic;
+
+using gbrainy.Core.Main;
+using gbrainy.Core.Main.Verbal;
+using gbrainy.Core.Main.Xml;
+using gbrainy.Core.Services;
+using System.Reflection;
+
+public class GamesStatistics
+{
+	public static void GameManagerPreload (GameManager gm)
+	{
+		gm.LoadAssemblyGames (Defines.GAME_ASSEMBLY);
+		gm.LoadVerbalAnalogies (System.IO.Path.Combine (Defines.DATA_DIR, Defines.VERBAL_ANALOGIES));
+		gm.LoadGamesFromXml (System.IO.Path.Combine (Defines.DATA_DIR, Defines.GAMES_FILE));
+		gm.LoadPlugins ();
+	}
+
+	static void InitCoreLibraries ()
+	{
+		// Register services
+		ServiceLocator.Instance.RegisterService <ITranslations> (new TranslationsCatalog ());
+		ServiceLocator.Instance.RegisterService <IConfiguration> (new MemoryConfiguration ());
+
+		// Configuration
+		ServiceLocator.Instance.GetService <IConfiguration> ().Set (ConfigurationKeys.GamesDefinitions, Defines.DATA_DIR);
+		ServiceLocator.Instance.GetService <IConfiguration> ().Set (ConfigurationKeys.GamesGraphics, Defines.DATA_DIR);
+		ServiceLocator.Instance.GetService <IConfiguration> ().Set (ConfigurationKeys.ThemesDir, Defines.DATA_DIR);
+
+		string mono_path = Environment.GetEnvironmentVariable ("MONO_PATH");
+
+		if (String.IsNullOrEmpty (mono_path))
+			mono_path = ".";
+
+		// Configuration
+		ServiceLocator.Instance.GetService <IConfiguration> ().Set (ConfigurationKeys.AssembliesDir, mono_path);
+	}
+
+	static int question_answer, multiple_options, words_options, words_compare, games_xml;
+	static int tip, rationale;
+
+	//Lists the games without tip
+	static void GetStatistics (GameManager gm)
+	{
+		question_answer = multiple_options = words_options = words_compare = games_xml = 0;
+		tip = rationale = 0;
+
+		GameManager.GameLocator [] games = gm.AvailableGames;
+
+		foreach (GameManager.GameLocator locator in games)
+		{
+			Game game = (Game) Activator.CreateInstance (locator.TypeOf, true);
+			game.Variant = locator.Variant;
+
+			if (game as AnalogiesQuestionAnswer != null)
+				question_answer++;
+			else if (game as AnalogiesMultipleOptions != null)
+				multiple_options++;
+			else if (game as AnalogiesPairOfWordsOptions != null)
+				words_options++;
+			else if (game as AnalogiesPairOfWordsCompare != null)
+				words_compare++;
+
+			if (game as GameXml != null)
+				games_xml++;
+
+			game.Begin ();
+
+			if (String.IsNullOrEmpty (game.TipString) == false)
+			{
+				tip++;
+			}
+
+			if (String.IsNullOrEmpty (game.Rationale) == false)
+			{
+				rationale++;
+			}
+		}
+
+		int verbal = question_answer + multiple_options + words_options + words_compare;
+		int nonverbal = games.Length - verbal;
+
+		Console.WriteLine ("All Games (including variations) - " + games.Length);
+		Console.WriteLine ("  Games (no-verbal): {0} ({1}%)", nonverbal, nonverbal * 100 / games.Length);
+		Console.WriteLine ("    Types");
+		Console.WriteLine ("      Harcoded: {0} ({1}%)", nonverbal - games_xml, (nonverbal - games_xml) * 100 / nonverbal);
+		Console.WriteLine ("      Xml: {0} ({1}%)", games_xml, games_xml * 100 / nonverbal);
+		 // In verbal analogies, tip does not make much sense
+		Console.WriteLine ("    No tip: {0} ({1}%)", nonverbal - tip, (nonverbal - tip) * 100 / nonverbal);
+		Console.WriteLine ("  Games (verbal): {0} ({1}%)", verbal, verbal * 100 / games.Length);
+		Console.WriteLine ("  No rationale: {0} ({1}%)", (games.Length - rationale), (games.Length - rationale) * 100 / games.Length);
+		Console.WriteLine ("");
+		Console.WriteLine ("Verbal analogies");
+		Console.WriteLine ("  Question answer {0}", question_answer);
+		Console.WriteLine ("  Multiple options {0}", multiple_options);
+		Console.WriteLine ("  Pair of words options {0}", words_options);
+		Console.WriteLine ("  Pair of words compare {0} (evil)", words_compare);
+	}
+
+	static void Main (string[] args)
+	{
+		InitCoreLibraries ();
+
+		GameSession session = new GameSession ();
+		GameManagerPreload (session.GameManager);
+
+		Console.WriteLine ("gbrainy {0} (built on {1})", Defines.VERSION, Defines.BUILD_TIME);
+		Console.WriteLine (session.GameManager.GetGamesSummary ());
+
+		Console.WriteLine ("");
+		GetStatistics (session.GameManager);
+	}
+}
+
diff --git a/tools/Makefile.am b/tools/Makefile.am
index a968d4c..1bb34e5 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -8,25 +8,37 @@ TRANSLATIONSCHECKER_CSFILES = \
 	$(srcdir)/GetTextParser/CatalogParser.cs \
 	$(srcdir)/GetTextParser/StringEscaping.cs
 
+GAMESSTATISTICS_CSFILES = \
+	$(srcdir)/Defines.cs	\
+	$(srcdir)/GamesStatistics.cs
+
 ASSEMBLIES = \
 	-r:../src/gbrainy.Core.dll	\
 	-r:Mono.Posix
 
-MONO_PATH = .:$(top_builddir)/src:
+MONO_PATH = $(top_builddir)/src
 
 GameXmlToGetString.exe: $(GAMESXMLSTRINGS_CSFILES) ../data/games.xml $(srcdir)/GameXmlGetStringTemplate.cs
-		   $(CSC) -target:winexe -out:$@ $(EXTRAFLAGS) $(GAMESXMLSTRINGS_CSFILES) $(ASSEMBLIES)
-		   export MONO_PATH=$(MONO_PATH) && $(MONO) $@ $(srcdir)
+		$(CSC) -target:winexe -out:$@ $(EXTRAFLAGS) $(GAMESXMLSTRINGS_CSFILES) $(ASSEMBLIES)
+		export MONO_PATH=$(MONO_PATH) && $(MONO) $@ $(srcdir)
 
 TranslationsChecker.exe: $(TRANSLATIONSCHECKER_CSFILES)
-		   $(CSC) -target:winexe -out:$@ $(EXTRAFLAGS) $(TRANSLATIONSCHECKER_CSFILES) $(ASSEMBLIES)
+		$(CSC) -target:winexe -out:$@ $(EXTRAFLAGS) $(TRANSLATIONSCHECKER_CSFILES) $(ASSEMBLIES)
+
+GamesStatistics.exe: $(GAMESSTATISTICS_CSFILES)
+		$(CSC) -target:winexe -out:$@ $(EXTRAFLAGS) $(GAMESSTATISTICS_CSFILES) $(ASSEMBLIES)
+		
 
 all: GameXmlToGetString.exe
 
+run-stats: 	GamesStatistics.exe
+		export MONO_PATH=$(MONO_PATH) && $(MONO) GamesStatistics.exe $(srcdir)
+
 EXTRA_DIST = $(GAMESXMLSTRINGS_CSFILES) $(srcdir)/GameXmlGetStringTemplate.cs  $(srcdir)/GameXmlGetString.cs
 
 CLEANFILES = GameXmlToGetString.exe \
-	     GameXmlGetString.cs
+		GameXmlGetString.cs \
+	     	GamesStatistics.exe
 
 DISTCLEANFILES = 				\
 	Makefile



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