Selaa lähdekoodia

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

chore/restructure-decoder
Blaz Smehov 1 viikko sitten
vanhempi
commit
c7e02b373a
2 muutettua tiedostoa jossa 11 lisäystä ja 19 poistoa
  1. +11
    -13
      cmd/location/main.go
  2. +0
    -6
      internal/pkg/model/types.go

+ 11
- 13
cmd/location/main.go Näytä tiedosto

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

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

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

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

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.LatestList[id] = model.Beacon{ID: id, BeaconType: adv.BeaconType, LastSeen: now, IncomingJSON: adv, BeaconLocation: adv.Hostname, Distance: getBeaconDistance(adv)}
ctx.LatestList.Lock.Unlock()
return
}

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

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

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()

beacon.IncomingJSON = adv
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 {
beacon.BeaconMetrics = make([]model.BeaconMetric, 0, ctx.Settings.Settings.BeaconMetricSize)


+ 0
- 6
internal/pkg/model/types.go Näytä tiedosto

@@ -78,13 +78,7 @@ type HTTPLocation struct {
Method string `json:"method"`
PreviousConfidentLocation string `json:"previous_confident_location"`
Distance float64 `json:"distance"`
Name string `json:"name"`
BeaconName string `json:"beacon_name"`
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"`
LastSeen int64 `json:"last_seen"`
}


Ladataan…
Peruuta
Tallenna