Permalink
Browse files

Create EpiSequence.php

  • Loading branch information...
dlnetworks committed Feb 28, 2014
1 parent 0db3c0d commit 308ecc65dfa44d060afb0ba64e2fba4d309b39eb
Showing with 54 additions and 0 deletions.
  1. +54 −0 EpiSequence.php
View
@@ -0,0 +1,54 @@
<?php
class EpiSequence
{
private $timers, $min, $max, $width = 100;
public function __construct($timers)
{
$this->timers = $timers;
$min = PHP_INT_MAX;
$max = 0;
foreach($this->timers as $timer)
{
$min = min($timer['start'], $min);
$max = max($timer['end'], $max);
}
$this->min = $min;
$this->max = $max;
$this->range = $max-$min;
$this->step = floatval($this->range/$this->width);
}
public function renderAscii()
{
$tpl = '';
foreach($this->timers as $timer)
$tpl .= $this->tplAscii($timer);
return $tpl;
}
private function tplAscii($timer)
{
$lpad = $rpad = 0;
$lspace = $chars = $rspace = '';
if($timer['start'] > $this->min)
$lpad = intval(($timer['start'] - $this->min) / $this->step);
if($timer['end'] < $this->max)
$rpad = intval(($this->max - $timer['end']) / $this->step);
$mpad = $this->width - $lpad - $rpad;
if($lpad > 0)
$lspace = str_repeat(' ', $lpad);
if($mpad > 0)
$chars = str_repeat('=', $mpad);
if($rpad > 0)
$rspace = str_repeat(' ', $rpad);
$tpl = <<<TPL
({$timer['api']} :: code={$timer['code']}, start={$timer['start']}, end={$timer['end']}, total={$timer['time']})
[{$lspace}{$chars}{$rspace}]
TPL;
return $tpl;
}
}

0 comments on commit 308ecc6

Please sign in to comment.