Skip to content
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

Feature/refine proxy proto #179

Merged
merged 16 commits into from
Feb 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions integration/cmd/osrm-traffic-updater/osrm_traffic_updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"log"
"time"

proxy "github.com/Telenav/osrm-backend/integration/pkg/trafficproxy"
"github.com/Telenav/osrm-backend/integration/pkg/trafficproxy"
"github.com/Telenav/osrm-backend/integration/pkg/trafficproxyclient"
"github.com/golang/glog"
)
Expand Down Expand Up @@ -83,7 +83,7 @@ loop:
return isFlowDone
}

func trafficData2map(trafficData proxy.TrafficResponse, m map[int64]int) {
func trafficData2map(trafficData trafficproxy.TrafficResponse, m map[int64]int) {
startTime := time.Now()
defer func() {
log.Printf("Processing time for building traffic map takes %f seconds\n", time.Now().Sub(startTime).Seconds())
Expand All @@ -100,7 +100,7 @@ func trafficData2map(trafficData proxy.TrafficResponse, m map[int64]int) {
}
}

wayid := flow.Flow.WayId
wayid := flow.Flow.WayID
m[wayid] = int(flow.Flow.Speed)

if wayid > 0 {
Expand All @@ -114,9 +114,9 @@ func trafficData2map(trafficData proxy.TrafficResponse, m map[int64]int) {
for _, incident := range trafficData.IncidentResponses {
if incident.Incident.IsBlocking { // only use blocking incidents
blockingIncidentCnt++
blockingIncidentAffectedWaysCnt += int64(len(incident.Incident.AffectedWayIds))
blockingIncidentAffectedWaysCnt += int64(len(incident.Incident.AffectedWayIDs))

for _, wayid := range incident.Incident.AffectedWayIds {
for _, wayid := range incident.Incident.AffectedWayIDs {
m[wayid] = 0

if wayid > 0 {
Expand Down
4 changes: 2 additions & 2 deletions integration/cmd/trafficproxy-cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"flag"

proxy "github.com/Telenav/osrm-backend/integration/pkg/trafficproxy"
"github.com/Telenav/osrm-backend/integration/pkg/trafficproxy"
"github.com/Telenav/osrm-backend/integration/pkg/trafficproxyclient"
"github.com/Telenav/osrm-backend/integration/trafficdumper"
"github.com/golang/glog"
Expand Down Expand Up @@ -51,7 +51,7 @@ func main() {
return
} else if flags.rpcMode == rpcModeStreamingDelta {

responseChan := make(chan proxy.TrafficResponse)
responseChan := make(chan trafficproxy.TrafficResponse)
waitChan := make(chan struct{})

// async startup dumper
Expand Down
4 changes: 2 additions & 2 deletions integration/pkg/trafficeater/interface.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package trafficeater

import proxy "github.com/Telenav/osrm-backend/integration/pkg/trafficproxy"
import "github.com/Telenav/osrm-backend/integration/pkg/trafficproxy"

// Eater is the interface that wraps the basic Eat method.
type Eater interface {

// Eat consumes traffic responses.
Eat(proxy.TrafficResponse)
Eat(trafficproxy.TrafficResponse)
}
23 changes: 12 additions & 11 deletions integration/pkg/trafficproxy/csv_string_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package proxy
package trafficproxy

import "testing"

Expand All @@ -10,14 +10,14 @@ func TestFlowCSVString(t *testing.T) {
humanFriendlyCSVString string
}{
{
Flow{WayId: 829733412, Speed: 20.280001, TrafficLevel: TrafficLevel_FREE_FLOW},
"829733412,20.280001,7",
"829733412,20.280001,FREE_FLOW",
Flow{WayID: 829733412, Speed: 20.280001, TrafficLevel: TrafficLevel_FREE_FLOW, Timestamp: 1579419488000},
"829733412,20.280001,7,1579419488000",
"829733412,20.280001,FREE_FLOW,1579419488000",
},
{
Flow{WayId: -129639168, Speed: 31.389999, TrafficLevel: TrafficLevel_FREE_FLOW},
"-129639168,31.389999,7",
"-129639168,31.389999,FREE_FLOW",
Flow{WayID: -129639168, Speed: 31.389999, TrafficLevel: TrafficLevel_FREE_FLOW, Timestamp: 1579419488000},
"-129639168,31.389999,7,1579419488000",
"-129639168,31.389999,FREE_FLOW,1579419488000",
},
}

Expand All @@ -44,8 +44,8 @@ func TestIncidentCSVString(t *testing.T) {
}{
{
Incident{
IncidentId: "TTI-f47b8dba-59a3-372d-9cec-549eb252e2d5-TTR46312939215361-1",
AffectedWayIds: []int64{100663296, -1204020275, 100663296, -1204020274, 100663296, -916744017, 100663296, -1204020245, 100663296, -1194204646, 100663296, -1204394608, 100663296, -1194204647, 100663296, -129639168, 100663296, -1194204645},
IncidentID: "TTI-f47b8dba-59a3-372d-9cec-549eb252e2d5-TTR46312939215361-1",
AffectedWayIDs: []int64{100663296, -1204020275, 100663296, -1204020274, 100663296, -916744017, 100663296, -1204020245, 100663296, -1194204646, 100663296, -1204394608, 100663296, -1194204647, 100663296, -129639168, 100663296, -1194204645},
IncidentType: IncidentType_MISCELLANEOUS,
IncidentSeverity: IncidentSeverity_CRITICAL,
IncidentLocation: &Location{Lat: 44.181220, Lon: -117.135840},
Expand All @@ -56,9 +56,10 @@ func TestIncidentCSVString(t *testing.T) {
EventCode: 500,
AlertCEventQuantifier: 0,
IsBlocking: false,
Timestamp: 1579419488000,
},
"TTI-f47b8dba-59a3-372d-9cec-549eb252e2d5-TTR46312939215361-1,\"100663296,-1204020275,100663296,-1204020274,100663296,-916744017,100663296,-1204020245,100663296,-1194204646,100663296,-1204394608,100663296,-1194204647,100663296,-129639168,100663296,-1194204645\",5,1,44.181220,-117.135840,\"Construction on I-84 EB near MP 359, Drive with caution.\",,,I-84 E,500,0,0",
"TTI-f47b8dba-59a3-372d-9cec-549eb252e2d5-TTR46312939215361-1,\"100663296,-1204020275,100663296,-1204020274,100663296,-916744017,100663296,-1204020245,100663296,-1194204646,100663296,-1204394608,100663296,-1194204647,100663296,-129639168,100663296,-1194204645\",MISCELLANEOUS,CRITICAL,44.181220,-117.135840,\"Construction on I-84 EB near MP 359, Drive with caution.\",,,I-84 E,500,0,false",
"TTI-f47b8dba-59a3-372d-9cec-549eb252e2d5-TTR46312939215361-1,\"100663296,-1204020275,100663296,-1204020274,100663296,-916744017,100663296,-1204020245,100663296,-1194204646,100663296,-1204394608,100663296,-1194204647,100663296,-129639168,100663296,-1194204645\",5,1,44.181220,-117.135840,\"Construction on I-84 EB near MP 359, Drive with caution.\",,,I-84 E,500,0,0,1579419488000",
"TTI-f47b8dba-59a3-372d-9cec-549eb252e2d5-TTR46312939215361-1,\"100663296,-1204020275,100663296,-1204020274,100663296,-916744017,100663296,-1204020245,100663296,-1194204646,100663296,-1204394608,100663296,-1194204647,100663296,-129639168,100663296,-1194204645\",MISCELLANEOUS,CRITICAL,44.181220,-117.135840,\"Construction on I-84 EB near MP 359, Drive with caution.\",,,I-84 E,500,0,false,1579419488000",
},
}

Expand Down
14 changes: 6 additions & 8 deletions integration/pkg/trafficproxy/flow_extension.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
package proxy
package trafficproxy

import "fmt"

const blockingSpeedThreshold = 1 // Think it's blocking if flow speed smaller than this threshold.

// IsBlocking tests whether the Flow is blocking or not.
// This function extends protoc-gen-go generated code on testing whether is blocking for Flow.
func (f *Flow) IsBlocking() bool {

return f.TrafficLevel == TrafficLevel_CLOSED || f.Speed < blockingSpeedThreshold
return f.TrafficLevel == TrafficLevel_CLOSED
}

// CSVString represents Flow as defined CSV format.
// I.e. 'wayID,Speed,TrafficLevel'
// I.e. 'wayID,Speed,TrafficLevel,Timestamp'
func (f *Flow) CSVString() string {
return fmt.Sprintf("%d,%f,%d", f.WayId, f.Speed, f.TrafficLevel)
return fmt.Sprintf("%d,%f,%d,%d", f.WayID, f.Speed, f.TrafficLevel, f.Timestamp)
}

// HumanFriendlyCSVString represents Flow as defined CSV format, but prefer human friendly string instead of integer.
// I.e. 'wayID,Speed,TrafficLevel'
// I.e. 'wayID,Speed,TrafficLevel,Timestamp'
func (f *Flow) HumanFriendlyCSVString() string {
return fmt.Sprintf("%d,%f,%s", f.WayId, f.Speed, f.TrafficLevel)
return fmt.Sprintf("%d,%f,%s,%d", f.WayID, f.Speed, f.TrafficLevel, f.Timestamp)
}
8 changes: 5 additions & 3 deletions integration/pkg/trafficproxy/incident_extension.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package proxy
package trafficproxy

import (
"bytes"
Expand All @@ -20,10 +20,10 @@ func (i *Incident) HumanFriendlyCSVString() string {

func (i *Incident) csvString(humanFriendly bool) string {
records := []string{}
records = append(records, i.IncidentId)
records = append(records, i.IncidentID)

affectedWayIDsString := []string{}
for _, wayID := range i.AffectedWayIds {
for _, wayID := range i.AffectedWayIDs {
affectedWayIDsString = append(affectedWayIDsString, strconv.FormatInt(wayID, 10))
}
records = append(records, strings.Join(affectedWayIDsString, ","))
Expand Down Expand Up @@ -53,6 +53,8 @@ func (i *Incident) csvString(humanFriendly bool) string {
records = append(records, strconv.Itoa(isBlockingInteger))
}

records = append(records, strconv.Itoa(int(i.Timestamp)))

var buff bytes.Buffer
w := csv.NewWriter(&buff)
w.UseCRLF = false
Expand Down
Loading