diff --git a/src/indicators.py b/src/indicators.py index 481b585..72e169a 100644 --- a/src/indicators.py +++ b/src/indicators.py @@ -317,9 +317,9 @@ class Indicators: # Fetch indicators based on visibility status if only_enabled: indicators_df = self.cache_manager.get_rows_from_datacache('indicators', - [('creator', user_id), ('visible', True)]) + [('creator', str(user_id)), ('visible', True)]) else: - indicators_df = self.cache_manager.get_rows_from_datacache('indicators', [('creator', user_id)]) + indicators_df = self.cache_manager.get_rows_from_datacache('indicators', [('creator', str(user_id))]) # Check if the DataFrame is empty if indicators_df is None or indicators_df.empty: @@ -355,17 +355,17 @@ class Indicators: :param indicator_names: List of indicator names to set as visible. :return: None """ - indicators = self.cache_manager.get_rows_from_datacache('indicators', [('creator', user_id)]) + indicators = self.cache_manager.get_rows_from_datacache('indicators', [('creator', str(user_id))]) if indicators.empty: return # Set visibility for all indicators off - self.cache_manager.modify_datacache_item('indicators', [('creator', user_id)], + self.cache_manager.modify_datacache_item('indicators', [('creator', str(user_id))], field_name='visible', new_data=False, overwrite='name') # Set visibility for the specified indicators on - self.cache_manager.modify_datacache_item('indicators', [('creator', user_id), ('name', indicator_names)], + self.cache_manager.modify_datacache_item('indicators', [('creator', str(user_id)), ('name', indicator_names)], field_name='visible', new_data=True, overwrite='name') def edit_indicator(self, user_name: str, params: dict): @@ -381,7 +381,7 @@ class Indicators: # Get the indicator from the user's indicator list user_id = self.users.get_id(user_name) indicator = self.cache_manager.get_rows_from_datacache('indicators', - [('name', indicator_name), ('creator', user_id)]) + [('name', indicator_name), ('creator', str(user_id))]) if indicator.empty: raise ValueError(f"Indicator '{indicator_name}' not found for user '{user_name}'.") @@ -396,7 +396,7 @@ class Indicators: if existing_properties_str != new_properties_str: self.cache_manager.modify_datacache_item( 'indicators', - [('creator', user_id), ('name', indicator_name)], + [('creator', str(user_id)), ('name', indicator_name)], field_name='properties', new_data=new_properties, overwrite='name' @@ -413,7 +413,7 @@ class Indicators: if existing_source_str != new_source_str and new_source_str is not None: self.cache_manager.modify_datacache_item( 'indicators', - [('creator', user_id), ('name', indicator_name)], + [('creator', str(user_id)), ('name', indicator_name)], field_name='source', new_data=new_source, overwrite='name' @@ -426,7 +426,7 @@ class Indicators: if current_visible != new_visible: self.cache_manager.modify_datacache_item( 'indicators', - [('creator', user_id), ('name', indicator_name)], + [('creator', str(user_id)), ('name', indicator_name)], field_name='visible', new_data=new_visible, overwrite='name' @@ -513,11 +513,11 @@ class Indicators: user_id = self.users.get_id(user_name=user_name) - visible = 1 if visible_only else 0 + visible = True if visible_only else False # Filter the indicators based on the query. indicators = self.cache_manager.get_rows_from_datacache('indicators', - [('creator', user_id), ('visible', visible)]) + [('creator', str(user_id)), ('visible', visible)]) # Return None if no indicators matched the query. if indicators.empty: @@ -537,6 +537,17 @@ class Indicators: (indicators['source'].apply(lambda s: s.get('exchange')) == source_exchange) & \ (indicators['source'].apply(lambda s: s.get('market')) == source_symbol) + # Convert source['market'] to a string for comparison + # source_market_str = json.dumps(source.get('market', {})) + # # Compare 'source' as strings + # mask = indicators['source'].apply( + # lambda s: ( + # json.dumps(json.loads(s).get('market', {})) == source_market_str + # if isinstance(s, str) else + # json.dumps(s.get('market', {})) == source_market_str + # ) + # ) + # Filter the DataFrame using the mask indicators = indicators[mask] @@ -571,7 +582,7 @@ class Indicators: # Get the user ID to filter the indicators belonging to the user user_id = self.users.get_id(user_name) - identifying_values = [('name', indicator_name), ('creator', user_id)] + identifying_values = [('name', indicator_name), ('creator', str(user_id))] self.cache_manager.remove_row_from_datacache(cache_name='indicators', filter_vals=identifying_values) def create_indicator(self, creator: str, name: str, kind: str, @@ -592,7 +603,8 @@ class Indicators: creator_id = self.users.get_id(creator) # Check if an indicator with the same name already exists - indicators = self.cache_manager.get_rows_from_datacache('indicators', [('name', name), ('creator', creator_id)]) + indicators = self.cache_manager.get_rows_from_datacache('indicators', [('name', name), + ('creator', str(creator_id))]) if not indicators.empty: print(f"Indicator '{name}' already exists for user '{creator}'. Skipping creation.")