Commit 2d7fafb2 authored by Xavier de Blas's avatar Xavier de Blas

run interval implemented:

        combo
        treeview
        simulate (also unlimited)
        execute (unlimited pending)
        last
        edit
        delete
        show in load session

new feature: jump or run repetitive until finish button is clicked:
        jumpRj with a jump "unlimted" button
        runInterval with a run "unlimited" button (useful for course navette ad other incremental tests)
        "run free" renamed "run custom"

fixed bug in Date representation in edit session
parent 50e0d3f7
CHANGELOG:
17 aug 2005
run interval implemented:
combo
treeview
simulate (also unlimited)
execute (unlimited pending)
last
edit
delete
show in load session
new feature: jump or run repetitive until finish button is clicked:
jumpRj with a jump "unlimted" button
runInterval with a run "unlimited" button (useful for course navette ad other incremental tests)
"run free" renamed "run custom"
fixed bug in Date representation in edit session
11 aug 2005
web created by create_web_chronojump.pl perl script, allows mantain
lots of pages in different languages.
......
No preview for this file type
This diff is collapsed.
This diff is collapsed.
......@@ -158,8 +158,10 @@ public class SessionEditWindow
entry_place.Text = currentSession.Place;
string [] dateFull = currentSession.Date.Split(new char[] {'/'});
Console.WriteLine("2: {0}, 0: {1}, 1: {2}", Convert.ToInt32(dateFull[2]),
Convert.ToInt32(dateFull[0]), Convert.ToInt32(dateFull[1]));
dateedit.Time = new DateTime (Convert.ToInt32(dateFull[2]),
Convert.ToInt32(dateFull[1]), Convert.ToInt32(dateFull[0]));
Convert.ToInt32(dateFull[0]), Convert.ToInt32(dateFull[1]));
TextBuffer tb = new TextBuffer (new TextTagTable());
tb.SetText(currentSession.Comments);
......@@ -270,9 +272,8 @@ public class SessionLoadWindow {
createTreeView(treeview_session_load);
store = new TreeStore(typeof (string), typeof (string), typeof (string), typeof (string),
typeof (string), typeof (string), typeof (string), typeof (string), typeof (string)
//, typeof(string)
);
typeof (string), typeof (string), typeof (string), typeof (string),
typeof (string), typeof (string) );
treeview_session_load.Model = store;
fillTreeView(treeview_session_load,store);
......@@ -296,12 +297,12 @@ public class SessionLoadWindow {
tv.AppendColumn ( Catalog.GetString ("Number"), new CellRendererText(), "text", count++);
tv.AppendColumn ( Catalog.GetString ("Name"), new CellRendererText(), "text", count++);
tv.AppendColumn ( Catalog.GetString ("Place"), new CellRendererText(), "text", count++);
tv.AppendColumn ( Catalog.GetString ("Date"), new CellRendererText(), "text", count++);
tv.AppendColumn ( Catalog.GetString ("Date (M/D/Y)"), new CellRendererText(), "text", count++);
tv.AppendColumn ( Catalog.GetString ("Persons"), new CellRendererText(), "text", count++);
tv.AppendColumn ( Catalog.GetString ("Simple Jumps"), new CellRendererText(), "text", count++);
tv.AppendColumn ( Catalog.GetString ("Reactive Jumps"), new CellRendererText(), "text", count++);
tv.AppendColumn ( Catalog.GetString ("Simple Runs"), new CellRendererText(), "text", count++);
//tv.AppendColumn ( Catalog.GetString ("Runs interval"), new CellRendererText(), "text", count++);
tv.AppendColumn ( Catalog.GetString ("Jumps simple"), new CellRendererText(), "text", count++);
tv.AppendColumn ( Catalog.GetString ("Jumps reactive"), new CellRendererText(), "text", count++);
tv.AppendColumn ( Catalog.GetString ("Runs simple"), new CellRendererText(), "text", count++);
tv.AppendColumn ( Catalog.GetString ("Runs interval"), new CellRendererText(), "text", count++);
tv.AppendColumn ( Catalog.GetString ("Comments"), new CellRendererText(), "text", count++);
}
......@@ -317,8 +318,8 @@ public class SessionLoadWindow {
myStringFull[5], //number of jumpers x session
myStringFull[6], //number of jumps x session
myStringFull[7], //number of jumpsRj x session
myStringFull[8], //number of runs x session
//myStringFull[9], //number of runsInterval x session
myStringFull[8], //number of runs x session
myStringFull[9], //number of runsInterval x session
myStringFull[4] //description of session
);
}
......
......@@ -458,7 +458,7 @@ public class JumpRj : Jump
int jumps; //total number of jumps
double time; //time elapsed
string limited; //the teorically values, eleven jumps: "11=J" (time recorded in "time"), 10 seconds: "10=T" (jumps recorded in jumps)
double limitAsDouble;
double limitAsDouble; //-1 for non limited (unlimited repetitive jump until "finish" is clicked)
bool jumpsLimited;
bool firstRjValue;
private double tcCount;
......@@ -534,6 +534,12 @@ public class JumpRj : Jump
tcString = tc.ToString();
equalTc = "=";
}
//if it's a unlimited reactive jump and it's simulated, put random value in limitAsDouble (will be jumps)
if(limitAsDouble == -1) {
limitAsDouble = Convert.ToInt32(rand.NextDouble() * 7);
}
for (double i=0 ; i < limitAsDouble ; i = i +.5) {
//we insert the RJs as a TV and TC string of all jumps separated by '='
if( nowTv ) {
......@@ -629,8 +635,6 @@ public class JumpRj : Jump
//jumpsLimited
do {
respuesta = cp.Read_event(out timestamp, out platformState);
/*
if(finish) {
write();
......@@ -647,28 +651,38 @@ public class JumpRj : Jump
progressBar.Fraction = myPb;
}
respuesta = cp.Read_event(out timestamp, out platformState);
if (respuesta == Chronopic.Respuesta.Ok) {
string equal = "";
//check if reactive jump should finish
if (jumpsLimited) {
//change the progressBar percent
//progressBar.Fraction = (tcCount + tvCount) / limitAsDouble ;
//don't allow progressBar be 1.0 before falseButtonClick is called
double myPb = (tcCount + tvCount) / limitAsDouble ;
if(myPb == 1.0 || myPb > 1.0) { myPb = 0.99; }
progressBar.Fraction = myPb;
if(Util.GetNumberOfJumps(tcString) >= limitAsDouble && Util.GetNumberOfJumps(tvString) >= limitAsDouble)
{
//finished writing the TC, let's put a "-1" in the TV
if (tcCount > tvCount) {
if(tvCount > 0) { equal = "="; }
tvString = tvString + equal + "-1";
//if reactive jump is "unlimited" not limited by jumps, nor time,
//then play with the progress bar until finish button is pressed
if(limitAsDouble == -1) {
double myPb = (tcCount + tvCount) / 5 ;
if(myPb == 1.0 || myPb > 1.0) { myPb = 0; }
progressBar.Fraction = myPb;
}
else {
//change the progressBar percent
//progressBar.Fraction = (tcCount + tvCount) / limitAsDouble ;
//don't allow progressBar be 1.0 before falseButtonClick is called
double myPb = (tcCount + tvCount) / limitAsDouble ;
if(myPb == 1.0 || myPb > 1.0) { myPb = 0.99; }
progressBar.Fraction = myPb;
if(Util.GetNumberOfJumps(tcString) >= limitAsDouble && Util.GetNumberOfJumps(tvString) >= limitAsDouble)
{
//finished writing the TC, let's put a "-1" in the TV
if (tcCount > tvCount) {
if(tvCount > 0) { equal = "="; }
tvString = tvString + equal + "-1";
}
write();
success = true;
}
write();
success = true;
}
} else {
//limited by time
......@@ -767,46 +781,6 @@ public class JumpRj : Jump
progressBar.Fraction = 1;
}
/*
private double getTotalTime (string stringTC, string stringTV)
{
if(stringTC.Length > 0 && stringTV.Length > 0) {
string [] tc = stringTC.Split(new char[] {'='});
string [] tv = stringTV.Split(new char[] {'='});
double totalTime = 0;
foreach (string jump in tc) {
totalTime = totalTime + Convert.ToDouble(jump);
}
foreach (string jump in tv) {
totalTime = totalTime + Convert.ToDouble(jump);
}
return totalTime ;
} else {
return 0;
}
}
*/
/*
private int getNumberOfJumps(string myString)
{
if(myString.Length > 0) {
string [] jumpsSeparated = myString.Split(new char[] {'='});
int count = 0;
foreach (string temp in jumpsSeparated) {
count++;
}
if(count == 0) { count =1; }
return count;
} else {
return 0;
}
}
*/
//called from chronojump.cs for finishing jumps earlier
public bool Finish
......
......@@ -76,6 +76,13 @@ public class JumpType
jumpsLimited = false;
fixedValue = 0;
isPredefined = true;
} else if(name == "RJ(unlimited)") {
startIn = true;
hasWeight = false;
isRepetitive = true;
jumpsLimited = true; //will finish in a concrete jump, not in a concrete second
fixedValue = -1; //don't ask for limit of jumps or seconds
isPredefined = true;
} else if(name == "triple jump") {
startIn = false;
hasWeight = false;
......
......@@ -314,10 +314,49 @@ public class RunInterval : Run
double timeTotal;
double distanceInterval;
string intervalTimesString;
int tracks;
double tracks; //double because if we limit by time (runType tracksLimited false), we do n.nn tracks
string limited; //the teorically values, eleven runs: "11=R" (time recorded in "time"), 10 seconds: "10=T" (tracks recorded in tracks)
double limitAsDouble; //-1 for non limited (unlimited repetitive run until "finish" is clicked)
bool tracksLimited;
bool firstIntervalValue;
double countContactTime;
//for finishing earlier from chronojump.cs
private bool finish;
//run execution
public RunInterval(int personID, int sessionID, string type, double distanceInterval, double limitAsDouble, bool tracksLimited,
Chronopic cp, Gtk.ProgressBar progressBar, Gnome.AppBar appbar, Gtk.Window app,
int pDN)
{
this.personID = personID;
this.sessionID = sessionID;
this.type = type;
this.distanceInterval = distanceInterval;
this.limitAsDouble = limitAsDouble;
this.tracksLimited = tracksLimited;
if(tracksLimited) {
this.limited = limitAsDouble.ToString() + "R"; //'R'uns (don't put 'T'racks for not confusing with 'T'ime)
} else {
this.limited = limitAsDouble.ToString() + "T";
timeTotal = limitAsDouble;
}
this.cp = cp;
this.progressBar = progressBar;
this.appbar = appbar;
this.app = app;
public RunInterval(int uniqueID, int personID, int sessionID, string type, double distanceTotal, double timeTotal, double distanceInterval, string intervalTimesString, int tracks, string description)
this.pDN = pDN;
falseButtonFinished = new Gtk.Button();
}
//after inserting database (SQL)
public RunInterval(int uniqueID, int personID, int sessionID, string type, double distanceTotal, double timeTotal, double distanceInterval, string intervalTimesString, double tracks, string description, string limited)
{
this.uniqueID = uniqueID;
this.personID = personID;
......@@ -329,14 +368,263 @@ public class RunInterval : Run
this.intervalTimesString = intervalTimesString;
this.tracks = tracks;
this.description = description;
this.limited = limited;
}
public string IntervalTimesString
public override void Simulate(Random rand)
{
get {
return intervalTimesString;
double intervalTime;
intervalTimesString = "";
string equalSymbol = "";
//if it's a unlimited intetrvalic run and it's simulated, put random value in limitAsDouble (will be tracks)
if(limitAsDouble == -1) {
limitAsDouble = Convert.ToInt32(rand.NextDouble() * 7);
tracksLimited = true;
limited = limitAsDouble.ToString() + "R";
}
if (tracksLimited) {
for (double i=0 ; i < limitAsDouble ; i++) {
intervalTime = rand.NextDouble() * 15;
timeTotal = timeTotal + intervalTime;
intervalTimesString = intervalTimesString + equalSymbol + intervalTime.ToString();
equalSymbol = "=";
}
} else {
//timeTotal is the defined as max
//timeCurrent is actual time running
//intervalTime is the time of this track
double timeCurrent = 0;
while (timeCurrent < timeTotal) {
intervalTime = rand.NextDouble() * 15;
if (intervalTime + timeCurrent > timeTotal) {
intervalTime = timeTotal - timeCurrent;
}
timeCurrent = timeCurrent + intervalTime;
intervalTimesString = intervalTimesString + equalSymbol + intervalTime.ToString();
equalSymbol = "=";
}
}
write();
}
public override void Manage(object o, EventArgs args)
{
Chronopic.Respuesta respuesta; //ok, error, or timeout in calling the platform
Chronopic.Plataforma platformState; //on (in platform), off (jumping), or unknow
do {
respuesta = cp.Read_platform(out platformState);
} while (respuesta!=Chronopic.Respuesta.Ok);
//you can start ON or OFF the platform,
//we record always de TV (or time between we abandonate the platform since we arrive)
if (platformState==Chronopic.Plataforma.ON) {
appbar.Push( Catalog.GetString("You are IN, RUN when prepared!!") );
loggedState = States.ON;
startIn = true;
} else {
appbar.Push( Catalog.GetString("You are OUT, RUN when prepared!!") );
loggedState = States.OFF;
startIn = false;
}
//initialize variables
intervalTimesString = "";
tracks = 0;
firstIntervalValue = true;
countContactTime = 0;
//reset progressBar
progressBar.Fraction = 0;
//prepare jump for being cancelled if desired
cancel = false;
//start thread
thread = new Thread(new ThreadStart(waitRun));
GLib.Idle.Add (new GLib.IdleHandler (Pulse));
thread.Start();
}
protected override void waitRun ()
{
double timestamp;
bool success = false;
string equal = "";
Chronopic.Respuesta respuesta; //ok, error, or timeout in calling the platform
Chronopic.Plataforma platformState; //on (in platform), off (jumping), or unknow
do {
//update the progressBar if limit is time
if ( ! tracksLimited) {
double myPb = Util.GetTotalTime (intervalTimesString) / limitAsDouble ;
//if(myPb > 1.0) { myPb = 1.0; }
//don't allow progressBar be 1.0 before falseButtonClick is called
if(myPb == 1.0 || myPb > 1.0) { myPb = 0.99; }
progressBar.Fraction = myPb;
}
respuesta = cp.Read_event(out timestamp, out platformState);
if (respuesta == Chronopic.Respuesta.Ok) {
if (platformState == Chronopic.Plataforma.ON && loggedState == States.OFF) {
//has arrived
loggedState = States.ON;
//if we start out, and we arrive to the platform for the first time, don't record nothing
if (firstIntervalValue && ! startIn) {
firstIntervalValue = false;
} else {
if (tracksLimited) {
tracks ++;
double myPb = (tracks) / limitAsDouble ;
if(myPb == 1.0 || myPb > 1.0) { myPb = 0.99; }
progressBar.Fraction = myPb;
if(intervalTimesString.Length > 0) { equal = "="; }
intervalTimesString = intervalTimesString + equal + (timestamp/1000).ToString();
if(tracks >= limitAsDouble)
{
//finished
write();
success = true;
}
} else {
if (Util.GetTotalTime (intervalTimesString, countContactTime.ToString())
>= limitAsDouble) {
//finished
write();
success = true;
} else {
if(intervalTimesString.Length > 0) { equal = "="; }
intervalTimesString = intervalTimesString + equal + (timestamp/1000).ToString();
tracks ++;
}
}
}
}
else if (platformState == Chronopic.Plataforma.OFF && loggedState == States.ON) {
//it's out, was inside (= has abandoned platform)
//don't record time
//progressBar.Fraction = progressBar.Fraction + 0.1;
//count the contact times when limited by time
//normally these are despreciable in runs, but if
//someone uses this for other application, we should record
if( ! tracksLimited) {
countContactTime = countContactTime + timestamp/1000;
}
//change the automata state
loggedState = States.OFF;
}
}
} while ( ! success && ! cancel && ! finish );
if (finish) {
write();
}
if(cancel || finish) {
//event will be raised, and managed in chronojump.cs
falseButtonFinished.Click();
}
}
protected override void write()
{
int tracks = 0;
string limitString = "";
//if user clicked in finish earlier
if(finish) {
/*
jumps = Util.GetNumberOfJumps(tvString);
if(jumpsLimited) {
limitString = jumps.ToString() + "J";
} else {
limitString = Util.GetTotalTime(tcString, tvString) + "T";
}
*/
} else {
if(tracksLimited) {
limitString = limitAsDouble.ToString() + "R";
tracks = (int) limitAsDouble;
} else {
limitString = limitAsDouble.ToString() + "T";
string [] myStringFull = intervalTimesString.Split(new char[] {'='});
tracks = myStringFull.Length;
}
}
distanceTotal = tracks * distanceInterval;
timeTotal = Util.GetTotalTime(intervalTimesString);
uniqueID = SqliteRun.InsertInterval(personID, sessionID, type,
distanceTotal, timeTotal,
distanceInterval, intervalTimesString, tracks,
"", //description
limitString
);
string myStringPush = Catalog.GetString("Last run: ") + RunnerName + " " +
type + " (" + limitString + ") " +
" AVG Speed: " + Util.TrimDecimals(
Util.GetSpeed(distanceTotal.ToString(),
timeTotal.ToString() )
, pDN ) ;
appbar.Push( myStringPush );
//event will be raised, and managed in chronojump.cs
falseButtonFinished.Click();
//put max value in progressBar. This makes the thread in Pulse() stop
progressBar.Fraction = 1;
}
public string IntervalTimesString
{
get { return intervalTimesString; }
}
public double DistanceInterval
{
get { return distanceInterval; }
}
public double DistanceTotal
{
get { return distanceTotal; }
}
public double TimeTotal
{
get { return timeTotal; }
}
public double Tracks
{
get { return tracks; }
}
public string Limited
{
get { return limited; }
set { limited = value; }
}
~RunInterval() {}
......
......@@ -29,63 +29,85 @@ public class RunType
protected double distance;
protected bool tracksLimited;
protected int fixedValue;
protected bool unlimited;
//predefined values
public RunType(string name) {
this.name = name;
unlimited = false; //default value
//if this changes, sqlite/runType.cs initialize tables should change
if(name == "Free") {
hasIntervals = false; //if it's a runInterval
//
//no interval
if(name == "Custom") {
hasIntervals = false;
distance = 0;
tracksLimited = false;
fixedValue = 0;
} else if(name == "20m") {
hasIntervals = false; //if it's a runInterval
hasIntervals = false;
distance = 20;
tracksLimited = false;
fixedValue = 0;
} else if(name == "100m") {
hasIntervals = false; //if it's a runInterval
hasIntervals = false;
distance = 100;
tracksLimited = false;
fixedValue = 0;
} else if(name == "200m") {
hasIntervals = false; //if it's a runInterval
hasIntervals = false;
distance = 200;
tracksLimited = false;
fixedValue = 0;
} else if(name == "400m") {
hasIntervals = false; //if it's a runInterval
hasIntervals = false;
distance = 400;
tracksLimited = false;
fixedValue = 0;
} else if(name == "1000m") {
hasIntervals = false; //if it's a runInterval
hasIntervals = false;
distance = 1000;
tracksLimited = false;
fixedValue = 0;
} else if(name == "2000m") {
hasIntervals = false; //if it's a runInterval
hasIntervals = false;
distance = 2000;
tracksLimited = false;
fixedValue = 0;
}
else if(name == "20m10times") {
hasIntervals = true; //if it's a runInterval
} //interval
else if(name == "byLaps") {
hasIntervals = true;
distance = 0;
tracksLimited = true;
fixedValue = 0;
} else if(name == "byTime") {
hasIntervals = true;
distance = 0;
tracksLimited = false;
fixedValue = 0;
} else if(name == "unlimited") {
hasIntervals = true;
distance = 0;
tracksLimited = false; //limited by time
fixedValue = 0;
unlimited = true;
} else if(name == "20m10times") {
hasIntervals = true;
distance = 20;
tracksLimited = true;
fixedValue = 10;
} else if(name == "7m30seconds") {
hasIntervals = true; //if it's a runInterval
hasIntervals = true;
distance = 7;
tracksLimited = false;
fixedValue = 30;
} else if(name == "20m endurance") {
hasIntervals = true; //if it's a runInterval
hasIntervals = true;
distance = 20;
tracksLimited = false;
fixedValue = 0;
unlimited = true;
}
}
......@@ -98,6 +120,7 @@ public class RunType
this.distance = distance;
this.tracksLimited = tracksLimited;
this.fixedValue = fixedValue;
this.unlimited = unlimited;
}
public string Name
......@@ -124,5 +147,10 @@ public class RunType
{
get { return fixedValue; }
}
public bool Unlimited
{
get { return unlimited; }
}
}
......@@ -56,7 +56,7 @@ class SqliteJump : Sqlite
"uniqueID INTEGER PRIMARY KEY, " +
"personID INT, " +
"sessionID INT, " +
"type TEXT, " + //in a future probably there are some types of rj
"type TEXT, " +
"tvMax FLOAT, " +
"tcMax FLOAT, " +
"fall INT, " +
......
......@@ -76,7 +76,9 @@ class SqliteJumpType : Sqlite
"startIn INT, " + //if it starts inside or outside the platform
"weight INT, " +
"jumpsLimited INT, " + //1 imited by jumps; 0 limited by time
"fixedValue FLOAT, " + //0: no fixed value; 3.5: 3.5 jumps or seconds
"fixedValue FLOAT, " + //0: no fixed value (ask),
//-1: don't ask (jump until "finish" button is clicked;
//3.5: 3.5 jumps or seconds
"description TEXT )";
dbcmd.ExecuteNonQuery();
}
......@@ -88,7 +90,9 @@ class SqliteJumpType : Sqlite
//name:startIn:weight:jumpsLimited:limitValue:description
"RJ(j):0:0:1:0:RJ limited by jumps",
"RJ(t):0:0:0:0:RJ limited by time",
"RJ(unlimited):1:0:1:-1:Jump unlimited until finish is clicked",
"triple jump:0:0:1:3:Triple jump"
//TODO: put something like: "continuous run until "finish" is clicked
};
foreach(string myJumpType in iniJumpTypes) {
JumpRjTypeInsert(myJumpType, true);
......
......@@ -94,7 +94,7 @@ class Sqlite
SqlitePersonSession.createTable();
SqlitePreferences.createTable();
SqlitePreferences.insert ("databaseVersion", "0.3");
SqlitePreferences.insert ("databaseVersion", "0.4");
SqlitePreferences.insert ("digitsNumber", "7");
SqlitePreferences.insert ("showHeight", "True");
SqlitePreferences.insert ("showInitialSpeed", "True");
......
......@@ -54,14 +54,14 @@ class SqliteRun : Sqlite
"uniqueID INTEGER PRIMARY KEY, " +
"personID INT, " +
"sessionID INT, " +
"type TEXT, " + //in a future probably there are some types of rj
"type TEXT, " +
"distanceTotal FLOAT, " +
"timeTotal FLOAT, " +
"distanceInterval FLOAT, " +
"intervalTimesString TEXT, " +
"tracks INT, " +
"description TEXT) ";
//"limited TEXT) "; //for RJ, "11J" or "11S" (11 Jumps, 11 seconds)
"tracks FLOAT, " + //float because if we limit by time (runType tracksLimited false), we do n.nn tracks
"description TEXT, " +
"limited TEXT) ";
dbcmd.ExecuteNonQuery();
}
......@@ -86,25 +86,23 @@ class SqliteRun : Sqlite
return myLast;
}
public static RunInterval InsertInterval(int personID, int sessionID, string type, double distanceTotal, double timeTotal, double distanceInterval, string intervalTimesString, int tracks, string description )
public static int InsertInterval(int personID, int sessionID, string type, double distanceTotal, double timeTotal, double distanceInterval, string intervalTimesString, double tracks, string description, string limited )
{
dbcon.Open();
dbcmd.CommandText = "INSERT INTO runInterval " +
"(uniqueID, personID, sessionID, type, distanceTotal, timeTotal, distanceInterval, intervalTimesString, tracks, description )" +
"(uniqueID, personID, sessionID, type, distanceTotal, timeTotal, distanceInterval, intervalTimesString, tracks, description, limited )" +
"VALUES (NULL, " +
personID + ", " + sessionID + ", '" + type + "', " +
distanceTotal + ", " + timeTotal + ", " + distanceInterval + ", " +
tracks + ", '" + description + "')" ;
distanceTotal