How to use the awe.chart.FlatDictTransformer function in awe

To help you get started, we’ve selected a few awe examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dankilman / awe / tests / test_chart.py View on Github external
def test_flat_transformer():
    flat = chart.FlatDictTransformer(
        chart_mapping=['one', 'two'],
        series_mapping=['three', 'four'],
        value_key='value_field'
    )
    assert flat.transform(None) == {}
    assert flat.transform([]) == {}

    transform = flat.transform([
        {'one': 'one1', 'two': 'two1', 'three': 'three1', 'four': 'four', 'value_field': 1, 'unused1': True},
        {'one': 'one1', 'two': 'two1', 'three': 'three2', 'four': 'four', 'value_field': 2, 'unused2': True},
        {'one': 'one2', 'two': 'two1', 'three': 'three1', 'four': 'four', 'value_field': 3, 'unused1': True},
        {'one': 'one2', 'two': 'two1', 'three': 'three2', 'four': 'four', 'value_field': 4, 'unused2': True},
        {'one': 'one1', 'two': 'two1', 'three': 'three1', 'four': 'four', 'value_field': 5, 'unused1': True},
        {'one': 'one1', 'two': 'two1', 'three': 'three2', 'four': 'four', 'value_field': 6, 'unused2': True},
        {'one': 'one2', 'two': 'two1', 'three': 'three1', 'four': 'four', 'value_field': 7, 'unused1': True},
        {'one': 'one2', 'two': 'two1', 'three': 'three2', 'four': 'four', 'value_field': 8, 'unused2': True},
github dankilman / awe / tests / test_chart.py View on Github external
def test_flat_transformer_timed_tuples():
    ts = 1000.12
    expected_ts = int(ts * 1000)
    numbers = chart.FlatDictTransformer(['a'], ['b'], 'c')
    for ds in [list, tuple]:
        transform = numbers.transform([ds((ts, {'a': 'a', 'b': 'b', 'c': 1234}))])
        assert transform == {
            'a': {'series': [{'data': [(expected_ts, 1234)], 'name': 'b'}], 'title': 'a', 'type': 'line'}
        }
github dankilman / awe / awe / chart.py View on Github external
def _process_path(self, chart_dict, now, path, value):
        level_to_key = {i+1: level for i, level in enumerate(path)}
        chart_key = ' '.join(level_to_key[l] for l in self._chart_mapping)
        series_key = ' '.join(level_to_key[l] for l in self._series_mapping)
        current_chart = chart_dict.setdefault(chart_key, {})
        series_data = current_chart.setdefault(series_key, [])
        series_data.append((now, value))


transformers = {t.key: t for t in [
    NoOpTransformer(),
    NumberSequenceTransformer(),
]}

transformer_classes = {t.key: t for t in [
    FlatDictTransformer
]}


@builtin
class Chart(Element):

    allow_children = False
    _transformer = None

    def _init(self, data=None, options=None, transform=None, moving_window=None):
        self.transformer = transform
        self.update_data({
            'data': self.transformer.transform(data),
            'options': options or {},
            'movingWindow': moving_window
        })