/* Mode=Run */ /* *********************************************************************** MATCH ANALYSIS FOR FOOTBALL REXX SUITE ---------------------------------------- Copyright Mark Naughton 1997 Version Date History -------------------------------------------------------------------------- 1.0 050197 First release. 1.1 150997 Added code to handle automatic scheduling with dates. As matches are played mid-week, it was better to get all the games in a 7-day period than just reading the Learn file where they are grouped together in the number of teams divide by 2 (some games would be outside this 7-day period). Amended displays. 1.2 250997 Amended displays of highest/lowest because when using dates, these still gave the week numbers. Routine that calculates the date for the listing is now a callable procedure. Fixed bug where the program expected games to be played every week and added games to weeks that had no games played - the range wasn't incremented enough. 151297 Tidied display. Added average number of goals per game for highest/lowest. 310599 Changed to handle extra data in '.sflearn' file. 250899 Added error msg to file checks. 050999 Converted to use locale. Some error messages, before reading the locale, will still be in English. Converted to use a global date format file. Now correctly translates date format to get required data. 050999 Found a problem where if the datafile was created with a different locale, you wouldn't be able to read it so now we read through the control files for all locales making sure we find the correct date data. 180999 Added support for own goals, bookings, red cards and attendances - but only if they have been input. Changed schedule directory. 021099 Added code to set markers when matches are played (sflearn is now read into an array) - this means the wrong match will NOT be picked up. Changed position of code that reads sflearn - now reads data based on match not on position. All works. Added code to display data that isn't used indicating a problem. ************************************************************************** Procedure --------- 1. Check files exist. Read Teams.df datafile and store league name. 2. If automatic scheduling, open Schedule definition file and store whether it is run by WEEKS or DATES. 3. Open Learn file if WEEKS or non-auto sched and get statistics for each match for each week. Close file. 4. Open '.sf' file if DATES and get statistics for each match for each week. Increase the range from the start date as the file goes on, adding 7 days. Close file. 5. Get the highest and lowest scoring weeks. 6. Display data and exit. ************************************************************************** */ PARSE ARG league_stuff version = 1 input_file = '.df' input2_file = '.sflearn' input3_file = '.sf' title = '*LEAGUE_NAME=' autosched = '*AUTOSCHD=' separator = '*' games. = '???' homew. = '???' awayw. = '???' draws. = '???' losses. = '???' goalss. = '???' yellows. = '???' reds. = '???' attendances. = '???' owngoals. = '???' selines. = '???' semkrs. = '???' secount = 0 weeks = 0 weekend. = '???' months = "January February March April May June July August September October November December" not_played = '__ __' parse var league_stuff league_file league_file = "Data/" || league_file addlib('rexxsupport.library',0,-30,0) if open(datafile,"Data/Football.locale",'r') then do line = readln(datafile) locdir = strip(line) close(datafile) end else do say say "ERROR : (MatchAnalysis)" say say "Cannot read 'Data/Football.locale' for the locale settings." exit end dfordir = locdir"Football.locale_data" locdir = locdir"User/MatchAnalysis.data" if open(datafile,"ENV:FootballRXPath",'r') then do line = readln(datafile) rxdir = strip(line) close(datafile) end else rxdir = "SYS:Rexxc/" if exists(locdir) > 0 then do address command rxdir'rx 'locdir VarCount = getclip('VarCount') do i = 1 to VarCount interpret getclip('var.'i) end end else do say say "ERROR : (MatchAnalysis)" say say "Cannot find '"locdir"' to read locale settings." exit end if exists(dfordir) > 0 then do address command rxdir'rx 'dfordir VarCount = getclip('VarCount') do i = 1 to VarCount interpret getclip('var.'i) end end else do say say "ERROR : (MatchAnalysis)" say say "Cannot find '"dfordir"' to read date locale settings." exit end if exists(league_file || input_file) = 0 then do say say ma_t1 say say fl_canfd"'"league_file || input_file"'." exit end if exists(league_file || input2_file) = 0 then do say say ma_t1 say say fl_canfd"'"league_file || input2_file"'." exit end if exists(league_file || input3_file) = 0 then do say say ma_t1 say say fl_canfd"'"league_file || input3_file"'." exit end autos = 0 if open(datafile,league_file || input_file,'r') then do do while ~eof(datafile) line = readln(datafile) if pos(title,line) > 0 then league_title = delstr(line,1,13) if pos(autosched,line) > 0 then do autofile = delstr(line,1,10) autos = 1 end end close(datafile) end else do say say ma_t1 say say fl_canread"'"league_file || input_file"' "ma_t4 exit end type = 0 if autos = 1 then do if open(datafile,"Data/Schedules/"||autofile||".schd",'r') then do line = readln(datafile) if pos("*WEEKS",line) > 0 then type = 10 if pos("*DATES",line) > 0 then do type = 20 start_date = substr(line,8,8) end close(datafile) end else do say say ma_t1 say say fl_canread"'Data/Schedules/"autofile".schd' "ma_t5 exit end end att_mkr = 0 /* for possible extra values */ yel_mkr = 0 red_mkr = 0 og_mkr = 0 /* use this method if its WEEKS or non-auto sched. */ if type < 20 then do if open(datafile,league_file || input2_file,'r') then do do while ~eof(datafile) line = readln(datafile) if pos(separator,line) = 0 then do if separator = sep then do /* CHANGE 31/05 */ weeks = weeks + 1 sep = '' games.weeks = 0 homew.weeks = 0 awayw.weeks = 0 draws.weeks = 0 losses.weeks = 0 goalss.weeks = 0 yellows.weeks= 0 reds.weeks = 0 owngoals.weeks = 0 attendances.weeks = 0 goals_for = 0 goals_aga = 0 goals = 0 end goals_for = strip(substr(line,32,2)) goals_aga = strip(substr(line,37,2)) if datatype(goals_for,'n') = 0 | datatype(goals_aga,'n') = 0 then leave games.weeks = games.weeks + 1 goalss.weeks = goalss.weeks + goals_for + goals_aga if goals_for > goals_aga then do homew.weeks = homew.weeks + 1 losses.weeks= losses.weeks + 1 end if goals_for = goals_aga then do draws.weeks = draws.weeks + 1 end if goals_for < goals_aga then do awayw.weeks = awayw.weeks + 1 losses.weeks= losses.weeks + 1 end end else do if pos("(og)",line) > 0 then do og_mkr = 1 owngoals.weeks = owngoals.weeks + 1 end if pos("*ATD=",line) > 0 then do att_mkr = 1 parse var line "*ATD=" attend attendances.weeks = attendances.weeks + attend end if pos("*HY=",line) > 0 | pos("*AY=",line) > 0 then do yel_mkr = 1 yellows.weeks = yellows.weeks + 1 end if pos("*HR=",line) > 0 | pos("*AR=",line) > 0 then do red_mkr = 1 reds.weeks = reds.weeks + 1 end if pos("*HYR=",line) > 0 | pos("*AYR=",line) > 0 then do yel_mkr = 1 red_mkr = 1 yellows.weeks = yellows.weeks + 1 reds.weeks = reds.weeks + 1 end sep = line end end close(datafile) end else do say say ma_t1 say say fl_canread"'"league_file || input2_file"'." exit end end /* DATES and automatic scheduling */ if type = 20 then do weeks = 1 mnth = substr(start_date,3,2) ndate= substr(start_date,5,4)||mnth||substr(start_date,1,2) range = date('b',ndate,'s') range = range + 6 games.weeks = 0 weekend.weeks = range homew.weeks = 0 awayw.weeks = 0 draws.weeks = 0 losses.weeks = 0 goalss.weeks = 0 yellows.weeks= 0 reds.weeks = 0 owngoals.weeks = 0 attendances.weeks = 0 goals_for = 0 goals_aga = 0 goals = 0 s_l = 0 match1 = "" match2 = "" if open(datafile2,league_file || input2_file,'r') then do do while ~eof(datafile2) line = readln(datafile2) if pos("**",line) = 0 & length(line) > 1 then do secount = secount + 1 selines.secount = strip(line) semkrs.secount = 0 end end close(datafile2) end else do say say ma_t1 say say fl_canread"'"league_file || input2_file"'." exit end if open(datafile,league_file || input3_file,'r') then do do while ~eof(datafile) line = readln(datafile) if pos(separator,line) > 0 then do if pos("*Date:",line) > 0 then do if s_l = 0 then do parse var line "*Date:" dateall search_loc = strip(word(dateall,words(dateall)-1)) do mnls=1 to 12 if pos(word(months,mnls),search_loc) > 0 then do s_l = 1 leave end end if s_l = 0 then do locale_cats = showdir("Locale/") do search_locale=1 to words(locale_cats) dfordir = "Locale/"word(locale_cats,search_locale)"/Football.locale_data" if exists(dfordir) > 0 then do address command rxdir'rx 'dfordir VarCount = getclip('VarCount') do i = 1 to VarCount interpret getclip('var.'i) end end parse var line "*Date:" dateall search_loc = strip(word(dateall,words(dateall)-1)) do mnls=1 to 12 if pos(word(months,mnls),search_loc) > 0 then do s_l = 1 leave end end if s_l = 1 then leave end end if s_l > 0 then do temp_dtal = dateall parse var date_format "day" sp1 "number" sp2 "month" sp3 "year" parse var line "*Date:" dateall do i=1 to 7 if pos(word(days,i),dateall) > 0 then do lk = pos(word(days,i),dateall) dateall = delstr(dateall,1,lk+length(word(days,i))+length(sp1)-1) end end dateall = strip(dateall) year = word(dateall,words(dateall)) mnth = strip(word(dateall,words(dateall)-1)) do lm=1 to length(mnth) if datatype(substr(mnth,1,1),'m') ~= 1 then mnth = delstr(mnth,1,1) end dateall = temp_dtal day = word(dateall,2) do lm=1 to length(day)-2 if datatype(substr(day,3,1),'n') ~= 1 then day = delstr(day,3,1) end cv = 0 do i=1 to 12 if pos(word(months,i),mnth) > 0 then do cv = i leave end end end end if s_l = 0 then do say say ma_t1 say say ma_t11 exit end sd = year||right(cv,2,0)||right(day,2,0) search_date = date('b',sd,'s') s_l = 0 if search_date > range then do range = range + 7 diff = 1 /* this hopes to skip weeks where no games are played. */ do while (diff > 0) diff = search_date - range if diff > 0 then range = range + 7 end weeks = weeks + 1 games.weeks = 0 weekend.weeks = range homew.weeks = 0 awayw.weeks = 0 draws.weeks = 0 losses.weeks = 0 goalss.weeks = 0 goals_for = 0 goals_aga = 0 goals = 0 yellows.weeks= 0 reds.weeks = 0 attendances.weeks = 0 owngoals.weeks = 0 end end end if pos(separator,line) = 0 & pos(not_played,line) = 0 then do goals_for = strip(substr(line,32,2)) goals_aga = strip(substr(line,37,2)) if datatype(goals_for,'n') > 0 & datatype(goals_aga,'n') > 0 then do games.weeks = games.weeks + 1 goalss.weeks = goalss.weeks + goals_for + goals_aga if goals_for > goals_aga then do homew.weeks = homew.weeks + 1 losses.weeks= losses.weeks + 1 end if goals_for = goals_aga then do draws.weeks = draws.weeks + 1 end if goals_for < goals_aga then do awayw.weeks = awayw.weeks + 1 losses.weeks= losses.weeks + 1 end stor1 = 0 do kej=1 to secount if semkrs.kej = 0 then do if pos(separator,selines.kej) = 0 then do if stor1 = 1 then leave if strip(selines.kej) == strip(line) then stor1 = 1 if stor1 = 1 then semkrs.kej = 1 end else do if stor1 = 1 then do if pos("(og)",selines.kej) > 0 then do og_mkr = 1 owngoals.weeks = owngoals.weeks + 1 end if pos("*ATD=",selines.kej) > 0 then do att_mkr = 1 parse var selines.kej "*ATD=" attend attendances.weeks = attendances.weeks + attend end if pos("*HY=",selines.kej) > 0 | pos("*AY=",selines.kej) > 0 then do yel_mkr = 1 yellows.weeks = yellows.weeks + 1 end if pos("*HR=",selines.kej) > 0 | pos("*AR=",selines.kej) > 0 then do red_mkr = 1 reds.weeks = reds.weeks + 1 end if pos("*HYR=",selines.kej) > 0 | pos("*AYR=",selines.kej) > 0 then do yel_mkr = 1 red_mkr = 1 yellows.weeks = yellows.weeks + 1 reds.weeks = reds.weeks + 1 end semkrs.kej = 1 end end end end end end end close(datafile) end else do say say ma_t1 say say fl_canread"'"league_file || input3_file"'." exit end end lowest = 10000 highest= 0 h = 0 l = 0 g = 0 los = 0 losc= 0 hwn = 0 hwnc= 0 awn = 0 awnc= 0 dra = 0 drac= 0 ogs = 0 ogsc= 0 rcs = 0 rcsc= 0 ycs = 0 ycsc= 0 acs = 0 acsc= 0 do i=1 to weeks if games.i ~= 0 then do if goalss.i > highest then do highest = goalss.i h = i end if goalss.i < lowest then do lowest = goalss.i l = i end g = g + games.i if losses.i > los then do los = losses.i losc= i end if homew.i > hwn then do hwn = homew.i hwnc= i end if awayw.i > awn then do awn = awayw.i awnc= i end if draws.i > dra then do dra = draws.i drac= i end if attendances.i > acs then do acs = attendances.i acsc= i end if yellows.i > ycs then do ycs = yellows.i ycsc= i end if reds.i > rcs then do rcs = reds.i rcsc= i end if owngoals.i > ogs then do ogs = owngoals.i ogsc= i end end end hgpmwk = 0 lgpmwk = 0 hgpm = 0 lgpm = 1000 tscr = 0 do i=1 to weeks if games.i ~= 0 then do tscr = trunc(goalss.i/games.i,2) if tscr > hgpm then do hgpm = tscr if type < 20 then hgpmwk = i else hgpmwk = weekend.i end if tscr < lgpm then do lgpm = tscr if type < 20 then lgpmwk = i else lgpmwk = weekend.i end end end say say center(txt_league_title"'"league_title"'",78) say "----------------------------------------------------------------------------------------------------" say say txt_matches""g say if type < 20 then do say txt_weekwins1""hwnc""txt_high1""hwn""txt_wins say txt_weekwins2""awnc""txt_high1""awn""txt_wins say txt_weekloss""losc""txt_high1""los""txt_losses say txt_weekdraws""drac""txt_high1""dra""txt_draws if og_mkr = 1 then say txt_weekog""ogsc""txt_high1""ogs""txt_ogoals if red_mkr= 1 then say txt_weekred""rcsc""txt_high1""rcs""txt_reds if yel_mkr= 1 then say txt_weekyell""ycsc""txt_high1""ycs""txt_yellows if att_mkr= 1 then say txt_weekattd""acsc""txt_high1""acs say say txt_weekhiscore""h""txt_high1""highest""txt_goals say txt_weekloscore""l""txt_high1""lowest""txt_goals say say ma_t6""hgpmwk""txt_high1""hgpm" "ma_t10 say ma_t7""lgpmwk""txt_high1""lgpm" "ma_t10 say end else do say txt_datewins1"'"getweek(weekend.hwnc)"'"txt_high1""hwn""txt_wins say txt_datewins2"'"getweek(weekend.awnc)"' with "awn" wins." say txt_dateloss"'"getweek(weekend.losc)"'"txt_high1""los""txt_losses say txt_datedraws"'"getweek(weekend.drac)"'"txt_high1""dra""txt_draws if og_mkr = 1 then say txt_dateog"'"getweek(weekend.ogsc)"'"txt_high1""ogs""txt_ogoals if red_mkr= 1 then say txt_datered"'"getweek(weekend.rcsc)"'"txt_high1""rcs""txt_reds if yel_mkr= 1 then say txt_dateyell"'"getweek(weekend.ycsc)"'"txt_high1""ycs""txt_yellows if att_mkr= 1 then say txt_dateattd"'"getweek(weekend.acsc)"'"txt_high1""acs say say txt_datehiscore"'"getweek(weekend.h)"'"txt_high1""highest""txt_goals say txt_dateloscore"'"getweek(weekend.l)"'"txt_high1""lowest""txt_goals say say ma_t8" '"getweek(hgpmwk)"'"txt_high1""hgpm" "ma_t10 say ma_t9" '"getweek(lgpmwk)"'"txt_high1""lgpm" "ma_t10 end say say if type < 20 then do if og_mkr = 1 then txt_weektable1 = txt_weektable1" "txt_owngoals1 if og_mkr = 1 then txt_weektable2 = txt_weektable2" "txt_owngoals2 if yel_mkr = 1 then txt_weektable1 = txt_weektable1" "left(' ',length(txt_bookings),' ') if yel_mkr = 1 then txt_weektable2 = txt_weektable2" "txt_bookings if red_mkr = 1 then txt_weektable1 = txt_weektable1" "txt_sendingoff1 if red_mkr = 1 then txt_weektable2 = txt_weektable2" "txt_sendingoff2 if att_mkr = 1 then txt_weektable1 = txt_weektable1" "left(' ',length(txt_attends),' ') if att_mkr = 1 then txt_weektable2 = txt_weektable2" "txt_attends say txt_weektable1 say txt_weektable2 end else do if og_mkr = 1 then txt_datetable1 = txt_datetable1" "txt_owngoals1 if og_mkr = 1 then txt_datetable2 = txt_datetable2" "txt_owngoals2 if yel_mkr = 1 then txt_datetable1 = txt_datetable1" "left(' ',length(txt_bookings),' ') if yel_mkr = 1 then txt_datetable2 = txt_datetable2" "txt_bookings if red_mkr = 1 then txt_datetable1 = txt_datetable1" "txt_sendingoff1 if red_mkr = 1 then txt_datetable2 = txt_datetable2" "txt_sendingoff2 if att_mkr = 1 then txt_datetable1 = txt_datetable1" "left(' ',length(txt_attends),' ') if att_mkr = 1 then txt_datetable2 = txt_datetable2" "txt_attends say txt_datetable1 say txt_datetable2 end if og_mkr = 1 then txt_line = txt_line" "txt_ogl if yel_mkr = 1 then txt_line = txt_line" "txt_bl if red_mkr = 1 then txt_line = txt_line" "txt_sol if att_mkr = 1 then txt_line = txt_line" "txt_al say txt_line say if type < 20 then do do i=1 to weeks if games.i ~= 0 then do poss_more = "" if og_mkr = 1 then poss_more = poss_more" "left(owngoals.i,length(txt_owngoals1)) if yel_mkr = 1 then poss_more = poss_more" "left(yellows.i,length(txt_bookings)) if red_mkr = 1 then poss_more = poss_more" "left(reds.i,length(txt_sendingoff1)) if att_mkr = 1 then poss_more = poss_more" "left(attendances.i,length(txt_attends)) 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)""poss_more end end end if type = 20 then do do i=1 to weeks if games.i ~= 0 then do poss_more = "" if og_mkr = 1 then poss_more = poss_more" "left(owngoals.i,length(txt_owngoals1)) if yel_mkr = 1 then poss_more = poss_more" "left(yellows.i,length(txt_bookings)) if red_mkr = 1 then poss_more = poss_more" "left(reds.i,length(txt_sendingoff1)) if att_mkr = 1 then poss_more = poss_more" "left(attendances.i,length(txt_attends)) sd = getweek(weekend.i) 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)""poss_more end end end say say "----------------------------------------------------------------------------------------------------" a = 0 do i=1 to secount if semkrs.i = 0 then do a = a + 1 if a = 1 then do say say say "There might a program error or datafile problem as the" say "following data has not been used :" say end say selines.i end end exit /* Procedure --------------------------------------------------------- */ getweek: parse arg days dd = days - 722450 dd = date('n',dd,'i') dd = delstr(dd,8,2) parse var dd dy mn yy dy = strip(dy) mn = strip(mn) yy = strip(yy) parse var date_format "day" sp1 "number" sp2 "month" sp3 "year" dd = dy||sp2||mn||sp3||yy return dd /* ------------------------------------------------------------------- */