Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 

72 rindas
2.0 KiB

  1. package main
  2. import (
  3. "context"
  4. "encoding/json"
  5. "fmt"
  6. "github.com/AFASystems/presence/internal/pkg/model"
  7. "github.com/redis/go-redis/v9"
  8. )
  9. func main() {
  10. ctx := context.Background()
  11. client := redis.NewClient(&redis.Options{
  12. Addr: "127.0.0.1:6379",
  13. Password: "",
  14. })
  15. }
  16. func getLikelyLocations(client *redis.Client, ctx context.Context) {
  17. beaconsList, err := client.Get(ctx, "beaconsList").Result()
  18. var beacons = make(map[string]model.Beacon)
  19. if err == redis.Nil {
  20. fmt.Println("no beacons list, starting empty")
  21. } else if err != nil {
  22. panic(err)
  23. } else {
  24. json.Unmarshal([]byte(beaconsList), &beacons)
  25. }
  26. for id, beacon := range beacons {
  27. if len(beacon.Beacon_metrics) == 0 {
  28. continue
  29. }
  30. if isExpired(&beacon, settings) {
  31. handleExpiredBeacon(&beacon, cl, ctx)
  32. continue
  33. }
  34. best := calculateBestLocation(&beacon)
  35. updateBeaconState(&beacon, best, settings, ctx, cl)
  36. appendHTTPResult(ctx, beacon, best)
  37. ctx.Beacons.Beacons[id] = beacon
  38. }
  39. }
  40. // get likely locations:
  41. /*
  42. 1. Locks the http_results list
  43. 2. inits list to empty struct type -> TODO: what is this list used for
  44. 3. loops through beacons list -> should be locked?
  45. 4. check for beacon metrics -> how do you get beacon metrics, I guess it has an array of timestamps
  46. 5. check for threshold value in the settings
  47. 5.1. check for property expired location
  48. 5.2. if location is not expired -> mark it as expired, generate message and send to all clients,
  49. if clients do not respond close the connection
  50. 6. Init best location with type Best_location{} -> what is this type
  51. 7. make locations list -> key: string, val: float64
  52. 7.1 set weight for seen and rssi
  53. 7.2 loop over metrics of the beacon -> some alogirthm based on location value
  54. I think the algorithm is recording names of different gateways and their rssi's and then from
  55. that it checks gateway name and makes decisions based on calculated values
  56. 7.3 writes result in best location and updates list location history with this name if the list
  57. is longer than 10 elements it removes the first element
  58. */