def get_recommendations(username): user_data = dbTesting.get_user_stocks_raw(username) # generate training and test data training_data = generate_training() test_data = generate_test(user_data) dt = build_tree(training_data) # perform recommendations recommendations = [] for i, row in enumerate(test_data): result = predict(row, dt) if result != 'do nothing': symbol = STOCK_SYMBOLS[i] stock_name = stock_info.getStockCompany(symbol) recommendation = [symbol, stock_name, result] recommendations.append(recommendation) return recommendations
def get_user_stocks(username): column = 1 shares = Shares.objects.filter(username=username).values_list() shares_array = shares[::1] user_stocks = [] for i in shares_array: for j in i: if column > 3 and j != 0: user_stocks.append([ stocks[column - 4], stock_info.getStockCompany(stocks[column - 4]), str(j), str(stock_info.getStockPrice(stocks[column - 4])) ]) column += 1 column = 0 return user_stocks
def create_all_stocks(): for x in stocks: create_stock(x, stock_info.getStockCompany(x), stock_info.getStockPrice(x), stock_info.getStockPercentChange(x), stock_info.getStockVWAP(x))