// Compiled by ClojureScript 0.0-2138
goog.provide('lt.objs.metrics');
goog.require('cljs.core');
goog.require('lt.util.js');
goog.require('lt.util.js');
goog.require('fetch.remotes');
goog.require('fetch.remotes');
goog.require('lt.objs.cache');
goog.require('lt.objs.cache');
goog.require('lt.objs.app');
goog.require('lt.objs.app');
goog.require('lt.object');
goog.require('lt.object');
lt.objs.metrics.server_url = "http://app.kodowa.com";
fetch.remotes.remote_uri = [cljs.core.str(lt.objs.metrics.server_url),cljs.core.str("/_fetch")].join('');
lt.objs.metrics.active_QMARK_ = true;
lt.objs.metrics.used_QMARK_ = false;
lt.objs.metrics._metrics = cljs.core.atom.call(null,cljs.core.PersistentVector.EMPTY);
lt.objs.metrics.metric_rate = 30000;
lt.objs.metrics.used_BANG_ = (function used_BANG_(){return lt.objs.metrics.used_QMARK_ = true;
});
/**
* @param {...*} var_args
*/
lt.objs.metrics.capture_BANG_ = (function() { 
var capture_BANG___delegate = function (ev,p__12207){var vec__12209 = p__12207;var ex = cljs.core.nth.call(null,vec__12209,0,null);var mtr = new cljs.core.PersistentArrayMap(null, 2, [new cljs.core.Keyword(null,"ev","ev",1013907491),ev,new cljs.core.Keyword(null,"ts","ts",1013907953),lt.util.js.now.call(null)], null);var mtr__$1 = (cljs.core.truth_(ex)?cljs.core.assoc.call(null,mtr,new cljs.core.Keyword(null,"ex","ex",1013907493),ex):mtr);return cljs.core.swap_BANG_.call(null,lt.objs.metrics._metrics,cljs.core.conj,mtr__$1);
};
var capture_BANG_ = function (ev,var_args){
var p__12207 = null;if (arguments.length > 1) {
  p__12207 = cljs.core.array_seq(Array.prototype.slice.call(arguments, 1),0);} 
return capture_BANG___delegate.call(this,ev,p__12207);};
capture_BANG_.cljs$lang$maxFixedArity = 1;
capture_BANG_.cljs$lang$applyTo = (function (arglist__12210){
var ev = cljs.core.first(arglist__12210);
var p__12207 = cljs.core.rest(arglist__12210);
return capture_BANG___delegate(ev,p__12207);
});
capture_BANG_.cljs$core$IFn$_invoke$arity$variadic = capture_BANG___delegate;
return capture_BANG_;
})()
;
lt.objs.metrics.send = (function send(mtrs){return fetch.remotes.remote_callback.call(null,"metrics!",new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [mtrs,lt.objs.cache.fetch.call(null,new cljs.core.Keyword(null,"uid","uid",1014020034))], null),null);
});
lt.objs.metrics.flush = (function flush(){if(cljs.core.truth_(lt.objs.metrics.active_QMARK_))
{var temp__4092__auto__ = cljs.core.seq.call(null,cljs.core.deref.call(null,lt.objs.metrics._metrics));if(temp__4092__auto__)
{var cur = temp__4092__auto__;cljs.core.reset_BANG_.call(null,lt.objs.metrics._metrics,cljs.core.PersistentVector.EMPTY);
return lt.objs.metrics.send.call(null,cur);
} else
{return null;
}
} else
{return null;
}
});
lt.objs.metrics.init = (function init(){if(cljs.core.truth_(lt.objs.cache.fetch.call(null,new cljs.core.Keyword(null,"no-metrics","no-metrics",4181152809))))
{lt.objs.metrics.active_QMARK_ = false;
} else
{}
if(cljs.core.truth_(lt.objs.metrics.active_QMARK_))
{fetch.remotes.remote_callback.call(null,"session",cljs.core.PersistentVector.EMPTY,(function (uid){if(cljs.core.truth_(lt.objs.cache.fetch.call(null,new cljs.core.Keyword(null,"uid","uid",1014020034))))
{} else
{lt.objs.cache.store_BANG_.call(null,new cljs.core.Keyword(null,"uid","uid",1014020034),uid);
}
lt.objs.metrics.capture_BANG_.call(null,new cljs.core.Keyword(null,"session-created","session-created",2199511587));
return lt.util.js.every.call(null,lt.objs.metrics.metric_rate,lt.objs.metrics.flush);
}));
return lt.util.js.every.call(null,60000,(function (){if(cljs.core.truth_(lt.objs.metrics.used_QMARK_))
{lt.objs.metrics.used_QMARK_ = false;
return lt.objs.metrics.capture_BANG_.call(null,new cljs.core.Keyword(null,"metrics.minute","metrics.minute",3221073169));
} else
{return null;
}
}));
} else
{return null;
}
});
lt.objs.metrics.__BEH__init_metrics = (function __BEH__init_metrics(){return lt.objs.metrics.init.call(null);
});
lt.object.behavior_STAR_.call(null,new cljs.core.Keyword("lt.objs.metrics","init-metrics","lt.objs.metrics/init-metrics",3820315356),new cljs.core.Keyword(null,"reaction","reaction",4441361819),lt.objs.metrics.__BEH__init_metrics,new cljs.core.Keyword(null,"triggers","triggers",2516997421),new cljs.core.PersistentHashSet(null, new cljs.core.PersistentArrayMap(null, 1, [new cljs.core.Keyword(null,"init","init",1017141378),null], null), null));
lt.objs.metrics.__BEH__disable_metrics = (function __BEH__disable_metrics(this$){return lt.objs.metrics.active_QMARK_ = false;
});
lt.object.behavior_STAR_.call(null,new cljs.core.Keyword("lt.objs.metrics","disable-metrics","lt.objs.metrics/disable-metrics",3662334164),new cljs.core.Keyword(null,"reaction","reaction",4441361819),lt.objs.metrics.__BEH__disable_metrics,new cljs.core.Keyword(null,"desc","desc",1016984067),"App: Disable metrics",new cljs.core.Keyword(null,"triggers","triggers",2516997421),new cljs.core.PersistentHashSet(null, new cljs.core.PersistentArrayMap(null, 1, [new cljs.core.Keyword(null,"object.instant","object.instant",773332388),null], null), null),new cljs.core.Keyword(null,"type","type",1017479852),new cljs.core.Keyword(null,"user","user",1017503549));
