[chronojump] Person show all events now uses Sqlite.SelectAllSessionsTestsCount. NEED TESTING!



commit bad0ef6925587fd2880fd2396bd22345d64faf98
Author: Xavier de Blas <xaviblas gmail com>
Date:   Sun Oct 16 14:00:10 2022 +0200

    Person show all events now uses Sqlite.SelectAllSessionsTestsCount. NEED TESTING!

 src/gui/person/showAllEvents.cs | 67 +++++++++++++++++++++++++++++++++--------
 src/sqlite/person.cs            |  4 +++
 src/sqlite/session.cs           | 62 +++++++++++++++++++++++++++++++++-----
 3 files changed, 113 insertions(+), 20 deletions(-)
---
diff --git a/src/gui/person/showAllEvents.cs b/src/gui/person/showAllEvents.cs
index 8cc491f53..2e704c97d 100644
--- a/src/gui/person/showAllEvents.cs
+++ b/src/gui/person/showAllEvents.cs
@@ -22,6 +22,7 @@ using System;
 using Gtk;
 using Glade;
 using System.Collections; //ArrayList
+using System.Collections.Generic; //List<T>
 using Mono.Unix;
 
 
@@ -83,9 +84,12 @@ public class PersonShowAllEventsWindow
                label_person_name.Text = currentPerson.Name;
                createComboPersons(sessionID, currentPerson.UniqueID.ToString(), currentPerson.Name);
                createTreeView(treeview_person_show_all_events);
-               store = new TreeStore( typeof (string), typeof (string), typeof (string), typeof (string), 
-                               typeof (string), typeof(string), typeof(string), typeof(string), 
typeof(string), typeof(string),
-                               typeof (string), typeof (string), typeof(string), typeof(string), 
typeof(string));
+               store = new TreeStore(
+                               typeof (string), typeof (string), typeof (string), //session
+                               typeof (string), typeof(string), //jumps
+                               typeof(string), typeof(string), typeof(string), //races
+                               typeof (string), typeof(string), //isometric, elastic
+                               typeof (string), typeof(string) ); //weights, inertial
                treeview_person_show_all_events.Model = store;
                fillTreeView(treeview_person_show_all_events,store, currentPerson.UniqueID);
        }
@@ -159,9 +163,12 @@ public class PersonShowAllEventsWindow
        {
                string myText = UtilGtk.ComboGetActive(combo_persons);
 
-               store = new TreeStore( typeof (string), typeof (string), typeof (string), typeof (string), 
-                               typeof (string), typeof(string), typeof(string), typeof(string), 
typeof(string), typeof(string),
-                               typeof (string), typeof (string), typeof(string), typeof(string), 
typeof(string));
+               store = new TreeStore(
+                               typeof (string), typeof (string), typeof (string), //session
+                               typeof (string), typeof(string), //jumps
+                               typeof(string), typeof(string), typeof(string), //races
+                               typeof (string), typeof(string), //isometric, elastic
+                               typeof (string), typeof(string) ); //weights, inertial
                treeview_person_show_all_events.Model = store;
 
                if(myText != "") {
@@ -200,25 +207,27 @@ public class PersonShowAllEventsWindow
        {
                tv.HeadersVisible=true;
                int count = 0;
+               tv.AppendColumn ( Catalog.GetString ("Date"), new CellRendererText(), "text", count++);
                tv.AppendColumn ( Catalog.GetString ("Session name"), new CellRendererText(), "text", 
count++);
                tv.AppendColumn ( Catalog.GetString ("Place"), new CellRendererText(), "text", count++);
-               tv.AppendColumn ( Catalog.GetString ("Date"), new CellRendererText(), "text", count++);
                tv.AppendColumn ( Catalog.GetString ("Jumps\nsimple"), new CellRendererText(), "text", 
count++);
                tv.AppendColumn ( Catalog.GetString ("Jumps\nreactive"), new CellRendererText(), "text", 
count++);
                tv.AppendColumn ( Catalog.GetString ("Races\nsimple"), new CellRendererText(), "text", 
count++);
                tv.AppendColumn ( Catalog.GetString ("Races\ninterval"), new CellRendererText(), "text", 
count++);
-               tv.AppendColumn ( Catalog.GetString ("Reaction\ntime"), new CellRendererText(), "text", 
count++);
-               tv.AppendColumn ( Catalog.GetString ("Pulses"), new CellRendererText(), "text", count++);
-               tv.AppendColumn ( Catalog.GetString ("MultiChronopic"), new CellRendererText(), "text", 
count++);
-               tv.AppendColumn ( Catalog.GetString ("Encoder sets"), new CellRendererText(), "text", 
count++);
-               tv.AppendColumn ( Catalog.GetString ("Encoder repetitions"), new CellRendererText(), "text", 
count++);
+               tv.AppendColumn ( Catalog.GetString ("Race analyzer"), new CellRendererText(), "text", 
count++);
                tv.AppendColumn ( Catalog.GetString ("Isometric"), new CellRendererText(), "text", count++);
                tv.AppendColumn ( Catalog.GetString ("Elastic"), new CellRendererText(), "text", count++);
-               tv.AppendColumn ( Catalog.GetString ("Race analyzer"), new CellRendererText(), "text", 
count++);
+               tv.AppendColumn (Catalog.GetString ("Weights") + "\n" +
+                               Catalog.GetString("Sets") + " ; " + Catalog.GetString("Repetitions"),
+                               new CellRendererText(), "text", count++);
+               tv.AppendColumn (Catalog.GetString ("Inertial") + "\n" +
+                               Catalog.GetString("Sets") + " ; " + Catalog.GetString("Repetitions"),
+                               new CellRendererText(), "text", count++);
        }
        
        private void fillTreeView (Gtk.TreeView tv, TreeStore store, int personID)
        {
+               /* old code using SqlitePerson.SelectAllPersonEvents
                ArrayList myEvents = new ArrayList ();
                if (personID >= 0)
                        myEvents = SqlitePerson.SelectAllPersonEvents(personID); 
@@ -229,6 +238,38 @@ public class PersonShowAllEventsWindow
                        store.AppendValues (myStr[0], myStr[1], myStr[2], myStr[3], myStr[4], myStr[5], 
                                        myStr[6], myStr[7], myStr[8], myStr[9], myStr[10], myStr[11], 
myStr[12], myStr[13], myStr[14]);
                }
+               */
+
+               //new code using SqliteSession.SelectAllSessionsTestsCount
+               if (personID < 0)
+                       return;
+
+               List<SessionTestsCount> stc_l = SqliteSession.SelectAllSessionsTestsCount (personID); 
//returns a string of values separated by ':'
+               foreach (SessionTestsCount stc in stc_l)
+               {
+                       string [] strings = new string [12];
+                       int i = 0;
+                       strings[i ++] = stc.sessionParams.Date;
+                       strings[i ++] = stc.sessionParams.Name;
+                       //no tags
+                       strings[i ++] = stc.sessionParams.Place;
+                       strings[i ++] = stc.JumpsSimple.ToString ();
+                       strings[i ++] = stc.JumpsReactive.ToString ();
+                       strings[i ++] = stc.RunsSimple.ToString ();
+                       strings[i ++] = stc.RunsInterval.ToString ();
+                       strings[i ++] = stc.RunsEncoder.ToString ();
+                       strings[i ++] = stc.Isometric.ToString ();
+                       strings[i ++] = stc.Elastic.ToString ();
+                       strings[i ++] = string.Format ("{0} ; {1}",
+                                       stc.WeightsSets, stc.WeightsReps); //number of encoder grav 
signal,reps x session
+                       strings[i ++] = string.Format ("{0} ; {1}",
+                                       stc.InertialSets, stc.InertialReps); //number of encoder inertial 
signal,reps x session
+                       store.AppendValues (strings);
+               }
+
+               store.SetSortFunc (0, UtilGtk.DateColumnCompare);
+               store.SetSortColumnId (0, Gtk.SortType.Descending); //date
+               store.ChangeSortColumn();
        }
 
        private void on_button_close_clicked (object o, EventArgs args)
diff --git a/src/sqlite/person.cs b/src/sqlite/person.cs
index 48f92d191..d5a9a131c 100644
--- a/src/sqlite/person.cs
+++ b/src/sqlite/person.cs
@@ -286,6 +286,9 @@ finishForeach:
                return arrayReturn;
        }
 
+       /*
+          unused, now used SqliteSession.SelectAllSessionsTestsCount
+
        public static ArrayList SelectAllPersonEvents (int personID)
        {
                SqliteDataReader reader;
@@ -627,6 +630,7 @@ finishForeach:
 
                return arrayAll;
        }
+*/
        
        public static bool ExistsAndItsNotMe(int uniqueID, string personName)
        {
diff --git a/src/sqlite/session.cs b/src/sqlite/session.cs
index 40bafa461..ccaefaa96 100644
--- a/src/sqlite/session.cs
+++ b/src/sqlite/session.cs
@@ -15,7 +15,7 @@
  *  along with this program; if not, write to the Free Software
  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
- * Copyright (C) 2004-2020   Xavier de Blas <xaviblas gmail com> 
+ * Copyright (C) 2004-2022   Xavier de Blas <xaviblas gmail com>
  */
 
 using System;
@@ -384,7 +384,7 @@ class SqliteSession : Sqlite
        // It's used by chronojump-importer and receives a specific database
        public static List<SessionTestsCount> SelectAllSessionsTestsCount (string filterName, 
SqliteConnection dbcon)
        {
-               return selectAllSessionsTestsCountDo (filterName, dbcon);
+               return selectAllSessionsTestsCountDo (filterName, -1, dbcon); //-1 for allTests, contrary to 
person show all events use
        }
 
        // This is the usual chronojump's call (default database)
@@ -393,7 +393,7 @@ class SqliteSession : Sqlite
                Sqlite.Open();
 
                // SelectAllSessionsTestCount is used here and by the Chronojump importer to allow to pass an 
arbitrary dbcon.
-               List<SessionTestsCount> stc_l = selectAllSessionsTestsCountDo (filterName, dbcon);
+               List<SessionTestsCount> stc_l = selectAllSessionsTestsCountDo (filterName, -1, dbcon);
 
                //close database connection
                Sqlite.Close();
@@ -401,7 +401,21 @@ class SqliteSession : Sqlite
                return stc_l;
        }
 
-       private static List<SessionTestsCount> selectAllSessionsTestsCountDo (string filterName, 
SqliteConnection dbcon)
+       //called from person show all events
+       public static List<SessionTestsCount> SelectAllSessionsTestsCount (int personID)
+       {
+               Sqlite.Open();
+
+               // SelectAllSessionsTestCount is used here and by the Chronojump importer to allow to pass an 
arbitrary dbcon.
+               List<SessionTestsCount> stc_l = selectAllSessionsTestsCountDo ("", personID, dbcon);
+
+               //close database connection
+               Sqlite.Close();
+
+               return stc_l;
+       }
+
+       private static List<SessionTestsCount> selectAllSessionsTestsCountDo (string filterName, int 
personID, SqliteConnection dbcon)
        {
                // This method should NOT use Sqlite.open() / Sqlite.close(): it should only use dbcon
                // to connect to the database. This method is used by the importer after opening an arbitrary
@@ -413,13 +427,26 @@ class SqliteSession : Sqlite
                if(filterName != "")
                        filterNameString = " AND LOWER(session.name) LIKE LOWER (\"%" + filterName  + "%\") ";
 
-               dbcmd.CommandText = 
-                       "SELECT session.*, sport.name, speciallity.name" +
+               if (personID < 0)
+                       dbcmd.CommandText =
+                               "SELECT session.*, sport.name, speciallity.name" +
                                " FROM session, sport, speciallity " +
                                " WHERE session.personsSportID == sport.uniqueID " + 
                                " AND session.personsSpeciallityID == speciallity.UniqueID " +
                                filterNameString + 
                                " ORDER BY session.uniqueID";
+               else {
+                       string tps = Constants.PersonSessionTable;
+                       dbcmd.CommandText =
+                               "SELECT session.*, sport.name, speciallity.name" +
+                               " FROM session, sport, speciallity, " + tps +
+                               " WHERE session.personsSportID == sport.uniqueID " +
+                               " AND session.personsSpeciallityID == speciallity.UniqueID " +
+                               " AND " + tps + ".personID = " + personID + " AND " + tps + ".sessionID = 
session.UniqueID" +
+                               filterNameString +
+                               " ORDER BY session.uniqueID";
+               }
+
                LogB.SQL(dbcmd.CommandText.ToString());
                dbcmd.ExecuteNonQuery();
 
@@ -458,8 +485,17 @@ class SqliteSession : Sqlite
                 * this solution it's more "lighter" for people who have  abig DB
                 * */
 
+               string wherePersonStr = "";
+               string andPersonStr = "";
+               if (personID >= 0)
+               {
+                       wherePersonStr = string.Format (" WHERE personID = {0} ", personID);
+                       andPersonStr = string.Format (" AND personID = {0} ", personID);
+               }
+
                //select persons of each session
                dbcmd.CommandText = "SELECT sessionID, count(*) FROM " + Constants.PersonSessionTable + 
+                       wherePersonStr +
                        " GROUP BY sessionID ORDER BY sessionID";
                LogB.SQL(dbcmd.CommandText.ToString());
                dbcmd.ExecuteNonQuery();
@@ -475,6 +511,7 @@ class SqliteSession : Sqlite
 
                //select jumps of each session
                dbcmd.CommandText = "SELECT sessionID, count(*) FROM " + Constants.JumpTable + 
+                       wherePersonStr +
                        " GROUP BY sessionID ORDER BY sessionID";
                LogB.SQL(dbcmd.CommandText.ToString());
                dbcmd.ExecuteNonQuery();
@@ -490,6 +527,7 @@ class SqliteSession : Sqlite
 
                //select jumpsRj of each session
                dbcmd.CommandText = "SELECT sessionID, count(*) FROM " + Constants.JumpRjTable + 
+                       wherePersonStr +
                        " GROUP BY sessionID ORDER BY sessionID";
                LogB.SQL(dbcmd.CommandText.ToString());
                dbcmd.ExecuteNonQuery();
@@ -505,6 +543,7 @@ class SqliteSession : Sqlite
 
                //select runs of each session
                dbcmd.CommandText = "SELECT sessionID, count(*) FROM " + Constants.RunTable + 
+                       wherePersonStr +
                        " GROUP BY sessionID ORDER BY sessionID";
                LogB.SQL(dbcmd.CommandText.ToString());
                dbcmd.ExecuteNonQuery();
@@ -520,6 +559,7 @@ class SqliteSession : Sqlite
 
                //select runsInterval of each session
                dbcmd.CommandText = "SELECT sessionID, count(*) FROM " + Constants.RunIntervalTable + 
+                       wherePersonStr +
                        " GROUP BY sessionID ORDER BY sessionID";
                LogB.SQL(dbcmd.CommandText.ToString());
                dbcmd.ExecuteNonQuery();
@@ -535,6 +575,7 @@ class SqliteSession : Sqlite
 
                //select reaction time of each session
                dbcmd.CommandText = "SELECT sessionID, count(*) FROM " + Constants.ReactionTimeTable + 
+                       wherePersonStr +
                        " GROUP BY sessionID ORDER BY sessionID";
                LogB.SQL(dbcmd.CommandText.ToString());
                dbcmd.ExecuteNonQuery();
@@ -550,6 +591,7 @@ class SqliteSession : Sqlite
 
                //select pulses of each session
                dbcmd.CommandText = "SELECT sessionID, count(*) FROM " + Constants.PulseTable + 
+                       wherePersonStr +
                        " GROUP BY sessionID ORDER BY sessionID";
                LogB.SQL(dbcmd.CommandText.ToString());
                dbcmd.ExecuteNonQuery();
@@ -565,6 +607,7 @@ class SqliteSession : Sqlite
 
                //select multichronopic of each session
                dbcmd.CommandText = "SELECT sessionID, count(*) FROM " + Constants.MultiChronopicTable + 
+                       wherePersonStr +
                        " GROUP BY sessionID ORDER BY sessionID";
                LogB.SQL(dbcmd.CommandText.ToString());
                dbcmd.ExecuteNonQuery();
@@ -580,7 +623,9 @@ class SqliteSession : Sqlite
 
 
                //select encoder stuff of each session
-               dbcmd.CommandText = "SELECT sessionID, encoderConfiguration, signalOrCurve FROM " + 
Constants.EncoderTable + " ORDER BY sessionID";
+               dbcmd.CommandText = "SELECT sessionID, encoderConfiguration, signalOrCurve FROM " + 
Constants.EncoderTable +
+                       wherePersonStr +
+                       " ORDER BY sessionID";
                LogB.SQL(dbcmd.CommandText.ToString());
                dbcmd.ExecuteNonQuery();
 
@@ -644,6 +689,7 @@ class SqliteSession : Sqlite
                {
                        dbcmd.CommandText = "SELECT sessionID, count(*) FROM " + Constants.ForceSensorTable +
                                " WHERE " + Constants.ForceSensorTable + ".stiffness < 0" + //isometric has 
stiffness -1.0
+                               andPersonStr +
                                " GROUP BY sessionID ORDER BY sessionID";
                        LogB.SQL(dbcmd.CommandText.ToString());
                        dbcmd.ExecuteNonQuery();
@@ -665,6 +711,7 @@ class SqliteSession : Sqlite
                {
                        dbcmd.CommandText = "SELECT sessionID, count(*) FROM " + Constants.ForceSensorTable +
                                " WHERE " + Constants.ForceSensorTable + ".stiffness > 0" + //elastic has 
stiffness > 0
+                               andPersonStr +
                                " GROUP BY sessionID ORDER BY sessionID";
                        LogB.SQL(dbcmd.CommandText.ToString());
                        dbcmd.ExecuteNonQuery();
@@ -685,6 +732,7 @@ class SqliteSession : Sqlite
                if(tableExists(true, Constants.RunEncoderTable))
                {
                        dbcmd.CommandText = "SELECT sessionID, count(*) FROM " + Constants.RunEncoderTable +
+                               wherePersonStr +
                                " GROUP BY sessionID ORDER BY sessionID";
                        LogB.SQL(dbcmd.CommandText.ToString());
                        dbcmd.ExecuteNonQuery();


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