I think it is all working except I don't think the indicators are caching on the database.

This commit is contained in:
Rob 2024-09-20 17:40:47 -03:00
parent 29f30cb358
commit 38de03c022
1 changed files with 25 additions and 13 deletions

View File

@ -317,9 +317,9 @@ class Indicators:
# Fetch indicators based on visibility status # Fetch indicators based on visibility status
if only_enabled: if only_enabled:
indicators_df = self.cache_manager.get_rows_from_datacache('indicators', indicators_df = self.cache_manager.get_rows_from_datacache('indicators',
[('creator', user_id), ('visible', True)]) [('creator', str(user_id)), ('visible', True)])
else: 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 # Check if the DataFrame is empty
if indicators_df is None or indicators_df.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. :param indicator_names: List of indicator names to set as visible.
:return: None :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: if indicators.empty:
return return
# Set visibility for all indicators off # 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') field_name='visible', new_data=False, overwrite='name')
# Set visibility for the specified indicators on # 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') field_name='visible', new_data=True, overwrite='name')
def edit_indicator(self, user_name: str, params: dict): def edit_indicator(self, user_name: str, params: dict):
@ -381,7 +381,7 @@ class Indicators:
# Get the indicator from the user's indicator list # Get the indicator from the user's indicator list
user_id = self.users.get_id(user_name) user_id = self.users.get_id(user_name)
indicator = self.cache_manager.get_rows_from_datacache('indicators', 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: if indicator.empty:
raise ValueError(f"Indicator '{indicator_name}' not found for user '{user_name}'.") 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: if existing_properties_str != new_properties_str:
self.cache_manager.modify_datacache_item( self.cache_manager.modify_datacache_item(
'indicators', 'indicators',
[('creator', user_id), ('name', indicator_name)], [('creator', str(user_id)), ('name', indicator_name)],
field_name='properties', field_name='properties',
new_data=new_properties, new_data=new_properties,
overwrite='name' overwrite='name'
@ -413,7 +413,7 @@ class Indicators:
if existing_source_str != new_source_str and new_source_str is not None: if existing_source_str != new_source_str and new_source_str is not None:
self.cache_manager.modify_datacache_item( self.cache_manager.modify_datacache_item(
'indicators', 'indicators',
[('creator', user_id), ('name', indicator_name)], [('creator', str(user_id)), ('name', indicator_name)],
field_name='source', field_name='source',
new_data=new_source, new_data=new_source,
overwrite='name' overwrite='name'
@ -426,7 +426,7 @@ class Indicators:
if current_visible != new_visible: if current_visible != new_visible:
self.cache_manager.modify_datacache_item( self.cache_manager.modify_datacache_item(
'indicators', 'indicators',
[('creator', user_id), ('name', indicator_name)], [('creator', str(user_id)), ('name', indicator_name)],
field_name='visible', field_name='visible',
new_data=new_visible, new_data=new_visible,
overwrite='name' overwrite='name'
@ -513,11 +513,11 @@ class Indicators:
user_id = self.users.get_id(user_name=user_name) 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. # Filter the indicators based on the query.
indicators = self.cache_manager.get_rows_from_datacache('indicators', 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. # Return None if no indicators matched the query.
if indicators.empty: 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('exchange')) == source_exchange) & \
(indicators['source'].apply(lambda s: s.get('market')) == source_symbol) (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 # Filter the DataFrame using the mask
indicators = indicators[mask] indicators = indicators[mask]
@ -571,7 +582,7 @@ class Indicators:
# Get the user ID to filter the indicators belonging to the user # Get the user ID to filter the indicators belonging to the user
user_id = self.users.get_id(user_name) 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) self.cache_manager.remove_row_from_datacache(cache_name='indicators', filter_vals=identifying_values)
def create_indicator(self, creator: str, name: str, kind: str, def create_indicator(self, creator: str, name: str, kind: str,
@ -592,7 +603,8 @@ class Indicators:
creator_id = self.users.get_id(creator) creator_id = self.users.get_id(creator)
# Check if an indicator with the same name already exists # 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: if not indicators.empty:
print(f"Indicator '{name}' already exists for user '{creator}'. Skipping creation.") print(f"Indicator '{name}' already exists for user '{creator}'. Skipping creation.")