Browse Source

add task to recreate file without duplicate data

pull/13/head
Aaron Parecki 7 years ago
parent
commit
6dd1550724
No known key found for this signature in database GPG Key ID: 276C2817346D6056
2 changed files with 46 additions and 0 deletions
  1. +45
    -0
      compass/app/Console/Commands/CleanFile.php
  2. +1
    -0
      compass/app/Console/Kernel.php

+ 45
- 0
compass/app/Console/Commands/CleanFile.php View File

@ -0,0 +1,45 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Laravel\Lumen\Routing\DispatchesJobs;
use Log;
use DateTime, DateTimeZone;
class Cleanfile extends Command {
protected $signature = 'clean:file {in} {out}';
protected $description = 'Discard duplicate out of order data from a file';
public function handle() {
$in = $this->argument('in');
$out = $this->argument('out');
$fp = @fopen($in, 'r');
$outf = @fopen($out, 'w');
if($fp && $outf) {
$last = false;
while(($line = fgets($fp)) !== false) {
$cur = new DateTime(substr($line, 0, 26), new DateTimeZone('UTC'));
if(!$last) {
$last = new DateTime(substr($line, 0, 26), new DateTimeZone('UTC'));
fwrite($outf, $line);
} else {
if((double)$cur->format('U.u') > (double)$last->format('U.u')) {
fwrite($outf, $line);
$last = new DateTime(substr($line, 0, 26), new DateTimeZone('UTC'));
} else {
Log::info("Discarding line");
}
}
}
fclose($fp);
fclose($outf);
} else {
Log::error("Could not find input file");
}
}
}

+ 1
- 0
compass/app/Console/Kernel.php View File

@ -14,6 +14,7 @@ class Kernel extends ConsoleKernel
*/
protected $commands = [
'App\Console\Commands\TestTrip',
'App\Console\Commands\CleanFile',
];
/**

Loading…
Cancel
Save