Skip to content

Instantly share code, notes, and snippets.

@collinprice
Created July 24, 2014 05:30
Show Gist options
  • Save collinprice/013d9a7c463f1da14c4b to your computer and use it in GitHub Desktop.
Save collinprice/013d9a7c463f1da14c4b to your computer and use it in GitHub Desktop.
Generate CSV files for my pareto generational data.
<?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