Projekt

Obecné

Profil

« Předchozí | Další » 

Revize d39750f3

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

re #8682 Modified parser to aggregate data according to buildings. Also added a method that merges information about jis and webauth activity into one list.

Zobrazit rozdíly:

Server/ServerApp/Parser/Parsers/DataParser.cs
24 24
        LogInParser loginParser;
25 25

  
26 26
        /// <summary> WeatherInfo </summary>
27
        public List<WeatherInfo> weatherList;
27
        List<WeatherInfo> weatherList;
28
        public List<WeatherInfo> WeatherList { get => weatherList; }
29
        /// <summary> ActivityInfo repersenting overall activity </summary>
30
        List<ActivityInfo> attendanceList;
31
        public List<ActivityInfo> AttendanceList { get => attendanceList; }
32

  
28 33
        /// <summary> ActivityInfo representing jis activity </summary>
29
        public List<ActivityInfo> jisList;
34
        List<ActivityInfo> jisList;
30 35
        /// <summary> ActivityInfo representing login activity</summary>
31
        public List<ActivityInfo> loginList;
36
        List<ActivityInfo> loginList;
32 37

  
33 38
        /// <summary>
34 39
        /// Constructor
......
37 42
        {
38 43
            TagInfo.CreateDictionaries();
39 44

  
40
            // TODO ask for data folder?
45
            // TODO ask for data folder
41 46
            this.path = path;
42 47
            DataLoader loader = new CsvDataLoader();
43 48

  
......
51 56
        /// </summary>
52 57
        /// <param name="interval">Length of an interval</param>
53 58
        /// <param name="wholeDay">Parse data as one instance per day</param>
54
        public void Parse(int interval = 1, bool wholeDay = true)
59
        public bool Parse(DateTime startTime, DateTime endTime, int interval = 1, bool wholeDay = true)
55 60
        {
61
            // TODO start and end time -> ask for files from this span, plus validate if the data really is from this span (issue with 00 files)
62

  
56 63
            var cultureInfo = CultureInfo.GetCultureInfo("en-GB");
57 64
            Thread.CurrentThread.CurrentCulture = cultureInfo;
58 65
            Thread.CurrentThread.CurrentUICulture = cultureInfo;
......
61 68
            string pathJis = path + "jis";
62 69
            string pathLogIn = path + "login";
63 70

  
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);
71
            weatherList = weatherParser.ParseWeatherData(pathWeather, wholeDay, interval);
72
            jisList = jisParser.ParseJisData(pathJis, wholeDay, interval);
73
            loginList = loginParser.ParseLogInData(pathLogIn, wholeDay, interval);
67 74

  
68 75
            //Console.WriteLine("WEATHER");
69 76
            //WriteToConsole(weatherList);
70
            Console.WriteLine("JIS");
71
            WriteToConsole(jisList);
77
            //Console.WriteLine("JIS");
78
            //WriteToConsole(jisList);
72 79
            //Console.WriteLine("LOGIN");
73 80
            //WriteToConsole(loginList);
81

  
82
            //WriteToConsole(AddListToOne(jisList));
83

  
84
            MergeAttendance();
85

  
86
            //Console.WriteLine("MERGED IN ONE LIST");
87
            //WriteToConsole(attendanceList);
88

  
89
            if (weatherList.Count == 0 || attendanceList.Count == 0)
90
                return false;
91

  
92
            return true;
93
        }
94

  
95
        /// <summary>
96
        /// Merges ActivityInfo lists with jis and login activity into one
97
        /// Adds information from the same time period together, doesn't change the rest
98
        /// </summary>
99
        private void MergeAttendance()
100
        {
101
            attendanceList = new List<ActivityInfo>();
102

  
103
            int indexJis = 0, indexLogin = 0;
104
            while (true)
105
            {
106
                if (indexJis >= jisList.Count && indexLogin >= loginList.Count)
107
                    break;
108

  
109
                ActivityInfo jis = jisList[indexJis];
110
                int jisTag = TagInfo.IndexOfBuilding(jis.building);
111
                ActivityInfo login = loginList[indexLogin];
112
                int loginTag = TagInfo.IndexOfBuilding(login.building);
113

  
114
                // if same time times -> add to one info
115
                if (jis.startTime == login.startTime)
116
                {
117
                    // need to have same building tags
118
                    if (jisTag == loginTag)
119
                    {
120
                        jis.amount += login.amount;
121
                        attendanceList.Add(jis);
122
                        indexJis++; indexLogin++;
123
                    }
124

  
125
                    if (jisTag < loginTag)
126
                    {
127
                        indexJis++;
128
                        attendanceList.Add(jis);
129
                    }
130

  
131
                    if (jisTag > loginTag)
132
                    {
133
                        indexLogin++;
134
                        attendanceList.Add(login);
135
                    }
136

  
137
                }
138

  
139
                // if jis time is smaller -> add jis and move
140
                if (jis.startTime < login.startTime)
141
                {
142
                    indexJis++;
143
                    attendanceList.Add(jis);
144
                }
145

  
146
                // if login time is smaller -> add login and move
147
                if (login.startTime < jis.startTime)
148
                {
149
                    indexLogin++;
150
                    attendanceList.Add(login);
151
                }
152

  
153
            }
154

  
155
        }
156

  
157
        /// <summary>
158
        /// Sum all info for separate intervals in the list to the appropriate day
159
        /// </summary>
160
        /// <param name="list">List with activity info, info separated into buildings and intervals</param>
161
        /// <returns></returns>
162
        private List<ActivityInfo> AddListToOne(List<ActivityInfo> list)
163
        {
164
            List<ActivityInfo> a2 = new List<ActivityInfo>();
165
            for (int i = 0; i < list.Count; i+=TagInfo.buildings.Length)
166
            {
167
                int amount = 0;
168
                for (int j = 0; j < TagInfo.buildings.Length; j++)
169
                {
170
                    amount += list[i + j].amount;
171
                }
172
                ActivityInfo info = new ActivityInfo("ALL", amount, list[i].startTime, list[i].intervalLength);
173
                a2.Add(info);
174
            }
175
            return a2;
176
        }
177

  
178
        /// <summary>
179
        /// Debug method - writing lists to console
180
        /// </summary>
181
        private void WriteToConsole(List<ActivityInfo> list)
182
        {
183
            // TODO useless in finished app
184
            if (list == null)
185
            {
186
                Console.WriteLine("Unsuccessful parsing");
187
                return;
188
            }
189
            Console.WriteLine(list.Count);
190

  
191
            for (int i = 0; i < list.Count; i++)
192
                Console.WriteLine(list[i].ToString());
74 193
        }
75 194

  
76 195
        /// <summary>
77 196
        /// Debug method - writing lists to console
78 197
        /// </summary>
79
        private void WriteToConsole<T>(List<T> list)
198
        private void WriteToConsole(List<WeatherInfo> list)
80 199
        {
81 200
            // TODO useless in finished app
82 201
            if (list == null)

Také k dispozici: Unified diff