Skip to content

Commit

Permalink
Set low rank for rssi of 127
Browse files Browse the repository at this point in the history
  • Loading branch information
mmocny committed May 19, 2015
1 parent 90948eb commit eca4552
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
3 changes: 1 addition & 2 deletions web-service/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,7 @@ def ComputeDistance(rssi, txpower):
try:
rssi = float(rssi)
txpower = float(txpower)
if rssi == 128:
# According to wiki, 127 is MAX and 128 is INVALID.
if rssi in [127, 128]: # Known invalid rssi values
return None
path_loss = txpower - rssi
distance = pow(10.0, (path_loss - 41) / 20)
Expand Down
22 changes: 22 additions & 0 deletions web-service/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,28 @@ def test_regression_urls(self):
#self.assertIn('id', result['metadata'][0])
#self.assertIn('icon', result['metadata'][0])

def test_invalid_rssi(self):
result = self.call({
'objects': [{
'url': 'http://github.com/google/physical-web/',
'rssi': 127,
'txpower': -41
}]
})
self.assertIn('metadata', result)
self.assertEqual(len(result['metadata']), 1)

beaconResult = result['metadata'][0]

self.assertIn('description', beaconResult)
self.assertIn('title', beaconResult)
self.assertIn('url', beaconResult)
self.assertIn('rank', beaconResult)
self.assertIn('id', beaconResult)
self.assertIn('icon', beaconResult)

self.assertEqual(1000, beaconResult['rank'])


class TestShortenUrl(PwsTest):
PATH = 'shorten-url'
Expand Down

0 comments on commit eca4552

Please sign in to comment.