Projekt

Obecné

Profil

Stáhnout (4.23 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 3811845f Alex Konig
using System;
7
using System.Collections.Generic;
8 7a998d66 Eliška Mourycová
using System.IO;
9 4a417b8b Eliška Mourycová
using System.Threading;
10 3811845f Alex Konig
11
namespace ServerApp
12
{
13 7a998d66 Eliška Mourycová
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 4a417b8b Eliška Mourycová
    public class Program
23 3811845f Alex Konig
    {
24 7a998d66 Eliška Mourycová
25 4a417b8b Eliška Mourycová
		public static void NotifyUserMessage(string message)
26
		{
27
			Console.WriteLine("Received user message: " + message);
28
		}
29 7a998d66 Eliška Mourycová
30 3811845f Alex Konig
        static void Main(string[] args)
31
        {
32
33 e257ae8f Eliška Mourycová
   //         Config config = FillConfigInfo(args);
34
			//if (config == null)
35
			//{
36
			//	Console.ReadLine();
37
			//	return;
38
			//}
39 7a998d66 Eliška Mourycová
40 4a417b8b Eliška Mourycová
			// create a thread for commands accepting:
41
			//Thread inputThread = new Thread(CommandsAcceptor.AcceptCommand);
42
			//inputThread.Start();
43
44 7a998d66 Eliška Mourycová
45
46
			//DataParser p = new DataParser("data/");
47
48
			//p.Parse();
49
50
51
			// test scenario - data download:
52 e257ae8f Eliška Mourycová
			//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 085453be Eliška Mourycová
59
60
61 e257ae8f Eliška Mourycová
			//Console.WriteLine("Saved files: ");
62
			//foreach (string s in savedFiles)
63
			//{
64
			//	Console.WriteLine(s);
65
			//}
66 d2d1c86a Eliška Mourycová
67 e257ae8f Eliška Mourycová
			//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 36c0667f Eliška Mourycová
73 e257ae8f Eliška Mourycová
			//List<string> retrievedData = dd.GetData(dd.DataSubDirectories[DataType.JIS], new Date(10, 2019), new Date(12, 2020));
74
			//Console.WriteLine("Retrieved data: ");
75
			//foreach (string s in retrievedData)
76
			//{
77
			//	Console.WriteLine(s);
78
			//}
79 36c0667f Eliška Mourycová
80 3811845f Alex Konig
81 9fc5fa93 Roman Kalivoda
82
83 7a998d66 Eliška Mourycová
84
			// test - connection:
85 e257ae8f Eliška Mourycová
			ConnectionListener cl = new ConnectionListener(8000/*int.Parse(config.Port)*/);
86
			cl.StartListening();
87 7a998d66 Eliška Mourycová
88
89
			//NaiveBayesClassifier naiveBayesClassifier = new NaiveBayesClassifier();
90
			//IEnumerable<ModelInput> modelInput = naiveBayesClassifier.ExtractModelInput(p.weatherList, p.jisList);
91
			//naiveBayesClassifier.Fit(modelInput);
92
			//List<ModelInput> dataList = new List<ModelInput>()
93
			//{
94
			//    new ModelInput()
95
			//    {
96
			//        Temp = -40,
97
			//    }
98
			//};
99
			//var result = naiveBayesClassifier.Predict(dataList);
100
101
			//Console.WriteLine($"Predictions: ");
102
			//foreach(var item in result)
103
			//{
104
			//    Console.WriteLine(item.ToString());
105
			//}
106
107
			Console.ReadLine();
108 3811845f Alex Konig
        }
109 7a998d66 Eliška Mourycová
110
111
        private static Config FillConfigInfo(string[] args)
112
		{
113
114
			Config extractedConfigInfo = new Config();
115
116
			Console.WriteLine(Directory.GetCurrentDirectory());
117
			
118
			if (args.Length != 1)
119
				Console.WriteLine("Wrong usage of parameters, pass the path to a config file."); // todo better explanation?
120
121
			string fullPathConfig = Path.GetFullPath(args[0]);
122
			string[] lines = null;
123
			try {
124
				lines = File.ReadAllLines(fullPathConfig);
125
			}
126
			catch(Exception ex)
127
			{
128
				Console.WriteLine("Could not open " + fullPathConfig);
129
				return null;
130
			}
131
			
132
			for (var i = 0; i < lines.Length; i += 1)
133
			{
134
				string line = lines[i];
135
				Console.WriteLine(line);
136
				if (line.Length == 0 || line == null || line.StartsWith("#"))
137
					continue;
138
139
				switch (line)
140
				{
141
					case "!site!":
142
						extractedConfigInfo.DataWebsite = lines[++i].Trim();
143
						break;
144
					case "!naming_convention!":
145
						extractedConfigInfo.DownloadedFilesNaming = lines[++i].Trim();
146
						break;
147
					case "!data_root_dir!":
148
						string dirWithConfig = Path.GetDirectoryName(fullPathConfig);
149
						string rootPath = dirWithConfig + Path.DirectorySeparatorChar + lines[++i].Trim();
150
						extractedConfigInfo.DataRootDir = rootPath;
151
						
152
						break;
153
					case "!port!":
154
						extractedConfigInfo.Port = lines[++i].Trim();
155
						break;
156
					default: break;
157
				}
158
			}
159
160
			return extractedConfigInfo;
161
		}
162 3811845f Alex Konig
    }
163
}