Skip to content

Commit

Permalink
proper productivity calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
vninja007 committed Aug 28, 2023
1 parent ff42ca7 commit a5406e7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
36 changes: 30 additions & 6 deletions punchcard/punch.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,12 +278,36 @@ async def elapsed(ctx, *, arg=""):
await ctx.send(elapsedError())


@bot.command()
async def productivity(ctx, *, arg=""):
arg = arg.split()
await ctx.send(str(getProductivity(ctx.author.id, arg[0]+" "+arg[1], arg[2]+" "+arg[3])))
def prodError():
s = """Malformed argument! Use one of the following:
p.productivity YYYY-MM-DD YYYY-MM-DD
p.productivity YYYY-MM-DD HH:mm:SS HH:mm:SS
p.productivity YYYY-MM-DD HH:mm:SS YYYY-MM-DD HH:mm:SS
p.dayproductivity YYYY-MM-DD
"""
return s

# Accurate to 3 decimal places because...


@bot.command()
async def dayproductivity(ctx, *, arg=""):
await ctx.send(str(getDayProductivity(ctx.author.id, arg)))
async def productivity(ctx, *, arg=""):
arg = arg.split()
if (not (1 <= len(arg) <= 4)):
await ctx.send(prodError())
else:
if (len(arg) == 1):
arg = [arg[0], "00:00:00", arg[0], "11:59:59"]
elif (len(arg) == 2):
arg = [arg[0], "00:00:00", arg[1], "11:59:59"]
elif (len(arg) == 3):
arg = [arg[0], arg[1], arg[0], arg[2]]
else: # len(arg)==4
pass
try:
prod = float(getProductivity(
ctx.author.id, arg[0]+" "+arg[1], arg[2]+" "+arg[3]))
prod = round(1000*prod)/10
await ctx.send(f"Productivity for {arg[0]} {arg[1]} to {arg[2]} {arg[3]} was **{prod}%**")
except (IndexError, ValueError):
await ctx.send(prodError())
2 changes: 1 addition & 1 deletion punchcard/utilfuncs.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def diffDatefromDate(start, end):
diff = end-start
if (not ("day" in str(diff))):
diff = "0 days, "+str(diff)
if ("-" in diff):
if ("-" in str(diff)):
return "-"+diffDatefromDate(end1, start1)
diff = str(diff).split(", ")
hms = diff[1]
Expand Down

0 comments on commit a5406e7

Please sign in to comment.