Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 734533a8

Přidáno uživatelem Alex Konig před více než 3 roky(ů)

re #8597 Code maintenance - comments, namespace changes

Zobrazit rozdíly:

Server/ServerApp/Parser/Parsers/JisParser.cs
1
using Parser.OutputInfo;
2
using System;
1
using System;
3 2
using System.Collections.Generic;
4 3
using System.IO;
5
using Parser.InputData;
4
using ServerApp.Parser.InputData;
5
using ServerApp.Parser.OutputInfo;
6 6

  
7
namespace Parser.Parsers
7
namespace ServerApp.Parser.Parsers
8 8
{
9
    /// <summary>
10
    /// Class parsing jis files into instances of ActivityInfo divided by given time interval
11
    /// Data parsed from 7am (included) to 18pm (included)
12
    /// </summary>
9 13
    class JisParser
10 14
    {
11

  
12
        public List<JisInfo> ParseJisData(string folder, bool wholeDay = true, int interval = 1)
15
        
16
        /// <summary>
17
        /// Parses jis data to ActivityInfo instances
18
        /// Data parsed from 7am (included) to 18pm (included)
19
        /// </summary>
20
        /// <param name="folder">Folder with login data files</param>
21
        /// <param name="wholeDay">Should data be parsed as one instance per day (if true parameter interval will be ignored)</param>
22
        /// <param name="interval">Time interval to divide days by, minimum is 1h</param>
23
        /// <returns></returns>
24
        public List<ActivityInfo> ParseJisData(string folder, bool wholeDay = true, int interval = 1)
13 25
        {
14
            List<JisInfo> list = new List<JisInfo>();
15

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

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

  
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í
29
            List<ActivityInfo> list = new List<ActivityInfo>();
30

  
31
            // parse all files
23 32
            string[] fileEntries = Directory.GetFiles(folder);
24 33
            foreach (string fileName in fileEntries)
25 34
            {
26
                List<JisInfo> loadedData = null;
27
                // pokud po jednom dni
35
                List<ActivityInfo> loadedData = null;
36

  
37
                // parse as one instance per day
28 38
                if (wholeDay)
29 39
                    loadedData = ProcessOneJisFileAsDays(fileName);
30
                // pokud po hodinách
40
                // parse by interval length
31 41
                else
32 42
                {
33 43
                    // pokud: konec dne nebo konec aktuálního intervalu -> vemu to co sem nasčítal
......
40 50
            return list;
41 51
        }
42 52

  
43
        private static List<JisInfo> ProcessOneJisFileAsDays(string path)
53
        /// <summary>
54
        /// Parses data from one data file as one instance per day
55
        /// </summary>
56
        /// <param name="path">Path ti file</param>
57
        /// <returns>List with ActivityInfo instances</returns>
58
        private static List<ActivityInfo> ProcessOneJisFileAsDays(string path)
44 59
        {
45
            List<JisInfo> jisInfo = new List<JisInfo>();
60
            if (!File.Exists(path))
61
                return null;
46 62

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

  
66
            // data for each faculty
50 67
            int[] recordedAmount = new int[TagInfo.faculties.Length];
68
            // min/max hour taken into account
51 69
            int[] minmaxHour = new int[] { 7, 18 };
70
            // interval length
52 71
            int range = minmaxHour[1] - minmaxHour[0];
53 72

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

  
62
                // v každym dni agreguju
81
                // start of the day -> make an instance
63 82
                string place = list[i].placeTag;
64
                DateTime date = new DateTime(list[i].dateTime.Year, list[i].dateTime.Month, list[i].dateTime.Day);
83
                DateTime date = new DateTime(list[i].dateTime.Year, list[i].dateTime.Month, list[i].dateTime.Day, minmaxHour[0], 0, 0);
65 84
                if (!date.Equals(lastStartTime)) 
66 85
                {
86
                    // data for each faculty separate
67 87
                    for (int k = 0; k < TagInfo.faculties.Length; k++)
68 88
                    {
69
                        JisInfo dayInfo = new JisInfo(TagInfo.faculties[k], recordedAmount[k], lastStartTime, range);
89
                        ActivityInfo dayInfo = new ActivityInfo(TagInfo.faculties[k], recordedAmount[k], lastStartTime, range);
70 90
                        jisInfo.Add(dayInfo);
71 91
                    }
72 92

  
......
74 94
                    lastStartTime = date;
75 95
                }
76 96

  
77
                // tady nasčítávát podle místa
97
                // aggregate data
78 98
                if (TagInfo.jisPlaces.ContainsKey(place))
79 99
                {
80 100
                    int index = TagInfo.jisPlaces[place];
......
87 107
                }
88 108
                else
89 109
                {
110
                    // TODO uknown code handling
90 111
                    Console.WriteLine("Unknown code " + list[i].placeTag);
91 112
                }
92 113

  
93 114
            }
94 115

  
116
            // last day
95 117
            for (int k = 0; k < TagInfo.faculties.Length; k++)
96 118
            {
97
                JisInfo dayInfo = new JisInfo(TagInfo.faculties[k], recordedAmount[k], lastStartTime, range);
119
                ActivityInfo dayInfo = new ActivityInfo(TagInfo.faculties[k], recordedAmount[k], lastStartTime, range);
98 120
                jisInfo.Add(dayInfo);
99 121
            }
100 122

  
101 123
            return jisInfo;
102 124
        }
103 125

  
104
        private static List<JisInfo> ProcessOneJisFileAsIntervals(string path, int interval)
126
        private static List<ActivityInfo> ProcessOneJisFileAsIntervals(string path, int interval)
105 127
        {
106 128
            throw new NotImplementedException();
107 129
        }

Také k dispozici: Unified diff