Skip to content

Instantly share code, notes, and snippets.

@ha1t
Created November 21, 2011 09:10
Show Gist options
  • Save ha1t/1382109 to your computer and use it in GitHub Desktop.
Save ha1t/1382109 to your computer and use it in GitHub Desktop.
DeNAのKPIレポートのcsvをマージするスクリプト
<?php
/**
*
*
*/
date_default_timezone_set('Asia/Tokyo');
$csv = array();
foreach (glob('report_kpi_*') as $filename) {
$lines = file($filename);
array_shift($lines);
$lines = array_map('trim', $lines);
foreach ($lines as $line) {
$columns = explode(',', $line);
$columns = array_map(function ($value) { return trim($value, '"'); }, $columns);
$columns[0] = str_replace('/', '-', $columns[0]);
$key = strtotime($columns[0]);
$csv[$key] = $columns;
}
}
ksort($csv);
$plain_text = "";
foreach ($csv as $line) {
$plain_text .= implode(',', $line) . PHP_EOL;
}
file_put_contents('report_kpi_all.csv', $plain_text);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment