Help with Iteration

Discussion in 'Python' started by Chris McComas, Oct 18, 2008.

  1. i have a python script that is computing ratings of sports teams.

    what i'm trying to do is setup an iteration for the rating so that the
    python program recomputes the rating if any of the value difference is
    > 0.00005. it's common for sports ratings to run such iterations...


    any tips, pointers on where to look on how to do this the best way?

    right now i'm getting the ratings from the file, limiting my results
    to 1 entry, the biggest number, if it's > 0.00005, then i want it to
    compute the ratings again. if it is < 0.00005 then it just goes on to
    the next step in the file.

    thnx in advance.
     
    Chris McComas, Oct 18, 2008
    #1
    1. Advertising

  2. On Oct 17, 10:44 pm, Chris McComas <> wrote:
    > i have a python script that is computing ratings of sports teams.
    >
    > what i'm trying to do is setup an iteration for the rating so that the
    > python program recomputes the rating if any of the value difference is
    >
    > > 0.00005. it's common for sports ratings to run such iterations...

    >
    > any tips, pointers on where to look on how to do this the best way?
    >
    > right now i'm getting the ratings from the file, limiting my results
    > to 1 entry, the biggest number, if it's > 0.00005, then i want it to
    > compute the ratings again. if it is < 0.00005 then it just goes on to
    > the next step in the file.
    >
    > thnx in advance.


    Can you cut and paste a few lines? Otherwise I assume your file looks
    like this:

    A 0.00001
    B 0.00003
    C 0.00006

    You interpret the file like this:

    name= A, rating= 0.00001
    name= B, rating= 0.00003
    name= C, rating= 0.00006
    --recompute--

    new values:
    name= A, rating= 0.00001
    name= B, rating= 0.00002
    name= C, rating= 0.00004

    new file:
    A 0.00001
    B 0.00002
    C 0.00004

    Am I right so far?
     
    Aaron \Castironpi\ Brady, Oct 18, 2008
    #2
    1. Advertising

  3. On Oct 18, 12:43 am, "Aaron \"Castironpi\" Brady"
    <> wrote:
    > On Oct 17, 10:44 pm, Chris McComas <> wrote:
    >
    > > i have a python script that is computing ratings of sports teams.

    >
    > > what i'm trying to do is setup an iteration for the rating so that the
    > > python program recomputes the rating if any of the value difference is

    >
    > > > 0.00005. it's common for sports ratings to run such iterations...

    >
    > > any tips, pointers on where to look on how to do this the best way?

    >
    > > right now i'm getting the ratings from the file, limiting my results
    > > to 1 entry, the biggest number, if it's > 0.00005, then i want it to
    > > compute the ratings again. if it is < 0.00005 then it just goes on to
    > > the next step in the file.

    >
    > > thnx in advance.

    >
    > Can you cut and paste a few lines? Otherwise I assume your file looks
    > like this:
    >
    > A 0.00001
    > B 0.00003
    > C 0.00006
    >
    > You interpret the file like this:
    >
    > name= A, rating= 0.00001
    > name= B, rating= 0.00003
    > name= C, rating= 0.00006
    > --recompute--
    >
    > new values:
    > name= A, rating= 0.00001
    > name= B, rating= 0.00002
    > name= C, rating= 0.00004
    >
    > new file:
    > A 0.00001
    > B 0.00002
    > C 0.00004
    >
    > Am I right so far?


    actually i'm running it online, with a mysql db. so in the db there is
    a table CollegeYear with the following fields:

    name
    rating
    change
    wp

    then another table Games

    date
    year
    team_1
    team_1_score
    team_2
    team_2_score

    it goes through and calculates everything, then when it's time to
    compute the rating i have say this code:

    http://dpaste.com/85300/

    it goes through and computes them, then add the new rating and
    absolute value of the changed rating to the db. what i need now is a
    way to get the largest entry for 'change' and if it is greater than
    0.00005 then do this code again. if it is less than 0.00005 then we're
    done.
     
    Chris McComas, Oct 18, 2008
    #3
  4. Chris McComas

    Aaron Brady Guest

    Chris McComas wrote:
    > actually i'm running it online, with a mysql db. so in the db there is
    > a table CollegeYear with the following fields:
    >
    > name
    > rating
    > change
    > wp
    >
    > then another table Games
    >
    > date
    > year
    > team_1
    > team_1_score
    > team_2
    > team_2_score
    >
    > it goes through and calculates everything, then when it's time to
    > compute the rating i have say this code:
    >
    > http://dpaste.com/85300/
    >
    > it goes through and computes them, then add the new rating and
    > absolute value of the changed rating to the db. what i need now is a
    > way to get the largest entry for 'change' and if it is greater than
    > 0.00005 then do this code again. if it is less than 0.00005 then we're
    > done.


    What about "SELECT MAX( rating ) FROM CollegeYear"?
     
    Aaron Brady, Oct 18, 2008
    #4
  5. On Oct 18, 3:46 pm, Aaron Brady <> wrote:
    > Chris McComas wrote:
    > > actually i'm running it online, with a mysql db. so in the db there is
    > > a table CollegeYear with the following fields:

    >
    > > name
    > > rating
    > > change
    > > wp

    >
    > > then another table Games

    >
    > > date
    > > year
    > > team_1
    > > team_1_score
    > > team_2
    > > team_2_score

    >
    > > it goes through and calculates everything, then when it's time to
    > > compute the rating i have say this code:

    >
    > >http://dpaste.com/85300/

    >
    > > it goes through and computes them, then add the new rating and
    > > absolute value of the changed rating to the db. what i need now is a
    > > way to get the largest entry for 'change' and if it is greater than
    > > 0.00005 then do this code again. if it is less than 0.00005 then we're
    > > done.

    >
    > What about "SELECT MAX( rating ) FROM CollegeYear"?


    Aaron,

    Thnx. To clarify I can get the max, that wasn't the issue, what I'm
    failing to try and visualise/figure out is how do I say, okay if MAX >
    0.00005 run this again, if MAX < 0.00005 you're done.
     
    Chris McComas, Oct 19, 2008
    #5
  6. Chris McComas

    John Machin Guest

    On Oct 19, 11:59 am, Chris McComas <> wrote:
    > On Oct 18, 3:46 pm, Aaron Brady <> wrote:
    >
    >
    >
    > > Chris McComas wrote:
    > > > actually i'm running it online, with a mysql db. so in the db there is
    > > > a table CollegeYear with the following fields:

    >
    > > > name
    > > > rating
    > > > change
    > > > wp

    >
    > > > then another table Games

    >
    > > > date
    > > > year
    > > > team_1
    > > > team_1_score
    > > > team_2
    > > > team_2_score

    >
    > > > it goes through and calculates everything, then when it's time to
    > > > compute the rating i have say this code:

    >
    > > >http://dpaste.com/85300/


    What is the point of this:

    if games.team_1_score > games.team_2_score
    t1_rating = t2_rating + t1_wp - .5
    t2_rating = t1_rating + t2_wp - .5
    elif games.team_1_score < games.team_2_score
    t1_rating = t2_rating + t1_wp - .5
    t2_rating = t1_rating + t2_wp - .5
    elif games.team_1_score == games.team_2_score
    t1_rating = t2_rating + t1_wp - .5
    t2_rating = t1_rating + t2_wp - .5

    You have the same code for each of the three conditions. Where are the
    colons? Have you actually tried to execute this code? Any good reason
    why the second elif is not an else?


    >
    > > > it goes through and computes them, then add the new rating and
    > > > absolute value of the changed rating to the db. what i need now is a
    > > > way to get the largest entry for 'change' and if it is greater than
    > > > 0.00005 then do this code again. if it is less than 0.00005 then we're
    > > > done.

    >
    > > What about "SELECT MAX( rating ) FROM CollegeYear"?

    >
    > Aaron,
    >
    > Thnx. To clarify I can get the max, that wasn't the issue, what I'm
    > failing to try and visualise/figure out is how do I say, okay if MAX >
    > 0.00005 run this again, if MAX < 0.00005 you're done.


    [Aside: if MAX == 0.00005, what? Go into a catatonic trance?]

    Let me get this straight: Is this your first program? Are you asking
    how to code a while loop?
     
    John Machin, Oct 19, 2008
    #6
  7. Chris McComas

    Aaron Brady Guest

    Chris McComas wrote:

    > On Oct 18, 3:46 pm, Aaron Brady <> wrote:
    >> Chris McComas wrote:
    >> > actually i'm running it online, with a mysql db. so in the db there is
    >> > a table CollegeYear with the following fields:

    >>
    >> > name
    >> > rating
    >> > change
    >> > wp

    >>
    >> > then another table Games

    >>
    >> > date
    >> > year
    >> > team_1
    >> > team_1_score
    >> > team_2
    >> > team_2_score

    >>
    >> > it goes through and calculates everything, then when it's time to
    >> > compute the rating i have say this code:

    >>
    >> >http://dpaste.com/85300/

    >>
    >> > it goes through and computes them, then add the new rating and
    >> > absolute value of the changed rating to the db. what i need now is a
    >> > way to get the largest entry for 'change' and if it is greater than
    >> > 0.00005 then do this code again. if it is less than 0.00005 then we're
    >> > done.

    >>
    >> What about "SELECT MAX( rating ) FROM CollegeYear"?

    >
    > Aaron,
    >
    > Thnx. To clarify I can get the max, that wasn't the issue, what I'm
    > failing to try and visualise/figure out is how do I say, okay if MAX >
    > 0.00005 run this again, if MAX < 0.00005 you're done.


    I don't know.

    while 1:
    calculate_stuff( )
    if stuff < 0.00005:
    break
     
    Aaron Brady, Oct 19, 2008
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. dwerdna
    Replies:
    5
    Views:
    5,495
    Ajeetha
    Mar 31, 2005
  2. Bruce Whitehouse
    Replies:
    3
    Views:
    398
    Alvin Bruney
    Nov 23, 2003
  3. jurujuba
    Replies:
    3
    Views:
    1,556
    Eliyahu Goldin
    Feb 20, 2005
  4. Rudi
    Replies:
    5
    Views:
    5,031
  5. Newb Newb

    Help on Directory Iteration

    Newb Newb, Jan 27, 2009, in forum: Ruby
    Replies:
    7
    Views:
    103
    Robert Klemme
    Jan 27, 2009
Loading...

Share This Page