コード例 #1
0
ファイル: balsa_update.py プロジェクト: navimont/balsa.cl
    def get(self, login_user=None, template_values={}):

        # hold update query in memcache
        q_new = memcache.get('new')
        if not q_new:
            q_new = Stop.all().filter('confirm =', 'NEW')
            memcache.set('new', q_new)

        offset = int(self.request.get("offset", "0"))
        new = q_new.fetch(limit=1, offset=offset)
        template_values['offset'] = offset+1
        if not new:
            # nothing to do
            self.redirect('/update')
            return
        new = new[0]

        # find datasets nearby
        query = Stop.all().filter('confirm =', 'NO')
        proximity = geo.geomodel.GeoModel.proximity_fetch(query, new.location, max_results=6, max_distance=500)

        compare=[]
        stop = {}
        stop['description'] = 'New:'
        stop['type'] = new.stop_type
        stop['name'] = ", ".join(new.names)
        stop['lat'] = new.location.lat
        stop['lon'] = new.location.lon
        stop['new'] = True
        stop['key'] = str(new.key())
        compare.append(stop)
        for pstop in proximity:
            stop = {}
            # calculate distance to new point
            dist = geo.geomath.distance(new.location,pstop.location)
            # calculate 'distance' between names (ratio of similarity)
            ndiff = difflib.SequenceMatcher(None,"".join(new.names),"".join(pstop.names))
            logging.debug("%s vs. %s ratio %f" % ("".join(new.names),"".join(pstop.names),ndiff.ratio()))
            if dist < 100.0 or ndiff.ratio() > 0.7:
                stop['checked'] = "checked"
                stop['style'] = "balsa-watch"
            stop['description'] = 'at %4.0f meters' % (dist)
            stop['type'] = pstop.stop_type
            stop['name'] = ", ".join(pstop.names)
            stop['lat'] = pstop.location.lat
            stop['lon'] = pstop.location.lon
            stop['new'] = False
            stop['key'] = str(pstop.key())
            compare.append(stop)
        template_values['compare'] = compare

        counter = StopMeta.all().get()
        template_values['new_num_stops'] = counter.counter_stop_new_confirm
        template_values['new_num_stations'] = counter.counter_station_new_confirm
        template_values['new_num_places'] = counter.counter_place_new_confirm

        path = os.path.join(os.path.dirname(__file__), "pages/confirm_new.html")
        self.response.out.write(template.render(path, template_values))
        return
コード例 #2
0
ファイル: balsa_update.py プロジェクト: navimont/balsa.cl
 def store():
     stop = Stop.get(key)
     stop.confirm = 'NO'
     # remove updated data set
     old_stop = Stop.all().ancestor(counter).filter("osm_id =", stop.osm_id).filter('confirm =', 'NO').get()
     assert old_stop, "Did not find original data for update"
     counter.counter_delta(-1, stop.stop_type, "UPDATE")
     counter.put()
     stop.put()
     old_stop.delete()
コード例 #3
0
ファイル: balsa_update.py プロジェクト: navimont/balsa.cl
 def store():
     for key in obsolete:
         stop = Stop.all().ancestor(counter).filter("__key__ =", Key(key)).get()
         counter.counter_delta(-1, stop.stop_type)
     counter.counter_delta(1, stop.stop_type)
     counter.counter_delta(-1, stop.stop_type, "NEW")
     db.put(new_stop)
     db.delete(obsolete)
     counter.put()
コード例 #4
0
ファイル: balsa_update.py プロジェクト: navimont/balsa.cl
    def get(self, login_user=None, template_values={}):

        obsolete = [key for key in self.request.get_all("obsolete_key", None)]
        logging.debug(obsolete)

        key = self.request.get("accept", None)
        assert key, "Did not receive key"

        new_stop = Stop.get(key)
        new_stop.confirm = "NO"

        counter = StopMeta.all().get()
        def store():
            for key in obsolete:
                stop = Stop.all().ancestor(counter).filter("__key__ =", Key(key)).get()
                counter.counter_delta(-1, stop.stop_type)
            counter.counter_delta(1, stop.stop_type)
            counter.counter_delta(-1, stop.stop_type, "NEW")
            db.put(new_stop)
            db.delete(obsolete)
            counter.put()
        db.run_in_transaction(store)

        self.redirect('/update/confirm/new')
コード例 #5
0
ファイル: balsa_stops.py プロジェクト: navimont/balsa.cl
    def update_node_cb(node, kind):
        """Callback function. Process nodes from osm data

        Different to import_node_cb (above) look for existing nodes with the
        same data and discard identical ones. Queue changed nodes and new nodes
        for confirmation.
        """
        # look for existing node with the same osm_id
        old_stop = Stop.get_by_key_id(node.osm_id)
        if old_stop:
            # create stop entity from node data
            stop = BalsaStopStoreTask.create_update_stop(node, kind)
            logging.debug("compare %s <==> %s" % (old_stop,stop))
            if old_stop == stop:
                # no change
                return
            else:
                # accumulate some greater number for efficient batch write to datastore
                BalsaStopWriter.add(stop, node.timestamp)
        else:
            # create stop entity from node data
            stop = BalsaStopStoreTask.create_new_stop(node, kind)
            BalsaStopWriter.add(stop, node.timestamp)
        return
コード例 #6
0
ファイル: balsa_update.py プロジェクト: navimont/balsa.cl
    def get(self, login_user=None, template_values={}):
        pass

        # hold update query in memcache
        q_update = memcache.get('update')
        if not q_update:
            q_update = Stop.all().filter('confirm =', 'UPDATE')
            memcache.set('update', q_update)

        offset = int(self.request.get("offset", "0"))
        update = q_update.fetch(limit=1, offset=offset)
        template_values['offset'] = offset+1
        if not update:
            # nothing to do
            self.redirect('/update')
            return
        update = update[0]

        # get corresponding production data
        production = Stop.all().filter('osm_id =', update.osm_id).filter('confirm =', 'NO').get()
        assert production, "Failed to fetch prodcution data for update osm_id=%d" % (update.osm_id)

        compare={}
        compare['key'] = str(update.key())
        compare['data'] = []
        data = {}
        data['type'] = 'Stop type'
        data['production'] = production.stop_type
        data['update'] = update.stop_type
        if production.stop_type != update.stop_type:
            data['style'] = "balsa-watch"
        compare['data'].append(data)
        data = {}
        data['type'] = 'Location (lat)'
        data['production'] = production.location.lat
        data['update'] = update.location.lat
        if production.location.lat != update.location.lat:
            data['style'] = "balsa-watch"
        compare['data'].append(data)
        data = {}
        data['type'] = 'Location (lon)'
        data['production'] = production.location.lon
        data['update'] = update.location.lon
        if production.location.lon != update.location.lon:
            data['style'] = "balsa-watch"
        compare['data'].append(data)
        data = {}
        data['type'] = 'Name(s)'
        data['production'] = ", ".join(production.names)
        data['update'] = ", ".join(update.names)
        if production.names != update.names:
            data['style'] = "balsa-watch"
        compare['data'].append(data)
        data = {}
        data['type'] = 'Location zoom'
        data['production'] = ", ".join(production.gov.gov_names)
        data['update'] = ", ".join(update.gov.gov_names)
        if production.gov.gov_names != update.gov.gov_names:
            data['style'] = "balsa-watch"
        compare['data'].append(data)
        template_values['compare'] = compare

        counter = StopMeta.all().get()
        template_values['update_num_stops'] = counter.counter_stop_update_confirm
        template_values['update_num_stations'] = counter.counter_station_update_confirm
        template_values['update_num_places'] = counter.counter_place_update_confirm

        path = os.path.join(os.path.dirname(__file__), "pages/confirm_update.html")
        self.response.out.write(template.render(path, template_values))
        return
コード例 #7
0
ファイル: balsa_update.py プロジェクト: navimont/balsa.cl
 def store():
     stop = Stop.get(key)
     counter.counter_delta(-1, stop.stop_type, "UPDATE")
     counter.put()
     stop.delete()