Skip to content

Commit

Permalink
review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jstucke committed Feb 11, 2021
1 parent 8ed9242 commit 829e9cf
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
14 changes: 5 additions & 9 deletions src/test/unit/web_interface/test_app_jinja_filter.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# pylint: disable=protected-access,wrong-import-order

import pytest
from flask import render_template_string

from test.unit.web_interface.base import WebInterfaceTest
from web_interface.components.jinja_filter import FilterClass

# pylint: disable=protected-access


class TestAppShowAnalysis(WebInterfaceTest):

Expand Down Expand Up @@ -60,14 +60,10 @@ def test_virtual_path_element_to_span(hid, uid, expected_output):
assert expected_output in FilterClass._virtual_path_element_to_span(hid, uid, 'root_uid')


class MockConfig:
pass


class FilterClassMock:
def __init__(self, value=None):
self._config = MockConfig()
setattr(self._config, 'getint', lambda *_, **__: value if value is not None else 10)
@staticmethod
def _get_chart_element_count():
return 10


@pytest.mark.parametrize('input_data, limit, expected_result', [
Expand Down
12 changes: 10 additions & 2 deletions src/web_interface/components/jinja_filter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import logging
from typing import List, Optional

from common_helper_filter.time import time_format
Expand Down Expand Up @@ -135,18 +136,25 @@ def check_auth(self, _):
return self._config.getboolean('ExpertSettings', 'authentication')

def data_to_chart_limited(self, data, limit: Optional[int] = None, color_list=None):
limit = self._config.getint('statistics', 'max_elements_per_chart', fallback=10) if limit is None else limit
limit = self._get_chart_element_count() if limit is None else limit
try:
label_list, value_list = [list(d) for d in zip(*data)]
except ValueError:
return None
label_list, value_list = flt.set_limit_for_data_to_chart(label_list, limit, value_list)
color_list = flt.set_color_list_for_data_to_chart(color_list, value_list, limit)
color_list = get_color_list(len(value_list), limit=limit) if color_list is None else color_list
return {
'labels': label_list,
'datasets': [{'data': value_list, 'backgroundColor': color_list, 'borderColor': '#fff', 'borderWidth': 2}]
}

def _get_chart_element_count(self):
limit = self._config.getint('statistics', 'max_elements_per_chart', fallback=10)
if limit > 100:
logging.warning('Value of "max_elements_per_chart" in configuration is too large.')
return 100
return limit

def data_to_chart(self, data):
color_list = get_color_list(1) * len(data)
return self.data_to_chart_limited(data, limit=0, color_list=color_list)
Expand Down
8 changes: 1 addition & 7 deletions src/web_interface/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from helperFunctions.compare_sets import remove_duplicates_from_list
from helperFunctions.dataConversion import make_unicode_string
from helperFunctions.tag import TagColor
from helperFunctions.web_interface import get_alternating_color_list, get_color_list
from helperFunctions.web_interface import get_alternating_color_list
from web_interface.security.authentication import user_has_privilege
from web_interface.security.privileges import PRIVILEGES

Expand Down Expand Up @@ -237,12 +237,6 @@ def data_to_chart_with_value_percentage_pairs(data, limit=10): # pylint: disabl
return result


def set_color_list_for_data_to_chart(color_list, value_list, limit: int):
if not color_list:
color_list = get_color_list(len(value_list), limit=limit)
return color_list


def set_limit_for_data_to_chart(label_list, limit, value_list):
if limit and len(label_list) > limit:
label_list = label_list[:limit]
Expand Down

0 comments on commit 829e9cf

Please sign in to comment.