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

  1. /* ***********************************************************************
  2.  
  3.    PERFORMANCE RATING PROGRAM FOR FOOTBALL REXX SUITE
  4.   ----------------------------------------------------
  5.  
  6.     Copyright  Mark Naughton 1998
  7.                                         From an idea by Steve Holland
  8.  
  9. Version    Date     History
  10. --------------------------------------------------------------------------
  11.  1.0       160998   First release. Will give different tables according to
  12.                     the values set below.
  13.            230998   Bug found where the values to be calculated for the
  14.                     position were summed to be Zero - Program failed.
  15.                     Fixed.
  16.  
  17. **************************************************************************
  18.  
  19. Procedure
  20. ---------
  21.  
  22. 1. Check files exist. Open 'Teams.df'.
  23. 2. Read in teams and their associated data; WIN, DRAW, LOST etc.
  24. 3. Close file.
  25. 4. Open 'Teams.sf' for reading.
  26. 5. Read each line that has a game played, and from that get the team names
  27.    and the score. Then update the relevant team data with the result.
  28. 6. Format data in form of a league table to two arrays.
  29. 8. Sort array.
  30. 9. Display table and exit.
  31.  
  32. ************************************************************************** */
  33. PARSE ARG league_file
  34.  
  35. version = 1
  36.  
  37. hgfp = 1          /* Points to be added for each goal scored at Home */
  38. hgap = 1.5        /* Points to be added for each goal scored against at Home */
  39. hcsp = 2          /* Points to be added for each clean sheet at Home */
  40. hpts = 1          /* Points to be added for points received at Home */
  41. agfp = 1.5        /* Points to be added for each goal scored Away */
  42. agap = 1          /* Points to be added for each goal scored against Away */
  43. acsp = 3          /* Points to be added for each clean sheet Away */
  44. apts = 1.5        /* Points to be added for points received Away */
  45. switch = 0
  46.  
  47. league_file  = "Data/" || league_file
  48. input2_file  = '.sf'
  49. input3_file  = '.df'
  50. title        = '*LEAGUE_NAME='
  51. points_win   = '*POINTS_PER_WIN='
  52. points_drw   = '*POINTS_PER_DRW='
  53. points_lse   = '*POINTS_PER_LSE='
  54. separator    = '*'
  55. teams.       = '???'
  56. teams2.      = '???'
  57. h_gof.       = '???'
  58. h_goa.       = '???'
  59. h_pts.       = '???'
  60. h_cls.       = '???'
  61. h_gms.       = '???'
  62. a_gof.       = '???'
  63. a_goa.       = '???'
  64. a_pts.       = '???'
  65. a_cls.       = '???'
  66. a_gms.       = '???'
  67. t_num.       = '???'
  68. ptswin       = 2
  69. ptsdrw       = 1
  70. ptslse       = 0
  71. not_played   = '__   __'
  72.  
  73.  
  74. if exists(league_file || input2_file) = 0 then exit
  75. if exists(league_file || input3_file) = 0 then exit
  76.  
  77. tcount = 0
  78. if open(datafile,league_file || input3_file,'r') then do
  79.    do while ~eof(datafile)
  80.       line = readln(datafile)
  81.       if pos(title,line) > 0 then        league_title = delstr(line,1,13)
  82.       if pos(points_win,line) > 0 then   ptswin=delstr(line,1,16)
  83.       if pos(points_drw,line) > 0 then   ptsdrw=delstr(line,1,16)
  84.       if pos(points_lse,line) > 0 then   ptslse=delstr(line,1,16)
  85.       if pos(separator,line) = 0 then do
  86.          line = strip(line)
  87.          tcount       = tcount + 1
  88.          teams.tcount = line
  89.       end
  90.    end
  91.    close(datafile)
  92. end
  93. else do
  94.    say
  95.    say "ERROR :    (PerformanceRating)"
  96.    say
  97.    say "Unable to open '"league_file || input3_file"' file."
  98.    exit
  99. end
  100.  
  101. do i=1 to tcount
  102.    h_gof.i = 0
  103.    h_goa.i = 0
  104.    h_pts.i = 0
  105.    h_cls.i = 0
  106.    h_gms.i = 0
  107.    a_gof.i = 0
  108.    a_goa.i = 0
  109.    a_pts.i = 0
  110.    a_cls.i = 0
  111.    a_gms.i = 0
  112. end
  113.  
  114. if open(datafile,league_file || input2_file,'r') then do
  115.    do while ~eof(datafile)
  116.       line = readln(datafile)
  117.       if pos(separator,line) = 0 then do
  118.          if pos(not_played,line) = 0 then do
  119.             home_team = strip(substr(line,1,30))
  120.             goals_for = substr(line,32,2)
  121.             goals_aga = substr(line,37,2)
  122.             away_team = strip(substr(line,41,30))
  123.  
  124.             do i=1 to tcount
  125.                if home_team = teams.i then do
  126.                   h_gof.i = h_gof.i + goals_for
  127.                   h_goa.i = h_goa.i + goals_aga
  128.                   h_gms.i = h_gms.i + 1
  129.                   if goals_aga = 0 then
  130.                      h_cls.i = h_cls.i + 1
  131.                   if goals_for = goals_aga then
  132.                      h_pts.i = h_pts.i + ptsdrw
  133.                   if goals_for < goals_aga then
  134.                      h_pts.i = h_pts.i + ptslse
  135.                   if goals_for > goals_aga then
  136.                      h_pts.i = h_pts.i + ptswin
  137.                end
  138.             end
  139.             do i=1 to tcount
  140.                if away_team = teams.i then do
  141.                   a_gof.i = a_gof.i + goals_aga
  142.                   a_goa.i = a_goa.i + goals_for
  143.                   a_gms.i = a_gms.i + 1
  144.                   if goals_for = 0 then
  145.                      a_cls.i = a_cls.i + 1
  146.                   if goals_for = goals_aga then
  147.                      a_pts.i = a_pts.i + ptsdrw
  148.                   if goals_for < goals_aga then
  149.                      a_pts.i = a_pts.i + ptswin
  150.                   if goals_for > goals_aga then
  151.                      a_pts.i = a_pts.i + ptslse
  152.                end
  153.             end
  154.          end
  155.       end
  156.    end
  157.    close(datafile)
  158. end
  159. else do
  160.    say
  161.    say "ERROR :    (PerformanceRating)"
  162.    say
  163.    say "Unable to open '"league_file || input2_file"'."
  164.    exit
  165. end
  166.  
  167. do i=1 to tcount
  168.    hp1 = ((h_gof.i * hgfp) + (h_cls.i * hcsp) + (h_pts.i * hpts))
  169.    hp2 =(h_goa.i * hgap)
  170.    hp = hp1-hp2
  171.    ap1 = ((a_gof.i * agfp) + (a_cls.i * acsp) + (a_pts.i * apts))
  172.    ap2 = (a_goa.i * agap)
  173.    ap = ap1-ap2
  174.    if switch = 1 then do
  175.       hp = trunc(hp / h_gms.i,3)
  176.       ap = trunc(ap / a_gms.i,3)
  177.    end
  178.    t_num.i = trunc(hp + ap,3)
  179. end
  180.  
  181. do i=1 to tcount
  182.    line = teams.i
  183.    line = insert(" ",line,length(line)+1,30-length(line))
  184.    hg = right(h_gms.i,3)
  185.    hf = right(h_gof.i,3)
  186.    ha = right(h_goa.i,3)
  187.    hc = right(h_cls.i,3)
  188.    hp = right(h_pts.i,3)
  189.    ag = right(a_gms.i,3)
  190.    af = right(a_gof.i,3)
  191.    aa = right(a_goa.i,3)
  192.    ac = right(a_cls.i,3)
  193.    ap = right(a_pts.i,3)
  194.    teams.i = line"    "hg"  "hf"  "ha" "hc" "hp"   "ag"  "af"  "aa" "ac" "ap"      "right(t_num.i,7,' ')
  195.    teams2.i= line"    "hg"  "hf"  "ha" "hc" "hp"   "ag"  "af"  "aa" "ac" "ap"      "right(t_num.i,7,' ')
  196. end
  197.  
  198. ctr = 0
  199. do while swapctr > 0
  200.    swapctr=9
  201.    do i=1 to tcount-1
  202.       swapdone=0
  203.       j = i + 1
  204.       if strip(substr(teams.i,84,12)) < strip(substr(teams.j,84,12)) then do
  205.          teams.i = teams2.j
  206.          teams.j = teams2.i
  207.          teams2.i= teams.i
  208.          teams2.j= teams.j
  209.          swapdone= 1
  210.          ctr = ctr + 1
  211.       end
  212.       if swapdone = 1 then
  213.          break
  214.    end
  215.    if ctr = 0 then
  216.       swapctr = 0
  217.    else
  218.       ctr = 0
  219. end
  220.  
  221. /* ---------------------------------------------- */
  222.  
  223. say
  224. say center("Performance Ratings For '"league_title"'",88)
  225. say "-------------------------------------------------------------------------------------------------"
  226. say
  227. if switch = 1 then
  228.    say "Performance Ratings:  Calculated by division of Matches."
  229. say
  230. say "                                       Home                    Away"
  231. say
  232. say "Pos Team                               Pld GlsF GlsA Cln Pts   Pld GlsF GlsA Cln Pts       Number"
  233. say "-------------------------------------------------------------------------------------------------"
  234.  
  235. do i=1 to tcount
  236.    if i<10 then
  237.       say " "i"  "teams.i
  238.    else
  239.       say i"  "teams.i
  240. end
  241. say "-------------------------------------------------------------------------------------------------"
  242. say
  243.  
  244. exit