コード例 #1
0
    def test_benchmark(self):
        start_micros = round(time.time() * 1e6)
        for td in self.testdata:
            olc.encode(td[0], td[1], td[2])
        duration_micros = round(time.time() * 1e6) - start_micros
        print('Encoding benchmark: %d passes, %d usec total, %.03f usec each' %
              (len(self.testdata), duration_micros,
               duration_micros / len(self.testdata)))

        start_micros = round(time.time() * 1e6)
        for td in self.testdata:
            olc.decode(td[3])
        duration_micros = round(time.time() * 1e6) - start_micros
        print('Decoding benchmark: %d passes, %d usec total, %.03f usec each' %
              (len(self.testdata), duration_micros,
               duration_micros / len(self.testdata)))
コード例 #2
0
 def test_decoding(self):
     precision = 10
     for td in self.testdata:
         decoded = olc.decode(td['code'])
         self.assertEqual(round(decoded.latitudeLo, precision),
                          round(td['latLo'], precision), td)
         self.assertEqual(round(decoded.longitudeLo, precision),
                          round(td['lngLo'], precision), td)
         self.assertEqual(round(decoded.latitudeHi, precision),
                          round(td['latHi'], precision), td)
         self.assertEqual(round(decoded.longitudeHi, precision),
                          round(td['longHi'], precision), td)
コード例 #3
0
 def test_decoding(self):
   precision = 10
   for td in self.testdata:
     decoded = olc.decode(td['code'])
     self.assertEqual(
         round(decoded.latitudeLo, precision),
         round(td['latLo'], precision), td)
     self.assertEqual(
         round(decoded.longitudeLo, precision),
         round(td['lngLo'], precision), td)
     self.assertEqual(
         round(decoded.latitudeHi, precision),
         round(td['latHi'], precision), td)
     self.assertEqual(
         round(decoded.longitudeHi, precision),
         round(td['longHi'], precision), td)
コード例 #4
0
def lambda_handler(event, context):
    table = dynamodb.Table('OpenCity')
    with table.batch_writer() as batch:
        items = dict()
        for record in event['Records']:
            payload = base64.b64decode(record['kinesis']['data'])
            #print(payload)
            obj = json.loads(payload.decode("utf-8"))
            obj['ubid'] = str(obj['hash'])
            for field in ['nds', 'members', 'tags']:
                if field in obj:
                    obj[field] = json.loads(obj[field])
                    if len(obj[field]) == 0:
                        del obj[field]
            for length in [8, 10, 11, 12]:
                grid = encode(obj['lat'], obj['lon'], length)
                obj['grid'] = "OSM:" + grid
                ca = decode(grid)
                lat, lon = ca.latitudeCenter, ca.longitudeCenter
                obj['distance'] = distance(lat, lon, obj['lat'], obj['lon'])
                o = json.loads(json.dumps(obj))
                for field in ['distance', 'lon', 'lat']:
                    o[field] = Decimal(str(o[field]))
                items[o['grid'] + o['hash']] = o
        for item in items.values():
            for k in list(item.keys()):
                if item[k] == '':
                    del item[k]
            try:
                batch.put_item(Item=item)
            except Exception as e:
                print("Unable to process item '%s'" % item)
                raise e
    print("Processed %d, %d distinct items" %
          (len(event['Records']), len(items)))
    # print("Decoded payload: " + obj)

    return {'statusCode': 200, 'body': json.dumps('Hello from Lambda!')}
コード例 #5
0
 def test_maxdigits_decoding(self):
   maxCharCode = "849VGJQF+VX7QR4M"
   maxChar = olc.decode(maxCharCode)
   maxCharExceeded = olc.decode(maxCharCode + "7QR4M")
   self.assertEqual(maxChar.latitudeCenter, maxCharExceeded.latitudeCenter)
   self.assertEqual(maxChar.longitudeCenter, maxCharExceeded.longitudeCenter)
コード例 #6
0
        # focus on the Alfred window) 2) it was slow (>5s) to startup.
        browser = Chrome(os.environ['CHROMEDRIVER'], options=opp)
        browser.get(pluscode_url)

        # wait until the URL get's rewritten to contain the logn form plus code (but max. 5s)
        wait = WebDriverWait(browser, 5)
        wait.until(lambda driver: driver.current_url != pluscode_url)

        url = browser.current_url
        browser.quit()

        o = urllib.parse.urlparse(url)
        pluscode = o.path[1:]

    # convert plus code to GPS
    codearea = decode(pluscode)
    latlng = "%s, %s" % (round(codearea.latitudeCenter,
                               6), round(codearea.longitudeCenter, 6))

    item = {
        'title': latlng,
        'subtitle': 'Latitude, Longitude',
        'arg': latlng,
        'text': {
            'copy': latlng
        },
        'mods': {
            "alt": {
                "arg": "http://maps.google.com/maps?q=%s" % (latlng),
                "subtitle": "Open in Google Maps"
            }