BasicTimeSeries - Having problems adding! HELP PLEASE!!

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Alfred

BasicTimeSeries - Having problems adding! HELP PLEASE!!

Post by Alfred » Fri Nov 15, 2002 3:15 pm

Hi,

I have a program that adds lots of data into a timeseries chart. I keep on getting can't add because that time period already exists. I was wondering if there is any whay around this problem. For example, i'm guessing since my timeseries takes in seconds and since i'm adding like over 700 entries the seconds are going to overlap, so is that the reason for this error.

I would really appreciate it if somebody could help me out to get around this problem.

Thanks,
Alfred

Irv Thomae

Re: BasicTimeSeries - Having problems adding! HELP PLEASE!!

Post by Irv Thomae » Fri Nov 15, 2002 3:35 pm

A BasicTimeSeries can have only one numeric value for each TimePeriod (in your case, for each second).

You can avoid that Exception by using the alternate method in BasicTimeSeries called addOrUpdate(). If your data incldes a second value for the same second, this method will simply replace the value it already held with your new one.

However,if you're getting a large number of overlaps in time, it would be prudent to investigate what's causing these apparent redundancies . For example, if you're getting two or more _partial_ results for each time-period, maybe you should look for a way to add them together?

Hope this helps,
Irv Thomae

Alfred

Re: BasicTimeSeries - Having problems adding! HELP PLEASE!!

Post by Alfred » Fri Nov 15, 2002 3:47 pm

Thanks for your reply,

I should have been more detailed on how my program works, sorry.

My program basically graphs the network utilization of a network where it grabs its data i.e. the timestamp and the percentage for that specific time. Since the program we use to collect the data collects every 10 min or so and causes the overlap since its possible to get the same second for a different day.

In terms of replacing the data I don't think that would be good because if my manager looks at my program and notices a whole on one the days on the graph she's going to wonder why thinking that it could have been a network failure of some sort and that would not be good hehe...

What i'm guessing is that jfreechart uses the second as a key of some sort when it stores the info so I guess I could edit the second to add a second so it's unique in that sense but I only want to do this if its my last resort.

Any other suggestions would be helpful

David Gilbert

Re: BasicTimeSeries - Having problems adding! HELP PLEASE!!

Post by David Gilbert » Fri Nov 15, 2002 4:01 pm

Hi Alfred,

Internally, the Second object records the Minute that it belongs to. The Minute records the Hour that it belongs to, and the Hour records the Day that it belongs to.

So if you create a Second for some time during today, it should never be equal to a Second for some time during yesterday.

What is the code you use to create the Second object?

Regards,

DG

Alfred

Re: BasicTimeSeries - Having problems adding! HELP PLEASE!!

Post by Alfred » Fri Nov 15, 2002 4:14 pm

This is a great forum I get instant replies hehe! =)

Anyways,

here is what i used maybe its wrong or something:

public void initialize(ResultSet inputrs, String inputtitle, int numofrows)
{
Timestamp temptimestamp = null;
String tempstring = "";
Double dvalue = null;
Second second = null;
ts = new BasicTimeSeries(inputtitle, Second.class);
title = inputtitle;
System.out.println("This is the title of the graph: " + title);
//initialize categories
try
{
while(inputrs.next())
{
temptimestamp = inputrs.getTimestamp(1);
dvalue = new Double((double)inputrs.getFloat(2));
second = new Second(temptimestamp);
ts.add(second, dvalue);
}
inputrs.close();
}
catch(SQLException ex)
{
System.err.println("SQLException: " + ex.getMessage());
System.exit(-1);
}
}

Alfred

Re: BasicTimeSeries - Having problems adding! HELP PLEASE!!

Post by Alfred » Fri Nov 15, 2002 4:26 pm

Hi again,

I think i gave the wrong code that was an older version that wouldn't let me add at all...I just changed the add line to:

.
.
.
ts.add(Second.parseSecond((temptimestamp.toString()).substring(0,19),
(double)inputrs.getFloat(2));
.
.
.
and made removed the variables and such that are not needed.

this allows me to get up to about 700 entries but doesn't allow me to go pass a certain date...it says that I have duplicate entries..which is weird.

David Gilbert

Re: BasicTimeSeries - Having problems adding! HELP PLEASE!!

Post by David Gilbert » Fri Nov 15, 2002 4:27 pm

I can't see anything obviously wrong in your code. Are the time stamps in the database all ten minutes apart? If so, then there must be a bug in the time period classes used by JFreeChart...it would help me to track it down if you could e-mail me a list of the millisecond values for each Timestamp in your result set.

Regards,

DG

David Gilbert

Re: BasicTimeSeries - Having problems adding! HELP PLEASE!!

Post by David Gilbert » Fri Nov 15, 2002 4:31 pm

If you are using Second.parseSecond(...), then a list of the dates as String objects would be useful. It wouldn't surprise me if the parse method has bugs...

Regards,

DG

Alfred

Re: BasicTimeSeries - Having problems adding! HELP PLEASE!!

Post by Alfred » Fri Nov 15, 2002 5:05 pm

Your absolutely correct,

there was a problem with the actual network monitoring program where it stored double dates for the exact same time for the exact same interface which is very weird. This then caused the problem because we had the exact same time. I'm looking into the problem now...thanks for your help and sorry to waste your time.

BTW, this is a great program you made it made my life a whole lot easier! Good job!

Locked