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

ios doesn't fill in metadata timezone information for rw documents #17

Open
shankari opened this issue Jul 25, 2016 · 3 comments
Open

Comments

@shankari
Copy link
Contributor

While investigating documents created directly from javascript today, I discovered that iOS doesn't fill in metadata timezone information, at least for for rw documents. And since the metadata is consistent, it probably doesn't fill in the information for any documents.

We do workaround this by setting the timezone to America/Los_Angeles if it is not present, but that's incorrect for locations other than the west coast of the US. We should either stop using the metadata timezone, or fill it in correctly.

@shankari
Copy link
Contributor Author

Example sensor_config objects without metadata timezone.

[{u'_id': ObjectId('57966efb115514afcd793360'),
  u'data': {u'accuracy': -1,
   u'accuracy_threshold': 200,
   u'android_geofence_responsiveness': -1,
   u'filter_distance': 50,
   u'filter_time': -1,
   u'geofence_radius': 100,
   u'ios_use_remote_push_for_sync': 1,
   u'ios_use_visit_notifications_for_detection': 1,
   u'is_duty_cycling': 0,
   u'simulate_user_interaction': 1,
   u'trip_end_stationary_mins': 10},
  u'metadata': {u'key': u'config/sensor_config',
   u'type': u'document',
   u'write_ts': 1469476603.373646},
  u'user_id': UUID('1c4e043f-cffe-3429-9ad8-09fadc96ff2f')},
 {u'_id': ObjectId('57964463115514afcd79334e'),
  u'data': {u'accuracy': -1,
   u'accuracy_threshold': 200,
   u'android_geofence_responsiveness': -1,
   u'filter_distance': 50,
   u'filter_time': -1,
   u'geofence_radius': 100,
   u'ios_use_remote_push_for_sync': 1,
   u'ios_use_visit_notifications_for_detection': 1,
   u'is_duty_cycling': 0,
   u'simulate_user_interaction': 1,
   u'trip_end_stationary_mins': 10},
  u'metadata': {u'key': u'config/sensor_config',
   u'type': u'document',
   u'write_ts': 1469473156.203633},
  u'user_id': UUID('3594ff76-d3e2-36c1-9118-45a6a698286e')},
 {u'_id': ObjectId('579671de115514afcd79336e'),
  u'data': {u'accuracy': -1,
   u'accuracy_threshold': 200,
   u'android_geofence_responsiveness': -1,
   u'filter_distance': 50,
   u'filter_time': -1,
   u'geofence_radius': 100,
   u'ios_use_remote_push_for_sync': 1,
   u'ios_use_visit_notifications_for_detection': 1,
   u'is_duty_cycling': 0,
   u'simulate_user_interaction': 0,
   u'trip_end_stationary_mins': 10},
  u'metadata': {u'key': u'config/sensor_config',
   u'type': u'document',
   u'write_ts': 1469478208.197791},
  u'user_id': UUID('0763de67-f61e-3f5d-90e7-518e69793954')}]

shankari added a commit to shankari/e-mission-server that referenced this issue Jul 25, 2016
As described in e-mission/cordova-usercache#17, it
looks like we never actually passed in a timezone from the client, which means
that the code to check for timezone validity was never tested.

And of course, that which is not tested is broken. Fix the check by adding
appropriate imports and module names.

With this change, we now store the incoming config

```
2016-07-25 15:28:17,503:DEBUG:module_name = emission.net.usercache.formatters.ios.consent
2016-07-25 15:28:17,555:DEBUG:write_ts = 1469477974
2016-07-25 15:28:17,556:DEBUG:insert called
2016-07-25 15:28:17,556:DEBUG:entry was fine, no need to fix it
2016-07-25 15:28:17,557:DEBUG:Inserting entry AttrDict({u'user_id': UUID('0763de67-f61e-3f5d-90e7-518e69793954'), u'_id': ObjectId('57969202115514afcd79338b'), u'data': AttrDict({u'category': u'emSensorDataCollectionProtocol', u'approval_date': u'2016-07-14', u'protocol_id': u'2014-04-6267'}), u'metadata': AttrDict({u'platform': u'ios', 'write_local_dt': LocalDate({'hour': 13, 'month': 7, 'second': 34, 'weekday': 0, 'year': 2016, 'timezone': u'America/Los_Angeles', 'day': 25, 'minute': 19}), u'read_ts': 0, u'key': u'config/consent', u'plugin': u'none', u'write_ts': 1469477974, u'type': u'rw-document', u'time_zone': u'America/Los_Angeles', 'write_fmt_time': '2016-07-25T13:19:34-07:00'})}) into timeseries
```

and return it as a document.

```
2016-07-25 15:28:45,014:DEBUG:finished querying values for ['config/consent']
2016-07-25 15:28:45,014:DEBUG:finished querying values for []
2016-07-25 15:28:45,015:DEBUG:Found 2 user overrides for user 0763de67-f61e-3f5d-90e7-518e69793954
2016-07-25 15:28:45,015:DEBUG:last entry is Entry({u'user_id': UUID('0763de67-f61e-3f5d-90e7-518e69793954'), u'_id': ObjectId('57969202115514afcd79338b'), u'data': {u'category': u'emSensorDataCollectionProtocol', u'approval_date': u'2016-07-14', u'protocol_id': u'2014-04-6267'}, u'metadata': {u'write_fmt_time': u'2016-07-25T13:19:34-07:00', u'write_ts': 1469477974, u'plugin': u'none', u'time_zone': u'America/Los_Angeles', u'platform': u'ios', u'write_local_dt': {u'hour': 13, u'month': 7, u'second': 34, u'weekday': 0, u'year': 2016, u'timezone': u'America/Los_Angeles', u'day': 25, u'minute': 19}, u'key': u'config/consent', u'read_ts': 0, u'type': u'rw-document'}})
2016-07-25 15:28:45,015:DEBUG:for 0763de67-f61e-3f5d-90e7-518e69793954, config is Consentconfig({u'category': u'emSensorDataCollectionProtocol', u'approval_date': u'2016-07-14', u'protocol_id': u'2014-04-6267'})
2016-07-25 15:28:45,016:DEBUG:Result = {'updatedExisting': False, u'nModified': 0, u'ok': 1, u'upserted': ObjectId('5796929d115514afcd793398'), u'n': 1} after updating document config/consent
```
@shankari
Copy link
Contributor Author

android is fine:

2016-07-22 10:00:09,501:DEBUG:Inserting entry AttrDict({'data': AttrDict({'curr_state': 2, 'transition': 2, 'local_dt': AttrDict({'hour': 10, 'month': 7, 'second': 55, 'weekday': 4, 'year': 2016, 'timezone': u'Europe/Copenhagen', 'day': 22, 'minute': 27}), 'ts': 1469176075.087, 'fmt_time': '2016-07-22T10:27:55.087000+02:00'}), '_id': ObjectId('5791e753abbf384cadf544d4'), 'user_id': UUID(<redacted>), 'metadata': AttrDict({u'platform': u'android', 'write_local_dt': LocalDate({'hour': 10, 'month': 7, 'second': 55, 'weekday': 4, 'year': 2016, 'timezone': u'Europe/Copenhagen', 'day': 22, 'minute': 27}), u'key': u'statemachine/transition', u'write_ts': 1469176075.087, u'read_ts': 0, u'type': u'message', u'time_zone': u'Europe/Copenhagen', 'write_fmt_time': '2016-07-22T10:27:55.087000+02:00'})}) into timeseries

but it looks like it works for iOS as well.

2016-07-25 16:00:17,144:DEBUG:Inserting entry AttrDict({'data': AttrDict({u'fmt_time': '2016-07-24T20:23:18.000018-03:00', <redacted>, u'filter': u'distance', 'local_dt': LocalDate({'hour': 20, 'month': 7, 'second': 18, 'weekday': 6, 'year': 2016, 'timezone': u'America/Sao_Paulo', 'day': 24, 'minute': 23}), u'latitude': -23.49404459352755, 'loc': <redacted>, u'sensed_speed': 31.05999946594238, u'accuracy': 10}), '_id': ObjectId('5796353dabbf384cadf9e0c2'), 'user_id': UUID(<redacted>), 'metadata': AttrDict({u'platform': u'ios', 'write_local_dt': LocalDate({'hour': 20, 'month': 7, 'second': 18, 'weekday': 6, 'year': 2016, 'timezone': u'America/Sao_Paulo', 'day': 24, 'minute': 23}), u'read_ts': 0, u'key': u'background/filtered_location', u'plugin': u'none', u'write_ts': 1469402598.315054, u'type': u'sensor-data', u'time_zone': u'America/Sao_Paulo', 'write_fmt_time': '2016-07-24T20:23:18.315054-03:00'})}) into timeseries

@shankari
Copy link
Contributor Author

shankari commented Jul 26, 2016

Actually, it looks like the metadata time_zone is missing only for documents, not read-write documents. So then why didn't we hit the errors fixed by e-mission/e-mission-server@a31ba77 earlier?

[{u'_id': ObjectId('5796b698115514afcd79339b'),
  u'data': {u'accuracy': -1,
   u'accuracy_threshold': 200,
   u'android_geofence_responsiveness': -1,
   u'filter_distance': 50,
   u'filter_time': -1,
   u'geofence_radius': 100,
   u'ios_use_remote_push_for_sync': 1,
   u'ios_use_visit_notifications_for_detection': 1,
   u'is_duty_cycling': 0,
   u'simulate_user_interaction': 0,
   u'trip_end_stationary_mins': 10},
  u'metadata': {u'key': u'config/sensor_config',
   u'platform': u'ios',
   u'plugin': u'none',
   u'read_ts': 0,
   u'time_zone': u'America/Los_Angeles',
   u'type': u'rw-document',
   u'write_ts': 1469494639.076389},
  u'user_id': UUID('0763de67-f61e-3f5d-90e7-518e69793954')},
 {u'_id': ObjectId('57969b14115514afcd79339a'),
  u'data': {u'accuracy': -1,
   u'accuracy_threshold': 200,
   u'android_geofence_responsiveness': -1,
   u'filter_distance': 30,
   u'filter_time': -1,
   u'geofence_radius': 100,
   u'ios_use_remote_push_for_sync': 1,
   u'ios_use_visit_notifications_for_detection': 1,
   u'is_duty_cycling': 0,
   u'simulate_user_interaction': 0,
   u'trip_end_stationary_mins': 10},
  u'metadata': {u'key': u'config/sensor_config',
   u'platform': u'ios',
   u'plugin': u'none',
   u'read_ts': 0,
   u'time_zone': u'America/Los_Angeles',
   u'type': u'rw-document',
   u'write_ts': 1469482757.695187},
  u'user_id': UUID('0763de67-f61e-3f5d-90e7-518e69793954')}]

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

No branches or pull requests

1 participant