home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / httpa200.zip / chart.cmd < prev    next >
OS/2 REXX Batch file  |  1995-11-19  |  13KB  |  431 lines

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