[chronojump] processMultiDatabases has computerDB records



commit c907d5171aba90cf48018cdc1f931b4f86f92bd6
Author: Xavier de Blas <xaviblas gmail com>
Date:   Fri Dec 20 15:50:06 2019 +0100

    processMultiDatabases has computerDB records

 processMultiDatabases/callR.cs                 |  14 +--
 processMultiDatabases/computerDB.cs            |  61 +++++++++++++
 processMultiDatabases/howto_compile.txt        |   2 +-
 processMultiDatabases/person.cs                |  20 ++---
 processMultiDatabases/processMultiDatabases.cs | 115 ++++++++++---------------
 processMultiDatabases/sqlite.cs                |   1 +
 6 files changed, 121 insertions(+), 92 deletions(-)
---
diff --git a/processMultiDatabases/callR.cs b/processMultiDatabases/callR.cs
index 06571327..86119322 100644
--- a/processMultiDatabases/callR.cs
+++ b/processMultiDatabases/callR.cs
@@ -54,12 +54,14 @@ public class CallR
                
                //on Windows we need the \"str\" to call without problems in path with spaces
                pinfo.Arguments = "\"" + getEncoderScriptCallGraph() + "\" " + optionsFile;
-       
+
+               /*      
                Console.WriteLine("Arguments:", pinfo.Arguments);
                Console.WriteLine("--- 1 --- " + optionsFile.ToString() + " ---");
                //Console.WriteLine("--- 2 --- " + scriptOptions + " ---");
                Console.WriteLine("--- 3 --- " + pinfo.Arguments.ToString() + " ---");
-               
+               */
+
                string outputFileCheck = "";
                string outputFileCheck2 = "";
                
@@ -113,7 +115,6 @@ public class CallR
                        Util.DeleteFile(specialData);
 
 
-               Console.WriteLine("process a");
 //             try {   
                        Process p = new Process();
                        p.StartInfo = pinfo;
@@ -133,9 +134,6 @@ public class CallR
                        //p.BeginOutputReadLine();
                        p.BeginErrorReadLine();
 
-                       Console.WriteLine("process b");
-
-
                        if(outputFileCheck2 == "")
                                while ( ! ( Util.FileReadable(outputFileCheck) )); //|| CancelRScript) );
                        else
@@ -147,12 +145,8 @@ public class CallR
                                copyExportedFile();
                                */
 
-                       Console.WriteLine("process c");
                        p.StandardInput.WriteLine("Q");
-                       //p.WaitForExit();
 
-                       Console.WriteLine("process d");
-       
 //             } catch {
 //                     Console.WriteLine("catched at startProcess");
 //                     return false;
diff --git a/processMultiDatabases/computerDB.cs b/processMultiDatabases/computerDB.cs
new file mode 100644
index 00000000..a001dc07
--- /dev/null
+++ b/processMultiDatabases/computerDB.cs
@@ -0,0 +1,61 @@
+/*
+ * 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.Collections.Generic; //List<T>
+
+class ComputerDB
+{
+       public string name;
+       public string path;
+       //exercises, if one is not done on that computer: -1
+       public int exBicepsCurlID;      //0% bodyweight
+       public int exJumpID;            //100% bodyweight
+       public int exSitToStandID;      //100% bodyweight
+       //do not analyze: shopping bag and object in shelf
+
+       public enum ExerciseString { BICEPSCURL, JUMP, SITTOSTAND };
+       public ComputerDB(string name, string path, int exBicepsCurlID, int exJumpID, int exSitToStandID)
+       {
+               this.name = name;
+               this.path = path;
+               this.exBicepsCurlID = exBicepsCurlID;
+               this.exJumpID = exJumpID;
+               this.exSitToStandID = exSitToStandID;
+       }
+}
+
+class ComputerDBManage
+{
+       public List<ComputerDB> list;
+       public ComputerDBManage()
+       {
+               list = new List<ComputerDB>();
+               list.Add(new ComputerDB(
+                               "barcelona1", 
+                               
"/home/xavier/Documents/academic/investigacio/Encoder_SITLESS/carpetes-chronojump-senceres/barcelona/wetransfer-8ba4dd/Encoder_Copies_17_07_2019/database",
+                               8, -1, 7));
+               list.Add(new ComputerDB(
+                               "barcelona2", 
+                               
"/home/xavier/Documents/academic/investigacio/Encoder_SITLESS/carpetes-chronojump-senceres/barcelona/wetransfer-8ba4dd/Encoder_Copies_17_07_2019/Darrera_còpia_pc_prèstec/chronojump/database",
+                               8, 4, 7));
+       }
+}
+
diff --git a/processMultiDatabases/howto_compile.txt b/processMultiDatabases/howto_compile.txt
index 83669479..0edf622e 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 person.cs sqlite.cs util.cs utilDate.cs utilEncoder.cs -r:Mono.Data.Sqlite -r:System.Data
+mcs processMultiDatabases.cs callR.cs computerDB.cs constants.cs encoderGraphOptions.cs encoderParams.cs 
encoderSQL.cs encoderStruct.cs person.cs sqlite.cs util.cs utilDate.cs utilEncoder.cs -r:Mono.Data.Sqlite 
-r:System.Data
diff --git a/processMultiDatabases/person.cs b/processMultiDatabases/person.cs
index ae435961..7ae85529 100644
--- a/processMultiDatabases/person.cs
+++ b/processMultiDatabases/person.cs
@@ -29,12 +29,12 @@ public class Person {
        private string name;
        private string sex; // "M" (male) , "F" (female) (Constants.M, Constants.F)
        private DateTime dateBorn;
-       private int race;
-       private int countryID;
+       //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
+       //private string future1;       //rfid
+       //private string future2;       //club ID, is an integer
+       //private int serverUniqueID; //not on server
 
        /*
        public Person() {
@@ -60,12 +60,12 @@ public class Person {
                this.sex = sex;
                this.name = name;
                this.dateBorn = dateBorn;
-               this.race = race;
-               this.countryID = countryID;
+               //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
+               //this.future1 = future1;
+               //this.future2 = future2;
+               //this.serverUniqueID = serverUniqueID; //remember don't do this on server
        }
 
        public override string ToString()
diff --git a/processMultiDatabases/processMultiDatabases.cs b/processMultiDatabases/processMultiDatabases.cs
index 8d271a3e..5a5c2b33 100644
--- a/processMultiDatabases/processMultiDatabases.cs
+++ b/processMultiDatabases/processMultiDatabases.cs
@@ -24,12 +24,7 @@
 //- 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
@@ -37,24 +32,10 @@ using System.Collections.Generic; //List<T>
 
 class ProcessMultiDatabases
 {
-       // start of configuration variables ---->
-       //
-       //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 distMinSitToStand = 20;
-
-       //current
-       private string currentDBPath;
-       private string currentFilenamePre;
-       private string currentExerciseString;
-       private int currentExercise;
-       private int currentPercentWeight;
+       private bool debug = false; //on debug just 5 sets of each compDB-exercise are used
+       private int distMin = 20; //distMinSitToStand = 20;
        private Sqlite sqlite;
+       TextWriter writer;
 
        //hardcoded stuff (search 'hardcoded' on):
        //callR.cs
@@ -68,56 +49,58 @@ class ProcessMultiDatabases
                new ProcessMultiDatabases();
        }
 
-       private void configure()
-       {
-               currentDBPath = barcelona1Path;
-               currentFilenamePre = "barcelona1";
-               currentExerciseString = "SITTOSTAND";
-               currentExercise = barcelona1ExSitToStand;
-               currentPercentWeight = 100;
-               /*
-               currentExerciseString = "BICEPSCURL";
-               currentExercise = barcelona1BicepsCurl;
-               currentPercentWeight = 0;
-               */
-               /*
-               currentExerciseString = "SHOPPINGBAG";
-               currentExercise = barcelona1ShoppingBag;
-               currentPercentWeight = 0;
-               */
-       }
-
        public ProcessMultiDatabases()
        {
-               configure();
-
                sqlite = new Sqlite();
-               sqlite.CreateConnection(currentDBPath);
-               sqlite.Open();
+               ComputerDBManage compDBManage = new ComputerDBManage();
+
+               writer = File.CreateText("/tmp/chronojump-processMultiEncoder.csv");
+               
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");
 
-               processDatabase();
+               foreach(ComputerDB compDB in compDBManage.list)
+               {
+                       sqlite.CreateConnection(compDB.path);
+                       sqlite.Open();
+
+                       if(compDB.exBicepsCurlID != -1)
+                               processCompDBEx(compDB, ComputerDB.ExerciseString.BICEPSCURL, 
compDB.exBicepsCurlID, 0);
+
+                       if(compDB.exJumpID != -1)
+                               processCompDBEx(compDB, ComputerDB.ExerciseString.JUMP, compDB.exJumpID, 100);
+
+                       if(compDB.exSitToStandID != -1)
+                               processCompDBEx(compDB, ComputerDB.ExerciseString.SITTOSTAND, 
compDB.exSitToStandID, 100);
+
+                       sqlite.Close();
+               }
+               writer.Close();
+               ((IDisposable)writer).Dispose();
 
-               sqlite.Close();
                Console.WriteLine("processMultiDatabases done!");
        }
 
-       private void processDatabase()
+       private void processCompDBEx (ComputerDB compDB, ComputerDB.ExerciseString exerciseString, int 
exerciseID, int percentBodyWeight)
        {
-               List<EncoderSQL> list = sqlite.SelectEncoder (currentExercise);
-
-               TextWriter writer = File.CreateText("/tmp/" + currentFilenamePre + "-" + 
currentExerciseString + ".csv");
-               
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");
+               List<EncoderSQL> list = sqlite.SelectEncoder (exerciseID);
 
                int count = 0;
                foreach(EncoderSQL eSQL in list)
                {
                        Console.WriteLine(string.Format("progress: {0}/{1} - ", count, list.Count) + 
eSQL.ToString());
+
+                       Console.WriteLine("copying file: " + compDB.path + "/../" + eSQL.url + "/" + 
eSQL.filename);
+                       if(! UtilEncoder.CopyEncoderDataToTemp(compDB.path + "/../" + eSQL.url, 
eSQL.filename))
+                       {
+                               Console.WriteLine("Could not copy file, discarding");
+                               continue;
+                       }
+
                        Person person = sqlite.SelectPerson (eSQL.personID);
                        double personWeight = sqlite.SelectPersonWeight(eSQL.personID);
 
                        EncoderParams ep = new EncoderParams(
-                                       20, 
//preferences.EncoderCaptureMinHeight(encoderConfigurationCurrent.has_inertia), 
-                                       currentPercentWeight, //TODO: change this value depending on exercise 
//getExercisePercentBodyWeightFromComboCapture (),
+                                       distMin, 
//preferences.EncoderCaptureMinHeight(encoderConfigurationCurrent.has_inertia),
+                                       percentBodyWeight, //getExercisePercentBodyWeightFromComboCapture (),
                                        Util.ConvertToPoint(personWeight), // 
Util.ConvertToPoint(findMass(Constants.MassType.BODY)),
                                        Util.ConvertToPoint(eSQL.extraWeight), 
//Util.ConvertToPoint(findMass(Constants.MassType.EXTRA)),
                                        "c", //findEccon(true),                                        
//force ecS (ecc-conc separated)
@@ -141,10 +124,7 @@ class ProcessMultiDatabases
                                        UtilEncoder.GetEncoderTempPathWithoutLastSep(),
                                        ep);
 
-                       Console.WriteLine("copying file: " + currentDBPath + "/../" + eSQL.url + "/" + 
eSQL.filename);
-                       UtilEncoder.CopyEncoderDataToTemp(currentDBPath + "/../" + eSQL.url, eSQL.filename);
-                       Console.WriteLine("copying file done. Calling R... ");
-
+                       Console.WriteLine("Calling R... ");
                        new CallR(es);
                        Console.WriteLine("CallR done!");
 
@@ -153,7 +133,6 @@ class ProcessMultiDatabases
                        
//,series,exercise,massBody,massExtra,start,width,height,meanSpeed,maxSpeed,maxSpeedT,meanPower,peakPower,peakPowerT,pp_ppt,meanForce,maxForce,maxForceT,maxForce_maxForceT,workJ,impulse,laterality,inertiaM
                        
//1,1,exerciseName,57.9,0,971,498,755,1.51152519574657,3.20590883396153,307,1694.08480044046,4423.25671303514,243,18202.7025227784,1108.13701938937,1754.09683966977,232,7560.7622399559,1980.64161525193,365.685216398493,,-1e-04
 
-                       //
                        //now we have to parse it to fill the big file
                        string filename = "/tmp/chronojump-last-encoder-curves.txt";
                        List<string> lines = Util.ReadFileAsStringList(filename);
@@ -163,29 +142,23 @@ class ProcessMultiDatabases
                                if(firstLine)
                                        firstLine = false;
                                else {
-                                       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
+                                       string line2 = string.Format("{0},{1},{2},{3},{4}", compDB.name, 
exerciseString, person.Name, person.Sex,  "(moment)") + line;
+                                       //note 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();
                                }
                        }
 
                        count ++;
-                       /*
-                       if(count >= 15)
+
+                       if(debug && count >= 5)
                                break;
-                               */
 
-                       System.Threading.Thread.Sleep(200); //rest a bit
+                       System.Threading.Thread.Sleep(100); //rest a bit
                }
 
-               writer.Close();
-               ((IDisposable)writer).Dispose();
                Console.WriteLine("processDatabase done!");
        }
-
-
 }
-
-
diff --git a/processMultiDatabases/sqlite.cs b/processMultiDatabases/sqlite.cs
index 8a2dff50..bd8e1d4e 100644
--- a/processMultiDatabases/sqlite.cs
+++ b/processMultiDatabases/sqlite.cs
@@ -99,6 +99,7 @@ public class Sqlite
        public List<EncoderSQL> SelectEncoder (int exerciseID)
         {
                dbcmd.CommandText = "SELECT * FROM encoder WHERE signalOrCurve = 'signal' AND exerciseID = " 
+ exerciseID;
+               Console.WriteLine(dbcmd.CommandText.ToString());
                SqliteDataReader reader;
                reader = dbcmd.ExecuteReader();
 


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