-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathParse-ok
executable file
·45 lines (39 loc) · 1.03 KB
/
Parse-ok
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
#!/opt/local/bin/perl -w
#use strict;
use JSON;
use Data::Dumper;
my $kmtomile = 0.621371192;
undef $/;
my $json_text = <STDIN>;
#my $json_text = '';
#while ( <STDIN> ) {
# $json_text .= $_;
#}
my $hash = decode_json($json_text);
#while ($hash->{export}) {
# print Dumper($_->{date});
#}
my $stories = $hash->{export};
#print Dumper(@stories);
while ($day = shift @$stories) {
#print Dumper($day);
my $total = 0;
my $date = $day->{date};
#print "$date\n";
while ($segment = shift @{$day->{segments}} ) {
next unless ($segment->{type} eq 'move');
#print $segment->{startTime} . "\n";
while ($activities = shift @{$segment->{activities}}) {
next unless ($activities->{activity} eq "trp");
$total += $activities->{distance};
#print "distance = " . $activities->{distance} . "m\n";
}
}
# any transport today?
next unless $total;
my $km = $total / 1000;
my $miles = $km * $kmtomile;
printf "Daily total for %s: %.2fMiles (%.2fKm)\n", $date, $miles, $km;
}
#my $days = $hash->{export};
#print Dumper($hash->{export}->[0]);