def run(target_folder, origins_path, destinations_path, mode):
    """
        make a table that ranks from least total time to most
    """
    # set up results paths
    results_path = join(target_folder, 'results.csv')
    rankings_path = join(target_folder, 'rankings.csv')
    log_path = join(target_folder, 'log_results.txt')
    geomap_path = join(target_folder, 'geomap.csv')

    origins = load_unique_lines(origins_path)
    destinations = load_unique_lines(destinations_path)

    json = get_json(origins, destinations, mode)

    # TODO: Check status of each output -> result.rows[i].elements[i].status
    origins, destinations = (json['origin_addresses'],
                             json['destination_addresses'])
    origin_to_destination_stats = zip(origins, json['rows'])

    geomap_table = get_geotable(origins, destinations)
    geomap_table.to_csv(geomap_path, index=False)
    duration_results, rankings = get_results(origin_to_destination_stats,
                                             destinations)
    # Output results
    log = [origin + ': ' + str(total_time) for
           origin, total_time in rankings]
    log = "\n".join(log)
    with open(log_path, 'w') as f:
        f.write(log)
    columns = ['Lodging Name', 'Destination', 'Duration']
    results_table = DataFrame(duration_results, columns=columns)
    results_table.to_csv(results_path, index=False)

    columns = ['Lodging Name', 'Total Time']
    rankings_table = DataFrame(rankings, columns=columns)
    rankings_table.to_csv(rankings_path, index=False)

    # Required print statement for crosscompute
    print("points_geotable_path = {0}".format(geomap_path))
    print("rankings_table_path = {0}".format(rankings_path))
    print("results_table_path = {0}".format(results_path))
    print("results_text_path = {0}".format(log_path))
    return (geomap_table, rankings_table)
예제 #2
0
def run(
        target_folder, journals_path=None, authors_path=None,
        keywords_path=None, mesh_terms_path=None,
        from_date=None, to_date=None, date_interval_in_years=0):
    search_count_path = join(target_folder, 'search_counts.csv')
    first_name_path = join(target_folder, 'first_named_articles.csv')
    image_path = join(target_folder, 'keyword_article_count.jpg')

    # Input retrieval
    journals = load_unique_lines(journals_path)
    text_words = load_unique_lines(keywords_path)
    mesh_terms = load_unique_lines(mesh_terms_path)
    authors = load_unique_lines(authors_path)
    # Get list containing intervals of date ranges based on interval specified
    #  by user
    try:
        date_ranges = get_date_ranges(
            from_date, to_date, date_interval_in_years)
    except ToolError as e:
        exit('to_date.error = {0}'.format(e))

    isAuthor, query_list = ((True, authors) if authors
                                  else (False, journals))
    # Tabulate keywords
    results = tabulate(
        query_list, date_ranges, text_words, mesh_terms, isAuthor)
    author_articles = results['author_articles']
    search_count = results['search_counts']
    sc_df = DataFrame(search_count[1:], columns=search_count[0])
    sc_df.to_csv(search_count_path, index=False)
    # crosscompute print statement
    if isAuthor:
        cols = ['Author', 'No. first name articles']
        first_name_articles = [(name, len(get_first_name_articles(
                                          name, author_articles[name])))
                                for name in authors]
        fa_df = DataFrame(first_name_articles, columns=cols)
        
        fa_df.to_csv(first_name_path, index=False)
        print("first_name_articles_table_path = " + first_name_path)
    print("search_count_table_path = " + search_count_path)
def test_load_unique_lines():
    lines = load_unique_lines(join(TEST_FOLDER, 'lines.txt'))
    assert lines == ['one', 'two']
def test_load_unique_lines():
    lines = load_unique_lines(join(TEST_FOLDER, 'lines.txt'))
    assert lines == ['one', 'two']