Storing data

Recommended Posts

Hello, I'm currently working on a sports management game which means I need to store a lot of data. I'm trying to figure out the best way to do this, right now I have written my own functions to store the classes binary. I have also been checking out XML and SQLite but I have failed to come up with a good way to organize the data when storing it. For example using XML, how would you store a structure like this?
struct Stats
{
int assists;
int games;
int goals;
int penaltyMinutes;
};

struct Player
{
int height;
int id;
int weight;
std::string name;
std::vector<Stats> stats;
};
The problem I have with the above structure is obviously storing the vector. Basically I have the same problem when using SQLite. I don't have any previous experience in this area and it is giving me a headache :) Any ideas are welcome.

Share on other sites
Hi dabo,

I would recommend to create a logical XML structure for your data first, and only then figure out how to read it. In this case I'd suggest:

<Player height='2' id='0' weight='80' name='John Doe'>  <Stats>    <Stat assists='4' games='20' goals='3' penaltyMinutes='32' />    <Stat assists='2' games='3' goals='1' penaltyMinutes='12' />  </Stats><Player>

To read the actual xml, you might want to check out the TinyXML library.

If you decide to use SQLite instead; I'd create 2 tables to model this.
- A Player table, containing the fields height, id, weight and name
- A Stats table, containing the fields assists, games, goals, penaltyMinutes and quite importantly playerID.
Than to get all stats of a certain player you'd be able to do something along the lines of:
RunQuery( "SELECT * FROM Stats WHERE playerID='{0}'", player.id );

Furthermore, I don't really have much domain knowledge of sports, but the fact that a player needs an array of stats in this manner seems a little odd to me. But again, I'm not exactly sure what you're trying to model, so it might be perfectly fine.

Kinds regards,
Tristan

[Edited by - Tristan85 on May 29, 2009 6:13:20 AM]

Share on other sites
Quote:
 Original post by daboHello, I'm currently working on a sports management game which means I need to store a lot of data. I'm trying to figure out the best way to do this, right now I have written my own functions to store the classes binary.

What are your requirements? If storing as binary is enough, why look for something else?

You can also look into JSON for storage:

{   height : 6,  id     : 1,  weight : 52,  name   : 'John',  stats  : [    {      assists : 3,      games   : 2,      goals   : 1,      penalty : 11     },    {      assists : 2,      games   : 2,      goals   : 8,      penalty : 3    }  ]}

Check out projects like jsoncpp.

Share on other sites
Thank you both for your replies.

Yes I would have no problems storing everything binary, but I'm just interested in hearing from others how they would do it.

Share on other sites
Quote:
 Original post by Tristan85If you decide to use SQLite instead; I'd create 2 tables to model this.- A Player table, containing the fields height, id, weight and name- A Stats table, containing the fields assists, games, goals, penaltyMinutes and quite importantly playerID.Than to get all stats of a certain player you'd be able to do something along the lines of:RunQuery( "SELECT * FROM Stats WHERE playerID='{0}'", player.id );

If you take this approach, you'll need some way to ensure the order of loaded stats, assuming it matters.

Quote:
 Furthermore, I don't really have much domain knowledge of sports, but the fact that a player needs an array of stats in this manner seems a little odd to me. But again, I'm not exactly sure what you're trying to model, so it might be perfectly fine.

I'm guessing that they're "career" stats, taken year-over-year. :)

In that case you could add a "year" column to Stats (and make the player-id/year combination a primary key, or something), and an ORDER BY clause to the select statement. But that still wouldn't tell you what year the player started in, and wouldn't handle any missing years. So in the corresponding C++ structures, you'd want to replace the vector with a map of int (the year) to Stats.

Create an account

Register a new account

• Forum Statistics

• Total Topics
628320
• Total Posts
2982057

• 12
• 9
• 9
• 13
• 11