Commits

Andy Mikhailenko committed 026f6d5

web: stripped down the dashboard, added day view (with prev/next links).

Comments (0)

Files changed (3)

timetra/web/__init__.py

     facts = storage.hamster_storage.get_todays_facts()
     stats = get_stats(facts)
     sleep_drift = drift.collect_drift_data(activity='sleeping', span_days=7)
-
     next_sleep = prediction.predict_next_occurence('sleeping')
+    day = datetime.date.today() - datetime.timedelta(days=1)
     return render_template('dashboard.html', facts=facts, stats=stats,
                            appraise_category=appraise_category,
                            sleep_drift=sleep_drift, next_sleep=next_sleep,
                            format_delta=format_delta, approx_time=approx_time,
-                           methodology=methodology)
+                           methodology=methodology, day=day)
+
+
+@blueprint.route('<int:year>/<int:month>/<int:day>/')
+def day_view(year, month, day):
+    day = datetime.date(year, month, day)
+    facts = storage.get_facts_for_day(day)
+    stats = get_stats(facts)
+    prev = day - datetime.timedelta(days=1)
+    next = day + datetime.timedelta(days=1)
+    return render_template('day.html', day=day, facts=facts, stats=stats,
+                           prev=prev, next=next)
 
 
 @blueprint.route('reports/drift/')

timetra/web/templates/dashboard.html

 {% block heading %} Dashboard: What's Up Today {% endblock %}
 {% block content %}
 
-    <div class="row">
-        <div class="alert alert-info">
-            <i class="icon-bell"></i>
-            {% if next_sleep.eta_is_negative %}
-                Я думал, ты уже спишь ≈{{ format_delta(next_sleep.eta) }}, чтобы проснуться около {{ next_sleep.end.strftime('%H:%M') }}. Уверен, что не пора?
-            {% else %}
-                Если
-                <strong>
-                    {% if next_sleep.eta.total_seconds() > 60*60 %}
-                        через {{ format_delta(next_sleep.eta, '{hours}') }} ч.
-                    {% else %}
-                        в течение часа
-                    {% endif %}
-                </strong>
-                уснешь, проснешься около {{ approx_time(next_sleep.end) }} после {{ format_delta(next_sleep.duration, '{hours}') }}-часового сна.
-            {% endif %}
-            (См. <a href="{{ url_for('timetra.report_drift') }}">режим сна</a> и <a href="{{ url_for('timetra.report_predictions') }}">список предсказаний</a>)
-        </div>
-
-        {% for message, category in methodology.analyse_day() %}
-            <div class="alert alert-{{category}}">
-                {{ message }}
-            </div>
-        {% endfor %}
-
-        <h2>Categories</h2>
-        <dl class="dl-horizontal">
-            {% for item in stats|reverse %}
-                <dt>{{ item.category }}</dt>
-                <dd>
-                    <div class="progress progress-{{ appraise_category(item.category) }}">
-                        <div class="bar" style="width: {{ item.percentage }}%;">
-                            {{ item.duration }}
-                        </div>
-                    </div>
-                </dd>
-            {% endfor %}
-        </dl>
+    <div class="alert alert-info">
+        <i class="icon-bell"></i>
+        {% if next_sleep.eta_is_negative %}
+            Я думал, ты уже спишь ≈{{ format_delta(next_sleep.eta) }}, чтобы проснуться около {{ next_sleep.end.strftime('%H:%M') }}. Уверен, что не пора?
+        {% else %}
+            Если
+            <strong>
+                {% if next_sleep.eta.total_seconds() > 60*60 %}
+                    через {{ format_delta(next_sleep.eta, '{hours}') }} ч.
+                {% else %}
+                    в течение часа
+                {% endif %}
+            </strong>
+            уснешь, проснешься около {{ approx_time(next_sleep.end) }} после {{ format_delta(next_sleep.duration, '{hours}') }}-часового сна.
+        {% endif %}
+        (См. <a href="{{ url_for('timetra.report_drift') }}">режим сна</a> и <a href="{{ url_for('timetra.report_predictions') }}">список предсказаний</a>)
     </div>
 
-    <h2>History</h2>
+    {% for message, category in methodology.analyse_day() %}
+        <div class="alert alert-{{category}}">
+            {{ message }}
+        </div>
+    {% endfor %}
 
-    {{ render_facts(facts|reverse, hide_date=True) }}
+    <h2>Категории</h2>
+    <dl class="dl-horizontal">
+        {% for item in stats|reverse %}
+            <dt>{{ item.category }}</dt>
+            <dd>
+                <div class="progress progress-{{ appraise_category(item.category) }}">
+                    <div class="bar" style="width: {{ item.percentage }}%;">
+                        {{ item.duration }}
+                    </div>
+                </div>
+            </dd>
+        {% endfor %}
+    </dl>
+
+    <h2>Последние факты</h2>
+
+    {{ render_facts(facts[-5:]|reverse, hide_date=True) }}
+
+    <a href="{{ url_for('timetra.day_view', year=day.year, month=day.month, day=day.day) }}" class="btn btn-primary btn-large">Смотреть весь день…</a>
+
 
 {% endblock %}

timetra/web/templates/day.html

+{% extends 'base.html' %}
+
+{% from "_helpers.html" import render_tags, render_facts %}
+
+{% block heading %} Facts for {{ day.strftime('%d %b %Y') }} {% endblock %}
+{% block content %}
+
+    <ul class="pager">
+        <li> {# class="previous">#}
+            <a href="{{ url_for('timetra.day_view', year=prev.year, month=prev.month, day=prev.day) }}">&larr; {{ prev.strftime('%e %b') }}</a>
+        </li>
+        <li>{{ day.strftime('%e %b %Y') }}</li>
+        <li> {# class="next">#}
+            <a href="{{ url_for('timetra.day_view', year=next.year, month=next.month, day=next.day) }}">{{ next.strftime('%e %b') }} &rarr;</a>
+        </li>
+    </ul>
+
+    <h2>History</h2>
+
+    {{ render_facts(facts, hide_date=True) }}
+
+{% endblock %}