Revize 9a529f10
Přidáno uživatelem Roman Kalivoda před téměř 4 roky(ů)
Server/ServerApp/Connection/ConnectionListener.cs | ||
---|---|---|
46 | 46 |
MethodInfo getEPListener = hepmType.GetMethod("GetEPListener", BindingFlags.Static | BindingFlags.NonPublic); |
47 | 47 |
FieldInfo heplCert = heplType.GetField("_cert", BindingFlags.NonPublic | BindingFlags.Instance); |
48 | 48 |
object epl = getEPListener.Invoke(null, new object[] { "*", PORT, listener, true }); |
49 |
// FIXME replace the magic string below with value loaded from config file |
|
49 | 50 |
X509Certificate cert = new X509Certificate2("cert.p12", "changeit"); |
50 | 51 |
heplCert.SetValue(epl, cert); |
51 | 52 |
|
Server/ServerApp/Predictor/PredictionController.cs | ||
---|---|---|
100 | 100 |
di.Create(); |
101 | 101 |
} |
102 | 102 |
FileInfo[] files = di.GetFiles(); |
103 |
if (Array.FindAll(files, f => Regex.IsMatch(f.Name, @"[-]?\d+_\d+.zip")).GroupBy(f => f.Name.Split("_.".ToCharArray())[0]).OrderBy(f => DateTime.FromBinary(Convert.ToInt64(f.Key))).Count() == Configuration.PredictorCount) |
|
103 |
var orderedEnumerable = Array.FindAll(files, f => Regex.IsMatch(f.Name, @"[-]?\d+_\d+.zip")).GroupBy(f => f.Name.Split("_.".ToCharArray())[0]).OrderBy(f => DateTime.FromBinary(Convert.ToInt64(f.Key))); |
|
104 |
if (orderedEnumerable.Where(g => g.Count() == Configuration.PredictorCount).Any()) |
|
104 | 105 |
{ |
105 | 106 |
_log.Info("Found existing predictors, loading the newest."); |
106 |
var predictorID = Array.FindAll(files, f => Regex.IsMatch(f.Name, @"[-]?\d+_\d+.zip")).GroupBy(f => f.Name.Split("_.".ToCharArray())[0]).OrderBy(f => DateTime.FromBinary(Convert.ToInt64(f.Key))).Last().Select(f => f.Name.Split("_".ToCharArray())[0]).First();
|
|
107 |
var predictorID = orderedEnumerable.Last().Select(f => f.Name.Split("_".ToCharArray())[0]).First();
|
|
107 | 108 |
this.Load(predictorID); |
108 | 109 |
} |
109 | 110 |
else |
... | ... | |
192 | 193 |
return 2; |
193 | 194 |
} |
194 | 195 |
FileInfo[] files = di.GetFiles(); |
195 |
if (Array.FindAll(files, f => Regex.IsMatch(f.Name, @"[-]?\d+_\d+.zip")).GroupBy(f => f.Name.Split("_.".ToCharArray())[0]).OrderBy(f => DateTime.FromBinary(Convert.ToInt64(f.Key))).Count() == Configuration.PredictorCount) |
|
196 |
var orderedEnumerable = Array.FindAll(files, f => Regex.IsMatch(f.Name, @"[-]?\d+_\d+.zip")).GroupBy(f => f.Name.Split("_.".ToCharArray())[0]).OrderBy(f => DateTime.FromBinary(Convert.ToInt64(f.Key))).Where(f => ! f.Key.Equals(this.PredictorID)); |
|
197 |
if (orderedEnumerable.Where(g => g.Count() == Configuration.PredictorCount).Any()) |
|
196 | 198 |
{ |
197 |
string RollbackedPredictorID = Array.FindAll(files, f => Regex.IsMatch(f.Name, @"[-]?\d+_\d+.zip")).GroupBy(f => f.Name.Split("_.".ToCharArray())[0]).OrderBy(f => DateTime.FromBinary(Convert.ToInt64(f.Key))).Last().Select(f => f.Name.Split("_".ToCharArray())[0]).First();
|
|
199 |
string RollbackedPredictorID = orderedEnumerable.Last().Select(f => f.Name.Split("_".ToCharArray())[0]).First();
|
|
198 | 200 |
this.Delete(this.PredictorID); |
199 | 201 |
return this.Load(RollbackedPredictorID); |
200 | 202 |
} else |
... | ... | |
229 | 231 |
{ |
230 | 232 |
DateTime end = new DateTime(year: request.end.year, month: request.end.month, day: request.end.day, hour: request.end.hour, minute: 0, second: 0); |
231 | 233 |
DateTime current = start; |
232 |
while (current < end) |
|
234 |
while (current <= end)
|
|
233 | 235 |
{ |
234 | 236 |
_log.Debug($"Predicting for date {current.Date.ToShortDateString()}"); |
235 |
while (current.Hour < Date.MAX_HOUR) |
|
237 |
while (current.Hour <= Date.MAX_HOUR)
|
|
236 | 238 |
{ |
239 |
if (current.Date == end.Date && current.Hour > end.Hour) |
|
240 |
{ |
|
241 |
break; // break if the end date was reached and hour is after the end time. |
|
242 |
} |
|
237 | 243 |
_log.Debug($"Predicting for time {current.TimeOfDay.ToString()}"); |
238 | 244 |
var prediction = PredictSingle(request, current); |
239 | 245 |
predictions.Add(prediction); |
Server/ServerApp/Properties/launchSettings.json | ||
---|---|---|
2 | 2 |
"profiles": { |
3 | 3 |
"ServerApp": { |
4 | 4 |
"commandName": "Project", |
5 |
"commandLineArgs": ".\\server_config"
|
|
5 |
"commandLineArgs": "C:\\Users\\kalivoda\\University\\KIV-ASWI\\aswi2021tri-musketyri\\Server\\ServerApp\\server_config"
|
|
6 | 6 |
} |
7 | 7 |
} |
8 | 8 |
} |
Server/ServerAppFunctionalTests/Predictor/PredictionControllerTests.cs | ||
---|---|---|
21 | 21 |
[TestClass()] |
22 | 22 |
public class PredictionControllerTests |
23 | 23 |
{ |
24 |
static PredictionController instance; |
|
25 |
|
|
24 | 26 |
[AssemblyInitialize()] |
25 | 27 |
public static void ClassInit(TestContext context) |
26 | 28 |
{ |
27 | 29 |
// setup logging service |
28 | 30 |
XmlConfigurator.Configure(); |
29 |
} |
|
30 |
|
|
31 |
[TestMethod()] |
|
32 |
public void PredictSingleTimeWeatherTest() |
|
33 |
{ |
|
34 | 31 |
System.IO.Directory.CreateDirectory(@".\data"); |
35 | 32 |
DataDownloader dd = new DataDownloader(@".\data\dd\", "http://openstore.zcu.cz/", "OD_ZCU_{type}_{month}_{year}_{format}.zip", "http://wttr.in/Plzen,czechia?format=j1"); |
36 |
PredictionController instance = new PredictionController(new JsonParser(dd, new CsvDataLoader()), new DataParser(dd));
|
|
33 |
instance = new PredictionController(new JsonParser(dd, new CsvDataLoader()), new DataParser(dd)); |
|
37 | 34 |
|
38 | 35 |
dd.DownloadData(DataType.JIS, DataFormat.CSV, new DataDownload.Date(1, 2019), new DataDownload.Date(12, 2020)); |
39 | 36 |
dd.DownloadData(DataType.STROJE, DataFormat.CSV, new DataDownload.Date(1, 2017), new DataDownload.Date(12, 2020)); |
40 | 37 |
dd.DownloadData(DataType.POCASI, DataFormat.CSV, new DataDownload.Date(1, 2017), new DataDownload.Date(12, 2020)); |
41 | 38 |
instance.Train(); |
39 |
} |
|
42 | 40 |
|
41 |
[TestMethod()] |
|
42 |
public void PredictSingleTimeWeatherTest() |
|
43 |
{ |
|
43 | 44 |
Request request = new Request() |
44 | 45 |
{ |
45 | 46 |
useEndDate = false, |
... | ... | |
56 | 57 |
CollectionAssert.AllItemsAreInstancesOfType(actual.predicitons, typeof(Prediction)); |
57 | 58 |
Assert.AreEqual(1, actual.predicitons.Length); |
58 | 59 |
} |
60 |
|
|
61 |
[TestMethod()] |
|
62 |
public void PredictStartEndWithinSingleDayTest() |
|
63 |
{ |
|
64 |
Request request = new Request |
|
65 |
{ |
|
66 |
useWeather = false, |
|
67 |
temperature = -0, |
|
68 |
wind = -0, |
|
69 |
rain = -0, |
|
70 |
weather = WeatherCondition.Sunny, |
|
71 |
useEndDate = true, |
|
72 |
start = new Connection.XMLProtocolHandler.Date |
|
73 |
{ |
|
74 |
day = 11, |
|
75 |
month = 6, |
|
76 |
year = 2021, |
|
77 |
hour = 7 |
|
78 |
}, |
|
79 |
end = new Connection.XMLProtocolHandler.Date |
|
80 |
{ |
|
81 |
day = 11, |
|
82 |
month = 6, |
|
83 |
year = 2021, |
|
84 |
hour = 12 |
|
85 |
} |
|
86 |
}; |
|
87 |
Response actual = instance.Predict(request); |
|
88 |
Assert.IsTrue(Math.Abs(actual.predicitons[0].dateTime.hour - request.start.hour) <= instance.Configuration.TimeResolution); |
|
89 |
Assert.IsTrue(Math.Abs(actual.predicitons[actual.predicitons.Length - 1].dateTime.hour - request.end.hour) <= instance.Configuration.TimeResolution); |
|
90 |
} |
|
91 |
|
|
92 |
[TestMethod()] |
|
93 |
public void PredictStartEndEqualTest() |
|
94 |
{ |
|
95 |
Request request = new Request |
|
96 |
{ |
|
97 |
useWeather = false, |
|
98 |
temperature = -0, |
|
99 |
wind = -0, |
|
100 |
rain = -0, |
|
101 |
weather = WeatherCondition.Sunny, |
|
102 |
useEndDate = true, |
|
103 |
start = new Connection.XMLProtocolHandler.Date |
|
104 |
{ |
|
105 |
day = 11, |
|
106 |
month = 6, |
|
107 |
year = 2021, |
|
108 |
hour = 7 |
|
109 |
}, |
|
110 |
end = new Connection.XMLProtocolHandler.Date |
|
111 |
{ |
|
112 |
day = 11, |
|
113 |
month = 6, |
|
114 |
year = 2021, |
|
115 |
hour = 7 |
|
116 |
} |
|
117 |
}; |
|
118 |
Response actual = instance.Predict(request); |
|
119 |
Assert.IsTrue(actual.predicitons.Length == 1); |
|
120 |
} |
|
121 |
|
|
122 |
[TestMethod()] |
|
123 |
public void RollbackTest() |
|
124 |
{ |
|
125 |
instance.Train(); |
|
126 |
int actual = instance.Rollback(); |
|
127 |
Assert.AreEqual(0, actual); |
|
128 |
} |
|
59 | 129 |
} |
60 | 130 |
} |
Server/ServerAppUnitTests/Predictor/PredictionControllerTests.cs | ||
---|---|---|
1 |
using Microsoft.VisualStudio.TestTools.UnitTesting; |
|
2 |
using Moq; |
|
3 |
using ServerApp.Connection.XMLProtocolHandler; |
|
4 |
using ServerApp.Parser.Parsers; |
|
5 |
using ServerApp.Predictor; |
|
6 |
using ServerApp.WeatherPredictionParser; |
|
7 |
// |
|
8 |
// Author: Roman Kalivoda |
|
9 |
// |
|
10 |
|
|
11 |
using System; |
|
12 |
using System.Collections.Generic; |
|
13 |
using System.Linq; |
|
14 |
using System.Text; |
|
15 |
using System.Threading.Tasks; |
|
16 |
|
|
17 |
namespace ServerApp.Predictor.Tests |
|
18 |
{ |
|
19 |
[TestClass()] |
|
20 |
public class PredictionControllerTests |
|
21 |
{ |
|
22 |
|
|
23 |
} |
|
24 |
} |
Také k dispozici: Unified diff
Re #9063 Refactoring, fixing bugs