<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Tucker Watson&#187; History</title>
	<atom:link href="http://tuckwat.com/blog/tag/history/feed/" rel="self" type="application/rss+xml" />
	<link>http://tuckwat.com/blog</link>
	<description>Software development - Flex, Niagara AX, oBIX, and more</description>
	<lastBuildDate>Fri, 05 Nov 2010 12:20:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>AX Program Object: Trend Analyzer</title>
		<link>http://tuckwat.com/blog/niagara-ax/ax-program-object-trend-analyzer/</link>
		<comments>http://tuckwat.com/blog/niagara-ax/ax-program-object-trend-analyzer/#comments</comments>
		<pubDate>Fri, 13 Feb 2009 01:00:19 +0000</pubDate>
		<dc:creator>Tucker</dc:creator>
				<category><![CDATA[Niagara]]></category>
		<category><![CDATA[AX]]></category>
		<category><![CDATA[History]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Program Objects]]></category>

		<guid isPermaLink="false">http://tuckwat.com/blog/?p=128</guid>
		<description><![CDATA[I&#8217;ll be posting various AX program objects and modules all fully commented and free to use how you wish.  This program object calculates the min, max, average, sum, and number of records for a selected history and time range.  The code shows how to run a BQL query programmatically and demonstrates a history rollup. The [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ll be posting various AX program objects and modules all fully commented and free to use how you wish.   This program object calculates the min, max, average, sum, and number of records for a selected history and time range.  The code shows how to run a BQL query programmatically and demonstrates a history rollup.</p>
<div id="attachment_131" class="wp-caption aligncenter" style="width: 588px"><img class="size-full wp-image-131" title="Trend Analyzer" src="http://tuckwat.com/blog/wp-content/uploads/2009/02/trendanalyzer.png" alt="Property sheet of Trend Analyzer" width="578" height="204" /><p class="wp-caption-text">Property sheet of Trend Analyzer</p></div>
<p><span id="more-128"></span></p>
<h2>The Code:</h2>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onExecute<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #003399;">String</span> fiftyYearsInMS <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;1577846298735&quot;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// Grab the ORD for the selected history</span>
  <span style="color: #003399;">String</span> hist <span style="color: #339933;">=</span> getHistory<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// Grab the start and end dates, note 'encodeToString()' makes it ORD friendly</span>
  <span style="color: #003399;">String</span> startDate <span style="color: #339933;">=</span> getDateRange<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getStartTime</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">encodeToString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #003399;">String</span> endDate <span style="color: #339933;">=</span> getDateRange<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getEndTime</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">encodeToString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  BOrd bqlOrd <span style="color: #339933;">=</span> BOrd.<span style="color: #006633;">make</span><span style="color: #009900;">&#40;</span>hist <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;?period=timeRange;start=&quot;</span> <span style="color: #339933;">+</span> startDate <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;;end=&quot;</span> <span style="color: #339933;">+</span> endDate
     <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;|bql:historyFunc:HistoryRollup.rollup(select *, baja:RelTime '&quot;</span> <span style="color: #339933;">+</span> fiftyYearsInMS <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;')&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// Run the BQL query</span>
  BITable result <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>BITable<span style="color: #009900;">&#41;</span> bqlOrd.<span style="color: #006633;">resolve</span><span style="color: #009900;">&#40;</span>Sys.<span style="color: #006633;">getStation</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  ColumnList columns <span style="color: #339933;">=</span> result.<span style="color: #006633;">getColumns</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  TableCursor c <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>TableCursor<span style="color: #009900;">&#41;</span> result.<span style="color: #006633;">cursor</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// We should only have one entry in the history since we're querying 50 years</span>
  c.<span style="color: #006633;">next</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">// Move to 1st (and only) record</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// Grab the info from the corresponding rows</span>
  <span style="color: #000066; font-weight: bold;">double</span> count <span style="color: #339933;">=</span> <span style="color: #003399;">Double</span>.<span style="color: #006633;">parseDouble</span><span style="color: #009900;">&#40;</span>c.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>columns.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">double</span> min <span style="color: #339933;">=</span> <span style="color: #003399;">Double</span>.<span style="color: #006633;">parseDouble</span><span style="color: #009900;">&#40;</span>c.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>columns.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">double</span> max <span style="color: #339933;">=</span> <span style="color: #003399;">Double</span>.<span style="color: #006633;">parseDouble</span><span style="color: #009900;">&#40;</span>c.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>columns.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">4</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">double</span> avg <span style="color: #339933;">=</span> <span style="color: #003399;">Double</span>.<span style="color: #006633;">parseDouble</span><span style="color: #009900;">&#40;</span>c.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>columns.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">double</span> sum <span style="color: #339933;">=</span> <span style="color: #003399;">Double</span>.<span style="color: #006633;">parseDouble</span><span style="color: #009900;">&#40;</span>c.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>columns.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">6</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// Set each value</span>
  getCount<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">setValue</span><span style="color: #009900;">&#40;</span>count<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  getMin<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">setValue</span><span style="color: #009900;">&#40;</span>min<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  getMax<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">setValue</span><span style="color: #009900;">&#40;</span>max<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  getAverage<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">setValue</span><span style="color: #009900;">&#40;</span>avg<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  getSum<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">setValue</span><span style="color: #009900;">&#40;</span>sum<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h2>Download:</h2>
<p><img src="http://tuckwat.com/blog/wp-content/uploads/2009/02/script.png" alt="Niagara AX Program Object Icon" title="script" width="16" height="16" class="size-full wp-image-166" /><a href="http://tuckwat.com/blog/wp-content/uploads/2009/02/trendanalyzer.bog"> trendanalyzer.bog</a></p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://tuckwat.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://tuckwat.com/blog/niagara-ax/ax-program-object-trend-analyzer/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
	</channel>
</rss>

