Projekt

Obecné

Profil

Stáhnout (3.01 KB) Statistiky
| Větev: | Tag: | Revize:
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, false, 2); // 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
}
(1-1/5)