def insult(): adjective1 = choice(phrase1) adjective2 = choice(phrase2) noun1 = choice(phrase3) cp("thou art a " + adjective1 + adjective2 + noun1 + "!", "cyan", attrs=["bold"]) return "you have been insulted!"
def usernamename(): wantname = input("view username [y/n]: ") if wantname.lower() == "y": cp("Your username: "******"cyan", attrs=["bold"]) elif wantname.lower() == "yes": cp("Your username: "******"cyan", attrs=["bold"]) elif wantname.lower() == "n": return "USERNAME VIEWER CANCELED!" elif wantname.lower() == "no": return "USERNAME VIEWER CANCELED!" return "Command Complete"
def sessionname(): wantname = input("view session name [y/n]: ") if wantname.lower() == "y": cp("Your session name: " + session, "cyan", attrs=["bold"]) elif wantname.lower() == "yes": cp("Your session name: " + session, "cyan", attrs=["bold"]) elif wantname.lower() == "n": return "SESSION VIEWER CANCELED!" elif wantname.lower() == "no": return "SESSION VIEWER CANCELED!" return "Command Complete"
def _min_max_scaling(train, test): """ using MinMax function for scaling array in range(-1,1) saving scaler in order to reuse it for precdictions param:: train:numpy.array, test:numpy.array return:: train_scaled:numpy.array, test_scaled:numpy.array s""" scaler = MinMaxScaler(feature_range=(-1, 1)) scaler = scaler.fit(train) # reshaping the array so they fit in the scaler train = train.reshape(train.shape[0], train.shape[1]) test = test.reshape(test.shape[0], test.shape[1]) train_scaled = scaler.transform(train) print(f'Scaler: {test.shape}') test_scaled = scaler.transform(test) # svaing the scaler try: save_data_to_(file_name='min-max-scaler.save', folder_name='saved_model_data', data=scaler, is_model=False) except Exception as save_error: print( cp( f'log[error]:Failed to save data for \'min-max-scaler.save\'. See log file', 'red')) logging.error('Failed to save data for', exc_info=True) return train_scaled, test_scaled
def add_color(): cp("pybot: ", "magenta", end="") if color == attrs == "": print(bot_response) elif color == "": cp(bot_response, "white", attrs=[attrs]) elif attrs == "": cp(bot_response, color) else: cp(bot_response, color, attrs=[attrs])
def _get_key_value_config(key, config): """ function returning the value of passed key param:: key:string return:: value:string """ try: return config['lstm-script'][key] except KeyError as key_error: print( cp(f'log[error]:Key not in config dictornay. See log file', 'red')) logging.error('Key not in config dictorna', exc_info=True)
def _load_config_json(): """ loading the config file in order to get target, feature, date, and groupby value assigns the constant CONFIG the json as dict{} """ try: with open(CONFIG_PATH, 'r') as conf: config = json.load(conf) return config except Exception as json_error: print( cp( f'log[error]:unable to load preprocessing.config.json file. See log file', 'red')) logging.error('unable to load preprocessing.config.json file', exc_info=True)
def stupid(): while True: stupid_bot_response = choice(stupidanswer) if color == attrs == "": print(stupid_bot_response) elif color == "": cp(stupid_bot_response, "white", attrs=[attrs]) elif attrs == "": cp(stupid_bot_response, color) else: cp(stupid_bot_response, color, attrs=[attrs]) stupidprompt = input(cd(loginuser + ": ", "yellow")) # so they get a prompt if stupidprompt.lower() == "!exitstupid": return "EXITING STUPID MODE!"
def fake(): while True: fake_bot_response = choice(fakeanswer) if color == attrs == "": print(fake_bot_response) elif color == "": cp(fake_bot_response, "white", attrs=[attrs]) elif attrs == "": cp(fake_bot_response, color) else: cp(fake_bot_response, color, attrs=[attrs]) fakeprompt = input(cd(loginuser + ": ", "yellow")) # so they get a prompt if fakeprompt.lower() == "!exitfake": return "EXITING FAKE MODE!"
def save_data_to_(file_name, folder_name, data, is_model): """ function to save model and scaler. Needed to change the current directory The is_model defindes which saver to use. for scaler and model two different needed param:: file_name:string, folder_name:string, data:obj, is_model:boolean return:: - raise: Execption """ try: os.chdir('infrastructure/ml-models/'.join(folder_name)) if is_model: data.save(file_name) else: joblib.dump(data, file_name) except Exception as saving_error: print( cp(f'log[error]:Failed to save data for {file_name}. See log file', 'red')) logging.error('Failed to save data for', exc_info=True) finally: os.path.dirname(os.path.abspath(__file__))
def prize(): global prize_given if prize_given: cp("YOU ALREADY UNBOXED A PRIZE!", "magenta") else: prize_response = choice(prizeunbox) cp(prize_response, "cyan") cp("PRIZE UNBOXED!", "magenta") prize_given = True return "Command Complete"
"haya", "timchen", "lmntl dj", "jimmymcjimface", "jbrown", ] staffpassword = [ "7ebf013ae25747d5f9646b5380adf0d1add777f912ebd88f64cd2ca95faeddb81c33107a7e1231a754f40bdc0289135d11cbb17573d2f2724afb1692ac15adb5" ] semistaffpassword = [ "0913de549bbebb374c0a55eb695a0e6cc556c7db15b2d5c759c7abb06320e6eb3addd75052b9a0d65a43ccf6658e69e28dd60964c36f5e42caa7508744e7b858" ] cp(ff("""PyBot\n v0.9.4""", font="starwars"), "yellow", attrs=["bold"]) print("\n" * 10) nickname = input("What Should I Call You: ") clear() cp(ff("PyBot\n v0.9.4", font="starwars"), "yellow", attrs=["bold"]) print("\n" * 10) lang = input("what's your spoken language: ") if lang.lower() == "": lang = "english"
def start_processor(): """ this is the main function with orchastrats the programm first the data (csv) will be load - as well as the config file. The data frame will be reduced to the data needed. next the differences of sales and prev-sales are computed followed by the creation of lags needed for the LSTM model as last step the LSTM model will be saved (both architecture and weights) in a .h5 file for later usage. In addition the fitted MinMaxScaler will be saved so it can be imported with the model.h5 for making proper predictions param:: - return:: - """ __init_logging() # fetch config file, extract values config = _load_config_json() df_path = _get_key_value_config('dataFrame-path', config) print(df_path) date_col = _get_key_value_config('date-col', config) target_col = _get_key_value_config('target-col', config) #loading data frame data = pd.read_csv(df_path, encoding='ISO-8859-1', sep=",") data = data.rename(columns={date_col: 'date', target_col: 'sales'}) date_col = 'date' target_col = 'sales' # data frame with Sales and Date only print(data.head()) df_lstm = data.loc[:, (date_col, target_col)].copy() # convert date field to pandas.Datetime obj and group by month df_lstm[date_col] = pd.to_datetime(df_lstm[date_col]) df_lstm[date_col] = df_lstm[date_col].dt.year.astype( 'str') + '-' + df_lstm[date_col].dt.month.astype('str') + '-01' df_lstm[date_col] = pd.to_datetime(df_lstm[date_col]) df_lstm = df_lstm.groupby(date_col).sales.sum().reset_index() ############################################################# # comupting the difference between sales and prev sales. Adding the lags to the data frame df_diff = df_lstm.copy() df_diff['prev_sales'] = df_diff['sales'].shift(1) df_diff = df_diff.dropna() df_diff['difference'] = _compute_diff_of_sales(df_diff['sales'], df_diff['prev_sales']) df_supervised = df_diff.drop(['prev_sales'], axis=1).copy() df_supervised = _create_lags_for_supervised(df_supervised, 12) df_features = df_supervised.drop(['sales', 'date'], axis=1) ############################################################# # split data frame in train test sets and scale both arrays train_set, test_set = df_features[0:-6].values, df_features[-6:].values train_scaled, test_scaled = _min_max_scaling(train_set, test_set) ############################################################# # creating feature and target variables. Model creation / fiting and saving X_train, y_train = train_scaled[:, 1:], train_scaled[:, 0:1] X_train = X_train.reshape(X_train.shape[0], 1, X_train.shape[1]) X_test, y_test = test_scaled[:, 1:], test_scaled[:, 0:1] X_test = X_test.reshape(X_test.shape[0], 1, X_test.shape[1]) lstm_model = _create_LSTM_model(X_train, y_train) try: save_data_to_(file_name='lstm-model.h5', folder_name='saved_model_data', data=lstm_model, is_model=True) except Exception as save_error: print( cp( f'log[error]:Failed to save data for \'lstm-model.h5\'. See log file', 'red')) logging.error('Failed to save data for', exc_info=True)
def log(mode="None",out="",noLog=False,file=fnameSet): try: from termcolor import colored as col from termcolor import cprint as cp import colorama except ImportError: print("\nMissing dependancy\n") raise missingContent from datetime import datetime colorama.init() type="" if out == "":#User used the function incorrectly raise incorrectUsage#User did an oof if mode == "None": raise incorrectUsage elif mode == 'e': type = "ERROR" if out != "": cp("{}".format(type),"white",'on_red',attrs=['bold'],end=""); print(": {}".format(out)) # this shows up in the interactive prompt elif mode == 'w': type = "Warning" if out != "": cp("{}".format(type),"yellow",attrs=['bold'],end=""); print(": {}".format(out)) # this shows up in the interactive prompt elif mode == 'n': type = "Notice" if out != "": print("{}: {}".format(type,out)) # this shows up in the interactive prompt elif mode == 'i': type = "Info" if out != "": cp("{}".format(type),"blue",attrs=['bold'],end=""); print(": {}".format(out)) # this shows up in the interactive prompt elif mode == 's': type = "SUCCESS" if out != "": print("{}: {}".format(col(type,"green",attrs=['bold']),out)) # this shows up in the interactive prompt elif mode == 'z': type = "SPAM" if noLog == True: raise incorrectUsage if noLog == False: try: f = open(file, 'a') #prints now go the the file f.write("\n{} - {}: {}".format(str(datetime.now().strftime('%Y-%m-%d %H:%M:%S')),type,out)) # nothing appears. it's written to log file instead f.close except FileNotFoundError: cp("consoleTools ERROR ","white",'on_red',attrs=['bold'],end=""); cp("Issue writing to log file - does not exist. Are you running from an IDE? (doesn't always work in an IDE)","red",'on_white',attrs=['bold'],end="\n") cp("Try specifying a log file when using the log tool if you are not running the script from the same directory as it is located.","red",'on_white',attrs=['bold'],end="\n") except FileExistsError: cp("consoleTools ERROR ","white",'on_red',attrs=['bold','blink'],end=""); cp("Issue writing to log file - file exists. Is the file open in the background/by another process (won't be able to write if so)","red",'on_white',attrs=['bold'],end="\n")