commit fffe7190caca26e39ca494c3ae8848b2109d6c75
Author: A-Konig <alex-nebulae@seznam.cz>
Date:   Wed May 19 12:36:03 2021 +0200

    re #8962 Adding filtering method GetPredictionForTime to json parser + adding attributes with file names to DataParser + fixing bug in json parser method Parse

diff --git a/Server/ServerApp/Parser/Parsers/DataParser.cs b/Server/ServerApp/Parser/Parsers/DataParser.cs
index 24ab8fa..8e98de1 100644
--- a/Server/ServerApp/Parser/Parsers/DataParser.cs
+++ b/Server/ServerApp/Parser/Parsers/DataParser.cs
@@ -82,6 +82,13 @@ namespace ServerApp.Parser.Parsers
             var jisFiles = downloader.GetData(pathJis, start, end);
             var loginFiles = downloader.GetData(pathLogIn, start, end);
 
+            WeatherDataUsed = new List<string>();
+            ActivityDataUsed = new List<string>();
+
+            WeatherDataUsed.AddRange(weatherFiles);
+            ActivityDataUsed.AddRange(jisFiles);
+            ActivityDataUsed.AddRange(loginFiles);
+
             WeatherList = weatherParser.ParseWeatherData(weatherFiles, startTime, endTime, wholeDay, interval);
             jisList = jisParser.ParseJisData(jisFiles, startTime, endTime, wholeDay, interval);
             loginList = loginParser.ParseLogInData(loginFiles, startTime, endTime, wholeDay, interval);
diff --git a/Server/ServerApp/Parser/Parsers/IDataParser.cs b/Server/ServerApp/Parser/Parsers/IDataParser.cs
index ae67a00..886db4c 100644
--- a/Server/ServerApp/Parser/Parsers/IDataParser.cs
+++ b/Server/ServerApp/Parser/Parsers/IDataParser.cs
@@ -21,6 +21,15 @@ namespace ServerApp.Parser.Parsers
         List<ActivityInfo> attendanceList;
         public List<ActivityInfo> AttendanceList { get => attendanceList; internal set => attendanceList = value; }
 
+        /// <summary> List of weather file names the parser was last used on </summary>
+        List<String> weatherdataUsed;
+        public List<string> WeatherDataUsed { get => weatherdataUsed; set => weatherdataUsed = value; }
+
+        /// <summary> List of activity file names the parser was last used on </summary>
+        List<String> activitydataUsed;
+        public List<string> ActivityDataUsed { get => activitydataUsed; set => activitydataUsed = value; }
+
+
         /// <summary>
         /// Parse data
         /// </summary>
diff --git a/Server/ServerApp/Program.cs b/Server/ServerApp/Program.cs
index 145f31b..b935858 100644
--- a/Server/ServerApp/Program.cs
+++ b/Server/ServerApp/Program.cs
@@ -1,6 +1,7 @@
 ﻿using ServerApp.Connection;
 using ServerApp.Connection.XMLProtocolHandler;
 using ServerApp.DataDownload;
+using ServerApp.Parser.OutputInfo;
 using ServerApp.Parser.Parsers;
 using ServerApp.Predictor;
 using ServerApp.User;
@@ -136,6 +137,13 @@ namespace ServerApp
             JsonParser jsonP = new JsonParser(null);
 			jsonP.ParsePrediction();
 
+			var res = jsonP.GetPredictionForTime(jsonP.Predictions[5].startTime, jsonP.Predictions[20].startTime);
+			Console.WriteLine("from " + jsonP.Predictions[5].startTime);
+			Console.WriteLine("end " + jsonP.Predictions[20].startTime);
+			foreach (WeatherInfo w in res)
+				Console.WriteLine(w.ToString());
+
+
 			// TODO nastavit čas
 			IDataParser p = new DataParser(dd);
             IPredictionController predictionController = new PredictionController(p);
diff --git a/Server/ServerApp/WeatherPredictionParser/IJsonParser.cs b/Server/ServerApp/WeatherPredictionParser/IJsonParser.cs
index 31c8058..3f34437 100644
--- a/Server/ServerApp/WeatherPredictionParser/IJsonParser.cs
+++ b/Server/ServerApp/WeatherPredictionParser/IJsonParser.cs
@@ -3,6 +3,7 @@
 //
 
 using ServerApp.Parser.OutputInfo;
+using System;
 using System.Collections.Generic;
 
 namespace ServerApp.WeatherPredictionParser
@@ -15,7 +16,7 @@ namespace ServerApp.WeatherPredictionParser
 
         /// <summary> Current weather </summary>
         WeatherInfo current;
-        public WeatherInfo Current { get => current; }
+        public WeatherInfo Current { get => current; set => current = value; }
 
         /// <summary> Prediction for today, tommorrow and day after tommorrow </summary>
         List<WeatherInfo> predictions;
@@ -27,6 +28,14 @@ namespace ServerApp.WeatherPredictionParser
         /// </summary>
         abstract public void ParsePrediction();
 
+        /// <summary>
+        /// Get predictions from Predictions that are within specified time span
+        /// </summary>
+        /// <param name="from">DateTime from</param>
+        /// <param name="to">DateTime to</param>
+        /// <returns>List of predictions that fit specified criteria</returns>
+        abstract public List<WeatherInfo> GetPredictionForTime(DateTime from, DateTime to);
+
     }
 
 }
diff --git a/Server/ServerApp/WeatherPredictionParser/JsonParser.cs b/Server/ServerApp/WeatherPredictionParser/JsonParser.cs
index 45b912b..a20349b 100644
--- a/Server/ServerApp/WeatherPredictionParser/JsonParser.cs
+++ b/Server/ServerApp/WeatherPredictionParser/JsonParser.cs
@@ -20,13 +20,6 @@ namespace ServerApp.WeatherPredictionParser
     /// <author>A. Konig</author>
     class JsonParser : IJsonParser
     {
-        /// <summary> Current weather </summary>
-        WeatherInfo current;
-        public new WeatherInfo Current { get => current; }
-        /// <summary> Prediction for today, tommorrow and day after tommorrow </summary>
-        List<WeatherInfo> predictions;
-        public new List<WeatherInfo> Predictions { get => predictions; set => predictions = value; }
-
         /// <summary> Data loader </summary>
         DataDownloader loader;
         /// <summary> Currently parsed day </summary>
@@ -46,6 +39,53 @@ namespace ServerApp.WeatherPredictionParser
             this.loader = loader;
         }
 
+        /// <summary>
+        /// Get predictions from Predictions that are within specified time span
+        /// From-to including
+        /// If from == null then all until to
+        /// If to  == null then all starting from from
+        /// </summary>
+        /// <param name="from">DateTime from</param>
+        /// <param name="to">DateTime to</param>
+        /// <returns>List of predictions that fit specified criteria or null if incorrect input</returns>
+        public override List<WeatherInfo> GetPredictionForTime(DateTime from, DateTime to)
+        {
+            if (Predictions == null)
+                return null;
+
+            List<WeatherInfo> res = new List<WeatherInfo>();
+
+            if (from == null)
+                from = Predictions[0].startTime;
+
+            if (to == null)
+                from = Predictions[Predictions.Count].startTime;
+
+            if (from > to)
+                return null;
+
+            foreach (WeatherInfo pred in Predictions)
+            {
+                int hour = pred.startTime.Hour + pred.intervalLength;
+                Console.WriteLine(pred.intervalLength);
+                bool addDay = false;
+                if (hour >= 24)
+                {
+                    hour -= 24;
+                    addDay = true;
+                }
+                DateTime endTime = new DateTime(pred.startTime.Year, pred.startTime.Month, pred.startTime.Day, hour, pred.startTime.Minute, pred.startTime.Second);
+                if (addDay)
+                    endTime = endTime.AddDays(1);
+
+                // if both end and start not outside of interval
+                if (!((pred.startTime < from && endTime <= from) || (pred.startTime > to && endTime >= to)))
+                    res.Add(pred);
+            }
+
+            return res;
+        }
+
         /// <summary>
         /// Parse weather prediction
         /// Results is in attributes current for current weather and pred for weather prediction for today, tommorrow and day after tommorrow
@@ -59,8 +99,8 @@ namespace ServerApp.WeatherPredictionParser
             DateTime now = DateTime.Now;
             Console.WriteLine(File.Exists(file));
 
-            current = new WeatherInfo();
-            predictions = new List<WeatherInfo>();
+            Current = new WeatherInfo();
+            Predictions = new List<WeatherInfo>();
 
             if (!File.Exists(file))
                 return;
@@ -84,7 +124,7 @@ namespace ServerApp.WeatherPredictionParser
                     case "current_condition":
                         {
                             ArrayEnumerator currentWeather = weatherP.Current.Value.EnumerateArray();
-                            current = ParseCurrentWeather(currentWeather);
+                            Current = ParseCurrentWeather(currentWeather);
 
                             break;
                         }
@@ -110,8 +150,8 @@ namespace ServerApp.WeatherPredictionParser
         /// </summary>
         private void TestConsoleOutput()
         {
-            Console.WriteLine(current);
-            foreach (WeatherInfo w in predictions)
+            Console.WriteLine(Current);
+            foreach (WeatherInfo w in Predictions)
                 Console.WriteLine(w);
         }
 
@@ -137,14 +177,14 @@ namespace ServerApp.WeatherPredictionParser
         private void EncompassSunRiseSetTimes()
         {
             // change current weather
-            if ((current.startTime.TimeOfDay > sunsetTime.TimeOfDay) || (current.startTime.TimeOfDay < sunriseTime.TimeOfDay))
-                current.condition = WeatherConditions.Dark;
+            if ((Current.startTime.TimeOfDay > sunsetTime.TimeOfDay) || (Current.startTime.TimeOfDay < sunriseTime.TimeOfDay))
+                Current.condition = WeatherConditions.Dark;
 
             // change prediction
-            for (int i = 0; i < predictions.Count - 1; i++)
+            for (int i = 0; i < Predictions.Count - 1; i++)
             {
-                WeatherInfo w = predictions[i];
-                WeatherInfo wNext = predictions[i + 1];
+                WeatherInfo w = Predictions[i];
+                WeatherInfo wNext = Predictions[i + 1];
 
                 // if wNext time < than w time then it is prediction from the next day -> add 24 to correctly calculate timespan
                 int timespan = wNext.startTime.Hour - w.startTime.Hour;
@@ -178,9 +218,9 @@ namespace ServerApp.WeatherPredictionParser
             }
 
             // last prediction
-            WeatherInfo wLast = predictions[predictions.Count - 1];
+            WeatherInfo wLast = Predictions[Predictions.Count - 1];
             TimeSpan endTimeW = new TimeSpan(24, 0, 0);
-            int timespanLast = endTimeW.Hours - wLast.startTime.Hour;
+            int timespanLast = 24 - wLast.startTime.Hour;
             wLast.intervalLength = timespanLast;
 
             // if start under sunset
@@ -338,7 +378,7 @@ namespace ServerApp.WeatherPredictionParser
                 }
 
                 // Console.WriteLine(weather.ToString());
-                predictions.Add(weather);
+                Predictions.Add(weather);
 
             }
 
@@ -401,5 +441,6 @@ namespace ServerApp.WeatherPredictionParser
             return res;
         }
 
+      
     }
 }
