Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand the profile screen to simulate bluetooth actions separately and handle them properly in the native code #1144

Merged
merged 7 commits into from
Apr 28, 2024

Conversation

shankari
Copy link
Contributor

No description provided.

@shankari shankari marked this pull request as draft April 11, 2024 16:50
@shankari
Copy link
Contributor Author

Starting Enter Range Exit
simulator_screenshot_CB7DC2EF-9371-4AFD-945C-CC50C51F5F97 simulator_screenshot_483D6789-53CF-477B-BAAD-8AA5BF41CB08 simulator_screenshot_744D1931-0BF2-4656-AA15-353883DAE8DC simulator_screenshot_EBA0962C-533A-441D-9F38-BEDF741E458F

@shankari
Copy link
Contributor Author

@shankari
Copy link
Contributor Author

Start scan Range Range Beacon found Beacon lost when stopped scan
simulator_screenshot_4F803D64-77EF-4A92-8F49-F26D55ED8ABA simulator_screenshot_32E9C38A-35E5-4FB5-8F65-ABBDE57F8404 simulator_screenshot_3BC7F2AC-9D69-4C2C-BF5F-7DCF8F04251F simulator_screenshot_754EC0AD-968D-47DD-85ED-A0D4A2F43DE8 simulator_screenshot_36BBF855-2438-4DF7-BDBB-C70DB8B07262

@shankari
Copy link
Contributor Author

shankari commented Apr 12, 2024

@JGreenlee @the-bay-kay @louisg1337 here are initial native code changes and templates to save entries and simulate transitions through the UI

@JGreenlee you should be able to use this to fill in the matching and conditional surveys for the draft trips
@the-bay-kay and @louisg1337 you should save similar entries into the usercache from your code so that the code that @JGreenlee writes can read them and populate the surveys accordingly

I still have some examples of reading and writing objects from the native code coming up, but need to go to meetings for a bit.

NOTE: The geofence exit simulator does not currently work; that is also upcoming

@JGreenlee
Copy link
Collaborator

@JGreenlee you should be able to use this to fill in the matching and conditional surveys for the draft trips

I have been working on this yesterday and today. I will get as far on it as I can today / this weekend. However, I don't have a lot of time to work on it this weekend.

@JGreenlee
Copy link
Collaborator

Draft PR is up at #1145

I think it might be done, but I don't have time today to test it with the "simulation" UI

@shankari
Copy link
Contributor Author

Hack to test native read and write

Android:

+        if (actionString.equals(ctxt.getString(R.string.transition_ble_beacon_found))) {
+            BluetoothBLE enterWrapper = BluetoothBLE.initFakeWithEventType("REGION_ENTER");
+            UserCacheFactory.getUserCache(ctxt).putSensorData(R.string.key_usercache_bluetooth_ble, enterWrapper);
+
+            for (int i = 0; i < 5; i++) {
+                BluetoothBLE rangeWrapper = BluetoothBLE.initFakeWithEventType("RANGE_UPDATE");
+                UserCacheFactory.getUserCache(ctxt).putSensorData(R.string.key_usercache_bluetooth_ble, rangeWrapper);
+            }
+
+            BluetoothBLE[] currentEntries = UserCacheFactory.getUserCache(ctxt).getLastSensorData(R.string.key_usercache_bluetooth_ble, 5, BluetoothBLE.class);
+            System.out.println("[BLE native] Found "+ currentEntries.length+" entries");
+            System.out.println("[BLE native] First entry is "+ currentEntries[0]+" last entry is "+currentEntries[currentEntries.length -1]);
+            System.out.println("[BLE native] while handling transition " + actionString);
+        }
+

iOS:

+    // HACK to test read and write in the native code
+    // Should be removed when we read and write directly from the service
+    if ([transition isEqualToString:CFCTransitionBeaconFound]) {
+        BluetoothBLE* enterWrapper = [[BluetoothBLE new] initFakeWithEventType:@"REGION_ENTER"];
+        [[BuiltinUserCache database] putSensorData:@"key.usercache.bluetooth_ble" value:enterWrapper];
+
+        for (int i = 0; i < 5; i++) {
+            BluetoothBLE* rangeWrapper = [[BluetoothBLE new] initFakeWithEventType:@"RANGE_UPDATE"];
+            [[BuiltinUserCache database] putSensorData:@"key.usercache.bluetooth_ble" value:rangeWrapper];
+        }
+
+        NSArray* currentEntries = [[BuiltinUserCache database] getLastSensorData:@"key.usercache.bluetooth_ble" nEntries:5 wrapperClass:BluetoothBLE.class];
+        NSLog(@"[BLE native] Found %lu entries", currentEntries.count);
+        NSLog(@"[BLE native] First entry is %@, last entry is %@", currentEntries[0], currentEntries[currentEntries.count-1]);
+        NSLog(@"[BLE native] while handling transition %@", transition);
+    }
+

Full patch:
hack-to-test-native-read-write.patch

shankari added a commit to shankari/e-mission-data-collection that referenced this pull request Apr 13, 2024
…etooth code

The data format is very similar to the beacon object in iOS.

We consciously patterned the object to be similar to `CLBeacon` since the
alt-beacon library for android is an effort to be compatible with iOS to the
extent possible.

Our only changes are to change the fields in iOS to be more easily serializable
e-mission/e-mission-docs#1062 (comment)
e-mission/e-mission-docs#1062 (comment)

Testing done:
After adding a hack to read/write messages on every ble_found transition,
e-mission/e-mission-phone#1144 (comment)
was able to verify that both read and write worked properly

Android:

```
sqlite> select * from userCache where type == "sensor-data";
1713026512.887||America/Los_Angeles|sensor-data|background/battery||{"android_health":"GOOD","android_plugged":"UNKNOWN","android_technology":"Li-ion","android_temperature":250,"android_voltage":250,"battery_level_pct":100.0,"battery_status":4,"ts":1.713026512887E9}
```

```
04-13 09:45:21.365 18332 18332 I TripDiaryStateMachineRcvr: TripDiaryStateMachineReciever onReceive(android.app.ReceiverRestrictedContext@9e3bd75, Intent { act=local.transition.ble_beacon_found flg=0x10 pkg=edu.berkeley.eecs.emission cmp=edu.berkeley.eecs.emission/.cordova.tracker.location.TripDiaryStateMachineReceiver }) called
04-13 09:45:21.385 18332 18332 I TripDiaryStateMachineService: Service created. Initializing one-time variables!
04-13 09:45:21.396 18332 18332 D TripDiaryStateMachineService: service started with flags = 0 startId = 1 action = local.transition.ble_beacon_found
04-13 09:45:21.404 18332 18332 D TripDiaryStateMachineService: after reading from the prefs, the current state is local.state.waiting_for_trip_start
04-13 09:45:21.424 18332 18332 D BuiltinUserCache: Added value for key statemachine/transition at time 1.713026721405E9
04-13 09:45:21.432 18332 18332 D TripDiaryStateMachineService: handleAction(local.state.waiting_for_trip_start, local.transition.ble_beacon_found) called
04-13 09:45:21.448 18332 18332 D BuiltinUserCache: Added value for key background/battery at time 1.713026721433E9
04-13 09:45:21.464 18332 18332 D BuiltinUserCache: Added value for key background/bluetooth_ble at time 1.713026721449E9
04-13 09:45:21.479 18332 18332 D BuiltinUserCache: Added value for key background/bluetooth_ble at time 1.713026721465E9
04-13 09:45:21.493 18332 18332 D BuiltinUserCache: Added value for key background/bluetooth_ble at time 1.71302672148E9
04-13 09:45:21.520 18332 18332 D BuiltinUserCache: Added value for key background/bluetooth_ble at time 1.713026721493E9
04-13 09:45:21.532 18332 18332 D BuiltinUserCache: Added value for key background/bluetooth_ble at time 1.71302672152E9
04-13 09:45:21.546 18332 18332 D BuiltinUserCache: Added value for key background/bluetooth_ble at time 1.713026721533E9
04-13 09:45:21.548 18332 18332 I System.out: [BLE native] Found 5 entries
04-13 09:45:21.548 18332 18332 I System.out: [BLE native] First entry is edu.berkeley.eecs.emission.cordova.tracker.wrapper.BluetoothBLE@afc8f12 last entry is edu.berkeley.eecs.emission.cordova.tracker.wrapper.BluetoothBLE@b0c96e3
04-13 09:45:21.548 18332 18332 I System.out: [BLE native] while handling transition local.transition.ble_beacon_found
```

```
sqlite> select * from userCache where type == "sensor-data";
1713026512.887||America/Los_Angeles|sensor-data|background/battery||{"android_health":"GOOD","android_plugged":"UNKNOWN","android_technology":"Li-ion","android_temperature":250,"android_voltage":250,"battery_level_pct":100.0,"battery_status":4,"ts":1.713026512887E9}
1713026710.433||America/Los_Angeles|sensor-data|background/battery||{"android_health":"GOOD","android_plugged":"UNKNOWN","android_technology":"Li-ion","android_temperature":250,"android_voltage":250,"battery_level_pct":100.0,"battery_status":4,"ts":1.713026710432E9}
1713026712.809||America/Los_Angeles|sensor-data|background/battery||{"android_health":"GOOD","android_plugged":"UNKNOWN","android_technology":"Li-ion","android_temperature":250,"android_voltage":250,"battery_level_pct":100.0,"battery_status":4,"ts":1.713026712808E9}
1713026721.433||America/Los_Angeles|sensor-data|background/battery||{"android_health":"GOOD","android_plugged":"UNKNOWN","android_technology":"Li-ion","android_temperature":250,"android_voltage":250,"battery_level_pct":100.0,"battery_status":4,"ts":1.713026721433E9}
1713026721.449||America/Los_Angeles|sensor-data|background/bluetooth_ble||{"accuracy":100.0,"eventType":"REGION_ENTER","major":4538,"minor":1256,"proximity":"ProximityNear","rssi":10,"ts":1.713026721E9,"uuid":"0e27c613-ff78-486c-b523-950776777d16"}
1713026721.465||America/Los_Angeles|sensor-data|background/bluetooth_ble||{"accuracy":100.0,"eventType":"RANGE_UPDATE","major":4538,"minor":1256,"proximity":"ProximityNear","rssi":10,"ts":1.713026721E9,"uuid":"d8635e19-4133-493c-b2fd-c04fdd920c6a"}
1713026721.48||America/Los_Angeles|sensor-data|background/bluetooth_ble||{"accuracy":100.0,"eventType":"RANGE_UPDATE","major":4538,"minor":1256,"proximity":"ProximityNear","rssi":10,"ts":1.713026721E9,"uuid":"5efe9e8b-ce30-4417-80e3-79ce9ff53ca9"}
1713026721.493||America/Los_Angeles|sensor-data|background/bluetooth_ble||{"accuracy":100.0,"eventType":"RANGE_UPDATE","major":4538,"minor":1256,"proximity":"ProximityNear","rssi":10,"ts":1.713026721E9,"uuid":"d9283862-2926-4a0c-b377-0e80718e6525"}
1713026721.52||America/Los_Angeles|sensor-data|background/bluetooth_ble||{"accuracy":100.0,"eventType":"RANGE_UPDATE","major":4538,"minor":1256,"proximity":"ProximityNear","rssi":10,"ts":1.713026721E9,"uuid":"cef2f3df-30c5-49d5-8707-2f234530ef18"}
1713026721.533||America/Los_Angeles|sensor-data|background/bluetooth_ble||{"accuracy":100.0,"eventType":"RANGE_UPDATE","major":4538,"minor":1256,"proximity":"ProximityNear","rssi":10,"ts":1.713026721E9,"uuid":"326876e5-9869-407d-976c-2de438bec330"}
1713026800.123||America/Los_Angeles|sensor-data|background/battery||{"android_health":"GOOD","android_plugged":"UNKNOWN","android_technology":"Li-ion","android_temperature":250,"android_voltage":250,"battery_level_pct":100.0,"battery_status":4,"ts":1.713026800121E9}
1713026800.788||America/Los_Angeles|sensor-data|background/battery||{"android_health":"GOOD","android_plugged":"UNKNOWN","android_technology":"Li-ion","android_temperature":250,"android_voltage":250,"battery_level_pct":100.0,"battery_status":4,"ts":1.713026800788E9}
```

iOS

```
$ sqlite3 /Users/kshankar/Library/Developer/CoreSimulator/Devices/42B6F8A1-A925-4CAD-A48A-4835D69595ED/data/Containers/Data/Application/13D8F42C-921C-4754-9420-89C4350CE63F/Library/LocalDatabase/userCacheDB
SQLite version 3.39.5 2022-10-14 20:58:05
Enter ".help" for usage hints.
sqlite> select * from userCache where type == "sensor-data";
sqlite>
```

```
2024-04-13 09:34:56.566596-0700 emission[17352:9891606] In TripDiaryStateMachine, received transition T_BLE_BEACON_FOUND in state STATE_ONGOING_TRIP
2024-04-13 09:34:56.566796-0700 emission[17352:9891606] DEBUG: In TripDiaryStateMachine, received transition T_BLE_BEACON_FOUND in state STATE_ONGOING_TRIP
2024-04-13 09:34:56.568786-0700 emission[17352:9891606] data has 92 bytes, str has size 92
2024-04-13 09:34:56.570995-0700 emission[17352:9891606] data has 69 bytes, str has size 69
2024-04-13 09:35:12.781616-0700 emission[17352:9891606] data has 177 bytes, str has size 177
2024-04-13 09:35:12.784409-0700 emission[17352:9891606] data has 176 bytes, str has size 176
2024-04-13 09:35:12.786659-0700 emission[17352:9891606] data has 177 bytes, str has size 177
2024-04-13 09:35:12.789160-0700 emission[17352:9891606] data has 177 bytes, str has size 177
2024-04-13 09:35:12.791407-0700 emission[17352:9891606] data has 176 bytes, str has size 176
2024-04-13 09:35:12.793945-0700 emission[17352:9891606] data has 177 bytes, str has size 177
2024-04-13 09:35:17.900501-0700 emission[17352:9891606] [BLE native] Found 5 entries
2024-04-13 09:35:17.900666-0700 emission[17352:9891606] [BLE native] First entry is <BluetoothBLE: 0x6000010b8c80>, last entry is <BluetoothBLE: 0x6000010ba3f0>
2024-04-13 09:35:17.900773-0700 emission[17352:9891606] [BLE native] while handling transition T_BLE_BEACON_FOUND
2024-04-13 09:35:20.434450-0700 emission[17352:9891606] Got unexpected transition T_BLE_BEACON_FOUND in state STATE_ONGOING_TRIP, ignoring
```

```
sqlite> select * from userCache where type == "sensor-data";
1713026112.78185||America/Los_Angeles|sensor-data|background/bluetooth_ble||{"major":4538,"minor":1256,"rssi":10,"eventType":"REGION_ENTER","ts":1713026111.2200561,"uuid":"35355A74-E587-4F09-B114-D6718E925DC0","proximity":"ProximityNear","accuracy":100}
1713026112.78457||America/Los_Angeles|sensor-data|background/bluetooth_ble||{"major":4538,"minor":1256,"rssi":10,"eventType":"RANGE_UPDATE","ts":1713026112.784344,"uuid":"3448C47C-BE3B-40B8-A11F-4BD3CC1C2F63","proximity":"ProximityNear","accuracy":100}
1713026112.78698||America/Los_Angeles|sensor-data|background/bluetooth_ble||{"major":4538,"minor":1256,"rssi":10,"eventType":"RANGE_UPDATE","ts":1713026112.7865958,"uuid":"A2778875-CDF8-4AA8-A2E1-0639C9B4B159","proximity":"ProximityNear","accuracy":100}
1713026112.78947||America/Los_Angeles|sensor-data|background/bluetooth_ble||{"major":4538,"minor":1256,"rssi":10,"eventType":"RANGE_UPDATE","ts":1713026112.7891002,"uuid":"EE5129DA-6D64-4B25-BA68-3FB3D0FE6BD6","proximity":"ProximityNear","accuracy":100}
1713026112.79173||America/Los_Angeles|sensor-data|background/bluetooth_ble||{"major":4538,"minor":1256,"rssi":10,"eventType":"RANGE_UPDATE","ts":1713026112.791352,"uuid":"5B6A86F3-BE4D-498E-A3FD-0CAB6039914E","proximity":"ProximityNear","accuracy":100}
1713026112.7941||America/Los_Angeles|sensor-data|background/bluetooth_ble||{"major":4538,"minor":1256,"rssi":10,"eventType":"RANGE_UPDATE","ts":1713026112.7938981,"uuid":"71E73F8E-4138-4346-8E5F-D05E045A6D69","proximity":"ProximityNear","accuracy":100}
```
shankari added a commit to shankari/e-mission-data-collection that referenced this pull request Apr 13, 2024
…plugin

We created a testing hack to test the previous read/write native changes.
e-mission/e-mission-phone#1144 (comment)

We now move that hack to the plugin interface and make it accessible externally.
That makes it easier to call from the UI for better mocking.
Concretely, we can modify
e-mission/e-mission-phone@7cb3882
to call the interface, which will write sensor data using native code.
This allows us to simulate the actual working of the system (writing native
code) through the UI

Summary of changes:
- Create a new `mockBLEObjects` method in the interface
- Implement it on both android and iOS
- Change the fake object implementaton in the BluetoothBLE wrapper to take more
  arguments to that they can be passed in from the UI

Testing done:
e-mission/e-mission-phone@463c2a5
shankari added a commit to shankari/e-mission-server that referenced this pull request Apr 14, 2024
These are the server side changes related to
e-mission/e-mission-docs#1062

The changes are fairly straightforward, and consistent with
https://github.com/e-mission/e-mission-docs/blob/2665b39e1335ea04896b6944a4a065e7887b6cdc/docs/dev/back/adding_a_new_data_type.md?plain=1#L4

Concretely:
- we add a new `bluetoothble` wrapper
- we add references to it to `entry.py` and `builtin_timeseries.py`
- we add formatters for both android and iOS

A new wrinkle this time is that we are modifying the FSM, so there are also
new transitions. Those needed to be added to the enums in the transition
wrapper, and to the maps in the formatters so that the enums could be created
properly.

Bonus fix: check for the `None` transition properly on android and iOS to
avoid spurious errors

```
>>> broken_transition_example = {'_id': ObjectId('661b129fc271a44bb612b464'), 'metadata': {'time_zone': 'America/Los_Angeles', 'plugin': 'none', 'write_ts': 1713050268.574551, 'platform': 'ios', 'read_ts': 0, 'key': 'statemachine/transition', 'type': 'message'}, 'user_id': UUID('f1aaae55-fc42-4527-bf7f-33f84d7c8c2f'), 'data': {'currState': 'STATE_ONGOING_TRIP', 'transition': None, 'ts': 1713050268.574418}}
>>> broken_transition_example_entry = ad.AttrDict(broken_transition_example)
>>> enufit.format(broken_transition_example_entry)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/kshankar/Desktop/data/e-mission/gis_branch_tests/emission/net/usercache/formatters/ios/transition.py", line 64, in format
    data.transition = transition_map[entry.data.transition].value
KeyError: None

----- fixed code ------

>>> importlib.reload(enufit)
<module 'emission.net.usercache.formatters.ios.transition' from '/Users/kshankar/Desktop/data/e-mission/gis_branch_tests/emission/net/usercache/formatters/ios/transition.py'>
>>> enufit.format(broken_transition_example_entry)
AttrDict({'_id': ObjectId('661b129fc271a44bb612b464'), 'user_id': UUID('f1aaae55-fc42-4527-bf7f-33f84d7c8c2f'), 'metadata': AttrDict({'time_zone': 'America/Los_Angeles', 'plugin': 'none', 'write_ts': 1713050268.574551, 'platform': 'ios', 'read_ts': 0, 'key': 'statemachine/transition', 'type': 'message', 'write_local_dt': LocalDate({'year': 2024, 'month': 4, 'day': 13, 'hour': 16, 'minute': 17, 'second': 48, 'weekday': 5, 'timezone': 'America/Los_Angeles'}), 'write_fmt_time': '2024-04-13T16:17:48.574551-07:00'}), 'data': AttrDict({'curr_state': 2, 'transition': None, 'ts': 1713050268.574551, 'local_dt': AttrDict({'year': 2024, 'month': 4, 'day': 13, 'hour': 16, 'minute': 17, 'second': 48, 'weekday': 5, 'timezone': 'America/Los_Angeles'}), 'fmt_time': '2024-04-13T16:17:48.574551-07:00'})})
```

Testing done:
Used the corresponding changes in
e-mission/e-mission-phone#1144
to simulate BLE as follows:
- Region exit
- A few range updates until the `ble_beacon_found` transition was generated
- Turned on location mocking from the android and iOS simulators, and manually
  generated the start trip transition on android
- Clicked "range update" at random times during the simulated trip
- BLE beacon lost from the UI
- Turn off location mocking
- Force end trip transition

Testing Results:

Android:

```
START 2024-04-13 17:36:02.096342 POST /usercache/put
END 2024-04-13 17:36:02.313529 POST /usercache/put ebc13f1b-671b-4094-bce6-fed342da7e9c 0.2171182632446289
START 2024-04-13 17:36:02.583812 POST /usercache/get
END 2024-04-13 17:36:02.591868 POST /usercache/get ebc13f1b-671b-4094-bce6-fed342da7e9c 0.007989168167114258
```

```
>>> edb.get_usercache_db().count_documents({"metadata.key": "background/bluetooth_ble"})
57
>>> edb.get_timeseries_db().count_documents({"metadata.key": "background/bluetooth_ble"})
0
```

```
2024-04-13 17:37:57,635:DEBUG:140704655566784:write_ts = 1713054811.255
2024-04-13 17:37:57,635:DEBUG:140704655566784:module_name = emission.net.userca
che.formatters.android.bluetooth_ble
2024-04-13 17:37:57,636:DEBUG:140704655566784:write_ts = 1713054811.294
2024-04-13 17:37:57,636:DEBUG:140704655566784:module_name = emission.net.userca
che.formatters.android.bluetooth_ble
2024-04-13 17:37:57,636:DEBUG:140704655566784:write_ts = 1713054811.316
2024-04-13 17:37:57,636:DEBUG:140704655566784:module_name = emission.net.userca
che.formatters.android.bluetooth_ble
2024-04-13 17:37:57,637:DEBUG:140704655566784:write_ts = 1713054811.339
2024-04-13 17:37:57,637:DEBUG:140704655566784:module_name = emission.net.userca
che.formatters.android.bluetooth_ble
2024-04-13 17:37:57,637:DEBUG:140704655566784:write_ts = 1713054811.369
```

```
>>> edb.get_usercache_db().count_documents({"metadata.key": "background/bluetooth_ble"})
0
>>> edb.get_timeseries_db().count_documents({"metadata.key": "background/bluetooth_ble"})
57
```

iOS

```
START 2024-04-13 16:17:50.707151 POST /usercache/put
START 2024-04-13 16:17:50.737703 POST /usercache/get
END 2024-04-13 16:17:50.763880 POST /usercache/get f1aaae55-fc42-4527-bf7f-33f84d7c8c2f 0.026064157485961914
END 2024-04-13 16:17:51.340867 POST /usercache/put f1aaae55-fc42-4527-bf7f-33f84d7c8c2f 0.6329052448272705
```

```
>>> edb.get_usercache_db().count_documents({"metadata.key": "background/bluetooth_ble"})
74
```

```
DEBUG:root:module_name = emission.net.usercache.formatters.ios.bluetooth_ble
DEBUG:root:write_ts = 1713050204.075974
DEBUG:root:module_name = emission.net.usercache.formatters.ios.bluetooth_ble
DEBUG:root:write_ts = 1713050204.077563
DEBUG:root:module_name = emission.net.usercache.formatters.ios.bluetooth_ble
DEBUG:root:write_ts = 1713050204.078974
DEBUG:root:module_name = emission.net.usercache.formatters.ios.bluetooth_ble
DEBUG:root:write_ts = 1713050207.32417
DEBUG:root:module_name = emission.net.usercache.formatters.ios.bluetooth_ble
DEBUG:root:write_ts = 1713050207.326033
```

```
>>> edb.get_usercache_db().count_documents({"metadata.key": "background/bluetooth_ble"})
0
>>> edb.get_timeseries_db().count_documents({"metadata.key": "background/bluetooth_ble"})
74
>>> edb.get_timeseries_error_db().count_documents({"metadata.key": "background/bluetooth_ble"})
0
```
in_range: status,
},
}));
let { monitorResult: _, in_range: _, ...noResultDevice } = sampleBLEDevices[uuid];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bundling JS fails at this line.
What is it supposed to do anyway? It doesn't appear to do anything

Copy link
Contributor Author

@shankari shankari Apr 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It removes monitorResult and in_range from sampleBLEDevices[uuid] and retains the rest in noResultDevice. We then save noresultDevice - it doesn't make sense to save the fake results along with it.
https://stackoverflow.com/a/34710102

what is the error that you get? Is this primarily in production mode? I am able to build in dev mode just fine.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont' see anywhere that noResultDevice is used, though

SyntaxError: ... Identifier '_' has already been declared.
it's trying to destructure the object and assign both monitorResult and in_range to a variable called _.

Yes this happened with build-prod-android

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this happened with build-prod-android

Ah I haven't tried the prod builds yet. A simple workaround would be to use { monitorResult: p0, in_range: p1, ...} to avoid reusing the _ variable.

I dont' see anywhere that noResultDevice is used, though

Ah, before my most recent set of commits, when i used a newly added native mock function, I was saving the values directly using the usercache. See 7cb3882

When I changed to use mocks, I forgot to clean these up. I can do that now, or you can comment them out to unblock yourself.

Comment on lines 125 to 130
let {
monitorResult: _,
rangeResult: _,
in_range: _,
...noResultDevice
} = sampleBLEDevices[uuid];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

In an earlier version of this PR, before I added mocking to the plugin,
we saved JSON objects directly. We created the objects to save by
removing results from the in-memory objects using a destructuring
assignment.

However, after the mocking was added, we create objects in native code.
So we don't need to create them here and can remove these unused
variables.
e-mission#1144 (comment)
Complementary to
e-mission/e-mission-data-collection#224

Very similar to the fitness checks, just calls through to the underlying
native javascript

Note that the bluetooth scan will currently only be used for fleet
configs since we don't use bluetooth in the general case, and forcing
people to enable it unnecessarily is bad.

Testing done:
e-mission/e-mission-data-collection#224 (comment)
The data collection plugin may have other changes coming in, so we are
installing it off a branch
e-mission/e-mission-data-collection#226
is now merged and a new release
https://github.com/e-mission/e-mission-data-collection/releases/tag/v1.8.5
has been created

So we can now use the version number instead of a branch while adding the
plugin

With this commit, the initial implementation in
e-mission#1144
is done, and we can merge it
@shankari shankari marked this pull request as ready for review April 26, 2024 04:49
Copy link

codecov bot commented Apr 28, 2024

Codecov Report

Attention: Patch coverage is 0% with 17 lines in your changes are missing coverage. Please review.

Project coverage is 26.42%. Comparing base (0f6aabc) to head (ccab0ca).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1144      +/-   ##
==========================================
- Coverage   27.32%   26.42%   -0.90%     
==========================================
  Files         113      114       +1     
  Lines        4816     4980     +164     
  Branches     1032     1062      +30     
==========================================
  Hits         1316     1316              
- Misses       3498     3662     +164     
  Partials        2        2              
Flag Coverage Δ
unit 26.42% <0.00%> (-0.90%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
www/js/bluetooth/BluetoothScanPage.tsx 0.00% <ø> (ø)
www/js/usePermissionStatus.ts 0.00% <0.00%> (ø)

@shankari
Copy link
Contributor Author

It's good that I first fixed #1148 before merging this because 0eebe4b did generate a regression

Ensure that we fail on error
Copied config.cordovabuild.xml -> config.xml and package.cordovabuild.json -> package.json
Copying fake FCM configurations for android and iOS
Setting up all npm packages
npm ERR! code 1
npm ERR! The git reference could not be found
npm ERR! command git --no-replace-objects checkout 1.8.5
npm ERR! error: pathspec '1.8.5' did not match any file(s) known to git

@shankari
Copy link
Contributor Author

I am going to ignore the codecov regression since our current coverage is only 27%, and we can write the test cases for these as we work through the backlog

@shankari shankari merged commit 8a9d9b3 into e-mission:master Apr 28, 2024
6 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants