Exemple #1
0
def receive_feedback():
    """
        Add user input from Feedback page to database
    """
    if request.method == 'POST':
        data = request.get_json(silent=False)

        category = data['selected_category']
        feedback = data['user_feedback']
        rating = data['user_rating']

        if (feedback != '' or rating != 0):
            feedback_ = Feedback(category=category,
                                 feedback=feedback,
                                 rating=rating)
            db.session.add(feedback_)

            # keep track of ratings from all users
            if (rating != 0):
                rating_ = Ratings(rating=rating)
                db.session.add(rating_)

            db.session.commit()
        return 'OK', 200

    return redirect('/')
Exemple #2
0
def review(ID):
    form = ReviewForm()
    if form.validate_on_submit():
        review = Ratings(User_id=current_user.id,
                         Score_given=form.score.data,
                         Film_id=ID)
        db.session.add(review)
        db.session.commit()
        f = open('ratings.csv', 'w')
        out = csv.writer(f)
        out.writerow(['User_id', 'Film_id', 'Score_given'])
        for item in Ratings.query.all():
            out.writerow([item.User_id, item.Film_id, item.Score_given])
        f.close()
        flash('Review DB updated - Thanks for your review!')
        return redirect(url_for('index'))
    return render_template('review.html', title='Review Page', form=form)
Exemple #3
0
def apply_review(form, storyid):

    srcip = request.headers.get('X-Forwarded-For') if request.headers.get(
        'X-Forwarded-For') else request.remote_addr
    new_rating = Ratings(
        nickname=bleach.clean(form.nickname.data, tags=[], strip=True),
        source_ip=srcip,
        overall=int(form.overall_rating.data),
        be_ctnt=int(form.be_rating.data),
        chars_ctnt=int(form.chars_rating.data),
        technical=int(form.technical_rating.data),
        comments=markdown.markdown(bleach.clean(form.comments.data,
                                                strip=True)),
        story=storyid,
    )
    db.session.add(new_rating)
    db.session.commit()
Exemple #4
0
def set_rating(sid, new_rating=None):

    if new_rating:
        uid, ip = get_identifier()
        print("Set-rating call for sid %s, uid %s, ip %s. Rating: %s" %
              (sid, uid, ip, new_rating))
        user_rtng = Ratings.query \
         .filter(Ratings.series_id == sid) \
         .filter(Ratings.user_id   == uid) \
         .filter(Ratings.source_ip == ip ) \
         .scalar()

        if user_rtng:
            user_rtng.rating = new_rating
        else:
            new_row = Ratings(
                rating=new_rating,
                series_id=sid,
                user_id=uid,
                source_ip=ip,
            )
            db.session.add(new_row)

        db.session.commit()

    # Now update the series row.
    s_ratings = Ratings.query \
     .filter(Ratings.series_id == sid) \
     .all()

    if s_ratings:
        ratings = [tmp.rating for tmp in s_ratings]
        newval = sum(ratings) / len(ratings)
        rcnt = len(ratings)
    else:
        newval = None
        rcnt = None

    Series.query \
     .filter(Series.id == sid) \
     .update({'rating' : newval, 'rating_count' : rcnt})

    db.session.commit()
Exemple #5
0
def set_rating(sid, new_rating):
    uid, ip = get_identifier()
    print("Set-rating call for sid %s, uid %s, ip %s. Rating: %s" %
          (sid, uid, ip, new_rating))
    user_rtng = Ratings.query \
     .filter(Ratings.series_id == sid) \
     .filter(Ratings.user_id   == uid) \
     .filter(Ratings.source_ip == ip ) \
     .scalar()

    if user_rtng:
        user_rtng.rating = new_rating
    else:
        new_row = Ratings(
            rating=new_rating,
            series_id=sid,
            user_id=uid,
            source_ip=ip,
        )
        db.session.add(new_row)

    db.session.commit()
Exemple #6
0
def update_rating_score(prod_rating):
    """
	Function to update the Rating Score for each product in the input dictionary.
	Input - Dict containing product public key and rating score string.
	"""
    for public_key, rating in prod_rating.items():
        with app.app_context():
            prod = Products.query.filter(
                Products.public_key == public_key).first()
            count = Ratings.query.filter(Ratings.product_id == prod.id).count()
            if count > 0:
                # Updating
                app.logger.info(
                    f"Updating to rating score of prod {prod.name}")
                rt = Ratings.query.filter(
                    Ratings.product_id == prod.id).first()
                rt.rating_score = rating
            else:
                # Inserting
                rt = Ratings(product_id=prod.id, rating_score=rating)
                db.session.add(rt)
                app.logger.info("Inserting new rating score")
            db.session.commit()
Exemple #7
0
try:
    teams_data = pd.read_csv("static/test_teams.csv")
    for index, row in teams_data.iterrows():
        team = Team()
        team.team_id = int(row["team_id"])
        team.team_name = row["team_name"].decode('utf-8')
        team.series_id = int(row["series_id"])
        team.series_name = row["series_name"]
        db.session.add(team)
        db.session.commit()
except Exception as e:
    log.error("Update ViewMenu error: {0}".format(str(e)))
    db.session.rollback()

try:
    teams_data = pd.read_csv("static/test_ratings.csv")
    for index, row in teams_data.iterrows():
        team = Ratings()
        team.team_id = int(row["team_id"])
        team.match_date = datetime.strptime(row["match_date"],
                                            '%Y-%m-%d %H:%M:%S').date()
        team.midfield_rating = int(row["midfield_rating"])
        team.defence_rating = int(row["defence_rating"])
        team.attack_rating = int(row["attack_rating"])
        db.session.add(team)
        db.session.commit()
except Exception as e:
    log.error("Update ViewMenu error: {0}".format(str(e)))
    db.session.rollback()
Exemple #8
0
 def get_avg_rating(self):
     try:
         self.avg_rating = Ratings.average(self.movie_id)
         Ratings.close_session()
     except QueryException as e:
         self.avg_rating = None