[chronojump] processMultiDatabases added person name, sex



commit 5ad509024ee2fb7cc82d1937d33700e6c941b792
Author: Xavier de Blas <xaviblas gmail com>
Date:   Fri Dec 20 12:38:28 2019 +0100

    processMultiDatabases added person name, sex

 processMultiDatabases/howto_compile.txt        |   2 +-
 processMultiDatabases/person.cs                | 144 +++++++++++++++++++++++++
 processMultiDatabases/processMultiDatabases.cs |  61 +++++++++--
 processMultiDatabases/util.cs                  |  10 +-
 processMultiDatabases/utilDate.cs              |  66 ++++++++++++
 5 files changed, 273 insertions(+), 10 deletions(-)
---
diff --git a/processMultiDatabases/howto_compile.txt b/processMultiDatabases/howto_compile.txt
index da55668d..93fcbbb7 100644
--- a/processMultiDatabases/howto_compile.txt
+++ b/processMultiDatabases/howto_compile.txt
@@ -1 +1 @@
-mcs processMultiDatabases.cs callR.cs constants.cs encoderGraphOptions.cs encoderParams.cs encoderSQL.cs 
encoderStruct.cs util.cs utilEncoder.cs -r:Mono.Data.Sqlite -r:System.Data
+mcs processMultiDatabases.cs callR.cs constants.cs encoderGraphOptions.cs encoderParams.cs encoderSQL.cs 
encoderStruct.cs person.cs util.cs utilDate.cs utilEncoder.cs -r:Mono.Data.Sqlite -r:System.Data
diff --git a/processMultiDatabases/person.cs b/processMultiDatabases/person.cs
new file mode 100644
index 00000000..ae435961
--- /dev/null
+++ b/processMultiDatabases/person.cs
@@ -0,0 +1,144 @@
+/*
+ * This file is part of ChronoJump
+ *
+ * ChronoJump is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or   
+ *    (at your option) any later version.
+ *    
+ * ChronoJump is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
+ *    GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ *  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) 2019   Xavier de Blas <xaviblas gmail com> 
+ */
+
+using System;
+using System.Data;
+using System.Text; //StringBuilder
+using System.Collections; //ArrayList
+
+public class Person {
+
+       private int uniqueID;
+       private string name;
+       private string sex; // "M" (male) , "F" (female) (Constants.M, Constants.F)
+       private DateTime dateBorn;
+       private int race;
+       private int countryID;
+       private string description;
+       private string future1;         //rfid
+       private string future2;         //club ID, is an integer
+       private int serverUniqueID; //not on server
+
+       /*
+       public Person() {
+       }
+       */
+       
+       //used when we create a new person, then uniqueID is -1
+       public Person(int uniqueID) {
+               this.uniqueID = uniqueID;
+       }
+
+       //suitable when we load a person from the database for being the current Person
+       //we know uniqueID
+       //used also in class PersonSessionTransaction where we define the uniqueID 
+       public Person(int uniqueID, string name, string sex, DateTime dateBorn, 
+                       int race, int countryID, string description, string future1, string future2, int 
serverUniqueID)
+       {
+               //needed by the return of gui/personAddModifyWindow
+               name = Util.RemoveTildeAndColon(name);
+               description = Util.RemoveTildeAndColon(description);
+
+               this.uniqueID = uniqueID;
+               this.sex = sex;
+               this.name = name;
+               this.dateBorn = dateBorn;
+               this.race = race;
+               this.countryID = countryID;
+               this.description = description;
+               this.future1 = future1;
+               this.future2 = future2;
+               this.serverUniqueID = serverUniqueID; //remember don't do this on server
+       }
+
+       public override string ToString()
+       {
+               return "[uniqueID: " + uniqueID + "]" + name + ", " + ", " + sex + ", " + 
dateBorn.ToShortDateString() + ", " + description;
+       }
+       
+       
+       //some "set"s are needed. If not data of personSession does not arrive to the server
+       
+       public string Name {
+               get { return name; }
+               set { name = value; }
+       }
+       
+       public string Sex {
+               get { return sex; } 
+               set { sex = value; }
+       }
+
+       /*      
+       public DateTime DateBorn {
+               get { return dateBorn; }
+               set { dateBorn = value; }
+       }
+       
+       public int Race {
+               get { return race; }
+               set { race = value; }
+       }
+
+       public int CountryID {
+               get { return countryID; }
+               set { countryID = value; }
+       }
+
+       public string Description {
+               get { return description; }
+               set { description = value; }
+       }
+
+       //rfid
+       public string Future1 {
+               get { return future1; }
+               set { future1 = value; }
+       }
+
+       //clubID
+       public string Future2 {
+               get { return future2; }
+               set { future2 = value; }
+       }
+
+       public int ServerUniqueID {
+               get { return serverUniqueID; }
+               set { serverUniqueID = value; }
+       }
+
+       public int UniqueID {
+               get { return uniqueID; }
+               set { uniqueID = value; }
+       }
+
+       public string DateLong {
+               get { return dateBorn.ToLongDateString(); }
+       }
+       
+       public string DateShort {
+               get { return dateBorn.ToShortDateString(); }
+       }
+       */
+       
+       
+       ~Person() {}
+          
+}
diff --git a/processMultiDatabases/processMultiDatabases.cs b/processMultiDatabases/processMultiDatabases.cs
index 79d79996..44246fb3 100644
--- a/processMultiDatabases/processMultiDatabases.cs
+++ b/processMultiDatabases/processMultiDatabases.cs
@@ -18,6 +18,19 @@
  * Copyright (C) 2019   Xavier de Blas <xaviblas gmail com> 
  */
 
+//TODO:
+//manage how to integrate with age that is on different database
+//moment: read the moment on the filename on processed files matching with date_time. problem on barcelona1 
baseline: need to put 1 before all dates
+//- barcelona check on which folder we have that date-time
+//- rest of the cities: read the code
+//ecc-con: on sit to stand
+//
+//do not analyze: shopping bag and object in shelf
+//
+//dist min: sit to stand: 30. study the different dist of each rep is we have a min rep of 3 cm
+//
+
+
 using System;
 using System.IO; //"File" things. TextWriter. Path
 using System.Collections.Generic; //List<T>
@@ -27,12 +40,14 @@ class ProcessMultiDatabases
 {
        // start of configuration variables ---->
        //
-       //barcelona
+       //barcelona1
        private string barcelona1Path = 
"/home/xavier/Documents/academic/investigacio/Encoder_SITLESS/carpetes-chronojump-senceres/barcelona/wetransfer-8ba4dd/Encoder_Copies_17_07_2019/database";
+//     private int barcelona1ExJump = ?;
        private int barcelona1ExSitToStand = 7;
        private int barcelona1BicepsCurl = 8;
-       private int barcelona1ShoppingBag = 9;
-       private int barcelona1ObjectInShelf = 10;
+//     private int barcelona1ShoppingBag = 9;
+//     private int barcelona1ObjectInShelf = 10;
+       private int distMinSitToStand = 20;
 
        //current
        private string currentDBPath;
@@ -60,19 +75,19 @@ class ProcessMultiDatabases
        {
                currentDBPath = barcelona1Path;
                currentFilenamePre = "barcelona1";
-               /*
                currentExerciseString = "SITTOSTAND";
                currentExercise = barcelona1ExSitToStand;
                currentPercentWeight = 100;
-               */
                /*
                currentExerciseString = "BICEPSCURL";
                currentExercise = barcelona1BicepsCurl;
                currentPercentWeight = 0;
                */
+               /*
                currentExerciseString = "SHOPPINGBAG";
                currentExercise = barcelona1ShoppingBag;
                currentPercentWeight = 0;
+               */
        }
 
        public ProcessMultiDatabases()
@@ -92,12 +107,13 @@ class ProcessMultiDatabases
                List<EncoderSQL> list = SelectEncoder (currentExercise);
 
                TextWriter writer = File.CreateText("/tmp/" + currentFilenamePre + "-" + 
currentExerciseString + ".csv");
-               writer.WriteLine("city,exercise,person(cjump: 
bad),moment,rep,series,exercise,massBody,massExtra,start,width,height,meanSpeed,maxSpeed,maxSpeedT,meanPower,peakPower,peakPowerT,pp_ppt,meanForce,maxForce,maxForceT,maxForce_maxForceT,workJ,impulse,laterality,inertiaM");
+               
writer.WriteLine("city,exercise,person,sex,moment,rep,series,exercise,massBody,massExtra,start,width,height,meanSpeed,maxSpeed,maxSpeedT,meanPower,peakPower,peakPowerT,RPD,meanForce,maxForce,maxForceT,RFD,workJ,impulse,laterality,inertiaM");
 
                int count = 0;
                foreach(EncoderSQL eSQL in list)
                {
                        Console.WriteLine(string.Format("progress: {0}/{1} - ", count, list.Count) + 
eSQL.ToString());
+                       Person person = SelectPerson (eSQL.personID);
                        double personWeight = SelectPersonWeight(eSQL.personID);
 
                        EncoderParams ep = new EncoderParams(
@@ -148,8 +164,9 @@ class ProcessMultiDatabases
                                if(firstLine)
                                        firstLine = false;
                                else {
-                                       string line2 = "BARCELONA," + currentExerciseString + "," + 
eSQL.personID + ", (moment)," + line;
+                                       string line2 = "BARCELONA," + currentExerciseString + "," + 
person.Name + "," + person.Sex + ",(moment)," + line;
                                        //TODO: note this personID is not correct because persons sometimes 
where evaluated on different chronojump machines
+                                       //for this reason has been changed to personName, we suppose is the 
same on different machines
                                        writer.WriteLine(line2);
                                        writer.Flush();
                                }
@@ -157,7 +174,7 @@ class ProcessMultiDatabases
 
                        count ++;
                        /*
-                       if(count >= 5)
+                       if(count >= 15)
                                break;
                                */
 
@@ -194,6 +211,34 @@ class ProcessMultiDatabases
                dbcon.Close();
        }
 
+       public Person SelectPerson (int uniqueID)
+       {
+               dbcmd.CommandText = "SELECT * FROM person77 WHERE uniqueID = " + uniqueID;
+               Console.WriteLine(dbcmd.CommandText.ToString());
+
+               SqliteDataReader reader;
+               reader = dbcmd.ExecuteReader();
+
+               Person p = new Person(-1);
+               if(reader.Read()) {
+                       p = new Person(
+                                       Convert.ToInt32(reader[0].ToString()), //uniqueID
+                                       reader[1].ToString(),                   //name
+                                       reader[2].ToString(),                   //sex
+                                       UtilDate.FromSql(reader[3].ToString()),//dateBorn
+                                       Convert.ToInt32(reader[4].ToString()), //race
+                                       Convert.ToInt32(reader[5].ToString()), //countryID
+                                       reader[6].ToString(),                   //description
+                                       reader[7].ToString(),                   //future1: rfid
+                                       reader[8].ToString(),                   //future2: clubID
+                                       Convert.ToInt32(reader[9].ToString()) //serverUniqueID
+                                     );
+               }
+               reader.Close();
+
+               return p;
+       }
+
        private double SelectPersonWeight (int personID)
        {
                dbcmd.CommandText = "SELECT weight FROM personSession77 WHERE personID = " + personID;
diff --git a/processMultiDatabases/util.cs b/processMultiDatabases/util.cs
index e7f806bb..f5dad98a 100644
--- a/processMultiDatabases/util.cs
+++ b/processMultiDatabases/util.cs
@@ -57,6 +57,15 @@ public class Util
                return myStringBuilder.ToString();
        }
 
+       public static string RemoveTildeAndColon(string myString)
+       {
+               StringBuilder myStringBuilder = new StringBuilder(myString);
+               myStringBuilder.Replace("'", " ");
+               myStringBuilder.Replace(":", " ");
+               return myStringBuilder.ToString();
+       }
+
+
        /*
        public static string MakeURLabsolute(string url) {
                string parentDir = Util.GetParentDir(true); //add final '/' or '\'
@@ -125,6 +134,5 @@ public class Util
                        return null;
                }
        }
-
 }
 
diff --git a/processMultiDatabases/utilDate.cs b/processMultiDatabases/utilDate.cs
new file mode 100644
index 00000000..17c1641c
--- /dev/null
+++ b/processMultiDatabases/utilDate.cs
@@ -0,0 +1,66 @@
+/*
+ * This file is part of ChronoJump
+ *
+ * ChronoJump is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or   
+ *    (at your option) any later version.
+ *              
+ * ChronoJump is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
+ *    GNU General Public License for more details.
+ *                      
+ * You should have received a copy of the GNU General Public License
+ *  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) 2019   Xavier de Blas <xaviblas gmail com> 
+ */
+
+using System;
+
+public class UtilDate
+{
+       //comes from sql like YYYY-MM-DD (with always all digits)
+        //return datetime
+        public static DateTime FromSql (string date)
+        {
+                Console.WriteLine("UtilDate.FromSql date: " + date);
+                /*
+                   on report we do a session select with uniqueID = -1
+                   it returns nothing, date has nothing
+                   */
+                if(date == null || date == "")
+                        return DateTime.Now; //TODO: ensure this now is year-month-day
+
+                /*
+                   maybe date format is before 0.72 (d/m/Y)
+                   this is still here and not in a standalone conversion
+                   because if someone converts from older database
+                   can have problems wih constructors with different date formats
+                   */
+
+                DateTime dt; //Datetime (year, month, day) constructor
+                if(date.IndexOf('/') == -1) {
+                        //not contains '/'
+                        //new sqlite3 compatible date format sice db 0.72 YYYY-MM-DD
+                        string [] dateFull = date.Split(new char[] {'-'});
+                        dt = new DateTime(
+                                        Convert.ToInt32(dateFull[0]),
+                                        Convert.ToInt32(dateFull[1]),
+                                        Convert.ToInt32(dateFull[2]));
+                } else {
+                        //contains '/'
+                        //old D/M/Y format 
+                        string [] dateFull = date.Split(new char[] {'/'});
+                        dt = new DateTime(
+                                        Convert.ToInt32(dateFull[2]),
+                                        Convert.ToInt32(dateFull[1]),
+                                        Convert.ToInt32(dateFull[0]));
+                }
+                return dt;
+        }
+
+}
+


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