Coverage for requests_tracker/sql/utils.py: 100%
0 statements
« prev ^ index » next coverage.py v7.4.4, created at 2024-04-18 22:19 +0000
« prev ^ index » next coverage.py v7.4.4, created at 2024-04-18 22:19 +0000
1# from django.utils.translation import gettext_lazy as _
2#
3#
4# def get_isolation_level_display(vendor: str, level: int) -> str:
5# if vendor != "postgresql":
6# raise ValueError(vendor)
7# import psycopg2.extensions
8#
9# choices = {
10# psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT: _("Autocommit"),
11# psycopg2.extensions.ISOLATION_LEVEL_READ_UNCOMMITTED: _("Read uncommitted"),
12# psycopg2.extensions.ISOLATION_LEVEL_READ_COMMITTED: _("Read committed"),
13# psycopg2.extensions.ISOLATION_LEVEL_REPEATABLE_READ: _("Repeatable read"),
14# psycopg2.extensions.ISOLATION_LEVEL_SERIALIZABLE: _("Serializable"),
15# }
16#
17# return str(choices.get(level))
18#
19#
20# def get_transaction_status_display(vendor: str, level: int) -> str:
21# if vendor != "postgresql":
22# raise ValueError(vendor)
23# import psycopg2.extensions
24#
25# choices = {
26# psycopg2.extensions.TRANSACTION_STATUS_IDLE: _("Idle"),
27# psycopg2.extensions.TRANSACTION_STATUS_ACTIVE: _("Active"),
28# psycopg2.extensions.TRANSACTION_STATUS_INTRANS: _("In transaction"),
29# psycopg2.extensions.TRANSACTION_STATUS_INERROR: _("In error"),
30# psycopg2.extensions.TRANSACTION_STATUS_UNKNOWN: _("Unknown"),
31# }
32#
33# return str(choices.get(level))
34#
35#
36# def contrasting_color_generator():
37# """
38# Generate constrasting colors by varying most significant bit of RGB first,
39# and then vary subsequent bits systematically.
40# """
41#
42# def rgb_to_hex(rgb):
43# return "#%02x%02x%02x" % tuple(rgb)
44#
45# triples = [
46# (1, 0, 0),
47# (0, 1, 0),
48# (0, 0, 1),
49# (1, 1, 0),
50# (0, 1, 1),
51# (1, 0, 1),
52# (1, 1, 1),
53# ]
54# n = 1 << 7
55# so_far = [[0, 0, 0]]
56# while True:
57# if n == 0: # This happens after 2**24 colours; presumably, never
58# yield "#000000" # black
59# copy_so_far = list(so_far)
60# for triple in triples:
61# for previous in copy_so_far:
62# rgb = [n * triple[i] + previous[i] for i in range(3)]
63# so_far.append(rgb)
64# yield rgb_to_hex(rgb)
65# n >>= 1