Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

TOTAL Element understanding - Why and how to use this?

by chandantul (Scribe)
on Apr 22, 2019 at 15:22 UTC ( #1232868=perlquestion: print w/replies, xml ) Need Help??

chandantul has asked for the wisdom of the Perl Monks concerning the following question:

Hi Leads, I have one doubt on TOTAL element while you suggested use this in Pivot table

I need your help to understand the TOTAL Element as I need to develop +the same in Java. Can I get any help? I do understand the associated array is not there in Java compare to P +erl. Can you please let me know how I can interpret between Perl and +Java. This is same critical project. I am able to generate the data through java but got stuck in +Pivot table creation in Java. I really would like understand the TOTA +L element here if you don't don't have any coding solution for JAVA.
$app = $responseapps5[$k]; $device = $responseclientdevice[$k]; $browser = $responseclientbrowser[$k]; $userid = $responseid[$k]; ++$pivot{$app}{$device}{$browser}; ++$pivot{$app}{'TOTAL'}{$browser}; ++$pivot{$app}{'TOTAL'}{'TOTAL'}; ++$pivot{$app}{$device}{'TOTAL'}; ++$pivot{'TOTAL'}{$device}{$browser}; #++$pivot{$app}{$browser}; ++$categ{'device'}{$device}; ++$categ{'browser'}{$browser}; ++$app{$app}; $row1++; #print Dumper $app;

Replies are listed 'Best First'.
Re: TOTAL Element understanding - Why and how to use this?
by haukex (Archbishop) on Apr 22, 2019 at 15:30 UTC
Re: TOTAL Element understanding - Why and how to use this?
by hdb (Monsignor) on Apr 22, 2019 at 16:40 UTC

    At a first glance it looks like the code is doing some counting and is doing sums by certain categories. Highest level is by app, then by device, then by browser. Wherever you see 'TOTAL' in a particular column, it means that the distinction between different devices, say, is ignored, and a total across all devices is done. Same for app and browser.

      Thanks for your responses! I would like to understand more in details, If you are telling highest is app label ( CGA,HGS,YAG, TAG) then device label (Computer,Mobie) then browser label (IE11,CHROME,EDGE), In the loop, its checking the counts for %pivot hash by $pivot{$app}{$device}{$browser}; ? Can you please elaborate the difference between following code snippet about which sum its doing ++$pivot{$app}{'TOTAL'}{$browser}; ( is this counting total app counts and what about the browser here? Please let me know about this too ++$pivot{$app}{'TOTAL'}{'TOTAL'}; Please check entire for loop

      for ($k = 0; $k <= $#responseid; $k++) { next if ($responseclientbrowser[$k] =~ /IE7/i); $worksheet1->write($row1,0, $responseid[$k],$format2); $worksheet1->write($row1,1, $responsdisp[$k],$format2); $worksheet1->write($row1,2, $responsalter[$k],$format2); $worksheet1->write($row1,3, $responseclientdevice[$k],$format2 +); $worksheet1->write($row1,4, $responseclientbrowser[$k],$format +2); $worksheet1->write($row1,5, $responseapps5[$k],$format2); $worksheet1->write($row1,6, $estdate[$k],$format2); $app = $responseapps5[$k]; $device = $responseclientdevice[$k]; $browser = $responseclientbrowser[$k]; $userid = $responseid[$k]; #print Dumper $browser; ++$pivot{$app}{$device}{$browser}; #print Dumper ++$pivot{$app}{$device}{$browser}; ++$pivot{$app}{'TOTAL'}{$browser}; # print Dumper ++$pivot{$app}{'TOTAL'}{$browser}; ++$pivot{$app}{'TOTAL'}{'TOTAL'}; #print Dumper $pivot{$app}{'TOTAL'}{'TOTAL'}; ++$pivot{$app}{$device}{'TOTAL'}; ++$pivot{'TOTAL'}{$device}{$browser}; #print Dumper $pivot{'TOTAL'}{$device}{$browser}; #++$pivot{$app}{$browser}; ++$categ{'device'}{$device}; ++$categ{'browser'}{$browser}; ++$app{$app}; $row1++; #print Dumper $app; }

        I have replaced the 'TOTAL' with a more "speaking" label. Pls look at the 'all...' rows and how they represent the sums of the (random) data in each of the blocks:

        use strict; use warnings; use Data::Dumper; my %pivot; # generate 100 random records for app(lications) being accessed thru s +ome dev(ices) with some bro(wsers) for(1..100){ my($app,$dev,$bro) = (qw(App1 App2 App3)[rand 3],qw(Dev1 Dev2 Dev3 +)[rand 3],qw(Bro1 Bro2 Bro3)[rand 3]); ++$pivot{$app}{$dev}{$bro}; ++$pivot{'allapps'}{$dev}{$bro}; ++$pivot{$app}{'alldevs'}{$bro}; ++$pivot{$app}{$dev}{'allbros'}; ++$pivot{'allapps'}{'alldevs'}{$bro}; ++$pivot{$app}{'alldevs'}{'allbros'}; ++$pivot{'allapps'}{$dev}{'allbros'}; ++$pivot{'allapps'}{'alldevs'}{'allbros'}; } # statistics for accesses for my $app (sort keys %pivot) { for my $dev (sort keys %{$pivot{$app}}) { for my $bro (sort keys %{$pivot{$app}{$dev}}) { print "$app\t$dev\t$bro\t$pivot{$app}{$dev}{$bro}\n"; } print "------------------------------------------------\n"; } }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1232868]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2022-08-16 07:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?