/** * Miso.Dataset - v0.1.3 - 6/14/2012 * http://github.com/misoproject/dataset * Copyright (c) 2012 Alex Graul, Irene Ros; * Dual Licensed: MIT, GPL * https://github.com/misoproject/dataset/blob/master/LICENSE-MIT * https://github.com/misoproject/dataset/blob/master/LICENSE-GPL */ (function(a,b){function z(a,b){this._d=a,this._isUTC=!!b}function A(a){return a<0?Math.ceil(a):Math.floor(a)}function B(a){var b=this._data={},c=a.years||a.y||0,d=a.months||a.M||0,e=a.weeks||a.w||0,f=a.days||a.d||0,g=a.hours||a.h||0,h=a.minutes||a.m||0,i=a.seconds||a.s||0,j=a.milliseconds||a.ms||0;this._milliseconds=j+i*1e3+h*6e4+g*36e5,this._days=f+e*7,this._months=d+c*12,b.milliseconds=j%1e3,i+=A(j/1e3),b.seconds=i%60,h+=A(i/60),b.minutes=h%60,g+=A(h/60),b.hours=g%24,f+=A(g/24),f+=e*7,b.days=f%30,d+=A(f/30),b.months=d%12,c+=A(d/12),b.years=c}function C(a,b){var c=a+"";while(c.length11?"pm":"am";case"A":return o?o(h,i,!0):h>11?"PM":"AM";case"H":return h;case"HH":return C(h,2);case"h":return h%12||12;case"hh":return C(h%12||12,2);case"m":return i;case"mm":return C(i,2);case"s":return j;case"ss":return C(j,2);case"S":return~~(l/100);case"SS":return C(~~(l/10),2);case"SSS":return C(l,3);case"Z":return(m<0?"-":"+")+C(~~(Math.abs(m)/60),2)+":"+C(~~(Math.abs(m)%60),2);case"ZZ":return(m<0?"-":"+")+C(~~(10*Math.abs(m)/6),4);case"L":case"LL":case"LLL":case"LLLL":case"LT":return G(b,moment.longDateFormat[c]);default:return c.replace(/(^\[)|(\\)|\]$/g,"")}}var d=b.month(),e=b.date(),f=b.year(),g=b.day(),h=b.hours(),i=b.minutes(),j=b.seconds(),l=b.milliseconds(),m=-b.zone(),n=moment.ordinal,o=moment.meridiem;return c.replace(k,p)}function H(a){switch(a){case"DDDD":return o;case"YYYY":return p;case"S":case"SS":case"SSS":case"DDD":return n;case"MMM":case"MMMM":case"ddd":case"dddd":case"a":case"A":return q;case"Z":case"ZZ":return r;case"T":return s;case"MM":case"DD":case"dd":case"YY":case"HH":case"hh":case"mm":case"ss":case"M":case"D":case"d":case"H":case"h":case"m":case"s":return m;default:return new RegExp(a.replace("\\",""))}}function I(a,b,c,d){var e;switch(a){case"M":case"MM":c[1]=b==null?0:~~b-1;break;case"MMM":case"MMMM":for(e=0;e<12;e++)if(moment.monthsParse[e].test(b)){c[1]=e;break}break;case"D":case"DD":case"DDD":case"DDDD":c[2]=~~b;break;case"YY":b=~~b,c[0]=b+(b>70?1900:2e3);break;case"YYYY":c[0]=~~Math.abs(b);break;case"a":case"A":d.isPm=(b+"").toLowerCase()==="pm";break;case"H":case"HH":case"h":case"hh":c[3]=~~b;break;case"m":case"mm":c[4]=~~b;break;case"s":case"ss":c[5]=~~b;break;case"S":case"SS":case"SSS":c[6]=~~(("0."+b)*1e3);break;case"Z":case"ZZ":d.isUTC=!0,e=(b+"").match(w),e&&e[1]&&(d.tzh=~~e[1]),e&&e[2]&&(d.tzm=~~e[2]),e&&e[0]==="+"&&(d.tzh=-d.tzh,d.tzm=-d.tzm)}}function J(b,c){var d=[0,0,1,0,0,0,0],e={tzh:0,tzm:0},f=c.match(k),g,h;for(g=0;g0,N.apply({},i)}function P(a,b){moment.fn[a]=function(a){var c=this._isUTC?"UTC":"";return a!=null?(this._d["set"+c+b](a),this):this._d["get"+c+b]()}}function Q(a){moment.duration.fn[a]=function(){return this._data[a]}}function R(a,b){moment.duration.fn["as"+a]=function(){return+this/b}}var moment,c="1.6.2",d=Math.round,e,f={},g="en",h=typeof module!="undefined",i="months|monthsShort|monthsParse|weekdays|weekdaysShort|longDateFormat|calendar|relativeTime|ordinal|meridiem".split("|"),j=/^\/?Date\((\-?\d+)/i,k=/(\[[^\[]*\])|(\\)?(Mo|MM?M?M?|Do|DDDo|DD?D?D?|dddd?|do?|w[o|w]?|YYYY|YY|a|A|hh?|HH?|mm?|ss?|SS?S?|zz?|ZZ?|LT|LL?L?L?)/g,l=/([0-9a-zA-Z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+)/gi,m=/\d\d?/,n=/\d{1,3}/,o=/\d{3}/,p=/\d{4}/,q=/[0-9a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+/i,r=/Z|[\+\-]\d\d:?\d\d/i,s=/T/i,t=/^\s*\d{4}-\d\d-\d\d(T(\d\d(:\d\d(:\d\d(\.\d\d?\d?)?)?)?)?([\+\-]\d\d:?\d\d)?)?/,u="YYYY-MM-DDTHH:mm:ssZ",v=[["HH:mm:ss.S",/T\d\d:\d\d:\d\d\.\d{1,3}/],["HH:mm:ss",/T\d\d:\d\d:\d\d/],["HH:mm",/T\d\d:\d\d/],["HH",/T\d\d/]],w=/([\+\-]|\d\d)/gi,x="Month|Date|Hours|Minutes|Seconds|Milliseconds".split("|"),y={Milliseconds:1,Seconds:1e3,Minutes:6e4,Hours:36e5,Days:864e5,Months:2592e6,Years:31536e6};moment=function(c,d){if(c===null||c==="")return null;var e,f,g;return moment.isMoment(c)?(e=new a(+c._d),g=c._isUTC):d?E(d)?e=L(c,d):e=J(c,d):(f=j.exec(c),e=c===b?new a:f?new a(+f[1]):c instanceof a?c:E(c)?F(c):typeof c=="string"?M(c):new a(c)),new z(e,g)},moment.utc=function(b,c){return E(b)?new z(new a(a.UTC.apply({},b)),!0):c&&b?moment(b+" +0000",c+" Z").utc():moment(b&&!r.exec(b)?b+"+0000":b).utc()},moment.unix=function(a){return moment(a*1e3)},moment.duration=function(a,b){var c=moment.isDuration(a),d=typeof a=="number",e=c?a._data:d?{}:a;return d&&(b?e[b]=a:e.milliseconds=a),new B(e)},moment.humanizeDuration=function(a,b,c){return moment.duration(a,b===!0?null:b).humanize(b===!0?!0:c)},moment.version=c,moment.defaultFormat=u,moment.lang=function(a,b){var c,d,e=[];if(!a)return g;if(b){for(c=0;c<12;c++)e[c]=new RegExp("^"+b.months[c]+"|^"+b.monthsShort[c].replace(".",""),"i");b.monthsParse=b.monthsParse||e,f[a]=b}if(f[a]){for(c=0;c/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,variable:"obj"};var N=cB("var index, result<% if (init) { %> = <%= init %><% } %>;\n<%= exit %>;\n<%= top %>;\n<% if (arrayBranch) { %>var length = <%= firstArg %>.length; index = -1; <% if (objectBranch) { %>\nif (length === length >>> 0) {<% } %>\n <%= arrayBranch.beforeLoop %>;\n while (<%= arrayBranch.loopExp %>) {\n <%= arrayBranch.inLoop %>;\n } <% if (objectBranch) { %>\n}\n<% }}if (objectBranch) { if (arrayBranch) { %>else {\n<% } if (!hasDontEnumBug) { %> var skipProto = typeof <%= iteratedObject %> == 'function';\n<% } %> <%= objectBranch.beforeLoop %>;\n for (<%= objectBranch.loopExp %>) { \n<% if (hasDontEnumBug) { if (useHas) { %> if (<%= hasExp %>) {\n <% } %> <%= objectBranch.inLoop %>;<% if (useHas) { %>\n }<% } } else { %> if (!(skipProto && index == 'prototype')<% if (useHas) { %> && <%= hasExp %><% } %>) {\n <%= objectBranch.inLoop %>;\n } <% } %>\n } <% if (hasDontEnumBug) { %>\n var ctor = <%= iteratedObject %>.constructor;\n <% for (var k = 0; k < 7; k++) { %>\n index = '<%= shadowed[k] %>';\n if (<% if (shadowed[k] == 'constructor') { %>!(ctor && ctor.prototype === <%= iteratedObject %>) && <% } %><%= hasExp %>) {\n <%= objectBranch.inLoop %>;\n }<% } } if (arrayBranch) { %>\n}<% }} %>\n<%= bottom %>;\nreturn result"),O={args:"collection, callback, thisArg",init:"collection",top:"if (!callback) {\n callback = identity\n}\nelse if (thisArg) {\n callback = iteratorBind(callback, thisArg)\n}",inLoop:"callback(collection[index], index, collection)"},P={init:"true",inLoop:"if (!callback(collection[index], index, collection)) return !result"},Q={args:"object",init:"object",top:"for (var source, sourceIndex = 1, length = arguments.length; sourceIndex < length; sourceIndex++) {\n source = arguments[sourceIndex];\n"+(d?" if (source) {":""),loopExp:"index in source",useHas:!1,inLoop:"object[index] = source[index]",bottom:(d?" }\n":"")+"}"},R={init:"[]",inLoop:"callback(collection[index], index, collection) && result.push(collection[index])"},S={top:"if (thisArg) callback = iteratorBind(callback, thisArg)"},T={inLoop:{object:O.inLoop}},$=U({args:"object",exit:"if (!objectTypes[typeof object] || object === null) throw TypeError()",init:"[]",inLoop:"result.push(index)"}),bc=U({args:"collection, target",init:"false",inLoop:"if (collection[index] === target) return true"}),bd=U(O,P),be=U(O,R),bf=U(O,S,{init:"",inLoop:"if (callback(collection[index], index, collection)) return collection[index]"}),bg=U(O,S),bh=U(O,{init:"",exit:"if (!collection) return []",beforeLoop:{array:"result = Array(length)",object:"result = []"},inLoop:{array:"result[index] = callback(collection[index], index, collection)",object:"result.push(callback(collection[index], index, collection))"}}),bi=U({args:"collection, callback, accumulator, thisArg",init:"accumulator",top:"var noaccum = arguments.length < 3;\nif (thisArg) callback = iteratorBind(callback, thisArg)",beforeLoop:{array:"if (noaccum) result = collection[++index]"},inLoop:{array:"result = callback(result, collection[index], index, collection)",object:"result = noaccum\n ? (noaccum = false, collection[index])\n : callback(result, collection[index], index, collection)"}}),bk=U(O,R,{inLoop:"!"+R.inLoop}),bl=U(O,P,{init:"false",inLoop:P.inLoop.replace("!","")}),bX=U(Q,{inLoop:"if (object[index] == undefined)"+Q.inLoop}),bY=U(Q),bZ=U(O,S,T,{useHas:!1}),b$=U(O,S,T),b_=U({args:"object",init:"[]",useHas:!1,inLoop:"if (toString.call(object[index]) == funcClass) result.push(index)",bottom:"result.sort()"}),cb=function(a){return E.call(a)=="[object Arguments]"};cb(arguments)||(cb=function(a){return!!a&&!!B.call(a,"callee")});var cc=G||function(a){return E.call(a)==r},cg=U({args:"value",init:"true",top:"var className = toString.call(value);\nif (className == arrayClass || className == stringClass) return !value.length",inLoop:{object:"return false"}}),cr=I?function(a){return typeof a=="function"?$(a):I(a)}:$,cv=U({args:"object",init:"[]",inLoop:"result.push(object[index])"});L.VERSION="0.3.1",L.after=bK,L.bind=bL,L.bindAll=bM,L.chain=cE,L.clone=bW,L.compact=bn,L.compose=bN,L.contains=bc,L.debounce=bO,L.defaults=bX,L.defer=bQ,L.delay=bP,L.difference=bo,L.escape=cw,L.every=bd,L.extend=bY,L.filter=be,L.find=bf,L.first=bp,L.flatten=bq,L.forEach=bg,L.forIn=bZ,L.forOwn=b$,L.functions=b_,L.groupBy=br,L.has=ca,L.identity=cx,L.indexOf=bs,L.initial=bt,L.intersection=bu,L.invoke=bv,L.isArguments=cb,L.isArray=cc,L.isBoolean=cd,L.isDate=ce,L.isElement=cf,L.isEmpty=cg,L.isEqual=ch,L.isFinite=ci,L.isFunction=cj,L.isNaN=cl,L.isNull=cm,L.isNumber=cn,L.isObject=ck,L.isRegExp=co,L.isString=cp,L.isUndefined=cq,L.keys=cr,L.last=bw,L.lastIndexOf=bx,L.map=bh,L.max=by,L.memoize=bR,L.min=bz,L.mixin=cy,L.noConflict=cz,L.once=bS,L.partial=bT,L.pick=cs,L.pluck=bA,L.range=bB,L.reduce=bi,L.reduceRight=bj,L.reject=bk,L.rest=bC,L.result=cA,L.shuffle=bD,L.size=ct,L.some=bl,L.sortBy=bE,L.sortedIndex=bF,L.tap=cu,L.template=cB,L.throttle=bU,L.times=cC,L.toArray=bm,L.union=bG,L.uniq=bH,L.uniqueId=cD,L.values=cv,L.without=bI,L.wrap=bV,L.zip=bJ,L.all=bd,L.any=bl,L.collect=bh,L.detect=bf,L.each=bg,L.foldl=bi,L.foldr=bj,L.head=bp,L.include=bc,L.inject=bi,L.methods=b_,L.select=be,L.tail=bC,L.take=bp,L.unique=bH,L._iteratorTemplate=N,L._shimKeys=$,M.prototype=L.prototype,cy(L),M.prototype.chain=cF,M.prototype.value=cG,bg(["pop","push","reverse","shift","sort","splice","unshift"],function(a){var b=y[a];M.prototype[a]=function(){var a=this._wrapped;return b.apply(a,arguments),a.length===0&&delete a[0],this._chain&&(a=new M(a),a._chain=!0),a}}),bg(["concat","join","slice"],function(a){var b=y[a];M.prototype[a]=function(){var a=this._wrapped,c=b.apply(a,arguments);return this._chain&&(c=new M(c),c._chain=!0),c}}),typeof define=="function"&&typeof define.amd=="object"&&define.amd?(a._=L,define(function(){return L})):c?typeof module=="object"&&module&&module.exports==c?(module.exports=L)._=L:c._=L:a._=L}(this),function(){var a=this.math={};a.mean=a.ave=a.average=function(b,c){return a.sum(b,c)/_(b).size()},a.median=function(b){var c=(b.length+1)/2,d=a.sort(b);return d.length%2?d[c-1]:(d[c-1.5]+d[c-.5])/2},a.pow=function(a,b){if(_.isNumber(a))return Math.pow(a,b);if(_.isArray(a))return _.map(a,function(a){return _.pow(a,b)})},a.scale=function(a,b){var b=b||1,c=_.max(a);return _.map(a,function(a){return a*(b/c)})},a.slope=function(a,b){return(b[1]-a[1])/(b[0]-a[0])},a.sort=function(a){return a.sort(function(a,b){return a-b})},a.stdDeviation=a.sigma=function(a){return Math.sqrt(_(a).variance())},a.sum=function(a,b){if(_.isArray(a)&&typeof a[0]=="number")var c=a;else var b=b||"value",c=_(a).pluck(b);var d=0;for(var e=0,f=c.length;e1?h.call(arguments,0):c,--f||i.resolveWith(i,b)}}function m(a){return function(b){e[a]=arguments.length>1?h.call(arguments,0):b,i.notifyWith(k,e)}}var b=h.call(arguments,0),c=0,d=b.length,e=new Array(d),f=d,g=d,i=d<=1&&a&&j(a.promise)?a:n.Deferred(),k=i.promise();if(d>1){for(;cb?1:0},numeric:function(a){return _.isNaN(Number(a))?0:Number(a)}},string:{name:"string",coerce:function(a){return a==null?null:a.toString()},test:function(a){return a===null||typeof a=="undefined"||typeof a=="string"},compare:function(a,b){return a==null&&b!=null?-1:a!=null&&b==null?1:ab?1:0},numeric:function(a){return _.isNaN(+a)?0:+a}},"boolean":{name:"boolean",regexp:/^(true|false)$/,coerce:function(a){return a==="false"?!1:Boolean(a)},test:function(a){return a===null||typeof a=="undefined"||typeof a=="boolean"||this.regexp.test(a)?!0:!1},compare:function(a,b){return a==null&&b!=null?-1:a!=null&&b==null?1:a==null&&b==null?0:a===b?0:ab?1:0},numeric:function(a){return a.valueOf()}}}}(this,_),function(a,_){var b=a.Miso||(a.Miso={});b.Event=function(a){_.isArray(a)||(a=[a]),this.deltas=a},_.extend(b.Event.prototype,{affectedColumns:function(){var a=[];return _.each(this.deltas,function(b){b.old=b.old||[],b.changed=b.changed||[],a=_.chain(a).union(_.keys(b.old),_.keys(b.changed)).reject(function(a){return a==="_id"}).value()}),a}}),_.extend(b.Event,{isRemove:function(a){return _.isUndefined(a.changed)||_.keys(a.changed).length===0?!0:!1},isAdd:function(a){return _.isUndefined(a.old)||_.keys(a.old).length===0?!0:!1},isUpdate:function(a){return!this.isRemove(a)&&!this.isAdd(a)?!0:!1}}),b.Events={},b.Events.bind=function(a,b,c){var d=this._callbacks||(this._callbacks={}),e=d[a]||(d[a]={}),f=e.tail||(e.tail=e.next={});return f.callback=b,f.context=c,e.tail=f.next={},this},b.Events.unbind=function(a,b){var c,d,e;if(!a)this._callbacks=null;else if(c=this._callbacks)if(!b)c[a]={};else if(d=c[a])while((e=d)&&(d=d.next)){if(d.callback!==b)continue;e.next=d.next,d.context=d.callback=null;break}return this},b.Events.trigger=function(a){var b,c,d,e,f,g=["all",a];if(!(c=this._callbacks))return this;while(f=g.pop()){if(!(b=c[f]))continue;e=f==="all"?arguments:Array.prototype.slice.call(arguments,1);while(b=b.next)(d=b.callback)&&d.apply(b.context||this,e)}return this},b.Events._buildEvent=function(a){return new b.Event(a)}}(this,_),function(a,_){var b=a.Miso||{};b.Builder={detectColumnType:function(a,c){var d=_.inject(c.slice(0,5),function(a,c){var d=b.typeOf(c);return c!==""&&a.indexOf(d)===-1&&!_.isNull(c)&&a.push(d),a},[]);return d.length===1?a.type=d[0]:a.type="mixed",a},detectColumnTypes:function(a,c){_.each(c,function(c,d){var e=a.column(d);if(e.type){e.force=!0;return}b.Builder.detectColumnType(e,c)},this)},cacheRows:function(a){b.Builder.clearRowCache(a),_.each(a._columns[a._columnPositionByName._id].data,function(b,c){a._rowPositionById[b]=c,a._rowIdByPosition.push(b)},a);var c=_.uniq(_.map(a._columns,function(a){return a.data.length}));if(c.length>1)throw new Error("Row lengths need to be the same. Empty values should be set to null."+_.map(a._columns,function(a){return a.data+"|||"}));a.length=c[0]},clearRowCache:function(a){a._rowPositionById={},a._rowIdByPosition=[]},cacheColumns:function(a){a._columnPositionByName={},_.each(a._columns,function(b,c){a._columnPositionByName[b.name]=c})}},Array.prototype.indexOf||(Array.prototype.indexOf=function(a,b){for(var c=b||0,d=this.length;c0&&(a=this.numericAt(c));return b.types[this.type].coerce(a,this)},_min:function(){var a=Infinity;for(var c=0;c=0;c--)a.apply(b||this,[this.rowByPosition(c),c])},eachColumn:function(a,b){var c=this.columnNames();for(var d=0;d=0)f(b,a-1),b--};if(c>2){g(c),d=c-1;while(d>1)e(d,0),d--,f(0,d)}else this.comparator(this.rowByPosition(0),this.rowByPosition(1))>0&&e(0,1);return this.comparator(this.rowByPosition(this.length-2),this.rowByPosition(this.length-1))>0&&e(this.length-1,this.length-2),this.syncable&&b.silent&&this.trigger("sort"),this},toJSON:function(){var a=[];for(var b=0;b0&&_.times(a,function(){b.push(_.uniqueId())}),this.addColumn({name:"_id",type:"number",data:b});if(this._columnPositionByName._id!==0){var c=this._columns[this._columnPositionByName._id],d=this._columnPositionByName._id;this._columns.splice(d,1),this._columns.unshift(c),this._columnPositionByName._id=0,_.each(this._columnPositionByName,function(a,b){b!=="_id"&&this._columnPositionByName[b]1&&(f=b),a},{}),new Error('You have more than one column named "'+f+'"')}_.each(a.table.rows,function(a){a=a.c;for(e=0;e0){var n=0,o=0,p=d.length;while(n