Просмотр исходного кода

chore: remove unecessary types

master
Blaz Smehov 2 недель назад
Родитель
Сommit
7411f34002
6 измененных файлов: 1496 добавлений и 49 удалений
  1. +1
    -1
      cmd/server/main.go
  2. +4
    -4
      internal/pkg/apiclient/updatedb.go
  3. +16
    -14
      internal/pkg/model/trackers.go
  4. +0
    -28
      internal/pkg/model/types.go
  5. +8
    -2
      internal/pkg/service/beacon_service.go
  6. +1467
    -0
      logging.md

+ 1
- 1
cmd/server/main.go Просмотреть файл

@@ -160,7 +160,7 @@ eventLoop:
continue
}

if err := db.Updates(&model.Tracker{ID: id, Battery: msg.Battery}).Error; err != nil {
if err := db.Updates(&model.Tracker{ID: id, Battery: msg.Battery, Temperature: msg.Temperature}).Error; err != nil {
fmt.Printf("Error in saving decoder event for beacon: %s\n", id)
continue
}


+ 4
- 4
internal/pkg/apiclient/updatedb.go Просмотреть файл

@@ -50,10 +50,10 @@ func UpdateDB(db *gorm.DB, ctx context.Context, cfg *config.Config, writer *kafk
syncTable(db, gateways)
}

if tracks, err := GetTracks(token, client); err == nil {
fmt.Printf("Tracks: %+v\n", tracks)
syncTable(db, tracks)
}
// if tracks, err := GetTracks(token, client); err == nil {
// fmt.Printf("Tracks: %+v\n", tracks)
// syncTable(db, tracks)
// }

if zones, err := GetZones(token, client); err == nil {
syncTable(db, zones)


+ 16
- 14
internal/pkg/model/trackers.go Просмотреть файл

@@ -1,18 +1,20 @@
package model

type Tracker struct {
ID string `json:"id" gorm:"primaryKey"`
Name string `json:"name"`
MAC string `json:"mac"`
Status string `json:"status"`
Model string `json:"model"`
Position string `json:"position"`
Notes string `json:"notes"`
X float32 `json:"x"`
Y float32 `json:"y"`
Floor string `json:"floor"`
Building string `json:"building"`
Location string `json:"location"`
Distance float64 `json:"distance"`
Battery uint32 `json:"battery"`
ID string `json:"id" gorm:"primaryKey"`
Name string `json:"name"`
MAC string `json:"mac"`
Status string `json:"status"`
Model string `json:"model"`
Position string `json:"position"`
Notes string `json:"notes"`
X float32 `json:"x"`
Y float32 `json:"y"`
Floor string `json:"floor"`
Building string `json:"building"`
Location string `json:"location"`
Distance float64 `json:"distance"`
Battery uint32 `json:"battery"`
BatteryThreshold uint32 `json:"batteryThreshold"`
Temperature uint16 `json:"temperature"`
}

+ 0
- 28
internal/pkg/model/types.go Просмотреть файл

@@ -35,12 +35,6 @@ type BeaconMetric struct {
Timestamp int64
}

// Location defines a physical location and synchronization control.
type Location struct {
Name string
Lock sync.RWMutex
}

// HTTPLocation describes a beacon's state as served over HTTP.
type HTTPLocation struct {
Method string `json:"method"`
@@ -51,17 +45,6 @@ type HTTPLocation struct {
LastSeen int64 `json:"last_seen"`
}

// LocationChange defines a change event for a beacon's detected location.
type LocationChange struct {
Method string `json:"method"`
BeaconRef Beacon `json:"beacon_info"`
Name string `json:"name"`
BeaconName string `json:"beacon_name"`
PreviousLocation string `json:"previous_location"`
NewLocation string `json:"new_location"`
Timestamp int64 `json:"timestamp"`
}

// Beacon holds all relevant information about a tracked beacon device.
type Beacon struct {
Name string `json:"name"`
@@ -136,12 +119,6 @@ type BeaconEventList struct {
Lock sync.RWMutex
}

// LocationsList holds all known locations with concurrency protection.
type LocationsList struct {
Locations map[string]Location
Lock sync.RWMutex
}

// RawReading represents an incoming raw sensor reading.
type RawReading struct {
Timestamp string `json:"timestamp"`
@@ -151,11 +128,6 @@ type RawReading struct {
RawData string `json:"rawData"`
}

type LatestBeaconsList struct {
LatestList map[string]Beacon
Lock sync.RWMutex
}

type ApiUpdate struct {
Method string
ID string


+ 8
- 2
internal/pkg/service/beacon_service.go Просмотреть файл

@@ -25,6 +25,11 @@ func LocationToBeaconService(msg model.HTTPLocation, db *gorm.DB, writer *kafka.
return
}

var tracker model.Tracker
if err := db.Where("id = ?", msg.ID).Find(&tracker).Error; err != nil {
return
}

var allowedZones []string
for _, z := range zones {
allowedZones = append(allowedZones, z.ZoneList...)
@@ -55,12 +60,13 @@ func LocationToBeaconService(msg model.HTTPLocation, db *gorm.DB, writer *kafka.
}
}

if err := db.Create(&model.Tracks{UUID: msg.ID, Timestamp: time.Now(), Gateway: gw.ID, GatewayMac: gw.MAC, Tracker: msg.ID}).Error; err != nil {
// status, subject, subject name?
if err := db.Create(&model.Tracks{UUID: msg.ID, Timestamp: time.Now(), Gateway: gw.ID, GatewayMac: gw.MAC, Tracker: msg.ID, Floor: gw.Floor, Building: gw.Building, TrackerMac: tracker.MAC}).Error; err != nil {
fmt.Println("Error in saving distance for beacon: ", err)
return
}

if err := db.Updates(&model.Tracker{ID: msg.ID, Location: gw.ID, Distance: msg.Distance}).Error; err != nil {
if err := db.Updates(&model.Tracker{ID: msg.ID, Location: gw.ID, Distance: msg.Distance, X: gw.X, Y: gw.Y}).Error; err != nil {
fmt.Println("Error in saving distance for beacon: ", err)
return
}


+ 1467
- 0
logging.md
Разница между файлами не показана из-за своего большого размера
Просмотреть файл


Загрузка…
Отмена
Сохранить