Ejemplo n.º 1
0
    def _write_fact(self, report, fact):
        # no having end time is fine
        end_time_str, end_time_iso_str = "", ""
        if fact.end_time:
            end_time_str = fact.end_time.strftime('%H:%M')
            end_time_iso_str = fact.end_time.isoformat()

        category = ""
        if fact.category != _("Unsorted"):  #do not print "unsorted" in list
            category = fact.category

        data = dict(
            date=fact.date.strftime(
                # date column format for each row in HTML report
                # Using python datetime formatting syntax. See:
                # http://docs.python.org/library/time.html#time.strftime
                C_("html report", "%b %d, %Y")),
            date_iso=fact.date.isoformat(),
            activity=fact.activity,
            category=category,
            tags=fact.tags,
            start=fact.start_time.strftime('%H:%M'),
            start_iso=fact.start_time.isoformat(),
            end=end_time_str,
            end_iso=end_time_iso_str,
            duration=stuff.format_duration(fact.delta) or "",
            duration_minutes="%d" % (stuff.duration_minutes(fact.delta)),
            duration_decimal="%.2f" %
            (stuff.duration_minutes(fact.delta) / 60.0),
            description=fact.description or "")
        self.fact_rows.append(
            Template(self.fact_row_template).safe_substitute(data))
Ejemplo n.º 2
0
    def _write_fact(self, fact):
        # no having end time is fine
        end_time_str, end_time_iso_str = "", ""
        if fact.end_time:
            end_time_str = fact.end_time.strftime('%H:%M')
            end_time_iso_str = fact.end_time.isoformat()

        category = ""
        if fact.category != _("Unsorted"): #do not print "unsorted" in list
            category = fact.category


        data = dict(
            date = fact.date.strftime(
                   # date column format for each row in HTML report
                   # Using python datetime formatting syntax. See:
                   # http://docs.python.org/library/time.html#time.strftime
                   C_("html report","%b %d, %Y")),
            date_iso = fact.date.isoformat(),
            activity = fact.activity,
            category = category,
            tags = fact.tags,
            start = fact.start_time.strftime('%H:%M'),
            start_iso = fact.start_time.isoformat(),
            end = end_time_str,
            end_iso = end_time_iso_str,
            duration = stuff.format_duration(fact.delta) or "",
            duration_minutes = "%d" % (stuff.duration_minutes(fact.delta)),
            duration_decimal = "%.2f" % (stuff.duration_minutes(fact.delta) / 60.0),
            description = fact.description or ""
        )
        self.fact_rows.append(Template(self.fact_row_template).safe_substitute(data))
Ejemplo n.º 3
0
    def calculate_totals(self):
        if not self.facts:
            return
        facts = self.facts

        category_sums, activity_sums, tag_sums = defaultdict(dt.timedelta), defaultdict(dt.timedelta), defaultdict(dt.timedelta),

        for fact in facts:
            if self.selected_categories and fact.category not in self.selected_categories:
                continue
            if self.selected_activities and fact.activity not in self.selected_activities:
                continue
            if self.selected_tags and len(set(self.selected_tags) - set(fact.tags)) > 0:
                continue

            category_sums[fact.category] += fact.delta
            activity_sums[fact.activity] += fact.delta

            for tag in fact.tags:
                tag_sums[tag] += fact.delta

        total_label = _("%s hours tracked total") % locale.format("%.1f", stuff.duration_minutes([fact.delta for fact in facts]) / 60.0)
        self.get_widget("total_hours").set_text(total_label)


        for key in category_sums:
            category_sums[key] = stuff.duration_minutes(category_sums[key]) / 60.0

        for key in activity_sums:
            activity_sums[key] = stuff.duration_minutes(activity_sums[key]) / 60.0

        for key in tag_sums:
            tag_sums[key] = stuff.duration_minutes(tag_sums[key]) / 60.0


        #category totals
        if category_sums:
            if self.category_sums:
                category_sums = [(key, category_sums[key] or 0) for key in self.category_sums[0]]
            else:
                category_sums = sorted(category_sums.items(), key=lambda x:x[1], reverse = True)

            self.category_sums = zip(*category_sums)

        # activity totals
        if self.activity_sums:
            activity_sums = [(key, activity_sums[key] or 0) for key in self.activity_sums[0]]
        else:
            activity_sums = sorted(activity_sums.items(), key=lambda x:x[1], reverse = True)

        self.activity_sums = zip(*activity_sums)


        # tag totals
        if tag_sums:
            if self.tag_sums:
                tag_sums = [(key, tag_sums[key] or 0) for key in self.tag_sums[0]]
            else:
                tag_sums = sorted(tag_sums.items(), key=lambda x:x[1], reverse = True)
            self.tag_sums = zip(*tag_sums)
Ejemplo n.º 4
0
 def _write_fact(self, fact):
     fact.delta = stuff.duration_minutes(fact.delta)
     self.csv_writer.writerow([
         fact.activity, fact.start_time, fact.end_time, fact.delta,
         fact.category, fact.description, fact.tags, fact.redmine_issue_id,
         fact.redmine_time_activity_id
     ])
Ejemplo n.º 5
0
 def __init__(self, fact):
     self.fact = fact
     match = re.match(TICKET_NAME_REGEX, fact.activity)
     self.id = match.group(1)
     self.comment = self.get_text(fact)
     self.date = self.get_date(fact)
     self.time_worked = stuff.duration_minutes(fact.delta)
Ejemplo n.º 6
0
 def __init__(self, fact):
     self.fact = fact
     match = re.match(TICKET_NAME_REGEX, fact.activity)
     self.id = match.group(1)
     self.comment = self.get_text(fact)
     self.date = self.get_date(fact)
     self.time_worked = stuff.duration_minutes(fact.delta)
     self.activity = self.get_activity(fact)
Ejemplo n.º 7
0
 def _write_fact(self, fact):
     fact.delta = stuff.duration_minutes(fact.delta)
     self.csv_writer.writerow([fact.activity,
                               fact.start_time,
                               fact.end_time,
                               fact.delta,
                               fact.category,
                               fact.description,
                               fact.tags])
Ejemplo n.º 8
0
 def _write_fact(self, fact):
     activity = self.doc.createElement("activity")
     activity.setAttribute("name", fact.activity)
     activity.setAttribute("start_time", fact.start_time)
     activity.setAttribute("end_time", fact.end_time)
     activity.setAttribute("duration_minutes", str(stuff.duration_minutes(fact.delta)))
     activity.setAttribute("category", fact.category)
     activity.setAttribute("description", fact.description)
     activity.setAttribute("tags", fact.tags)
     self.activity_list.appendChild(activity)
Ejemplo n.º 9
0
 def _write_fact(self, file, fact):
     activity = self.doc.createElement("activity")
     activity.setAttribute("name", fact.activity)
     activity.setAttribute("start_time", fact.start_time)
     activity.setAttribute("end_time", fact.end_time)
     activity.setAttribute("duration_minutes",
                           str(stuff.duration_minutes(fact.delta)))
     activity.setAttribute("category", fact.category)
     activity.setAttribute("description", fact.description)
     activity.setAttribute("tags", fact.tags)
     self.activity_list.appendChild(activity)
Ejemplo n.º 10
0
 def __init__(self, fact):
     self.fact = fact
     rt_match = re.match(TICKET_NAME_REGEX, fact.activity)
     if rt_match:
         self.id = rt_match.group(1)
     jira_match = re.match(JIRA_ISSUE_NAME_REGEX, fact.activity)
     if jira_match:
         self.id = jira_match.group(1)
     self.comment = self.get_text(fact)
     self.date = self.get_date(fact)
     self.time_worked = stuff.duration_minutes(fact.delta)
Ejemplo n.º 11
0
 def __init__(self, fact):
     self.fact = fact
     rt_match = re.match(TICKET_NAME_REGEX, fact.activity)
     if rt_match:
         self.id = rt_match.group(1)
     jira_match = re.match(JIRA_ISSUE_NAME_REGEX, fact.activity)
     if jira_match:
         self.id = jira_match.group(1)
     self.comment = self.get_text(fact)
     self.date = self.get_date(fact)
     self.time_worked = stuff.duration_minutes(fact.delta)
Ejemplo n.º 12
0
    def __report(self, fact_row):
        fact = fact_row.fact
        logging.warn(fact_row.name)
        if runtime.get_external().tracker:
            match = re.match(TICKET_NAME_REGEX, fact.activity)
            #            if not fact_row.selected:
            #                logging.warn("Row not selected: %s" % fact.activity)
            if fact_row.selected and fact.end_time and match:
                ticket_id = match.group(1)
                text = self.get_text(fact)
                time_worked = stuff.duration_minutes(fact.delta)
                if runtime.get_external().tracker.comment(ticket_id, text, time_worked):
                    logging.warn("updated ticket #%s: %s - %s min" % (ticket_id, text, time_worked))
                    runtime.storage.update_fact(fact.id, fact, False, True)
                    fact_row.selected = False

            else:
                logging.warn("Not a RT ticket or in progress: %s" % fact.activity)
        else:
            logging.warn("Not connected to/logged in RT")
Ejemplo n.º 13
0
    def __report(self, fact_row):
        fact = fact_row.fact
        logging.warn(fact_row.name)
        if runtime.get_external().tracker:
            match = re.match(TICKET_NAME_REGEX, fact.activity)
            #            if not fact_row.selected:
            #                logging.warn("Row not selected: %s" % fact.activity)
            if fact_row.selected and fact.end_time and match:
                ticket_id = match.group(1)
                text = self.get_text(fact)
                time_worked = stuff.duration_minutes(fact.delta)
                if runtime.get_external().tracker.comment(
                        ticket_id, text, time_worked):
                    logging.warn("updated ticket #%s: %s - %s min" %
                                 (ticket_id, text, time_worked))
                    runtime.storage.update_fact(fact.id, fact, False, True)
                    fact_row.selected = False

            else:
                logging.warn("Not a RT ticket or in progress: %s" %
                             fact.activity)
        else:
            logging.warn("Not connected to/logged in RT")
Ejemplo n.º 14
0
 def _write_fact(self, file, fact):
     fact.delta = stuff.duration_minutes(fact.delta)
     self.csv_writer.writerow([
         fact.activity, fact.start_time, fact.end_time, fact.delta,
         fact.category, fact.description, fact.tags
     ])
Ejemplo n.º 15
0
    def calculate_totals(self):
        if not self.facts:
            return
        facts = self.facts

        category_sums, activity_sums, tag_sums = defaultdict(
            dt.timedelta), defaultdict(dt.timedelta), defaultdict(
                dt.timedelta),

        for fact in facts:
            if self.selected_categories and fact.category not in self.selected_categories:
                continue
            if self.selected_activities and fact.activity not in self.selected_activities:
                continue
            if self.selected_tags and len(
                    set(self.selected_tags) - set(fact.tags)) > 0:
                continue

            category_sums[fact.category] += fact.delta
            activity_sums[fact.activity] += fact.delta

            for tag in fact.tags:
                tag_sums[tag] += fact.delta

        total_label = _("%s hours tracked total") % locale.format(
            "%.1f",
            stuff.duration_minutes([fact.delta for fact in facts]) / 60.0)
        self.get_widget("total_hours").set_text(total_label)

        for key in category_sums:
            category_sums[key] = stuff.duration_minutes(
                category_sums[key]) / 60.0

        for key in activity_sums:
            activity_sums[key] = stuff.duration_minutes(
                activity_sums[key]) / 60.0

        for key in tag_sums:
            tag_sums[key] = stuff.duration_minutes(tag_sums[key]) / 60.0

        #category totals
        if category_sums:
            if self.category_sums:
                category_sums = [(key, category_sums[key] or 0)
                                 for key in self.category_sums[0]]
            else:
                category_sums = sorted(category_sums.items(),
                                       key=lambda x: x[1],
                                       reverse=True)

            self.category_sums = zip(*category_sums)

        # activity totals
        if self.activity_sums:
            activity_sums = [(key, activity_sums[key] or 0)
                             for key in self.activity_sums[0]]
        else:
            activity_sums = sorted(activity_sums.items(),
                                   key=lambda x: x[1],
                                   reverse=True)

        self.activity_sums = zip(*activity_sums)

        # tag totals
        if tag_sums:
            if self.tag_sums:
                tag_sums = [(key, tag_sums[key] or 0)
                            for key in self.tag_sums[0]]
            else:
                tag_sums = sorted(tag_sums.items(),
                                  key=lambda x: x[1],
                                  reverse=True)
            self.tag_sums = zip(*tag_sums)
Ejemplo n.º 16
0
    def calculate_totals(self):
        if not self.facts:
            return
        facts = []

        category_sums, activity_sums, tag_sums = defaultdict(dt.timedelta), defaultdict(dt.timedelta), defaultdict(dt.timedelta),

        for fact in self.facts:
            if self.selected_categories and fact.category not in self.selected_categories:
                continue
            if self.selected_activities and fact.activity not in self.selected_activities:
                continue
            if self.selected_tags:
                if fact.tags and not (set(self.selected_tags) & set(fact.tags)):
                    continue
                if not fact.tags and WITHOUT_TAG not in self.selected_tags:
                    continue
            facts.append(fact)
            
            category_sums[fact.category] += fact.delta
            activity_sums[fact.activity] += fact.delta
            
            if fact.tags:
                for tag in fact.tags:
                    tag_sums[tag] += fact.delta
            else:
                tag_sums[_(WITHOUT_TAG)] += fact.delta
                
        total_minutes = stuff.duration_minutes([fact.delta for fact in facts])
        total_label = _("%s hours (%s minutes) tracked total") % (locale.format("%.2f", total_minutes/60.0), locale.format("%d", total_minutes))
        self.get_widget("total_hours").set_text(total_label)


        for key in category_sums:
            category_minutes = stuff.duration_minutes(category_sums[key])
            category_sums[key] = category_minutes / 60.0

        for key in activity_sums:
            activity_minutes = stuff.duration_minutes(activity_sums[key])
            activity_sums[key] = activity_minutes / 60.0

        for key in tag_sums:
            tag_minutes = stuff.duration_minutes(tag_sums[key])
            tag_sums[key] = tag_minutes / 60.0


        #category totals
        if category_sums:
            if self.category_sums:
                category_sums = [(key, category_sums[key] or 0) for key in self.category_sums[0]]
            else:
                category_sums = sorted(category_sums.items(), key=lambda x:x[1], reverse = True)

            self.category_sums = zip(*category_sums)

        # activity totals
        if self.activity_sums:
            activity_sums = [(key, activity_sums[key] or 0) for key in self.activity_sums[0]]
        else:
            activity_sums = sorted(activity_sums.items(), key=lambda x:x[1], reverse = True)

        self.activity_sums = zip(*activity_sums)


        # tag totals
        if tag_sums:
            if self.tag_sums:
                tag_sums = [(key, tag_sums[key] or 0) for key in self.tag_sums[0]]
            else:
                tag_sums = sorted(tag_sums.items(), key=lambda x:x[1], reverse = True)
            self.tag_sums = zip(*tag_sums)