# HG changeset patch # User Daniele Nicolodi # Date 1320626720 -3600 # Node ID 3974044734309c85020a5804481b908e56c8ad62 # Parent 6b5fa909bce3fee20d3f16cef9bffd36263a5b93 Polish and extend activity view to show activity per day. diff -r 6b5fa909bce3 -r 397404473430 src/ltpdarepo/static/style.css --- a/src/ltpdarepo/static/style.css Mon Nov 07 01:45:16 2011 +0100 +++ b/src/ltpdarepo/static/style.css Mon Nov 07 01:45:20 2011 +0100 @@ -295,8 +295,8 @@ .activity { border: 1px solid #CCC; + margin: 0; padding: 2px; - margin: 0; box-shadow: 0px 0px 2px #DDD; -moz-box-shadow: 0px 0px 2px #DDD; -webkit-box-shadow: 0px 0px 2px #DDD; @@ -304,38 +304,37 @@ .activity table { width: 100%; - border-collapse: collapse; } .activity td { - margin: 0; - padding: 4px 0; border: none; font-size: 90%; + padding: 4px 0; } -.activity td span.num { +.activity .bars span { display: inline-block; - width: 2em; - visibility: hidden; font-size: 90%; padding: 2px 0; + visibility: hidden; + width: 2em; } -.activity td:hover span.num { +.activity td:hover span { visibility: visible; - color: red; } -.activity td.bars { +.activity .bars { padding: 0 1px; margin: 0; vertical-align: bottom; } -.activity td div { +.activity .bars a { background: #DDD; border-bottom: 2px solid #DDD; + cursor: default; + display: block; width: 100%; } diff -r 6b5fa909bce3 -r 397404473430 src/ltpdarepo/templates/activity.html --- a/src/ltpdarepo/templates/activity.html Mon Nov 07 01:45:16 2011 +0100 +++ b/src/ltpdarepo/templates/activity.html Mon Nov 07 01:45:20 2011 +0100 @@ -2,28 +2,40 @@ {% block title %}{{ database.id }}{% endblock %} {% block body %}

Database «{{ database.id }}»

-

{{ database.description }}

-

Objects submitted per day in {{ curr.strftime('%B %Y') }}

-
-
- prev - next +

{{ database.description }}

+

 

+ +
- {% for day, num in activity %} - {% set height = num * 300 / nmax %} + {% for when, num in activity %} + {% set height = num * 300 / nmax %} {% endfor %} {% for when, num in activity %} - + {% set url = url_for('browse.query', database=database.id, field=('submitted', 'submitted'), operator=('>', '<'), value=(when, when + dt)) %} + {% endfor %}
- {{ num }}
 
+ {{ num }}
{{ when.strftime('%d') }}{{ when.strftime(frmt) }}
diff -r 6b5fa909bce3 -r 397404473430 src/ltpdarepo/views/browse.py --- a/src/ltpdarepo/views/browse.py Mon Nov 07 01:45:16 2011 +0100 +++ b/src/ltpdarepo/views/browse.py Mon Nov 07 01:45:20 2011 +0100 @@ -656,28 +656,48 @@ @app.route('//activity') +@app.route('//activity/') @require('user') -def activity(database, date=None): +def activity(database, when=None): with view('database', database): db = Database().load(database) if db is None: # not found abort(404) + # defaults today = datetime.today().date() - date = request.args.get('date') - if date is not None: - today = datetime.strptime(date, '%Y-%m-%d').date() + span = 'MONTH' + + if when is not None: + if when.count('-') == 2: + span = 'DAY' + today = datetime.strptime(when, '%Y-%m-%d').date() + if when.count('-') == 1: + span = 'MONTH' + today = datetime.strptime(when, '%Y-%m').date() + - begin = today + relativedelta(day=1) - end = begin + relativedelta(months=1, days=-1) - prev = begin + relativedelta(months=-1) - next = begin + relativedelta(months=+1) + if span == 'MONTH': + begin = today + relativedelta(day=1) + end = begin + relativedelta(months=1, days=-1) + prev = (begin + relativedelta(months=-1)).strftime('%Y-%m') + next = (begin + relativedelta(months=+1)).strftime('%Y-%m') + increment = 'DAY' + dt = relativedelta(days=1) + + if span == 'DAY': + begin = today + relativedelta(hour=0) + end = begin + relativedelta(hour=0, days=1) + prev = (begin + relativedelta(days=-1)).strftime('%Y-%m-%d') + next = (begin + relativedelta(days=+1)).strftime('%Y-%m-%d') + increment = 'HOUR' + dt = relativedelta(hours=1) curs = g.db.cursor() # prepare timeintervals table with proper intervals - curs.execute("""CALL makeintervals(%s, %s, 1, 'DAY')""", (begin, end)) + curs.execute("""CALL makeintervals(%s, %s, 1, %s)""", (begin, end, increment)) # collect number of objects for each interval curs.execute("""SELECT ts.begin AS date, COUNT(objmeta.obj_id) AS count @@ -694,7 +714,7 @@ nmax = ceil(nmax / base)*base return render_template('activity.html', database=db, activity=activity, nmax=nmax, - curr=today, prev=prev, next=next, dt=relativedelta(days=1)) + curr=today, prev=prev, next=next, span=span, dt=dt) module = app