e-mission / e-mission-docs

Repository for docs and issues. If you need help, please file an issue here. Public conversations are better for open source projects than private email.
https://e-mission.readthedocs.io/en/latest
BSD 3-Clause "New" or "Revised" License
15 stars 34 forks source link

🐛 `background/bluetooth_ble` entries disappear once they get to the server #1067

Closed JGreenlee closed 7 months ago

JGreenlee commented 7 months ago

I have yet to see a trip show up on my iPhone, which is what I'm testing dfc-fermata on. As far as I could tell, the state remained in ONGOING_TRIP the entire time I was away from home, even when I went into the store and my beacon was still in my car. Only when I got home and went inside (leaving the beacon in my car) did it transition and now says WAITING_FOR_TRIP_START.

So, I thought that a very long draft trip would show up, but I don't see one

Logs on the phone showed that there were bluetooth_ble entries (a LOT of them). Evidently, they weren't synced because when I logged into that opcode from an emulator and queried for them, there were none

Now they are gone from the phone, and seemingly gone forever


May be due to:

2024-04-16 00:21:03,698:WARNING:140347683919680:Got error No module named 'emission.net.usercache.formatters.ios.bluetooth_ble' while saving entry AttrDict({'_id': ObjectId('661db723610916071b576ed5'), 'user_id': UUID('4acedfd2-de6a-4623-a968-9d5046a8573b'), 'metadata': {'time_zone': 'America/New_York', 'plugin': 'none', 'write_ts': 1713216469.099677, 'platform': 'ios', 'read_ts': 0, 'key': 'background/bluetooth_ble', 'type': 'sensor-data'}, 'data': {'major': 57280, 'minor': 65520, 'rssi': -84, 'eventType': 'RANGE_UPDATE', 'ts': 1713216469.097594, 'uuid': 'BF3DF3B1-6E46-35FA-86E5-927C95DD096C', 'proximity': 'ProximityFar', 'accuracy': 22.76727203664656}}) -> None
the-bay-kay commented 7 months ago

This is the line that stores the bluetooth region data into the BuiltinUserCache on iOS. As we can see from the following logs...

image

We are at the very least successfully receiving notifications via didRangeBeacons, which lends itself to the theory that this may be an issue with the phone-server communication.

Link to the BEMUserCache code here, specifically putSensorData

shankari commented 7 months ago

This is because the server for this deployment had not yet been updated

$ ./e-mission-py.bash
>>> edb.get_timeseries_error_db().distinct("metadata.key")
['statemachine/transition', 'background/bluetooth_ble']

So the timeseries_error DB has the transition and ble entries

>>> edb.get_timeseries_error_db().distinct("user_id")
[UUID('118bcfb4-19b1-4d92-b02e-7d5bfc1d6032'), UUID('c8e6ad49-c7a5-4650-b1ad-c61747c761fe'), UUID('170c02b7-5937-4227-9128-5da1bcdfe8c6'), UUID('97b8efad-8c28-4ffa-870b-828de7a1cb03'), UUID('29627e30-ca62-494e-af8c-b9de8e8f0f89'), UUID('e61c0e74-82db-42aa-b3ea-ba07392efcd2'), UUID('11fc1417-0776-47fc-b306-5484c34f6138'), UUID('dfa77402-da79-4e39-9c64-7bebd1f8b410'), UUID('50fcffc9-16c7-4153-a548-1ffb3f6c379a'), UUID('519df704-2f64-400d-b84e-df6e6143dae0'), UUID('629e97a4-601a-4954-80a6-ce3c0bca5579'), UUID('10fd95ea-5065-4e1d-a861-30dc80590bbf'), UUID('4acedfd2-de6a-4623-a968-9d5046a8573b')]

And after fixing them, we may need to reset the pipeline for these users

shankari commented 7 months ago

Ran the script, everything is copied over, no errors left.

>>> edb.get_timeseries_error_db().distinct("metadata.key")
[]

Now resetting the pipeline, and re-running it for at least the ones that have BLE beacons. These are the users we will re-run the pipeline for

>>> edb.get_usercache_db().find({"metadata.key": "background/bluetooth_ble"}).distinct("user_id")
[UUID('c8e6ad49-c7a5-4650-b1ad-c61747c761fe'), UUID('11fc1417-0776-47fc-b306-5484c34f6138'), UUID('629e97a4-601a-4954-80a6-ce3c0bca5579'), UUID('dfa77402-da79-4e39-9c64-7bebd1f8b410'), UUID('10fd95ea-5065-4e1d-a861-30dc80590bbf'), UUID('4acedfd2-de6a-4623-a968-9d5046a8573b')]
shankari commented 7 months ago

Reset pipelines for 13 users. Some of them were only the None transition errors. 6 users had BLE beacon information, manually ran the pipeline for them

One of them had obsolete transitions which we are not going to fix

Got error 'T_ENTERED_BLE_RANGE' while saving entry AttrDict({'_id': ObjectId('661b29806109164d65102979'), 'user_id': UUID('dfa77402-da79-4e39-9c64-7bebd1f8b410'), 'metadata': {'time_zone': 'America/Los_Angeles', 'plugin': 'none', 'write_ts': 1713041202.864598, 'platform': 'ios', 'read_ts': 0, 'key': 'statemachine/transition', 'type': 'message'}, 'data': {'currState': 'STATE_ONGOING_TRIP', 'transition': 'T_ENTERED_BLE_RANGE', 'ts': 1713041202.86425}}) -> None
Got error 'T_ENTERED_BLE_RANGE' while saving entry AttrDict({'_id': ObjectId('661b29806109164d6510297b'), 'user_id': UUID('dfa77402-da79-4e39-9c64-7bebd1f8b410'), 'metadata': {'time_zone': 'America/Los_Angeles', 'plugin': 'none', 'write_ts': 1713041203.863857, 'platform': 'ios', 'read_ts': 0, 'key': 'statemachine/transition', 'type': 'message'}, 'data': {'currState': 'STATE_ONGOING_TRIP', 'transition': 'T_ENTERED_BLE_RANGE', 'ts': 1713041203.863525}}) -> None
Got error 'T_ENTERED_BLE_RANGE' while saving entry AttrDict({'_id': ObjectId('661b29806109164d6510297d'), 'user_id': UUID('dfa77402-da79-4e39-9c64-7bebd1f8b410'), 'metadata': {'time_zone': 'America/Los_Angeles', 'plugin': 'none', 'write_ts': 1713041204.864588, 'platform': 'ios', 'read_ts': 0, 'key': 'statemachine/transition', 'type': 'message'}, 'data': {'currState': 'STATE_ONGOING_TRIP', 'transition': 'T_ENTERED_BLE_RANGE', 'ts': 1713041204.864253}}) -> None

A second user had ill-formatted entries, which we are also not going to fix

Got error 'AttrDict' instance has no attribute 'currState' while saving entry AttrDict({'_id': ObjectId('661d4ae161091667901a055e'), 'user_id': UUID('4acedfd2-de6a-4623-a968-9d5046a8573b'), 'metadata': {'time_zone': 'America/New_York', 'plugin': 'none', 'write_ts': 1713195745.456911, 'platform': 'ios', 'read_ts': 0, 'key': 'statemachine/transition', 'type': 'message'}, 'data': {'curr_state': 'STATE_ONGOING_TRIP', 'transition': 'T_TRIP_ENDED', 'ts': 1713195745.455}}) -> None
Got error 'AttrDict' instance has no attribute 'currState' while saving entry AttrDict({'_id': ObjectId('661d5fca61091667901a1fe4'), 'user_id': UUID('4acedfd2-de6a-4623-a968-9d5046a8573b'), 'metadata': {'time_zone': 'America/New_York', 'plugin': 'none', 'write_ts': 1713201068.700629, 'platform': 'ios', 'read_ts': 0, 'key': 'statemachine/transition', 'type': 'message'}, 'data': {'curr_state': 'STATE_ONGOING_TRIP', 'transition': 'T_EXITED_GEOFENCE', 'ts': 1713201068.698}}) -> None
JGreenlee commented 7 months ago

No vehicle identity found for major:minor pair 0000:0000


I am pretty sure this is from old simulated entries, before https://github.com/e-mission/e-mission-data-collection/pull/223, where major and minor were not filled in correctly

JGreenlee commented 7 months ago

After dismissing that popup (for me, there were 5 of them), it looks to be working!

Recent trips I've taken, when the beacon was with me, are recognized as "Jack's Mazda 3" and prompt for "Gas Car Survey"

Older trips, where the beacon not with me, just show "Detected" modes and don't prompt for any survey

shankari commented 7 months ago

I can delete those (this is all test data, so I have no qualms about mucking around with it). Let me do that now.

shankari commented 7 months ago

There are 127 of these spurious entries. Deleting them...

>>> edb.get_timeseries_db().count_documents({"metadata.key": "background/bluetooth_ble", "data.major": 0, "data.minor": 0})
127

>>> edb.get_timeseries_db().delete_many({"metadata.key": "background/bluetooth_ble", "data.major": 0, "data.minor": 0})
<pymongo.results.DeleteResult object at 0x7f38ea0dabb0>
>>> edb.get_timeseries_db().count_documents({"metadata.key": "background/bluetooth_ble", "data.major": 0, "data.minor": 0})
0

Done.

JGreenlee commented 7 months ago

Resolved by server upgrade and manually deleting the bad entries