-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4942 from mpimenov/traffic-python-bindings
[traffic] Added python bindings for traffic serialization.
- Loading branch information
Showing
5 changed files
with
196 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#pragma once | ||
|
||
#include "std/vector.hpp" | ||
|
||
#include <boost/python.hpp> | ||
|
||
namespace | ||
{ | ||
template <typename T> | ||
vector<T> python_list_to_std_vector(boost::python::object const & iterable) | ||
{ | ||
return vector<T>(boost::python::stl_input_iterator<T>(iterable), | ||
boost::python::stl_input_iterator<T>()); | ||
} | ||
|
||
template <typename T> | ||
boost::python::list std_vector_to_python_list(vector<T> const & v) | ||
{ | ||
boost::python::object get_iter = boost::python::iterator<vector<T>>(); | ||
return boost::python::list(get_iter(v)); | ||
} | ||
} // namespace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from pytraffic import RoadSegmentId, SegmentSpeeds, load_classificator, generate_traffic_keys, generate_traffic_values | ||
import argparse | ||
|
||
parser = argparse.ArgumentParser(description='Example usage of pytraffic.') | ||
parser.add_argument("--path_to_classificator", dest="path_to_classificator", help="Path to the directory that contains classificator.txt.") | ||
parser.add_argument("--path_to_mwm", dest="path_to_mwm", help="Path to the target mwm file.") | ||
|
||
options = parser.parse_args() | ||
if not options.path_to_classificator or not options.path_to_mwm: | ||
parser.print_help() | ||
exit() | ||
|
||
load_classificator(options.path_to_classificator) | ||
|
||
keys = [ | ||
RoadSegmentId(0, 0, 0), | ||
RoadSegmentId(1, 0, 0), | ||
RoadSegmentId(1, 0, 1), | ||
] | ||
|
||
keys_from_mwm = generate_traffic_keys(options.path_to_mwm) | ||
|
||
mapping = { | ||
RoadSegmentId(0, 0, 0):SegmentSpeeds(1.0, 2.0, 3.0), | ||
RoadSegmentId(1, 0, 1):SegmentSpeeds(4.0, 5.0, 6.0), | ||
} | ||
|
||
buf = generate_traffic_values(keys, mapping) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters