Projekt

Obecné

Profil

Stáhnout (4.41 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 System;
7
using System.Collections.Generic;
8
using System.IO;
9
using System.Threading;
10

    
11
namespace ServerApp
12
{
13

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

    
22
    public class Program
23
    {
24

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

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

    
33
            Config config = FillConfigInfo(args);
34
			if (config == null)
35
			{
36
				Console.ReadLine();
37
				return;
38
			}
39

    
40
			// create a thread for commands accepting:
41
			//Thread inputThread = new Thread(CommandsAcceptor.AcceptCommand);
42
			//inputThread.Start();
43

    
44

    
45

    
46
			//DataParser p = new DataParser("data/");
47

    
48
			//p.Parse();
49

    
50

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

    
59

    
60

    
61
			Console.WriteLine("Saved files: ");
62
			foreach (string s in savedFiles)
63
			{
64
				Console.WriteLine(s);
65
			}
66

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

    
73
			dd.GetData(dd.DataSubDirectories[DataType.JIS], new Date(1, 2019), new Date(12, 2020));
74

    
75

    
76

    
77

    
78

    
79

    
80
			// date testing
81
			//Date d1 = new Date(2, 2020);
82
			//Date d2 = new Date(1, 2019);
83

    
84
			//Console.WriteLine("equals" + d1.Equals(d2));
85
			//Console.WriteLine("==" + (d1 == d2));
86
			//Console.WriteLine("!=" + (d1 != d2));
87
			//Console.WriteLine(">" + (d1 > d2));
88
			//Console.WriteLine("<" + (d1 < d2));
89
			//Console.WriteLine(">=" + (d1 >= d2));
90
			//Console.WriteLine("<=" + (d1 <= d2));
91

    
92

    
93

    
94

    
95
			// test - connection:
96
			//AsynchronousSocketListener asl = new AsynchronousSocketListener();
97
			//asl.StartListening();
98

    
99

    
100
			//NaiveBayesClassifier naiveBayesClassifier = new NaiveBayesClassifier();
101
			//IEnumerable<ModelInput> modelInput = naiveBayesClassifier.ExtractModelInput(p.weatherList, p.jisList);
102
			//naiveBayesClassifier.Fit(modelInput);
103
			//List<ModelInput> dataList = new List<ModelInput>()
104
			//{
105
			//    new ModelInput()
106
			//    {
107
			//        Temp = -40,
108
			//    }
109
			//};
110
			//var result = naiveBayesClassifier.Predict(dataList);
111

    
112
			//Console.WriteLine($"Predictions: ");
113
			//foreach(var item in result)
114
			//{
115
			//    Console.WriteLine(item.ToString());
116
			//}
117

    
118
			Console.ReadLine();
119
        }
120

    
121

    
122
        private static Config FillConfigInfo(string[] args)
123
		{
124

    
125
			Config extractedConfigInfo = new Config();
126

    
127
			Console.WriteLine(Directory.GetCurrentDirectory());
128
			
129
			if (args.Length != 1)
130
				Console.WriteLine("Wrong usage of parameters, pass the path to a config file."); // todo better explanation?
131

    
132
			string fullPathConfig = Path.GetFullPath(args[0]);
133
			string[] lines = null;
134
			try {
135
				lines = File.ReadAllLines(fullPathConfig);
136
			}
137
			catch(Exception ex)
138
			{
139
				Console.WriteLine("Could not open " + fullPathConfig);
140
				return null;
141
			}
142
			
143
			for (var i = 0; i < lines.Length; i += 1)
144
			{
145
				string line = lines[i];
146
				Console.WriteLine(line);
147
				if (line.Length == 0 || line == null || line.StartsWith("#"))
148
					continue;
149

    
150
				switch (line)
151
				{
152
					case "!site!":
153
						extractedConfigInfo.DataWebsite = lines[++i].Trim();
154
						break;
155
					case "!naming_convention!":
156
						extractedConfigInfo.DownloadedFilesNaming = lines[++i].Trim();
157
						break;
158
					case "!data_root_dir!":
159
						string dirWithConfig = Path.GetDirectoryName(fullPathConfig);
160
						string rootPath = dirWithConfig + Path.DirectorySeparatorChar + lines[++i].Trim();
161
						extractedConfigInfo.DataRootDir = rootPath;
162
						
163
						break;
164
					case "!port!":
165
						extractedConfigInfo.Port = lines[++i].Trim();
166
						break;
167
					default: break;
168
				}
169
			}
170

    
171
			return extractedConfigInfo;
172
		}
173
    }
174
}
(2-2/5)