Beispiel #1
0
def on_event_request():
    ''' Receives GET requests from the user to setup subscriptions. '''

    # Does the user want a linked outpage to make it easier to link to?
    htmlPage = bool(request.query.html)
    event = None

    tag = request.query.tag
    lat, lon, radius = subscriptionWorker.checkGeos(request.query.lat,
                                                    request.query.lon,
                                                    request.query.radius)

    if tag and len(tag) > 0:
        event = {'object': 'tag', 'tag': tag.lower()}

    elif lat and lon and radius:

        # Convert the incoming metres radius to degrees
        latRad, lonRad = crowdedWorker.radialToLinearUnits(float(lat))
        scale = (latRad + lonRad) / 2.0
        radius = float(radius) / scale

        event = {
            'object': 'geography',
            'lat': float(lat),
            'lon': float(lon),
            'radius': float(radius)
        }

    else:
        print 'Must specify a lat/lon/radius or tag.'
        redirect("/help")
        return

    if not event:
        response = {'success': False}
    # Get the response form updating the backend records
    else:
        response = subscriptionWorker.buildSubscription(event)

        # Now get something populated in that so that its not blank
        subInfo = [{
            "object": response['object'],
            "object_id": response['objectId']
        }]
        crowdedWorker.main(p, json.dumps(subInfo))

    # A user linked page for getting to the event splash page
    if response.has_key('url') and response['success'] == True:
        if htmlPage == True:
            output = template("goToEventPage",
                              objectId=response['objectId'],
                              eventPage=response['url'],
                              helpPage=p.helpUrl)
        else:
            output = json.dumps(response)
    else:
        redirect("/help")

    return output
Beispiel #2
0
def queryByGeo(url, lat, lon, radius):
    ''' Queries the remote service by geographical parameters. '''

    # Scale the radius back to metres     
    latScale, lonScale = crowdedWorker.radialToLinearUnits(float(lat))
    scale = (latScale + lonScale)/2.0
    print scale
    radius *= scale
    print radius
    
    url = url.replace('<event_latitude>', str(lat)) 
    url = url.replace('<event_longitude>', str(lon))
    url = url.replace('<event_radius_in_metres>', str(radius))
    
    print 'URL: %s' %url
    
    errors, data = hitUrl(url) 
    if len(errors) > 0:
        for error in errors:
            print error
    else:
        media = json.loads(data)
    
    print 'Media: %s' %(media)
    
    return media
Beispiel #3
0
def on_event_request():
    ''' Receives GET requests from the user to setup subscriptions. '''

    # Does the user want a linked outpage to make it easier to link to?
    htmlPage = bool(request.query.html)
    event = None
    
    tag    = request.query.tag
    lat, lon, radius = subscriptionWorker.checkGeos(request.query.lat, request.query.lon, request.query.radius)
    
    if tag and len(tag) > 0:
        event = {'object' : 'tag',
                 'tag'    :  tag.lower()}
    
    elif lat and lon and radius:
        
        # Convert the incoming metres radius to degrees
        latRad, lonRad = crowdedWorker.radialToLinearUnits(float(lat))
        scale = (latRad+lonRad)/2.0
        radius = float(radius)/scale
        
        event = {'object' : 'geography',
                 'lat'    : float(lat),
                 'lon'    : float(lon),
                 'radius' : float(radius)}    
    
    else:
        print 'Must specify a lat/lon/radius or tag.'
        redirect("/help")
        return
    
    if not event:
        response = {'success': False}
    # Get the response form updating the backend records
    else:
        response = subscriptionWorker.buildSubscription(event)
        
        # Now get something populated in that so that its not blank
        subInfo = [{"object" : response['object'], "object_id" : response['objectId']}]
        crowdedWorker.main(p, json.dumps(subInfo))
    
    # A user linked page for getting to the event splash page
    if response.has_key('url') and response['success']==True:
        if htmlPage == True:
            output = template("goToEventPage",
                              objectId=response['objectId'],
                              eventPage=response['url'],
                              helpPage=p.helpUrl)
        else:
            output = json.dumps(response)
    else:
        redirect("/help")
        
    return output
Beispiel #4
0
def eventSplash(objectId=None):
    ''' Renders the media that relates to this event out to the browser. '''

    if not objectId:
        redirect("/help")
        return

    # Get the objectId
    doc = crowdedWorker.getMediaByObjectId(p, objectId)
    if not doc or len(doc.keys()) < 1 or 'subType' not in doc.keys():
        redirect("/noevent/%s" % (objectId))
        return

    # Reorder the media by timestamp
    media = crowdedWorker.reorderMedia(doc['media'], 200)

    # Other web page elements
    header = 'Event Media...'

    # Get subheader
    if doc['subType'] == 'geography':
        loc = doc['loc']
        # Get the correct radius units
        # Convert the incoming metres radius to degrees
        latRad, lonRad = crowdedWorker.radialToLinearUnits(float(loc[1]))
        scale = (latRad + lonRad) / 2.0
        radius = float(doc['radius']) * scale

        subHeader = 'Event Location: lat: %s, lon: %s, radius: %sm' % (
            loc[1], loc[0], radius)
    elif doc['subType'] == 'tag':
        subHeader = 'Event Tag: %s' % (objectId)

    # Filter the list down
    usefulTags = crowdedWorker.popUselessTags(p, doc['tags'])
    tags = crowdedWorker.filterTagsByCount(usefulTags,
                                           objectId,
                                           numberTopTags=15)
    associatedTags = 'Most commonly associated tags (count): '
    associatedTags += ', '.join(tags)

    # When the subscription was registered
    initiated = doc['start'].strftime('%H:%M:%SZ on %a %d %b %Y')

    # Push the arguments through the template and return the output
    output = template("renderMedia",
                      photos=media,
                      header=header,
                      subHeader=subHeader,
                      associatedTags=associatedTags,
                      initiated=initiated)

    return output
Beispiel #5
0
def eventSplash(objectId=None):
    ''' Renders the media that relates to this event out to the browser. '''

    if not objectId:
        redirect("/help")
        return

    # Get the objectId
    doc = crowdedWorker.getMediaByObjectId(p, objectId)
    if not doc or len(doc.keys())<1 or 'subType' not in doc.keys():
        redirect("/noevent/%s" %(objectId)) 
        return
    
    # Reorder the media by timestamp
    media = crowdedWorker.reorderMedia(doc['media'], 200)

    # Other web page elements
    header = 'Event Media...'
    
    # Get subheader
    if doc['subType']=='geography':
        loc = doc['loc']
        # Get the correct radius units
        # Convert the incoming metres radius to degrees
        latRad, lonRad = crowdedWorker.radialToLinearUnits(float(loc[1]))
        scale = (latRad+lonRad)/2.0
        radius = float(doc['radius'])*scale
        
        subHeader = 'Event Location: lat: %s, lon: %s, radius: %sm' %(loc[1], loc[0], radius)
    elif doc['subType']=='tag':
        subHeader = 'Event Tag: %s' %(objectId)

    # Filter the list down
    usefulTags = crowdedWorker.popUselessTags(p, doc['tags'])
    tags = crowdedWorker.filterTagsByCount(usefulTags, objectId, numberTopTags=15)
    associatedTags = 'Most commonly associated tags (count): '
    associatedTags += ', '.join(tags)
    
    # When the subscription was registered
    initiated = doc['start'].strftime('%H:%M:%SZ on %a %d %b %Y')

    # Push the arguments through the template and return the output
    output = template("renderMedia",
                      photos         = media,
                      header         = header,
                      subHeader      = subHeader,
                      associatedTags = associatedTags,
                      initiated      = initiated)
    
    return output