Projekt

Obecné

Profil

Stáhnout (4.01 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 99e5517e A-Konig
			IDataParser p = new DataParser(dd);
87 4cb8ae48 A-Konig
			DateTime startT = new DateTime(2019, 10, 5);
88
			DateTime endT = new DateTime(2020, 12, 23);
89 cdf3c217 A-Konig
			p.Parse(startT, endT, wholeDay: false, interval: 3);
90
91 4cb8ae48 A-Konig
			//parse(new DateTime(2019, 10, 5), , interval = 1, wholeDay = true)
92
93 cdf3c217 A-Konig
94 7a998d66 Eliška Mourycová
			// test - connection:
95 3aba3c34 Eliška Mourycová
			//ConnectionListener cl = new ConnectionListener(int.Parse(args[0])/*8000*//*int.Parse(config.Port)*/);
96
			//cl.StartListening();
97 7a998d66 Eliška Mourycová
98 3dc0ae76 A-Konig
			Console.ReadLine();
99 3811845f Alex Konig
        }
100 7a998d66 Eliška Mourycová
101
102
        private static Config FillConfigInfo(string[] args)
103
		{
104
105
			Config extractedConfigInfo = new Config();
106
107
			Console.WriteLine(Directory.GetCurrentDirectory());
108
			
109
			if (args.Length != 1)
110
				Console.WriteLine("Wrong usage of parameters, pass the path to a config file."); // todo better explanation?
111
112
			string fullPathConfig = Path.GetFullPath(args[0]);
113
			string[] lines = null;
114
			try {
115
				lines = File.ReadAllLines(fullPathConfig);
116
			}
117
			catch(Exception ex)
118
			{
119
				Console.WriteLine("Could not open " + fullPathConfig);
120
				return null;
121
			}
122
			
123
			for (var i = 0; i < lines.Length; i += 1)
124
			{
125
				string line = lines[i];
126
				Console.WriteLine(line);
127
				if (line.Length == 0 || line == null || line.StartsWith("#"))
128
					continue;
129
130
				switch (line)
131
				{
132
					case "!site!":
133
						extractedConfigInfo.DataWebsite = lines[++i].Trim();
134
						break;
135
					case "!naming_convention!":
136
						extractedConfigInfo.DownloadedFilesNaming = lines[++i].Trim();
137
						break;
138
					case "!data_root_dir!":
139
						string dirWithConfig = Path.GetDirectoryName(fullPathConfig);
140
						string rootPath = dirWithConfig + Path.DirectorySeparatorChar + lines[++i].Trim();
141
						extractedConfigInfo.DataRootDir = rootPath;
142
						
143
						break;
144
					case "!port!":
145
						extractedConfigInfo.Port = lines[++i].Trim();
146
						break;
147
					default: break;
148
				}
149
			}
150
151
			return extractedConfigInfo;
152
		}
153 3811845f Alex Konig
    }
154
}