Advertisement
nagual2

Untitled

Jan 20th, 2025
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.21 KB | Source Code | 0 0
  1. use strict;
  2. use List::Util 'sum';
  3.  
  4. local $\ = "\n";
  5. local $, = "\n";
  6.  
  7. my $STRUCTURE;
  8. my @FEEDS = sort { $a <=> $b } keys %{{map { map { $_ => 1 } map { keys %{$_->{'feeds'}} } values %$_ } @$STRUCTURE}};
  9.  
  10. print
  11.     map {
  12.         my $d=$_;
  13.        
  14.         map {
  15.             my $a=$_;
  16.            
  17.             T('stat', {'date' => $d},
  18.                 T('feeds', undef,
  19.                     map {
  20.                         my $f=$_;
  21.                         T('feed', {'id' => $f},
  22.                             map { my $t=$_; T($t, undef, sum map { $_->{$t} } map { $_->{$f} } map { $_->{'feeds'} } @$a) } 'request', 'click', 'error'
  23.                         )
  24.                     } @FEEDS
  25.                 ),
  26.                
  27.                 T('total', undef,
  28.                     map { my $t=$_; T($t, undef, sum map { $_->{$t} } map { $_->{'total'} } @$a) } 'request', 'click'
  29.                 ),
  30.             )
  31.         } [
  32.             map { $_->{$d} || () } @$STRUCTURE
  33.         ]
  34.     }
  35.     sort keys %{{map { map { $_ => 1 } keys %$_ } @$STRUCTURE}};
  36.  
  37. sub T {
  38.     my ($name, $attr) = (shift, shift);
  39.     map { @_ ? ("<$_>", @_, "") : "<$_/>" }
  40.     join ' ', $name, map { qq{$_="$attr->{$_}"} } keys %$attr;
  41. }
  42.  
Tags: map
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement