var data_run=[ ["label a",1],["label b",2],["label_c",99]];
####
use strict; use warnings;
use DBI;
my $storagefile='finddata';
my $DBH = DBI->connect( "dbi:SQLite:dbname=".$storagefile ) || die "Cannot connect: $storagefile $DBI::errstr";
my $sql = 'SELECT queue_name,jobs_pend,jobs_run
FROM queues
ORDER BY jobs_run DESC';
my $sth = $DBH->prepare( $sql );
$sth->execute();
# input
my %table = ();
my $recno = 0;
my @top = ();
while (my ($name,$pend,$run) = $sth->fetchrow_array){
my $key = ($recno++ < 5) ? $name : 'other' ;
push @top,$key unless (defined ($top[-1]) && $top[-1] eq 'other');
$table{$key}{'pend'} += $pend;
$table{$key}{'run'} += $run;
}
#So first you need to make your interior arrays
my @iarray_run;
for my $key (@top){
push @iarray_run,'["'.$key.'",'.$table{$key}{'run'}.']';
}
# then you join them and assign them
my $orun=join(',',@iarray_run);
print "var data_run=[$orun];\n";
####
var data_run=[["adice_short",192],["ncsim_short",84],["ncsim_long",78],["adice_long",39],["normal",30],["other",34]];