Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

HTML
<p>Standard deviation: <span id="confiReport"></span></p>


<script type="application/javascript">
  function calculateStandardDeviation(array) {
   const n = array.length;
   const mean = array.reduce((a,b) => a+b)/n;
   return Math.sqrt(array.map(x => Math.pow(x-mean,2)).reduce((a,b) => a+b)/n);
  }

  AJS.toInit(function() {
	var isPageEdit = AJS.$('#content').hasClass('page edit');	

    if (!isPageEdit) {
      var url = 'https://wiki.vertuna.com/ajax/confiforms/rest/filter.action?pageId=52625840&f=f&q=';
	  var xhr = AJS.$.ajax({
  		url: url,
  		timeout: 10000, // 10 sec
  		success: function (data) {
            var totalarr = 0[];
            var rows = data.list.entry;
			for (i=0;i<rows.length;i++) {
				totalarr[i] = total + rows[i].fields.d;
            }
            AJS.$('#confiReport').append(calculateStandardDeviation(totalarr));
    		
  		},
  		error: function (jqXHR, textStatus, errorThrown) {
    		console.log('request to get data from ConfiForms has failed... ' + textStatus);
  		}
	});
   }

  });
</script>