Skip to content
Browse files

Adding our suggested solutions.

  • Loading branch information...
1 parent 7e8e488 commit 82ceca7dec4c20b7d402704f1b3b525a879382ef @jhannah committed Mar 4, 2010
Showing with 70 additions and 0 deletions.
  1. +42 −0 elle/Khisanth.pl
  2. +28 −0 elle/jhannah.pl
View
42 elle/Khisanth.pl
@@ -0,0 +1,42 @@
+use strict;
+use warnings;
+
+# Usage: perl count_infections.pl input1 input2 input3 ...
+
+# create date to week conversion table
+my %date_to_week;
+open my $week_converter, "<", "weekConverter.txt"
+ or die "Couldn't open 'weekConverter.txt': $!";
+
+while( my $line = <$week_converter> ) {
+ chomp $line;
+ my ($date, $week) = split /\t/, $line;
+ $date_to_week{ $date } = $week;
+}
+
+
+# process all the files specified on the command line
+for my $file ( @ARGV ) {
+ open my $date_type, "<", $file or die "Couldn't open '$file': $!";
+
+ my %counts;
+ while( my $line = <$date_type> ) {
+ chomp $line;
+ my ($date, $type) = split /\t/, $line;
+
+ if( exists( $date_to_week{ $date } ) ) {
+ # zero pad for sorting
+ my $week = sprintf "%02d", $date_to_week{ $date };
+ $counts{ "$week\t$type" }++;
+ } else {
+ # what to do if no conversion is available is not specified
+ }
+ }
+
+ print "Week\tType\tCounts\n";
+ for my $week_type ( sort keys %counts ) {
+ print "$week_type\t$counts{$week_type}\n";
+ }
+}
+
+
View
28 elle/jhannah.pl
@@ -0,0 +1,28 @@
+use strict;
+use warnings;
+use diagnostics;
+
+my %weeks;
+open my $fh, "<", "weekConverter.txt" or die "Can't open weeks file: $!";
+while (<$fh>) {
+ chomp;
+ my ($date, $week) = split /\t/;
+}
+close $fh;
+
+my $stats = {};
+open my $fh, "<", "NAdate_type.txt" or die "Can't open types file: $!";
+<$fh>; # discard header
+while (<$fh>) {
+ chomp;
+ my ($type, $date) = split /\t/;
+ my $week = $weeks{$date};
+ my $stats->{$week}->{$type}++;
+}
+close $fh;
+
+foreach my $week (keys %stats) {
+ foreach my $type (keys %{$stats->{$week}}) {
+ print "$week $type " . $stats->{$week}->{$type} . "\n";
+ }
+}

0 comments on commit 82ceca7

Please sign in to comment.
Something went wrong with that request. Please try again.