Logging data (i.e. temperature over time) to database and draw graph

Posted 15 February 2012 - 12:58 AM

Hi,

First of all, I am not asking for a complete solution - merely a hint in the right direction.

I have been Googling around for hours but I am still very confused. I want to log a set of data like temperature inside, outside etc with a timestamp. Currently I am logging this to a .txt file, but this makes it very hard to present the data in graphs in order to show temperatures from i.e. last 24 hours, or last week, last month etc.

Correct me if I am wrong, but I have come to the conclusion that I need to learn how to do this using database (SQL?) and then when the data are stored in the database I will need to figure out a way to draw the graphs from there.

So what I am wondering:

1) Will this be the best/easiest way to attack this problem, store the data in an SQL database and then draw graphs?

2) If yes, where should I begin - are there any good tutorials or other resources you guys could recommend?

Then you could have a key being the timeDate and the value being the temperature. This would allow you to find any temperature by its date, by searching the keys, or allow you to find all dates where it was a certain temperature by searching the values.

You can write the data stored in your dictionaries to a textfile (XML files allow you to load data from them directly into your class structure) and load the data from the text file when the application is started, this is a very common way of doing configuration files.

The process is called Serialization. Not hard to find tutorials on the subject, learnt it myself the other day.

To save settings after you've closed a WinForms application you have to have written something to the actual hard drive rather than just memory. So yeah you could also write it to a database, just personally I don't see the point unless you need to use that database for something outside of a .NET application.

Thanks again! I am an electric engineer and even if I have programmed a fair share of C# in my spare time this is completely new territory for me! Im very excited to learn this. I'll get well known with Dictionary before I go further ahead and learn Serialization though.

Horribly messy, but still: The DateTime variable are so accurate (down to milliseconds I think), so I wonder if I wanted to pick out values from time A to time B (i.e. Feb 1st to Feb 2nd) I wonder how to achieve this.

But anyway your help has brought me closer to what I am trying to achieve!

This post has been edited by tlhIn`toq: 15 February 2012 - 06:40 AM
Reason for edit:: No need to quote the entire immediately preceding post

Also, a big plus is that it's open source. So you can see for yourself how does it actually work.

Funny you should say that, I googled around (using your google link) and ended up with ZedGraph myself. Im already graphing up things as we speak, it seems very easy to use.

Could I just ask you though, would you serialize as XML (what Im currently doing) or as binary code? Each year I will do 500 thousand measurements, will this bee too much for a dictionary in your opinion?

I would export it to XML so that you can easily modify it later on, or when you plan on upgrading the system, and so that you can use it in other applications too. (You could use binary format in other applications, but this way it's much easier to get the data you're after).

This way when you plan on changing the name of a variable you don't have to rewrite the code, just to rename your node in XML.

And 500 entries is nothing. I've loaded thousands and thousands of entries from a dataBase and it went fine.

I just wanted to post the result, showing temperature inside and outside for the last 24 hours, week, month and year.
If anyone needs help with something similar I would be happy to contribute back to the community by helping others.

I realize that I am a little late on this topic, but another option to consider for future projects is to use a database. If so, you can always grab MySQL for free. Once you have that, you can use their connector to pull the data. In addition, check out Fluent NHibernate as a data mapper. It makes life very easy when dealing with a database.