[chronojump] ProcessMultiDatabases with barcelona stuff



commit 6819f04f6576eeb2226fd9563073e39d79c4ce0e
Author: Xavier de Blas <xaviblas gmail com>
Date:   Mon Sep 28 16:33:31 2020 +0200

    ProcessMultiDatabases with barcelona stuff

 processMultiDatabases/computerDB.cs |  9 +++++++-
 processMultiDatabases/joinGroup.R   | 10 ++++++---
 processMultiDatabases/person.cs     | 42 +++++++++++++++++++++++++++++++++++++
 processMultiDatabases/util.cs       | 26 +++++++++++++++++++++++
 4 files changed, 83 insertions(+), 4 deletions(-)
---
diff --git a/processMultiDatabases/computerDB.cs b/processMultiDatabases/computerDB.cs
index ba85ee79..7c65e1c4 100644
--- a/processMultiDatabases/computerDB.cs
+++ b/processMultiDatabases/computerDB.cs
@@ -139,8 +139,12 @@ class ComputerDBManage
        public List<ComputerDB> list;
        public ComputerDBManage()
        {
+               //atencio pq a barcelona1 hi ha:
+               
///home/xavier/Documents/academic/investigacio/Encoder_SITLESS_nogit/carpetes-chronojump-senceres/barcelona/wetransfer-8ba4dd/Encoder_Copies_17_07_2019/database/chronojump.db
 (604 Kb)
+               //      i
+               
///home/xavier/Documents/academic/investigacio/Encoder_SITLESS_nogit/carpetes-chronojump-senceres/barcelona/wetransfer-8ba4dd/Encoder_Copies_17_07_2019/database/chronojump/database/chronojump.db
 (186 Kb)
+
                list = new List<ComputerDB>();
-               /*
                list.Add(new ComputerDB(
                                "barcelona",
                                "barcelona1", 
@@ -155,6 +159,7 @@ class ComputerDBManage
                                
"/home/xavier/Documents/academic/investigacio/Encoder_SITLESS/arxius-processats-per-ells/barcelona",
                                8, 4, 7,
                                "", "", "", ""));
+               /*
                //belfast is ok except the double exercise on biceps
                list.Add(new ComputerDB(
                                "belfast",
@@ -178,6 +183,7 @@ class ComputerDBManage
                                8, 11, 7,
                                "PRE", "POST", "FU12", "FU18"));
                */
+               /*
                list.Add(new ComputerDB(
                                "ulm",
                                "ulm1",
@@ -185,6 +191,7 @@ class ComputerDBManage
                                "",
                                8,4,7,
                                "PRE", "A2", "A3", "A4")); //in caps because comparison is done in caps
+               */
                /*
                list.Add(new ComputerDB(
                                "ulm",
diff --git a/processMultiDatabases/joinGroup.R b/processMultiDatabases/joinGroup.R
index aba41714..9f53d6f1 100644
--- a/processMultiDatabases/joinGroup.R
+++ b/processMultiDatabases/joinGroup.R
@@ -22,6 +22,9 @@ mergeAndWrite <- function (filename, data, centre = "BL")
        if(centre == "UL") {
                data = data[data$centre==4,]
        }       
+       if(centre == "BA") {
+               data = data[data$centre==2,]
+       }
        data <- data[c(2,4,7)] # nos quedamos solo con la columna grupo y la del identificador
        names(df)[10] = "exercise2"     # En df hay dos columnas con el nombre "exercise", cambiamos la 
segunda
        df2 <- merge(df, data, by.x = "personCode", by.y ="participante", all = F)
@@ -30,9 +33,10 @@ mergeAndWrite <- function (filename, data, centre = "BL")
 
 data <- read_excel(paste(path, "ID_GROUP.xlsx", sep=""))
 
-mergeAndWrite (paste(path, "chronojump-processMultiEncoder-belfast-done.csv", sep=""), data, centre = "BL")
-mergeAndWrite (paste(path, "chronojump-processMultiEncoder-denmark-done.csv", sep=""), data, centre = "DN")
-mergeAndWrite (paste(path, "chronojump-processMultiEncoder-ulm-done.csv", sep=""), data, centre = "UL")
+#mergeAndWrite (paste(path, "chronojump-processMultiEncoder-belfast-done.csv", sep=""), data, centre = "BL")
+#mergeAndWrite (paste(path, "chronojump-processMultiEncoder-denmark-done.csv", sep=""), data, centre = "DN")
+#mergeAndWrite (paste(path, "chronojump-processMultiEncoder-ulm-done.csv", sep=""), data, centre = "UL")
+mergeAndWrite (paste(path, "chronojump-processMultiEncoder-barcelona-done.csv", sep=""), data, centre = "BA")
 
 
 # ---- start of initial code to test denmark data and check number of observations ---->
diff --git a/processMultiDatabases/person.cs b/processMultiDatabases/person.cs
index 3244c1ec..b8a8e8f4 100644
--- a/processMultiDatabases/person.cs
+++ b/processMultiDatabases/person.cs
@@ -107,6 +107,48 @@ public class Person {
                        Match match = Regex.Match(nameClean, @"(\d+)");
                        if(match.Groups.Count == 2)
                                return match.Value;
+               } else if (city == "barcelona")
+               {
+                       //first num is the centre, second is the personCode, third is the moment
+                       //but need to return both first numbers without the _
+                       //02_092_4 should be 2092
+                       //10_317_3 should be 10317
+                       Match match = Regex.Match(name, @"^(\d+)_(\d+)_\d+");
+                       if(match.Groups.Count == 3)
+                       {
+                               string firstChars = match.Groups[1].Value;
+                               if(firstChars[0] == 0)
+                                       firstChars = firstChars.Substring(1,1);
+
+                               return firstChars + match.Groups[2].Value;
+                       }
+
+                       //043_2 should be 1043
+                       match = Regex.Match(name, @"^(\d+)_\d+");
+                       if(match.Groups.Count == 2)
+                       {
+                               return "1" + match.Groups[1].Value;
+                       }
+
+                       //062 should be: 1062
+                       //123 should be: 1123
+                       if(Util.IsNumber(name, false))
+                       {
+                               int num = Convert.ToInt32(name);
+                               if(num < 1000)
+                                       num += 1000;
+
+                               return num.ToString();
+                       }
+
+                       //sometimes the code is: 01035 and should be: 1035
+                       if(name.Length > 0 && name[0] == '0')
+                       {
+                               return name.Substring(1, name.Length -1);
+                       }
+
+                       //many of them come with the personCode correct, like 1025
+                       return name;
                }
 
                return "";
diff --git a/processMultiDatabases/util.cs b/processMultiDatabases/util.cs
index f5dad98a..e43f829b 100644
--- a/processMultiDatabases/util.cs
+++ b/processMultiDatabases/util.cs
@@ -134,5 +134,31 @@ public class Util
                        return null;
                }
        }
+
+       //gets a string and returns if all the chars are numbers or the decimal point in current localization
+       public static bool IsNumber(string str, bool canBeDecimal)
+       {
+               //false if it's blank
+               if(str.Length == 0)
+                       return false;
+
+               if(canBeDecimal) {
+                       double numD;
+                       //param 2 && 3 are needed on latin languages to achieve a negative result on "23.75"
+                       //without those params, "23.75" and "23,75" will be true on latin. Undesired
+                       if (double.TryParse(
+                                               str,
+                                               System.Globalization.NumberStyles.Float,
+                                               System.Globalization.NumberFormatInfo.CurrentInfo,
+                                               out numD))
+                               return true;
+               }
+
+               int numI;
+               if (int.TryParse(str, out numI))
+                       return true;
+
+               return false;
+       }
 }
 


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