Exemplo n.º 1
0
def generate_tags():
    '''
    Generate most relevant tags
    '''

    ## create database clients
    DB = database.DB()

    ## get paths to csv
    cluster_path = '../scrapper/data/clusters'
    save_path = '../scrapper/data/tfidf'
    cluster_files = glob.glob(cluster_path + '/*.csv')

    ## store dataframe for each data types
    clusters = []

    for cluster in cluster_files:
        df_cluster = pd.read_csv(cluster, index_col=0, header=0)
        df_cluster['top_tags'] = ''

        parkunit = df_cluster['parkunit'].values[0]
        park = usnp.Park(parkunit)

        df_cluster['top_tags'] = df_cluster['rank'].apply(
            lambda x: ";".join([x[0] for x in park.get_top_tags(x)]))

        print('... tf-idf computed for ' + cluster.split('/')[-1])

        ## save cluster dataframe
        df_cluster.to_csv(os.path.join(save_path, parkunit + ".csv"))
Exemplo n.º 2
0
def update_cluster():
    results = request.args.get('locationSelect')
    results = results.split("//")
    parkname = results[0]
    cluster_rank = int(results[1])

    ## create park object
    parkunit = usnp.parks.parkname_to_parkunit(parkname)
    park = usnp.Park(parkunit)
    photo_count = park.photo_count

    ## get cluster info
    if photo_count > 0:
        clusters = park.clusters
        cluster_count = clusters.shape[0]
    else:
        clusters, cluster_count = 0, 0

    message = 'Click a scene marker to explore.'
    if cluster_count == 0:
        message = 'There are no locations to explore for this park.'

    ## map
    folium_map = park.show_park()
    folium_map.save('app/templates/map.html')

    ## locations
    form = SelectForm()
    form.locationSelect.choices = [(parkname + '//' + str(i + 1),
                                    'Scene ' + str(i + 1))
                                   for i in range(cluster_count)]

    ## get cluster id
    cluster_id = clusters.loc[clusters['rank'] == cluster_rank,
                              'labels'].to_numpy()[0]

    ## photos
    photos = park.get_top_photos(int(cluster_id), n_photos=25)

    ## tf-idf
    tags = park.clusters[park.clusters['rank'] ==
                         cluster_rank]['top_tags'].values[0]
    if tags:
        tags = tags.split(";")

    return render_template("explore.html",
                           parkname=parkname,
                           state=park.state,
                           parkunit=parkunit,
                           photo_count="{:,}".format(photo_count),
                           cluster_count=cluster_count,
                           description=park.description,
                           park_website=park.official_website,
                           park_trails=park.alltrails_website,
                           message=message,
                           form=form,
                           samples=photos,
                           cluster_rank=cluster_rank,
                           tags=tags)
Exemplo n.º 3
0
def explore_park():

    ## retrieve infos
    parkname = request.args.get('autocomp')

    ## validate input (i.e. check parkname in DB)
    if not usnp.parks.is_park_in_db(parkname):
        form = SearchForm(request.form)
        return render_template('find.html',
                               message="Enter a valid park name.",
                               form=form)

    ## create park object
    parkunit = usnp.parks.parkname_to_parkunit(parkname)
    park = usnp.Park(parkunit)
    photo_count = park.photo_count

    ## get cluster info
    if photo_count > 0:
        clusters = park.clusters
        cluster_count = clusters.shape[0]
    else:
        clusters, cluster_count = 0, 0

    message = 'Click a scene marker to explore.'
    if cluster_count == 0:
        message = 'There are no locations to explore for this park.'

    ## map
    folium_map = park.show_park()
    folium_map.save('app/templates/map.html')

    ## locations
    form = SelectForm()
    form.locationSelect.choices = [(parkname + '//' + str(i + 1),
                                    'Scene ' + str(i + 1))
                                   for i in range(cluster_count)]

    ## selected clusters
    cluster_rank = 1

    ## get cluster id
    cluster_id = clusters.loc[clusters['rank'] == cluster_rank,
                              'labels'].to_numpy()[0]

    ## photos
    photos = park.get_top_photos(int(cluster_id), n_photos=25)

    ## tf-idf
    tags = park.clusters[park.clusters['rank'] ==
                         cluster_rank]['top_tags'].values[0]
    if tags:
        tags = tags.split(";")

    return render_template("explore.html",
                           parkname=parkname,
                           state=park.state,
                           parkunit=parkunit,
                           photo_count="{:,}".format(photo_count),
                           cluster_count=cluster_count,
                           description=park.description,
                           park_website=park.official_website,
                           park_trails=park.alltrails_website,
                           message=message,
                           form=form,
                           samples=photos,
                           cluster_rank=cluster_rank,
                           tags=tags)
Exemplo n.º 4
0
def model_details():
    parkunit = request.args.get('parkunit')
    park = usnp.db.parks.find_one({'parkunit': parkunit})
    park = usnp.Park(parkunit)
    return render_template("modeldetails.html", park=park)
Exemplo n.º 5
0
 def __init__(self, parkunit):
     self.park = usnp.Park(parkunit)