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

Refactor Oasis Ranker #321

Open
CodeBear801 opened this issue May 4, 2020 · 0 comments
Open

Refactor Oasis Ranker #321

CodeBear801 opened this issue May 4, 2020 · 0 comments
Labels
Refactor Rewrite existing code in order to improve its readability, reusability or structure

Comments

@CodeBear801
Copy link

CodeBear801 commented May 4, 2020

Current status:

  • Ranker provide two interface:
// Ranker used to ranking a group of points
type Ranker interface {

	// RankPointIDsByGreatCircleDistance ranks a group of points based on great circle distance to given location
	RankPointIDsByGreatCircleDistance(center Location, targets []*PointInfo) []*RankedPointInfo

	// RankPointIDsByShortestDistance ranks a group of points based on shortest path distance to given location
	RankPointIDsByShortestDistance(center Location, targets []*PointInfo) []*RankedPointInfo
}

There is factory to create different rankers:

// CreateRanker creates implementations of interface Ranker
func CreateRanker(rankerType string, oc *osrmconnector.OSRMConnector) spatialindexer.Ranker {
	switch rankerType {
	case SimpleRanker:
		return newSimpleRanker()
	case OSRMBasedRanker:
		return newOsrmRanker(oc)
	default:
		return newSimpleRanker()
	}
}
  • Adjust spatialindexer/interface.go
    // RankedPointInfo used to record ranking result to center point
    // Distance record distance from center point to current point
    // Duration records duration from center point to current point
type RankedPointInfo struct {
	PointInfo
	Distance float64
         // todo
        Duration float64
}

Target

  1. Just use one interface function
// Ranker used to ranking a group of points
type Ranker interface {

	// RankPointIDs ranks a group of points based on ranking strategy
	RankPointIDs(center Location, targets []*PointInfo) []*RankedPointInfo
}
  1. Refine names
// CreateRanker creates implementations of interface Ranker
func CreateRanker(rankerType string, oc *osrmconnector.OSRMConnector) spatialindexer.Ranker {
	switch rankerType {
	case GreatCircleDistanceBasedRanker:
		return newSimpleRanker()
	case ShortestpathBasedRanker:
		return newOsrmRanker(oc)
	default:
		return newSimpleRanker()
	}
}
@CodeBear801 CodeBear801 added the Refactor Rewrite existing code in order to improve its readability, reusability or structure label May 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Refactor Rewrite existing code in order to improve its readability, reusability or structure
Projects
None yet
Development

No branches or pull requests

1 participant