예제 #1
0
def get_literature_earliest_date(data):
    """Returns earliest date. If earliest date is missing month or day
    it's set as 1 as DB does not accept date without day or month

    Returns:
        str: earliest date represented in a string
    """
    date_paths = [
        "preprint_date",
        "thesis_info.date",
        "thesis_info.defense_date",
        "publication_info.year",
        "legacy_creation_date",
        "imprints.date",
    ]

    dates = [
        str(el) for el in chain.from_iterable(
            force_list(get_value(data, path)) for path in date_paths)
    ]

    if dates:
        result = earliest_date(dates, full_date=True)
        if result:
            return result

    return None
예제 #2
0
파일: utils.py 프로젝트: tsgit/inspirehep
def get_literature_earliest_date(data):
    """Returns earliest date.

    Returns:
        str: earliest date represented in a string
    """
    date_paths = [
        "preprint_date",
        "thesis_info.date",
        "thesis_info.defense_date",
        "publication_info.year",
        "legacy_creation_date",
        "imprints.date",
    ]

    dates = [
        str(el) for el in chain.from_iterable(
            force_list(get_value(data, path)) for path in date_paths)
    ]

    if dates:
        result = earliest_date(dates)
        if result:
            return result

    return None
예제 #3
0
def legacy_creation_date(self, key, value):
    if 'legacy_creation_date' in self and self['legacy_creation_date']:
        return self['legacy_creation_date']

    x_values = force_list(value.get('x'))
    if x_values:
        return earliest_date(x_values)
예제 #4
0
def populate_earliest_date(record):
    """Populate the ``earliest_date`` field of Literature records."""
    date_paths = [
        'preprint_date',
        'thesis_info.date',
        'thesis_info.defense_date',
        'publication_info.year',
        'legacy_creation_date',
        'imprints.date',
    ]

    dates = [
        str(el) for el in chain.from_iterable(
            [force_list(get_value(record, path)) for path in date_paths])
    ]

    if dates:
        result = earliest_date(dates)
        if result:
            record['earliest_date'] = result
예제 #5
0
def populate_earliest_date(sender, json, *args, **kwargs):
    """Populate the ``earliest_date`` field of Literature records."""
    if not is_hep(json):
        return

    date_paths = [
        'preprint_date',
        'thesis_info.date',
        'thesis_info.defense_date',
        'publication_info.year',
        'legacy_creation_date',
        'imprints.date',
    ]

    dates = [str(el) for el in chain.from_iterable(
        [force_list(get_value(json, path)) for path in date_paths])]

    if dates:
        result = earliest_date(dates)
        if result:
            json['earliest_date'] = result
예제 #6
0
def populate_earliest_date(record):
    """Populate the ``earliest_date`` field of Literature records."""
    date_paths = [
        'preprint_date',
        'thesis_info.date',
        'thesis_info.defense_date',
        'publication_info.year',
        'legacy_creation_date',
        'imprints.date',
    ]

    dates = [
        str(el) for el in chain.from_iterable(
            [force_list(get_value(record, path)) for path in date_paths]
        )
    ]

    if dates:
        result = earliest_date(dates)
        if result:
            record['earliest_date'] = result
예제 #7
0
def populate_earliest_date(sender, json, *args, **kwargs):
    """Populate the ``earliest_date`` field of Literature records."""
    if 'hep.json' not in json.get('$schema'):
        return

    date_paths = [
        'preprint_date',
        'thesis_info.date',
        'thesis_info.defense_date',
        'publication_info.year',
        'legacy_creation_date',
        'imprints.date',
    ]

    dates = [
        str(el) for el in chain.from_iterable(
            [force_list(get_value(json, path)) for path in date_paths])
    ]

    if dates:
        result = earliest_date(dates)
        if result:
            json['earliest_date'] = result
예제 #8
0
def test_earliest_date():
    expected = '1686-06-30'
    result = earliest_date(['1686-06', '1686-06-30'])

    assert expected == result
예제 #9
0
def test_earliest_date_missing_month_and_day_without_full_date():
    assert earliest_date(["2000"]) == "2000"
예제 #10
0
def test_earliest_date_missing_month_and_day_with_full_date():
    assert earliest_date(["2000"], full_date=True) == "2000-01-01"