[chronojump] Added encoder curves treeview. TODO: fix power data



commit 59e71cd959a4010e06cf7c7376e82d844a12b7ad
Author: Xavier de Blas <xaviblas gmail com>
Date:   Sat Mar 31 14:21:26 2012 +0800

    Added encoder curves treeview. TODO: fix power data

 encoder/graph.R           |   33 ++++++----
 encoder/pyserial_pyper.py |   14 +++--
 glade/chronojump.glade    |  135 +++++++++++++++++++++-------------------
 src/encoder.cs            |   14 ++--
 src/gui/chronojump.cs     |    2 +
 src/gui/encoder.cs        |  152 ++++++++++++++++++++++++++++++++------------
 src/util.cs               |   15 +++++
 7 files changed, 233 insertions(+), 132 deletions(-)
---
diff --git a/encoder/graph.R b/encoder/graph.R
index 66c75a3..f956326 100644
--- a/encoder/graph.R
+++ b/encoder/graph.R
@@ -68,7 +68,7 @@ reduceCurveBySpeed <- function(startT, rawdata, smoothing) {
 }
 
 #go here with every single jump
-kinematics <- function(a, mass, g) {
+kinematicsF <- function(a, mass, g) {
 	speed <- smooth.spline( 1:length(a), a, spar=smoothingOne)
 	accel <- predict( speed, deriv=1 )
 	accel$y <- accel$y * 1000 #input data is in mm, conversion to m
@@ -82,19 +82,19 @@ kinematics <- function(a, mass, g) {
 }
 
 powerBars <- function(kinematics) {
-	#meanSpeed <- mean(abs(kinematics$speedy))
-	#maxSpeed <- max(abs(kinematics$speedy))
+	meanSpeed <- mean(abs(kinematics$speedy))
+	maxSpeed <- max(abs(kinematics$speedy))
 	meanPower <- mean(abs(kinematics$power))
 	peakPower <- max(kinematics$power)
 	peakPowerT <- which(kinematics$power == peakPower)
-	return(data.frame(meanPower,peakPower,peakPowerT))
+	return(data.frame(meanSpeed, maxSpeed, meanPower,peakPower,peakPowerT))
 }
 
 kinematicRanges <- function(rawdata,curves,mass,g) {
 	n=length(curves[,1])
 	maxSpeedy=0;maxForce=0;maxPower=0
 	for(i in 1:n) { 
-		kn=kinematics(rawdata[curves[i,1]:curves[i,2]],mass,g)
+		kn=kinematicsF(rawdata[curves[i,1]:curves[i,2]],mass,g)
 		if(max(abs(kn$speedy)) > maxSpeedy)
 			maxSpeedy = max(abs(kn$speedy))
 		if(max(abs(kn$force)) > maxForce)
@@ -299,13 +299,13 @@ paint <- function(rawdata, eccon, xmin, xmax, yrange, knRanges, superpose, highl
 
 paintPowerPeakPowerBars <- function(paf) {
 	pafColors=c("tomato1","tomato4",topo.colors(10)[3])
-	bp <- barplot(rbind(paf[,1],paf[,2]),beside=T,col=pafColors[1:2],width=c(1.4,.6),
+	bp <- barplot(rbind(paf[,3],paf[,4]),beside=T,col=pafColors[1:2],width=c(1.4,.6),
 			names.arg=1:n,xlim=c(1,n*3+.5),xlab="",ylab="Power (W)")
 	par(new=T)
-	plot(bp[2,],paf[,3],type="o",lwd=2,xlim=c(1,n*3+.5),axes=F,xlab="",ylab="",col=pafColors[3])
+	plot(bp[2,],paf[,5],type="o",lwd=2,xlim=c(1,n*3+.5),axes=F,xlab="",ylab="",col=pafColors[3])
 	legend("bottomleft",col=pafColors, lty=c(0,0,1), lwd=c(1,1,2), pch=c(15,15,NA), legend=c("Power","Peak Power", "Time at Peak Power"))
 	axis(4)
-	mtext("time at peak power (s)", side=4, line=3)
+	mtext("time at peak power (s)", side=4, line=-1)
 }
 		
 find.mfrow <- function(n) {
@@ -349,6 +349,7 @@ if(length(args) < 3) {
 	png(outputGraph, width=width, height=height)
 
 	rawdata=scan(file=file,sep=",")
+	rawdata.cumsum=cumsum(rawdata)
 
 	titleType = "execution"
 	if(isJump)
@@ -357,7 +358,7 @@ if(length(args) < 3) {
 	curvesPlot = FALSE
 	if(analysis=="curves") {
 		curvesPlot = TRUE
-		par(mar=c(1,2.5,1,1))
+		par(mar=c(2,2.5,1,1))
 	}
 	curves=findCurves(rawdata, eccon, minHeight, curvesPlot)
 	n=length(curves[,1])
@@ -366,7 +367,6 @@ if(length(args) < 3) {
 			curves[i,1]=reduceCurveBySpeed(curves[i,1],rawdata[curves[i,1]:curves[i,2]], smoothingAll)
 	}
 	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])) 
@@ -415,12 +415,19 @@ if(length(args) < 3) {
 		par(new=F)
 		print(knRanges)
 	}
-	if(analysis=="powerBars") {
+	if(analysis=="powerBars" || analysis=="curves") {
 		paf = data.frame()
 		for(i in 1:n) { 
-			paf=rbind(paf,(powerBars(kinematics(rawdata[curves[i,1]:curves[i,2]], mass, g))))
+			paf=rbind(paf,(powerBars(kinematicsF(rawdata[curves[i,1]:curves[i,2]], mass, g))))
+		}
+		if(analysis=="powerBars")
+			paintPowerPeakPowerBars(paf)
+		if(analysis=="curves") {
+			paf=cbind(curves[,2]-curves[,1],rawdata.cumsum[curves[,2]]-curves[,3],paf)
+			colnames(paf)=c("width","height","meanSpeed","maxSpeed","meanPower","peakPower","peakPowerT")
+			print(paf)
+			write.csv(paf, outputData1)
 		}
-		paintPowerPeakPowerBars(paf)
 	}
 	if(analysis=="others") {
 		#revisar amb ec-con
diff --git a/encoder/pyserial_pyper.py b/encoder/pyserial_pyper.py
index e655e3d..b816d73 100644
--- a/encoder/pyserial_pyper.py
+++ b/encoder/pyserial_pyper.py
@@ -31,9 +31,10 @@ outputFile = sys.argv[1]
 record_time = int(sys.argv[2])*1000		#from s to ms
 mass = float(sys.argv[3])
 smoothingOne = float(sys.argv[4])
+eccon = sys.argv[5]				#contraction "ec" or "c"
 
 delete_initial_time = 20			#delete first records because there's encoder bug
-#w_baudrate = 9600                           # Setting the baudrate of Chronopic(115200)
+#w_baudrate = 9600                           # Setting the baudrate of Chronopic(9600)
 w_baudrate = 115200                           # Setting the baudrate of Chronopic(115200)
 #w_serial_port = 4                           # Setting the serial port (Windows), windows's device number need minus 1
 w_serial_port = "/dev/ttyUSB0"             # Setting the serial port (Linux)
@@ -92,7 +93,7 @@ def colorize(text, color, bold):
 	return ESCAPE + (FORMAT % (color, )) + text + RESET
 
 
-def calculate_all_in_r(temp, top_values, bottom_values, direction_now, smoothingOne):
+def calculate_all_in_r(temp, top_values, bottom_values, direction_now, smoothingOne, eccon):
 	if (len(top_values)>0 and len(bottom_values)>0):
 		if direction_now == 1:
 			start=top_values[len(top_values)-1]
@@ -132,8 +133,9 @@ def calculate_all_in_r(temp, top_values, bottom_values, direction_now, smoothing
 		else: colSpeed = GREEN
 		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
+		
+		if eccon == "ec" or direction_now == -1:
+			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):
@@ -224,7 +226,7 @@ if __name__ == '__main__':
 				phase = 0
 				speed = 0
 	
-				if(direction_now == 1):
+				if direction_now == 1:
 					#we are going up, we passed the ditection_change_count
 					#then we can record the bottom moment
 					#and print speed on going down
@@ -246,7 +248,7 @@ if __name__ == '__main__':
 
 				if len(frames_pull_top1)>0 and len(frames_push_bottom1)>0:
 					calculate_all_in_r(temp, frames_pull_top1, frames_push_bottom1, 
-							direction_now, smoothingOne)
+							direction_now, smoothingOne, eccon)
 	
 				file.write(''+','.join([str(i) for i in temp[
 					previous_frame_change:new_frame_change
diff --git a/glade/chronojump.glade b/glade/chronojump.glade
index d69d1a1..61bae90 100644
--- a/glade/chronojump.glade
+++ b/glade/chronojump.glade
@@ -14506,6 +14506,63 @@ Chronopic</property>
                                               </packing>
                                             </child>
                                             <child>
+                                              <widget class="GtkHBox" id="hbox87">
+                                                <property name="visible">True</property>
+                                                <property name="spacing">8</property>
+                                                <child>
+                                                  <widget class="GtkLabel" id="label82">
+                                                    <property name="visible">True</property>
+                                                    <property name="xalign">0</property>
+                                                    <property name="label" translatable="yes">Recording time</property>
+                                                  </widget>
+                                                  <packing>
+                                                    <property name="position">0</property>
+                                                  </packing>
+                                                </child>
+                                                <child>
+                                                  <widget class="GtkHBox" id="hbox74">
+                                                    <property name="visible">True</property>
+                                                    <property name="spacing">4</property>
+                                                    <child>
+                                                      <widget class="GtkSpinButton" id="spin_encoder_capture_time">
+                                                        <property name="visible">True</property>
+                                                        <property name="can_focus">True</property>
+                                                        <property name="invisible_char">â</property>
+                                                        <property name="adjustment">10 5 99 1 10 0</property>
+                                                        <property name="climb_rate">1</property>
+                                                        <property name="snap_to_ticks">True</property>
+                                                        <property name="numeric">True</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="label84">
+                                                        <property name="visible">True</property>
+                                                        <property name="xalign">1</property>
+                                                        <property name="label" translatable="yes">s</property>
+                                                      </widget>
+                                                      <packing>
+                                                        <property name="expand">False</property>
+                                                        <property name="fill">False</property>
+                                                        <property name="position">1</property>
+                                                      </packing>
+                                                    </child>
+                                                  </widget>
+                                                  <packing>
+                                                    <property name="position">1</property>
+                                                  </packing>
+                                                </child>
+                                              </widget>
+                                              <packing>
+                                                <property name="expand">False</property>
+                                                <property name="position">2</property>
+                                              </packing>
+                                            </child>
+                                            <child>
                                               <widget class="GtkHBox" id="hbox86">
                                                 <property name="visible">True</property>
                                                 <property name="spacing">8</property>
@@ -14513,7 +14570,7 @@ Chronopic</property>
                                                   <widget class="GtkLabel" id="label85">
                                                     <property name="visible">True</property>
                                                     <property name="xalign">0</property>
-                                                    <property name="label" translatable="yes">Smoothing factor</property>
+                                                    <property name="label" translatable="yes">Smoothing</property>
                                                   </widget>
                                                   <packing>
                                                     <property name="expand">False</property>
@@ -14541,7 +14598,7 @@ Chronopic</property>
                                               <packing>
                                                 <property name="expand">False</property>
                                                 <property name="fill">False</property>
-                                                <property name="position">2</property>
+                                                <property name="position">3</property>
                                               </packing>
                                             </child>
                                           </widget>
@@ -22973,7 +23030,7 @@ on current Chronojump version.</property>
                                                             <child>
                                                             <widget class="GtkHBox" id="hbox89">
                                                             <property name="visible">True</property>
-                                                            <property name="spacing">4</property>
+                                                            <property name="spacing">12</property>
                                                             <child>
                                                             <widget class="GtkRadioButton" id="radiobutton_encoder_concentric">
                                                             <property name="label" translatable="yes">Concentric</property>
@@ -22984,6 +23041,7 @@ on current Chronojump version.</property>
                                                             <property name="draw_indicator">True</property>
                                                             </widget>
                                                             <packing>
+                                                            <property name="expand">False</property>
                                                             <property name="position">0</property>
                                                             </packing>
                                                             </child>
@@ -22998,63 +23056,19 @@ on current Chronojump version.</property>
                                                             <property name="group">radiobutton_encoder_concentric</property>
                                                             </widget>
                                                             <packing>
-                                                            <property name="position">1</property>
-                                                            </packing>
-                                                            </child>
-                                                            </widget>
-                                                            <packing>
-                                                            <property name="position">0</property>
-                                                            </packing>
-                                                            </child>
-                                                            <child>
-                                                            <widget class="GtkVSeparator" id="vseparator3">
-                                                            <property name="visible">True</property>
-                                                            </widget>
-                                                            <packing>
                                                             <property name="expand">False</property>
-                                                            <property name="fill">False</property>
                                                             <property name="position">1</property>
                                                             </packing>
                                                             </child>
-                                                            <child>
-                                                            <widget class="GtkHBox" id="hbox87">
-                                                            <property name="visible">True</property>
-                                                            <property name="spacing">4</property>
-                                                            <child>
-                                                            <widget class="GtkLabel" id="label82">
-                                                            <property name="visible">True</property>
-                                                            <property name="xalign">0</property>
-                                                            <property name="label" translatable="yes">Recording time</property>
-                                                            </widget>
-                                                            <packing>
-                                                            <property name="position">0</property>
-                                                            </packing>
-                                                            </child>
-                                                            <child>
-                                                            <widget class="GtkHBox" id="hbox74">
-                                                            <property name="visible">True</property>
-                                                            <property name="spacing">4</property>
-                                                            <child>
-                                                            <widget class="GtkSpinButton" id="spin_encoder_capture_time">
-                                                            <property name="visible">True</property>
-                                                            <property name="can_focus">True</property>
-                                                            <property name="invisible_char">â</property>
-                                                            <property name="adjustment">10 5 99 1 10 0</property>
-                                                            <property name="climb_rate">1</property>
-                                                            <property name="snap_to_ticks">True</property>
-                                                            <property name="numeric">True</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="label84">
+                                                            <widget class="GtkVSeparator" id="vseparator3">
                                                             <property name="visible">True</property>
-                                                            <property name="xalign">1</property>
-                                                            <property name="label" translatable="yes">s</property>
                                                             </widget>
                                                             <packing>
                                                             <property name="expand">False</property>
@@ -23062,20 +23076,10 @@ on current Chronojump version.</property>
                                                             <property name="position">1</property>
                                                             </packing>
                                                             </child>
-                                                            </widget>
-                                                            <packing>
-                                                            <property name="position">1</property>
-                                                            </packing>
-                                                            </child>
-                                                            </widget>
-                                                            <packing>
-                                                            <property name="position">2</property>
-                                                            </packing>
-                                                            </child>
                                                             <child>
                                                             <widget class="GtkHBox" id="hbox88">
                                                             <property name="visible">True</property>
-                                                            <property name="spacing">4</property>
+                                                            <property name="spacing">8</property>
                                                             <child>
                                                             <widget class="GtkLabel" id="label78">
                                                             <property name="visible">True</property>
@@ -23125,7 +23129,8 @@ on current Chronojump version.</property>
                                                             </child>
                                                             </widget>
                                                             <packing>
-                                                            <property name="position">3</property>
+                                                            <property name="expand">False</property>
+                                                            <property name="position">2</property>
                                                             </packing>
                                                             </child>
                                                             <child>
@@ -23170,7 +23175,8 @@ on current Chronojump version.</property>
                                                             </child>
                                                             </widget>
                                                             <packing>
-                                                            <property name="position">4</property>
+                                                            <property name="expand">False</property>
+                                                            <property name="position">3</property>
                                                             </packing>
                                                             </child>
                                                           </widget>
@@ -23256,7 +23262,7 @@ on current Chronojump version.</property>
                                                     <property name="vscrollbar_policy">automatic</property>
                                                     <property name="shadow_type">etched-in</property>
                                                     <child>
-                                                      <widget class="GtkTreeView" id="treeview_jumps1">
+                                                      <widget class="GtkTreeView" id="treeview_encoder_curves">
                                                         <property name="visible">True</property>
                                                         <property name="can_focus">True</property>
                                                         <property name="rules_hint">True</property>
@@ -23306,7 +23312,7 @@ on current Chronojump version.</property>
                                                           </widget>
                                                           <packing>
                                                             <property name="expand">False</property>
-                                                            <property name="fill">False</property>
+                                                            <property name="pack_type">end</property>
                                                             <property name="position">2</property>
                                                           </packing>
                                                         </child>
@@ -23327,7 +23333,6 @@ on current Chronojump version.</property>
                                                           </widget>
                                                           <packing>
                                                             <property name="expand">False</property>
-                                                            <property name="fill">False</property>
                                                             <property name="pack_type">end</property>
                                                             <property name="position">1</property>
                                                           </packing>
@@ -23335,6 +23340,7 @@ on current Chronojump version.</property>
                                                       </widget>
                                                       <packing>
                                                         <property name="expand">False</property>
+                                                        <property name="pack_type">end</property>
                                                         <property name="position">1</property>
                                                       </packing>
                                                     </child>
@@ -23526,6 +23532,7 @@ on current Chronojump version.</property>
                                                             <signal name="clicked" handler="on_button_encoder_analyze_clicked"/>
                                                             </widget>
                                                             <packing>
+                                                            <property name="expand">False</property>
                                                             <property name="padding">12</property>
                                                             <property name="position">0</property>
                                                             </packing>
diff --git a/src/encoder.cs b/src/encoder.cs
index 209040c..f7d8078 100644
--- a/src/encoder.cs
+++ b/src/encoder.cs
@@ -28,35 +28,35 @@ public class EncoderParams
 {
 	private int time;
 	private string mass; //to pass always as "." to R
-
 	private int minHeight;
 	private bool isJump;
-	private string contractionEC;
+	private string eccon;
 	private string analysis;
 	private string smooth; //to pass always as "." to R
 	private int curve;
 	private int width;
 	private int height;
 	
-	public EncoderParams(int time, string mass, string smooth)
+	public EncoderParams(int time, string mass, string smooth, string eccon)
 	{
 		this.time = time;
 		this.mass = mass;
 		this.smooth = smooth;
+		this.eccon = eccon;
 	}
 	
 	public string ToString1 () 
 	{
-		return time.ToString() + " " + mass.ToString() + " " + smooth;
+		return time.ToString() + " " + mass.ToString() + " " + smooth + " " + eccon;
 	}
 	
-	public EncoderParams(int minHeight, bool isJump, string mass, string contractionEC, 
+	public EncoderParams(int minHeight, bool isJump, string mass, string eccon, 
 			string analysis, string smooth, int curve, int width, int height)
 	{
 		this.minHeight = minHeight;
 		this.isJump = isJump;
 		this.mass = mass;
-		this.contractionEC = contractionEC;
+		this.eccon = eccon;
 		this.analysis = analysis;
 		this.smooth = smooth;
 		this.curve = curve;
@@ -66,7 +66,7 @@ public class EncoderParams
 	
 	public string ToString2 () 
 	{
-		return minHeight + " " + isJump + " " + mass + " " + contractionEC + " " + analysis + " " + 
+		return minHeight + " " + isJump + " " + mass + " " + eccon + " " + analysis + " " + 
 			smooth + " " + curve + " " + width + " " + height;
 	}
 
diff --git a/src/gui/chronojump.cs b/src/gui/chronojump.cs
index adc201f..310bb55 100644
--- a/src/gui/chronojump.cs
+++ b/src/gui/chronojump.cs
@@ -475,6 +475,8 @@ public partial class ChronoJumpWindow
 		//changeTestImage("", "", "LOGO");
 
 		notebook_main_encoder_and_server_hide();
+		CreateTreeViewEncoder();
+
 		//We have no session, mark some widgets as ".Sensitive = false"
 		sensitiveGuiNoSession();
 		definedSession = false;
diff --git a/src/gui/encoder.cs b/src/gui/encoder.cs
index 658c506..69305ab 100644
--- a/src/gui/encoder.cs
+++ b/src/gui/encoder.cs
@@ -19,6 +19,7 @@
  */
 
 using System;
+using System.IO; 
 using Gtk;
 using Gdk;
 using Glade;
@@ -38,6 +39,7 @@ public partial class ChronoJumpWindow
 	[Widget] Gtk.SpinButton spin_encoder_capture_time;
 	[Widget] Gtk.SpinButton spin_encoder_capture_min_height;
 	[Widget] Gtk.Image image_encoder_capture;
+	[Widget] Gtk.TreeView treeview_encoder_curves;
 	
 	[Widget] Gtk.RadioButton radiobutton_encoder_analyze_powerbars;
 	[Widget] Gtk.RadioButton radiobutton_encoder_analyze_single;
@@ -48,8 +50,8 @@ public partial class ChronoJumpWindow
 	[Widget] Gtk.Viewport viewport_image_encoder_analyze;
 	[Widget] Gtk.Image image_encoder_analyze;
 
+	TreeStore store;
 
-	private string encoderEC="c";	//"c" or "ec"
 	private string encoderAnalysis="powerBars";
 
 //TODO: on capture only show ups if concentric
@@ -57,8 +59,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
+	//TODO: in ec, curves and powerBars have to be different on ec than on c
+	//
 	
 	public void on_radiobutton_encoder_capture_bar_toggled (object obj, EventArgs args) {
 		spin_encoder_bar_limit.Sensitive = true;
@@ -80,7 +82,9 @@ public partial class ChronoJumpWindow
 		EncoderParams ep = new EncoderParams(
 				(int) spin_encoder_capture_time.Value, 
 				findMass(),
-				Util.ConvertToPoint((double) spin_encoder_analyze_smooth.Value)); //R decimal: '.'
+				Util.ConvertToPoint((double) spin_encoder_analyze_smooth.Value), //R decimal: '.'
+				findEccon()
+				); 
 
 		EncoderStruct es = new EncoderStruct(
 				"",					//no data input
@@ -90,20 +94,17 @@ public partial class ChronoJumpWindow
 		Util.RunPythonEncoder(Constants.EncoderScriptCapture, es, true);
 
 		makeCurvesGraph();
+		updateTreeView();
 	}
 	
 	void on_button_encoder_recalculate_clicked (object o, EventArgs args) 
 	{
 		makeCurvesGraph();
+		updateTreeView();
 	}
 
 	private void makeCurvesGraph() 
 	{
-		if(radiobutton_encoder_concentric.Active)
-			encoderEC = "c";
-		else
-			encoderEC = "ec";
-		
 	      	//show curves graph
 		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;
@@ -112,30 +113,48 @@ public partial class ChronoJumpWindow
 				(int) spin_encoder_capture_min_height.Value, 
 				false,			//isJump (1st) is not used in "curves"
 				findMass(),
-				encoderEC, "curves",
+				findEccon(), "curves",
 				"0", 0, w, h); 		//smoothOne, and curve are not used in "curves"
 
 		EncoderStruct es = new EncoderStruct(
 				Util.GetEncoderDataTempFileName(), 
 				Util.GetEncoderGraphTempFileName(),
-				"NULL", "NULL", ep);		//no data ouptut
+				Util.GetEncoderCurvesTempFileName(), 
+				"NULL", ep);
 		
 		Util.RunPythonEncoder(Constants.EncoderScriptGraphCall, es,false);
 
 		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: '.'
+
+	//TODO: garantir path windows	
+	private void on_button_encoder_analyze_clicked (object o, EventArgs args) 
+	{
+		int w = UtilGtk.WidgetWidth(viewport_image_encoder_analyze)-2; //image is inside (is smaller than) viewport
+		int h = UtilGtk.WidgetHeight(viewport_image_encoder_analyze)-2;
+
+		EncoderParams ep = new EncoderParams(
+				(int) spin_encoder_capture_min_height.Value, 
+				!radiobutton_encoder_capture_bar.Active,
+				findMass(),
+				findEccon(), encoderAnalysis,
+				Util.ConvertToPoint((double) spin_encoder_analyze_smooth.Value), //R decimal: '.'
+				(int) spin_encoder_analyze_curve_num.Value, w, h);
+
+		EncoderStruct es = new EncoderStruct(
+				Util.GetEncoderDataTempFileName(), 
+				Util.GetEncoderGraphTempFileName(),
+				"NULL", "NULL", ep);		//no data ouptut
+
+		Util.RunPythonEncoder(Constants.EncoderScriptGraphCall, es, false);
+
+		//TODO pensar en si s'ha de fer 1er amb mida petita i despres amb gran (en el zoom), o si es una sola i fa alguna edicio
+		Pixbuf pixbuf = new Pixbuf (Util.GetEncoderGraphTempFileName()); //from a file
+		image_encoder_analyze.Pixbuf = pixbuf;
 	}
-	
+
 	//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;
@@ -159,42 +178,91 @@ public partial class ChronoJumpWindow
 		encoderAnalysis="powerBars";
 	}
 
-	//TODO: garantir path windows	
-	private void on_button_encoder_analyze_clicked (object o, EventArgs args) 
-	{
+	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: '.'
+	}
+	
+	private string findEccon() {	
 		if(radiobutton_encoder_concentric.Active)
-			encoderEC = "c";
+			return "c";
 		else
-			encoderEC = "ec";
+			return "ec";
+	}
+	
 
-		int w = UtilGtk.WidgetWidth(viewport_image_encoder_analyze)-2; //image is inside (is smaller than) viewport
-		int h = UtilGtk.WidgetHeight(viewport_image_encoder_analyze)-2;
+	/* TreeView stuff */	
 
-		EncoderParams ep = new EncoderParams(
-				(int) spin_encoder_capture_min_height.Value, 
-				!radiobutton_encoder_capture_bar.Active,
-				mass,
-				encoderEC, encoderAnalysis,
-				Util.ConvertToPoint((double) spin_encoder_analyze_smooth.Value), //R decimal: '.'
-				(int) spin_encoder_analyze_curve_num.Value, w, h);
+	public void CreateTreeViewEncoder() {
+		string [] columnsString = {"n","Width","Height","MeanSpeed","MaxSpeed",
+			"MeanPower","PeakPower","PeakPowerT"};
 
-		EncoderStruct es = new EncoderStruct(
-				Util.GetEncoderDataTempFileName(), 
-				Util.GetEncoderGraphTempFileName(),
-				"NULL", "NULL", ep);		//no data ouptut
+		int columns=8;
+		Type [] types = new Type [columns];
+		int i;
+		for (i=0; i < columns; i++) {
+			types[i] = typeof (string);
+		}
+		store = new TreeStore(types);
 
-		Util.RunPythonEncoder(Constants.EncoderScriptGraphCall, es, false);
+		treeview_encoder_curves.Model = store;
+		
+		//prepareHeaders
+		treeview_encoder_curves.HeadersVisible=true;
+		i=0;
+		foreach(string myCol in columnsString) {
+			treeview_encoder_curves.AppendColumn (myCol, new CellRendererText(), "text", i++);
+		}
+	}
+	
+	private void removeColumns() {
+		Gtk.TreeViewColumn [] myColumns = treeview_encoder_curves.Columns;
+		foreach (Gtk.TreeViewColumn column in myColumns) 
+			treeview_encoder_curves.RemoveColumn (column);
+	}
 
-		//TODO pensar en si s'ha de fer 1er amb mida petita i despres amb gran (en el zoom), o si es una sola i fa alguna edicio
-		Pixbuf pixbuf = new Pixbuf (Util.GetEncoderGraphTempFileName()); //from a file
-		image_encoder_analyze.Pixbuf = pixbuf;
+	private void updateTreeView() {
+		removeColumns();
+		CreateTreeViewEncoder();
+		fillTreeView();
 	}
 
+	private void fillTreeView()
+	{
+		TreeIter iter = new TreeIter();
+		
+		string contents = Util.ReadFile(Util.GetEncoderCurvesTempFileName());
+		string line;
+		if (contents != null) {
+			using (StringReader reader = new StringReader (contents)) {
+				line = reader.ReadLine ();	//headers
+				do {
+					line = reader.ReadLine ();
+					if (line == null)
+						break;
+
+					string [] cells = line.Split(new char[] {','});
+					cells = fixDecimals(cells);
+					iter = store.AppendValues(cells);
+				} while(true);
+			}
+		}
+	}
+	
+	private string [] fixDecimals(string [] cells) {
+		for(int i=3; i <= 6; i++)
+			cells[i] = Util.TrimDecimals(Convert.ToDouble(Util.ChangeDecimalSeparator(cells[i])),3);
+		return cells;
+	}
+	
+	
+	/* end of TreeView stuff */	
+
+	
 }	
 
diff --git a/src/util.cs b/src/util.cs
index da5cf67..f49a23a 100644
--- a/src/util.cs
+++ b/src/util.cs
@@ -837,6 +837,9 @@ public class Util
 	public static string GetEncoderDataTempFileName() {
 		return Path.Combine(Path.GetTempPath(), Constants.EncoderDataTemp);
 	}
+	public static string GetEncoderCurvesTempFileName() {
+		return Path.Combine(Path.GetTempPath(), Constants.EncoderCurvesTemp);
+	}
 	public static string GetEncoderGraphTempFileName() {
 		return Path.Combine(Path.GetTempPath(), Constants.EncoderGraphTemp);
 	}
@@ -966,6 +969,18 @@ public class Util
 		while (!File.Exists(outputFileCheck));
 	}
 
+	public static string ReadFile(string fileName)
+	{
+		try {
+			StreamReader reader = File.OpenText(fileName);
+			string contents = reader.ReadToEnd ();
+			reader.Close();
+			return contents;
+		} catch {
+			return null;
+		}
+	}
+
 
 
 /*



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