[chronojump] ForceSensor: Implemented get max avg force in window



commit f32cc853dbcb1dd8e0ae595964aa70effe25c3e8
Author: Xavier de Blas <xaviblas gmail com>
Date:   Thu Feb 11 13:54:22 2021 +0100

    ForceSensor: Implemented get max avg force in window

 glade/app1.glade                   | 83 ++++++++++++++++++++++++++++++++------
 src/forceSensor.cs                 | 48 ++++++++++++++++++++++
 src/gui/app1/forceSensorAnalyze.cs |  7 ++++
 3 files changed, 125 insertions(+), 13 deletions(-)
---
diff --git a/glade/app1.glade b/glade/app1.glade
index 9e2c6ac6..6009dae9 100644
--- a/glade/app1.glade
+++ b/glade/app1.glade
@@ -23838,6 +23838,9 @@ Concentric</property>
                                                             <child>
                                                             <placeholder/>
                                                             </child>
+                                                            <child>
+                                                            <placeholder/>
+                                                            </child>
                                                             </widget>
                                                             <packing>
                                                             <property name="expand">False</property>
@@ -23848,7 +23851,7 @@ Concentric</property>
                                                             <child>
                                                             <widget class="GtkTable" 
id="table_force_sensor_ai_impulse_variability_and_feedback">
                                                             <property name="can_focus">False</property>
-                                                            <property name="n_rows">3</property>
+                                                            <property name="n_rows">4</property>
                                                             <property name="n_columns">2</property>
                                                             <property name="column_spacing">12</property>
                                                             <property name="row_spacing">6</property>
@@ -24022,6 +24025,57 @@ Concentric</property>
                                                             <property name="y_options">GTK_FILL</property>
                                                             </packing>
                                                             </child>
+                                                            <child>
+                                                            <widget class="GtkLabel" 
id="label_force_sensor_ai_max_avg_in_window">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">False</property>
+                                                            <property name="xalign">0</property>
+                                                            <property name="label">Max AVG Force in 
1s</property>
+                                                            </widget>
+                                                            <packing>
+                                                            <property name="top_attach">3</property>
+                                                            <property name="bottom_attach">4</property>
+                                                            <property name="x_options">GTK_FILL</property>
+                                                            <property name="y_options">GTK_FILL</property>
+                                                            </packing>
+                                                            </child>
+                                                            <child>
+                                                            <widget class="GtkHBox" 
id="hbox_force_sensor_ai_max_avg_in_window">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">False</property>
+                                                            <property name="spacing">6</property>
+                                                            <child>
+                                                            <widget class="GtkLabel" 
id="label_force_sensor_ai_max_avg_in_window_values">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">False</property>
+                                                            </widget>
+                                                            <packing>
+                                                            <property name="expand">False</property>
+                                                            <property name="fill">False</property>
+                                                            <property name="position">0</property>
+                                                            </packing>
+                                                            </child>
+                                                            <child>
+                                                            <widget class="GtkLabel" id="label595">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">False</property>
+                                                            <property name="label">N</property>
+                                                            </widget>
+                                                            <packing>
+                                                            <property name="expand">False</property>
+                                                            <property name="fill">False</property>
+                                                            <property name="position">1</property>
+                                                            </packing>
+                                                            </child>
+                                                            </widget>
+                                                            <packing>
+                                                            <property name="left_attach">1</property>
+                                                            <property name="right_attach">2</property>
+                                                            <property name="top_attach">3</property>
+                                                            <property name="bottom_attach">4</property>
+                                                            <property name="y_options">GTK_FILL</property>
+                                                            </packing>
+                                                            </child>
                                                             </widget>
                                                             <packing>
                                                             <property name="expand">False</property>
@@ -28939,6 +28993,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>
@@ -28975,18 +29041,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>
@@ -37281,6 +37335,9 @@ then click this button.</property>
                                                             <child>
                                                             <placeholder/>
                                                             </child>
+                                                            <child>
+                                                            <placeholder/>
+                                                            </child>
                                                             </widget>
                                                             <packing>
                                                             <property name="expand">False</property>
diff --git a/src/forceSensor.cs b/src/forceSensor.cs
index 71bf7e4d..a1db5ec7 100644
--- a/src/forceSensor.cs
+++ b/src/forceSensor.cs
@@ -938,6 +938,51 @@ public class ForceSensorCapturePoints
 
                avg = sum / ((countB - countA) +1);
        }
+
+       public void GetMaxAverageForceInWindow (int countA, int countB, double windowSeconds, out double 
avgMax, out string error)
+       {
+//TODO: remember to store the result and countA and countB somewhere to not calculate it again everytime 
window refreshes or mouse is move. Same for other methods
+
+               double timeA = GetTimeAtCount(countA);
+               
+               if(GetTimeAtCount(countB) - timeA <= 1000000 * windowSeconds)
+               {
+                       avgMax = 0;
+                       error = "Need more time";
+                       return;
+               }
+
+               avgMax = 0;
+               error = "";
+
+               double sum = 0;
+               int count = 0;
+
+               //note if countB - countA < 1s then can have higher values than all the set
+               // 1) get the first second (or whatever in windowSeconds)
+               int i;
+               for(i = countA; i <= countB && GetTimeAtCount(i) - timeA <= 1000000 * windowSeconds; i ++)
+               {
+                       sum += forces[i];
+                       count ++;
+                       avgMax = sum / count;
+               }
+               LogB.Information(string.Format("avgMax 1st for: {0}", avgMax));
+               //note "count" has the window size in samples
+
+               // 2) continue until the end
+               for(int j = i+1; j < countB; j ++)
+               {
+                       sum -= forces[j - count];
+                       sum += forces[j];
+
+                       double avg = sum / count;
+                       if(avg > avgMax)
+                               avgMax = avg;
+               }
+               LogB.Information(string.Format("Average max force in {0} seconds: {1}", windowSeconds, 
avgMax));
+       }
+
        public double GetRFD(int countA, int countB)
        {
                double calc = (forces[countB] - forces[countA]) / (times[countB]/1000000.0 - 
times[countA]/1000000.0); //microsec to sec
@@ -1671,6 +1716,8 @@ public class ForceSensorAnalyzeInstant
        public double AccelMAX;
        public double PowerAVG;
        public double PowerMAX;
+       public double ForceMaxAvgInWindow;
+       public string ForceMaxAvgInWindowError; //if there is any error
 
        //for elastic
        public bool CalculedElasticPSAP;
@@ -1972,6 +2019,7 @@ public class ForceSensorAnalyzeInstant
                }
 
                fscAIPoints.GetAverageAndMaxForce(countA, countB, out ForceAVG, out ForceMAX);
+               fscAIPoints.GetMaxAverageForceInWindow (countA, countB, 1, out ForceMaxAvgInWindow, out 
ForceMaxAvgInWindowError);
 
                if(CalculedElasticPSAP)
                {
diff --git a/src/gui/app1/forceSensorAnalyze.cs b/src/gui/app1/forceSensorAnalyze.cs
index 95f43130..eadfa986 100644
--- a/src/gui/app1/forceSensorAnalyze.cs
+++ b/src/gui/app1/forceSensorAnalyze.cs
@@ -687,6 +687,7 @@ public partial class ChronoJumpWindow
        [Widget] Gtk.Label label_force_sensor_ai_rfd_diff;
        [Widget] Gtk.Label label_force_sensor_ai_rfd_average;
        [Widget] Gtk.Label label_force_sensor_ai_rfd_max;
+       [Widget] Gtk.Label label_force_sensor_ai_max_avg_in_window_values;
 
        ForceSensorAnalyzeInstant fsAI;
 
@@ -1912,9 +1913,15 @@ public partial class ChronoJumpWindow
                        if(countA != countB) {
                                label_force_sensor_ai_force_average.Text = Math.Round(fsAI.ForceAVG, 
1).ToString();
                                label_force_sensor_ai_force_max.Text = Math.Round(fsAI.ForceMAX, 
1).ToString();
+
+                               if(fsAI.ForceMaxAvgInWindowError == "")
+                                       label_force_sensor_ai_max_avg_in_window_values.Text = 
Math.Round(fsAI.ForceMaxAvgInWindow, 1).ToString();
+                               else
+                                       label_force_sensor_ai_max_avg_in_window_values.Text = "----";
                        } else {
                                label_force_sensor_ai_force_average.Text = "";
                                label_force_sensor_ai_force_max.Text = "";
+                               label_force_sensor_ai_max_avg_in_window_values.Text = "";
                        }
                }
 


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