def setUp(self): ContextTestCase.setUp(self) context = AppContext.get_context() context.register_singleton_component(DataProcessorService()) context.register_singleton_component(ARIMAPredictionService()) self.configuration.load("../test/cfg/test.json") self.category_id = "BER" self.show_plots = True
def wrapper(*args, **kwargs): from app import AppContext ctx = AppContext.get_context() logger = ctx.match_component_by_type(logging.Logger) func_name = args[0].__class__.__name__ + "." + func.__name__ module_name = args[0].__class__.__module__.strip("__") module_info = {"module": module_name} logger.info(func_name + " started", module_info) result = func(*args, **kwargs) logger.info(func_name + " completed", module_info) return result
def setUp(self): ContextTestCase.setUp(self) context = AppContext.get_context() context.register_singleton_component(DataProcessorService()) context.register_singleton_component(SupervisedPredictionService()) self.configuration.load("../test/cfg/test.json") self.category_id = "VIE" data_file_name = self.configuration.get().get("data_files").get( "data_file_cat_name").replace("{metric}", "INCOME_NETTO").replace( "{cat}", self.category_id) ts_field = self.configuration.get().get("model").get("ts_field") self.df = pd.read_csv(data_file_name, self.configuration.CSV_DELIMITER) self.df.index = pd.to_datetime(self.df[ts_field], format="%Y-%m-%d") self.df = self.df.drop([ts_field], axis=1).sort_index() self.show_plots = True
def wrapper(*args, **kwargs): if func.__annotations__ is None: return func(args, kwargs) from app import AppContext ctx = AppContext.get_context() for (arg_key, arg_type) in func.__annotations__.items(): instance_required = arg_key not in kwargs if instance_required and arg_key != 'return': while inspect.isfunction(arg_type): arg_type = arg_type.__annotations__['return'] kwargs[arg_key] = ctx.match_component_by_type(arg_type) return func(*args, **kwargs) return_type = func.__annotations__['return'] while inspect.isfunction(return_type): return_type = return_type.__annotations__['return'] return ctx.match_component_by_type(return_type)
default=False, action="store_true", help="invert reaction") parser.add_argument("-s", "--stock", help="stock to analize") parser.add_argument("-d", "--date", type=valid_date, help="run analysis with a given date as a start date") parser.add_argument("-i", "--interval", type=int, default=1, help="run analysis for a given interval from a date") args = parser.parse_args() APP = AppContext() date = args.date if args.date is not None else datetime.today() stocks = APP.load_stocks(args.stock) bets = [] with concurrent.futures.ThreadPoolExecutor(max_workers=5) as executor: future_to_signals = { executor.submit(APP.analyze_timeframe, stock, args.period, args.function, args.threshold, date, args.interval, args.frame, args.invert): stock.symbol for stock in stocks } for future in concurrent.futures.as_completed(future_to_signals): bets += future.result()
def __init__(self, args): self.__args = args # AppConfig.execute() AppContext.initialize_context(__file__)
def setUp(self): context = AppContext.get_context() context.register_singleton_component(Configuration()) context.register_singleton_component(log.Logger().logger)
from app import AppContext import concurrent.futures from stocks.symbols import US_SYMBOLS from botocore.errorfactory import ClientError app = AppContext() def check_not_exists(symbol): try: content = app.s3.get(f"tickers/{symbol}/5m/2019-07-24.csv") return None if '.' in content else symbol except ClientError: return symbol missing = [] counter = 0 with concurrent.futures.ThreadPoolExecutor(max_workers=5) as executor: futures = [ executor.submit(check_not_exists, symbol) for symbol in US_SYMBOLS ] for future in concurrent.futures.as_completed(futures): counter += 1 print(counter) res = future.result() if res: missing.append(res) print(",".join(missing)) print(len(missing))
import argparse from app import AppContext from stocks.models import Ticker parser = argparse.ArgumentParser() parser.add_argument("-s", "--stocks") parser.add_argument("-l", "--limit", type=int, default=100) parser.add_argument("-t", "--type", default=Ticker.Type.ONE_MIN, choices=Ticker.TYPES) parser.add_argument("-p", "--period", type=int, default=1) args = parser.parse_args() # always load all data for 1d intervals period = 'max' if args.type == Ticker.Type.ONE_DAY else args.period # split stocks before updating stocks = args.stocks.split() if args.stocks else [] AppContext().update(stocks, args.type, period, args.limit)
import argparse from app import AppContext parser = argparse.ArgumentParser() parser.add_argument("-u", "--update", default=False, action="store_true", help="update tweets") parser.add_argument("-t", "--terms", default=False, action="store_true") parser.add_argument("-d", "--date") args = parser.parse_args() if args.update: AppContext().twitter_update() if args.terms: print(AppContext().extterms(args.date))