annotate scripts/getan-report.py @ 440:f441913a5cdc

TODO: adds task for displaying of licensing info.
author Bernhard Reiter <bernhard@intevation.de>
date Thu, 04 Jan 2018 10:59:19 +0100
parents c272982799b5
children
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:
404
c272982799b5 scripts/getan-report.py: also accepts YYYYMMDD as reportdate.
Bernhard Reiter <bernhard@intevation.de>
parents: 403
diff changeset
85 try:
c272982799b5 scripts/getan-report.py: also accepts YYYYMMDD as reportdate.
Bernhard Reiter <bernhard@intevation.de>
parents: 403
diff changeset
86 report_range_start = \
c272982799b5 scripts/getan-report.py: also accepts YYYYMMDD as reportdate.
Bernhard Reiter <bernhard@intevation.de>
parents: 403
diff changeset
87 datetime.datetime.strptime(args.reportday, "%Y-%m-%d")
c272982799b5 scripts/getan-report.py: also accepts YYYYMMDD as reportdate.
Bernhard Reiter <bernhard@intevation.de>
parents: 403
diff changeset
88 except ValueError:
c272982799b5 scripts/getan-report.py: also accepts YYYYMMDD as reportdate.
Bernhard Reiter <bernhard@intevation.de>
parents: 403
diff changeset
89 report_range_start = \
c272982799b5 scripts/getan-report.py: also accepts YYYYMMDD as reportdate.
Bernhard Reiter <bernhard@intevation.de>
parents: 403
diff changeset
90 datetime.datetime.strptime(args.reportday, "%Y%m%d")
c272982799b5 scripts/getan-report.py: also accepts YYYYMMDD as reportdate.
Bernhard Reiter <bernhard@intevation.de>
parents: 403
diff changeset
91
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
92 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
93 # 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
94 report_range_start = datetime.datetime.combine(
387
0fd096670ae7 Update coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 382
diff changeset
95 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
96 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
97 # 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
98 report_range_start = datetime.datetime.combine(
387
0fd096670ae7 Update coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 382
diff changeset
99 datetime.date.today() - datetime.timedelta(days=1),
0fd096670ae7 Update coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 382
diff changeset
100 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
101 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
102
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.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
104 conn = sqlite3.connect(
0fd096670ae7 Update coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 382
diff changeset
105 args.dbfilename,
0fd096670ae7 Update coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 382
diff changeset
106 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
107 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
108
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 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
110 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
111
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 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
113 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
114 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
115 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
116 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
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 # from getan 1.0 20130103
387
0fd096670ae7 Update coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 382
diff changeset
119 # 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
120 # 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
121 # 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
122 # 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
123 # 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
124 # 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
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 # 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
127 # );
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
128
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 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
130
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 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
133 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
134 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
135 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
136 l.debug(e)
402
9d4a8f7da935 getan-report.py: ignores microseconds.
Bernhard Reiter <bernhard@intevation.de>
parents: 387
diff changeset
137 # let us ignore microseconds
9d4a8f7da935 getan-report.py: ignores microseconds.
Bernhard Reiter <bernhard@intevation.de>
parents: 387
diff changeset
138 start_time = e[2].replace(microsecond = 0)
9d4a8f7da935 getan-report.py: ignores microseconds.
Bernhard Reiter <bernhard@intevation.de>
parents: 387
diff changeset
139 stop_time = e[3].replace(microsecond = 0)
9d4a8f7da935 getan-report.py: ignores microseconds.
Bernhard Reiter <bernhard@intevation.de>
parents: 387
diff changeset
140 length = stop_time - start_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
141
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 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
143
402
9d4a8f7da935 getan-report.py: ignores microseconds.
Bernhard Reiter <bernhard@intevation.de>
parents: 387
diff changeset
144 if start_time >= report_range_start and start_time < report_range_end:
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 args.t:
403
f656d9370085 getan-report.py: improves -t output format.
Bernhard Reiter <bernhard@intevation.de>
parents: 402
diff changeset
146 print("{0:%Y-%m-%d %H:%M}-\n"
f656d9370085 getan-report.py: improves -t output format.
Bernhard Reiter <bernhard@intevation.de>
parents: 402
diff changeset
147 "{1:%Y-%m-%d %H:%M} {4} {2}: {3}\n".
402
9d4a8f7da935 getan-report.py: ignores microseconds.
Bernhard Reiter <bernhard@intevation.de>
parents: 387
diff changeset
148 format(start_time, stop_time, desc, e[4],
387
0fd096670ae7 Update coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 382
diff changeset
149 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
150 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
151 print("{0} {2}: {3} {4}".
402
9d4a8f7da935 getan-report.py: ignores microseconds.
Bernhard Reiter <bernhard@intevation.de>
parents: 387
diff changeset
152 format(start_time, stop_time, desc, e[4],
387
0fd096670ae7 Update coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 382
diff changeset
153 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
154 if desc in factor:
387
0fd096670ae7 Update coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 382
diff changeset
155 # python3.1 does not allow timedelta division.
0fd096670ae7 Update coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 382
diff changeset
156 # 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
157 # 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
158 # length = (length * int(factor[desc]*1000))/1000
0fd096670ae7 Update coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 382
diff changeset
159 # 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
160 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
161 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
162 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
163 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
164 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
165 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
166 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
167
bdc4e45f9f4f Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff changeset
168 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
169 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
170 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
171 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
172
bdc4e45f9f4f Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff changeset
173 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
174
bdc4e45f9f4f Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff changeset
175 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
176 main()
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)