def upload_unmatched(unmatched, spreadsheet_name, output_number, affiliations):
    output = [{'affiliation': r[0], 'number': affiliations[r[0]]} for r in unmatched]
    output = sorted(output, key=lambda r: int(r['number']), reverse=True)[:output_number]
    print 'Found %d unmatched affiliations.' % len(output)
    print 'Exporting %d results to Google Docs.' % len(output)

    spreadsheet_interface.upload_data(output, spreadsheet_name, 'Unmatched')
def upload_unmatched(unmatched, spreadsheet_name, output_number, affiliations):
    output = [{
        'affiliation': r[0],
        'number': affiliations[r[0]]
    } for r in unmatched]
    output = sorted(output, key=lambda r: int(r['number']),
                    reverse=True)[:output_number]
    print 'Found %d unmatched affiliations.' % len(output)
    print 'Exporting %d results to Google Docs.' % len(output)

    spreadsheet_interface.upload_data(output, spreadsheet_name, 'Unmatched')
def upload_matched(matched, spreadsheet_name, output_number, affiliations):
    output = []
    matched = [(affiliations[aff], aff, res) for aff, res in matched]
    print 'Found %d matched affiliations.' % len(matched)
    for number, aff, res in sorted(matched, key=lambda r: int(r[0]), reverse=True)[:output_number]:
        d = {'affiliation': aff, 'number': number}
        d['first'] = res[0]['display_name']
        if len(res) > 1:
            d['second'] = res[1]['display_name']
            d['confidence'] = '%.2f' % (1 - res[1]['score'] / res[0]['score'])
        output.append(d)
    print 'Exporting %d results to Google Docs.' % len(output)

    spreadsheet_interface.upload_data(output, spreadsheet_name, 'Matched')
def upload_matched(matched, spreadsheet_name, output_number, affiliations):
    output = []
    matched = [(affiliations[aff], aff, res) for aff, res in matched]
    print 'Found %d matched affiliations.' % len(matched)
    for number, aff, res in sorted(matched,
                                   key=lambda r: int(r[0]),
                                   reverse=True)[:output_number]:
        d = {'affiliation': aff, 'number': number}
        d['first'] = res[0]['display_name']
        if len(res) > 1:
            d['second'] = res[1]['display_name']
            d['confidence'] = '%.2f' % (1 - res[1]['score'] / res[0]['score'])
        output.append(d)
    print 'Exporting %d results to Google Docs.' % len(output)

    spreadsheet_interface.upload_data(output, spreadsheet_name, 'Matched')