本文整理汇总了Python中helpers.firebase.firebase_pusher.FirebasePusher.replace_event_matches方法的典型用法代码示例。如果您正苦于以下问题:Python FirebasePusher.replace_event_matches方法的具体用法?Python FirebasePusher.replace_event_matches怎么用?Python FirebasePusher.replace_event_matches使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类helpers.firebase.firebase_pusher.FirebasePusher
的用法示例。
在下文中一共展示了FirebasePusher.replace_event_matches方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update_bluezone
# 需要导入模块: from helpers.firebase.firebase_pusher import FirebasePusher [as 别名]
# 或者: from helpers.firebase.firebase_pusher.FirebasePusher import replace_event_matches [as 别名]
#.........这里部分代码省略.........
if current_match and not current_match.has_been_played and now < cutoff_time \
and current_match_key not in blacklisted_match_keys \
and current_match.event_key_name not in blacklisted_event_keys:
logging.info("[BLUEZONE] Keeping current match {}".format(current_match.key.id()))
to_log += "[BLUEZONE] Keeping current match {}\n".format(current_match.key.id())
bluezone_matches.append(current_match)
for match in potential_matches:
if len(bluezone_matches) >= 2: # one current, one future
break
logging.info("[BLUEZONE] Trying potential match: {}".format(match.key.id()))
to_log += "[BLUEZONE] Trying potential match: {}\n".format(match.key.id())
if filter(lambda m: m.key.id() == match.key.id(), bluezone_matches):
logging.info("[BLUEZONE] Match {} already chosen".format(match.key.id()))
to_log += "[BLUEZONE] Match {} already chosen\n".format(match.key.id())
continue
if match.event_key_name in blacklisted_event_keys:
logging.info("[BLUEZONE] Event {} is blacklisted, skipping...".format(match.event_key_name))
to_log += "[BLUEZONE] Event {} is blacklisted, skipping...\n".format(match.event_key_name)
continue
if match.key.id() not in blacklisted_match_keys:
if match.key.id() == current_match_key:
if current_match_predicted_time and cutoff_time < now and len(potential_matches) > 1:
# We've been on this match too long
new_blacklisted_match_keys.add(match.key.id())
logging.info("[BLUEZONE] Adding match to blacklist: {}".format(match.key.id()))
to_log += "[BLUEZONE] Adding match to blacklist: {}\n".format(match.key.id())
logging.info("[BLUEZONE] scheduled time: {}, now: {}".format(current_match_predicted_time, now))
to_log += "[BLUEZONE] scheduled time: {}, now: {}\n".format(current_match_predicted_time, now)
OutgoingNotificationHelper.send_slack_alert(slack_url, "Blacklisting match {}. Predicted time: {}, now: {}".format(match.key.id(), current_match_predicted_time, now))
else:
# We can continue to use this match
bluezone_matches.append(match)
logging.info("[BLUEZONE] Continuing to use match: {}".format(match.key.id()))
to_log += "[BLUEZONE] Continuing to use match: {}\n".format(match.key.id())
else:
# Found a new good match
bluezone_matches.append(match)
logging.info("[BLUEZONE] Found a good new match: {}".format(match.key.id()))
to_log += "[BLUEZONE] Found a good new match: {}\n".format(match.key.id())
else:
logging.info("[BLUEZONE] Match already blacklisted: {}".format(match.key.id()))
to_log += "[BLUEZONE] Match already blacklisted: {}\n".format(match.key.id())
new_blacklisted_match_keys.add(match.key.id())
if not bluezone_matches:
logging.info("[BLUEZONE] No match selected")
to_log += "[BLUEZONE] No match selected\n"
logging.info("[BLUEZONE] All selected matches: {}".format([m.key.id() for m in bluezone_matches]))
to_log += "[BLUEZONE] All selected matches: {}\n".format([m.key.id() for m in bluezone_matches])
# (3) Switch to hottest match
fake_event = cls.build_fake_event()
if bluezone_matches:
bluezone_match = bluezone_matches[0]
real_event = filter(lambda x: x.key_name == bluezone_match.event_key_name, live_events)[0]
# Create Fake event for return
fake_event.webcast_json = json.dumps([real_event.current_webcasts[0]])
if bluezone_match.key_name != current_match_key:
current_match_switch_time = now
logging.info("[BLUEZONE] Switching to: {}".format(bluezone_match.key.id()))
to_log += "[BLUEZONE] Switching to: {}\n".format(bluezone_match.key.id())
OutgoingNotificationHelper.send_slack_alert(slack_url, "It is now {}. Switching BlueZone to {}, scheduled for {} and predicted to be at {}.".format(now, bluezone_match.key.id(), bluezone_match.time, bluezone_match.predicted_time))
if not current_match or current_match.has_been_played:
last_match = current_match
# Only need to update if things changed
if bluezone_match.key_name != current_match_key or new_blacklisted_match_keys != blacklisted_match_keys:
FirebasePusher.update_event(fake_event)
bluezone_config.contents = {
'current_match': bluezone_match.key.id(),
'last_match': last_match.key.id() if last_match else '',
'current_match_predicted': bluezone_match.predicted_time.strftime(cls.TIME_PATTERN),
'blacklisted_matches': list(new_blacklisted_match_keys),
'blacklisted_events': list(blacklisted_event_keys),
'current_match_switch_time': current_match_switch_time.strftime(cls.TIME_PATTERN),
}
bluezone_config.put()
# Log to cloudstorage
log_dir = '/tbatv-prod-hrd.appspot.com/tba-logging/'
log_file = 'bluezone_{}.txt'.format(now.date())
full_path = log_dir + log_file
existing_contents = ''
if full_path in set([f.filename for f in cloudstorage.listbucket(log_dir)]):
with cloudstorage.open(full_path, 'r') as existing_file:
existing_contents = existing_file.read()
with cloudstorage.open(full_path, 'w') as new_file:
new_file.write(existing_contents + to_log)
bluezone_matches.insert(0, last_match)
bluezone_matches = filter(lambda m: m is not None, bluezone_matches)
FirebasePusher.replace_event_matches('bluezone', bluezone_matches)
return fake_event