Skip to content

Commit

Permalink
update to match e-mission/e-mission-server master (#6)
Browse files Browse the repository at this point in the history
* Add a new method to store data synchronously

This is intended for **foreground use only**, primarily to synchronously save
user inputs in case we need it for server-specific services (e.g. generating a
suggestion) or in case we want to ensure that the data is saved before the app
is uninstalled.

Since it is used in the foreground, users can be interactively notified if the
save failed.

In order to reduce abuse for sending background sensed data, this can accept one entry at a time.

For client integrators, as you can see, this is similar to `/profile/update`, but the data is under `the_entry` instead of `update_doc`

Testing done:

We have 76 entries

```
In [16]: edb.get_usercache_db().find({"metadata.key": "manual/mode_confirm"}).count()
Out[16]: 76
```

We save one more

```
In [17]: test_input = {
    ...:   "user": "test_mode_purpose",
    ...:   "the_entry" : {
    ...:      "metadata": {"key": "manual/mode_confirm", "write_ts": 12345678, "type": "
    ...: message"},
    ...:      "data": {"start_ts": 1234, "end_ts": 5678, "label": "pogo_sticking"}
    ...:   }
    ...: }

In [18]: requests.post("http://localhost:8080/usercache/putone", data=json.dumps(test_in
    ...: put), headers=headers)
Out[18]: <Response [200]>
```

```
START 2019-05-08 19:17:35.633951 POST /usercache/putone
END 2019-05-08 19:17:35.649836 POST /usercache/putone 49e72fc4-f1d8-4f4d-9666-57dc597d1133 0.015433073043823242
```

We now have 77 entries

```
In [19]: edb.get_usercache_db().find({"metadata.key": "manual/mode_confirm"}).count()
Out[19]: 77
```

and the new one is the right one

```
In [20]: edb.get_usercache_db().find({"metadata.key": "manual/mode_confirm", "data.label
    ...: ": "pogo_sticking"}).count()
Out[20]: 1

In [21]: edb.get_usercache_db().find_one({"metadata.key": "manual/mode_confirm", "data.l
    ...: abel": "pogo_sticking"})
Out[21]:
{'_id': ObjectId('5cd38dbfbe04ee70f576335d'),
 'data': {'end_ts': 5678, 'label': 'pogo_sticking', 'start_ts': 1234},
 'metadata': {'key': 'manual/mode_confirm',
  'type': 'message',
  'write_ts': 12345678},
 'user_id': UUID('49e72fc4-f1d8-4f4d-9666-57dc597d1133')}
```

This also fixes e-mission/e-mission-docs#351 in a
more principled way.

* Add support for the new destination_confirm class

Changes include:
- new wrapper class
- formatters for the input processing

This is also hopefully a nicer, shorter, self-contained example of how to add
new manually reported objects to the server.
  • Loading branch information
trevor-wu authored May 11, 2019
1 parent 1b55d84 commit 2e31986
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 0 deletions.
3 changes: 3 additions & 0 deletions emission/core/wrapper/entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ def _getData2Wrapper():
"manual/mode_confirm": "userlabel",
# user confirmation of the travel purpose
"manual/purpose_confirm": "userlabel",
# user confirmation of the destination (unsure how this will
# interact with purpose
"manual/destination_confirm": "userlabel",
### END: incoming data types ###
### BEGIN: analysis result data types ###
### ** BEGIN: objects generated after the initial segmentation step **
Expand Down
10 changes: 10 additions & 0 deletions emission/net/api/cfc_webapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,16 @@ def putIntoCache():
from_phone = request.json['phone_to_server']
return usercache.sync_phone_to_server(user_uuid, from_phone)

@post('/usercache/putone')
def putIntoOneEntry():
logging.debug("Called userCache.putone with request " % request)
user_uuid=getUUID(request)
logging.debug("user_uuid %s" % user_uuid)
the_entry = request.json['the_entry']
# sync_phone_to_server requires a list, so we wrap our one entry in the list
from_phone = [the_entry]
return usercache.sync_phone_to_server(user_uuid, from_phone)

@post('/timeline/getTrips/<day>')
def getTrips(day):
logging.debug("Called timeline.getTrips/%s" % day)
Expand Down
12 changes: 12 additions & 0 deletions emission/net/usercache/formatters/android/destination_confirm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from __future__ import unicode_literals
from __future__ import print_function
from __future__ import division
from __future__ import absolute_import
from future import standard_library
standard_library.install_aliases()
from builtins import *
import logging
import emission.net.usercache.formatters.generic.userlabel as fgl

def format(entry):
return fgl.format(entry)
12 changes: 12 additions & 0 deletions emission/net/usercache/formatters/ios/destination_confirm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from __future__ import unicode_literals
from __future__ import print_function
from __future__ import division
from __future__ import absolute_import
from future import standard_library
standard_library.install_aliases()
from builtins import *
import logging
import emission.net.usercache.formatters.generic.userlabel as fgl

def format(entry):
return fgl.format(entry)
1 change: 1 addition & 0 deletions emission/storage/timeseries/builtin_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def __init__(self, user_id):
"manual/incident": self.timeseries_db,
"manual/mode_confirm": self.timeseries_db,
"manual/purpose_confirm": self.timeseries_db,
"manual/destination_confirm": self.timeseries_db,
"segmentation/raw_trip": self.analysis_timeseries_db,
"segmentation/raw_place": self.analysis_timeseries_db,
"segmentation/raw_section": self.analysis_timeseries_db,
Expand Down

0 comments on commit 2e31986

Please sign in to comment.