Mercurial > getan
annotate scripts/getan-report.py @ 382:7a63212924c3
Rename getan_report.py to getan-report.py
All scripts are using the minus symbol do split words.
author | Björn Ricks <bjoern.ricks@intevation.de> |
---|---|
date | Mon, 05 Jan 2015 11:04:07 +0100 |
parents | scripts/getan_report.py@20fde79f8e12 |
children | 0fd096670ae7 |
rev | line source |
---|---|
378
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
1 #!/usr/bin/env python3 |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
2 """write a daily report accessing a database from http://hg.intevation.de/getan 1.1dev3.""" |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
3 # hastily done, written to learn the getan database format and its manipulation |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
4 # Free Software under GNU GPL v>=3 |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
5 # 20130109 bernhard@intevation.de |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
6 # 20140103 bernhard@intevation.de: |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
7 # started from 2013/getan-writeout-timesorted.py |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
8 # ported to python3. Removed the dependency for functions from worklog.py. |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
9 # the timesorted variant can be uncommented in the code for now |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
10 # 20140109 bernhard@intevation.de: |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
11 # Total time output format improved. |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
12 # 20140120 bernhard@intevation.de: |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
13 # added command line options, requires argparse module now (e.g. Python>=3.2) |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
14 # 20141104 bernhard@intevation.de: |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
15 # migration to argparse complete, added -t option |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
16 # TODO: |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
17 # * use python v>=3.2 variants in the code where noted. |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
18 |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
19 import argparse |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
20 import datetime |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
21 import logging |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
22 import sqlite3 |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
23 import sys |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
24 |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
25 factor = {'privat' : 0} |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
26 |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
27 l = logging |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
28 l.basicConfig(level=logging.INFO, |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
29 #l.basicConfig(level=logging.DEBUG, |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
30 format='%(message)s') |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
31 # format='%(asctime)s %(levelname)s %(message)s') |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
32 |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
33 def hhhmm_from_timedelta(td): |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
34 """Return a string '-HHH:MM' from the timedelta parameter. |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
35 |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
36 Accounts for way the integer division works for negative numbers: |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
37 -2 // 60 == -1 |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
38 -2 % 60 == 58 |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
39 by first working on the positive number and then adding the minus |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
40 to the string. |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
41 |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
42 For python >=3.1. Successor of hhmm_from_timedelta() from |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
43 http://intevation.de/cgi-bin/viewcvs-misc.cgi/worklog.py/ . |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
44 """ |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
45 total_minutes = abs(round(td.days*24*60 + td.seconds/60)) |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
46 # variant for Python v>3.2: |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
47 #total_minutes = abs(round(td/datetime.timedelta(minutes=1))) |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
48 |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
49 hours = total_minutes//60 |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
50 minutes = total_minutes%60 |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
51 |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
52 h_string = "{}".format(hours) |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
53 |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
54 if(td.days<0): |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
55 h_string = "-" + h_string |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
56 |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
57 return "{:>3s}:{:02d}".format(h_string, minutes) |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
58 |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
59 def self_test(): |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
60 """Run some simple tests on hhhmm_from_timedelta(). |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
61 |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
62 e.g. run like |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
63 python3 -c 'from getan_report_20140103 import *; self_test()' |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
64 """ |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
65 l.info(hhhmm_from_timedelta(datetime.timedelta(minutes=1))) |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
66 l.info(hhhmm_from_timedelta(datetime.timedelta(minutes=-2))) |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
67 |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
68 def main(): |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
69 parser = argparse.ArgumentParser(description=__doc__) |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
70 parser.add_argument("-t", action='store_true', |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
71 help="timesorted output and default reportday to today") |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
72 parser.add_argument("dbfilename") |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
73 parser.add_argument("reportday", nargs='?', |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
74 help="day to report yyyy-mm-dd") |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
75 |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
76 args = parser.parse_args() |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
77 l.debug(args) |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
78 |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
79 if args.reportday: |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
80 report_range_start = \ |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
81 datetime.datetime.strptime(args.reportday, "%Y-%m-%d") |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
82 elif args.t: |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
83 # start with today 00:00 |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
84 report_range_start = datetime.datetime.combine( |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
85 datetime.date.today(), datetime.time()) |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
86 else: |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
87 # start with yesterday 00:00 |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
88 report_range_start = datetime.datetime.combine( |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
89 datetime.date.today() - datetime.timedelta(days=1), |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
90 datetime.time()) |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
91 report_range_end = report_range_start + datetime.timedelta(days=1) |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
92 |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
93 |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
94 l.info("Opening sqlite3 database '%s'" % args.dbfilename) |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
95 conn = sqlite3.connect(args.dbfilename, detect_types=sqlite3.PARSE_DECLTYPES|sqlite3.PARSE_COLNAMES) |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
96 c = conn.cursor() |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
97 |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
98 tasks = {} |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
99 task_total = {} |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
100 |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
101 c.execute('select * from projects') |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
102 for t in c: |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
103 l.debug(t) |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
104 tasks[t[0]] = t[2] |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
105 task_total[t[0]] = datetime.timedelta() |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
106 |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
107 # from getan 1.0 20130103 |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
108 #CREATE TABLE entries ( |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
109 # id INTEGER PRIMARY KEY AUTOINCREMENT, |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
110 # project_id INTEGER REFERENCES projects(id), |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
111 # start_time TIMESTAMP NOT NULL, |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
112 # stop_time TIMESTAMP NOT NULL, |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
113 # description VARCHAR(256), |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
114 # |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
115 # CHECK (strftime('%s', start_time) <= strftime('%s', stop_time)) |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
116 #); |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
117 |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
118 total_time = datetime.timedelta() |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
119 |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
120 if args.t: |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
121 c.execute('select * from entries order by start_time') |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
122 else: |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
123 c.execute('select * from entries order by project_id') |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
124 for e in c: |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
125 l.debug(e) |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
126 length = e[3]-e[2] |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
127 |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
128 desc = tasks[e[1]] |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
129 |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
130 if e[2] >= report_range_start and e[2] < report_range_end: |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
131 if args.t: |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
132 print("{2}: {3} {4}\n\t\t\t{0} {1}". |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
133 format(e[2], e[3], desc, e[4],hhhmm_from_timedelta(length))) |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
134 else: |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
135 print("{0} {2}: {3} {4}". |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
136 format(e[2], e[3], desc, e[4],hhhmm_from_timedelta(length))) |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
137 if desc in factor: |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
138 ##python3.1 does not allow timedelta division. |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
139 ##TODO: Make python3.1 save or update to python3.2. |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
140 #l.info("applying factor %f to entry %s" % (factor[desc], e)) |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
141 #length = (length * int(factor[desc]*1000))/1000 |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
142 #Until python3.2 we only honor a factor of zero: |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
143 if factor[desc] == 0: |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
144 length = datetime.timedelta(0) |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
145 l.info("not counting {}".format(e)) |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
146 else: |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
147 l.info("ignoring factor {}".factor[desc]) |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
148 total_time += length |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
149 task_total[e[1]] += length |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
150 |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
151 print("(" + hhhmm_from_timedelta(total_time).strip() + ")") |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
152 for t in tasks: |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
153 if task_total[t] != datetime.timedelta(0): |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
154 print("\t" + tasks[t], hhhmm_from_timedelta(task_total[t])) |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
155 |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
156 c.close() |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
157 |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
158 if __name__ == "__main__": |
bdc4e45f9f4f
Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
159 main() |