[chronojump] SelectJumpProfile objects working



commit 22284d3261966f03a0f7f0300af50fa7248c699a
Author: Xavier de Blas <xaviblas gmail com>
Date:   Tue Oct 21 12:21:43 2014 -0300

    SelectJumpProfile objects working

 src/genericObjects.cs     |  112 ++++++++++++++++++++++++++++++++++++++++++++-
 src/sqlite/executeAuto.cs |    9 +++-
 src/sqlite/main.cs        |   47 +++++++++++++++++--
 src/sqlite/stat.cs        |   32 +++++++++++++
 4 files changed, 192 insertions(+), 8 deletions(-)
---
diff --git a/src/genericObjects.cs b/src/genericObjects.cs
index 887d489..c8d8b5b 100644
--- a/src/genericObjects.cs
+++ b/src/genericObjects.cs
@@ -1,4 +1,5 @@
 using System;
+using System.Collections; //ArrayList
 using System.Collections.Generic; //List<T>
 
 public class IDName
@@ -11,6 +12,10 @@ public class IDName
                this.name = name;
        }
 
+       public override string ToString() {
+               return uniqueID.ToString() + ":" + name.ToString();
+       }
+
        public int UniqueID {
               get { return uniqueID; }
        }              
@@ -19,12 +24,12 @@ public class IDName
               get { return name; }
        }
 }
-
 public class IDNameList
 {
-       private List<IDName> l;
+       public List<IDName> l; //public in order to do foreach from other methods
 
        public IDNameList() {
+               l = new List<IDName>();
        }
        
        //some string [], divided by ":" have first and second strings: uniqueID and name
@@ -37,6 +42,14 @@ public class IDNameList
                }
        }
 
+       public void Add(IDName idName) {
+               l.Add(idName);
+       }
+       
+       public int Count() {
+               return l.Count;
+       }
+       
        public int FindID(string name) {
                foreach(IDName i in l)
                        if(i.Name == name)
@@ -51,3 +64,98 @@ public class IDNameList
                return "";
        }
 }
+
+
+public class IDDouble
+{
+       private int uniqueID;
+       private double num;
+
+       public IDDouble() {
+       }
+
+       public IDDouble(int uniqueID, double num) {
+               this.uniqueID = uniqueID;
+               this.num = num;
+       }
+       
+       public override string ToString() {
+               return uniqueID.ToString() + ":" + num.ToString();
+       }
+
+
+       public int UniqueID {
+              get { return uniqueID; }
+       }              
+       
+       public double Num {
+              get { return num; }
+       }
+}
+//an SQL select can return a list of pairs id and double
+public class IDDoubleList
+{
+       public List<IDDouble> l; //public in order to do foreach from other methods
+
+       public IDDoubleList() {
+               l = new List<IDDouble>();
+       }
+       
+       public void Add(IDDouble idDouble) {
+               l.Add(idDouble);
+       }
+
+       public override string ToString() {
+               string str = "";
+               foreach(IDDouble i in l)
+                       str += "\n" + i.ToString();
+               
+               return str;
+       }
+       
+       //is useful also as an Exists method
+       public double FindDouble(int uniqueID) {
+               foreach(IDDouble i in l)
+                       if(i.UniqueID == uniqueID)
+                               return i.Num;
+               return -1;
+       }
+}
+
+//this is a list of the lists
+//it's used when some gets some lists
+//and want to match them together, writing '-' when lacks a value
+public class IDNameIDDoubleListOfLists
+{
+       private IDNameList lname;
+       private ArrayList ldoublelistoflists;
+
+       public IDNameIDDoubleListOfLists(IDNameList lname, ArrayList ldoublelistoflists) {
+               this.lname = lname;
+               this.ldoublelistoflists = ldoublelistoflists;
+       }
+
+       public string [] GetStringArray() {
+               string [] str = new string [lname.Count()];
+               int i = 0;
+               foreach(IDName iname in lname.l)
+                       str[i++] = iname.ToString();
+
+               //read every list
+               foreach(IDDoubleList ldoublelist in ldoublelistoflists) {
+                       Log.WriteLine(ldoublelist.ToString());
+
+                       //find if exists a record on this list for the uniqueID on lname
+                       i = 0;
+                       foreach(IDName iname in lname.l) {
+                               double d = ldoublelist.FindDouble(iname.UniqueID);
+                               if(d == -1)
+                                       str[i++] += ":" + "-";
+                               else
+                                       str[i++] += ":" + d.ToString();
+                       }
+               }
+               return str;
+       }
+}
+
diff --git a/src/sqlite/executeAuto.cs b/src/sqlite/executeAuto.cs
index 6efcd32..199ba61 100644
--- a/src/sqlite/executeAuto.cs
+++ b/src/sqlite/executeAuto.cs
@@ -82,8 +82,9 @@ class SqliteExecuteAuto : Sqlite
        protected internal static void addChronojumpProfileAndBilateral()
        {
                string [] jumps = SqliteJumpType.SelectJumpTypes(true, "", "", false);
-               IDNameList jList = new IDNameList(jumps,':');
 
+               IDNameList jList = new IDNameList(jumps,':');
+               
                List <ExecuteAutoSQL> eaSQLlist = new List<ExecuteAutoSQL> {
                        new ExecuteAutoSQL( -1, "Chronojump profile", ExecuteAuto.ModeTypes.BY_PERSONS, 
"Complete profile using jumps",
                                        new List<int> { jList.FindID("SJ"), jList.FindID("SJl"), 
jList.FindID("CMJ"), jList.FindID("ABK"), jList.FindID("DJa") },
@@ -107,7 +108,11 @@ class SqliteExecuteAuto : Sqlite
                                        new List<int> { jList.FindID("slCMJleft"), jList.FindID("CMJ"), 
jList.FindID("slCMJright") }
                                        )
                };
-
+               
+               foreach(IDName idName in jList.l) {
+                       Log.WriteLine(idName.ToString());
+               }
+               
                foreach(ExecuteAutoSQL eaSQL in eaSQLlist) {
                        Insert(true, eaSQL);
                }
diff --git a/src/sqlite/main.cs b/src/sqlite/main.cs
index 87572b5..5af7c8a 100644
--- a/src/sqlite/main.cs
+++ b/src/sqlite/main.cs
@@ -450,6 +450,8 @@ class Sqlite
        }
 
        public static bool ConvertToLastChronojumpDBVersion() {
+               Log.WriteLine("SelectChronojumpProfile ()");
+               SqliteStat.SelectChronojumpProfile ();
 
                //if(checkIfIsSqlite2())
                //      convertSqlite2To3();
@@ -458,10 +460,6 @@ class Sqlite
 
                currentVersion = SqlitePreferences.Select("databaseVersion");
 
-//dbcon.Open();
-//SqliteExecuteAuto.addChronojumpProfileAndBilateral();
-//dbcon.Close();
-
                //Log.WriteLine("lastDB: {0}", Convert.ToDouble(lastChronojumpDatabaseVersion));
                //Log.WriteLine("currentVersion: {0}", Convert.ToDouble(currentVersion));
 
@@ -2553,6 +2551,47 @@ Console.WriteLine("5" + tableName);
                return myReaderStr;
        }
 
+       protected static IDNameList fillIDNameList(string selectStr) 
+       {
+               //select personID and jump type 'SJ' mean
+               dbcmd.CommandText = selectStr;
+               Log.WriteLine(dbcmd.CommandText.ToString());
+               dbcmd.ExecuteNonQuery();
+
+               SqliteDataReader reader = dbcmd.ExecuteReader();
+
+               IDNameList list = new IDNameList();
+               while(reader.Read()) {
+                       IDName idname = new IDName( Convert.ToInt32(reader[0].ToString()),
+                                               reader[1].ToString());
+                       Log.WriteLine(idname.ToString());
+                       
+                       list.Add(new IDName( Convert.ToInt32(reader[0].ToString()),
+                                               reader[1].ToString() ));
+               }
+               reader.Close();
+               return list;
+       }
+
+       protected static IDDoubleList fillIDDoubleList(string selectStr) 
+       {
+               //select personID and jump type 'SJ' mean
+               dbcmd.CommandText = selectStr;
+               Log.WriteLine(dbcmd.CommandText.ToString());
+               dbcmd.ExecuteNonQuery();
+
+               SqliteDataReader reader = dbcmd.ExecuteReader();
+
+               IDDoubleList list = new IDDoubleList();
+               while(reader.Read()) {
+                       list.Add(new IDDouble( Convert.ToInt32(reader[0].ToString()),
+                                               
Convert.ToDouble(Util.ChangeDecimalSeparator(reader[1].ToString())) ));
+               }
+               reader.Close();
+               return list;
+       }
+
+
        /* methods for different classes */
 
        public static int Max (string tableName, string column, bool dbconOpened)
diff --git a/src/sqlite/stat.cs b/src/sqlite/stat.cs
index 00bfa8f..57fc521 100644
--- a/src/sqlite/stat.cs
+++ b/src/sqlite/stat.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.Unix;
 using Mono.Data.Sqlite;
 
@@ -1376,6 +1377,37 @@ Log.WriteLine(intervalSpeeds);
                dbcon.Close();
                return myArray;
        }
+
+       public static void SelectChronojumpProfile ()
+       {
+               dbcon.Open();
+               
+               //select personID and personName (IDNameList)
+               IDNameList idNameList = fillIDNameList( 
+                               "SELECT personSession77.personID, person77.name FROM personSession77, 
person77 " +
+                               "WHERE personSession77.sessionID==7 AND personSession77.personID = 
person77.uniqueID");
        
+               //prepare big arraylist
+               ArrayList array = new ArrayList();
+
+               //select personID and jump type 'SJ' mean
+               IDDoubleList idDoubleListSJ = fillIDDoubleList( 
+                               "SELECT personID, AVG(tv) FROM jump WHERE type=='SJ' AND sessionID==7 GROUP 
BY personID");
+               array.Add(idDoubleListSJ);
        
+
+               //select personID and jump type 'CMJ' mean
+               IDDoubleList idDoubleListCMJ = fillIDDoubleList( 
+                               "SELECT personID, AVG(tv) FROM jump WHERE type=='CMJ' AND sessionID==7 GROUP 
BY personID");
+               array.Add(idDoubleListCMJ);
+       
+               //print all     
+               IDNameIDDoubleListOfLists superlist = new IDNameIDDoubleListOfLists(idNameList, array);
+               Log.WriteLine("superlist");
+               Log.WriteLine( Util.StringArrayToString(superlist.GetStringArray(),"\n") );
+               Log.WriteLine("end of superlist");
+               
+               dbcon.Close();
+       }
+
 }


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