Revize 127a92b1
Přidáno uživatelem Eliška Mourycová před téměř 4 roky(ů)
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 |
|
Také k dispozici: Unified diff
Cosmetic changes, documentation adding, warnings fixing.