Merge pull request #4955 from mpimenov/traffic-python-fields

[traffic] Python bindings for struct fields.
This commit is contained in:
Sergey Yershov 2016-12-12 17:03:48 +03:00 committed by GitHub
commit 11c08c6c0f
3 changed files with 19 additions and 1 deletions

View file

@ -153,10 +153,17 @@ BOOST_PYTHON_MODULE(pytraffic)
vector_uint8t_from_python_str();
class_<SegmentSpeeds>("SegmentSpeeds", init<double, double, double>())
.def("__repr__", &SegmentSpeedsRepr);
.def("__repr__", &SegmentSpeedsRepr)
.def_readwrite("weighted_speed", &SegmentSpeeds::m_weightedSpeed)
.def_readwrite("weighted_ref_speed", &SegmentSpeeds::m_weightedRefSpeed)
.def_readwrite("weight", &SegmentSpeeds::m_weight)
;
class_<traffic::TrafficInfo::RoadSegmentId>("RoadSegmentId", init<uint32_t, uint16_t, uint8_t>())
.def("__repr__", &RoadSegmentIdRepr)
.add_property("fid", &traffic::TrafficInfo::RoadSegmentId::GetFid)
.add_property("idx", &traffic::TrafficInfo::RoadSegmentId::GetIdx)
.add_property("dir", &traffic::TrafficInfo::RoadSegmentId::GetDir)
;
class_<std::vector<traffic::TrafficInfo::RoadSegmentId>>("RoadSegmentIdVec")

View file

@ -18,8 +18,15 @@ keys = [
RoadSegmentId(1, 0, 1),
]
fid, idx, dir = keys[2].fid, keys[2].idx, keys[2].dir
print fid, idx, dir
keys_from_mwm = generate_traffic_keys(options.path_to_mwm)
seg_speeds = SegmentSpeeds(1.0, 2.0, 3.0)
ws, wrs, w = seg_speeds.weighted_speed, seg_speeds.weighted_ref_speed, seg_speeds.weight
print ws, wrs, w
mapping = {
RoadSegmentId(0, 0, 0):SegmentSpeeds(1.0, 2.0, 3.0),
RoadSegmentId(1, 0, 1):SegmentSpeeds(4.0, 5.0, 6.0),

View file

@ -58,6 +58,10 @@ public:
return m_dir < o.m_dir;
}
uint32_t GetFid() const { return m_fid; }
uint16_t GetIdx() const { return m_idx; }
uint8_t GetDir() const { return m_dir; }
// The ordinal number of feature this segment belongs to.
uint32_t m_fid;