Skip to content

Commit 107dfdf

Browse files
committed
[qa] Run openwisp-qa-format
Applied openwisp-qa-format only. No functional changes.
1 parent 8fe905a commit 107dfdf

File tree

19 files changed

+605
-519
lines changed

19 files changed

+605
-519
lines changed

README.rst

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ Documentation
8686
- `Usage documentation <https://openwisp.io/docs/stable/monitoring/>`_
8787
- `Developer documentation
8888
<https://openwisp.io/docs/stable/monitoring/developer/>`_
89+
8990
------------
9091

9192
.. contents:: **Table of Contents**:
@@ -261,7 +262,7 @@ Run the docker container:
261262
Setup (integrate in an existing Django project)
262263
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
263264

264-
Follow the setup instructions of `openwisp-controller
265+
Follow the setup instructions of `openwisp-controller repository
265266
<https://github.com/openwisp/openwisp-controller>`_, then add the settings described below.
266267

267268
.. code-block:: python
@@ -885,20 +886,21 @@ Example taken from the default configuration of the traffic chart:
885886

886887
.. code-block:: python
887888
888-
'traffic': {
889-
# other configurations for this chart
890-
891-
# traffic measured in 'B' (bytes)
892-
# unit B, KB, MB, GB, TB
893-
'unit': 'adaptive_prefix+B',
894-
},
889+
CHARTS = {
890+
'traffic': {
891+
# other configurations for this chart
895892
896-
'bandwidth': {
897-
# adaptive unit for bandwidth related charts
898-
# bandwidth measured in 'bps'(bits/sec)
899-
# unit bps, Kbps, Mbps, Gbps, Tbps
900-
'unit': 'adaptive_prefix+bps',
901-
},
893+
# traffic measured in 'B' (bytes)
894+
# unit B, KB, MB, GB, TB
895+
'unit': 'adaptive_prefix+B',
896+
},
897+
'bandwidth': {
898+
# adaptive unit for bandwidth related charts
899+
# bandwidth measured in 'bps' (bits/sec)
900+
# unit bps, Kbps, Mbps, Gbps, Tbps
901+
'unit': 'adaptive_prefix+bps',
902+
},
903+
}
902904
903905
Monitoring WiFi Sessions
904906
------------------------

openwisp_monitoring/db/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
chart_query = timeseries_db.queries.chart_query
44

5-
__all__ = ['timeseries_db', 'chart_query']
5+
__all__ = ["timeseries_db", "chart_query"]

openwisp_monitoring/db/backends/__init__.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@
1010
TIMESERIES_DB = getattr(settings, "TIMESERIES_DATABASE", None)
1111
if not TIMESERIES_DB:
1212
TIMESERIES_DB = {
13-
'BACKEND': 'openwisp_monitoring.db.backends.influxdb',
14-
'USER': getattr(settings, 'INFLUXDB_USER', 'openwisp'),
15-
'PASSWORD': getattr(settings, 'INFLUXDB_PASSWORD', 'openwisp'),
16-
'NAME': getattr(settings, 'INFLUXDB_DATABASE', 'openwisp2'),
17-
'HOST': getattr(settings, 'INFLUXDB_HOST', 'localhost'),
18-
'PORT': getattr(settings, 'INFLUXDB_PORT', '8086'),
13+
"BACKEND": "openwisp_monitoring.db.backends.influxdb",
14+
"USER": getattr(settings, "INFLUXDB_USER", "openwisp"),
15+
"PASSWORD": getattr(settings, "INFLUXDB_PASSWORD", "openwisp"),
16+
"NAME": getattr(settings, "INFLUXDB_DATABASE", "openwisp2"),
17+
"HOST": getattr(settings, "INFLUXDB_HOST", "localhost"),
18+
"PORT": getattr(settings, "INFLUXDB_PORT", "8086"),
1919
}
2020
logger.warning(
21-
'The previous method to define Timeseries Database has been deprecated. Please refer to the docs:\n'
22-
'https://github.com/openwisp/openwisp-monitoring#setup-integrate-in-an-existing-django-project'
21+
"The previous method to define Timeseries Database has been deprecated. Please refer to the docs:\n"
22+
"https://github.com/openwisp/openwisp-monitoring#setup-integrate-in-an-existing-django-project"
2323
)
2424

2525

@@ -31,17 +31,17 @@ def load_backend_module(backend_name=TIMESERIES_DB["BACKEND"], module=None):
3131
well defined.
3232
"""
3333
try:
34-
assert 'BACKEND' in TIMESERIES_DB, 'BACKEND'
35-
if 'BACKEND' in TIMESERIES_DB and '2' in TIMESERIES_DB['BACKEND']:
34+
assert "BACKEND" in TIMESERIES_DB, "BACKEND"
35+
if "BACKEND" in TIMESERIES_DB and "2" in TIMESERIES_DB["BACKEND"]:
3636
# InfluxDB 2.x specific checks
37-
assert 'TOKEN' in TIMESERIES_DB, 'TOKEN'
38-
assert 'ORG' in TIMESERIES_DB, 'ORG'
39-
assert 'BUCKET' in TIMESERIES_DB, 'BUCKET'
37+
assert "TOKEN" in TIMESERIES_DB, "TOKEN"
38+
assert "ORG" in TIMESERIES_DB, "ORG"
39+
assert "BUCKET" in TIMESERIES_DB, "BUCKET"
4040
else:
4141
# InfluxDB 1.x specific checks
42-
assert 'USER' in TIMESERIES_DB, 'USER'
43-
assert 'PASSWORD' in TIMESERIES_DB, 'PASSWORD'
44-
assert 'NAME' in TIMESERIES_DB, 'NAME'
42+
assert "USER" in TIMESERIES_DB, "USER"
43+
assert "PASSWORD" in TIMESERIES_DB, "PASSWORD"
44+
assert "NAME" in TIMESERIES_DB, "NAME"
4545
if module:
4646
return import_module(f"{backend_name}.{module}")
4747
else:
@@ -55,7 +55,7 @@ def load_backend_module(backend_name=TIMESERIES_DB["BACKEND"], module=None):
5555
except ImportError as e:
5656
# The database backend wasn't found. Display a helpful error message
5757
# listing all built-in database backends.
58-
builtin_backends = ['influxdb', 'influxdb2']
58+
builtin_backends = ["influxdb", "influxdb2"]
5959
if backend_name not in [
6060
f"openwisp_monitoring.db.backends.{b}" for b in builtin_backends
6161
]:
@@ -66,5 +66,5 @@ def load_backend_module(backend_name=TIMESERIES_DB["BACKEND"], module=None):
6666
) from e
6767

6868

69-
timeseries_db = load_backend_module(module='client').DatabaseClient()
70-
timeseries_db.queries = load_backend_module(module='queries')
69+
timeseries_db = load_backend_module(module="client").DatabaseClient()
70+
timeseries_db.queries = load_backend_module(module="queries")

openwisp_monitoring/db/backends/influxdb/client.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class DatabaseClient(object):
6666
]
6767

6868
def __init__(self, db_name=None):
69-
self.db_name = db_name or TIMESERIES_DB['NAME']
69+
self.db_name = db_name or TIMESERIES_DB["NAME"]
7070
self.client_error = InfluxDBClientError
7171

7272
@retry
@@ -346,7 +346,7 @@ def read(self, key, fields, tags, **kwargs):
346346
q = f"{q} LIMIT {limit}"
347347
return list(self.query(q, precision=precision).get_points())
348348

349-
def get_list_query(self, query, precision='s', **kwargs):
349+
def get_list_query(self, query, precision="s", **kwargs):
350350
result = self.query(query, precision=precision)
351351
if not len(result.keys()) or result.keys()[0][1] is None:
352352
return list(result.get_points())
@@ -533,7 +533,7 @@ def _get_top_fields(
533533
Returns top fields if ``get_fields`` set to ``True`` (default)
534534
else it returns points containing the top fields.
535535
"""
536-
q = default_query.replace('{field_name}', '{fields}')
536+
q = default_query.replace("{field_name}", "{fields}")
537537
q = self.get_query(
538538
query=q,
539539
params=params,
@@ -554,7 +554,7 @@ def _get_top_fields(
554554
keys = list(sorted_dict.keys())
555555
keys.reverse()
556556
top = keys[0:number]
557-
top_fields = [item.replace('sum_', '') for item in top]
557+
top_fields = [item.replace("sum_", "") for item in top]
558558
if get_fields:
559559
return top_fields
560560
query = self.get_query(
@@ -568,15 +568,15 @@ def _get_top_fields(
568568
timezone=timezone,
569569
)
570570
return self.get_list_query(query)
571-
571+
572572
def default_chart_query(self, tags):
573573
q = "SELECT {field_name} FROM {key} WHERE time >= '{time}'"
574574
if tags:
575575
q += " AND content_type = '{content_type}' AND object_id = '{object_id}'"
576576
return q
577577

578578
def _device_data(self, key, tags, rp, **kwargs):
579-
""" returns last snapshot of ``device_data`` """
579+
"""returns last snapshot of ``device_data``"""
580580
query = (
581581
f"SELECT data FROM {rp}.{key} WHERE pk = '{tags['pk']}' "
582582
"ORDER BY time DESC LIMIT 1"

0 commit comments

Comments
 (0)