Projekt

Obecné

Profil

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

    
12
namespace ServerApp
13
{
14

    
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
    public class Program
24
    {
25

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

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

    
34
			// SETUP FOLDERS
35

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

    
57
			Console.WriteLine("Saved files: ");
58
			foreach (string s in savedFiles)
59
			{
60
				Console.WriteLine(s);
61
			}
62

    
63
			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

    
69
			/*
70
			
71
			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
			*/
78

    
79
			// PARSE DATA
80

    
81

    
82
			JsonParser jsonP = new JsonParser(null);
83
			jsonP.ParsePrediction();
84

    
85
			// TODO nastavit čas
86
			IDataParser p = new DataParser(dd);
87
			DateTime startT = new DateTime(2018, 6, 5);
88
			DateTime endT = new DateTime(2019, 10, 30);
89
			p.Parse(startT, endT, wholeDay: false, interval: 3);
90

    
91
			Console.WriteLine(p.WeatherList.Count);
92

    
93
			// test - connection:
94
			//ConnectionListener cl = new ConnectionListener(int.Parse(args[0])/*8000*//*int.Parse(config.Port)*/);
95
			//cl.StartListening();
96

    
97
			Console.ReadLine();
98
        }
99

    
100

    
101
        private static Config FillConfigInfo(string[] args)
102
		{
103

    
104
			Config extractedConfigInfo = new Config();
105

    
106
			Console.WriteLine(Directory.GetCurrentDirectory());
107
			
108
			if (args.Length != 1)
109
				Console.WriteLine("Wrong usage of parameters, pass the path to a config file."); // todo better explanation?
110

    
111
			string fullPathConfig = Path.GetFullPath(args[0]);
112
			string[] lines = null;
113
			try {
114
				lines = File.ReadAllLines(fullPathConfig);
115
			}
116
			catch(Exception ex)
117
			{
118
				Console.WriteLine("Could not open " + fullPathConfig);
119
				return null;
120
			}
121
			
122
			for (var i = 0; i < lines.Length; i += 1)
123
			{
124
				string line = lines[i];
125
				Console.WriteLine(line);
126
				if (line.Length == 0 || line == null || line.StartsWith("#"))
127
					continue;
128

    
129
				switch (line)
130
				{
131
					case "!site!":
132
						extractedConfigInfo.DataWebsite = lines[++i].Trim();
133
						break;
134
					case "!naming_convention!":
135
						extractedConfigInfo.DownloadedFilesNaming = lines[++i].Trim();
136
						break;
137
					case "!data_root_dir!":
138
						string dirWithConfig = Path.GetDirectoryName(fullPathConfig);
139
						string rootPath = dirWithConfig + Path.DirectorySeparatorChar + lines[++i].Trim();
140
						extractedConfigInfo.DataRootDir = rootPath;
141
						
142
						break;
143
					case "!port!":
144
						extractedConfigInfo.Port = lines[++i].Trim();
145
						break;
146
					default: break;
147
				}
148
			}
149

    
150
			return extractedConfigInfo;
151
		}
152
    }
153
}
(2-2/5)