def show_tweets(): tweet_records = Tweet.query.all() user_records = User.query.all() print(tweet_records) parsed_tweets = parse_records(tweet_records) parsed_users = parse_records(user_records) # return jsonify(parsed_tweets) return render_template("tweets.html", message="List of All Tweets", tweets=parsed_tweets, users=parsed_users)
def get_text_search(): """Function/Endpoint takes the parameters send in a post request and passes them to a model to return the matching strains based on the arguments that were passed by the user. Arguments: ----------- None impicit arguments text {str} : a String that the user send from an imput feild that is passed to a model that tried to recommend strains based on their description. Returns: ---------- data {jsonb} : the entries in the databse that match the resulting predicted strains """ text = request.form['text'] #init the model m = modelone(PICKLE_DIR + 'nn_isaac.pickle', PICKLE_DIR + 'tfidf_isaac.pickle') # make predictions based on the passed string m.transform_predict([text]) pred = m.getResults()[0] print(pred) data = Strains.query.filter(Strains.index.in_([int(x) for x in pred])).all() return jsonify(parse_records(data))
def get_search(): """Function/Endpoint takes the parameters send in a post request and passes them to a model to return the matching strains based on the arguments that were passed by the user. Arguments: ----------- None impicit arguments flavors {str} : the string of comma seperated flavors that is passed to the POST request from an input form effects {str} : a string of comma seperated values that passed with the POST request from an input form Returns: ---------- data {jsonb} : the entries in the databse that match the resulting predicted strains """ flavors = request.form['flavors'] effects = request.form['effects'] #init the model m = modelone(PICKLE_DIR + 'nn_mark.pickle', PICKLE_DIR + 'tfidf_mark.pickle') # make predictions based on the passed string m.transform_predict([effects + flavors]) pred = m.getResults()[0] print(pred) data = Strains.query.filter(Strains.index.in_([int(x) for x in pred])).all() return jsonify(parse_records(data))
def list_books(): # books = [ # {"id": 1, "title": "Book 1"}, # {"id": 2, "title": "Book 2"}, # {"id": 3, "title": "Book 3"}, # ] book_records = Book.query.all() print(book_records) books = parse_records(book_records) return jsonify(books)
def list_books_for_humans(): # books = [ # {"id": 1, "title": "Book 1"}, # {"id": 2, "title": "Book 2"}, # {"id": 3, "title": "Book 3"}, # ] book_records = Book.query.all() print(book_records) books = parse_records(book_records) return render_template("books.html", message="Here's a list of All Books", books=books)
def return_all(): db_comments = Comment.query.all() comments_response = parse_records(db_comments) json_comments = jsonify(comments_response) return json_comments #return render_template("users.html", users=db_comments.user, # text=db_comments.text, sentiment=db_comments.sentiment) #json_ids = jsonify(db_comment.id) #json_users = jsonify(db_comment.user) #json_text = jsonify(db_comment.text) #json_sentiment = jsonify(db_comment.sentiment) # @stat_routes.route('/stats/comments/ids') # def return_ids(): # db_comments = Comment.query.all() # comments_response = parse_records(db_comments) # db_ids = comments_response['user'] # json_ids = jsonify(db_ids) # return json_ids # @stat_routes.route('/stats/comments/users') # def return_users(): # db_comments = Comment.query.all() # db_users = db_comments.user # comments_response = parse_records(db_users) # json_users = jsonify(comments_response) # return json_users # @stat_routes.route('/stats/comments/text') # def return_text(): # db_comments = Comment.query.all() # db_text = db_comments.text # comments_response = parse_records(db_text) # json_text = jsonify(comments_response) # return json_text # @stat_routes.route('/stats/comments/sentiment') # def return_sentiment(): # db_comments = Comment.query.all() # db_sentiment = db_comments.sentiment # comments_response = parse_records(db_sentiment) # json_sentiment = jsonify(comments_response) # return json_sentiment
def get_user_by_name(): if request.method == 'GET': users = parse_records(User.query.all()) return render_template('users_list.html', users=users) # print("FORM DATA:", dict(request.form)) else: user = dict(request.form) # print(user["username"]) user = User.query.filter_by(screen_name=user["username"]).one_or_none() if not user: flash("User not found in database", "danger") return redirect("/list") else: users = [] users.append(user) return render_template('users_list.html', users=users)
def index(): user_records = User.query.all() print(user_records) users = parse_records(user_records) return render_template("prediction_form.html", users=users)
def list_users(): db_users = User.query.all() users_response = parse_records(db_users) return jsonify(users_response)
def cabinet(): db_cabinet = Cabinet.query.all() cabinet_response = parse_records(db_cabinet) return jsonify(cabinet_response)
def recommender(): """ creates list with top n recommended strains. Paramaters __________ request: dictionary (json object) list of user's desired effects listed in order of user ranking. { "effects":[], "negatives":[], "ailments":[] } n: int, optional number of recommendations to return, default 10. Returns _______ list_strains: python list of n recommended strains. """ desired_dict = request.json n = 10 effects, negatives, ailments = (desired_dict.get("effects"), desired_dict.get("negatives"), desired_dict.get("ailments")) effects = [effect.lower() for effect in effects] negatives = [negative.lower() for negative in negatives] ailments = [ailment.lower() for ailment in ailments] for index, effect in enumerate(effects): if effect in columns: effects[index] = columns.index(effect) for index, negative in enumerate(negatives): if negative in columns: negatives[index] = columns.index(negative) for index, ailment in enumerate(ailments): if ailment in columns: ailments[index] = columns.index(ailment) vector = [0 for _ in range(len(columns))] weight = 100 for index in effects: if isinstance(index, int): vector[index] = weight weight *= .8 weight = int(weight) weight = 100 for index in negatives: if isinstance(index, int): vector[index] = weight weight *= .8 weight = int(weight) weight = 100 for index in ailments: if isinstance(index, int): vector[index] = weight weight *= .8 weight = int(weight) data = numpy.array(vector) request_series = pd.Series(data, index=columns) distance, neighbors = nn.kneighbors([request_series]) list_strains = [] for points in neighbors: for index in points: list_strains.append(index) result = [{"id": str(val)} for val in list_strains[:n]] return_list = [str(val) for val in list_strains[:n]] records = parse_records( Cabinet.query.filter(Cabinet.model_id.in_(return_list)).all()) return jsonify(records)
def get_cards(): """Function/endpoint returns all of the entries in the database """ db_strains = Strains.query.all() response = parse_records(db_strains) return jsonify(response)