Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 7a998d66

Přidáno uživatelem Eliška Mourycová před více než 3 roky(ů)

Re #8691. Big refactor + config file added + working on providing methods for Parser.

Zobrazit rozdíly:

Server/ServerApp/Program.cs
1
using Connection;
1
using ServerApp.Connection;
2
using ServerApp.DataDownload;
2 3
using ServerApp.Parser.Parsers;
3 4
using ServerApp.Predictor;
4 5
using System;
5 6
using System.Collections.Generic;
7
using System.IO;
6 8

  
7 9
namespace ServerApp
8 10
{
11

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

  
9 20
    class Program
10 21
    {
22

  
23

  
24

  
11 25
        static void Main(string[] args)
12 26
        {
13
            DataParser p = new DataParser("data/");
14 27

  
15
            //p.Parse();
28
            Config config = FillConfigInfo(args);
29
			if (config == null)
30
			{
31
				Console.ReadLine();
32
				return;
33
			}
34

  
35

  
36

  
37
			//DataParser p = new DataParser("data/");
38

  
39
			//p.Parse();
40

  
41

  
42
			// test scenario - data download:
43
			DataDownloader dd = new DataDownloader(config.DataRootDir, config.DataWebsite, config.DownloadedFilesNaming);
44
			dd.OverwriteExisting = false;
45
			List<string> savedFiles = new List<string>();
46
			savedFiles.AddRange(dd.DownloadData(DataType.JIS, DataFormat.CSV, new Date(1, 2017), new Date(12, 2020)));
47
			savedFiles.AddRange(dd.DownloadData(DataType.STROJE, DataFormat.CSV, new Date(1, 2017), new Date(12, 2020)));
48
			savedFiles.AddRange(dd.DownloadData(DataType.POCASI, DataFormat.CSV, new Date(1, 2017), new Date(12, 2020)));
49

  
16 50

  
17 51

  
18
            // test scenario - data download:
19
            //DataDownloader dd = new DataDownloader();
20
            //         List<string> savedFiles = new List<string>();
21
            //         savedFiles.AddRange(dd.DownloadData(DataType.JIS, DataFormat.CSV, 2017, 2021, 0, 13));
22
            //         savedFiles.AddRange(dd.DownloadData(DataType.POCASI, DataFormat.CSV, 2017, 2021, 0, 13));
23
            //         savedFiles.AddRange(dd.DownloadData(DataType.STROJE, DataFormat.CSV, 2017, 2021, 0, 13));
52
			Console.WriteLine("Saved files: ");
53
			foreach (string s in savedFiles)
54
			{
55
				Console.WriteLine(s);
56
			}
24 57

  
58
			Console.WriteLine("subdirectories: ");
59
			foreach (KeyValuePair<DataType, string> kvp in dd.DataSubDirectories)
60
			{
61
				Console.WriteLine("Key = {0}, Value = {1}", kvp.Key, kvp.Value);
62
			}
25 63

  
26
            //         Console.WriteLine("Saved files: ");
27
            //         foreach(string s in savedFiles)
28
            //{
29
            //             Console.WriteLine(s);
30
            //}
31 64

  
32 65

  
66
			// date testing
67
			//Date d1 = new Date(2, 2020);
68
			//Date d2 = new Date(1, 2019);
33 69

  
34
            // test - connection:
35
            AsynchronousSocketListener asl = new AsynchronousSocketListener();
36
            asl.StartListening();
37
           
70
			//Console.WriteLine("equals" + d1.Equals(d2));
71
			//Console.WriteLine("==" + (d1 == d2));
72
			//Console.WriteLine("!=" + (d1 != d2));
73
			//Console.WriteLine(">" + (d1 > d2));
74
			//Console.WriteLine("<" + (d1 < d2));
75
			//Console.WriteLine(">=" + (d1 >= d2));
76
			//Console.WriteLine("<=" + (d1 <= d2));
38 77

  
39
            NaiveBayesClassifier naiveBayesClassifier = new NaiveBayesClassifier();
40
            IEnumerable<ModelInput> modelInput = naiveBayesClassifier.ExtractModelInput(p.weatherList, p.jisList);
41
            naiveBayesClassifier.Fit(modelInput);
42
            List<ModelInput> dataList = new List<ModelInput>()
43
            {
44
                new ModelInput()
45
                {
46
                    Temp = -40,
47
                }
48
            };
49
            var result = naiveBayesClassifier.Predict(dataList);
50 78

  
51
            Console.WriteLine($"Predictions: ");
52
            foreach(var item in result)
53
            {
54
                Console.WriteLine(item.ToString());
55
            }
56 79

  
57
            Console.ReadLine();
80

  
81
			// test - connection:
82
			//AsynchronousSocketListener asl = new AsynchronousSocketListener();
83
			//         asl.StartListening();
84

  
85

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

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

  
104
			Console.ReadLine();
58 105
        }
106

  
107

  
108
        private static Config FillConfigInfo(string[] args)
109
		{
110

  
111
			Config extractedConfigInfo = new Config();
112

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

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

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

  
157
			return extractedConfigInfo;
158
		}
59 159
    }
60 160
}

Také k dispozici: Unified diff