microsoft/Bing-Maps-Fleet-Tracker

Geofence Reports are empty

wvmstr opened this issue · 10 comments

I have one asset that has triggered a geofence condition several times. The emails were sent out.

What functions/tables are involved in making this report functionality work?

You mean the emails are being sent out but the reports are not counting the triggers correctly?

There is no data in the report. If you tell me what tables are involved then I can tell you if it is a matter of not adding correctly or a matter of not having data to count.

friendly reminder

I investigated this issue, and it was a regression caused by a change in the way GeofenceUpdates work, introduced in #6.

There is no easy fix for this, as reverting this change would cause significant performance issues in some cases. The proper solution is for the reports feature to be reworked to rely on aggregation tables instead of on the fly calculations.

If you are interested in contributing with this rework, I can share pointers with you on where to start.

I might be interested in taking a look. Can you PM me with details?

Friendly reminder.

Hi,

The current logic creating the reports can be found in Trackable.Services/Services/ReportingService.cs. This logic aggregates the data on the fly and returns that to the portal to display. This becomes ridiculously slow once you have a dozen or so assets and a few weeks worth of data, so we will need to change the way this works. This goes hand in hand with the fix for the geofences report, as the solution to both issues is the same: creating separate tables in the database that include aggregate counts.

A short article outlining what aggregate tables are can be found here. For the trips and points based reports, we should run a recurring job (see HostedInstrumentationService.cs and HostedServiceBase.cs as an example for how to schedule a job in ASP.Net Core 2) that aggregates the data from the real table, and stores the aggregated results in the aggregate tables which you will create. You can then modify the Trackable.Services/Services/ReportingService.cs to read from the aggregate tables you created, instead of re-aggregating for every request. This will also allow us to generate more powerful reports such as points per asset per day or the like.

For the geofence triggering reports, you will also create an aggregate table, however the aggregation logic cannot be done with a recurring job like the others. This is because we only store the latest GeoFenceUpdate in the database for performance reasons. The GeoFenceUpdates table is where we keep track of which Geofences have been triggered by each asset. Instead, you will need to modify the logic in the HandlePoints function in the Trackable.Services/Services/GeoFenceService.cs to write to the aggregate table (along with the original GeoFenceUpdates table) when updating the status for the triggered geofence/asset.

If you want to ask any further questions feel free to PM me or @momohs directly.

You can find my email on my profile.

I'll close this issue for now, please feel free to reopen/start a new one if more questions/issues pop up.