forked from GNOME/chronojump
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pulse.cs
118 lines (99 loc) · 3.34 KB
/
pulse.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
/*
* 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-2009 Xavier de Blas <xaviblas@gmail.com>
*/
using System;
using System.Data;
using Mono.Unix;
public class Pulse : Event
{
double fixedPulse;
int totalPulsesNum;
string timesString;
int tracks;
double contactTime;
//used on treeviewPulse
public Pulse() {
}
//after inserting database (SQL)
public Pulse(int uniqueID, int personID, int sessionID, string type, double fixedPulse,
int totalPulsesNum, string timesString, string description, int simulated)
{
this.uniqueID = uniqueID;
this.personID = personID;
this.sessionID = sessionID;
this.type = type;
this.fixedPulse = fixedPulse;
this.totalPulsesNum = totalPulsesNum;
this.timesString = timesString;
this.description = description;
this.simulated = simulated;
}
//used to select a event at SqlitePulse.SelectPulseData and at Sqlite.convertTables
public Pulse(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.fixedPulse = Convert.ToDouble(Util.ChangeDecimalSeparator(eventString[4]));
this.totalPulsesNum = Convert.ToInt32(eventString[5]);
this.timesString = eventString[6].ToString();
this.description = eventString[7].ToString();
this.simulated = Convert.ToInt32(eventString[8]);
}
public override int InsertAtDB (bool dbconOpened, string tableName) {
return SqlitePulse.Insert(dbconOpened, tableName,
uniqueID.ToString(),
personID, sessionID,
type, fixedPulse, totalPulsesNum, timesString,
description, simulated);
}
//called from treeViewPulse
public double GetErrorAverage(bool relative)
{
double pulseToComparate = Convert.ToDouble(Util.GetAverage(timesString));
string [] myStringFull = timesString.Split(new char[] {'='});
string myErrors = "";
string separatorString = "";
double error = 0;
foreach (string myPulse in myStringFull) {
if(relative)
error = (Convert.ToDouble(myPulse) - pulseToComparate) *100 / pulseToComparate;
else
error = Convert.ToDouble(myPulse) - pulseToComparate;
//all the values should be positive
if (error < 0)
error = error * -1;
myErrors += separatorString + error.ToString();
separatorString = "=";
}
return Util.GetAverage(myErrors);
}
public double FixedPulse {
get { return fixedPulse; }
set { fixedPulse = value; }
}
public int TotalPulsesNum {
set { totalPulsesNum = value; }
}
public string TimesString {
get { return timesString; }
set { timesString = value; }
}
~Pulse() {}
}