Projekt

Obecné

Profil

Stáhnout (4.07 KB) Statistiky
| Větev: | Tag: | Revize:
1 7a998d66 Eliška Mourycová
using ServerApp.Connection;
2
using ServerApp.DataDownload;
3 57a75f60 Roman Kalivoda
using ServerApp.Parser.Parsers;
4 9fc5fa93 Roman Kalivoda
using ServerApp.Predictor;
5 4a417b8b Eliška Mourycová
using ServerApp.User;
6 cdf3c217 A-Konig
using ServerApp.WeatherPredictionParser;
7 3811845f Alex Konig
using System;
8
using System.Collections.Generic;
9 7a998d66 Eliška Mourycová
using System.IO;
10 4a417b8b Eliška Mourycová
using System.Threading;
11 3811845f Alex Konig
12
namespace ServerApp
13
{
14 7a998d66 Eliška Mourycová
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 4a417b8b Eliška Mourycová
    public class Program
24 3811845f Alex Konig
    {
25 7a998d66 Eliška Mourycová
26 4a417b8b Eliška Mourycová
		public static void NotifyUserMessage(string message)
27
		{
28
			Console.WriteLine("Received user message: " + message);
29
		}
30 7a998d66 Eliška Mourycová
31 3811845f Alex Konig
        static void Main(string[] args)
32
        {
33
34 cdf3c217 A-Konig
			// SETUP FOLDERS
35 c9eed50c A-Konig
36 3aba3c34 Eliška Mourycová
			Config config = FillConfigInfo(args);
37
			if (config == null)
38
			{
39
				Console.ReadLine();
40
				return;
41
			}
42 7a998d66 Eliška Mourycová
43 cdf3c217 A-Konig
			/* 
44 3aba3c34 Eliška Mourycová
			//create a thread for commands accepting:
45
			Thread inputThread = new Thread(CommandsAcceptor.AcceptCommand);
46
			inputThread.Start();
47 cdf3c217 A-Konig
			 */
48 7a998d66 Eliška Mourycová
49 3aba3c34 Eliška Mourycová
			//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 085453be Eliška Mourycová
57 3aba3c34 Eliška Mourycová
			Console.WriteLine("Saved files: ");
58
			foreach (string s in savedFiles)
59
			{
60
				Console.WriteLine(s);
61
			}
62 d2d1c86a Eliška Mourycová
63 3aba3c34 Eliška Mourycová
			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 36c0667f Eliška Mourycová
69 cdf3c217 A-Konig
			/*
70
			
71 3aba3c34 Eliška Mourycová
			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 c9eed50c A-Konig
			*/
78 36c0667f Eliška Mourycová
79 cdf3c217 A-Konig
			// PARSE DATA
80
81
82
			JsonParser jsonP = new JsonParser(null);
83
			jsonP.ParsePrediction();
84
85
			// TODO nastavit čas
86 ebe96ca4 Roman Kalivoda
			IDataParser p = new DataParser(dd);
87 cdf3c217 A-Konig
			DateTime startT = new DateTime(2019, 10, 5);
88
			DateTime endT = new DateTime(2020, 6, 30);
89 ebe96ca4 Roman Kalivoda
            IPredictionController predictionController = new PredictionController(p);
90
            predictionController.Train();
91
            //var results = predictionController.Predict()
92
93 cdf3c217 A-Konig
94
95 7a998d66 Eliška Mourycová
			// test - connection:
96 3aba3c34 Eliška Mourycová
			//ConnectionListener cl = new ConnectionListener(int.Parse(args[0])/*8000*//*int.Parse(config.Port)*/);
97
			//cl.StartListening();
98 7a998d66 Eliška Mourycová
99 3dc0ae76 A-Konig
			Console.ReadLine();
100 3811845f Alex Konig
        }
101 7a998d66 Eliška Mourycová
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 3811845f Alex Konig
    }
155
}