[chronojump] Moving to DB 1.06:"connect signal with curves" 25%
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] Moving to DB 1.06:"connect signal with curves" 25%
- Date: Fri, 16 May 2014 06:26:16 +0000 (UTC)
commit a4ddb91176d53dfd82eb69ffe6a403b7ee1aae08
Author: Xavier de Blas <xaviblas gmail com>
Date: Fri May 16 08:24:39 2014 +0200
Moving to DB 1.06:"connect signal with curves" 25%
src/sqlite/encoder.cs | 51 +++++++++++++++++++++++++++++++++++++++++++++++++
src/util.cs | 34 ++++++++++++++++++++++++++++++++
2 files changed, 85 insertions(+), 0 deletions(-)
---
diff --git a/src/sqlite/encoder.cs b/src/sqlite/encoder.cs
index 45b3562..819692a 100644
--- a/src/sqlite/encoder.cs
+++ b/src/sqlite/encoder.cs
@@ -586,6 +586,57 @@ class SqliteEncoder : Sqlite
return array;
}
+
+
+ /*
+ * database conversions
+ */
+
+ //convert from DB 1.05 to 1.06
+ //1.06 have curves connected to signals
+ //as curves detection on every signal can change depending on smoothing, minimal_height, ...
+ //1.06 needs to know where the curve is located in the signal
+ //starting ms is not reliable because changes with smoothing
+ //use central millisecond.
+ //
+ //this method will find where the central millisecond of a curve is located in a signal
+ //and this will be stored in 1.06 in new EncoderSignalCurve table
+ //signalID,curveID,contraction(c,ecS,ceS),msCentral
+ //encoder table will continue with signals and curves because we don't want to break things now
+ //
+ //as explained, following method is only used in conversions from 1.05 to 1.06
+ //newly saved curves in 1.06 will write msCentral in EncoderSignalCurve table without needing this
method
+ public static int FindCurveInSignal(string signalFile, string curveFile)
+ {
+ int [] signalInts = Util.ReadFileAsInts(signalFile);
+ /*
+ Log.WriteLine("found INTS");
+ for(int i=0; i < signalInts.Length; i ++)
+ Log.Write(signalInts[i] + " ");
+ */
+
+ int [] curveInts = Util.ReadFileAsInts(curveFile);
+ /*
+ Log.WriteLine("found INTS");
+ for(int i=0; i < curveInts.Length; i ++)
+ Log.Write(curveInts[i] + " ");
+ */
+
+ int c;
+ for(int s=0; s < signalInts.Length; s ++) {
+ for(c=0; c < curveInts.Length; c ++) {
+ if(signalInts[s + c] != curveInts[c])
+ break;
+ }
+ if(c == curveInts.Length) {
+ Log.WriteLine("Start at: " + s);
+ Log.WriteLine("Middle at: " + s + Convert.ToInt32(c / 2));
+ return s + Convert.ToInt32(c / 2);
+ }
+ }
+
+ return -1;
+ }
}
diff --git a/src/util.cs b/src/util.cs
index d127afc..63a68c7 100644
--- a/src/util.cs
+++ b/src/util.cs
@@ -926,6 +926,40 @@ public class Util
}
}
+ //returns int [] of encoder signal or curve
+ //currently used on db conversion 1.05 -> 1.06
+ public static int [] ReadFileAsInts(string fileName)
+ {
+ string contents;
+ try {
+ StreamReader reader = File.OpenText(fileName);
+ contents = reader.ReadToEnd ();
+ reader.Close();
+ } catch {
+ return new int [] {};
+ }
+
+ //create ints file bigger enought to hold all possible values
+ int [] ints = new int [contents.Length];
+ int count = 0;
+ for(int i=0; i < contents.Length; i++) {
+ if(Char.IsDigit(contents[i])) {
+ ints[count] = Convert.ToInt32(contents[i]);
+ if(i > 0 && contents[i-1] == '-')
+ ints[count] *= -1;
+
+ count ++;
+ }
+ }
+
+ //create int [] with the needed sized
+ int [] intsCut = new int [count];
+ for(int i=0; i < count; i ++)
+ intsCut[i] = ints[i];
+
+ return intsCut;
+ }
+
public static void RunRScript(string rScript){
//CancelRScript = false;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]