Projekt

Obecné

Profil

Stáhnout (6.09 KB) Statistiky
| Větev: | Tag: | Revize:
1
using ServerApp.Connection;
2
using ServerApp.Connection.XMLProtocolHandler;
3
using ServerApp.DataDownload;
4
using ServerApp.Parser.InputData;
5
using ServerApp.Parser.OutputInfo;
6
using ServerApp.Parser.Parsers;
7
using ServerApp.Predictor;
8
using ServerApp.User;
9
using ServerApp.WeatherPredictionParser;
10
using System;
11
using System.Collections.Generic;
12
using System.IO;
13
using System.Threading;
14

    
15
namespace ServerApp
16
{
17

    
18
	class Config // TBD where this should go
19
	{
20
		public string DataWebsite { get; set; }
21
		public string DownloadedFilesNaming { get; set; }
22
		public string DataRootDir { get; set; }
23
		public string Port { get; set; }
24
	}
25

    
26
    public class Program
27
    {
28

    
29
		public static void NotifyUserMessage(string message)
30
		{
31
			Console.WriteLine("Received user message: " + message);
32
		}
33

    
34
        static void Main(string[] args)
35
        {
36

    
37
			// SETUP FOLDERS
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
            JsonParser jsonP = new JsonParser(dd, new CsvDataLoader());
136
			jsonP.ParsePrediction();
137

    
138
			var res = jsonP.GetPredictionForTime(jsonP.Predictions[5].startTime, jsonP.Predictions[20].startTime);
139
			Console.WriteLine("from " + jsonP.Predictions[5].startTime);
140
			Console.WriteLine("end " + jsonP.Predictions[20].startTime);
141
			foreach (WeatherInfo w in res)
142
				Console.WriteLine(w.ToString());
143

    
144

    
145
			// TODO nastavit čas
146
			IDataParser p = new DataParser(dd);
147
            IPredictionController predictionController = new PredictionController(p);
148
            //predictionController.Train();
149
            //var results = predictionController.Predict()
150
			
151

    
152
			//parse(new DateTime(2019, 10, 5), , interval = 1, wholeDay = true)
153

    
154

    
155
			// test - connection:
156
			//ConnectionListener cl = new ConnectionListener(int.Parse(args[0])/*8000*//*int.Parse(config.Port)*/);
157
			//cl.StartListening();
158

    
159
			Console.ReadLine();
160
        }
161

    
162

    
163
        private static Config FillConfigInfo(string[] args)
164
		{
165

    
166
			Config extractedConfigInfo = new Config();
167

    
168
			Console.WriteLine(Directory.GetCurrentDirectory());
169
			
170
			if (args.Length != 1)
171
				Console.WriteLine("Wrong usage of parameters, pass the path to a config file."); // todo better explanation?
172

    
173
			string fullPathConfig = Path.GetFullPath(args[0]);
174
			string[] lines = null;
175
			try {
176
				lines = File.ReadAllLines(fullPathConfig);
177
			}
178
			catch(Exception ex)
179
			{
180
				Console.WriteLine("Could not open " + fullPathConfig);
181
				return null;
182
			}
183
			
184
			for (var i = 0; i < lines.Length; i += 1)
185
			{
186
				string line = lines[i];
187
				Console.WriteLine(line);
188
				if (line.Length == 0 || line == null || line.StartsWith("#"))
189
					continue;
190

    
191
				switch (line)
192
				{
193
					case "!site!":
194
						extractedConfigInfo.DataWebsite = lines[++i].Trim();
195
						break;
196
					case "!naming_convention!":
197
						extractedConfigInfo.DownloadedFilesNaming = lines[++i].Trim();
198
						break;
199
					case "!data_root_dir!":
200
						string dirWithConfig = Path.GetDirectoryName(fullPathConfig);
201
						string rootPath = dirWithConfig + Path.DirectorySeparatorChar + lines[++i].Trim();
202
						extractedConfigInfo.DataRootDir = rootPath;
203
						
204
						break;
205
					case "!port!":
206
						extractedConfigInfo.Port = lines[++i].Trim();
207
						break;
208
					default: break;
209
				}
210
			}
211

    
212
			return extractedConfigInfo;
213
		}
214
    }
215
}
(2-2/5)