Projekt

Obecné

Profil

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

    
13
namespace ServerApp
14
{
15

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

    
24
    public class Program
25
    {
26

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

    
32
        static void Main(string[] args)
33
        {
34

    
35
			// SETUP FOLDERS
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

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

    
53
			#region UNCOMMENT
54
			//test scenario -data download:
55
			DataDownloader dd = new DataDownloader(config.DataRootDir, config.DataWebsite, config.DownloadedFilesNaming);
56
			dd.OverwriteExisting = false;
57
			List<string> savedFiles = new List<string>();
58
			savedFiles.AddRange(dd.DownloadData(DataType.JIS, DataFormat.CSV, new DataDownload.Date(1, 2019), new DataDownload.Date(12, 2020)));
59
			savedFiles.AddRange(dd.DownloadData(DataType.STROJE, DataFormat.CSV, new DataDownload.Date(1, 2017), new DataDownload.Date(12, 2020)));
60
			savedFiles.AddRange(dd.DownloadData(DataType.POCASI, DataFormat.CSV, new DataDownload.Date(1, 2017), new DataDownload.Date(12, 2020)));
61

    
62

    
63

    
64
			//Console.WriteLine("Saved files: ");
65
			//foreach (string s in savedFiles)
66
			//{
67
			//	Console.WriteLine(s);
68
			//}
69

    
70
			//Console.WriteLine("subdirectories: ");
71
			//foreach (KeyValuePair<DataType, string> kvp in dd.DataSubDirectories)
72
			//{
73
			//	Console.WriteLine("Key = {0}, Value = {1}", kvp.Key, kvp.Value);
74
			//}
75

    
76
			//List<string> retrievedData = dd.GetData(dd.DataSubDirectories[DataType.JIS], new DataDownload.Date(10, 2019), new DataDownload.Date(12, 2020));
77
			//Console.WriteLine("Retrieved data: ");
78
			//foreach (string s in retrievedData)
79
			//{
80
			//	Console.WriteLine(s);
81
			//}
82
			//Console.WriteLine("all from directory:");
83
			//retrievedData = dd.GetData(dd.DataSubDirectories[DataType.JIS], null, null);
84
			//foreach (string s in retrievedData)
85
			//{
86
			//	Console.WriteLine(s);
87
			//}
88
			// test - connection:
89
			//ConnectionListener cl = new ConnectionListener(int.Parse(config.Port));
90
			//cl.StartListening();
91
			#endregion
92

    
93
			#region XML_TEST
94
			//Response response = Response.Randomize();
95
			//var xml = XmlCommunication.Serialize(response);
96
			//Console.WriteLine(xml);
97
			//Response responseDeserialized = XmlCommunication.Deserialize(response, xml);
98

    
99
			//Console.WriteLine("------");
100

    
101

    
102
			//Request request = Request.Randomize();
103
			//xml = XmlCommunication.Serialize(request);
104
			//Console.WriteLine(xml);
105
			//Request requestDeserialized = XmlCommunication.Deserialize(request, xml);
106
			#endregion
107

    
108

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

    
115
			//Console.WriteLine("subdirectories: ");
116
			//foreach (KeyValuePair<DataType, string> kvp in dd.DataSubDirectories)
117
			//{
118
			//	Console.WriteLine("Key = {0}, Value = {1}", kvp.Key, kvp.Value);
119
			//}
120

    
121
			/*
122
			
123
			List<string> retrievedData = dd.GetData(dd.DataSubDirectories[DataType.JIS], new Date(10, 2019), new Date(12, 2020));
124
			Console.WriteLine("Retrieved data: ");
125
			foreach (string s in retrievedData)
126
			{
127
				Console.WriteLine(s);
128
			}
129
			*/
130

    
131
            // PARSE DATA
132

    
133

    
134

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

    
138
			// TODO nastavit čas
139
			IDataParser p = new DataParser(dd);
140
            IPredictionController predictionController = new PredictionController(p);
141
            predictionController.Train();
142
            //var results = predictionController.Predict()
143
			
144

    
145
			//parse(new DateTime(2019, 10, 5), , interval = 1, wholeDay = true)
146

    
147

    
148
			// test - connection:
149
			//ConnectionListener cl = new ConnectionListener(int.Parse(args[0])/*8000*//*int.Parse(config.Port)*/);
150
			//cl.StartListening();
151

    
152
			Console.ReadLine();
153
        }
154

    
155

    
156
        private static Config FillConfigInfo(string[] args)
157
		{
158

    
159
			Config extractedConfigInfo = new Config();
160

    
161
			Console.WriteLine(Directory.GetCurrentDirectory());
162
			
163
			if (args.Length != 1)
164
				Console.WriteLine("Wrong usage of parameters, pass the path to a config file."); // todo better explanation?
165

    
166
			string fullPathConfig = Path.GetFullPath(args[0]);
167
			string[] lines = null;
168
			try {
169
				lines = File.ReadAllLines(fullPathConfig);
170
			}
171
			catch(Exception ex)
172
			{
173
				Console.WriteLine("Could not open " + fullPathConfig);
174
				return null;
175
			}
176
			
177
			for (var i = 0; i < lines.Length; i += 1)
178
			{
179
				string line = lines[i];
180
				Console.WriteLine(line);
181
				if (line.Length == 0 || line == null || line.StartsWith("#"))
182
					continue;
183

    
184
				switch (line)
185
				{
186
					case "!site!":
187
						extractedConfigInfo.DataWebsite = lines[++i].Trim();
188
						break;
189
					case "!naming_convention!":
190
						extractedConfigInfo.DownloadedFilesNaming = lines[++i].Trim();
191
						break;
192
					case "!data_root_dir!":
193
						string dirWithConfig = Path.GetDirectoryName(fullPathConfig);
194
						string rootPath = dirWithConfig + Path.DirectorySeparatorChar + lines[++i].Trim();
195
						extractedConfigInfo.DataRootDir = rootPath;
196
						
197
						break;
198
					case "!port!":
199
						extractedConfigInfo.Port = lines[++i].Trim();
200
						break;
201
					default: break;
202
				}
203
			}
204

    
205
			return extractedConfigInfo;
206
		}
207
    }
208
}
(2-2/5)