-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDatapoint.pde
More file actions
155 lines (138 loc) · 3.45 KB
/
Datapoint.pde
File metadata and controls
155 lines (138 loc) · 3.45 KB
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
public class Datapoint
{
/**
* Datapoint class which stores weather data for a particular
* point in time.
* Parses through a single string line from a text file.
* The string must be delimited by commas and contain no spaces.
* @author Charlie
**/
private String rawDate; // GMT
private String maxTemp; // C
private String meanTemp; // C
private String minTemp;// C
private String maxPressure; // hPa
private String meanPressure; // hPa
private String minPressure; // hPa
private String maxWindSpeed; // km/hr
private String meanWindSpeed; // km/hr
private float precipitation; // mm
private String events; // ?
private String windDirection; // degrees
private float cloudCover; // X out of 10, i.e. 8/10 = overcast.
// A single line of a text file is passed
// to the constructor and column formatting.
// @param line Line of text file
// @param columns Array list of ints that correspond
// to file column formatting
public Datapoint(String line, int[] columns)
{
String[] data = split(line, ",");
try
{
rawDate = data[columns[0]];
}catch(IndexOutOfBoundsException e){rawDate = " - ";}
try
{
maxTemp = data[columns[1]];
}catch(IndexOutOfBoundsException e){maxTemp = " - ";}
try
{
meanTemp = data[columns[2]];
}catch(IndexOutOfBoundsException e){meanTemp = " - ";}
try
{
minTemp = data[columns[3]];
}catch(IndexOutOfBoundsException e){minTemp = " - ";}
try
{
maxPressure = data[columns[4]];
}catch(IndexOutOfBoundsException e){maxPressure = " - ";}
try
{
meanPressure = data[columns[5]];
}catch(IndexOutOfBoundsException e){meanPressure = " - ";}
try
{
minPressure = data[columns[6]];
}catch(IndexOutOfBoundsException e){minPressure = " - ";}
try
{
maxWindSpeed = data[columns[7]];
}catch(IndexOutOfBoundsException e){maxWindSpeed = " - ";}
try
{
meanWindSpeed = data[columns[8]];
}catch(IndexOutOfBoundsException e){meanWindSpeed = " - ";}
try
{
precipitation = Float.parseFloat(data[columns[9]]);
}catch(IndexOutOfBoundsException e){precipitation = -1;}
try
{
events = data[columns[10]];
}catch(IndexOutOfBoundsException e){events = " - ";}
try
{
windDirection = data[columns[11]];
}catch(IndexOutOfBoundsException e){windDirection = " - ";}
try
{
cloudCover = Float.parseFloat(data[columns[12]]);
}catch(IndexOutOfBoundsException e){cloudCover = -1;}
catch(NumberFormatException e){cloudCover = -1;}
}
// Getters for variables
public String getRawDate()
{
return rawDate;
}
public String getMaxTemp()
{
return maxTemp;
}
public String getMeanTemp()
{
return meanTemp;
}
public String getMinTemp()
{
return minTemp;
}
public String getMaxPressure()
{
return maxPressure;
}
public String getMeanPressure()
{
return meanPressure;
}
public String getMinPressure()
{
return minPressure;
}
public String getMaxWindSpeed()
{
return maxWindSpeed;
}
public String getMeanWindSpeed()
{
return meanWindSpeed;
}
public float getPrecipitation()
{
return precipitation;
}
public String getEvents()
{
return events;
}
public String getWindDirection()
{
return windDirection;
}
public float getCloudCover()
{
return cloudCover;
}
}