Trevor M
Trevor M

Reputation: 157

Storing users with many data points

I am trying to take a user from a game and track their stats. Each user has their own stats, so needs tracked separately. This ends up with each user has one dataset, and each dataset has many data points. In code I end up with..

public class User
{
    public string Name { get; set; }
    public List<DataPoint> Data { get; set;}
}

public class DataPoint
{
    public byte Month { get; set; }
    public byte Day { get; set; }
    public short Year { get; set; }
    public Stats stats { get; set; }
}

public class Stats
{
    //user stats, just numbers.
}

(I am using my own month day and year because I don't need the extras of DateTime.)

This works for storing everything in memory, I just can't figure out a good way to persist it. I've been trying to do it in a relational database(SQL). It is the list that is really throwing me off. Should the one table just have a bunch of references to keys of data points? Should just serialize it and store the serialized data instead? I spent some time researching how other people store data points but I couldn't find anything useful.

I am working with Entity Framework in C#.

Upvotes: 1

Views: 143

Answers (2)

smj
smj

Reputation: 1284

If I have understood correctly, could use the following structure in a relational database, you'd use a foreign key on the dataPoint entity to reference the user that the dataPoint relate to. This assumes that the stats collection is pretty consistent.

enter image description here

Upvotes: 1

tinonetic
tinonetic

Reputation: 8036

  1. If persisting objects on a DB, I would use Json as opposed to pure XML(serialization). It is less verbose, lighter on storage and easy to read
  2. I would certainly agree with moving away from relational databases for this use, and would consider NoSQL or key-value store options. If your requirements are as minimal as that, these are fast, have a small footprint, scale cheaper and better.
  3. For an Entity Framework,Code First,NoSQL solution, try BrightstarDb.
  4. Lastly, did you know there's a dedicated Gamedev section in the Stack Exchange network? Here's some goodie I dug up for you from there.

Upvotes: 1

Related Questions