Comparing and updating Arrays in mySQL records

43 views Asked by At

Scenario: I have multiple static receivers detecting mobile beacons and recording relative signal strength of each. Each beacon pings 1/second, and I am using a rolling average to smooth out the variances in that reading over time. I record that average reading every x seconds (15) locally, then post that array to an sql database every y seconds (300s, so an array of 20).

My constraints are:

  • receivers can’t talk to each other locally
  • I don’t want to post to the server for every signal each receiver receives (way too many records very quickly)
  • I am writing in python and mySql because that’s what I know (noSQL may be a future implementation)
  • I don’t control the server, so scheduling server-side processing is challenging (I think)
  • arrays are of an indeterminate length (hence array instead of fields)

My goal is to reject the receiver that has the lower signal (i.e. is comparatively further away from the beacon) for each element of the posted array.

My current approach is:

  • post a set to the database

  • query that database for any sets from the same beacon (but different receivers) that intersect the time window of the posted set

    • expect up to 2 sets for each nearby receiver, so under 10 records would match the query
  • pull those sets into a 2D array (correcting for offsets when the time windows aren’t exactly the same)

  • zip(*lis) to transform that array
  • find the minimum element in each row, write that as 1 and the rest as 0
  • zip(*lis) that back into the original form of the 2D array
  • post the results back to a “winner” field in the database via update (this way we retain the original signal readings)

I recognize this exposes me to a problem where multiple receivers are posting at the same time and overwriting each others filtered array results.

I suspect there may be other problems with this approach, but I can’t figure out a better way. Is there a better way to do this?

0

There are 0 answers