Skip to content

Commit

Permalink
Pull reporting options into config
Browse files Browse the repository at this point in the history
  • Loading branch information
harto committed Nov 2, 2012
1 parent f1f1452 commit 509e203
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 15 deletions.
8 changes: 8 additions & 0 deletions config.example.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@
# 'alecsloman',
),

# Reporting options
# Size of reporting window: one of week, sprint, month
'reporting.window': 'month',
# Uncomment & edit these when reporting.window == sprint
# 'reporting.sprint_start_weekday': 'monday',
# 'reporting.sprint_length_weeks': 2,
# 'reporting.first_sprint_week_of_year': 1,

# Whether to display the interactive debugger on error
# Don't enable this in publicly-accessible environments
'flask.debug': False,
Expand Down
29 changes: 18 additions & 11 deletions src/survivor/reporting.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,37 @@
"""
Report generation helpers.
Reporting helpers
The functions defined here take some date within a reporting period and
return the start and end dates of that period.
These functions take some date within a reporting period and return the start
and end dates of that period.
"""

from collections import namedtuple
from datetime import datetime, timedelta
from dateutil.relativedelta import relativedelta, FR, SU
from dateutil.relativedelta import relativedelta
from dateutil import relativedelta as days

from survivor import config

Period = namedtuple('Period', 'start end')

### Weekly reporting

def weekly_reporting_period(anchor, offset=0):
# Find Sunday in the given week
end = anchor + relativedelta(weeks=offset) + relativedelta(weekday=SU)
end = anchor + relativedelta(weeks=offset) + relativedelta(weekday=days.SU)
return Period(end - relativedelta(weeks=1), end)

### Sprint reporting

# TODO: move these into configuration
sprint_start_weekday = FR
sprint_length_weeks = 2
first_sprint_week_of_year = 1
def _sprint_start_weekday():
day_name = config['reporting.sprint_start_weekday']
return getattr(days, day_name[:2].upper())

def _sprint_end(anchor):
sprint_start_weekday = _sprint_start_weekday()
sprint_length_weeks = config['reporting.sprint_length_weeks']
first_sprint_week_of_year = config['reporting.first_sprint_week_of_year']

def sprint_end(anchor):
# Find the next instance of the sprint start/end weekday
# This will either be the end date of a sprint, or the equivalent
# weekday partway through a sprint
Expand All @@ -39,7 +45,8 @@ def sprint_end(anchor):
return anchor + relativedelta(weeks=sprint_weeks_remaining)

def sprint_reporting_period(anchor, offset=0):
end = sprint_end(anchor) + relativedelta(weeks=offset * sprint_length_weeks)
sprint_length_weeks = config['reporting.sprint_length_weeks']
end = _sprint_end(anchor) + relativedelta(weeks=offset * sprint_length_weeks)
return Period(end - relativedelta(weeks=sprint_length_weeks), end)

### Monthly reporting
Expand Down
8 changes: 4 additions & 4 deletions src/survivor/web/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from jinja2 import FileSystemLoader

import survivor
from survivor import reporting, timeutils
from survivor import reporting, timeutils, config
from survivor.models import User, Issue
from survivor.web import template

Expand Down Expand Up @@ -39,7 +39,7 @@ def reporting_period(unit, anchor, offset=0):
def dashboard():
today = timeutils.today()

reporting_unit = request_arg('reporting_unit', default='sprint')
reporting_unit = request_arg('reporting_unit', default=config['reporting.window'])
previous_periods = int(request_arg('previous_periods', default=12))

reporting_periods = [reporting_period(reporting_unit, today, -i)
Expand Down Expand Up @@ -131,7 +131,7 @@ def stats():
app.jinja_loader = FileSystemLoader(os.path.join(app_root, 'templates'))
app.static_folder = '%s/res/static' % app_root

try: app.debug = survivor.config['flask.debug']
try: app.debug = config['flask.debug']
except KeyError: pass

app.run(**survivor.config['flask.settings'])
app.run(**config['flask.settings'])

0 comments on commit 509e203

Please sign in to comment.