I'm trying to create a dynamic chart. I've got series of data in a database (for example pH, with first column timestamp and second column the value) and I'm trying to display series into a chart. The series have different time record for their values, so I'm trying to subtract the first timestamp of a serie to all timestamps of the same serie so that all the series should have the same time range so they will be superimposed on the chart.
I can do this by converting the timestamp in a long and then I can easily do my subtraction. But I have troubles to convert back the long into a timestamp and so display the modified serie in a chart. I tried many things but didn't work so I need help. I'm using the function getTime() to convert in a long, but I don't know why, the function Timestamp() doesn't work.
Maybe there is also a better way to subtract timestamp, I tried to find one but I didn't.
Here's part of my code if that can help to understand:
I need the timestamp because records of data are sometimes made at different times, they are not regular (for example: for the first serie I record one value at 6pm then 7pm then 9pm, and for a second serie I record one value at 6:30pm then 7pm then 8pm then 9pm.) but I don't care that the date displayed on the X-axis is the wrong one.
So this is for that I'm trying to subtract the first timestamp to each timestamp of a column of a dataset. For now I success to subtract but I'm not able to convert the value into a timestamp again, and I didn't find a function for that
Q1. Have you a separate binding for each trend? If not, what is the structure of the data returned by the named query?
Q2. You want the X-axis in HH:mm:ss since the start of the test?
Data are recorded in a database and are all linked to a key value. This key value changes which allows to differentiate each series. My named query retrieves values with this key value as parameter and returns a dataset of two columns:
first column is the timestamp
second column is the value
So something like this:
The X-axis is not useful there, what interests me is to be able to compare the different series thanks to their trend, but for that I need them to be side by side, which is not the case if I don't modify them.
To specify how to retrieve my values for the trends:
I have a list of all the key values available (so all series), the user can select one then use a add button which will add this key value to an array. Then, with an update button, a script will make a loop depending on the number of key values added to the array. For each pass in the loop, a dataset will be filled with the data of the named query with the key value in parameter, then it will be modified and then added to the chart.
Thanks it makes sense, but unfortunately functions are not working.
The dateDiff takes "Date" type as parameters but I have timestamp in my dataset so I think it's not working because of that. I tried several things to convert timestamp as Date type but I didn't success, any idea ?
Yes I found this function and already tried it, but didn't work. Actually I don't understand why I can make the function getTime work but not the Timestamp function while they are from the same constructor.
When I say it doesn't work, it's because just after the function I put a command like:
with msFromT0 the result of the function, but the program don't go further than the line of the function. Even when I tried to display something else in my label, like "a", I have nothing.
This is my code (for now, I'm just trying to apply it for one value, I guess as soon as I am able to do it for one value, I can do it for the whole dataset):
Ah, there's no jython function getTime(). But java.util.Date and java.sql.Timestamp both have a .getTime() instance method that yields long milliseconds. You can shorten that to its NetBeans property equivalent, .time. So,
It's not in my interest to not showing you something...
Here's my whole code (linked to an event onActionPerformed of a button), I also put you values and type in comments:
def runAction(self, event):
"""
Method that will run whenever the selected event fires.
Arguments:
self: A reference to the component that is invoking this function.
event: An object that holds information about the selected event type
"""
# Retrieve the selected values from the Dropdown boxe
data_to_display = self.getSibling("Dropdown_data_to_display").props.value
dataset = system.db.runNamedQuery("Charts/" + data_to_display, {"ProductionLot":"3212016"})
pydataset = system.dataset.toPyDataSet(dataset)
timestamp = pydataset[0][0]
#timestamp = 1687178960070
#type(timestamp) = <type 'java.sql.Timestamp'>
first_value = pydataset[0][0].getTime()
#first_value = 1687178960070
#type(first_value) = <type 'long'>
second_value = pydataset[1][0].getTime()
#second_value = 1687182947547
#type(second_value) = <type 'long'>
sub = second_value - first_value
#sub = 3987477
#type(sub) = <type 'long'>
Oh yes you're right my bad for that. I tried and deleted a lot of things so I put what I remembered. But in my first message I wrote it like that
Thanks for you help