diff options
author | Nathan Kinkade <nath@nkinka.de> | 2014-02-08 23:50:59 +0000 |
---|---|---|
committer | Nathan Kinkade <nath@nkinka.de> | 2014-02-08 23:50:59 +0000 |
commit | 874f644e15774dd840716b9b03dbf221f66bc1b5 (patch) | |
tree | 71e2a4308b64159c557dcf277f4818b80db95a16 | |
parent | c9fe1847bf798e172060c104d89429dbe3ba1d45 (diff) |
Shorted file handle variable that were getting out of control, and added code to sort cases into various prioritized groups.
-rw-r--r-- | interesting_defendants/interesting_defendants.php | 114 |
1 files changed, 82 insertions, 32 deletions
diff --git a/interesting_defendants/interesting_defendants.php b/interesting_defendants/interesting_defendants.php index e5330db..d3f31f5 100644 --- a/interesting_defendants/interesting_defendants.php +++ b/interesting_defendants/interesting_defendants.php @@ -7,18 +7,25 @@ $dbh = new PDO('mysql:host=localhost;dbname=mdcc', 'mdcc', 'Mdcc.'); $fatal_dispositions = file('./fatal_dispositions', FILE_IGNORE_NEW_LINES); $excludable_charges = file('./excludable_charges', FILE_IGNORE_NEW_LINES); $safe_dispositions = file('./safe_dispositions', FILE_IGNORE_NEW_LINES); +$disposition_groups = file('./disposition_groups', FILE_IGNORE_NEW_LINES); // CSV files -$interesting_defendants_csv = fopen('./output/interesting_defendants.csv', 'w'); -$interesting_defendants_with_multiple_cases_csv = fopen('./output/interesting_defendants_with_multiple_cases.csv', 'w'); -$interesting_defendants_with_akas_csv = fopen('./output/interesting_defendants_with_akas.csv', 'w'); -$interesting_defendants_with_akas_and_multiple_cases_csv = fopen('./output/interesting_defendants_with_akas_and_multiple_cases.csv', 'w'); +$def_no_grp_csv = fopen('./output/interesting_defendants_no_group.csv', 'w'); +$def_grp1_csv = fopen('./output/interesting_defendants_group_1.csv', 'w'); +$def_grp2_csv = fopen('./output/interesting_defendants_group_2.csv', 'w'); +$def_grp3_csv = fopen('./output/interesting_defendants_group_3.csv', 'w'); +$def_multiple_cases_csv = fopen('./output/interesting_defendants_with_multiple_cases.csv', 'w'); +$def_akas_csv = fopen('./output/interesting_defendants_with_akas.csv', 'w'); +$def_akas_multiple_cases_csv = fopen('./output/interesting_defendants_with_akas_and_multiple_cases.csv', 'w'); // HTML files -$interesting_defendants_html = fopen('./output/interesting_defendants.html', 'w'); -$interesting_defendants_with_multiple_cases_html = fopen('./output/interesting_defendants_with_multiple_cases.html', 'w'); -$interesting_defendants_with_akas_html = fopen('./output/interesting_defendants_with_akas.html', 'w'); -$interesting_defendants_with_akas_and_multiple_cases_html = fopen('./output/interesting_defendants_with_akas_and_multiple_cases.html', 'w'); +$def_no_grp_html = fopen('./output/interesting_defendants_no_group.html', 'w'); +$def_grp1_html = fopen('./output/interesting_defendants_group_1.html', 'w'); +$def_grp2_html = fopen('./output/interesting_defendants_group_2.html', 'w'); +$def_grp3_html = fopen('./output/interesting_defendants_group_3.html', 'w'); +$def_multiple_cases_html = fopen('./output/interesting_defendants_with_multiple_cases.html', 'w'); +$def_akas_html = fopen('./output/interesting_defendants_with_akas.html', 'w'); +$def_akas_multiple_cases_html = fopen('./output/interesting_defendants_with_akas_and_multiple_cases.html', 'w'); // HTML template start $html_start = <<<HTML @@ -38,9 +45,12 @@ $html_end = <<<HTML HTML; // Initialize the HTML files -fwrite($interesting_defendants_html, $html_start); -fwrite($interesting_defendants_with_multiple_cases_html, $html_start); -fwrite($interesting_defendants_with_akas_html, $html_start); +fwrite($def_no_grp_html, $html_start); +fwrite($def_grp1_html, $html_start); +fwrite($def_grp2_html, $html_start); +fwrite($def_grp3_html, $html_start); +fwrite($def_multiple_cases_html, $html_start); +fwrite($def_akas_html, $html_start); $sql = "SELECT * FROM cases"; @@ -74,8 +84,25 @@ HTML; $st_charge = $dbh->prepare($sql_charge); $st_charge->execute(); $charges = $st_charge->fetchAll(PDO::FETCH_ASSOC); + + // The default group is no group (i.e. 0) + $disposition_group = 0; + foreach ( $charges as $charge ) { + // Figure out into which, if any, disposition group + // this charge puts the case + foreach ( $disposition_groups as $group_and_disposition ) { + list($group,$disposition) = explode(',', $group_and_disposition); + if ( $charge['disposition'] == $disposition ) { + // Only move a case into a higher group, never backward + if ( $disposition_group == '0' || $group < $disposition_group ) { + $disposition_group = $group; + } + + } + } + // Don't process this case if there is an empty disposition if ( ! trim($charge['disposition']) ) { continue(2); @@ -111,43 +138,66 @@ HTML; } if ( $has_multiple_cases && ! $has_akas ) { - fputcsv($interesting_defendants_with_multiple_cases_csv, $defendant_csv); - fwrite($interesting_defendants_with_multiple_cases_html, $defendant_html); + fputcsv($def_multiple_cases_csv, $defendant_csv); + fwrite($def_multiple_cases_html, $defendant_html); } if ( $has_akas && ! $has_multiple_cases ) { - fputcsv($interesting_defendants_with_akas_csv, $defendant_csv); - fwrite($interesting_defendants_with_akas_html, $defendant_html); + fputcsv($def_akas_csv, $defendant_csv); + fwrite($def_akas_html, $defendant_html); } if ( $has_multiple_cases && $has_akas ) { - fputcsv($interesting_defendants_with_akas_and_multiple_cases_csv, $defendant_csv); - fwrite($interesting_defendants_with_akas_and_multiple_cases_html, $defendant_html); + fputcsv($def_akas_multiple_cases_csv, $defendant_csv); + fwrite($def_akas_multiple_cases_html, $defendant_html); } // The highest quality list if ( ! $has_multiple_cases && ! $has_akas ) { - fputcsv($interesting_defendants_csv, $defendant_csv); - fwrite($interesting_defendants_html, $defendant_html); + switch ( $disposition_group ) { + case '1': + fputcsv($def_grp1_csv, $defendant_csv); + fwrite($def_grp1_html, $defendant_html); + break; + case '2': + fputcsv($def_grp2_csv, $defendant_csv); + fwrite($def_grp2_html, $defendant_html); + case '3': + fputcsv($def_grp3_csv, $defendant_csv); + fwrite($def_grp3_html, $defendant_html); + break; + default: + fputcsv($def_no_grp_csv, $defendant_csv); + fwrite($def_no_grp_html, $defendant_html); + } } } } // Finalize HTML files -fwrite($interesting_defendants_html, $html_stop); -fwrite($interesting_defendants_with_multiple_cases_html, $html_stop); -fwrite($interesting_defendants_with_akas_html, $html_stop); -fwrite($interesting_defendants_with_akas_and_multiple_cases_html, $html_stop); - -fclose($interesting_defendants_csv); -fclose($interesting_defendants_with_multiple_cases_csv); -fclose($interesting_defendants_with_akas_csv); -fclose($interesting_defendants_with_akas_and_multiple_cases_csv); -fclose($interesting_defendants_html); -fclose($interesting_defendants_with_multiple_cases_html); -fclose($interesting_defendants_with_akas_html); -fclose($interesting_defendants_with_akas_and_multiple_cases_html); +fwrite($def_no_grp_html, $html_stop); +fwrite($def_grp1_html, $html_stop); +fwrite($def_grp2_html, $html_stop); +fwrite($def_grp3_html, $html_stop); +fwrite($def_multiple_cases_html, $html_stop); +fwrite($def_akas_html, $html_stop); +fwrite($def_akas_multiple_cases_html, $html_stop); + +fclose($def_no_group_csv); +fclose($def_grp1_csv); +fclose($def_grp2_csv); +fclose($def_grp3_csv); +fclose($def_multiple_cases_csv); +fclose($def_akas_csv); +fclose($def_akas_multiple_cases_csv); +fclose($def_no_group_html); +fclose($def_grp1_html); +fclose($def_grp2_html); +fclose($def_grp3_html); +fclose($def_multiple_cases_html); +fclose($def_akas_html); +fclose($def_akas_multiple_cases_html); ?> |