コード例 #1
0
function test($edges, $data)
{
    $table = new Elkuku\Console\Helper\ConsoleTable();
    $table->setHeaders(array_merge(["Original"], array_map(function ($set) {
        if (empty($set)) {
            return "No edges";
        }
        array_walk($set, function (&$value, $key) {
            $value = "{$key}: " . $value;
        });
        return join(", ", array_values($set));
    }, $edges)));
    foreach ($data as $base => $candidates) {
        $base = (double) $base;
        // $rounder->printAnalysis($base);
        $row = [$base];
        foreach ($edges as $set) {
            $rounder = new BestPriceRounder($set);
            $row[] = $rounder->round($base);
        }
        $table->addRow($row);
    }
    echo $table->getTable();
}
コード例 #2
0
 public function printAnalysis($mixed, $to_string = false)
 {
     $analysis = $this->getAnalysis($mixed);
     $has_console_table = class_exists("Elkuku\\Console\\Helper\\ConsoleTable");
     $headers = ["Candidate for: " . $analysis["original"], "Base Diff", "%", "Total Diff", "%", "Score"];
     if ($has_console_table) {
         $table = new \Elkuku\Console\Helper\ConsoleTable(\Elkuku\Console\Helper\ConsoleTable::ALIGN_RIGHT);
         $table->setHeaders($headers);
         array_walk($analysis["candidates"], function ($row, $index, $table) {
             $table->addRow($row);
         }, $table);
         $table_content = $table->getTable();
         if ($to_string) {
             return $table_content;
         }
         echo $table_content;
     } else {
         array_unshift($analysis["candidates"], $headers);
         return print_r($analysis, $to_string);
     }
 }