Revize fffe7190
Přidáno uživatelem Alex Konig před více než 3 roky(ů)
Server/ServerApp/Parser/Parsers/DataParser.cs | ||
---|---|---|
82 | 82 |
var jisFiles = downloader.GetData(pathJis, start, end); |
83 | 83 |
var loginFiles = downloader.GetData(pathLogIn, start, end); |
84 | 84 |
|
85 |
WeatherDataUsed = new List<string>(); |
|
86 |
ActivityDataUsed = new List<string>(); |
|
87 |
|
|
88 |
WeatherDataUsed.AddRange(weatherFiles); |
|
89 |
ActivityDataUsed.AddRange(jisFiles); |
|
90 |
ActivityDataUsed.AddRange(loginFiles); |
|
91 |
|
|
85 | 92 |
WeatherList = weatherParser.ParseWeatherData(weatherFiles, startTime, endTime, wholeDay, interval); |
86 | 93 |
jisList = jisParser.ParseJisData(jisFiles, startTime, endTime, wholeDay, interval); |
87 | 94 |
loginList = loginParser.ParseLogInData(loginFiles, startTime, endTime, wholeDay, interval); |
Server/ServerApp/Parser/Parsers/IDataParser.cs | ||
---|---|---|
21 | 21 |
List<ActivityInfo> attendanceList; |
22 | 22 |
public List<ActivityInfo> AttendanceList { get => attendanceList; internal set => attendanceList = value; } |
23 | 23 |
|
24 |
/// <summary> List of weather file names the parser was last used on </summary> |
|
25 |
List<String> weatherdataUsed; |
|
26 |
public List<string> WeatherDataUsed { get => weatherdataUsed; set => weatherdataUsed = value; } |
|
27 |
|
|
28 |
/// <summary> List of activity file names the parser was last used on </summary> |
|
29 |
List<String> activitydataUsed; |
|
30 |
public List<string> ActivityDataUsed { get => activitydataUsed; set => activitydataUsed = value; } |
|
31 |
|
|
32 |
|
|
24 | 33 |
/// <summary> |
25 | 34 |
/// Parse data |
26 | 35 |
/// </summary> |
Server/ServerApp/Program.cs | ||
---|---|---|
1 | 1 |
using ServerApp.Connection; |
2 | 2 |
using ServerApp.Connection.XMLProtocolHandler; |
3 | 3 |
using ServerApp.DataDownload; |
4 |
using ServerApp.Parser.OutputInfo; |
|
4 | 5 |
using ServerApp.Parser.Parsers; |
5 | 6 |
using ServerApp.Predictor; |
6 | 7 |
using ServerApp.User; |
... | ... | |
136 | 137 |
JsonParser jsonP = new JsonParser(null); |
137 | 138 |
jsonP.ParsePrediction(); |
138 | 139 |
|
140 |
var res = jsonP.GetPredictionForTime(jsonP.Predictions[5].startTime, jsonP.Predictions[20].startTime); |
|
141 |
Console.WriteLine("from " + jsonP.Predictions[5].startTime); |
|
142 |
Console.WriteLine("end " + jsonP.Predictions[20].startTime); |
|
143 |
foreach (WeatherInfo w in res) |
|
144 |
Console.WriteLine(w.ToString()); |
|
145 |
|
|
146 |
|
|
139 | 147 |
// TODO nastavit čas |
140 | 148 |
IDataParser p = new DataParser(dd); |
141 | 149 |
IPredictionController predictionController = new PredictionController(p); |
Server/ServerApp/WeatherPredictionParser/IJsonParser.cs | ||
---|---|---|
3 | 3 |
// |
4 | 4 |
|
5 | 5 |
using ServerApp.Parser.OutputInfo; |
6 |
using System; |
|
6 | 7 |
using System.Collections.Generic; |
7 | 8 |
|
8 | 9 |
namespace ServerApp.WeatherPredictionParser |
... | ... | |
15 | 16 |
|
16 | 17 |
/// <summary> Current weather </summary> |
17 | 18 |
WeatherInfo current; |
18 |
public WeatherInfo Current { get => current; } |
|
19 |
public WeatherInfo Current { get => current; set => current = value; }
|
|
19 | 20 |
|
20 | 21 |
/// <summary> Prediction for today, tommorrow and day after tommorrow </summary> |
21 | 22 |
List<WeatherInfo> predictions; |
... | ... | |
27 | 28 |
/// </summary> |
28 | 29 |
abstract public void ParsePrediction(); |
29 | 30 |
|
31 |
/// <summary> |
|
32 |
/// Get predictions from Predictions that are within specified time span |
|
33 |
/// </summary> |
|
34 |
/// <param name="from">DateTime from</param> |
|
35 |
/// <param name="to">DateTime to</param> |
|
36 |
/// <returns>List of predictions that fit specified criteria</returns> |
|
37 |
abstract public List<WeatherInfo> GetPredictionForTime(DateTime from, DateTime to); |
|
38 |
|
|
30 | 39 |
} |
31 | 40 |
|
32 | 41 |
} |
Server/ServerApp/WeatherPredictionParser/JsonParser.cs | ||
---|---|---|
20 | 20 |
/// <author>A. Konig</author> |
21 | 21 |
class JsonParser : IJsonParser |
22 | 22 |
{ |
23 |
/// <summary> Current weather </summary> |
|
24 |
WeatherInfo current; |
|
25 |
public new WeatherInfo Current { get => current; } |
|
26 |
/// <summary> Prediction for today, tommorrow and day after tommorrow </summary> |
|
27 |
List<WeatherInfo> predictions; |
|
28 |
public new List<WeatherInfo> Predictions { get => predictions; set => predictions = value; } |
|
29 |
|
|
30 | 23 |
/// <summary> Data loader </summary> |
31 | 24 |
DataDownloader loader; |
32 | 25 |
/// <summary> Currently parsed day </summary> |
... | ... | |
46 | 39 |
this.loader = loader; |
47 | 40 |
} |
48 | 41 |
|
42 |
/// <summary> |
|
43 |
/// Get predictions from Predictions that are within specified time span |
|
44 |
/// From-to including |
|
45 |
/// If from == null then all until to |
|
46 |
/// If to == null then all starting from from |
|
47 |
/// </summary> |
|
48 |
/// <param name="from">DateTime from</param> |
|
49 |
/// <param name="to">DateTime to</param> |
|
50 |
/// <returns>List of predictions that fit specified criteria or null if incorrect input</returns> |
|
51 |
public override List<WeatherInfo> GetPredictionForTime(DateTime from, DateTime to) |
|
52 |
{ |
|
53 |
if (Predictions == null) |
|
54 |
return null; |
|
55 |
|
|
56 |
List<WeatherInfo> res = new List<WeatherInfo>(); |
|
57 |
|
|
58 |
if (from == null) |
|
59 |
from = Predictions[0].startTime; |
|
60 |
|
|
61 |
if (to == null) |
|
62 |
from = Predictions[Predictions.Count].startTime; |
|
63 |
|
|
64 |
if (from > to) |
|
65 |
return null; |
|
66 |
|
|
67 |
foreach (WeatherInfo pred in Predictions) |
|
68 |
{ |
|
69 |
int hour = pred.startTime.Hour + pred.intervalLength; |
|
70 |
Console.WriteLine(pred.intervalLength); |
|
71 |
bool addDay = false; |
|
72 |
if (hour >= 24) |
|
73 |
{ |
|
74 |
hour -= 24; |
|
75 |
addDay = true; |
|
76 |
} |
|
77 |
DateTime endTime = new DateTime(pred.startTime.Year, pred.startTime.Month, pred.startTime.Day, hour, pred.startTime.Minute, pred.startTime.Second); |
|
78 |
if (addDay) |
|
79 |
endTime = endTime.AddDays(1); |
|
80 |
|
|
81 |
// if both end and start not outside of interval |
|
82 |
if (!((pred.startTime < from && endTime <= from) || (pred.startTime > to && endTime >= to))) |
|
83 |
res.Add(pred); |
|
84 |
} |
|
85 |
|
|
86 |
return res; |
|
87 |
} |
|
88 |
|
|
49 | 89 |
/// <summary> |
50 | 90 |
/// Parse weather prediction |
51 | 91 |
/// Results is in attributes current for current weather and pred for weather prediction for today, tommorrow and day after tommorrow |
... | ... | |
59 | 99 |
DateTime now = DateTime.Now; |
60 | 100 |
Console.WriteLine(File.Exists(file)); |
61 | 101 |
|
62 |
current = new WeatherInfo();
|
|
63 |
predictions = new List<WeatherInfo>();
|
|
102 |
Current = new WeatherInfo();
|
|
103 |
Predictions = new List<WeatherInfo>();
|
|
64 | 104 |
|
65 | 105 |
if (!File.Exists(file)) |
66 | 106 |
return; |
... | ... | |
84 | 124 |
case "current_condition": |
85 | 125 |
{ |
86 | 126 |
ArrayEnumerator currentWeather = weatherP.Current.Value.EnumerateArray(); |
87 |
current = ParseCurrentWeather(currentWeather);
|
|
127 |
Current = ParseCurrentWeather(currentWeather);
|
|
88 | 128 |
|
89 | 129 |
break; |
90 | 130 |
} |
... | ... | |
110 | 150 |
/// </summary> |
111 | 151 |
private void TestConsoleOutput() |
112 | 152 |
{ |
113 |
Console.WriteLine(current);
|
|
114 |
foreach (WeatherInfo w in predictions)
|
|
153 |
Console.WriteLine(Current);
|
|
154 |
foreach (WeatherInfo w in Predictions)
|
|
115 | 155 |
Console.WriteLine(w); |
116 | 156 |
} |
117 | 157 |
|
... | ... | |
137 | 177 |
private void EncompassSunRiseSetTimes() |
138 | 178 |
{ |
139 | 179 |
// change current weather |
140 |
if ((current.startTime.TimeOfDay > sunsetTime.TimeOfDay) || (current.startTime.TimeOfDay < sunriseTime.TimeOfDay))
|
|
141 |
current.condition = WeatherConditions.Dark;
|
|
180 |
if ((Current.startTime.TimeOfDay > sunsetTime.TimeOfDay) || (Current.startTime.TimeOfDay < sunriseTime.TimeOfDay))
|
|
181 |
Current.condition = WeatherConditions.Dark;
|
|
142 | 182 |
|
143 | 183 |
// change prediction |
144 |
for (int i = 0; i < predictions.Count - 1; i++)
|
|
184 |
for (int i = 0; i < Predictions.Count - 1; i++)
|
|
145 | 185 |
{ |
146 |
WeatherInfo w = predictions[i];
|
|
147 |
WeatherInfo wNext = predictions[i + 1];
|
|
186 |
WeatherInfo w = Predictions[i];
|
|
187 |
WeatherInfo wNext = Predictions[i + 1];
|
|
148 | 188 |
|
149 | 189 |
// if wNext time < than w time then it is prediction from the next day -> add 24 to correctly calculate timespan |
150 | 190 |
int timespan = wNext.startTime.Hour - w.startTime.Hour; |
... | ... | |
178 | 218 |
} |
179 | 219 |
|
180 | 220 |
// last prediction |
181 |
WeatherInfo wLast = predictions[predictions.Count - 1];
|
|
221 |
WeatherInfo wLast = Predictions[Predictions.Count - 1];
|
|
182 | 222 |
TimeSpan endTimeW = new TimeSpan(24, 0, 0); |
183 |
int timespanLast = endTimeW.Hours - wLast.startTime.Hour;
|
|
223 |
int timespanLast = 24 - wLast.startTime.Hour;
|
|
184 | 224 |
wLast.intervalLength = timespanLast; |
185 | 225 |
|
186 | 226 |
// if start under sunset |
... | ... | |
338 | 378 |
} |
339 | 379 |
|
340 | 380 |
// Console.WriteLine(weather.ToString()); |
341 |
predictions.Add(weather);
|
|
381 |
Predictions.Add(weather);
|
|
342 | 382 |
|
343 | 383 |
} |
344 | 384 |
|
... | ... | |
401 | 441 |
return res; |
402 | 442 |
} |
403 | 443 |
|
444 |
|
|
404 | 445 |
} |
405 | 446 |
} |
Také k dispozici: Unified diff
re #8962 Adding filtering method GetPredictionForTime to json parser + adding attributes with file names to DataParser + fixing bug in json parser method Parse