Revize 734533a8
Přidáno uživatelem Alex Konig před více než 3 roky(ů)
Server/ServerApp.sln | ||
---|---|---|
1 |
|
|
1 |
|
|
2 | 2 |
Microsoft Visual Studio Solution File, Format Version 12.00 |
3 | 3 |
# Visual Studio Version 16 |
4 | 4 |
VisualStudioVersion = 16.0.31105.61 |
5 | 5 |
MinimumVisualStudioVersion = 10.0.40219.1 |
6 |
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ServerApp", "ServerApp\ServerApp.csproj", "{916C1E8A-0D6D-43FB-8BDE-DBEDF441842D}"
|
|
6 |
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ServerApp", "ServerApp\ServerApp.csproj", "{B49B2821-751C-4032-8637-B4E9282DCF06}"
|
|
7 | 7 |
EndProject |
8 | 8 |
Global |
9 | 9 |
GlobalSection(SolutionConfigurationPlatforms) = preSolution |
... | ... | |
11 | 11 |
Release|Any CPU = Release|Any CPU |
12 | 12 |
EndGlobalSection |
13 | 13 |
GlobalSection(ProjectConfigurationPlatforms) = postSolution |
14 |
{916C1E8A-0D6D-43FB-8BDE-DBEDF441842D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
15 |
{916C1E8A-0D6D-43FB-8BDE-DBEDF441842D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
16 |
{916C1E8A-0D6D-43FB-8BDE-DBEDF441842D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
17 |
{916C1E8A-0D6D-43FB-8BDE-DBEDF441842D}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
14 |
{B49B2821-751C-4032-8637-B4E9282DCF06}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
15 |
{B49B2821-751C-4032-8637-B4E9282DCF06}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
16 |
{B49B2821-751C-4032-8637-B4E9282DCF06}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
17 |
{B49B2821-751C-4032-8637-B4E9282DCF06}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
18 | 18 |
EndGlobalSection |
19 | 19 |
GlobalSection(SolutionProperties) = preSolution |
20 | 20 |
HideSolutionNode = FALSE |
21 | 21 |
EndGlobalSection |
22 | 22 |
GlobalSection(ExtensibilityGlobals) = postSolution |
23 |
SolutionGuid = {4E18E2F7-ED86-43DF-9B8D-47294B10BA49}
|
|
23 |
SolutionGuid = {CF3D6A57-E659-4E12-884C-6346F59A3735}
|
|
24 | 24 |
EndGlobalSection |
25 | 25 |
EndGlobal |
Server/ServerApp/Parser/InputData/CsvDataLoader.cs | ||
---|---|---|
3 | 3 |
using System.Globalization; |
4 | 4 |
using System.IO; |
5 | 5 |
|
6 |
namespace Parser.InputData |
|
6 |
namespace ServerApp.Parser.InputData
|
|
7 | 7 |
{ |
8 |
/// <summary> |
|
9 |
/// Class responsible for loading data from file |
|
10 |
/// </summary> |
|
8 | 11 |
static class CsvDataLoader |
9 | 12 |
{ |
13 |
/// <summary> Culture info for parsing numbers </summary> |
|
10 | 14 |
static CultureInfo cultureInfo = new CultureInfo("de-DE"); |
11 | 15 |
|
16 |
/// <summary> |
|
17 |
/// Load csv file into array |
|
18 |
/// </summary> |
|
19 |
/// <param name="name">Path to file</param> |
|
20 |
/// <returns>Array with loaded data</returns> |
|
12 | 21 |
static string[] LoadCsv(string name) |
13 | 22 |
{ |
14 | 23 |
string[] lines = File.ReadAllLines(name); |
15 | 24 |
return lines; |
16 | 25 |
} |
17 | 26 |
|
27 |
/// <summary> |
|
28 |
/// Load jis data from file |
|
29 |
/// </summary> |
|
30 |
/// <param name="pathToFile">Path to file</param> |
|
31 |
/// <returns></returns> |
|
18 | 32 |
public static List<JisInstance> LoadJisFile(string pathToFile) |
19 | 33 |
{ |
20 | 34 |
var lines = LoadCsv(pathToFile); |
... | ... | |
38 | 52 |
return list; |
39 | 53 |
} |
40 | 54 |
|
55 |
/// <summary> |
|
56 |
/// Load login data from file |
|
57 |
/// </summary> |
|
58 |
/// <param name="pathToFile">Path to file</param> |
|
59 |
/// <returns></returns> |
|
41 | 60 |
public static List<LogInInstance> LoadLoginFile(string pathToFile) |
42 | 61 |
{ |
43 | 62 |
var lines = LoadCsv(pathToFile); |
... | ... | |
71 | 90 |
return list; |
72 | 91 |
} |
73 | 92 |
|
93 |
/// <summary> |
|
94 |
/// Load weather data from file |
|
95 |
/// </summary> |
|
96 |
/// <param name="pathToFile">Path to file</param> |
|
97 |
/// <returns></returns> |
|
74 | 98 |
public static List<WeatherInstance> LoadWeatherFile(string pathToFile) |
75 | 99 |
{ |
76 | 100 |
var lines = LoadCsv(pathToFile); |
Server/ServerApp/Parser/InputData/JisInstance.cs | ||
---|---|---|
1 | 1 |
using System; |
2 | 2 |
|
3 |
namespace Parser.InputData |
|
3 |
namespace ServerApp.Parser.InputData
|
|
4 | 4 |
{ |
5 | 5 |
/// <summary> |
6 |
/// |
|
6 |
/// Data from jis data file |
|
7 |
/// |
|
7 | 8 |
/// Data contains: |
8 | 9 |
/// datum_a_cas - timestamp of JIS authentication(accuracy in milliseconds) |
9 | 10 |
/// pocet_logu - number of authentized users in given time |
... | ... | |
14 | 15 |
/// </summary> |
15 | 16 |
class JisInstance |
16 | 17 |
{ |
17 |
//0 |
|
18 |
/// <summary> Place tag </summary> |
|
19 |
// index 0 |
|
18 | 20 |
public string placeTag; |
19 |
//1 |
|
21 |
/// <summary> Date time </summary> |
|
22 |
// index 1 |
|
20 | 23 |
public DateTime dateTime; |
21 |
//2 |
|
24 |
/// <summary> Number of events </summary> |
|
25 |
// index 2 |
|
22 | 26 |
public int amount; |
23 | 27 |
|
28 |
/// <summary> |
|
29 |
/// Constructor |
|
30 |
/// </summary> |
|
31 |
/// <param name="placeTag"></param> |
|
32 |
/// <param name="dateTime"></param> |
|
33 |
/// <param name="amount"></param> |
|
24 | 34 |
public JisInstance(string placeTag, DateTime dateTime, int amount) |
25 | 35 |
{ |
26 | 36 |
this.placeTag = placeTag; |
Server/ServerApp/Parser/InputData/LogInInstance.cs | ||
---|---|---|
1 | 1 |
using System; |
2 | 2 |
|
3 |
namespace Parser.InputData |
|
3 |
namespace ServerApp.Parser.InputData
|
|
4 | 4 |
{ |
5 | 5 |
|
6 | 6 |
/// <summary> |
7 |
/// |
|
7 |
/// Data from login data file
|
|
8 | 8 |
/// |
9 | 9 |
/// Data contains: |
10 | 10 |
/// datum - date of access |
... | ... | |
22 | 22 |
/// </summary> |
23 | 23 |
class LogInInstance |
24 | 24 |
{ |
25 |
/// <summary> Date time </summary> |
|
25 | 26 |
// index 0 |
26 | 27 |
public DateTime date; |
28 |
/// <summary> Number of events </summary> |
|
27 | 29 |
// index 1 |
28 | 30 |
public int amount; |
29 | 31 |
// index 2 |
30 | 32 |
public int lesson; |
33 |
/// <summary> Time of the start of the lesson </summary> |
|
31 | 34 |
// index 3 |
32 | 35 |
public DateTime lessonStart; |
36 |
/// <summary> Time of the endof the lesson </summary> |
|
33 | 37 |
// index 4 |
34 | 38 |
public DateTime lessonEnd; |
39 |
/// <summary> Building tag </summary> |
|
35 | 40 |
// index 5 |
36 | 41 |
public string building; |
42 |
/// <summary> Room type </summary> |
|
37 | 43 |
// index 6 |
38 | 44 |
public string roomType; |
45 |
/// <summary> Room number </summary> |
|
39 | 46 |
// index 7 |
40 | 47 |
public string room; |
48 |
/// <summary> PC hostname </summary> |
|
41 | 49 |
// index 8 |
42 | 50 |
public string hostname; |
43 |
|
|
44 | 51 |
|
52 |
/// <summary> |
|
53 |
/// Constructor |
|
54 |
/// </summary> |
|
55 |
/// <param name="date"></param> |
|
56 |
/// <param name="amount"></param> |
|
57 |
/// <param name="lesson"></param> |
|
58 |
/// <param name="lessonStart"></param> |
|
59 |
/// <param name="lessonEnd"></param> |
|
60 |
/// <param name="building"></param> |
|
61 |
/// <param name="roomtType"></param> |
|
62 |
/// <param name="room"></param> |
|
63 |
/// <param name="hostname"></param> |
|
45 | 64 |
public LogInInstance(DateTime date, int amount, int lesson, DateTime lessonStart, DateTime lessonEnd, string building, string roomtType, string room, string hostname) |
46 | 65 |
{ |
47 | 66 |
this.date = date; |
... | ... | |
55 | 74 |
this.hostname = hostname; |
56 | 75 |
} |
57 | 76 |
|
77 |
/// <summary> |
|
78 |
/// To string |
|
79 |
/// </summary> |
|
80 |
/// <returns></returns> |
|
58 | 81 |
public override string ToString() |
59 | 82 |
{ |
60 | 83 |
return date + " " + room + " " + lessonStart + "-" + lessonEnd + " " + amount; |
Server/ServerApp/Parser/InputData/WeatherInstance.cs | ||
---|---|---|
1 | 1 |
using System; |
2 | 2 |
|
3 |
namespace Parser.InputData |
|
3 |
namespace ServerApp.Parser.InputData
|
|
4 | 4 |
{ |
5 | 5 |
/// <summary> |
6 |
/// Data from weather data file |
|
6 | 7 |
/// |
7 | 8 |
/// Csv format: |
8 | 9 |
/// "30.04.2019 16:19:01";20.3;5.3;0;19 |
... | ... | |
10 | 11 |
/// </summary> |
11 | 12 |
class WeatherInstance |
12 | 13 |
{ |
13 |
// 0 |
|
14 |
/// <summary> Date and time </summary> |
|
15 |
// index 0 |
|
14 | 16 |
public DateTime dateTime; |
15 |
// 1 |
|
17 |
/// <summary> Temperature in °C </summary> |
|
18 |
// index 1 |
|
16 | 19 |
public double temp; |
17 |
// 2 |
|
20 |
/// <summary> Wind in m/s </summary> |
|
21 |
// index 2 |
|
18 | 22 |
public double wind; |
19 |
// 3 |
|
23 |
/// <summary> Rain (0 if none, 1 if rain) </summary> |
|
24 |
// index 3 |
|
20 | 25 |
public int rain; |
21 |
// 4 |
|
26 |
/// <summary> Luminance in klux </summary> |
|
27 |
// index 4 |
|
22 | 28 |
public double lum; |
23 | 29 |
|
30 |
/// <summary> |
|
31 |
/// Constructor |
|
32 |
/// </summary> |
|
33 |
/// <param name="date"></param> |
|
34 |
/// <param name="temp"></param> |
|
35 |
/// <param name="wind"></param> |
|
36 |
/// <param name="rain"></param> |
|
37 |
/// <param name="lum"></param> |
|
24 | 38 |
public WeatherInstance(DateTime date, double temp, double wind, int rain, double lum) |
25 | 39 |
{ |
26 | 40 |
this.dateTime = date; |
Server/ServerApp/Parser/OutputInfo/ActivityInfo.cs | ||
---|---|---|
1 |
using System; |
|
2 |
|
|
3 |
namespace ServerApp.Parser.OutputInfo |
|
4 |
{ |
|
5 |
/// <summary> |
|
6 |
/// Class representing the number of events in a given time interval a given faculty |
|
7 |
/// - shortest possible interval is 1h |
|
8 |
/// </summary> |
|
9 |
class ActivityInfo |
|
10 |
{ |
|
11 |
/// <summary> Faculty </summary> |
|
12 |
public string faculty; |
|
13 |
/// <summary> Number of events </summary> |
|
14 |
public int amount; |
|
15 |
/// <summary> Start of interval </summary> |
|
16 |
public DateTime startTime; |
|
17 |
/// <summary> Length of interval in hours </summary> |
|
18 |
public int intervalLength; |
|
19 |
|
|
20 |
/// <summary> |
|
21 |
/// Constructor |
|
22 |
/// </summary> |
|
23 |
/// <param name="faculty">Faculty</param> |
|
24 |
/// <param name="amount">Number of events</param> |
|
25 |
/// <param name="startTime">Start of recorded interval</param> |
|
26 |
/// <param name="intervalLength">Length of recorded interval</param> |
|
27 |
public ActivityInfo(string faculty, int amount, DateTime startTime, int intervalLength) |
|
28 |
{ |
|
29 |
this.faculty = faculty; |
|
30 |
this.amount = amount; |
|
31 |
this.startTime = startTime; |
|
32 |
this.intervalLength = intervalLength; |
|
33 |
} |
|
34 |
|
|
35 |
/// <summary> |
|
36 |
/// To string |
|
37 |
/// </summary> |
|
38 |
/// <returns>"start time faculty number of events"</returns> |
|
39 |
public override string ToString() |
|
40 |
{ |
|
41 |
return $"{startTime.ToString()} \t {faculty} \t {amount}"; |
|
42 |
} |
|
43 |
} |
|
44 |
} |
Server/ServerApp/Parser/OutputInfo/JisInfo.cs | ||
---|---|---|
1 |
using System; |
|
2 |
using System.Collections.Generic; |
|
3 |
using System.Linq; |
|
4 |
using System.Text; |
|
5 |
using System.Threading.Tasks; |
|
6 |
|
|
7 |
namespace Parser.OutputInfo |
|
8 |
{ |
|
9 |
class JisInfo |
|
10 |
{ |
|
11 |
string faculty; |
|
12 |
int amount; |
|
13 |
DateTime startTime; |
|
14 |
int intervalLength; |
|
15 |
|
|
16 |
public JisInfo(string faculty, int amount, DateTime startTime, int intervalLength) |
|
17 |
{ |
|
18 |
this.faculty = faculty; |
|
19 |
this.amount = amount; |
|
20 |
this.startTime = startTime; |
|
21 |
this.intervalLength = intervalLength; |
|
22 |
} |
|
23 |
|
|
24 |
public override string ToString() |
|
25 |
{ |
|
26 |
return $"{startTime.ToString()} \t {faculty} \t {amount}"; |
|
27 |
} |
|
28 |
} |
|
29 |
} |
Server/ServerApp/Parser/OutputInfo/LogInInfo.cs | ||
---|---|---|
1 |
using System; |
|
2 |
using System.Collections.Generic; |
|
3 |
using System.Linq; |
|
4 |
using System.Text; |
|
5 |
using System.Threading.Tasks; |
|
6 |
|
|
7 |
namespace Parser.OutputInfo |
|
8 |
{ |
|
9 |
class LogInInfo |
|
10 |
{ |
|
11 |
string faculty; |
|
12 |
int amount; |
|
13 |
DateTime startTime; |
|
14 |
int intervalLength; |
|
15 |
|
|
16 |
public LogInInfo(string faculty, int amount, DateTime startTime, int intervalLength) |
|
17 |
{ |
|
18 |
this.faculty = faculty; |
|
19 |
this.amount = amount; |
|
20 |
this.startTime = startTime; |
|
21 |
this.intervalLength = intervalLength; |
|
22 |
} |
|
23 |
|
|
24 |
public override string ToString() |
|
25 |
{ |
|
26 |
return $"{startTime.ToString()} \t {faculty} \t {amount}"; |
|
27 |
} |
|
28 |
} |
|
29 |
} |
Server/ServerApp/Parser/OutputInfo/LumInfo.cs | ||
---|---|---|
1 |
using System; |
|
2 |
using System.Collections.Generic; |
|
3 |
using System.Linq; |
|
4 |
using System.Text; |
|
5 |
using System.Threading.Tasks; |
|
6 |
|
|
7 |
namespace Parser.OutputInfo |
|
8 |
{ |
|
9 |
class LumInfo |
|
10 |
{ |
|
11 |
// in lux |
|
12 |
double value; |
|
13 |
DateTime startTime; |
|
14 |
int intervalLength; |
|
15 |
|
|
16 |
public LumInfo(double value, DateTime startTime, int intervalLength) |
|
17 |
{ |
|
18 |
this.value = value; |
|
19 |
this.startTime = startTime; |
|
20 |
this.intervalLength = intervalLength; |
|
21 |
} |
|
22 |
|
|
23 |
public override string ToString() |
|
24 |
{ |
|
25 |
return $"{startTime.ToString()} \t {value}"; |
|
26 |
} |
|
27 |
} |
|
28 |
} |
Server/ServerApp/Parser/OutputInfo/RainInfo.cs | ||
---|---|---|
1 |
using System; |
|
2 |
|
|
3 |
namespace Parser.OutputInfo |
|
4 |
{ |
|
5 |
class RainInfo |
|
6 |
{ |
|
7 |
// probability in % |
|
8 |
double value; |
|
9 |
DateTime startTime; |
|
10 |
int intervalLength; |
|
11 |
|
|
12 |
public RainInfo(double value, DateTime startTime, int intervalLength) |
|
13 |
{ |
|
14 |
this.value = value; |
|
15 |
this.startTime = startTime; |
|
16 |
this.intervalLength = intervalLength; |
|
17 |
} |
|
18 |
|
|
19 |
public override string ToString() |
|
20 |
{ |
|
21 |
return $"{startTime.ToString()} \t {value}"; |
|
22 |
} |
|
23 |
} |
|
24 |
} |
Server/ServerApp/Parser/OutputInfo/TempInfo.cs | ||
---|---|---|
1 |
using System; |
|
2 |
|
|
3 |
namespace Parser.OutputInfo |
|
4 |
{ |
|
5 |
class TempInfo |
|
6 |
{ |
|
7 |
// in °C |
|
8 |
double value; |
|
9 |
DateTime startTime; |
|
10 |
int intervalLength; |
|
11 |
|
|
12 |
public TempInfo(double value, DateTime startTime, int intervalLength) |
|
13 |
{ |
|
14 |
this.value = value; |
|
15 |
this.startTime = startTime; |
|
16 |
this.intervalLength = intervalLength; |
|
17 |
} |
|
18 |
|
|
19 |
public override string ToString() |
|
20 |
{ |
|
21 |
return $"{startTime.ToString()} \t {value}"; |
|
22 |
} |
|
23 |
} |
|
24 |
} |
Server/ServerApp/Parser/OutputInfo/WeatherConditions.cs | ||
---|---|---|
1 |
namespace ServerApp.Parser.OutputInfo |
|
2 |
{ |
|
3 |
/// <summary> |
|
4 |
/// Weather conditions in regards to sun level |
|
5 |
/// </summary> |
|
6 |
public enum WeatherConditions |
|
7 |
{ |
|
8 |
Sunny, Cloudy, Overcast, Dark |
|
9 |
} |
|
10 |
|
|
11 |
/// <summary> |
|
12 |
/// Transfers lux values to weather conditions and vice versa |
|
13 |
/// </summary> |
|
14 |
public static class LuxToConditions |
|
15 |
{ |
|
16 |
/// <summary> |
|
17 |
/// Lux to weather conditions |
|
18 |
/// </summary> |
|
19 |
/// <param name="lux">Lux value</param> |
|
20 |
/// <returns>Weather conditions</returns> |
|
21 |
public static WeatherConditions TransferLuxToConditions(double lux) |
|
22 |
{ |
|
23 |
if (lux > 40_000) |
|
24 |
return WeatherConditions.Sunny; |
|
25 |
|
|
26 |
if (lux > 20_000) |
|
27 |
return WeatherConditions.Cloudy; |
|
28 |
|
|
29 |
if (lux > 10_000) |
|
30 |
return WeatherConditions.Overcast; |
|
31 |
|
|
32 |
return WeatherConditions.Dark; |
|
33 |
} |
|
34 |
|
|
35 |
/// <summary> |
|
36 |
/// Weather conditions to average lux |
|
37 |
/// </summary> |
|
38 |
/// <param name="condition">Weather conditions</param> |
|
39 |
/// <returns>Lux value</returns> |
|
40 |
internal static double TransferConditionsToLux(WeatherConditions condition) |
|
41 |
{ |
|
42 |
if (condition == WeatherConditions.Sunny) |
|
43 |
return 50_000; |
|
44 |
|
|
45 |
if (condition == WeatherConditions.Cloudy) |
|
46 |
return 30_000; |
|
47 |
|
|
48 |
if (condition == WeatherConditions.Overcast) |
|
49 |
return 15_000; |
|
50 |
|
|
51 |
if (condition == WeatherConditions.Dark) |
|
52 |
return 5_000; |
|
53 |
|
|
54 |
return -1; |
|
55 |
} |
|
56 |
} |
|
57 |
} |
Server/ServerApp/Parser/OutputInfo/WeatherInfo.cs | ||
---|---|---|
1 | 1 |
using System; |
2 | 2 |
|
3 |
namespace Parser.OutputInfo |
|
3 |
namespace ServerApp.Parser.OutputInfo
|
|
4 | 4 |
{ |
5 |
/// <summary> |
|
6 |
/// Class representing the weather in a given interval at ZCU |
|
7 |
/// - shortest possible interval is 1h |
|
8 |
/// </summary> |
|
5 | 9 |
class WeatherInfo |
6 | 10 |
{ |
7 |
double temp; |
|
8 |
int rain; |
|
9 |
double wind; |
|
10 |
double lum; |
|
11 |
/// <summary> Temperature in °C </summary> |
|
12 |
public double temp; |
|
13 |
/// <summary> Probability of rain in % </summary> |
|
14 |
public int rain; |
|
15 |
/// <summary> Wind in m/s </summary> |
|
16 |
public double wind; |
|
17 |
/// <summary> Luminance </summary> |
|
18 |
public double lum; |
|
19 |
/// <summary> General weather conditions </summary> |
|
20 |
public WeatherConditions condition; |
|
11 | 21 |
|
22 |
/// <summary> Start of interval </summary> |
|
12 | 23 |
DateTime startTime; |
13 |
int range; |
|
24 |
/// <summary> Length of interval in hours </summary> |
|
25 |
int intervalLength; |
|
14 | 26 |
|
15 |
public WeatherInfo(DateTime startTime, double temp, int rain, double wind, double lum, int range) |
|
27 |
/// <summary> |
|
28 |
/// Constructor |
|
29 |
/// </summary> |
|
30 |
/// <param name="startTime">Start of the interval</param> |
|
31 |
/// <param name="temp">Temperature in °C</param> |
|
32 |
/// <param name="rain">Probability of rain in %</param> |
|
33 |
/// <param name="wind">Wind in m/w</param> |
|
34 |
/// <param name="lum">Luminance in lux</param> |
|
35 |
/// <param name="intervalLength">Interval length</param> |
|
36 |
public WeatherInfo(DateTime startTime, double temp, int rain, double wind, double lum, int intervalLength) |
|
16 | 37 |
{ |
17 | 38 |
this.startTime = startTime; |
18 | 39 |
this.temp = temp; |
19 | 40 |
this.rain = rain; |
20 | 41 |
this.wind = wind; |
21 | 42 |
this.lum = lum; |
22 |
this.range = range; |
|
43 |
this.intervalLength = intervalLength; |
|
44 |
|
|
45 |
condition = LuxToConditions.TransferLuxToConditions(lum); |
|
46 |
} |
|
47 |
|
|
48 |
/// <summary> |
|
49 |
/// Constructor |
|
50 |
/// </summary> |
|
51 |
/// <param name="startTime">Start of the interval</param> |
|
52 |
/// <param name="temp">Temperature in °C</param> |
|
53 |
/// <param name="rain">Probability of rain in %</param> |
|
54 |
/// <param name="wind">Wind in m/s</param> |
|
55 |
/// <param name="condition">Weather conditions</param> |
|
56 |
/// <param name="intervalLength">Interval length</param> |
|
57 |
public WeatherInfo(DateTime startTime, double temp, int rain, double wind, WeatherConditions condition, int intervalLength) |
|
58 |
{ |
|
59 |
this.startTime = startTime; |
|
60 |
this.temp = temp; |
|
61 |
this.rain = rain; |
|
62 |
this.wind = wind; |
|
63 |
this.condition = condition; |
|
64 |
this.intervalLength = intervalLength; |
|
65 |
|
|
66 |
lum = LuxToConditions.TransferConditionsToLux(condition); |
|
23 | 67 |
} |
24 | 68 |
|
69 |
/// <summary> |
|
70 |
/// To string |
|
71 |
/// </summary> |
|
72 |
/// <returns>interval start temperature probability of rain wind weather condition</returns> |
|
25 | 73 |
public override string ToString() |
26 | 74 |
{ |
27 |
return $"{startTime.ToString()} \t {temp}°C \t {rain}% \t {wind}m/s \t {lum}lux";
|
|
75 |
return $"{startTime.ToString()} \t {temp}°C \t {rain}% \t {wind}m/s \t {condition.ToString()}";
|
|
28 | 76 |
} |
29 | 77 |
|
30 | 78 |
} |
Server/ServerApp/Parser/OutputInfo/WindInfo.cs | ||
---|---|---|
1 |
using System; |
|
2 |
|
|
3 |
namespace Parser.OutputInfo |
|
4 |
{ |
|
5 |
class WindInfo |
|
6 |
{ |
|
7 |
// in m/s |
|
8 |
double value; |
|
9 |
DateTime startTime; |
|
10 |
int intervalLength; |
|
11 |
|
|
12 |
public WindInfo(double value, DateTime startTime, int intervalLength) |
|
13 |
{ |
|
14 |
this.value = value; |
|
15 |
this.startTime = startTime; |
|
16 |
this.intervalLength = intervalLength; |
|
17 |
} |
|
18 |
|
|
19 |
public override string ToString() |
|
20 |
{ |
|
21 |
return $"{startTime.ToString()} \t {value}"; |
|
22 |
} |
|
23 |
} |
|
24 |
} |
Server/ServerApp/Parser/Parsers/CsvParser.cs | ||
---|---|---|
1 |
using Parser.OutputInfo; |
|
2 |
using System; |
|
3 |
using System.Collections.Generic; |
|
4 |
using System.Globalization; |
|
5 |
using System.Threading; |
|
6 |
|
|
7 |
namespace Parser.Parsers |
|
8 |
{ |
|
9 |
class CsvParser |
|
10 |
{ |
|
11 |
|
|
12 |
string path; |
|
13 |
WeatherParser weatherParser; |
|
14 |
JisParser jisParser; |
|
15 |
LogInParser loginParser; |
|
16 |
|
|
17 |
public List<WeatherInfo> weatherList; |
|
18 |
public List<JisInfo> jisList; |
|
19 |
public List<LogInInfo> loginList; |
|
20 |
|
|
21 |
public CsvParser() |
|
22 |
{ |
|
23 |
TagInfo.CreateDictionaries(); |
|
24 |
path = "data/"; |
|
25 |
|
|
26 |
weatherParser = new WeatherParser(); |
|
27 |
jisParser = new JisParser(); |
|
28 |
loginParser = new LogInParser(); |
|
29 |
} |
|
30 |
|
|
31 |
public void Parse() |
|
32 |
{ |
|
33 |
var cultureInfo = CultureInfo.GetCultureInfo("en-GB"); |
|
34 |
Thread.CurrentThread.CurrentCulture = cultureInfo; |
|
35 |
Thread.CurrentThread.CurrentUICulture = cultureInfo; |
|
36 |
|
|
37 |
string pathWeather = path + "weather"; |
|
38 |
string pathJis = path + "jis"; |
|
39 |
string pathLogIn = path + "login"; |
|
40 |
|
|
41 |
weatherList = weatherParser.ParseWeatherData(pathWeather); |
|
42 |
jisList = jisParser.ParseJisData(pathJis); |
|
43 |
loginList = loginParser.ParseLogInData(pathLogIn); |
|
44 |
|
|
45 |
Console.WriteLine("WEATHER"); |
|
46 |
WriteToConsole(weatherList); |
|
47 |
Console.WriteLine("JIS"); |
|
48 |
WriteToConsole(jisList); |
|
49 |
Console.WriteLine("LOGIN"); |
|
50 |
WriteToConsole(loginList); |
|
51 |
} |
|
52 |
|
|
53 |
private void WriteToConsole<T>(List<T> list) |
|
54 |
{ |
|
55 |
if (list == null) |
|
56 |
{ |
|
57 |
Console.WriteLine("Unsuccessful parsing"); |
|
58 |
return; |
|
59 |
} |
|
60 |
Console.WriteLine(list.Count); |
|
61 |
|
|
62 |
for (int i = 0; i < list.Count; i++) |
|
63 |
Console.WriteLine(list[i].ToString()); |
|
64 |
} |
|
65 |
|
|
66 |
} |
|
67 |
} |
Server/ServerApp/Parser/Parsers/DataParser.cs | ||
---|---|---|
1 |
using ServerApp.Parser.OutputInfo; |
|
2 |
using System; |
|
3 |
using System.Collections.Generic; |
|
4 |
using System.Globalization; |
|
5 |
using System.Threading; |
|
6 |
|
|
7 |
namespace ServerApp.Parser.Parsers |
|
8 |
{ |
|
9 |
/// <summary> |
|
10 |
/// Class parsing data files into instances of ActivityInfo and WeatherInfo divided by given time interval |
|
11 |
/// Data parsed from 7am (included) to 18pm (included) |
|
12 |
/// </summary> |
|
13 |
class DataParser |
|
14 |
{ |
|
15 |
/// <summary> Path to data folder </summary> |
|
16 |
string path; |
|
17 |
/// <summary> Weather data parser </summary> |
|
18 |
WeatherParser weatherParser; |
|
19 |
/// <summary> Jis data parser </summary> |
|
20 |
JisParser jisParser; |
|
21 |
/// <summary> Login data parser </summary> |
|
22 |
LogInParser loginParser; |
|
23 |
|
|
24 |
/// <summary> WeatherInfo </summary> |
|
25 |
public List<WeatherInfo> weatherList; |
|
26 |
/// <summary> ActivityInfo representing jis activity </summary> |
|
27 |
public List<ActivityInfo> jisList; |
|
28 |
/// <summary> ActivityInfo representing login activity</summary> |
|
29 |
public List<ActivityInfo> loginList; |
|
30 |
|
|
31 |
/// <summary> |
|
32 |
/// Constructor |
|
33 |
/// </summary> |
|
34 |
public DataParser() |
|
35 |
{ |
|
36 |
TagInfo.CreateDictionaries(); |
|
37 |
|
|
38 |
// TODO ask for data folder? |
|
39 |
path = "data/"; |
|
40 |
|
|
41 |
weatherParser = new WeatherParser(); |
|
42 |
jisParser = new JisParser(); |
|
43 |
loginParser = new LogInParser(); |
|
44 |
} |
|
45 |
|
|
46 |
/// <summary> |
|
47 |
/// Parse data |
|
48 |
/// </summary> |
|
49 |
/// <param name="interval">Length of an interval</param> |
|
50 |
/// <param name="wholeDay">Parse data as one instance per day</param> |
|
51 |
public void Parse(int interval = 1, bool wholeDay = true) |
|
52 |
{ |
|
53 |
var cultureInfo = CultureInfo.GetCultureInfo("en-GB"); |
|
54 |
Thread.CurrentThread.CurrentCulture = cultureInfo; |
|
55 |
Thread.CurrentThread.CurrentUICulture = cultureInfo; |
|
56 |
|
|
57 |
string pathWeather = path + "weather"; |
|
58 |
string pathJis = path + "jis"; |
|
59 |
string pathLogIn = path + "login"; |
|
60 |
|
|
61 |
weatherList = weatherParser.ParseWeatherData(pathWeather, wholeDay, interval); |
|
62 |
jisList = jisParser.ParseJisData(pathJis, wholeDay, interval); |
|
63 |
loginList = loginParser.ParseLogInData(pathLogIn, wholeDay, interval); |
|
64 |
|
|
65 |
Console.WriteLine("WEATHER"); |
|
66 |
WriteToConsole(weatherList); |
|
67 |
Console.WriteLine("JIS"); |
|
68 |
WriteToConsole(jisList); |
|
69 |
Console.WriteLine("LOGIN"); |
|
70 |
WriteToConsole(loginList); |
|
71 |
} |
|
72 |
|
|
73 |
/// <summary> |
|
74 |
/// Debug method - writing lists to console |
|
75 |
/// </summary> |
|
76 |
private void WriteToConsole<T>(List<T> list) |
|
77 |
{ |
|
78 |
// TODO useless in finished app |
|
79 |
if (list == null) |
|
80 |
{ |
|
81 |
Console.WriteLine("Unsuccessful parsing"); |
|
82 |
return; |
|
83 |
} |
|
84 |
Console.WriteLine(list.Count); |
|
85 |
|
|
86 |
for (int i = 0; i < list.Count; i++) |
|
87 |
Console.WriteLine(list[i].ToString()); |
|
88 |
} |
|
89 |
|
|
90 |
} |
|
91 |
} |
Server/ServerApp/Parser/Parsers/JisParser.cs | ||
---|---|---|
1 |
using Parser.OutputInfo; |
|
2 |
using System; |
|
1 |
using System; |
|
3 | 2 |
using System.Collections.Generic; |
4 | 3 |
using System.IO; |
5 |
using Parser.InputData; |
|
4 |
using ServerApp.Parser.InputData; |
|
5 |
using ServerApp.Parser.OutputInfo; |
|
6 | 6 |
|
7 |
namespace Parser.Parsers |
|
7 |
namespace ServerApp.Parser.Parsers
|
|
8 | 8 |
{ |
9 |
/// <summary> |
|
10 |
/// Class parsing jis files into instances of ActivityInfo divided by given time interval |
|
11 |
/// Data parsed from 7am (included) to 18pm (included) |
|
12 |
/// </summary> |
|
9 | 13 |
class JisParser |
10 | 14 |
{ |
11 |
|
|
12 |
public List<JisInfo> ParseJisData(string folder, bool wholeDay = true, int interval = 1) |
|
15 |
|
|
16 |
/// <summary> |
|
17 |
/// Parses jis data to ActivityInfo instances |
|
18 |
/// Data parsed from 7am (included) to 18pm (included) |
|
19 |
/// </summary> |
|
20 |
/// <param name="folder">Folder with login data files</param> |
|
21 |
/// <param name="wholeDay">Should data be parsed as one instance per day (if true parameter interval will be ignored)</param> |
|
22 |
/// <param name="interval">Time interval to divide days by, minimum is 1h</param> |
|
23 |
/// <returns></returns> |
|
24 |
public List<ActivityInfo> ParseJisData(string folder, bool wholeDay = true, int interval = 1) |
|
13 | 25 |
{ |
14 |
List<JisInfo> list = new List<JisInfo>(); |
|
15 |
|
|
16 |
// najít složku, ve složce sou data co se budou parsovat |
|
17 |
|
|
18 | 26 |
if (!Directory.Exists(folder)) |
19 | 27 |
return null; |
20 | 28 |
|
21 |
// když v jednej složce budou všechny jis data co chci zpracovat |
|
22 |
// pro každej soubor budu spouštět parsování |
|
29 |
List<ActivityInfo> list = new List<ActivityInfo>(); |
|
30 |
|
|
31 |
// parse all files |
|
23 | 32 |
string[] fileEntries = Directory.GetFiles(folder); |
24 | 33 |
foreach (string fileName in fileEntries) |
25 | 34 |
{ |
26 |
List<JisInfo> loadedData = null; |
|
27 |
// pokud po jednom dni |
|
35 |
List<ActivityInfo> loadedData = null; |
|
36 |
|
|
37 |
// parse as one instance per day |
|
28 | 38 |
if (wholeDay) |
29 | 39 |
loadedData = ProcessOneJisFileAsDays(fileName); |
30 |
// pokud po hodinách
|
|
40 |
// parse by interval length
|
|
31 | 41 |
else |
32 | 42 |
{ |
33 | 43 |
// pokud: konec dne nebo konec aktuálního intervalu -> vemu to co sem nasčítal |
... | ... | |
40 | 50 |
return list; |
41 | 51 |
} |
42 | 52 |
|
43 |
private static List<JisInfo> ProcessOneJisFileAsDays(string path) |
|
53 |
/// <summary> |
|
54 |
/// Parses data from one data file as one instance per day |
|
55 |
/// </summary> |
|
56 |
/// <param name="path">Path ti file</param> |
|
57 |
/// <returns>List with ActivityInfo instances</returns> |
|
58 |
private static List<ActivityInfo> ProcessOneJisFileAsDays(string path) |
|
44 | 59 |
{ |
45 |
List<JisInfo> jisInfo = new List<JisInfo>(); |
|
60 |
if (!File.Exists(path)) |
|
61 |
return null; |
|
46 | 62 |
|
47 |
// načíst data ze souboru
|
|
63 |
List<ActivityInfo> jisInfo = new List<ActivityInfo>();
|
|
48 | 64 |
List<JisInstance> list = CsvDataLoader.LoadJisFile(path); |
49 | 65 |
|
66 |
// data for each faculty |
|
50 | 67 |
int[] recordedAmount = new int[TagInfo.faculties.Length]; |
68 |
// min/max hour taken into account |
|
51 | 69 |
int[] minmaxHour = new int[] { 7, 18 }; |
70 |
// interval length |
|
52 | 71 |
int range = minmaxHour[1] - minmaxHour[0]; |
53 | 72 |
|
54 |
// procházet data ze souboru
|
|
55 |
DateTime lastStartTime = new DateTime(list[0].dateTime.Year, list[0].dateTime.Month, list[0].dateTime.Day); |
|
73 |
// first day
|
|
74 |
DateTime lastStartTime = new DateTime(list[0].dateTime.Year, list[0].dateTime.Month, list[0].dateTime.Day, minmaxHour[0], 0, 0);
|
|
56 | 75 |
for (int i = 0; i < list.Count; i++) |
57 | 76 |
{ |
58 | 77 |
int currHour = list[i].dateTime.Hour; |
59 | 78 |
if (currHour < minmaxHour[0] || currHour > minmaxHour[1]) |
60 | 79 |
continue; |
61 | 80 |
|
62 |
// v každym dni agreguju
|
|
81 |
// start of the day -> make an instance
|
|
63 | 82 |
string place = list[i].placeTag; |
64 |
DateTime date = new DateTime(list[i].dateTime.Year, list[i].dateTime.Month, list[i].dateTime.Day); |
|
83 |
DateTime date = new DateTime(list[i].dateTime.Year, list[i].dateTime.Month, list[i].dateTime.Day, minmaxHour[0], 0, 0);
|
|
65 | 84 |
if (!date.Equals(lastStartTime)) |
66 | 85 |
{ |
86 |
// data for each faculty separate |
|
67 | 87 |
for (int k = 0; k < TagInfo.faculties.Length; k++) |
68 | 88 |
{ |
69 |
JisInfo dayInfo = new JisInfo(TagInfo.faculties[k], recordedAmount[k], lastStartTime, range);
|
|
89 |
ActivityInfo dayInfo = new ActivityInfo(TagInfo.faculties[k], recordedAmount[k], lastStartTime, range);
|
|
70 | 90 |
jisInfo.Add(dayInfo); |
71 | 91 |
} |
72 | 92 |
|
... | ... | |
74 | 94 |
lastStartTime = date; |
75 | 95 |
} |
76 | 96 |
|
77 |
// tady nasčítávát podle místa
|
|
97 |
// aggregate data
|
|
78 | 98 |
if (TagInfo.jisPlaces.ContainsKey(place)) |
79 | 99 |
{ |
80 | 100 |
int index = TagInfo.jisPlaces[place]; |
... | ... | |
87 | 107 |
} |
88 | 108 |
else |
89 | 109 |
{ |
110 |
// TODO uknown code handling |
|
90 | 111 |
Console.WriteLine("Unknown code " + list[i].placeTag); |
91 | 112 |
} |
92 | 113 |
|
93 | 114 |
} |
94 | 115 |
|
116 |
// last day |
|
95 | 117 |
for (int k = 0; k < TagInfo.faculties.Length; k++) |
96 | 118 |
{ |
97 |
JisInfo dayInfo = new JisInfo(TagInfo.faculties[k], recordedAmount[k], lastStartTime, range);
|
|
119 |
ActivityInfo dayInfo = new ActivityInfo(TagInfo.faculties[k], recordedAmount[k], lastStartTime, range);
|
|
98 | 120 |
jisInfo.Add(dayInfo); |
99 | 121 |
} |
100 | 122 |
|
101 | 123 |
return jisInfo; |
102 | 124 |
} |
103 | 125 |
|
104 |
private static List<JisInfo> ProcessOneJisFileAsIntervals(string path, int interval)
|
|
126 |
private static List<ActivityInfo> ProcessOneJisFileAsIntervals(string path, int interval)
|
|
105 | 127 |
{ |
106 | 128 |
throw new NotImplementedException(); |
107 | 129 |
} |
Server/ServerApp/Parser/Parsers/LogInParser.cs | ||
---|---|---|
1 |
using Parser.InputData; |
|
2 |
using Parser.OutputInfo; |
|
1 |
using ServerApp.Parser.InputData;
|
|
2 |
using ServerApp.Parser.OutputInfo;
|
|
3 | 3 |
using System; |
4 | 4 |
using System.Collections.Generic; |
5 | 5 |
using System.IO; |
6 | 6 |
|
7 |
namespace Parser.Parsers |
|
7 |
namespace ServerApp.Parser.Parsers
|
|
8 | 8 |
{ |
9 |
/// <summary> |
|
10 |
/// Class parsing login files into instances of ActivityInfo divided by given time interval |
|
11 |
/// Data parsed from 7am (included) to 18pm (included) |
|
12 |
/// </summary> |
|
9 | 13 |
class LogInParser |
10 | 14 |
{ |
11 |
public List<LogInInfo> ParseLogInData(string folder, bool wholeDay = true, int interval = 1) |
|
15 |
/// <summary> |
|
16 |
/// Parses login data to ActivityInfo instances |
|
17 |
/// Data parsed from 7am (included) to 18pm (included) |
|
18 |
/// </summary> |
|
19 |
/// <param name="folder">Folder with login data files</param> |
|
20 |
/// <param name="wholeDay">Should data be parsed as one instance per day (if true parameter interval will be ignored)</param> |
|
21 |
/// <param name="interval">Time interval to divide days by, minimum is 1h</param> |
|
22 |
/// <returns></returns> |
|
23 |
public List<ActivityInfo> ParseLogInData(string folder, bool wholeDay = true, int interval = 1) |
|
12 | 24 |
{ |
13 |
List<LogInInfo> list = new List<LogInInfo>(); |
|
14 |
|
|
15 |
// najít složku, ve složce sou data co se budou parsovat |
|
16 |
|
|
17 | 25 |
if (!Directory.Exists(folder)) |
18 | 26 |
return null; |
27 |
|
|
28 |
List<ActivityInfo> list = new List<ActivityInfo>(); |
|
19 | 29 |
|
20 |
// když v jednej složce budou všechny jis data co chci zpracovat |
|
21 |
// pro každej soubor budu spouštět parsování |
|
30 |
// get all files in folder |
|
22 | 31 |
string[] fileEntries = Directory.GetFiles(folder); |
23 | 32 |
foreach (string fileName in fileEntries) |
24 | 33 |
{ |
25 |
List<LogInInfo> loadedData = null; |
|
26 |
// pokud po jednom dni |
|
34 |
List<ActivityInfo> loadedData = null; |
|
35 |
|
|
36 |
// parse as one instance per day |
|
27 | 37 |
if (wholeDay) |
28 | 38 |
loadedData = ProcessOneLogInFileAsDays(fileName); |
29 |
// pokud po hodinách
|
|
39 |
// parse by interval length
|
|
30 | 40 |
else |
31 | 41 |
{ |
32 | 42 |
// pokud: konec dne nebo konec aktuálního intervalu -> vemu to co sem nasčítal |
... | ... | |
39 | 49 |
return list; |
40 | 50 |
} |
41 | 51 |
|
42 |
private static List<LogInInfo> ProcessOneLogInFileAsDays(string path) |
|
52 |
/// <summary> |
|
53 |
/// Parses data from one data file as one instance per day |
|
54 |
/// </summary> |
|
55 |
/// <param name="path">Path ti file</param> |
|
56 |
/// <returns>List with ActivityInfo instances</returns> |
|
57 |
private static List<ActivityInfo> ProcessOneLogInFileAsDays(string path) |
|
43 | 58 |
{ |
44 |
List<LogInInfo> loginInfo = new List<LogInInfo>(); |
|
59 |
if (!File.Exists(path)) |
|
60 |
return null; |
|
45 | 61 |
|
46 |
// načíst data ze souboru
|
|
62 |
List<ActivityInfo> loginInfo = new List<ActivityInfo>();
|
|
47 | 63 |
List<LogInInstance> list = CsvDataLoader.LoadLoginFile(path); |
48 | 64 |
|
65 |
// data for each faculty |
|
49 | 66 |
int[] recordedAmount = new int[TagInfo.faculties.Length]; |
67 |
// min/max hour taken into account |
|
50 | 68 |
int[] minmaxHour = new int[] { 7, 18 }; |
69 |
// interval length |
|
51 | 70 |
int range = minmaxHour[1] - minmaxHour[0]; |
52 | 71 |
|
53 |
// procházet data ze souboru
|
|
54 |
DateTime lastStartDay = new DateTime(list[0].date.Year, list[0].date.Month, list[0].date.Day); |
|
72 |
// first day
|
|
73 |
DateTime lastStartDay = new DateTime(list[0].date.Year, list[0].date.Month, list[0].date.Day, minmaxHour[0], 0, 0);
|
|
55 | 74 |
for (int i = 0; i < list.Count; i++) |
56 | 75 |
{ |
57 | 76 |
int currHour = list[i].lessonStart.Hour; |
58 | 77 |
if (currHour < minmaxHour[0] || currHour > minmaxHour[1]) |
59 | 78 |
continue; |
60 | 79 |
|
61 |
// v každym dni agreguju
|
|
80 |
// start of the day -> make an instance
|
|
62 | 81 |
string place = list[i].building; |
63 |
DateTime date = new DateTime(list[i].date.Year, list[i].date.Month, list[i].date.Day); |
|
82 |
DateTime date = new DateTime(list[i].date.Year, list[i].date.Month, list[i].date.Day, minmaxHour[0], 0, 0);
|
|
64 | 83 |
if (!date.Equals(lastStartDay)) |
65 | 84 |
{ |
85 |
// data for each faculty separate |
|
66 | 86 |
for (int k = 0; k < TagInfo.faculties.Length; k++) |
67 | 87 |
{ |
68 |
LogInInfo dayInfo = new LogInInfo(TagInfo.faculties[k], recordedAmount[k], lastStartDay, range);
|
|
88 |
ActivityInfo dayInfo = new ActivityInfo(TagInfo.faculties[k], recordedAmount[k], lastStartDay, range);
|
|
69 | 89 |
loginInfo.Add(dayInfo); |
70 | 90 |
} |
71 | 91 |
|
... | ... | |
73 | 93 |
lastStartDay = date; |
74 | 94 |
} |
75 | 95 |
|
76 |
// tady nasčítávát podle místa
|
|
96 |
// aggregate data
|
|
77 | 97 |
if (TagInfo.buildingTags.ContainsKey(place)) |
78 | 98 |
{ |
79 | 99 |
int index = TagInfo.buildingTags[place]; |
100 |
// to all |
|
80 | 101 |
if (index == -1) |
81 | 102 |
for (int l = 0; l < TagInfo.faculties.Length; l++) |
82 | 103 |
recordedAmount[l] += list[i].amount; |
104 |
// to first two |
|
83 | 105 |
else if (index == -2) |
84 | 106 |
{ |
85 | 107 |
recordedAmount[0] += list[i].amount; |
... | ... | |
91 | 113 |
} |
92 | 114 |
else |
93 | 115 |
{ |
116 |
// TODO uknown code handling |
|
94 | 117 |
Console.WriteLine("Unknown code " + list[i].building); |
95 | 118 |
} |
96 | 119 |
|
97 | 120 |
} |
98 | 121 |
|
122 |
// last day |
|
99 | 123 |
for (int k = 0; k < TagInfo.faculties.Length; k++) |
100 | 124 |
{ |
101 |
LogInInfo dayInfo = new LogInInfo(TagInfo.faculties[k], recordedAmount[k], lastStartDay, range);
|
|
125 |
ActivityInfo dayInfo = new ActivityInfo(TagInfo.faculties[k], recordedAmount[k], lastStartDay, range);
|
|
102 | 126 |
loginInfo.Add(dayInfo); |
103 | 127 |
} |
104 | 128 |
|
105 | 129 |
return loginInfo; |
106 | 130 |
} |
107 | 131 |
|
108 |
private static List<JisInfo> ProcessOneLoginFileAsIntervals(string path, int interval)
|
|
132 |
private static List<ActivityInfo> ProcessOneLoginFileAsIntervals(string path, int interval)
|
|
109 | 133 |
{ |
110 | 134 |
throw new NotImplementedException(); |
111 | 135 |
} |
Server/ServerApp/Parser/Parsers/TagInfo.cs | ||
---|---|---|
1 | 1 |
using System.Collections.Generic; |
2 | 2 |
|
3 |
namespace Parser.Parsers |
|
3 |
namespace ServerApp.Parser.Parsers
|
|
4 | 4 |
{ |
5 | 5 |
class TagInfo |
6 | 6 |
{ |
Server/ServerApp/Parser/Parsers/WeatherParser.cs | ||
---|---|---|
1 |
using Parser.InputData; |
|
2 |
using Parser.OutputInfo; |
|
1 |
using ServerApp.Parser.InputData;
|
|
2 |
using ServerApp.Parser.OutputInfo;
|
|
3 | 3 |
using System; |
4 | 4 |
using System.Collections.Generic; |
5 | 5 |
using System.IO; |
6 | 6 |
|
7 |
namespace Parser.Parsers |
|
7 |
namespace ServerApp.Parser.Parsers
|
|
8 | 8 |
{ |
9 |
/// <summary> |
|
10 |
/// Class parsing weather files into instances of WeatherInfo divided by given time interval |
|
11 |
/// Data parsed from 7am (included) to 18pm (included) |
|
12 |
/// </summary> |
|
9 | 13 |
class WeatherParser |
10 | 14 |
{ |
11 |
|
|
15 |
/// <summary> |
|
16 |
/// Parses weather data to WeatherInfo instances |
|
17 |
/// Data parsed from 7am (included) to 18pm (included) |
|
18 |
/// </summary> |
|
19 |
/// <param name="folder">Folder with weather data files</param> |
|
20 |
/// <param name="wholeDay">Should data be parsed as one instance per day (if true parameter interval will be ignored)</param> |
|
21 |
/// <param name="interval">Time interval to divide days by, minimum is 1h</param> |
|
22 |
/// <returns></returns> |
|
12 | 23 |
public List<WeatherInfo> ParseWeatherData(string folder, bool wholeDay = true, int interval = 1) |
13 | 24 |
{ |
14 |
List<WeatherInfo> list = new List<WeatherInfo>(); |
|
15 |
|
|
16 |
// najít složku, ve složce sou data co se budou parsovat |
|
17 |
|
|
18 | 25 |
if (!Directory.Exists(folder)) |
19 | 26 |
return null; |
20 | 27 |
|
21 |
// když v jednej složce budou všechny jis data co chci zpracovat |
|
22 |
// pro každej soubor budu spouštět parsování |
|
28 |
List<WeatherInfo> list = new List<WeatherInfo>(); |
|
29 |
|
|
30 |
// get all files in folder |
|
23 | 31 |
string[] fileEntries = Directory.GetFiles(folder); |
24 | 32 |
foreach (string fileName in fileEntries) |
25 | 33 |
{ |
26 | 34 |
List<WeatherInfo> loadedData = null; |
27 |
// pokud po jednom dni |
|
35 |
|
|
36 |
// parse as one instance per day |
|
28 | 37 |
if (wholeDay) |
29 | 38 |
loadedData = ProcessOneWeatherFileAsDays(fileName); |
30 |
// pokud po hodinách
|
|
39 |
// parse according to interval
|
|
31 | 40 |
else |
32 | 41 |
{ |
33 | 42 |
// pokud: konec dne nebo konec aktuálního intervalu -> vemu to co sem nasčítal |
... | ... | |
40 | 49 |
return list; |
41 | 50 |
} |
42 | 51 |
|
52 |
/// <summary> |
|
53 |
/// Parses data from one data file as one instance per day |
|
54 |
/// </summary> |
|
55 |
/// <param name="path">Path ti file</param> |
|
56 |
/// <returns>List with WeatherInfo instances</returns> |
|
43 | 57 |
private static List<WeatherInfo> ProcessOneWeatherFileAsDays(string path) |
44 | 58 |
{ |
45 |
List<WeatherInfo> weatherInfo = new List<WeatherInfo>(); |
|
59 |
if (!File.Exists(path)) |
|
60 |
return null; |
|
46 | 61 |
|
47 |
// načíst data ze souboru
|
|
62 |
List<WeatherInfo> weatherInfo = new List<WeatherInfo>();
|
|
48 | 63 |
List<WeatherInstance> list = CsvDataLoader.LoadWeatherFile(path); |
49 | 64 |
|
50 |
//temp, rain, wind, lum
|
|
65 |
// array with data [temp, rain, wind, lum]
|
|
51 | 66 |
double[] recordedAmount = new double[4]; |
67 |
// min/max hour taken into account |
|
52 | 68 |
int[] minmaxHour = new int[] { 7, 18 }; |
69 |
// interval length |
|
53 | 70 |
int range = minmaxHour[1] - minmaxHour[0]; |
54 | 71 |
|
55 |
// procházet data ze souboru |
|
56 |
DateTime lastStartDay = new DateTime(list[0].dateTime.Year, list[0].dateTime.Month, list[0].dateTime.Day); |
|
72 |
// first day |
|
73 |
DateTime lastStartDay = new DateTime(list[0].dateTime.Year, list[0].dateTime.Month, list[0].dateTime.Day, minmaxHour[0], 0, 0); |
|
74 |
// number of values in day |
|
57 | 75 |
int values = 0; |
58 | 76 |
for (int i = 0; i < list.Count; i++) |
59 | 77 |
{ |
... | ... | |
61 | 79 |
if (currHour < minmaxHour[0] || currHour > minmaxHour[1]) |
62 | 80 |
continue; |
63 | 81 |
|
64 |
// v každym dni agreguju
|
|
65 |
DateTime date = new DateTime(list[i].dateTime.Year, list[i].dateTime.Month, list[i].dateTime.Day); |
|
82 |
// start of new day -> make a new instance
|
|
83 |
DateTime date = new DateTime(list[i].dateTime.Year, list[i].dateTime.Month, list[i].dateTime.Day, minmaxHour[0], 0, 0);
|
|
66 | 84 |
if (!date.Equals(lastStartDay)) |
67 | 85 |
{ |
68 | 86 |
WeatherInfo dayInfo = new WeatherInfo(lastStartDay, recordedAmount[0] / values, (int)(recordedAmount[1] / values * 100), recordedAmount[2] / values, recordedAmount[3] / values, range); |
... | ... | |
73 | 91 |
values = 0; |
74 | 92 |
} |
75 | 93 |
|
76 |
// tady nasčítávát data
|
|
94 |
// aggregate data
|
|
77 | 95 |
recordedAmount[0] += list[i].temp; |
78 | 96 |
recordedAmount[1] += list[i].rain; |
79 | 97 |
recordedAmount[2] += list[i].wind; |
80 | 98 |
recordedAmount[3] += list[i].lum * 1000; |
99 |
|
|
81 | 100 |
values++; |
82 | 101 |
} |
83 | 102 |
|
103 |
// data from last day |
|
84 | 104 |
WeatherInfo dayInfo2 = new WeatherInfo(lastStartDay, recordedAmount[0] / values, (int)(recordedAmount[1] / values * 100), recordedAmount[2] / values, recordedAmount[3] / values, range); |
85 | 105 |
weatherInfo.Add(dayInfo2); |
86 | 106 |
|
87 | 107 |
return weatherInfo; |
88 | 108 |
} |
89 | 109 |
|
90 |
private static List<JisInfo> ProcessOneWeatherFileAsIntervals(string path, int interval)
|
|
110 |
private static List<ActivityInfo> ProcessOneWeatherFileAsIntervals(string path, int interval)
|
|
91 | 111 |
{ |
92 | 112 |
throw new NotImplementedException(); |
93 | 113 |
} |
Server/ServerApp/Program.cs | ||
---|---|---|
1 |
using Parser.Parsers; |
|
1 |
using ServerApp.Parser.Parsers;
|
|
2 | 2 |
using System; |
3 |
using System.Collections.Generic; |
|
4 |
using System.Linq; |
|
5 |
using System.Text; |
|
6 |
using System.Threading.Tasks; |
|
7 | 3 |
|
8 | 4 |
namespace ServerApp |
9 | 5 |
{ |
... | ... | |
11 | 7 |
{ |
12 | 8 |
static void Main(string[] args) |
13 | 9 |
{ |
14 |
CsvParser p = new CsvParser();
|
|
10 |
DataParser p = new DataParser();
|
|
15 | 11 |
|
16 | 12 |
p.Parse(); |
17 | 13 |
|
Server/ServerApp/ServerApp.csproj | ||
---|---|---|
48 | 48 |
<Compile Include="Parser\InputData\JisInstance.cs" /> |
49 | 49 |
<Compile Include="Parser\InputData\LogInInstance.cs" /> |
50 | 50 |
<Compile Include="Parser\InputData\WeatherInstance.cs" /> |
51 |
<Compile Include="Parser\OutputInfo\JisInfo.cs" /> |
|
52 |
<Compile Include="Parser\OutputInfo\LogInInfo.cs" /> |
|
53 |
<Compile Include="Parser\OutputInfo\LumInfo.cs" /> |
|
54 |
<Compile Include="Parser\OutputInfo\RainInfo.cs" /> |
|
55 |
<Compile Include="Parser\OutputInfo\TempInfo.cs" /> |
|
51 |
<Compile Include="Parser\OutputInfo\ActivityInfo.cs" /> |
|
52 |
<Compile Include="Parser\OutputInfo\WeatherConditions.cs" /> |
|
56 | 53 |
<Compile Include="Parser\OutputInfo\WeatherInfo.cs" /> |
57 |
<Compile Include="Parser\OutputInfo\WindInfo.cs" /> |
|
58 |
<Compile Include="Parser\Parsers\CsvParser.cs" /> |
|
54 |
<Compile Include="Parser\Parsers\DataParser.cs" /> |
|
59 | 55 |
<Compile Include="Parser\Parsers\JisParser.cs" /> |
60 | 56 |
<Compile Include="Parser\Parsers\LogInParser.cs" /> |
61 | 57 |
<Compile Include="Parser\Parsers\TagInfo.cs" /> |
Server/ServerApp/obj/Debug/ServerApp.csproj.CoreCompileInputs.cache | ||
---|---|---|
1 |
446e0a8c9360f09ce5d918714762c9add41796cd |
|
1 |
e944a18ef305c65a78390072fd21554ec2955315 |
Také k dispozici: Unified diff
re #8597 Code maintenance - comments, namespace changes