def add_data(self, prev_time, next_time, class_and_title): # Make a proverbial tick for every minute # Take care of the interval before the second lt = time.localtime(prev_time + time.timezone) if is_productive(class_and_title[0], class_and_title[1]): self.productive[lt.tm_hour * 60 + lt.tm_min] -= prev_time - int(prev_time) else: self.unproductive[lt.tm_hour * 60 + lt.tm_min] += prev_time - int(prev_time) for i in range(int(prev_time), int(next_time), 1): lt = time.localtime(i + time.timezone) if is_productive(class_and_title[0], class_and_title[1]): self.productive[lt.tm_hour * 60 + lt.tm_min] += 1 else: self.unproductive[lt.tm_hour * 60 + lt.tm_min] += 1 lt = time.localtime(int(next_time) + time.timezone) if is_productive(class_and_title[0], class_and_title[1]): self.productive[lt.tm_hour * 60 + lt.tm_min] += next_time - int(next_time) else: self.unproductive[lt.tm_hour * 60 + lt.tm_min] += next_time - int(next_time)
def add_data(self, prev_time, next_time, class_and_title): lt = time.localtime(prev_time + time.timezone) if is_productive(class_and_title[0], class_and_title[1]): self.productive[lt.tm_wday] += next_time - prev_time else: self.unproductive[lt.tm_wday] += next_time - prev_time
def add_data(self, prev_time, next_time, class_and_title): lt = time.localtime(prev_time + time.timezone) weekdays = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'] index = (lt.tm_year, lt.tm_mon, lt.tm_mday, weekdays[lt.tm_wday]) tud = self.days[index] if is_productive(class_and_title[0], class_and_title[1]): tud.productive += next_time - prev_time else: tud.unproductive += next_time - prev_time
def add_data(self, prev_time, next_time, class_and_title): lt = time.localtime(prev_time + time.timezone) weekdays = [ 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday' ] index = (lt.tm_year, lt.tm_mon, lt.tm_mday, weekdays[lt.tm_wday]) tud = self.days[index] if is_productive(class_and_title[0], class_and_title[1]): tud.productive += next_time - prev_time else: tud.unproductive += next_time - prev_time
def add_increment(self, class_and_title, prev_time, time_incr, idle, write=False): if not idle and class_and_title != ('',''): self.total_time += time_incr if write: # we don't want to save entries that have been read before if self.prev_class_and_title == class_and_title: self.ct_file.seek(self.prev_tell) self.ct_file.write("%f %f %s\n" % ( self.prev_start_time, time(), " ".join(class_and_title))) else: self.prev_start_time = prev_time self.prev_class_and_title = class_and_title self.prev_tell = self.ct_file.tell() self.ct_file.write("%f %f %s\n" % ( self.prev_start_time, time(), " ".join(class_and_title))) self.ct_file.flush() class_and_title = (class_and_title[0].strip('"'), class_and_title[1].strip('"')) by_class_title[class_and_title] += time_incr by_title[class_and_title[1]] += time_incr by_class[class_and_title[0]] += time_incr if not is_ignored(class_and_title[0], class_and_title[1]): if is_productive(class_and_title[0], class_and_title[1]): self.productive += time_incr else: self.unproductive += time_incr else: self.prev_idle_time = time() #most = sorted(by_class_title.iteritems(), key=operator.itemgetter(1), reverse=True) most = sorted(by_class.iteritems(), key=operator.itemgetter(1), reverse=True) most1 = sorted(by_class_title.iteritems(), key=operator.itemgetter(1), reverse=True) print chr(27) + "[2J" + chr(27) + "[;H" ''' print "xss_info.window:", xss_info.contents.window print "xss_info.state:", xss_info.contents.state print "xss_info.kind:", xss_info.contents.kind print "xss_info.since:", xss_info.contents.since print "xss_info.idle:", xss_info.contents.idle ''' if self.productive > self.unproductive: print "%.3f %s %s" % ( self.productive / (self.productive + self.unproductive), strftime("%H:%M:%S", localtime(self.productive + timezone)) , "productive") print "%.3f %s %s" % ( self.unproductive / (self.productive + self.unproductive), strftime("%H:%M:%S", localtime(self.unproductive + timezone)) , "unproductive") else: print "%.3f %s %s" % ( self.unproductive / self.total_time, strftime("%H:%M:%S", localtime(self.unproductive + timezone)) , "unproductive") print "%.3f %s %s" % ( self.productive / self.total_time, strftime("%H:%M:%S", localtime(self.productive + timezone)) , "productive") print ''' if self.unproductive < 0.25 * self.total_time: print "Free time: %s" % ( strftime("%H:%M:%S", localtime(0.25 * self.total_time - self.unproductive + timezone))) if self.unproductive < (1/3.) * self.productive: print "Free time: %s" % ( strftime("%H:%M:%S", localtime((1/3.) * self.productive - self.unproductive + timezone))) else: print "Free time: 00:00:00 Time to make up: %s" % ( strftime("%H:%M:%S", localtime((self.unproductive * 3.) - self.productive + timezone))) ''' print "Ratio (productive / unproductive): %.3f" % (self.productive / (self.unproductive + 0.1)) print '---------------------------------------------------------' for i in xrange(min(10, len(most))): #print "%.3f %6.1f %s" % ( most[i][1] / self.total_time, most[i][1] , most[i][0]) print "%.3f %s %s" % ( most[i][1] / self.total_time, strftime("%H:%M:%S", localtime(most[i][1] + timezone)) , most[i][0]) print print print "Active time: %s Total active time: %s Total time: %s Start time: %s" % ( strftime("%H:%M:%S", localtime(time() - self.prev_idle_time + timezone)), strftime("%H:%M:%S", localtime(self.total_time + timezone)), strftime("%H:%M:%S", localtime(time() - self.start_time + timezone)), strftime("%H:%M:%S", localtime(self.start_time)) ) print '---------------------------------------------------------' for i in xrange(min(20, len(most1))): #print "%.3f %6.1f %s" % ( most[i][1] / self.total_time, most[i][1] , most[i][0]) if is_productive(most1[i][0][0], most1[i][0][1]): prod_str = 'P' else: prod_str = 'U' print "%.3f %s %s %s" % ( most1[i][1] / self.total_time, prod_str, strftime("%H:%M:%S", localtime(most1[i][1] + timezone)) , most1[i][0]) self.prev_time = time() sys.stdout.flush()
def main(): parser = OptionParser() #parser.add_option('-o', '--options', dest='some_option', default='yo', help="Place holder for a real option", type='str') parser.add_option('-l', '--lines', dest='lines', default=10000000, help="The number of lines to read from the data file.", type=int) parser.add_option( '-m', '--plot-minute', dest='plot_minute', default=False, help="Plot the productive and unproductive times spent each minute.", action='store_true') parser.add_option( '-w', '--plot-day-of-week', dest='plot_day_of_week', default=False, help= "Plot the productive and unproductive times spent each day of the week.", action='store_true') parser.add_option('-d', '--days', dest='days', default=-1, help="Show the data for the past n days", type=int) parser.add_option('-u', '--unproductive', dest='show_unproductive', default=False, help="List the unproductive entries.", action='store_true') (options, args) = parser.parse_args() data_file = open('beenrun.csv', 'r') counter = 0 sbd = SumByDay() mh = MinuteHistogram() dwh = DayOfWeekHistogram() lines = data_file.readlines() for line in reversed(lines): if counter >= options.lines: break counter += 1 try: parts = shlex.split(line) except ValueError: continue prev_time = float(parts[0]) next_time = float(parts[1]) if len(parts) == 3: class_and_title = (parts[2], '') elif len(parts) == 2: class_and_title = ('', '') else: class_and_title = (parts[2], parts[3]) if options.days >= 0: lt = dt.date.fromtimestamp(prev_time) nt = dt.date.fromtimestamp(time.time()) delta = nt - lt if delta.days > options.days - 1: break sbd.add_data(prev_time, next_time, class_and_title) if options.plot_minute: mh.add_data(prev_time, next_time, class_and_title) if options.plot_day_of_week: dwh.add_data(prev_time, next_time, class_and_title) if is_productive(class_and_title[0], class_and_title[1]): pass else: if options.show_unproductive: print class_and_title[0], class_and_title[1] if options.plot_minute: mh.plot() elif options.plot_day_of_week: dwh.plot() else: sbd.summarize()
def main(): parser = OptionParser() #parser.add_option('-o', '--options', dest='some_option', default='yo', help="Place holder for a real option", type='str') parser.add_option('-l', '--lines', dest='lines', default=10000000, help="The number of lines to read from the data file.", type=int) parser.add_option('-m', '--plot-minute', dest='plot_minute', default=False, help="Plot the productive and unproductive times spent each minute.", action='store_true') parser.add_option('-w', '--plot-day-of-week', dest='plot_day_of_week', default=False, help="Plot the productive and unproductive times spent each day of the week.", action='store_true') parser.add_option('-d', '--days', dest='days', default=-1, help="Show the data for the past n days", type=int) parser.add_option('-u', '--unproductive', dest='show_unproductive', default=False, help="List the unproductive entries.", action='store_true') (options, args) = parser.parse_args() data_file = open('beenrun.csv', 'r') counter = 0 sbd = SumByDay() mh = MinuteHistogram() dwh = DayOfWeekHistogram() lines = data_file.readlines() for line in reversed(lines): if counter >= options.lines: break counter += 1 try: parts = shlex.split(line) except ValueError: continue prev_time = float(parts[0]) next_time = float(parts[1]) if len(parts) == 3: class_and_title = (parts[2], '') elif len(parts) == 2: class_and_title = ('', '') else: class_and_title = (parts[2], parts[3]) if options.days >= 0: lt = dt.date.fromtimestamp(prev_time) nt = dt.date.fromtimestamp(time.time()) delta = nt - lt if delta.days > options.days-1: break sbd.add_data(prev_time, next_time, class_and_title) if options.plot_minute: mh.add_data(prev_time, next_time, class_and_title) if options.plot_day_of_week: dwh.add_data(prev_time, next_time, class_and_title) if is_productive(class_and_title[0], class_and_title[1]): pass else: if options.show_unproductive: print class_and_title[0], class_and_title[1] if options.plot_minute: mh.plot() elif options.plot_day_of_week: dwh.plot() else: sbd.summarize()
def add_increment(self, class_and_title, prev_time, time_incr, idle, write=False): if not idle and class_and_title != ('', ''): self.total_time += time_incr if write: # we don't want to save entries that have been read before if self.prev_class_and_title == class_and_title: self.ct_file.seek(self.prev_tell) self.ct_file.write("%f %f %s\n" % (self.prev_start_time, time(), " ".join(class_and_title))) else: self.prev_start_time = prev_time self.prev_class_and_title = class_and_title self.prev_tell = self.ct_file.tell() self.ct_file.write("%f %f %s\n" % (self.prev_start_time, time(), " ".join(class_and_title))) self.ct_file.flush() class_and_title = (class_and_title[0].strip('"'), class_and_title[1].strip('"')) by_class_title[class_and_title] += time_incr by_title[class_and_title[1]] += time_incr by_class[class_and_title[0]] += time_incr if not is_ignored(class_and_title[0], class_and_title[1]): if is_productive(class_and_title[0], class_and_title[1]): self.productive += time_incr else: self.unproductive += time_incr else: self.prev_idle_time = time() #most = sorted(by_class_title.iteritems(), key=operator.itemgetter(1), reverse=True) most = sorted(by_class.iteritems(), key=operator.itemgetter(1), reverse=True) most1 = sorted(by_class_title.iteritems(), key=operator.itemgetter(1), reverse=True) print chr(27) + "[2J" + chr(27) + "[;H" ''' print "xss_info.window:", xss_info.contents.window print "xss_info.state:", xss_info.contents.state print "xss_info.kind:", xss_info.contents.kind print "xss_info.since:", xss_info.contents.since print "xss_info.idle:", xss_info.contents.idle ''' if self.productive > self.unproductive: print "%.3f %s %s" % ( self.productive / (self.productive + self.unproductive), strftime("%H:%M:%S", localtime(self.productive + timezone)), "productive") print "%.3f %s %s" % ( self.unproductive / (self.productive + self.unproductive), strftime("%H:%M:%S", localtime(self.unproductive + timezone)), "unproductive") else: print "%.3f %s %s" % ( self.unproductive / self.total_time, strftime("%H:%M:%S", localtime(self.unproductive + timezone)), "unproductive") print "%.3f %s %s" % ( self.productive / self.total_time, strftime("%H:%M:%S", localtime(self.productive + timezone)), "productive") print ''' if self.unproductive < 0.25 * self.total_time: print "Free time: %s" % ( strftime("%H:%M:%S", localtime(0.25 * self.total_time - self.unproductive + timezone))) if self.unproductive < (1/3.) * self.productive: print "Free time: %s" % ( strftime("%H:%M:%S", localtime((1/3.) * self.productive - self.unproductive + timezone))) else: print "Free time: 00:00:00 Time to make up: %s" % ( strftime("%H:%M:%S", localtime((self.unproductive * 3.) - self.productive + timezone))) ''' print "Ratio (productive / unproductive): %.3f" % ( self.productive / (self.unproductive + 0.1)) print '---------------------------------------------------------' for i in xrange(min(10, len(most))): #print "%.3f %6.1f %s" % ( most[i][1] / self.total_time, most[i][1] , most[i][0]) print "%.3f %s %s" % (most[i][1] / self.total_time, strftime("%H:%M:%S", localtime(most[i][1] + timezone)), most[i][0]) print print print "Active time: %s Total active time: %s Total time: %s Start time: %s" % ( strftime("%H:%M:%S", localtime(time() - self.prev_idle_time + timezone)), strftime("%H:%M:%S", localtime(self.total_time + timezone)), strftime("%H:%M:%S", localtime(time() - self.start_time + timezone)), strftime("%H:%M:%S", localtime(self.start_time))) print '---------------------------------------------------------' for i in xrange(min(20, len(most1))): #print "%.3f %6.1f %s" % ( most[i][1] / self.total_time, most[i][1] , most[i][0]) if is_productive(most1[i][0][0], most1[i][0][1]): prod_str = 'P' else: prod_str = 'U' print "%.3f %s %s %s" % ( most1[i][1] / self.total_time, prod_str, strftime("%H:%M:%S", localtime(most1[i][1] + timezone)), most1[i][0]) self.prev_time = time() sys.stdout.flush()