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

  1. /* ***********************************************************************
  2.  
  3.    MATCH ANALYSIS FOR FOOTBALL REXX SUITE
  4.   ----------------------------------------
  5.                    Copyright  Mark Naughton 1997
  6.  
  7.  
  8. Version    Date     History
  9. --------------------------------------------------------------------------
  10.  1.0       050197   First release.
  11.  1.1       150997   Added code to handle automatic scheduling with dates.
  12.                     As matches are played mid-week, it was better to get
  13.                     all the games in a 7-day period than just reading the
  14.                     Learn file where they are grouped together in the
  15.                     number of teams divide by 2 (some games would be outside
  16.                     this 7-day period). Amended displays.
  17.  1.2       250997   Amended displays of highest/lowest because when using
  18.                     dates, these still gave the week numbers. Routine that
  19.                     calculates the date for the listing is now a callable
  20.                     procedure. Fixed bug where the program expected games
  21.                     to be played every week and added games to weeks that
  22.                     had no games played - the range wasn't incremented
  23.                     enough.
  24.            151297   Tidied display. Added average number of goals per
  25.                     game for highest/lowest.
  26.  
  27. **************************************************************************
  28.  
  29. Procedure
  30. ---------
  31.  
  32. 1. Check files exist. Read Teams.df datafile and store league name.
  33. 2. If automatic scheduling, open Schedule definition file and store
  34.    whether it is run by WEEKS or DATES.
  35. 3. Open Learn file if WEEKS or non-auto sched and get statistics for
  36.    each match for each week. Close file.
  37. 4. Open '.sf' file if DATES and get statistics for each match for each
  38.    week. Increase the range from the start date as the file goes on, adding
  39.    7 days. Close file.
  40. 5. Get the highest and lowest scoring weeks.
  41. 6. Display data and exit.
  42.  
  43. ************************************************************************** */
  44. PARSE ARG league_stuff
  45.  
  46. version      = 1
  47. input_file   = '.df'
  48. input2_file  = '.sflearn'
  49. input3_file  = '.sf'
  50. title        = '*LEAGUE_NAME='
  51. autosched    = '*AUTOSCHD='
  52. separator    = '*'
  53. games.       = '???'
  54. homew.       = '???'
  55. awayw.       = '???'
  56. draws.       = '???'
  57. losses.      = '???'
  58. goalss.      = '???'
  59. weeks        = 0
  60. weekend.     = '???'
  61. months       = "January February March April May June July August September October November December"
  62. not_played   = '__   __'
  63.  
  64.  
  65. parse var league_stuff league_file
  66. league_file = "Data/" || league_file
  67.  
  68. if exists(league_file || input_file) = 0  then exit
  69. if exists(league_file || input2_file) = 0  then exit
  70. if exists(league_file || input3_file) = 0  then exit
  71.  
  72. autos = 0
  73. if open(datafile,league_file || input_file,'r') then do
  74.    do while ~eof(datafile)
  75.       line = readln(datafile)
  76.       if pos(title,line) > 0 then
  77.          league_title = delstr(line,1,13)
  78.       if pos(autosched,line) > 0 then do
  79.          autofile = delstr(line,1,10)
  80.          autos = 1
  81.       end
  82.    end
  83.    close(datafile)
  84. end
  85. else do
  86.    say
  87.    say "ERROR :    (MatchAnalysis)"
  88.    say
  89.    say "Cannot read '"league_file || input_file"' for league name."
  90.    exit
  91. end
  92.  
  93. type = 0
  94. if autos = 1 then do
  95.    if open(datafile,"Data/"||autofile||".schd",'r') then do
  96.       line = readln(datafile)
  97.       if pos("*WEEKS",line) > 0 then
  98.          type = 10
  99.       if pos("*DATES",line) > 0 then do
  100.          type = 20
  101.          start_date = substr(line,8,8)
  102.       end
  103.       close(datafile)
  104.    end
  105.    else do
  106.       say
  107.       say "ERROR :    (MatchAnalysis)"
  108.       say
  109.       say "Cannot read 'Data/"autofile".schd' to check what type of"
  110.       say "schedule it is."
  111.       exit
  112.    end
  113. end
  114.                           /* use this method if its WEEKS or non-auto sched. */
  115. if type < 20 then do
  116.    if open(datafile,league_file || input2_file,'r') then do
  117.       do while ~eof(datafile)
  118.          line = readln(datafile)
  119.          if pos(separator,line) = 0 then do
  120.             if pos(separator,sep) > 0 then do
  121.                weeks = weeks + 1
  122.                sep = ''
  123.                games.weeks = 0
  124.                homew.weeks = 0
  125.                awayw.weeks = 0
  126.                draws.weeks = 0
  127.                losses.weeks = 0
  128.                goalss.weeks = 0
  129.                goals_for = 0
  130.                goals_aga = 0
  131.                goals = 0
  132.             end
  133.             goals_for = strip(substr(line,32,2))
  134.             goals_aga = strip(substr(line,37,2))
  135.             if datatype(goals_for,'n') = 0 | datatype(goals_aga,'n') = 0 then
  136.                leave
  137.             games.weeks = games.weeks + 1
  138.             goalss.weeks = goalss.weeks + goals_for + goals_aga
  139.  
  140.             if goals_for > goals_aga then do
  141.                homew.weeks = homew.weeks + 1
  142.                losses.weeks= losses.weeks + 1
  143.             end
  144.             if goals_for = goals_aga then do
  145.                draws.weeks = draws.weeks + 1
  146.             end
  147.             if goals_for < goals_aga then do
  148.                awayw.weeks = awayw.weeks + 1
  149.                losses.weeks= losses.weeks + 1
  150.             end
  151.          end
  152.          else
  153.             sep = line
  154.       end
  155.       close(datafile)
  156.    end
  157.    else do
  158.       say
  159.       say "ERROR :    (MatchAnalysis)"
  160.       say
  161.       say "Cannot read '"league_file || input2_file"' datafile."
  162.       exit
  163.    end
  164. end                      /* DATES and automatic scheduling */
  165.  
  166. if type = 20 then do
  167.    weeks = 1
  168.    mnth = substr(start_date,3,2)
  169.    ndate= substr(start_date,5,4)||mnth||substr(start_date,1,2)
  170.    range = date('b',ndate,'s')
  171.    range = range + 6
  172.    games.weeks = 0
  173.    weekend.weeks = range
  174.    homew.weeks = 0
  175.    awayw.weeks = 0
  176.    draws.weeks = 0
  177.    losses.weeks = 0
  178.    goalss.weeks = 0
  179.    goals_for = 0
  180.    goals_aga = 0
  181.    goals = 0
  182.    if open(datafile,league_file || input3_file,'r') then do
  183.       do while ~eof(datafile)
  184.          line = readln(datafile)
  185.          if pos(separator,line) > 0 then do
  186.             if pos("*Date:",line) > 0 then do
  187.                year = word(line,5)
  188.                mnth = word(line,4)
  189.                day  = word(line,3)
  190.                cv = 0
  191.                do i=1 to 12
  192.                   if pos(mnth,word(months,i)) > 0 then do
  193.                      cv = i
  194.                      leave
  195.                   end
  196.                end
  197.                sd   = year||right(cv,2,0)||right(day,2,0)
  198.                search_date = date('b',sd,'s')
  199.  
  200.                if search_date > range then do
  201.                   range = range + 7
  202.                   diff  = 1
  203.                                                /* this hopes to skip weeks where no games are played. */
  204.                   do while (diff > 0)
  205.                      diff = search_date - range
  206.                      if diff > 0 then
  207.                         range = range + 7
  208.                   end
  209.  
  210.                   weeks = weeks + 1
  211.                   games.weeks = 0
  212.                   weekend.weeks = range
  213.                   homew.weeks = 0
  214.                   awayw.weeks = 0
  215.                   draws.weeks = 0
  216.                   losses.weeks = 0
  217.                   goalss.weeks = 0
  218.                   goals_for = 0
  219.                   goals_aga = 0
  220.                   goals = 0
  221.                end
  222.             end
  223.          end
  224.          if pos(separator,line) = 0 & pos(not_played,line) = 0 then do
  225.             goals_for = strip(substr(line,32,2))
  226.             goals_aga = strip(substr(line,37,2))
  227.             if datatype(goals_for,'n') > 0 & datatype(goals_aga,'n') > 0 then do
  228.  
  229.                games.weeks = games.weeks + 1
  230.                goalss.weeks = goalss.weeks + goals_for + goals_aga
  231.  
  232.                if goals_for > goals_aga then do
  233.                   homew.weeks = homew.weeks + 1
  234.                   losses.weeks= losses.weeks + 1
  235.                end
  236.                if goals_for = goals_aga then do
  237.                   draws.weeks = draws.weeks + 1
  238.                end
  239.                if goals_for < goals_aga then do
  240.                   awayw.weeks = awayw.weeks + 1
  241.                   losses.weeks= losses.weeks + 1
  242.                end
  243.             end
  244.          end
  245.       end
  246.       close(datafile)
  247.    end
  248.    else do
  249.       say
  250.       say "ERROR :    (MatchAnalysis)"
  251.       say
  252.       say "Cannot read '"league_file || input3_file"' datafile."
  253.       exit
  254.    end
  255. end
  256.  
  257. lowest = 10000
  258. highest= 0
  259. h = 0
  260. l = 0
  261. g = 0
  262. los = 0
  263. losc= 0
  264. hwn = 0
  265. hwnc= 0
  266. awn = 0
  267. awnc= 0
  268. dra = 0
  269. drac= 0
  270. do i=1 to weeks
  271.    if games.i ~= 0 then do
  272.       if goalss.i > highest then do
  273.          highest = goalss.i
  274.          h = i
  275.       end
  276.       if goalss.i < lowest then do
  277.          lowest = goalss.i
  278.          l = i
  279.       end
  280.       g = g + games.i
  281.       if losses.i > los then do
  282.          los = losses.i
  283.          losc= i
  284.       end
  285.       if homew.i > hwn then do
  286.          hwn = homew.i
  287.          hwnc= i
  288.       end
  289.       if awayw.i > awn then do
  290.          awn = awayw.i
  291.          awnc= i
  292.       end
  293.       if draws.i > dra then do
  294.          dra = draws.i
  295.          drac= i
  296.       end
  297.    end
  298. end
  299.  
  300. hgpmwk = 0
  301. lgpmwk = 0
  302. hgpm   = 0
  303. lgpm   = 1000
  304. tscr   = 0
  305.  
  306. do i=1 to weeks
  307.    if games.i ~= 0 then do
  308.       tscr = trunc(goalss.i/games.i,2)
  309.       if tscr > hgpm then do
  310.          hgpm = tscr
  311.          if type < 20 then
  312.             hgpmwk = i
  313.          else
  314.             hgpmwk = weekend.i
  315.       end
  316.       if tscr < lgpm then do
  317.          lgpm = tscr
  318.          if type < 20 then
  319.             lgpmwk = i
  320.          else
  321.             lgpmwk = weekend.i
  322.       end
  323.    end
  324. end
  325.  
  326. say
  327. say center("Match Analysis for '"league_title"'",78)
  328. say "-------------------------------------------------------------------------------"
  329. say
  330. say "Matches Played : "g
  331. say
  332. if type < 20 then do
  333.    say "Highest Number of Home Wins: Week No."hwnc"  with "hwn" wins."
  334.    say "                  Away Wins: Week No."awnc"  with "awn" wins."
  335.    say "                  Losses   : Week No."losc"  with "los" losses."
  336.    say "                  Draws    : Week No."drac"  with "dra" draws."
  337.    say
  338.    say "Highest Scoring: Week No."h"  with "highest" goals."
  339.    say "Lowest Scoring : Week No."l"  with "lowest" goals."
  340.    say
  341.    say "Highest Average Goals Per Match: Week No."hgpmwk"  with "hgpm" goals per match."
  342.    say "Lowest Average Goals Per Match : Week No."lgpmwk"  with "lgpm" goals per match."
  343. end
  344. else do
  345.    say "Highest Number of Home Wins: Week ending '"getweek(weekend.hwnc)"'  with "hwn" wins."
  346.    say "                  Away Wins: Week ending '"getweek(weekend.awnc)"'  with "awn" wins."
  347.    say "                  Losses   : Week ending '"getweek(weekend.losc)"'  with "los" losses."
  348.    say "                  Draws    : Week ending '"getweek(weekend.drac)"'  with "dra" draws."
  349.    say
  350.    say "Highest Scoring: Week ending '"getweek(weekend.h)"'  with "highest" goals."
  351.    say "Lowest Scoring : Week ending '"getweek(weekend.l)"'  with "lowest" goals."
  352.    say
  353.    say "Highest Average Goals Per Match: Week ending '"getweek(hgpmwk)"'  with "hgpm" goals per match."
  354.    say "Lowest Average Goals Per Match : Week ending '"getweek(lgpmwk)"'  with "lgpm" goals per match."
  355. end
  356. say
  357. say
  358. if type < 20 then do
  359.    say "Week No.    Games        Wins                          Goals"
  360.    say "            Played    Home  Away    Draws    Losses    Scored"
  361. end
  362. else do
  363.    say "Week        Games        Wins                          Goals"
  364.    say "Ending      Played    Home  Away    Draws    Losses    Scored"
  365. end
  366. say "---------   ------    ----------    -----    ------    ------"
  367. say
  368. if type < 20 then do
  369.    do i=1 to weeks
  370.       if games.i ~= 0 then
  371.          say "  "left(i,6)"      "left(games.i,4)"     "left(homew.i,3)"   "left(awayw.i,3)"     "left(draws.i,4)"     "left(losses.i,5)"     "left(goalss.i,5)
  372.    end
  373. end
  374. if type = 20 then do
  375.    do i=1 to weeks
  376.       if games.i ~= 0 then do
  377.          sd = getweek(weekend.i)
  378.          say left(sd,13)" "left(games.i,4)"     "left(homew.i,3)"   "left(awayw.i,3)"     "left(draws.i,4)"     "left(losses.i,5)"     "left(goalss.i,5)
  379.       end
  380.    end
  381. end
  382. say
  383. say "-------------------------------------------------------------------------------"
  384.  
  385. exit
  386.  
  387. /* Procedure --------------------------------------------------------- */
  388.  
  389. getweek: procedure
  390. parse arg days
  391.  
  392. dd = days - 722450
  393. dd = date('n',dd,'i')
  394. dd = delstr(dd,8,2)
  395. return dd
  396.  
  397. /* ------------------------------------------------------------------- */