• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

iplweb / bpp / 18634744198

19 Oct 2025 07:00PM UTC coverage: 31.618% (-29.9%) from 61.514%
18634744198

push

github

mpasternak
Merge branch 'release/v202510.1270'

657 of 9430 branches covered (6.97%)

Branch coverage included in aggregate %.

229 of 523 new or added lines in 42 files covered. (43.79%)

11303 existing lines in 316 files now uncovered.

14765 of 39346 relevant lines covered (37.53%)

0.38 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

29.91
src/import_common/normalization.py
1
from decimal import Decimal
1✔
2

3
from django.core.exceptions import ValidationError
1✔
4
from numpy import isnan
1✔
5
from pathspec.util import normalize_file
1✔
6

7

8
def remove_trailing_interpunction(s: str) -> str:
1✔
UNCOV
9
    try:
×
UNCOV
10
        while s[-1] in ".,-":
×
11
            s = s[:-1]
×
12
    except IndexError:
×
13
        return ""
×
14

UNCOV
15
    return s
×
16

17

18
def remove_extra_spaces(s: str) -> str:
1✔
19
    while s.find("  ") >= 0:
1!
UNCOV
20
        s = s.replace("  ", " ")
×
21
    s = s.strip()
1✔
22
    return s
1✔
23

24

25
def fix_spaces_before_dots_and_commas(s: str) -> str:
1✔
UNCOV
26
    while s.find(" .") >= 0 or s.find(" ,") >= 0:
×
27
        s = s.replace(" .", ". ").replace(" ,", ", ")
×
UNCOV
28
    return s
×
29

30

31
def normalize_first_name(s: str) -> str | None:
1✔
32
    if not isinstance(s, str) or s is None or s == "" or not s:
1!
33
        return
×
34
    return remove_extra_spaces(s)
1✔
35

36

37
normalize_last_name = normalize_first_name
1✔
38
normalize_publisher = normalize_first_name
1✔
39

40

41
def normalize_boolean(s: str | None | bool) -> bool | None:
1✔
UNCOV
42
    if isinstance(s, bool):
×
43
        return s
×
44

UNCOV
45
    if not isinstance(s, str):
×
46
        return
×
47

UNCOV
48
    s = s.strip().lower()
×
49

UNCOV
50
    if s.lower() in ["tak", "prawda", "true", "t", "p"]:
×
UNCOV
51
        return True
×
52

53
    if s in ["false", "nie", "fałsz", "falsz", "f", "n"]:
×
54
        return False
×
55

56

57
def normalize_nullboleanfield(s: str | None | bool) -> bool | None:
1✔
UNCOV
58
    return normalize_boolean(s)
×
59

60

61
def normalize_skrot(s):
1✔
UNCOV
62
    if s is None:
×
63
        return
×
UNCOV
64
    return remove_extra_spaces(fix_spaces_before_dots_and_commas(s.lower()))
×
65

66

67
def normalize_tytul_naukowy(s):
1✔
68
    return normalize_skrot(s)
×
69

70

71
def normalize_title(s: str) -> str | None:
1✔
UNCOV
72
    if s is None or not s:
×
73
        return
×
UNCOV
74
    return remove_extra_spaces(s)
×
75

76

77
ONLINE_STR = "[online]"
1✔
78

79

80
def normalize_tytul_publikacji(s):
1✔
UNCOV
81
    if s is None:
×
82
        return
×
UNCOV
83
    ret = remove_trailing_interpunction(
×
84
        remove_extra_spaces(fix_spaces_before_dots_and_commas(s))
85
    )
UNCOV
86
    if ret.endswith(ONLINE_STR):
×
UNCOV
87
        ret = ret[: -len(ONLINE_STR)].strip()
×
UNCOV
88
    ret = ret.replace("\r", " ").replace("\n", " ")
×
UNCOV
89
    return remove_extra_spaces(ret)
×
90

91

92
def normalize_funkcja_autora(s: str) -> str:
1✔
UNCOV
93
    return normalize_skrot(s).lower()
×
94

95

96
def normalize_grupa_pracownicza(s: str):
1✔
UNCOV
97
    return normalize_skrot(s)
×
98

99

100
def normalize_wymiar_etatu(s: str):
1✔
UNCOV
101
    return normalize_skrot(s)
×
102

103

104
def normalize_nazwa_jednostki(s: str) -> str:
1✔
UNCOV
105
    return remove_extra_spaces(s.strip())
×
106

107

108
def normalize_nazwa_wydawcy(s: str) -> str:
1✔
109
    return remove_extra_spaces(s.strip())
1✔
110

111

112
def normalize_exception_reason(s: str) -> str:
1✔
113
    return remove_extra_spaces(s.replace("\n", " ").replace("\r\n", " "))
×
114

115

116
def normalize_tytul_zrodla(s):
1✔
UNCOV
117
    return remove_extra_spaces(fix_spaces_before_dots_and_commas(s))
×
118

119

120
def normalize_nazwa_dyscypliny(s):
1✔
UNCOV
121
    return remove_extra_spaces(fix_spaces_before_dots_and_commas(s))
×
122

123

124
def normalize_isbn(isbn: str) -> str | None:
1✔
125
    if isbn is None or not isinstance(isbn, str) or not isbn:
1✔
126
        return
1✔
127

128
    return isbn.replace(".", "").replace("-", "").replace(" ", "").strip()
1✔
129

130

131
normalize_issn = normalize_isbn
1✔
132

133

134
def normalize_kod_dyscypliny(k):
1✔
135
    if k is None:
1!
136
        return None
×
137

138
    if k.endswith("_0"):
1!
UNCOV
139
        k = k[:-2]
×
UNCOV
140
        return f"{k[0]}.{int(k[1:])}"
×
141
    if k.find(".") >= 0:
1!
142
        return k
1✔
143

UNCOV
144
    if len(k) == 4 and k[0] in "123456789":
×
145
        # 1001 -> 10.1
UNCOV
146
        return f"{k[0]}{k[1]}.{int(k[2:])}"
×
147

UNCOV
148
    return f"{k[0]}.{int(k[1:])}"
×
149

150

151
def normalize_public_uri(public_uri):
1✔
152
    if public_uri is not None:
×
153
        return public_uri.strip()
×
154

155

156
def normalize_doi(s: str) -> None | str:
1✔
157
    """
158
    https://www.doi.org/doi_handbook/2_Numbering.html#2.4
159
    """
160

161
    if s is None:
1!
UNCOV
162
        return
×
163

164
    s = s.strip()
1✔
165

166
    if not s:
1!
UNCOV
167
        return
×
168

169
    return (
1✔
170
        s.lower()
171
        .replace("http://", "")
172
        .replace("https://", "")
173
        .replace("dx.doi.org/", "")
174
        .replace("doi.org/", "")
175
    )
176

177

178
def normalize_filename(s: str) -> str:
1✔
179
    s = normalize_file(s).replace(" ", "_").replace(",", "_")
×
180

181
    while s.find("__") != -1:
×
182
        s = s.replace("__", "_")
×
183
    return s
×
184

185

186
def normalize_orcid(s: str) -> str | None:
1✔
187
    if not isinstance(s, str) or s is None or s == "" or not s:
1!
UNCOV
188
        return
×
189
    return (
1✔
190
        s.strip()
191
        .lower()
192
        .replace("http://orcid.org/", "")
193
        .replace("https://orcid.org/", "")
194
        .upper()
195
    )
196

197

198
def normalize_nulldecimalfield(probably_decimal):
1✔
199
    if probably_decimal is None:
×
200
        return
×
201

202
    try:
×
203
        if probably_decimal is not None and isnan(probably_decimal):
×
204
            return
×
205
    except TypeError:
×
206
        raise ValidationError(
×
207
            f"Nie mogę skonwertować liczby w formacie {probably_decimal} na typ Decimal"
208
        )
209

210
    try:
×
211
        # float() zeby pozbyc sie np numpy.int64
212
        return Decimal(float(probably_decimal))
×
213
    except TypeError:
×
214
        raise ValidationError(
×
215
            f"Nie mogę skonwertować liczby w formacie {probably_decimal} na typ Decimal"
216
        )
217

218

219
def normalize_oplaty_za_publikacje(
1✔
220
    rekord,
221
    opl_pub_cost_free,
222
    opl_pub_research_potential,
223
    opl_pub_research_or_development_projects,
224
    opl_pub_other,
225
    opl_pub_amount,
226
):
227
    # Publikacja bezkosztowa
228
    rekord.opl_pub_cost_free = False
×
229
    if normalize_boolean(opl_pub_cost_free):
×
230
        rekord.opl_pub_cost_free = True
×
231

232
    # Środki finansowe o których mowa w artykule 365
233
    rekord.opl_pub_research_potential = False
×
234
    if normalize_boolean(opl_pub_research_potential):
×
235
        rekord.opl_pub_research_potential = True
×
236

237
    # Środki finansowe na realizację projektu
238
    rekord.opl_pub_research_or_development_projects = False
×
239
    if normalize_boolean(opl_pub_research_or_development_projects):
×
240
        rekord.opl_pub_research_or_development_projects = True
×
241

242
    # Inne srodki finansowe
243
    rekord.opl_pub_other = False
×
244
    if normalize_boolean(opl_pub_other):
×
245
        rekord.opl_pub_other = True
×
246

247
    # Kwota
248
    rekord.opl_pub_amount = normalize_nulldecimalfield(opl_pub_amount)
×
249

250
    rekord.clean()
×
251

252

253
def normalize_rekord_id(rekord_id):
1✔
254
    """Normalizuje z postaci (43, 43) do {43,43} zeby mozna odpytac baze dancyh."""
255
    if not isinstance(rekord_id, str):
×
256
        return
×
257

258
    if rekord_id is None:
×
259
        return
×
260

261
    if not rekord_id:
×
262
        return
×
263

264
    ret = rekord_id.replace("(", "{").replace(")", "}").strip()
×
265
    if not ret.startswith("{"):
×
266
        ret = "{" + ret
×
267
    if not ret.endswith("}"):
×
268
        ret += "}"
×
269

270
    return ret
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc