diff options
-rwxr-xr-x | perc | 48 |
1 files changed, 34 insertions, 14 deletions
@@ -1,6 +1,6 @@ #! /usr/bin/env python -# McAuthor: CarpNet (thanks to a paradigm shifting idea by Bikeman) +# McAuthor: CarpNet (thanks to a paradigm shifting idea by Bikeman) (some changes by wjoe) # TODO 1: some crazy AI heuristics stuff, see The Terminator and Skynet for ideas. @@ -36,7 +36,10 @@ # 3.5: # - Created Config class to more cleanly get/set config options # - Split config files into perc.cfg and custom_perc.cfg for options that can change on commit and custom user specified options that are persistent - +# 3.6: +# - Added a 'count' output option to display a countdown of days until the finish +# - wjoe ruined everything +# import copy import decimal import json @@ -45,6 +48,7 @@ import random import re import string import sys +import math from datetime import datetime, date, timedelta, time @@ -85,7 +89,7 @@ WORK_WEEK = [ MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY ] IMPORTANT_TEMPORAL_EVENTS = ["LATER", "tomorrow", "friday", "new year", "newyear", "christmas", "xmas", "weekend", "midday", "noon", "lunch", "easter", "halloween"] RECURRANCE_PERIODS = ["hourly", "daily", "weekly", "fortnightly", "monthly", "yearly"] -OUTPUT_TYPES = ["perc", "bar", "ram", "pint"] +OUTPUT_TYPES = ["perc", "bar", "ram", "pint", "count"] VERB_FORMS = ["is", "is not", "should be", "could be", "would be", "ought to be", "might be", "may become"] @@ -116,6 +120,10 @@ def float_to_decimal(f): def delta_in_seconds(delta): return (delta.microseconds + (delta.seconds + delta.days * 24 * 3600) * 10**6) / 10**6 +def calculate_count(start, finish): + delta = (finish - NOW) + return delta + def calculate_ratio(start, finish): total = float(delta_in_seconds(finish - start)) done = float(delta_in_seconds(NOW - start)) @@ -367,15 +375,16 @@ def parseUserArgs(args, user): output_type = options.output if options.output else user.output ratio = clamp(calculate_ratio(start, finish), 0.0, 1.0) - - return start_formatted, finish_formatted, ratio, output_type + delta = calculate_count(start, finish) + + return start_formatted, finish_formatted, ratio, output_type, delta class Output(object): - def perc(self, ratio, start, finish): + def perc(self, ratio, start, finish, delta): print CONFIG["OUTPUT"]["PERCENTAGE"].format(ratio=ratio, start=start, finish=finish) - def bar(self, ratio, start, finish): + def bar(self, ratio, start, finish, delta): length = CONFIG["OUTPUT"]["BAR"]["length"] if not options.mobile else CONFIG["OUTPUT"]["BAR"]["length_mobile"] char = CONFIG["OUTPUT"]["BAR"]["character"] @@ -388,7 +397,7 @@ class Output(object): print "{start} [{ratio:{char}^{current}}{space}] {finish}".format(ratio=ratiostr, char=char, current=current, space=space, start=start, finish=finish) - def ram(self, ratio, start, finish): + def ram(self, ratio, start, finish, delta): # 10 raised arm men indicates a complete day # Raised arm men parts (3 parts per raised arm man and 10 of them) @@ -396,13 +405,24 @@ class Output(object): print "Not implemented" - def pint(self, ratio, start, finish): + def pint(self, ratio, start, finish, delta): print "Not implemented" - - def output(self, type, ratio, start, finish): + + def count(self, ratio, start, finish, delta): + seconds = delta.seconds + days = int(math.floor(seconds/60/60/24)) + seconds = seconds - (days*60*60*24) + hours = int(math.floor(seconds/60/60)) + seconds = seconds - (hours*60*60) + minutes = int(math.floor(seconds/60)) + seconds = int(seconds - (minutes*60)) + + print 'Event in ' + str(days) + ' day(s), ' + str(hours) + ' hour(s), ' + str(minutes) + ' minute(s), ' + str(seconds) + ' second(s).' + + def output(self, type, ratio, start, finish, count): func = getattr(self, type, self.perc) - func(ratio, start, finish) + func(ratio, start, finish, count) class TimeRange(object): @@ -710,11 +730,11 @@ def user(args): nick = options.nick.lower() user = User(nick) - start, finish, ratio, output_type = parseUserArgs(args, user) + start, finish, ratio, output_type, delta = parseUserArgs(args, user) # Finally output the percentage in the specified way output = Output() - output.output(output_type, ratio, start, finish) + output.output(output_type, ratio, start, finish, delta) def readConfig(): global CONFIG, CUSTOM_CONFIG |