Revize 260b1217
Přidáno uživatelem Alex Konig před asi 4 roky(ů)
Server/ServerApp/Parser/Parsers/JisParser.cs | ||
---|---|---|
39 | 39 |
loadedData = ProcessOneJisFileAsDays(fileName); |
40 | 40 |
// parse by interval length |
41 | 41 |
else |
42 |
{ |
|
43 |
// pokud: konec dne nebo konec aktuálního intervalu -> vemu to co sem nasčítal |
|
44 |
throw new NotImplementedException(); |
|
45 |
} |
|
42 |
loadedData = ProcessOneJisFileAsIntervals(fileName, interval); |
|
46 | 43 |
|
47 | 44 |
list.AddRange(loadedData); |
48 | 45 |
} |
... | ... | |
125 | 122 |
|
126 | 123 |
private static List<ActivityInfo> ProcessOneJisFileAsIntervals(string path, int interval) |
127 | 124 |
{ |
128 |
throw new NotImplementedException(); |
|
125 |
if (!File.Exists(path)) |
|
126 |
return null; |
|
127 |
|
|
128 |
List<ActivityInfo> jisInfo = new List<ActivityInfo>(); |
|
129 |
List<JisInstance> list = CsvDataLoader.LoadJisFile(path); |
|
130 |
|
|
131 |
// data for each faculty |
|
132 |
int[] recordedAmount = new int[TagInfo.faculties.Length]; |
|
133 |
// min/max hour taken into account |
|
134 |
int[] minmaxHour = new int[] { 7, 18 }; |
|
135 |
int range = minmaxHour[1] - minmaxHour[0]; |
|
136 |
|
|
137 |
if (interval > range) |
|
138 |
return null; |
|
139 |
|
|
140 |
int indices = (int) Math.Ceiling(range / (double)interval); |
|
141 |
int[] from = new int[indices]; |
|
142 |
for (int i = 0; i < from.Length; i++) { |
|
143 |
from[i] = minmaxHour[0] + interval * (i+1); |
|
144 |
Console.Write(from[i] + " "); |
|
145 |
} |
|
146 |
Console.WriteLine(); |
|
147 |
|
|
148 |
// first day |
|
149 |
DateTime lastStartTime = new DateTime(list[0].dateTime.Year, list[0].dateTime.Month, list[0].dateTime.Day, minmaxHour[0], 0, 0); |
|
150 |
for (int i = 0; i < list.Count; i++) |
|
151 |
{ |
|
152 |
int currHour = list[i].dateTime.Hour; |
|
153 |
if (currHour < minmaxHour[0] || currHour > minmaxHour[1]) |
|
154 |
continue; |
|
155 |
|
|
156 |
// start of the day -> make an instance |
|
157 |
string place = list[i].placeTag; |
|
158 |
bool trigger = false; |
|
159 |
DateTime date = new DateTime(list[i].dateTime.Year, list[i].dateTime.Month, list[i].dateTime.Day, list[i].dateTime.Hour, 0, 0); |
|
160 |
|
|
161 |
// end of the day |
|
162 |
if (!(date.Year == lastStartTime.Year && date.Month == lastStartTime.Month && date.Day == lastStartTime.Day)) |
|
163 |
trigger = true; |
|
164 |
|
|
165 |
// end of interval period |
|
166 |
if ( (date.Hour - lastStartTime.Hour) >= interval || trigger) |
|
167 |
{ |
|
168 |
// data for each faculty separate |
|
169 |
for (int k = 0; k < TagInfo.faculties.Length; k++) |
|
170 |
{ |
|
171 |
ActivityInfo dayInfo = new ActivityInfo(TagInfo.faculties[k], recordedAmount[k], lastStartTime, interval); |
|
172 |
jisInfo.Add(dayInfo); |
|
173 |
} |
|
174 |
|
|
175 |
recordedAmount = new int[TagInfo.faculties.Length]; |
|
176 |
lastStartTime = date; |
|
177 |
} |
|
178 |
|
|
179 |
// aggregate data |
|
180 |
if (TagInfo.jisPlaces.ContainsKey(place)) |
|
181 |
{ |
|
182 |
int index = TagInfo.jisPlaces[place]; |
|
183 |
if (index == -1) |
|
184 |
for (int l = 0; l < TagInfo.faculties.Length; l++) |
|
185 |
recordedAmount[l] += list[i].amount; |
|
186 |
else |
|
187 |
recordedAmount[index] += list[i].amount; |
|
188 |
|
|
189 |
} |
|
190 |
else |
|
191 |
{ |
|
192 |
// TODO uknown code handling |
|
193 |
Console.WriteLine("Unknown code " + list[i].placeTag); |
|
194 |
} |
|
195 |
|
|
196 |
} |
|
197 |
|
|
198 |
// last day |
|
199 |
for (int k = 0; k < TagInfo.faculties.Length; k++) |
|
200 |
{ |
|
201 |
ActivityInfo dayInfo = new ActivityInfo(TagInfo.faculties[k], recordedAmount[k], lastStartTime, interval); |
|
202 |
jisInfo.Add(dayInfo); |
|
203 |
} |
|
204 |
|
|
205 |
return jisInfo; |
|
129 | 206 |
} |
130 | 207 |
} |
131 | 208 |
} |
Také k dispozici: Unified diff
re #8610 Parsing in intervals dependand on data