[chronojump/FS-TFT-Menu] Encoder save best rep, best n reps, consecutive uses RepCriteria of previous commits



commit a72b246de333d881629db1c285de60d917430073
Author: Xavier de Blas <xaviblas gmail com>
Date:   Tue Apr 5 18:00:14 2022 +0200

    Encoder save best rep, best n reps, consecutive uses RepCriteria of previous commits

 src/encoder.cs               | 74 +++++++++++++++++++++++++++++++++-----------
 src/gui/app1/encoder.cs      |  6 +++-
 src/gui/encoderTreeviews.cs  | 18 +++++++----
 src/json/compujumpEncoder.cs | 12 +++----
 4 files changed, 79 insertions(+), 31 deletions(-)
---
diff --git a/src/encoder.cs b/src/encoder.cs
index ef3b5a7c4..b66ba5ded 100644
--- a/src/encoder.cs
+++ b/src/encoder.cs
@@ -15,7 +15,7 @@
  *  along with this program; if not, write to the Free Software
  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
- *  Copyright (C) 2004-2020   Xavier de Blas <xaviblas gmail com> 
+ *  Copyright (C) 2004-2022   Xavier de Blas <xaviblas gmail com>
  */
 
 using System;
@@ -530,25 +530,48 @@ public class EncoderSignal
        
        //this is an ecc-con curve
        //start is a counter of phases not of repetitions
-       public int FindPosOfBestEccCon(int start, string variable)
+       public int FindPosOfBestEccCon(int start, string variable, Preferences.EncoderRepetitionCriteria 
repCriteria)
        {
                double eccValue = 0;
                double conValue = 0;
 
-               double bestValue = 0; //will be ecc-con average
-               int bestValuePos = start; //will be the position of the ecc
+               double bestValue = 0; //will be ecc-con average, ecc or con depending on repCriteria
+               int bestValuePos = start; //will always be the position of the ecc
                int i = 0;
                
                bool ecc = true;
                foreach(EncoderCurve curve in curves) 
                {
-                       if(ecc) {
-                               eccValue = curve.GetParameter(variable);
-                       } else {
-                               conValue = curve.GetParameter(variable);
-                               if( i >= start && ( (eccValue + conValue) / 2 ) > bestValue) {
-                                       bestValue = (eccValue + conValue) / 2;
-                                       bestValuePos = i -1;
+                       if(repCriteria == Preferences.EncoderRepetitionCriteria.ECC_CON)
+                       {
+                               if(ecc) {
+                                       eccValue = curve.GetParameter(variable);
+                               } else {
+                                       conValue = curve.GetParameter(variable);
+                                       if( i >= start && ( (eccValue + conValue) / 2 ) > bestValue) {
+                                               bestValue = (eccValue + conValue) / 2;
+                                               bestValuePos = i -1; //the ecc
+                                       }
+                               }
+                       }
+                       else if(repCriteria == Preferences.EncoderRepetitionCriteria.ECC)
+                       {
+                               if(ecc) {
+                                       eccValue = curve.GetParameter(variable);
+                                       if(i >= start && eccValue > bestValue) {
+                                               bestValue = eccValue;
+                                               bestValuePos = i; //the ecc
+                                       }
+                               }
+                       }
+                       else// if(repCriteria == Preferences.EncoderRepetitionCriteria.CON)
+                       {
+                               if(! ecc) {
+                                       conValue = curve.GetParameter(variable);
+                                       if(i >= start && conValue > bestValue) {
+                                               bestValue = conValue;
+                                               bestValuePos = i-1; //the ecc
+                                       }
                                }
                        }
 
@@ -559,7 +582,7 @@ public class EncoderSignal
        }
 
        public enum Contraction { EC, C };
-       public List<int> FindPosOfBestN(int start, string variable, int n, Contraction eccon)
+       public List<int> FindPosOfBestN(int start, string variable, int n, Contraction eccon, 
Preferences.EncoderRepetitionCriteria repCriteria)
        {
                //1) find how many values to return
                //size of list will be n or the related curves if it is smaller
@@ -593,7 +616,7 @@ public class EncoderSignal
                        if(eccon == Contraction.C)
                                posOfBest = es.FindPosOfBest(start, variable);
                        else //(eccon == Contraction.EC)
-                               posOfBest = es.FindPosOfBestEccCon(start, variable);
+                               posOfBest = es.FindPosOfBestEccCon(start, variable, repCriteria);
 
                        listOfPos.Add(posOfBest);
                        count ++;
@@ -629,7 +652,7 @@ public class EncoderSignal
                }
                return bestValuePos;
        }
-       public int FindPosOfBestNConsecutiveEccCon(int start, string variable, int n)
+       public int FindPosOfBestNConsecutiveEccCon(int start, string variable, int n, 
Preferences.EncoderRepetitionCriteria repCriteria)
        {
                //2) find the best values and fill listOfPos
                double bestValue = 0;
@@ -640,19 +663,34 @@ public class EncoderSignal
                while(count <= curves.Count - n)
                {
                        double sum = 0;
+                       double eccSum = 0; //used on EncoderRepetitionCriteria.ECC
+                       double conSum = 0; //used on EncoderRepetitionCriteria.CON
+
                        for(int i = count; i < count + n; i += 2)
                        {
                                double eccValue = ((EncoderCurve) curves[i]).GetParameter(variable);
                                double conValue = ((EncoderCurve) curves[i+1]).GetParameter(variable);
                                sum += (eccValue + conValue) / 2;
-                               LogB.Information(string.Format("eccValue: {0}, conValue: {1}, accumulated 
sum: {2}", eccValue, conValue, sum));
+                               eccSum += eccValue;
+                               conSum += conValue;
+                               //LogB.Information(string.Format("eccValue: {0}, conValue: {1}, accumulated 
sum: {2}", eccValue, conValue, sum));
                        }
-                       LogB.Information("total sum: " + sum.ToString());
-                       if (sum > bestValue)
+                       //LogB.Information("total sum: " + sum.ToString());
+                       if(repCriteria == Preferences.EncoderRepetitionCriteria.ECC_CON && sum > bestValue)
                        {
                                bestValue = sum;
                                bestValuePos = count;
-                               LogB.Information(string.Format("bestValue: {0}, bestValuePos: {1}", 
bestValue, bestValuePos));
+                               //LogB.Information(string.Format("bestValue: {0}, bestValuePos: {1}", 
bestValue, bestValuePos));
+                       }
+                       else if (repCriteria == Preferences.EncoderRepetitionCriteria.ECC && eccSum > 
bestValue)
+                       {
+                               bestValue = eccSum;
+                               bestValuePos = count;
+                       }
+                       else if (repCriteria == Preferences.EncoderRepetitionCriteria.CON && conSum > 
bestValue)
+                       {
+                               bestValue = conSum;
+                               bestValuePos = count;
                        }
 
                        count += 2;
diff --git a/src/gui/app1/encoder.cs b/src/gui/app1/encoder.cs
index 18ab01064..c1c3b8517 100644
--- a/src/gui/app1/encoder.cs
+++ b/src/gui/app1/encoder.cs
@@ -7746,7 +7746,11 @@ public partial class ChronoJumpWindow
                                return;
                }
 
-               uo.Calcule();
+               Preferences.EncoderRepetitionCriteria repCriteria = 
preferences.encoderRepetitionCriteriaGravitatory;
+               if(current_mode == Constants.Modes.POWERINERTIAL)
+                       repCriteria = preferences.encoderRepetitionCriteriaInertial;
+
+               uo.Calcule(repCriteria);
 
                /*
                 * Problems on Json by accents like "Pressió sobre banc"
diff --git a/src/gui/encoderTreeviews.cs b/src/gui/encoderTreeviews.cs
index 436c8bd6a..7cb2f0147 100644
--- a/src/gui/encoderTreeviews.cs
+++ b/src/gui/encoderTreeviews.cs
@@ -15,7 +15,7 @@
  *  along with this program; if not, write to the Free Software
  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
- * Copyright (C) 2004-2020   Xavier de Blas <xaviblas gmail com> 
+ * Copyright (C) 2004-2022   Xavier de Blas <xaviblas gmail com>
  */
 
 using System;
@@ -420,22 +420,28 @@ public partial class ChronoJumpWindow
                                        numRows = encoderSignal.CurvesNum();
                                else if(saveOption == Constants.EncoderAutoSaveCurve.BESTN)
                                        list_bestN = encoderSignal.FindPosOfBestN(inertialStart, mainVariable,
-                                                       bestN, EncoderSignal.Contraction.C);
+                                                       bestN, EncoderSignal.Contraction.C,
+                                                       Preferences.EncoderRepetitionCriteria.CON); //but not 
used
                                else if(saveOption == Constants.EncoderAutoSaveCurve.BESTNCONSECUTIVE)
                                        bestRow = encoderSignal.FindPosOfBestNConsecutive(inertialStart, 
mainVariable,
                                                        bestN);
                        } else {
+                               //decide if best is by ecc_con average, ecc or con
+                               Preferences.EncoderRepetitionCriteria repCriteria = 
preferences.encoderRepetitionCriteriaGravitatory;
+                               if( current_mode == Constants.Modes.POWERINERTIAL)
+                                       repCriteria = preferences.encoderRepetitionCriteriaInertial;
+
                                EncoderSignal encoderSignal = new 
EncoderSignal(treeviewEncoderCaptureCurvesGetCurves(AllEccCon.ALL));
                                if(saveOption == Constants.EncoderAutoSaveCurve.BEST)
-                                       bestRow = encoderSignal.FindPosOfBestEccCon(inertialStart, 
mainVariable); //will be pos of the ecc
+                                       bestRow = encoderSignal.FindPosOfBestEccCon(inertialStart, 
mainVariable, repCriteria); //will be pos of the ecc
                                else if(saveOption == Constants.EncoderAutoSaveCurve.FROM4TOPENULTIMATE)
                                        numRows = encoderSignal.CurvesNum();
                                else if(saveOption == Constants.EncoderAutoSaveCurve.BESTN)
                                        list_bestN = encoderSignal.FindPosOfBestN(inertialStart, mainVariable,
-                                                       bestN, EncoderSignal.Contraction.EC);
+                                                       bestN, EncoderSignal.Contraction.EC, repCriteria);
                                else if(saveOption == Constants.EncoderAutoSaveCurve.BESTNCONSECUTIVE)
                                        bestRow = 
encoderSignal.FindPosOfBestNConsecutiveEccCon(inertialStart, mainVariable,
-                                                       bestN);
+                                                       bestN, repCriteria);
                        }
                }
 
@@ -1072,7 +1078,7 @@ public partial class ChronoJumpWindow
                        (cell as Gtk.CellRendererText).Text = 
                                decimal.Truncate((Convert.ToInt32(curve.N) +1) /2).ToString() + phase;
                } else 
-               {       //(ecconLast=="ce" || ecconLast =="ceS") {
+               {       //(ecconLast=="ce" || ecconLast =="ceS")
                        string phase = "c";
                        bool isEven = Util.IsEven(Convert.ToInt32(curve.N));
                        if(isEven)
diff --git a/src/json/compujumpEncoder.cs b/src/json/compujumpEncoder.cs
index d53a27dd8..b38e41eda 100644
--- a/src/json/compujumpEncoder.cs
+++ b/src/json/compujumpEncoder.cs
@@ -16,7 +16,7 @@
  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
  * Copyright (C) 2016-2017 Carles Pina
- * Copyright (C) 2016-2020 Xavier de Blas
+ * Copyright (C) 2016-2022 Xavier de Blas
  */
 
 using System;
@@ -129,12 +129,12 @@ public class UploadEncoderDataObject
                return true;
        }
 
-       public void Calcule()
+       public void Calcule (Preferences.EncoderRepetitionCriteria repCriteria)
        {
                if(eccon == "c")
                        calculeObjectCon (curves);
                else
-                       calculeObjectEccCon (curves);
+                       calculeObjectEccCon (curves, repCriteria);
        }
 
 
@@ -171,14 +171,14 @@ public class UploadEncoderDataObject
                lossByPower = getConLoss(curves, byTypes.POWER);
        }
 
-       private void calculeObjectEccCon (ArrayList curves)
+       private void calculeObjectEccCon (ArrayList curves, Preferences.EncoderRepetitionCriteria repCriteria)
        {
                repetitions = curves.Count / 2;
                EncoderSignal eSignal = new EncoderSignal(curves);
 
                //this n is the n of the ecc curve
-               int nSpeed = eSignal.FindPosOfBestEccCon(0, Constants.MeanSpeed);
-               int nPower = eSignal.FindPosOfBestEccCon(0, Constants.MeanPower);
+               int nSpeed = eSignal.FindPosOfBestEccCon(0, Constants.MeanSpeed, repCriteria);
+               int nPower = eSignal.FindPosOfBestEccCon(0, Constants.MeanPower, repCriteria);
 
                rangeBySpeed = Util.ConvertToPoint( eSignal.GetEccConMax(nSpeed, Constants.Range) );
                rangeByPower = Util.ConvertToPoint( eSignal.GetEccConMax(nPower, Constants.Range) );


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