filters.py 1.46 KB
Newer Older
LE GAC Renaud's avatar
LE GAC Renaud committed
1
# -*- coding: utf-8 -*-
2 3 4 5
"""a collections of functions to correct entries in the database.

"""

LE GAC Renaud's avatar
LE GAC Renaud committed
6

7 8
def CLEAN_COLLABORATION(value):
    """Correct stupid mistakes on the collaboration field.
LE GAC Renaud's avatar
LE GAC Renaud committed
9

10 11 12 13
        * No heading and trailing spaces.
        * No duplicate entries.
        * Remove entries starting with *on behalf*.
        * Collaboration always start with a Capital letter.
LE GAC Renaud's avatar
LE GAC Renaud committed
14

15 16
    Args:
        value (unicode): string where collaborations are separated by comma
LE GAC Renaud's avatar
LE GAC Renaud committed
17

18 19
    Returns:
        unicode:
LE GAC Renaud's avatar
LE GAC Renaud committed
20

21 22
    """
    li = []
LE GAC Renaud's avatar
LE GAC Renaud committed
23

24 25 26
    for el in value.split(','):
        # Fix to remove space at the beginning and at the end
        el = el.strip()
LE GAC Renaud's avatar
LE GAC Renaud committed
27

28 29
        # Fix "XXX collaboration" as "XXX Collaboration"
        el = el.replace('collaboration', 'Collaboration')
30 31
        el = el.replace('consortium', 'Consortium')
        el = el.replace('group', 'Group')
LE GAC Renaud's avatar
LE GAC Renaud committed
32

33 34 35
        # Fix to avoid duplicate entries
        if el in li:
            continue
LE GAC Renaud's avatar
LE GAC Renaud committed
36

37 38 39
        # Fix to remove 'on behalf of the LHCb Collaboration'
        if el.startswith('on behalf'):
            continue
LE GAC Renaud's avatar
LE GAC Renaud committed
40

41
        li.append(el)
LE GAC Renaud's avatar
LE GAC Renaud committed
42

43 44 45 46
    return ', '.join(li)


def CLEAN_THESIS_DEFENSE(value):
47
    """Correct stupid mistakes on the thesis defence field.
48

49
        * Remove prefix like *Presented*, *on*, *etc*.
LE GAC Renaud's avatar
LE GAC Renaud committed
50

51 52
    Args:
        value (unicode): string with the defence date
LE GAC Renaud's avatar
LE GAC Renaud committed
53

54 55
    Returns:
        unicode:
LE GAC Renaud's avatar
LE GAC Renaud committed
56

57 58
    """
    value = value.replace('Presented ', '')
59
    value = value.replace('presented ', '')
60
    value = value.replace('on ', '')
LE GAC Renaud's avatar
LE GAC Renaud committed
61
    return value