[chronojump] encoder work and impulse shown while capturing (was 0 on 2.0.2)



commit 18e3c775b0f7b2b0453a2a4dd83da999829a83d3
Author: Xavier de Blas <xaviblas gmail com>
Date:   Wed Oct 21 18:01:55 2020 +0200

    encoder work and impulse shown while capturing (was 0 on 2.0.2)

 src/constants.cs               | 14 ++++++++--
 src/encoder.cs                 | 15 +++++++++--
 src/gui/app1/encoder.cs        |  8 ++++--
 src/gui/encoderGraphObjects.cs | 61 ++++++++++++++++++++++++++----------------
 4 files changed, 69 insertions(+), 29 deletions(-)
---
diff --git a/src/constants.cs b/src/constants.cs
index c5f96f65..f147a6e5 100644
--- a/src/constants.cs
+++ b/src/constants.cs
@@ -1189,11 +1189,13 @@ public class Constants
        public const string MaxForce = "Max force";
        public const string MeanPower = "Mean power";
        public const string PeakPower = "Peak power";
+       public const string WorkJ = "WorkJ";
+       public const string Impulse = "Impulse";
        public static string [] EncoderVariablesCaptureList = {
-               RangeAbsolute, MeanSpeed, MaxSpeed, MeanForce, MaxForce, MeanPower, PeakPower
+               RangeAbsolute, MeanSpeed, MaxSpeed, MeanForce, MaxForce, MeanPower, PeakPower, WorkJ, Impulse
        };
        public enum EncoderVariablesCapture {
-               RangeAbsolute, MeanSpeed, MaxSpeed, MeanForce, MaxForce, MeanPower, PeakPower
+               RangeAbsolute, MeanSpeed, MaxSpeed, MeanForce, MaxForce, MeanPower, PeakPower, WorkJ, Impulse
        }
        public static string GetEncoderVariablesCapture(EncoderVariablesCapture enumVariable) {
                switch(enumVariable) {
@@ -1211,6 +1213,10 @@ public class Constants
                                return MeanPower;
                        case EncoderVariablesCapture.PeakPower:
                                return PeakPower;
+                       case EncoderVariablesCapture.WorkJ:
+                               return WorkJ;
+                       case EncoderVariablesCapture.Impulse:
+                               return Impulse;
                }
                return MeanPower;
        }
@@ -1230,6 +1236,10 @@ public class Constants
                                return EncoderVariablesCapture.MeanPower;
                        case PeakPower:
                                return EncoderVariablesCapture.PeakPower;
+                       case WorkJ:
+                               return EncoderVariablesCapture.WorkJ;
+                       case Impulse:
+                               return EncoderVariablesCapture.Impulse;
                }
                return EncoderVariablesCapture.MeanPower;
        }
diff --git a/src/encoder.cs b/src/encoder.cs
index 4a3dbec6..5e85abcb 100644
--- a/src/encoder.cs
+++ b/src/encoder.cs
@@ -1375,8 +1375,11 @@ public class EncoderBarsData
        public double MaxForce;
        public double MeanPower;
        public double PeakPower;
+       public double WorkJ;
+       public double Impulse;
        
-       public EncoderBarsData(double range, double meanSpeed, double maxSpeed, double meanForce, double 
maxForce, double meanPower, double peakPower)
+       public EncoderBarsData(double range, double meanSpeed, double maxSpeed, double meanForce, double 
maxForce,
+                       double meanPower, double peakPower, double workJ, double impulse)
        {
                this.Range = range;
                this.MeanSpeed = meanSpeed;
@@ -1385,6 +1388,8 @@ public class EncoderBarsData
                this.MaxForce  = maxForce;
                this.MeanPower = meanPower;
                this.PeakPower = peakPower;
+               this.WorkJ = workJ;
+               this.Impulse = impulse;
        }
 
        public double GetValue (string option)
@@ -1403,8 +1408,14 @@ public class EncoderBarsData
                        return MaxForce;
                else if(option == Constants.MeanPower)
                        return MeanPower;
-               else // option == Constants.PeakPower
+               else if(option == Constants.PeakPower)
                        return PeakPower;
+               else if(option == Constants.WorkJ)
+                       return WorkJ;
+               else if(option == Constants.Impulse)
+                       return Impulse;
+
+               return MeanPower;
        }
        
        ~EncoderBarsData() {}
diff --git a/src/gui/app1/encoder.cs b/src/gui/app1/encoder.cs
index 836f8feb..9d1023ae 100644
--- a/src/gui/app1/encoder.cs
+++ b/src/gui/app1/encoder.cs
@@ -6071,7 +6071,9 @@ public partial class ChronoJumpWindow
                        double maxForce = Convert.ToDouble(Util.ChangeDecimalSeparator(strs[12]));
                        double meanPower = Convert.ToDouble(Util.ChangeDecimalSeparator(strs[7]));
                        double peakPower = Convert.ToDouble(Util.ChangeDecimalSeparator(strs[8]));
-                       captureCurvesBarsData.Add(new EncoderBarsData(range, meanSpeed, maxSpeed, meanForce, 
maxForce, meanPower, peakPower));
+                       double workJ = Convert.ToDouble(Util.ChangeDecimalSeparator(strs[15]));
+                       double impulse = Convert.ToDouble(Util.ChangeDecimalSeparator(strs[16]));
+                       captureCurvesBarsData.Add(new EncoderBarsData(range, meanSpeed, maxSpeed, meanForce, 
maxForce, meanPower, peakPower, workJ, impulse));
                        
                        LogB.Information("activating needToRefreshTreeviewCapture");
 
@@ -6740,7 +6742,9 @@ public partial class ChronoJumpWindow
                                                                        Convert.ToDouble(curve.MeanForce),
                                                                        Convert.ToDouble(curve.MaxForce),
                                                                        Convert.ToDouble(curve.MeanPower),
-                                                                       Convert.ToDouble(curve.PeakPower)
+                                                                       Convert.ToDouble(curve.PeakPower),
+                                                                       Convert.ToDouble(curve.WorkJ),
+                                                                       Convert.ToDouble(curve.Impulse)
                                                                        ));
                                        }
                                }
diff --git a/src/gui/encoderGraphObjects.cs b/src/gui/encoderGraphObjects.cs
index 58452aea..fe6c84c6 100644
--- a/src/gui/encoderGraphObjects.cs
+++ b/src/gui/encoderGraphObjects.cs
@@ -43,7 +43,7 @@ public class EncoderGraphDoPlot
        private RepetitiveConditionsWindow repetitiveConditionsWin;
        private bool hasInertia;
        private bool playSoundsFromFile;
-       private ArrayList data7Variables;
+       private ArrayList data9Variables;
        private Gtk.ListStore encoderCaptureListStore;
        private bool relativeToSet;
        private double maxPowerSpeedForceIntersession; //it will be one of these 3
@@ -56,6 +56,8 @@ public class EncoderGraphDoPlot
        private ArrayList data; //data is related to mainVariable (barplot)
        private ArrayList dataSecondary; //dataSecondary is related to secondary variable (by default range)
        private ArrayList dataRangeOfMovement; //ROM, need it to discard last rep for loss. Is not the same 
as dataSecondary because maybe user selected another variable as secondary. only checks con.
+       private ArrayList dataWorkJ;
+       private ArrayList dataImpulse;
 
        private RepetitionMouseLimits encoderRepetitionMouseLimits;
 
@@ -145,7 +147,7 @@ public class EncoderGraphDoPlot
                        string secondaryVariable, bool capturing, string eccon,
                        RepetitiveConditionsWindow repetitiveConditionsWin,
                        bool hasInertia, bool playSoundsFromFile,
-                       ArrayList data7Variables, Gtk.ListStore encoderCaptureListStore,
+                       ArrayList data9Variables, Gtk.ListStore encoderCaptureListStore,
                        bool relativeToSet,
                        double maxPowerSpeedForceIntersession, string maxPowerSpeedForceIntersessionDate)
        {
@@ -158,7 +160,7 @@ public class EncoderGraphDoPlot
                this.repetitiveConditionsWin = repetitiveConditionsWin;
                this.hasInertia = hasInertia;
                this.playSoundsFromFile = playSoundsFromFile;
-               this.data7Variables = data7Variables;
+               this.data9Variables = data9Variables;
                this.encoderCaptureListStore = encoderCaptureListStore;
                this.relativeToSet = relativeToSet;
                this.maxPowerSpeedForceIntersession = maxPowerSpeedForceIntersession;
@@ -174,14 +176,16 @@ public class EncoderGraphDoPlot
 
        private void fillDataVariables()
        {
-               data = new ArrayList (data7Variables.Count); //data is related to mainVariable (barplot)
-               dataSecondary = new ArrayList (data7Variables.Count); //dataSecondary is related to secondary 
variable (by default range)
-               dataRangeOfMovement = new ArrayList (data7Variables.Count);
+               data = new ArrayList (data9Variables.Count); //data is related to mainVariable (barplot)
+               dataSecondary = new ArrayList (data9Variables.Count); //dataSecondary is related to secondary 
variable (by default range)
+               dataRangeOfMovement = new ArrayList (data9Variables.Count);
+               dataWorkJ = new ArrayList (data9Variables.Count);
+               dataImpulse = new ArrayList (data9Variables.Count);
                bool lastIsEcc = false;
                int count = 0;
 
                //discard repetitions according to showNRepetitions
-               foreach(EncoderBarsData ebd in data7Variables)
+               foreach(EncoderBarsData ebd in data9Variables)
                {
                        //LogB.Information(string.Format("count: {0}, value: {1}", count, 
ebd.GetValue(mainVariable)));
                        //when capture ended, show all repetitions
@@ -191,19 +195,23 @@ public class EncoderGraphDoPlot
                                if(secondaryVariable != "")
                                        dataSecondary.Add(ebd.GetValue(secondaryVariable));
                                dataRangeOfMovement.Add(ebd.GetValue(Constants.RangeAbsolute));
+                               dataWorkJ.Add(ebd.GetValue(Constants.WorkJ));
+                               dataImpulse.Add(ebd.GetValue(Constants.Impulse));
                        }
                        else {
-                               if(eccon == "c" && ( data7Variables.Count <= showNRepetitions ||        
//total repetitions are less than show repetitions threshold ||
-                                               count >= data7Variables.Count - showNRepetitions ) )    
//count is from the last group of reps (reps that have to be shown)
+                               if(eccon == "c" && ( data9Variables.Count <= showNRepetitions ||        
//total repetitions are less than show repetitions threshold ||
+                                               count >= data9Variables.Count - showNRepetitions ) )    
//count is from the last group of reps (reps that have to be shown)
                                {
                                        data.Add(ebd.GetValue(mainVariable));
                                        if(secondaryVariable != "")
                                                dataSecondary.Add(ebd.GetValue(secondaryVariable));
                                        dataRangeOfMovement.Add(ebd.GetValue(Constants.RangeAbsolute));
+                                       dataWorkJ.Add(ebd.GetValue(Constants.WorkJ));
+                                       dataImpulse.Add(ebd.GetValue(Constants.Impulse));
                                }
                                else if(eccon != "c" && (
-                                               data7Variables.Count <= 2 * showNRepetitions ||
-                                               count >= data7Variables.Count - 2 * showNRepetitions) )
+                                               data9Variables.Count <= 2 * showNRepetitions ||
+                                               count >= data9Variables.Count - 2 * showNRepetitions) )
                                {
                                        if(! Util.IsEven(count +1))     //if it is "impar"
                                        {
@@ -212,6 +220,8 @@ public class EncoderGraphDoPlot
                                                if(secondaryVariable != "")
                                                        dataSecondary.Add(ebd.GetValue(secondaryVariable));
                                                
dataRangeOfMovement.Add(ebd.GetValue(Constants.RangeAbsolute));
+                                               dataWorkJ.Add(ebd.GetValue(Constants.WorkJ));
+                                               dataImpulse.Add(ebd.GetValue(Constants.Impulse));
                                                lastIsEcc = true;
                                        } else {                        //it is "par"
                                                if(lastIsEcc)
@@ -220,12 +230,15 @@ public class EncoderGraphDoPlot
                                                        if(secondaryVariable != "")
                                                                
dataSecondary.Add(ebd.GetValue(secondaryVariable));
                                                        
dataRangeOfMovement.Add(ebd.GetValue(Constants.RangeAbsolute));
+                                                       dataWorkJ.Add(ebd.GetValue(Constants.WorkJ));
+                                                       dataImpulse.Add(ebd.GetValue(Constants.Impulse));
                                                        LogB.Information("added con");
                                                        lastIsEcc = false;
                                                }
                                        }
                                }
                        }
+                       //LogB.Information("data workJ: " + dataWorkJ[count].ToString());
                        count ++;
                }
        }
@@ -829,16 +842,18 @@ public class EncoderGraphDoPlot
                                }
                        }
 
-                       //work
-                       if(iterOk) {
+                       //work and impulse
+                       if(dataWorkJ.Count > 0)
+                       {
                                if(preferences.encoderWorkKcal)
-                                       workTotal += ((EncoderCurve) encoderCaptureListStore.GetValue (iter, 
0)).WorkKcalD;
+                                       workTotal += Convert.ToDouble(dataWorkJ[count]) * 0.000239006;
                                else
-                                       workTotal += ((EncoderCurve) encoderCaptureListStore.GetValue (iter, 
0)).WorkJD;
-
-                               impulseTotal += ((EncoderCurve) encoderCaptureListStore.GetValue (iter, 
0)).ImpulseD;
+                                       workTotal += Convert.ToDouble(dataWorkJ[count]);
                        }
 
+                       if(dataImpulse.Count > 0)
+                               impulseTotal += Convert.ToDouble(dataImpulse[count]);
+
                        //add text on the bottom
                        if (eccon == "c" || Util.IsEven(count +1)) //par
                        {
@@ -853,14 +868,14 @@ public class EncoderGraphDoPlot
                                if(showNRepetitions > 0 && capturing)
                                {
 
-                                       if (eccon == "c" && data7Variables.Count > showNRepetitions)
-                                               bottomText = ( (data7Variables.Count - showNRepetitions) + 
count +1).ToString();
-                                       else if (eccon != "c" && data7Variables.Count > showNRepetitions*2)
+                                       if (eccon == "c" && data9Variables.Count > showNRepetitions)
+                                               bottomText = ( (data9Variables.Count - showNRepetitions) + 
count +1).ToString();
+                                       else if (eccon != "c" && data9Variables.Count > showNRepetitions*2)
                                        {
-                                               //LogB.Information(string.Format("bottomText vars B: {0}, 
{1}, {2}, {3}", data7Variables.Count, showNRepetitions*2, count,
-                                               //                      
Math.Floor(Convert.ToDouble((data7Variables.Count +1)/2)) - showNRepetitions + 
Math.Floor(Convert.ToDouble(((count +1)/2)))
+                                               //LogB.Information(string.Format("bottomText vars B: {0}, 
{1}, {2}, {3}", data9Variables.Count, showNRepetitions*2, count,
+                                               //                      
Math.Floor(Convert.ToDouble((data9Variables.Count +1)/2)) - showNRepetitions + 
Math.Floor(Convert.ToDouble(((count +1)/2)))
                                                //                      ));
-                                               bottomText = ( 
Math.Floor(Convert.ToDouble((data7Variables.Count +1)/2)) - showNRepetitions + 
Math.Floor(Convert.ToDouble(((count +1)/2))) ).ToString();
+                                               bottomText = ( 
Math.Floor(Convert.ToDouble((data9Variables.Count +1)/2)) - showNRepetitions + 
Math.Floor(Convert.ToDouble(((count +1)/2))) ).ToString();
                                        }
                                }
 


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