DavidPeleg6 / Financial_News_Sentiments

extracts financial sentiments about stocks from the news sources
1 stars 0 forks source link

time is never added #23

Closed DavidPeleg6 closed 1 year ago

DavidPeleg6 commented 1 year ago

this line throws an exception (probably went unnoticed because it was only a print there): if "time" not in kwargs: raise Exception(f"Invalid use of the cache_dec decorator. {func} must have a time variable")

in dataloader.py

AvihaiDidi commented 1 year ago

what what is this referring to @DavidPeleg6

DavidPeleg6 commented 1 year ago

def cache_dec(filename: str):

this decorator MUST be used alongside @st.cache_data. this one should come first

# the function which is decorated should have a 'time' variable, preferabbly with a default value of 'None'.
def decorator(func):
    def wrapper(*args, **kwargs):
        if "time" not in kwargs:
            raise Exception(f"Invalid use of the cache_dec decorator. {func} must have a time variable")
        cachedata_fname = filename
        if "predgoal" in kwargs:
            cachedata_fname = cachedata_fname + "_" + kwargs["predgoal"]
        time = _checkIfCacheUpdate(cachedata_fname)
        result = func(*args, time = time, **kwargs)
        return result
    return wrapper
return decorator

Here, if time is added as one of the kwargs - we get an exception because theres double definition of time (when we call the result= ... line) if we dont add it, we get an exception for invalid use. in the meantime, I used st.cache_data(ttl=606024) as the caching mechanism

AvihaiDidi commented 1 year ago

ye I think just using the built in cache instead of my nonesense decorator is for the better