1 |
734533a8
|
A-Konig
|
using ServerApp.Parser.OutputInfo;
|
2 |
93452c41
|
A-Konig
|
using System;
|
3 |
|
|
using System.Collections.Generic;
|
4 |
|
|
using System.Globalization;
|
5 |
|
|
using System.Threading;
|
6 |
|
|
|
7 |
734533a8
|
A-Konig
|
namespace ServerApp.Parser.Parsers
|
8 |
93452c41
|
A-Konig
|
{
|
9 |
734533a8
|
A-Konig
|
/// <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 |
93452c41
|
A-Konig
|
{
|
15 |
734533a8
|
A-Konig
|
/// <summary> Path to data folder </summary>
|
16 |
93452c41
|
A-Konig
|
string path;
|
17 |
734533a8
|
A-Konig
|
/// <summary> Weather data parser </summary>
|
18 |
93452c41
|
A-Konig
|
WeatherParser weatherParser;
|
19 |
734533a8
|
A-Konig
|
/// <summary> Jis data parser </summary>
|
20 |
93452c41
|
A-Konig
|
JisParser jisParser;
|
21 |
734533a8
|
A-Konig
|
/// <summary> Login data parser </summary>
|
22 |
93452c41
|
A-Konig
|
LogInParser loginParser;
|
23 |
|
|
|
24 |
734533a8
|
A-Konig
|
/// <summary> WeatherInfo </summary>
|
25 |
78428231
|
A-Konig
|
public List<WeatherInfo> weatherList;
|
26 |
734533a8
|
A-Konig
|
/// <summary> ActivityInfo representing jis activity </summary>
|
27 |
|
|
public List<ActivityInfo> jisList;
|
28 |
|
|
/// <summary> ActivityInfo representing login activity</summary>
|
29 |
|
|
public List<ActivityInfo> loginList;
|
30 |
78428231
|
A-Konig
|
|
31 |
734533a8
|
A-Konig
|
/// <summary>
|
32 |
|
|
/// Constructor
|
33 |
|
|
/// </summary>
|
34 |
|
|
public DataParser()
|
35 |
93452c41
|
A-Konig
|
{
|
36 |
|
|
TagInfo.CreateDictionaries();
|
37 |
734533a8
|
A-Konig
|
|
38 |
|
|
// TODO ask for data folder?
|
39 |
93452c41
|
A-Konig
|
path = "data/";
|
40 |
|
|
|
41 |
|
|
weatherParser = new WeatherParser();
|
42 |
|
|
jisParser = new JisParser();
|
43 |
|
|
loginParser = new LogInParser();
|
44 |
|
|
}
|
45 |
|
|
|
46 |
734533a8
|
A-Konig
|
/// <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 |
93452c41
|
A-Konig
|
{
|
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 |
734533a8
|
A-Konig
|
weatherList = weatherParser.ParseWeatherData(pathWeather, wholeDay, interval);
|
62 |
260b1217
|
A-Konig
|
jisList = jisParser.ParseJisData(pathJis, false, 2); // wholeDay, interval);
|
63 |
734533a8
|
A-Konig
|
loginList = loginParser.ParseLogInData(pathLogIn, wholeDay, interval);
|
64 |
93452c41
|
A-Konig
|
|
65 |
260b1217
|
A-Konig
|
//Console.WriteLine("WEATHER");
|
66 |
|
|
//WriteToConsole(weatherList);
|
67 |
93452c41
|
A-Konig
|
Console.WriteLine("JIS");
|
68 |
|
|
WriteToConsole(jisList);
|
69 |
260b1217
|
A-Konig
|
//Console.WriteLine("LOGIN");
|
70 |
|
|
//WriteToConsole(loginList);
|
71 |
93452c41
|
A-Konig
|
}
|
72 |
|
|
|
73 |
734533a8
|
A-Konig
|
/// <summary>
|
74 |
|
|
/// Debug method - writing lists to console
|
75 |
|
|
/// </summary>
|
76 |
93452c41
|
A-Konig
|
private void WriteToConsole<T>(List<T> list)
|
77 |
|
|
{
|
78 |
734533a8
|
A-Konig
|
// TODO useless in finished app
|
79 |
93452c41
|
A-Konig
|
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 |
|
|
}
|