summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2013-05-23 23:25:05 +0100
committerdakkar <dakkar@thenautilus.net>2013-05-23 23:25:05 +0100
commit0370a468d9ff22b47e6eabcb995f68ee997793de (patch)
tree735b7685fc076035fde8f242b5a2b2ef26b51d53
parentmore sample data (diff)
downloadHomePanel-0370a468d9ff22b47e6eabcb995f68ee997793de.tar.gz
HomePanel-0370a468d9ff22b47e6eabcb995f68ee997793de.tar.bz2
HomePanel-0370a468d9ff22b47e6eabcb995f68ee997793de.zip
DataBlock slices, better spans and stripes
-rw-r--r--forecast.html.tt36
-rw-r--r--lib/WebService/ForecastIo/DataBlock.pm23
2 files changed, 45 insertions, 14 deletions
diff --git a/forecast.html.tt b/forecast.html.tt
index 57edfb7..d45e2db 100644
--- a/forecast.html.tt
+++ b/forecast.html.tt
@@ -1,7 +1,15 @@
[%
cur = f.currently; today = f.daily.data.0;
- MACRO hours_length BLOCK;
- span.stop_time.subtract_datetime(span.start_time).in_units('hours');
+ 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);
+ v=d.in_units('days','hours');
+ v.0 * 24 + v.1;
+ END;
+ MACRO time(d) BLOCK;
+ d.clone.set_time_zone('Europe/London').strftime('%H:%M');
END;
-%]
<html>
@@ -58,10 +66,10 @@
</div>
<div class="next-day">
<h2>Next 24 hours</h2>
- <span class="icon"><img src="[% icon_for(f.hourly.icon) %]" alt="[% f.hourly.icon %]" /></span>
+ <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">[% f.hourly.summary %]</dd>
+ <dd class="summary">[% hourly.summary %]</dd>
</dl>
</div>
<div class="next-week">
@@ -79,28 +87,28 @@
<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">[% today.temperatureMinTime.strftime('%H:%M') %]</span></dd>
+ <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">[% today.temperatureMaxTime.strftime('%H:%M') %]</span></dd>
+ <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">[% today.sunriseTime.strftime('%H:%M') %]</span></dd>
+ <dd class="sunrise"><span class="time">[% time(today.sunriseTime) %]</span></dd>
<dt class="sunset">Sunset:</dt>
- <dd class="sunset"><span class="time">[% today.sunsetTime.strftime('%H:%M') %]</span></dd>
+ <dd class="sunset"><span class="time">[% time(today.sunsetTime) %]</span></dd>
</dl>
<div class="timeline">
<div class="summary">
- [% left=0 ;FOR span IN f.hourly.spans_by_string('summary');
- width=3*hours_length(span=span) %]
- <span class="stripes" style="width: [% width %]em; left: [% left %]em"><span>[% span.value %] [% span.start_time %] [% span.stop_time %]</span></span>
+ [% 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 span IN [ 0 .. 23 ] %]
- <span class="stripes" style="width: 3em; left: [% left %]em"><span>[% span %]</span></span>
+ [% 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 f.hourly.data %]
+ [% 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>
diff --git a/lib/WebService/ForecastIo/DataBlock.pm b/lib/WebService/ForecastIo/DataBlock.pm
index 42b3d0e..c01e1cf 100644
--- a/lib/WebService/ForecastIo/DataBlock.pm
+++ b/lib/WebService/ForecastIo/DataBlock.pm
@@ -42,6 +42,26 @@ sub spans_by_number {
);
}
+sub slice {
+ my ($self,%opts) = @_;
+
+ my $from = $opts{from} // 0-'Inf';
+ my $to = $opts{to} // 0+'Inf';
+
+ warn "slicing $from $to\n";
+
+ return ref($self)->new({
+ summary => $self->summary,
+ icon => $self->icon,
+ data => [
+ grep {
+ warn "looking at ".$_->time."\n";
+ $_->time >= $from && $_->time <= $to }
+ $self->data_points
+ ],
+ });
+}
+
sub _spans {
my ($self,$field,$comp) = @_;
@@ -68,6 +88,9 @@ sub _spans {
}
}
}
+ if (@$out) {
+ $out->[-1]->_set_stop_time($self->data->[-1]->time);
+ }
return $out;
}