All Downloads are FREE. Search and download functionalities are using the official Maven repository.

js.models.charting.stat.Model.js Maven / Gradle / Ivy

define(function(require){
	
	var View = require("text!./View.html"),
		$ = require("jquery"),
		MV = require("mv");
		
	return function(cfg){
		
		this.html = View;
		
		var self = this;
		
		cfg = $.extend({
		}, cfg);
		
		this.stats = MV.observableArray();
		
		this.update = function(plots){
			self.stats.removeAll();
			
			//Create an enhanced object for each plot
			plots.forEach(function(plot){
				
				if (plot.data.length == 0)
					return;
				
				self.stats.push({
					label: plot.label,
					min: plot.data
					.reduce(function(previousValue, currentValue, index, array){
						if (previousValue[1] < currentValue[1])
							return previousValue;
						else
							return currentValue;
					})
					.reduce(function(previousValue, currentValue){
						return {
							value: currentValue,
							time: new Date(previousValue)
						}
					}),
					max: plot.data
					.reduce(function(previousValue, currentValue, index, array){
						if (previousValue[1] > currentValue[1])
							return previousValue;
						else
							return currentValue;
					})
					.reduce(function(previousValue, currentValue){
						return {
							value: currentValue,
							time: new Date(previousValue)
						}
					}),
					average: plot.data
					.map(function(a){ return a[1]; })
					.reduce(function(previousValue, currentValue, index, array){
						return (previousValue + currentValue);
					}) / plot.data.length
				});
				
			});
		};

	};
	
});




© 2015 - 2025 Weber Informatics LLC | Privacy Policy