Last active
September 23, 2016 03:33
-
-
Save iansltx/3ddc62e56aca203cd54c703f27b5c014 to your computer and use it in GitHub Desktop.
Ting CSV parser
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if ($argc < 4) { | |
die("Usage: php ting.php minutesXXX.csv messagesXXX.csv megabytesXXX.csv\n"); | |
} | |
$people = []; | |
$voice = fopen($argv[1], 'r'); | |
$sms = fopen($argv[2], 'r'); | |
$data = fopen($argv[3], 'r'); | |
fgetcsv($voice); | |
fgetcsv($sms); | |
fgetcsv($data); | |
while ($row = fgetcsv($voice)) { | |
@$people[$row[4]]['Min'] += $row[11]; | |
} | |
while ($row = fgetcsv($sms)) { | |
@$people[$row[3]]['SMS']++; | |
} | |
while ($row = fgetcsv($data)) { | |
@$people[$row[2]]['MB'] += $row[4] / 1000; | |
} | |
foreach ($people as $name => $stats) { | |
echo $name . ': ' . ($stats['Min'] ?? 0) . ' minutes, ' . ($stats['SMS'] ?? 0) . ' texts, ' . | |
round($stats['MB'] ?? 0) . "MB\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment