src/xstream_piflow_scatter_plot_chart.py
1"""PiFlow scatter-plot projection and ordering, without image rendering."""
2from dacp_piflow_support import params, identifier, query
3
4
5def process(ctx):
6 p = params(ctx, ['legend', 'customizedProperties'])
7 legend, dimensions = p['legend'], p['customizedProperties']
8 if not isinstance(legend, str) or not legend or not isinstance(dimensions, dict) or not dimensions:
9 raise ValueError('legend and nonempty dimension mapping required')
10 if any(not isinstance(k, str) or not k or type(v) is not int for k, v in dimensions.items()):
11 raise ValueError('dimension names must map to integers')
12 if legend in dimensions or len(set(dimensions.values())) != len(dimensions):
13 raise ValueError('unique dimensions and order positions required')
14 names = [legend] + sorted(dimensions, key=dimensions.get)
15 query(ctx, 'SELECT ' + ','.join(map(identifier, names)) + ' FROM source ORDER BY ' + identifier(legend) + ',' + identifier(names[1]))
16
17
18def infer_outputs(inputs, params):
19 import pyarrow as pa
20 from xstream_operator import descriptor, result, records_schema
21 expected = {'source'}
22 if set(inputs) != expected:
23 raise ValueError('unexpected input ports')
24 outputs = {'result': {'representations': ['records'], 'formats': ['arrow'], 'certainty': 'unknown'}}
25 return result(outputs)
26
27
28def preview_outputs(inputs, params, limits):
29 from xstream_operator import preview_process
30 return preview_process(process, inputs, params, limits)
31
32
33if __name__ == '__main__':
34 from xstream_operator import run_operator
35 run_operator(process, infer_outputs, preview_outputs=preview_outputs)