def correct_data_types_withing_data_dict_list(self, table_name: str, input_dict_list): table = self.get_table_by_name(table_name) for data_dict in input_dict_list: for column_name, value in data_dict.items(): column = table.get_column(column_name) if column is not None: if column.is_integer: data_dict[column_name] = int( MyMath.get_float_for_string(value)) elif column.is_boolean: if value == 'True': data_dict[column_name] = True elif value == 'False': data_dict[column_name] = False elif column.is_float: if MyText.is_number(value): data_dict[ column_name] = MyMath.get_float_for_string( value) elif column.is_date: if MyText.is_date_time_date(value): data_dict[column_name] = MyText.get_date_time_date( value) elif column.is_time: if MyText.is_date_time_time(value): data_dict[column_name] = MyText.get_date_time_time( value)
def add_row_specific_styles_to_table_style_data(rows, table_style_data): column_id = DC.ACTUAL fractions = 5 color_dict = { 1: 'orange', 2: 'bisque', 3: 'ivory', 4: 'lightgreen', 5: 'lime' } for row in rows: if row[DC.ID] != '': actual_price = MyMath.get_float_for_string(row[DC.ACTUAL]) stop = MyMath.get_float_for_string(row[DC.STOP]) limit = stop * 1.05 if row[ DC.LIMIT] == 'inf' else MyMath.get_float_for_string( row[DC.LIMIT]) if actual_price <= stop: bg_color = 'red' else: bg_color = 'green' value_range = limit - stop value_range_fraction = value_range / fractions for i in range(1, fractions + 1): if actual_price <= stop + i * value_range_fraction: bg_color = color_dict[i] break filter_color = '{{{}}} eq "{}"'.format(DC.ID, row[DC.ID]) table_style_data.append({ 'if': { 'column_id': column_id, 'filter': filter_color }, 'backgroundColor': bg_color })
def add_row_specific_styles_to_table_style_data(rows, table_style_data): column_id = PDC.AMOUNT_AVAILABLE for row in rows: if row[PDC.EXCHANGE] != '': amount = MyMath.get_float_for_string(row[PDC.AMOUNT]) amount_available = MyMath.get_float_for_string( row[PDC.AMOUNT_AVAILABLE]) if amount != amount_available: bg_color = 'bisque' filter_color = '{{{}}} eq "{}"'.format( PDC.ASSET, row[PDC.ASSET]) table_style_data.append({ 'if': { 'column_id': column_id, 'filter': filter_color }, 'backgroundColor': bg_color })
def __get_corrected_value__(key: str, value): if key == SLDC.TITLE: return value.replace('/', ' / ') if type(key) is str else value elif key == SLDC.PRICE: if type(value) is str: return MyMath.get_float_for_string(value) elif key == SLDC.START_DATE: return MyDate.get_date_str_for_date_term(value) elif key in [SLDC.VISITS, SLDC.BOOK_MARKS]: if type(value) is str: return int(value.split(' ')[0]) return value
def __get_pattern_result_for_doc_as_float__(self, doc: Doc): text_result = self.__get_pattern_result_for_doc_as_text__(doc) return MyMath.get_float_for_string(text_result)
def add_price(self, input_str: str): self.set_value(SLDC.PRICE, MyMath.get_float_for_string(input_str, delimiter='.')) self.set_value(SLDC.PRICE_SINGLE, self.get_value(SLDC.PRICE)) self.set_value(SLDC.PRICE_ORIGINAL, self.get_value(SLDC.PRICE))