[chronojump] compare intersession, select by weights 75% done



commit 996a5ad3f6ae705c45dc731b9a1060c34008790d
Author: Xavier de Blas <xaviblas gmail com>
Date:   Wed May 25 18:28:00 2016 +0200

    compare intersession, select by weights 75% done

 src/encoder.cs                      |   52 ++++++++++++++++---
 src/gui/encoder.cs                  |    6 ++
 src/gui/encoderSelectRepetitions.cs |   32 +++++++++++-
 src/gui/genericWindow.cs            |    6 +-
 src/sqlite/encoder.cs               |   94 ++++++++++++++++++++++++++++------
 src/util.cs                         |   18 ++++++-
 6 files changed, 176 insertions(+), 32 deletions(-)
---
diff --git a/src/encoder.cs b/src/encoder.cs
index c87e63d..b189797 100644
--- a/src/encoder.cs
+++ b/src/encoder.cs
@@ -820,7 +820,21 @@ public class EncoderSQL
 
 }
 
+//related to all reps, not only active
+public class EncoderPersonCurvesInDBDeep
+{
+       public double extraWeight;
+       public int count; //this count is all reps (not only active)
+
+       public EncoderPersonCurvesInDBDeep(double w, int c) {
+               this.extraWeight = w;
+               this.count = c;
+       }
 
+       public override string ToString() {
+               return count.ToString() + "*" + extraWeight.ToString();// + "Kg";
+       }
+}
 public class EncoderPersonCurvesInDB
 {
        public int personID;
@@ -829,24 +843,44 @@ public class EncoderPersonCurvesInDB
        public string sessionDate;
        public int countActive;
        public int countAll;
+       public List<EncoderPersonCurvesInDBDeep> lDeep;
        
        public EncoderPersonCurvesInDB() {
        }
-       public EncoderPersonCurvesInDB(int personID, int sessionID, string sessionName, string sessionDate,
-                       int countActive, int countAll) {
+       public EncoderPersonCurvesInDB(int personID, int sessionID, string sessionName, string sessionDate) 
+       {
                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()
-                       countAll.ToString()
-               };
+       public string [] ToStringArray(bool deep) {
+               string [] s;
+
+               //the "" will be for the checkbox on genericWin
+               if(deep) {
+                       s = new string[]{ sessionID.ToString(), "", sessionName, sessionDate,
+                               //countActive.ToString(), countAll.ToString()
+                               countAll.ToString(), DeepPrint()
+                       };
+               } else {
+                       s = new string[]{ sessionID.ToString(), "", sessionName, sessionDate,
+                               //countActive.ToString(), countAll.ToString()
+                               countAll.ToString()
+                       };
+               }
+
+               return s;
+       }
+
+       private string DeepPrint() {
+               string s = "";
+               string sep = "";
+               foreach(EncoderPersonCurvesInDBDeep e in lDeep) {
+                       s += sep + e.ToString();
+                       sep = " ";
+               }
                return s;
        }
 }
diff --git a/src/gui/encoder.cs b/src/gui/encoder.cs
index b22968d..43db628 100644
--- a/src/gui/encoder.cs
+++ b/src/gui/encoder.cs
@@ -1618,6 +1618,12 @@ public partial class ChronoJumpWindow
                                        false, true);
                        updateComboEncoderAnalyzeCurveNumSavedReps(data, encSelReps.RepsActive);
                } //interperson and intersession modes don't use combo_encoder_analyze_curve_num_combo
+               
+               if(radio_encoder_analyze_individual_all_sessions.Active) {
+                       LogB.Information("EncoderInterSessionDateOnXWeights");
+                       foreach (double d in encSelReps.EncoderInterSessionDateOnXWeights)
+                               LogB.Information(d.ToString());
+               }
        
                button_encoder_analyze_sensitiveness();
        }
diff --git a/src/gui/encoderSelectRepetitions.cs b/src/gui/encoderSelectRepetitions.cs
index 95ee296..8521976 100644
--- a/src/gui/encoderSelectRepetitions.cs
+++ b/src/gui/encoderSelectRepetitions.cs
@@ -69,6 +69,7 @@ public class EncoderSelectRepetitions
        public ArrayList EncoderCompareInter;
        public int RepsActive;
        public int RepsAll;
+       public ArrayList EncoderInterSessionDateOnXWeights;
 
        
        public EncoderSelectRepetitions() {
@@ -377,12 +378,15 @@ public class EncoderSelectRepetitionsIndividualCurrentSession : EncoderSelectRep
 
 public class EncoderSelectRepetitionsIndividualAllSessions : EncoderSelectRepetitions
 {
+       private int repsByWeightsColumn;
+
        public EncoderSelectRepetitionsIndividualAllSessions() {
                Type = Types.INDIVIDUAL_ALL_SESSIONS;
        
                dateColumn = 3;
                //activeRepsColumn = 4;
                allRepsColumn = 4;
+               repsByWeightsColumn = allRepsColumn +1;
 
                if(EncoderCompareInter == null)
                        EncoderCompareInter = new ArrayList ();
@@ -432,7 +436,8 @@ public class EncoderSelectRepetitionsIndividualAllSessions : EncoderSelectRepeti
                        Catalog.GetString("Session date"),
                        //Catalog.GetString("Selected\nrepetitions"),
                        //Catalog.GetString("All\nrepetitions")
-                       Catalog.GetString("Saved repetitions")
+                       Catalog.GetString("Saved repetitions"),
+                       "Weights (repetitions * weight)"
                };
 
                bigArray = new ArrayList();
@@ -456,7 +461,7 @@ public class EncoderSelectRepetitionsIndividualAllSessions : EncoderSelectRepeti
                //convert data from array of EncoderPersonCurvesInDB to array of strings []
                ArrayList dataConverted = new ArrayList();
                foreach(EncoderPersonCurvesInDB encPS in data) {
-                       dataConverted.Add(encPS.ToStringArray());
+                       dataConverted.Add(encPS.ToStringArray(true));
                }
 
                genericWin.SetTreeview(columnsString, true, dataConverted, nonSensitiveRows, 
Constants.ContextMenu.NONE, false);
@@ -470,12 +475,34 @@ public class EncoderSelectRepetitionsIndividualAllSessions : EncoderSelectRepeti
                
                //to have encoderCompareInter without opening the select window
                updateEncoderCompareInterAndReps();
+               updateEncoderInterSessionDateOnXWeights();
 
                //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
        }
+               
+       private void updateEncoderInterSessionDateOnXWeights() 
+       {
+               EncoderInterSessionDateOnXWeights = new ArrayList();
+               
+               string [] selectedID = genericWin.GetColumn(0,true); //only active
+               string [] selectedRepsByWeights = genericWin.GetColumn(repsByWeightsColumn,true); //only 
active
+               for (int i=0 ; i < selectedID.Length ; i ++) 
+               {
+                       string [] repsByWeights = selectedRepsByWeights[i].Split(new char[] {' '});
+                       //repsByWeights is "3*10", "5*70", "4*120"
+                       foreach(string repByWeight in repsByWeights) {
+                               string [] chunks = repByWeight.Split(new char[] {'*'});
+                               if(Util.IsNumber(chunks[1], true))
+                                       EncoderInterSessionDateOnXWeights = Util.AddToArrayListIfNotExist(
+                                                       EncoderInterSessionDateOnXWeights, 
Convert.ToDouble(chunks[1]));
+                       }
+               }
+                                       
+               EncoderInterSessionDateOnXWeights.Sort();
+       }
        
        protected override void on_show_repetitions_done (object o, EventArgs args) 
        {
@@ -483,6 +510,7 @@ public class EncoderSelectRepetitionsIndividualAllSessions : EncoderSelectRepeti
                genericWin.Button_accept.Clicked -= new EventHandler(on_show_repetitions_done);
        
                updateEncoderCompareInterAndReps();
+               updateEncoderInterSessionDateOnXWeights();
        
                FakeButtonDone.Click();         
                LogB.Information("done");
diff --git a/src/gui/genericWindow.cs b/src/gui/genericWindow.cs
index ed2e971..dabc976 100644
--- a/src/gui/genericWindow.cs
+++ b/src/gui/genericWindow.cs
@@ -597,13 +597,13 @@ public class GenericWindow
        
        public int GetCell(int uniqueID, int column) 
        {
-               LogB.Information(" GetCell " + uniqueID.ToString() + " " + column.ToString());
+               //LogB.Information(" GetCell " + uniqueID.ToString() + " " + column.ToString());
                Gtk.TreeIter iter;
                bool okIter = store.GetIterFirst(out iter);
                if(okIter) {
                        do {
-                               LogB.Information("_0_ " + (string) store.GetValue (iter, 0));
-                               LogB.Information("_column_ " + column.ToString() + " " + (string) 
store.GetValue (iter, column));
+                               //LogB.Information("_0_ " + (string) store.GetValue (iter, 0));
+                               //LogB.Information("_column_ " + column.ToString() + " " + (string) 
store.GetValue (iter, column));
                                if( ((string) store.GetValue (iter, 0)) == uniqueID.ToString()) {
                                        return Convert.ToInt32( (string) store.GetValue (iter, column) );
                                }
diff --git a/src/sqlite/encoder.cs b/src/sqlite/encoder.cs
index 866344d..eefb2f0 100644
--- a/src/sqlite/encoder.cs
+++ b/src/sqlite/encoder.cs
@@ -22,6 +22,7 @@ using System;
 using System.Data;
 using System.IO;
 using System.Collections; //ArrayList
+using System.Collections.Generic; //List<T>
 using Mono.Data.Sqlite;
 using Mono.Unix;
 
@@ -327,7 +328,7 @@ class SqliteEncoder : Sqlite
 
                //returns a row for each session where there are active or inactive
                dbcmd.CommandText = 
-                       "SELECT encoder.sessionID, session.name, session.date, " +
+                       "SELECT encoder.sessionID, session.name, session.date, encoder.extraWeight, " +
                        " SUM(CASE WHEN encoder.status = \"active\" THEN 1 END) as active, " +
                        " SUM(CASE WHEN encoder.status = \"inactive\" THEN 1 END) as inactive " + 
                        " FROM encoder, session, person77 " +
@@ -335,7 +336,7 @@ class SqliteEncoder : Sqlite
                        exerciseIDStr +         
                        " 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.status";
+                       " GROUP BY encoder.sessionID, encoder.extraWeight ORDER BY encoder.sessionID, 
encoder.extraWeight, encoder.status";
        
                LogB.SQL(dbcmd.CommandText.ToString());
                
@@ -344,27 +345,86 @@ class SqliteEncoder : Sqlite
 
                ArrayList array = new ArrayList();
                EncoderPersonCurvesInDB encPS = new EncoderPersonCurvesInDB();
+               /*
+                * eg.
+                * sessID|sess name|date|extraWe|a|i (a: active, i: inactive)
+                * 20|Encoder tests|2012-12-10|7|3|
+                * 20|Encoder tests|2012-12-10|0||9
+                * 20|Encoder tests|2012-12-10|10||34
+                * 20|Encoder tests|2012-12-10|58||1
+                * 20|Encoder tests|2012-12-10|61||1
+                * 26|sessio-proves|2013-07-08|10|5|36
+                * 30|proves encoder|2013-11-08|0|2|
+                * 30|proves encoder|2013-11-08|100|5|
+                * 
+                * convert to:
+                *
+                * sessID|sess name|date|a|i|reps*weights       (a: active, i: inactive)
+                * 20|Encoder tests|2012-12-10|3|45|3*7 9*0 34*10 1*58 1*61 (but sorted)
+                *
+                */
+               int sessIDDoing = -1; //of this sessionID
+               int sessIDThisRow = -1; //of this SQL row
+               List<EncoderPersonCurvesInDBDeep> lDeep = new List<EncoderPersonCurvesInDBDeep>();
+               bool firstSession = true;
+               int activeThisRow;
+               int inactiveThisRow;
+               int activeThisSession = 0;
+               int inactiveThisSession = 0;
+
                while(reader.Read()) {
-                       int active = 0;
-                       string activeStr = reader[3].ToString();
+                       //1 get sessionID of this row
+                       sessIDThisRow = Convert.ToInt32(reader[0].ToString());
+
+                       //2 get active an inactive curves of this row
+                       activeThisRow = 0;
+                       string activeStr = reader[4].ToString();
                        if(Util.IsNumber(activeStr, false))
-                               active = Convert.ToInt32(activeStr);
+                               activeThisRow = Convert.ToInt32(activeStr);
                        
-                       int inactive = 0;
-                       string inactiveStr = reader[4].ToString();
+                       inactiveThisRow = 0;
+                       string inactiveStr = reader[5].ToString();
                        if(Util.IsNumber(inactiveStr, false))
-                               inactive = Convert.ToInt32(inactiveStr);
+                               inactiveThisRow = Convert.ToInt32(inactiveStr);
+                       
+                       //3 if session of this row is different than previous row
+                       if(sessIDThisRow != sessIDDoing) 
+                       {
+                               sessIDDoing = sessIDThisRow;
+
+                               if(! firstSession) {
+                                       //if is not first session (means we have processed a session before)
+                                       //update encPS with the lDeep and then add to array
+                                       encPS.lDeep = lDeep;
+                                       encPS.countActive = activeThisSession;
+                                       encPS.countAll = activeThisSession + inactiveThisSession;
+                                       array.Add(encPS);
+                               }
 
+                               firstSession = false;
+
+                               //create new EncoderPersonCurvesInDB
+                               encPS = new EncoderPersonCurvesInDB (
+                                               personID,
+                                               Convert.ToInt32(reader[0].ToString()),  //sessionID
+                                               reader[1].ToString(),                   //sessionName
+                                               reader[2].ToString());                  //sessionDate
+                                       
+                               activeThisSession = 0;
+                               inactiveThisSession = 0;
+                               //empty lDeep
+                               lDeep = new List<EncoderPersonCurvesInDBDeep>();
+
+                       }
+                       //4 add deep info: (weight, all reps)
+                       EncoderPersonCurvesInDBDeep deep = new EncoderPersonCurvesInDBDeep(
+                                       Convert.ToDouble(Util.ChangeDecimalSeparator(reader[3].ToString())), 
activeThisRow + inactiveThisRow);
+                       //add to lDeep
+                       lDeep.Add(deep);
+                       
+                       activeThisSession += activeThisRow;
+                       inactiveThisSession += inactiveThisRow;
 
-                       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)
diff --git a/src/util.cs b/src/util.cs
index 0c6c843..e064326 100644
--- a/src/util.cs
+++ b/src/util.cs
@@ -1376,6 +1376,14 @@ public class Util
 
                return myArrayList;
        }
+       
+       public static ArrayList AddToArrayListIfNotExist(ArrayList myArrayList, double d) {
+               bool found = FoundInArrayList(myArrayList, d);
+               if(!found)
+                       myArrayList.Add(d);
+
+               return myArrayList;
+       }
 
        public static bool FoundInArrayList(ArrayList a, string str) {
                foreach (string str2 in a)
@@ -1387,7 +1395,15 @@ public class Util
 
        public static bool FoundInArrayList(ArrayList a, int i) {
                foreach (int j in a)
-                       if(i == j)
+                       if(j == i)
+                               return true;
+
+               return false;
+       }
+
+       public static bool FoundInArrayList(ArrayList a, double d) {
+               foreach (double d2 in a)
+                       if(d2 == d)
                                return true;
 
                return false;


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