Projekt

Obecné

Profil

« Předchozí | Další » 

Revize f7eb37b3

Přidáno uživatelem Eliška Mourycová před téměř 4 roky(ů)

Refactor + logging config modification

Zobrazit rozdíly:

Server/ServerApp/Program.cs
1
using log4net.Config;
1
using log4net;
2
using log4net.Config;
2 3
using ServerApp.Connection;
3 4
using ServerApp.Connection.XMLProtocolHandler;
4 5
using ServerApp.DataDownload;
......
27 28

  
28 29
    public class Program
29 30
    {
31
		// logger class instance
32
		private static readonly ILog logger = LogManager.GetLogger(typeof(Program));
30 33

  
31
        static void Main(string[] args)
34
		static void Main(string[] args)
32 35
        {
36
			Console.WriteLine("Server start.");
37

  
33 38
            // setup logging service
34 39
            XmlConfigurator.Configure();
35 40

  
......
41 46
				Console.ReadLine();
42 47
				return;
43 48
			}
49
			Console.WriteLine("Config parsing successful.");
50

  
51
			//logger.Debug("ahoj");
52
			//logger.Warn("ahoj2");
53
			//Console.ReadLine();
44 54

  
45
			// data download test
46
			DataDownloader dd = DataDownloadAndRetrievalTest(config);
55
			// data download init
56
			Console.WriteLine("Downloading open data...");
57
			DataDownloader dd = DataDownloaderInit(config);
58
			Console.WriteLine("Data downloaded and saved.");
47 59

  
48 60
			//WeatherAsStringTest(dd);
49 61
			//Console.ReadLine();
......
51 63
			// xml building test
52 64
			//XMLTest();
53 65

  
54
			// PARSE DATA
55
			//DataParser parser = new DataParser(dd);
56
			//parser.Parse(new DateTime())
57 66

  
58 67
			// json parser test
59 68
			//JSONParserTest();
60 69

  
61
			// model test
62
			IPredictionController controller = PredictionTest(dd);
70
			// model init
71
			Console.WriteLine("Training the predictor...");
72
			IPredictionController controller = PredictionControllerInit(dd);
73
			Console.WriteLine("Predictor training finished.");
63 74

  
64
			//parse(new DateTime(2019, 10, 5), , interval = 1, wholeDay = true)
65 75

  
66 76
			// commands accepting test
67 77
			// create a thread for commands accepting:
......
70 80
			inputThread.Start();
71 81

  
72 82

  
73
			// connection test
74
			ConnectionTest(controller, config);
83
			// connection init
84
			ConnectionInit(controller, config);
75 85

  
76
			//Console.ReadLine();
77 86
        }
78 87

  
79 88

  
80
		private static DataDownloader DataDownloadAndRetrievalTest(Config config)
89
		private static DataDownloader DataDownloaderInit(Config config)
81 90
		{
82 91
			//test scenario -data download:
83 92
			DataDownloader dd = new DataDownloader(config.DataRootDir, config.DataWebsite, config.DownloadedFilesNaming, config.WeatherSite);
......
91 100

  
92 101

  
93 102

  
94
			Console.WriteLine("Saved files: ");
95
			foreach (string s in savedFiles)
96
			{
97
				Console.WriteLine(s);
98
			}
103
			//Console.WriteLine("Saved files: ");
104
			//foreach (string s in savedFiles)
105
			//{
106
			//	Console.WriteLine(s);
107
			//}
99 108

  
100
			Console.WriteLine("subdirectories: ");
101
			foreach (KeyValuePair<DataType, string> kvp in dd.DataSubDirectories)
102
			{
103
				Console.WriteLine("Key = {0}, Value = {1}", kvp.Key, kvp.Value);
104
			}
109
			//Console.WriteLine("subdirectories: ");
110
			//foreach (KeyValuePair<DataType, string> kvp in dd.DataSubDirectories)
111
			//{
112
			//	Console.WriteLine("Key = {0}, Value = {1}", kvp.Key, kvp.Value);
113
			//}
105 114

  
106
			List<string> retrievedData = dd.GetData(dd.DataSubDirectories[DataType.JIS], new DataDownload.Date(10, 2019), new DataDownload.Date(12, 2020));
107
			Console.WriteLine("Retrieved data: ");
108
			foreach (string s in retrievedData)
109
			{
110
				Console.WriteLine(s);
111
			}
112
			Console.WriteLine("all from directory:");
113
			retrievedData = dd.GetData(dd.DataSubDirectories[DataType.JIS], null, null);
114
			foreach (string s in retrievedData)
115
			{
116
				Console.WriteLine(s);
117
			}
115
			//List<string> retrievedData = dd.GetData(dd.DataSubDirectories[DataType.JIS], new DataDownload.Date(10, 2019), new DataDownload.Date(12, 2020));
116
			//Console.WriteLine("Retrieved data: ");
117
			//foreach (string s in retrievedData)
118
			//{
119
			//	Console.WriteLine(s);
120
			//}
121
			//Console.WriteLine("all from directory:");
122
			//retrievedData = dd.GetData(dd.DataSubDirectories[DataType.JIS], null, null);
123
			//foreach (string s in retrievedData)
124
			//{
125
			//	Console.WriteLine(s);
126
			//}
118 127

  
119 128

  
120 129
			return dd;
......
166 175
			Console.WriteLine(dd.DownloadWeatherPrediction());
167 176
		}
168 177

  
169
		private static IPredictionController PredictionTest(DataDownloader dd)
178
		private static IPredictionController PredictionControllerInit(DataDownloader dd)
170 179
		{
171
			// TODO nastavit čas
172 180
			IDataParser p = new DataParser(dd);
173 181
            // FIXME pass the right references to the JsonParser constructor
174 182
            IJsonParser jsonP = new JsonParser(dd, new CsvDataLoader());
175 183
            IPredictionController predictionController = new PredictionController(jsonP, p);
176 184
            predictionController.Train();
177
            //var results = predictionController.Predict()
178 185
			
179 186

  
180 187
			return predictionController;
181 188
		}
182 189

  
183
		private static void ConnectionTest(IPredictionController predictionController, Config config)
190
		private static void ConnectionInit(IPredictionController predictionController, Config config)
184 191
		{
185 192
			ConnectionListenerAsync cl = new ConnectionListenerAsync(int.Parse(config.Port), predictionController);
186 193
			cl.StartListening();
......
195 202

  
196 203
			Config extractedConfigInfo = new Config();
197 204

  
198
			Console.WriteLine(Directory.GetCurrentDirectory());
199 205
			Console.WriteLine("Parsing configuration file...");
200 206
			
201 207
			if (args.Length != 1)

Také k dispozici: Unified diff