Bläddra i källkod

fix: missing beacons init in context, remove redundant properties of httpRes type

chore/restructure-decoder
Blaz Smehov 1 vecka sedan
förälder
incheckning
c7e02b373a
2 ändrade filer med 11 tillägg och 19 borttagningar
  1. +11
    -13
      cmd/location/main.go
  2. +0
    -6
      internal/pkg/model/types.go

+ 11
- 13
cmd/location/main.go Visa fil

@@ -24,7 +24,7 @@ func main() {
BeaconMetricSize: 30, BeaconMetricSize: 30,
HASendInterval: 5, HASendInterval: 5,
HASendChangesOnly: false, HASendChangesOnly: false,
RSSIEnforceThreshold: true,
RSSIEnforceThreshold: false,
RSSIMinThreshold: 100, RSSIMinThreshold: 100,
}, },
}, },
@@ -32,6 +32,9 @@ func main() {
LatestList: model.LatestBeaconsList{ LatestList: model.LatestBeaconsList{
LatestList: make(map[string]model.Beacon), LatestList: make(map[string]model.Beacon),
}, },
Beacons: model.BeaconsList{
Beacons: make(map[string]model.Beacon),
},
} }


cfg := config.Load() cfg := config.Load()
@@ -83,13 +86,10 @@ func getLikelyLocations(ctx *model.AppContext, writer *kafka.Writer) {
ctx.Beacons.Lock.Unlock() ctx.Beacons.Lock.Unlock()


for _, beacon := range beacons { for _, beacon := range beacons {
fmt.Printf("beacon: %+v", beacon)

// Shrinking the model because other properties have nothing to do with the location // Shrinking the model because other properties have nothing to do with the location
r := model.HTTPLocation{ r := model.HTTPLocation{
Method: "Standard", Method: "Standard",
Distance: 999, Distance: 999,
Name: beacon.Name,
ID: beacon.ID, ID: beacon.ID,
Location: "", Location: "",
LastSeen: 999, LastSeen: 999,
@@ -188,30 +188,28 @@ func assignBeaconToList(adv model.BeaconAdvertisement, ctx *model.AppContext) {
now := time.Now().Unix() now := time.Now().Unix()


if !ok { if !ok {
// handle removing from the list somewhere else, probably at the point where this is being used which is nowhere in the original code
ctx.LatestList.Lock.Lock() ctx.LatestList.Lock.Lock()
ctx.LatestList.LatestList[id] = model.Beacon{ID: id, BeaconType: adv.BeaconType, LastSeen: now, IncomingJSON: adv, BeaconLocation: adv.Hostname, Distance: getBeaconDistance(adv)} ctx.LatestList.LatestList[id] = model.Beacon{ID: id, BeaconType: adv.BeaconType, LastSeen: now, IncomingJSON: adv, BeaconLocation: adv.Hostname, Distance: getBeaconDistance(adv)}
ctx.LatestList.Lock.Unlock() ctx.LatestList.Lock.Unlock()
return return
} }


fmt.Println("Beacon exists: ", id)

fmt.Println("RSSI: ", adv.RSSI)
if ctx.Settings.Settings.RSSIEnforceThreshold && (int64(adv.RSSI) < ctx.Settings.Settings.RSSIMinThreshold) { if ctx.Settings.Settings.RSSIEnforceThreshold && (int64(adv.RSSI) < ctx.Settings.Settings.RSSIMinThreshold) {
return return
} }


ctx.Beacons.Lock.Lock() ctx.Beacons.Lock.Lock()
beacon := ctx.Beacons.Beacons[id]
beacon, ok := ctx.Beacons.Beacons[id]
if !ok {
beacon = model.Beacon{
ID: id,
}
}
ctx.Beacons.Lock.Unlock() ctx.Beacons.Lock.Unlock()


beacon.IncomingJSON = adv beacon.IncomingJSON = adv
beacon.LastSeen = now beacon.LastSeen = now
beacon.BeaconType = adv.BeaconType
beacon.HSButtonCounter = adv.HSButtonCounter
beacon.HSBattery = adv.HSBatteryLevel
beacon.HSRandomNonce = adv.HSRandomNonce
beacon.HSButtonMode = adv.HSButtonMode


if beacon.BeaconMetrics == nil { if beacon.BeaconMetrics == nil {
beacon.BeaconMetrics = make([]model.BeaconMetric, 0, ctx.Settings.Settings.BeaconMetricSize) beacon.BeaconMetrics = make([]model.BeaconMetric, 0, ctx.Settings.Settings.BeaconMetricSize)


+ 0
- 6
internal/pkg/model/types.go Visa fil

@@ -78,13 +78,7 @@ type HTTPLocation struct {
Method string `json:"method"` Method string `json:"method"`
PreviousConfidentLocation string `json:"previous_confident_location"` PreviousConfidentLocation string `json:"previous_confident_location"`
Distance float64 `json:"distance"` Distance float64 `json:"distance"`
Name string `json:"name"`
BeaconName string `json:"beacon_name"`
ID string `json:"id"` ID string `json:"id"`
BeaconType string `json:"beacon_type"`
HSBattery int64 `json:"hs_battery"`
HSButtonMode string `json:"hs_button_mode"`
HSButtonCounter int64 `json:"hs_button_counter"`
Location string `json:"location"` Location string `json:"location"`
LastSeen int64 `json:"last_seen"` LastSeen int64 `json:"last_seen"`
} }


Laddar…
Avbryt
Spara