def create_db(args): """Creates a database with the data model given by obj:`apps.models.Track` Args: args: Argparse args - should include args.Value, args.Reactions, args.Composure, args.Age, args.ShortPassing, args.Vision, args.LongPassing Returns: None """ RDS = eval(args.RDS) if RDS is True: engine_string = get_connection() else: engine_string = args.enging_string engine = sql.create_engine(engine_string) Base.metadata.create_all(engine) logger.info('database created') session = get_session(engine_string=engine_string) player = Player(Value=args.Value, Reactions=args.Reactions, Composure=args.Composure, Age=args.Age, ShortPassing=args.ShortPassing, Vision=args.Vision, LongPassing=args.LongPassing) session.add(player) session.commit() logger.info( "Database created with player info added, Value: %s, Reactions: %s, Composure: %s, Age: %s, ShortPassing: %s, Vision: %s, LongPassing: %s,", args.Value, args.Reactions, args.Composure, args.Age, args.ShortPassing, args.Vision, args.LongPassing) session.close()
def add_movie(args): """Seeds an existing database with additional movies. Args: args: Argparse args - should include args.movie, args.rating Returns:None """ if args.engine_string == "false": conn_type = "mysql+pymysql" user = os.environ.get("MYSQL_USER") password = os.environ.get("MYSQL_PASSWORD") host = os.environ.get("MYSQL_HOST") port = os.environ.get("MYSQL_PORT") engine_string = "{}://{}:{}@{}:{}/{}".format(conn_type, user, password, host, port, DATABASE_NAME) else: engine_string = create_connection(engine_string=args.engine_string) session = get_session(engine_string=engine_string) userinput = UserInput(movie=args.movie, rating=args.rating) session.add(userinput) session.commit() logger.info("%s rated %s add to database.", args.movie, args.rating)
def create_db(args): """Creates a database with the data model given by obj:`apps.models.UserInput` Args: args: Argparse args - should include args.movie, args.rating Returns: None """ if args.engine_string == "false": conn_type = "mysql+pymysql" user = os.environ.get("MYSQL_USER") password = os.environ.get("MYSQL_PASSWORD") host = os.environ.get("MYSQL_HOST") port = os.environ.get("MYSQL_PORT") engine_string = "{}://{}:{}@{}:{}/{}".format(conn_type, user, password, host, port, DATABASE_NAME) engine = create_connection(engine_string=engine_string) else: engine = create_connection(engine_string=args.engine_string) Base.metadata.create_all(engine) session = get_session(engine=engine) userinput = UserInput(movie=args.movie, rating=args.rating) session.add(userinput) session.commit() logger.info("Database created with input added: %s rated %s", args.movie, args.rating) session.close()
def add_soccer(args): """Seeds an existing database with additional players. Args: args: Argparse args - should include args.Value, args.Reactions, args.Composure, args.Age, args.ShortPassing, args.Vision, args.LongPassing Returns:None """ RDS = eval(args.RDS) if RDS is True: engine_string = get_connection() else: engine_string = args.enging_string session = get_session(engine_string=engine_string) Value = int(args.Value) Reactions = int(args.Reactions) Composure = int(args.Composure) Age = int(args.Age) ShortPassing = int(args.ShortPassing) Vision = int(args.Vision) LongPassing = int(args.LongPassing) #Output = args.Output with open('models/model.pkl', "rb") as f: model = pickle.load(f) X = pd.DataFrame({ 'Reactions': [Reactions], 'Composure': [Composure], 'Vision': [Vision], 'ShortPassing': [ShortPassing], 'LongPassing': [LongPassing], 'Value': [Value], 'Age': [Age] }) #print(X) Class = model.predict(X) if Class == 0: Output = 'Bad' else: Output = 'Good' #print(Class) player = Player(Value=args.Value, Reactions=args.Reactions, Composure=args.Composure, Age=args.Age, ShortPassing=args.ShortPassing, Vision=args.Vision, LongPassing=args.LongPassing, Output=Output) session.add(player) session.commit() logger.info( "player added with info: Value: %s, Reactions: %s, Composure: %s, Age: %s, ShortPassing: %s, Vision: %s, LongPassing: %s, Output: %s", args.Value, args.Reactions, args.Composure, args.Age, args.ShortPassing, args.Vision, args.LongPassing, Output) session.close()
def create_ARIMA_Params(engine, df): """ Stores ARIMA_Params in the database :param engine: DB engine :param df: Dataframe containing ARIMA parameters :return: None """ try: session = get_session(engine) old_ARIMA_Params = session.query(ARIMA_Params.CURRENCY, ARIMA_Params.P, ARIMA_Params.D, ARIMA_Params.Q) old_ARIMA_Params.delete() session.bulk_insert_mappings(ARIMA_Params, df.to_dict(orient="records")) session.commit() except Exception as e: logger.error(e) sys.exit(1) finally: session.close() return
def create_Predictions(engine, df): """ Stores Predictions in the database :param engine: DB engine :param df: Dataframe containing ARIMA parameters :return: None """ try: session = get_session(engine) old_Predictions = session.query(Predictions.CURRENCY, Predictions.PRED_DATE, Predictions.PRED_RATE) old_Predictions.delete() session.bulk_insert_mappings(Predictions, df.to_dict(orient="records")) session.commit() logger.info("Predictions stored in the database") except Exception as e: logger.error(e) sys.exit(1) finally: session.close() return