Projekt

Obecné

Profil

Stáhnout (6.04 KB) Statistiky
| Větev: | Tag: | Revize:
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 fffe7190 A-Konig
using ServerApp.Parser.OutputInfo;
5 57a75f60 Roman Kalivoda
using ServerApp.Parser.Parsers;
6 9fc5fa93 Roman Kalivoda
using ServerApp.Predictor;
7 4a417b8b Eliška Mourycová
using ServerApp.User;
8 cdf3c217 A-Konig
using ServerApp.WeatherPredictionParser;
9 3811845f Alex Konig
using System;
10
using System.Collections.Generic;
11 7a998d66 Eliška Mourycová
using System.IO;
12 4a417b8b Eliška Mourycová
using System.Threading;
13 3811845f Alex Konig
14
namespace ServerApp
15
{
16 7a998d66 Eliška Mourycová
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 4a417b8b Eliška Mourycová
    public class Program
26 3811845f Alex Konig
    {
27 7a998d66 Eliška Mourycová
28 4a417b8b Eliška Mourycová
		public static void NotifyUserMessage(string message)
29
		{
30
			Console.WriteLine("Received user message: " + message);
31
		}
32 7a998d66 Eliška Mourycová
33 3811845f Alex Konig
        static void Main(string[] args)
34
        {
35
36 cdf3c217 A-Konig
			// SETUP FOLDERS
37 c9eed50c A-Konig
38 3aba3c34 Eliška Mourycová
			Config config = FillConfigInfo(args);
39
			if (config == null)
40
			{
41
				Console.ReadLine();
42
				return;
43
			}
44 7a998d66 Eliška Mourycová
45 d358b79e Roman Kalivoda
            
46 3aba3c34 Eliška Mourycová
			//create a thread for commands accepting:
47 d358b79e Roman Kalivoda
			//Thread inputThread = new Thread(CommandsAcceptor.AcceptCommand);
48
			//inputThread.Start();
49 7a998d66 Eliška Mourycová
50
51
52
			//DataParser p = new DataParser("data/");
53
			//p.Parse();
54
55 6b4c34a2 Eliška Mourycová
			#region UNCOMMENT
56 d358b79e Roman Kalivoda
			//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 4129ce12 Eliška Mourycová
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 d358b79e Roman Kalivoda
			// test - connection:
91
			//ConnectionListener cl = new ConnectionListener(int.Parse(config.Port));
92
			//cl.StartListening();
93 6b4c34a2 Eliška Mourycová
			#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 085453be Eliška Mourycová
111 d358b79e Roman Kalivoda
			//Console.WriteLine("Saved files: ");
112
			//foreach (string s in savedFiles)
113
			//{
114
			//	Console.WriteLine(s);
115
			//}
116 d2d1c86a Eliška Mourycová
117 d358b79e Roman Kalivoda
			//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 36c0667f Eliška Mourycová
123 cdf3c217 A-Konig
			/*
124
			
125 3aba3c34 Eliška Mourycová
			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 c9eed50c A-Konig
			*/
132 36c0667f Eliška Mourycová
133 d358b79e Roman Kalivoda
            // PARSE DATA
134 cdf3c217 A-Konig
135
136 d358b79e Roman Kalivoda
137
            JsonParser jsonP = new JsonParser(null);
138 cdf3c217 A-Konig
			jsonP.ParsePrediction();
139
140 fffe7190 A-Konig
			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 cdf3c217 A-Konig
			// TODO nastavit čas
148 99e5517e A-Konig
			IDataParser p = new DataParser(dd);
149 ebe96ca4 Roman Kalivoda
            IPredictionController predictionController = new PredictionController(p);
150
            predictionController.Train();
151
            //var results = predictionController.Predict()
152 d358b79e Roman Kalivoda
			
153 cdf3c217 A-Konig
154 4cb8ae48 A-Konig
			//parse(new DateTime(2019, 10, 5), , interval = 1, wholeDay = true)
155
156 cdf3c217 A-Konig
157 7a998d66 Eliška Mourycová
			// test - connection:
158 3aba3c34 Eliška Mourycová
			//ConnectionListener cl = new ConnectionListener(int.Parse(args[0])/*8000*//*int.Parse(config.Port)*/);
159
			//cl.StartListening();
160 7a998d66 Eliška Mourycová
161 3dc0ae76 A-Konig
			Console.ReadLine();
162 3811845f Alex Konig
        }
163 7a998d66 Eliška Mourycová
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 3811845f Alex Konig
    }
217
}