[chronojump] Encoder inertial graphs on X: equivalent mass or inertia moment or diameter



commit acc089979f28a13c3e2bbad4d1dee9c181540eee
Author: Xavier de Blas <xaviblas gmail com>
Date:   Tue Nov 17 13:52:43 2020 +0100

    Encoder inertial graphs on X: equivalent mass or inertia moment or diameter

 encoder/graph.R             | 36 ++++++++++++++++++++++++------------
 encoder/util.R              |  9 ++++++---
 src/encoder.cs              | 15 +++++++++------
 src/encoderRProc.cs         | 12 +++++++++---
 src/gui/app1/encoder.cs     |  9 ++++++---
 src/gui/encoderTreeviews.cs |  8 ++++----
 src/utilEncoder.cs          |  6 ++++--
 7 files changed, 62 insertions(+), 33 deletions(-)
---
diff --git a/encoder/graph.R b/encoder/graph.R
index a3e5313e..efb3a6ae 100644
--- a/encoder/graph.R
+++ b/encoder/graph.R
@@ -1574,6 +1574,10 @@ findPosInPaf <- function(var, option) {
                 pos = 17
         else if(var == "Inertia")
                 pos = 18
+        else if(var == "Diameter") #Inertial
+                pos = 19
+        else if(var == "EquivalentMass") #Inertial
+                pos = 20
         
         if( ( var == "Speed" || var == "Power" || var == "Force") & option == "max")
                 pos=pos+1
@@ -1839,17 +1843,24 @@ paintCrossVariablesLaterality <- function(x, y, laterality, colBalls, varX = "Lo
 paintCrossVariables <- function (paf, varX, varY, option, 
                                  dateAsX, dateTime,
                                  isAlone, title, singleFile, Eccon, ecconVector, seriesName,
-                                 diameter, gearedDown,
+                                inertialGraphX,
                                  do1RM, do1RMMethod, outputData1) 
 {
         hasInertia <- FALSE
         if(findInertialCurves(paf))
                 hasInertia <- TRUE
-        
+
         #if there's one or more inertial curves: show inertia instead of mass
         if(varX == "Load" && hasInertia)
-                varX = "Inertia"
-        
+       {
+               if(inertialGraphX == "EQUIVALENT_MASS")
+                       varX = "EquivalentMass"
+               else if(inertialGraphX == "INERTIA_MOMENT")
+                       varX = "Inertia"
+               else
+                       varX = "Diameter"
+       }
+
         if(varX == "Load")
                 x = (paf[,findPosInPaf("MassExtra", option)])
         else
@@ -1882,6 +1893,7 @@ paintCrossVariables <- function (paf, varX, varY, option,
         #        varX = "Resistant torque"
         #        varXut = "Resistant torque (Kg*cm)"
         #}
+       #if in the future we use this code again, use cols from paf
         
         if(dateAsX) {
                 xCopy <- x
@@ -3743,7 +3755,7 @@ doProcess <- function(options)
                                                     op$Eccon,
                                                     ecconVector,
                                                     mySeries, 
-                                                    repOp$diameter, repOp$gearedDown,
+                                                    op$InertialGraphX,
                                                     FALSE, FALSE, op$OutputData1) 
                                 par(new=T)
                                 paintCrossVariables(paf, op$AnalysisVariables[2], analysisVertVars[2], 
op$AnalysisVariables[3], 
@@ -3753,7 +3765,7 @@ doProcess <- function(options)
                                                     op$Eccon,
                                                     ecconVector,
                                                     mySeries, 
-                                                    repOp$diameter, repOp$gearedDown,
+                                                    op$InertialGraphX,
                                                     FALSE, FALSE, op$OutputData1) 
                         } else {
                                #if Force,Power is on Y, then send only force to paintCrossVariables. Power 
will be added on that function
@@ -3771,7 +3783,7 @@ doProcess <- function(options)
                                                     op$Eccon,
                                                     ecconVector,
                                                     mySeries, 
-                                                    repOp$diameter, repOp$gearedDown,
+                                                    op$InertialGraphX,
                                                     FALSE, FALSE, op$OutputData1) 
                         }
                 }
@@ -3789,7 +3801,7 @@ doProcess <- function(options)
                                             op$Eccon,
                                             ecconVector,
                                             mySeries, 
-                                            repOp$diameter, repOp$gearedDown,
+                                           op$InertialGraphX,
                                             op$AnalysisVariables[1], op$AnalysisVariables[2], #speed1RM, 
method
                                             op$OutputData1) 
                 }
@@ -3911,7 +3923,7 @@ doProcess <- function(options)
                                                 "maxForce_maxForceT",
                                                "workJ", "impulse",
                                                 "laterality", "inertiaM", "diameter",
-                                               "massEq" #calculation of massEquivalent using gearedDown
+                                               "equivalentMass"
                         )
                         
                         #Add "Max", "AVG" and "SD" when analyzing, not on "curves", not on "curvesAC", not 
on "curvesProcessMultiDB"
@@ -3931,7 +3943,7 @@ doProcess <- function(options)
                                                          max(pafCurves$meanForce), max(pafCurves$maxForce), 
max(pafCurves$maxForceT),
                                                          max(pafCurves$maxForce_maxForceT),
                                                         max(pafCurves$workJ), max(pafCurves$impulse),
-                                                         "", max(pafCurves$inertiaM), 
max(pafCurves$diameter), max(pafCurves$massEq)
+                                                         "", max(pafCurves$inertiaM), 
max(pafCurves$diameter), max(pafCurves$equivalentMass)
                                         )
                                         
                                         #2) AVG
@@ -3943,7 +3955,7 @@ doProcess <- function(options)
                                                          mean(pafCurves$meanForce), 
mean(pafCurves$maxForce), mean(pafCurves$maxForceT),
                                                          mean(pafCurves$maxForce_maxForceT),
                                                         mean(pafCurves$workJ), mean(pafCurves$impulse),
-                                                         "", mean(pafCurves$inertiaM), 
mean(pafCurves$diameter), mean(pafCurves$massEq)
+                                                         "", mean(pafCurves$inertiaM), 
mean(pafCurves$diameter), mean(pafCurves$equivalentMass)
                                         )
                                         
                                         #3) Add SD if there's more than one data row.
@@ -3956,7 +3968,7 @@ doProcess <- function(options)
                                                                 sd(pafCurves$meanForce), 
sd(pafCurves$maxForce), sd(pafCurves$maxForceT),
                                                                sd(pafCurves$maxForce_maxForceT),
                                                                sd(pafCurves$workJ), sd(pafCurves$impulse),
-                                                                "", sd(pafCurves$inertiaM), 
sd(pafCurves$diameter), sd(pafCurves$massEq)
+                                                                "", sd(pafCurves$inertiaM), 
sd(pafCurves$diameter), sd(pafCurves$equivalentMass)
                                                 )
                                         
                                         
diff --git a/encoder/util.R b/encoder/util.R
index 649fa215..e2105c1f 100644
--- a/encoder/util.R
+++ b/encoder/util.R
@@ -99,7 +99,8 @@ assignOptions <- function(options) {
                    #   englishWords [29]
                    #   translatedWords [30]
                    SeparateSessionInDays = options[35],
-                   AnalysisMode         = options[36]
+                   AnalysisMode         = options[36],
+                   InertialGraphX       = options[37]
                    ))
 }
 
@@ -824,6 +825,8 @@ pafGenerate <- function(eccon, kinematics, massBody, massExtra, laterality, iner
        mass = kinematics$mass
        #names will be used on graph.R writeCurves
 
+       equivalentMass = calculateEquivalentMass(inertiaMomentum, gearedDown, diameter)
+
        return(data.frame(
                          meanSpeed, maxSpeed, maxSpeedT,
                          meanPower, peakPower, peakPowerT, pp_ppt,
@@ -831,11 +834,11 @@ pafGenerate <- function(eccon, kinematics, massBody, massExtra, laterality, iner
                          mass, massBody, massExtra,            #kinematics$mass is Load
                          workJ, impulse,
                          laterality, inertiaMomentum, diameter,
-                         calculateMassEquivalent(inertiaMomentum, gearedDown, diameter)
+                         equivalentMass
                          ))
 }
 
-calculateMassEquivalent <- function(inertiaMomentum, gearedDown, diameter)
+calculateEquivalentMass <- function(inertiaMomentum, gearedDown, diameter)
 {
        if(inertiaMomentum > 0 && gearedDown > 0 && diameter > 0)
                return (10000 * inertiaMomentum * 1/gearedDown / 4 / (diameter^2))
diff --git a/src/encoder.cs b/src/encoder.cs
index b8234141..7bf21bbd 100644
--- a/src/encoder.cs
+++ b/src/encoder.cs
@@ -163,6 +163,7 @@ public class EncoderGraphROptions
        private string triggerList;
        public bool separateSessionInDays;
        public AnalysisModes analysisMode; //the four analysisModes
+       Preferences.EncoderInertialGraphsXTypes inertialGraphX;
 
        public enum AnalysisModes { CAPTURE, INDIVIDUAL_CURRENT_SET, INDIVIDUAL_CURRENT_SESSION, 
INDIVIDUAL_ALL_SESSIONS, GROUPAL_CURRENT_SESSION }
 
@@ -173,7 +174,7 @@ public class EncoderGraphROptions
                        string title, string operatingSystem,
                        string englishWords, string translatedWords,
                        bool debug, bool crossValidate, bool cutByTriggers, string triggerList,
-                       bool separateSessionInDays, AnalysisModes analysisMode)
+                       bool separateSessionInDays, AnalysisModes analysisMode, 
Preferences.EncoderInertialGraphsXTypes inertialGraphX)
        {
                this.inputData = inputData;
                this.outputGraph = outputGraph;
@@ -191,6 +192,7 @@ public class EncoderGraphROptions
                this.triggerList = triggerList;
                this.separateSessionInDays = separateSessionInDays;
                this.analysisMode = analysisMode;
+               this.inertialGraphX = inertialGraphX;
 
                //ensure triggerList is not null or blank
                if(triggerList == null || triggerList == "")
@@ -214,7 +216,8 @@ public class EncoderGraphROptions
                        "#cutByTriggers\n" +    Util.BoolToRBool(cutByTriggers) + "\n" +
                        "#triggerList\n" +      triggerList + "\n" +
                        "#separateSessionInDays\n" +    Util.BoolToRBool(separateSessionInDays) + "\n" +
-                       "#analysisMode\n" +     analysisMode.ToString() + "\n";
+                       "#analysisMode\n" +     analysisMode.ToString() + "\n" +
+                       "#inertialGraphX\n" +   inertialGraphX.ToString() + "\n";
        }
        
 
@@ -235,7 +238,7 @@ public class EncoderCurve
        public double DisplacedWeight;
        public int Inertia;             //analyze inertial
        public double Diameter;         //analyze inertial
-       public double MassEquivalent;   //analyze inertial
+       public double EquivalentMass;   //analyze inertial
        public string Start;
        public string Duration;
        public string Height;
@@ -291,7 +294,7 @@ public class EncoderCurve
        public EncoderCurve (string n, string series, string exercise, 
                        string laterality,
                        double extraWeight, double displacedWeight,
-                       int inertia, double diameter, double massEquivalent,    //3 inertial params
+                       int inertia, double diameter, double EquivalentMass,    //3 inertial params
                        string start, string duration, string height,
                        string meanSpeed, string maxSpeed, string maxSpeedT,
                        string meanPower, string peakPower, string peakPowerT, 
@@ -308,7 +311,7 @@ public class EncoderCurve
                this.DisplacedWeight = displacedWeight;
                this.Inertia = inertia;         //inertial
                this.Diameter = diameter;       //inertial
-               this.MassEquivalent = massEquivalent;   //inertial
+               this.EquivalentMass = EquivalentMass;   //inertial
                this.Start = start;
                this.Duration = duration;
                this.Height = height;
@@ -450,7 +453,7 @@ public class EncoderCurve
                                ExtraWeight + sep + DisplacedWeight + sep;
 
                        if(currentMode == Constants.Menuitem_modes.POWERINERTIAL)
-                               str += Inertia + sep + Util.TrimDecimals(Diameter,1) + sep + 
Util.TrimDecimals(MassEquivalent,3) + sep;
+                               str += Inertia + sep + Util.TrimDecimals(Diameter,1) + sep + 
Util.TrimDecimals(EquivalentMass,3) + sep;
 
                        str +=
                                Start + sep + Duration + sep + Height + sep + 
diff --git a/src/encoderRProc.cs b/src/encoderRProc.cs
index 8f090d87..b3c825cb 100644
--- a/src/encoderRProc.cs
+++ b/src/encoderRProc.cs
@@ -260,7 +260,9 @@ public class EncoderRProcCapture : EncoderRProc
                                (CutByTriggers != Preferences.TriggerTypes.NO_TRIGGERS),
                                printTriggers(TriggerList.Type3.ON),
                                false,  //separateSessionInDays (false at capture)
-                               EncoderGraphROptions.AnalysisModes.CAPTURE).ToString();
+                               EncoderGraphROptions.AnalysisModes.CAPTURE,
+                               Preferences.EncoderInertialGraphsXTypes.EQUIVALENT_MASS //unused on capture
+                               ).ToString();
 
                TextWriter writer = File.CreateText(optionsFile);
                writer.Write(scriptOptions);
@@ -289,6 +291,7 @@ public class EncoderRProcAnalyze : EncoderRProc
        private bool cutByTriggers;
        private TriggerList triggerList;
        private EncoderGraphROptions.AnalysisModes analysisMode;
+       private Preferences.EncoderInertialGraphsXTypes inertialGraphX;
 
        /*
         * to avoid problems on some windows. R exports csv to Util.GetEncoderExportTempFileName()
@@ -302,7 +305,8 @@ public class EncoderRProcAnalyze : EncoderRProc
        }
 
        public void SendData(string title, bool neuromuscularProfileDo, bool translate,
-                       bool cutByTriggers, TriggerList triggerList, EncoderGraphROptions.AnalysisModes 
analysisMode)
+                       bool cutByTriggers, TriggerList triggerList,
+                       EncoderGraphROptions.AnalysisModes analysisMode, 
Preferences.EncoderInertialGraphsXTypes inertialGraphX)
        {
                this.title = title;
                this.neuromuscularProfileDo = neuromuscularProfileDo;
@@ -310,6 +314,7 @@ public class EncoderRProcAnalyze : EncoderRProc
                this.cutByTriggers = cutByTriggers;
                this.triggerList = triggerList;
                this.analysisMode = analysisMode;
+               this.inertialGraphX = inertialGraphX;
                
                CancelRScript = false;
        }
@@ -520,7 +525,8 @@ public class EncoderRProcAnalyze : EncoderRProc
                                cutByTriggers,
                                printTriggers(TriggerList.Type3.ON),
                                SeparateSessionInDays,
-                               analysisMode
+                               analysisMode,
+                               inertialGraphX
                                ).ToString();
 
                TextWriter writer = File.CreateText(optionsFile);
diff --git a/src/gui/app1/encoder.cs b/src/gui/app1/encoder.cs
index b0b579ee..c7bc6d17 100644
--- a/src/gui/app1/encoder.cs
+++ b/src/gui/app1/encoder.cs
@@ -1477,7 +1477,8 @@ public partial class ChronoJumpWindow
                                preferences.RGraphsTranslate,
                                (preferences.encoderCaptureCutByTriggers != 
Preferences.TriggerTypes.NO_TRIGGERS),
                                triggerListEncoder,
-                               getAnalysisMode()
+                               getAnalysisMode(),
+                               preferences.encoderInertialGraphsX
                                ); 
                bool result = encoderRProcAnalyze.StartOrContinue(es);
                                
@@ -2030,7 +2031,8 @@ public partial class ChronoJumpWindow
                                preferences.RGraphsTranslate,
                                (preferences.encoderCaptureCutByTriggers != 
Preferences.TriggerTypes.NO_TRIGGERS),
                                new TriggerList(),
-                               getAnalysisMode()
+                               getAnalysisMode(),
+                               preferences.encoderInertialGraphsX
                                );
                encoderRProcAnalyze.StartOrContinue(encoderStruct);
 
@@ -3345,7 +3347,8 @@ public partial class ChronoJumpWindow
                                preferences.RGraphsTranslate,
                                (preferences.encoderCaptureCutByTriggers != 
Preferences.TriggerTypes.NO_TRIGGERS),
                                triggerListEncoder,
-                               getAnalysisMode()
+                               getAnalysisMode(),
+                               preferences.encoderInertialGraphsX
                                );
 
                encoderRProcAnalyze.StartOrContinue(encoderStruct);
diff --git a/src/gui/encoderTreeviews.cs b/src/gui/encoderTreeviews.cs
index 89200d2c..2b55b619 100644
--- a/src/gui/encoderTreeviews.cs
+++ b/src/gui/encoderTreeviews.cs
@@ -815,7 +815,7 @@ public partial class ChronoJumpWindow
                                        aColumn.SetCellDataFunc (aCell, new Gtk.TreeCellDataFunc 
(RenderDiameter));     //inertial
                                        break;
                                case 8:
-                                       aColumn.SetCellDataFunc (aCell, new Gtk.TreeCellDataFunc 
(RenderMassEquivalent));       //inertial
+                                       aColumn.SetCellDataFunc (aCell, new Gtk.TreeCellDataFunc 
(RenderEquivalentMass));       //inertial
                                        break;
                                case 9:
                                        aColumn.SetCellDataFunc (aCell, new Gtk.TreeCellDataFunc 
(RenderStart));
@@ -1207,11 +1207,11 @@ public partial class ChronoJumpWindow
                renderBoldIfNeeded(cell, curve, str);
        }
 
-       private void RenderMassEquivalent (Gtk.TreeViewColumn column, Gtk.CellRenderer cell, Gtk.TreeModel 
model, Gtk.TreeIter iter)
+       private void RenderEquivalentMass (Gtk.TreeViewColumn column, Gtk.CellRenderer cell, Gtk.TreeModel 
model, Gtk.TreeIter iter)
        {
                EncoderCurve curve = (EncoderCurve) model.GetValue (iter, 0);
 
-               string str = 
String.Format(UtilGtk.TVNumPrint(curve.MassEquivalent.ToString(),6,2),Convert.ToDouble(curve.MassEquivalent));
+               string str = 
String.Format(UtilGtk.TVNumPrint(curve.EquivalentMass.ToString(),6,2),Convert.ToDouble(curve.EquivalentMass));
 
                renderBoldIfNeeded(cell, curve, str);
        }
@@ -1679,7 +1679,7 @@ public partial class ChronoJumpWindow
 
                //capture does not return inerta
                //analyze returns inertia (can be different on "saved curves") comes as Kg*m^2, convert it to 
Kg*cm^2
-               //analyze returns also diameter and massEquivalent (both used on inertial)
+               //analyze returns also diameter and equivalentMass (both used on inertial)
                if(! captureOrAnalyze) {
                        double inertiaInM = Convert.ToDouble(Util.ChangeDecimalSeparator(cells[22]));
                        cells[22] = (Convert.ToInt32(inertiaInM * 10000)).ToString();
diff --git a/src/utilEncoder.cs b/src/utilEncoder.cs
index 065fdfae..2f30dd25 100644
--- a/src/utilEncoder.cs
+++ b/src/utilEncoder.cs
@@ -340,7 +340,8 @@ public class UtilEncoder
 
        public static EncoderGraphROptions PrepareEncoderGraphOptions(
                        string title, EncoderStruct es, bool neuromuscularProfileDo, bool translate, bool 
debug, bool crossValidate,
-                       bool cutByTriggers, string triggerStr, bool separateSessionInDays, 
EncoderGraphROptions.AnalysisModes analysisMode)
+                       bool cutByTriggers, string triggerStr, bool separateSessionInDays,
+                       EncoderGraphROptions.AnalysisModes analysisMode, 
Preferences.EncoderInertialGraphsXTypes inertialGraphX)
        {
                string operatingSystem = OperatingSystemForRGraphs();
                        
@@ -395,7 +396,8 @@ public class UtilEncoder
                                title, operatingSystem,
                                Util.StringArrayToString(Constants.EncoderEnglishWords,";"),
                                Util.StringArrayToString(encoderTranslatedWordsOK,";"),
-                               debug, crossValidate, cutByTriggers, triggerStr, separateSessionInDays, 
analysisMode
+                               debug, crossValidate, cutByTriggers, triggerStr, separateSessionInDays,
+                               analysisMode, inertialGraphX
                                );
        }
 


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