File: transform_region.pl

package info (click to toggle)
rickshaw 1.5.1.dfsg-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,864 kB
  • sloc: javascript: 15,281; makefile: 97; perl: 59
file content (34 lines) | stat: -rwxr-xr-x 682 bytes parent folder | download | duplicates (5)
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
#!/usr/bin/env perl

use warnings;
use strict;

use Time::Local 'timegm';

my @header;
my $data;

while (<>) {

	# the third line is the header
	if ($. == 3) {
		          # and we want the years in epoch seconds
		@header = map { m/^(\d{4})/; year_to_seconds($1); }
	              (split ',')[1..11];
	}

	if (m/^(Northeast|Midwest|South|West)/) {
		my $i = -1;
		$data .= "\n{\n\tname: \"$1\",\n";
		$data .= "\tdata: [ " . join(", ", map { "{ x: $header[++$i], y: $_ }" } (split ',')[1..11]) . " ],\n\n},";
	}

	chop $data && last  if  m/^Alabama/; # we have what we need now.
}

sub year_to_seconds {
	my $year = shift;
	return timegm(0, 0, 0, 1, 0, $year);
}

print "$data\n";