コード例 #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 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')
コード例 #3
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