def test_create_data_from_nested_iterable(): Data( symbol="TDM_1", entries=[Comment("t / s s(t) / m"), Comment("here be data")] + rowmajor2rows((("0", "-2"), ("1.1", "0.1"), ("2.0", "3.1"), ("2.9", "4.5"))) # row major order "C-style" + columnmajor2rows( # column major order "Fortran-style" (("0", "1.1", "2.0", "2.9"), ("-2", "0.1", "3.1", "4.5")) ), )
def test_create_data_from_nested_iterable(): Data( symbol='TDM_1', entries=[ Comment('t / s s(t) / m'), Comment('here be data'), ] + rowmajor2rows( # row major order "C-style" (('0', '-2'), ('1.1', '0.1'), ('2.0', '3.1'), ('2.9', '4.5'))) + columnmajor2rows( # column major order "Fortran-style" (('0', '1.1', '2.0', '2.9'), ('-2', '0.1', '3.1', '4.5'))))
def test_create_data_from_custom_source(): # formatter is called for every cell, replacing the cell # formatter also available for: # columnmajor2rows, DataRow and DataColumn # # for more elaborate examples see test_streaming Data( symbol="TDM_1", entries=[Comment("t / s s(t) / m"), Comment("here be data from custom source")] + rowmajor2rows(((0, -2), (1.1, 0.1), (2.0, 3.1), (2.9, 4.5)), formatter=lambda x: "%.1f" % (x,)), )
def test_create_data_from_custom_source(): # formatter is called for every cell, replacing the cell # formatter also available for: # columnmajor2rows, DataRow and DataColumn # # for more elaborate examples see test_streaming Data( symbol='TDM_1', entries=[ Comment('t / s s(t) / m'), Comment('here be data from custom source') ] + rowmajor2rows(((0, -2), (1.1, 0.1), (2.0, 3.1), (2.9, 4.5)), formatter=lambda x: '%.1f' % (x, )), )
def adapt_packet(self, packet, context): # rowmajor2rows works with any nested iterable # see also test_table_sections.py return cl1.rowmajor2rows(packet)
def test_inject_tables(lhrstream): lhrstream.inject_packets( [ TableDefinitionsHeader(), KeyValue('table1', 't_1'), KeyValue('table2', 't_2'), DataDefinitionsHeader('t_1'), KeyValue('distance', 'd [m]'), KeyValue('time', 't [s]'), DataHeader('t_1'), Comment('d t'), DataRow(("2.3", "4.555")), DataRow(("1.2", "4.15")), DataDefinitionsHeader('t_2'), KeyValue('Energy', 'E [J]'), KeyValue('distance', 'd [m]'), # data streaming examples: # ------------------------ DataHeader('t_2'), DataRow(("2.3", "1.33")), DataRow(["100.2", "44.2"]), format_data_row((2.3, 4.555), lambda x: '%.2f' % (x, )) ] ) # Stream columns that are all known at a time. # For sequential streaming see test_column_data_protocol.py lhrstream.inject_packets( cl1.columns2rows( ( cl1.DataColumn(("1.0", "3.4", "5.2")), cl1.DataColumn(("2.0", "2.4", "2.2")), ) ) ) # stream nested iterable lhrstream.inject_packets( cl1.rowmajor2rows( ( ('0', '-2'), ('1.1', '0.1'), ('2.0', '3.1'), ('2.9', '4.5') ) ) ) # use a formatter: lhrstream.inject_packets( cl1.columnmajor2rows( ( (0, 1.1, 2.0, 2.9), (-2, 0.1, 3.1, 4.5) ), formatter=lambda x: '%.2f' % (x, ) ) )