Compare commits
No commits in common. "c8f973019caf12f114f032fcf001447b9ce11d26" and "766b313911467ca8409e9b5f0aee494f858695ea" have entirely different histories.
c8f973019c
...
766b313911
|
@ -1,24 +1,2 @@
|
|||
.env
|
||||
map-dots
|
||||
|
||||
# If you prefer the allow list template instead of the deny list, see community template:
|
||||
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
|
||||
#
|
||||
# Binaries for programs and plugins
|
||||
*.exe
|
||||
*.exe~
|
||||
*.dll
|
||||
*.so
|
||||
*.dylib
|
||||
|
||||
# Test binary, built with `go test -c`
|
||||
*.test
|
||||
|
||||
# Output of the go coverage tool, specifically when used with LiteIDE
|
||||
*.out
|
||||
|
||||
# Dependency directories (remove the comment below to include it)
|
||||
# vendor/
|
||||
|
||||
# Go workspace file
|
||||
go.work
|
|
@ -1,8 +0,0 @@
|
|||
package data
|
||||
|
||||
type LocationData struct {
|
||||
Latitude float64
|
||||
Longitude float64
|
||||
Speed uint32
|
||||
Altitude float64
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
package traccar
|
||||
|
||||
import "git.fjla.uk/fred.boniface/map-dots/data"
|
||||
|
||||
func MapToPositionData(positions []Positions) []data.LocationData {
|
||||
var locationDataList []data.LocationData
|
||||
|
||||
for _, pos := range positions {
|
||||
speedInMph := int(pos.Speed * 1.15078)
|
||||
// Unsure of the accuracy of the speed data
|
||||
|
||||
locationData := data.LocationData{
|
||||
Latitude: pos.Latitude,
|
||||
Longitude: pos.Longitude,
|
||||
Speed: uint32(speedInMph),
|
||||
Altitude: pos.Altitude,
|
||||
}
|
||||
|
||||
locationDataList = append(locationDataList, locationData)
|
||||
}
|
||||
|
||||
return locationDataList
|
||||
}
|
|
@ -1,96 +0,0 @@
|
|||
package traccar
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
|
||||
"git.fjla.uk/fred.boniface/map-dots/data"
|
||||
)
|
||||
|
||||
var user string = os.Getenv("TRACCAR_USER")
|
||||
var pass string = os.Getenv("TRACCAR_PASS")
|
||||
|
||||
var params = map[string]string{
|
||||
"deviceId": "2",
|
||||
"from": "2023-07-10T20:00:00Z",
|
||||
"to": "2023-08-10T20:00:00Z",
|
||||
}
|
||||
|
||||
func GetPositions() ([]data.LocationData, error) {
|
||||
req, err := createRequest()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
client := http.Client{}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var positions []Positions
|
||||
err = json.Unmarshal(body, &positions)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return MapToPositionData(positions), err
|
||||
}
|
||||
|
||||
func createRequest() (*http.Request, error) {
|
||||
baseURL := "https://traccar.fjla.uk/api/positions"
|
||||
|
||||
u, err := url.Parse(baseURL)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
queryParams := url.Values{}
|
||||
|
||||
for key, value := range params {
|
||||
queryParams.Add(key, value)
|
||||
}
|
||||
|
||||
u.RawQuery = queryParams.Encode()
|
||||
|
||||
req, err := http.NewRequest("GET", u.String(), nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
req.SetBasicAuth(user, pass)
|
||||
|
||||
return req, nil
|
||||
}
|
||||
|
||||
type Attributes map[string]interface{} // Generic map to hold attributes
|
||||
|
||||
type Positions struct {
|
||||
ID int64 `json:"id"`
|
||||
Attributes Attributes `json:"attributes"`
|
||||
DeviceID int64 `json:"deviceId"`
|
||||
Protocol string `json:"protocol"`
|
||||
ServerTime string `json:"serverTime"`
|
||||
DeviceTime string `json:"deviceTime"`
|
||||
FixTime string `json:"fixTime"`
|
||||
Outdated bool `json:"outdated"`
|
||||
Valid bool `json:"valid"`
|
||||
Latitude float64 `json:"latitude"`
|
||||
Longitude float64 `json:"longitude"`
|
||||
Altitude float64 `json:"altitude"`
|
||||
Speed float64 `json:"speed"`
|
||||
Course float64 `json:"course"`
|
||||
Address string `json:"address"`
|
||||
Accuracy float64 `json:"accuracy"`
|
||||
Network interface{} `json:"network"` // Inferred as interface{} since it's not clear
|
||||
GeofenceIDs interface{} `json:"geofenceIds"` // Inferred as interface{} since it's not clear
|
||||
}
|
Loading…
Reference in New Issue