Projekt

Obecné

Profil

Stáhnout (4.18 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
			//p.Parse();
48

    
49

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

    
58

    
59

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

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

    
72
			List<string> retrievedData = dd.GetData(dd.DataSubDirectories[DataType.JIS], new Date(10, 2019), new Date(12, 2020));
73
			Console.WriteLine("Retrieved data: ");
74
			foreach (string s in retrievedData)
75
			{
76
				Console.WriteLine(s);
77
			}
78

    
79

    
80

    
81

    
82

    
83
			// test - connection:
84
			//ConnectionListener cl = new ConnectionListener(int.Parse(args[0])/*8000*//*int.Parse(config.Port)*/);
85
			//cl.StartListening();
86

    
87

    
88
			//NaiveBayesClassifier naiveBayesClassifier = new NaiveBayesClassifier();
89
			//IEnumerable<ModelInput> modelInput = naiveBayesClassifier.ExtractModelInput(p.weatherList, p.jisList);
90
			//naiveBayesClassifier.Fit(modelInput);
91
			//List<ModelInput> dataList = new List<ModelInput>()
92
			//{
93
			//    new ModelInput()
94
			//    {
95
			//        Temp = -40,
96
			//    }
97
			//};
98
			//var result = naiveBayesClassifier.Predict(dataList);
99

    
100
			//Console.WriteLine($"Predictions: ");
101
			//foreach(var item in result)
102
			//{
103
			//    Console.WriteLine(item.ToString());
104
			//}
105

    
106
			Console.ReadLine();
107
        }
108

    
109

    
110
        private static Config FillConfigInfo(string[] args)
111
		{
112

    
113
			Config extractedConfigInfo = new Config();
114

    
115
			Console.WriteLine(Directory.GetCurrentDirectory());
116
			
117
			if (args.Length != 1)
118
				Console.WriteLine("Wrong usage of parameters, pass the path to a config file."); // todo better explanation?
119

    
120
			string fullPathConfig = Path.GetFullPath(args[0]);
121
			string[] lines = null;
122
			try {
123
				lines = File.ReadAllLines(fullPathConfig);
124
			}
125
			catch(Exception ex)
126
			{
127
				Console.WriteLine("Could not open " + fullPathConfig);
128
				return null;
129
			}
130
			
131
			for (var i = 0; i < lines.Length; i += 1)
132
			{
133
				string line = lines[i];
134
				Console.WriteLine(line);
135
				if (line.Length == 0 || line == null || line.StartsWith("#"))
136
					continue;
137

    
138
				switch (line)
139
				{
140
					case "!site!":
141
						extractedConfigInfo.DataWebsite = lines[++i].Trim();
142
						break;
143
					case "!naming_convention!":
144
						extractedConfigInfo.DownloadedFilesNaming = lines[++i].Trim();
145
						break;
146
					case "!data_root_dir!":
147
						string dirWithConfig = Path.GetDirectoryName(fullPathConfig);
148
						string rootPath = dirWithConfig + Path.DirectorySeparatorChar + lines[++i].Trim();
149
						extractedConfigInfo.DataRootDir = rootPath;
150
						
151
						break;
152
					case "!port!":
153
						extractedConfigInfo.Port = lines[++i].Trim();
154
						break;
155
					default: break;
156
				}
157
			}
158

    
159
			return extractedConfigInfo;
160
		}
161
    }
162
}
(2-2/5)