Пример #1
0
        public IEnumerable <PrecisionCalculation> GetPrecisionReport(GetPrecisionReportQuery query)
        {
            var userLocalizations = this.databaseContext.UserLocalizations
                                    .Where(query.LocaleId, localeId => localization => localization.LocaleId == localeId)
                                    .Where(query.AfterDate, afterDate => localization => localization.DateTime > afterDate)
                                    .Where(query.BeforeDate, beforeDate => localization => localization.DateTime < beforeDate)
                                    .Include(userLocalization => userLocalization.LocalizationMeasurements)
                                    .ToList();

            foreach (var localization in userLocalizations)
            {
                var command = new EstimatePositionCommand()
                {
                    UseDistance             = query.UseDistance,
                    LocaleId                = localization.LocaleId,
                    Measurements            = localization.LocalizationMeasurements !.Select(measurement => new Measurement(measurement)).ToList(),
                    BleWeight               = query.BleWeight,
                    WifiWeight              = query.WifiWeight,
                    MagnetometerWeight      = query.MagnetometerWeight,
                    UnmatchedSignalsWeight  = query.UnmatchedSignalsWeight,
                    StandardDeviationFactor = query.StandardDeviationFactor,
                    Neighbours              = query.Neighbours
                };

                var calculatedPosition = this.positionEstimationService.EstimatePosition(command).Result;

                yield return(new PrecisionCalculation(localization, calculatedPosition));
            }
        }
    }
Пример #2
0
        public void GetPrecisionReportByPosition(
            [FromServices] IReportsService reportsService,
            [FromQuery] GetPrecisionReportQuery query)
        {
            var report = reportsService.GetPrecisionReport(query).ToList()
                         .GroupBy(data => new { X = data.RealX, Y = data.RealY })
                         .Select(position => new
            {
                position.Key.X,
                position.Key.Y,
                Error    = position.Average(position => position.Error),
                MinError = position.Min(position => position.Error),
                MaxError = position.Max(position => position.Error)
            });

            var csvConfiguration = new CsvConfiguration(CultureInfo.InvariantCulture)
            {
            };

            var formattedDate     = DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss");
            var formattedFilename = $"PrecisionPerPosition-{query.LocaleId}-N{query.Neighbours}-USW{query.UnmatchedSignalsWeight}-_{formattedDate}.csv";

            this.HttpContext.Response.StatusCode = 200;
            this.HttpContext.Response.Headers.Add("Content-Type", "text/csv");
            this.HttpContext.Response.Headers.Add("Content-Disposition", $"attachment; filename=\"{formattedFilename}\"");

            var streamWriter = new StreamWriter(
                this.HttpContext.Response.BodyWriter.AsStream());

            using var csvWriter = new CsvWriter(streamWriter, csvConfiguration);

            csvWriter.WriteRecords(report);
        }
Пример #3
0
        public void GetPrecisionReports(
            [FromServices] IReportsService reportsService,
            [FromQuery] GetPrecisionReportQuery query)
        {
            var report = reportsService.GetPrecisionReport(query);

            var csvConfiguration = new CsvConfiguration(CultureInfo.InvariantCulture)
            {
            };

            var formattedDate     = DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss");
            var formattedFilename = $"PrecisionPerLocalization-{query.LocaleId}-N{query.Neighbours}-USW{query.UnmatchedSignalsWeight}-_{formattedDate}.csv";

            this.HttpContext.Response.StatusCode = 200;
            this.HttpContext.Response.Headers.Add("Content-Type", "text/csv");
            this.HttpContext.Response.Headers.Add("Content-Disposition", $"attachment; filename=\"{formattedFilename}\"");

            var streamWriter = new StreamWriter(
                this.HttpContext.Response.BodyWriter.AsStream());

            using var csvWriter = new CsvWriter(streamWriter, csvConfiguration);

            csvWriter.WriteRecords(report);
        }
Пример #4
0
        private IEnumerable <LocaleParameters> EnumerateParametersReport(
            IReportsService reportsService,
            DatabaseContext databaseContext,
            GetParametersReportQuery query)
        {
            for (int neighbours = query.MinNeighbours; neighbours <= query.MaxNeighbours; neighbours += query.NeighboursStep)
            {
                for (double wifiWeight = query.MinWifiWeight; wifiWeight <= query.MaxWifiWeight; wifiWeight += query.WifiWeightStep)
                {
                    for (double bleWeight = query.MinBleWeight; bleWeight <= query.MaxBleWeight; bleWeight += query.BleWeightStep)
                    {
                        for (double magnetometerWeight = query.MinMagnetometerWeight; magnetometerWeight <= query.MaxMagnetometerWeight; magnetometerWeight += query.MagnetometerWeightStep)
                        {
                            for (double unmatchedSignalsWeight = query.MinUnmatchedSignalsWeight; unmatchedSignalsWeight <= query.MaxUnmatchedSignalsWeight; unmatchedSignalsWeight += query.UnmatchedSignalsWeightStep)
                            {
                                for (double standardDeviationFactor = query.MinStandardDeviationFactor; standardDeviationFactor <= query.MaxStandardDeviationFactor; standardDeviationFactor += query.StandardDeviationFactorStep)
                                {
                                    var command = new GetPrecisionReportQuery();
                                    command.LocaleId = query.LocaleId;
                                    command.UnmatchedSignalsWeight = unmatchedSignalsWeight;
                                    command.BleWeight               = bleWeight;
                                    command.WifiWeight              = wifiWeight;
                                    command.Neighbours              = neighbours;
                                    command.MagnetometerWeight      = magnetometerWeight;
                                    command.UseDistance             = query.UseDistance;
                                    command.StandardDeviationFactor = standardDeviationFactor;
                                    var data     = reportsService.GetPrecisionReport(command);
                                    var error    = 0.0;
                                    var n        = 0;
                                    var missings = 0;
                                    foreach (var estimation in data)
                                    {
                                        if (estimation.CalculatedX != 0 && estimation.CalculatedY != 0)
                                        {
                                            error += estimation.Error;
                                            n++;
                                        }
                                        else
                                        {
                                            missings++;
                                        }
                                    }

                                    var parametersAnalysis = new LocaleParameters()
                                    {
                                        LocaleId                = command.LocaleId,
                                        BleWeight               = command.BleWeight,
                                        WifiWeight              = command.WifiWeight,
                                        MagnetometerWeight      = command.MagnetometerWeight,
                                        MeanError               = error / n,
                                        Neighbours              = command.Neighbours,
                                        UnmatchedSignalsWeight  = command.UnmatchedSignalsWeight,
                                        StandardDeviationFactor = command.StandardDeviationFactor,
                                        Missings                = missings,
                                        UseDistance             = command.UseDistance
                                    };

                                    databaseContext.Add(parametersAnalysis);
                                    Console.WriteLine(JsonSerializer.Serialize(parametersAnalysis));

                                    yield return(parametersAnalysis);
                                }
                            }
                        }
                    }
                }

                databaseContext.SaveChanges();
            }
        }