annotate scripts/getan-report.py @ 387:0fd096670ae7

Update coding style for pep8
author Björn Ricks <bjoern.ricks@intevation.de>
date Mon, 26 Jan 2015 13:09:52 +0100
parents 7a63212924c3
children 9d4a8f7da935
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
387
0fd096670ae7 Update coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 382
diff changeset
2 """
0fd096670ae7 Update coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 382
diff changeset
3 write a daily report accessing a database from
0fd096670ae7 Update coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 382
diff changeset
4 http://hg.intevation.de/getan 1.1dev3.
0fd096670ae7 Update coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 382
diff changeset
5 """
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
6 # 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
7 # 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
8 # 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
9 # 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
10 # 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
11 # 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
12 # 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
13 # 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
14 # 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
15 # 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
16 # 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
17 # 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
18 # migration to argparse complete, added -t option
387
0fd096670ae7 Update coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 382
diff changeset
19 # TODO:
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
20 # * 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
21
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 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
23 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
24 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
25 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
26
387
0fd096670ae7 Update coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 382
diff changeset
27 factor = {'privat': 0}
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
28
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 = 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
30 l.basicConfig(level=logging.INFO,
387
0fd096670ae7 Update coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 382
diff changeset
31 # l.basicConfig(level=logging.DEBUG,
0fd096670ae7 Update coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 382
diff changeset
32 format='%(message)s')
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
33 # 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
34
387
0fd096670ae7 Update coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 382
diff changeset
35
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
36 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
37 """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
38
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 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
40 -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
41 -2 % 60 == 58
387
0fd096670ae7 Update coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 382
diff changeset
42 by first working on the positive number and then adding the minus
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
43 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
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 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
46 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
47 """
387
0fd096670ae7 Update coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 382
diff changeset
48 total_minutes = abs(round(td.days * 24 * 60 + td.seconds / 60))
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
49 # variant for Python v>3.2:
387
0fd096670ae7 Update coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 382
diff changeset
50 # total_minutes = abs(round(td/datetime.timedelta(minutes=1)))
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
51
387
0fd096670ae7 Update coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 382
diff changeset
52 hours = total_minutes // 60
0fd096670ae7 Update coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 382
diff changeset
53 minutes = total_minutes % 60
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
54
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 = "{}".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
56
387
0fd096670ae7 Update coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 382
diff changeset
57 if(td.days < 0):
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
58 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
59
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 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
61
387
0fd096670ae7 Update coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 382
diff changeset
62
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
63 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
64 """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
65
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 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
67 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
68 """
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 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
70 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
71
387
0fd096670ae7 Update coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 382
diff changeset
72
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
73 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
74 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
75 parser.add_argument("-t", action='store_true',
387
0fd096670ae7 Update coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 382
diff changeset
76 help="timesorted output and default reportday to today")
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
77 parser.add_argument("dbfilename")
387
0fd096670ae7 Update coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 382
diff changeset
78 parser.add_argument("reportday", nargs='?',
0fd096670ae7 Update coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 382
diff changeset
79 help="day to report yyyy-mm-dd")
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
80
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 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
82 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
83
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 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
85 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
86 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
87 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
88 # 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
89 report_range_start = datetime.datetime.combine(
387
0fd096670ae7 Update coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 382
diff changeset
90 datetime.date.today(), datetime.time())
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
91 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
92 # 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
93 report_range_start = datetime.datetime.combine(
387
0fd096670ae7 Update coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 382
diff changeset
94 datetime.date.today() - datetime.timedelta(days=1),
0fd096670ae7 Update coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 382
diff changeset
95 datetime.time())
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
96 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
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 l.info("Opening sqlite3 database '%s'" % args.dbfilename)
387
0fd096670ae7 Update coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 382
diff changeset
99 conn = sqlite3.connect(
0fd096670ae7 Update coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 382
diff changeset
100 args.dbfilename,
0fd096670ae7 Update coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 382
diff changeset
101 detect_types=sqlite3.PARSE_DECLTYPES | sqlite3.PARSE_COLNAMES)
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
102 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
103
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 = {}
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 = {}
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 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
108 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
109 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
110 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
111 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
112
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 # from getan 1.0 20130103
387
0fd096670ae7 Update coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 382
diff changeset
114 # CREATE TABLE entries (
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
115 # 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
116 # 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
117 # 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
118 # 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
119 # 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
120 #
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 # CHECK (strftime('%s', start_time) <= strftime('%s', stop_time))
387
0fd096670ae7 Update coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 382
diff changeset
122 # );
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
123
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 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
125
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 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
127 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
128 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
129 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
130 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
131 l.debug(e)
387
0fd096670ae7 Update coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 382
diff changeset
132 length = e[3] - e[2]
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
133
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 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
135
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 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
137 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
138 print("{2}: {3} {4}\n\t\t\t{0} {1}".
387
0fd096670ae7 Update coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 382
diff changeset
139 format(e[2], e[3], desc, e[4],
0fd096670ae7 Update coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 382
diff changeset
140 hhhmm_from_timedelta(length)))
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
141 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
142 print("{0} {2}: {3} {4}".
387
0fd096670ae7 Update coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 382
diff changeset
143 format(e[2], e[3], desc, e[4],
0fd096670ae7 Update coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 382
diff changeset
144 hhhmm_from_timedelta(length)))
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
145 if desc in factor:
387
0fd096670ae7 Update coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 382
diff changeset
146 # python3.1 does not allow timedelta division.
0fd096670ae7 Update coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 382
diff changeset
147 # TODO: Make python3.1 save or update to python3.2.
0fd096670ae7 Update coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 382
diff changeset
148 # l.info("applying factor %f to entry %s" % (factor[desc], e))
0fd096670ae7 Update coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 382
diff changeset
149 # length = (length * int(factor[desc]*1000))/1000
0fd096670ae7 Update coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 382
diff changeset
150 # Until python3.2 we only honor a factor of zero:
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
151 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
152 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
153 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
154 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
155 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
156 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
157 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
158
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 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
160 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
161 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
162 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
163
bdc4e45f9f4f Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff changeset
164 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
165
bdc4e45f9f4f Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff changeset
166 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
167 main()
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)