annotate scripts/getan-daily-report @ 541:a12301b219fa

merge
author Bernhard Reiter <bernhard@intevation.de>
date Thu, 30 Jan 2020 10:48:21 +0100
parents a4044956e08c
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
533
a4044956e08c scripts/getan-daily-report: improve summary output
Bernhard Reiter <bernhard@intevation.de>
parents: 490
diff changeset
24 import locale
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
25 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
26 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
27
387
0fd096670ae7 Update coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 382
diff changeset
28 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
29
533
a4044956e08c scripts/getan-daily-report: improve summary output
Bernhard Reiter <bernhard@intevation.de>
parents: 490
diff changeset
30 # sets the locale for all categories to the user’s default setting
a4044956e08c scripts/getan-daily-report: improve summary output
Bernhard Reiter <bernhard@intevation.de>
parents: 490
diff changeset
31 #(typically specified in the LANG environment variable).
a4044956e08c scripts/getan-daily-report: improve summary output
Bernhard Reiter <bernhard@intevation.de>
parents: 490
diff changeset
32 locale.setlocale(locale.LC_ALL, '')
a4044956e08c scripts/getan-daily-report: improve summary output
Bernhard Reiter <bernhard@intevation.de>
parents: 490
diff changeset
33
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
34 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
35 l.basicConfig(level=logging.INFO,
387
0fd096670ae7 Update coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 382
diff changeset
36 # l.basicConfig(level=logging.DEBUG,
0fd096670ae7 Update coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 382
diff changeset
37 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
38 # 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
39
387
0fd096670ae7 Update coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 382
diff changeset
40
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
41 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
42 """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
43
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 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
45 -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
46 -2 % 60 == 58
387
0fd096670ae7 Update coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 382
diff changeset
47 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
48 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
49
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 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
51 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
52 """
387
0fd096670ae7 Update coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 382
diff changeset
53 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
54 # variant for Python v>3.2:
387
0fd096670ae7 Update coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 382
diff changeset
55 # 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
56
387
0fd096670ae7 Update coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 382
diff changeset
57 hours = total_minutes // 60
0fd096670ae7 Update coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 382
diff changeset
58 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
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 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
61
387
0fd096670ae7 Update coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 382
diff changeset
62 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
63 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
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 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
66
387
0fd096670ae7 Update coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 382
diff changeset
67
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
68 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
69 """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
70
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 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
72 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
73 """
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 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
75 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
76
387
0fd096670ae7 Update coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 382
diff changeset
77
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
78 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
79 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
80 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
81 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
82 parser.add_argument("dbfilename")
387
0fd096670ae7 Update coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 382
diff changeset
83 parser.add_argument("reportday", nargs='?',
0fd096670ae7 Update coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 382
diff changeset
84 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
85
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 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
87 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
88
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 if args.reportday:
404
c272982799b5 scripts/getan-report.py: also accepts YYYYMMDD as reportdate.
Bernhard Reiter <bernhard@intevation.de>
parents: 403
diff changeset
90 try:
c272982799b5 scripts/getan-report.py: also accepts YYYYMMDD as reportdate.
Bernhard Reiter <bernhard@intevation.de>
parents: 403
diff changeset
91 report_range_start = \
c272982799b5 scripts/getan-report.py: also accepts YYYYMMDD as reportdate.
Bernhard Reiter <bernhard@intevation.de>
parents: 403
diff changeset
92 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
93 except ValueError:
c272982799b5 scripts/getan-report.py: also accepts YYYYMMDD as reportdate.
Bernhard Reiter <bernhard@intevation.de>
parents: 403
diff changeset
94 report_range_start = \
c272982799b5 scripts/getan-report.py: also accepts YYYYMMDD as reportdate.
Bernhard Reiter <bernhard@intevation.de>
parents: 403
diff changeset
95 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
96
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
97 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
98 # 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
99 report_range_start = datetime.datetime.combine(
387
0fd096670ae7 Update coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 382
diff changeset
100 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
101 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
102 # 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
103 report_range_start = datetime.datetime.combine(
387
0fd096670ae7 Update coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 382
diff changeset
104 datetime.date.today() - datetime.timedelta(days=1),
0fd096670ae7 Update coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 382
diff changeset
105 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
106 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
107
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 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
109 conn = sqlite3.connect(
0fd096670ae7 Update coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 382
diff changeset
110 args.dbfilename,
0fd096670ae7 Update coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 382
diff changeset
111 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
112 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
113
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 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
115 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
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 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
118 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
119 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
120 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
121 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
122
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 # from getan 1.0 20130103
387
0fd096670ae7 Update coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 382
diff changeset
124 # 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
125 # 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
126 # 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
127 # 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
128 # 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
129 # 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
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 # 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
132 # );
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 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
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 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
137 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
138 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
139 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
140 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
141 l.debug(e)
402
9d4a8f7da935 getan-report.py: ignores microseconds.
Bernhard Reiter <bernhard@intevation.de>
parents: 387
diff changeset
142 # let us ignore microseconds
9d4a8f7da935 getan-report.py: ignores microseconds.
Bernhard Reiter <bernhard@intevation.de>
parents: 387
diff changeset
143 start_time = e[2].replace(microsecond = 0)
9d4a8f7da935 getan-report.py: ignores microseconds.
Bernhard Reiter <bernhard@intevation.de>
parents: 387
diff changeset
144 stop_time = e[3].replace(microsecond = 0)
9d4a8f7da935 getan-report.py: ignores microseconds.
Bernhard Reiter <bernhard@intevation.de>
parents: 387
diff changeset
145 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
146
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 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
148
402
9d4a8f7da935 getan-report.py: ignores microseconds.
Bernhard Reiter <bernhard@intevation.de>
parents: 387
diff changeset
149 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
150 if args.t:
403
f656d9370085 getan-report.py: improves -t output format.
Bernhard Reiter <bernhard@intevation.de>
parents: 402
diff changeset
151 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
152 "{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
153 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
154 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
155 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
156 print("{0} {2}: {3} {4}".
402
9d4a8f7da935 getan-report.py: ignores microseconds.
Bernhard Reiter <bernhard@intevation.de>
parents: 387
diff changeset
157 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
158 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
159 if desc in factor:
387
0fd096670ae7 Update coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 382
diff changeset
160 # python3.1 does not allow timedelta division.
0fd096670ae7 Update coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 382
diff changeset
161 # 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
162 # 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
163 # length = (length * int(factor[desc]*1000))/1000
0fd096670ae7 Update coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 382
diff changeset
164 # 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
165 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
166 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
167 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
168 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
169 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
170 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
171 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
172
533
a4044956e08c scripts/getan-daily-report: improve summary output
Bernhard Reiter <bernhard@intevation.de>
parents: 490
diff changeset
173 print(report_range_start.strftime("%Y%m%d %a"), 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
174 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
175 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
176 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
177 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
178
bdc4e45f9f4f Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff changeset
179 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
180
bdc4e45f9f4f Added contrib/getan_report.py, a script to write a daily report by Bernhard Reiter.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff changeset
181 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
182 main()
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)