File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed
src/daq_config_server/models/converters/lookup_tables Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -17,3 +17,24 @@ def check_row_length_matches_n_columns(self):
1717 f"of columns: { self .column_names } "
1818 )
1919 return self
20+
21+ def get_value (
22+ self ,
23+ column_name : str ,
24+ value : int | float ,
25+ target_column_name : str ,
26+ value_must_exist : bool = True ,
27+ ) -> int | float :
28+ column_index = self .column_names .index (column_name )
29+ column = [row [column_index ] for row in self .rows ]
30+ target_column_index = self .column_names .index (target_column_name )
31+
32+ closest_value = (
33+ min (column , key = lambda x : abs (x - value )) if not value_must_exist else value
34+ )
35+ target_row = self .rows [column .index (closest_value )]
36+
37+ return target_row [target_column_index ]
38+
39+ def columns (self ) -> list [list [int | float ]]:
40+ return [[row [i ] for row in self .rows ] for i in range (len (self .column_names ))]
You can’t perform that action at this time.
0 commit comments