[chronojump] processMultiDatabases: Updated code



commit f6ffdfd24a95e14c47e111a1de2dafc470786e34
Author: Xavier de Blas <xaviblas gmail com>
Date:   Wed Jan 15 11:37:02 2020 +0100

    processMultiDatabases: Updated code

 processMultiDatabases/computerDB.cs            | 166 +++++++++++++++++++++++--
 processMultiDatabases/processMultiDatabases.cs |  79 +++++++++++-
 processMultiDatabases/utilDate.cs              |  46 -------
 3 files changed, 231 insertions(+), 60 deletions(-)
---
diff --git a/processMultiDatabases/computerDB.cs b/processMultiDatabases/computerDB.cs
index 71aca1b9..0965069b 100644
--- a/processMultiDatabases/computerDB.cs
+++ b/processMultiDatabases/computerDB.cs
@@ -19,10 +19,34 @@
  */
 
 using System;
+using System.IO;
 using System.Collections.Generic; //List<T>
+using System.Text.RegularExpressions; //Regex
+
+/*
+ * Denmark has:
+ * ID number_initials of the participant_time period (pre, post, fu12, fu18).
+ * but fu can be also in caps
+ * and sometimes is found IDnumberinitialstimeperiod, and other times initialsIDnumbertimeperiod
+ * sometimes separated by underscores and other times not
+ *
+ * 545-1318_fllu_FU18-2019-08-01_13-43-58.txt
+ * 479-1318fllufu12-2019-03-19_10-10-30.txt
+ * 265-knni1310pre-2017-10-20_12-51-48.txt
+ *
+ * so- remove until the first -
+ * remove datetime.txt
+ * find pre, post (caps or not), see if find a fu12 or fu18 (caps or not), and remove it
+ * find number: should be code
+ * the rest removing - or _ shoul be the name
+ *
+ * on the other computer must of the names have no moment (pre, post, ...)
+ */
+
 
 class ComputerDB
 {
+       public string city;
        public string name;
        public string path;
        public string pathToFindMoments; //at barcelona we can find datetimes on 4 folders to know which 
moment
@@ -31,19 +55,74 @@ class ComputerDB
        public int exJumpID;            //100% bodyweight
        public int exSitToStandID;      //100% bodyweight
        //do not analyze: shopping bag and object in shelf
+       public string momentPreName;
+       public string momentPostName;
+       public string moment12Name;
+       public string moment18Name;
 
        public enum ExerciseString { BICEPSCURL, JUMP, SITTOSTAND };
-       public ComputerDB(string name,
+       public ComputerDB(
+                       string city,
+                       string name,
                        string path,
                        string pathToFindMoments,
-                       int exBicepsCurlID, int exJumpID, int exSitToStandID)
+                       int exBicepsCurlID, int exJumpID, int exSitToStandID,
+                       string momentPreName, string momentPostName,
+                       string moment12Name, string moment18Name
+                       )
        {
+               this.city = city;
                this.name = name;
                this.path = path;
                this.pathToFindMoments = pathToFindMoments;
                this.exBicepsCurlID = exBicepsCurlID;
                this.exJumpID = exJumpID;
                this.exSitToStandID = exSitToStandID;
+               this.momentPreName = momentPreName;
+               this.momentPostName = momentPostName;
+               this.moment12Name = moment12Name;
+               this.moment18Name = moment18Name;
+       }
+
+       public enum Moment { NONE, PRE, POST, M12, M18, MULTIPLE }
+       public string FindMoment (string filename)
+       {
+               filename = filename.ToUpper();
+               Moment m = Moment.NONE;
+
+               Console.WriteLine("FindNotBarcelona filename: " + filename);
+               if(filename.Contains(momentPreName))
+               {
+                       if(m != Moment.NONE)
+                               m = Moment.MULTIPLE;
+                       else
+                               m = Moment.PRE;
+               } else if(filename.Contains(momentPostName))
+               {
+                       if(m != Moment.NONE)
+                               m = Moment.MULTIPLE;
+                       else
+                               m = Moment.POST;
+               } else if(filename.Contains(moment12Name))
+               {
+                       if(m != Moment.NONE)
+                               m = Moment.MULTIPLE;
+                       else
+                               m = Moment.M12;
+               } else if(filename.Contains(moment18Name))
+               {
+                       if(m != Moment.NONE)
+                               m = Moment.MULTIPLE;
+                       else
+                               m = Moment.M18;
+               }
+
+               //some cities did not use the PRE and they simply left blank, so default to PRE
+               if(m == Moment.NONE)
+                       m = Moment.PRE;
+
+
+               return m.ToString();
        }
 }
 
@@ -59,46 +138,113 @@ class ComputerDBManage
        public ComputerDBManage()
        {
                list = new List<ComputerDB>();
+               /*
                list.Add(new ComputerDB(
+                               "barcelona",
                                "barcelona1", 
                                
"/home/xavier/Documents/academic/investigacio/Encoder_SITLESS/carpetes-chronojump-senceres/barcelona/wetransfer-8ba4dd/Encoder_Copies_17_07_2019/database",
                                
"/home/xavier/Documents/academic/investigacio/Encoder_SITLESS/arxius-processats-per-ells/barcelona",
-                               8, -1, 7));
+                               8, -1, 7,
+                               "", "", "", ""));
                list.Add(new ComputerDB(
+                               "barcelona",
                                "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",
                                
"/home/xavier/Documents/academic/investigacio/Encoder_SITLESS/arxius-processats-per-ells/barcelona",
-                               8, 4, 7));
+                               8, 4, 7,
+                               "", "", "", ""));
                list.Add(new ComputerDB(
+                               "belfast",
                                "belfast",
                                
"/home/xavier/Documents/academic/investigacio/Encoder_SITLESS/carpetes-chronojump-senceres/Belfast_chronojump/chronojump/database",
                                "",
-                               12, 14, 15)); //note: belfast has biceps curl 12 (2kg), and 13 (4kg)
+                               12, 14, 15,     //note: belfast has biceps curl 12 (2kg), and 13 (4kg)
+                               "PRE", "PI", "12M", "18M"));
+                               */
                list.Add(new ComputerDB(
+                               "denmark",
                                "denmark1",
                                
"/home/xavier/Documents/academic/investigacio/Encoder_SITLESS/carpetes-chronojump-senceres/denmark/wetransfer-08b800/Chronojump
 Backup 09.10.2019 - HP - FINAL - DK site/database",
                                "",
-                               8, 9, 7));
+                               8, 9, 7,
+                               "PRE", "POST", "FU12", "FU18"));
                list.Add(new ComputerDB(
+                               "denmark",
                                "denmark2",
                                
"/home/xavier/Documents/academic/investigacio/Encoder_SITLESS/carpetes-chronojump-senceres/denmark/wetransfer-08b800/Chronojump
 Backup 09.10.2019 - Lenovo - FINAL - DK site/database",
                                "",
-                               8, 11, 7));
+                               8, 11, 7,
+                               "PRE", "POST", "FU12", "FU18"));
+               /*
                list.Add(new ComputerDB(
+                               "ulm",
                                "ulm1",
                                
"/home/xavier/Documents/academic/investigacio/Encoder_SITLESS/carpetes-chronojump-senceres/Encoder_Ulm/Laptop1_Chronojump_für
 Maria_Nov2019/chronojump/database",
                                "",
-                               8,4,7));
+                               8,4,7,
+                               "PRE", "a2", "a3", "a4"));
+               /*
                list.Add(new ComputerDB(
+                               "ulm",
                                "ulm2",
                                
"/home/xavier/Documents/academic/investigacio/Encoder_SITLESS/carpetes-chronojump-senceres/Encoder_Ulm/Laptop2_Chronojump_für
 Maria_Nov2019/database",
                                "",
-                               8,9,7)); //note: they have also jumps on 4
+                               8,9,7,  //note: they have also jumps on 4
+                               "PRE", "a2", "a3", "a4"));
                list.Add(new ComputerDB(
+                               "ulm",
                                "ulm3",
                                
"/home/xavier/Documents/academic/investigacio/Encoder_SITLESS/carpetes-chronojump-senceres/Encoder_Ulm/Laptop3_Chronojump_für
 Maria_Nov2019/database",
                                "",
-                               8,4,7));
+                               8,4,7,
+                               "PRE", "a2", "a3", "a4"));
+                               */
        }
 }
 
+static class ComputerDBMomentByProcessedFiles
+{
+       public static string FindOnBarcelona(string location, string filename)
+       {
+               //1 parse date of filename
+               Console.WriteLine("FindMoment for filename: " + filename);
+               string searchedDatetime = getFilenameDatetime(filename);
+               if(searchedDatetime == "")
+                       return "(moment)";
+
+               //2 search date on all folders
+               int foundCount = 0;
+               string moment = "NOTFOUND:" + searchedDatetime;
+               DirectoryInfo [] dirArray = new DirectoryInfo(location).GetDirectories();
+                foreach (DirectoryInfo dir in dirArray)
+               {
+                       foreach (FileInfo file in dir.GetFiles())
+                       {
+                               //Console.WriteLine("filename: {0}, date: {1}", file.Name, 
getFilenameDatetime(file.Name));
+                               if(getFilenameDatetime(file.Name) == searchedDatetime)
+                               {
+                                       Console.WriteLine("FOUND at folder: {0}", dir.Name);
+                                       moment = dir.Name;
+                                       foundCount ++;
+                               }
+                       }
+               }
+
+               if(foundCount >= 2)
+               {
+                       Console.WriteLine(string.Format("FOUND {0} times!!!", foundCount));
+                       return "DUPLICATED";
+               }
+               return moment;
+       }
+       //this function is exclusive from processMultiDatabases code
+       private static string getFilenameDatetime(string filename)
+       {
+               Match match = Regex.Match(filename, @"(\d+-\d+-\d+_\d+-\d+-\d+)");
+               if(match.Groups.Count == 2)
+                       return match.Value;
+
+               return "";
+       }
+
+}
diff --git a/processMultiDatabases/processMultiDatabases.cs b/processMultiDatabases/processMultiDatabases.cs
index 02b60a0b..4f7ee393 100644
--- a/processMultiDatabases/processMultiDatabases.cs
+++ b/processMultiDatabases/processMultiDatabases.cs
@@ -18,6 +18,68 @@
  * Copyright (C) 2019   Xavier de Blas <xaviblas gmail com> 
  */
 
+/*
+ * crashed at:
+ * expression("1 Title=", "hola")
+[1] "/tmp/chronojump-last-encoder-data.txt"
+[1] "/tmp/chronojump-last-encoder-graph.png"
+[1] "/tmp/chronojump-last-encoder-curves.txt"
+[1] "/tmp/chronojump-encoder-status-"
+[1] "/tmp/chronojump-special-data.txt"
+Read 8713 items
+
+Unhandled Exception:
+System.IO.IOException: Write fault on path 
/home/xavier/informatica/progs_meus/chronojump/chronojump/processMultiDatabases/[Unknown]
+  at System.IO.FileStream.WriteInternal (System.Byte[] src, System.Int32 offset, System.Int32 count) 
<0x7f96f2c927d0 + 0x001ba> in <d2ec5c92492f4d6ba8c422bdf574b786>:0
+  at System.IO.FileStream.Write (System.Byte[] array, System.Int32 offset, System.Int32 count) 
<0x7f96f2c92680 + 0x000bd> in <d2ec5c92492f4d6ba8c422bdf574b786>:0
+  at System.IO.StreamWriter.Flush (System.Boolean flushStream, System.Boolean flushEncoder) <0x7f96f2c615c0 
+ 0x000c4> in <d2ec5c92492f4d6ba8c422bdf574b786>:0
+  at System.IO.StreamWriter.WriteSpan (System.ReadOnlySpan`1[T] buffer, System.Boolean appendNewLine) 
<0x7f96f2c61a30 + 0x001f5> in <d2ec5c92492f4d6ba8c422bdf574b786>:0
+  at System.IO.StreamWriter.WriteLine (System.String value) <0x7f96f2c61de0 + 0x00178> in 
<d2ec5c92492f4d6ba8c422bdf574b786>:0
+  at CallR.callRStart () [0x0019d] in <1c2b597e9ef34320b28fca7ab406049b>:0
+  at CallR..ctor (EncoderStruct es) [0x0001a] in <1c2b597e9ef34320b28fca7ab406049b>:0
+  at ProcessMultiDatabases.processCompDBEx (ComputerDB compDB, ComputerDB+ExerciseString exerciseString, 
System.Int32 exerciseID, System.Int32 percentBodyWeight) [0x00169] in <1c2b597e9ef34320b28fca7ab406049b>:0
+  at ProcessMultiDatabases..ctor () [0x000a2] in <1c2b597e9ef34320b28fca7ab406049b>:0
+  at ProcessMultiDatabases.Main (System.String[] args) [0x00000] in <1c2b597e9ef34320b28fca7ab406049b>:0
+[ERROR] FATAL UNHANDLED EXCEPTION: System.IO.IOException: Write fault on path 
/home/xavier/informatica/progs_meus/chronojump/chronojump/processMultiDatabases/[Unknown]
+  at System.IO.FileStream.WriteInternal (System.Byte[] src, System.Int32 offset, System.Int32 count) 
<0x7f96f2c927d0 + 0x001ba> in <d2ec5c92492f4d6ba8c422bdf574b786>:0
+  at System.IO.FileStream.Write (System.Byte[] array, System.Int32 offset, System.Int32 count) 
<0x7f96f2c92680 + 0x000bd> in <d2ec5c92492f4d6ba8c422bdf574b786>:0
+  at System.IO.StreamWriter.Flush (System.Boolean flushStream, System.Boolean flushEncoder) <0x7f96f2c615c0 
+ 0x000c4> in <d2ec5c92492f4d6ba8c422bdf574b786>:0
+  at System.IO.StreamWriter.WriteSpan (System.ReadOnlySpan`1[T] buffer, System.Boolean appendNewLine) 
<0x7f96f2c61a30 + 0x001f5> in <d2ec5c92492f4d6ba8c422bdf574b786>:0
+  at System.IO.StreamWriter.WriteLine (System.String value) <0x7f96f2c61de0 + 0x00178> in 
<d2ec5c92492f4d6ba8c422bdf574b786>:0
+  at CallR.callRStart () [0x0019d] in <1c2b597e9ef34320b28fca7ab406049b>:0
+  at CallR..ctor (EncoderStruct es) [0x0001a] in <1c2b597e9ef34320b28fca7ab406049b>:0
+  at ProcessMultiDatabases.processCompDBEx (ComputerDB compDB, ComputerDB+ExerciseString exerciseString, 
System.Int32 exerciseID, System.Int32 percentBodyWeight) [0x00169] in <1c2b597e9ef34320b28fca7ab406049b>:0
+  at ProcessMultiDatabases..ctor () [0x000a2] in <1c2b597e9ef34320b28fca7ab406049b>:0
+  at ProcessMultiDatabases.Main (System.String[] args) [0x00000] in <1c2b597e9ef34320b28fca7ab406049b>:0
+
+  maybe R has been closed and have to be opened again, see how is done in Chronojump
+  */
+
+/*results of moment are:
+ * > d=read.csv("chronojump-processMultiEncoder.csv")
+ * > table(d$moment)
+
+                       12M_3                        18M_4
+                        1760                         1382
+                    Baseline                        End_2
+                        6236                          584
+NOTFOUND:2015-11-27_13-35-27 NOTFOUND:2015-11-27_13-38-49
+                           5                            1
+NOTFOUND:2015-11-27_13-45-37 NOTFOUND:2015-12-03_08-28-14
+                           6                            3
+NOTFOUND:2015-12-18_16-07-48 NOTFOUND:2015-12-18_16-08-19
+                           3                            3
+NOTFOUND:2015-12-18_16-08-33 NOTFOUND:2016-01-11_18-15-47
+                           3                            3
+NOTFOUND:2018-02-06_12-23-01 NOTFOUND:2018-02-15_10-44-45
+                           3                            3
+NOTFOUND:2018-03-09_09-50-31 NOTFOUND:2018-03-12_10-00-07
+                           2                            4
+NOTFOUND:2018-07-19_09-04-43 NOTFOUND:2019-03-26_09-58-30
+                           3                            3
+*/
+
+
 //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
@@ -25,6 +87,7 @@
 //- rest of the cities: read the code
 //ecc-con: on sit to stand
 //dist min: sit to stand: 30. study the different dist of each rep is we have a min rep of 3 cm
+//- need to manage the extra weight on each exercise (biceps curl at belfast is 2 or 4 Kg). but no problem, 
is stored on the eSQL
 
 using System;
 using System.IO; //"File" things. TextWriter. Path
@@ -55,7 +118,7 @@ class ProcessMultiDatabases
                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");
+               
writer.WriteLine("city,computer,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");
 
                foreach(ComputerDB compDB in compDBManage.list)
                {
@@ -135,7 +198,10 @@ class ProcessMultiDatabases
 
                        string moment = "(moment)";
                        if(compDB.pathToFindMoments != "")
-                               moment = UtilDate.FindMoment(compDB.pathToFindMoments, eSQL.filename);
+                               moment = 
ComputerDBMomentByProcessedFiles.FindOnBarcelona(compDB.pathToFindMoments, eSQL.filename);
+                       else {
+                               moment = compDB.FindMoment(eSQL.filename);
+                       }
 
                        //now we have to parse it to fill the big file
                        string filename = "/tmp/chronojump-last-encoder-curves.txt";
@@ -146,7 +212,7 @@ class ProcessMultiDatabases
                                if(firstRep)
                                        firstRep = false;
                                else {
-                                       string repToWriter = string.Format("{0},{1},{2},{3},{4},", 
compDB.name, exerciseString, person.Name, person.Sex,  moment) + rep;
+                                       string repToWriter = string.Format("{0},{1},{2},{3},{4},{5},", 
compDB.city, compDB.name, exerciseString, person.Name, person.Sex,  moment) + rep;
                                        //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
 
@@ -160,7 +226,12 @@ class ProcessMultiDatabases
                        if(debug && count >= 5)
                                break;
 
-                       System.Threading.Thread.Sleep(100); //rest a bit
+                       System.Threading.Thread.Sleep(200);
+                       /*
+                        * rest a bit 100 gave me one problem:
+                        * System.IO.IOException: Write fault on path 
/home/xavier/informatica/progs_meus/chronojump/chronojump/processMultiDatabases/[Unknown]
+                        * trying 200
+                        */
                }
 
                Console.WriteLine("processDatabase done!");
diff --git a/processMultiDatabases/utilDate.cs b/processMultiDatabases/utilDate.cs
index ff36931a..17c1641c 100644
--- a/processMultiDatabases/utilDate.cs
+++ b/processMultiDatabases/utilDate.cs
@@ -19,8 +19,6 @@
  */
 
 using System;
-using System.IO;
-using System.Text.RegularExpressions; //Regex
 
 public class UtilDate
 {
@@ -64,49 +62,5 @@ public class UtilDate
                 return dt;
         }
 
-       //this function is exclusive from processMultiDatabases code
-       public static string FindMoment(string location, string filename)
-       {
-               //1 parse date of filename
-               Console.WriteLine("FindMoment for filename: " + filename);
-               string searchedDatetime = getFilenameDatetime(filename);
-               if(searchedDatetime == "")
-                       return "(moment)";
-
-               //2 search date on all folders
-               int foundCount = 0;
-               string moment = "NOTFOUND:" + searchedDatetime;
-               DirectoryInfo [] dirArray = new DirectoryInfo(location).GetDirectories();
-                foreach (DirectoryInfo dir in dirArray)
-               {
-                       foreach (FileInfo file in dir.GetFiles())
-                       {
-                               //Console.WriteLine("filename: {0}, date: {1}", file.Name, 
getFilenameDatetime(file.Name));
-                               if(getFilenameDatetime(file.Name) == searchedDatetime)
-                               {
-                                       Console.WriteLine("FOUND at folder: {0}", dir.Name);
-                                       moment = dir.Name;
-                                       foundCount ++;
-                               }
-                       }
-               }
-
-               if(foundCount >= 2)
-               {
-                       Console.WriteLine(string.Format("FOUND {0} times!!!", foundCount));
-                       return "DUPLICATED";
-               }
-               return moment;
-       }
-
-       //this function is exclusive from processMultiDatabases code
-       private static string getFilenameDatetime(string filename)
-       {
-               Match match = Regex.Match(filename, @"(\d+-\d+-\d+_\d+-\d+-\d+)");
-               if(match.Groups.Count == 2)
-                       return match.Value;
-
-               return "";
-       }
 }
 


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