This topic is locked

Calculating a loss over a time

1/26/2012 9:33:53 PM
PHPRunner General questions
S
swanside author

Hi there

I have the following table. I want to be able to do the following, but I can not for the life of me work it out how to do this.

"Parameter 34 - 13varchar(10) NOT NULL," The data inputted in to this field is water pressure, now, everyday I take a reading of the water pressure and it gets entered into this field.
When saved the data is timestamped.
Now, I need to be able to see the difference in the water pressure against the timestamp, like this

On a Monday I take the water pressure so I have this
Timestamp = 2012-01-23 01:01:32 and Parameter 34 - 13 = 1.50

On a Tuesday I take the water pressure so I have this
Timestamp = 2012-01-24 01:01:32 and Parameter 34 - 13 = 1.40

So now, over a 24 hour period I have lost 0.10, If I now divide the loss by the time, it will give me a loss per minute, so 24H * 60 = 1440 mins / 0.10 = 0.0000694 per min
Can anybody help me work out how I can get the previous data entered and perform this calculation please?
Thanks
paul



ThrusterIdint(11) NOT NULL auto_increment,
Datedate NOT NULL,
Usernamevarchar(100) NOT NULL,
Areavarchar(100) default NULL,
RigNamevarchar(50) default NULL,
Catagoryvarchar(50) default NULL,
Parameter 34 - 12varchar(10) NOT NULL,
Parameter 34 - 13varchar(10) NOT NULL,
Parameter 34 - 14varchar(10) NOT NULL,
Parameter 34 - 15varchar(10) NOT NULL,
Parameter 34 - 16varchar(10) NOT NULL,
TimestampRef` timestamp NOT NULL default '0000-00-00 00:00:00' on update CURRENT_TIMESTAMP,

C
cgphp 1/27/2012

Can anybody help me work out how I can get the previous data entered and perform this calculation please?


It's not very clear what you want to do. Please, explain in more detail your request.

S
swanside author 1/27/2012



It's not very clear what you want to do. Please, explain in more detail your request.



Ok I will try

I have this in my SQL

SELECT

ThrusterId,

Date,

Username,

Area,

RigName,

Catagory,

Parameter 34 - 12,

Parameter 34 - 13,

Parameter 34 - 14,

Parameter 34 - 15,

Parameter 34 - 16,

TimestampRef

FROM Thruster



Now I enter the values in my page and save them. So it would look like this

SELECT

ThrusterId,

Date, = 21/01/12

Username, = Bob

Area, = 1

RigName, = 1

Catagory, = 1

Parameter 34 - 12, = 0.10

Parameter 34 - 13, = 1.24

Parameter 34 - 14, = 4.45

Parameter 34 - 15, = 2.12

Parameter 34 - 16, = 12.12

TimestampRef = 2012-01-21 17:44:56

FROM Thruster



The next week, I would do the same inspections and have this

SELECT

ThrusterId,

Date, = 27/01/12

Username, = Bob

Area, = 1

RigName, = 1

Catagory, = 1

Parameter 34 - 12, = 0.12

Parameter 34 - 13, = 1.14

Parameter 34 - 14, = 4.43

Parameter 34 - 15, = 2.12

Parameter 34 - 16, = 12.12

TimestampRef = 2012-01-27 17:44:56

FROM Thruster


Now, the part I need to know is the difference between Parameter 34 - 13 on the 21/01/12 and Parameter 34 - 13 on the 27/01/12. This is a water pressure, so on the 21/01/12 it was 1.24 BAR and on the 27/01/12 it was 1.14 BAR, so over a week it has lost 0.10 BAR, now the time difference over that period from the timestamps is the first week 2012-01-21 17:44:56 and the second week 2012-01-27 17:44:56 which is 168 hours, I have made up the timestamps to work out the hours better, which is 10080 minutes. So if I now divide the loss of BAR which is 0.10 by the time it has taken which is 10080 (Minutes in a week) it gives me a vlue of 0.0000099 BAR, So I now know that I am looseing water at a rate of 0.0000099 bar a week, I can then calculate when I need to fill up again with water, or monitor it to a graph to see if it gets worse.

I could also do it on a daily basis which would just mean entering the reading daily.
Does that make it any better?

I suppose I could try to say this

SELECT

ThrusterId,

Date, = 27/01/12

Username, = Bob

Area, = 1

RigName, = 1

Catagory, = 1

Parameter 34 - 12, = 0.12

Parameter 34 - 13, = 1.14

Parameter 34 - 14, = 4.43

Parameter 34 - 15, = 2.12

Parameter 34 - 16, = 12.12

Select (previous Parameter 34 - 13) AS Last Weeks Reading

TimestampRef = 2012-01-27 17:44:56

FROM Thruster


Cheers

Paul