-
Notifications
You must be signed in to change notification settings - Fork 7
/
run.cs
379 lines (327 loc) · 10.2 KB
/
run.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
/*
* This file is part of ChronoJump
*
* ChronoJump is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* ChronoJump is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Copyright (C) 2004-2022 Xavier de Blas <xaviblas@gmail.com>
*/
using System;
using System.Data;
using System.IO; //for detect OS //TextWriter
using System.Collections.Generic; //List
using System.Threading;
using Mono.Unix;
public class Run : Event
{
protected double distance;
protected double time;
//for not checking always in database
protected bool startIn;
protected bool initialSpeed;
//protected Chronopic cp;
protected bool metersSecondsPreferred;
protected string datetime;
/*
//used by the updateTimeProgressBar for display its time information
//changes a bit on runSimple and runInterval
//explained at each of the updateTimeProgressBar()
protected enum runPhases {
PRE_RUNNING, PLATFORM_INI, RUNNING, PLATFORM_END
}
protected runPhases runPhase;
*/
public Run() {
}
//after inserting database (SQL)
public Run(int uniqueID, int personID, int sessionID, string type, double distance, double time, string description, int simulated, bool initialSpeed, string datetime)
{
this.uniqueID = uniqueID;
this.personID = personID;
this.sessionID = sessionID;
this.type = type;
this.distance = distance;
this.time = time;
this.description = description;
this.simulated = simulated;
this.initialSpeed = initialSpeed;
this.datetime = datetime;
}
//used to select a run at SqliteRun.SelectRunData and at Sqlite.convertTables
public Run(string [] eventString)
{
this.uniqueID = Convert.ToInt32(eventString[0]);
this.personID = Convert.ToInt32(eventString[1]);
this.sessionID = Convert.ToInt32(eventString[2]);
this.type = eventString[3].ToString();
this.distance = Convert.ToDouble(Util.ChangeDecimalSeparator(eventString[4]));
this.time = Convert.ToDouble(Util.ChangeDecimalSeparator(eventString[5]));
this.description = eventString[6].ToString();
this.simulated = Convert.ToInt32(eventString[7]);
this.initialSpeed = Util.IntToBool(Convert.ToInt32(eventString[8]));
this.datetime = eventString[9];
}
public static List<Event> RunListToEventList(List<Run> runs)
{
List<Event> events = new List<Event>();
foreach(Run run in runs)
events.Add((Event) run);
return events;
}
public override int InsertAtDB (bool dbconOpened, string tableName) {
return SqliteRun.Insert(dbconOpened, tableName,
uniqueID.ToString(),
personID, sessionID,
type, distance, time,
description, simulated, initialSpeed, datetime);
}
public override string ToString() {
return uniqueID + ":" + personID + ":" + sessionID + ":" + type + ":" + distance + ":" + time + ":" + datetime + ":" + description + ":" + simulated + ":" + initialSpeed;
}
public virtual double Speed
{
get {
if(metersSecondsPreferred) {
return distance / time ;
} else {
return (distance / time) * 3.6 ;
}
}
}
public double Distance
{
get { return distance; }
set { distance = value; }
}
public double Time
{
get { return time; }
set { time = value; }
}
public bool MetersSecondsPreferred {
set { metersSecondsPreferred = value; }
}
public bool InitialSpeed
{
get { return initialSpeed; }
set { initialSpeed = value; }
}
public string Datetime {
get { return datetime; }
set { datetime = value; }
}
~Run() {}
}
public class RunInterval : Run
{
double distanceTotal;
double timeTotal;
double distanceInterval;
string intervalTimesString;
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)
private List<int> photocell_l;
public RunInterval() {
}
//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, int simulated, bool initialSpeed, string datetime, List<int> photocell_l)
{
this.uniqueID = uniqueID;
this.personID = personID;
this.sessionID = sessionID;
this.type = type;
this.distanceTotal = distanceTotal;
this.timeTotal = timeTotal;
this.distanceInterval = distanceInterval;
this.intervalTimesString = intervalTimesString;
this.tracks = tracks;
this.description = description;
this.limited = limited;
this.simulated = simulated;
this.initialSpeed = initialSpeed;
this.datetime = datetime;
this.photocell_l = photocell_l;
}
//used to select a run at SqliteRun.SelectIntervalRunData and at Sqlite.convertTables
public RunInterval(string [] eventString)
{
this.uniqueID = Convert.ToInt32(eventString[0]);
this.personID = Convert.ToInt32(eventString[1]);
this.sessionID = Convert.ToInt32(eventString[2]);
this.type = eventString[3].ToString();
this.distanceTotal = Convert.ToDouble(Util.ChangeDecimalSeparator(eventString[4]));
this.timeTotal = Convert.ToDouble(Util.ChangeDecimalSeparator(eventString[5]));
this.distanceInterval = Convert.ToDouble(Util.ChangeDecimalSeparator(eventString[6]));
this.intervalTimesString = Util.ChangeDecimalSeparator(eventString[7]);
this.tracks = Convert.ToDouble(Util.ChangeDecimalSeparator(eventString[8]));
this.description = eventString[9].ToString();
this.limited = eventString[10].ToString();
this.simulated = Convert.ToInt32(eventString[11]);
this.initialSpeed = Util.IntToBool(Convert.ToInt32(eventString[12]));
this.datetime = eventString[13];
this.photocell_l = Util.SQLStringToListInt(eventString[14], ";");
}
public static List<Event> RunIntervalListToEventList(List<RunInterval> runsI)
{
List<Event> events = new List<Event>();
foreach(RunInterval runI in runsI)
events.Add((Event) runI);
return events;
}
public override int InsertAtDB (bool dbconOpened, string tableName) {
return SqliteRunInterval.Insert(dbconOpened, tableName,
uniqueID.ToString(),
personID, sessionID,
type, distanceTotal, timeTotal,
distanceInterval, intervalTimesString,
tracks, description,
limited, simulated, initialSpeed, datetime, photocell_l);
}
//to debug
public override string ToString()
{
return string.Format("uniqueID: {0}, personID: {1}, sessionID: {2}, " +
"type: {3}, distanceTotal: {4}, timeTotal: {5}, " +
"distanceInterval: {6}, intervalTimesString: {7}, " +
"tracks: {8}, description: {9}, " +
"limited: {10}, simulated: {11}, initialSpeed: {12}, " +
"datetime: {13}, photocell_l: {14}",
uniqueID, personID, sessionID,
type, distanceTotal, timeTotal,
distanceInterval, intervalTimesString,
tracks, description,
limited, simulated, initialSpeed, datetime, photocell_l);
}
//this discards RSA
public static string GetSprintPositions(double distanceInterval, string intervalTimesString, string distancesString)
{
string positions = "";
string [] intervalTimesSplit = intervalTimesString.Split(new char[] {'='});
if(! distancesString.Contains("R") ) //discard RSA
{
string sep = "";
for(int i=0; i < intervalTimesSplit.Length; i ++)
{
positions += sep + Util.GetRunITotalDistance(distanceInterval, distancesString, i+1);
sep = ";";
}
//format positions
positions = Util.ChangeChars(positions, "-", ";");
}
return positions;
}
public static string GetSplitTimes(string intervalTimesString, int prefsDigitsNumber)
{
string [] intervalTimesSplit = intervalTimesString.Split(new char[] {'='});
//manage accumulated time
double timeAccumulated = 0;
string splitTimes = "";
string sep = "";
foreach(string time in intervalTimesSplit)
{
double timeD = Convert.ToDouble(time);
timeAccumulated += timeD;
splitTimes += sep + Util.TrimDecimals(timeAccumulated, prefsDigitsNumber);
sep = ";";
}
return splitTimes;
}
private List<double> timeList
{
get {
List<double> l = new List<double>();
string [] strFull = intervalTimesString.Split(new char[] {'='});
foreach(string str in strFull)
{
if(Util.IsNumber(Util.ChangeDecimalSeparator(str), true))
l.Add(Convert.ToDouble(Util.ChangeDecimalSeparator(str)));
}
return l;
}
}
public double TimeLast
{
get {
if(timeList == null || timeList.Count == 0)
return 0;
else
return timeList[timeList.Count -1];
}
}
public static string GetCSVInputMulti() {
return Path.Combine(Path.GetTempPath(), "sprintInputMulti.csv");
}
public static string GetCSVResultsFileName() {
return "sprintResults.csv";
}
public static string GetCSVResultsURL() {
return Path.Combine(Path.GetTempPath(), GetCSVResultsFileName());
}
public string IntervalTimesString
{
get { return intervalTimesString; }
set { intervalTimesString = value; }
}
public double DistanceInterval
{
get { return distanceInterval; }
set { distanceInterval = value; }
}
public double DistanceTotal
{
get { return distanceTotal; }
set { distanceTotal = value; }
}
public double TimeTotal
{
get { return timeTotal; }
set { timeTotal = value; }
}
public double Tracks
{
get { return tracks; }
set { tracks = value; }
}
public string Limited
{
get { return limited; }
set { limited = value; }
}
public bool StartIn
{
get { return startIn; }
}
public override double Speed
{
get {
//if(metersSecondsPreferred) {
return distanceTotal / timeTotal ;
/*} else {
return (distanceTotal / timeTotal) * 3.6 ;
}
*/
}
}
public List<int> Photocell_l
{
get { return photocell_l; }
}
/*
public string Photocell_l_str
{
get { return Util.ListIntToSQLString (photocell_l, ";"); }
}
*/
~RunInterval() {}
}