Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^2: How to calculate the column and print it in pie chart format using perl?

by finddata (Sexton)
on Mar 22, 2017 at 06:09 UTC ( #1185408=note: print w/replies, xml ) Need Help??


in reply to Re: How to calculate the column and print it in pie chart format using perl?
in thread How to calculate the column and print it in pie chart format using perl?

<head> <link rel="stylesheet" type="text/css" href="../lib/DataTables/med +ia/css/jquery.dataTables.css"> <link rel="stylesheet" type="text/css" href="../lib/Dat +aTables/examples/resources/syntax/shCore.css"> <script language="javascript" type="text/javascript" src="../l +ib/flot/current/jquery.js"></script> <script type="text/javascript" language="javascript" src="../l +ib/DataTables/media/js/jquery.dataTables.js"></script> <script type="text/javascript" language="javascript" src="../l +ib/DataTables/examples/resources/syntax/shCore.js"></script> <script type="text/javascript" language="javascript" src="../l +ib/DataTables/examples/resources/demo.js"></script> <script type="text/javascript" language="javascript" src="../l +ib/DataTables/extensions/ColVis/js/dataTables.colVis.js"></script> + <script type="text/javascript" language="javascript" src="../l +ib/DataTables/extensions/TableTools/js/dataTables.tableTools.js"></sc +ript> <script language="javascript" type="text/javascript" src=" . +./lib/flot/current/jquery.flot.js"></script> <!-- <script language="javascript" type="text/javascript" src= +" ../lib/flot/current/demo_table.css"></script> --> <script language="javascript" type="text/javascript" +src=" ../lib/new_style.css"></script> <script language="javascript" type="text/javascript" src=" .. +/lib/flot/current/jquery.flot.categories.js"></script> <script language="javascript" type="text/javascript" src=" .. +/lib/flot/current/jquery.flot.pie.js"></script> <script language="javascript" type="text/javascript" src=" .. +/lib/flot/current/jquery.flot.stack.js"></script> <script language="javascript" type="text/javascript" src=" ../ +lib/flot/current/jquery.flot.axislabels.js"></script> <script language="javascript" type="text/javascript" src=" .. +/lib/flot/current/jquery.flot.resize.js"></script> <script language="javascript" type="text/javascript" src=" .. +/lib/flot/current/jquery.flot.tooltip.js"></script> <script language="javascript" type="text/javascript" src=" .. +/lib/flot/current/jquery.flot.navigate.js "></script> <script language="javascript" type="text/javascript" src=" .. +/lib/flot/current/date.js"></script> <script language="javascript" type="text/javascript" src=" .. +/lib/flot/current/jquery.dataTables.min.js"></script> <script language="javascript" type="text/javascript" src=" .. +/lib/flot/current/jquery.validate.js"></script> <script language="javascript" type="text/javascript" src="../l +ib/flot_test.js"></script> <script language="javascript" type="text/javascript" src="../l +ib/flot.js"></script> <link rel="stylesheet" type="text/css" href="../lib/stylesheet.css +"> <link rel="stylesheet" type="text/css" href="../lib/DataTables +/media/css/jquery.dataTables.css"> <link rel="stylesheet" type="text/css" href="../lib/DataTables/exa +mples/resources/syntax/shCore.css"> <!-- <link rel="stylesheet" type="text/css" href=" ../lib/mysty +le.css">--> <!-- <link rel="stylesheet" type="text/css" href="../lib/DataTa +bles/extensions/ColVis/css/dataTables.colVis.css"> <link rel="stylesheet" type="text/css" href="../lib/DataTables +/extensions/TableTools/css/dataTables.tableTools.css"> --> <!-- <link rel="stylesheet" type="text/css" href="../etc/css/st +yles.css" /> --> <script type="text/javascript" language="javascript" src="../l +ib/DataTables/examples/resources/syntax/shCore.js"></script> <script type="text/javascript" language="javascript" src="../l +ib/DataTables/examples/resources/demo.js"></script> <META HTTP-EQUIV="Pragma" CONTENT="no-cache"> <META HTTP-EQUIV="Expires" CONTENT="-1"> </head>
  • Comment on Re^2: How to calculate the column and print it in pie chart format using perl?
  • Download Code

Replies are listed 'Best First'.
Re^3: How to calculate the column and print it in pie chart format using perl?
by huck (Parson) on Mar 22, 2017 at 07:17 UTC

    since you are serving it from your website that seems to be some wort of homebrew javascript package. As such we will be of little use in helping you prepare the statements that will properly call it. Possibly somebody else at work can help you with that

    in the meantime you can work on getting your input data prepared correctly. From what you have shown %TABLE_DATA is empty.

    Each time you reference $TABLE_DATA{5}{'ENTRY'} it will have the same data, it makes no difference if the label is Vcs or Adice. possibly you meant $TABLE_DATA{5}{'Vcs'} instead. what would even make more sense would be $TABLE_DATA{'jobs_running'}{'Vcs'}. we once showed you a way to translate the data returned by  my $table = $sth->fetchall_arrayref; into data of that form.

    Because i would like this exercise in futility to end quicker i propose something like

    sub print_overall_summary { my $str = shift; $DBH = &connect or die "Cannot connect to the sql server \n"; $DBH->do("USE $str;"); my $stmt="select queue_name,jobs_pending,jobs_running from summary o +rder by time desc ;"; ; my $sth = $DBH->prepare( $stmt ); $sth->execute() or print "Could not prepare_overall_summarydata"; print "<script language=\"javascript\" type=\"text/javascript\"> \n" +; print "\$(document).ready(function(){ \n"; %TABLE_DATA =(); my @sys=qw/Adice Incisive Vcs other/; my $table = $sth->fetchall_hashref; for my $r (@$table) { my $name='other'; for my $s (@sys){ if ($r->{queue_name)=~m/$s/i) {$name=$s; last;} } $TABLE_DATA{$name}{jobs_pending}+=$r->{jobs_pending}; $TABLE_DATA{$name}{jobs_running}+=$r->{jobs_running}; } for my $var(qw/running pending/) { my @parts=(); for my $s (@sys){ push @parts,'["'.$s.'",' .$TABLE_DATA{$s}{'jobs_'.$var} .']'; } print 'var data_'.$var.'=['.join(',',@parts).']'."\n"; } print " \n pieChart(\"placeholder39\",data_running,{title:\"<b><ce +nter>Jobs Running</center></b>\"});\n"; print " \n pieChart(\"placeholder41\",data_pending,{title:\"<b><ce +nter>Jobs Pending</center></b>\"});\n"; print "});"; print "</script>"; }
    Untested, if there are syntax errors it s up to you to fix them.

    notice you have not made any variables for data_machine or data_cpu so those piecharts would fail.

    You need to talk to your boss about how these tasks are way beyond your abilities even though they are so simple. And how you need to get others to do your work for you.

    Or you could make and effort to learn perl instead

      why you had used hashref is it not possible with arrayref?

        You can easily convert between arrayref and hashref.

        If converting between arrays and hashes is problematic for you, maybe you should review your Perl learning material or program some exercises about how to convert between an array and a hash (and a hash and an array).

        For example, you might have this array:

        #!perl -w use strict; # Name Age Street my @user = (qw(John 42 Infinityway)); my %user = ...;

        How would you convert the data from @user (an array) to a hash (%user)?

        The names are easier for you to understand. your previous code used hashs.

        and what effective difference does it make, just how many rows are going to come back from that select? "use DBI;" probably cost more than hashref for this query.

      The following error occurs: DBI fetchall_hashref: invalid number of arguments: got handle + 0, expected handle + between 1 and 1 Usage: $h->fetchall_hashref($key_field)

        Replace

        my $table = $sth->fetchall_hashref; for my $r (@$table) {
        with
        while(my $r=$sth->fetchrow_hashref ){

        So what did your boss say? Did you tell him yet that you cannot do this yourself and that you need to get others to do your assignments for you? He should be getting that idea by now anyway.

        edit killed erroneous semicolon

      After changing it to while(my $r=$sth->fetchall_hashref;) what does the following line denotes: for my $r (@$table) { my $name='other'; for my $s (@sys){ if ($r->{queue_name}=~m/$s/i) {$name=$s; last;} }
      How the $table is used here without any pre declaration.

        Hi finddata,

        Some time ago, a fellow sent emails asking for help over and over. I mentioned a book to read. The Perl by Example by Ellie Quigley is a great resource in helping one master Perl with classroom-like instructions. This fellow did the very thing.

        Do not be overwhelm by the number of pages. Only the first 200 ~ 230 pages will fill your mind with a wonderful foundation regarding the Perl scripting language. Just think, you'd reach page 5, then onwards to page 10, and soon understand everything up through page 35. You'd soon reach page 140 and want to celebrate with the entire family and friends upon crossing the 200 mark.

        Visualize reaching this milestone. What a fantastic journey that might be.

        Regards, Mario

        You dont follow directions well do you?

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2019-12-11 23:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?