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

  1. /* ***********************************************************************
  2.  
  3.    CUP INFORMATION PROGRAM FOR FOOTBALL REXX SUITE
  4.   -------------------------------------------------
  5.                    Copyright  Mark Naughton 1998
  6.  
  7.  
  8. Version    Date     History
  9. --------------------------------------------------------------------------
  10.  1.0       140998   First release.
  11.            160998   Changed way best record is calculated.
  12.  
  13. **************************************************************************
  14.  
  15. Procedure
  16. ---------
  17.  
  18. 1. Check files exist.
  19. 2. Read '.cf' file and get details. Read '.cfrw' and do the same.
  20. 3. If '.cfsave' doesn't exist, read the '.scf' file adjusting the output
  21.    for replays, extra time, first leg and penalties.
  22. 4. If '.cfsave' is found, read to display current matches.
  23. 5. Read '.scf' into an array. Search array, storing goals. When finished,
  24.    search through the team array, calculating the best record :
  25.  
  26.     (Goals Scored / Goals Away) * Matches Played
  27.  
  28.     Goals Scored = Goals Scored At Home + (Goals Scored Away * 1.5)
  29.  
  30. 6. Write data to a file and call an external sort program. Read the details
  31.    back in and delete the temporary file.
  32. 7. Adjust options.
  33. 8. Display report : display options/rounds, teams and the best record, the
  34.    current round matches and if the history file has been selected, read
  35.    the file for previous/current winners.
  36. 9. Exit.
  37.  
  38. ************************************************************************** */
  39. PARSE ARG league_stuff
  40.  
  41. version      = 1
  42. input_file   = '.cf'
  43. input2_file  = '.scf'
  44. input3_file  = '.cfrw'
  45. input4_file  = '.cfh'
  46. input5_file  = '.cfsave'
  47. output_file  = 'RAM:Football.tempcup'
  48. title        = '*CUP_TITLE='
  49. thirdpl      = '*CUP_THIRD='
  50. rounddef     = '*CUP_RNDDEF='
  51. currond      = '*CUP_ROND='
  52. currrondn    = '*CUP_CRDN='
  53. roundddef    = '*CUP_RDEF='
  54. cuphistory   = '*CUP_HISTORY='
  55. thirdpl      = '*CUP_THIRD='
  56. teams_cnt    = '*CUP_TCNT='
  57. awaygs       = '*CUP_AWAYG='
  58. schedtype    = '*CUP_SCHEDULE='
  59. first        = '*WINNER='
  60. pkversion    = '*  Version='
  61. matches.     = '???'
  62. separator    = '*'
  63. teams.       = '???'
  64. rnds.        = '???'
  65. lines.       = '???'
  66. replays.     = '???'
  67. working.     = '???'
  68. losing.      = '???'
  69. repct        = 0
  70. repno.       = '???'
  71. tcount       = 0
  72. ttc          = 0
  73. rndcnt       = 0
  74. linesct      = 0
  75. league_file  = "Data/"league_stuff
  76. curnd        = ''
  77. curndn       = 0
  78. not_played   = "__   __"
  79. mcount       = 0
  80. bstats.      = '???'
  81. btemp.       = '???'
  82. btcnt        = 0
  83. bpstats.     = '???'
  84. bgsstats.    = '???'
  85. bgastats.    = '???'
  86. bagstats.    = '???'
  87.  
  88.  
  89. parse var league_stuff league_file search_team
  90. league_file = "Data/" || league_file
  91.  
  92. if exists(league_file || input_file) = 0  then exit
  93. if exists(league_file || input2_file) = 0 then exit
  94.  
  95. tcount = 0
  96. if open(datafile,league_file || input_file,'r') then do
  97.    do while ~eof(datafile)
  98.       line = readln(datafile)
  99.       if pos(title,line) > 0 then        cupname  = delstr(line,1,11)
  100.       if pos(thirdpl,line) > 0 then      third    = delstr(line,1,11)
  101.       if pos(awaygs,line) > 0 then       awaygoals= delstr(line,1,11)
  102.       if pos(pkversion,line) > 0 then    fversion = delstr(line,1,12)
  103.       if pos(cuphistory,line) > 0 then   cuph     = delstr(line,1,13)
  104.       if pos(schedtype,line) > 0 then    scht     = delstr(line,1,14)
  105.       if pos(rounddef,line) > 0 then do
  106.          rndcnt = rndcnt + 1
  107.          rnds.rndcnt = delstr(line,1,12)
  108.       end
  109.       if pos(separator,line) = 0 then do
  110.          line = strip(line)
  111.          tcount       = tcount + 1
  112.          teams.tcount = line
  113.       end
  114.    end
  115.    close(datafile)
  116. end
  117. else do
  118.    say
  119.    say "ERROR :    (CupInformation)"
  120.    say
  121.    say "Unable to open '"league_file || input_file"' file."
  122.    exit
  123. end
  124.  
  125. if open(datafile,league_file || input3_file,'r') then do
  126.    do while ~eof(datafile)
  127.       line = readln(datafile)
  128.       if pos(currond,line)   > 0 then crond  = strip(substr(line,11,2))
  129.       if pos(roundddef,line) > 0 then tcrondn= strip(substr(line,11,5))
  130.       if pos(currrondn,line) > 0 then do
  131.          crondn = strip(substr(line,11,30))
  132.          tleg_no = 0
  133.          if pos("1 Leg",line) > 0 then tleg_no = 1
  134.          if pos("2 Legs",line) > 0 then tleg_no = 2
  135.       end
  136.    end
  137.    close(datafile)
  138. end
  139. else do
  140.    say
  141.    say "ERROR :    (CupInformation)"
  142.    say
  143.    say "Unable to open '"league_file || input3_file"' file."
  144.    exit
  145. end
  146.  
  147. a      = 0
  148. mcount = 0
  149. if exists(league_file || input5_file) = 0 then do
  150.    if open(datafile,league_file || input2_file,'r') then do
  151.       do while ~eof(datafile)
  152.          line = readln(datafile)
  153.          if pos("*Round="strip(tcrondn),line) > 0 then
  154.             a = 1
  155.          if a = 1 then do
  156.             if pos(separator,line) = 0 & pos('#',line) = 0 then do
  157.                mcount = mcount + 1
  158.                matches.mcount = line
  159.             end
  160.             else do
  161.                if pos("Replay",line) > 0 then do
  162.                   mcount = mcount + 1
  163.                   matches.mcount = " "
  164.                   mcount = mcount + 1
  165.                   matches.mcount = "Replay"
  166.                   mcount = mcount + 1
  167.                   matches.mcount = "------"
  168.                   mcount = mcount + 1
  169.                   matches.mcount = " "
  170.                end
  171.                if pos("#1st Leg",line) > 0 then do
  172.                   mcount = mcount + 1
  173.                   matches.mcount = overlay("After 1st Leg",line,1,13)
  174.                end
  175.                if pos("#Score After Extra Time",line) > 0 then do
  176.                   mcount = mcount + 1
  177.                   matches.mcount = overlay("Score After Extra Time  ",line,1,23)
  178.                end
  179.                if pos("#Penalties",line) > 0 then do
  180.                   mcount = mcount + 1
  181.                   matches.mcount = overlay("After Penalties",line,1,15)
  182.                end
  183.             end
  184.          end
  185.       end
  186.       close(datafile)
  187.    end
  188.    else do
  189.       say
  190.       say "ERROR :    (CupInformation)"
  191.       say
  192.       say "Cannot open '"league_file||input2_file"' for reading."
  193.       exit
  194.    end
  195. end
  196. else do
  197.    if open(datafile,league_file || input5_file,'r') then do
  198.       do while ~eof(datafile)
  199.          line = readln(datafile)
  200.          if pos(separator,line) = 0 & pos('#',line) = 0 then do
  201.             mcount = mcount + 1
  202.             matches.mcount = line
  203.          end
  204.          else do
  205.             if pos(not_played,line) = 0 then do
  206.                if pos("Replay",line) > 0 then do
  207.                   mcount = mcount + 1
  208.                   matches.mcount = " "
  209.                   mcount = mcount + 1
  210.                   matches.mcount = "Replay"
  211.                   mcount = mcount + 1
  212.                   matches.mcount = "------"
  213.                   mcount = mcount + 1
  214.                   matches.mcount = " "
  215.                end
  216.                if pos("#1st Leg",line) > 0 then do
  217.                   mcount = mcount + 1
  218.                   matches.mcount = line
  219.                   matches.mcount = overlay("After 1st Leg",matches.mcount,1,13)
  220.                end
  221.                if pos("#Score After Extra Time",line) > 0 then do
  222.                   mcount = mcount + 1
  223.                   matches.mcount = line
  224.                   matches.mcount = overlay("Score After Extra Time ",matches.mcount,1,23)
  225.                end
  226.                if pos("#Penalties",line) > 0 then do
  227.                   mcount = mcount + 1
  228.                   matches.mcount = line
  229.                   matches.mcount = overlay("After Penalties",matches.mcount,1,15)
  230.                end
  231.             end
  232.          end
  233.       end
  234.       close(datafile)
  235.    end
  236.    else do
  237.       say
  238.       say "ERROR :    (CupInformation)"
  239.       say
  240.       say "Cannot open '"league_file||input5_file"' for reading."
  241.       exit
  242.    end
  243. end
  244.  
  245. do i=1 to tcount
  246.    bpstats.i = 0
  247.    bgsstats.i = 0
  248.    bgastats.i = 0
  249.    bagstats.i = 0
  250. end
  251. np    = 0
  252. btcnt = 0
  253. if open(datafile,league_file || input2_file,'r') then do
  254.    do while ~eof(datafile)
  255.       line = readln(datafile)
  256.       btcnt = btcnt + 1
  257.       btemp.btcnt = line
  258.    end
  259.    close(datafile)
  260. end
  261. else do
  262.    say
  263.    say "ERROR :    (CupInformation)"
  264.    say
  265.    say "Cannot open '"league_file||input2_file"' for reading."
  266.    exit
  267. end
  268. do k=1 to btcnt
  269.    if pos(not_played,btemp.k) = 0 & pos(separator,btemp.k) = 0 & pos('#',btemp.k) = 0 then do
  270.       teama = strip(substr(btemp.k,1,30))
  271.       teamb = strip(substr(btemp.k,41,30))
  272.       np = 1
  273.       do l=1 to tcount
  274.          if pos(teama,teams.l) > 0 then do
  275.             bpstats.l = bpstats.l + 1
  276.             l11 = k + 1
  277.             if pos("#1st Leg",btemp.l11) > 0 then
  278.                l11 = k + 2
  279.             if pos("Extra Time",btemp.l11) = 0 then do
  280.                bgsstats.l = bgsstats.l + strip(substr(btemp.k,32,2))
  281.                bgastats.l = bgastats.l + strip(substr(btemp.k,37,2))
  282.             end
  283.             else do
  284.                bgsstats.l = bgsstats.l + strip(substr(btemp.l11,32,2))
  285.                bgastats.l = bgastats.l + strip(substr(btemp.l11,37,2))
  286.             end
  287.          end
  288.          if pos(teamb,teams.l) > 0 then do
  289.             bpstats.l = bpstats.l + 1
  290.             l11 = k + 1
  291.             if pos("#1st Leg",btemp.l11) > 0 then
  292.                l11 = k + 2
  293.             if pos("Extra Time",btemp.l11) = 0 then do
  294.                bagstats.l = bagstats.l + strip(substr(btemp.k,37,2))
  295.                bgastats.l = bgastats.l + strip(substr(btemp.k,32,2))
  296.             end
  297.             else do
  298.                bagstats.l = bagstats.l + strip(substr(btemp.l11,37,2))
  299.                bgastats.l = bgastats.l + strip(substr(btemp.l11,32,2))
  300.             end
  301.          end
  302.       end
  303.    end
  304. end
  305.  
  306. if open(datafile,output_file,'w') then do
  307.    do i=1 to tcount
  308.       if bpstats.i = "" | bgsstats.i = "" | bgastats.i = "" | bagstats.i = "" then iterate
  309.       if bgastats.i = 0 then
  310. /*         average = "0.000" */
  311.          average = trunc((bgsstats.i + (bagstats.i * 1.5))*bpstats.i,3)
  312.       else
  313.          average = trunc(((bgsstats.i + (bagstats.i * 1.5))/bgastats.i)*bpstats.i,3)
  314.       bstats.i = right(average,7)"   "left(teams.i,30,' ')"    "left(bpstats.i,3,' ')"       "left(bgsstats.i+bagstats.i,3,' ')"          "left(bgastats.i,3,' ')
  315.       writeln(datafile,bstats.i)
  316.    end
  317.    close(datafile)
  318.    address command 'Exec/Sort7Chars'
  319.    btcnt = 0
  320.    if open(datafile,output_file,'r') then do
  321.       do while ~eof(datafile)
  322.          line = readln(datafile)
  323.          if line ~= "" then do
  324.             btcnt = btcnt + 1
  325.             bstats.btcnt = substr(line,9)"   "substr(line,1,8)
  326.          end
  327.       end
  328.       close(datafile)
  329.       address command 'c:delete >NIL: 'output_file
  330.    end
  331.    else do
  332.       say
  333.       say "ERROR :    (CupInformation)"
  334.       say
  335.       say "Unable to open '"output_file"' file for reading."
  336.       exit
  337.    end
  338. end
  339. else do
  340.    say
  341.    say "ERROR :    (CupInformation)"
  342.    say
  343.    say "Unable to open '"output_file"' file for writing."
  344.    exit
  345. end
  346.  
  347. if pos("YES",cuph) > 0 then
  348.    cuph = "Yes"
  349. else
  350.    cuph = "No "
  351. if pos("YES",third) > 0 then
  352.    third = "Yes"
  353. else
  354.    third = "No "
  355. if pos("YES",awaygoals) > 0 then
  356.    awaygoals = "Yes"
  357. else
  358.    awaygoals = "No "
  359.  
  360. say
  361. say center("Information for '"cupname"'",78)
  362. say "-------------------------------------------------------------------------------"
  363. say
  364. say "Away Goals           : "awaygoals"   (Only for Two-Leg matches)"
  365. say "Cup History          : "cuph
  366. if pos("MANUAL",scht) > 0 then
  367.    say "Scheduling           : Manual"
  368. else
  369.    say "Scheduling           : Automatic"
  370. say "Third Place Play-Off : "third
  371. say
  372. say "This cup is scheduled for "rndcnt" rounds, with the following settings"
  373. say "regarding Extra Time and Penalties and Legs for each round as listed below..."
  374. say
  375. say "Round  ExtraTime     Penalties       Legs"
  376. say "--------------------------------------------------"
  377. say
  378. do i=1 to rndcnt
  379.    if pos("1 Leg",rnds.i) > 0 then do
  380.       k = pos("1 Leg",rnds.i)
  381.       rnds.i = overlay("      ",rnds.i,k)
  382.       say rnds.i
  383.    end
  384.    else
  385.       say rnds.i
  386. end
  387. say
  388. say "_______________________________________________________________________________"
  389. say
  390. say
  391. say "Best Record"
  392. say "-----------"
  393. say
  394. say "Rating = ((Goals Scored Home + (Goals Scored Away * 1.5)) / Goals Away) * Matches Played"
  395. say
  396. say "Pos Team                              Pld  GoalsScored  GoalsAgainst  Rating"
  397. say "----------------------------------------------------------------------------"
  398. do i=1 to tcount
  399.    say left(i,3,' ')" "bstats.i
  400. end
  401. say
  402. say "Teams Participating :  "tcount
  403. say "-------------------"
  404. say
  405. do i=1 to tcount by 2
  406.    a = i + 1
  407.    say left(teams.i,30,' ')"    "teams.a
  408. end
  409. say
  410. say "_______________________________________________________________________________"
  411. say
  412. if tleg_no = 0 then legged = "Blank"
  413. if tleg_no = 1 then legged = "1 Leg"
  414. if tleg_no = 2 then legged = "2 Legs"
  415. tempname = "Current Round : "bettername(word(rnds.crond,1),legged)
  416. say tempname
  417. uline = ''
  418. do i=1 to length(tempname)
  419.    uline = insert('-',uline,i,1)
  420. end
  421. say strip(uline)
  422. say
  423. do i=1 to mcount
  424.    if matches.i ~= "" then
  425.       say matches.i
  426. end
  427. say
  428. if pos("Yes",cuph) > 0 & exists(league_file||input4_file) > 0 then do
  429.    say "_______________________________________________________________________________"
  430.    say
  431.    say "Cup Winners"
  432.    say "-----------"
  433.    say
  434.    if open(datafile,league_file || input4_file,'r') then do
  435.       do while ~eof(datafile)
  436.          line = readln(datafile)
  437.          if pos(first,line)   > 0 then do
  438.             parse var line "*WINNER="wteam
  439.             say wteam
  440.          end
  441.       end
  442.       close(datafile)
  443.    end
  444.    else do
  445.       say
  446.       say "ERROR :    (CupInformation)"
  447.       say
  448.       say "Unable to open '"league_file || input4_file"' file."
  449.       exit
  450.    end
  451.    say
  452. end
  453. say "-------------------------------------------------------------------------------"
  454. say
  455.  
  456. exit
  457.  
  458. /* Routine ----------------------------------------------------------- */
  459.  
  460. bettername:
  461. parse arg crn,legless
  462.  
  463. trdn = strip(substr(crn,1,1))
  464. if datatype(trdn,'n') = 1 then do
  465.    parse var crn roundno" "extra
  466.    trn = strip(crn)" Round "extra
  467. end
  468. else do
  469.    if pos("Final",crn) > 0 then do
  470.       parse var crn . " "extra
  471.       if pos("Replay",crn) > 0 then
  472.          trn = "Final "extra
  473.       else
  474.          trn = "Final"
  475.    end
  476.    if pos("Semi",crn) > 0 then do
  477.       parse var crn . " "extra
  478.       if pos("Replay",crn) > 0 then
  479.          trn = "Semi-Final "extra
  480.       else
  481.          trn = "Semi-Finals"
  482.    end
  483.    if pos("Quart",crn) > 0 then do
  484.       parse var crn . " "extra
  485.       if pos("Replay",crn) > 0 then
  486.          trn = "Quarter-Final "extra
  487.       else
  488.          trn = "Quarter-Finals"
  489.    end
  490.    if pos("Third",crn) > 0 then do
  491.       trn = "Third Place Play-Off"
  492.    end
  493. end
  494.  
  495. if pos("1 Leg",legless) > 0 then
  496.    trn = trn||"  (1st Leg)"
  497. if pos("2 Legs",legless) > 0 then
  498.    trn = trn||"  (2nd Leg)"
  499.  
  500. return trn
  501.  
  502. /* ------------------------------------------------------------------- */