-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.go
executable file
·105 lines (87 loc) · 3.18 KB
/
model.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package main
import (
"math"
"time"
mgo "gopkg.in/mgo.v2"
"gopkg.in/mgo.v2/bson"
)
// ========== data section
type tokenReq struct {
Token string `form:"token" binding:"required" bson:"token"`
}
type distanceReq struct {
Distance float64 `form:"distance" binding:"required"`
}
// ========== Users
type (
geoUser struct {
ID bson.ObjectId `form:"_id" bson:"_id,omitempty"`
Name string `form:"name" bson:"name,omitempty"`
Text string `form:"text" bson:"text,omitempty"`
Tags []string `form:"tags" bson:"tags,omitempty"`
Email string `form:"email" bson:"email,omitempty"`
Events []mgo.DBRef `form:"events" bson:"events,omitempty"`
}
)
// ========== Events
// Event struct for processing events
type (
geoEvent struct {
ID bson.ObjectId `form:"_id" bson:"_id,omitempty"`
Name string `form:"name" bson:"name,omitempty"`
Text string `form:"text" bson:"text,omitempty"`
Tags []string `form:"tags" bson:"tags,omitempty"`
TTLEvent time.Time `form:"ttl" bson:"ttl,omitempty"`
Timestamp time.Time `form:"timestamp" bson:"timestamp,omitempty"`
Users []mgo.DBRef `form:"users" bson:"users,omitempty"`
}
)
// ========== locs
// id GeoLocation should be id user/event
type (
geoObject struct {
Type string `json:"type,omitempty"`
Coordinates [2]float64 `json:"coordinates,omitempty"`
}
geoLocation struct {
ID bson.ObjectId `form:"_id" json:"_id,omitempty" bson:"_id,omitempty"`
TObject string `form:"tobject" json:"tobject,omitempty" bson:"tobject,omitempty"`
Location geoObject `form:"location" json:"location,omitempty" bson:"location,omitempty"`
}
respondID struct {
ID bson.ObjectId `form:"_id" json:"_id,omitempty"`
}
reqGeoEvent struct {
GeoLoc geoLocation `form:"geoloc" json:"geoloc,omitempty"`
Event geoEvent `form:"event" json:"event,omitempty"`
}
reqNear struct {
Scope float64 `form:"scope" json:"scope,omitempty"`
TGeos string `form:"tgeos" json:"tgeos,omitempty"`
Lat float64 `form:"lat" json:"lat,omitempty"`
Lng float64 `form:"lng" json:"lng,omitempty"`
}
reqFilter struct {
TObject string `form:"tobject" json:"tobject,omitempty"`
Scope float64 `form:"scope" json:"scope,omitempty"`
TTime string `form:"ttime" json:"ttime,omitempty"`
Tags []string `form:"tags" json:"tags,omitempty"`
Lat float64 `form:"lat" json:"lat,omitempty"`
Lng float64 `form:"lng" json:"lng,omitempty"`
}
eventLoc struct {
ID bson.ObjectId `form:"_id" bson:"_id,omitempty"`
Name string `form:"name" bson:"name,omitempty"`
Text string `form:"text" bson:"text,omitempty"`
Tags []string `form:"tags" bson:"tags,omitempty"`
TObject string `form:"tobject" bson:"tobject,omitempty"`
Timestamp time.Time `form:"timestamp" bson:"timestamp,omitempty"`
Location geoObject `form:"location" bson:"location,omitempty"`
}
)
func distance(locFrom, locTo *geoLocation) float64 {
return math.Sqrt(
math.Pow(locFrom.Location.Coordinates[0]-locTo.Location.Coordinates[0], 2) +
math.Pow(locFrom.Location.Coordinates[1]-locTo.Location.Coordinates[1], 2),
)
}