+ Reply to Thread
Results 1 to 5 of 5

Thread: Three Options

  1. #1
    garrensilverwing's Avatar
    garrensilverwing is offline x10 Sophmore garrensilverwing is an unknown quantity at this point
    Join Date
    Nov 2008
    Posts
    148

    Three Options

    I am working on a website for a chess club and one of the features I am going to add is a database of all the games played at the club or sponsored tournaments. I have three ways of going about this:

    1. Store the games in their raw PGN state.
    2. Extract all the data to store in separate columns in a table.
    3. Extract all the data and then store it with the PGN in the table.


    Code wise I already have the code to extract the data from a previous post but I am looking for the most efficient way to do it. From the get go there will probably not be many games but there is potential for a lot of games. There are three things I want to do with the games:

    • List the games based on their data (excluding the moves). With a search feature.
    • (Eventually) Have a clickable javascript chessboard where you can play through the game on the site.
    • Download the games in a PGN format (either the full database or whatever they come up with the search.
    I am leaning toward the second way because coding it to reconstruct the PGN file would be easier (and probably less server-taxing) than having it deconstruct the PGN every time someone views the game Also it will only include relevant information. I am just looking for opinions from professionals since I am just an amateur! Thanks!

  2. #2
    marshian's Avatar
    marshian is offline x10 Elder marshian is an unknown quantity at this point
    Join Date
    Jan 2008
    Location
    Belgium
    Posts
    526

    Re: Three Options

    All those "PGN" files you are talking about... are they png files?

    Basically, you need raw data (PGN files?) and data that can be deducted from that raw data. I'll enumerate all of the possibilities.
    t1 and t2 are the time required to extract the data (t1) and to restore the raw data (t2).
    m1 and m1 are the memory requirements for the data (m1) and raw data (m2).
    The given times are assumed if you need both the raw and extracted data.
    1. Store only the raw data. Time: t1, memory: m2 (more time, more memory)
    2. Store only the extracted data. Time: t2, memory: m1 (less time, less memory)
    3. Store both. Time: 0, memory: m1 + m2 (least time, most memory)

    As you see, the time/memory-efficiency of your program/script will depend heavily on the chosen method. Usually time is more important than memory though, especially when talking about storage memory (like a HDD). As a server application, if you think it will be executed a lot, I'd certainly go for the time-efficient method most of the times. Servers should be able to handle a lot of requests at the same time. Imagine your script (apart from the above mentioned times t1 and t2) takes 500 ms to execute. Take 500 ms for t1 and 250 ms for t2. Using the first method your script executes in 1000 ms, so you can serve one client every second. Using the second method, it is 750 ms, or 1.33 clients per second. However, using the last method it only takes 500 ms, the equivalent of 2 clients per second. Of course these are fictional numbers, but they're just to give you an idea of how to look at it.

    Personally, in this case I'd go for the last option in the first place and change to the second one if the database is growing out of proportions.

    I hope this helps (:
    Last edited by marshian; 12-23-2009 at 12:32 PM. Reason: typo

  3. #3
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: Three Options

    If you're doing anything more than regurgitating PGN data (which you are), option 1 isn't worthwhile. Whether you pick option 2 or 3 is a matter of how much disk space you have remaining in your quota, and whether certain functionality is easier to perform on PGN data than your parsed version.

    Quote Originally Posted by marshian View Post
    All those "PGN" files you are talking about... are they png files?
    PGN: Portable Game Notation.

    If you're ever really concerned about minimizing space usage, have a read at "Programmer Puzzle: Encoding a chess board state throughout a game".
    Last edited by misson; 12-23-2009 at 11:09 PM.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

  4. #4
    slacker3 is offline x10 Sophmore slacker3 is an unknown quantity at this point
    Join Date
    Jul 2009
    Posts
    146

    Wink Re: Three Options

    SQL:
    I would store this values separately
    Code:
    [Event "F/S Return Match"]
    [Site "Belgrade, Serbia Yugoslavia|JUG"]
    [Date "1992.11.04"]
    [Round "29"]
    [White "Fischer, Robert J."]
    [Black "Spassky, Boris V."]
    [Result "1/2-1/2"]
    and this one just as one varchar:
    Code:
    1. e4 e5 2. Nf3 Nc6 3. Bb5 {This opening is called the Ruy Lopez.} 3... a6
    4. Ba4 Nf6 5. O-O Be7 6. Re1 b5 7. Bb3 d6 8. c3 O-O 9. h3 Nb8  10. d4 Nbd7
    11. c4 c6 12. cxb5 axb5 13. Nc3 Bb7 14. Bg5 b4 15. Nb1 h6 16. Bh4 c5 17. dxe5
    Nxe4 18. Bxe7 Qxe7 19. exd6 Qf6 20. Nbd2 Nxd6 21. Nc4 Nxc4 22. Bxc4 Nb6
    23. Ne5 Rae8 24. Bxf7+ Rxf7 25. Nxf7 Rxe1+ 26. Qxe1 Kxf7 27. Qe3 Qg5 28. Qxg5
    hxg5 29. b3 Ke6 30. a3 Kd6 31. axb4 cxb4 32. Ra5 Nd5 33. f3 Bc8 34. Kf2 Bf5
    35. Ra7 g6 36. Ra6+ Kc5 37. Ke1 Nf4 38. g3 Nxh3 39. Kd2 Kb5 40. Rd6 Kc5 41. Ra6
    Nf2 42. g4 Bd3 43. Re6 1/2-1/2
    So it's easy and fast to search for specific games.


    http://chessflash.com/chessflash.html
    To display (or download) selected games you just have to concatenate the whole game data.

    Display it by appending your gamedata after "&pgndata=", for example
    Code:
    <div><object type="application/x-shockwave-flash" data="http://chessflash.com/releases/latest/ChessFlash.swf" width="100%" height="350"><param name="movie" value="http://chessflash.com/releases/latest/ChessFlash.swf" /><param name="flashvars" value='orientation=H&tabmode=true&light=f4f4fF&dark=0072b9&bordertext=494949&headerforeground=ffffff&mtforeground=000000&mtvariations=FF0000&mtmainline=000000&mtbackground=ffffff&pgndata=[Event "F/S Return Match"]...   game data here   ...43. Re6 1/2-1/2 '/></object></div>

    Just an suggestion ;)


    btw,
    http://jost.byethost2.com/xmas.html
    Last edited by slacker3; 12-24-2009 at 02:57 AM.

  5. #5
    garrensilverwing's Avatar
    garrensilverwing is offline x10 Sophmore garrensilverwing is an unknown quantity at this point
    Join Date
    Nov 2008
    Posts
    148

    Re: Three Options

    thanks for the input, generally PGN format games are very low memory and it will probably take a long time to reach any kind of memory limits so i think i'll go with the third option, to make it easy

+ Reply to Thread

Similar Threads

  1. Urgent - can't fix options menu!
    By Sohail in forum Computers & Technology
    Replies: 4
    Last Post: 02-15-2008, 07:44 AM
  2. Need to enable some PHP options.
    By Super_Fly in forum Soporte
    Replies: 4
    Last Post: 12-17-2007, 04:06 PM
  3. Forum Options Error
    By WeeRowan in forum Free Hosting
    Replies: 6
    Last Post: 12-29-2005, 06:39 PM
  4. vBulletin - Optimization !!!!!
    By bin_asc in forum Scripts & 3rd Party Apps
    Replies: 7
    Last Post: 08-05-2005, 04:27 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers