-
Notifications
You must be signed in to change notification settings - Fork 0
/
by_race2.pl
executable file
·66 lines (59 loc) · 1.36 KB
/
by_race2.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#! env perl
use 5.38.0;
use DBI;
use Getopt::Long;
my $grades;
my $category;
GetOptions(
"grades=s" => \$grades, # string
"category=s" => \$category, # string
)
or usage();
if (not defined $grades) {
say STDERR "FATAL: Argument 'grades' is mandatory.";
usage();
}
if (not defined $category) {
say STDERR "FATAL: Argument 'category' is mandatory.";
usage();
}
my $dbh = DBI->connect("dbi:SQLite:dbname=ops.sqlite3","","");
my $strsql1 = <<SQL;
SELECT count(*)
FROM disc
JOIN resolution_categories rc ON (disc.resolutionName = rc.resolutionName)
WHERE rc.category = '$category'
AND Grade IN ($grades)
AND RaceEthnicity = ?
SQL
my $sth1 = $dbh->prepare($strsql1);
my $strsql2 = <<SQL;
SELECT count(*)
FROM disc
WHERE Grade IN ($grades)
AND RaceEthnicity = ?
SQL
my $sth2 = $dbh->prepare($strsql2);
my %positive_by_race;
foreach my $race (
"African American",
"Asian",
"Hispanic",
"Multi Racial",
"Native American",
"Pacific Islander",
"White",
) {
$sth1->execute($race);
while (my @row = $sth1->fetchrow) {
$positive_by_race{$race} = $row[0];
}
$sth2->execute($race);
while (my @row = $sth2->fetchrow) {
say sprintf("%s|%d|%d|%0.2f", $race, $positive_by_race{$race}, $row[0], $positive_by_race{$race} / $row[0] * 100);
}
}
sub usage {
say STDERR "Usage: $0 " . '--grades "\'PK\', \'KG\', 1, 2, 3"';
exit;
}