[chronojump] encoder: Done recalculate, improved curves



commit d5de32dcd64a66c099dd542a65a85c81c71ebd7a
Author: Xavier de Blas <xaviblas gmail com>
Date:   Sat Mar 31 03:26:29 2012 +0800

    encoder: Done recalculate, improved curves

 encoder/graph.R           |   22 +++++++++++-----------
 encoder/pyserial_pyper.py |    3 +--
 glade/chronojump.glade    |    1 +
 src/encoder.cs            |    6 +++---
 src/gui/encoder.cs        |   34 +++++++++++++++++++++++++---------
 5 files changed, 41 insertions(+), 25 deletions(-)
---
diff --git a/encoder/graph.R b/encoder/graph.R
index 775b105..66c75a3 100644
--- a/encoder/graph.R
+++ b/encoder/graph.R
@@ -49,12 +49,6 @@ findCurves <- function(rawdata, eccon, min_height, draw) {
 	if(draw) {
 		plot(a,type="l",xlim=c(1,length(a)),xlab="",ylab="",axes=T)
 		abline(v=b$maxindex,lty=3); abline(v=b$minindex,lty=3)
-		if(eccon=="c") 
-			segments(x0=start,y0=min(a),x1=end,y1=min(a),col="red")
-		else
-			arrows(x0=start,y0=min(a),x1=end,y1=min(a),col="red",code=3)
-		for(i in 1:length(start)) 
-			text(x=(start[i]+end[i])/2,y=min(a),labels=i, adj=c(0.5,0),cex=1,col="red")
 	}
 	return(as.data.frame(cbind(start,end,startH)))
 }
@@ -361,16 +355,22 @@ if(length(args) < 3) {
 		titleType="jump"
 	
 	curvesPlot = FALSE
-	if(analysis=="curves") 
+	if(analysis=="curves") {
 		curvesPlot = TRUE
+		par(mar=c(1,2.5,1,1))
+	}
 	curves=findCurves(rawdata, eccon, minHeight, curvesPlot)
 	n=length(curves[,1])
 	for(i in 1:n) { 
-		if(eccon=="c") {
+		if(eccon=="c") 
 			curves[i,1]=reduceCurveBySpeed(curves[i,1],rawdata[curves[i,1]:curves[i,2]], smoothingAll)
-			if(curvesPlot)
-				abline(v=curves[i,1],col="red")
-		}
+	}
+	if(curvesPlot) {
+		rawdata.cumsum=cumsum(rawdata)
+		arrows(x0=curves[,1],y0=min(rawdata.cumsum),x1=curves[,2],y1=min(rawdata.cumsum),
+				col="red",code=3,length=0.1)
+		for(i in 1:length(curves[,1])) 
+			text(x=(curves[i,1]+curves[i,2])/2,y=min(rawdata.cumsum),labels=i, adj=c(0.5,0),cex=1,col="red")
 	}
 
 	print(curves)
diff --git a/encoder/pyserial_pyper.py b/encoder/pyserial_pyper.py
index 0178d32..e655e3d 100644
--- a/encoder/pyserial_pyper.py
+++ b/encoder/pyserial_pyper.py
@@ -133,8 +133,7 @@ def calculate_all_in_r(temp, top_values, bottom_values, direction_now, smoothing
 		if(meanPower > 3500): colPower = REDINV
 		else: colPower = RED
 			
-		print phaseCol + "%6i," % phaseRange + colorize(meanSpeedCol,colSpeed,TRUE) + "%9.2f," % maxSpeed + 
-		colorize(meanPowerCol,colPower,TRUE) + "%10.2f," % peakPower + "%11i" % peakPowerT
+		print phaseCol + "%6i," % phaseRange + colorize(meanSpeedCol,colSpeed,TRUE) + "%9.2f," % maxSpeed + colorize(meanPowerCol,colPower,TRUE) + "%10.2f," % peakPower + "%11i" % peakPowerT
 
 
 def calculate_range(temp_cumsum, top_values, bottom_values, direction_now):
diff --git a/glade/chronojump.glade b/glade/chronojump.glade
index 59bb33f..d69d1a1 100644
--- a/glade/chronojump.glade
+++ b/glade/chronojump.glade
@@ -23222,6 +23222,7 @@ on current Chronojump version.</property>
                                                         <property name="can_default">True</property>
                                                         <property name="receives_default">True</property>
                                                         <property name="use_underline">True</property>
+                                                        <signal name="clicked" handler="on_button_encoder_recalculate_clicked"/>
                                                       </widget>
                                                       <packing>
                                                         <property name="expand">False</property>
diff --git a/src/encoder.cs b/src/encoder.cs
index 0c921b5..209040c 100644
--- a/src/encoder.cs
+++ b/src/encoder.cs
@@ -27,7 +27,7 @@ using Mono.Unix;
 public class EncoderParams
 {
 	private int time;
-	private double mass;
+	private string mass; //to pass always as "." to R
 
 	private int minHeight;
 	private bool isJump;
@@ -38,7 +38,7 @@ public class EncoderParams
 	private int width;
 	private int height;
 	
-	public EncoderParams(int time, double mass, string smooth)
+	public EncoderParams(int time, string mass, string smooth)
 	{
 		this.time = time;
 		this.mass = mass;
@@ -50,7 +50,7 @@ public class EncoderParams
 		return time.ToString() + " " + mass.ToString() + " " + smooth;
 	}
 	
-	public EncoderParams(int minHeight, bool isJump, double mass, string contractionEC, 
+	public EncoderParams(int minHeight, bool isJump, string mass, string contractionEC, 
 			string analysis, string smooth, int curve, int width, int height)
 	{
 		this.minHeight = minHeight;
diff --git a/src/gui/encoder.cs b/src/gui/encoder.cs
index 58224c7..658c506 100644
--- a/src/gui/encoder.cs
+++ b/src/gui/encoder.cs
@@ -57,6 +57,8 @@ public partial class ChronoJumpWindow
 	//TODO: que el curve no pugui ser mes alt de actual numero de curves, per tant s'ha de retornar algun valor. ha de canviar cada cop que hi ha un capture o recalculate
 
 	//TODO: campanes a l'encoder pq mostri colors i sons en funcio del que passa
+	//TODO:recording time a main options (entre weights i smoothing)
+	//TODO: curves amb par mar mes gran
 	
 	public void on_radiobutton_encoder_capture_bar_toggled (object obj, EventArgs args) {
 		spin_encoder_bar_limit.Sensitive = true;
@@ -73,16 +75,11 @@ public partial class ChronoJumpWindow
 		//TODO: que surti barra de progres de calculando... despres de capturar i boto de cerrar automatico
 		//TODO: i mostrar valors des de la gui (potser a zona dreta damunt del zoom)
 		
-		double mass = 0;
-		if(radiobutton_encoder_capture_bar.Active)
-			mass = spin_encoder_bar_limit.Value;
-		else
-			mass = Convert.ToDouble(label_encoder_person_weight.Text) + spin_encoder_jump_limit.Value;
 
 		//capture data
 		EncoderParams ep = new EncoderParams(
 				(int) spin_encoder_capture_time.Value, 
-				mass,
+				findMass(),
 				Util.ConvertToPoint((double) spin_encoder_analyze_smooth.Value)); //R decimal: '.'
 
 		EncoderStruct es = new EncoderStruct(
@@ -92,7 +89,16 @@ public partial class ChronoJumpWindow
 
 		Util.RunPythonEncoder(Constants.EncoderScriptCapture, es, true);
 
+		makeCurvesGraph();
+	}
+	
+	void on_button_encoder_recalculate_clicked (object o, EventArgs args) 
+	{
+		makeCurvesGraph();
+	}
 
+	private void makeCurvesGraph() 
+	{
 		if(radiobutton_encoder_concentric.Active)
 			encoderEC = "c";
 		else
@@ -102,14 +108,14 @@ public partial class ChronoJumpWindow
 		int w = UtilGtk.WidgetWidth(viewport_image_encoder_capture)-2; //image is inside (is smaller than) viewport
 		int h = UtilGtk.WidgetHeight(viewport_image_encoder_capture)-2;
 
-		ep = new EncoderParams(
+		EncoderParams ep = new EncoderParams(
 				(int) spin_encoder_capture_min_height.Value, 
 				false,			//isJump (1st) is not used in "curves"
-				mass,
+				findMass(),
 				encoderEC, "curves",
 				"0", 0, w, h); 		//smoothOne, and curve are not used in "curves"
 
-		es = new EncoderStruct(
+		EncoderStruct es = new EncoderStruct(
 				Util.GetEncoderDataTempFileName(), 
 				Util.GetEncoderGraphTempFileName(),
 				"NULL", "NULL", ep);		//no data ouptut
@@ -119,7 +125,17 @@ public partial class ChronoJumpWindow
 		Pixbuf pixbuf = new Pixbuf (Util.GetEncoderGraphTempFileName()); //from a file
 		image_encoder_capture.Pixbuf = pixbuf;
 	}
+	
+	private string findMass() {
+		double mass = 0;
+		if(radiobutton_encoder_capture_bar.Active)
+			mass = spin_encoder_bar_limit.Value;
+		else
+			mass = Convert.ToDouble(label_encoder_person_weight.Text) + spin_encoder_jump_limit.Value;
 
+		return Util.ConvertToPoint(mass); //R decimal: '.'
+	}
+	
 	//show curve_num only on simple and superpose
 	public void on_radiobutton_encoder_analyze_single_toggled (object obj, EventArgs args) {
 		label_encoder_analyze_curve_num.Sensitive=true;



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