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

iplweb / bpp / 0cececd7-a2e7-4a75-a26c-21df764ad54e

24 Aug 2025 10:29PM UTC coverage: 41.169% (-2.5%) from 43.704%
0cececd7-a2e7-4a75-a26c-21df764ad54e

push

circleci

mpasternak
Merge branch 'release/v202508.1206'

1 of 1 new or added line in 1 file covered. (100.0%)

2674 existing lines in 124 files now uncovered.

16057 of 39003 relevant lines covered (41.17%)

0.76 hits per line

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

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

3
import json
2✔
4
import textwrap
2✔
5

6
from django.db import models
2✔
7

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

10

11
def json_format_with_wrap(item: [] | {} | str | None, width: int = 70) -> str:
2✔
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")
×
UNCOV
16
    news = []
×
UNCOV
17
    for elem in s:
×
UNCOV
18
        if len(elem) > width:
×
UNCOV
19
            elem = textwrap.fill(elem, width=width)
×
UNCOV
20
        news.append(elem)
×
UNCOV
21
    return "\n".join(news)
×
22

23

24
def perform_trigram_search(
2✔
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 = {
×
45
        db_trigram_target: TrigramSimilarity(trigram_db_field, trigram_db_value)
46
    }
47

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

UNCOV
57
        cnt = my_queryset[: max_number_records + 1].count()
×
UNCOV
58
        if cnt == max_number_records + 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:
×
64
            # Za mało rekordów. Zmniejsz poszukiwane prawdopodobieństwo:
UNCOV
65
            current_similarity -= similarity_step_down
×
UNCOV
66
            continue
×
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