Link to home
Start Free TrialLog in
Avatar of ronan_40060
ronan_40060Flag for United States of America

asked on

displaying result in a specific table format

The following is the required perl code which displays the result
print "<table align=\"center\" bgcolor=\"#f5deb3\" border=2 bordercolor=\"maroon\">";
      print "<tr>";
      print "<td>";
      while (<FILE>) {
        next unless /$date/i;
        print "<b>Date: $1 $2\n</b>" if /Date:.{4}(.{6}).{10}(.{4})/;
        print"<br>";
      if (my ($xml,  $x_pdf,  $x_reussite) = /XML:(\d+)[^:]+:(\d+)[^:]+:\s*([^\n]+)/i)
        {
           printf "Nombre de XML: $xml<br>\nNombre de PDF(xml):$x_pdf<br>\nPourcentage de réussite:%.1f",$x_reussite;
        }
        print "<br>";
        print "\n------------------------------------------\n";  
        print "<br>";
        if (my ($doc,  $d_pdf,  $d_reussite) = /DOC:(\d+)[^:]+:(\d+)[^:]+:\s*([^\n]+)/i)
        {
           printf "Nombre de DOC: $doc<br>\nNombre de PDF(doc):$d_pdf<br>\nPourcentage de réussite:%.1f",$d_reussite;
        }
        last;
        print "<br>";  
        print "<br>";    
      }
      print "</td>";
      print "</tr>";
      close FILE;
      print "</table>";

the above script displays the result in the following format

                        Date: Dec 12 2002
                  Nombre de XML: 224
                  Nombre de PDF(xml):204
                  Pourcentage de réussite:91.1
            ------------------------------------------
                  Nombre de DOC: 27
                  Nombre de PDF(doc):27
                  Pourcentage de réussite:100.0

---------------------------------------------------------------------------------------
I need to display the same result above into the following table format

----------------------------------------------------------------------------------------------------------
|Date           |  No XML |  Nb XML (pdf) | % reussite | Nb Doc | Nb DOC(pdf)| % reussite |
----------------------------------------------------------------------------------------------------------
|Dec 12 2002 |  224     |    204             |   91.1        |  27      |     27           |   100.0    |
-------------------------------------------------------------------------------------------------------
What changes are to be made in the given perl script ?
Avatar of cjmos
cjmos

ronan_40060

I havn't had time to test this but try altering the above to:

######################
print "<table align=\"center\" bgcolor=\"#f5deb3\" border=2 bordercolor=\"maroon\">";
print "<tr>";
print "<td>";
print "Date</td><td>No XML</td><td>Nb XML (pdf)</td><td>% reussite</td><td>Nb Doc</td><td>Nb DOC(pdf)</td><td>% reussite</td></tr>";

while (<FILE>) {
    next unless /$date/i;
    $dateStr = "<b>Date: $1 $2\n</b>" if /Date:.{4}(.{6}).{10}(.{4})/;
   
    if ((my ($doc,  $d_pdf,  $d_reussite) = /DOC:(\d+)[^:]+:(\d+)[^:]+:\s*([^\n]+)/i) && (my ($xml,  $x_pdf,  $x_reussite) = /XML:(\d+)[^:]+:(\d+)[^:]+:\s*([^\n]+)/i))
    {
        printf  "<tr><td>$dateStr</td><td>$xml</td><td>$x_pdf</td><td>%.1f</td><td>$doc</td><td>$d_pdf</td><td>%.1f",$x_reussite,$d_reussite;
    }
        last;  
}
print "</td>";
print "</tr>";
print "</table>";
   
close FILE;
###########################
oops, if using strict

 Comment from cjmos
Date: 05/03/2004 07:51PM BST
 Your Comment  


ronan_40060

I havn't had time to test this but try altering the above to:

######################
print "<table align=\"center\" bgcolor=\"#f5deb3\" border=2 bordercolor=\"maroon\">";
print "<tr>";
print "<td>";
print "Date</td><td>No XML</td><td>Nb XML (pdf)</td><td>% reussite</td><td>Nb Doc</td><td>Nb DOC(pdf)</td><td>% reussite</td></tr>";

while (<FILE>) {
    next unless /$date/i;
    my $dateStr = "<b>Date: $1 $2\n</b>" if /Date:.{4}(.{6}).{10}(.{4})/;
   
    if ((my ($doc,  $d_pdf,  $d_reussite) = /DOC:(\d+)[^:]+:(\d+)[^:]+:\s*([^\n]+)/i) && (my ($xml,  $x_pdf,  $x_reussite) = /XML:(\d+)[^:]+:(\d+)[^:]+:\s*([^\n]+)/i))
    {
        printf  "<tr><td>$dateStr</td><td>$xml</td><td>$x_pdf</td><td>%.1f</td><td>$doc</td><td>$d_pdf</td><td>%.1f",$x_reussite,$d_reussite;
    }
        last;  
}
print "</td>";
print "</tr>";
print "</table>";
   
close FILE;
###########################
 
Avatar of ronan_40060

ASKER

thanks cjmos
 I will try and will let you know :)
regards
ronan
hello cjmos
its working out very well thanks now I need little help
for given three dates i m displaying the result like as shown below

Date              Nb de XML  Nb de XML(pdf)     % reussite    Nb de DOC      Nb de DOC(pdf)     % reussite
Apr 22 2004           159                47                   92.5                58                    51                   87.9
Apr 23 2004           176               173                   98.3               36                    30                    83.3
Apr 24 2004               0                 0                      0.0                 0                     0                      0.0
----------------------------------------------------------------------------------------------------------------------------------------------
I just need to add the total , hence the o/p wud look like below
how do we add all the records to get like one below

Date                 Nb de XML   Nb de XML(pdf)   % reussite    Nb de DOC   Nb de DOC(pdf)    % reussite
Apr 22 2004              159                47                   92.5             58                   51             87.9
Apr 23 2004               176              173                   98.3             36                  30             83.3
Apr 24 2004                  0                  0                      0.0              0                   0              0.0
total                           335               220                   63.6            94                  81             57.06


thanks for the help
waiting for ur reply
ronan_40060,

I've made a few changes to your original script. See if this works (there are a few ways of doing things like this, i've just chosen a simple one).


###############################
my ($xmlTot,$x_pdfTot,$docTot,$d_pdfTot,$x_reussiteAv,$d_reussiteAv,$cnt) =0;
my $dateStr="";

print "<table align=\"center\" bgcolor=\"#f5deb3\" border=2 bordercolor=\"maroon\"><tr><td>";
print "Date</td><td>No XML</td><td>Nb XML (pdf)</td><td>% reussite</td><td>Nb Doc</td><td>Nb DOC(pdf)</td><td>% reussite</td></tr>";

while (<FILE>) {
    next unless /$date/i;
    $dateStr = "<b>Date: $1 $2\n</b>" if /Date:.{4}(.{6}).{10}(.{4})/;

    if ((my ($doc,  $d_pdf,  $d_reussite) = /DOC:(\d+)[^:]+:(\d+)[^:]+:\s*([^\n]+)/i) && (my ($xml,  $x_pdf,  $x_reussite) = /XML:(\d+)[^:]+:(\d+)[^:]+:\s*([^\n]+)/i))
    {
        $xmlTot   += $xml;
        $x_pdfTot += $x_pdf;
        $docTot   += $doc;
        $d_pdfTot += $d_pdf;
        $x_reussiteAv = ($x_reussiteAv+$x_reussite)/++$cnt;
        $d_reussiteAv = ($d_reussiteAv+$d_reussite)/$cnt;
       
        printf "<tr><td>$dateStr</td><td>$xml</td><td>$x_pdf</td><td>%.1f</td><td>$doc</td><td>$d_pdf</td><td>%.1f</td></tr>",$x_reussite,$d_reussite;
    }
        last;  
}

printf "<tr><td>total</td><td>$xmlTot</td><td>$x_pdfTot</td><td>%.1f</td><td>$docTot</td><td>$d_pdfTot</td><td>%.1f</td></tr>",$x_reussiteAv,$d_reussiteAv;
print "</table>";
   
close FILE;
##################################
hang in there good buddy
I am trying
will put the results soon
thanks
ronan
I have an HTML form in the front end where in the search criteria a user types in the date in yyyy-mm-dd format and then I am displaying the result of a seach query onto a browser .
All the data  i.e records are stored in a log file which is a simple text file
the sample records corresponding to search query 2002-12-12 is
GENERATION DE PDF           Date:Thu Dec 12 22:39:50 2002
 Nombre XML:224       Nombre de PDF (xml) :204   pourcentage de reussite: 91.0714285714286%
 Nombre DOC:27        Nombre de PDF (doc) :27   pourcentage de reussite: 100%

Now for the backend part my entire  script is as follows
use warnings;
use strict;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
my $q = new CGI;
my $monthName;
my $longdate=$q->param('START');
my($year, $month, $day) = split (/-/, $longdate);
my @months = ( ['',0], ['Jan',31], ['Feb',28], ['Mar',31], ['Apr',30], ['May',31],['Jun',30],['Jul',31],['Aug',31],['Sep',30],['Oct',31],['Nov',30],['Dec',31]  );
my $date.= $months[$month][0].' +'.'.*'.$year;
$/ ="GENERATION";
open FILE, "c:/Apache/Apache2/cgi-bin/Upload/generation.txt" or die $!;
      print $q->header;
      print "<html><body>";
      print "<BODY leftmargin=0 topmargin=0>";
      print "<table height=\"100%\" width = \"100%\" cellpadding = \"0\" cellspacing = \"0\" border = \"2\" align = \"center\">";
      print "<tr height=\"5%\">";
      print "<td align = \"center\" colspan =\"1\" bgColor=\"#000080\">";
      print "<FONT face=\"Times New Roman\" size=\"5.5\" Color =\"White\"> Result Pour Nb PDF Générés Par  + Taux de Réussite </font>";
      print "</td>";
      print "</tr>";
      print "<tr height=\"90%\">";
      print "<td width = \"100%\" colspan = \"1\">";
      print "<A href=http://localhost/cgi-bin/lastpdf.pl><IMG SRC= FILE:///C:/Apache/Apache2/cgi-bin/Accueil.gif ALIGN=TOP></A>";
      print "<br>";      
      print "<br>";
      print "<table align=\"center\" bgcolor=\"aliceblue\" border=2 bordercolor=\"navy\">";
      print "<tr>";
      print "<td>";
      print "<b>Date</b></td><td><b>Nb de XML</b></td><td><b>Nb de XML(pdf)</b></td><td><b>% reussite</b></td><td><b>Nb de DOC</b></td><td><b>Nb de DOC(pdf)</b></td><td><b>% reussite</b></td></tr>";
      while (<FILE>) {
        next unless /$date/i;
        my $dateStr = "$1 $2\n" if /Date:.{4}(.{6}).{10}(.{4})/;
        if ((my ($xml,$x_pdf,$x_reussite) = /XML:(\d+)[^:]+:(\d+)[^:]+:\s*([^\n]+)/i) && (my ($doc, $d_pdf,  $d_reussite) = /DOC:(\d+)[^:]+:(\d+)[^:]+:\s*([^\n]+)/i))
        {
           printf "<tr><td>$dateStr</td><td>$xml</td><td>$x_pdf</td><td>%.1f</td><td>$doc</td><td>$d_pdf</td><td>%.1f",$x_reussite,$d_reussite;
        }
        #last;          
        }
        print "</td>";
       
        print "</tr>";
        print "</table>";
        close FILE;
      print "<br>";
      print "<br>";
      print "<br>";
      print "<tr height=\"5%\">";
      print "<td align = \"center\" colspan =\"2\" bgColor=\"#000080\">&nbsp;</td>";
      print "</tr>";
      print "</table>";
      print "</body></html>";

now I will put your modified script into above and will post the results
:)
thanks for all your help
gonna post the results soon
ronan
Holly Molly
Bingo :):):)
its working cjmos
I tested it with a monthly records and the script is giving awesome results
except in the % section  where for the entire month i received Total as only 4.2 for both Xml and docs
could u pls check this
thanks a million
your script is working very well
best regards
ronan
Oops, yeh sorry, there is an error in my math...

Change the lines

$x_reussiteAv = ($x_reussiteAv+$x_reussite)/++$cnt;
$d_reussiteAv = ($d_reussiteAv+$d_reussite)/$cnt;

to

$x_reussiteAv = ($x_reussiteTot+=$x_reussite)/++$cnt;
$d_reussiteAv = ($d_reussiteTot+=$d_reussite)/++$cnt;

And

my ($xmlTot,$x_pdfTot,$docTot,$d_pdfTot,$x_reussiteAv,$d_reussiteAv,$cnt) =0;

to

my ($xmlTot,$x_pdfTot,$docTot,$d_pdfTot,$x_reussiteAv,$d_reussiteAv,$cnt,$d_reussiteTot,$x_reussiteTot) =0;

That should fix it.
thanks cjmos
Im home now
I will do the first work as soon as I go office
thanks for all ur valuable comments
best regards
ronan

hello cjmos
i did the required changes and tested for a monthly records  still its giving me result like
for XML  its giving me the avg as 40.7 which should have been 90.5
and for DOC its givingme the avg as 36.7 instead of 79.8
what cud be wrong
ronan
This is now what I did
$x_reussiteAv = (($x_pdfTot)/($xmlTot)*100);
$d_reussiteAv = (($d_pdfTot)/($docTot)*100);

and I tested , it works fine for some monthly records but then for some months , it throws an errors that illegal divison by zero at $x_reussiteAv = (($x_pdfTot)/($xmlTot)*100);
waiting for ur replies cjmos
Can you show me whole code that you've got now?

Also, i've just spotted the reason why the original change didn't work.

$x_reussiteAv = ($x_reussiteTot+=$x_reussite)/++$cnt;
$d_reussiteAv = ($d_reussiteTot+=$d_reussite)/++$cnt;

Should have been

$x_reussiteAv = ($x_reussiteTot+=$x_reussite)/++$cnt;
$d_reussiteAv = ($d_reussiteTot+=$d_reussite)/$cnt;

I was incrementing thew counter twice... which was rather silly of me.

Ok no worries
here is my whole code
to display all the records for a given month and display their total
use warnings;
use strict;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
my $q = new CGI;
my(%HM) = undef;
my $monthName;
my $longdate=$q->param('START');
my($year, $month, $day) = split (/-/, $longdate);
my @months = ( ['',0], ['Jan',31], ['Feb',28], ['Mar',31], ['Apr',30], ['May',31],['Jun',30],['Jul',31],['Aug',31],['Sep',30],['Oct',31],['Nov',30],['Dec',31]  );
my $date.= $months[$month][0].' +'.'.*'.$year;
$HM{'Jan'} = "01";$HM{'Feb'} = "02";$HM{'Mar'} = "03";$HM{'Apr'} = "04";$HM{'May'} = "05";$HM{'Jun'} = "06";$HM{'Jul'} = "07";$HM{'Aug'} = "08";$HM{'Sep'} = "09";$HM{'Oct'} = "10";$HM{'Nov'} = "11";$HM{'Dec'} = "12";
my ($xmlTot,$x_pdfTot,$docTot,$d_pdfTot,$x_reussiteAv,$d_reussiteAv,$cnt,$d_reussiteTot,$x_reussiteTot) =0;
my $dateStr="";
$/ ="GENERATION";
      open FILE, "c:/Apache/Apache2/cgi-bin/Upload/generation.txt" or die $!;
      print $q->header;
      print "<html><body>";
      print "<BODY leftmargin=0 topmargin=0>";
      print "<table height=\"100%\" width = \"100%\" cellpadding = \"0\" cellspacing = \"0\" border = \"2\" align = \"center\">";
      print "<tr height=\"5%\">";
      print "<td align = \"center\" colspan =\"1\" bgColor=\"navy\">";
      print "<FONT face=\"Times New Roman\" size=\"5.5\" Color = \"White\"> <b>8.Result Pour Nb PDF Générés par Mois </b> </font>";
      print "</td>";
      print "</tr>";
      print "<tr height=\"90%\">";
      print "<td width = \"100%\" colspan = \"1\">";
print <<EOF;
            <style>
               body{font-family:Times New Roman;}
              a{color:navy;text-decoration:none;font:bold}
               a:hover{color:#cd853f}
               td.menu{background:"white"}
               table.menu
                {
               font-size:100%;
                position:absolute;
               visibility:hidden;
               }
            </style>
            <script type="text/javascript">
              function showmenu(elmnt)
             {
             document.all(elmnt).style.visibility="visible"
             }
             function hidemenu(elmnt)
              {
              document.all(elmnt).style.visibility="hidden"
              }
            </script>
                 
               <table width="14%" align= "top" >
               <tr bgcolor="navy">
              <td onmouseover="showmenu('Accueil')" onmouseout="hidemenu('accueil')">
              <font color = white><b>Accueil</b></font><br />
              <table class="menu" id="accueil" width="100%">
              <tr><td class="menu"><a href="http://localhost/cgi-bin/functionality.pl">Statistics GEDI</a></td></tr>
              <tr><td class="menu"><a href="http://localhost/cgi-bin/lastpdf.pl">Recherche Encore</a></td></tr>
              </table>
              </td>
              </tr>
            </table>
EOF
      #print "<A href=http://localhost/cgi-bin/lastpdf.pl><IMG SRC= FILE:///C:/Apache/Apache2/cgi-bin/Accueil.gif ALIGN=TOP></A>";
      #print "<br>";      
      #print "<br>";
      print "<table align=\"center\" bgcolor=\"aliceblue\" border=2 bordercolor=\"navy\">";
      print "<tr>";
      print "<td>";
      print "<b>Date</b></td><td><b>Nb de XML</b></td><td><b>Nb de XML(pdf)</b></td><td><b>% reussite</b></td><td><b>Nb de DOC</b></td><td><b>Nb de DOC(pdf)</b></td><td><b>% reussite</b></td></tr>";
      while (<FILE>) {
        next unless /$date/i;
        my $dateStr = "$2/$HM{$1}/$3\n" if /Date:.{4}(.{3})\s(.{2}).{10}(.{4})/;
        if ((my ($xml,$x_pdf,$x_reussite) = /XML:(\d+)[^:]+:(\d+)[^:]+:\s*([^\n]+)/i) && (my ($doc, $d_pdf,  $d_reussite) = /DOC:(\d+)[^:]+:(\d+)[^:]+:\s*([^\n]+)/i))
        {
              $xmlTot   += $xml;
              $x_pdfTot += $x_pdf;
              $docTot   += $doc;
              $d_pdfTot += $d_pdf;
              #$x_reussiteAv = ($x_reussiteAv+$x_reussite)/++$cnt;
              #$d_reussiteAv = ($d_reussiteAv+$d_reussite)/$cnt;
              #$x_reussiteAv = ($x_reussiteTot+=$x_reussite)/++$cnt;
            #$d_reussiteAv = ($d_reussiteTot+=$d_reussite)/++$cnt;
            #$x_reussiteAv = (($x_pdfTot)/($xmlTot)*100);
            #$d_reussiteAv = (($d_pdfTot)/($docTot)*100);
            $x_reussiteAv = ($x_reussiteTot+=$x_reussite)/++$cnt;
            $d_reussiteAv = ($d_reussiteTot+=$d_reussite)/$cnt;


        printf "<tr><td>$dateStr</td><td>$xml</td><td>$x_pdf</td><td>%.1f</td><td>$doc</td><td>$d_pdf</td><td>%.1f</td></tr>",$x_reussite,$d_reussite;
        }                                          
        #last;          
      }
        printf "<tr><td><b>Total</b></td><td><b>$xmlTot</b></td><td><b>$x_pdfTot</b></td><td><b>%.1f</b></td><td><b>$docTot</b></td><td><b>$d_pdfTot</b></td><td><b>%.1f</b></td></tr>",$x_reussiteAv,$d_reussiteAv;
        print "</table>";
        close FILE;
      print "<br>";
      print "<tr height=\"6%\">";
      print "<td align = \"center\" colspan =\"2\" bgColor=\"#000080\">&nbsp;</td>";
      print "</tr>";
      print "</table>";
      print "</body></html>";
Now the basic idea is like this
for a given month
there are dates where no pdf documents were created from xml and doc files
so when we calculate the total of al XML for a a given month suppose for april it comes to be 1520
and total of  no of pdf files created from xml are 1320 for that month
so the overall the rate  wud be (1320/1520)*100 = 86.6
and ourcode calculates the average of all the % (total of all %)/no of days so the result of this is different than the result that we got from (1320/1520)*100 = 86.6

what we need is (1320/1520)*100 = 86.6
I am also working , If  find something I will let u know
thanks cjmos for all your help
do let me know what u think and how can we manage to  get the required result
best wishes
ronan

 
ASKER CERTIFIED SOLUTION
Avatar of cjmos
cjmos

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks cjmos
you solved the big problem
I am home now but I am downloading Activeperl and Apache sever and I will test the whole code at home
thanks
I will keep you posted
Thanks a million for all
I am gonna download Komodo ide for perl (trial version :(:(   from activestate
best regards
ronan
I tested it at home and  its working excellent
Great man , you solved it :):):):)
thanks a lot
I wish to come up woth another question again ;)
best wishes
ronan
No probs. Glad to help :)