ELynah Forum

General Category => Hockey => Topic started by: CowbellGuy on April 24, 2002, 01:09:41 PM

Title: My brain hurts...
Post by: CowbellGuy on April 24, 2002, 01:09:41 PM
So I have a list of penalties in a game for each team, the time the penalty occurred, and length of each penalty. Then I have a list of goals for each team, and the time of the goal. What I'm trying to do is figure out the number of skaters on the ice for each goal. The 96 lines of code I amassed to do this works about 98% of the time, but the game against Wilfrid Laurier (with 17 penalties and 42 PIM) broke it handily.

So, obviously, I need to rewrite it, and it would be very helpful to have a clear flow chart to know exactly how to approach it before I start and I was hoping some of you here might be able to help. Things like "count the number of Cornell goals from time A to time B" but NOT "count the number of power play goals from time A to time B" are possible. Goals are simply recorded as goals. Penalties as penalties. Any help would be greatly appreciated, since the assholes at collegehockeystats won't offer any help whatsoever. :-(

Title: Re: My brain hurts...
Post by: tml5 on April 24, 2002, 05:38:38 PM
An irresistable puzzle.  I hate you.  :-))

(note - flow charts I can do, but you're on your own for writing/debugging the actual code, since I can't actually program)

Just to make sure I've got this straight:
You want to know the number of skaters for each team on the ice.  
This means you need a flow chart of sorts that incorporates rules for the following:
(Cornell number on left in all cases)
Goals scored at 5x3, 5x4, 5x5
Goals scored at 4x3, 4x4, 4x5
Goals scored at 3x3, 3x4, 3x5

You're trying to get these rules based on inputs of penalty time, penalty length, and time of goal scored.  I guess the biggest snags are major penalties and multiple matching penalties.  

Assumptions and terms:

Opp = opponent
Cor = Cornell
G = Goal
P = Penalty
Tg = time of goal
Tp = Time of penalty
S = duration of penalty in seconds
Tpn = Time of penalty n
P1 = penalty 1
P2 = penalty 2
...
Pn = penalty n

Note that I did not build in the counting of the penalties.  You should have it set to count the number of penalties assessed to Cornell, and the number of penalties assessed to opponent, so that each penalty will have a unique combination of cornell/opponent and n value.


Rules:

Initial, Opp=Cor=5
If TgExpiration of penalties defined:
  Tp+S = Te
  At time Te:
    Cornell penalty:  Opp(Te)=N, Cor(Te)=(N'+1)
    Opponent penalty:  Opp(Te)=(N+1), Cor(Te)=N'


When a penalty occurs:
If S=<120, p=minor
If S=300, p=major
If Tpncor = Tpn'opp, p=matching
Is p matching?
  If Yes
    If p is major, Opp=N(Tp) Cor=N'(Tp).
    Is Cor=Opp=5?
       If No, Opp=N(Tpn), Cor=N'(Tpn)
  If Cor=Opp=5
    Multiple penalties?
      Yes – multiple matching
   Opp=Cor=5
      Yes – 1 matching plus extra
   No match on extra, go to minor penalty
    If matching, non-major, not multiple, and no existing penalty:
      If Tp      If Tg>(Tp+120) Opp(Tg)=Cor(Tg)=5

If non-matching
 Is p major?
   If Yes
     Cor penalty: If Tp     Opp penalty: If Tp   If minor penalty
     Cor penalty: If Tp     Opp penalty: If Tp     If Tp

So that's what I've got.  What did I miss?  I'm sure I missed something.  I'll look at it again later, but I have to leave now.

I just realized what I missed.  What about a situation where the team is already two men down. . . damn it.  I'll figure that out later and put it in, which means I have to stop being lazy and include the n values.  If you see anything else, let me know.
Title: Re: My brain hurts...
Post by: CowbellGuy on April 24, 2002, 08:28:12 PM
Heh, sorry, but we're just scratching the surface here. Unless I'm missing something, that doesn't take into account penalties being released by PP goals being scored before the one currently being considered, or early release of the first of a double minor. And the real pain in the ass, more than 2 nonmatching minors where the third doesn't start until the first has been scored on or expires. :`( And we're back to the title of the thread... What I can do is have it "remember" the number of skaters for a previous goal.

Title: Re: My brain hurts...
Post by: tml5 on April 25, 2002, 06:31:06 AM
Sorry, I was assuming some kind of memory function.  I guess I didn't make that clear.  It's way too early (um, late?), and I won't get to more of this until sometime this weekend, which is roughly when I plan to get out of bed.  I'll give it a better go then.

Edit - I have no idea what I'm talking about.  Your memory function is totally different from what I was thinking of.  Ugh.
Title: Re: My brain hurts...
Post by: jkahn on April 25, 2002, 02:22:00 PM
This may be too simplistic, but can't you just merge the goal and penalty files by time, and flow through the game.  C=CU players, O=opp. players, start C=5, O=5 and reduce where appropriate for penalties and then add back when appropriate for expiration or early release for goals.  Each time a goal occurs, you'll know the values of C and O.

Title: Re: My brain hurts...
Post by: David Craine on April 25, 2002, 04:44:04 PM
That probably wouldn't take into account goals at even strength 4 on 4 which wouldn't allow anyone out of the box.  Would it be possible to set up an if-then statement saying if C
Title: Re: My brain hurts...
Post by: CowbellGuy on April 25, 2002, 04:45:33 PM
nope. well, yeah, but you still need to figure out if C
Title: Re: My brain hurts...
Post by: David Craine on April 25, 2002, 05:45:28 PM
Not only that but you have to account for major penalties where players aren't let out of the box.
Title: Re: My brain hurts...
Post by: jkahn on April 25, 2002, 05:58:52 PM
Admittedly, it's been 30 years since I wrote a program (although I did have a summer job as a programmer in '69, '70 and '71).  Anyway, if you start at C=5 and O=5 and adjust for every penalty and goal ( the program should be able to act like a ref and know how many should be on the ice at any time), I don't see why you wouldn't be able to get the values of C and O each time a goal is scored. The input would be the penalties and goals processed sequentially, which are the events that control the values of C and O at any time.  Obviously, you'd need to program in the rules, such as  you don't increase the value of C or O if the player in the box is serving a major, and more complex things such as if two guys in the box on same team, first penalty expires, etc.

Title: Re: My brain hurts...
Post by: CowbellGuy on April 26, 2002, 09:30:15 AM
Because it doesn't know how many men are on the ice going into a situation without figuring it all out again. The only way it could do that is step through the entire game a second at a time and have an array with 3600 values for each team. Hardly efficient or elegant. Also, I need to be able to plug in a goal and get its type back without doing the whole procedure for a game (ie, count power play goals for a player in a season). I'll just show you how I was doing it, in this case for a Cornell goal. I started with C=5 and O=5 as you mentioned.
I. Get time and length from opponent 2 minute penalties in the last 120 seconds and 5 minute penalties in the last 300 seconds.
 A. If 5 minute
  1. O decreases by one. (Simplistic and wrong, but I was having enough trouble getting the 2 mins right and didn't even get to deal with 5's right)
 B. If 2 minute
  1. Count 2 minute penalties at that time for Cornell
   a. If there are any and O=5 and C=5, O decreases by one
   b. Get time of Cornell goals in the 2 minutes prior to this penalty.
    i. Here it checks if there were any other goals scored at this time that it already figured out (this was a kludge and obviously wouldn't work in the actual version). If it's a Cornell goal, and there were more Cornell skaters than opponent skaters, O increases by one.


Anyway, you get the idea. Then it walks through more or less the same procedure for Cornell penalties in that time span and does the opposite. It doesn't take into account a LOT of things, and obviously isn't satisfactory for the issues I described earlier.

Title: Re: My brain hurts...
Post by: ursusminor on April 26, 2002, 10:52:48 AM
Age, I think that you really have to walk it through the entire game adjusting every time that a penalty is given or a goal is scored, because conceivably in the third period there might be delayed penalties that have backed up from the first period.  Clearly, such games are rare, but it is not unknown to have a series of penalties backing up for ten minutes. The only possible way of getting around this is by adding up the total amount of penalties in the game and thus conclude that such a sitation couldn't happen.

The other way of getting around it is checking if Clarkson is playing. ::rolleyes::
Title: Re: My brain hurts...
Post by: jtwcornell91 on April 26, 2002, 12:00:05 PM
ursaminor wrote:
QuoteThe other way of getting around it is checking if Clarkson is playing. ::rolleyes::
LOL! ::laugh::

Title: Re: My brain hurts...
Post by: CowbellGuy on April 26, 2002, 12:40:08 PM
Heh. OmniGraffle is cool.

http://www.hockey.cornell.edu/pictures/chart.jpg

Title: Re: My brain hurts...
Post by: KeithK on April 26, 2002, 01:39:44 PM
Interesting programming problem, but... Seems to me the easiest way to do it is to just write a script to preprocess the goals from each game as a block and then store the nxm numbers in the DB.  That way you could step through the entire game but would only do it once and never real time.
Title: Re: My brain hurts...
Post by: CowbellGuy on April 26, 2002, 02:32:05 PM
But then if anything changes or you correct a mistake you have to reprocess the game. And if you're going to store stuff statically, might as well just flag the goals when you enter them into the db. That's no fun.


Also, if collegehockeystats is doing it on the fly and they refuse to throw me a bone, I'll be damned if I settle for anything less.

Title: Re: My brain hurts...
Post by: CowbellGuy on April 26, 2002, 03:51:03 PM
If there are offsetting 5 min majors at 5x5, do the teams skate 4x4 for 5 min or not?

Title: Re: My brain hurts...
Post by: Greg Berge on April 26, 2002, 05:55:28 PM
No, you only remove manpower from the ice simultaneously for coincidental minors from full strength.
Title: Re: My brain hurts...
Post by: Robb on April 26, 2002, 10:54:11 PM
You don't need 3600 values in your table, you just need a 3 column table where the three columns are time, #cornell players, #opponent players.    There would only need to be 2 x number of penalties + number of goals rows.  2x penalties because each penalty has a beginning and an end. This would capture all events that change the number of players on the ice (naturally, there would be overlap, since a goal often coincides with the end of a penalty).   Then you just have to look at the rows in the table that represent goals and see how many players were on the ice at the time (i.e. in the previous row, just before the goal was scored).  Doesn't seem that bad to me - but then, no problem seems that bad before you actually try to solve it...
Title: Re: My brain hurts...
Post by: CowbellGuy on May 06, 2002, 02:37:25 PM
Well, I think I finally got it doing 2 minute penalties right. 4's and 5's should be easily integrated. *phew*

Title: Re: My brain hurts...
Post by: CowbellGuy on May 15, 2002, 03:00:23 PM
Well, I would like to just send out a resounding ::flipd:: to the ::asshole:: at Collegehockeystats who wouldn't help out with the penalty system, as I finally got mine working today, for real, and should work in any potential situation. yay!