<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Percent Used Bar Chart]]></title><description><![CDATA[<p dir="auto">We have a few MQTT occupancy sensors that have a binary data point called "occupancy" that indicates a cubicle is vacant (0) or occupied (1).</p>
<p dir="auto">The client would like to trend the utilization of each sensor by hour or day for a certain time range. For example, the client would like to see a bar chart of percent used of a cubicle by hour for Today So Far. Any advise on how to approach this?</p>
<p dir="auto">BR,<br />
Ricardo</p>
]]></description><link>https://forum.mango-os.com/topic/5187/percent-used-bar-chart</link><generator>RSS for Node</generator><lastBuildDate>Wed, 10 Jun 2026 09:07:56 GMT</lastBuildDate><atom:link href="https://forum.mango-os.com/topic/5187.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 21 May 2021 12:19:50 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Percent Used Bar Chart on Sat, 29 May 2021 01:21:34 GMT]]></title><description><![CDATA[<p dir="auto">Of course, one of my suggestions was doing the whole thing as a reusable directive. If you can think of it, the only limitations are hardware and imagination</p>
<p dir="auto">Fox</p>
]]></description><link>https://forum.mango-os.com/post/26674</link><guid isPermaLink="true">https://forum.mango-os.com/post/26674</guid><dc:creator><![CDATA[MattFox]]></dc:creator><pubDate>Sat, 29 May 2021 01:21:34 GMT</pubDate></item><item><title><![CDATA[Reply to Percent Used Bar Chart on Sat, 29 May 2021 00:50:37 GMT]]></title><description><![CDATA[<p dir="auto">Hi Matt,</p>
<p dir="auto">Do you think we can do this dynamically with AngularJS rather than with data points? One advantage doing it dynamically is we can change the bin group dynamically. What do you think?</p>
<p dir="auto">BR,<br />
Ricardo</p>
]]></description><link>https://forum.mango-os.com/post/26673</link><guid isPermaLink="true">https://forum.mango-os.com/post/26673</guid><dc:creator><![CDATA[ricardo]]></dc:creator><pubDate>Sat, 29 May 2021 00:50:37 GMT</pubDate></item><item><title><![CDATA[Reply to Percent Used Bar Chart on Fri, 28 May 2021 19:30:58 GMT]]></title><description><![CDATA[<p dir="auto">Here is something I quickly threw together to illustrate my point. When doing the pie chart, just get the length of the pointValues array for each datapoint in your timeframe,<br />
Each of the variables are context points in a virtual datasource.</p>
<pre><code>var prevState = state.lastValue(1);print(prevState)
if(state.value &amp;&amp; !prevState.value)
{
   timeTracker.set(0);
   LOG.info("timestracker set")
   
}

else if(prevState.value &amp;&amp; !state.value)
{
    var prevTimestamp = timeTracker.time;
    var newTimestamp = state.time;
    
    var timespent = (newTimestamp - prevTimestamp)/60000.0; //In minutes
    timeTracker.set(timespent,newTimestamp);
   LOG.info("time spent")
   LOG.info(timespent)
   
    if(timespent&lt;1)
    {
        
        //LOG.info("less than one")
        lessThanOne.set(timespent);
    }
    else if(timespent&gt;=1 &amp;&amp; timespent&lt;10)
    {
        //LOG.info("less than ten")
        lessThanTen.set(timespent,newTimestamp);
    }
    else if(timespent&gt;=10)
    {
        //LOG.info("more than ten")
        moreThanTen.set(timespent,newTimestamp);
    }
}
</code></pre>
]]></description><link>https://forum.mango-os.com/post/26671</link><guid isPermaLink="true">https://forum.mango-os.com/post/26671</guid><dc:creator><![CDATA[MattFox]]></dc:creator><pubDate>Fri, 28 May 2021 19:30:58 GMT</pubDate></item><item><title><![CDATA[Reply to Percent Used Bar Chart on Fri, 28 May 2021 06:37:42 GMT]]></title><description><![CDATA[<p dir="auto">Roger, Ill have something for you to look at later tonight. Thank you for making an effort.<br />
Generally, if you log at as the data comes in, its easier to filter with a window filter for ensuring you do not have false positives. But if you are happy with the quality of the data, I shall work with that.</p>
<p dir="auto">Fox</p>
]]></description><link>https://forum.mango-os.com/post/26670</link><guid isPermaLink="true">https://forum.mango-os.com/post/26670</guid><dc:creator><![CDATA[MattFox]]></dc:creator><pubDate>Fri, 28 May 2021 06:37:42 GMT</pubDate></item><item><title><![CDATA[Reply to Percent Used Bar Chart on Fri, 28 May 2021 06:21:17 GMT]]></title><description><![CDATA[<p dir="auto">Hi Matt,</p>
<p dir="auto">The occupancy data point's logging type is set to "When point value changes".</p>
<p dir="auto">BR,<br />
Ricardo</p>
]]></description><link>https://forum.mango-os.com/post/26669</link><guid isPermaLink="true">https://forum.mango-os.com/post/26669</guid><dc:creator><![CDATA[ricardo]]></dc:creator><pubDate>Fri, 28 May 2021 06:21:17 GMT</pubDate></item><item><title><![CDATA[Reply to Percent Used Bar Chart on Fri, 28 May 2021 06:14:54 GMT]]></title><description><![CDATA[<p dir="auto">Ok, I can help expand, however, is this data inserted at set intervals or only when there is a change in state?</p>
<p dir="auto">Fox</p>
]]></description><link>https://forum.mango-os.com/post/26668</link><guid isPermaLink="true">https://forum.mango-os.com/post/26668</guid><dc:creator><![CDATA[MattFox]]></dc:creator><pubDate>Fri, 28 May 2021 06:14:54 GMT</pubDate></item><item><title><![CDATA[Reply to Percent Used Bar Chart on Thu, 27 May 2021 10:52:18 GMT]]></title><description><![CDATA[<p dir="auto">Hi Matt,</p>
<p dir="auto">Thank you for your follow up.  I don't understand which initial suggestion you are referring to, but I have further explored with the idea of using a meta data point for occupiedTime in sec.</p>
<p dir="auto">The following is the script for the meta data point and it is executed when the occupancy binary (0) is updated (update context checked).</p>
<pre><code>// return o.past(HOUR, 1).get(true).runtime / (60*1000)

curState = o.value;
lastState = o.lastValue(false).value;

if(curState == false) { //falling edge only
    if(lastState != false) {
        duration = (o.time - o.lastValue(false).time) / 1000;
        LOG.info(o.time);
        LOG.info(o.lastValue(false).time);
        return duration;
}
</code></pre>
<p dir="auto">However, this implementation has a glitch that it generates "zero" when occupancy data points goes from "false" to "true" (e.g. rising edge).</p>
<p dir="auto">With this occupiedTime meta data point, I can now generate bar charts showing the total occupied time by hour and possible manipulating the pointValues to generate a new series in percent. Next I will have to figure out how to do histogram (binning) the different occupied time.</p>
<p dir="auto">BR,<br />
Ricardo</p>
]]></description><link>https://forum.mango-os.com/post/26665</link><guid isPermaLink="true">https://forum.mango-os.com/post/26665</guid><dc:creator><![CDATA[ricardo]]></dc:creator><pubDate>Thu, 27 May 2021 10:52:18 GMT</pubDate></item><item><title><![CDATA[Reply to Percent Used Bar Chart on Mon, 24 May 2021 20:25:23 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/ricardo" aria-label="Profile: ricardo">@<bdi>ricardo</bdi></a> said in <a href="/post/26653">Percent Used Bar Chart</a>:</p>
<blockquote>
<p dir="auto">Would you suggest to change the meta data point from update hourly interval to possibly update by context update?</p>
</blockquote>
<p dir="auto">No because that means your code would fire and look at the previous hour every time an update came in.</p>
<blockquote>
<p dir="auto">However, the client would like to do further analytics by binning the occupied time into 3 groups: &lt;1 min, &lt;10min and &gt;10min.</p>
</blockquote>
<p dir="auto">Then I advise you look at my initial suggestion as I figured this would happen. You need this to work as occupied events, not just overall statistics. These events can then be evaluated and set a value on a datapoint that represents each timeframe. I'd advise a scripting datasource in this instance as each datapoint mentioned all relates basck to the same script.</p>
<p dir="auto">Also, please read the docs and give things a go. We're not here to do your job for you.</p>
<pre><code>The StartsAndRuntimeList object is returned by Binary and Multistate points. It contains the following properties:

periodStartTime (integer) the start time used for the calculation
periodEndTime (integer) the end time used for the calculation
--&gt; count (integer) count of the total number of entries  
startValue: the value before or exactly at the period start time
firstValue: the first value in the period
firstTime: (integer) the time of the first value
lastValue: the last value in the period
lastTime: (integer) the time of the last value
data: (array) the list of individual StartAndRuntime objects.
Each StartAndRuntime object has the following properties:

value: (boolean for Binary, integer for Multistate) the point state to which the remaining properties apply 
starts: (integer) the number of times the state was entered over the period
--&gt; runtime: (integer) the amount of time in milliseconds the point was in the state over the period
proportion: (float) the proportion of the period the point was in the state (runtime / real duration)
</code></pre>
<p dir="auto">Fox</p>
]]></description><link>https://forum.mango-os.com/post/26656</link><guid isPermaLink="true">https://forum.mango-os.com/post/26656</guid><dc:creator><![CDATA[MattFox]]></dc:creator><pubDate>Mon, 24 May 2021 20:25:23 GMT</pubDate></item><item><title><![CDATA[Reply to Percent Used Bar Chart on Mon, 24 May 2021 11:26:16 GMT]]></title><description><![CDATA[<p dir="auto">Thanks for the suggestion. I have implemented a “occupiedTime” meta data point for each occupancy sensor per your suggestion but modifying it so that it captures the hourly occupied time in the hour. However, the client would like to do further analytics by binning the occupied time into 3 groups: &lt;1 min, &lt;10min and &gt;10min. Would you suggest to change the meta data point from update hourly interval to possibly update by context update?</p>
<p dir="auto">Also any suggestions on how to create a pie chart to present the distribution of the three binned groups?</p>
<p dir="auto">BR,<br />
Ricardo</p>
]]></description><link>https://forum.mango-os.com/post/26653</link><guid isPermaLink="true">https://forum.mango-os.com/post/26653</guid><dc:creator><![CDATA[ricardo]]></dc:creator><pubDate>Mon, 24 May 2021 11:26:16 GMT</pubDate></item><item><title><![CDATA[Reply to Percent Used Bar Chart on Sat, 22 May 2021 17:34:25 GMT]]></title><description><![CDATA[<p dir="auto">A person who never made a mistake never tried anything new. - A.Einstein</p>
<p dir="auto">Edit and thank you Fox!</p>
]]></description><link>https://forum.mango-os.com/post/26651</link><guid isPermaLink="true">https://forum.mango-os.com/post/26651</guid><dc:creator><![CDATA[Ralf]]></dc:creator><pubDate>Sat, 22 May 2021 17:34:25 GMT</pubDate></item><item><title><![CDATA[Reply to Percent Used Bar Chart on Sat, 22 May 2021 09:45:46 GMT]]></title><description><![CDATA[<p dir="auto">Thanks Ralf, by the looks of your answer, you'd use percentage, not proportion as per the docs. That or just multiply your answer by 100</p>
<p dir="auto">Fox</p>
]]></description><link>https://forum.mango-os.com/post/26650</link><guid isPermaLink="true">https://forum.mango-os.com/post/26650</guid><dc:creator><![CDATA[MattFox]]></dc:creator><pubDate>Sat, 22 May 2021 09:45:46 GMT</pubDate></item><item><title><![CDATA[Reply to Percent Used Bar Chart on Sat, 22 May 2021 17:03:10 GMT]]></title><description><![CDATA[<p dir="auto">Like Fox I would use a meta data point, run it every hour. Try this code:</p>
<pre><code>return b.past(HOUR, 1).get(true).percentage;
</code></pre>
<p dir="auto">Check the docs:</p>
<p dir="auto"><a href="http://docs-v4.mango-os.com/about-mango-java-script" rel="nofollow ugc">http://docs-v4.mango-os.com/about-mango-java-script</a></p>
]]></description><link>https://forum.mango-os.com/post/26649</link><guid isPermaLink="true">https://forum.mango-os.com/post/26649</guid><dc:creator><![CDATA[Ralf]]></dc:creator><pubDate>Sat, 22 May 2021 17:03:10 GMT</pubDate></item><item><title><![CDATA[Reply to Percent Used Bar Chart on Sat, 22 May 2021 01:06:34 GMT]]></title><description><![CDATA[<p dir="auto">I can see two ways of doing this, maybe three but am not sure how well maStatistics will work for you.</p>
<ol>
<li>
<p dir="auto">use a meta point to have start (0) and stop (finished time in minutes) then sum the results up into an hourly period with another meta point to derive hourly percentages.</p>
</li>
<li>
<p dir="auto">do the above with a dedicated component to the same thing with a single pull of all values in a given time frame and calculate it all in one go.</p>
</li>
<li>
<p dir="auto">possibly use ma statistics to derive mean and average values/times. I do not use this directive as it has no application for me at this time and is a bit resource intensive.</p>
</li>
</ol>
<p dir="auto">Good luck</p>
<p dir="auto">Fox</p>
]]></description><link>https://forum.mango-os.com/post/26648</link><guid isPermaLink="true">https://forum.mango-os.com/post/26648</guid><dc:creator><![CDATA[MattFox]]></dc:creator><pubDate>Sat, 22 May 2021 01:06:34 GMT</pubDate></item></channel></rss>