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

iplweb / bpp / 58b9a630-8512-44e6-b730-daac96d1c4d7

29 Aug 2025 07:21AM UTC coverage: 47.493% (+2.5%) from 45.008%
58b9a630-8512-44e6-b730-daac96d1c4d7

push

circleci

mpasternak
Fix tests

6 of 27 new or added lines in 2 files covered. (22.22%)

1342 existing lines in 64 files now uncovered.

19323 of 40686 relevant lines covered (47.49%)

1.51 hits per line

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

89.66
src/crossref_bpp/utils.py
1
from __future__ import annotations
4✔
2

3
import json
4✔
4
import textwrap
4✔
5

6
from django.db import models
4✔
7

8
from django.contrib.postgres.search import TrigramSimilarity
4✔
9

10

11
def json_format_with_wrap(item: [] | {} | str | None, width: int = 70) -> str:
4✔
12
    """Formatuje 'ładnie' dane JSON, w sytuacji, gdyby jakas linia
13
    przekraczała szerokośc ``width``, zawija.
14
    """
UNCOV
15
    s = json.dumps(item, indent=2).split("\n")
1✔
UNCOV
16
    news = []
1✔
UNCOV
17
    for elem in s:
1✔
UNCOV
18
        if len(elem) > width:
1✔
UNCOV
19
            elem = textwrap.fill(elem, width=width)
1✔
UNCOV
20
        news.append(elem)
1✔
UNCOV
21
    return "\n".join(news)
1✔
22

23

24
def perform_trigram_search(
4✔
25
    queryset,
26
    trigram_db_field,
27
    trigram_db_value,
28
    max_number_records=5,
29
    minimum_acceptable_similarity=0.6,
30
    db_trigram_target="podobienstwo",
31
    similarity_step_down=0.05,
32
    similarity_step_up=0.01,
33
    max_steps=20,
34
) -> list[models.Model] | None:
35
    """Performs a TrigramSimilarity search, starting from similarity value of
36
    1.0, desceding every ``step`` as long as the number of records is below ``max_number_records``
37

38
    :param queryset: Django queryset, can be anything.
39
    :param trigram_db_field: trigram database field, can be Lower('db_column') etc,
40
    :param trigram_db_value: value you're looking for in trigram_db_field, will be used
41
    to compare similarity.
42
    """
43

UNCOV
44
    kwargs_annotate = {
1✔
45
        db_trigram_target: TrigramSimilarity(trigram_db_field, trigram_db_value)
46
    }
47

UNCOV
48
    current_similarity = 1.0
1✔
UNCOV
49
    current_step = 0
1✔
UNCOV
50
    while (
1✔
51
        current_similarity > minimum_acceptable_similarity or current_step >= max_steps
52
    ):
UNCOV
53
        current_step += 1
1✔
UNCOV
54
        kwargs_filter = {db_trigram_target + "__gte": current_similarity}
1✔
UNCOV
55
        my_queryset = queryset.annotate(**kwargs_annotate).filter(**kwargs_filter)
1✔
56

UNCOV
57
        cnt = my_queryset[: max_number_records + 1].count()
1✔
UNCOV
58
        if cnt == max_number_records + 1:
1✔
59
            # Za dużo rekordów. Zwiększ nieznacznie pożądane podobieństwo i szukaj dalej.
60
            current_similarity += similarity_step_up
×
61
            continue
×
62

UNCOV
63
        if cnt == 0:
1✔
64
            # Za mało rekordów. Zmniejsz poszukiwane prawdopodobieństwo:
UNCOV
65
            current_similarity -= similarity_step_down
1✔
UNCOV
66
            continue
1✔
67

68
        return my_queryset.order_by(f"-{db_trigram_target}")
×
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