Beispiel #1
0
 def __insert_data(postid, userid, rating):
     uid = tools.get_uuid()
     TabRating.create(
         uid=uid,
         post_id=postid,
         user_id=userid,
         rating=rating,
         timestamp=tools.timestamp(),
     )
     return uid
Beispiel #2
0
    def delete(uid):
        '''
        Delete by uid
        :param uid:
        :return:
        '''

        q_u1 = TabPostHist.delete().where(TabPostHist.post_id == uid)
        q_u1.execute()
        q_u2 = TabRel.delete().where(TabRel.post_f_id == uid
                                     or TabRel.post_t_id == uid)
        q_u2.execute()
        q_u3 = TabCollect.delete().where(TabCollect.post_id == uid)
        q_u3.execute()
        q_u4 = TabPost2Tag.delete().where(TabPost2Tag.post_id == uid)
        q_u4.execute()
        q_u5 = TabUsage.delete().where(TabUsage.post_id == uid)
        q_u5.execute()

        reply_arr = []
        for reply in TabUser2Reply.select().where(
                TabUser2Reply.reply_id == uid):
            reply_arr.append(reply.reply_id.uid)

        q_u6 = TabUser2Reply.delete().where(TabUser2Reply.reply_id == uid)
        q_u6.execute()

        for replyid in reply_arr:
            TabReply.delete().where(TabReply.uid == replyid).execute()

        q_u7 = TabEvaluation.delete().where(TabEvaluation.post_id == uid)
        q_u7.execute()
        q_u8 = TabRating.delete().where(TabRating.post_id == uid)
        q_u8.execute()
        return MHelper.delete(TabPost, uid)
Beispiel #3
0
 def update(postid, userid, rating):
     uu = TabRating.select().where((TabRating.post_id == postid)
                                   & (TabRating.user_id == userid))
     if uu.count() > 0:
         MRating.__update_rating(uu.get().uid, rating)
     else:
         MRating.__insert_data(postid, userid, rating)
Beispiel #4
0
 def __update_rating(uid, rating):
     '''
     Update rating.
     '''
     entry = TabRating.update(
         rating=rating
     ).where(TabRating.uid == uid)
     entry.execute()
Beispiel #5
0
 def get_rating(postid, userid):
     try:
         uu = TabRating.select().where((TabRating.post_id == postid)
                                       & (TabRating.user_id == userid))
     except:
         return False
     if uu.count() > 0:
         return uu.get().rating
     else:
         return False
Beispiel #6
0
 def update(postid, userid, rating):
     '''
     Update the rating of certain post and user.
     The record will be created if no record exists.
     '''
     rating_recs = TabRating.select().where((TabRating.post_id == postid) & (TabRating.user_id == userid))
     if rating_recs.count() > 0:
         MRating.__update_rating(rating_recs.get().uid, rating)
     else:
         MRating.__insert_data(postid, userid, rating)
Beispiel #7
0
 def get_rating(postid, userid):
     '''
     Get the rating of certain post and user.
     '''
     try:
         recs = TabRating.select().where((TabRating.post_id == postid) & (TabRating.user_id == userid))
     except:
         return False
     if recs.count() > 0:
         return recs.get().rating
     else:
         return False
Beispiel #8
0
 def query_average_rating(postid, limit=1000):
     return TabRating.select(
         peewee.fn.Avg(TabRating.rating).over(
             order_by=[TabRating.timestamp.desc()])).where(
                 TabRating.post_id == postid).limit(limit).scalar()
Beispiel #9
0
 def query_by_post(postid, limit=20):
     return TabRating.select().where(
         TabRating.post_id == postid).limit(limit)