Made towels part of normal point system
This commit is contained in:
parent
941ae19dad
commit
c6f2dd9844
|
|
@ -20,6 +20,7 @@ JOB_VAL = 1
|
||||||
LATE_VAL = 0.5
|
LATE_VAL = 0.5
|
||||||
MISS_VAL = -1
|
MISS_VAL = -1
|
||||||
SIGNOFF_VAL = 0.1
|
SIGNOFF_VAL = 0.1
|
||||||
|
TOWEL_VAL = 0.1
|
||||||
|
|
||||||
# What to put for a non-signed-off job
|
# What to put for a non-signed-off job
|
||||||
SIGNOFF_PLACEHOLDER = "E-SIGNOFF"
|
SIGNOFF_PLACEHOLDER = "E-SIGNOFF"
|
||||||
|
|
@ -86,6 +87,14 @@ class PointStatus(object):
|
||||||
fmt(self.bonus_points),
|
fmt(self.bonus_points),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def towel_contribution_count(self) -> int:
|
||||||
|
return round(self.towel_points / TOWEL_VAL)
|
||||||
|
|
||||||
|
@towel_contribution_count.setter
|
||||||
|
def towel_contribution_count(self, val: int) -> None:
|
||||||
|
self.towel_points = val * TOWEL_VAL
|
||||||
|
|
||||||
|
|
||||||
def strip_all(l: List[str]) -> List[str]:
|
def strip_all(l: List[str]) -> List[str]:
|
||||||
return [x.strip() for x in l]
|
return [x.strip() for x in l]
|
||||||
|
|
|
||||||
2
main.py
2
main.py
|
|
@ -35,7 +35,7 @@ def main() -> None:
|
||||||
|
|
||||||
# Add towel rolling
|
# Add towel rolling
|
||||||
wrap.add_hook(slavestothemachine.count_work_hook)
|
wrap.add_hook(slavestothemachine.count_work_hook)
|
||||||
wrap.add_hook(slavestothemachine.dump_work_hook)
|
# wrap.add_hook(slavestothemachine.dump_work_hook)
|
||||||
|
|
||||||
# Add job management
|
# Add job management
|
||||||
wrap.add_hook(job_commands.signoff_hook)
|
wrap.add_hook(job_commands.signoff_hook)
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,18 @@
|
||||||
|
import re
|
||||||
|
import textwrap
|
||||||
from typing import Match
|
from typing import Match
|
||||||
|
|
||||||
from slackclient import SlackClient
|
from slackclient import SlackClient
|
||||||
|
|
||||||
import channel_util
|
import channel_util
|
||||||
import slack_util
|
import house_management
|
||||||
import identifier
|
import identifier
|
||||||
import re
|
import slack_util
|
||||||
import shelve
|
from scroll_util import Brother
|
||||||
|
|
||||||
from scroll_util import BrotherNotFound
|
|
||||||
|
|
||||||
counted_data = ["flaked", "rolled", "replaced", "washed", "dried"]
|
counted_data = ["flaked", "rolled", "replaced", "washed", "dried"]
|
||||||
lookup_format = "{}\s+(\d+)"
|
lookup_format = "{}\s+(\d+)"
|
||||||
|
|
||||||
DB_NAME = "towels_rolled"
|
|
||||||
|
|
||||||
|
|
||||||
def fmt_work_dict(work_dict: dict) -> str:
|
def fmt_work_dict(work_dict: dict) -> str:
|
||||||
return ",\n".join(["{} × {}".format(job, count) for job, count in sorted(work_dict.items())])
|
return ",\n".join(["{} × {}".format(job, count) for job, count in sorted(work_dict.items())])
|
||||||
|
|
@ -22,79 +20,76 @@ def fmt_work_dict(work_dict: dict) -> str:
|
||||||
|
|
||||||
# noinspection PyUnusedLocal
|
# noinspection PyUnusedLocal
|
||||||
async def count_work_callback(slack: SlackClient, msg: dict, match: Match) -> None:
|
async def count_work_callback(slack: SlackClient, msg: dict, match: Match) -> None:
|
||||||
with shelve.open(DB_NAME) as db:
|
# Make an error wrapper
|
||||||
text = msg["text"].lower().strip()
|
verb = slack_util.VerboseWrapper(slack, msg)
|
||||||
|
|
||||||
# Couple things to work through.
|
# Tidy the text
|
||||||
# One: Who sent the message?
|
text = msg["text"].lower().strip()
|
||||||
who_wrote = await identifier.lookup_msg_brother(msg)
|
|
||||||
who_wrote_label = "{} [{}]".format(who_wrote.name, who_wrote.scroll)
|
|
||||||
|
|
||||||
# Two: What work did they do?
|
# Couple things to work through.
|
||||||
new_work = {}
|
# One: Who sent the message?
|
||||||
for job in counted_data:
|
who_wrote = await verb(identifier.lookup_msg_brother(msg))
|
||||||
pattern = lookup_format.format(job)
|
who_wrote_label = "{} [{}]".format(who_wrote.name, who_wrote.scroll)
|
||||||
match = re.search(pattern, text)
|
|
||||||
if match:
|
|
||||||
new_work[job] = int(match.group(1))
|
|
||||||
|
|
||||||
# Three: check if we found anything
|
# Two: What work did they do?
|
||||||
if len(new_work) == 0:
|
new_work = {}
|
||||||
if re.search(r'\s\d\s', text) is not None:
|
for job in counted_data:
|
||||||
slack_util.reply(slack, msg,
|
pattern = lookup_format.format(job)
|
||||||
"No work recognized. Use words {} or work will not be recorded".format(counted_data))
|
match = re.search(pattern, text)
|
||||||
return
|
if match:
|
||||||
|
new_work[job] = int(match.group(1))
|
||||||
|
|
||||||
# Three: Add it to their total work. We key by user_id, to avoid annoying identity shit
|
# Three: check if we found anything
|
||||||
db_key = msg["user"]
|
if len(new_work) == 0:
|
||||||
old_work = db.get(db_key) or {}
|
if re.search(r'\s\d\s', text) is not None:
|
||||||
total_work = dict(old_work)
|
slack_util.reply(slack, msg,
|
||||||
|
"If you were trying to record work, it was not recognized.\n"
|
||||||
|
"Use words {} or work will not be recorded".format(counted_data))
|
||||||
|
return
|
||||||
|
|
||||||
for job, count in new_work.items():
|
# Four: Knowing they did something, record to total work
|
||||||
if job not in total_work:
|
contribution_count = sum(new_work.values())
|
||||||
total_work[job] = 0
|
new_total = await verb(record_towel_contribution(who_wrote, contribution_count))
|
||||||
total_work[job] += count
|
|
||||||
|
|
||||||
# Save
|
# Five, congratulate them on their work!
|
||||||
db[db_key] = total_work
|
congrats = textwrap.dedent("""{} recorded work:
|
||||||
|
{}
|
||||||
# Four, congratulate them on their work
|
Net increase in points: {}
|
||||||
congrats = "{} recorded work:\n{}\nTotal work since last dump now\n{}".format(who_wrote_label,
|
Total points since last reset: {}""".format(who_wrote_label,
|
||||||
fmt_work_dict(new_work),
|
fmt_work_dict(new_work),
|
||||||
fmt_work_dict(total_work))
|
contribution_count,
|
||||||
slack_util.reply(slack, msg, congrats)
|
new_total))
|
||||||
|
slack_util.reply(slack, msg, congrats)
|
||||||
|
|
||||||
|
|
||||||
# noinspection PyUnusedLocal
|
async def record_towel_contribution(for_brother: Brother, contribution_count: int) -> int:
|
||||||
async def dump_work_callback(slack: SlackClient, msg: dict, match: Match) -> None:
|
"""
|
||||||
with shelve.open(DB_NAME) as db:
|
Grants <count> contribution point to the specified user.
|
||||||
# Dump out each user
|
Returns the new total.
|
||||||
keys = db.keys()
|
"""
|
||||||
result = ["All work:"]
|
# Import house points
|
||||||
for user_id in keys:
|
headers, points = await house_management.import_points()
|
||||||
# Get the work
|
|
||||||
work = db[user_id]
|
|
||||||
del db[user_id]
|
|
||||||
|
|
||||||
# Get the name
|
# Find the brother
|
||||||
try:
|
for p in points:
|
||||||
brother = await identifier.lookup_slackid_brother(user_id)
|
if p is None or p.brother != for_brother:
|
||||||
except BrotherNotFound:
|
continue
|
||||||
brother = user_id
|
|
||||||
else:
|
|
||||||
brother = brother.name
|
|
||||||
|
|
||||||
result.append("{} has done:\n{}".format(brother, fmt_work_dict(work)))
|
# If found, mog with more points
|
||||||
|
p.towel_contribution_count += contribution_count
|
||||||
|
|
||||||
result.append("Database wiped. Next dump will show new work since the time of this message")
|
# Export
|
||||||
# Send it back
|
house_management.export_points(headers, points)
|
||||||
slack_util.reply(slack, msg, "\n".join(result))
|
|
||||||
|
# Return the new total
|
||||||
|
return p.towel_contribution_count
|
||||||
|
|
||||||
|
# If not found, get mad!
|
||||||
|
raise KeyError("No score entry found for brother {}".format(for_brother))
|
||||||
|
|
||||||
|
|
||||||
# Make dem HOOKs
|
# Make dem HOOKs
|
||||||
count_work_hook = slack_util.Hook(count_work_callback,
|
count_work_hook = slack_util.Hook(count_work_callback,
|
||||||
patterns=".*",
|
patterns=".*",
|
||||||
channel_whitelist=[channel_util.SLAVES_TO_THE_MACHINE_ID])
|
channel_whitelist=[channel_util.SLAVES_TO_THE_MACHINE_ID],
|
||||||
dump_work_hook = slack_util.Hook(dump_work_callback,
|
consumer=False)
|
||||||
patterns="dump towel data",
|
|
||||||
channel_whitelist=[channel_util.COMMAND_CENTER_ID])
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue