Sumsar1812
Sumsar1812

Reputation: 618

How should I save statistics to a database

I have currently made an irc bot for twitch. I want to save statistics to a database with data like, how many users joined the channel, how many new followers were gained and other stuff too. I am not sure how this is done correctly but the way I have done it now is like this:

CREATE TABLE stats(year,month,day,hour,joinedChannel,TotalFollowers);

But I feel like this will be a wierd way to do it. My question basicly is if there is a smarter way for me to save statistics like shown above.

edit: Hmm well it seems like i didnt supply all the information. Currently I have a table looking like this "CREATE TABLE users(id,points,timespent,follower,followed,wMessage);" I have a few features in my bot like, song request and a queue to join games. I would like to have stats so I can see how many used song requests this day and how many used the queue feature this day and how many followed the channel this day, where "this" would be any chosen day. Wouldn't I need a more complex table design for that? –

Upvotes: 2

Views: 1970

Answers (2)

John Specko
John Specko

Reputation: 307

Combine all of your date_time columns into one using something along the lines of GETDATE() or CURRENT_TIMESTAMP. With what you are keeping track of now. There isn't really a reason to split up into a more complex table design.

So something like this.

CREATE TABLE stats
(
	joinTime DATETIME,
	joinedChannel nvarchar(100), --who joined the channel?
	totalFollowers int
)

Upvotes: 2

Speakard
Speakard

Reputation: 16

You could put year, month, day, hour in the same field. And the joinedChannel would be in another table. Then create a foreign key relationship of joinedChannel to stats. The whole thing would become more dynamically. You could also put the date in different table. At least year, but not day and hour...

Upvotes: 0

Related Questions