[chronojump] processMultiDatabases search moment in Barcelona data



commit 0fa641ca6f1c18dc661c01c16f937aad425574a9
Author: Xavier de Blas <xaviblas gmail com>
Date:   Mon Dec 23 15:27:25 2019 +0100

    processMultiDatabases search moment in Barcelona data

 processMultiDatabases/computerDB.cs            | 11 ++++++
 processMultiDatabases/processMultiDatabases.cs | 18 ++++++----
 processMultiDatabases/utilDate.cs              | 46 ++++++++++++++++++++++++++
 3 files changed, 68 insertions(+), 7 deletions(-)
---
diff --git a/processMultiDatabases/computerDB.cs b/processMultiDatabases/computerDB.cs
index 99ed3eb3..71aca1b9 100644
--- a/processMultiDatabases/computerDB.cs
+++ b/processMultiDatabases/computerDB.cs
@@ -25,6 +25,7 @@ class ComputerDB
 {
        public string name;
        public string path;
+       public string pathToFindMoments; //at barcelona we can find datetimes on 4 folders to know which 
moment
        //exercises, if one is not done on that computer: -1
        public int exBicepsCurlID;      //0% bodyweight
        public int exJumpID;            //100% bodyweight
@@ -34,10 +35,12 @@ class ComputerDB
        public enum ExerciseString { BICEPSCURL, JUMP, SITTOSTAND };
        public ComputerDB(string name,
                        string path,
+                       string pathToFindMoments,
                        int exBicepsCurlID, int exJumpID, int exSitToStandID)
        {
                this.name = name;
                this.path = path;
+               this.pathToFindMoments = pathToFindMoments;
                this.exBicepsCurlID = exBicepsCurlID;
                this.exJumpID = exJumpID;
                this.exSitToStandID = exSitToStandID;
@@ -59,34 +62,42 @@ class ComputerDBManage
                list.Add(new ComputerDB(
                                "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));
                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",
+                               
"/home/xavier/Documents/academic/investigacio/Encoder_SITLESS/arxius-processats-per-ells/barcelona",
                                8, 4, 7));
                list.Add(new ComputerDB(
                                "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)
                list.Add(new ComputerDB(
                                "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));
                list.Add(new ComputerDB(
                                "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));
                list.Add(new ComputerDB(
                                "ulm1",
                                
"/home/xavier/Documents/academic/investigacio/Encoder_SITLESS/carpetes-chronojump-senceres/Encoder_Ulm/Laptop1_Chronojump_für
 Maria_Nov2019/chronojump/database",
+                               "",
                                8,4,7));
                list.Add(new ComputerDB(
                                "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
                list.Add(new ComputerDB(
                                "ulm3",
                                
"/home/xavier/Documents/academic/investigacio/Encoder_SITLESS/carpetes-chronojump-senceres/Encoder_Ulm/Laptop3_Chronojump_für
 Maria_Nov2019/database",
+                               "",
                                8,4,7));
        }
 }
diff --git a/processMultiDatabases/processMultiDatabases.cs b/processMultiDatabases/processMultiDatabases.cs
index 5a5c2b33..02b60a0b 100644
--- a/processMultiDatabases/processMultiDatabases.cs
+++ b/processMultiDatabases/processMultiDatabases.cs
@@ -133,20 +133,24 @@ 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
 
+                       string moment = "(moment)";
+                       if(compDB.pathToFindMoments != "")
+                               moment = UtilDate.FindMoment(compDB.pathToFindMoments, eSQL.filename);
+
                        //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);
-                       bool firstLine = true;
-                       foreach(string line in lines)
+                       List<string> reps = Util.ReadFileAsStringList(filename);
+                       bool firstRep = true;
+                       foreach(string rep in reps)
                        {
-                               if(firstLine)
-                                       firstLine = false;
+                               if(firstRep)
+                                       firstRep = false;
                                else {
-                                       string line2 = string.Format("{0},{1},{2},{3},{4}", compDB.name, 
exerciseString, person.Name, person.Sex,  "(moment)") + line;
+                                       string repToWriter = string.Format("{0},{1},{2},{3},{4},", 
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
 
-                                       writer.WriteLine(line2);
+                                       writer.WriteLine(repToWriter);
                                        writer.Flush();
                                }
                        }
diff --git a/processMultiDatabases/utilDate.cs b/processMultiDatabases/utilDate.cs
index 17c1641c..ff36931a 100644
--- a/processMultiDatabases/utilDate.cs
+++ b/processMultiDatabases/utilDate.cs
@@ -19,6 +19,8 @@
  */
 
 using System;
+using System.IO;
+using System.Text.RegularExpressions; //Regex
 
 public class UtilDate
 {
@@ -62,5 +64,49 @@ 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]