home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / httpa200.zip / CHART_F.CMD next >
OS/2 REXX Batch file  |  1995-11-28  |  14KB  |  464 lines

  1. /* Image File support code test */
  2.   Call RxFuncAdd 'RxgdLoadFuncs', 'RXGDUTIL', 'RxgdLoadFuncs'
  3.   Call RxgdLoadFuncs
  4.   Call RxFuncAdd 'SysLoadFuncs', 'REXXUTIL', 'SysLoadFuncs'
  5.   Call SysLoadFuncs
  6.  
  7.  
  8.   html_name  = haFinalHTML
  9.   url_name   = haURLFinalGIF
  10.  
  11.  
  12.   rc = SysFileDelete(html_name)
  13.   rc = LineOut(html_name, '<HTML>')
  14.   rc = LineOut(html_name, '<TITLE><HEAD>HTTPAccess Stats</HEAD></TITLE>')
  15.   rc = LineOut(html_name, '<BODY>')
  16.   rc = LineOut(html_name, '<img src=' || url_name || ' height=600 width=800>')
  17.  
  18.   rc = LineOut(html_name, '<PRE>')
  19.   rc = LineOut(html_name, 'Date              : ' || haMon || ' ' || haDay || ' ' || haYear)
  20.  
  21.   rc = LineOut(html_name, 'Total Running Time: ' || haHours || ':' || haMinutes);
  22.  
  23.   totalreq = 0
  24.   totalunq = 0
  25.   do i = 1 to 24
  26.     totalreq = totalreq + haRequests.i
  27.     totalunq = totalunq + haUnique.i
  28.   end
  29.   rc = LineOut(html_name, 'Total Requests:' || totalreq)
  30.   rc = LineOut(html_name, 'Total Unique  :' || totalunq)
  31.  
  32.   rc = LineOut(html_name, '</PRE>')
  33.  
  34.   rc = LineOut(html_name, '<HR>')
  35.   rc = LineOut(html_name, 'Weekly Status')
  36.   bwidth = 135 + (35 * haYearStats.0)
  37.   rc = LineOut(html_name, '<img src=' || haURLWeeklyGIF || ' height=400 width=' || width || '>')
  38.   rc = LineOut(html_name, '<HR>')
  39.   rc = LineOut(html_name, 'Top ' || haTopPagesCnt || ' documents downloaded<BR><SL>')
  40.  
  41.   do i = 1 to haTopPagesCnt
  42.     rc = Lineout(html_name, '<LI>' || FORMAT(haTopPages.Cnt.i+0, 5) || '  ' || haTopPages.Str.i)
  43.   end
  44.  
  45.   rc = LineOut(html_name, '</SL><HR>')
  46.   rc = LineOut(html_name, 'Top ' || haTopHostsCnt || ' hosts<BR><SL>')
  47.  
  48.   do i = 1 to haTopHostsCnt
  49.     rc = Lineout(html_name, '<LI>' || FORMAT(haTopHosts.Cnt.i+0, 5) || '  ' || haTopHosts.Str.i)
  50.   end
  51.   rc = LineOut(html_name, '</SL><HR>')
  52.  
  53.   rc = LineOut(html_name, '</BODY></HTML>')
  54.   rc = LineOut(html_name)
  55. /*  rc = stream(html_name, 'c', 'CLOSE')*/
  56.  
  57.   width        = 800
  58.   height       = 600
  59.   tborder      = 60
  60.   lborder      = 75
  61.   rborder      = 20
  62.   border       = 50
  63.   b_columns    = 2
  64.   static_label = 'Hits per hour'
  65.   bar_label    = 'Hour'
  66.   horz_or_vert = 'V'
  67.   bar_cnt      = 24
  68.   title        = haTitle
  69.   graph_name   = haFinalGIF
  70.  
  71.   max_ticks    = 15
  72.   increment    = 25
  73.   do i = 1 to bar_cnt
  74.      bar_data.bar_caption.i = right(i-1,2,0);
  75.      bar_data.bar_detail.1.i = haRequests.i
  76.      bar_data.bar_detail.2.i = haUnique.i
  77.   end
  78.  
  79.  
  80.   call BarGraph
  81.  
  82.   tborder      = 60
  83.   lborder      = 75
  84.   rborder      = 60
  85.   border       = 50
  86.   width        = bwidth
  87.   height       = 400
  88.   b_columns    = 2
  89.   static_label = '# Unique Hosts & Docs / day'
  90.   bar_label    = 'Past ' || haYearStats.0 || ' Days'
  91.   horz_or_vert = 'V'
  92.   bar_cnt      =  haYearStats.0
  93.   title        = haTitle
  94.   graph_name   = haWeeklyGIF
  95.  
  96.  
  97.   max_ticks    = 10
  98.   increment    = 100
  99.   do i = 1 to bar_cnt
  100.      bar_data.bar_caption.i = haYearStats.Mon.i || '/' || haYearStats.Day.i || '/' || haYearStats.Year.i
  101.      bar_data.bar_detail.1.i    = haYearStats.TotalHosts.i
  102.      bar_data.bar_detail.2.i    = haYearStats.TotalDocs.i
  103.      bar_data.bar_detail.3.i    = haYearStats.Reqs.i
  104.   end
  105.  
  106.   call BarGraph
  107.  
  108.   Call RxgdUnloadFuncs
  109.   Call RxFuncDrop 'RxgdLoadFuncs'
  110.   Call RxFuncDrop 'HTTPAccLoadVars'
  111.  
  112. RETURN;
  113.  
  114. /* -------------------------------------------------------------------- */
  115. /* ---------------------------- STOP ---------------------------------- */
  116. /* -------------------------------------------------------------------- */
  117.  
  118.  
  119. /* -------------------------------------------------------------------- */
  120. /* BARGRAPH                                                             */
  121. /* -------------------------------------------------------------------- */
  122. BarGraph:
  123.  
  124.  
  125. font.l.w =  8;
  126. font.l.h = 16;
  127. font.m.w =  7;
  128. font.m.h = 13;
  129. font.s.w =  6;
  130. font.s.h = 12;
  131. font.t.w =  5;
  132. font.t.h =  8;
  133. font.g.w =  9;
  134. font.g.h = 15;
  135.  
  136.  
  137. im = RxgdImageCreate(width, height)
  138.  
  139. gray  = RxgdImageColorAllocate(im, 128, 128, 128)
  140. black = RxgdImageColorAllocate(im,   0,   0,   0)
  141. white = RxgdImageColorAllocate(im, 255, 255, 255)
  142. red   = RxgdImageColorAllocate(im, 255,   0,   0)
  143. blue  = RxgdImageColorAllocate(im,   0,   0, 255)
  144. green = RxgdImageColorAllocate(im,   0, 255,   0)
  145.  
  146.  
  147. rc = RxgdImageColorTransparent(im, gray);
  148.  
  149.    /**********************************************/
  150.    /* Initialize colors                          */
  151.    /**********************************************/
  152.   do i = 1 to bar_cnt
  153.      bar_data.bar_color.1.i = blue;
  154.      bar_data.bar_color.2.i = red;
  155.      bar_data.bar_color.3.i = green;
  156.      bar_data.bar_detail_color.i = black;
  157.   end
  158.  
  159.  
  160.  
  161.    /**********************************************/
  162.    /* Find and set MAX number                    */
  163.    /**********************************************/
  164.       scalemax = 0
  165.       max_caption_text = ''
  166.       do i = 1 to bar_cnt
  167.  
  168.          if LENGTH(bar_data.bar_caption.i) > LENGTH(max_caption_text) THEN
  169.            do
  170.              max_caption_text = bar_data.bar_caption.i
  171.            end
  172.  
  173.          do j = 1 to b_columns
  174.            if bar_data.bar_detail.j.i  > scalemax then
  175.              scalemax = bar_data.bar_detail.j.i
  176.          end
  177.  
  178.       end
  179.  
  180.  
  181.    /**********************************************/
  182.    /* Calculate max scale.                       */
  183.    /**********************************************/
  184.    inc_chk   = increment;
  185.    loop = 1;
  186.    do while loop == 1
  187.  
  188.       temp = scalemax;
  189.       temp = temp + inc_chk;
  190.       temp = temp % inc_chk;
  191.       temp = temp * inc_chk;
  192.       tic_count = temp / inc_chk;
  193.  
  194.       if  tic_count <= max_ticks  then
  195.         do
  196.         loop = 0
  197.         scalemax = temp;
  198.         end
  199.       else
  200.         inc_chk = inc_chk + increment;
  201.    end
  202.  
  203.    /**********************************************/
  204.    /* Calculate bottom border position.          */
  205.    /*    This is based on caption text length.   */
  206.    /**********************************************/
  207.       if horz_or_vert = 'H' then
  208.          lborder = 40 + stringlength(max_caption_text, 'L');
  209.       else
  210.          bborder = 40 + stringlength(max_caption_text, 'L');
  211.  
  212.    /**********************************************/
  213.    /* Setup the tic captions.                    */
  214.    /**********************************************/
  215.       textmax = 0;
  216.       max_tic_text = "";
  217.       do i = 1 to tic_count
  218.          tic_label_text.i  = trunc(scalemax * i / tic_count);
  219.          if length(trunc(scalemax * i / tic_count)) > textmax then do
  220.             textmax = length(trunc(scalemax * i / tic_count))
  221.             max_tic_text = trunc(scalemax * i / tic_count);
  222.          end
  223.       end
  224.  
  225.    /**********************************************/
  226.    /* Calculate left border position.            */
  227.    /*    This is based on the tic text length.   */
  228.    /**********************************************/
  229.       if horz_or_vert = 'H' then
  230.          bborder = 40 + stringlength(max_tic_text, 'L');
  231.       else
  232.          lborder = 40 + stringlength(max_tic_text, 'L');
  233.  
  234.  
  235.    /**********************************************/
  236.    /* Calculate some other sizes.                */
  237.    /**********************************************/
  238.       if horz_or_vert = 'H' then do
  239.          u_width = height - (bborder + tborder);
  240.          t_width = u_width / bar_cnt;
  241.          b_width = t_width * .7
  242.          spacing = t_width * .3
  243.          tic_spacing = (width - (lborder + rborder)) / tic_count;
  244.       end
  245.       else do
  246.          u_width = width - (lborder + rborder);
  247.          t_width = u_width / bar_cnt;
  248.          b_width = t_width * .7
  249.          spacing = t_width * .3
  250.          tic_spacing = (height - (tborder + bborder)) / tic_count;
  251.       end
  252.  
  253.       if horz_or_vert == 'H' then
  254.         do
  255.           h_label = bar_label;
  256.           v_label = static_label;
  257.         end
  258.       else
  259.         do
  260.           v_label = bar_label;
  261.           h_label = static_label;
  262.         end
  263.  
  264.  
  265.    /* draw the title                    */
  266.       rc = RxgdImageString(im,   'G', centerstring(width, title, 'G'), 20, title, black)
  267.  
  268.    /* draw a vertical line  and border */
  269.       rc = RxgdImageString(im,   'G', centerstring(width, v_label, 'G'), height - 20, v_label, black)
  270.       rc = RxgdImageStringUp(im, 'G', 10, centerstringup(height, h_label, 'G') , h_label, black)
  271.       rc = RxgdImageLine(im, lborder-2, tborder-2, lborder-2, height - (bborder-2), black);
  272.       rc = RxgdImageLine(im, lborder-2, height - (bborder-2), width - (rborder), height - (bborder-2), black);
  273.  
  274.    do i = 1 to tic_count
  275.       if horz_or_vert = 'H' then do
  276.          tic = lborder + i * tic_spacing;
  277.          rc = RxgdImageLine(im, tic, height - bborder - 5, tic, height - bborder + 5, black)
  278.          rc = RxgdImageStringup(im, 'L', tic - font.L.h/2 , height - bborder + stringlength(tic_label_text.i, 'L') + 5, tic_label_text.i, black)
  279.       end
  280.       else do
  281.          tic = height - bborder - i * tic_spacing;
  282.          rc = RxgdImageLine(im, lborder - 7, tic, lborder + 3, tic, black)
  283.          rc = RxgdImageString(im, 'L', lborder - stringlength(tic_label_text.i, 'L') - 5, tic-5, tic_label_text.i, black)
  284.       end
  285.    end
  286.  
  287.    do i = 1 to bar_cnt
  288.       rc = DisplayBar(i,horz_or_vert);
  289.    end
  290.  
  291.    rc = RxgdImageGIF(im, graph_name)
  292.  
  293.    rc = RxgdImageDestroy(im)
  294.  
  295.  
  296. rc = stream(infile, 'C', 'close');
  297. return;
  298.  
  299. /* Skip lines in a file */
  300. skiplines: procedure
  301.    parse arg counter, filename
  302.    do counter
  303.       rc = linein(filename);
  304.    end
  305. return 0
  306.  
  307. /* return the length in character pixels for a string. */
  308. stringlength:
  309. parse arg data, fontname
  310.    rc = length(data) * font.fontname.w
  311. return rc
  312.  
  313. /* calculate the starting posistion of a string in a caption based on pixel size */
  314. centerstring: procedure expose font.
  315.    parse arg width, text, fontname
  316.    length = stringlength(text, fontname);
  317.    rc = (width - length)/2;
  318. return rc
  319.  
  320. /* calculate the starting posistion of a string in a caption based on pixel size */
  321. centerstringup: procedure expose font.
  322.    parse arg width, text, fontname
  323.    length = stringlength(text, fontname);
  324.    rc = width - (width - length)/2;
  325. return rc
  326.  
  327. /* calculate the text posistion in the center of a horizontal bar */
  328. CenterBar: procedure expose font. b_width
  329.    parse arg offset, fontname
  330.    rc = offset + b_width / 2 - font.fontname.h/2
  331. return rc
  332.  
  333. /* calculate the text posistion in the center of a vertical bar */
  334. CenterBarUp: procedure expose font. b_width
  335.    parse arg offset, fontname
  336.    rc = offset + b_width / 2 - font.fontname.h/2
  337. return rc
  338.  
  339. /* calculate the text posistion in the center of a horizontal bar */
  340. CenterBarBar: procedure expose font. b_width b_columns
  341.    parse arg offset, fontname
  342.    rc = offset + (b_width / b_columns) / 2 - font.fontname.h/2
  343. return rc
  344.  
  345. /* calculate the text posistion in the center of a vertical bar */
  346. CenterBarBarUp: procedure expose font. b_width b_columns
  347.    parse arg offset, fontname
  348.    rc = offset + (b_width / b_columns) / 2 - font.fontname.h/2
  349. return rc
  350.  
  351.  
  352. /* Dispaly a bar, detail text, and caption. */
  353. DisplayBar: procedure expose bar_data. b_width graph_type im font. height bborder lborder tborder scalemax spacing width rborder b_columns
  354.    parse upper arg i, up
  355.  
  356.    bar_size = b_width / b_columns;
  357.  
  358.    do j = 1 to b_columns
  359.      b_add = ((j-1) * bar_size);
  360.  
  361.      if b_add <> 0 then b_add = b_add + 1;
  362.  
  363.      x_add = 0
  364.      y_add = 0
  365.  
  366.      if up = 'V' then do
  367.         x_add = b_add
  368.         bottom = height - bborder;
  369.         if bar_data.bar_detail.j.i > 0 then do
  370.            top = height - (bborder + tborder);
  371.            top = height - (top * (bar_data.bar_detail.j.i / scalemax)) - bborder;
  372.         end
  373.         else do
  374.            top = height - bborder;
  375.         end
  376.  
  377.         offset = lborder + spacing;
  378.         offset = offset + (b_width + spacing) * (i-1)
  379.         x1 = offset;
  380.         y1 = top;
  381.         x2 = offset + (b_width / b_columns);
  382.         y2 = bottom;
  383.      end
  384.      else do
  385.         y_add = b_add
  386.         if bar_data.bar_detail.j.i > 0 then do
  387.            u_width = width - lborder - rborder;
  388.            bottom = u_width * (bar_data.bar_detail.j.i / scalemax) + lborder;
  389.         end
  390.         else do
  391.            bottom = lborder;
  392.         end
  393.  
  394.  
  395.         offset = tborder + (b_width + spacing) * (i-1)
  396.         x1 = offset;
  397.         y1 = lborder;
  398.         x2 = offset + (b_width / b_columns);
  399.         y2 = bottom;
  400.  
  401.         y1 = offset;
  402.         x1 = lborder;
  403.         y2 = offset + (b_width / b_columns);
  404.         x2 = bottom;
  405.      end
  406.  
  407.      if bar_data.bar_detail.j.i > 0 then do
  408.  
  409.         rc = RxgdImageFilledRectangle(im,,
  410.                  x1 + x_add,y1 + y_add,x2 + x_add, y2+y_add,,
  411.                  bar_data.bar_color.j.i)
  412.         if up = 'V' then
  413.            rc = RxgdImageStringUp(im,,
  414.                     'M',,
  415.                     CenterBarBarUp(x1+x_add, 'M'),,
  416.                     y1 - 5,,
  417.                     bar_data.bar_detail.j.i,,
  418.                     bar_data.bar_detail_color.i)
  419.         else
  420.            rc = RxgdImageString(im,,
  421.                     'M',,
  422.                     x2 + 5,,
  423.                     CenterBarBar(y1+y_add,'M'),,
  424.                     bar_data.bar_detail.j.i,,
  425.                     bar_data.bar_detail_color.i)
  426.      end
  427.    end
  428.  
  429.    /* display Caption text for bar */
  430.    if up = 'V' then do
  431.       rc = RxgdImageStringUp(im,,
  432.                'L',,
  433.                CenterBarUp(x1, 'L'),,
  434.                y2 + stringlength(bar_data.bar_caption.i,'L') + 10,,
  435.                bar_data.bar_caption.i,,
  436.                bar_data.bar_detail_color.i)
  437.  
  438.       /* display Tic Mark on bar */
  439.       rc = RxgdImageLine(im,,
  440.                x1 + (b_width/2),,
  441.                y2,,
  442.                x1 + (b_width/2),,
  443.                y2 + 7,,
  444.                bar_data.bar_detail_color.i)
  445.    end
  446.    else do
  447.       rc = RxgdImageString(im,,
  448.                'L',,
  449.                30,,
  450.                CenterBar(y1, 'L'),,
  451.                bar_data.bar_caption.i,,
  452.                bar_data.bar_detail_color.i)
  453.  
  454.       /* display Tic Mark on bar */
  455.       rc = RxgdImageLine(im,,
  456.                x1 - 7,,
  457.                y1 + (b_width / 2),,
  458.                x1,,
  459.                y1 + (b_width / 2),,
  460.                bar_data.bar_detail_color.i)
  461.  
  462.    end
  463. return 0;
  464.