1
|
using ServerApp.Parser.InputData;
|
2
|
using ServerApp.Parser.OutputInfo;
|
3
|
using System;
|
4
|
using System.Collections.Generic;
|
5
|
using System.Globalization;
|
6
|
using System.Threading;
|
7
|
|
8
|
namespace ServerApp.Parser.Parsers
|
9
|
{
|
10
|
/// <summary>
|
11
|
/// Class parsing data files into instances of ActivityInfo and WeatherInfo divided by given time interval
|
12
|
/// Data parsed from 7am (included) to 18pm (included)
|
13
|
/// </summary>
|
14
|
/// <author>Alex Konig</author>
|
15
|
class DataParser
|
16
|
{
|
17
|
/// <summary> Path to data folder </summary>
|
18
|
string path;
|
19
|
/// <summary> Weather data parser </summary>
|
20
|
WeatherParser weatherParser;
|
21
|
/// <summary> Jis data parser </summary>
|
22
|
JisParser jisParser;
|
23
|
/// <summary> Login data parser </summary>
|
24
|
LogInParser loginParser;
|
25
|
|
26
|
/// <summary> WeatherInfo </summary>
|
27
|
public List<WeatherInfo> weatherList;
|
28
|
/// <summary> ActivityInfo representing jis activity </summary>
|
29
|
public List<ActivityInfo> jisList;
|
30
|
/// <summary> ActivityInfo representing login activity</summary>
|
31
|
public List<ActivityInfo> loginList;
|
32
|
|
33
|
/// <summary>
|
34
|
/// Constructor
|
35
|
/// </summary>
|
36
|
public DataParser(string path)
|
37
|
{
|
38
|
TagInfo.CreateDictionaries();
|
39
|
|
40
|
// TODO ask for data folder?
|
41
|
this.path = path;
|
42
|
DataLoader loader = new CsvDataLoader();
|
43
|
|
44
|
weatherParser = new WeatherParser(loader);
|
45
|
jisParser = new JisParser(loader);
|
46
|
loginParser = new LogInParser(loader);
|
47
|
}
|
48
|
|
49
|
/// <summary>
|
50
|
/// Parse data
|
51
|
/// </summary>
|
52
|
/// <param name="interval">Length of an interval</param>
|
53
|
/// <param name="wholeDay">Parse data as one instance per day</param>
|
54
|
public void Parse(int interval = 1, bool wholeDay = true)
|
55
|
{
|
56
|
var cultureInfo = CultureInfo.GetCultureInfo("en-GB");
|
57
|
Thread.CurrentThread.CurrentCulture = cultureInfo;
|
58
|
Thread.CurrentThread.CurrentUICulture = cultureInfo;
|
59
|
|
60
|
string pathWeather = path + "weather";
|
61
|
string pathJis = path + "jis";
|
62
|
string pathLogIn = path + "login";
|
63
|
|
64
|
weatherList = weatherParser.ParseWeatherData(pathWeather, false, 2); // wholeDay, interval);
|
65
|
jisList = jisParser.ParseJisData(pathJis, false, 2); // wholeDay, interval);
|
66
|
loginList = loginParser.ParseLogInData(pathLogIn, false, 2); // wholeDay, interval);
|
67
|
|
68
|
//Console.WriteLine("WEATHER");
|
69
|
//WriteToConsole(weatherList);
|
70
|
Console.WriteLine("JIS");
|
71
|
WriteToConsole(jisList);
|
72
|
//Console.WriteLine("LOGIN");
|
73
|
//WriteToConsole(loginList);
|
74
|
}
|
75
|
|
76
|
/// <summary>
|
77
|
/// Debug method - writing lists to console
|
78
|
/// </summary>
|
79
|
private void WriteToConsole<T>(List<T> list)
|
80
|
{
|
81
|
// TODO useless in finished app
|
82
|
if (list == null)
|
83
|
{
|
84
|
Console.WriteLine("Unsuccessful parsing");
|
85
|
return;
|
86
|
}
|
87
|
Console.WriteLine(list.Count);
|
88
|
|
89
|
for (int i = 0; i < list.Count; i++)
|
90
|
Console.WriteLine(list[i].ToString());
|
91
|
}
|
92
|
|
93
|
}
|
94
|
}
|