Add counties to output (% of ride spent in each county)
This commit is contained in:
parent
f0b45fd4c6
commit
340612e566
7 changed files with 47 additions and 24 deletions
1
.gitattributes
vendored
1
.gitattributes
vendored
|
@ -1 +1,2 @@
|
|||
*.bin filter=lfs diff=lfs merge=lfs -text
|
||||
pkg/placenames/data.go diff=nodiff
|
||||
|
|
|
@ -26,6 +26,7 @@ func main() {
|
|||
b := placenames.NamedBoundary{
|
||||
Name: r.Name,
|
||||
Type: r.LocalType,
|
||||
County: r.CountyUnitary,
|
||||
Xmin: r.MbrXMin,
|
||||
Ymin: r.MbrYMin,
|
||||
Xmax: r.MbrXMax,
|
||||
|
|
|
@ -36,7 +36,7 @@ type Record struct {
|
|||
DistrictBoroughUri string
|
||||
DistrictBoroughType string
|
||||
CountyUnitary string
|
||||
ConutyUnitaryUri string
|
||||
CountyUnitaryUri string
|
||||
CountyUnitaryType string
|
||||
Region string
|
||||
RegionUri string
|
||||
|
@ -143,7 +143,7 @@ func parseRecord(xs []string) (*Record, error) {
|
|||
DistrictBoroughUri: xs[22],
|
||||
DistrictBoroughType: xs[23],
|
||||
CountyUnitary: xs[24],
|
||||
ConutyUnitaryUri: xs[25],
|
||||
CountyUnitaryUri: xs[25],
|
||||
CountyUnitaryType: xs[26],
|
||||
Region: xs[27],
|
||||
RegionUri: xs[28],
|
||||
|
|
File diff suppressed because one or more lines are too long
BIN
pkg/placenames/placenames.bin
(Stored with Git LFS)
BIN
pkg/placenames/placenames.bin
(Stored with Git LFS)
Binary file not shown.
|
@ -14,6 +14,7 @@ import (
|
|||
type NamedBoundary struct {
|
||||
Name string
|
||||
Type string
|
||||
County string
|
||||
Xmin float64
|
||||
Ymin float64
|
||||
Xmax float64
|
||||
|
|
|
@ -84,6 +84,7 @@ type TrackSummary struct {
|
|||
Descent float64
|
||||
PointsOfInterest []POI
|
||||
RefreshmentStops []RefreshmentStop `json:",omitempty"`
|
||||
Counties map[string]int
|
||||
}
|
||||
|
||||
func (gs *GPXSummarizer) SummarizeTrack(r io.Reader, stops *rtreego.Rtree) (*TrackSummary, error) {
|
||||
|
@ -94,6 +95,7 @@ func (gs *GPXSummarizer) SummarizeTrack(r io.Reader, stops *rtreego.Rtree) (*Tra
|
|||
var s TrackSummary
|
||||
s.Name = g.Metadata.Name
|
||||
s.Time = g.Metadata.Time
|
||||
s.Counties = make(map[string]int)
|
||||
for _, l := range g.Metadata.Link {
|
||||
if strings.HasPrefix(l.HREF, "http") {
|
||||
s.Link = l.HREF
|
||||
|
@ -128,20 +130,23 @@ func (gs *GPXSummarizer) SummarizeTrack(r io.Reader, stops *rtreego.Rtree) (*Tra
|
|||
prevPlacePoint = thisPoint
|
||||
prevPoint = thisPoint
|
||||
s.PointsOfInterest = append(s.PointsOfInterest, POI{Name: nn.Name, Type: nn.Type, Distance: 0.0})
|
||||
s.Counties[nn.County]++
|
||||
init = false
|
||||
continue
|
||||
}
|
||||
s.Distance += distance(thisPoint, prevPoint)
|
||||
dE += thisPoint[0] - start[0]
|
||||
dN += thisPoint[1] - start[1]
|
||||
if nn.Contains(thisPoint) &&
|
||||
nn.Name != prevPlace &&
|
||||
if nn.Contains(thisPoint) {
|
||||
s.Counties[nn.County]++
|
||||
if nn.Name != prevPlace &&
|
||||
distance(thisPoint, prevPlacePoint) > gs.minDist &&
|
||||
populatedPlaceRank[nn.Type] >= gs.minSettlementRank {
|
||||
s.PointsOfInterest = append(s.PointsOfInterest, POI{Name: nn.Name, Type: nn.Type, Distance: s.Distance})
|
||||
prevPlace = nn.Name
|
||||
prevPlacePoint = thisPoint
|
||||
}
|
||||
}
|
||||
if stops != nil {
|
||||
stop, ok := stops.NearestNeighbor(thisPoint).(*cafes.RefreshmentStop)
|
||||
if ok && stop.Contains(thisPoint) && (prevStop == nil || stop.Name != prevStop.Name) {
|
||||
|
@ -160,9 +165,24 @@ func (gs *GPXSummarizer) SummarizeTrack(r io.Reader, stops *rtreego.Rtree) (*Tra
|
|||
s.Finish = prevPlace
|
||||
s.Direction = calcDirection(dE, dN)
|
||||
s.Ascent, s.Descent = calcUphillDownhill(elevations)
|
||||
s.Counties = toPercentages(s.Counties)
|
||||
return &s, nil
|
||||
}
|
||||
|
||||
func toPercentages(m map[string]int) map[string]int {
|
||||
t := 0
|
||||
for _, v := range m {
|
||||
t += v
|
||||
}
|
||||
for k, v := range m {
|
||||
m[k] = v * 100 / t
|
||||
if m[k] == 0 {
|
||||
delete(m, k)
|
||||
}
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
func calcDirection(dE, dN float64) string {
|
||||
if dN == 0 {
|
||||
if dE >= 0 {
|
||||
|
|
Loading…
Reference in a new issue