Skip to content

Commit

Permalink
feat: implement the tool of place connectivity generator.
Browse files Browse the repository at this point in the history
issue: #238
  • Loading branch information
CodeBear801 committed Apr 2, 2020
1 parent 4c65cb0 commit 6a6ef8d
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 3 deletions.
21 changes: 21 additions & 0 deletions integration/cmd/place-connectivity-gen/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Package main contains the tool of chargestation-connectivity generator
//
// stage 1:
// inputs is json file
// => convert to slice of [id:string,location: lat,lon]
// => calculate cellids for each point(for all levels)
// => build revese index for cellID -> ids
//
// stage 2:
// => iterate each point
// => generate a circle(s2::cap), find all cellids intersect with that circle
// => retrieve all ids
// => generate result of id(from), ids(all ids in certain distance)
//
// stage 3:
// => load data from file
// => for each line, its formid and all other ids
// => calculate distance between fromid and all other ids
// => sort result based on distance and write back to file
//
package main
13 changes: 13 additions & 0 deletions integration/cmd/place-connectivity-gen/flags.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package main

import "flag"

var flags struct {
inputPath string
outputFolder string
}

func init() {
flag.StringVar(&flags.inputPath, "i", "", "path for input file in json format")
flag.StringVar(&flags.outputFolder, "o", "", "path for output folder")
}
10 changes: 10 additions & 0 deletions integration/cmd/place-connectivity-gen/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package main

import (
"fmt"
)

func main() {
// @todo: add logic to generate connectivity for charge stations
fmt.Print("Hello World!")
}
26 changes: 23 additions & 3 deletions integration/service/connectivitymap/connectivity_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,36 @@ func NewConnectivityMap(maxRange float64) *ConnectivityMap {
}

// Build creates ConnectivityMap
func (cm *ConnectivityMap) Build() {
glog.Info("Successfully finished GenerateConnectivityMap\n")
func (cm *ConnectivityMap) Build(iterator spatialindexer.PointsIterator, finder spatialindexer.Finder,
ranker spatialindexer.Ranker, numOfWorkers int) *ConnectivityMap {
cm.id2nearByIDs = newConnectivityMapBuilder(iterator, finder, ranker, cm.maxRange, numOfWorkers).build()
cm.statistic = cm.statistic.build(cm.id2nearByIDs, cm.maxRange)

glog.Info("Successfully finished Build ConnectivityMap\n")
return cm
}

// Dump dump ConnectivityMap's content to given folderPath
func (cm *ConnectivityMap) Dump(folderPath string) {
if err := removeAllDumpFiles(folderPath); err != nil {
glog.Fatalf("removeAllDumpFiles for ConnectivityMap failed with error %+v\n", err)
}

if err := serializeConnectivityMap(cm, folderPath); err != nil {
glog.Fatalf("serializeConnectivityMap failed with error %+v\n", err)
}

glog.Infof("Successfully finished Dump ConnectivityMap to %s\n", folderPath)
}

// Load rebuild ConnectivityMap from dumpped data in given folderPath
func (cm *ConnectivityMap) Load(folderPath string) {
func (cm *ConnectivityMap) Load(folderPath string) *ConnectivityMap {
if err := deSerializeConnectivityMap(cm, folderPath); err != nil {
glog.Fatalf("deSerializeConnectivityMap failed with error %+v\n", err)
}

glog.Infof("Successfully finished Load ConnectivityMap from %s\n", folderPath)
return cm
}

// QueryConnectivity answers connectivity query for given placeInfo
Expand Down

0 comments on commit 6a6ef8d

Please sign in to comment.