Пример #1
0
 def save(self):
     registration = self.cleaned_data.get('registration')
     match = self.cleaned_data.get('match')
     tipped_team = self.cleaned_data.get('tipped_team')
     try:
         tip = Tip.objects.get(registration=registration, match=match)
     except Tip.DoesNotExist:
         tip = Tip(registration=registration, match=match)
     tip.winner = tipped_team
     tip.save()
     return tip
Пример #2
0
def save_tips():
    for tdata in iterate_file("tip", shortcircuit=True):
        tip = Tip()
        tip.business_id = tdata['business_id']
        tip.text = tdata['text']
        tip.user_id = tdata['user_id']
        tip.date = datetime.strptime(tdata['date'], "%Y-%m-%d")
        tip.likes = int(tdata['likes'])
        tip.save()
Пример #3
0
def get_away_win_tips(home_team, away_team, competition, kickoff, match_history):
    tips = []
    sorted_matches = sorted(match_history, key=lambda match: match["date"], reverse=True)
    away_wins_form = get_away_wins_form_8_matches(away_team, competition, sorted_matches)
    home_loss_form = get_home_loss_form_8_matches(home_team, competition, sorted_matches)
    wins_form = get_wins_form_6_matches(away_team, competition, sorted_matches)
    loss_form = get_loss_form_6_matches(home_team, competition, sorted_matches)

    if away_wins_form >= 5 and home_loss_form >= 5 and (wins_form >= 4 or loss_form >= 4):
        home_description = "Home loss: %i/8.\nHome/Away loss: %i/6." % (home_loss_form, loss_form)
        away_description = "Away wins: %i/8.\nHome/Away wins: %i/6." % (away_wins_form, wins_form)

        tip = Tip(HomeTeamName=home_team,
                  AwayTeamName=away_team,
                  KickOff=kickoff,
                  MarketType=0,
                  MarketParticipantType=3,
                  Status=0,
                  LastUpdate=datetime.utcnow(),
                  Competition=competition,
                  HomeMatches=home_description,
                  AwayMatches=away_description)

        tips.append(tip)

    return tips
Пример #4
0
def get_goals_over_tips(home_team, away_team, competition, kickoff, match_history, threshold=2.5):
    tips = []
    sorted_matches = sorted(match_history, key=lambda match: match["date"], reverse=True)
    home_overs_count = get_home_goals_over_form_8_matches(home_team, competition, sorted_matches, threshold)
    away_overs_count = get_away_goals_over_form_8_matches(away_team, competition, sorted_matches, threshold)
    home_overs_all_average = get_goals_over_average_6_matches(home_team, competition, sorted_matches)
    away_overs_all_average = get_goals_over_average_6_matches(away_team, competition, sorted_matches)

    average_threshold = threshold + 0.25
    if home_overs_count >= 5 and away_overs_count >= 5 and home_overs_all_average >= average_threshold and away_overs_all_average >= average_threshold:
        home_description = "Matches > 2.5 goals: %i/8.\nAverage goals over 6 matches: %.2f.\n" % (home_overs_count, home_overs_all_average)
        away_description = "Matches > 2.5 goals: %i/8.\nAverage goals over 6 matches: %.2f.\n" % (away_overs_count, away_overs_all_average)

        tip = Tip(HomeTeamName=home_team,
                  AwayTeamName=away_team,
                  KickOff=kickoff,
                  MarketType=1,
                  MarketParticipantType=6,
                  MarketParticipantThreshold=2.5,
                  Status=0,
                  LastUpdate=datetime.utcnow(),
                  Competition=competition,
                  HomeMatches=home_description,
                  AwayMatches=away_description)

        tips.append(tip)

    return tips
def save_tips():
    for tdata in iterate_file("tip", shortcircuit=True):
        tip = Tip()
        tip.business_id = tdata['business_id']
        tip.text = tdata['text']
        tip.user_id = tdata['user_id']
        tip.date = datetime.strptime(tdata['date'], "%Y-%m-%d")
        tip.likes = int(tdata['likes'])
        tip.save()
Пример #6
0
def save_tips():
    for tdata in iterate_file("tip", shortcircuit=True):
        tip = Tip()
        tip.business_id = tdata['business_id']
        tip.text = tdata['text']
        tip.user_id = tdata['user_id']
        tip.date = datetime.strptime(tdata['date'], "%Y-%m-%d")
        tip.likes = int(tdata['likes'])
        try:
            tip.save()
        except InternalError:
            print "i dont care"
            pass
Пример #7
0
def add_tip(request):
    target_model = request.POST.get('model', '').lower()
    target_name = request.POST.get('id', '').lower()
    tip = request.POST.get('tip', '').lower()
    errors = []

    if target_model.strip() and target_name.strip():
        cleaned_tip = tip.strip()
        tip_object = Tip(target_model=target_model,
                         target_name=target_name,
                         tip=cleaned_tip)
        tip_object.save()

    response = {'success': True, 'errors': errors}
    return shortcuts.render_to_response(
        'json.html', {'response': json.dumps(response)},
        context_instance=RequestContext(request),
        mimetype="application/json")
Пример #8
0
def add_tip(request):
    target_model = request.POST.get('model', '').lower()
    target_name = request.POST.get('id', '').lower()
    tip = request.POST.get('tip', '').lower()
    errors = []
    
    if target_model.strip() and target_name.strip():
        cleaned_tip = tip.strip()
        tip_object = Tip(target_model = target_model, 
                         target_name = target_name, 
                         tip = cleaned_tip)
        tip_object.save()
    
    response = {'success':True, 'errors':errors}
    return shortcuts.render_to_response('json.html',
                                         {'response':json.dumps(response)},
                                         context_instance = RequestContext(request),
                                         mimetype = "application/json") 
Пример #9
0
 def post(self):
     r = request.get_json(force=True)
     tipBatch = r[10:len(r) - 6].strip().replace("\n", "").split('},   {')
     for singleTip in tipBatch:
         json_data = json.loads('{' + singleTip + '}')
         try:
             tip = Tip(user_id=json_data['user_id'],
                       text=json_data['text'],
                       business_id=json_data['business_id'],
                       compliment_count=json_data['compliment_count'],
                       date=json_data['date'],
                       deleted=json_data['deleted'])
         except Exception as e:
             return (str(e))
         postgres.session.add(tip)
     postgres.session.commit()
     return {}
Пример #10
0
def do_tip_group(client, message, *args, **kwargs):
	user = kwargs.get('user')
	session = kwargs.get('session')
	if user.coins <= 0:
		m = app.send_message(chat_id=message.chat.id, text="⛔ {}: Non possiedi abbastanza FiberCoin." \
							 .format(MENTION.format(user.name, user.chat_id)))
		# Queue a job for deleting the message
		threading.Timer(10.0, delete_message_cb,
						kwargs={'chat_id': message.chat.id, 'message_id': m.message_id}).start()
		# Delete messages which are not replies to other messages
		app.delete_messages(message.chat.id, message.message_id)
		return
	if not message.reply_to_message:
		m = app.send_message(chat_id=message.chat.id, text="⛔ {}: Devi rispondere al messaggio da tippare" \
							 .format(MENTION.format(user.name, user.chat_id)))
		# Queue a job for deleting the message
		threading.Timer(10.0, delete_message_cb,
						kwargs={'chat_id': message.chat.id, 'message_id': m.message_id}).start()
		# Delete messages which are not replies to other messages
		app.delete_messages(message.chat.id, message.message_id)
		return
	to = session.query(User).filter(User.chat_id == message.reply_to_message.from_user.id).first()
	if not to:
		m = app.send_message(chat_id=message.chat.id, text="😢 {}: L'utente non è stato fibberato!"\
							 .format(MENTION.format(user.name, user.chat_id)))
		# Queue a job for deleting the message
		threading.Timer(10.0, delete_message_cb, kwargs={'chat_id': message.chat.id, 'message_id': m.message_id}).start()
	elif to == user:
		m = app.send_message(chat_id=message.chat.id, text="⛔ {}: Non puoi tipparti da solo!"\
							 .format(MENTION.format(user.name, user.chat_id)))
		threading.Timer(10.0, delete_message_cb, kwargs={'chat_id': message.chat.id, 'message_id': m.message_id}).start()
	else:
		# Get Tip Record for that message
		tip = session.query(Tip).filter((Tip.author_id == message.reply_to_message.from_user.id) & \
										(Tip.chat_id == message.reply_to_message.chat.id) & \
										(Tip.message_id == message.reply_to_message.message_id)
										).first()
		if not tip: # Or create a new one
			tip = Tip(chat_id=message.reply_to_message.chat.id,
					  message_id=message.reply_to_message.message_id,
					  author_id=message.reply_to_message.from_user.id,
					  total=0,
					  last_tipper=user
				)
			session.add(tip)
		elif tip.last_tipper == user:
			m = app.send_message(chat_id=message.chat.id,
								 text="⛔ {}: Non puoi tippare lo stesso messaggio più volte di seguito."\
								 .format(MENTION.format(user.name, user.chat_id)))
			threading.Timer(10.0, delete_message_cb, kwargs={'chat_id': message.chat.id, 'message_id': m.message_id}).start()
			app.delete_messages(message.chat.id, message.message_id)
			return
		else:
			tip.last_tipper = user
		user.coins -= FC_PER_GROUP_TIP
		to.coins += FC_PER_GROUP_TIP
		tip.total += 1
		session.commit()
		app.send_message(chat_id=to.chat_id,
						 text="Hai ricevuto 💸**{} FiberCoin** da {}\n"
				  				"💰 Borsellino: 💸**{} FiberCoin**"\
						.format(FC_PER_GROUP_TIP, MENTION.format(user.name, user.chat_id), to.coins)
						)
		app.send_message(chat_id=user.chat_id,
						 text="Hai inviato 💸**{} FiberCoin** a {}\n"
				  				"💰 Borsellino: 💸**{} FiberCoin**"\
						.format(FC_PER_GROUP_TIP, MENTION.format(to.name, to.chat_id), user.coins)
						)

		message.reply_to_message.reply("● **{} FiberCoin**{} ●\n{} ha tippato".format(
			tip.total,
			" 👌 " if any(word in str(tip.total) for word in ["69", "420"]) else "",
			MENTION.format(user.name, user.chat_id)
		))
	#Delete tip request message
	app.delete_messages(message.chat.id, message.message_id)