Created
July 24, 2014 05:30
-
-
Save collinprice/013d9a7c463f1da14c4b to your computer and use it in GitHub Desktop.
Generate CSV files for my pareto generational data.
This file contains 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 | |
class ExafsStruct { | |
public $exafs; | |
public $ff; | |
function __construct($exafs, $ff) { | |
$this->exafs = $exafs; | |
$this->ff = $ff; | |
} | |
public function __toString() { | |
return $this->exafs . "," . $this->ff; | |
} | |
} | |
$FOLDER = "pareto"; | |
$files = array_filter(glob('test*/run*/results.csv')); | |
@mkdir($FOLDER, 0755, true); | |
$run_count = 0; | |
foreach ($files as $file) { | |
$stat_file = fopen($file, "r"); | |
if ($stat_file) { | |
$run_dir = $FOLDER . "/run" . $run_count; | |
++$run_count; | |
@mkdir($run_dir, 0755, true); | |
$generation_count = 0; | |
while( (($exafs_line = fgets($stat_file)) !== false) && (($ff_line = fgets($stat_file)) !== false) ) { | |
$generation_filename = $run_dir . "/gen" . $generation_count; | |
$generation_file = fopen($generation_filename, "w"); | |
++$generation_count; | |
$exafs_scores = explode(",", $exafs_line); | |
$ff_scores = explode(",", $ff_line); | |
unset($exafs_scores[count($exafs_scores)-1]); | |
unset($ff_scores[count($ff_scores)-1]); | |
$scores = array(); | |
for ($i = 0; $i < count($exafs_scores); ++$i) { | |
$scores[] = new ExafsStruct($exafs_scores[$i], $ff_scores[$i]); | |
} | |
$unique_scores = array_unique($scores); | |
foreach ($unique_scores as $score) { | |
fputs($generation_file, "$score->exafs,$score->ff\n"); | |
} | |
fclose($generation_file); | |
chmod($generation_filename, 0644); | |
} | |
} | |
fclose($stat_file); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment