1 |
7a998d66
|
Eliška Mourycová
|
using ServerApp.Connection;
|
2 |
6b4c34a2
|
Eliška Mourycová
|
using ServerApp.Connection.XMLProtocolHandler;
|
3 |
7a998d66
|
Eliška Mourycová
|
using ServerApp.DataDownload;
|
4 |
57a75f60
|
Roman Kalivoda
|
using ServerApp.Parser.Parsers;
|
5 |
9fc5fa93
|
Roman Kalivoda
|
using ServerApp.Predictor;
|
6 |
4a417b8b
|
Eliška Mourycová
|
using ServerApp.User;
|
7 |
cdf3c217
|
A-Konig
|
using ServerApp.WeatherPredictionParser;
|
8 |
3811845f
|
Alex Konig
|
using System;
|
9 |
|
|
using System.Collections.Generic;
|
10 |
7a998d66
|
Eliška Mourycová
|
using System.IO;
|
11 |
4a417b8b
|
Eliška Mourycová
|
using System.Threading;
|
12 |
3811845f
|
Alex Konig
|
|
13 |
|
|
namespace ServerApp
|
14 |
|
|
{
|
15 |
7a998d66
|
Eliška Mourycová
|
|
16 |
|
|
class Config // TBD where this should go
|
17 |
|
|
{
|
18 |
|
|
public string DataWebsite { get; set; }
|
19 |
|
|
public string DownloadedFilesNaming { get; set; }
|
20 |
|
|
public string DataRootDir { get; set; }
|
21 |
|
|
public string Port { get; set; }
|
22 |
|
|
}
|
23 |
|
|
|
24 |
4a417b8b
|
Eliška Mourycová
|
public class Program
|
25 |
3811845f
|
Alex Konig
|
{
|
26 |
7a998d66
|
Eliška Mourycová
|
|
27 |
4a417b8b
|
Eliška Mourycová
|
public static void NotifyUserMessage(string message)
|
28 |
|
|
{
|
29 |
|
|
Console.WriteLine("Received user message: " + message);
|
30 |
|
|
}
|
31 |
7a998d66
|
Eliška Mourycová
|
|
32 |
3811845f
|
Alex Konig
|
static void Main(string[] args)
|
33 |
|
|
{
|
34 |
|
|
|
35 |
cdf3c217
|
A-Konig
|
// SETUP FOLDERS
|
36 |
c9eed50c
|
A-Konig
|
|
37 |
3aba3c34
|
Eliška Mourycová
|
Config config = FillConfigInfo(args);
|
38 |
|
|
if (config == null)
|
39 |
|
|
{
|
40 |
|
|
Console.ReadLine();
|
41 |
|
|
return;
|
42 |
|
|
}
|
43 |
7a998d66
|
Eliška Mourycová
|
|
44 |
d358b79e
|
Roman Kalivoda
|
|
45 |
3aba3c34
|
Eliška Mourycová
|
//create a thread for commands accepting:
|
46 |
d358b79e
|
Roman Kalivoda
|
//Thread inputThread = new Thread(CommandsAcceptor.AcceptCommand);
|
47 |
|
|
//inputThread.Start();
|
48 |
7a998d66
|
Eliška Mourycová
|
|
49 |
|
|
|
50 |
|
|
|
51 |
|
|
//DataParser p = new DataParser("data/");
|
52 |
|
|
//p.Parse();
|
53 |
|
|
|
54 |
6b4c34a2
|
Eliška Mourycová
|
#region UNCOMMENT
|
55 |
d358b79e
|
Roman Kalivoda
|
//test scenario -data download:
|
56 |
|
|
DataDownloader dd = new DataDownloader(config.DataRootDir, config.DataWebsite, config.DownloadedFilesNaming);
|
57 |
|
|
dd.OverwriteExisting = false;
|
58 |
|
|
List<string> savedFiles = new List<string>();
|
59 |
|
|
savedFiles.AddRange(dd.DownloadData(DataType.JIS, DataFormat.CSV, new DataDownload.Date(1, 2019), new DataDownload.Date(12, 2020)));
|
60 |
|
|
savedFiles.AddRange(dd.DownloadData(DataType.STROJE, DataFormat.CSV, new DataDownload.Date(1, 2017), new DataDownload.Date(12, 2020)));
|
61 |
|
|
savedFiles.AddRange(dd.DownloadData(DataType.POCASI, DataFormat.CSV, new DataDownload.Date(1, 2017), new DataDownload.Date(12, 2020)));
|
62 |
4129ce12
|
Eliška Mourycová
|
|
63 |
|
|
|
64 |
|
|
|
65 |
|
|
//Console.WriteLine("Saved files: ");
|
66 |
|
|
//foreach (string s in savedFiles)
|
67 |
|
|
//{
|
68 |
|
|
// Console.WriteLine(s);
|
69 |
|
|
//}
|
70 |
|
|
|
71 |
|
|
//Console.WriteLine("subdirectories: ");
|
72 |
|
|
//foreach (KeyValuePair<DataType, string> kvp in dd.DataSubDirectories)
|
73 |
|
|
//{
|
74 |
|
|
// Console.WriteLine("Key = {0}, Value = {1}", kvp.Key, kvp.Value);
|
75 |
|
|
//}
|
76 |
|
|
|
77 |
|
|
//List<string> retrievedData = dd.GetData(dd.DataSubDirectories[DataType.JIS], new DataDownload.Date(10, 2019), new DataDownload.Date(12, 2020));
|
78 |
|
|
//Console.WriteLine("Retrieved data: ");
|
79 |
|
|
//foreach (string s in retrievedData)
|
80 |
|
|
//{
|
81 |
|
|
// Console.WriteLine(s);
|
82 |
|
|
//}
|
83 |
|
|
//Console.WriteLine("all from directory:");
|
84 |
|
|
//retrievedData = dd.GetData(dd.DataSubDirectories[DataType.JIS], null, null);
|
85 |
|
|
//foreach (string s in retrievedData)
|
86 |
|
|
//{
|
87 |
|
|
// Console.WriteLine(s);
|
88 |
|
|
//}
|
89 |
d358b79e
|
Roman Kalivoda
|
// test - connection:
|
90 |
|
|
//ConnectionListener cl = new ConnectionListener(int.Parse(config.Port));
|
91 |
|
|
//cl.StartListening();
|
92 |
6b4c34a2
|
Eliška Mourycová
|
#endregion
|
93 |
|
|
|
94 |
|
|
#region XML_TEST
|
95 |
|
|
//Response response = Response.Randomize();
|
96 |
|
|
//var xml = XmlCommunication.Serialize(response);
|
97 |
|
|
//Console.WriteLine(xml);
|
98 |
|
|
//Response responseDeserialized = XmlCommunication.Deserialize(response, xml);
|
99 |
|
|
|
100 |
|
|
//Console.WriteLine("------");
|
101 |
|
|
|
102 |
|
|
|
103 |
|
|
//Request request = Request.Randomize();
|
104 |
|
|
//xml = XmlCommunication.Serialize(request);
|
105 |
|
|
//Console.WriteLine(xml);
|
106 |
|
|
//Request requestDeserialized = XmlCommunication.Deserialize(request, xml);
|
107 |
|
|
#endregion
|
108 |
|
|
|
109 |
085453be
|
Eliška Mourycová
|
|
110 |
d358b79e
|
Roman Kalivoda
|
//Console.WriteLine("Saved files: ");
|
111 |
|
|
//foreach (string s in savedFiles)
|
112 |
|
|
//{
|
113 |
|
|
// Console.WriteLine(s);
|
114 |
|
|
//}
|
115 |
d2d1c86a
|
Eliška Mourycová
|
|
116 |
d358b79e
|
Roman Kalivoda
|
//Console.WriteLine("subdirectories: ");
|
117 |
|
|
//foreach (KeyValuePair<DataType, string> kvp in dd.DataSubDirectories)
|
118 |
|
|
//{
|
119 |
|
|
// Console.WriteLine("Key = {0}, Value = {1}", kvp.Key, kvp.Value);
|
120 |
|
|
//}
|
121 |
36c0667f
|
Eliška Mourycová
|
|
122 |
cdf3c217
|
A-Konig
|
/*
|
123 |
|
|
|
124 |
3aba3c34
|
Eliška Mourycová
|
List<string> retrievedData = dd.GetData(dd.DataSubDirectories[DataType.JIS], new Date(10, 2019), new Date(12, 2020));
|
125 |
|
|
Console.WriteLine("Retrieved data: ");
|
126 |
|
|
foreach (string s in retrievedData)
|
127 |
|
|
{
|
128 |
|
|
Console.WriteLine(s);
|
129 |
|
|
}
|
130 |
c9eed50c
|
A-Konig
|
*/
|
131 |
36c0667f
|
Eliška Mourycová
|
|
132 |
d358b79e
|
Roman Kalivoda
|
// PARSE DATA
|
133 |
cdf3c217
|
A-Konig
|
|
134 |
|
|
|
135 |
d358b79e
|
Roman Kalivoda
|
|
136 |
|
|
JsonParser jsonP = new JsonParser(null);
|
137 |
cdf3c217
|
A-Konig
|
jsonP.ParsePrediction();
|
138 |
|
|
|
139 |
|
|
// TODO nastavit čas
|
140 |
99e5517e
|
A-Konig
|
IDataParser p = new DataParser(dd);
|
141 |
22211075
|
Roman Kalivoda
|
IPredictionController predictionController = new PredictionController(p);
|
142 |
ebe96ca4
|
Roman Kalivoda
|
predictionController.Train();
|
143 |
|
|
//var results = predictionController.Predict()
|
144 |
d358b79e
|
Roman Kalivoda
|
|
145 |
cdf3c217
|
A-Konig
|
|
146 |
4cb8ae48
|
A-Konig
|
//parse(new DateTime(2019, 10, 5), , interval = 1, wholeDay = true)
|
147 |
|
|
|
148 |
cdf3c217
|
A-Konig
|
|
149 |
7a998d66
|
Eliška Mourycová
|
// test - connection:
|
150 |
3aba3c34
|
Eliška Mourycová
|
//ConnectionListener cl = new ConnectionListener(int.Parse(args[0])/*8000*//*int.Parse(config.Port)*/);
|
151 |
|
|
//cl.StartListening();
|
152 |
7a998d66
|
Eliška Mourycová
|
|
153 |
3dc0ae76
|
A-Konig
|
Console.ReadLine();
|
154 |
3811845f
|
Alex Konig
|
}
|
155 |
7a998d66
|
Eliška Mourycová
|
|
156 |
|
|
|
157 |
|
|
private static Config FillConfigInfo(string[] args)
|
158 |
|
|
{
|
159 |
|
|
|
160 |
|
|
Config extractedConfigInfo = new Config();
|
161 |
|
|
|
162 |
|
|
Console.WriteLine(Directory.GetCurrentDirectory());
|
163 |
|
|
|
164 |
|
|
if (args.Length != 1)
|
165 |
|
|
Console.WriteLine("Wrong usage of parameters, pass the path to a config file."); // todo better explanation?
|
166 |
|
|
|
167 |
|
|
string fullPathConfig = Path.GetFullPath(args[0]);
|
168 |
|
|
string[] lines = null;
|
169 |
|
|
try {
|
170 |
|
|
lines = File.ReadAllLines(fullPathConfig);
|
171 |
|
|
}
|
172 |
|
|
catch(Exception ex)
|
173 |
|
|
{
|
174 |
|
|
Console.WriteLine("Could not open " + fullPathConfig);
|
175 |
|
|
return null;
|
176 |
|
|
}
|
177 |
|
|
|
178 |
|
|
for (var i = 0; i < lines.Length; i += 1)
|
179 |
|
|
{
|
180 |
|
|
string line = lines[i];
|
181 |
|
|
Console.WriteLine(line);
|
182 |
|
|
if (line.Length == 0 || line == null || line.StartsWith("#"))
|
183 |
|
|
continue;
|
184 |
|
|
|
185 |
|
|
switch (line)
|
186 |
|
|
{
|
187 |
|
|
case "!site!":
|
188 |
|
|
extractedConfigInfo.DataWebsite = lines[++i].Trim();
|
189 |
|
|
break;
|
190 |
|
|
case "!naming_convention!":
|
191 |
|
|
extractedConfigInfo.DownloadedFilesNaming = lines[++i].Trim();
|
192 |
|
|
break;
|
193 |
|
|
case "!data_root_dir!":
|
194 |
|
|
string dirWithConfig = Path.GetDirectoryName(fullPathConfig);
|
195 |
|
|
string rootPath = dirWithConfig + Path.DirectorySeparatorChar + lines[++i].Trim();
|
196 |
|
|
extractedConfigInfo.DataRootDir = rootPath;
|
197 |
|
|
|
198 |
|
|
break;
|
199 |
|
|
case "!port!":
|
200 |
|
|
extractedConfigInfo.Port = lines[++i].Trim();
|
201 |
|
|
break;
|
202 |
|
|
default: break;
|
203 |
|
|
}
|
204 |
|
|
}
|
205 |
|
|
|
206 |
|
|
return extractedConfigInfo;
|
207 |
|
|
}
|
208 |
3811845f
|
Alex Konig
|
}
|
209 |
|
|
}
|