Revize 127a92b1
Přidáno uživatelem Eliška Mourycová před téměř 4 roky(ů)
Server/ServerApp/Connection/ConnectionListener.cs | ||
---|---|---|
5 | 5 |
using ServerApp.Connection.XMLProtocolHandler; |
6 | 6 |
using ServerApp.Predictor; |
7 | 7 |
using System; |
8 |
using System.Collections.Concurrent; |
|
9 |
using System.Collections.Generic; |
|
10 |
using System.Diagnostics; |
|
11 | 8 |
using System.IO; |
12 | 9 |
using System.Net; |
13 | 10 |
using System.Reflection; |
14 | 11 |
using System.Net.Sockets; |
15 |
using System.Text; |
|
16 |
using System.Threading; |
|
17 | 12 |
using System.Web; |
18 | 13 |
using System.Security.Cryptography.X509Certificates; |
19 | 14 |
using log4net; |
... | ... | |
337 | 332 |
|
338 | 333 |
} |
339 | 334 |
|
340 |
|
|
335 |
/// <summary> |
|
336 |
/// UNUSED |
|
337 |
/// This method should modify the input time span if it is longer than mxTimeSpan given in days. |
|
338 |
/// </summary> |
|
339 |
/// <param name="startDate">The start of the time span</param> |
|
340 |
/// <param name="endDate">The end of the time span</param> |
|
341 |
/// <param name="maxTimeSpan">The maximum length of the time span in days</param> |
|
342 |
/// <returns>New end date if it is more than maxTimeSpan away from start date, original endDate otherwise.</returns> |
|
341 | 343 |
public XMLProtocolHandler.Date CheckTimeSpanModifyEnd(Date startDate, Date endDate, int maxTimeSpan) |
342 | 344 |
{ |
343 | 345 |
int comp = startDate.CompareTo(endDate); // -1 if start date lower |
... | ... | |
358 | 360 |
catch(ArgumentOutOfRangeException aore) |
359 | 361 |
{ |
360 | 362 |
// hopefully the predictor will know what to do |
363 |
logger.Debug("Wrong type of date passed to time span checking, argument out of range."); |
|
364 |
logger.Debug("Start date: " + startDate.ToString()); |
|
365 |
logger.Debug("End date: " + endDate.ToString()); |
|
366 |
logger.Debug(aore.Message); |
|
361 | 367 |
return endDate; |
362 | 368 |
} |
363 | 369 |
|
Server/ServerApp/DataDownload/DataDownloader.cs | ||
---|---|---|
90 | 90 |
CreateSubdirectories(); // todo should we do it like this? |
91 | 91 |
|
92 | 92 |
webClient = new WebClient(); |
93 |
|
|
94 |
logger.Info("Data downlader ready."); |
|
93 | 95 |
} |
94 | 96 |
|
95 | 97 |
/// <summary> |
... | ... | |
114 | 116 |
// this shouldn't happen |
115 | 117 |
//Console.WriteLine("Weather prediction download failed!"); |
116 | 118 |
logger.Error("Weather prediction download failed!"); |
119 |
logger.Error(e.Message); |
|
117 | 120 |
return null; |
118 | 121 |
} |
119 | 122 |
|
... | ... | |
280 | 283 |
try |
281 | 284 |
{ |
282 | 285 |
//Console.WriteLine("Downloading .zip to " + Path.GetFullPath(nameZip) + "..."); |
286 |
logger.Info("Trying to download " + url); |
|
283 | 287 |
|
284 | 288 |
// Download the zip file: |
285 | 289 |
webClient.DownloadFile(url, nameZip); |
... | ... | |
332 | 336 |
catch(System.Net.WebException we) |
333 | 337 |
{ |
334 | 338 |
// download fails, if the specified url is invalid |
335 |
//Console.WriteLine("Download from " + url + " failed."); |
|
336 |
//Console.WriteLine(we.Message); |
|
339 |
logger.Info("Download of " + url + " was not succesful. That is no problem if the given time span does not contain respective open data."); |
|
340 |
logger.Info(we.Message); |
|
341 |
|
|
337 | 342 |
} |
338 | 343 |
|
339 | 344 |
|
... | ... | |
404 | 409 |
return savedFiles; |
405 | 410 |
} |
406 | 411 |
|
407 |
public bool CheckForNewData() |
|
408 |
{ |
|
409 |
throw new NotImplementedException(); |
|
410 |
} |
|
411 |
|
|
412 | 412 |
|
413 | 413 |
/// <summary> |
414 | 414 |
/// Retrieves all data files with dates falling within the specified range. If not all data for the specified range is found |
Server/ServerApp/Program.cs | ||
---|---|---|
48 | 48 |
} |
49 | 49 |
Console.WriteLine("Config parsing successful."); |
50 | 50 |
|
51 |
//logger.Debug("ahoj"); |
|
52 |
//logger.Warn("ahoj2"); |
|
53 |
//Console.ReadLine(); |
|
54 | 51 |
|
55 | 52 |
// data download init |
56 | 53 |
Console.WriteLine("Downloading open data..."); |
57 | 54 |
DataDownloader dd = DataDownloaderInit(config); |
58 | 55 |
Console.WriteLine("Data downloaded and saved."); |
59 | 56 |
|
60 |
//WeatherAsStringTest(dd); |
|
61 |
//Console.ReadLine(); |
|
62 |
|
|
63 |
// xml building test |
|
64 |
//XMLTest(); |
|
65 |
|
|
66 |
|
|
67 |
// json parser test |
|
68 |
//JSONParserTest(); |
|
69 | 57 |
|
70 | 58 |
// model init |
71 | 59 |
Console.WriteLine("Training the predictor..."); |
... | ... | |
85 | 73 |
|
86 | 74 |
} |
87 | 75 |
|
88 |
|
|
76 |
/// <summary> |
|
77 |
/// Initializes DataDownloader. Downloads default span of data and saves the files. |
|
78 |
/// </summary> |
|
79 |
/// <param name="config">The Config instance</param> |
|
80 |
/// <returns>New instance of DataDownloader</returns> |
|
89 | 81 |
private static DataDownloader DataDownloaderInit(Config config) |
90 | 82 |
{ |
91 |
//test scenario -data download: |
|
83 |
|
|
92 | 84 |
DataDownloader dd = new DataDownloader(config.DataRootDir, config.DataWebsite, config.DownloadedFilesNaming, config.WeatherSite); |
93 | 85 |
dd.OverwriteExisting = false; |
94 | 86 |
List<string> savedFiles = new List<string>(); |
95 | 87 |
|
96 |
// -> 12-2019 to exclude corona? But we lose a lot of data
|
|
88 |
// -> 12-2019 to exclude corona period which could mess with the predictor
|
|
97 | 89 |
savedFiles.AddRange(dd.DownloadData(DataType.JIS, DataFormat.CSV, new DataDownload.Date(1, 2017), new DataDownload.Date(12, 2019))); |
98 | 90 |
savedFiles.AddRange(dd.DownloadData(DataType.STROJE, DataFormat.CSV, new DataDownload.Date(1, 2017), new DataDownload.Date(12, 2019))); |
99 | 91 |
savedFiles.AddRange(dd.DownloadData(DataType.POCASI, DataFormat.CSV, new DataDownload.Date(1, 2017), new DataDownload.Date(12, 2019))); |
... | ... | |
130 | 122 |
} |
131 | 123 |
|
132 | 124 |
|
133 |
private static void XMLTest() |
|
134 |
{ |
|
135 |
Response response = Response.Randomize(); |
|
136 |
var xml = XmlCommunication.Serialize(response); |
|
137 |
//xml = "haha"; |
|
138 |
Response response1 = new Response(); |
|
139 |
Console.WriteLine(xml); |
|
140 |
try |
|
141 |
{ |
|
142 |
Response responseDeserialized = XmlCommunication.Deserialize<Response>(xml); |
|
143 |
} |
|
144 |
catch(Exception e) |
|
145 |
{ |
|
146 |
Console.WriteLine("bad format"); |
|
147 |
} |
|
148 |
|
|
149 |
|
|
150 |
Console.WriteLine("------"); |
|
151 |
|
|
152 |
|
|
153 |
Request request = Request.Randomize(); |
|
154 |
xml = XmlCommunication.Serialize(request); |
|
155 |
Console.WriteLine(xml); |
|
156 |
Request requestDeserialized = XmlCommunication.Deserialize<Request>(xml); |
|
157 |
} |
|
158 |
|
|
159 |
|
|
160 | 125 |
private static void JSONParserTest() |
161 | 126 |
{ |
162 | 127 |
// FIXME pass the right references to the JsonParser constructor |
... | ... | |
175 | 140 |
Console.WriteLine(dd.DownloadWeatherPrediction()); |
176 | 141 |
} |
177 | 142 |
|
143 |
/// <summary> |
|
144 |
/// Initializes and trains the predictor if need be. |
|
145 |
/// </summary> |
|
146 |
/// <param name="dd">The DataDownloader instance.</param> |
|
147 |
/// <returns>New instance of the predictor.</returns> |
|
178 | 148 |
private static IPredictionController PredictionControllerInit(DataDownloader dd) |
179 | 149 |
{ |
180 | 150 |
IDataParser p = new DataParser(dd); |
... | ... | |
187 | 157 |
return predictionController; |
188 | 158 |
} |
189 | 159 |
|
160 |
/// <summary> |
|
161 |
/// Initializes waiting for the clients' requests. |
|
162 |
/// </summary> |
|
163 |
/// <param name="predictionController">The initialized and trained instance of the predictor.</param> |
|
164 |
/// <param name="config">The Config class instance.</param> |
|
190 | 165 |
private static void ConnectionInit(IPredictionController predictionController, Config config) |
191 | 166 |
{ |
192 | 167 |
ConnectionListenerAsync cl = new ConnectionListenerAsync(int.Parse(config.Port), predictionController); |
193 | 168 |
cl.StartListening(); |
194 | 169 |
|
195 |
//HttpRequestHandler hrh = new HttpRequestHandler(int.Parse(config.Port)); |
|
196 |
//hrh.ListenAsynchronously(); |
|
197 | 170 |
} |
198 | 171 |
|
199 |
|
|
172 |
/// <summary> |
|
173 |
/// Parses the configuration file and extracts valuable information from it. |
|
174 |
/// </summary> |
|
175 |
/// <param name="args">The arguments passed to the program.</param> |
|
176 |
/// <returns>Filled instance of the Config class, null if there was a problem.</returns> |
|
200 | 177 |
private static Config FillConfigInfo(string[] args) |
201 | 178 |
{ |
202 | 179 |
|
... | ... | |
215 | 192 |
catch(Exception ex) |
216 | 193 |
{ |
217 | 194 |
Console.WriteLine("Could not open " + fullPathConfig); |
195 |
Console.WriteLine(ex.Message); |
|
218 | 196 |
return null; |
219 | 197 |
} |
220 | 198 |
|
... | ... | |
256 | 234 |
bool success = int.TryParse(extractedConfigInfo.Port, out parsedPort); |
257 | 235 |
if (!success) |
258 | 236 |
{ |
259 |
Console.WriteLine("Configured port " + extractedConfigInfo.Port + " is not an integer number! Abort.");
|
|
237 |
Console.WriteLine("Configured port " + extractedConfigInfo.Port + " is not an integer! Abort."); |
|
260 | 238 |
return null; |
261 | 239 |
} |
262 | 240 |
|
Server/ServerApp/User/Command.cs | ||
---|---|---|
2 | 2 |
// Author: Eliska Mourycova |
3 | 3 |
// |
4 | 4 |
|
5 |
using System; |
|
6 | 5 |
using System.Collections.Generic; |
7 |
using System.Linq; |
|
8 |
using System.Text; |
|
9 |
using System.Threading.Tasks; |
|
10 | 6 |
|
11 | 7 |
namespace ServerApp.User |
12 | 8 |
{ |
Server/ServerApp/User/CommandsAcceptor.cs | ||
---|---|---|
167 | 167 |
Console.WriteLine(f); |
168 | 168 |
|
169 | 169 |
} |
170 |
catch(Exception ex)
|
|
170 |
catch (Exception)
|
|
171 | 171 |
{ |
172 | 172 |
Console.WriteLine("Data download failed, please ensure the start date is before or same as end date."); |
173 | 173 |
return; |
... | ... | |
188 | 188 |
/// <param name="c">The command</param> |
189 | 189 |
private void HandleModelCommand(Command c) |
190 | 190 |
{ |
191 |
// TODO: |
|
192 |
// model -files |
|
193 |
// model -retrain |
|
194 |
// model -rollback |
|
195 | 191 |
|
196 | 192 |
// todo if the command has something else after the flag - abort? |
197 | 193 |
if (c.FlagsAndData.ContainsKey("files")) |
Také k dispozici: Unified diff
Cosmetic changes, documentation adding, warnings fixing.