public TemporalSummary CalcSMapMinMaxMean(SMapSensorReading reading)
        {
            TemporalSummary temporalSummary = new TemporalSummary
            {
                MinValue = double.MaxValue,
                MaxValue = double.MinValue,
                MeanValue = 0
            };
            if (reading.Readings.Count > 1)
            {
                DateTime fromTime = dateConverter.ConvertDate((long)reading.Readings[0][0]);
                DateTime toTime = dateConverter.ConvertDate((long)reading.Readings[reading.Readings.Count - 1][0]);
                TimeSpan timeSpan = toTime - fromTime;

                for (int i = 0; i < reading.Readings.Count - 1; i++)
                {
                    List<double> readings = new List<double>();
                    readings.AddRange(reading.Readings[i]);

                    double readingsValue = readings[1];
                    if (temporalSummary.MinValue > readingsValue)
                    {
                        temporalSummary.MinValue = readingsValue;
                    }

                    if (temporalSummary.MaxValue < readingsValue)
                    {
                        temporalSummary.MaxValue = readingsValue;
                    }

                    DateTime time = dateConverter.ConvertDate((long)readings[0]);
                    TimeSpan? timeDif = dateConverter.ConvertDate((long)reading.Readings[i + 1][0]) - time;
                    temporalSummary.MeanValue += readingsValue * (timeDif.Value.TotalSeconds / timeSpan.TotalSeconds);
                }
            }
            else if (reading.Readings.Count == 1)
            {
                double readingsValue = reading.Readings[0][0];
                temporalSummary.MinValue = readingsValue;

                temporalSummary.MaxValue = readingsValue;
                temporalSummary.MeanValue = readingsValue;
            }
            else
            {
                temporalSummary.MaxValue = 0;
                temporalSummary.MinValue = 0;
            }
            return temporalSummary;
        }
        private void CalcSMapMinMaxMeanCase(SMapSensorReading reading, DateTime timeFrom, DateTime timeTo,
            TemporalSummary temporalSummary)
        {
            TimeSpan timeSpan = timeTo - timeFrom;
            double state = reading.Readings[0][1];
            DateTime time = dateConverter.ConvertDate((long)reading.Readings[0][0]);

            temporalSummary.MaxValue = 1;
            temporalSummary.MinValue = 0;

            TimeSpan timeFromStart = time - timeFrom;
            TimeSpan timeToEnd = timeTo - time;

            if (state.Equals(0.0))
            {
                temporalSummary.MeanValue = 1 * (timeFromStart.TotalSeconds / timeSpan.TotalSeconds);
            }

            temporalSummary.MeanValue += state * (timeToEnd.TotalSeconds / timeSpan.TotalSeconds);
        }
        public TemporalSummary CalcSMapMinMaxMean(SMapSensorReading reading, DateTime timeFrom, DateTime timeTo)
        {
            TemporalSummary temporalSummary = new TemporalSummary
            {
                MinValue = double.MaxValue,
                MaxValue = double.MinValue,
                MeanValue = 0
            };
            if (reading.Readings.Count > 1)
            {
                temporalSummary.MaxValue = 1;
                temporalSummary.MinValue = 0;
                TimeSpan timeSpan = timeTo - timeFrom;
                for (int i = 0; i < reading.Readings.Count - 1; i++)
                {
                    DateTime timeCurrent = dateConverter.ConvertDate((long)reading.Readings[i][0]);
                    double state = reading.Readings[i][1];

                    if (i + 1 > reading.Readings.Count)
                    {
                        TimeSpan timeBeetween = timeTo - timeCurrent;
                        temporalSummary.MeanValue += state * (timeBeetween.TotalSeconds / timeSpan.TotalSeconds);
                    }
                    else if (i != 0)
                    {
                        DateTime timeNext = dateConverter.ConvertDate((long)reading.Readings[i + 1][0]);
                        TimeSpan timeBeetween = timeNext - timeCurrent;
                        temporalSummary.MeanValue += state * (timeBeetween.TotalSeconds / timeSpan.TotalSeconds);
                    }
                    else //i = 0
                    {
                        DateTime timeNext = dateConverter.ConvertDate((long)reading.Readings[i + 1][0]);
                        //if state = 0, then all values before was 1
                        if (state.Equals(0.0))
                        {
                            TimeSpan timeFromStart = timeCurrent - timeFrom;
                            temporalSummary.MeanValue += 1 * (timeFromStart.TotalSeconds / timeSpan.TotalSeconds);
                        }
                        else
                        {
                            TimeSpan timeBeetween = timeNext - timeCurrent;
                            temporalSummary.MeanValue += state * (timeBeetween.TotalSeconds / timeSpan.TotalSeconds);

                        }
                    }
                }
            }
            else if (reading.Readings.Count == 1)
            {
                CalcSMapMinMaxMeanCase(reading, timeFrom, timeTo, temporalSummary);
            }
            else
            {
                temporalSummary.MaxValue = 0;
                temporalSummary.MinValue = 0;
            }
            return temporalSummary;
        }