Skip to content

Instantly share code, notes, and snippets.

@kiang
Created August 19, 2015 08:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kiang/a25c5b576410adefcfdf to your computer and use it in GitHub Desktop.
Save kiang/a25c5b576410adefcfdf to your computer and use it in GitHub Desktop.
<?php
$fh = fopen(__DIR__ . '/1040818.csv', 'r');
$counter = array();
while ($line = fgetcsv($fh, 2048)) {
if ($line[0] === '確定日期') {
//empty vars
$currentArea = '';
$currentDay = '';
} elseif (!empty($line[3])) {
if (empty($currentDay)) {
$dayParts = explode('/', $line[0]);
$currentDay = implode('-', array(
2015,
str_pad(intval($dayParts[1]), 2, '0', STR_PAD_LEFT),
str_pad(intval($dayParts[2]), 2, '0', STR_PAD_LEFT),
));
}
if (!empty($line[1])) {
$currentArea = $line[1];
}
$cPos = strpos($line[2], '(');
if (false !== $cPos) {
$line[2] = substr($line[2], 0, $cPos);
}
$key = "{$currentArea}{$line[2]}";
if (!isset($counter[$key])) {
$counter[$key] = array(
'total' => $line[3],
'logs' => array(),
);
} else {
$counter[$key]['total'] += $line[3];
}
$counter[$key]['logs'][] = array(
$currentDay,
$line[3],
);
//echo "{$currentDay} - {$currentArea} - {$line[2]} : +{$line[3]}\n";
}
}
print_r($counter);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment