diff --git a/CentralHub.Api.Tests/MeasurementControllerTests.cs b/CentralHub.Api.Tests/MeasurementControllerTests.cs index 9e68536..6b14dc0 100644 --- a/CentralHub.Api.Tests/MeasurementControllerTests.cs +++ b/CentralHub.Api.Tests/MeasurementControllerTests.cs @@ -100,34 +100,4 @@ public async Task TrackersFilteredFromMeasurements() Assert.That(addedMeasurements, Has.Count.EqualTo(0)); } - - [Test] - public async Task CalibrateMeasurements() - { - var measurements = new Measurement[] { - new Measurement("12:22:33:44:55:66", Measurement.Protocol.Bluetooth, 10), - new Measurement("ab:bb:cc:dd:ee:ff", Measurement.Protocol.Wifi, 20) - }; - - var addMeasurementsRequest = new AddMeasurementsRequest(_trackerId, measurements); - await _measurementController.AddMeasurements(addMeasurementsRequest, default); - - await _localizationService.AggregateMeasurementsAsync(default); - - var measurements3 = new Measurement[] { - new Measurement("13:22:33:44:55:66", Measurement.Protocol.Bluetooth, 10), - new Measurement("ac:bb:cc:dd:ee:ff", Measurement.Protocol.Wifi, 20), - new Measurement("14:22:33:44:55:66", Measurement.Protocol.Bluetooth, 10), - new Measurement("ab:bb:cc:dd:ee:ff", Measurement.Protocol.Wifi, 20) - }; - - var addMeasurementsRequest3 = new AddMeasurementsRequest(_trackerId, measurements3); - await _measurementController.AddMeasurements(addMeasurementsRequest3, default); - await _localizationService.AggregateMeasurementsAsync(default); - - var lastAggregatedMeasurements = (await _measurementController.GetAggregateMeasurements(_roomId, default)).AggregatedMeasurements.Last(); - - Assert.That(lastAggregatedMeasurements.BluetoothCount, Is.EqualTo(1)); - Assert.That(lastAggregatedMeasurements.WifiCount, Is.EqualTo(1)); - } } \ No newline at end of file diff --git a/CentralHub.Api/Controllers/MeasurementController.cs b/CentralHub.Api/Controllers/MeasurementController.cs index 8810a37..47f420b 100644 --- a/CentralHub.Api/Controllers/MeasurementController.cs +++ b/CentralHub.Api/Controllers/MeasurementController.cs @@ -138,19 +138,12 @@ await _occupancySettings.Lock(os => private static IReadOnlyList CreateMeasurements(IEnumerable aggregatedMeasurements) { - var recentAggregatedMeasurements = aggregatedMeasurements - .Where(am => am.EndTime > (DateTime.UtcNow - TimeSpan.FromDays(1))) - .ToImmutableArray(); - - var bluetoothCalibrationNumber = recentAggregatedMeasurements.Min(am => am.BluetoothCount); - var wifiCalibrationNumber = recentAggregatedMeasurements.Min(am => am.WifiCount); - return aggregatedMeasurements.Select(am => new AggregatedMeasurements( am.AggregatedMeasurementDtoId, am.StartTime, am.EndTime, - am.BluetoothCount - bluetoothCalibrationNumber, - am.WifiCount - wifiCalibrationNumber) + am.BluetoothCount, + am.WifiCount) ).ToImmutableArray(); } diff --git a/CentralHub.Api/Services/TrackerRepository.cs b/CentralHub.Api/Services/TrackerRepository.cs index 6a57ead..9478929 100644 --- a/CentralHub.Api/Services/TrackerRepository.cs +++ b/CentralHub.Api/Services/TrackerRepository.cs @@ -110,6 +110,16 @@ public async Task RemoveTrackerAsync(TrackerDto trackerDto, CancellationToken ca } room.Trackers.Remove(trackerDto); + var unregisteredTracker = await UnregisteredTrackersMutex.Lock(unregisteredTrackers => + { + var unregisteredTracker = new UnregisteredTrackerDto() + { + BluetoothMacAddress = trackerDto.BluetoothMacAddress, + WifiMacAddress = trackerDto.WifiMacAddress, + }; + unregisteredTrackers.Add(unregisteredTracker); + return unregisteredTracker; + }, cancellationToken); _applicationDbContext.Rooms.Update(room); try { @@ -120,6 +130,10 @@ public async Task RemoveTrackerAsync(TrackerDto trackerDto, CancellationToken ca // Set the roomDto to unchanged _applicationDbContext.Rooms.Attach(room).State = EntityState.Unchanged; room.Trackers.Add(trackerDto); + await UnregisteredTrackersMutex.Lock(unregisteredTrackers => + { + unregisteredTrackers.Remove(unregisteredTracker); + }, cancellationToken); throw; } }