def post(self, id): args = self.reqparse.parse_args() text = args["text"] # getting sentiment analysis from google nlp api annotations = get_sentiment(text) sentiment = annotations.document_sentiment.score # getting emotion from deepaffects text api emotion = list(json.loads(get_emotion(text).text)["response"].keys())[0] ketchup = CheckIn(id, text, sentiment, emotion) self.add_checkin_to_db(ketchup) most_common, average, slope, r2 = self.get_data(id) return jsonify({"emotion": emotion, "sentiment": sentiment, "most_freq_emotion": most_common, "average_sentiment": average, "slope": slope, "r2": r2})
def checkin_new(): checkin = CheckIn() if request.method == 'POST': form = CheckInForm(request.form, obj=checkin) if form.validate(): try: form.populate_obj(checkin) validate_check_in_creation(checkin) checkin.save() flash('Yes, check in feito com sucesso.', 'success') return redirect(url_for('checkins.checkin_index')) except AttributeError as e: flash(str(e), 'warning') else: form = CheckInForm(obj=checkin) return render_template('checkins/new.html', form=form)
def check_in(MealId): try: meal = session.query(Meal).filter(Meal.MealId == MealId).first() canCheckInBool = session.query(CheckIn).filter( CheckIn.MealId == MealId, CheckIn.Email == current_user.Email).first() is not None # Check if Member is in the time frame to check-in for a meal if can_check_in(meal, canCheckInBool) and has_swipes(): checkIn = CheckIn(MealId=MealId, Email=current_user.Email, Timestamp=datetime.datetime.now(), IsLatePlate=False) # Check if user already is checked in if session.query(CheckIn).filter(CheckIn.MealId == checkIn.MealId, CheckIn.Email == checkIn.Email).first() is None: session.add(checkIn) session.commit() meal = session.query(Meal).filter( Meal.MealId == MealId).first() flash("Check In Was a Success!") return render_template('pages/view_checkin.html', meal=meal) else: flash("You were already checked in for that meal." ) # should never get here else: flash( "Cannot check-in for a meal more than 30 minutes before or after. Also, make sure you have swipes left this week." ) return redirect(url_for("get_meal", mealId=MealId)) except Exception as e: flash( "CheckIn for Meal with ID of {} was unsuccessful. Please try again. {}" .format(MealId, e)) return redirect(url_for("get_meal", mealId=MealId))
def late_plate(MealId): try: meal = session.query(Meal).filter(Meal.MealId == MealId).first() # Check if Member has swipes for late plate and MUST request before 5 PM the day before if can_rsvp(meal) and has_swipes(): checkIn = CheckIn(MealId=MealId, Email=current_user.Email, Timestamp=datetime.datetime.now(), IsLatePlate=True) # Check if user already is checked in if session.query(CheckIn).filter(CheckIn.MealId == checkIn.MealId, CheckIn.Email == checkIn.Email).first() is None: session.add(checkIn) session.commit() meal = session.query(Meal).filter( Meal.MealId == MealId).first() flash("Late Plate Was a Success!") return redirect(url_for("get_meal", mealId=MealId)) else: flash("You were already checked in for that meal." ) # should never get here else: flash( "Cannot request a Late Plate after 5PM the day before. Also, make sure you have swipes left this week." ) return redirect(url_for("get_meal", mealId=MealId)) except Exception as e: flash( "Late Plate for Meal with ID of {} was unsuccessful. Please try again. {}" .format(MealId, e)) return redirect(url_for("get_meal", mealId=MealId))
def test_invalid_check_in(self): checkin = CheckIn(check_out_time=date(2020, 9, 5)) with self.assertRaises(AttributeError): validate_check_in_creation(checkin)