{"id":62032,"date":"2023-12-19T03:01:33","date_gmt":"2023-12-18T17:01:33","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/ITblog\/?p=62032"},"modified":"2023-12-19T14:53:38","modified_gmt":"2023-12-19T04:53:38","slug":"powerball-number-pick-xml-genericization-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/powerball-number-pick-xml-genericization-tutorial\/","title":{"rendered":"Powerball Number Pick XML Genericization Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/histogram_pie.html\"><img decoding=\"async\" style=\"border: 15px solid pink;\" alt=\"Powerball Number Pick XML Genericization Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/histogram_pie_form.jpg\" title=\"Powerball Number Pick XML Genericization Tutorial\"  style=\"float:left;\"  \/><\/a><p class=\"wp-caption-text\">Powerball Number Pick XML Genericization Tutorial<\/p><\/div>\n<p>There have been many projects where we start with hardcoded wording involved in the webpage, and then to move on, we parameterize (or genericize) those hardcodings via &#8230;<\/p>\n<ul>\n<li>HTML form &#8230; user data collection &#8230;<\/li>\n<li>gathered together via a method=GET form into an &#8220;argument rich&#8221; follow up URL navigation &#8230; calling the same webpage &#8230;<\/li>\n<li>and displaying results according to those user defined HTML form inputs<\/li>\n<\/ul>\n<p>Yesterday&#8217;s <a title='Powerball Number Pick Counts XML Tutorial' href='#pnpcxmlt'>Powerball Number Pick Counts XML Tutorial<\/a> project is no different.  We saw that potential hardcodings were to do with &#8230;<\/p>\n<ul>\n<li>chart title<\/li>\n<li>XML data public URL<\/li>\n<li>XML XPath<\/li>\n<li>data delimiter<\/li>\n<\/ul>\n<p> &#8230; and then we stopped and thought a bit about &#8220;value adding&#8221;.  Was &#8220;Count&#8221; as a &#8220;measure basis&#8221; the only &#8220;measure basis&#8221; of any relevance for the Histograms and Pie Charts?  In the end we continued &#8230;<\/p>\n<ul>\n<li>Count &#8230; as the default &#8220;measure basis&#8221; &#8230; to which we added (all reducing a set of numbers to one representative value in the case of Powerball Winning Numbers, at least) &#8230;<\/li>\n<li>Count of an ordinal position according to the data delimiter and the data itself (doh!)<\/li>\n<li>Mean (if numerical)<\/li>\n<li>Median (if numerical)<\/li>\n<li>Mode (if numerical)<\/li>\n<li>Sum (if numerical)<\/li>\n<li>Range (if numerical)<\/li>\n<li>Standard Deviation (if numerical)<\/li>\n<\/ul>\n<p> &#8230; could all be &#8220;value add&#8221; evaluations a user might find interesting, even just playing around with the Powerball NY US 2010 XML data.<\/p>\n<p><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/diff.php?one=http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/histogram_pie.html-GETME\">See how we got to<\/a> our <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/histogram_pie.html-GETME\">more generic HTML and Javascript histogram_pie.html<\/a> arrangement with <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/histogram_pie.html\">this link<\/a>.<\/p>\n<p><!--p>You can also see this play out at WordPress 4.1.1's <a target=_blank  href='\/\/www.rjmprogramming.com.au\/ITblog\/powerball-number-pick-xml-genericization-tutorial\/'>Powerball Number Pick XML Genericization Tutorial<\/a>.<\/p-->\n<hr>\n<p id='pnpcxmlt'>Previous relevant <a target=_blank title='Powerball Number Pick Counts XML Tutorial' href='\/\/www.rjmprogramming.com.au\/ITblog\/powerball-number-pick-counts-xml-tutorial\/'>Powerball Number Pick Counts XML Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/powerball_us_ny_winning_numbers_since_21010.html\"><img decoding=\"async\" style=\"border: 15px solid pink;\" alt=\"Powerball Number Pick Counts XML Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/powerball_ny.jpg\" title=\"Powerball Number Pick Counts XML Tutorial\"  style=\"float:left;\"  \/><\/a><p class=\"wp-caption-text\">Powerball Number Pick Counts XML Tutorial<\/p><\/div>\n<p>We&#8217;re starting a &#8230;<\/p>\n<ul>\n<li>public data source &#8230; repository based &#8230;<\/li>\n<li><a target=_blank title='XML information from Wikipedia ... thanks' href='https:\/\/en.wikipedia.org\/wiki\/XML'>XML<\/a> &#8230; <a target=_blank title='XML data' href='https:\/\/data.ny.gov\/api\/views\/d6yy-54nr\/rows.xml'>data<\/a> based &#8230;<\/li>\n<li><a target=_blank title='Ajax information from Wikipedia ... thanks' href='https:\/\/en.wikipedia.org\/wiki\/Ajax_(programming)'>Ajax<\/a> &#8230; driven (and thanks to <a target=_blank title='XML data Ajax code' href='https:\/\/www.w3schools.com\/xml\/xpath_examples.asp'>W3Schools<\/a> here, for the XML XPath basis in code) &#8230;<\/li>\n<li>clientside web application &#8230; outputting, in this first draft (which is very &#8220;bare bones&#8221;), as outputs &#8230;<\/li>\n<li><a title=\"Google Chart Tools provide a perfect way to visualize data on your website. From simple line charts to complex hierarchical tree maps, the chart galley provides a large number of well-designed chart types. Populating your data is easy using the provided client- and server-side tools.\" href=\"https:\/\/developers.google.com\/chart\/interactive\/docs\/index\" target=\"_blank\">Google Charts<\/a> &#8230;\n<ol>\n<li><a target=_blank href='https:\/\/developers.google.com\/chart\/interactive\/docs\/gallery\/histogram' title='Google Histogram Charts'>Histogram Chart<\/a><\/li>\n<li><a target=_blank href='https:\/\/developers.google.com\/chart\/interactive\/docs\/gallery\/piechart' title='Google Pie Charts'>Pie Chart<\/a><\/li>\n<\/ol>\n<\/li>\n<\/ul>\n<p> &#8230; new <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/powerball_us_ny_winning_numbers_since_21010.html_GETME\">powerball_us_ny_winning_numbers_since_21010.html<\/a> <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/powerball_us_ny_winning_numbers_since_21010.html\">web application<\/a> project today.  Why those two charts?  Well, they give different views of built up data pairings, involving two data members, one &#8220;subject item&#8221; (which today, happens to be numerical, but does not have to be) and the other numerical data item having a relationship with that &#8220;subject item&#8221; as a measure, in today&#8217;s case that being a count of &#8230;<\/p>\n<p><code><br \/>\nNew York State, US Powerball Number Pick Counts since 2010<br \/>\n<\/code><\/p>\n<p>Yes, you can glean many things from the public online data resources out there, today&#8217;s one for us coming from the US Governmental <a target=_blank title='data.gov XML data for Powerball draw in NY US' href='https:\/\/catalog.data.gov\/dataset?q=&#038;sort=views_recent+desc'>data.gov<\/a> &#8230; thanks all around.<\/p>\n<p>In the code, what is the crucial single codeline, at least for us?  <font color=blue>It&#8217;s<\/font> &#8230;<\/p>\n<table>\n<tr>\n<td>\n<details>\n<summary><\/summary>\n<p><code><br \/>\n<font size=1>var datasofar='', nums=[], ij=0, jk=0;<br \/>\nvar xhttp = new XMLHttpRequest();<br \/>\nxhttp.onreadystatechange = function() {<br \/>\n    if (this.readyState == 4 && this.status == 200) {<br \/>\n        showResult(xhttp.responseXML);<br \/>\n    }<br \/>\n};<br \/>\nxhttp.open(\"GET\", \"\/\/data.ny.gov\/api\/views\/d6yy-54nr\/rows.xml\", true);<br \/>\nxhttp.send();<br \/>\n<br \/>\nfunction showResult(xml) {<br \/>\n    var txt = \"\";<\/font><br \/>\n<\/code><br \/>\n<\/details>\n<p><code><br \/>\n    <font color=blue>path = \"\/<\/font><font color=magenta>response<\/font>\/<font color=silver>row<\/font>\/<font color=purple>row<\/font>\/<font color=brown>winning_numbers<\/font><font color=blue>\"<\/font><br \/>\n<\/code><\/p>\n<details>\n<summary><\/summary>\n<p><code><br \/>\n    <font size=1>if (xml.evaluate) {<br \/>\n        var nodes = xml.evaluate(path, xml, null, XPathResult.ANY_TYPE, null);<br \/>\n        var result = nodes.iterateNext();<br \/>\n        while (result) {<br \/>\n            txt += result.childNodes[0].nodeValue + \"&lt;br&gt;\";<br \/>\n    nums=('' + result.childNodes[0].nodeValue).split(' ');<br \/>\n    for (ii=0; ii&lt;nums.length; ii++) {<br \/>\n      if (datasofar.indexOf(',[~' + nums[ii] + '~,') == -1) {<br \/>\n       datasofar+=',[~' + nums[ii] + '~,1]';<br \/>\n      } else {<br \/>\n       jk=eval(datasofar.split(',[~' + nums[ii] + '~,')[1].split(']')[0]);<br \/>\n       datasofar=datasofar.replace(',[~' + nums[ii] + '~,' + jk + ']', ',[~' + nums[ii] + '~,' + eval(1 + jk) + ']');<br \/>\n      }<br \/>\n    }<br \/>\n            result = nodes.iterateNext();<br \/>\n        }<br \/>\n    \/\/ Code For Internet Explorer<br \/>\n    } else if (window.ActiveXObject || xhttp.responseType == \"msxml-document\") {<br \/>\n        xml.setProperty(\"SelectionLanguage\", \"XPath\");<br \/>\n        nodes = xml.selectNodes(path);<br \/>\n        for (i = 0; i &lt; nodes.length; i++) {<br \/>\n            txt += nodes[i].childNodes[0].nodeValue + \"&lt;br&gt;\";<br \/>\n    nums=('' + nodes[i].childNodes[0].nodeValue).split(' ');<br \/>\n    for (ii=0; ii&lt;nums.length; ii++) {<br \/>\n      if (datasofar.indexOf(',[~' + nums[ii] + '~,') == -1) {<br \/>\n       datasofar+=',[~' + nums[ii] + '~,1]';<br \/>\n      } else {<br \/>\n       jk=eval(datasofar.split(',[~' + nums[ii] + '~,')[1].split(']')[0]);<br \/>\n       datasofar=datasofar.replace(',[~' + nums[ii] + '~,' + jk + ']', ',[~' + nums[ii] + '~,' + eval(1 + jk) + ']');<br \/>\n      }<br \/>\n    }<br \/>\n        }<br \/>\n    }<br \/>\n    \/\/document.getElementById(\"demo\").innerHTML = txt;<br \/>\n    var proposed=document.getElementById('myi').src.split('&data=')[0] + '&data=' + datasofar;<br \/>\n    if (eval('' + proposed.length) &lt; 850) {<br \/>\n    document.getElementById('myi').src=document.getElementById('myi').src.split('&data=')[0] + '&data=' + datasofar;<br \/>\n    document.getElementById('mpi').src=document.getElementById('mpi').src.split('&data=')[0] + '&data=' + datasofar.replace(\/\\]\\,\\[\/g, ']%20,%20[').replace(',[', ',%20[');<br \/>\n    } else {<br \/>\n    document.getElementById('data').value=datasofar;<br \/>\n    document.getElementById('mybut').click();<br \/>\n    document.getElementById('datap').value=datasofar.replace(\/\\]\\,\\[\/g, '] , [').replace(',[', ', ['); \/\/ ,%20[~45~,23]%20,%20[~<br \/>\n    document.getElementById('mybutp').click();<br \/>\n    }<br \/>\n    document.getElementById('myi').style.display='block';<br \/>\n    document.getElementById('mpi').style.display='block';<br \/>\n}<\/font><br \/>\n<\/code><br \/>\n<\/details>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<code><br \/>\n<font color=magenta>&lt;response&gt;<\/font><br \/>\n<font color=silver>&lt;row&gt;<\/font><br \/>\n<font color=purple>&lt;row _id=\"row-nx2r_usun.g52b\" _uuid=\"00000000-0000-0000-9D99-B9EA775FDC5E\" _position=\"0\" _address=\"https:\/\/data.ny.gov\/resource\/d6yy-54nr\/row-nx2r_usun.g52b\"&gt;<\/font><br \/>\n&lt;draw_date&gt;2020-09-26T00:00:00&lt;\/draw_date&gt;<br \/>\n<font color=brown>&lt;winning_numbers&gt;11 21 27 36 62 24&lt;\/winning_numbers&gt;<\/font><br \/>\n&lt;multiplier&gt;3&lt;\/multiplier&gt;<br \/>\n&lt;\/row&gt;<br \/>\n<font color=purple>&lt;row _id=\"row-e8ru_54jr.pm4v\" _uuid=\"00000000-0000-0000-43B5-52ACB7706E11\" _position=\"0\" _address=\"https:\/\/data.ny.gov\/resource\/d6yy-54nr\/row-e8ru_54jr.pm4v\"&gt;<\/font><br \/>\n&lt;draw_date&gt;2020-09-30T00:00:00&lt;\/draw_date&gt;<br \/>\n<font color=brown>&lt;winning_numbers&gt;14 18 36 49 67 18&lt;\/winning_numbers&gt;<\/font><br \/>\n&lt;multiplier&gt;2&lt;\/multiplier&gt;<br \/>\n&lt;\/row&gt;<br \/>\n<font color=purple>&lt;row _id=\"row-tq8m.jys2~s8vu\" _uuid=\"00000000-0000-0000-A5B2-0AAE86635EA3\" _position=\"0\" _address=\"https:\/\/data.ny.gov\/resource\/d6yy-54nr\/row-tq8m.jys2~s8vu\"&gt;<\/font><br \/>\n&lt;draw_date&gt;2020-10-03T00:00:00&lt;\/draw_date&gt;<br \/>\n<font color=brown>&lt;winning_numbers&gt;18 31 36 43 47 20&lt;\/winning_numbers&gt;<\/font><br \/>\n&lt;multiplier&gt;2&lt;\/multiplier&gt;<br \/>\n&lt;\/row&gt;<br \/>\n<font color=purple>&lt;row _id=\"row-fyha_3jj2-8cdk\" _uuid=\"00000000-0000-0000-8755-E68E26427D31\" _position=\"0\" _address=\"https:\/\/data.ny.gov\/resource\/d6yy-54nr\/row-fyha_3jj2-8cdk\"&gt;<\/font><br \/>\n&lt;draw_date&gt;2020-10-07T00:00:00&lt;\/draw_date&gt;<br \/>\n<font color=brown>&lt;winning_numbers&gt;06 24 30 53 56 19&lt;\/winning_numbers&gt;<\/font><br \/>\n&lt;multiplier&gt;2&lt;\/multiplier&gt;<br \/>\n&lt;\/row&gt;<br \/>\n<font color=purple>&lt;row _id=\"row-t7k7-dhjv-h47w\" _uuid=\"00000000-0000-0000-EF27-CF03FBB38022\" _position=\"0\" _address=\"https:\/\/data.ny.gov\/resource\/d6yy-54nr\/row-t7k7-dhjv-h47w\"&gt;<\/font><br \/>\n&lt;draw_date&gt;2020-10-10T00:00:00&lt;\/draw_date&gt;<br \/>\n<font color=brown>&lt;winning_numbers&gt;05 18 23 40 50 18&lt;\/winning_numbers&gt;<\/font><br \/>\n&lt;multiplier&gt;3&lt;\/multiplier&gt;<br \/>\n&lt;\/row&gt;<br \/>\n\/\/ many more rows here<br \/>\n\/\/ end of many more rows<br \/>\n&lt;\/row&gt;<br \/>\n&lt;\/response&gt;<br \/>\n<\/code>\n<\/td>\n<\/tr>\n<\/table>\n<p> &#8230; this codeline&#8217;s &#8220;slicing through complexity&#8221; cut through, perfectly suited to the XML data scenario above, presenting those <a title=\"Google Chart Tools provide a perfect way to visualize data on your website. From simple line charts to complex hierarchical tree maps, the chart galley provides a large number of well-designed chart types. Populating your data is easy using the provided client- and server-side tools.\" href=\"https:\/\/developers.google.com\/chart\/interactive\/docs\/index\" target=\"_blank\">Google Chart<\/a> displays, as the end result.<\/p>\n<p><iframe src=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/powerball_us_ny_winning_numbers_since_21010.html\" style=\"width:100%;height:600px;\"><\/iframe><\/p>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d62017' onclick='var dv=document.getElementById(\"d62017\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/xml\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d62017' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d62032' onclick='var dv=document.getElementById(\"d62032\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/count\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d62032' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>There have been many projects where we start with hardcoded wording involved in the webpage, and then to move on, we parameterize (or genericize) those hardcodings via &#8230; HTML form &#8230; user data collection &#8230; gathered together via a method=GET &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/powerball-number-pick-xml-genericization-tutorial\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,37],"tags":[69,1885,1835,4602,2743,4603,290,2146,452,1839,519,3362,565,652,752,4606,4607,3861,830,2394,856,944,4601,989,4199,4604,2141,1055,2821,4609,4608,1345,1480,4605],"class_list":["post-62032","post","type-post","status-publish","format-standard","hentry","category-elearning","category-tutorials","tag-ajax","tag-argument","tag-arguments","tag-chance","tag-count","tag-counts","tag-data","tag-data-gov","tag-form","tag-genericization","tag-google-charts","tag-hardcoding","tag-histogram","tag-javascript","tag-mathematics","tag-mean","tag-median","tag-mode","tag-navigation","tag-number","tag-odds","tag-pie-chart","tag-powerball","tag-probability","tag-public-data","tag-public-data-repository","tag-range","tag-repository","tag-set","tag-standard-deviation","tag-sum","tag-url","tag-xml","tag-xpath"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/62032"}],"collection":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/comments?post=62032"}],"version-history":[{"count":5,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/62032\/revisions"}],"predecessor-version":[{"id":62037,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/62032\/revisions\/62037"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=62032"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=62032"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=62032"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}