def format_element(bfo):
    """
    Return list of profile data.
    """
    data_dict = {}
    year_fields = map(bfo.fields, ["260__c", "269__c", "773__y", "502__d"])
    recid = bfo.recID

    data_dict["year_fields"] = year_fields

    return serialize([recid, data_dict])
def format_element(bfo):
    """
    Return list of profile data.
    """
    data_dict = {}
    year_fields = map(bfo.fields, ['260__c', '269__c', '773__y', '502__d'])
    recid = bfo.recID

    data_dict['year_fields'] = year_fields

    return serialize([recid, data_dict])
示例#3
0
def process_authors(pids):
    # get the author - paper associations for authors
    # with id: min_pid <= id < max_pid (excluding rejected papers)
    associations = set(
        run_sql("""select personid, bibref_table, bibref_value, bibrec
                                  from aidPERSONIDPAPERS
                                  where flag > -2
                                  and personid in ( %s ) """ %
                ' , '.join("'" + str(p) + "'" for p in pids)))

    # get mapping of: (bibref_table, bibref_value) -> name
    bibref_to_name = dict()
    bibrefs = set([(table, ref) for _, table, ref, _ in associations])
    counter = 0
    for bibref in bibrefs:
        counter += 1
        bibref_to_name[bibref] = get_name_by_bibref(bibref)
        write_message('Got name: %s for bibref: %s.' %
                      (bibref_to_name[bibref], str(bibref)))

    # get mapping of: author -> affiliations
    pid_to_affiliations = dict()
    counterr = 0
    for pid in pids:
        counterr += 1
        pid_to_affiliations[pid] = get_affiliations_for_author(pid)
        write_message('Got affiliations: %s for author: %s.' %
                      (pid_to_affiliations[pid], str(pid)))

    # get the affiliated records for this group of authors: (rec, name, affiliation, ... + some extra info)
    affiliated_records = list()
    for pid, table, ref, rec in associations:
        # we don't want to keep records which have no affiliation/s
        affiliations, year = pid_to_affiliations[pid]
        if not affiliations:
            continue
        affiliated_records += [
            rec, bibref_to_name[(table, ref)],
            serialize(affiliations), table, ref, year
        ]

    # flush data to db
    if affiliated_records:
        write_message('Populating table with %s records.' %
                      len(affiliated_records))
        populate_table('bibEDITAFFILIATIONS_tmp', [
            'bibrec', 'name', 'affiliations', 'bibref_table', 'bibref_value',
            'year'
        ],
                       affiliated_records,
                       empty_table_first=False)

    return len(affiliated_records)
示例#4
0
def format_element(bfo):
    """
    Return list of profile affiliations.
    """
    fields = bfo.fields("100__")
    fields2 = bfo.fields("700__")
    dic = {}
    recid = bfo.recID

    for f in fields + fields2:
        if f.has_key('a') and f.has_key('u') and f['u']:
            u = f['u']
            try:
                dic[f['a']].append(u)
            except KeyError:
                dic[f['a']] = [u]

    return serialize([recid, dic])
def update_cache(cached, name, key, target, *args):
    '''
    Actual update of cached value of (name, key). Updates to the result of target(args).
    If value present in cache, not up to date but last_updated less than a threshold it does nothing,
    as someone surely precached it and is computing the results already. If not present in cache it
    precaches it, computes its value and stores it in cache returning its value.
    '''
    #print '--Updating cache: ', name,' ',key
    if cached['present']:
        delay = datetime.now() - cached['last_updated']
        if delay < RECOMPUTE_PRECACHED_ELEMENT_DELAY and cached['precached']:
            #print '--!!!Udating cache skip precached!'
            return [False, None]
    precache_element(name, key)
    el = target(*args)
    cache_element(name, key, serialize(el))
    #print '--Updating cache: ', name,' ',key, ' returning! ', str(el)[0:10]
    return [True, el]
def format_element(bfo):
    """
    Return list of profile affiliations.
    """
    fields = bfo.fields("100__")
    fields2 = bfo.fields("700__")
    dic = {}
    recid = bfo.recID

    for f in fields + fields2:
        if f.has_key('a') and f.has_key('u') and f['u']:
            u = f['u']
            try:
                dic[f['a']].append(u)
            except KeyError:
                dic[f['a']] = [u]

    return serialize([recid, dic])
def update_cache(cached, name, key, target, *args):
    '''
    Actual update of cached value of (name, key). Updates to the result of target(args).
    If value present in cache, not up to date but last_updated less than a threshold it does nothing,
    as someone surely precached it and is computing the results already. If not present in cache it
    precaches it, computes its value and stores it in cache returning its value.
    '''
    #print '--Updating cache: ', name,' ',key
    if cached['present']:
        delay = datetime.now() - cached['last_updated']
        if delay < RECOMPUTE_PRECACHED_ELEMENT_DELAY and cached['precached']:
            #print '--!!!Udating cache skip precached!'
            return [False, None]
    precache_element(name, key)
    el = target(*args)
    cache_element(name, key, serialize(el))
    #print '--Updating cache: ', name,' ',key, ' returning! ', str(el)[0:10]
    return [True, el]
示例#8
0
def format_element(bfo):
    """
    Return list of profile affiliations.
    """
    fields = bfo.fields("100__", repeatable_subfields_p=True)
    fields2 = bfo.fields("700__", repeatable_subfields_p=True)
    dic = {}
    recid = bfo.recID

    for f in fields + fields2:
        if f.has_key('a') and f.has_key('u') and f['u']:
            us = f['u']
            for u in us:
                try:
                    dic[f['a'][0]].append(u)
                except KeyError:
                    dic[f['a'][0]] = [u]

    return serialize([recid, dic])
示例#9
0
def process_authors(pids):
    # get the author - paper associations for authors
    # with id: min_pid <= id < max_pid (excluding rejected papers)
    associations = set(run_sql("""select personid, bibref_table, bibref_value, bibrec
                                  from aidPERSONIDPAPERS
                                  where flag > -2
                                  and personid in ( %s ) """ % ' , '.join("'"+str(p)+"'" for p in pids)))


    # get mapping of: (bibref_table, bibref_value) -> name
    bibref_to_name = dict()
    bibrefs = set([(table, ref) for _, table, ref, _ in associations])
    counter = 0
    for bibref in bibrefs:
        counter += 1
        bibref_to_name[bibref] = get_name_by_bibref(bibref)
        write_message('Got name: %s for bibref: %s.' % (bibref_to_name[bibref], str(bibref)))

    # get mapping of: author -> affiliations
    pid_to_affiliations = dict()
    counterr = 0
    for pid in pids:
        counterr += 1
        pid_to_affiliations[pid] = get_affiliations_for_author(pid)
        write_message('Got affiliations: %s for author: %s.' % (pid_to_affiliations[pid], str(pid)))

    # get the affiliated records for this group of authors: (rec, name, affiliation, ... + some extra info)
    affiliated_records = list()
    for pid, table, ref, rec in associations:
        # we don't want to keep records which have no affiliation/s
        affiliations, year = pid_to_affiliations[pid]
        if not affiliations:
            continue
        affiliated_records += [rec, bibref_to_name[(table, ref)], serialize(affiliations), table, ref, year]

    # flush data to db
    if affiliated_records:
        write_message('Populating table with %s records.' % len(affiliated_records))
        populate_table('bibEDITAFFILIATIONS_tmp', ['bibrec','name','affiliations','bibref_table','bibref_value', 'year'], affiliated_records, empty_table_first=False)

    return len(affiliated_records)