[chronojump] Safer encoder export to csv
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] Safer encoder export to csv
- Date: Mon, 9 Nov 2015 11:47:07 +0000 (UTC)
commit 3317f388c79c7c1caaefbfae21461b35173ae1c3
Author: Xavier de Blas <xaviblas gmail com>
Date: Mon Nov 9 12:44:30 2015 +0100
Safer encoder export to csv
encoder/graph.R | 5 +++++
src/encoderRProc.cs | 25 +++++++++++++++++++++++++
src/gui/encoder.cs | 4 +++-
src/util.cs | 8 ++++++++
4 files changed, 41 insertions(+), 1 deletions(-)
---
diff --git a/encoder/graph.R b/encoder/graph.R
index 5ad2f24..d6b4e9c 100644
--- a/encoder/graph.R
+++ b/encoder/graph.R
@@ -2719,6 +2719,9 @@ doProcess <- function(options)
#since Chronojump 1.3.6, encoder analyze has a treeview that can show the curves
#when an analysis is done, curves file has to be written
writeCurves = TRUE
+ #but don't writeCurves on exportCSV because outputfile is the same
+ if(op$Analysis == "exportCSV")
+ writeCurves = FALSE
if(
op$Analysis == "powerBars" || op$Analysis == "cross" ||
@@ -3034,6 +3037,8 @@ doProcess <- function(options)
}
if(op$Analysis=="exportCSV") {
print("Starting export...")
+ write("starting export", stderr())
+
curvesNum = length(curves[,1])
maxLength = 0
diff --git a/src/encoderRProc.cs b/src/encoderRProc.cs
index 7db56b5..1e9f75b 100644
--- a/src/encoderRProc.cs
+++ b/src/encoderRProc.cs
@@ -317,6 +317,12 @@ public class EncoderRProcAnalyze : EncoderRProc
private bool neuromuscularProfileDo;
private bool translate;
+ /*
+ * to avoid problems on some windows. R exports csv to Util.GetEncoderExportTempFileName()
+ * then C# copies it to exportFileName
+ */
+ public string ExportFileName;
+
public bool CancelRScript;
public EncoderRProcAnalyze() {
@@ -431,6 +437,11 @@ public class EncoderRProcAnalyze : EncoderRProc
while ( ! ( fileWritten(outputFileCheck) || CancelRScript) );
else
while ( ! ( (fileWritten(outputFileCheck) && fileWritten(outputFileCheck2))
|| CancelRScript ) );
+
+ //copy export from temp file to the file that user has selected
+ if(es.Ep.Analysis == "exportCSV" && ! CancelRScript)
+ copyExportedFile();
+
} catch {
LogB.Warning("catched at startProcess");
return false;
@@ -478,10 +489,24 @@ public class EncoderRProcAnalyze : EncoderRProc
while ( ! ( fileWritten(outputFileCheck) || CancelRScript) );
else
while ( ! ( (fileWritten(outputFileCheck) && fileWritten(outputFileCheck2)) ||
CancelRScript ) );
+
+ //copy export from temp file to the file that user has selected
+ if(es.Ep.Analysis == "exportCSV" && ! CancelRScript)
+ copyExportedFile();
+
LogB.Debug("files written");
return true;
}
+
+ //copy export from temp file to the file that user has selected
+ private void copyExportedFile() {
+ //wait first this status mark that is created when file is fully exported
+ while ( ! Util.FileExists(UtilEncoder.GetEncoderStatusTempBaseFileName() + "5.txt") )
+ ;
+ //copy the file
+ File.Copy(es.OutputData1, ExportFileName, true);
+ }
private string getEncoderScriptCallGraph() {
diff --git a/src/gui/encoder.cs b/src/gui/encoder.cs
index 1fece3b..d5561d7 100644
--- a/src/gui/encoder.cs
+++ b/src/gui/encoder.cs
@@ -1634,11 +1634,13 @@ public partial class ChronoJumpWindow
EncoderStruct encoderStruct = new EncoderStruct(
dataFileName,
UtilEncoder.GetEncoderGraphTempFileName(),
- selectedFileName,
+ Util.GetEncoderExportTempFileName(),
UtilEncoder.GetEncoderStatusTempBaseFileName(),
UtilEncoder.GetEncoderSpecialDataTempFileName(),
ep);
+ encoderRProcAnalyze.ExportFileName = selectedFileName;
+
encoderRProcAnalyze.SendData(
Util.ChangeSpaceAndMinusForUnderscore(currentPerson.Name) + "-" +
Util.ChangeSpaceAndMinusForUnderscore(lastEncoderSQLSignal.exerciseName) +
diff --git a/src/util.cs b/src/util.cs
index ee7deb8..33365d9 100644
--- a/src/util.cs
+++ b/src/util.cs
@@ -932,7 +932,15 @@ public class Util
}
/********** end of multimedia paths ************/
+
+
+ /********** start of encoder paths ************/
+
+ public static string GetEncoderExportTempFileName() {
+ return Path.Combine(Path.GetTempPath(), "encoder_export.csv");
+ }
+ /********** end of encoder paths ************/
public static string GetManualDir() {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]