1
|
using ServerApp.Connection;
|
2
|
using ServerApp.DataDownload;
|
3
|
using ServerApp.Parser.Parsers;
|
4
|
using ServerApp.Predictor;
|
5
|
using ServerApp.User;
|
6
|
using ServerApp.WeatherPredictionParser;
|
7
|
using System;
|
8
|
using System.Collections.Generic;
|
9
|
using System.IO;
|
10
|
using System.Threading;
|
11
|
|
12
|
namespace ServerApp
|
13
|
{
|
14
|
|
15
|
class Config // TBD where this should go
|
16
|
{
|
17
|
public string DataWebsite { get; set; }
|
18
|
public string DownloadedFilesNaming { get; set; }
|
19
|
public string DataRootDir { get; set; }
|
20
|
public string Port { get; set; }
|
21
|
}
|
22
|
|
23
|
public class Program
|
24
|
{
|
25
|
|
26
|
public static void NotifyUserMessage(string message)
|
27
|
{
|
28
|
Console.WriteLine("Received user message: " + message);
|
29
|
}
|
30
|
|
31
|
static void Main(string[] args)
|
32
|
{
|
33
|
|
34
|
// SETUP FOLDERS
|
35
|
|
36
|
Config config = FillConfigInfo(args);
|
37
|
if (config == null)
|
38
|
{
|
39
|
Console.ReadLine();
|
40
|
return;
|
41
|
}
|
42
|
|
43
|
/*
|
44
|
//create a thread for commands accepting:
|
45
|
Thread inputThread = new Thread(CommandsAcceptor.AcceptCommand);
|
46
|
inputThread.Start();
|
47
|
*/
|
48
|
|
49
|
//test scenario -data download:
|
50
|
DataDownloader dd = new DataDownloader(config.DataRootDir, config.DataWebsite, config.DownloadedFilesNaming);
|
51
|
dd.OverwriteExisting = false;
|
52
|
List<string> savedFiles = new List<string>();
|
53
|
savedFiles.AddRange(dd.DownloadData(DataType.JIS, DataFormat.CSV, new Date(1, 2019), new Date(12, 2020)));
|
54
|
savedFiles.AddRange(dd.DownloadData(DataType.STROJE, DataFormat.CSV, new Date(1, 2017), new Date(12, 2020)));
|
55
|
savedFiles.AddRange(dd.DownloadData(DataType.POCASI, DataFormat.CSV, new Date(1, 2017), new Date(12, 2020)));
|
56
|
|
57
|
Console.WriteLine("Saved files: ");
|
58
|
foreach (string s in savedFiles)
|
59
|
{
|
60
|
Console.WriteLine(s);
|
61
|
}
|
62
|
|
63
|
Console.WriteLine("subdirectories: ");
|
64
|
foreach (KeyValuePair<DataType, string> kvp in dd.DataSubDirectories)
|
65
|
{
|
66
|
Console.WriteLine("Key = {0}, Value = {1}", kvp.Key, kvp.Value);
|
67
|
}
|
68
|
|
69
|
/*
|
70
|
|
71
|
List<string> retrievedData = dd.GetData(dd.DataSubDirectories[DataType.JIS], new Date(10, 2019), new Date(12, 2020));
|
72
|
Console.WriteLine("Retrieved data: ");
|
73
|
foreach (string s in retrievedData)
|
74
|
{
|
75
|
Console.WriteLine(s);
|
76
|
}
|
77
|
*/
|
78
|
|
79
|
// PARSE DATA
|
80
|
|
81
|
|
82
|
JsonParser jsonP = new JsonParser(null);
|
83
|
jsonP.ParsePrediction();
|
84
|
|
85
|
// TODO nastavit čas
|
86
|
IDataParser p = new DataParser(dd);
|
87
|
IPredictionController predictionController = new PredictionController(p);
|
88
|
predictionController.Train();
|
89
|
//var results = predictionController.Predict()
|
90
|
|
91
|
|
92
|
//parse(new DateTime(2019, 10, 5), , interval = 1, wholeDay = true)
|
93
|
|
94
|
|
95
|
// test - connection:
|
96
|
//ConnectionListener cl = new ConnectionListener(int.Parse(args[0])/*8000*//*int.Parse(config.Port)*/);
|
97
|
//cl.StartListening();
|
98
|
|
99
|
Console.ReadLine();
|
100
|
}
|
101
|
|
102
|
|
103
|
private static Config FillConfigInfo(string[] args)
|
104
|
{
|
105
|
|
106
|
Config extractedConfigInfo = new Config();
|
107
|
|
108
|
Console.WriteLine(Directory.GetCurrentDirectory());
|
109
|
|
110
|
if (args.Length != 1)
|
111
|
Console.WriteLine("Wrong usage of parameters, pass the path to a config file."); // todo better explanation?
|
112
|
|
113
|
string fullPathConfig = Path.GetFullPath(args[0]);
|
114
|
string[] lines = null;
|
115
|
try {
|
116
|
lines = File.ReadAllLines(fullPathConfig);
|
117
|
}
|
118
|
catch(Exception ex)
|
119
|
{
|
120
|
Console.WriteLine("Could not open " + fullPathConfig);
|
121
|
return null;
|
122
|
}
|
123
|
|
124
|
for (var i = 0; i < lines.Length; i += 1)
|
125
|
{
|
126
|
string line = lines[i];
|
127
|
Console.WriteLine(line);
|
128
|
if (line.Length == 0 || line == null || line.StartsWith("#"))
|
129
|
continue;
|
130
|
|
131
|
switch (line)
|
132
|
{
|
133
|
case "!site!":
|
134
|
extractedConfigInfo.DataWebsite = lines[++i].Trim();
|
135
|
break;
|
136
|
case "!naming_convention!":
|
137
|
extractedConfigInfo.DownloadedFilesNaming = lines[++i].Trim();
|
138
|
break;
|
139
|
case "!data_root_dir!":
|
140
|
string dirWithConfig = Path.GetDirectoryName(fullPathConfig);
|
141
|
string rootPath = dirWithConfig + Path.DirectorySeparatorChar + lines[++i].Trim();
|
142
|
extractedConfigInfo.DataRootDir = rootPath;
|
143
|
|
144
|
break;
|
145
|
case "!port!":
|
146
|
extractedConfigInfo.Port = lines[++i].Trim();
|
147
|
break;
|
148
|
default: break;
|
149
|
}
|
150
|
}
|
151
|
|
152
|
return extractedConfigInfo;
|
153
|
}
|
154
|
}
|
155
|
}
|