[chronojump] Nicer method for FindPostOfBestN (con and eccon)
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] Nicer method for FindPostOfBestN (con and eccon)
- Date: Mon, 28 Oct 2019 18:04:09 +0000 (UTC)
commit 2d4b215f3e8627a6131899c89d942d070f5aa856
Author: Xavier de Blas <xaviblas gmail com>
Date: Mon Oct 28 19:03:49 2019 +0100
Nicer method for FindPostOfBestN (con and eccon)
src/encoder.cs | 77 ++++++++++++++-------------------------------
src/gui/encoderTreeviews.cs | 4 +--
2 files changed, 25 insertions(+), 56 deletions(-)
---
diff --git a/src/encoder.cs b/src/encoder.cs
index 0e7cf9b9..998bb75a 100644
--- a/src/encoder.cs
+++ b/src/encoder.cs
@@ -500,76 +500,46 @@ public class EncoderSignal
return bestValuePos;
}
-// 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)
+ public enum Contraction { EC, C };
+ public List<int> FindPosOfBestN(int start, string variable, int n, Contraction eccon)
{
- //size of list will be n or the related curves if it is smaller
- if(curves.Count - start < n)
- n = curves.Count - start;
-
- List<int> listOfPos = new List<int>(n);
-
- int posOfBest = -1;
- int count = 0;
+ //1) find how many values to return
+ if(eccon == Contraction.C)
+ {
+ //size of list will be n or the related curves if it is smaller
+ if(curves.Count - start < n)
+ n = curves.Count - start;
+ } else { //(eccon == Contraction.EC)
+ if(curves.Count/2 - start < n) //TODO check 0/2 return before
+ n = curves.Count/2 - start;
+ }
+ //2) make a copy of curves and have a new EncoderSignal to work with
ArrayList curvesCopy = new ArrayList();
foreach(EncoderCurve curve in curves)
- {
- EncoderCurve curveCopy = curve.Copy();
- curvesCopy.Add(curveCopy);
- }
+ curvesCopy.Add(curve.Copy());
EncoderSignal es = new EncoderSignal(curvesCopy);
- while(count < n)
- {
- if(posOfBest >= 0)
- {
- //LogB.Information("posOfBest: " + posOfBest.ToString());
- //curves.RemoveAt(posOfBest);
- //do not RemoveAt because it is difficult to know pos of next values,
- //just zero that curve
- ((EncoderCurve) curvesCopy[posOfBest]).ZeroAll();
- }
-
- posOfBest = es.FindPosOfBest(start, variable);
- listOfPos.Add(posOfBest);
- count ++;
- }
- return listOfPos;
- }
- public List<int> FindPosOfBestNEccCon(int start, string variable, int n)
- {
- //size of list will be n or the related curves if it is smaller
- if(curves.Count/2 - start < n) //TODO check 0/2 return before
- n = curves.Count/2 - start;
-
+ //3) find the best values and fill listOfPos
List<int> listOfPos = new List<int>(n);
-
int posOfBest = -1;
int count = 0;
- ArrayList curvesCopy = new ArrayList();
- foreach(EncoderCurve curve in curves)
- {
- EncoderCurve curveCopy = curve.Copy();
- curvesCopy.Add(curveCopy);
- }
- EncoderSignal es = new EncoderSignal(curvesCopy);
-
while(count < n)
{
if(posOfBest >= 0)
{
- //LogB.Information("posOfBest: " + posOfBest.ToString());
- //curves.RemoveAt(posOfBest);
- //do not RemoveAt because it is difficult to know pos of next values,
- //just zero that curve
+ //curves.RemoveAt(posOfBest); //do not do it because it is difficult to know
pos of next values, just zero that curve
((EncoderCurve) curvesCopy[posOfBest]).ZeroAll();
- ((EncoderCurve) curvesCopy[posOfBest+1]).ZeroAll();
+ if(eccon == Contraction.EC)
+ ((EncoderCurve) curvesCopy[posOfBest+1]).ZeroAll();
}
- posOfBest = es.FindPosOfBestEccCon(start, variable);
+ if(eccon == Contraction.C)
+ posOfBest = es.FindPosOfBest(start, variable);
+ else //(eccon == Contraction.EC)
+ posOfBest = es.FindPosOfBestEccCon(start, variable);
+
listOfPos.Add(posOfBest);
count ++;
}
@@ -577,7 +547,6 @@ public class EncoderSignal
}
-
public double GetEccConMean(int eccPos, string variable)
{
return(
diff --git a/src/gui/encoderTreeviews.cs b/src/gui/encoderTreeviews.cs
index 57f53b08..7cee8cf8 100644
--- a/src/gui/encoderTreeviews.cs
+++ b/src/gui/encoderTreeviews.cs
@@ -376,12 +376,12 @@ public partial class ChronoJumpWindow
EncoderSignal encoderSignal = new
EncoderSignal(treeviewEncoderCaptureCurvesGetCurves(AllEccCon.CON));
bestRow = encoderSignal.FindPosOfBest(inertialStart, mainVariable);
//this for BEST
numRows = encoderSignal.CurvesNum();
//this for FROM4TOPENULTIMATE
- list_bestN = encoderSignal.FindPosOfBestN(inertialStart, mainVariable, 3);
+ list_bestN = encoderSignal.FindPosOfBestN(inertialStart, mainVariable, 3,
EncoderSignal.Contraction.C);
} else {
EncoderSignal encoderSignal = new
EncoderSignal(treeviewEncoderCaptureCurvesGetCurves(AllEccCon.ALL));
bestRow = encoderSignal.FindPosOfBestEccCon(inertialStart, mainVariable);
//this for BEST //will be pos of the ecc
numRows = encoderSignal.CurvesNum();
//this for FROM4TOPENULTIMATE
- list_bestN = encoderSignal.FindPosOfBestNEccCon(inertialStart, mainVariable,
3);
+ list_bestN = encoderSignal.FindPosOfBestN(inertialStart, mainVariable, 3,
EncoderSignal.Contraction.EC);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]