[chronojump] Reorganized SQL jumpsProfile code



commit 0e15cd35eb5eefdab57f14a8ee8f4cd461cd0fd3
Author: Xavier de Blas <xaviblas gmail com>
Date:   Fri Jul 1 09:07:48 2016 +0200

    Reorganized SQL jumpsProfile code

 src/jumpsProfile.cs |    2 +-
 src/sqlite/jump.cs  |   49 ++++++++++++++++
 src/sqlite/main.cs  |   19 ++++++
 src/sqlite/stat.cs  |  157 ---------------------------------------------------
 4 files changed, 69 insertions(+), 158 deletions(-)
---
diff --git a/src/jumpsProfile.cs b/src/jumpsProfile.cs
index fdf5fcc..38dc2bc 100644
--- a/src/jumpsProfile.cs
+++ b/src/jumpsProfile.cs
@@ -127,7 +127,7 @@ public class JumpsProfile
 
        public void Calculate (int personID, int sessionID)
        {
-               List<Double> l = SqliteStat.SelectChronojumpProfile(personID, sessionID);
+               List<Double> l = SqliteJump.SelectChronojumpProfile(personID, sessionID);
 
                double sj  = l[0];
                double sjl = l[1];
diff --git a/src/sqlite/jump.cs b/src/sqlite/jump.cs
index f19da60..dfc1be7 100644
--- a/src/sqlite/jump.cs
+++ b/src/sqlite/jump.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;
 
 
@@ -253,6 +254,54 @@ class SqliteJump : Sqlite
                return str;
        }
        
+       public static List<Double> SelectChronojumpProfile (int pID, int sID)
+       {
+               string personID = pID.ToString();
+               string sessionID = sID.ToString();
+
+               Sqlite.Open();
+               
+               double sj = selectDouble( 
+                               "SELECT MAX(tv * tv * 1.226) " +
+                               " FROM jump " +
+                               " WHERE type = \"SJ\" " +
+                               " AND personID = " + personID + " AND sessionID = " + sessionID);
+               
+               double sjl = selectDouble( 
+                               "SELECT MAX(tv * tv * 1.226) " +
+                               " FROM jump " +
+                               " WHERE type = \"SJl\" AND jump.weight = 100 " +
+                               " AND personID = " + personID + " AND sessionID = " + sessionID);
+               
+               double cmj = selectDouble( 
+                               "SELECT MAX(tv * tv * 1.226) " +
+                               " FROM jump " +
+                               " WHERE type = \"CMJ\" " +
+                               " AND personID = " + personID + " AND sessionID = " + sessionID);
+               
+               double abk = selectDouble( 
+                               "SELECT MAX(tv * tv * 1.226) " +
+                               " FROM jump " +
+                               " WHERE type = \"ABK\" " +
+                               " AND personID = " + personID + " AND sessionID = " + sessionID);
+               
+               double dja = selectDouble( 
+                               "SELECT MAX(tv * tv * 1.226) " +
+                               " FROM jump " +
+                               " WHERE type = \"DJa\" " +
+                               " AND personID = " + personID + " AND sessionID = " + sessionID);
+
+               Sqlite.Close();
+
+               List<Double> l = new List<Double>();
+               l.Add(sj);
+               l.Add(sjl);
+               l.Add(cmj);
+               l.Add(abk);
+               l.Add(dja);
+               return l;
+       }
+
 
        public static void Update(int jumpID, string type, string tv, string tc, string fall, int personID, 
double weight, string description, double angle)
        {
diff --git a/src/sqlite/main.cs b/src/sqlite/main.cs
index 222c7a6..8bf9194 100644
--- a/src/sqlite/main.cs
+++ b/src/sqlite/main.cs
@@ -2815,6 +2815,25 @@ LogB.SQL("5" + tableName);
 
 
        /* methods for different classes */
+       
+       protected static double selectDouble (string sqlSelect) 
+       {
+               dbcmd.CommandText = sqlSelect;
+               LogB.SQL(dbcmd.CommandText.ToString());
+               dbcmd.ExecuteNonQuery();
+
+               SqliteDataReader reader;
+               reader = dbcmd.ExecuteReader();
+               
+               double result = 0;
+               if(reader.Read())
+                       result = Convert.ToDouble(Util.ChangeDecimalSeparator(reader[0].ToString()));
+
+               reader.Close();
+               
+               return result;
+       }
+
 
        public static int Max (string tableName, string column, bool dbconOpened)
        {
diff --git a/src/sqlite/stat.cs b/src/sqlite/stat.cs
index 5d66211..5f201bb 100644
--- a/src/sqlite/stat.cs
+++ b/src/sqlite/stat.cs
@@ -22,7 +22,6 @@ 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;
 
@@ -1378,162 +1377,6 @@ LogB.SQL(intervalSpeeds);
                return myArray;
        }
        
-       /*
-        * TODO: Al this have to be in % then need all the data to do it
-       maximum values of each jump!!!!
-       all with heights
-       SJ100           F Max
-       SJ-SJ100        F Expl
-       CMJ-SJ          Cap. Elastica (hability)
-       ABK-CMJ         Cap. Braços (hability)
-       DJa             F Reactiu-reflexa
-       */
-
-       private static double selectDouble (string sqlSelect) 
-       {
-               dbcmd.CommandText = sqlSelect;
-               LogB.SQL(dbcmd.CommandText.ToString());
-               dbcmd.ExecuteNonQuery();
-
-               SqliteDataReader reader;
-               reader = dbcmd.ExecuteReader();
-               
-               double result = 0;
-               if(reader.Read())
-                       result = Convert.ToDouble(Util.ChangeDecimalSeparator(reader[0].ToString()));
-
-               reader.Close();
-               
-               return result;
-       }
-
-       //Current person
-       public static List<Double> SelectChronojumpProfile (int pID, int sID)
-       {
-               string personID = pID.ToString();
-               string sessionID = sID.ToString();
-
-               Sqlite.Open();
-               
-               double sj = selectDouble( 
-                               "SELECT MAX(tv * tv * 1.226) " +
-                               " FROM jump " +
-                               " WHERE type = \"SJ\" " +
-                               " AND personID = " + personID + " AND sessionID = " + sessionID);
-               
-               double sjl = selectDouble( 
-                               "SELECT MAX(tv * tv * 1.226) " +
-                               " FROM jump " +
-                               " WHERE type = \"SJl\" AND jump.weight = 100 " +
-                               " AND personID = " + personID + " AND sessionID = " + sessionID);
-               
-               double cmj = selectDouble( 
-                               "SELECT MAX(tv * tv * 1.226) " +
-                               " FROM jump " +
-                               " WHERE type = \"CMJ\" " +
-                               " AND personID = " + personID + " AND sessionID = " + sessionID);
-               
-               double abk = selectDouble( 
-                               "SELECT MAX(tv * tv * 1.226) " +
-                               " FROM jump " +
-                               " WHERE type = \"ABK\" " +
-                               " AND personID = " + personID + " AND sessionID = " + sessionID);
-               
-               double dja = selectDouble( 
-                               "SELECT MAX(tv * tv * 1.226) " +
-                               " FROM jump " +
-                               " WHERE type = \"DJa\" " +
-                               " AND personID = " + personID + " AND sessionID = " + sessionID);
-
-               Sqlite.Close();
-
-               List<Double> l = new List<Double>();
-               l.Add(sj);
-               l.Add(sjl);
-               l.Add(cmj);
-               l.Add(abk);
-               l.Add(dja);
-               return l;
-       }
-
-       //Current person
-       public static List<Double> SelectChronojumpProfileOld (int pID, int sID)
-       {
-               string personID = pID.ToString();
-               string sessionID = sID.ToString();
-
-               Sqlite.Open();
-               
-               //this is used in all indexes
-               double DjaMax = selectDouble( 
-                               "SELECT MAX(tv * tv * 1.226) " +
-                               " FROM jump " +
-                               " WHERE type = \"DJa\" " +
-                               " AND personID = " + personID + " AND sessionID = " + sessionID);
-
-               List<Double> l = new List<Double>();
-               //if not Dja, return a 00000 list
-               if(DjaMax == 0) {
-                       for(int i=0; i <= 4; i++)
-                               l.Add(0);
-                       return l;
-               }
-               
-               //select personID and each index (using IDDoubleLists)
-               double fMax = selectDouble( 
-                               "SELECT MAX(tv * tv * 1.226) " +
-                               " FROM jump " +
-                               " WHERE type = \"SJl\" AND jump.weight = 100 " +
-                               " AND personID = " + personID + " AND sessionID = " + sessionID);
-               
-               double fExpl = selectDouble( 
-                               "SELECT MAX(j1.tv * j1.tv * 1.226) - MAX(j2.tv * j2.tv * 1.226) AS myIndex " +
-                               " FROM jump AS j1, jump AS j2 " +
-                               " WHERE j1.type = \"SJ\" AND j2.type = \"SJl\" AND j2.weight=100 " +
-                               " AND j1.personID = " + personID + " AND j2.personID = " + personID + 
-                               " AND j1.sessionID = " + sessionID + " AND j2.sessionID = " + sessionID);
-
-               double cElast = selectDouble( 
-                               "SELECT MAX(j1.tv * j1.tv * 1.226) - MAX(j2.tv * j2.tv * 1.226) AS myIndex " +
-                               " FROM jump AS j1, jump AS j2 " +
-                               " WHERE j1.type = \"CMJ\" AND j2.type = \"SJ\" " +
-                               " AND j1.personID = " + personID + " AND j2.personID = " + personID + 
-                               " AND j1.sessionID = " + sessionID + " AND j2.sessionID = " + sessionID);
-       
-               double cArms = selectDouble( 
-                               "SELECT MAX(j1.tv * j1.tv * 1.226) - MAX(j2.tv * j2.tv * 1.226) AS myIndex " +
-                               " FROM jump AS j1, jump AS j2 " +
-                               " WHERE j1.type = \"ABK\" AND j2.type = \"CMJ\" " +
-                               " AND j1.personID = " + personID + " AND j2.personID = " + personID + 
-                               " AND j1.sessionID = " + sessionID + " AND j2.sessionID = " + sessionID);
-
-               double fReact = selectDouble( 
-                               "SELECT MAX(j1.tv * j1.tv * 1.226) - MAX(j2.tv * j2.tv * 1.226) AS myIndex " +
-                               " FROM jump AS j1, jump AS j2 " +
-                               " WHERE j1.type = \"DJa\" AND j2.type = \"ABK\" " +
-                               " AND j1.personID = " + personID + " AND j2.personID = " + personID + 
-                               " AND j1.sessionID = " + sessionID + " AND j2.sessionID = " + sessionID);
-               
-               if(fMax > 0)
-                       fMax /= DjaMax;
-               if(fExpl > 0)
-                       fExpl /= DjaMax;
-               if(cElast > 0)
-                       cElast /= DjaMax;
-               if(cArms > 0)
-                       cArms /= DjaMax;
-               if(fReact > 0)
-                       fReact /= DjaMax;
-       
-               Sqlite.Close();
-
-               l.Add(fMax);
-               l.Add(fExpl);
-               l.Add(cElast);
-               l.Add(cArms);
-               l.Add(fReact);
-               return l;
-       }
 
        //all persons in session (unused)
        /*


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