Add traffic records matched statistics and total processing time (#46)
* feat: statistics fwd and bwd traffic matched * fix: missed line wrap * feat: statistics osrm_traffic_updater processing time
This commit is contained in:
parent
c613b1737c
commit
a247e34ea4
@ -11,6 +11,8 @@ type dumperStatisticItems struct {
|
||||
bwdRecordCnt uint64
|
||||
wayMatchedCnt uint64
|
||||
nodeMatchedCnt uint64
|
||||
fwdTrafficMatchedCnt uint64
|
||||
bwdTrafficMatchedCnt uint64
|
||||
}
|
||||
|
||||
type dumperStatistic struct {
|
||||
@ -37,21 +39,24 @@ func (d* dumperStatistic) Close() {
|
||||
d.sum.bwdRecordCnt += item.bwdRecordCnt
|
||||
d.sum.wayMatchedCnt += item.wayMatchedCnt
|
||||
d.sum.nodeMatchedCnt += item.nodeMatchedCnt
|
||||
d.sum.fwdTrafficMatchedCnt += item.fwdTrafficMatchedCnt
|
||||
d.sum.bwdTrafficMatchedCnt += item.bwdTrafficMatchedCnt
|
||||
}
|
||||
d.close = true
|
||||
}
|
||||
|
||||
func (d* dumperStatistic) Sum() (dumperStatisticItems) {
|
||||
func (d *dumperStatistic) Sum() dumperStatisticItems {
|
||||
return d.sum
|
||||
}
|
||||
|
||||
func (d *dumperStatistic) Update(wayCnt uint64, nodeCnt uint64, fwdRecordCnt uint64,
|
||||
bwdRecordCnt uint64, wayMatchedCnt uint64, nodeMatchedCnt uint64) {
|
||||
bwdRecordCnt uint64, wayMatchedCnt uint64, nodeMatchedCnt uint64,
|
||||
fwdTrafficMatchedCnt uint64, bwdTrafficMatchedCnt uint64) {
|
||||
if !d.init {
|
||||
fmt.Printf("dumperStatistic->Update() failed, please call Init() first otherwise will block all functions. \n")
|
||||
return
|
||||
}
|
||||
d.c <- (dumperStatisticItems{wayCnt, nodeCnt, fwdRecordCnt, bwdRecordCnt, wayMatchedCnt, nodeMatchedCnt})
|
||||
d.c <- (dumperStatisticItems{wayCnt, nodeCnt, fwdRecordCnt, bwdRecordCnt, wayMatchedCnt, nodeMatchedCnt, fwdTrafficMatchedCnt, bwdTrafficMatchedCnt})
|
||||
}
|
||||
|
||||
func (d *dumperStatistic) Output() {
|
||||
@ -64,7 +69,8 @@ func (d* dumperStatistic) Output() {
|
||||
fmt.Printf("Load %d way from data with %d nodes.\n", d.sum.wayCnt, d.sum.nodeCnt)
|
||||
fmt.Printf("%d way with %d nodes matched with traffic record.\n",
|
||||
d.sum.wayMatchedCnt, d.sum.nodeMatchedCnt)
|
||||
fmt.Printf("%d traffic records(%d forward and %d backward) have been matched.\n",
|
||||
d.sum.fwdTrafficMatchedCnt+d.sum.bwdTrafficMatchedCnt, d.sum.fwdTrafficMatchedCnt, d.sum.bwdTrafficMatchedCnt)
|
||||
fmt.Printf("Generate %d records in final result with %d of them from forward traffic and %d from backword.\n",
|
||||
d.sum.fwdRecordCnt+d.sum.bwdRecordCnt, d.sum.fwdRecordCnt, d.sum.bwdRecordCnt)
|
||||
}
|
||||
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"sync"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestDumperStatistic(t *testing.T) {
|
||||
@ -26,7 +26,6 @@ func TestDumperStatistic(t *testing.T) {
|
||||
}
|
||||
|
||||
func accumulateDumper(d *dumperStatistic, wg *sync.WaitGroup) {
|
||||
d.Update(1,2,3,4,5,6)
|
||||
d.Update(1, 2, 3, 4, 5, 6, 7, 8)
|
||||
wg.Done()
|
||||
}
|
||||
|
||||
|
||||
@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
var flags struct {
|
||||
@ -27,6 +28,12 @@ const CACHEDOBJECTS = 4000000
|
||||
func main() {
|
||||
flag.Parse()
|
||||
|
||||
startTime := time.Now()
|
||||
defer func() {
|
||||
endTime := time.Now()
|
||||
fmt.Printf("Total processing time %f seconds\n", endTime.Sub(startTime).Seconds())
|
||||
}()
|
||||
|
||||
isFlowDoneChan := make(chan bool, 1)
|
||||
wayid2speed := make(map[int64]int)
|
||||
go getTrafficFlow(flags.ip, flags.port, wayid2speed, isFlowDoneChan)
|
||||
@ -46,7 +53,7 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
func wait4PreConditions(flowChan <-chan bool) (bool) {
|
||||
func wait4PreConditions(flowChan <-chan bool) bool {
|
||||
var isFlowDone bool
|
||||
loop:
|
||||
for {
|
||||
|
||||
@ -1,14 +1,14 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"log"
|
||||
"fmt"
|
||||
"bufio"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
"strings"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
var tasksWg sync.WaitGroup
|
||||
@ -52,7 +52,7 @@ func wait4AllTasksFinished(sink chan string, ds *dumperStatistic) {
|
||||
}
|
||||
|
||||
func task(wayid2speed map[int64]int, source <-chan string, sink chan<- string, ds *dumperStatistic) {
|
||||
var wayCnt, nodeCnt, fwdRecordCnt, bwdRecordCnt, wayMatched, nodeMatched uint64
|
||||
var wayCnt, nodeCnt, fwdRecordCnt, bwdRecordCnt, wayMatched, nodeMatched, fwdTrafficMatched, bwdTrafficMatched uint64
|
||||
var err error
|
||||
for str := range source {
|
||||
elements := strings.Split(str, ",")
|
||||
@ -75,6 +75,13 @@ func task(wayid2speed map[int64]int, source <-chan string, sink chan<- string, d
|
||||
var nodes []string = elements[1:]
|
||||
wayMatched += 1
|
||||
nodeMatched += (uint64)(len(nodes))
|
||||
if okFwd {
|
||||
fwdTrafficMatched += 1
|
||||
}
|
||||
if okBwd {
|
||||
bwdTrafficMatched += 1
|
||||
}
|
||||
|
||||
for i := 0; (i + 1) < len(nodes); i++ {
|
||||
var n1, n2 uint64
|
||||
if n1, err = strconv.ParseUint(nodes[i], 10, 64); err != nil {
|
||||
@ -98,14 +105,14 @@ func task(wayid2speed map[int64]int, source <-chan string, sink chan<- string, d
|
||||
}
|
||||
}
|
||||
|
||||
ds.Update(wayCnt, nodeCnt, fwdRecordCnt, bwdRecordCnt, wayMatched, nodeMatched)
|
||||
ds.Update(wayCnt, nodeCnt, fwdRecordCnt, bwdRecordCnt, wayMatched, nodeMatched, fwdTrafficMatched, bwdTrafficMatched)
|
||||
tasksWg.Done()
|
||||
}
|
||||
|
||||
// format
|
||||
// if dir = true, means traffic for forward, generate: from, to, speed
|
||||
// if dir = false, means this speed is for backward flow, generate: to, from, speed
|
||||
func generateSingleRecord(from, to uint64, speed int, dir bool) (string){
|
||||
func generateSingleRecord(from, to uint64, speed int, dir bool) string {
|
||||
if dir {
|
||||
return fmt.Sprintf("%d,%d,%d\n", from, to, speed)
|
||||
} else {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user