protected override void waitEvent() { double timestamp = 0; bool success = false; shouldFinishAtNextFall = false; bool ok; int countForSavingTempTable = 0; do { if (simulated) { ok = true; } else { ok = cp.Read_event(out timestamp, out platformState); } //if chronopic signal is Ok and state has changed if (ok && ( (platformState == Chronopic.Plataforma.ON && loggedState == States.OFF) || (platformState == Chronopic.Plataforma.OFF && loggedState == States.ON)) && !cancel && !finish) { if (simulated) { timestamp = simulatedTimeLast * 1000; //conversion to milliseconds } LogB.Information(Util.GetTotalTime(tcString, tvString).ToString()); string equal = ""; //while no finished time or jumps, continue recording events if (!success) { //don't record the time until the first event if (firstRjValue) { firstRjValue = false; //but start timer initializeTimer(); feedbackMessage = ""; needShowFeedbackMessage = true; } else { //reactive jump has not finished... record the next jump LogB.Information(string.Format("tcCount: {0}, tvCount: {1}", tcCount, tvCount)); if (tcCount == tvCount) { lastTc = timestamp / 1000.0; if (tcCount > 0) { equal = "="; } tcString = tcString + equal + lastTc.ToString(); updateTimerCountWithChronopicData(tcString, tvString); tcCount = tcCount + 1; } else { //tcCount > tvCount lastTv = timestamp / 1000.0; if (tvCount > 0) { equal = "="; } tvString = tvString + equal + lastTv.ToString(); updateTimerCountWithChronopicData(tcString, tvString); tvCount = tvCount + 1; //update event progressbar //app1.ProgressBarEventOrTimePreExecution( updateProgressBar = new UpdateProgressBar( true, //isEvent jumpsLimited, //if jumpsLimited: do fraction; if time limited: do pulse tvCount ); needUpdateEventProgressBar = true; //update graph PrepareEventGraphJumpReactiveObject = new PrepareEventGraphJumpReactive(lastTv, lastTc, tvString, tcString); needUpdateGraphType = eventType.JUMPREACTIVE; needUpdateGraph = true; //put button_finish as sensitive when first jump is done (there's something recordable) if (tvCount == 1) { needSensitiveButtonFinish = true; } //save temp table if needed countForSavingTempTable++; if (countForSavingTempTable == timesForSavingRepetitive) { writeRj(true); //tempTable countForSavingTempTable = 0; } } } } //if we finish by time, and allowFinishAfterTime == true, when time passed, if the jumper is jumping //if flags the shouldFinishAtNextFall that will finish when he arrives to the platform if (shouldFinishAtNextFall && platformState == Chronopic.Plataforma.ON && loggedState == States.OFF) { finish = true; } //check if reactive jump should finish if (jumpsLimited) { if (limitAsDouble != -1) { if (Util.GetNumberOfJumps(tvString, false) >= limitAsDouble) { jumpPhase = jumpPhases.PLATFORM_END; writeRj(false); //tempTable success = true; //update event progressbar //app1.ProgressBarEventOrTimePreExecution( updateProgressBar = new UpdateProgressBar( true, //isEvent true, //percentageMode tvCount ); needUpdateEventProgressBar = true; //update graph PrepareEventGraphJumpReactiveObject = new PrepareEventGraphJumpReactive(lastTv, lastTc, tvString, tcString); needUpdateGraphType = eventType.JUMPREACTIVE; needUpdateGraph = true; } } } if (platformState == Chronopic.Plataforma.OFF) { loggedState = States.OFF; } else { loggedState = States.ON; } } } while (!success && !cancel && !finish); if (finish) { //write only if there's a jump at minimum if (Util.GetNumberOfJumps(tcString, false) >= 1 && Util.GetNumberOfJumps(tvString, false) >= 1) { jumpPhase = jumpPhases.PLATFORM_END; writeRj(false); //tempTable totallyFinished = true; } else { //cancel a jump if clicked finish before any events done cancel = true; } } //if(cancel || finish) if (cancel) { //event will be raised, and managed in chronojump.cs fakeButtonFinished.Click(); totallyCancelled = true; } }
protected void writeRj(bool tempTable) { Log.WriteLine("----------WRITING----------"); int jumps; string limitString = ""; string description = ""; //if user clicked in finish earlier //or toggled with shouldFinishAtNextTime if(finish) { //if user clicked finish and last event was tc, probably there are more TCs than TFs //if last event was tc, it has no sense, it should be deleted tcString = Util.DeleteLastTcIfNeeded(tcString, tvString); //when we mark that jump should finish by time, chronopic thread is probably capturing data //check if it captured more than date limit, and if it has done, delete last(s) jump(s) //also have in mind that allowFinishAfterTime exist bool deletedEvent = false; if( ! jumpsLimited && limitAsDouble != -1) { bool eventPassed = Util.EventPassedFromMaxTime(tcString, tvString, limitAsDouble, allowFinishAfterTime); while(eventPassed) { tcString = Util.DeleteLastSubEvent(tcString); tvString = Util.DeleteLastSubEvent(tvString); Log.WriteLine("Deleted one event out of time"); eventPassed = Util.EventPassedFromMaxTime(tcString, tvString, limitAsDouble, allowFinishAfterTime); deletedEvent = true; } } if(deletedEvent) { //update graph if a event was deleted PrepareEventGraphJumpReactiveObject = new PrepareEventGraphJumpReactive(Util.GetLast(tvString), Util.GetLast(tcString), tvString, tcString); needUpdateGraphType = eventType.JUMPREACTIVE; needUpdateGraph = true; //try to fix this: //http://mail.gnome.org/archives/chronojump-list/2007-June/msg00013.html updateProgressBar= new UpdateProgressBar ( true, //isEvent jumpsLimited, //if jumpsLimited: do fraction; if time limited: do pulse Util.GetNumberOfJumps(tvString, false) ); needUpdateEventProgressBar = true; //and this: //http://mail.gnome.org/archives/chronojump-list/2007-June/msg00017.html updateTimerCountWithChronopicData(tcString, tvString); } jumps = Util.GetNumberOfJumps(tvString, false); if(jumpsLimited) { limitString = jumps.ToString() + "J"; } else { limitString = Util.GetTotalTime(tcString, tvString) + "T"; limited = limitString; //define limited because it's checked in treeviewJump, and possibly it's not the initial defined time (specially when allowFinishRjAfterTime is true) //leave the initial selected time into description/comments: description = string.Format(Catalog.GetString("Initially selected {0} seconds"), limitAsDouble.ToString()); } } else { if(jumpsLimited) { limitString = limitAsDouble.ToString() + "J"; jumps = (int) limitAsDouble; } else { //if time finished and the last event was tc, probably there are more TCs than TFs //if last event was tc, it has no sense, it should be deleted //this is not aplicable in tempTable if(! tempTable) tcString = Util.DeleteLastTcIfNeeded(tcString, tvString); //limitString = limitAsDouble.ToString() + "T"; limitString = Util.GetTotalTime(tcString, tvString) + "T"; limited = limitString; //define limited because it's checked in treeviewJump, and possibly it's not the initial defined time (specially when allowFinishRjAfterTime is true) //leave the initial selected time into description/comments: description = string.Format(Catalog.GetString("Initially selected {0} seconds"), limitAsDouble.ToString()); string [] myStringFull = tcString.Split(new char[] {'='}); jumps = myStringFull.Length; } } if(type == Constants.RunAnalysisName) { //double speed = (fall /10) / Util.GetTotalTime(tcString, tvString); /* * Josep Ma Padullés test * string tcStringWithoutFirst = Util.DeleteFirstSubEvent(tcString); string tvStringWithoutFirst = Util.DeleteFirstSubEvent(tvString); double averagePlatformTimes = ( Util.GetAverage(tcStringWithoutFirst) + Util.GetAverage(tvStringWithoutFirst) ) / 2; double freq = 1 / averagePlatformTimes; //amplitud double range = speed / freq; //don't put "=" because can appear problems in different parts of the code description = Catalog.GetString ("AVG speed") + "->" + Util.TrimDecimals(speed.ToString(), pDN) + "m/s, " + Catalog.GetString ("AVG frequencies") + "->" + Util.TrimDecimals(freq.ToString(), pDN) + "Hz, " + Catalog.GetString ("AVG range") + "->" + Util.TrimDecimals(range.ToString(), pDN) + "m."; */ } if(tempTable) SqliteJumpRj.Insert(false, Constants.TempJumpRjTable, "NULL", personID, sessionID, type, Util.GetMax(tvString), Util.GetMax(tcString), fall, weight, description, Util.GetAverage(tvString), Util.GetAverage(tcString), tvString, tcString, jumps, Util.GetTotalTime(tcString, tvString), limitString, angleString, Util.BoolToNegativeInt(simulated) ); else { uniqueID = SqliteJumpRj.Insert(false, Constants.JumpRjTable, "NULL", personID, sessionID, type, Util.GetMax(tvString), Util.GetMax(tcString), fall, weight, description, Util.GetAverage(tvString), Util.GetAverage(tcString), tvString, tcString, jumps, Util.GetTotalTime(tcString, tvString), limitString, angleString, Util.BoolToNegativeInt(simulated) ); //define the created object eventDone = new JumpRj(uniqueID, personID, sessionID, type, tvString, tcString, fall, weight, description, jumps, Util.GetTotalTime(tcString, tvString), limitString, angleString, Util.BoolToNegativeInt(simulated)); //event will be raised, and managed in chronojump.cs /* string myStringPush = //Catalog.GetString("Last jump: ") + personName + " " + type + " (" + limitString + ") " + " " + Catalog.GetString("AVG TF") + ": " + Util.TrimDecimals( Util.GetAverage (tvString).ToString(), pDN ) + " " + Catalog.GetString("AVG TC") + ": " + Util.TrimDecimals( Util.GetAverage (tcString).ToString(), pDN ) ; */ if(simulated) feedbackMessage = Catalog.GetString(Constants.SimulatedMessage); else feedbackMessage = ""; needShowFeedbackMessage = true; //event will be raised, and managed in chronojump.cs fakeButtonFinished.Click(); needEndEvent = true; //used for hiding some buttons on eventWindow, and also for updateTimeProgressBar here } }
protected void writeRj(bool tempTable) { LogB.Information("----------WRITING----------"); int jumps; string limitString = ""; string description = ""; //if user clicked in finish earlier //or toggled with shouldFinishAtNextTime if (finish) { //if user clicked finish and last event was tc, probably there are more TCs than TFs //if last event was tc, it has no sense, it should be deleted tcString = Util.DeleteLastTcIfNeeded(tcString, tvString); //when we mark that jump should finish by time, chronopic thread is probably capturing data //check if it captured more than date limit, and if it has done, delete last(s) jump(s) //also have in mind that allowFinishAfterTime exist bool deletedEvent = false; if (!jumpsLimited && limitAsDouble != -1) { bool eventPassed = Util.EventPassedFromMaxTime(tcString, tvString, limitAsDouble, allowFinishAfterTime); while (eventPassed) { tcString = Util.DeleteLastSubEvent(tcString); tvString = Util.DeleteLastSubEvent(tvString); LogB.Information("Deleted one event out of time"); eventPassed = Util.EventPassedFromMaxTime(tcString, tvString, limitAsDouble, allowFinishAfterTime); deletedEvent = true; } } if (deletedEvent) { //update graph if a event was deleted PrepareEventGraphJumpReactiveObject = new PrepareEventGraphJumpReactive(Util.GetLast(tvString), Util.GetLast(tcString), tvString, tcString); needUpdateGraphType = eventType.JUMPREACTIVE; needUpdateGraph = true; //try to fix this: //http://mail.gnome.org/archives/chronojump-list/2007-June/msg00013.html updateProgressBar = new UpdateProgressBar( true, //isEvent jumpsLimited, //if jumpsLimited: do fraction; if time limited: do pulse Util.GetNumberOfJumps(tvString, false) ); needUpdateEventProgressBar = true; //and this: //http://mail.gnome.org/archives/chronojump-list/2007-June/msg00017.html updateTimerCountWithChronopicData(tcString, tvString); } jumps = Util.GetNumberOfJumps(tvString, false); if (jumpsLimited) { limitString = jumps.ToString() + "J"; } else { limitString = Util.GetTotalTime(tcString, tvString) + "T"; limited = limitString; //define limited because it's checked in treeviewJump, and possibly it's not the initial defined time (specially when allowFinishRjAfterTime is true) //leave the initial selected time into description/comments: description = string.Format(Catalog.GetString("Initially selected {0} seconds"), limitAsDouble.ToString()); } } else { if (jumpsLimited) { limitString = limitAsDouble.ToString() + "J"; jumps = (int)limitAsDouble; } else { //if time finished and the last event was tc, probably there are more TCs than TFs //if last event was tc, it has no sense, it should be deleted //this is not aplicable in tempTable if (!tempTable) { tcString = Util.DeleteLastTcIfNeeded(tcString, tvString); } //limitString = limitAsDouble.ToString() + "T"; limitString = Util.GetTotalTime(tcString, tvString) + "T"; limited = limitString; //define limited because it's checked in treeviewJump, and possibly it's not the initial defined time (specially when allowFinishRjAfterTime is true) //leave the initial selected time into description/comments: description = string.Format(Catalog.GetString("Initially selected {0} seconds"), limitAsDouble.ToString()); string [] myStringFull = tcString.Split(new char[] { '=' }); jumps = myStringFull.Length; } } if (type == Constants.RunAnalysisName) { //double speed = (fall /10) / Util.GetTotalTime(tcString, tvString); /* * Josep Ma Padullés test * * string tcStringWithoutFirst = Util.DeleteFirstSubEvent(tcString); * string tvStringWithoutFirst = Util.DeleteFirstSubEvent(tvString); * * double averagePlatformTimes = ( Util.GetAverage(tcStringWithoutFirst) + Util.GetAverage(tvStringWithoutFirst) ) / 2; * double freq = 1 / averagePlatformTimes; * * //amplitud * double range = speed / freq; * * //don't put "=" because can appear problems in different parts of the code * description = * Catalog.GetString ("AVG speed") + "->" + Util.TrimDecimals(speed.ToString(), pDN) + "m/s, " + * Catalog.GetString ("AVG frequencies") + "->" + Util.TrimDecimals(freq.ToString(), pDN) + "Hz, " + * Catalog.GetString ("AVG range") + "->" + Util.TrimDecimals(range.ToString(), pDN) + "m."; */ } if (tempTable) { SqliteJumpRj.Insert(false, Constants.TempJumpRjTable, "NULL", personID, sessionID, type, Util.GetMax(tvString), Util.GetMax(tcString), fall, weight, description, Util.GetAverage(tvString), Util.GetAverage(tcString), tvString, tcString, jumps, Util.GetTotalTime(tcString, tvString), limitString, angleString, Util.BoolToNegativeInt(simulated) ); } else { uniqueID = SqliteJumpRj.Insert(false, Constants.JumpRjTable, "NULL", personID, sessionID, type, Util.GetMax(tvString), Util.GetMax(tcString), fall, weight, description, Util.GetAverage(tvString), Util.GetAverage(tcString), tvString, tcString, jumps, Util.GetTotalTime(tcString, tvString), limitString, angleString, Util.BoolToNegativeInt(simulated) ); //define the created object eventDone = new JumpRj(uniqueID, personID, sessionID, type, tvString, tcString, fall, weight, description, jumps, Util.GetTotalTime(tcString, tvString), limitString, angleString, Util.BoolToNegativeInt(simulated)); //event will be raised, and managed in chronojump.cs /* * string myStringPush = * //Catalog.GetString("Last jump: ") + * personName + " " + * type + " (" + limitString + ") " + * " " + Catalog.GetString("AVG TF") + ": " + Util.TrimDecimals( Util.GetAverage (tvString).ToString(), pDN ) + * " " + Catalog.GetString("AVG TC") + ": " + Util.TrimDecimals( Util.GetAverage (tcString).ToString(), pDN ) ; */ if (simulated) { feedbackMessage = Catalog.GetString(Constants.SimulatedMessage); } else { feedbackMessage = ""; } needShowFeedbackMessage = true; //event will be raised, and managed in chronojump.cs fakeButtonFinished.Click(); needEndEvent = true; //used for hiding some buttons on eventWindow, and also for updateTimeProgressBar here } }
protected override void waitEvent() { double timestamp = 0; bool success = false; shouldFinishAtNextFall = false; bool ok; int countForSavingTempTable = 0; do { if(simulated) ok = true; else ok = cp.Read_event(out timestamp, out platformState); //if chronopic signal is Ok and state has changed if (ok && ( (platformState == Chronopic.Plataforma.ON && loggedState == States.OFF) || (platformState == Chronopic.Plataforma.OFF && loggedState == States.ON) ) && !cancel && !finish) { if(simulated) timestamp = simulatedTimeLast * 1000; //conversion to milliseconds Log.Write(Util.GetTotalTime(tcString, tvString).ToString()); string equal = ""; //while no finished time or jumps, continue recording events if ( ! success) { //don't record the time until the first event if (firstRjValue) { firstRjValue = false; //but start timer initializeTimer(); feedbackMessage = ""; needShowFeedbackMessage = true; } else { //reactive jump has not finished... record the next jump Log.WriteLine(string.Format("tcCount: {0}, tvCount: {1}", tcCount, tvCount)); if ( tcCount == tvCount ) { lastTc = timestamp/1000.0; if(tcCount > 0) { equal = "="; } tcString = tcString + equal + lastTc.ToString(); updateTimerCountWithChronopicData(tcString, tvString); tcCount = tcCount + 1; } else { //tcCount > tvCount lastTv = timestamp/1000.0; if(tvCount > 0) { equal = "="; } tvString = tvString + equal + lastTv.ToString(); updateTimerCountWithChronopicData(tcString, tvString); tvCount = tvCount + 1; //update event progressbar //app1.ProgressBarEventOrTimePreExecution( updateProgressBar= new UpdateProgressBar ( true, //isEvent jumpsLimited, //if jumpsLimited: do fraction; if time limited: do pulse tvCount ); needUpdateEventProgressBar = true; //update graph PrepareEventGraphJumpReactiveObject = new PrepareEventGraphJumpReactive(lastTv, lastTc, tvString, tcString); needUpdateGraphType = eventType.JUMPREACTIVE; needUpdateGraph = true; //put button_finish as sensitive when first jump is done (there's something recordable) if(tvCount == 1) needSensitiveButtonFinish = true; //save temp table if needed countForSavingTempTable ++; if(countForSavingTempTable == timesForSavingRepetitive) { writeRj(true); //tempTable countForSavingTempTable = 0; } } } } //if we finish by time, and allowFinishAfterTime == true, when time passed, if the jumper is jumping //if flags the shouldFinishAtNextFall that will finish when he arrives to the platform if(shouldFinishAtNextFall && platformState == Chronopic.Plataforma.ON && loggedState == States.OFF) finish = true; //check if reactive jump should finish if (jumpsLimited) { if(limitAsDouble != -1) { if(Util.GetNumberOfJumps(tvString, false) >= limitAsDouble) { writeRj(false); //tempTable success = true; //update event progressbar //app1.ProgressBarEventOrTimePreExecution( updateProgressBar= new UpdateProgressBar ( true, //isEvent true, //percentageMode tvCount ); needUpdateEventProgressBar = true; //update graph PrepareEventGraphJumpReactiveObject = new PrepareEventGraphJumpReactive(lastTv, lastTc, tvString, tcString); needUpdateGraphType = eventType.JUMPREACTIVE; needUpdateGraph = true; } } } else { //limited by time, if passed it, write if(success) { //write(); //write only if there's a jump at minimum if(Util.GetNumberOfJumps(tcString, false) >= 1 && Util.GetNumberOfJumps(tvString, false) >= 1) { writeRj(false); //tempTable } else { //cancel a jump if clicked finish before any events done cancel = true; } } } /* EndingConditionsJumpRj conditions = new EndingConditionsJumpRj(); if(! conditionsOk(tv,tc)) { finish = true; posar MARCA de que les conditions no estan be i després mostrar quines */ if(platformState == Chronopic.Plataforma.OFF) loggedState = States.OFF; else loggedState = States.ON; } } while ( ! success && ! cancel && ! finish ); if (finish) { //write only if there's a jump at minimum if(Util.GetNumberOfJumps(tcString, false) >= 1 && Util.GetNumberOfJumps(tvString, false) >= 1) { writeRj(false); //tempTable totallyFinished = true; } else { //cancel a jump if clicked finish before any events done cancel = true; } } //if(cancel || finish) { if(cancel) { //event will be raised, and managed in chronojump.cs fakeButtonFinished.Click(); totallyCancelled = true; } }