private static StringBuilder MakeReport(List <Location> data)
        {
            var builder = new StringBuilder();

            builder.AppendLine("Latitude;Longitude;Accuary;Error;DetectionTime;SaveTime;Flag;");
            var lastKnownLocation = data.FirstOrDefault();

            foreach (var location in data)
            {
                var flag = Flags.K;

                if (location.Error)
                {
                    flag = Flags.E;
                }

                if (location.Accuary > 100)
                {
                    flag = Flags.U;
                }

                if (DataManipulationHelper.IsTwoLocationSame(lastKnownLocation, location))
                {
                    flag = Flags.F;
                }

                int miss = (location.SaveTime - lastKnownLocation.SaveTime).Minutes - 1;

                if (miss >= 1)
                {
                    flag = Flags.M;
                }

                if (DataManipulationHelper.DistanceBetweenLocations(lastKnownLocation, location) > 500)
                {
                    flag = Flags.J;
                }

                string strFlag = flag +
                                 (miss >= 1 ? miss.ToString() : string.Empty);

                builder.AppendFormat(
                    "{0};{1};{2};{3};{4:yyyy-MM-dd HH:mm:ss};{5:yyyy-MM-dd HH:mm};{6};{7}",
                    location.Latitude,
                    location.Longitude,
                    location.Accuary,
                    location.Error,
                    location.DetectionTime,
                    location.SaveTime,
                    strFlag,
                    Environment.NewLine);

                lastKnownLocation = location;
            }
            return(builder);
        }
        private static List <Location> MakeMergedResult(List <Location> data, Fill fillType)
        {
            List <Location> result;

            switch (fillType)
            {
            case Fill.LastData:
                result = DataManipulationHelper.FillErrorsWithLastData(data);
                break;

            case Fill.LinearInterpolation:
                result = DataManipulationHelper.FillErrorsWithLinearInterpolation(data);
                break;

            default:
                result = data;
                break;
            }
            return(result);
        }
        public static string  GetSummary(IService service, int ellapsedDays, DateTime from)
        {
            var builder       = new StringBuilder();
            int samplesNeeded = ellapsedDays * 1440 + Convert.ToInt32(DateTime.Now.TimeOfDay.TotalMinutes);

            int toleranceLimit = Convert.ToInt32(samplesNeeded * 0.8);
            int minimumSamples = Convert.ToInt32(samplesNeeded * 0.5);
            var userNames      = service.GetUserNames().OrderBy(s => s);

            foreach (string userName in userNames)
            {
                string userId          = service.GetUserId(userName);
                var    ienumerableData = service.GetLocations(userId, from, null).ToList();
                int    count           = ienumerableData.Count();

                if (count >= toleranceLimit) // 0.8 -
                {
                    builder.AppendFormat(
                        "{0} : {1} of {2} row, within the tolerance {3}",
                        userName,
                        count,
                        samplesNeeded,
                        Environment.NewLine);
                }
                else if (count < minimumSamples) // 0 - 0.5
                {
                    builder.AppendFormat(
                        "{0} : {1} of {2} row, out of tolerance {3}",
                        userName,
                        count,
                        samplesNeeded,
                        Environment.NewLine);
                }
                else // 0.5 - 0.8
                {
                    var  lastKnownLocation = new Location();
                    bool isError           = false;
                    bool sameTheTwoWall    = true;

                    foreach (var location in ienumerableData)
                    {
                        if (!location.Error && location.Accuary < 100 &&
                            !DataManipulationHelper.IsTwoLocationSame(lastKnownLocation, location))
                        {
                            if (isError)
                            {
                                if (DataManipulationHelper.DistanceBetweenLocations(lastKnownLocation, location) > 500)
                                {
                                    sameTheTwoWall = false;
                                }
                            }

                            lastKnownLocation = location;
                            isError           = false;
                        }
                        else
                        {
                            isError = true;
                        }
                    }

                    builder.AppendFormat(
                        sameTheTwoWall
                            ? "{0} : {1} of {2} row, can we fill it {3}"
                            : "{0} : {1} of {2} row, need to interpolate {3}",
                        userName,
                        count,
                        samplesNeeded,
                        Environment.NewLine);
                }
            }

            return(builder.ToString());
        }