def check_retetion(the_bot,user): print("user: "******"user_id: ",user_id) users = [] dates = {} #THIS FUCTION MUST RUN EVERY 24 HOURS AT THE SAME TIME EVERY DAY print("Checking user's retention") #from the tweets table make a select distinct to filters ids of users without repeating ids Point = Tweet.select(Tweet.user_tweets).distinct().order_by(Tweet.user_tweets) for u in Point: users.append( u.user_tweets.user_id) print("user:"******"more than 24 hours have passed: ", itemx.user_tweets.user_id) #add a row to the pointsgivent table with a -0.25 point PointsGiven.create(user_who_gave_point = user_id,user_who_received_point =itemx.user_tweets.user_id,tweet_with_answer = 000,point = -0.25 ) #let know the user each day the number of points that he has lost, maybe a private message(dont' know if the user has to follow the bot)??? message = "@"+itemx.user_tweets.screen_name+ " you lost a quarter of a point, you didn't participate in the last 24 hours" the_bot.update_status( message ) break dates [itemx.user_tweets.user_id] = itemx.created_date
def count_points_user(the_bot,user): print("user: "******"user_id", user_id) points = PointsGiven.select(PointsGiven.point,PointsGiven.user_who_received_point).where(PointsGiven.user_who_received_point == user_id ) sq = PointsGiven.select() tweetspositive = sq.where((PointsGiven.user_who_received_point == user_id ) & (PointsGiven.point == 1) ) tweetsanswer = sq.where((PointsGiven.user_who_received_point == user_id ) & (PointsGiven.point == 2) ) answer_points = (tweetsanswer.count())* 2 tweetsnegative = sq.where((PointsGiven.user_who_received_point == user_id ) & (PointsGiven.point == -1) ) quarterpoint = sq.where((PointsGiven.user_who_received_point == user_id ) & (PointsGiven.point == -0.25) ) quarterpoint = (quarterpoint.count())*0.25 totalpoints = (tweetspositive.count() + answer_points ) - (tweetsnegative.count()) - quarterpoint print("total points: ", totalpoints) return totalpoints
def get_leaderboard(): users = [] leaderboard = {} Point = PointsGiven.select(PointsGiven.user_who_received_point).distinct() for u in Point: users.append( u.user_who_received_point.user_id) print("user who received the point: ", u.user_who_received_point.user_id) for item in users: print("user:"******"count pos is: ",tweetspositive.count()) print("user is:", item) tweetsanswer = sq.where((PointsGiven.user_who_received_point == item ) & (PointsGiven.point == 2) ) answer_points = (tweetsanswer.count())* 2 print("count answ is: ",answer_points) print("user is:", item) tweetsnegative = sq.where((PointsGiven.user_who_received_point == item) & (PointsGiven.point == -1) ) print("count neg is: ",tweetsnegative.count()) print("user is:", item) quarterpoint = sq.where((PointsGiven.user_who_received_point == item ) & (PointsGiven.point == -0.25) ) quarterpoint = (quarterpoint.count())*0.25 print("quarter is: ",) print("user is:", item) totalpoints = (tweetspositive.count() + answer_points ) - (tweetsnegative.count()) - quarterpoint leaderboard[item] = totalpoints sorted_dic = [(k,v) for v,k in sorted( [(v,k) for k,v in leaderboard.items()],reverse=True ) ] return sorted_dic