Easier to read presentation (more compact)

as suggested by @mwmiller
https://github.com/duckduckgo/zeroclickinfo-goodies/pull/734#issuecomment-63051123
master
youri 2014-11-15 11:35:07 +00:00
parent 881805111d
commit eaeac1aded
2 changed files with 26 additions and 22 deletions

View File

@ -25,7 +25,7 @@ triggers startend => "uptime", start => "uptime of";
# Near zero duration messages
my $JUST_NOW_MSG = "just now"; # from Time::Duration
my $LESS_THAN_ONE_SECOND_MSG = "Less than one second"; # from us
my $LESS_THAN_ONE_SECOND_MSG = "less than one second"; # from us
# Compute the downtime string durations (year, month, day)
@ -49,15 +49,16 @@ sub fix_just_now {
sub format_text {
my ($uptime_percentage, $downtime_year, $downtime_month, $downtime_day) = @_;
my $text = $uptime_percentage . " uptime\n";
$text .= "Implied downtimes\n";
if ($downtime_year eq $LESS_THAN_ONE_SECOND_MSG) {
$text .= "No downtime or less than a second during a year\n";
$text .= "No downtime or less than a second during a year";
return $text;
}
$text .= $downtime_day . " downtime per day\n";
$text .= $downtime_month . " downtime per month\n";
$text .= $downtime_year . " downtime per year\n";
$text .= "Daily: " . $downtime_day . "\n";
$text .= "Monthly: " . $downtime_month . "\n";
$text .= "Annually: " . $downtime_year;
return $text;
}
@ -65,16 +66,17 @@ sub format_text {
# Format response as HTML
sub format_html {
my ($uptime_percentage, $downtime_year, $downtime_month, $downtime_day) = @_;
my $html = '<div class="zci__caption">' . $uptime_percentage . " uptime</div>";
my $html = '<div class="zci__header">' . $uptime_percentage . " uptime</div>";
$html .= '<div class="zci__header__sub">Implied downtimes</div>';
if ($downtime_year eq $LESS_THAN_ONE_SECOND_MSG) {
$html .= '<div class="zci__content">No downtime or less than a second during a year</div>';
return $html;
}
$html .= '<div class="zci__content">' . $downtime_day . " downtime per day<br>";
$html .= $downtime_month . " downtime per month<br>";
$html .= $downtime_year . " downtime per year</div>";
$html .= '<div class="zci__content"> Daily: ' . $downtime_day . '<br>';
$html .= 'Monthly: ' . $downtime_month . '<br>';
$html .= 'Annually: ' . $downtime_year . '</div>';
return $html;
}

View File

@ -13,19 +13,21 @@ ddg_goodie_test(
# A complete text+html positive test
'uptime 99%' => test_zci(qr/^99% uptime.*/, html=>qr/.*/),
'uptime 99%' => test_zci(qr/.*14 minutes and 24 seconds downtime per day.*/, html=>qr/.*/),
'uptime 99%' => test_zci(qr/.*7 hours and 18 minutes downtime per month.*/, html=>qr/.*/),
'uptime 99%' => test_zci(qr/.*3 days and 16 hours downtime per year.*/, html=>qr/.*/),
'uptime 99%' => test_zci(qr/.*Implied downtimes.*/, html=>qr/.*/),
'uptime 99%' => test_zci(qr/.*Daily: 14 minutes and 24 seconds.*/, html=>qr/.*/),
'uptime 99%' => test_zci(qr/.*Monthly: 7 hours and 18 minutes.*/, html=>qr/.*/),
'uptime 99%' => test_zci(qr/.*Annually: 3 days and 16 hours$/, html=>qr/.*/),
'uptime 99%' => test_zci(qr/.*/, html=>qr/.*99% uptime.*/),
'uptime 99%' => test_zci(qr/.*/, html=>qr/.*14 minutes and 24 seconds downtime per day.*/),
'uptime 99%' => test_zci(qr/.*/, html=>qr/.*7 hours and 18 minutes downtime per month.*/),
'uptime 99%' => test_zci(qr/.*/, html=>qr/.*3 days and 16 hours downtime per year.*/),
'uptime 99%' => test_zci(qr/.*/, html=>qr/.*Implied downtimes.*/),
'uptime 99%' => test_zci(qr/.*/, html=>qr/.*Daily: 14 minutes and 24 seconds.*/),
'uptime 99%' => test_zci(qr/.*/, html=>qr/.*Monthly: 7 hours and 18 minutes.*/),
'uptime 99%' => test_zci(qr/.*/, html=>qr/.*Annually: 3 days and 16 hours.*/),
# Alternate trigger
'uptime of 99%' => test_zci(qr/^99% uptime.*/, html=>qr/.*/),
# Startend trigger
'99% uptime' => test_zci(qr/^99% uptime.*/, html=>qr/.*/),
'99% uptime' => test_zci(qr/^99% uptime$.*/, html=>qr/.*/),
# Decimal separator
'uptime 99,99%' => test_zci(qr/.*/, html=>qr/.*99,99% uptime.*/),
@ -38,12 +40,12 @@ ddg_goodie_test(
'uptime 99.999999999%' => test_zci(qr/.*/, html=>qr/.*No downtime or less than a second during a year.*/),
# Some parts (but not all) are below 1 second
'uptime 99.9999%' => test_zci(qr/.*/, html=>qr/.*31 seconds downtime per year.*/),
'uptime 99.9999%' => test_zci(qr/.*/, html=>qr/.*2 seconds downtime per month.*/),
'uptime 99.9999%' => test_zci(qr/.*/, html=>qr/.*Less than one second downtime per day.*/),
'uptime 99.99999%' => test_zci(qr/.*/, html=>qr/.*3 seconds downtime per year.*/),
'uptime 99.99999%' => test_zci(qr/.*/, html=>qr/.*Less than one second downtime per month.*/),
'uptime 99.99999%' => test_zci(qr/.*/, html=>qr/.*Less than one second downtime per day.*/),
'uptime 99.9999%' => test_zci(qr/.*/, html=>qr/.*Annually: 31 seconds.*/),
'uptime 99.9999%' => test_zci(qr/.*/, html=>qr/.*Monthly: 2 seconds.*/),
'uptime 99.9999%' => test_zci(qr/.*/, html=>qr/.*Daily: less than one second.*/),
'uptime 99.99999%' => test_zci(qr/.*/, html=>qr/.*Annually: 3 seconds.*/),
'uptime 99.99999%' => test_zci(qr/.*/, html=>qr/.*Monthly: less than one second.*/),
'uptime 99.99999%' => test_zci(qr/.*/, html=>qr/.*Daily: less than one second.*/),
# Lower limit
'uptime 0%' => test_zci(qr/.*/, html=>qr/.*0% uptime.*/),