home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format 126 / af126a.adf / Football.lzx / football / exec / Stats.rexx < prev    next >
OS/2 REXX Batch file  |  1999-05-22  |  11KB  |  341 lines

  1. /* ***********************************************************************
  2.  
  3.    STATS PROGRAM FOR FOOTBALL REXX SUITE
  4.   ---------------------------------------
  5.                    Copyright  Mark Naughton 1996
  6.  
  7.  
  8. Version    Date     History
  9. --------------------------------------------------------------------------
  10.  1.0       270996   First release.
  11.            300996   Amended display for Performance. Tidied some code and
  12.                     added an error message.
  13.  1.1       111196   Added to Football as a callable component. Amended for
  14.                     different leagues. Fixed bug where if one match was
  15.                     played, the performance wasn't shown. Fixed bug where
  16.                     the longest performance record wasn't correctly done.
  17.                     Removed messages.
  18.            131196   Added checks for files - if not found, exits without
  19.                     a message.
  20.            181196   Fixed bug where if 3 matches had been played, the
  21.                     performance was not printed correctly as the number
  22.                     of iterations required to format it was wrong.
  23.            201196   Added code to display home and away performance.
  24.            211196   Updated and tidied the display.
  25.  1.2       110497   Added code to support Points_Per_Goals.
  26.            151297   Tidied display.
  27.  1.3       190499   Added clean sheet to stats and added Key. Remoulded
  28.                     the display.
  29.  
  30.  
  31. **************************************************************************
  32.  
  33. Procedure
  34. ---------
  35.  
  36. 1. Check files exist. Read Teams.df datafile and store teams and points.
  37. 2. Close file. Prompt user for a team to display fixtures for.
  38. 3. Display data and open 'Teams.sflearn'.
  39. 4. Read data about matches that the selected team has played and store it.
  40.    This applies to both home and away matches even though the data is on
  41.    different panels.
  42. 5. Close file and then display data.
  43. 6. Calculate record and performance and then display these. Then exit...
  44.  
  45. ************************************************************************** */
  46. PARSE ARG league_stuff
  47.  
  48. version      = 1
  49. input_file   = '.df'
  50. input2_file  = '.sflearn'
  51. title        = '*LEAGUE_NAME='
  52. points_win   = '*POINTS_PER_WIN='
  53. points_drw   = '*POINTS_PER_DRW='
  54. points_lse   = '*POINTS_PER_LSE='
  55. points_gls   = '*POINTS_PER_GLS='
  56. separator    = '*'
  57. teams.       = '???'
  58. counter      = 0
  59. not_played   = '__   __'
  60. hplay        = 0
  61. hwin         = 0
  62. hdraw        = 0
  63. hloss        = 0
  64. hgoals       = 0
  65. hagoals      = 0
  66. hpts         = 0
  67. hcls         = 0
  68. aplay        = 0
  69. awin         = 0
  70. adraw        = 0
  71. aloss        = 0
  72. agoals       = 0
  73. aagoals      = 0
  74. apts         = 0
  75. acls         = 0
  76. ptsgls       = 0
  77.  
  78.  
  79. parse var league_stuff league_file search_team
  80. league_file = "Data/" || league_file
  81.  
  82. if exists(league_file || input_file) = 0  then exit
  83. if exists(league_file || input2_file) = 0 then exit
  84.  
  85. if open(datafile,league_file || input_file,'r') then do
  86.    do while ~eof(datafile)
  87.       line = readln(datafile)
  88.       if pos(title,line) > 0 then       league_title = delstr(line,1,13)
  89.       if pos(points_win,line) > 0 then  ptswin=delstr(line,1,16)
  90.       if pos(points_drw,line) > 0 then  ptsdrw=delstr(line,1,16)
  91.       if pos(points_lse,line) > 0 then  ptslse=delstr(line,1,16)
  92.       if pos(points_gls,line) > 0 then  ptsgls=delstr(line,1,16)
  93.       if pos(separator,line) = 0 then do
  94.          line = strip(line)
  95.          if counter = 0 then do
  96.             teams.1 = line
  97.             counter = 1
  98.          end
  99.          else do
  100.             counter       = counter + 1
  101.             teams.counter = line
  102.          end
  103.       end
  104.    end
  105.    close(datafile)
  106.  
  107.    sel=-1
  108.    search_team = strip(search_team)
  109.    do i=1 to counter
  110.       if pos(search_team,teams.i) > 0 then sel = i
  111.    end
  112.  
  113.    if sel > 0 then do
  114.       say
  115.       say center("Display Team Statistics in '"league_title"'",78)
  116.       say "-------------------------------------------------------------------------------"
  117.       say
  118.       say
  119.       say "  Statistics For: "upper(teams.sel)
  120.       say
  121.       say
  122.       say
  123.       matches = 0
  124.       lrecord = ''
  125.       awayperf= ''
  126.       homeperf= ''
  127.       if open(datafile,league_file || input2_file,'r') then do
  128.          do while ~eof(datafile)
  129.             line = readln(datafile)
  130.             if pos(separator,line) = 0 then do
  131.                if pos(not_played,line) = 0 then do
  132.                   home_team = strip(substr(line,1,30))
  133.                   goals_for = substr(line,32,2)
  134.                   goals_aga = substr(line,37,2)
  135.                   away_team = strip(substr(line,41,30))
  136.                   strng     = strip(teams.sel)
  137.  
  138.                   if strng = home_team then do
  139.                      if goals_aga = 0 then
  140.                         hcls = hcls + 1
  141.                      if goals_for > goals_aga then do
  142.                         hwin = hwin + 1
  143.                         ltemp = 'W'
  144.                         hpts = hpts + ptswin
  145.                      end
  146.                      if goals_for = goals_aga then do
  147.                         hdraw = hdraw + 1
  148.                         ltemp = 'D'
  149.                         hpts = hpts + ptsdrw
  150.                      end
  151.                      if goals_for < goals_aga then do
  152.                         hloss = hloss + 1
  153.                         ltemp = 'L'
  154.                         hpts = hpts + ptslse
  155.                      end
  156.                      lrecord = insert(ltemp,lrecord,matches+1,1)
  157.                      homeperf= insert(ltemp,homeperf,hplay+1,1)
  158.                      hgoals  = hgoals + goals_for
  159.                      hagoals = hagoals+ goals_aga
  160.                      hplay   = hplay + 1
  161.                      matches = matches + 1
  162.                      hpts    = hpts + (goals_for * ptsgls)
  163.                   end
  164.                   if strng = away_team then do
  165.                      if goals_for = 0 then
  166.                         acls = acls + 1
  167.                      if goals_for > goals_aga then do
  168.                         aloss = aloss + 1
  169.                         ltemp = 'L'
  170.                         apts  = apts + ptslse
  171.                      end
  172.                      if goals_for = goals_aga then do
  173.                         adraw = adraw + 1
  174.                         ltemp = 'D'
  175.                         apts  = apts + ptsdrw
  176.                      end
  177.                      if goals_for < goals_aga then do
  178.                         awin  = awin + 1
  179.                         ltemp = 'W'
  180.                         apts  = apts + ptswin
  181.                      end
  182.                      lrecord = insert(ltemp,lrecord,matches+1,1)
  183.                      awayperf= insert(ltemp,awayperf,aplay+1,1)
  184.                      agoals  = agoals + goals_aga
  185.                      aagoals = aagoals+ goals_for
  186.                      aplay   = aplay + 1
  187.                      matches = matches + 1
  188.                      apts    = apts + (goals_aga * ptsgls)
  189.                   end
  190.                end
  191.             end
  192.          end
  193.          close(datafile)
  194.          say
  195.          if matches = 0 then do
  196.             say "  No matches yet played."
  197.             say
  198.          end
  199.          else do
  200.             say "  Home                                       Away"
  201.             say
  202.             say "  Pl  W   D   L   Cln  Gf   Ga   Pts         Pl  W   D   L   Cln  Gf   Ga   Pts"
  203.             say "  --------------------------------------     --------------------------------------"
  204.             h1 = "  "left(hplay,3)" "
  205.             h2 = left(hwin,3)" "
  206.             h3 = left(hdraw,3)" "
  207.             h4 = left(hloss,3)" "
  208.             h5 = left(hgoals,4)" "
  209.             h6 = left(hagoals,4)" "
  210.             h7 = left(hpts,6)"      "
  211.             h8 = left(hcls,4)" "
  212.             a1 = left(aplay,3)" "
  213.             a2 = left(awin,3)" "
  214.             a3 = left(adraw,3)" "
  215.             a4 = left(aloss,3)" "
  216.             a5 = left(agoals,4)" "
  217.             a6 = left(aagoals,4)" "
  218.             a7 = left(apts,6)
  219.             a8 = left(acls,4)" "
  220.             say h1||h2||h3||h4||h8||h5||h6||h7||a1||a2||a3||a4||a8||a5||a6||a7
  221.             say
  222.             say
  223.             say
  224.             say
  225.             say
  226.             re  = 0
  227.             lre = 0
  228.             do i=1 to matches+1
  229.                if substr(lrecord,i,1) = 'W' then re = re + 1
  230.                if substr(lrecord,i,1) = 'D' then re = re + 1
  231.                if substr(lrecord,i,1) = 'L' then do
  232.                   if re > lre then lre = re
  233.                   re = 0
  234.                end
  235.             end
  236.             if lre = 0 then lre = re
  237.  
  238.             lrecord = strip(lrecord)
  239.             countr = (matches * 2) - 1
  240.             if matches > 8 then do
  241.                lrecord = right(lrecord,8)
  242.                countr  = 15
  243.             end
  244.             call format_perf(lrecord,countr)
  245.             if countr = 1 then ptemp = lrecord
  246.             if matches < 9 then
  247.                say "  Performance over last "matches" games: "ptemp
  248.             else
  249.                say "  Performance over last 8 games: "ptemp
  250.  
  251.             homeperf=strip(homeperf)
  252.             hcountr = (hplay * 2) - 1
  253.             if hplay > 8 then do
  254.                homeperf = right(homeperf,8)
  255.                hcountr  = 15
  256.             end
  257.             call format_perf(homeperf,hcountr)
  258.             if hplay = 1 then ptemp = homeperf
  259.             say
  260.             say "                Home Record    : "ptemp
  261.  
  262.             awayperf=strip(awayperf)
  263.             acountr = (aplay * 2) - 1
  264.             if aplay > 8 then do
  265.                awayperf = right(awayperf,8)
  266.                acountr  = 15
  267.             end
  268.             call format_perf(awayperf,acountr)
  269.             if aplay = 1 then ptemp = awayperf
  270.             say
  271.             say "                Away Record    : "ptemp
  272.             say
  273.             say
  274.             say
  275.             say "     Current undefeated run    : "re" games."
  276.             say "     Longest undefeated run    : "lre" games."
  277.             say
  278.             say
  279.             say
  280.             say
  281.             say
  282.             say
  283.             say
  284.             say
  285.             say
  286.          end
  287.          say "-------------------------------------------------------------------------------"
  288.          say "Key:"
  289.          say "      Pl   Played         Gf   Goals For"
  290.          say "      W    Win            Ga   Goals Against"
  291.          say "      D    Draw           Pts  Points"
  292.          say "      L    Loss"
  293.          say "      Cln  Clean Sheet"
  294.       end
  295.       else do
  296.          say
  297.          say "ERROR :    (Stats)"
  298.          say
  299.          say "Cannot read '"league_file || input2_file"' datafile."
  300.          exit
  301.       end
  302.    end
  303.    else do
  304.       say
  305.       say "ERROR :    (Stats)"
  306.       say
  307.       say "Incorrect team. '"search_team"' cannot be found in this"
  308.       say "league."
  309.       exit
  310.    end
  311. end
  312. else do
  313.    say
  314.    say "ERROR :    (Stats)"
  315.    say
  316.    say "Cannot read '"league_file || input_file"' datafile."
  317. end
  318.  
  319. exit
  320.  
  321. /* Routine ----------------------------------------------------------- */
  322.  
  323. format_perf:
  324. ARG fstrg,counter
  325.  
  326. ptemp = ''
  327. i = 1
  328. j = 1
  329. do while i <= counter
  330.    ptemp = insert(substr(fstrg,j,1),ptemp,i,1)
  331.    i = i + 1
  332.    j = j + 1
  333.    if i < counter then do
  334.       ptemp = insert(".",ptemp,i,1)
  335.       i = i + 1
  336.    end
  337. end
  338. ptemp = strip(ptemp)
  339. return
  340.  
  341. /* ------------------------------------------------------------------- */