Butterbean Posted January 11, 2015 Share Posted January 11, 2015 (edited) I have an energy monitoring system that I am building. This EMS gathers data once per minute and drops that data into a mssql db. I have php set up to interpret the values and allow the customer to query the mssql for data for a peak value within a 15 minute interval. The user enters the 15 minute interval into the web app, along with the timeperiod (15 minute interval in question) example (2014-10-16 at 07:30:00 - 07:44:59 ). Sometimes there is no data in that interval because there was nothing reported (due to power outages or internet connection issue). When there is no data to report, there is not even an entry row set in mssql, therefore the time and date it is querying is not present. I am trying to find a way that if php queries mssql and the row that is queried does not exist, have php look forward than backwards simultaneously until it finds any value (it can even be a zero as long as its a value) to report. I would think I could cover any situation including a major power outage by looking forward three (3) days and back three (3) days. I'm not sure where to even start with something like this. Does anyone have a suggestion on how to start? Edited January 11, 2015 by Butterbean Quote Link to comment https://forums.phpfreaks.com/topic/293849-when-there-is-no-value-in-a-cell/ Share on other sites More sharing options...
QuickOldCar Posted January 11, 2015 Share Posted January 11, 2015 If you query a date that don't exist you should output it as zero and also be calculating that into any graphs or usage. No data to me equates to zero usage, correct? Quote Link to comment https://forums.phpfreaks.com/topic/293849-when-there-is-no-value-in-a-cell/#findComment-1502563 Share on other sites More sharing options...
Butterbean Posted January 12, 2015 Author Share Posted January 12, 2015 (edited) I see why you would think that, however, if there is no data, the metering sends an empty packet with zero values. So there will be a row in mssql that has all zeros. Occasionally there is no row of data sent by the EMS, so if it doesnt exist, it doesnt mean that they were using zero energy, it just means that the data never reached the server ( in the timestamped period), so we look at the next timestamps. In that event I need a backup plan to look forward then backward until it finds data (that data can even be zero). This system never stops sending data, so if it doesnt make it to the server, there is some reason (something blocking the 900 MHz, internet down or electric down). Edited January 12, 2015 by Butterbean Quote Link to comment https://forums.phpfreaks.com/topic/293849-when-there-is-no-value-in-a-cell/#findComment-1502609 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.