mwheen Posted November 5, 2008 Share Posted November 5, 2008 I am successfully using a firmware counter to count from a water meter using a U3 and would like to construct a bar graph showing the daily count. Any help would be greatly appreciated. Link to comment Share on other sites More sharing options...
AzeoTech Posted November 6, 2008 Share Posted November 6, 2008 1) create a new channel to hold the daily totals. Make it device type Test, and select Timing of 0. Lets say you call it dailytotal 2) In the event for your firmware counter channel, which we will say you called Counts, put: if (formatdatetime("%d",counts.time[0]) != formatdatetime("%d",counts.time[1])) private total = sum(counts[systime(),systime() - 86400]) total.time = systime() dailytotal.addvalue(total) endif 3) Graph dailytotal vs time Link to comment Share on other sites More sharing options...
mwheen Posted November 6, 2008 Author Share Posted November 6, 2008 Thanks alot for your quick response. I really appreciate it! One other question, I am also looking to create a variable display showing only the counts starting from 0:00hrs for the current day. Thanks again. Link to comment Share on other sites More sharing options...
AzeoTech Posted November 7, 2008 Share Posted November 7, 2008 That's just: sum(counts[floor(systime()/86400)*86400, systime()] floor(x/y)*y is the standard algorithm in all programming languages to find the largest integer multiple of y that is less than x. 86400 is the number of seconds in the day, and since systime() returns time since midnight 1970, the above does what you want. Notice how I'm subsetting in time instead of by index (i.e. counts[0]) Link to comment Share on other sites More sharing options...
mwheen Posted November 10, 2008 Author Share Posted November 10, 2008 Am I supposed to be summing over a count interval or a raw count value? Cheers Link to comment Share on other sites More sharing options...
AzeoTech Posted November 10, 2008 Share Posted November 10, 2008 What I've sent so far assumes that you are resetting the counter every time you read it. This is not necessarily the best way as it will miss occasional counts, but it is easier to work with to some extent. If you expect a large amount of counts (say 100 per second or more), then you really don't want to reset the counter ever and the logic changes. In this case, you should create a global variable with the counts at the end of the previous day and subtract it from the counts at the end of the day. First, create the global variable in a startup sequence that sets this to 0 and resets the counter (once). Then the event code becomes (assuming that global is lastdaycount: if (formatdatetime("%d",counts.time[0]) != formatdatetime("%d",counts.time[1])) private total = counts[0] - lastdaycount total.time = systime() dailytotal.addvalue(total) lastdaycount = counts[0] endif Then to display the accumulated for the day, just do: counts[0] - lastdaycount Link to comment Share on other sites More sharing options...
andybdjuk Posted September 13, 2009 Share Posted September 13, 2009 Hi, I was interested in using this count routine to display my cumulative kWh for today, from midnight. Could you just tell me how to.. "First, create the global variable in a startup sequence that sets this to 0 and resets the counter (once). Then the event code becomes (assuming that global is lastdaycount:" Thanks Andy Link to comment Share on other sites More sharing options...
AzeoTech Posted September 14, 2009 Share Posted September 14, 2009 It depends. Are you measuring KWh or KW? I guess it comes down to: do you just want a sum of a channel for the day, or is the hardware doing the summing (as it is in the rest of this post)? If you just want a sum of a channel its just: sum(mychannel[floor(systime()/86400)*86400, systime()]) floor(systime()/86400)*86400 is midnight today. Systime() is just now, so we are just getting all the data points in mychannel from midnight until now and summing it. The rest of this post is about putting the sum for the day into a separate channel so you can graph daily totals over time. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.