/build/static/layout/Breadcrumb_cap_w.png

Scripting Question


Hours between certain times

04/22/2015 1432 views

I'm trying to adjust the below script to charge specific rates between certain hours during the day.

Mid-peak rate 7:00am - 11:00am cost is 11.4 cents/kwh

On-peak rate 11:00am - 5:00pm cost is 14 cents/kwh

Mid-peak rate 5:00pm - 7:00pm cost is 11.4 cents/kwh

Off-peak rate 7:00pm - 7:00am cost is 7.7 cents/kwh

SELECT M.NAME as 'Machine', FORMAT(SUM(MDU.HOURS), 0) as 'Hours On',FORMAT((COUNT(MDU.ID)*24) - SUM(MDU.HOURS),0) as 'Hours Off', FORMAT(SUM(MDU.HOURS) / COUNT(MDU.ID),0) as 'Avg Hours Per Day', CONCAT('$',FORMAT(SUM(MDU.HOURS) * .07 * .31, 2)) as 'Energy Cost Spent',
CONCAT('$', FORMAT(((COUNT(MDU.ID)*24) - SUM(MDU.HOURS)) *.07 * .31, 2)) as 'Energy Cost Saved'
FROM MACHINE M, MACHINE_DAILY_UPTIME MDU
WHERE MDU.MACHINE_ID = M.ID
AND MDU.DAY >= DATE_SUB(NOW(), INTERVAL 2 WEEK )
GROUP BY M.NAME


Does anyone know if this is possible?

Thanks

Matt



0 Comments   [ + ] Show comments

Comments


All Answers

0
The MACHINE_DAILY_UPTIME table doesn't track which hours the machine was on, just how many, because of that you can't calculate which of the hours it was in use. In order to break out costs by time interval you need data on when machines were actually powered on and powered off, not just the total hours they were powered on.
Answered 04/23/2015 by: chucksteel
Red Belt

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login

View more:

Share

 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ