Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 4b847de5

Přidáno uživatelem Alex Konig před téměř 4 roky(ů)

re #8933 Testing LoginParser

Zobrazit rozdíly:

Server/ServerApp/DataDownload/DataDownloader.cs
84 84
			webClient = new WebClient();
85 85
		}
86 86

  
87
		/// <summary>
88
		/// Downloads json file
89
		/// </summary>
90
		/// <returns> Path to file </returns>
91
		public string DownloadWeatherPrediction()
92
		{
93
			// TODO either set this path as attribute or if parameter JsonParser needs an attribute that would be set through constructor
94
			string predictionSite = "http://wttr.in/Plzen,czechia?format=j1";
95

  
96
			DateTime now = DateTime.Now;
97
			WebClient webClient = new WebClient();
98
			webClient.DownloadFile(predictionSite, $"data/{now.Year}{now.Month}{now.Day}.json");
99

  
100
			return $"data/{now.Year}{now.Month}{now.Day}.json";
101
		}
102

  
87 103
		/// <summary>
88 104
		/// Creates subdirectories for all data types
89 105
		/// TBD if we want to do it this way
Server/ServerApp/Parser/Parsers/LogInParser.cs
15 15
    /// Data parsed from 7am (included) to 18pm (included)
16 16
    /// </summary>
17 17
    /// <author>A. Konig</author>
18
    class LogInParser
18
    public class LogInParser
19 19
    {
20 20
        /// <summary> Datafile loader  </summary>
21 21
        IDataLoader loader;
......
99 99
                // start of the day -> make an instance
100 100
                string place = list[i].building;
101 101
                DateTime date = new DateTime(list[i].date.Year, list[i].date.Month, list[i].date.Day, minmaxHour[0], 0, 0);
102
                DateTime dateOfLessonStart = new DateTime(list[i].date.Year, list[i].date.Month, list[i].date.Day, list[i].lessonStart.Hour, list[i].lessonStart.Minute, list[i].lessonStart.Second);
102 103
                if (!date.Equals(lastStartDay))
103 104
                {
104 105
                    // data for each faculty separate
105 106
                    for (int k = 0; k < TagInfo.buildings.Length; k++)
106 107
                    {
107 108
                        ActivityInfo dayInfo = new ActivityInfo(TagInfo.buildings[k], recordedAmount[k], lastStartDay, range); 
108
                        loginInfo.Add(dayInfo);
109
                        if (recordedAmount[k] != 0)
110
                            loginInfo.Add(dayInfo);
109 111
                    }
110 112

  
111 113
                    recordedAmount = new int[TagInfo.buildings.Length];
......
113 115
                }
114 116

  
115 117
                // if not in allowed time window -> discard
116
                if (list[i].date < startTime || list[i].date > endTime)
118
                if (dateOfLessonStart < startTime || dateOfLessonStart > endTime)
117 119
                    continue;
118 120

  
119 121
                // aggregate data
......
142 144
            for (int k = 0; k < TagInfo.buildings.Length; k++)
143 145
            {
144 146
                ActivityInfo dayInfo = new ActivityInfo(TagInfo.buildings[k], recordedAmount[k], lastStartDay, range);
145
                loginInfo.Add(dayInfo);
147
                if (recordedAmount[k] != 0)
148
                    loginInfo.Add(dayInfo);
146 149
            }
147 150

  
148 151
            return loginInfo;
......
192 195
                // start of the day -> make an instance
193 196
                string place = list[i].building;
194 197
                DateTime date = new DateTime(list[i].date.Year, list[i].date.Month, list[i].date.Day, list[i].lessonStart.Hour, 0, 0);
198
                DateTime dateOfLessonStart = new DateTime(list[i].date.Year, list[i].date.Month, list[i].date.Day, list[i].lessonStart.Hour, list[i].lessonStart.Minute, list[i].lessonStart.Second);
195 199

  
196 200
                // end of the day
197 201
                if (!(date.Year == lastStartTime.Year && date.Month == lastStartTime.Month && date.Day == lastStartTime.Day))
......
205 209
                        for (int l = 0; l < TagInfo.buildings.Length; l++)
206 210
                        {
207 211
                            ActivityInfo dayInfo = new ActivityInfo(TagInfo.buildings[l], data[k][l], stTime, interval);
208
                            loginInfo.Add(dayInfo);
212
                            if (data[k][l] != 0)
213
                                loginInfo.Add(dayInfo);
209 214
                        }
210 215

  
211 216
                        data[k] = new int[TagInfo.buildings.Length];
......
214 219
                }
215 220

  
216 221
                // if not in allowed time window -> discard
217
                if (list[i].date < startTime || list[i].date > endTime)
222
                if (dateOfLessonStart < startTime || dateOfLessonStart > endTime)
218 223
                    continue;
219 224

  
220 225
                // find index for current instance
......
262 267
                for (int l = 0; l < TagInfo.buildings.Length; l++)
263 268
                {
264 269
                    ActivityInfo dayInfo = new ActivityInfo(TagInfo.buildings[l], data[k][l], stTime, interval);
265
                    loginInfo.Add(dayInfo);
270
                    if (data[k][l] != 0)
271
                        loginInfo.Add(dayInfo);
266 272
                }
267 273
            }
268 274

  
Server/ServerApp/WeatherPredictionParser/IJsonParser.cs
10 10
    /// <summary>
11 11
    /// Abstract class that every Json parser should inherit from
12 12
    /// </summary>
13
    abstract class IJsonParser
13
    public abstract class IJsonParser
14 14
    {
15 15

  
16 16
        /// <summary> Current weather </summary>
17 17
        WeatherInfo current;
18
        public WeatherInfo Current { get => current; }
18
        public WeatherInfo Current { get => current; set => predictions = value; }
19 19

  
20 20
        /// <summary> Prediction for today, tommorrow and day after tommorrow </summary>
21 21
        List<WeatherInfo> predictions;
Server/ServerApp/WeatherPredictionParser/JsonParser.cs
18 18
    /// Class representing a parser for json prediction data
19 19
    /// </summary>
20 20
    /// <author>A. Konig</author>
21
    class JsonParser : IJsonParser
21
    public class JsonParser : IJsonParser
22 22
    {
23
        /// <summary> Current weather </summary>
24
        WeatherInfo current;
25
        public new WeatherInfo Current { get => current; }
26
        /// <summary> Prediction for today, tommorrow and day after tommorrow </summary>
27
        List<WeatherInfo> predictions;
28
        public new List<WeatherInfo> Predictions { get => predictions; set => predictions = value; }
29

  
30 23
        /// <summary> Data loader </summary>
31 24
        DataDownloader loader;
32 25
        /// <summary> Currently parsed day </summary>
......
55 48
            // TODO ask DataDownloader for download said file and return path to it
56 49
            
57 50
            // get file
58
            string file = DownloadWeatherPrediction();
51
            string file = loader.DownloadWeatherPrediction();
59 52
            DateTime now = DateTime.Now;
60 53
            Console.WriteLine(File.Exists(file));
61 54

  
62
            current = new WeatherInfo();
63
            predictions = new List<WeatherInfo>();
55
            Current = new WeatherInfo();
56
            Predictions = new List<WeatherInfo>();
64 57

  
65 58
            if (!File.Exists(file))
66 59
                return;
......
84 77
                    case "current_condition":
85 78
                        {
86 79
                            ArrayEnumerator currentWeather = weatherP.Current.Value.EnumerateArray();
87
                            current = ParseCurrentWeather(currentWeather);
80
                            Current = ParseCurrentWeather(currentWeather);
88 81

  
89 82
                            break;
90 83
                        }
......
110 103
        /// </summary>
111 104
        private void TestConsoleOutput()
112 105
        {
113
            Console.WriteLine(current);
114
            foreach (WeatherInfo w in predictions)
106
            Console.WriteLine(Current);
107
            foreach (WeatherInfo w in Predictions)
115 108
                Console.WriteLine(w);
116 109
        }
117 110

  
118
        // TODO move to data loader
119
        /// <summary>
120
        /// Downloads json file
121
        /// </summary>
122
        /// <returns> Path to file </returns>
123
        private string DownloadWeatherPrediction()
124
        {
125
            DateTime now = DateTime.Now;
126
            WebClient webClient = new WebClient();
127
            webClient.DownloadFile("http://wttr.in/Plzen,czechia?format=j1", $"data/{now.Year}{now.Month}{now.Day}.json");
128

  
129
            return $"data/{now.Year}{now.Month}{now.Day}.json";
130
        }
131

  
132 111
        /// <summary>
133 112
        /// Change data in a way that they now reflect sunrise and sunset times
134 113
        /// If current time under sunrise or over sunset -> WeatherConditions is Dark
......
137 116
        private void EncompassSunRiseSetTimes()
138 117
        {
139 118
            // change current weather
140
            if ((current.startTime.TimeOfDay > sunsetTime.TimeOfDay) || (current.startTime.TimeOfDay < sunriseTime.TimeOfDay))
141
                current.condition = WeatherConditions.Dark;
119
            if ((Current.startTime.TimeOfDay > sunsetTime.TimeOfDay) || (Current.startTime.TimeOfDay < sunriseTime.TimeOfDay))
120
                Current.condition = WeatherConditions.Dark;
142 121

  
143 122
            // change prediction
144
            for (int i = 0; i < predictions.Count - 1; i++)
123
            for (int i = 0; i < Predictions.Count - 1; i++)
145 124
            {
146
                WeatherInfo w = predictions[i];
147
                WeatherInfo wNext = predictions[i + 1];
125
                WeatherInfo w = Predictions[i];
126
                WeatherInfo wNext = Predictions[i + 1];
148 127

  
149 128
                // if wNext time < than w time then it is prediction from the next day -> add 24 to correctly calculate timespan
150 129
                int timespan = wNext.startTime.Hour - w.startTime.Hour;
......
178 157
            }
179 158

  
180 159
            // last prediction
181
            WeatherInfo wLast = predictions[predictions.Count - 1];
160
            WeatherInfo wLast = Predictions[Predictions.Count - 1];
182 161
            TimeSpan endTimeW = new TimeSpan(24, 0, 0);
183 162
            int timespanLast = endTimeW.Hours - wLast.startTime.Hour;
184 163
            wLast.intervalLength = timespanLast;
......
338 317
                }
339 318

  
340 319
                // Console.WriteLine(weather.ToString());
341
                predictions.Add(weather);
342

  
320
                Predictions.Add(weather);
343 321
            }
344 322

  
345 323
        }
Server/TestProject/ParserTests/TestingParser.cs
5 5
using ServerApp.Parser.OutputInfo;
6 6
using Moq;
7 7
using ServerApp.Parser.InputData;
8
using ServerApp.WeatherPredictionParser;
9
using ServerApp.DataDownload;
8 10

  
9 11
// 1h
10 12
// 0.5h to edit parsers 
......
440 442

  
441 443
        #endregion
442 444

  
445
        // -------------------------------- JIS PARSER -----------------------------------------
446

  
443 447
        #region Jis parser
444 448

  
445 449
        #region Parse days
......
703 707
            Assert.AreEqual(new ActivityInfo("MENZA", 5, new DateTime(2000, 1, 1, 11, 0, 0), 2), retVal[1]);
704 708
            Assert.AreEqual(new ActivityInfo("MENZA", 1, new DateTime(2000, 1, 1, 17, 0, 0), 2), retVal[2]);
705 709
        }
710
        #endregion
711

  
712
        #endregion
713

  
714
        // -------------------------------- LOGIN PARSER ----------------------------------------
715

  
716
        #region Login parser
717

  
718
        #region Parse days
719
        [TestMethod]
720
        public void ParseLoginDayOne()
721
        {
722
            TagInfo.CreateDictionaries();
723

  
724
            string path = "";
725
            List<LogInInstance> data = new List<LogInInstance>();
726
            // "01.06.2019 00:00:00"; 2; 4; "10:15"; "11:00"; "LS"; "Učebna"; "LS-234"; "ls233p02-fdu"
727
            data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 2, 3, new DateTime(2000, 1, 1, 9, 20, 0), new DateTime(2000, 1, 1, 10, 5, 0), "LS", "Učebna", "LS-108", "ls233p02-fdu"));
728
            data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 1, 4, new DateTime(2000, 1, 1, 10, 15, 0), new DateTime(2000, 1, 1, 11, 0, 0), "UC", "Učebna", "UC-108", "uc233p02-fav"));
729
            data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 2, 6, new DateTime(2000, 1, 1, 12, 20, 0), new DateTime(2000, 1, 1, 10, 5, 0), "LS", "Učebna", "LS-108", "ls233p02-fdu"));
730
            data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 5, 7, new DateTime(2000, 1, 1, 16, 00, 0), new DateTime(2000, 1, 1, 10, 5, 0), "UC", "Učebna", "LS-108", "ls233p02-fdu"));
731

  
732
            Mock<IDataLoader> dl = new Mock<IDataLoader>();
733
            dl.Setup(m => m.LoadLoginFile(path)).Returns(data);
734

  
735
            LogInParser target = new LogInParser(dl.Object);
736
            PrivateObject obj = new PrivateObject(target);
737

  
738
            List<ActivityInfo> retVal = (List<ActivityInfo>)obj.Invoke("ProcessOneLogInFileAsDays", path, new DateTime(2000, 1, 1), new DateTime(2001, 1, 1));
739

  
740
            Assert.AreEqual(2, retVal.Count);
741
            Assert.AreEqual(new ActivityInfo("FDU", 4, new DateTime(2000, 1, 1, 7, 0, 0), 18 - 7), retVal[0]);
742
            Assert.AreEqual(new ActivityInfo("FAV", 6, new DateTime(2000, 1, 1, 7, 0, 0), 18 - 7), retVal[1]);
743
        }
744

  
745
        [TestMethod]
746
        public void ParseLoginDayOneFiltering()
747
        {
748
            TagInfo.CreateDictionaries();
749

  
750
            string path = "";
751
            List<LogInInstance> data = new List<LogInInstance>();
752
            // "01.06.2019 00:00:00"; 2; 4; "10:15"; "11:00"; "LS"; "Učebna"; "LS-234"; "ls233p02-fdu"
753
            data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 2, 3, new DateTime(2000, 1, 1, 6, 20, 0), new DateTime(2000, 1, 1, 10, 5, 0), "LS", "Učebna", "LS-108", "ls233p02-fdu"));
754
            data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 2, 3, new DateTime(2000, 1, 1, 9, 20, 0), new DateTime(2000, 1, 1, 10, 5, 0), "LS", "Učebna", "LS-108", "ls233p02-fdu"));
755
            data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 1, 4, new DateTime(2000, 1, 1, 10, 15, 0), new DateTime(2000, 1, 1, 11, 0, 0), "UC", "Učebna", "UC-108", "uc233p02-fav"));
756
            data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 2, 6, new DateTime(2000, 1, 1, 12, 20, 0), new DateTime(2000, 1, 1, 12, 5, 0), "LS", "Učebna", "LS-108", "ls233p02-fdu"));
757
            data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 5, 7, new DateTime(2000, 1, 1, 16, 00, 0), new DateTime(2000, 1, 1, 16, 5, 0), "UC", "Učebna", "UC-108", "ls233p02-fdu"));
758
            data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 5, 7, new DateTime(2000, 1, 1, 17, 00, 0), new DateTime(2000, 1, 1, 17, 5, 0), "UC", "Učebna", "UC-108", "ls233p02-fdu"));
759

  
760
            Mock<IDataLoader> dl = new Mock<IDataLoader>();
761
            dl.Setup(m => m.LoadLoginFile(path)).Returns(data);
762

  
763
            LogInParser target = new LogInParser(dl.Object);
764
            PrivateObject obj = new PrivateObject(target);
765

  
766
            List<ActivityInfo> retVal = (List<ActivityInfo>)obj.Invoke("ProcessOneLogInFileAsDays", path, new DateTime(2000, 1, 1), new DateTime(2000, 1, 1, 16, 0, 0));
767

  
768
            Assert.AreEqual(2, retVal.Count);
769
            Assert.AreEqual(new ActivityInfo("FDU", 4, new DateTime(2000, 1, 1, 7, 0, 0), 18 - 7), retVal[0]);
770
            Assert.AreEqual(new ActivityInfo("FAV", 6, new DateTime(2000, 1, 1, 7, 0, 0), 18 - 7), retVal[1]);
771
        }
772

  
773
        [TestMethod]
774
        public void ParseLoginDayTwo()
775
        {
776
            TagInfo.CreateDictionaries();
777

  
778
            string path = "";
779
            List<LogInInstance> data = new List<LogInInstance>();
780
            // "01.06.2019 00:00:00"; 2; 4; "10:15"; "11:00"; "LS"; "Učebna"; "LS-234"; "ls233p02-fdu"
781
            data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 2, 3, new DateTime(2000, 1, 1, 9, 20, 0), new DateTime(2000, 1, 1, 10, 5, 0), "LS", "Učebna", "LS-108", "ls233p02-fdu"));
782
            data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 1, 4, new DateTime(2000, 1, 1, 10, 15, 0), new DateTime(2000, 1, 1, 11, 0, 0), "UC", "Učebna", "UC-108", "uc233p02-fav"));
783
            data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 2, 6, new DateTime(2000, 1, 1, 12, 20, 0), new DateTime(2000, 1, 1, 12, 5, 0), "LS", "Učebna", "LS-108", "ls233p02-fdu"));
784
            data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 5, 7, new DateTime(2000, 1, 1, 16, 00, 0), new DateTime(2000, 1, 1, 16, 5, 0), "UC", "Učebna", "UC-108", "ls233p02-fdu"));
785

  
786
            data.Add(new LogInInstance(new DateTime(2000, 1, 2, 0, 0, 0), 2, 3, new DateTime(2000, 1, 1, 9, 20, 0), new DateTime(2000, 1, 1, 10, 5, 0), "LS", "Učebna", "LS-108", "ls233p02-fdu"));
787
            data.Add(new LogInInstance(new DateTime(2000, 1, 2, 0, 0, 0), 3, 4, new DateTime(2000, 1, 1, 10, 15, 0), new DateTime(2000, 1, 1, 11, 0, 0), "EU", "Učebna", "EU-108", "uc233p02-fav"));
788
            data.Add(new LogInInstance(new DateTime(2000, 1, 2, 0, 0, 0), 5, 6, new DateTime(2000, 1, 1, 12, 20, 0), new DateTime(2000, 1, 1, 12, 5, 0), "LS", "Učebna", "LS-108", "ls233p02-fdu"));
789
            data.Add(new LogInInstance(new DateTime(2000, 1, 2, 0, 0, 0), 2, 7, new DateTime(2000, 1, 1, 17, 00, 0), new DateTime(2000, 1, 1, 17, 5, 0), "EU", "Učebna", "EU-108", "ls233p02-fdu"));
790

  
791
            Mock<IDataLoader> dl = new Mock<IDataLoader>();
792
            dl.Setup(m => m.LoadLoginFile(path)).Returns(data);
793

  
794
            LogInParser target = new LogInParser(dl.Object);
795
            PrivateObject obj = new PrivateObject(target);
796

  
797
            List<ActivityInfo> retVal = (List<ActivityInfo>)obj.Invoke("ProcessOneLogInFileAsDays", path, new DateTime(2000, 1, 1), new DateTime(2000, 1, 3, 0, 0, 0));
798

  
799
            Assert.AreEqual(4, retVal.Count);
800
            Assert.AreEqual(new ActivityInfo("FDU", 4, new DateTime(2000, 1, 1, 7, 0, 0), 18 - 7), retVal[0]);
801
            Assert.AreEqual(new ActivityInfo("FAV", 6, new DateTime(2000, 1, 1, 7, 0, 0), 18 - 7), retVal[1]);
802

  
803
            Assert.AreEqual(new ActivityInfo("FDU", 7, new DateTime(2000, 1, 2, 7, 0, 0), 18 - 7), retVal[2]);
804
            Assert.AreEqual(new ActivityInfo("FEL", 5, new DateTime(2000, 1, 2, 7, 0, 0), 18 - 7), retVal[3]);
805
        }
806

  
807
        [TestMethod]
808
        public void ParseLoginDayTwoFiltering()
809
        {
810
            TagInfo.CreateDictionaries();
811

  
812
            string path = "";
813
            List<LogInInstance> data = new List<LogInInstance>();
814
            // "01.06.2019 00:00:00"; 2; 4; "10:15"; "11:00"; "LS"; "Učebna"; "LS-234"; "ls233p02-fdu"
815
            data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 2, 3, new DateTime(2000, 1, 1, 5, 20, 0), new DateTime(2000, 1, 1, 10, 5, 0), "LS", "Učebna", "LS-108", "ls233p02-fdu"));
816
            data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 2, 3, new DateTime(2000, 1, 1, 9, 20, 0), new DateTime(2000, 1, 1, 10, 5, 0), "LS", "Učebna", "LS-108", "ls233p02-fdu"));
817
            data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 1, 4, new DateTime(2000, 1, 1, 10, 15, 0), new DateTime(2000, 1, 1, 11, 0, 0), "UC", "Učebna", "UC-108", "uc233p02-fav"));
818
            data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 2, 6, new DateTime(2000, 1, 1, 12, 20, 0), new DateTime(2000, 1, 1, 12, 5, 0), "LS", "Učebna", "LS-108", "ls233p02-fdu"));
819
            data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 5, 7, new DateTime(2000, 1, 1, 16, 00, 0), new DateTime(2000, 1, 1, 16, 5, 0), "UC", "Učebna", "UC-108", "ls233p02-fdu"));
820

  
821
            data.Add(new LogInInstance(new DateTime(2000, 1, 2, 0, 0, 0), 2, 7, new DateTime(2000, 1, 1, 6, 00, 0), new DateTime(2000, 1, 1, 17, 5, 0), "EU", "Učebna", "EU-108", "ls233p02-fdu"));
822
            data.Add(new LogInInstance(new DateTime(2000, 1, 2, 0, 0, 0), 2, 3, new DateTime(2000, 1, 1, 9, 20, 0), new DateTime(2000, 1, 1, 10, 5, 0), "LS", "Učebna", "LS-108", "ls233p02-fdu"));
823
            data.Add(new LogInInstance(new DateTime(2000, 1, 2, 0, 0, 0), 3, 4, new DateTime(2000, 1, 1, 10, 15, 0), new DateTime(2000, 1, 1, 11, 0, 0), "EU", "Učebna", "EU-108", "uc233p02-fav"));
824
            data.Add(new LogInInstance(new DateTime(2000, 1, 2, 0, 0, 0), 5, 6, new DateTime(2000, 1, 1, 12, 20, 0), new DateTime(2000, 1, 1, 12, 5, 0), "LS", "Učebna", "LS-108", "ls233p02-fdu"));
825
            data.Add(new LogInInstance(new DateTime(2000, 1, 2, 0, 0, 0), 2, 7, new DateTime(2000, 1, 1, 17, 00, 0), new DateTime(2000, 1, 1, 17, 5, 0), "EU", "Učebna", "EU-108", "ls233p02-fdu"));
826
            data.Add(new LogInInstance(new DateTime(2000, 1, 2, 0, 0, 0), 2, 7, new DateTime(2000, 1, 1, 19, 00, 0), new DateTime(2000, 1, 1, 17, 5, 0), "EU", "Učebna", "EU-108", "ls233p02-fdu"));
827

  
828
            data.Add(new LogInInstance(new DateTime(2000, 1, 3, 0, 0, 0), 2, 7, new DateTime(2000, 1, 1, 17, 00, 0), new DateTime(2000, 1, 1, 17, 5, 0), "EU", "Učebna", "EU-108", "ls233p02-fdu"));
829
            data.Add(new LogInInstance(new DateTime(2000, 1, 3, 0, 0, 0), 2, 7, new DateTime(2000, 1, 1, 17, 00, 0), new DateTime(2000, 1, 1, 17, 5, 0), "EU", "Učebna", "EU-108", "ls233p02-fdu"));
830

  
831
            Mock<IDataLoader> dl = new Mock<IDataLoader>();
832
            dl.Setup(m => m.LoadLoginFile(path)).Returns(data);
833

  
834
            LogInParser target = new LogInParser(dl.Object);
835
            PrivateObject obj = new PrivateObject(target);
836

  
837
            List<ActivityInfo> retVal = (List<ActivityInfo>)obj.Invoke("ProcessOneLogInFileAsDays", path, new DateTime(2000, 1, 1), new DateTime(2000, 1, 3, 0, 0, 0));
838

  
839
            Assert.AreEqual(4, retVal.Count);
840
            Assert.AreEqual(new ActivityInfo("FDU", 4, new DateTime(2000, 1, 1, 7, 0, 0), 18 - 7), retVal[0]);
841
            Assert.AreEqual(new ActivityInfo("FAV", 6, new DateTime(2000, 1, 1, 7, 0, 0), 18 - 7), retVal[1]);
842

  
843
            Assert.AreEqual(new ActivityInfo("FDU", 7, new DateTime(2000, 1, 2, 7, 0, 0), 18 - 7), retVal[2]);
844
            Assert.AreEqual(new ActivityInfo("FEL", 5, new DateTime(2000, 1, 2, 7, 0, 0), 18 - 7), retVal[3]);
845
        }
846

  
847

  
848
        [TestMethod]
849
        public void ParseLoginDayNone()
850
        {
851
            TagInfo.CreateDictionaries();
706 852

  
853
            string path = "";
854
            List<LogInInstance> data = new List<LogInInstance>();
855
            // "01.06.2019 00:00:00"; 2; 4; "10:15"; "11:00"; "LS"; "Učebna"; "LS-234"; "ls233p02-fdu"
856
            data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 2, 3, new DateTime(2000, 1, 1, 5, 20, 0), new DateTime(2000, 1, 1, 10, 5, 0), "LS", "Učebna", "LS-108", "ls233p02-fdu"));
857
            data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 1, 4, new DateTime(2000, 1, 1, 10, 15, 0), new DateTime(2000, 1, 1, 11, 0, 0), "UC", "Učebna", "UC-108", "uc233p02-fav"));
858
            data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 2, 6, new DateTime(2000, 1, 1, 12, 20, 0), new DateTime(2000, 1, 1, 12, 5, 0), "LS", "Učebna", "LS-108", "ls233p02-fdu"));
859
            data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 5, 7, new DateTime(2000, 1, 1, 16, 00, 0), new DateTime(2000, 1, 1, 16, 5, 0), "UC", "Učebna", "UC-108", "ls233p02-fdu"));
860

  
861
            data.Add(new LogInInstance(new DateTime(2000, 1, 2, 0, 0, 0), 2, 3, new DateTime(2000, 1, 1, 9, 20, 0), new DateTime(2000, 1, 1, 10, 5, 0), "LS", "Učebna", "LS-108", "ls233p02-fdu"));
862
            data.Add(new LogInInstance(new DateTime(2000, 1, 2, 0, 0, 0), 3, 4, new DateTime(2000, 1, 1, 10, 15, 0), new DateTime(2000, 1, 1, 11, 0, 0), "EU", "Učebna", "EU-108", "uc233p02-fav"));
863
            data.Add(new LogInInstance(new DateTime(2000, 1, 2, 0, 0, 0), 5, 6, new DateTime(2000, 1, 1, 12, 20, 0), new DateTime(2000, 1, 1, 12, 5, 0), "LS", "Učebna", "LS-108", "ls233p02-fdu"));
864
            data.Add(new LogInInstance(new DateTime(2000, 1, 2, 0, 0, 0), 2, 7, new DateTime(2000, 1, 1, 17, 00, 0), new DateTime(2000, 1, 1, 17, 5, 0), "EU", "Učebna", "EU-108", "ls233p02-fdu"));
865

  
866
            Mock<IDataLoader> dl = new Mock<IDataLoader>();
867
            dl.Setup(m => m.LoadLoginFile(path)).Returns(data);
868

  
869
            LogInParser target = new LogInParser(dl.Object);
870
            PrivateObject obj = new PrivateObject(target);
871

  
872
            List<ActivityInfo> retVal = (List<ActivityInfo>)obj.Invoke("ProcessOneLogInFileAsDays", path, new DateTime(2000, 1, 1), new DateTime(2000, 1, 1, 9, 0, 0));
873
            
874
            Assert.AreEqual(0, retVal.Count);
875
        }
707 876
        #endregion
708 877

  
878
        #region Parse hours
879
        [TestMethod]
880
        public void ParseLoginHourlyOne()
881
        {
882
            TagInfo.CreateDictionaries();
883

  
884
            string path = "";
885
            List<LogInInstance> data = new List<LogInInstance>();
886
            // "01.06.2019 00:00:00"; 2; 4; "10:15"; "11:00"; "LS"; "Učebna"; "LS-234"; "ls233p02-fdu"
887
            data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 2, 3, new DateTime(2000, 1, 1, 9, 20, 0), new DateTime(2000, 1, 1, 10, 5, 0), "LS", "Učebna", "LS-108", "ls233p02-fdu"));
888
            data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 1, 4, new DateTime(2000, 1, 1, 10, 15, 0), new DateTime(2000, 1, 1, 11, 0, 0), "EL", "Učebna", "UC-108", "uc233p02-fav"));
889

  
890
            data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 2, 6, new DateTime(2000, 1, 1, 13, 20, 0), new DateTime(2000, 1, 1, 10, 5, 0), "LS", "Učebna", "LS-108", "ls233p02-fdu"));
891
            data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 5, 7, new DateTime(2000, 1, 1, 14, 00, 0), new DateTime(2000, 1, 1, 10, 5, 0), "UC", "Učebna", "LS-108", "ls233p02-fdu"));
892

  
893
            data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 2, 6, new DateTime(2000, 1, 1, 18, 0, 0), new DateTime(2000, 1, 1, 10, 5, 0), "LS", "Učebna", "LS-108", "ls233p02-fdu"));
894
            data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 5, 7, new DateTime(2000, 1, 1, 18, 20, 0), new DateTime(2000, 1, 1, 10, 5, 0), "LS", "Učebna", "LS-108", "ls233p02-fdu"));
895

  
896
            Mock<IDataLoader> dl = new Mock<IDataLoader>();
897
            dl.Setup(m => m.LoadLoginFile(path)).Returns(data);
898

  
899
            LogInParser target = new LogInParser(dl.Object);
900
            PrivateObject obj = new PrivateObject(target);
901

  
902
            List<ActivityInfo> retVal = (List<ActivityInfo>)obj.Invoke("ProcessOneLoginFileAsIntervals", path, 2, new DateTime(2000, 1, 1), new DateTime(2001, 1, 1));
903

  
904
            Assert.AreEqual(5, retVal.Count);
905
            Assert.AreEqual(new ActivityInfo("FDU", 2, new DateTime(2000, 1, 1, 9, 0, 0), 2), retVal[0]);
906
            Assert.AreEqual(new ActivityInfo("FEL", 1, new DateTime(2000, 1, 1, 9, 0, 0), 2), retVal[1]);
907
            Assert.AreEqual(new ActivityInfo("FDU", 2, new DateTime(2000, 1, 1, 13, 0, 0), 2), retVal[2]);
908
            Assert.AreEqual(new ActivityInfo("FAV", 5, new DateTime(2000, 1, 1, 13, 0, 0), 2), retVal[3]);
909
            Assert.AreEqual(new ActivityInfo("FDU", 7, new DateTime(2000, 1, 1, 17, 0, 0), 2), retVal[4]);
910
        }
911

  
912
        [TestMethod]
913
        public void ParseLoginDayHourlyMultiple()
914
        {
915
            TagInfo.CreateDictionaries();
916

  
917
            string path = "";
918
            List<LogInInstance> data = new List<LogInInstance>();
919
            // "01.06.2019 00:00:00"; 2; 4; "10:15"; "11:00"; "LS"; "Učebna"; "LS-234"; "ls233p02-fdu"
920
            data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 2, 3, new DateTime(2000, 1, 1, 9, 20, 0), new DateTime(2000, 1, 1, 10, 5, 0), "LS", "Učebna", "LS-108", "ls233p02-fdu"));
921
            data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 1, 4, new DateTime(2000, 1, 1, 10, 15, 0), new DateTime(2000, 1, 1, 11, 0, 0), "EL", "Učebna", "UC-108", "uc233p02-fav"));
922

  
923
            data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 2, 6, new DateTime(2000, 1, 1, 13, 20, 0), new DateTime(2000, 1, 1, 10, 5, 0), "LS", "Učebna", "LS-108", "ls233p02-fdu"));
924
            data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 5, 7, new DateTime(2000, 1, 1, 14, 00, 0), new DateTime(2000, 1, 1, 10, 5, 0), "UC", "Učebna", "LS-108", "ls233p02-fdu"));
925

  
926
            data.Add(new LogInInstance(new DateTime(2000, 1, 2, 0, 0, 0), 2, 6, new DateTime(2000, 1, 1, 18, 0, 0), new DateTime(2000, 1, 1, 10, 5, 0), "LS", "Učebna", "LS-108", "ls233p02-fdu"));
927
            data.Add(new LogInInstance(new DateTime(2000, 1, 2, 0, 0, 0), 5, 7, new DateTime(2000, 1, 1, 18, 20, 0), new DateTime(2000, 1, 1, 10, 5, 0), "LS", "Učebna", "LS-108", "ls233p02-fdu"));
928

  
929
            Mock<IDataLoader> dl = new Mock<IDataLoader>();
930
            dl.Setup(m => m.LoadLoginFile(path)).Returns(data);
931

  
932
            LogInParser target = new LogInParser(dl.Object);
933
            PrivateObject obj = new PrivateObject(target);
934

  
935
            List<ActivityInfo> retVal = (List<ActivityInfo>)obj.Invoke("ProcessOneLoginFileAsIntervals", path, 2, new DateTime(2000, 1, 1), new DateTime(2001, 1, 1));
936

  
937
            Assert.AreEqual(5, retVal.Count);
938
            Assert.AreEqual(new ActivityInfo("FDU", 2, new DateTime(2000, 1, 1, 9, 0, 0), 2), retVal[0]);
939
            Assert.AreEqual(new ActivityInfo("FEL", 1, new DateTime(2000, 1, 1, 9, 0, 0), 2), retVal[1]);
940
            Assert.AreEqual(new ActivityInfo("FDU", 2, new DateTime(2000, 1, 1, 13, 0, 0), 2), retVal[2]);
941
            Assert.AreEqual(new ActivityInfo("FAV", 5, new DateTime(2000, 1, 1, 13, 0, 0), 2), retVal[3]);
942
            Assert.AreEqual(new ActivityInfo("FDU", 7, new DateTime(2000, 1, 2, 17, 0, 0), 2), retVal[4]);
943
        }
944

  
945
        [TestMethod]
946
        public void ParseLoginHourlyFiltering()
947
        {
948
            TagInfo.CreateDictionaries();
949

  
950
            string path = "";
951
            List<LogInInstance> data = new List<LogInInstance>();
952
            // "01.06.2019 00:00:00"; 2; 4; "10:15"; "11:00"; "LS"; "Učebna"; "LS-234"; "ls233p02-fdu"
953
            data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 2, 3, new DateTime(2000, 1, 1, 5, 20, 0), new DateTime(2000, 1, 1, 10, 5, 0), "LS", "Učebna", "LS-108", "ls233p02-fdu"));
954
            data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 2, 3, new DateTime(2000, 1, 1, 9, 20, 0), new DateTime(2000, 1, 1, 10, 5, 0), "LS", "Učebna", "LS-108", "ls233p02-fdu"));
955
            data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 1, 4, new DateTime(2000, 1, 1, 10, 15, 0), new DateTime(2000, 1, 1, 11, 0, 0), "EL", "Učebna", "UC-108", "uc233p02-fav"));
956

  
957
            data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 2, 6, new DateTime(2000, 1, 1, 13, 20, 0), new DateTime(2000, 1, 1, 10, 5, 0), "LS", "Učebna", "LS-108", "ls233p02-fdu"));
958
            data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 5, 7, new DateTime(2000, 1, 1, 14, 00, 0), new DateTime(2000, 1, 1, 10, 5, 0), "UC", "Učebna", "LS-108", "ls233p02-fdu"));
959

  
960
            data.Add(new LogInInstance(new DateTime(2000, 1, 2, 0, 0, 0), 2, 6, new DateTime(2000, 1, 1, 18, 0, 0), new DateTime(2000, 1, 1, 10, 5, 0), "LS", "Učebna", "LS-108", "ls233p02-fdu"));
961
            data.Add(new LogInInstance(new DateTime(2000, 1, 2, 0, 0, 0), 5, 7, new DateTime(2000, 1, 1, 18, 20, 0), new DateTime(2000, 1, 1, 10, 5, 0), "LS", "Učebna", "LS-108", "ls233p02-fdu"));
962
            data.Add(new LogInInstance(new DateTime(2000, 1, 2, 0, 0, 0), 5, 7, new DateTime(2000, 1, 1, 19, 20, 0), new DateTime(2000, 1, 1, 10, 5, 0), "LS", "Učebna", "LS-108", "ls233p02-fdu"));
963

  
964
            Mock<IDataLoader> dl = new Mock<IDataLoader>();
965
            dl.Setup(m => m.LoadLoginFile(path)).Returns(data);
966

  
967
            LogInParser target = new LogInParser(dl.Object);
968
            PrivateObject obj = new PrivateObject(target);
969

  
970
            List<ActivityInfo> retVal = (List<ActivityInfo>)obj.Invoke("ProcessOneLoginFileAsIntervals", path, 2, new DateTime(2000, 1, 1), new DateTime(2001, 1, 1));
971

  
972
            Assert.AreEqual(5, retVal.Count);
973
            Assert.AreEqual(new ActivityInfo("FDU", 2, new DateTime(2000, 1, 1, 9, 0, 0), 2), retVal[0]);
974
            Assert.AreEqual(new ActivityInfo("FEL", 1, new DateTime(2000, 1, 1, 9, 0, 0), 2), retVal[1]);
975
            Assert.AreEqual(new ActivityInfo("FDU", 2, new DateTime(2000, 1, 1, 13, 0, 0), 2), retVal[2]);
976
            Assert.AreEqual(new ActivityInfo("FAV", 5, new DateTime(2000, 1, 1, 13, 0, 0), 2), retVal[3]);
977
            Assert.AreEqual(new ActivityInfo("FDU", 7, new DateTime(2000, 1, 2, 17, 0, 0), 2), retVal[4]);
978
        }
979

  
980
        [TestMethod]
981
        public void ParseLoginHourlyNone()
982
        {
983
            TagInfo.CreateDictionaries();
984

  
985
            string path = "";
986
            List<LogInInstance> data = new List<LogInInstance>();
987
            // "01.06.2019 00:00:00"; 2; 4; "10:15"; "11:00"; "LS"; "Učebna"; "LS-234"; "ls233p02-fdu"
988
            data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 2, 3, new DateTime(2000, 1, 1, 5, 20, 0), new DateTime(2000, 1, 1, 10, 5, 0), "LS", "Učebna", "LS-108", "ls233p02-fdu"));
989
            data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 1, 4, new DateTime(2000, 1, 1, 9, 15, 0), new DateTime(2000, 1, 1, 11, 0, 0), "EL", "Učebna", "UC-108", "uc233p02-fav"));
990

  
991
            data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 2, 6, new DateTime(2000, 1, 1, 19, 0, 0), new DateTime(2000, 1, 1, 10, 5, 0), "LS", "Učebna", "LS-108", "ls233p02-fdu"));
992
            data.Add(new LogInInstance(new DateTime(2000, 1, 1, 0, 0, 0), 5, 7, new DateTime(2000, 1, 1, 19, 20, 0), new DateTime(2000, 1, 1, 10, 5, 0), "UC", "Učebna", "LS-108", "ls233p02-fdu"));
993

  
994
            data.Add(new LogInInstance(new DateTime(2000, 1, 2, 0, 0, 0), 2, 6, new DateTime(2000, 1, 1, 18, 0, 0), new DateTime(2000, 1, 1, 10, 5, 0), "LS", "Učebna", "LS-108", "ls233p02-fdu"));
995
            data.Add(new LogInInstance(new DateTime(2000, 1, 2, 0, 0, 0), 5, 7, new DateTime(2000, 1, 1, 18, 20, 0), new DateTime(2000, 1, 1, 10, 5, 0), "LS", "Učebna", "LS-108", "ls233p02-fdu"));
996

  
997
            Mock<IDataLoader> dl = new Mock<IDataLoader>();
998
            dl.Setup(m => m.LoadLoginFile(path)).Returns(data);
999

  
1000
            LogInParser target = new LogInParser(dl.Object);
1001
            PrivateObject obj = new PrivateObject(target);
1002

  
1003
            List<ActivityInfo> retVal = (List<ActivityInfo>)obj.Invoke("ProcessOneLoginFileAsIntervals", path, 2, new DateTime(2000, 1, 1, 10, 0, 0), new DateTime(2000, 1, 2, 10, 0, 0));
1004

  
1005
            Assert.AreEqual(0, retVal.Count);
1006
        }
1007
        #endregion
1008

  
1009
        #endregion
1010

  
1011
        // -------------------------------- JSON PARSER -----------------------------------------
1012

  
1013
        #region Json parser
1014

  
1015
        [TestMethod]
1016
        public void JsonParser()
1017
        {
1018
            // TODO needs rewrite after DataDownloader has correct download method
1019
            TagInfo.CreateDictionaries();
1020

  
1021
            string data = "";
1022

  
1023
            Mock<DataDownloader> dl = new Mock<DataDownloader>();
1024
            dl.Setup(m => m.DownloadWeatherPrediction()).Returns(data);
1025

  
1026
            JsonParser target = new JsonParser(dl.Object);
1027

  
1028
            target.ParsePrediction();
1029
            WeatherInfo current = target.Current;
1030
            List<WeatherInfo> retVal = target.Predictions;
1031

  
1032
            Assert.AreEqual(8, retVal.Count);
1033
            Assert.AreEqual(new ActivityInfo("FDU", 2, new DateTime(2000, 1, 1, 9, 0, 0), 2), retVal[0]);
1034
            Assert.AreEqual(new ActivityInfo("FEL", 1, new DateTime(2000, 1, 1, 9, 0, 0), 2), retVal[1]);
1035
            Assert.AreEqual(new ActivityInfo("FDU", 2, new DateTime(2000, 1, 1, 13, 0, 0), 2), retVal[2]);
1036
            Assert.AreEqual(new ActivityInfo("FAV", 5, new DateTime(2000, 1, 1, 13, 0, 0), 2), retVal[3]);
1037
            Assert.AreEqual(new ActivityInfo("FDU", 7, new DateTime(2000, 1, 1, 17, 0, 0), 2), retVal[4]);
1038
            Assert.AreEqual(new ActivityInfo("FDU", 7, new DateTime(2000, 1, 1, 17, 0, 0), 2), retVal[5]);
1039
            Assert.AreEqual(new ActivityInfo("FDU", 7, new DateTime(2000, 1, 1, 17, 0, 0), 2), retVal[6]);
1040
            Assert.AreEqual(new ActivityInfo("FDU", 7, new DateTime(2000, 1, 1, 17, 0, 0), 2), retVal[7]);
1041
        }
1042

  
709 1043
        #endregion
710 1044
    }
711 1045
}

Také k dispozici: Unified diff