Projekt

Obecné

Profil

Stáhnout (4 KB) Statistiky
| Větev: | Tag: | Revize:
1
using Parser.InputData;
2
using Parser.OutputInfo;
3
using System;
4
using System.Collections.Generic;
5
using System.IO;
6

    
7
namespace Parser.Parsers
8
{
9
    class LogInParser
10
    {
11
        public List<LogInInfo> ParseLogInData(string folder, bool wholeDay = true, int interval = 1)
12
        {
13
            List<LogInInfo> list = new List<LogInInfo>();
14

    
15
            // najít složku, ve složce sou data co se budou parsovat
16

    
17
            if (!Directory.Exists(folder))
18
                return null;
19

    
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í
22
            string[] fileEntries = Directory.GetFiles(folder);
23
            foreach (string fileName in fileEntries)
24
            {
25
                List<LogInInfo> loadedData = null;
26
                // pokud po jednom dni
27
                if (wholeDay)
28
                    loadedData = ProcessOneLogInFileAsDays(fileName);
29
                // pokud po hodinách
30
                else
31
                {
32
                    // pokud: konec dne nebo konec aktuálního intervalu -> vemu to co sem nasčítal
33
                    throw new NotImplementedException();
34
                }
35

    
36
                list.AddRange(loadedData);
37
            }
38

    
39
            return list;
40
        }
41

    
42
        private static List<LogInInfo> ProcessOneLogInFileAsDays(string path)
43
        {
44
            List<LogInInfo> loginInfo = new List<LogInInfo>();
45

    
46
            // načíst data ze souboru
47
            List<LogInInstance> list = CsvDataLoader.LoadLoginFile(path);
48

    
49
            int[] recordedAmount = new int[TagInfo.faculties.Length];
50
            int[] minmaxHour = new int[] { 7, 18 };
51
            int range = minmaxHour[1] - minmaxHour[0];
52

    
53
            // procházet data ze souboru
54
            DateTime lastStartDay = new DateTime(list[0].date.Year, list[0].date.Month, list[0].date.Day);
55
            for (int i = 0; i < list.Count; i++)
56
            {
57
                int currHour = list[i].lessonStart.Hour;
58
                if (currHour < minmaxHour[0] || currHour > minmaxHour[1])
59
                    continue;
60

    
61
                // v každym dni agreguju
62
                string place = list[i].building;
63
                DateTime date = new DateTime(list[i].date.Year, list[i].date.Month, list[i].date.Day);
64
                if (!date.Equals(lastStartDay))
65
                {
66
                    for (int k = 0; k < TagInfo.faculties.Length; k++)
67
                    {
68
                        LogInInfo dayInfo = new LogInInfo(TagInfo.faculties[k], recordedAmount[k], lastStartDay, range); 
69
                        loginInfo.Add(dayInfo);
70
                    }
71

    
72
                    recordedAmount = new int[TagInfo.faculties.Length];
73
                    lastStartDay = date;
74
                }
75

    
76
                // tady nasčítávát podle místa
77
                if (TagInfo.buildingTags.ContainsKey(place))
78
                {
79
                    int index = TagInfo.buildingTags[place];
80
                    if (index == -1)
81
                        for (int l = 0; l < TagInfo.faculties.Length; l++)
82
                            recordedAmount[l] += list[i].amount;
83
                    else if (index == -2)
84
                    {
85
                        recordedAmount[0] += list[i].amount;
86
                        recordedAmount[1] += list[i].amount;
87
                    }
88
                    else
89
                        recordedAmount[index] += list[i].amount;
90

    
91
                }
92
                else
93
                {
94
                    Console.WriteLine("Unknown code " + list[i].building);
95
                }
96

    
97
            }
98

    
99
            for (int k = 0; k < TagInfo.faculties.Length; k++)
100
            {
101
                LogInInfo dayInfo = new LogInInfo(TagInfo.faculties[k], recordedAmount[k], lastStartDay, range);
102
                loginInfo.Add(dayInfo);
103
            }
104

    
105
            return loginInfo;
106
        }
107

    
108
        private static List<JisInfo> ProcessOneLoginFileAsIntervals(string path, int interval)
109
        {
110
            throw new NotImplementedException();
111
        }
112

    
113
    }
114
}
(3-3/5)