mirror of
https://github.com/dolthub/dolt.git
synced 2026-01-31 03:18:43 -06:00
Regroup common code.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
package main
|
||||
package common
|
||||
|
||||
import (
|
||||
"math"
|
||||
@@ -1,13 +1,13 @@
|
||||
// This file was generated by nomdl/codegen.
|
||||
|
||||
package main
|
||||
package common
|
||||
|
||||
import (
|
||||
"github.com/attic-labs/noms/ref"
|
||||
"github.com/attic-labs/noms/types"
|
||||
)
|
||||
|
||||
var __mainPackageInFile_sha1_6d5e1c5_CachedRef ref.Ref
|
||||
var __commonPackageInFile_geo_CachedRef ref.Ref
|
||||
|
||||
// This function builds up a Noms value that describes the type
|
||||
// package implemented by this file and registers it with the global
|
||||
@@ -29,7 +29,7 @@ func init() {
|
||||
types.Choices{},
|
||||
),
|
||||
}, []ref.Ref{})
|
||||
__mainPackageInFile_sha1_6d5e1c5_CachedRef = types.RegisterPackage(&p)
|
||||
__commonPackageInFile_geo_CachedRef = types.RegisterPackage(&p)
|
||||
}
|
||||
|
||||
// Geoposition
|
||||
@@ -72,7 +72,7 @@ func (m Geoposition) TypeRef() types.TypeRef {
|
||||
}
|
||||
|
||||
func init() {
|
||||
__typeRefForGeoposition = types.MakeTypeRef(__mainPackageInFile_sha1_6d5e1c5_CachedRef, 0)
|
||||
__typeRefForGeoposition = types.MakeTypeRef(__commonPackageInFile_geo_CachedRef, 0)
|
||||
types.RegisterFromValFunction(__typeRefForGeoposition, func(v types.Value) types.Value {
|
||||
return GeopositionFromVal(v)
|
||||
})
|
||||
@@ -164,7 +164,7 @@ func (m Georectangle) TypeRef() types.TypeRef {
|
||||
}
|
||||
|
||||
func init() {
|
||||
__typeRefForGeorectangle = types.MakeTypeRef(__mainPackageInFile_sha1_6d5e1c5_CachedRef, 1)
|
||||
__typeRefForGeorectangle = types.MakeTypeRef(__commonPackageInFile_geo_CachedRef, 1)
|
||||
types.RegisterFromValFunction(__typeRefForGeorectangle, func(v types.Value) types.Value {
|
||||
return GeorectangleFromVal(v)
|
||||
})
|
||||
@@ -1,4 +1,4 @@
|
||||
package main
|
||||
package common
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
17
clients/common/incident.noms
Normal file
17
clients/common/incident.noms
Normal file
@@ -0,0 +1,17 @@
|
||||
alias geo = import "geo.noms"
|
||||
|
||||
struct Incident {
|
||||
ID: Int64
|
||||
Category: String
|
||||
Description: String
|
||||
DayOfWeek: String
|
||||
Date: String
|
||||
Time: String
|
||||
PdDistrict: String
|
||||
Resolution: String
|
||||
Address: String
|
||||
Geoposition: geo.Geoposition
|
||||
PdID: String
|
||||
}
|
||||
|
||||
using List(Ref(Incident))
|
||||
443
clients/common/incident.noms.go
Normal file
443
clients/common/incident.noms.go
Normal file
@@ -0,0 +1,443 @@
|
||||
// This file was generated by nomdl/codegen.
|
||||
|
||||
package common
|
||||
|
||||
import (
|
||||
"github.com/attic-labs/noms/chunks"
|
||||
"github.com/attic-labs/noms/ref"
|
||||
"github.com/attic-labs/noms/types"
|
||||
)
|
||||
|
||||
var __commonPackageInFile_incident_CachedRef ref.Ref
|
||||
|
||||
// This function builds up a Noms value that describes the type
|
||||
// package implemented by this file and registers it with the global
|
||||
// type package definition cache.
|
||||
func init() {
|
||||
p := types.NewPackage([]types.TypeRef{
|
||||
types.MakeStructTypeRef("Incident",
|
||||
[]types.Field{
|
||||
types.Field{"ID", types.MakePrimitiveTypeRef(types.Int64Kind), false},
|
||||
types.Field{"Category", types.MakePrimitiveTypeRef(types.StringKind), false},
|
||||
types.Field{"Description", types.MakePrimitiveTypeRef(types.StringKind), false},
|
||||
types.Field{"DayOfWeek", types.MakePrimitiveTypeRef(types.StringKind), false},
|
||||
types.Field{"Date", types.MakePrimitiveTypeRef(types.StringKind), false},
|
||||
types.Field{"Time", types.MakePrimitiveTypeRef(types.StringKind), false},
|
||||
types.Field{"PdDistrict", types.MakePrimitiveTypeRef(types.StringKind), false},
|
||||
types.Field{"Resolution", types.MakePrimitiveTypeRef(types.StringKind), false},
|
||||
types.Field{"Address", types.MakePrimitiveTypeRef(types.StringKind), false},
|
||||
types.Field{"Geoposition", types.MakeTypeRef(ref.Parse("sha1-6d5e1c54214264058be9f61f4b4ece0368c8c678"), 0), false},
|
||||
types.Field{"PdID", types.MakePrimitiveTypeRef(types.StringKind), false},
|
||||
},
|
||||
types.Choices{},
|
||||
),
|
||||
}, []ref.Ref{
|
||||
ref.Parse("sha1-6d5e1c54214264058be9f61f4b4ece0368c8c678"),
|
||||
})
|
||||
__commonPackageInFile_incident_CachedRef = types.RegisterPackage(&p)
|
||||
}
|
||||
|
||||
// Incident
|
||||
|
||||
type Incident struct {
|
||||
m types.Map
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
func NewIncident() Incident {
|
||||
return Incident{types.NewMap(
|
||||
types.NewString("ID"), types.Int64(0),
|
||||
types.NewString("Category"), types.NewString(""),
|
||||
types.NewString("Description"), types.NewString(""),
|
||||
types.NewString("DayOfWeek"), types.NewString(""),
|
||||
types.NewString("Date"), types.NewString(""),
|
||||
types.NewString("Time"), types.NewString(""),
|
||||
types.NewString("PdDistrict"), types.NewString(""),
|
||||
types.NewString("Resolution"), types.NewString(""),
|
||||
types.NewString("Address"), types.NewString(""),
|
||||
types.NewString("Geoposition"), NewGeoposition(),
|
||||
types.NewString("PdID"), types.NewString(""),
|
||||
), &ref.Ref{}}
|
||||
}
|
||||
|
||||
type IncidentDef struct {
|
||||
ID int64
|
||||
Category string
|
||||
Description string
|
||||
DayOfWeek string
|
||||
Date string
|
||||
Time string
|
||||
PdDistrict string
|
||||
Resolution string
|
||||
Address string
|
||||
Geoposition GeopositionDef
|
||||
PdID string
|
||||
}
|
||||
|
||||
func (def IncidentDef) New() Incident {
|
||||
return Incident{
|
||||
types.NewMap(
|
||||
types.NewString("ID"), types.Int64(def.ID),
|
||||
types.NewString("Category"), types.NewString(def.Category),
|
||||
types.NewString("Description"), types.NewString(def.Description),
|
||||
types.NewString("DayOfWeek"), types.NewString(def.DayOfWeek),
|
||||
types.NewString("Date"), types.NewString(def.Date),
|
||||
types.NewString("Time"), types.NewString(def.Time),
|
||||
types.NewString("PdDistrict"), types.NewString(def.PdDistrict),
|
||||
types.NewString("Resolution"), types.NewString(def.Resolution),
|
||||
types.NewString("Address"), types.NewString(def.Address),
|
||||
types.NewString("Geoposition"), def.Geoposition.New(),
|
||||
types.NewString("PdID"), types.NewString(def.PdID),
|
||||
), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s Incident) Def() (d IncidentDef) {
|
||||
d.ID = int64(s.m.Get(types.NewString("ID")).(types.Int64))
|
||||
d.Category = s.m.Get(types.NewString("Category")).(types.String).String()
|
||||
d.Description = s.m.Get(types.NewString("Description")).(types.String).String()
|
||||
d.DayOfWeek = s.m.Get(types.NewString("DayOfWeek")).(types.String).String()
|
||||
d.Date = s.m.Get(types.NewString("Date")).(types.String).String()
|
||||
d.Time = s.m.Get(types.NewString("Time")).(types.String).String()
|
||||
d.PdDistrict = s.m.Get(types.NewString("PdDistrict")).(types.String).String()
|
||||
d.Resolution = s.m.Get(types.NewString("Resolution")).(types.String).String()
|
||||
d.Address = s.m.Get(types.NewString("Address")).(types.String).String()
|
||||
d.Geoposition = s.m.Get(types.NewString("Geoposition")).(Geoposition).Def()
|
||||
d.PdID = s.m.Get(types.NewString("PdID")).(types.String).String()
|
||||
return
|
||||
}
|
||||
|
||||
var __typeRefForIncident types.TypeRef
|
||||
|
||||
func (m Incident) TypeRef() types.TypeRef {
|
||||
return __typeRefForIncident
|
||||
}
|
||||
|
||||
func init() {
|
||||
__typeRefForIncident = types.MakeTypeRef(__commonPackageInFile_incident_CachedRef, 0)
|
||||
types.RegisterFromValFunction(__typeRefForIncident, func(v types.Value) types.Value {
|
||||
return IncidentFromVal(v)
|
||||
})
|
||||
}
|
||||
|
||||
func IncidentFromVal(val types.Value) Incident {
|
||||
// TODO: Do we still need FromVal?
|
||||
if val, ok := val.(Incident); ok {
|
||||
return val
|
||||
}
|
||||
// TODO: Validate here
|
||||
return Incident{val.(types.Map), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s Incident) InternalImplementation() types.Map {
|
||||
return s.m
|
||||
}
|
||||
|
||||
func (s Incident) Equals(other types.Value) bool {
|
||||
if other, ok := other.(Incident); ok {
|
||||
return s.Ref() == other.Ref()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (s Incident) Ref() ref.Ref {
|
||||
return types.EnsureRef(s.ref, s)
|
||||
}
|
||||
|
||||
func (s Incident) Chunks() (chunks []ref.Ref) {
|
||||
chunks = append(chunks, s.TypeRef().Chunks()...)
|
||||
chunks = append(chunks, s.m.Chunks()...)
|
||||
return
|
||||
}
|
||||
|
||||
func (s Incident) ID() int64 {
|
||||
return int64(s.m.Get(types.NewString("ID")).(types.Int64))
|
||||
}
|
||||
|
||||
func (s Incident) SetID(val int64) Incident {
|
||||
return Incident{s.m.Set(types.NewString("ID"), types.Int64(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s Incident) Category() string {
|
||||
return s.m.Get(types.NewString("Category")).(types.String).String()
|
||||
}
|
||||
|
||||
func (s Incident) SetCategory(val string) Incident {
|
||||
return Incident{s.m.Set(types.NewString("Category"), types.NewString(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s Incident) Description() string {
|
||||
return s.m.Get(types.NewString("Description")).(types.String).String()
|
||||
}
|
||||
|
||||
func (s Incident) SetDescription(val string) Incident {
|
||||
return Incident{s.m.Set(types.NewString("Description"), types.NewString(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s Incident) DayOfWeek() string {
|
||||
return s.m.Get(types.NewString("DayOfWeek")).(types.String).String()
|
||||
}
|
||||
|
||||
func (s Incident) SetDayOfWeek(val string) Incident {
|
||||
return Incident{s.m.Set(types.NewString("DayOfWeek"), types.NewString(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s Incident) Date() string {
|
||||
return s.m.Get(types.NewString("Date")).(types.String).String()
|
||||
}
|
||||
|
||||
func (s Incident) SetDate(val string) Incident {
|
||||
return Incident{s.m.Set(types.NewString("Date"), types.NewString(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s Incident) Time() string {
|
||||
return s.m.Get(types.NewString("Time")).(types.String).String()
|
||||
}
|
||||
|
||||
func (s Incident) SetTime(val string) Incident {
|
||||
return Incident{s.m.Set(types.NewString("Time"), types.NewString(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s Incident) PdDistrict() string {
|
||||
return s.m.Get(types.NewString("PdDistrict")).(types.String).String()
|
||||
}
|
||||
|
||||
func (s Incident) SetPdDistrict(val string) Incident {
|
||||
return Incident{s.m.Set(types.NewString("PdDistrict"), types.NewString(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s Incident) Resolution() string {
|
||||
return s.m.Get(types.NewString("Resolution")).(types.String).String()
|
||||
}
|
||||
|
||||
func (s Incident) SetResolution(val string) Incident {
|
||||
return Incident{s.m.Set(types.NewString("Resolution"), types.NewString(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s Incident) Address() string {
|
||||
return s.m.Get(types.NewString("Address")).(types.String).String()
|
||||
}
|
||||
|
||||
func (s Incident) SetAddress(val string) Incident {
|
||||
return Incident{s.m.Set(types.NewString("Address"), types.NewString(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s Incident) Geoposition() Geoposition {
|
||||
return s.m.Get(types.NewString("Geoposition")).(Geoposition)
|
||||
}
|
||||
|
||||
func (s Incident) SetGeoposition(val Geoposition) Incident {
|
||||
return Incident{s.m.Set(types.NewString("Geoposition"), val), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s Incident) PdID() string {
|
||||
return s.m.Get(types.NewString("PdID")).(types.String).String()
|
||||
}
|
||||
|
||||
func (s Incident) SetPdID(val string) Incident {
|
||||
return Incident{s.m.Set(types.NewString("PdID"), types.NewString(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
// ListOfRefOfIncident
|
||||
|
||||
type ListOfRefOfIncident struct {
|
||||
l types.List
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
func NewListOfRefOfIncident() ListOfRefOfIncident {
|
||||
return ListOfRefOfIncident{types.NewList(), &ref.Ref{}}
|
||||
}
|
||||
|
||||
type ListOfRefOfIncidentDef []ref.Ref
|
||||
|
||||
func (def ListOfRefOfIncidentDef) New() ListOfRefOfIncident {
|
||||
l := make([]types.Value, len(def))
|
||||
for i, d := range def {
|
||||
l[i] = NewRefOfIncident(d)
|
||||
}
|
||||
return ListOfRefOfIncident{types.NewList(l...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfRefOfIncident) Def() ListOfRefOfIncidentDef {
|
||||
d := make([]ref.Ref, l.Len())
|
||||
for i := uint64(0); i < l.Len(); i++ {
|
||||
d[i] = l.l.Get(i).(RefOfIncident).TargetRef()
|
||||
}
|
||||
return d
|
||||
}
|
||||
|
||||
func ListOfRefOfIncidentFromVal(val types.Value) ListOfRefOfIncident {
|
||||
// TODO: Do we still need FromVal?
|
||||
if val, ok := val.(ListOfRefOfIncident); ok {
|
||||
return val
|
||||
}
|
||||
// TODO: Validate here
|
||||
return ListOfRefOfIncident{val.(types.List), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfRefOfIncident) InternalImplementation() types.List {
|
||||
return l.l
|
||||
}
|
||||
|
||||
func (l ListOfRefOfIncident) Equals(other types.Value) bool {
|
||||
if other, ok := other.(ListOfRefOfIncident); ok {
|
||||
return l.Ref() == other.Ref()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (l ListOfRefOfIncident) Ref() ref.Ref {
|
||||
return types.EnsureRef(l.ref, l)
|
||||
}
|
||||
|
||||
func (l ListOfRefOfIncident) Chunks() (chunks []ref.Ref) {
|
||||
chunks = append(chunks, l.TypeRef().Chunks()...)
|
||||
chunks = append(chunks, l.l.Chunks()...)
|
||||
return
|
||||
}
|
||||
|
||||
// A Noms Value that describes ListOfRefOfIncident.
|
||||
var __typeRefForListOfRefOfIncident types.TypeRef
|
||||
|
||||
func (m ListOfRefOfIncident) TypeRef() types.TypeRef {
|
||||
return __typeRefForListOfRefOfIncident
|
||||
}
|
||||
|
||||
func init() {
|
||||
__typeRefForListOfRefOfIncident = types.MakeCompoundTypeRef(types.ListKind, types.MakeCompoundTypeRef(types.RefKind, types.MakeTypeRef(__commonPackageInFile_incident_CachedRef, 0)))
|
||||
types.RegisterFromValFunction(__typeRefForListOfRefOfIncident, func(v types.Value) types.Value {
|
||||
return ListOfRefOfIncidentFromVal(v)
|
||||
})
|
||||
}
|
||||
|
||||
func (l ListOfRefOfIncident) Len() uint64 {
|
||||
return l.l.Len()
|
||||
}
|
||||
|
||||
func (l ListOfRefOfIncident) Empty() bool {
|
||||
return l.Len() == uint64(0)
|
||||
}
|
||||
|
||||
func (l ListOfRefOfIncident) Get(i uint64) RefOfIncident {
|
||||
return l.l.Get(i).(RefOfIncident)
|
||||
}
|
||||
|
||||
func (l ListOfRefOfIncident) Slice(idx uint64, end uint64) ListOfRefOfIncident {
|
||||
return ListOfRefOfIncident{l.l.Slice(idx, end), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfRefOfIncident) Set(i uint64, val RefOfIncident) ListOfRefOfIncident {
|
||||
return ListOfRefOfIncident{l.l.Set(i, val), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfRefOfIncident) Append(v ...RefOfIncident) ListOfRefOfIncident {
|
||||
return ListOfRefOfIncident{l.l.Append(l.fromElemSlice(v)...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfRefOfIncident) Insert(idx uint64, v ...RefOfIncident) ListOfRefOfIncident {
|
||||
return ListOfRefOfIncident{l.l.Insert(idx, l.fromElemSlice(v)...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfRefOfIncident) Remove(idx uint64, end uint64) ListOfRefOfIncident {
|
||||
return ListOfRefOfIncident{l.l.Remove(idx, end), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfRefOfIncident) RemoveAt(idx uint64) ListOfRefOfIncident {
|
||||
return ListOfRefOfIncident{(l.l.RemoveAt(idx)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (l ListOfRefOfIncident) fromElemSlice(p []RefOfIncident) []types.Value {
|
||||
r := make([]types.Value, len(p))
|
||||
for i, v := range p {
|
||||
r[i] = v
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
type ListOfRefOfIncidentIterCallback func(v RefOfIncident, i uint64) (stop bool)
|
||||
|
||||
func (l ListOfRefOfIncident) Iter(cb ListOfRefOfIncidentIterCallback) {
|
||||
l.l.Iter(func(v types.Value, i uint64) bool {
|
||||
return cb(v.(RefOfIncident), i)
|
||||
})
|
||||
}
|
||||
|
||||
type ListOfRefOfIncidentIterAllCallback func(v RefOfIncident, i uint64)
|
||||
|
||||
func (l ListOfRefOfIncident) IterAll(cb ListOfRefOfIncidentIterAllCallback) {
|
||||
l.l.IterAll(func(v types.Value, i uint64) {
|
||||
cb(v.(RefOfIncident), i)
|
||||
})
|
||||
}
|
||||
|
||||
type ListOfRefOfIncidentFilterCallback func(v RefOfIncident, i uint64) (keep bool)
|
||||
|
||||
func (l ListOfRefOfIncident) Filter(cb ListOfRefOfIncidentFilterCallback) ListOfRefOfIncident {
|
||||
nl := NewListOfRefOfIncident()
|
||||
l.IterAll(func(v RefOfIncident, i uint64) {
|
||||
if cb(v, i) {
|
||||
nl = nl.Append(v)
|
||||
}
|
||||
})
|
||||
return nl
|
||||
}
|
||||
|
||||
// RefOfIncident
|
||||
|
||||
type RefOfIncident struct {
|
||||
target ref.Ref
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
func NewRefOfIncident(target ref.Ref) RefOfIncident {
|
||||
return RefOfIncident{target, &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (r RefOfIncident) TargetRef() ref.Ref {
|
||||
return r.target
|
||||
}
|
||||
|
||||
func (r RefOfIncident) Ref() ref.Ref {
|
||||
return types.EnsureRef(r.ref, r)
|
||||
}
|
||||
|
||||
func (r RefOfIncident) Equals(other types.Value) bool {
|
||||
if other, ok := other.(RefOfIncident); ok {
|
||||
return r.Ref() == other.Ref()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (r RefOfIncident) Chunks() []ref.Ref {
|
||||
return r.TypeRef().Chunks()
|
||||
}
|
||||
|
||||
func RefOfIncidentFromVal(val types.Value) RefOfIncident {
|
||||
// TODO: Do we still need FromVal?
|
||||
if val, ok := val.(RefOfIncident); ok {
|
||||
return val
|
||||
}
|
||||
return NewRefOfIncident(val.(types.Ref).TargetRef())
|
||||
}
|
||||
|
||||
// A Noms Value that describes RefOfIncident.
|
||||
var __typeRefForRefOfIncident types.TypeRef
|
||||
|
||||
func (m RefOfIncident) TypeRef() types.TypeRef {
|
||||
return __typeRefForRefOfIncident
|
||||
}
|
||||
|
||||
func init() {
|
||||
__typeRefForRefOfIncident = types.MakeCompoundTypeRef(types.RefKind, types.MakeTypeRef(__commonPackageInFile_incident_CachedRef, 0))
|
||||
types.RegisterFromValFunction(__typeRefForRefOfIncident, func(v types.Value) types.Value {
|
||||
return RefOfIncidentFromVal(v)
|
||||
})
|
||||
}
|
||||
|
||||
func (r RefOfIncident) TargetValue(cs chunks.ChunkSource) Incident {
|
||||
return types.ReadValue(r.target, cs).(Incident)
|
||||
}
|
||||
|
||||
func (r RefOfIncident) SetTargetValue(val Incident, cs chunks.ChunkSink) RefOfIncident {
|
||||
return NewRefOfIncident(types.WriteValue(val, cs))
|
||||
}
|
||||
558
clients/common/photo.noms.go
Normal file
558
clients/common/photo.noms.go
Normal file
@@ -0,0 +1,558 @@
|
||||
// This file was generated by nomdl/codegen.
|
||||
|
||||
package common
|
||||
|
||||
import (
|
||||
"github.com/attic-labs/noms/ref"
|
||||
"github.com/attic-labs/noms/types"
|
||||
)
|
||||
|
||||
var __commonPackageInFile_photo_CachedRef ref.Ref
|
||||
|
||||
// This function builds up a Noms value that describes the type
|
||||
// package implemented by this file and registers it with the global
|
||||
// type package definition cache.
|
||||
func init() {
|
||||
p := types.NewPackage([]types.TypeRef{
|
||||
types.MakeStructTypeRef("RemotePhoto",
|
||||
[]types.Field{
|
||||
types.Field{"Id", types.MakePrimitiveTypeRef(types.StringKind), false},
|
||||
types.Field{"Title", types.MakePrimitiveTypeRef(types.StringKind), false},
|
||||
types.Field{"Url", types.MakePrimitiveTypeRef(types.StringKind), false},
|
||||
types.Field{"Geoposition", types.MakeTypeRef(ref.Parse("sha1-6d5e1c54214264058be9f61f4b4ece0368c8c678"), 0), false},
|
||||
types.Field{"Sizes", types.MakeCompoundTypeRef(types.MapKind, types.MakeTypeRef(ref.Ref{}, 1), types.MakePrimitiveTypeRef(types.StringKind)), false},
|
||||
types.Field{"Tags", types.MakeCompoundTypeRef(types.SetKind, types.MakePrimitiveTypeRef(types.StringKind)), false},
|
||||
},
|
||||
types.Choices{},
|
||||
),
|
||||
types.MakeStructTypeRef("Size",
|
||||
[]types.Field{
|
||||
types.Field{"Width", types.MakePrimitiveTypeRef(types.UInt32Kind), false},
|
||||
types.Field{"Height", types.MakePrimitiveTypeRef(types.UInt32Kind), false},
|
||||
},
|
||||
types.Choices{},
|
||||
),
|
||||
}, []ref.Ref{
|
||||
ref.Parse("sha1-6d5e1c54214264058be9f61f4b4ece0368c8c678"),
|
||||
})
|
||||
__commonPackageInFile_photo_CachedRef = types.RegisterPackage(&p)
|
||||
}
|
||||
|
||||
// RemotePhoto
|
||||
|
||||
type RemotePhoto struct {
|
||||
m types.Map
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
func NewRemotePhoto() RemotePhoto {
|
||||
return RemotePhoto{types.NewMap(
|
||||
types.NewString("Id"), types.NewString(""),
|
||||
types.NewString("Title"), types.NewString(""),
|
||||
types.NewString("Url"), types.NewString(""),
|
||||
types.NewString("Geoposition"), NewGeoposition(),
|
||||
types.NewString("Sizes"), NewMapOfSizeToString(),
|
||||
types.NewString("Tags"), NewSetOfString(),
|
||||
), &ref.Ref{}}
|
||||
}
|
||||
|
||||
type RemotePhotoDef struct {
|
||||
Id string
|
||||
Title string
|
||||
Url string
|
||||
Geoposition GeopositionDef
|
||||
Sizes MapOfSizeToStringDef
|
||||
Tags SetOfStringDef
|
||||
}
|
||||
|
||||
func (def RemotePhotoDef) New() RemotePhoto {
|
||||
return RemotePhoto{
|
||||
types.NewMap(
|
||||
types.NewString("Id"), types.NewString(def.Id),
|
||||
types.NewString("Title"), types.NewString(def.Title),
|
||||
types.NewString("Url"), types.NewString(def.Url),
|
||||
types.NewString("Geoposition"), def.Geoposition.New(),
|
||||
types.NewString("Sizes"), def.Sizes.New(),
|
||||
types.NewString("Tags"), def.Tags.New(),
|
||||
), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s RemotePhoto) Def() (d RemotePhotoDef) {
|
||||
d.Id = s.m.Get(types.NewString("Id")).(types.String).String()
|
||||
d.Title = s.m.Get(types.NewString("Title")).(types.String).String()
|
||||
d.Url = s.m.Get(types.NewString("Url")).(types.String).String()
|
||||
d.Geoposition = s.m.Get(types.NewString("Geoposition")).(Geoposition).Def()
|
||||
d.Sizes = s.m.Get(types.NewString("Sizes")).(MapOfSizeToString).Def()
|
||||
d.Tags = s.m.Get(types.NewString("Tags")).(SetOfString).Def()
|
||||
return
|
||||
}
|
||||
|
||||
var __typeRefForRemotePhoto types.TypeRef
|
||||
|
||||
func (m RemotePhoto) TypeRef() types.TypeRef {
|
||||
return __typeRefForRemotePhoto
|
||||
}
|
||||
|
||||
func init() {
|
||||
__typeRefForRemotePhoto = types.MakeTypeRef(__commonPackageInFile_photo_CachedRef, 0)
|
||||
types.RegisterFromValFunction(__typeRefForRemotePhoto, func(v types.Value) types.Value {
|
||||
return RemotePhotoFromVal(v)
|
||||
})
|
||||
}
|
||||
|
||||
func RemotePhotoFromVal(val types.Value) RemotePhoto {
|
||||
// TODO: Do we still need FromVal?
|
||||
if val, ok := val.(RemotePhoto); ok {
|
||||
return val
|
||||
}
|
||||
// TODO: Validate here
|
||||
return RemotePhoto{val.(types.Map), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s RemotePhoto) InternalImplementation() types.Map {
|
||||
return s.m
|
||||
}
|
||||
|
||||
func (s RemotePhoto) Equals(other types.Value) bool {
|
||||
if other, ok := other.(RemotePhoto); ok {
|
||||
return s.Ref() == other.Ref()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (s RemotePhoto) Ref() ref.Ref {
|
||||
return types.EnsureRef(s.ref, s)
|
||||
}
|
||||
|
||||
func (s RemotePhoto) Chunks() (chunks []ref.Ref) {
|
||||
chunks = append(chunks, s.TypeRef().Chunks()...)
|
||||
chunks = append(chunks, s.m.Chunks()...)
|
||||
return
|
||||
}
|
||||
|
||||
func (s RemotePhoto) Id() string {
|
||||
return s.m.Get(types.NewString("Id")).(types.String).String()
|
||||
}
|
||||
|
||||
func (s RemotePhoto) SetId(val string) RemotePhoto {
|
||||
return RemotePhoto{s.m.Set(types.NewString("Id"), types.NewString(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s RemotePhoto) Title() string {
|
||||
return s.m.Get(types.NewString("Title")).(types.String).String()
|
||||
}
|
||||
|
||||
func (s RemotePhoto) SetTitle(val string) RemotePhoto {
|
||||
return RemotePhoto{s.m.Set(types.NewString("Title"), types.NewString(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s RemotePhoto) Url() string {
|
||||
return s.m.Get(types.NewString("Url")).(types.String).String()
|
||||
}
|
||||
|
||||
func (s RemotePhoto) SetUrl(val string) RemotePhoto {
|
||||
return RemotePhoto{s.m.Set(types.NewString("Url"), types.NewString(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s RemotePhoto) Geoposition() Geoposition {
|
||||
return s.m.Get(types.NewString("Geoposition")).(Geoposition)
|
||||
}
|
||||
|
||||
func (s RemotePhoto) SetGeoposition(val Geoposition) RemotePhoto {
|
||||
return RemotePhoto{s.m.Set(types.NewString("Geoposition"), val), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s RemotePhoto) Sizes() MapOfSizeToString {
|
||||
return s.m.Get(types.NewString("Sizes")).(MapOfSizeToString)
|
||||
}
|
||||
|
||||
func (s RemotePhoto) SetSizes(val MapOfSizeToString) RemotePhoto {
|
||||
return RemotePhoto{s.m.Set(types.NewString("Sizes"), val), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s RemotePhoto) Tags() SetOfString {
|
||||
return s.m.Get(types.NewString("Tags")).(SetOfString)
|
||||
}
|
||||
|
||||
func (s RemotePhoto) SetTags(val SetOfString) RemotePhoto {
|
||||
return RemotePhoto{s.m.Set(types.NewString("Tags"), val), &ref.Ref{}}
|
||||
}
|
||||
|
||||
// Size
|
||||
|
||||
type Size struct {
|
||||
m types.Map
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
func NewSize() Size {
|
||||
return Size{types.NewMap(
|
||||
types.NewString("Width"), types.UInt32(0),
|
||||
types.NewString("Height"), types.UInt32(0),
|
||||
), &ref.Ref{}}
|
||||
}
|
||||
|
||||
type SizeDef struct {
|
||||
Width uint32
|
||||
Height uint32
|
||||
}
|
||||
|
||||
func (def SizeDef) New() Size {
|
||||
return Size{
|
||||
types.NewMap(
|
||||
types.NewString("Width"), types.UInt32(def.Width),
|
||||
types.NewString("Height"), types.UInt32(def.Height),
|
||||
), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s Size) Def() (d SizeDef) {
|
||||
d.Width = uint32(s.m.Get(types.NewString("Width")).(types.UInt32))
|
||||
d.Height = uint32(s.m.Get(types.NewString("Height")).(types.UInt32))
|
||||
return
|
||||
}
|
||||
|
||||
var __typeRefForSize types.TypeRef
|
||||
|
||||
func (m Size) TypeRef() types.TypeRef {
|
||||
return __typeRefForSize
|
||||
}
|
||||
|
||||
func init() {
|
||||
__typeRefForSize = types.MakeTypeRef(__commonPackageInFile_photo_CachedRef, 1)
|
||||
types.RegisterFromValFunction(__typeRefForSize, func(v types.Value) types.Value {
|
||||
return SizeFromVal(v)
|
||||
})
|
||||
}
|
||||
|
||||
func SizeFromVal(val types.Value) Size {
|
||||
// TODO: Do we still need FromVal?
|
||||
if val, ok := val.(Size); ok {
|
||||
return val
|
||||
}
|
||||
// TODO: Validate here
|
||||
return Size{val.(types.Map), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s Size) InternalImplementation() types.Map {
|
||||
return s.m
|
||||
}
|
||||
|
||||
func (s Size) Equals(other types.Value) bool {
|
||||
if other, ok := other.(Size); ok {
|
||||
return s.Ref() == other.Ref()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (s Size) Ref() ref.Ref {
|
||||
return types.EnsureRef(s.ref, s)
|
||||
}
|
||||
|
||||
func (s Size) Chunks() (chunks []ref.Ref) {
|
||||
chunks = append(chunks, s.TypeRef().Chunks()...)
|
||||
chunks = append(chunks, s.m.Chunks()...)
|
||||
return
|
||||
}
|
||||
|
||||
func (s Size) Width() uint32 {
|
||||
return uint32(s.m.Get(types.NewString("Width")).(types.UInt32))
|
||||
}
|
||||
|
||||
func (s Size) SetWidth(val uint32) Size {
|
||||
return Size{s.m.Set(types.NewString("Width"), types.UInt32(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s Size) Height() uint32 {
|
||||
return uint32(s.m.Get(types.NewString("Height")).(types.UInt32))
|
||||
}
|
||||
|
||||
func (s Size) SetHeight(val uint32) Size {
|
||||
return Size{s.m.Set(types.NewString("Height"), types.UInt32(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
// MapOfSizeToString
|
||||
|
||||
type MapOfSizeToString struct {
|
||||
m types.Map
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
func NewMapOfSizeToString() MapOfSizeToString {
|
||||
return MapOfSizeToString{types.NewMap(), &ref.Ref{}}
|
||||
}
|
||||
|
||||
type MapOfSizeToStringDef map[SizeDef]string
|
||||
|
||||
func (def MapOfSizeToStringDef) New() MapOfSizeToString {
|
||||
kv := make([]types.Value, 0, len(def)*2)
|
||||
for k, v := range def {
|
||||
kv = append(kv, k.New(), types.NewString(v))
|
||||
}
|
||||
return MapOfSizeToString{types.NewMap(kv...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (m MapOfSizeToString) Def() MapOfSizeToStringDef {
|
||||
def := make(map[SizeDef]string)
|
||||
m.m.Iter(func(k, v types.Value) bool {
|
||||
def[k.(Size).Def()] = v.(types.String).String()
|
||||
return false
|
||||
})
|
||||
return def
|
||||
}
|
||||
|
||||
func MapOfSizeToStringFromVal(val types.Value) MapOfSizeToString {
|
||||
// TODO: Do we still need FromVal?
|
||||
if val, ok := val.(MapOfSizeToString); ok {
|
||||
return val
|
||||
}
|
||||
// TODO: Validate here
|
||||
return MapOfSizeToString{val.(types.Map), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (m MapOfSizeToString) InternalImplementation() types.Map {
|
||||
return m.m
|
||||
}
|
||||
|
||||
func (m MapOfSizeToString) Equals(other types.Value) bool {
|
||||
if other, ok := other.(MapOfSizeToString); ok {
|
||||
return m.Ref() == other.Ref()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (m MapOfSizeToString) Ref() ref.Ref {
|
||||
return types.EnsureRef(m.ref, m)
|
||||
}
|
||||
|
||||
func (m MapOfSizeToString) Chunks() (chunks []ref.Ref) {
|
||||
chunks = append(chunks, m.TypeRef().Chunks()...)
|
||||
chunks = append(chunks, m.m.Chunks()...)
|
||||
return
|
||||
}
|
||||
|
||||
// A Noms Value that describes MapOfSizeToString.
|
||||
var __typeRefForMapOfSizeToString types.TypeRef
|
||||
|
||||
func (m MapOfSizeToString) TypeRef() types.TypeRef {
|
||||
return __typeRefForMapOfSizeToString
|
||||
}
|
||||
|
||||
func init() {
|
||||
__typeRefForMapOfSizeToString = types.MakeCompoundTypeRef(types.MapKind, types.MakeTypeRef(__commonPackageInFile_photo_CachedRef, 1), types.MakePrimitiveTypeRef(types.StringKind))
|
||||
types.RegisterFromValFunction(__typeRefForMapOfSizeToString, func(v types.Value) types.Value {
|
||||
return MapOfSizeToStringFromVal(v)
|
||||
})
|
||||
}
|
||||
|
||||
func (m MapOfSizeToString) Empty() bool {
|
||||
return m.m.Empty()
|
||||
}
|
||||
|
||||
func (m MapOfSizeToString) Len() uint64 {
|
||||
return m.m.Len()
|
||||
}
|
||||
|
||||
func (m MapOfSizeToString) Has(p Size) bool {
|
||||
return m.m.Has(p)
|
||||
}
|
||||
|
||||
func (m MapOfSizeToString) Get(p Size) string {
|
||||
return m.m.Get(p).(types.String).String()
|
||||
}
|
||||
|
||||
func (m MapOfSizeToString) MaybeGet(p Size) (string, bool) {
|
||||
v, ok := m.m.MaybeGet(p)
|
||||
if !ok {
|
||||
return "", false
|
||||
}
|
||||
return v.(types.String).String(), ok
|
||||
}
|
||||
|
||||
func (m MapOfSizeToString) Set(k Size, v string) MapOfSizeToString {
|
||||
return MapOfSizeToString{m.m.Set(k, types.NewString(v)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
// TODO: Implement SetM?
|
||||
|
||||
func (m MapOfSizeToString) Remove(p Size) MapOfSizeToString {
|
||||
return MapOfSizeToString{m.m.Remove(p), &ref.Ref{}}
|
||||
}
|
||||
|
||||
type MapOfSizeToStringIterCallback func(k Size, v string) (stop bool)
|
||||
|
||||
func (m MapOfSizeToString) Iter(cb MapOfSizeToStringIterCallback) {
|
||||
m.m.Iter(func(k, v types.Value) bool {
|
||||
return cb(k.(Size), v.(types.String).String())
|
||||
})
|
||||
}
|
||||
|
||||
type MapOfSizeToStringIterAllCallback func(k Size, v string)
|
||||
|
||||
func (m MapOfSizeToString) IterAll(cb MapOfSizeToStringIterAllCallback) {
|
||||
m.m.IterAll(func(k, v types.Value) {
|
||||
cb(k.(Size), v.(types.String).String())
|
||||
})
|
||||
}
|
||||
|
||||
type MapOfSizeToStringFilterCallback func(k Size, v string) (keep bool)
|
||||
|
||||
func (m MapOfSizeToString) Filter(cb MapOfSizeToStringFilterCallback) MapOfSizeToString {
|
||||
nm := NewMapOfSizeToString()
|
||||
m.IterAll(func(k Size, v string) {
|
||||
if cb(k, v) {
|
||||
nm = nm.Set(k, v)
|
||||
}
|
||||
})
|
||||
return nm
|
||||
}
|
||||
|
||||
// SetOfString
|
||||
|
||||
type SetOfString struct {
|
||||
s types.Set
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
func NewSetOfString() SetOfString {
|
||||
return SetOfString{types.NewSet(), &ref.Ref{}}
|
||||
}
|
||||
|
||||
type SetOfStringDef map[string]bool
|
||||
|
||||
func (def SetOfStringDef) New() SetOfString {
|
||||
l := make([]types.Value, len(def))
|
||||
i := 0
|
||||
for d, _ := range def {
|
||||
l[i] = types.NewString(d)
|
||||
i++
|
||||
}
|
||||
return SetOfString{types.NewSet(l...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s SetOfString) Def() SetOfStringDef {
|
||||
def := make(map[string]bool, s.Len())
|
||||
s.s.Iter(func(v types.Value) bool {
|
||||
def[v.(types.String).String()] = true
|
||||
return false
|
||||
})
|
||||
return def
|
||||
}
|
||||
|
||||
func SetOfStringFromVal(val types.Value) SetOfString {
|
||||
// TODO: Do we still need FromVal?
|
||||
if val, ok := val.(SetOfString); ok {
|
||||
return val
|
||||
}
|
||||
return SetOfString{val.(types.Set), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s SetOfString) InternalImplementation() types.Set {
|
||||
return s.s
|
||||
}
|
||||
|
||||
func (s SetOfString) Equals(other types.Value) bool {
|
||||
if other, ok := other.(SetOfString); ok {
|
||||
return s.Ref() == other.Ref()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (s SetOfString) Ref() ref.Ref {
|
||||
return types.EnsureRef(s.ref, s)
|
||||
}
|
||||
|
||||
func (s SetOfString) Chunks() (chunks []ref.Ref) {
|
||||
chunks = append(chunks, s.TypeRef().Chunks()...)
|
||||
chunks = append(chunks, s.s.Chunks()...)
|
||||
return
|
||||
}
|
||||
|
||||
// A Noms Value that describes SetOfString.
|
||||
var __typeRefForSetOfString types.TypeRef
|
||||
|
||||
func (m SetOfString) TypeRef() types.TypeRef {
|
||||
return __typeRefForSetOfString
|
||||
}
|
||||
|
||||
func init() {
|
||||
__typeRefForSetOfString = types.MakeCompoundTypeRef(types.SetKind, types.MakePrimitiveTypeRef(types.StringKind))
|
||||
types.RegisterFromValFunction(__typeRefForSetOfString, func(v types.Value) types.Value {
|
||||
return SetOfStringFromVal(v)
|
||||
})
|
||||
}
|
||||
|
||||
func (s SetOfString) Empty() bool {
|
||||
return s.s.Empty()
|
||||
}
|
||||
|
||||
func (s SetOfString) Len() uint64 {
|
||||
return s.s.Len()
|
||||
}
|
||||
|
||||
func (s SetOfString) Has(p string) bool {
|
||||
return s.s.Has(types.NewString(p))
|
||||
}
|
||||
|
||||
type SetOfStringIterCallback func(p string) (stop bool)
|
||||
|
||||
func (s SetOfString) Iter(cb SetOfStringIterCallback) {
|
||||
s.s.Iter(func(v types.Value) bool {
|
||||
return cb(v.(types.String).String())
|
||||
})
|
||||
}
|
||||
|
||||
type SetOfStringIterAllCallback func(p string)
|
||||
|
||||
func (s SetOfString) IterAll(cb SetOfStringIterAllCallback) {
|
||||
s.s.IterAll(func(v types.Value) {
|
||||
cb(v.(types.String).String())
|
||||
})
|
||||
}
|
||||
|
||||
type SetOfStringFilterCallback func(p string) (keep bool)
|
||||
|
||||
func (s SetOfString) Filter(cb SetOfStringFilterCallback) SetOfString {
|
||||
ns := NewSetOfString()
|
||||
s.IterAll(func(v string) {
|
||||
if cb(v) {
|
||||
ns = ns.Insert(v)
|
||||
}
|
||||
})
|
||||
return ns
|
||||
}
|
||||
|
||||
func (s SetOfString) Insert(p ...string) SetOfString {
|
||||
return SetOfString{s.s.Insert(s.fromElemSlice(p)...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s SetOfString) Remove(p ...string) SetOfString {
|
||||
return SetOfString{s.s.Remove(s.fromElemSlice(p)...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s SetOfString) Union(others ...SetOfString) SetOfString {
|
||||
return SetOfString{s.s.Union(s.fromStructSlice(others)...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s SetOfString) Subtract(others ...SetOfString) SetOfString {
|
||||
return SetOfString{s.s.Subtract(s.fromStructSlice(others)...), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s SetOfString) Any() string {
|
||||
return s.s.Any().(types.String).String()
|
||||
}
|
||||
|
||||
func (s SetOfString) fromStructSlice(p []SetOfString) []types.Set {
|
||||
r := make([]types.Set, len(p))
|
||||
for i, v := range p {
|
||||
r[i] = v.s
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
func (s SetOfString) fromElemSlice(p []string) []types.Value {
|
||||
r := make([]types.Value, len(p))
|
||||
for i, v := range p {
|
||||
r[i] = types.NewString(v)
|
||||
}
|
||||
return r
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package main
|
||||
package common
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -197,7 +197,7 @@ func (qt *QuadTreeDef) makeChildren() {
|
||||
qt.Tiles[br] = CreateNewQuadTreeDef(qt.Depth+1, qt.Path+"d", brRect)
|
||||
}
|
||||
|
||||
func (qt *QuadTreeDef) SaveToNoms(cs chunks.ChunkSink, start time.Time) *SQuadTree {
|
||||
func (qt *QuadTreeDef) SaveToNoms(cs chunks.ChunkSink, start time.Time, quiet bool) *SQuadTree {
|
||||
wChan := make(chan *SQuadTree, 1024)
|
||||
var wg sync.WaitGroup
|
||||
for i := 0; i < 32; i++ {
|
||||
@@ -214,18 +214,18 @@ func (qt *QuadTreeDef) SaveToNoms(cs chunks.ChunkSink, start time.Time) *SQuadTr
|
||||
defer util.StopCPUProfile()
|
||||
}
|
||||
|
||||
sqt := qt.saveNodeToNoms(wChan, cs, start)
|
||||
sqt := qt.saveNodeToNoms(wChan, cs, start, quiet)
|
||||
close(wChan)
|
||||
wg.Wait()
|
||||
return sqt
|
||||
}
|
||||
|
||||
func (qt *QuadTreeDef) saveNodeToNoms(wChan chan *SQuadTree, cs chunks.ChunkSink, start time.Time) *SQuadTree {
|
||||
func (qt *QuadTreeDef) saveNodeToNoms(wChan chan *SQuadTree, cs chunks.ChunkSink, start time.Time, quiet bool) *SQuadTree {
|
||||
tileRefs := MapOfStringToRefOfSQuadTreeDef{}
|
||||
nrefs := make(ListOfRefOfValueDef, 0, len(qt.Nodes))
|
||||
if qt.hasTiles() {
|
||||
for q, tile := range qt.Tiles {
|
||||
child := tile.saveNodeToNoms(wChan, cs, start)
|
||||
child := tile.saveNodeToNoms(wChan, cs, start, quiet)
|
||||
ref := child.Ref()
|
||||
tileRefs[q] = ref
|
||||
}
|
||||
@@ -246,8 +246,8 @@ func (qt *QuadTreeDef) saveNodeToNoms(wChan chan *SQuadTree, cs chunks.ChunkSink
|
||||
|
||||
wChan <- sqtp
|
||||
saveCount++
|
||||
if saveCount%1e4 == 0 && !*quietFlag {
|
||||
fmt.Printf("Nodes Saved: %d, elapsed time: %.2f secs\n", saveCount, secsSince(start))
|
||||
if saveCount%1e4 == 0 && !quiet {
|
||||
fmt.Printf("Nodes Saved: %d, elapsed time: %.2f secs\n", saveCount, SecsSince(start))
|
||||
}
|
||||
return sqtp
|
||||
}
|
||||
@@ -259,6 +259,6 @@ func max(x, y uint8) uint8 {
|
||||
return y
|
||||
}
|
||||
|
||||
func secsSince(start time.Time) float64 {
|
||||
func SecsSince(start time.Time) float64 {
|
||||
return time.Now().Sub(start).Seconds()
|
||||
}
|
||||
24
clients/common/quad_tree.noms
Normal file
24
clients/common/quad_tree.noms
Normal file
@@ -0,0 +1,24 @@
|
||||
alias Geo = import "geo.noms"
|
||||
|
||||
struct Node {
|
||||
Geoposition: Geo.Geoposition
|
||||
Reference: Ref(Value)
|
||||
}
|
||||
|
||||
struct QuadTree {
|
||||
Nodes: List(Node)
|
||||
Tiles: Map(String, QuadTree)
|
||||
Depth: UInt8
|
||||
NumDescendents: UInt32
|
||||
Path: String
|
||||
Georectangle: Geo.Georectangle
|
||||
}
|
||||
|
||||
struct SQuadTree {
|
||||
Nodes: List(Ref(Value))
|
||||
Tiles: Map(String, Ref(SQuadTree))
|
||||
Depth: UInt8
|
||||
NumDescendents: UInt32
|
||||
Path: String
|
||||
Georectangle: Geo.Georectangle
|
||||
}
|
||||
1105
clients/common/quad_tree.noms.go
Normal file
1105
clients/common/quad_tree.noms.go
Normal file
File diff suppressed because it is too large
Load Diff
32
clients/common/quad_tree_query.go
Normal file
32
clients/common/quad_tree_query.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package common
|
||||
|
||||
import "github.com/attic-labs/noms/datas"
|
||||
|
||||
func (qt *SQuadTree) Query(p GeopositionDef, kilometers float64, ds datas.DataStore) (GeorectangleDef, []Incident) {
|
||||
r := BoundingRectangle(p, kilometers)
|
||||
nodes := qt.Search(r, p, float32(kilometers), ds)
|
||||
return r, nodes
|
||||
}
|
||||
|
||||
func (qt *SQuadTree) Search(r GeorectangleDef, p GeopositionDef, kilometers float32, ds datas.DataStore) []Incident {
|
||||
nodes := []Incident{}
|
||||
if qt.Tiles().Len() > 0 {
|
||||
for _, q := range quadrants {
|
||||
tile := qt.Tiles().Get(q).TargetValue(ds)
|
||||
if IntersectsRect(tile.Georectangle().Def(), r) {
|
||||
tnodes := tile.Search(r, p, kilometers, ds)
|
||||
nodes = append(nodes, tnodes...)
|
||||
}
|
||||
}
|
||||
} else if qt.Nodes().Len() > 0 {
|
||||
qt.Nodes().Iter(func(r RefOfValue, i uint64) bool {
|
||||
incident := r.TargetValue(ds).(Incident)
|
||||
if DistanceTo(p, incident.Geoposition().Def()) < kilometers {
|
||||
nodes = append(nodes, incident)
|
||||
}
|
||||
return false
|
||||
})
|
||||
}
|
||||
|
||||
return nodes
|
||||
}
|
||||
3
clients/common/rungen.go
Normal file
3
clients/common/rungen.go
Normal file
@@ -0,0 +1,3 @@
|
||||
package common
|
||||
|
||||
//go:generate go run ../../nomdl/codegen/codegen.go -package=common -out-dir=.
|
||||
@@ -1,4 +1,4 @@
|
||||
alias Img = import "../types/photo.noms"
|
||||
alias Img = import "../common/photo.noms"
|
||||
|
||||
struct User {
|
||||
Id: String
|
||||
|
||||
@@ -1,97 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/attic-labs/noms/Godeps/_workspace/src/github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestPoint(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
p1 := GeopositionDef{5, 5}
|
||||
p2 := GeopositionDef{3, 7}
|
||||
p3 := GeopositionDef{10, 7}
|
||||
p4 := GeopositionDef{10, 12}
|
||||
|
||||
assert.True(TopLeftOf(p1, p2))
|
||||
assert.False(TopLeftOf(p2, p1))
|
||||
assert.True(BelowRightOf(p2, p1))
|
||||
assert.False(BelowRightOf(p1, p2))
|
||||
assert.False(TopLeftOf(p1, p1))
|
||||
assert.False(BelowRightOf(p2, p2))
|
||||
|
||||
assert.True(TopLeftOrSameOf(p3, p2))
|
||||
assert.True(TopLeftOrSameOf(p3, p3))
|
||||
assert.False(TopLeftOrSameOf(p4, p3))
|
||||
assert.True(BelowRightOrSameOf(p2, p3))
|
||||
assert.True(BelowRightOrSameOf(p3, p3))
|
||||
assert.False(BelowRightOrSameOf(p3, p4))
|
||||
assert.True(TopLeftOrSameOf(p3, p4))
|
||||
}
|
||||
|
||||
func TestRectangle(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
tl1 := GeopositionDef{10, 5}
|
||||
br1 := GeopositionDef{5, 10}
|
||||
r1 := GeorectangleDef{tl1, br1}
|
||||
|
||||
tl2 := GeopositionDef{9, 7}
|
||||
br2 := GeopositionDef{7, 9}
|
||||
r2 := GeorectangleDef{tl2, br2}
|
||||
|
||||
tl3 := GeopositionDef{30, 20}
|
||||
br3 := GeopositionDef{20, 30}
|
||||
r3 := GeorectangleDef{tl3, br3}
|
||||
|
||||
assert.True(TopLeftOf(tl1, br2))
|
||||
|
||||
assert.True(IntersectsRect(r1, r2))
|
||||
assert.True(IntersectsRect(r2, r1))
|
||||
assert.True(IntersectsRect(r2, r2))
|
||||
|
||||
assert.True(ContainsRect(r1, r2))
|
||||
assert.False(ContainsRect(r2, r1))
|
||||
assert.True(ContainsRect(r2, r2))
|
||||
|
||||
assert.False(IntersectsRect(r1, r3))
|
||||
assert.False(ContainsRect(r1, r3))
|
||||
|
||||
assert.True(ContainsPoint(r1, tl2))
|
||||
assert.False(ContainsPoint(r1, br3))
|
||||
|
||||
tlRect, blRect, trRect, brRect := Split(r3)
|
||||
tl0 := GeopositionDef{30, 20}
|
||||
tm0 := GeopositionDef{30, 25}
|
||||
lm0 := GeopositionDef{25, 20}
|
||||
mm0 := GeopositionDef{25, 25}
|
||||
rm0 := GeopositionDef{25, 30}
|
||||
bm0 := GeopositionDef{20, 25}
|
||||
br0 := GeopositionDef{20, 30}
|
||||
|
||||
topLeft := GeorectangleDef{tl0, mm0}
|
||||
bottomLeft := GeorectangleDef{lm0, bm0}
|
||||
topRight := GeorectangleDef{tm0, rm0}
|
||||
bottomRight := GeorectangleDef{mm0, br0}
|
||||
|
||||
assert.True(tlRect == topLeft)
|
||||
assert.True(blRect == bottomLeft)
|
||||
assert.True(trRect == topRight)
|
||||
assert.True(brRect == bottomRight)
|
||||
}
|
||||
|
||||
func TestDistances(t *testing.T) {
|
||||
p1 := GeopositionDef{37.83, -122.52}
|
||||
p2 := GeopositionDef{37.70, -122.36}
|
||||
|
||||
km1 := DistanceTo(p1, p2)
|
||||
fmt.Printf("distance from %v to %v: %f\n", p1, p2, km1)
|
||||
km2 := DistanceTo(p2, p1)
|
||||
fmt.Printf("distance from %v to %v: %f\n", p2, p1, km2)
|
||||
assert.Equal(t, km1, km2)
|
||||
|
||||
point := GeopositionDef{37.7644008, -122.4511607}
|
||||
kms := 0.9
|
||||
boundingRect := BoundingRectangle(point, kms)
|
||||
fmt.Printf("Point: %v, distance: %f kms, Bounding %v", point, kms, boundingRect)
|
||||
}
|
||||
1
clients/quad_tree/incident.noms
Symbolic link
1
clients/quad_tree/incident.noms
Symbolic link
@@ -0,0 +1 @@
|
||||
../sfcrime_importer/incident.noms
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/attic-labs/noms/clients/common"
|
||||
"github.com/attic-labs/noms/d"
|
||||
"github.com/attic-labs/noms/datas"
|
||||
"github.com/attic-labs/noms/dataset"
|
||||
@@ -43,13 +44,13 @@ func main() {
|
||||
log.Fatalf("Invalid inputRef: %v", *inputRefStr)
|
||||
}
|
||||
|
||||
gr := GeorectangleDef{
|
||||
TopLeft: GeopositionDef{Latitude: 37.83, Longitude: -122.52},
|
||||
BottomRight: GeopositionDef{Latitude: 37.70, Longitude: -122.36},
|
||||
gr := common.GeorectangleDef{
|
||||
TopLeft: common.GeopositionDef{Latitude: 37.83, Longitude: -122.52},
|
||||
BottomRight: common.GeopositionDef{Latitude: 37.70, Longitude: -122.36},
|
||||
}
|
||||
qtRoot := QuadTreeDef{
|
||||
Nodes: ListOfNodeDef{},
|
||||
Tiles: MapOfStringToQuadTreeDef{},
|
||||
qtRoot := common.QuadTreeDef{
|
||||
Nodes: common.ListOfNodeDef{},
|
||||
Tiles: common.MapOfStringToQuadTreeDef{},
|
||||
Depth: 0,
|
||||
NumDescendents: 0,
|
||||
Path: "",
|
||||
@@ -61,21 +62,21 @@ func main() {
|
||||
|
||||
list := types.ReadValue(inputRef, dataset.Store()).(types.List)
|
||||
if !*quietFlag {
|
||||
fmt.Printf("Reading from nodeList: %d items, elapsed time: %.2f secs\n", list.Len(), secsSince(start))
|
||||
fmt.Printf("Reading from nodeList: %d items, elapsed time: %.2f secs\n", list.Len(), SecsSince(start))
|
||||
}
|
||||
|
||||
nChan := make(chan *NodeDef, 1024)
|
||||
nChan := make(chan *common.NodeDef, 1024)
|
||||
nodesConverted := uint32(0)
|
||||
go func() {
|
||||
list.IterAllP(64, func(v types.Value, i uint64) {
|
||||
// Need to replace incident with generic type
|
||||
r := RefOfValueFromVal(v)
|
||||
incident := r.TargetValue(datastore).(Incident)
|
||||
nodeDef := &NodeDef{Geoposition: incident.Geoposition().Def(), Reference: r.TargetRef()}
|
||||
r := common.RefOfValueFromVal(v)
|
||||
incident := r.TargetValue(datastore).(common.Incident)
|
||||
nodeDef := &common.NodeDef{Geoposition: incident.Geoposition().Def(), Reference: r.TargetRef()}
|
||||
nChan <- nodeDef
|
||||
nConverted := atomic.AddUint32(&nodesConverted, 1)
|
||||
if !*quietFlag && nConverted%1e5 == 0 {
|
||||
fmt.Printf("Nodes Converted: %d, elapsed time: %.2f secs\n", nodesConverted, secsSince(start))
|
||||
fmt.Printf("Nodes Converted: %d, elapsed time: %.2f secs\n", nodesConverted, SecsSince(start))
|
||||
}
|
||||
})
|
||||
close(nChan)
|
||||
@@ -86,20 +87,20 @@ func main() {
|
||||
qtRoot.Append(nodeDef)
|
||||
nodesAppended++
|
||||
if !*quietFlag && nodesAppended%1e5 == 0 {
|
||||
fmt.Printf("Nodes Appended: %d, elapsed time: %.2f secs\n", nodesAppended, secsSince(start))
|
||||
fmt.Printf("Nodes Appended: %d, elapsed time: %.2f secs\n", nodesAppended, SecsSince(start))
|
||||
qtRoot.Analyze()
|
||||
}
|
||||
}
|
||||
|
||||
if !*quietFlag {
|
||||
fmt.Printf("Nodes Appended: %d, elapsed time: %.2f secs\n", nodesAppended, secsSince(start))
|
||||
fmt.Printf("Nodes Appended: %d, elapsed time: %.2f secs\n", nodesAppended, SecsSince(start))
|
||||
qtRoot.Analyze()
|
||||
fmt.Printf("Calling SaveToNoms(), elapsed time: %.2f secs\n", secsSince(start))
|
||||
fmt.Printf("Calling SaveToNoms(), elapsed time: %.2f secs\n", SecsSince(start))
|
||||
}
|
||||
|
||||
nomsQtRoot := qtRoot.SaveToNoms(dataset.Store(), start)
|
||||
nomsQtRoot := qtRoot.SaveToNoms(dataset.Store(), start, *quietFlag)
|
||||
if !*quietFlag {
|
||||
fmt.Printf("Calling Commit(), elapsed time: %.2f secs\n", secsSince(start))
|
||||
fmt.Printf("Calling Commit(), elapsed time: %.2f secs\n", SecsSince(start))
|
||||
}
|
||||
_, ok = dataset.Commit(types.NewRef(nomsQtRoot.Ref()))
|
||||
d.Chk.True(ok, "Could not commit due to conflicting edit")
|
||||
@@ -108,3 +109,7 @@ func main() {
|
||||
}
|
||||
fmt.Println("QuadTree ref:", nomsQtRoot.Ref())
|
||||
}
|
||||
|
||||
func SecsSince(start time.Time) float64 {
|
||||
return time.Now().Sub(start).Seconds()
|
||||
}
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
package main
|
||||
|
||||
//go:generate go run ../../nomdl/codegen/codegen.go -package=main -out-dir=.
|
||||
@@ -1,217 +0,0 @@
|
||||
// This file was generated by nomdl/codegen.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/attic-labs/noms/ref"
|
||||
"github.com/attic-labs/noms/types"
|
||||
)
|
||||
|
||||
var __mainPackageInFile_sha1_6d5e1c5_CachedRef ref.Ref
|
||||
|
||||
// This function builds up a Noms value that describes the type
|
||||
// package implemented by this file and registers it with the global
|
||||
// type package definition cache.
|
||||
func init() {
|
||||
p := types.NewPackage([]types.TypeRef{
|
||||
types.MakeStructTypeRef("Geoposition",
|
||||
[]types.Field{
|
||||
types.Field{"Latitude", types.MakePrimitiveTypeRef(types.Float32Kind), false},
|
||||
types.Field{"Longitude", types.MakePrimitiveTypeRef(types.Float32Kind), false},
|
||||
},
|
||||
types.Choices{},
|
||||
),
|
||||
types.MakeStructTypeRef("Georectangle",
|
||||
[]types.Field{
|
||||
types.Field{"TopLeft", types.MakeTypeRef(ref.Ref{}, 0), false},
|
||||
types.Field{"BottomRight", types.MakeTypeRef(ref.Ref{}, 0), false},
|
||||
},
|
||||
types.Choices{},
|
||||
),
|
||||
}, []ref.Ref{})
|
||||
__mainPackageInFile_sha1_6d5e1c5_CachedRef = types.RegisterPackage(&p)
|
||||
}
|
||||
|
||||
// Geoposition
|
||||
|
||||
type Geoposition struct {
|
||||
m types.Map
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
func NewGeoposition() Geoposition {
|
||||
return Geoposition{types.NewMap(
|
||||
types.NewString("Latitude"), types.Float32(0),
|
||||
types.NewString("Longitude"), types.Float32(0),
|
||||
), &ref.Ref{}}
|
||||
}
|
||||
|
||||
type GeopositionDef struct {
|
||||
Latitude float32
|
||||
Longitude float32
|
||||
}
|
||||
|
||||
func (def GeopositionDef) New() Geoposition {
|
||||
return Geoposition{
|
||||
types.NewMap(
|
||||
types.NewString("Latitude"), types.Float32(def.Latitude),
|
||||
types.NewString("Longitude"), types.Float32(def.Longitude),
|
||||
), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s Geoposition) Def() (d GeopositionDef) {
|
||||
d.Latitude = float32(s.m.Get(types.NewString("Latitude")).(types.Float32))
|
||||
d.Longitude = float32(s.m.Get(types.NewString("Longitude")).(types.Float32))
|
||||
return
|
||||
}
|
||||
|
||||
var __typeRefForGeoposition types.TypeRef
|
||||
|
||||
func (m Geoposition) TypeRef() types.TypeRef {
|
||||
return __typeRefForGeoposition
|
||||
}
|
||||
|
||||
func init() {
|
||||
__typeRefForGeoposition = types.MakeTypeRef(__mainPackageInFile_sha1_6d5e1c5_CachedRef, 0)
|
||||
types.RegisterFromValFunction(__typeRefForGeoposition, func(v types.Value) types.Value {
|
||||
return GeopositionFromVal(v)
|
||||
})
|
||||
}
|
||||
|
||||
func GeopositionFromVal(val types.Value) Geoposition {
|
||||
// TODO: Do we still need FromVal?
|
||||
if val, ok := val.(Geoposition); ok {
|
||||
return val
|
||||
}
|
||||
// TODO: Validate here
|
||||
return Geoposition{val.(types.Map), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s Geoposition) InternalImplementation() types.Map {
|
||||
return s.m
|
||||
}
|
||||
|
||||
func (s Geoposition) Equals(other types.Value) bool {
|
||||
if other, ok := other.(Geoposition); ok {
|
||||
return s.Ref() == other.Ref()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (s Geoposition) Ref() ref.Ref {
|
||||
return types.EnsureRef(s.ref, s)
|
||||
}
|
||||
|
||||
func (s Geoposition) Chunks() (chunks []ref.Ref) {
|
||||
chunks = append(chunks, s.TypeRef().Chunks()...)
|
||||
chunks = append(chunks, s.m.Chunks()...)
|
||||
return
|
||||
}
|
||||
|
||||
func (s Geoposition) Latitude() float32 {
|
||||
return float32(s.m.Get(types.NewString("Latitude")).(types.Float32))
|
||||
}
|
||||
|
||||
func (s Geoposition) SetLatitude(val float32) Geoposition {
|
||||
return Geoposition{s.m.Set(types.NewString("Latitude"), types.Float32(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s Geoposition) Longitude() float32 {
|
||||
return float32(s.m.Get(types.NewString("Longitude")).(types.Float32))
|
||||
}
|
||||
|
||||
func (s Geoposition) SetLongitude(val float32) Geoposition {
|
||||
return Geoposition{s.m.Set(types.NewString("Longitude"), types.Float32(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
// Georectangle
|
||||
|
||||
type Georectangle struct {
|
||||
m types.Map
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
func NewGeorectangle() Georectangle {
|
||||
return Georectangle{types.NewMap(
|
||||
types.NewString("TopLeft"), NewGeoposition(),
|
||||
types.NewString("BottomRight"), NewGeoposition(),
|
||||
), &ref.Ref{}}
|
||||
}
|
||||
|
||||
type GeorectangleDef struct {
|
||||
TopLeft GeopositionDef
|
||||
BottomRight GeopositionDef
|
||||
}
|
||||
|
||||
func (def GeorectangleDef) New() Georectangle {
|
||||
return Georectangle{
|
||||
types.NewMap(
|
||||
types.NewString("TopLeft"), def.TopLeft.New(),
|
||||
types.NewString("BottomRight"), def.BottomRight.New(),
|
||||
), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s Georectangle) Def() (d GeorectangleDef) {
|
||||
d.TopLeft = s.m.Get(types.NewString("TopLeft")).(Geoposition).Def()
|
||||
d.BottomRight = s.m.Get(types.NewString("BottomRight")).(Geoposition).Def()
|
||||
return
|
||||
}
|
||||
|
||||
var __typeRefForGeorectangle types.TypeRef
|
||||
|
||||
func (m Georectangle) TypeRef() types.TypeRef {
|
||||
return __typeRefForGeorectangle
|
||||
}
|
||||
|
||||
func init() {
|
||||
__typeRefForGeorectangle = types.MakeTypeRef(__mainPackageInFile_sha1_6d5e1c5_CachedRef, 1)
|
||||
types.RegisterFromValFunction(__typeRefForGeorectangle, func(v types.Value) types.Value {
|
||||
return GeorectangleFromVal(v)
|
||||
})
|
||||
}
|
||||
|
||||
func GeorectangleFromVal(val types.Value) Georectangle {
|
||||
// TODO: Do we still need FromVal?
|
||||
if val, ok := val.(Georectangle); ok {
|
||||
return val
|
||||
}
|
||||
// TODO: Validate here
|
||||
return Georectangle{val.(types.Map), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s Georectangle) InternalImplementation() types.Map {
|
||||
return s.m
|
||||
}
|
||||
|
||||
func (s Georectangle) Equals(other types.Value) bool {
|
||||
if other, ok := other.(Georectangle); ok {
|
||||
return s.Ref() == other.Ref()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (s Georectangle) Ref() ref.Ref {
|
||||
return types.EnsureRef(s.ref, s)
|
||||
}
|
||||
|
||||
func (s Georectangle) Chunks() (chunks []ref.Ref) {
|
||||
chunks = append(chunks, s.TypeRef().Chunks()...)
|
||||
chunks = append(chunks, s.m.Chunks()...)
|
||||
return
|
||||
}
|
||||
|
||||
func (s Georectangle) TopLeft() Geoposition {
|
||||
return s.m.Get(types.NewString("TopLeft")).(Geoposition)
|
||||
}
|
||||
|
||||
func (s Georectangle) SetTopLeft(val Geoposition) Georectangle {
|
||||
return Georectangle{s.m.Set(types.NewString("TopLeft"), val), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s Georectangle) BottomRight() Geoposition {
|
||||
return s.m.Get(types.NewString("BottomRight")).(Geoposition)
|
||||
}
|
||||
|
||||
func (s Georectangle) SetBottomRight(val Geoposition) Georectangle {
|
||||
return Georectangle{s.m.Set(types.NewString("BottomRight"), val), &ref.Ref{}}
|
||||
}
|
||||
@@ -1,147 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"math"
|
||||
)
|
||||
|
||||
const (
|
||||
// EarthRadius the Earth's radius is about 6,371km according to Wikipedia
|
||||
EarthRadius = 6371
|
||||
)
|
||||
|
||||
// Latitude64 casts the Latitude value to a float64 for convenience.
|
||||
func Latitude64(p GeopositionDef) float64 {
|
||||
return float64(p.Latitude)
|
||||
}
|
||||
|
||||
// Longitude64 casts the Longitude value to a float64 for convenience.
|
||||
func Longitude64(p GeopositionDef) float64 {
|
||||
return float64(p.Longitude)
|
||||
}
|
||||
|
||||
// TopLeftOf returns true if it is above and to the left of "o"
|
||||
func TopLeftOf(p GeopositionDef, o GeopositionDef) bool {
|
||||
return p.Latitude > o.Latitude && p.Longitude < o.Longitude
|
||||
}
|
||||
|
||||
// BelowRightOf returns true if it's below and to the right of "o"
|
||||
func BelowRightOf(p GeopositionDef, o GeopositionDef) bool {
|
||||
return p.Latitude < o.Latitude && p.Longitude > o.Longitude
|
||||
}
|
||||
|
||||
// TopLeftOrSameOf returns true if it is above and to the left of "o"
|
||||
func TopLeftOrSameOf(p GeopositionDef, o GeopositionDef) bool {
|
||||
return p.Latitude >= o.Latitude && p.Longitude <= o.Longitude
|
||||
}
|
||||
|
||||
// BelowRightOrSameOf returns true if it's below and to the right of "o"
|
||||
func BelowRightOrSameOf(p GeopositionDef, o GeopositionDef) bool {
|
||||
return p.Latitude <= o.Latitude && p.Longitude >= o.Longitude
|
||||
}
|
||||
|
||||
// PointAtDistanceAndBearing returns a Point populated with the lat and lng coordinates
|
||||
// by transposing the origin point the passed in distance (in kilometers)
|
||||
// by the passed in compass bearing (in degrees).
|
||||
// Original Implementation from: http://www.movable-type.co.uk/scripts/latlong.html
|
||||
func PointAtDistanceAndBearing(p GeopositionDef, dist float64, bearing float64) *GeopositionDef {
|
||||
dr := dist / EarthRadius
|
||||
|
||||
bearing = bearing * (math.Pi / 180.0)
|
||||
|
||||
lat1 := Latitude64(p) * (math.Pi / 180.0)
|
||||
lng1 := Longitude64(p) * (math.Pi / 180.0)
|
||||
|
||||
lat2Part1 := math.Sin(lat1) * math.Cos(dr)
|
||||
lat2Part2 := math.Cos(lat1) * math.Sin(dr) * math.Cos(bearing)
|
||||
|
||||
lat2 := math.Asin(lat2Part1 + lat2Part2)
|
||||
|
||||
lng2Part1 := math.Sin(bearing) * math.Sin(dr) * math.Cos(lat1)
|
||||
lng2Part2 := math.Cos(dr) - (math.Sin(lat1) * math.Sin(lat2))
|
||||
|
||||
lng2 := lng1 + math.Atan2(lng2Part1, lng2Part2)
|
||||
lng2 = math.Mod((lng2+3*math.Pi), (2*math.Pi)) - math.Pi
|
||||
|
||||
lat2 = lat2 * (180.0 / math.Pi)
|
||||
lng2 = lng2 * (180.0 / math.Pi)
|
||||
|
||||
return &GeopositionDef{Latitude: float32(lat2), Longitude: float32(lng2)}
|
||||
}
|
||||
|
||||
// DistanceTo calculates the Haversine distance between two points in kilometers.
|
||||
// Original Implementation from: http://www.movable-type.co.uk/scripts/latlong.html
|
||||
func DistanceTo(p GeopositionDef, o GeopositionDef) float32 {
|
||||
dLat := (Latitude64(o) - Latitude64(p)) * (math.Pi / 180.0)
|
||||
dLon := (Longitude64(o) - Longitude64(p)) * (math.Pi / 180.0)
|
||||
|
||||
lat1 := Latitude64(p) * (math.Pi / 180.0)
|
||||
lat2 := Latitude64(o) * (math.Pi / 180.0)
|
||||
|
||||
a1 := math.Sin(dLat/2) * math.Sin(dLat/2)
|
||||
a2 := math.Sin(dLon/2) * math.Sin(dLon/2) * math.Cos(lat1) * math.Cos(lat2)
|
||||
|
||||
a := a1 + a2
|
||||
|
||||
c := 2 * math.Atan2(math.Sqrt(a), math.Sqrt(1-a))
|
||||
|
||||
return float32(EarthRadius * c)
|
||||
}
|
||||
|
||||
// BoundingRectangle calculates a rectangle whose sides east/west and north/south.
|
||||
// The center of the rectangle is "p" and each side is "2 * radius" in length.
|
||||
// A radius value of 1 equals 1 kilometer.
|
||||
func BoundingRectangle(p GeopositionDef, radius float64) GeorectangleDef {
|
||||
northPoint := PointAtDistanceAndBearing(p, radius, 0)
|
||||
eastPoint := PointAtDistanceAndBearing(p, radius, 90)
|
||||
southPoint := PointAtDistanceAndBearing(p, radius, 180)
|
||||
westPoint := PointAtDistanceAndBearing(p, radius, 270)
|
||||
|
||||
return GeorectangleDef{
|
||||
TopLeft: GeopositionDef{Latitude: northPoint.Latitude, Longitude: westPoint.Longitude},
|
||||
BottomRight: GeopositionDef{Latitude: southPoint.Latitude, Longitude: eastPoint.Longitude},
|
||||
}
|
||||
}
|
||||
|
||||
// IntersectsRect returns true if "o" intersects r
|
||||
func IntersectsRect(r GeorectangleDef, o GeorectangleDef) bool {
|
||||
return TopLeftOf(r.TopLeft, o.BottomRight) && BelowRightOf(r.BottomRight, o.TopLeft)
|
||||
}
|
||||
|
||||
// ContainsRect returns true if "o" is within r
|
||||
func ContainsRect(r GeorectangleDef, o GeorectangleDef) bool {
|
||||
return TopLeftOrSameOf(r.TopLeft, o.TopLeft) && BelowRightOrSameOf(r.BottomRight, o.BottomRight)
|
||||
}
|
||||
|
||||
// ContainsPoint returns true if p is contained in r
|
||||
func ContainsPoint(r GeorectangleDef, p GeopositionDef) bool {
|
||||
return TopLeftOrSameOf(r.TopLeft, p) && BelowRightOf(r.BottomRight, p)
|
||||
}
|
||||
|
||||
// Split creates one new rectangle for each quadrant in "r"
|
||||
func Split(r GeorectangleDef) (tlRect, blRect, trRect, brRect GeorectangleDef) {
|
||||
maxLat := r.TopLeft.Latitude
|
||||
minLon := r.TopLeft.Longitude
|
||||
minLat := r.BottomRight.Latitude
|
||||
maxLon := r.BottomRight.Longitude
|
||||
midLat := ((maxLat - minLat) / 2) + minLat
|
||||
midLon := ((maxLon - minLon) / 2) + minLon
|
||||
|
||||
tlRect = GeorectangleDef{
|
||||
TopLeft: GeopositionDef{Latitude: maxLat, Longitude: minLon},
|
||||
BottomRight: GeopositionDef{Latitude: midLat, Longitude: midLon},
|
||||
}
|
||||
blRect = GeorectangleDef{
|
||||
TopLeft: GeopositionDef{Latitude: midLat, Longitude: minLon},
|
||||
BottomRight: GeopositionDef{Latitude: minLat, Longitude: midLon},
|
||||
}
|
||||
trRect = GeorectangleDef{
|
||||
TopLeft: GeopositionDef{Latitude: maxLat, Longitude: midLon},
|
||||
BottomRight: GeopositionDef{Latitude: midLat, Longitude: maxLon},
|
||||
}
|
||||
brRect = GeorectangleDef{
|
||||
TopLeft: GeopositionDef{Latitude: midLat, Longitude: midLon},
|
||||
BottomRight: GeopositionDef{Latitude: minLat, Longitude: maxLon},
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
package main
|
||||
|
||||
//go:generate go run ../../nomdl/codegen/codegen.go -package=main -out-dir=.
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/attic-labs/noms/chunks"
|
||||
"github.com/attic-labs/noms/clients/common"
|
||||
"github.com/attic-labs/noms/clients/util"
|
||||
"github.com/attic-labs/noms/d"
|
||||
"github.com/attic-labs/noms/dataset"
|
||||
@@ -33,7 +34,7 @@ var (
|
||||
const maxListSize = 1e5
|
||||
|
||||
type incidentWithIndex struct {
|
||||
incident *IncidentDef
|
||||
incident *common.IncidentDef
|
||||
index int
|
||||
}
|
||||
|
||||
@@ -106,8 +107,8 @@ func main() {
|
||||
id, _ := strconv.ParseInt(r[0], 10, 64)
|
||||
lon64, _ := strconv.ParseFloat(r[9], 32)
|
||||
lat64, _ := strconv.ParseFloat(r[10], 32)
|
||||
geopos := GeopositionDef{Latitude: float32(lat64), Longitude: float32(lon64)}
|
||||
incident := IncidentDef{
|
||||
geopos := common.GeopositionDef{Latitude: float32(lat64), Longitude: float32(lon64)}
|
||||
incident := common.IncidentDef{
|
||||
ID: id,
|
||||
Category: r[1],
|
||||
Description: r[2],
|
||||
|
||||
@@ -1,147 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"math"
|
||||
)
|
||||
|
||||
const (
|
||||
// EarthRadius the Earth's radius is about 6,371km according to Wikipedia
|
||||
EarthRadius = 6371
|
||||
)
|
||||
|
||||
// Latitude64 casts the Latitude value to a float64 for convenience.
|
||||
func Latitude64(p GeopositionDef) float64 {
|
||||
return float64(p.Latitude)
|
||||
}
|
||||
|
||||
// Longitude64 casts the Longitude value to a float64 for convenience.
|
||||
func Longitude64(p GeopositionDef) float64 {
|
||||
return float64(p.Longitude)
|
||||
}
|
||||
|
||||
// TopLeftOf returns true if it is above and to the left of "o"
|
||||
func TopLeftOf(p GeopositionDef, o GeopositionDef) bool {
|
||||
return p.Latitude > o.Latitude && p.Longitude < o.Longitude
|
||||
}
|
||||
|
||||
// BelowRightOf returns true if it's below and to the right of "o"
|
||||
func BelowRightOf(p GeopositionDef, o GeopositionDef) bool {
|
||||
return p.Latitude < o.Latitude && p.Longitude > o.Longitude
|
||||
}
|
||||
|
||||
// TopLeftOrSameOf returns true if it is above and to the left of "o"
|
||||
func TopLeftOrSameOf(p GeopositionDef, o GeopositionDef) bool {
|
||||
return p.Latitude >= o.Latitude && p.Longitude <= o.Longitude
|
||||
}
|
||||
|
||||
// BelowRightOrSameOf returns true if it's below and to the right of "o"
|
||||
func BelowRightOrSameOf(p GeopositionDef, o GeopositionDef) bool {
|
||||
return p.Latitude <= o.Latitude && p.Longitude >= o.Longitude
|
||||
}
|
||||
|
||||
// PointAtDistanceAndBearing returns a Point populated with the lat and lng coordinates
|
||||
// by transposing the origin point the passed in distance (in kilometers)
|
||||
// by the passed in compass bearing (in degrees).
|
||||
// Original Implementation from: http://www.movable-type.co.uk/scripts/latlong.html
|
||||
func PointAtDistanceAndBearing(p GeopositionDef, dist float64, bearing float64) *GeopositionDef {
|
||||
dr := dist / EarthRadius
|
||||
|
||||
bearing = bearing * (math.Pi / 180.0)
|
||||
|
||||
lat1 := Latitude64(p) * (math.Pi / 180.0)
|
||||
lng1 := Longitude64(p) * (math.Pi / 180.0)
|
||||
|
||||
lat2Part1 := math.Sin(lat1) * math.Cos(dr)
|
||||
lat2Part2 := math.Cos(lat1) * math.Sin(dr) * math.Cos(bearing)
|
||||
|
||||
lat2 := math.Asin(lat2Part1 + lat2Part2)
|
||||
|
||||
lng2Part1 := math.Sin(bearing) * math.Sin(dr) * math.Cos(lat1)
|
||||
lng2Part2 := math.Cos(dr) - (math.Sin(lat1) * math.Sin(lat2))
|
||||
|
||||
lng2 := lng1 + math.Atan2(lng2Part1, lng2Part2)
|
||||
lng2 = math.Mod((lng2+3*math.Pi), (2*math.Pi)) - math.Pi
|
||||
|
||||
lat2 = lat2 * (180.0 / math.Pi)
|
||||
lng2 = lng2 * (180.0 / math.Pi)
|
||||
|
||||
return &GeopositionDef{Latitude: float32(lat2), Longitude: float32(lng2)}
|
||||
}
|
||||
|
||||
// DistanceTo calculates the Haversine distance between two points in kilometers.
|
||||
// Original Implementation from: http://www.movable-type.co.uk/scripts/latlong.html
|
||||
func DistanceTo(p GeopositionDef, o GeopositionDef) float32 {
|
||||
dLat := (Latitude64(o) - Latitude64(p)) * (math.Pi / 180.0)
|
||||
dLon := (Longitude64(o) - Longitude64(p)) * (math.Pi / 180.0)
|
||||
|
||||
lat1 := Latitude64(p) * (math.Pi / 180.0)
|
||||
lat2 := Latitude64(o) * (math.Pi / 180.0)
|
||||
|
||||
a1 := math.Sin(dLat/2) * math.Sin(dLat/2)
|
||||
a2 := math.Sin(dLon/2) * math.Sin(dLon/2) * math.Cos(lat1) * math.Cos(lat2)
|
||||
|
||||
a := a1 + a2
|
||||
|
||||
c := 2 * math.Atan2(math.Sqrt(a), math.Sqrt(1-a))
|
||||
|
||||
return float32(EarthRadius * c)
|
||||
}
|
||||
|
||||
// BoundingRectangle calculates a rectangle whose sides east/west and north/south.
|
||||
// The center of the rectangle is "p" and each side is "2 * radius" in length.
|
||||
// A radius value of 1 equals 1 kilometer.
|
||||
func BoundingRectangle(p GeopositionDef, radius float64) GeorectangleDef {
|
||||
northPoint := PointAtDistanceAndBearing(p, radius, 0)
|
||||
eastPoint := PointAtDistanceAndBearing(p, radius, 90)
|
||||
southPoint := PointAtDistanceAndBearing(p, radius, 180)
|
||||
westPoint := PointAtDistanceAndBearing(p, radius, 270)
|
||||
|
||||
return GeorectangleDef{
|
||||
TopLeft: GeopositionDef{Latitude: northPoint.Latitude, Longitude: westPoint.Longitude},
|
||||
BottomRight: GeopositionDef{Latitude: southPoint.Latitude, Longitude: eastPoint.Longitude},
|
||||
}
|
||||
}
|
||||
|
||||
// IntersectsRect returns true if "o" intersects r
|
||||
func IntersectsRect(r GeorectangleDef, o GeorectangleDef) bool {
|
||||
return TopLeftOf(r.TopLeft, o.BottomRight) && BelowRightOf(r.BottomRight, o.TopLeft)
|
||||
}
|
||||
|
||||
// ContainsRect returns true if "o" is within r
|
||||
func ContainsRect(r GeorectangleDef, o GeorectangleDef) bool {
|
||||
return TopLeftOrSameOf(r.TopLeft, o.TopLeft) && BelowRightOrSameOf(r.BottomRight, o.BottomRight)
|
||||
}
|
||||
|
||||
// ContainsPoint returns true if p is contained in r
|
||||
func ContainsPoint(r GeorectangleDef, p GeopositionDef) bool {
|
||||
return TopLeftOrSameOf(r.TopLeft, p) && BelowRightOf(r.BottomRight, p)
|
||||
}
|
||||
|
||||
// Split creates one new rectangle for each quadrant in "r"
|
||||
func Split(r GeorectangleDef) (tlRect, blRect, trRect, brRect GeorectangleDef) {
|
||||
maxLat := r.TopLeft.Latitude
|
||||
minLon := r.TopLeft.Longitude
|
||||
minLat := r.BottomRight.Latitude
|
||||
maxLon := r.BottomRight.Longitude
|
||||
midLat := ((maxLat - minLat) / 2) + minLat
|
||||
midLon := ((maxLon - minLon) / 2) + minLon
|
||||
|
||||
tlRect = GeorectangleDef{
|
||||
TopLeft: GeopositionDef{Latitude: maxLat, Longitude: minLon},
|
||||
BottomRight: GeopositionDef{Latitude: midLat, Longitude: midLon},
|
||||
}
|
||||
blRect = GeorectangleDef{
|
||||
TopLeft: GeopositionDef{Latitude: midLat, Longitude: minLon},
|
||||
BottomRight: GeopositionDef{Latitude: minLat, Longitude: midLon},
|
||||
}
|
||||
trRect = GeorectangleDef{
|
||||
TopLeft: GeopositionDef{Latitude: maxLat, Longitude: midLon},
|
||||
BottomRight: GeopositionDef{Latitude: midLat, Longitude: maxLon},
|
||||
}
|
||||
brRect = GeorectangleDef{
|
||||
TopLeft: GeopositionDef{Latitude: midLat, Longitude: midLon},
|
||||
BottomRight: GeopositionDef{Latitude: minLat, Longitude: maxLon},
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
@@ -1,97 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/attic-labs/noms/Godeps/_workspace/src/github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestPoint(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
p1 := GeopositionDef{5, 5}
|
||||
p2 := GeopositionDef{3, 7}
|
||||
p3 := GeopositionDef{10, 7}
|
||||
p4 := GeopositionDef{10, 12}
|
||||
|
||||
assert.True(TopLeftOf(p1, p2))
|
||||
assert.False(TopLeftOf(p2, p1))
|
||||
assert.True(BelowRightOf(p2, p1))
|
||||
assert.False(BelowRightOf(p1, p2))
|
||||
assert.False(TopLeftOf(p1, p1))
|
||||
assert.False(BelowRightOf(p2, p2))
|
||||
|
||||
assert.True(TopLeftOrSameOf(p3, p2))
|
||||
assert.True(TopLeftOrSameOf(p3, p3))
|
||||
assert.False(TopLeftOrSameOf(p4, p3))
|
||||
assert.True(BelowRightOrSameOf(p2, p3))
|
||||
assert.True(BelowRightOrSameOf(p3, p3))
|
||||
assert.False(BelowRightOrSameOf(p3, p4))
|
||||
assert.True(TopLeftOrSameOf(p3, p4))
|
||||
}
|
||||
|
||||
func TestRectangle(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
tl1 := GeopositionDef{10, 5}
|
||||
br1 := GeopositionDef{5, 10}
|
||||
r1 := GeorectangleDef{tl1, br1}
|
||||
|
||||
tl2 := GeopositionDef{9, 7}
|
||||
br2 := GeopositionDef{7, 9}
|
||||
r2 := GeorectangleDef{tl2, br2}
|
||||
|
||||
tl3 := GeopositionDef{30, 20}
|
||||
br3 := GeopositionDef{20, 30}
|
||||
r3 := GeorectangleDef{tl3, br3}
|
||||
|
||||
assert.True(TopLeftOf(tl1, br2))
|
||||
|
||||
assert.True(IntersectsRect(r1, r2))
|
||||
assert.True(IntersectsRect(r2, r1))
|
||||
assert.True(IntersectsRect(r2, r2))
|
||||
|
||||
assert.True(ContainsRect(r1, r2))
|
||||
assert.False(ContainsRect(r2, r1))
|
||||
assert.True(ContainsRect(r2, r2))
|
||||
|
||||
assert.False(IntersectsRect(r1, r3))
|
||||
assert.False(ContainsRect(r1, r3))
|
||||
|
||||
assert.True(ContainsPoint(r1, tl2))
|
||||
assert.False(ContainsPoint(r1, br3))
|
||||
|
||||
tlRect, blRect, trRect, brRect := Split(r3)
|
||||
tl0 := GeopositionDef{30, 20}
|
||||
tm0 := GeopositionDef{30, 25}
|
||||
lm0 := GeopositionDef{25, 20}
|
||||
mm0 := GeopositionDef{25, 25}
|
||||
rm0 := GeopositionDef{25, 30}
|
||||
bm0 := GeopositionDef{20, 25}
|
||||
br0 := GeopositionDef{20, 30}
|
||||
|
||||
topLeft := GeorectangleDef{tl0, mm0}
|
||||
bottomLeft := GeorectangleDef{lm0, bm0}
|
||||
topRight := GeorectangleDef{tm0, rm0}
|
||||
bottomRight := GeorectangleDef{mm0, br0}
|
||||
|
||||
assert.True(tlRect == topLeft)
|
||||
assert.True(blRect == bottomLeft)
|
||||
assert.True(trRect == topRight)
|
||||
assert.True(brRect == bottomRight)
|
||||
}
|
||||
|
||||
func TestDistances(t *testing.T) {
|
||||
p1 := GeopositionDef{37.83, -122.52}
|
||||
p2 := GeopositionDef{37.70, -122.36}
|
||||
|
||||
km1 := DistanceTo(p1, p2)
|
||||
fmt.Printf("distance from %v to %v: %f\n", p1, p2, km1)
|
||||
km2 := DistanceTo(p2, p1)
|
||||
fmt.Printf("distance from %v to %v: %f\n", p2, p1, km2)
|
||||
assert.Equal(t, km1, km2)
|
||||
|
||||
point := GeopositionDef{37.7644008, -122.4511607}
|
||||
kms := 0.9
|
||||
boundingRect := BoundingRectangle(point, kms)
|
||||
fmt.Printf("Point: %v, distance: %f kms, Bounding %v", point, kms, boundingRect)
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
package main
|
||||
|
||||
const (
|
||||
maxNodes = 16
|
||||
maxDepth = 10
|
||||
tl = "TopLeft"
|
||||
bl = "BottomLeft"
|
||||
tr = "TopRight"
|
||||
br = "BottomRight"
|
||||
)
|
||||
|
||||
var (
|
||||
quadrants = []string{tl, bl, tr, br}
|
||||
)
|
||||
|
||||
func (qt *SQuadTree) Query(p GeopositionDef, kilometers float64) (GeorectangleDef, []Incident) {
|
||||
r := BoundingRectangle(p, kilometers)
|
||||
nodes := qt.Search(r, p, float32(kilometers))
|
||||
return r, nodes
|
||||
}
|
||||
|
||||
func (qt *SQuadTree) Search(r GeorectangleDef, p GeopositionDef, kilometers float32) []Incident {
|
||||
nodes := []Incident{}
|
||||
if qt.Tiles().Len() > 0 {
|
||||
for _, q := range quadrants {
|
||||
tile := qt.Tiles().Get(q)
|
||||
if IntersectsRect(tile.Georectangle().Def(), r) {
|
||||
tnodes := tile.Search(r, p, kilometers)
|
||||
nodes = append(nodes, tnodes...)
|
||||
}
|
||||
}
|
||||
} else if qt.Nodes().Len() > 0 {
|
||||
qt.Nodes().Iter(func(n Incident, i uint64) bool {
|
||||
if DistanceTo(p, n.Geoposition().Def()) < kilometers {
|
||||
nodes = append(nodes, n)
|
||||
}
|
||||
return false
|
||||
})
|
||||
}
|
||||
|
||||
return nodes
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
package main
|
||||
|
||||
//go:generate go run ../../nomdl/codegen/codegen.go -package=main -out-dir=.
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/attic-labs/noms/clients/common"
|
||||
"github.com/attic-labs/noms/d"
|
||||
"github.com/attic-labs/noms/datas"
|
||||
"github.com/attic-labs/noms/ref"
|
||||
@@ -23,7 +24,7 @@ var (
|
||||
latFlag = flag.Float64("lat", 0.0, "latitude of point to search for crime instances")
|
||||
lonFlag = flag.Float64("lon", 0.0, "longitude of point to search for crime instances")
|
||||
distanceFlag = flag.Float64("distance", 0.5, "distince in kilometers from point to search for crime instances")
|
||||
sqtRoot SQuadTree
|
||||
sqtRoot common.SQuadTree
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -54,8 +55,8 @@ func main() {
|
||||
return
|
||||
}
|
||||
|
||||
gp := GeopositionDef{Latitude: float32(*latFlag), Longitude: float32(*lonFlag)}
|
||||
var incidents []Incident
|
||||
gp := common.GeopositionDef{Latitude: float32(*latFlag), Longitude: float32(*lonFlag)}
|
||||
var incidents []common.Incident
|
||||
if *quadTreeRefFlag != "" {
|
||||
incidents = searchWithQuadTree(gp, datastore)
|
||||
} else if *incidentListRefFlag != "" {
|
||||
@@ -66,7 +67,7 @@ func main() {
|
||||
return
|
||||
}
|
||||
|
||||
var resDefs []IncidentDef
|
||||
var resDefs []common.IncidentDef
|
||||
for _, incident := range incidents {
|
||||
resDefs = append(resDefs, incident.Def())
|
||||
}
|
||||
@@ -78,11 +79,11 @@ func main() {
|
||||
fmt.Printf("Done, elapsed time: %.2f secs\n", time.Now().Sub(start).Seconds())
|
||||
}
|
||||
|
||||
func searchWithQuadTree(gp GeopositionDef, ds datas.DataStore) []Incident {
|
||||
func searchWithQuadTree(gp common.GeopositionDef, ds datas.DataStore) []common.Incident {
|
||||
argName := "quadtree-ref"
|
||||
r := readRef(*quadTreeRefFlag, argName)
|
||||
sqtRoot := types.ReadValue(r, ds).(SQuadTree)
|
||||
if !ContainsPoint(sqtRoot.Georectangle().Def(), gp) {
|
||||
sqtRoot := types.ReadValue(r, ds).(common.SQuadTree)
|
||||
if !common.ContainsPoint(sqtRoot.Georectangle().Def(), gp) {
|
||||
log.Fatalf("lat/lon: %+v is not within sf area: %+v\n", gp, sqtRoot.Georectangle().Def())
|
||||
}
|
||||
gr, results := sqtRoot.Query(gp, *distanceFlag, ds)
|
||||
@@ -90,7 +91,7 @@ func searchWithQuadTree(gp GeopositionDef, ds datas.DataStore) []Incident {
|
||||
return results
|
||||
}
|
||||
|
||||
func searchWithList(gp GeopositionDef, ds datas.DataStore) []Incident {
|
||||
func searchWithList(gp common.GeopositionDef, ds datas.DataStore) []common.Incident {
|
||||
argName := "incident-list-ref"
|
||||
r := readRef(*incidentListRefFlag, argName)
|
||||
val := types.ReadValue(r, ds)
|
||||
@@ -101,15 +102,15 @@ func searchWithList(gp GeopositionDef, ds datas.DataStore) []Incident {
|
||||
if l.Len() == 0 {
|
||||
log.Fatalf("Value for %s argument is an empty list\n", argName)
|
||||
}
|
||||
results := []Incident{}
|
||||
incidentList := ListOfRefOfValueFromVal(val)
|
||||
results := []common.Incident{}
|
||||
incidentList := common.ListOfRefOfValueFromVal(val)
|
||||
t0 := time.Now()
|
||||
for i := uint64(0); i < incidentList.Len(); i++ {
|
||||
if i%uint64(10000) == 0 {
|
||||
fmt.Printf("%.2f%%: %v\n", float64(i)/float64(incidentList.Len())*float64(100), time.Now().Sub(t0))
|
||||
}
|
||||
incident := incidentList.Get(i).TargetValue(ds).(Incident)
|
||||
if DistanceTo(incident.Geoposition().Def(), gp) <= float32(*distanceFlag) {
|
||||
incident := incidentList.Get(i).TargetValue(ds).(common.Incident)
|
||||
if common.DistanceTo(incident.Geoposition().Def(), gp) <= float32(*distanceFlag) {
|
||||
results = append(results, incident)
|
||||
}
|
||||
}
|
||||
@@ -127,7 +128,7 @@ func readRef(rs string, argName string) ref.Ref {
|
||||
return r
|
||||
}
|
||||
|
||||
type ByDate []IncidentDef
|
||||
type ByDate []common.IncidentDef
|
||||
|
||||
func (s ByDate) Len() int {
|
||||
return len(s)
|
||||
|
||||
@@ -1,217 +0,0 @@
|
||||
// This file was generated by nomdl/codegen.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/attic-labs/noms/ref"
|
||||
"github.com/attic-labs/noms/types"
|
||||
)
|
||||
|
||||
var __mainPackageInFile_sha1_6d5e1c5_CachedRef ref.Ref
|
||||
|
||||
// This function builds up a Noms value that describes the type
|
||||
// package implemented by this file and registers it with the global
|
||||
// type package definition cache.
|
||||
func init() {
|
||||
p := types.NewPackage([]types.TypeRef{
|
||||
types.MakeStructTypeRef("Geoposition",
|
||||
[]types.Field{
|
||||
types.Field{"Latitude", types.MakePrimitiveTypeRef(types.Float32Kind), false},
|
||||
types.Field{"Longitude", types.MakePrimitiveTypeRef(types.Float32Kind), false},
|
||||
},
|
||||
types.Choices{},
|
||||
),
|
||||
types.MakeStructTypeRef("Georectangle",
|
||||
[]types.Field{
|
||||
types.Field{"TopLeft", types.MakeTypeRef(ref.Ref{}, 0), false},
|
||||
types.Field{"BottomRight", types.MakeTypeRef(ref.Ref{}, 0), false},
|
||||
},
|
||||
types.Choices{},
|
||||
),
|
||||
}, []ref.Ref{})
|
||||
__mainPackageInFile_sha1_6d5e1c5_CachedRef = types.RegisterPackage(&p)
|
||||
}
|
||||
|
||||
// Geoposition
|
||||
|
||||
type Geoposition struct {
|
||||
m types.Map
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
func NewGeoposition() Geoposition {
|
||||
return Geoposition{types.NewMap(
|
||||
types.NewString("Latitude"), types.Float32(0),
|
||||
types.NewString("Longitude"), types.Float32(0),
|
||||
), &ref.Ref{}}
|
||||
}
|
||||
|
||||
type GeopositionDef struct {
|
||||
Latitude float32
|
||||
Longitude float32
|
||||
}
|
||||
|
||||
func (def GeopositionDef) New() Geoposition {
|
||||
return Geoposition{
|
||||
types.NewMap(
|
||||
types.NewString("Latitude"), types.Float32(def.Latitude),
|
||||
types.NewString("Longitude"), types.Float32(def.Longitude),
|
||||
), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s Geoposition) Def() (d GeopositionDef) {
|
||||
d.Latitude = float32(s.m.Get(types.NewString("Latitude")).(types.Float32))
|
||||
d.Longitude = float32(s.m.Get(types.NewString("Longitude")).(types.Float32))
|
||||
return
|
||||
}
|
||||
|
||||
var __typeRefForGeoposition types.TypeRef
|
||||
|
||||
func (m Geoposition) TypeRef() types.TypeRef {
|
||||
return __typeRefForGeoposition
|
||||
}
|
||||
|
||||
func init() {
|
||||
__typeRefForGeoposition = types.MakeTypeRef(__mainPackageInFile_sha1_6d5e1c5_CachedRef, 0)
|
||||
types.RegisterFromValFunction(__typeRefForGeoposition, func(v types.Value) types.Value {
|
||||
return GeopositionFromVal(v)
|
||||
})
|
||||
}
|
||||
|
||||
func GeopositionFromVal(val types.Value) Geoposition {
|
||||
// TODO: Do we still need FromVal?
|
||||
if val, ok := val.(Geoposition); ok {
|
||||
return val
|
||||
}
|
||||
// TODO: Validate here
|
||||
return Geoposition{val.(types.Map), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s Geoposition) InternalImplementation() types.Map {
|
||||
return s.m
|
||||
}
|
||||
|
||||
func (s Geoposition) Equals(other types.Value) bool {
|
||||
if other, ok := other.(Geoposition); ok {
|
||||
return s.Ref() == other.Ref()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (s Geoposition) Ref() ref.Ref {
|
||||
return types.EnsureRef(s.ref, s)
|
||||
}
|
||||
|
||||
func (s Geoposition) Chunks() (chunks []ref.Ref) {
|
||||
chunks = append(chunks, s.TypeRef().Chunks()...)
|
||||
chunks = append(chunks, s.m.Chunks()...)
|
||||
return
|
||||
}
|
||||
|
||||
func (s Geoposition) Latitude() float32 {
|
||||
return float32(s.m.Get(types.NewString("Latitude")).(types.Float32))
|
||||
}
|
||||
|
||||
func (s Geoposition) SetLatitude(val float32) Geoposition {
|
||||
return Geoposition{s.m.Set(types.NewString("Latitude"), types.Float32(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s Geoposition) Longitude() float32 {
|
||||
return float32(s.m.Get(types.NewString("Longitude")).(types.Float32))
|
||||
}
|
||||
|
||||
func (s Geoposition) SetLongitude(val float32) Geoposition {
|
||||
return Geoposition{s.m.Set(types.NewString("Longitude"), types.Float32(val)), &ref.Ref{}}
|
||||
}
|
||||
|
||||
// Georectangle
|
||||
|
||||
type Georectangle struct {
|
||||
m types.Map
|
||||
ref *ref.Ref
|
||||
}
|
||||
|
||||
func NewGeorectangle() Georectangle {
|
||||
return Georectangle{types.NewMap(
|
||||
types.NewString("TopLeft"), NewGeoposition(),
|
||||
types.NewString("BottomRight"), NewGeoposition(),
|
||||
), &ref.Ref{}}
|
||||
}
|
||||
|
||||
type GeorectangleDef struct {
|
||||
TopLeft GeopositionDef
|
||||
BottomRight GeopositionDef
|
||||
}
|
||||
|
||||
func (def GeorectangleDef) New() Georectangle {
|
||||
return Georectangle{
|
||||
types.NewMap(
|
||||
types.NewString("TopLeft"), def.TopLeft.New(),
|
||||
types.NewString("BottomRight"), def.BottomRight.New(),
|
||||
), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s Georectangle) Def() (d GeorectangleDef) {
|
||||
d.TopLeft = s.m.Get(types.NewString("TopLeft")).(Geoposition).Def()
|
||||
d.BottomRight = s.m.Get(types.NewString("BottomRight")).(Geoposition).Def()
|
||||
return
|
||||
}
|
||||
|
||||
var __typeRefForGeorectangle types.TypeRef
|
||||
|
||||
func (m Georectangle) TypeRef() types.TypeRef {
|
||||
return __typeRefForGeorectangle
|
||||
}
|
||||
|
||||
func init() {
|
||||
__typeRefForGeorectangle = types.MakeTypeRef(__mainPackageInFile_sha1_6d5e1c5_CachedRef, 1)
|
||||
types.RegisterFromValFunction(__typeRefForGeorectangle, func(v types.Value) types.Value {
|
||||
return GeorectangleFromVal(v)
|
||||
})
|
||||
}
|
||||
|
||||
func GeorectangleFromVal(val types.Value) Georectangle {
|
||||
// TODO: Do we still need FromVal?
|
||||
if val, ok := val.(Georectangle); ok {
|
||||
return val
|
||||
}
|
||||
// TODO: Validate here
|
||||
return Georectangle{val.(types.Map), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s Georectangle) InternalImplementation() types.Map {
|
||||
return s.m
|
||||
}
|
||||
|
||||
func (s Georectangle) Equals(other types.Value) bool {
|
||||
if other, ok := other.(Georectangle); ok {
|
||||
return s.Ref() == other.Ref()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (s Georectangle) Ref() ref.Ref {
|
||||
return types.EnsureRef(s.ref, s)
|
||||
}
|
||||
|
||||
func (s Georectangle) Chunks() (chunks []ref.Ref) {
|
||||
chunks = append(chunks, s.TypeRef().Chunks()...)
|
||||
chunks = append(chunks, s.m.Chunks()...)
|
||||
return
|
||||
}
|
||||
|
||||
func (s Georectangle) TopLeft() Geoposition {
|
||||
return s.m.Get(types.NewString("TopLeft")).(Geoposition)
|
||||
}
|
||||
|
||||
func (s Georectangle) SetTopLeft(val Geoposition) Georectangle {
|
||||
return Georectangle{s.m.Set(types.NewString("TopLeft"), val), &ref.Ref{}}
|
||||
}
|
||||
|
||||
func (s Georectangle) BottomRight() Geoposition {
|
||||
return s.m.Get(types.NewString("BottomRight")).(Geoposition)
|
||||
}
|
||||
|
||||
func (s Georectangle) SetBottomRight(val Geoposition) Georectangle {
|
||||
return Georectangle{s.m.Set(types.NewString("BottomRight"), val), &ref.Ref{}}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
alias Photo = import "../types/photo.noms"
|
||||
alias Photo = import "../common/photo.noms"
|
||||
|
||||
using Map(String, Set(Ref(Photo.RemotePhoto)))
|
||||
using Set(Ref(Photo.RemotePhoto))
|
||||
|
||||
Reference in New Issue
Block a user