-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.go
More file actions
85 lines (75 loc) · 1.37 KB
/
database.go
File metadata and controls
85 lines (75 loc) · 1.37 KB
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
package main
import (
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/sqlite"
)
type Session struct {
gorm.Model
Name string
User string
StartTime int
EndTime int
Datapoints []Datapoint `gorm:"foreignkey:SessionId"`
Beacons []SessionBeacon `gorm:"foreignkey:SessionId"`
Locations []Location `gorm:"foreignkey:SessionId"`
Finished bool `gorm:"default:false"`
Map string
}
type Datapoint struct {
gorm.Model
SessionId int
UUID string
Major string
Minor string
Timestamp int
RSSI int
Steps int
RotationX float64
RotationY float64
RotationZ float64
}
type Beacon struct {
gorm.Model
UUID string
Major string
Minor string
Name string
}
type SessionBeacon struct {
gorm.Model
SessionId int
UUID string
Major string
Minor string
Name string
XCoordinate float64
YCoordinate float64
}
type Location struct {
gorm.Model
SessionId int
StartTime int
EndTime int
XCoordinate float64
YCoordinate float64
Duration int
Walking bool
HeadMovement bool
}
type URL struct {
Url string
}
var db *gorm.DB
func init() {
init_db, err := gorm.Open("sqlite3", "firetracker.db")
if err != nil {
panic("failed to connect database")
}
db = init_db
db.Set("gorm:auto_preload", true)
db.AutoMigrate(&Session{})
db.AutoMigrate(&Datapoint{})
db.AutoMigrate(&Beacon{})
db.AutoMigrate(&SessionBeacon{})
db.AutoMigrate(&Location{})
}