[chronojump] Encoder: implemented BestN save repetitions method
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] Encoder: implemented BestN save repetitions method
- Date: Mon, 28 Oct 2019 17:54:00 +0000 (UTC)
commit 8e78e92836732cdff4376458994b540bf973af78
Author: Xavier de Blas <xaviblas gmail com>
Date: Mon Oct 28 18:53:30 2019 +0100
Encoder: implemented BestN save repetitions method
glade/app1.glade | 50 ++++++++++++++++++--------
src/constants.cs | 4 ++-
src/encoder.cs | 85 ++++++++++++++++++++++++++++++++++++++++++++-
src/gui/encoder.cs | 4 +++
src/gui/encoderTreeviews.cs | 19 ++++++----
5 files changed, 139 insertions(+), 23 deletions(-)
---
diff --git a/glade/app1.glade b/glade/app1.glade
index 0ef9c0d2..3d9e2b8d 100644
--- a/glade/app1.glade
+++ b/glade/app1.glade
@@ -22147,6 +22147,9 @@ Concentric</property>
<child>
<placeholder/>
</child>
+ <child>
+ <placeholder/>
+ </child>
</widget>
<packing>
<property name="expand">False</property>
@@ -24095,6 +24098,18 @@ Concentric</property>
<property name="can_focus">False</property>
<property name="spacing">6</property>
<child>
+ <widget class="GtkLabel"
id="label_video_encoder_tests_will_be_filmed">
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">Tests
will be filmed</property>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="pack_type">end</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
<widget class="GtkHBox"
id="hbox_video_encoder_capturing">
<property name="can_focus">False</property>
<property name="spacing">4</property>
@@ -24131,18 +24146,6 @@ Concentric</property>
</packing>
</child>
<child>
- <widget class="GtkLabel"
id="label_video_encoder_tests_will_be_filmed">
- <property name="can_focus">False</property>
- <property name="label" translatable="yes">Tests
will be filmed</property>
- </widget>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- <property name="pack_type">end</property>
- <property name="position">0</property>
- </packing>
- </child>
- <child>
<widget class="GtkHBox"
id="hbox_video_encoder_no_capturing">
<property name="visible">True</property>
<property name="can_focus">False</property>
@@ -24378,6 +24381,20 @@ Concentric</property>
</packing>
</child>
<child>
+ <widget class="GtkButton"
id="button_encoder_capture_curves_best_n">
+ <property name="label" translatable="yes">Best
n</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <signal name="clicked"
handler="on_button_encoder_capture_curves_best_n_clicked" swapped="no"/>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">2</property>
+ </packing>
+ </child>
+ <child>
<widget class="GtkButton"
id="button_encoder_capture_curves_all">
<property name="label"
translatable="yes">All</property>
<property name="visible">True</property>
@@ -24388,7 +24405,7 @@ Concentric</property>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
- <property name="position">2</property>
+ <property name="position">3</property>
</packing>
</child>
<child>
@@ -24402,7 +24419,7 @@ Concentric</property>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
- <property name="position">3</property>
+ <property name="position">4</property>
</packing>
</child>
<child>
@@ -24416,7 +24433,7 @@ Concentric</property>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
- <property name="position">4</property>
+ <property name="position">5</property>
</packing>
</child>
</widget>
@@ -31116,6 +31133,9 @@ then click this button.</property>
<child>
<placeholder/>
</child>
+ <child>
+ <placeholder/>
+ </child>
</widget>
<packing>
<property name="expand">False</property>
diff --git a/src/constants.cs b/src/constants.cs
index 995ef96e..9fc8b595 100644
--- a/src/constants.cs
+++ b/src/constants.cs
@@ -1209,7 +1209,9 @@ public class Constants
public const string ForceSensorLateralityLeft = "Left";
public const string ForceSensorLateralityRight = "Right";
- public enum EncoderAutoSaveCurve { ALL, NONE, BEST, FROM4TOPENULTIMATE } //note last mode not need to
be 4 because DB 1.63 introduces the config of this value
+ public enum EncoderAutoSaveCurve { ALL, NONE, BEST, BESTN, BESTNCONSECUTIVE, FROM4TOPENULTIMATE }
+ //BESTN means: "bests" (cannot say this in English)
+ //note last mode not need to be 4 because DB 1.63 introduces the config of this value
//BIGGEST_TC will be the default mode.
// - at END of each track: track ends before the biggest TC (just before the trunk arrives)
diff --git a/src/encoder.cs b/src/encoder.cs
index 6ff27c1b..0e7cf9b9 100644
--- a/src/encoder.cs
+++ b/src/encoder.cs
@@ -438,10 +438,13 @@ public class EncoderSignal
{
private ArrayList curves;
+ // constructor ----
+
public EncoderSignal (ArrayList curves) {
this.curves = curves;
}
+
public int CurvesNum() {
return curves.Count;
}
@@ -455,9 +458,11 @@ public class EncoderSignal
foreach(EncoderCurve curve in curves)
{
- if(i >= start && curve.GetParameter(variable) > bestValue) {
+ if(i >= start && curve.GetParameter(variable) > bestValue)
+ {
bestValue = curve.GetParameter(variable);
bestValuePos = i;
+ LogB.Information(string.Format("bestValue: {0}; bestValuePos: {1}",
bestValue, bestValuePos));
}
i++;
@@ -495,6 +500,84 @@ 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)
+ {
+ //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;
+
+ 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
+ ((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;
+
+ 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
+ ((EncoderCurve) curvesCopy[posOfBest]).ZeroAll();
+ ((EncoderCurve) curvesCopy[posOfBest+1]).ZeroAll();
+ }
+
+ posOfBest = es.FindPosOfBestEccCon(start, variable);
+ listOfPos.Add(posOfBest);
+ count ++;
+ }
+ return listOfPos;
+ }
+
+
+
public double GetEccConMean(int eccPos, string variable)
{
return(
diff --git a/src/gui/encoder.cs b/src/gui/encoder.cs
index f31bf1af..dc9663fc 100644
--- a/src/gui/encoder.cs
+++ b/src/gui/encoder.cs
@@ -4179,6 +4179,10 @@ public partial class ChronoJumpWindow
encoderCaptureSaveCurvesAllNoneBest(Constants.EncoderAutoSaveCurve.BEST,
Constants.GetEncoderVariablesCapture(preferences.encoderCaptureMainVariable));
}
+ void on_button_encoder_capture_curves_best_n_clicked (object o, EventArgs args) {
+ encoderCaptureSaveCurvesAllNoneBest(Constants.EncoderAutoSaveCurve.BESTN,
+ Constants.GetEncoderVariablesCapture(preferences.encoderCaptureMainVariable));
+ }
void on_button_encoder_capture_curves_none_clicked (object o, EventArgs args) {
encoderCaptureSaveCurvesAllNoneBest(Constants.EncoderAutoSaveCurve.NONE,
Constants.GetEncoderVariablesCapture(preferences.encoderCaptureMainVariable));
diff --git a/src/gui/encoderTreeviews.cs b/src/gui/encoderTreeviews.cs
index a3602f7c..57f53b08 100644
--- a/src/gui/encoderTreeviews.cs
+++ b/src/gui/encoderTreeviews.cs
@@ -356,6 +356,7 @@ public partial class ChronoJumpWindow
{
int bestRow = 0;
int numRows = 0;
+ List<int> list_bestN = new List<int>();
int inertialStart = 0;
if( current_menuitem_mode == Constants.Menuitem_modes.POWERINERTIAL)
@@ -366,20 +367,24 @@ public partial class ChronoJumpWindow
inertialStart = 2 * preferences.encoderCaptureInertialDiscardFirstN;
}
- if(saveOption == Constants.EncoderAutoSaveCurve.BEST || saveOption ==
Constants.EncoderAutoSaveCurve.FROM4TOPENULTIMATE) {
+ if(saveOption == Constants.EncoderAutoSaveCurve.BEST ||
+ saveOption == Constants.EncoderAutoSaveCurve.FROM4TOPENULTIMATE ||
+ saveOption == Constants.EncoderAutoSaveCurve.BESTN)
+ {
if(ecconLast == "c") {
//get the concentric curves
EncoderSignal encoderSignal = new
EncoderSignal(treeviewEncoderCaptureCurvesGetCurves(AllEccCon.CON));
- bestRow = encoderSignal.FindPosOfBest(inertialStart, mainVariable);
- numRows = encoderSignal.CurvesNum();
+ bestRow = encoderSignal.FindPosOfBest(inertialStart, mainVariable);
//this for BEST
+ numRows = encoderSignal.CurvesNum();
//this for FROM4TOPENULTIMATE
+ list_bestN = encoderSignal.FindPosOfBestN(inertialStart, mainVariable, 3);
} else {
EncoderSignal encoderSignal = new
EncoderSignal(treeviewEncoderCaptureCurvesGetCurves(AllEccCon.ALL));
- bestRow = encoderSignal.FindPosOfBestEccCon(inertialStart, mainVariable);
//will be pos of the ecc
- numRows = encoderSignal.CurvesNum();
+ 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);
}
}
-
int i = 0; //on "c" and ! "c": i is every row
string sep = "";
string messageRows = "";
@@ -417,8 +422,10 @@ public partial class ChronoJumpWindow
if(
(! curve.Record && ! thisRowDiscarded && saveOption ==
Constants.EncoderAutoSaveCurve.ALL) ||
(! curve.Record && ! thisRowDiscarded && saveOption ==
Constants.EncoderAutoSaveCurve.BEST && i == bestRow) ||
+ (! curve.Record && ! thisRowDiscarded && saveOption ==
Constants.EncoderAutoSaveCurve.BESTN && Util.FoundInListInt(list_bestN, i)) ||
(! curve.Record && ! thisRowDiscarded && saveOption ==
Constants.EncoderAutoSaveCurve.FROM4TOPENULTIMATE && fromValidToPenult) ||
(curve.Record && (thisRowDiscarded || saveOption ==
Constants.EncoderAutoSaveCurve.BEST && i != bestRow)) ||
+ (curve.Record && (thisRowDiscarded || saveOption ==
Constants.EncoderAutoSaveCurve.BESTN && ! Util.FoundInListInt(list_bestN, i))) ||
(curve.Record && (thisRowDiscarded || saveOption ==
Constants.EncoderAutoSaveCurve.NONE)) ||
(curve.Record && (thisRowDiscarded || saveOption ==
Constants.EncoderAutoSaveCurve.FROM4TOPENULTIMATE && ! fromValidToPenult)) )
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]