Removed aforementioned delay, and instead just made it a batch job

This commit is contained in:
Jacob Henry 2018-11-03 16:37:35 -04:00
parent 208617db2f
commit 46129b8d24
1 changed files with 26 additions and 25 deletions

View File

@ -2,9 +2,8 @@ from fuzzywuzzy import process
import channel_util import channel_util
import google_api import google_api
import slack_util
import identifier import identifier
import time import slack_util
SHEET_ID = "1lPj9GjB00BuIq9GelOWh5GmiGsheLlowPnHLnWBvMOM" SHEET_ID = "1lPj9GjB00BuIq9GelOWh5GmiGsheLlowPnHLnWBvMOM"
@ -14,6 +13,7 @@ output_range = "JobScoreTracker"
MIN_RATIO = 0.9 MIN_RATIO = 0.9
SIGNOFF_REWARD = 0.1 SIGNOFF_REWARD = 0.1
SAFETY_DELAY = 5
# Used to track a sufficiently shitty typed name # Used to track a sufficiently shitty typed name
@ -64,9 +64,7 @@ def signoff_callback(slack, msg, match):
# Try giving the person a point # Try giving the person a point
try: try:
bro_name, bro_total = adjust_score(name, 1) (bro_name, bro_total), (ass_name, ass_total) = adjust_scores((name, 1), (signer, SIGNOFF_REWARD))
time.sleep(1)
ass_name, ass_total = adjust_score(signer, SIGNOFF_REWARD)
slack_util.reply(slack, msg, "Gave {} one housejob point.\n" slack_util.reply(slack, msg, "Gave {} one housejob point.\n"
"They now have {} for this period.\n" "They now have {} for this period.\n"
"You ({}) were credited with the signoff".format(bro_name, bro_total, ass_name)) "You ({}) were credited with the signoff".format(bro_name, bro_total, ass_name))
@ -84,9 +82,7 @@ def punish_callback(slack, msg, match):
# Try giving the person a point # Try giving the person a point
try: try:
bro_name, bro_total = adjust_score(name, -1) (bro_name, bro_total), (ass_name, ass_total) = adjust_scores((name, -1), (signer, -SIGNOFF_REWARD))
time.sleep(1)
ass_name, ass_total = adjust_score(signer, -SIGNOFF_REWARD)
slack_util.reply(slack, msg, "Took one housejob point from {}.\n" slack_util.reply(slack, msg, "Took one housejob point from {}.\n"
"They now have {} for this period.\n" "They now have {} for this period.\n"
"Under the assumption that this was to undo a mistake, we have deducted the " "Under the assumption that this was to undo a mistake, we have deducted the "
@ -99,11 +95,13 @@ def punish_callback(slack, msg, match):
slack_util.reply(slack, msg, e.as_response()) slack_util.reply(slack, msg, e.as_response())
def adjust_score(name, delta): def adjust_scores(*name_delta_tuples):
# Get the current stuff # Get the current stuff
points = get_curr_points() points = get_curr_points()
names = [p[0] for p in points] names = [p[0] for p in points]
results = []
for name, delta in name_delta_tuples:
# Find our guy # Find our guy
target_name, ratio = process.extractOne(name, names) target_name, ratio = process.extractOne(name, names)
ratio = ratio / 100.0 ratio = ratio / 100.0
@ -120,13 +118,16 @@ def adjust_score(name, delta):
# target should be in the form index, (name, score) # target should be in the form index, (name, score)
target_new = [target_name, curr_score + delta] target_new = [target_name, curr_score + delta]
results.append(target_new)
# Put it back # Put it back
points[target_index] = target_new points[target_index] = target_new
# Record all when done
put_points(points) put_points(points)
# Return the adjusted name # Return the adjusted name/score_tuples
return target_new return results
def reset_callback(slack, msg, match): def reset_callback(slack, msg, match):