calcNumericPercentile.xts 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3. Licensed Materials - Property of IBM
  4. BI and PM: qs
  5. (C) Copyright IBM Corp. 2001, 2017
  6. US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  7. -->
  8. <!--
  9. Copyright (C) 2008 Cognos ULC, an IBM Company. All rights reserved.
  10. Cognos (R) is a trademark of Cognos ULC, (formerly Cognos Incorporated).
  11. -->
  12. <!--
  13. Used for percentile, quantile, quartile
  14. -->
  15. <xts:morphlet resolverBase="prompting" version="1.0" xmlns:xts="http://developer.cognos.com/schemas/xts/" messageBase="messages/QSRVUITextPL.xml,messages/portal.xml,messages/portalRL.xml" requiredCapability="canUseQueryStudio">
  16. <xts:block id="browserDetection" path="qs/browserDetection.xslt" mode="interpret" type="exec" processor="XSLT" contentId="browserDetection" partId="1"/>
  17. <xts:block id="page" type="exec" mode="output" processor="XSLT" mimeType="text/html" dependency="browserDetection">
  18. <!-- get the debug logic sheet -->
  19. <xts:logicsheet path="logicsheets/debuglogic.xslt"/>
  20. <!-- get the new theme stuff -->
  21. <!-- apply the following logicsheets in order -->
  22. <xts:logicsheet path="qs/logicsheets/calc_theme.xsl"/>
  23. <xts:logicsheet path="logicsheets/portal.xsl"/>
  24. <xts:logicsheet path="qs/logicsheets/dialogs.xsl"/>
  25. <xts:logicsheet path="logicsheets/presentation/dialog/framework.xsl"/>
  26. <xts:logicsheet path="logicsheets/presentation/layout.xsl"/>
  27. <xts:logicsheet path="logicsheets/presentation/dialog/presentation.xsl"/>
  28. <xts:logicsheet path="logicsheets/presentation/controls/framework.xsl"/>
  29. <xts:logicsheet path="logicsheets/presentation/controls/presentation.xsl"/>
  30. <xts:logicsheet path="logicsheets/cm-logic.xsl"/>
  31. <!-- apply the form logic -->
  32. <xts:logicsheet path="logicsheets/formlogic.xslt"/>
  33. <xsl:stylesheet version="1.0"
  34. xmlns:clcdlg="test_calculationDlg"
  35. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  36. xmlns:xts="http://developer.cognos.com/schemas/xts/"
  37. xmlns:lyt="http://developer.cognos.com/schemas/xts/logicsheets/xslt/presentation/layout/"
  38. xmlns:pf="http://developer.cognos.com/schemas/xts/pf"
  39. xmlns:dp="http://developer.cognos.com/schemas/xts/logicsheets/xslt/presentation/dialog/presentation/"
  40. xmlns:df="http://developer.cognos.com/schemas/xts/logicsheets/xslt/presentation/dialog/framework/"
  41. xmlns:cp="http://developer.cognos.com/schemas/xts/logicsheets/xslt/presentation/controls/presentation/"
  42. xmlns:cf="http://developer.cognos.com/schemas/xts/logicsheets/xslt/presentation/controls/framework/"
  43. xmlns:dbg="http://developer.cognos.com/schemas/xts/logicsheets/xslt/debug/"
  44. xmlns:qsdlg="http://developer.cognos.com/schemas/xts/logicsheets/xslt/qs/dialog/"
  45. xmlns:xtsext="xalan://com.cognos.xts.ext.XTSExt"
  46. exclude-result-prefixes="clcdlg xsl xts lyt pf dp df cp cf dbg qsdlg xtsext">
  47. <xsl:output method="html" version="1.0" encoding="UTF-8" indent="no"/>
  48. <!-- Default variables (like skin) and prompt variables -->
  49. <qsdlg:variables/>
  50. <qsdlg:promptVariables/>
  51. <!-- Prompt Control XSL include -->
  52. <xsl:include href="p_include.xsl"/>
  53. <!-- add any theme variables -->
  54. <df:variables/>
  55. <pf:variables/>
  56. <!-- start the output -->
  57. <xsl:template match="/root">
  58. <dp:page>
  59. <dp:script>
  60. <xsl:call-template name="getPromptCommonIncludes"/>
  61. <xsl:call-template name="gettextBoxIncludes">
  62. <xsl:with-param name="promptLocale" select="$promptLocale"/>
  63. <xsl:with-param name="promptContentLocale" select="$contentLocale"/>
  64. </xsl:call-template>
  65. <script type="text/javascript">
  66. <xsl:attribute name="src"><xsl:value-of select="$webRoot"/>/qs/layout.js</xsl:attribute>
  67. <xsl:text/>//<xsl:text/>
  68. </script>
  69. <script type="text/javascript">
  70. <xsl:attribute name="src"><xsl:value-of select="$webRoot"/>/qs/classes/CDialogManager.js</xsl:attribute>
  71. <xsl:text/>//<xsl:text/>
  72. </script>
  73. <script type="text/javascript">
  74. <xsl:attribute name="src"><xsl:value-of select="$webRoot"/>/qs/classes/CWindowManager.js</xsl:attribute>
  75. <xsl:text/>//<xsl:text/>
  76. </script>
  77. <script type="text/javascript">&lt;!--
  78. var goDialogManager = new CDialogManager();
  79. <clcdlg:jvs/>
  80. var expression = new Array();
  81. var regularAggs = new Array();
  82. var calculatedExpression = new Array();
  83. var cf = getConfigFrame();
  84. var calcType = cf.dlgGlobalGetParm('xxCalcType');
  85. var calcParentIds = new Array();
  86. var calcParentLabels = new Array();
  87. var groupsInfoValid = true;
  88. function execute()
  89. {
  90. var oMQMgr = goDialogManager.getMiniQueryManager();
  91. var before_col_id = cf.dlgGlobalGetParm('xxInsBeforeColid');
  92. var calcOp = document.f.calcList.options[document.f.calcList.selectedIndex].value; // Percentile, Quartile, or Quantile
  93. var calcBy = "report";
  94. var calcExpr = "generated";
  95. var calcBase = expression[document.f.repSel.options.selectedIndex];
  96. var quantVal = 1;
  97. var cType = -1;
  98. var cUsage = -1;
  99. var detailAgg = -1;
  100. var regularAgg = -1;
  101. var listSeparator = goDialogManager.getMiniQueryManager().getListSeparator();
  102. if (calcOp == "quantile")
  103. {
  104. if ((typeof textBoxquantileValue != "undefined")&amp;&amp;(textBoxquantileValue.isValid())&amp;&amp;(textBoxquantileValue.sGetValue() > 0))
  105. quantVal = textBoxquantileValue.sGetValue();
  106. else
  107. return;
  108. calcBase += listSeparator + " " + quantVal;
  109. }
  110. if (cf.dlgGlobalGetParm('xxGroupedColInfo') != null &amp;&amp; document.f.basedOn[1].checked &amp;&amp; groupsInfoValid)
  111. {
  112. calcBy = document.f.repGroups.options[document.f.repGroups.options.selectedIndex].value;
  113. }
  114. if (calcOp == "percentile")
  115. calcExpr = "percentile(^^^0^^^ for " + calcBy + " prefilter)";
  116. else if (calcOp == "quartile")
  117. calcExpr = "quartile(^^^0^^^ for " + calcBy + " prefilter)";
  118. else
  119. {
  120. var quantVal = 1;
  121. if ((typeof textBoxquantileValue != "undefined")&amp;&amp;(textBoxquantileValue.isValid())&amp;&amp;(textBoxquantileValue.sGetValue() > 0))
  122. quantVal = textBoxquantileValue.sGetValue();
  123. else
  124. return;
  125. calcExpr = "quantile(^^^0^^^" + listSeparator + " " + quantVal + " for " + calcBy + " prefilter)";
  126. }
  127. var calculationExpression = calcExpr;
  128. var summarizationExpression = calcExpr;
  129. calculationExpression = stringReplace (calculationExpression, "\\^\\^\\^" + 0 + "\\^\\^\\^", expression[document.f.repSel.options.selectedIndex]);
  130. summarizationExpression = stringReplace (summarizationExpression, "\\^\\^\\^" + 0 + "\\^\\^\\^", calculatedExpression[document.f.repSel.options.selectedIndex]);
  131. if(calcBy != "report")
  132. summarizationExpression = calculatedExpression[document.f.repSel.options.selectedIndex] + ", " + quantVal;
  133. // alert(calculationExpression + "\n--\n" + summarizationExpression);
  134. var calcName = getCalcName();
  135. var queryId = -1;
  136. for (var i = 0; i &lt; calcParentLabels.length; i++)
  137. {
  138. if (calcParentLabels[i] == document.f.repSel.options[document.f.repSel.options.selectedIndex].text)
  139. {
  140. queryId = i;
  141. break;
  142. }
  143. }
  144. if (queryId &lt; 0)
  145. return;
  146. //TODO - CLEANUP can the following code be replaced by below?
  147. //queryId = oMQMgr.isMeasure(calcParentIds[queryId]);
  148. for (var j = 0; j &lt; oMQMgr.getAllColumns().length; j++)
  149. {
  150. if (calcParentIds[queryId] == oMQMgr.getColumnId(j))
  151. {
  152. queryId = oMQMgr.isMeasure(j);
  153. break;
  154. }
  155. }
  156. if (queryId &lt; 0)
  157. return;
  158. else if (queryId == false)
  159. {
  160. cType = 21;
  161. cUsage = 2;
  162. detailAgg = "none";
  163. regularAgg = "none";
  164. }
  165. getConfigFrame().addCalcColumn(before_col_id, calculationExpression, summarizationExpression, calcName, calcBy, calcOp, calcBase, -1, cType, cUsage, regularAgg, -1, detailAgg);
  166. }
  167. function generateName(withQuotes)
  168. {
  169. var calcName = document.f.calcList.options[document.f.calcList.selectedIndex].value; // Percentile, Quartile, or Quantile
  170. var percentileColumn = document.f.repSel.options[document.f.repSel.options.selectedIndex].text;
  171. if (withQuotes &amp;&amp; document.f.basedOn &amp;&amp; document.f.basedOn[1].checked &amp;&amp; groupsInfoValid)
  172. {
  173. if (calcName == "percentile")
  174. calcName = "<xts:string id="CALCULATION_PERCENTILE_GROUP_EQUATION" encode="javascript"/>";
  175. else if (calcName == "quartile")
  176. calcName = "<xts:string id="CALCULATION_QUARTILE_GROUP_EQUATION" encode="javascript"/>";
  177. else
  178. {
  179. calcName = "<xts:string id="CALCULATION_QUANTILE_GROUP_EQUATION" encode="javascript"/>";
  180. var quantVal = 1;
  181. if ((typeof textBoxquantileValue != "undefined")&amp;&amp;(textBoxquantileValue.isValid())&amp;&amp;(textBoxquantileValue.sGetValue() > 0))
  182. quantVal = textBoxquantileValue.sGetFormatValue();
  183. else if ((typeof textBoxquantileValue != "undefined")&amp;&amp;(textBoxquantileValue.m_oForm.value > 0))
  184. quantVal = textBoxquantileValue.m_oForm.value;
  185. calcName = stringReplace (calcName, "\\^2", quantVal);
  186. }
  187. calcName = stringReplace (calcName, "\\^1", document.f.repGroups.options[document.f.repGroups.options.selectedIndex].text);
  188. }
  189. else
  190. {
  191. if (calcName == "percentile")
  192. calcName = "<xts:string id="CALCULATION_PERCENTILE_EQUATION" encode="javascript"/>";
  193. else if (calcName == "quartile")
  194. calcName = "<xts:string id="CALCULATION_QUARTILE_EQUATION" encode="javascript"/>";
  195. else
  196. {
  197. calcName = "<xts:string id="CALCULATION_QUANTILE_EQUATION" encode="javascript"/>";
  198. var quantVal = 1;
  199. if ((typeof textBoxquantileValue != "undefined")&amp;&amp;(textBoxquantileValue.isValid())&amp;&amp;(textBoxquantileValue.sGetValue() > 0))
  200. quantVal = textBoxquantileValue.sGetFormatValue();
  201. else if ((typeof textBoxquantileValue != "undefined")&amp;&amp;(textBoxquantileValue.m_oForm.value))
  202. quantVal = textBoxquantileValue.m_oForm.value;
  203. calcName = stringReplace (calcName, "\\^1", quantVal);
  204. }
  205. }
  206. calcName = stringReplace (calcName, "\\^0", percentileColumn);
  207. return calcName;
  208. }
  209. function init()
  210. {
  211. attachMouseEvents();
  212. for (var i = 0; i &lt; cf.dlgGlobalSize('xxCalcParentIds'); i++)
  213. {
  214. var label = cf.dlgGlobalGetParmAt('xxCalcParentIds', i);
  215. calcParentIds[i] = label[0];
  216. calcParentLabels[i] = label[1];
  217. }
  218. for (var i = 0; i &lt; cf.dlgGlobalSize('xxColInfo'); i++)
  219. {
  220. var colInfo = cf.dlgGlobalGetParmAt('xxColInfo', i);
  221. expression[i] = colInfo[1];
  222. calculatedExpression[i] = colInfo[1];
  223. document.f.repSel.options[document.f.repSel.options.length] = new Option(colInfo[0], i);
  224. }
  225. for (var i = 0; i &lt; cf.dlgGlobalSize('xxAggs'); i++)
  226. {
  227. var aggs = cf.dlgGlobalGetParmAt('xxAggs', i);
  228. regularAggs[i] = aggs[1];
  229. }
  230. if (cf.dlgGlobalGetParm('xxGroupedColInfo') != null)
  231. {
  232. // populate list of grouped columns menu
  233. for (var i = 0; i &lt; cf.dlgGlobalSize('xxGroupedColInfo'); i++)
  234. {
  235. var label = cf.dlgGlobalGetParmAt('xxGroupedColInfo', i);
  236. document.f.repGroups.options[document.f.repGroups.options.length] = new Option(label[0], label[1]);
  237. }
  238. document.getElementById("displayBasedOn").style.display = "inline";
  239. }
  240. var validCalcs = new Array();
  241. for (var i = 0; i &lt; cf.dlgGlobalSize('xxValidCalcItem'); i++)
  242. validCalcs[validCalcs.length] = cf.dlgGlobalGetParmAt('xxValidCalcItem', i);
  243. populateCalculationList(calcType, validCalcs, "analytic");
  244. // select calculation
  245. document.f.calcList.selectedIndex = cf.dlgGlobalGetParm('xxCalcTypeIdx');
  246. document.f.calcNumberList.selectedIndex = cf.dlgGlobalGetParm('xxCalcSubTypeIdx');
  247. if (cf.dlgGlobalGetParm('xxGroupedColInfo') != null)
  248. {
  249. document.f.basedOn[0].checked = true;
  250. document.f.repGroups.disabled = true;
  251. }
  252. getConfigFrame().cfgSet("CALCULATION_REFRESH", true);
  253. updateRepItemSelection();
  254. loadHint();
  255. setGlobals(calcType, false);
  256. addInsert();
  257. if (typeof textBoxquantileValue != "undefined")
  258. {
  259. <xsl:choose>
  260. <xsl:when test="/root/browserInfo/isNS6='true'">
  261. textBoxquantileValue.m_oForm.addEventListener("keydown", redrawHint, true);
  262. </xsl:when>
  263. <xsl:otherwise>
  264. textBoxquantileValue.m_oForm.attachEvent("onkeydown", redrawHint);
  265. </xsl:otherwise>
  266. </xsl:choose>
  267. textBoxquantileValue.m_oForm.focus();
  268. }
  269. }
  270. function redrawHint()
  271. {
  272. setTimeout(loadHint, 10);
  273. }
  274. function toggleRepGroupsState()
  275. {
  276. if (document.f.basedOn[0].checked)
  277. document.f.repGroups.disabled = true;
  278. else
  279. document.f.repGroups.disabled = false;
  280. }
  281. function updateRepItemSelection()
  282. {
  283. if (cf.dlgGlobalGetParm('xxGroupedColInfo') == null)
  284. {
  285. document.getElementById("displayBasedOn").style.display = "none";
  286. groupsInfoValid = false;
  287. }
  288. else
  289. {
  290. document.getElementById("displayBasedOn").style.display = "inline";
  291. groupsInfoValid = true;
  292. }
  293. loadHint();
  294. }
  295. //--&gt;</script>
  296. </dp:script>
  297. <form style="margin:0px" name="f" method="POST" onsubmit="execute();return false;">
  298. <table border="0" cellspacing="0" cellpadding="0" height="100%" width="100%">
  299. <tr>
  300. <td width="100%" height="0%">
  301. <!-- dialog header -->
  302. <clcdlg:basic_header/>
  303. </td>
  304. </tr>
  305. <tr>
  306. <td width="100%" height="100%" valign="top">
  307. <lyt:layout style="2" border="no">
  308. <lyt:section>
  309. <clcdlg:calculationsType/>
  310. <clcdlg:calculations/>
  311. <dp:input>
  312. <dp:section1>
  313. <xts:string id="CALCULATION_REP_ITEM"/>
  314. </dp:section1>
  315. <dp:section2>
  316. <select name="repSel" size="1" style="width:260" onChange="javascript:updateRepItemSelection();"/>
  317. </dp:section2>
  318. </dp:input>
  319. <xsl:if test="/root/env/param[@name='xxDialogType'] = 'CALCULATION_QUANTILE'">
  320. <dp:input>
  321. <dp:section1>
  322. <xts:string id="CALCULATION_QUANTILE_NUMBER"/>
  323. </dp:section1>
  324. <dp:section2>
  325. <xsl:call-template name="getTextBox">
  326. <xsl:with-param name="promptLocale" select="$promptLocale"/>
  327. <xsl:with-param name="promptFormName" select="$promptFormName"/>
  328. <xsl:with-param name="promptRequired" select="'false'"/>
  329. <xsl:with-param name="promptId" select="'quantileValue'"/>
  330. <xsl:with-param name="promptHideText" select="'false'"/>
  331. <xsl:with-param name="promptMultiLine" select="'false'"/>
  332. <xsl:with-param name="promptParameter" select="'quantileParam'"/>
  333. <xsl:with-param name="promptDataType" select="'whole'"/>
  334. <xsl:with-param name="promptMaxLength" select="'15'"/>
  335. </xsl:call-template>
  336. </dp:section2>
  337. </dp:input>
  338. </xsl:if>
  339. <div id="displayBasedOn" style="display:none">
  340. <dp:choice title="CALCULATION_BASED_ON_LABEL">
  341. <dp:section1>
  342. <input type="radio" name="basedOn" onClick="javascript:loadHint();toggleRepGroupsState();"/>
  343. </dp:section1>
  344. <dp:section2>
  345. <xts:string id="CALCULATION_ALLVALUES"/>
  346. </dp:section2>
  347. <dp:section1>
  348. <input type="radio" name="basedOn" onClick="javascript:loadHint();toggleRepGroupsState();"/>
  349. </dp:section1>
  350. <dp:section2>
  351. <xts:string id="CALCULATION_GROUP"/>
  352. </dp:section2>
  353. <dp:section3>
  354. <select name="repGroups" size="1" style="width:260" onChange="javascript:loadHint();"/>
  355. </dp:section3>
  356. </dp:choice>
  357. </div>
  358. </lyt:section>
  359. <lyt:section>
  360. <clcdlg:calc_hint/>
  361. </lyt:section>
  362. </lyt:layout>
  363. </td>
  364. </tr>
  365. <tr>
  366. <td width="100%" height="0%">
  367. <!-- Use default buttons [ OK = execute() and CANCEL = hideDialogFrame() ] -->
  368. <clcdlg:buttons/>
  369. </td>
  370. </tr>
  371. <!-- <dbg:dumpxml select="/"/> -->
  372. </table>
  373. </form>
  374. </dp:page>
  375. </xsl:template>
  376. </xsl:stylesheet>
  377. </xts:block>
  378. </xts:morphlet>