-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add segments to Flow
to update traffic on part of way
#322
base: master
Are you sure you want to change the base?
Changes from all commits
08168d0
200ccd3
865f616
23a7824
d1a1f47
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,8 @@ import ( | |
"strconv" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/Telenav/osrm-backend/integration/traffic/livetraffic/trafficproxy" | ||
) | ||
|
||
func TestSpeedTableDumper1(t *testing.T) { | ||
|
@@ -23,16 +25,41 @@ func TestSpeedTableDumper1(t *testing.T) { | |
|
||
// construct mock traffic | ||
wayid2speed := make(map[int64]int) | ||
segmentsOfWay := make(map[int64][]*trafficproxy.SegmentedFlow) | ||
loadMockTrafficFlow2Map(wayid2speed) | ||
|
||
var ds dumperStatistic | ||
ds.Init(TASKNUM) | ||
dumpSpeedTable4Customize(wayid2speed, sources, "./testdata/target.csv", &ds) | ||
dumpSpeedTable4Customize(wayid2speed, segmentsOfWay, sources, "./testdata/target.csv", &ds) | ||
|
||
compareFileContentUnstable("./testdata/target.csv", "./testdata/expect.csv", t) | ||
validateStatistic(&ds, t) | ||
} | ||
|
||
func TestSpeedTableDumper2(t *testing.T) { | ||
// load result into sources | ||
var sources [TASKNUM]chan string | ||
for i := range sources { | ||
sources[i] = make(chan string, 10000) | ||
} | ||
go loadWay2NodeidsTable("./testdata/id-mapping-segment.csv.snappy", sources) | ||
|
||
// construct mock traffic | ||
wayid2speed := make(map[int64]int) | ||
wayid2speed[733690162] = 60 | ||
wayid2speed[-733689924] = 60 | ||
|
||
segmentsOfWay := make(map[int64][]*trafficproxy.SegmentedFlow) | ||
loadMockTrafficFlowSegment2Map(segmentsOfWay) | ||
|
||
var ds dumperStatistic | ||
ds.Init(TASKNUM) | ||
dumpSpeedTable4Customize(wayid2speed, segmentsOfWay, sources, "./testdata/target-segment.csv", &ds) | ||
|
||
compareFileContentUnstable("./testdata/target-segment.csv", "./testdata/expect-segment.csv", t) | ||
// validateStatistic(&ds, t) | ||
} | ||
|
||
func TestGenerateSingleRecord1(t *testing.T) { | ||
str := generateSingleRecord(12345, 54321, 33, true) | ||
if strings.Compare(str, "12345,54321,33\n") != 0 { | ||
|
@@ -62,6 +89,19 @@ func loadMockTrafficFlow2Map(wayid2speed map[int64]int) { | |
wayid2speed[-24418344] = 59 | ||
} | ||
|
||
func loadMockTrafficFlowSegment2Map(segmentsOfWay map[int64][]*trafficproxy.SegmentedFlow) { | ||
segmentsOfWay[733690162] = []*trafficproxy.SegmentedFlow{ | ||
{Speed: 25, Begin: 25, End: 75}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It tests part of way have segmented flow. I'm thinking about the case that every segments of way have segmented flow. E.g., There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's possible. I've added the test case. |
||
{Speed: 42, Begin: 80, End: 175}, // negative case | ||
} | ||
segmentsOfWay[-733689924] = []*trafficproxy.SegmentedFlow{ | ||
{Speed: 10, Begin: 0, End: 25}, | ||
{Speed: 20, Begin: 26, End: 50}, | ||
{Speed: 30, Begin: 51, End: 100}, | ||
{Speed: 42, Begin: 50, End: 25}, // negative case | ||
} | ||
} | ||
|
||
type tNodePair struct { | ||
f, t uint64 | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
1253042677,6871726226,10 | ||
6871775001,1253042677,20 | ||
6871775003,6871775001,30 | ||
6871726248,6871775003,30 | ||
6871726238,6871744979,60 | ||
6871744979,6871744978,60 | ||
6871744978,6871744977,25 | ||
6871744977,6871744976,25 | ||
6871744976,6871744975,25 | ||
6871744975,6871744974,25 | ||
6871744974,6871744973,60 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
733690162,6871726238,6871744979,6871744978,6871744977,6871744976,6871744975,6871744974,6871744973 | ||
733689924,6871726226,1253042677,6871775001,6871775003,6871726248 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here might be some problem due to floating calculation. E.g., totally
11
nodes and3
segmented flows{Speed: 10, Begin: 0, End: 27},{Speed: 25, Begin: 28, End: 75},{Speed: 60, Begin: 76, End: 100}
on a way, and the segmented flows will be applied to node0~2
,3~8
,8~11
, but the2~3
is missed.To solve the problem, it might be better to sort the segmented flows of the way first, then adjust the nodes offset, i.e.
3~8
->2~8
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wangyoucao577 I got it. But maybe it is ok.
For example, if first
End
and secondBegin
have the same osm nodeID, the segments will be{Speed: 10, Begin: 0, End: 27}, {Speed: 20, Begin: 27, End: 75}
. It works for the same dataset on each side (traffic-updater and traffic-proxy).On the other hand, I could add this condition
But it will affect all segments i.e
8~11
->7~11
May be
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh! Maybe this issue will gone if we simply to make sure
next begin == last end
. I.e.,first segment:
{Speed: 10, Begin: 0, End: 27}
, then{Speed: 25, Begin: 27, End: 75}
instead of{Speed: 25, Begin: 28, End: 75}
as second segment(Begin: 28
->Begin: 27
).How's your opinion?