general advice on data storage

M

Mike

Hi,

I'm new to vb.net and would be grateful if anyone could offer some
advice on the best way to approach this problem:

I wish to dynamically capture pricing information e.g. 10 stock prices
and use this data to generate a number of graphs over time (in real
time) of each share price. This means for each share I need to store a
price and a timestamp.

I would need to collect around 600 pairs of data per stock (once per
second for 10 mins), so around 6000 in total, then roll the data
forward so that I only ever keep 600 records i.e. always have the last
10 minutes worth of data for each stock.

I would therefore like to know the best method to store this data on
the fly. I can only think of an array or dataset as a way to do this
but maybe there are better solutions I am unaware of?

Thanks for any help,

Mike
 
C

Cor Ligthert [MVP]

Mike,

It is a very rough answer for a newsgroup, however I think that I would
first try for an SQLExpress or the old MSDE database. With a table per
share.

Than add it everytime rows using the insert to the share tables with a new
datatime field as key.

Creating those tables is easy to do in VBNet in a for each loop.

To get than a datatable for the last 10 minutes is just getting that with a
fill with a "where" clause the < datatime. It is not slow however I don't
know if it is quick enough.

It needs of course consequent deleting with another seperate running program
from the old rows.

Using the dataset/datatable itself inside a dataset will almost for sure
break you up in VS2003. Deleting of that will probably be to slow (this
should be improved in VS2005, however I did not try it yet)

Just as first idea when I saw your question.

Cor
 
J

Jevon

How often will the graph be redrawn?

In addition to Cor's reply, here's another option:
Use a linked list. Something like the following [psuedocode]:

public struct StockHistoryItem
Dim price as double
Dim timestamp as DateTime
end struct

class StockHistory
Private data() as StockHistoryItem
Private startData as Long = 0
Private endData as Long = 0
Private maxSize as Long = 0

public Sub New(byref size as Long)
if Size>0 then
maxSize = size
Redim data(maxSize) As StockHistoryItem
else
throw new Exception - invalid
end if
end sub

public sub AddItem(ByVal newItem as StockHistoryItem)
if endData = maxSize then
endData = 0
else
endData += 1
end if
data(endData) = newItem
if endData = maxSize Then
startData = 0
else
startData += 1
end if
end sub
end class

Bear in mind I don't think the upper bound stuff is correct - you might need
(endData + 1) in the "If" statements involving it. You obviously need
functions to retrieve data - you could implement IEnumerable or have
something like:
public sub GetItem(byref index as Long)
if index >=0 AND index <= maxsize - 1 then
' You also need to check in case you haven't yet filled the
structure with values.
GetItem = data(Dim item As Long = (index + startData) Mod
maxSize)
end if
end sub


If you took Cor's route, you don't necessarily need an entirely separate
program, you could clean up old rows each time you draw the graph.

Jevon
 
J

Jevon

Sorry, I should add to this that it obviously isn't necessarily the best
option if memory is an issue, but for the amount of data you mention it
shouldn't be too much of a problem.

Jevon

Jevon said:
How often will the graph be redrawn?

In addition to Cor's reply, here's another option:
Use a linked list. Something like the following [psuedocode]:

public struct StockHistoryItem
Dim price as double
Dim timestamp as DateTime
end struct

class StockHistory
Private data() as StockHistoryItem
Private startData as Long = 0
Private endData as Long = 0
Private maxSize as Long = 0

public Sub New(byref size as Long)
if Size>0 then
maxSize = size
Redim data(maxSize) As StockHistoryItem
else
throw new Exception - invalid
end if
end sub

public sub AddItem(ByVal newItem as StockHistoryItem)
if endData = maxSize then
endData = 0
else
endData += 1
end if
data(endData) = newItem
if endData = maxSize Then
startData = 0
else
startData += 1
end if
end sub
end class

Bear in mind I don't think the upper bound stuff is correct - you might
need (endData + 1) in the "If" statements involving it. You obviously need
functions to retrieve data - you could implement IEnumerable or have
something like:
public sub GetItem(byref index as Long)
if index >=0 AND index <= maxsize - 1 then
' You also need to check in case you haven't yet filled the
structure with values.
GetItem = data(Dim item As Long = (index + startData) Mod
maxSize)
end if
end sub


If you took Cor's route, you don't necessarily need an entirely separate
program, you could clean up old rows each time you draw the graph.

Jevon


Mike said:
Hi,

I'm new to vb.net and would be grateful if anyone could offer some
advice on the best way to approach this problem:

I wish to dynamically capture pricing information e.g. 10 stock prices
and use this data to generate a number of graphs over time (in real
time) of each share price. This means for each share I need to store a
price and a timestamp.

I would need to collect around 600 pairs of data per stock (once per
second for 10 mins), so around 6000 in total, then roll the data
forward so that I only ever keep 600 records i.e. always have the last
10 minutes worth of data for each stock.

I would therefore like to know the best method to store this data on
the fly. I can only think of an array or dataset as a way to do this
but maybe there are better solutions I am unaware of?

Thanks for any help,

Mike
 
M

Mike

Thanks for the alternative. I would ideally like to redraw the graph
each time a new data point is stored, so I'm hoping once a second.

I'm not sure whether the performance of graphing add-ins would be able
to handle this or not, but maybe I could resort to drawing it if they
can't. My ultimate aim would be to have each of these graphs running
within a datagrid cell (which would most likely require me to draw
manually) but that is way beyond my current level so I'll save that
part of it as a project for the future :)

Thanks again,

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top