[chronojump] sprint communication Done, and solves problems without threads
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] sprint communication Done, and solves problems without threads
- Date: Thu, 23 Mar 2017 17:20:16 +0000 (UTC)
commit 63c226c875a6a16cd98ce39d5f33b950985d4ecc
Author: Xavier de Blas <xaviblas gmail com>
Date: Thu Mar 23 18:19:34 2017 +0100
sprint communication Done, and solves problems without threads
glade/app1.glade | 18 ++++++++++++++----
r-scripts/sprint.R | 30 ++++++++++++++++++++++++++----
src/gui/sprint.cs | 28 ++++++++++++++++++++++++++--
src/sprint.cs | 26 +++++++++++++-------------
src/utilEncoder.cs | 20 ++++++++++++++++----
5 files changed, 95 insertions(+), 27 deletions(-)
---
diff --git a/glade/app1.glade b/glade/app1.glade
index faff3f8..91de068 100644
--- a/glade/app1.glade
+++ b/glade/app1.glade
@@ -13681,6 +13681,7 @@ Concentric</property>
<property name="can_focus">False</property>
<child>
<widget class="GtkHBox" id="hbox76">
+ <property name="height_request">150</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="spacing">12</property>
@@ -13734,16 +13735,22 @@ Concentric</property>
</child>
</widget>
<packing>
- <property name="expand">True</property>
- <property name="fill">True</property>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
- <widget class="GtkLabel" id="label41">
+ <widget class="GtkViewport" id="viewport_sprint">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="label">result</property>
+ <child>
+ <widget class="GtkImage" id="image_sprint">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="stock">gtk-missing-image</property>
+ </widget>
+ </child>
</widget>
<packing>
<property name="expand">True</property>
@@ -19609,6 +19616,9 @@ then click this button.</property>
<child>
<placeholder/>
</child>
+ <child>
+ <placeholder/>
+ </child>
</widget>
<packing>
<property name="expand">False</property>
diff --git a/r-scripts/sprint.R b/r-scripts/sprint.R
index cd04672..1ee5c32 100644
--- a/r-scripts/sprint.R
+++ b/r-scripts/sprint.R
@@ -16,6 +16,7 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# Copyright (C) 2017 Xavier Padullés <x padulles gmail com>
+# Copyright (C) 2017 Xavier de Blas <xaviblas gmail com>
#This code uses splitTimes: accumulated time (not lap time)
@@ -322,7 +323,6 @@ drawSprintFromPhotocells <- function(sprintDynamics, splitTimes, positions, titl
textXPos = splitTimes[1:length(splitTimes) - 1] + diff(splitTimes)/2
# Plotting average speed
- pdf("/tmp/photocellsSprintGraph.pdf", width = 16, height = 8)
barplot(height = avg.speeds, width = diff(splitTimes), space = 0, ylim = c(0, max(c(avg.speeds,
sprintDynamics$Vmax) + 1)), main=title, xlab="Time(s)", ylab="Velocity(m/s)", axes = FALSE, yaxs= "i", xaxs =
"i")
text(textXPos, avg.speeds, round(avg.speeds, digits = 2), pos = 3)
@@ -361,22 +361,38 @@ drawSprintFromPhotocells <- function(sprintDynamics, splitTimes, positions, titl
Vmax=round(sprintDynamics$Vmax.fitted, digits=3),
K=round(sprintDynamics$K.fitted, digits=3))),
pos=4, cex=1, col ="red")
- dev.off()
}
}
+prepareGraph <- function(os, pngFile, width, height)
+{
+ if(os == "Windows")
+ Cairo(width, height, file = pngFile, type="png", bg="white")
+ else
+ png(pngFile, width=width, height=height)
+}
+endGraph <- function()
+{
+ dev.off()
+}
+
testPhotocellsCJ <- function(positions, splitTimes, mass, personHeight, tempC)
{
sprint = getSprintFromPhotocell(position = positions, splitTimes = splitTimes)
sprintDynamics = getDynamicsFromSprint(K = sprint$K, Vmax = sprint$Vmax, mass, tempC, personHeight,
maxTime = max(splitTimes))
print(paste("K =",sprintDynamics$K.fitted, "Vmax =", sprintDynamics$Vmax.fitted))
+
drawSprintFromPhotocells(sprintDynamics = sprintDynamics, splitTimes, positions, title = "Testing
graph")
}
args <- commandArgs(TRUE)
-optionsFile <- args[1]
+
+tempPath <- args[1]
+optionsFile <- paste(tempPath, "/Roptions.txt", sep="")
+pngFile <- paste(tempPath, "/sprintGraph.png", sep="")
+
options <- scan(optionsFile, comment.char="#", what=character(), sep="\n")
assignOptions <- function(options) {
return(list(
@@ -384,13 +400,19 @@ assignOptions <- function(options) {
splitTimes = as.numeric(unlist(strsplit(options[2], "\\;"))),
mass = as.numeric(options[3]),
personHeight = as.numeric(options[4]),
- tempC = as.numeric(options[5])
+ tempC = as.numeric(options[5]),
+ os = options[6],
+ graphWidth = as.numeric(options[7]),
+ graphHeight = as.numeric(options[8])
))
}
op <- assignOptions(options)
#print(op$positions)
+
+prepareGraph(op$os, pngFile, op$graphWidth, op$graphHeight)
testPhotocellsCJ(op$positions, op$splitTimes, op$mass, op$personHeight, op$tempC)
+endGraph()
#Examples of use
diff --git a/src/gui/sprint.cs b/src/gui/sprint.cs
index 8d76e3a..2d75182 100644
--- a/src/gui/sprint.cs
+++ b/src/gui/sprint.cs
@@ -29,6 +29,9 @@ using System.Collections.Generic; //List<T>
public partial class ChronoJumpWindow
{
[Widget] Gtk.Button button_sprint;
+ [Widget] Gtk.Viewport viewport_sprint;
+ [Widget] Gtk.Image image_sprint;
+
static Sprint sprint;
private void createTreeView_runs_interval_sprint (Gtk.TreeView tv)
@@ -190,7 +193,28 @@ public partial class ChronoJumpWindow
return;
}
- sprint.CallR();
- new DialogMessage(Constants.MessageTypes.WARNING, "Ok");
+ Util.FileDelete(UtilEncoder.GetSprintImage());
+
+ image_sprint.Sensitive = false;
+
+ bool success = sprint.CallR(
+ viewport_sprint.Allocation.Width -5,
+ viewport_sprint.Allocation.Height -5);
+
+ if(! success)
+ {
+ new DialogMessage(Constants.MessageTypes.WARNING, "Problems on sprint R script.");
+ return;
+ }
+
+ while ( ! Util.FileReadable(UtilEncoder.GetSprintImage()));
+
+ image_sprint = UtilGtk.OpenImageSafe(
+ UtilEncoder.GetSprintImage(),
+ image_sprint);
+ image_sprint.Sensitive = true;
+
+ new DialogMessage(Constants.MessageTypes.INFO, "Ok");
}
+
}
diff --git a/src/sprint.cs b/src/sprint.cs
index 789ac9b..84c0a90 100644
--- a/src/sprint.cs
+++ b/src/sprint.cs
@@ -24,8 +24,6 @@ using System.Collections.Generic; //List<T>
public class Sprint
{
- string optionsFile;
-
//private List<double> positions;
//private List<double> splitTimes;
private string positions;
@@ -56,27 +54,26 @@ public class Sprint
}
*/
- public void CallR()
+ public bool CallR(int graphWidth, int graphHeight)
{
- optionsFile = Path.GetTempPath() + "Roptions.txt";
-
string executable = UtilEncoder.RProcessBinURL();
List<string> parameters = new List<string>();
- parameters.Insert(0, "\"" + UtilEncoder.GetScriptSprint() + "\"");
- parameters.Insert(1, "\"" + optionsFile + "\"");
+ parameters.Insert(0, "\"" + UtilEncoder.GetSprintScript() + "\"");
+ parameters.Insert(1, "\"" + Path.GetTempPath() + "\"");
- writeOptionsFile();
+ writeOptionsFile(graphWidth, graphHeight);
LogB.Information("\nCalling sprint.R ----->");
- //ExecuteProcess.Result execute_result = ExecuteProcess.run (executable, parameters);
+ //ExecuteProcess.run (executable, parameters);
+ ExecuteProcess.Result execute_result = ExecuteProcess.run (executable, parameters);
//LogB.Information("Result = " + execute_result.stdout);
- ExecuteProcess.run (executable, parameters);
LogB.Information("\n<------ Done calling sprint.R.");
+ return execute_result.success;
}
- private void writeOptionsFile()
+ private void writeOptionsFile(int graphWidth, int graphHeight)
{
/*
string scriptOptions =
@@ -91,9 +88,12 @@ public class Sprint
"#splitTimes\n" + splitTimes + "\n" +
"#mass\n" + mass + "\n" +
"#personHeight\n" + personHeight + "\n" +
- "#tempC\n" + tempC + "\n";
+ "#tempC\n" + tempC + "\n" +
+ "#os\n" + UtilEncoder.OperatingSystemForRGraphs() + "\n" +
+ "#graphWidth\n" + graphWidth.ToString() + "\n" +
+ "#graphHeight\n" + graphHeight.ToString() + "\n";
- TextWriter writer = File.CreateText(optionsFile);
+ TextWriter writer = File.CreateText(Path.GetTempPath() + "Roptions.txt");
writer.Write(scriptOptions);
writer.Flush();
writer.Close();
diff --git a/src/utilEncoder.cs b/src/utilEncoder.cs
index 5139e5e..f347c01 100644
--- a/src/utilEncoder.cs
+++ b/src/utilEncoder.cs
@@ -236,9 +236,12 @@ public class UtilEncoder
/********** start of r-scripts paths ************/
- public static string GetScriptSprint() {
+ public static string GetSprintScript() {
return System.IO.Path.Combine(Util.GetDataDir(), "r-scripts", "sprint.R");
}
+ public static string GetSprintImage() {
+ return System.IO.Path.Combine(Path.GetTempPath(), "sprintGraph.png");
+ }
/********** end of r-scripts paths ************/
@@ -303,10 +306,20 @@ public class UtilEncoder
while ( ! ( File.Exists(outputFileCheck) || CancelRScript) );
}
*/
-
- public static EncoderGraphROptions PrepareEncoderGraphOptions(string title, EncoderStruct es, bool
neuromuscularProfileDo, bool translate, bool debug, bool crossValidate)
+
+ //R plots on Windows using Cairo, need to know if it's windows or not
+ public static string OperatingSystemForRGraphs()
{
string operatingSystem = "Linux";
+ if (UtilAll.IsWindows())
+ operatingSystem = "Windows";
+
+ return operatingSystem;
+ }
+
+ public static EncoderGraphROptions PrepareEncoderGraphOptions(string title, EncoderStruct es, bool
neuromuscularProfileDo, bool translate, bool debug, bool crossValidate)
+ {
+ string operatingSystem = OperatingSystemForRGraphs();
title = Util.RemoveBackSlash(title);
title = Util.RemoveChar(title, '\'');
@@ -323,7 +336,6 @@ public class UtilEncoder
//es.OutputData2 = es.OutputData2.Replace("\\","/");
//es.SpecialData = es.SpecialData.Replace("\\","/");
es.EncoderTempPath = es.EncoderTempPath.Replace("\\","/");
- operatingSystem = "Windows";
}
//if translators add ";", it will be converted to ','
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]