Skip to content

Commit ee10c23

Browse files
committed
Add support for the new mode_confirm and purpose_confirm classes
Changes include: - new wrapper class - formatters for the input processing This is also hopefully a nice, self-contained example of how to add new manually reported objects to the server. See also: https://github.com/e-mission/e-mission-server/issues/516#issuecomment-325426620
1 parent c720ec7 commit ee10c23

File tree

10 files changed

+74
-0
lines changed

10 files changed

+74
-0
lines changed

emission/core/wrapper/entry.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ def _getData2Wrapper():
4141
"stats/client_nav_event": "statsevent",
4242
"stats/client_error": "statsevent",
4343
"manual/incident": "incident",
44+
"manual/mode_confirm": "userlabel",
45+
"manual/purpose_confirm": "userlabel",
4446
"segmentation/raw_trip": "rawtrip",
4547
"segmentation/raw_place": "rawplace",
4648
"segmentation/raw_section": "section",

emission/core/wrapper/userlabel.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import logging
2+
import emission.core.wrapper.wrapperbase as ecwb
3+
4+
class Userlabel(ecwb.WrapperBase):
5+
props = {"start_ts": ecwb.WrapperBase.Access.RO, # geojson representation of the point
6+
"start_local_dt": ecwb.WrapperBase.Access.RO, # start datetime in local time
7+
"start_fmt_time": ecwb.WrapperBase.Access.RO, # start formatted time (in timezone of point)
8+
"end_ts": ecwb.WrapperBase.Access.WORM, # end UTC timestamp (in secs)
9+
"end_local_dt": ecwb.WrapperBase.Access.RO, # end datetime in local time
10+
"end_fmt_time": ecwb.WrapperBase.Access.RO, # end formatted time (in timezone of point)
11+
"label": ecwb.WrapperBase.Access.RO # string representation of mode
12+
}
13+
14+
enums = {}
15+
geojson = []
16+
nullable = []
17+
local_dates = ["start_local_dt", "end_local_dt"]
18+
19+
def _populateDependencies(self):
20+
pass
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import logging
2+
import emission.net.usercache.formatters.generic.userlabel as fgl
3+
4+
def format(entry):
5+
return fgl.format(entry)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import logging
2+
import emission.net.usercache.formatters.generic.userlabel as fgl
3+
4+
def format(entry):
5+
return fgl.format(entry)

emission/net/usercache/formatters/common.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,9 @@ def expand_metadata_times(m):
1919
def expand_data_times(d,m):
2020
d.local_dt = ecsdlq.get_local_date(d.ts, m.time_zone)
2121
d.fmt_time = arrow.get(d.ts).to(m.time_zone).isoformat()
22+
23+
def expand_start_end_data_times(d,m):
24+
d.start_local_dt = ecsdlq.get_local_date(d.start_ts, m.time_zone)
25+
d.start_fmt_time = arrow.get(d.start_ts).to(m.time_zone).isoformat()
26+
d.end_local_dt = ecsdlq.get_local_date(d.end_ts, m.time_zone)
27+
d.end_fmt_time = arrow.get(d.end_ts).to(m.time_zone).isoformat()

emission/net/usercache/formatters/generic/__init__.py

Whitespace-only changes.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import logging
2+
import arrow
3+
4+
import emission.net.usercache.formatters.common as fc
5+
import emission.storage.decorations.local_date_queries as ecsdlq
6+
import attrdict as ad
7+
8+
def format(entry):
9+
formatted_entry = ad.AttrDict()
10+
formatted_entry["_id"] = entry["_id"]
11+
formatted_entry.user_id = entry.user_id
12+
13+
metadata = entry.metadata
14+
if "time_zone" not in metadata:
15+
metadata.time_zone = "America/Los_Angeles"
16+
logging.debug("Timestamp conversion: %s -> %s done" % (entry.metadata.write_ts, metadata.write_ts))
17+
fc.expand_metadata_times(metadata)
18+
formatted_entry.metadata = metadata
19+
20+
data = entry.data
21+
fc.expand_start_end_data_times(data, metadata)
22+
formatted_entry.data = data
23+
24+
return formatted_entry
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import logging
2+
import emission.net.usercache.formatters.generic.userlabel as fgl
3+
4+
def format(entry):
5+
return fgl.format(entry)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import logging
2+
import emission.net.usercache.formatters.generic.userlabel as fgl
3+
4+
def format(entry):
5+
return fgl.format(entry)

emission/storage/timeseries/builtin_timeseries.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ def __init__(self, user_id):
4848
"stats/client_nav_event": self.timeseries_db,
4949
"stats/client_error": self.timeseries_db,
5050
"manual/incident": self.timeseries_db,
51+
"manual/mode_confirm": self.timeseries_db,
52+
"manual/purpose_confirm": self.timeseries_db,
5153
"segmentation/raw_trip": self.analysis_timeseries_db,
5254
"segmentation/raw_place": self.analysis_timeseries_db,
5355
"segmentation/raw_section": self.analysis_timeseries_db,

0 commit comments

Comments
 (0)