[chronojump] Race analyzer export with triggers. Done!



commit 4d342be20c1094dabd10077b8233f19da40b5d97
Author: Xavier de Blas <xaviblas gmail com>
Date:   Wed Mar 10 20:23:23 2021 +0100

    Race analyzer export with triggers. Done!

 r-scripts/sprintEncoder.R |  8 +++++---
 src/exportFiles/re.cs     | 23 +++++++++++++++++++++--
 src/runEncoder.cs         | 19 ++++++++++++++-----
 3 files changed, 40 insertions(+), 10 deletions(-)
---
diff --git a/r-scripts/sprintEncoder.R b/r-scripts/sprintEncoder.R
index b582c16e..0fa2248b 100644
--- a/r-scripts/sprintEncoder.R
+++ b/r-scripts/sprintEncoder.R
@@ -782,7 +782,7 @@ start <- function(op)
        #2) read the csv
        dataFiles = read.csv(file = paste(tempPath, "/cj_race_analyzer_input_multi.csv", sep=""), sep=";", 
stringsAsFactors=F)
 
-       #3) call doProcess
+       #3) call testEncoderCJ
        progressFolder = paste(tempPath, "/chronojump_export_progress", sep ="")
        tempGraphsFolder = paste(tempPath, "/chronojump_race_analyzer_export_graphs/", sep ="")
        exportDF = NULL
@@ -796,8 +796,10 @@ start <- function(op)
                prepareGraph(op$os, pngFile, op$graphWidth, op$graphHeight)
                exportRow = testEncoderCJ(as.vector(dataFiles$fullURL[i]), dataFiles$testLength[i], 
dataFiles$splitLength[i],
                                dataFiles$mass[i], dataFiles$personHeight[i], dataFiles$tempC[i],
-                               dataFiles$device[i], dataFiles$title[i], dataFiles$datetime[i],
-                               op$startAccel)
+                               dataFiles$device[i], dataFiles$title[i], dataFiles$datetime[i], op$startAccel,
+                               as.numeric(unlist(strsplit(dataFiles$triggersOn[i], "\\,"))),
+                               as.numeric(unlist(strsplit(dataFiles$triggersOff[i], "\\,")))
+               )
 
                if(! is.null(exportRow))
                {
diff --git a/src/exportFiles/re.cs b/src/exportFiles/re.cs
index 07ccb56b..b52c0a64 100644
--- a/src/exportFiles/re.cs
+++ b/src/exportFiles/re.cs
@@ -18,6 +18,7 @@
  * Copyright (C) 2021   Xavier de Blas <xaviblas gmail com>
  */
 
+using System;
 using System.IO;                       //Directory, ...
 using System.Collections;              //ArrayList
 using System.Collections.Generic;      //List<T>
@@ -38,6 +39,7 @@ public class RunEncoderExport : ExportFiles
        private List<RunEncoder> re_l;
        ArrayList personSession_l;
        private ArrayList reEx_l;
+       private List<TriggerList> triggerListOfLists;
 
        //constructor
        public RunEncoderExport (
@@ -87,6 +89,20 @@ public class RunEncoderExport : ExportFiles
                personSession_l = SqlitePersonSession.SelectCurrentSessionPersons(sessionID, true);
                reEx_l = SqliteRunEncoderExercise.Select (false, -1, false);
 
+               //get all the triggers to not be opening and closing sqlite on processSets
+               triggerListOfLists = new List<TriggerList>();
+               Sqlite.Open();
+               foreach(RunEncoder re in re_l)
+               {
+                       TriggerList triggerListRunEncoder = new TriggerList(
+                                       SqliteTrigger.Select(
+                                               true, Trigger.Modes.RACEANALYZER,
+                                               re.UniqueID)
+                                       );
+                       triggerListOfLists.Add(triggerListRunEncoder);
+               }
+               Sqlite.Close();
+
                return re_l.Count > 0;
        }
 
@@ -97,9 +113,12 @@ public class RunEncoderExport : ExportFiles
 
                List<RunEncoderGraphExport> rege_l = new List<RunEncoderGraphExport>();
 
-               int count = 1;
+               //int count = 1;
+               int element = -1; //used to sync re_l[element] with triggerListOfLists[element]
                foreach(RunEncoder re in re_l)
                {
+                       element ++;
+
                        // 1) checks
                        //check fs is ok
                        if(re == null || ! Util.FileExists(re.FullURL))
@@ -153,6 +172,7 @@ public class RunEncoderExport : ExportFiles
                                        re.Device,
                                        re.Temperature, re.Distance,
                                        reEx, title, re.DateTimePublic,
+                                       triggerListOfLists[element],
                                        re.Comments
                                        );
                        rege_l.Add(rege);
@@ -170,7 +190,6 @@ public class RunEncoderExport : ExportFiles
                                        plotRawAccel, plotFittedAccel,
                                        plotRawForce, plotFittedForce,
                                        plotRawPower, plotFittedPower,
-                                       //triggerList,
                                        rege_l,
                                        exportDecimalSeparator,
                                        includeImages
diff --git a/src/runEncoder.cs b/src/runEncoder.cs
index c4c2bdf2..46efe149 100644
--- a/src/runEncoder.cs
+++ b/src/runEncoder.cs
@@ -422,6 +422,7 @@ public class RunEncoderGraphExport
        private RunEncoderExercise rex;
        private string title;
        private string datetime;
+       private TriggerList triggerList;
        private string comments;
 
        public RunEncoderGraphExport(
@@ -430,6 +431,7 @@ public class RunEncoderGraphExport
                        RunEncoder.Devices device,
                        double tempC, int testLength,
                        RunEncoderExercise rex, string title, string datetime,
+                       TriggerList triggerList,
                        string comments)
        {
                this.fullURL = fullURL; //filename
@@ -442,6 +444,7 @@ public class RunEncoderGraphExport
                this.title = title;
                this.datetime = datetime;
                this.comments = comments;
+               this.triggerList = triggerList;
        }
 
        public string ToCSVRowOnExport()
@@ -455,14 +458,21 @@ public class RunEncoderGraphExport
                        rex.SegmentMeters.ToString() + ";" +
                        title + ";" +
                        datetime + ";" +
+                       printTriggers(TriggerList.Type3.ON) + ";" +
+                       printTriggers(TriggerList.Type3.OFF) + ";" +
                        Util.RemoveChar(comments, ';');  //TODO: check this really removes
        }
 
+       private string printTriggers(TriggerList.Type3 type3)
+       {
+               return triggerList.ToRCurvesString(type3, ','); //because we pass a csv separated by ;
+       }
+
        public static string PrintCSVHeaderOnExport()
        {
                return "fullURL;mass;personHeight;device;tempC;testLength;" +
                        "splitLength;" + //segmentMeters on C#, splitLength on R
-                       "title;datetime;comments";
+                       "title;datetime;triggersOn;triggersOff;comments";
        }
 }
 
@@ -543,7 +553,6 @@ public class RunEncoderGraph
                        bool plotRawAccel, bool plotFittedAccel,
                        bool plotRawForce, bool plotFittedForce,
                        bool plotRawPower, bool plotFittedPower,
-                       //TriggerList triggerList,
                        List<RunEncoderGraphExport> rege_l,
                        char exportDecimalSeparator,
                        bool includeImagesOnExport
@@ -602,8 +611,8 @@ public class RunEncoderGraph
                        "#plotFittedForce\n" +          Util.BoolToRBool(plotFittedForce) + "\n" +
                        "#plotRawPower\n" +             Util.BoolToRBool(plotRawPower) + "\n" +
                        "#plotFittedPower\n" +          Util.BoolToRBool(plotFittedPower) + "\n" +
-                       printTriggers(TriggerList.Type3.ON) + "\n" +
-                       printTriggers(TriggerList.Type3.OFF) + "\n" +
+                       printTriggers(TriggerList.Type3.ON) + "\n" +            //unused on multiple
+                       printTriggers(TriggerList.Type3.OFF) + "\n" +           //unused on multiple
                        "#singleOrMultiple\n" +         Util.BoolToRBool(singleOrMultiple) + "\n" +
                        "#decimalCharAtExport\n" +      exportDecimalSeparator + "\n" +
                        "#includeImagesOnExport\n" +    Util.BoolToRBool(includeImagesOnExport) + "\n";
@@ -636,7 +645,7 @@ public class RunEncoderGraph
 
        private string printTriggers(TriggerList.Type3 type3)
        {
-               return triggerList.ToRCurvesString(type3);
+               return triggerList.ToRCurvesString(type3, ';');
        }
 
        public static string GetDataDir(int sessionID)


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