def enroll(): db = DBConnection() success, dbId = db.addUserCredentials() if success != True: return False, None dbUsername, dbPassword = db.getUserCredentials(dbId) print('Starting the Enrollment process') counter = 0 while counter < 2: print('Sample => {}'.format(counter + 1)) username = input('Enter username:\n').strip() if username != dbUsername: print('Removed the sample as username did not match') continue print('Enter password:') user = linuxGetTimelog.User(dbId, dbUsername, dbPassword) success, date = user.startLogging() if success == True: extractFeatures(dbId, date) addToCSV(dbId, date) counter += 1 sys.stdout.flush(); tcflush(sys.stdin, TCIOFLUSH) db.closeConnection() global userId userId = dbId print("Enrollment Process over") return True, userId
def testModel(userId): print('Let us test the created model') db = DBConnection() dbUsername, dbPassword = db.getUserCredentials(userId) username = input('Enter username:\n').strip() if username != dbUsername: print('Removed the sample as username did not match') return print('Enter password:'******'data/user_input/{}/userData.csv'.format(userId), header=0).tail(1) X = userData[[ 'release_codes', 'pp', 'pr', 'rp', 'rr', 'ppavg', 'pravg', 'rpavg', 'rravg', 'total' ]] X = get_hashed_matrix(X) names = [ "Isolation Forest Ensemble", ] classifiers = [ IsolationForest(random_state=np.random.RandomState(42)), ] for name, clf in zip(names, classifiers): # print("\nLoading classifier : {}".format(name)) clf = joblib.load('data/user_input/{}/userModel-{}.pkl'.format( userId, name)) result = clf.predict(X) if result[0] == 1: print('Welcome') else: print('Stay away impostor!') # testModel(114)