Projekt

Obecné

Profil

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

    
7
namespace Parser.Parsers
8
{
9
    class JisParser
10
    {
11

    
12
        public List<JisInfo> ParseJisData(string folder, bool wholeDay = true, int interval = 1)
13
        {
14
            List<JisInfo> list = new List<JisInfo>();
15

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

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

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

    
37
                list.AddRange(loadedData);
38
            }
39

    
40
            return list;
41
        }
42

    
43
        private static List<JisInfo> ProcessOneJisFileAsDays(string path)
44
        {
45
            List<JisInfo> jisInfo = new List<JisInfo>();
46

    
47
            // načíst data ze souboru
48
            List<JisInstance> list =  CsvDataLoader.LoadJisFile(path);
49

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

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

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

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

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

    
87
                }
88
                else
89
                {
90
                    Console.WriteLine("Unknown code " + list[i].placeTag);
91
                }
92

    
93
            }
94

    
95
            for (int k = 0; k < TagInfo.faculties.Length; k++)
96
            {
97
                JisInfo dayInfo = new JisInfo(TagInfo.faculties[k], recordedAmount[k], lastStartTime, range);
98
                jisInfo.Add(dayInfo);
99
            }
100

    
101
            return jisInfo;
102
        }
103

    
104
        private static List<JisInfo> ProcessOneJisFileAsIntervals(string path, int interval)
105
        {
106
            throw new NotImplementedException();
107
        }
108
    }
109
}
(1-1/4)