hamster-applet r621 - trunk/hamster



Author: tbaugis
Date: Sat Nov  8 10:29:02 2008
New Revision: 621
URL: http://svn.gnome.org/viewvc/hamster-applet?rev=621&view=rev

Log:
showing totals in report, fixes bug 549562

Modified:
   trunk/hamster/reports.py

Modified: trunk/hamster/reports.py
==============================================================================
--- trunk/hamster/reports.py	(original)
+++ trunk/hamster/reports.py	Sat Nov  8 10:29:02 2008
@@ -48,7 +48,7 @@
     <meta http-equiv="content-type" content="text/html; charset=utf-8" />
     <meta name="author" content="hamster-applet" />
     <title>%s</title>
-    <style>
+    <style type="text/css">
         body {
             padding: 12px;
         }
@@ -56,11 +56,18 @@
             border-bottom: 1px solid gray;
             padding-bottom: 4px;
         }
-        table {margin-left: 24px}
+        h2 {
+            margin-top: 2em;
+        }
+        table {
+            margin-left: 24px
+        }
         th {
             text-align: left;
         }
-        tr {padding: 6px;}
+        tr {
+            padding: 6px;
+        }
         td {
             padding: 2px;
             padding-right: 24px;
@@ -72,7 +79,6 @@
     
     report.write("<h1>%s</h1>" % title)
     
-    
     report.write("""<table>
         <tr>
             <th>""" + _("Date") + """</th>
@@ -85,6 +91,7 @@
     
     #get id of last activity so we know when to show current duration
     last_activity_id = storage.get_last_activity()["id"]
+    sum_time = {}
     
     for fact in facts:
         duration = None
@@ -101,7 +108,7 @@
             end_time_str = end_time.strftime('%H:%M')
 
         category = ""
-        if fact["category"] != _("Unsorted"): #do not print "unsorted"
+        if fact["category"] != _("Unsorted"): #do not print "unsorted" in list
             category = fact["category"]
         # fact date column in HTML report
         report.write("""<tr>
@@ -117,8 +124,37 @@
             fact["start_time"].strftime('%H:%M'),
             end_time_str,
             stuff.format_duration(duration) or ""))
+
+
+
+        # save data for summary table
+        if duration:
+            id_string = "<td>%s</td><td>%s</td>" % (fact["category"], fact["name"])
+            if id_string in sum_time:
+                sum_time[id_string] += duration
+            else:
+                sum_time[id_string] = duration
+     
+    report.write("</table>")
+
+    # summary table
+    report.write("\n<h2>%s</h2>\n" % _("Summary of Activities"))
+    report.write("""<table>
+    <tr>
+        <th>""" + _("Category") + """</th>
+        <th>""" + _("Activity") + """</th>
+        <th>""" + _("Duration") + """</th>
+    </tr>\n""")
+    tot_time = 0
+    for key in sorted(sum_time.keys()):
+        report.write("    <tr>%s<td>%s</td></tr>\n" % (key, stuff.format_duration(sum_time[key])))
+        tot_time += sum_time[key]
+    report.write("    <tr><th colspan=\"2\">Total Time:</th><th>%s</th></tr>\n" % (stuff.format_duration(tot_time)))
+    report.write("</table>\n")
+
+    report.write("</body>\n</html>")
+
     
-    report.write("</table></body></html>")
     report.close()
 
     webbrowser.open_new("file://"+report_path)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]