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