[chronojump] encoder compare intersession done



commit b4e0486a52406250d55943a0510d8316a9a61aa6
Author: Xavier de Blas <xaviblas gmail com>
Date:   Thu Mar 7 16:42:35 2013 +0100

    encoder compare intersession done

 glade/chronojump.glade |    2 +-
 src/encoder.cs         |   29 +++++++
 src/gui/encoder.cs     |  203 ++++++++++++++++++++++++++++++++++++++++--------
 src/sqlite/encoder.cs  |   74 +++++++++++++++++-
 4 files changed, 270 insertions(+), 38 deletions(-)
---
diff --git a/glade/chronojump.glade b/glade/chronojump.glade
index 4c76011..fd50a29 100644
--- a/glade/chronojump.glade
+++ b/glade/chronojump.glade
@@ -13336,7 +13336,7 @@ on current Chronojump version.</property>
                                                             </child>
                                                             <child>
                                                             <widget class="GtkButton" 
id="button_encoder_analyze_data_compare">
-                                                            <property name="label" 
translatable="yes">Compare</property>
+                                                            <property name="label" 
translatable="yes">Compare to</property>
                                                             <property name="can_focus">True</property>
                                                             <property name="receives_default">True</property>
                                                             <property 
name="use_action_appearance">False</property>
diff --git a/src/encoder.cs b/src/encoder.cs
index 902068d..8ab232c 100644
--- a/src/encoder.cs
+++ b/src/encoder.cs
@@ -319,6 +319,35 @@ public class EncoderSQL
 
 }
 
+public class EncoderPersonCurvesInDB
+{
+       public int personID;
+       public int sessionID;
+       public string sessionName;
+       public string sessionDate;
+       public int countActive;
+       public int countAll;
+       
+       public EncoderPersonCurvesInDB() {
+       }
+       public EncoderPersonCurvesInDB(int personID, int sessionID, string sessionName, string sessionDate,
+                       int countActive, int countAll) {
+               this.personID =         personID;
+               this.sessionID =        sessionID;
+               this.sessionName =      sessionName;
+               this.sessionDate =      sessionDate;
+               this.countActive =      countActive;
+               this.countAll =         countAll;
+       }
+
+       public string [] ToStringArray() {
+               string [] s = { "", sessionID.ToString(), sessionName, sessionDate,
+                       countActive.ToString(), countAll.ToString()
+               };
+               return s;
+       }
+}
+
 public class EncoderExercise
 {
        public int uniqueID;
diff --git a/src/gui/encoder.cs b/src/gui/encoder.cs
index 453ea84..881004a 100644
--- a/src/gui/encoder.cs
+++ b/src/gui/encoder.cs
@@ -121,7 +121,8 @@ public partial class ChronoJumpWindow
        private string encoderTimeStamp;
        private string encoderSignalUniqueID;
 
-       private ArrayList encoderComparePersons;
+       private ArrayList encoderCompareInterperson;    //personID:personName
+       private ArrayList encoderCompareIntersession;   //sessionID:sessionDate
 
        private static int encoderCaptureCountdown;
        private static Gdk.Point [] encoderCapturePoints;               //stored to be realtime displayed
@@ -491,6 +492,16 @@ public partial class ChronoJumpWindow
        
        void on_button_encoder_analyze_data_compare_clicked (object o, EventArgs args) 
        {
+               if(Util.FindOnArray(':',1,0,UtilGtk.ComboGetActive(combo_encoder_analyze_data_compare),
+                                       encoderDataCompareTranslation) == "Between persons")
+                       encoder_analyze_data_compare_interperson();
+               else if(Util.FindOnArray(':',1,0,UtilGtk.ComboGetActive(combo_encoder_analyze_data_compare),
+                                       encoderDataCompareTranslation) == "Between sessions")
+                       encoder_analyze_data_compare_intersession();
+       }
+
+       void encoder_analyze_data_compare_interperson () 
+       {
                //find all persons except current person
                ArrayList dataPre = SqlitePersonSession.SelectCurrentSessionPersons(currentSession.UniqueID); 
                ArrayList data = new ArrayList();
@@ -517,7 +528,7 @@ public partial class ChronoJumpWindow
                int count = 0;
                foreach(string [] sPersons in data) {
                        bool found = false;
-                       foreach(string s2 in encoderComparePersons)
+                       foreach(string s2 in encoderCompareInterperson)
                                if(Util.FetchID(s2).ToString() == sPersons[1])
                                        found = true;
 
@@ -529,8 +540,8 @@ public partial class ChronoJumpWindow
                        
                string [] columnsString = {
                        Catalog.GetString("hiddennothing"),
-                       Catalog.GetString("ID"),
-                       Catalog.GetString("Name"),
+                       Catalog.GetString("Person ID"),
+                       Catalog.GetString("Person name"),
                        Catalog.GetString("Selected\ncurves"),
                        Catalog.GetString("All\ncurves")
                };
@@ -556,7 +567,8 @@ public partial class ChronoJumpWindow
                genericWin.ShowButtonCancel(false);
                genericWin.SetButtonAcceptSensitive(true);
                //manage selected, unselected curves
-               genericWin.Button_accept.Clicked += new EventHandler(on_encoder_analyze_data_compare_done);
+               genericWin.Button_accept.Clicked += new EventHandler(
+                               on_encoder_analyze_data_compare_interperson_done);
 
                //used when we don't need to read data, 
                //and we want to ensure next window will be created at needed size
@@ -566,22 +578,121 @@ public partial class ChronoJumpWindow
                genericWin.ShowNow();
        }
 
-       void on_encoder_analyze_data_compare_done (object o, EventArgs args) {
-               genericWin.Button_accept.Clicked -= new EventHandler(on_encoder_analyze_data_compare_done);
+       void on_encoder_analyze_data_compare_interperson_done (object o, EventArgs args) {
+               genericWin.Button_accept.Clicked -= new EventHandler(
+                               on_encoder_analyze_data_compare_interperson_done);
        
-               encoderComparePersons = new ArrayList ();
+               encoderCompareInterperson = new ArrayList ();
                string [] selectedID = genericWin.GetCheckboxesStatus(1,true);
                string [] selectedName = genericWin.GetCheckboxesStatus(2,true);
 
                for (int i=0 ; i < selectedID.Length ; i ++)
-                       encoderComparePersons.Add(Convert.ToInt32(selectedID[i]) + ":" + selectedName[i]);
-               //encoderComparePersons.Add(currentPerson.UniqueID + ":" + currentPerson.Name);
+                       encoderCompareInterperson.Add(Convert.ToInt32(selectedID[i]) + ":" + selectedName[i]);
 
                genericWin.HideAndNull();
                
                Log.WriteLine("done");
        }
+       
+       void encoder_analyze_data_compare_intersession () 
+       {
+               //select all curves of this person on all sessions
+               ArrayList dataPre = SqliteEncoder.SelectCompareIntersession(
+                               false, currentPerson.UniqueID); 
+               
+               //..except on current session
+               ArrayList data = new ArrayList();
+               foreach(EncoderPersonCurvesInDB encPS in dataPre)
+                       if(encPS.sessionID != currentSession.UniqueID)
+                               data.Add(encPS);
+       
+               //prepare unsensitive rows      
+               ArrayList nonSensitiveRows = new ArrayList();
+               int count = 0;
+               foreach(EncoderPersonCurvesInDB encPS in data) {
+                       if(encPS.countActive == 0)
+                               nonSensitiveRows.Add(count);
+                       count ++;
+               }
+               
+               //prepare checkboxes to be marked       
+               string [] checkboxes = new string[data.Count]; //to store active or inactive status
+               count = 0;
+               foreach(EncoderPersonCurvesInDB encPS in data) {
+                       bool found = false;
+                       foreach(string s2 in encoderCompareIntersession)
+                               if(Util.FetchID(s2) == encPS.sessionID)
+                                       found = true;
 
+                       if(found)
+                               checkboxes[count++] = "active";
+                       else
+                               checkboxes[count++] = "inactive";
+               }                       
+                       
+               string [] columnsString = {
+                       Catalog.GetString("hiddennothing"),
+                       Catalog.GetString("Session ID"),
+                       Catalog.GetString("Session name"),
+                       Catalog.GetString("Session date"),
+                       Catalog.GetString("Selected\ncurves"),
+                       Catalog.GetString("All\ncurves")
+               };
+
+               ArrayList bigArray = new ArrayList();
+               ArrayList a1 = new ArrayList();
+               ArrayList a2 = new ArrayList();
+               
+               //0 is the widgget to show; 1 is the editable; 2 id default value
+               a1.Add(Constants.GenericWindowShow.COMBOALLNONESELECTED); a1.Add(true); a1.Add("ALL");
+               bigArray.Add(a1);
+               
+               a2.Add(Constants.GenericWindowShow.TREEVIEW); a2.Add(true); a2.Add("");
+               bigArray.Add(a2);
+               
+               genericWin = GenericWindow.Show(false,  //don't show now
+                               string.Format(Catalog.GetString("Compare curves of {0} from this session with 
the following sessions."), 
+                                       currentPerson.Name), bigArray);
+
+               //convert data from array of EncoderPersonCurvesInDB to array of strings []
+               ArrayList dataConverted = new ArrayList();
+               foreach(EncoderPersonCurvesInDB encPS in data) {
+                       dataConverted.Add(encPS.ToStringArray());
+               }
+
+               genericWin.CreateComboAllNoneSelected();
+               genericWin.SetTreeview(columnsString, true, dataConverted, nonSensitiveRows);
+               genericWin.MarkActiveCurves(checkboxes);
+               genericWin.ShowButtonCancel(false);
+               genericWin.SetButtonAcceptSensitive(true);
+               //manage selected, unselected curves
+               genericWin.Button_accept.Clicked += new EventHandler(
+                               on_encoder_analyze_data_compare_intersession_done);
+
+               //used when we don't need to read data, 
+               //and we want to ensure next window will be created at needed size
+               //genericWin.DestroyOnAccept=true;
+               //here is comented because we are going to read the checkboxes
+
+               genericWin.ShowNow();
+       }
+
+       void on_encoder_analyze_data_compare_intersession_done (object o, EventArgs args) {
+               genericWin.Button_accept.Clicked -= new EventHandler(
+                               on_encoder_analyze_data_compare_intersession_done);
+       
+               encoderCompareIntersession = new ArrayList ();
+               string [] selectedID = genericWin.GetCheckboxesStatus(1,true);
+               string [] selectedDate = genericWin.GetCheckboxesStatus(3,true);
+
+               for (int i=0 ; i < selectedID.Length ; i ++)
+                       encoderCompareIntersession.Add(Convert.ToInt32(selectedID[i]) + ":" + 
selectedDate[i]);
+
+               genericWin.HideAndNull();
+               
+               Log.WriteLine("done");
+       }
+       
 
        void on_button_encoder_load_signal_clicked (object o, EventArgs args) 
        {
@@ -1214,17 +1325,34 @@ public partial class ChronoJumpWindow
                        //select curves for this person
                        ArrayList data = new ArrayList();
 
+                       //select currentPerson, currentSession curves
                        data = SqliteEncoder.Select(
                                false, -1, currentPerson.UniqueID, currentSession.UniqueID, "curve", true);
                        
-                       //if compare, select curves for other persons and add
+                       //if compare persons, select curves for other persons and add
                        
if(Util.FindOnArray(':',1,0,UtilGtk.ComboGetActive(combo_encoder_analyze_data_compare),
-                                       encoderDataCompareTranslation) != "No compare") {
+                                       encoderDataCompareTranslation) == "Between persons") {
                                ArrayList dataPre = new ArrayList();
-                               for (int i=0 ; i < encoderComparePersons.Count ; i ++) {
+                               for (int i=0 ; i < encoderCompareInterperson.Count ; i ++) {
                                        dataPre = SqliteEncoder.Select(
-                                               false, -1, Util.FetchID(encoderComparePersons[i].ToString()),
-                                               currentSession.UniqueID, "curve", true);
+                                               false, -1, 
+                                               Util.FetchID(encoderCompareInterperson[i].ToString()),
+                                               currentSession.UniqueID, 
+                                               "curve", true);
+                                       //this curves are added to data, data included currentPerson, 
currentSession
+                                       foreach(EncoderSQL es in dataPre) 
+                                               data.Add(es);
+                               }
+                       } else 
if(Util.FindOnArray(':',1,0,UtilGtk.ComboGetActive(combo_encoder_analyze_data_compare),
+                                       encoderDataCompareTranslation) == "Between sessions") {
+                               ArrayList dataPre = new ArrayList();
+                               for (int i=0 ; i < encoderCompareIntersession.Count ; i ++) {
+                                       dataPre = SqliteEncoder.Select(
+                                               false, -1,
+                                               currentPerson.UniqueID, 
+                                               Util.FetchID(encoderCompareIntersession[i].ToString()),
+                                               "curve", true);
+                                       //this curves are added to data, data included currentPerson, 
currentSession
                                        foreach(EncoderSQL es in dataPre) 
                                                data.Add(es);
                                }
@@ -1240,7 +1368,8 @@ public partial class ChronoJumpWindow
                                        SqliteEncoder.SelectEncoderExercises(true, -1, false);
                        Sqlite.Close(); 
                        EncoderExercise ex = new EncoderExercise();
-
+                                               
+Log.WriteLine("AT ANALYZE");
                        foreach(EncoderSQL eSQL in data) {
                                foreach(EncoderExercise eeSearch in eeArray)
                                        if(eSQL.exerciseID == eeSearch.uniqueID)
@@ -1251,20 +1380,29 @@ public partial class ChronoJumpWindow
                                //      SqliteEncoder.SelectEncoderExercises(true, eSQL.exerciseID, false)[0];
                                mass += bodyMass * ex.percentBodyWeight / 100.0;
 
-                               //personName
-                               string personName = "";
+                               //seriesName
+                               string seriesName = "";
                                if(Util.FindOnArray(':',1,0,
                                                        
UtilGtk.ComboGetActive(combo_encoder_analyze_data_compare),
-                                               encoderDataCompareTranslation) != "No compare") 
+                                               encoderDataCompareTranslation) == "Between persons") 
                                {
-                                       foreach(string str in encoderComparePersons)
+                                       foreach(string str in encoderCompareInterperson)
                                                if(Util.FetchID(str) == eSQL.personID)
-                                                       personName = Util.FetchName(str);
+                                                       seriesName = Util.FetchName(str);
+                               } else if(Util.FindOnArray(':',1,0,
+                                                       
UtilGtk.ComboGetActive(combo_encoder_analyze_data_compare),
+                                               encoderDataCompareTranslation) == "Between sessions") 
+                               {
+                                       foreach(string str in encoderCompareIntersession) {
+Log.WriteLine(str);
+                                               if(Util.FetchID(str) == eSQL.sessionID)
+                                                       seriesName = Util.FetchName(str);
+                                       }
                                }
-                               if(personName == "")
-                                       personName = currentPerson.Name;
+                               if(seriesName == "")
+                                       seriesName = currentPerson.Name;
 
-                               writer.WriteLine(eSQL.future1 + "," + personName + "," + ex.name + "," + 
+                               writer.WriteLine(eSQL.future1 + "," + seriesName + "," + ex.name + "," + 
                                                Util.ConvertToPoint(mass).ToString() + "," + 
                                                Util.ConvertToPoint(eSQL.smooth) + "," + eSQL.GetDate(true) + 
"," + 
                                                eSQL.GetFullURL(true) + "," +   //convertPathToR
@@ -1641,19 +1779,16 @@ public partial class ChronoJumpWindow
                        button_encoder_analyze_data_compare.Visible = true;
 
                        //put some data just in case user doesn't click on compare button
-                       encoderComparePersonsInitialize();
+                       encoderCompareInitialize();
                }
        }
 
        //put some data just in case user doesn't click on compare button
-       private void encoderComparePersonsInitialize() {
-               if(encoderComparePersons == null)
-                       encoderComparePersons = new ArrayList ();
-               /*
-               string myPerson = currentPerson.UniqueID + ":" + currentPerson.Name;
-               if(! Util.FoundInArrayList(encoderComparePersons, myPerson))
-                       encoderComparePersons.Add(myPerson);
-                       */
+       private void encoderCompareInitialize() {
+               if(encoderCompareInterperson == null)
+                       encoderCompareInterperson = new ArrayList ();
+               if(encoderCompareIntersession == null)
+                       encoderCompareIntersession = new ArrayList ();
        }
 
        void on_combo_encoder_analyze_cross_changed (object o, EventArgs args)
@@ -2407,7 +2542,7 @@ Log.Write("l");
                treeview_encoder_analyze_curves.Sensitive = false;
 
                //put some data just in case user doesn't click on compare button
-               encoderComparePersonsInitialize();
+               encoderCompareInitialize();
        }
 
        private void encoderButtonsSensitive(encoderSensEnum option) {
diff --git a/src/sqlite/encoder.cs b/src/sqlite/encoder.cs
index e8a6048..ace2f30 100644
--- a/src/sqlite/encoder.cs
+++ b/src/sqlite/encoder.cs
@@ -135,6 +135,7 @@ class SqliteEncoder : Sqlite
        //or
        //pass uniqueID==-1 and personID, sessionID, signalOrCurve values, and will return some records
        //personID can be -1 to get all on that session
+       //sessionID can be -1 to get all sessions
        public static ArrayList Select (bool dbconOpened, 
                        int uniqueID, int personID, int sessionID, string signalOrCurve, bool onlyActive)
        {
@@ -143,14 +144,18 @@ class SqliteEncoder : Sqlite
 
                string personIDStr = "";
                if(personID != -1)
-                       personIDStr = "personID = " + personID + " AND ";
+                       personIDStr = " personID = " + personID + " AND ";
+
+               string sessionIDStr = "";
+               if(sessionID != -1)
+                       sessionIDStr = " sessionID = " + sessionID + " AND ";
 
                string selectStr = "";
                if(uniqueID != -1)
                        selectStr = Constants.EncoderTable + ".uniqueID = " + uniqueID;
                else
-                       selectStr = personIDStr + " sessionID = " + sessionID + 
-                       " AND signalOrCurve = '" + signalOrCurve + "'";
+                       selectStr = personIDStr + sessionIDStr + 
+                       " signalOrCurve = '" + signalOrCurve + "'";
 
                string onlyActiveString = "";
                if(onlyActive)
@@ -203,6 +208,69 @@ class SqliteEncoder : Sqlite
                return array;
        }
        
+
+       public static ArrayList SelectCompareIntersession (bool dbconOpened, int personID)
+       {
+               if(! dbconOpened)
+                       dbcon.Open();
+
+               /* OLD, returns a row for active and a row for inactive at each session 
+               dbcmd.CommandText = 
+                       "SELECT count(*), encoder.sessionID, session.name, session.date, encoder.future1 " +
+                       " FROM encoder, session, person77 " +
+                       " WHERE encoder.personID == " + personID + " AND signalOrCurve == 'curve' AND " + 
+                       " encoder.personID == person77.uniqueID AND encoder.sessionID == session.uniqueID " + 
+                       " GROUP BY encoder.sessionID, encoder.future1 ORDER BY encoder.sessionID, 
encoder.future1";
+                       */
+
+               //returns a row for each session where there are active or inactive
+               dbcmd.CommandText = 
+                       "SELECT encoder.sessionID, session.name, session.date, " +
+                       " SUM(CASE WHEN encoder.future1 = 'active' THEN 1 END) as active, " +
+                       " SUM(CASE WHEN encoder.future1 = 'inactive' THEN 1 END) as inactive " + 
+                       " FROM encoder, session, person77 " +
+                       " WHERE encoder.personID == " + personID + " AND signalOrCurve == 'curve' AND " +
+                       " encoder.personID == person77.uniqueID AND encoder.sessionID == session.uniqueID " +
+                       " GROUP BY encoder.sessionID ORDER BY encoder.sessionID, encoder.future1";
+       
+               Log.WriteLine(dbcmd.CommandText.ToString());
+               
+               SqliteDataReader reader;
+               reader = dbcmd.ExecuteReader();
+
+               ArrayList array = new ArrayList();
+               EncoderPersonCurvesInDB encPS = new EncoderPersonCurvesInDB();
+               while(reader.Read()) {
+                       int active = 0;
+                       string activeStr = reader[3].ToString();
+                       if(Util.IsNumber(activeStr, false))
+                               active = Convert.ToInt32(activeStr);
+                       
+                       int inactive = 0;
+                       string inactiveStr = reader[4].ToString();
+                       if(Util.IsNumber(inactiveStr, false))
+                               inactive = Convert.ToInt32(inactiveStr);
+
+
+                       encPS = new EncoderPersonCurvesInDB (
+                                       personID,
+                                       Convert.ToInt32(reader[0].ToString()),  //sessionID
+                                       reader[1].ToString(),                   //sessionName
+                                       reader[2].ToString(),                   //sessionDate
+                                       active,                                 //active
+                                       active + inactive                       //all: active + inactive 
+                                       );
+                       array.Add(encPS);
+               }
+               reader.Close();
+               if(! dbconOpened)
+                       dbcon.Close();
+
+               return array;
+       }
+
+       
+
        /*
         * EncoderExercise stuff
         */


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