summaryrefslogtreecommitdiff
path: root/forecast.html.tt
blob: eedc078c6ede15bad70e81793cdcc32e83374e86 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
[%
 cur = f.currently; today = f.daily.data.0;
 today_start = f.hourly.data.0.time.clone
 today_stop = f.hourly.data.0.time.clone.add('days'=>1);
 hourly = f.hourly.slice('from', today_start, 'to', today_stop);
 MACRO hours_length(span) BLOCK;
  d=span.stop_time.subtract_datetime(span.start_time);
  format_duration(
    'pattern','%k',
    'base',span.start_time,
    'normalize',1).format_duration(d);
 END;
 MACRO time(d) BLOCK;
  d.clone.set_time_zone('Europe/London').strftime('%H:%M');
 END;
 MACRO minsec_until(d) BLOCK;
  dur=d.subtract_datetime(now);
  format_duration(
    'pattern','%M:%S',
    'base',now,
    'normalize',1).format_duration(dur);
 END;
-%]
<html>
  <head>
    <title>Forecast</title>
    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
    <style type="text/css">
      .icon img {
        width: 2em; height: 2em;
        float: left;
      }
      .timeline {
        position: relative;
        height: 6em;
      }
      .stripes {
        position: absolute;
        text-align: center;
        border: solid thin black;
        height: 2em; line-height: 2em;
      }
      .stripes span {
        font-size: 30%;
        vertical-align: middle;
      }
      .timeline .summary > span {
        top: 0;
      }
      .timeline .hours > span {
        top: 2em;
      }
      .timeline .temperature > span {
        top: 4em;
      }
    </style>
  </head>
  <body>
    <div class="forecast">
      <div class="currently">
        <h2>Currently</h2>
        <span class="icon"><img src="[% icon_for(cur.icon) %]" alt="[% cur.icon %]" /></span>
        <dl class="currently">
          <dt class="temperature">Temperature:</dt>
          <dd class="temperature">[% cur.temperature %]°</dd>
          <dt class="summary">Summary:</dt>
          <dd class="summary">[% cur.summary %]</dd>
        </dl>
      </div>
      <div class="next-hour">
        <h2>Next hour</h2>
        <span class="icon"><img src="[% icon_for(f.minutely.icon) %]" alt="[% f.minutely.icon %]" /></span>
        <dl class="next-hour">
          <dt class="summary">Summary:</dt>
          <dd class="summary">[% f.minutely.summary %]</dd>
        </dl>
      </div>
      <div class="next-day">
        <h2>Next 24 hours</h2>
        <span class="icon"><img src="[% icon_for(hourly.icon) %]" alt="[% hourly.icon %]" /></span>
        <dl class="next-day">
          <dt class="summary">Summary:</dt>
          <dd class="summary">[% hourly.summary %]</dd>
        </dl>
      </div>
      <div class="next-week">
        <h2>Next 7 days</h2>
        <span class="icon"><img src="[% icon_for(f.daily.icon) %]" alt="[% f.daily.icon %]" /></span>
        <dl class="next-week">
          <dt class="summary">Summary:</dt>
          <dd class="summary">[% f.daily.summary %]</dd>
        </dl>
      </div>
      <div class="days">
        <div class="day today">
          <span class="icon"><img src="[% icon_for(today.icon) %]" alt="[% today.icon %]" /></span>
          <dl class="today">
            <dt class="summary">Summary:</dt>
            <dd class="summary">[% today.summary %]</dd>
            <dt class="temperature min">Min temperature:</dt>
            <dd class="temperature min">[% today.temperatureMin %]° <span class="time">[% time(today.temperatureMinTime) %]</span></dd>
            <dt class="temperature max">Max temperature:</dt>
            <dd class="temperature max">[% today.temperatureMax %]° <span class="time">[% time(today.temperatureMaxTime) %]</span></dd>
            <dt class="sunrise">Sunrise:</dt>
            <dd class="sunrise"><span class="time">[% time(today.sunriseTime) %]</span></dd>
            <dt class="sunset">Sunset:</dt>
            <dd class="sunset"><span class="time">[% time(today.sunsetTime) %]</span></dd>
          </dl>
          <div class="timeline">
            <div class="summary">
              [% left=0 ;FOR span IN hourly.spans_by_string('summary');
              width=3*hours_length(span) %]
              <span class="stripes" style="width: [% width %]em; left: [% left %]em"><span>[% span.value %]</span></span>
              [% left=left+width; END %]
            </div>
            <div class="hours">
              [% left=0; FOR h IN hourly.data; BREAK IF loop.last %]
              <span class="stripes" style="width: 3em; left: [% left %]em"><span>[% time(h.time) %]</span></span>
              [% left=left+3; END %]
            </div>
            <div class="temperature">
              [% left=0; FOR h IN hourly.data; BREAK IF loop.last %]
              <span class="stripes" style="width: 3em; left: [% left %]em"><span>[% h.temperature %]°</span></span>
              [% left=left+3; END %]
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="bus">
      <table class="prediction">
        <thead>
          <tr><th>Line</th><th>Destination</th><th>When</th></tr>
        </thead>
        <tbody>
          [% FOREACH p IN b.Prediction %]
          <tr>
            <td>[% p.LineName %]</td>
            <td>[% p.DestinationText %]</td>
            <td>[% minsec_until(p.EstimatedTime) %]</td>
          </tr>
          [% END %]
        </tbody>
      </table>
    </div>
    <div class="tube">
      <table class="status">
        <thead>
          <tr><th>Line</th><th>Status</th><th>Details</th></tr>
        </thead>
        <tbody>
          [% FOREACH line IN t.lines %]
          <tr>
            <td>[% line.name %]</td>
            <td>[% line.status.description %]</td>
            <td>[% line.status.details %]</td>
          </tr>
          [% END %]
        </tbody>
      </table>
    </div>
  </body>
</html>