Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env perl
- use strict;
- use warnings;
- use Text::CSV;
- my @language_sites = qw();
- my $csv = Text::CSV->new;
- my $top_row = $csv->getline(*STDIN);
- my @rows = ();
- while (my $row = $csv->getline(*STDIN)) {
- $row->[0] =~ s/^StackExchange\.(.*)/lc($1)/e;
- push @rows, $row;
- }
- sub report {
- my ($include_top, $include_bottom, $include_median, @sites) = @_;
- print " up down\n";
- for (my $rank = 0; $rank < @rows; $rank++) {
- my @row = @{$rows[$rank]};
- my $site = $row[0];
- printf "%-18s %5.2f %5.2f\n", $site, @row[4,5]
- if $rank < $include_top
- or $include_median && $rank == @rows / 2
- or $rank >= @rows - $include_bottom
- or grep {$_ eq $site} @sites;
- }
- }
- if (@ARGV == 0) {
- report(scalar(@rows), 0, ());
- } elsif ($ARGV[0] eq '--help') {
- print <<EOF;
- Usage: $0 [STYLE]
- Show the average number of upvotes and downvotes per post on Stack Exchange
- sites. Deleted posts are excluded.
- This script reads CSV data on standard input. The data can be retrieved from
- http://data.stackexchange.com/stackoverflow/query/195762/average-number-of-votes-on-all-sites
- EOF
- } elsif ($ARGV[0] eq 'cs') {
- report(6, 1, 1, qw(astronomy biology chemistry cogsci crypto cs cstheory
- earthscience linguistics
- math matheducators mathoverflow
- philosphy physics programmers
- scicomp stackoverflow stats tex));
- } elsif ($ARGV[0] eq 'it') {
- report(1, 1, 1, qw(android apple arduino blender codegolf codereview
- dba drupal dsp ebooks electronics expressionengine
- gamedev gis joomla magento mathematica
- networkengineering programmers
- raspberrypi reverseengineering salesforce
- security serverfault sharepoint stackoverflow superuser
- tex tor tridion ubuntu unix ux
- webapps webmasters windowsphone wordpress));
- } elsif ($ARGV[0] eq 'lang') {
- report(1, 1, 1, qw(chinese ell english french german italian
- japanese linguistics russian spanish writers));
- } elsif ($ARGV[0] =~ /[[:space:[,]/) {
- report(0, 0, 0, split(/[[:space:],]+/, $ARGV[0]));
- } else {
- die "Unknown report style";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement