[traffic] Python bindings for struct fields.

This commit is contained in:
Maxim Pimenov 2016-12-12 14:25:39 +03:00
parent e86e847c42
commit 9bfa0ab864
3 changed files with 23 additions and 1 deletions

View file

@ -34,6 +34,10 @@ struct SegmentSpeeds
{
}
double GetWeightedSpeed() const { return m_weightedSpeed; }
double GetWeightedRefSpeed() const { return m_weightedRefSpeed; }
double GetWeight() const { return m_weight; }
double m_weightedSpeed = 0;
double m_weightedRefSpeed = 0;
double m_weight = 0;
@ -153,10 +157,17 @@ BOOST_PYTHON_MODULE(pytraffic)
vector_uint8t_from_python_str();
class_<SegmentSpeeds>("SegmentSpeeds", init<double, double, double>())
.def("__repr__", &SegmentSpeedsRepr);
.def("__repr__", &SegmentSpeedsRepr)
.def("get_weighted_speed", &SegmentSpeeds::GetWeightedSpeed)
.def("get_weighted_ref_speed", &SegmentSpeeds::GetWeightedRefSpeed)
.def("get_weight", &SegmentSpeeds::GetWeight)
;
class_<traffic::TrafficInfo::RoadSegmentId>("RoadSegmentId", init<uint32_t, uint16_t, uint8_t>())
.def("__repr__", &RoadSegmentIdRepr)
.def("get_fid", &traffic::TrafficInfo::RoadSegmentId::GetFid)
.def("get_idx", &traffic::TrafficInfo::RoadSegmentId::GetIdx)
.def("get_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].get_fid(), keys[2].get_idx(), keys[2].get_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.get_weighted_speed(), seg_speeds.get_weighted_ref_speed(), seg_speeds.get_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;