Projekt

Obecné

Profil

Stáhnout (6.04 KB) Statistiky
| Větev: | Tag: | Revize:
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
			Config config = FillConfigInfo(args);
38
			if (config == null)
39
			{
40
				Console.ReadLine();
41
				return;
42
			}
43

    
44
            
45
			//create a thread for commands accepting:
46
			//Thread inputThread = new Thread(CommandsAcceptor.AcceptCommand);
47
			//inputThread.Start();
48

    
49

    
50

    
51
			//DataParser p = new DataParser("data/");
52
			//p.Parse();
53

    
54
			#region UNCOMMENT
55
			//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

    
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
			// test - connection:
90
			//ConnectionListener cl = new ConnectionListener(int.Parse(config.Port));
91
			//cl.StartListening();
92
			#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

    
110
			//Console.WriteLine("Saved files: ");
111
			//foreach (string s in savedFiles)
112
			//{
113
			//	Console.WriteLine(s);
114
			//}
115

    
116
			//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

    
122
			/*
123
			
124
			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
			*/
131

    
132
            // PARSE DATA
133

    
134

    
135

    
136
            JsonParser jsonP = new JsonParser(null);
137
			jsonP.ParsePrediction();
138

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

    
145

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

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

    
155

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

    
160
			Console.ReadLine();
161
        }
162

    
163

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

    
167
			Config extractedConfigInfo = new Config();
168

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

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

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

    
213
			return extractedConfigInfo;
214
		}
215
    }
216
}
(1-1/3)