You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apex.apache.org by da...@apache.org on 2015/11/30 22:06:50 UTC

[44/98] [abbrv] [partial] incubator-apex-malhar git commit: Removing all web demos

http://git-wip-us.apache.org/repos/asf/incubator-apex-malhar/blob/e1a45507/web/demos/package/app/scripts/5f986af9.scripts.js
----------------------------------------------------------------------
diff --git a/web/demos/package/app/scripts/5f986af9.scripts.js b/web/demos/package/app/scripts/5f986af9.scripts.js
deleted file mode 100644
index 724adf5..0000000
--- a/web/demos/package/app/scripts/5f986af9.scripts.js
+++ /dev/null
@@ -1,19 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-!function(){"use strict";angular.module("widgets",["socket"]),angular.module("twitter",["rest","socket","widgets","ngGrid"]),angular.module("mobile",["rest","widgets","ngGrid","google-maps"]),angular.module("machine",["ng","rest","widgets"]),angular.module("dimensions",["ng","rest","widgets"]),angular.module("fraud",["rest","widgets"]),angular.module("app",["ngRoute","socket","twitter","mobile","machine","dimensions","fraud"]),angular.module("app").config(["$routeProvider","socketProvider",function(a,b){window.settings&&b.setWebSocketURL(settings.webSocketURL),a.when("/",{templateUrl:"views/welcome.html"}).when("/twitterUrls",{templateUrl:"views/twitter.html",controller:"TwitterUrlsController"}).when("/twitterHashtags",{templateUrl:"views/twitter.html",controller:"TwitterHashtagsController"}).when("/mobile",{templateUrl:"views/mobile.html",controller:"MobileController"}).when("/machine",{templateUrl:"views/machine.html",controller:"MachineController"}).when("/dimensions",{templateUr
 l:"views/dimensions.html",controller:"DimensionsController"}).when("/fraud",{templateUrl:"views/fraud.html",controller:"FraudController"})}])}(),function(){"use strict";angular.module("rest",["ng","restangular"]).factory("rest",["$q","Restangular",function(a,b){return{getApp:function(c){var d=a.defer();return b.oneUrl("applications","ws/v2/applications").get().then(function(a){var b=null;if(a&&a.apps&&a.apps.length>0){var e=_.where(a.apps,{name:c,state:"RUNNING"});if(e.length>0){e=_.sortBy(e,function(a){return parseInt(a.elapsedTime,10)});var f=e[0];d.resolve(f)}else b=c+" is not found. Please make sure application is running."}else b="No applications available.";b&&(d.reject(b),jQuery.pnotify({title:"Error",text:b,type:"error",icon:!1,hide:!1}))}),d.promise},getMachineData:function(a){var c=b.one("machine").get(a);return c.then(null,function(a){jQuery.pnotify({title:"Error",text:"Error getting data from server. Status Code: "+a.status,type:"error",icon:!1,hide:!1})}),c},getDimensio
 nsData:function(a){var c=b.one("dimensions").get(a);return c.then(null,function(a){jQuery.pnotify({title:"Error",text:"Error getting data from server. Status Code: "+a.status,type:"error",icon:!1,hide:!1})}),c}}}]).run(function(){})}(),function(){"use strict";angular.module("socket",[]).factory("visibly",["$window",function(a){return a.visibly}]).provider("socket",function(){var a,b;return{$get:["$q","$rootScope","$timeout","visibly",function(c,d,e,f){if(!a&&!b)throw"WebSocket URL is not defined";var g=b?b:new WebSocket(a),h=c.defer();g.onopen=function(){h.resolve(),d.$apply(),jQuery.pnotify({title:"WebSocket",text:"WebSocket connection established.",type:"success",delay:2e3,icon:!1,history:!1})};var i=!1;g.onclose=function(){i||jQuery.pnotify({title:"WebSocket Closed",text:"WebSocket connection has been closed. Try refreshing the page.",type:"error",icon:!1,hide:!1,history:!1})},g.onerror=function(){i=!0,jQuery.pnotify({title:"WebSocket Error",text:"WebSocket error. Try refreshing 
 the page.",type:"error",icon:!1,hide:!1,history:!1})};var j={},k=!1;g.onmessage=function(a){if(!k){var b=JSON.parse(a.data),c=b.topic;j.hasOwnProperty(c)&&j[c].fire(b)}};var l;return f.onHidden(function(){l=e(function(){k=!0,l=null},6e4)}),f.onVisible(function(){k=!1,l&&e.cancel(l)}),{send:function(a){var b=JSON.stringify(a);h.promise.then(function(){console.log("send "+b),g.send(b)})},publish:function(a,b){var c={type:"publish",topic:a,data:b};this.send(c)},subscribe:function(a,b,c){var d=j[a];if(!d){var e={type:"subscribe",topic:a};this.send(e),d=jQuery.Callbacks(),j[a]=d}d.add(b),c&&c.$on("$destroy",function(){this.unsubscribe(a,b)}.bind(this))},unsubscribe:function(a,b){if(j.hasOwnProperty(a)){var c=j[a];c.remove(b)}}}}],setWebSocketURL:function(b){a=b},setWebSocketObject:function(a){b=a}}})}(),function(){"use strict";angular.module("widgets").directive("lineChart",function(){return{template:"<div></div>",scope:{chart:"="},restrict:"E",replace:!0,link:function(a,b){function c(a)
 {var b=a.data;b||(b=[]);var c=new google.visualization.DataTable;c.addColumn("datetime"),c.addColumn("number"),c.addRows(b.length);for(var e=new google.visualization.DataView(c),f=0;f<b.length;f++){var g=b[f];c.setCell(f,0,new Date(g.timestamp));var h=parseFloat(g.value);c.setCell(f,1,h)}var i;i=0===b.length&&a.emptyChartOptions?a.emptyChartOptions():a.options,d.draw(e,i)}var d=new google.visualization.LineChart(b[0]);a.$watch("chart",function(a){a&&c(a)})}}})}(),function(){"use strict";angular.module("widgets").directive("gauge",function(){return{restrict:"A",replace:!0,scope:{label:"@",min:"=",max:"=",value:"="},link:function(a,b,c){var d={size:280,label:c.label,min:void 0!==a.min?a.min:0,max:void 0!==a.max?a.max:100,minorTicks:5},e=d.max-d.min;d.yellowZones=[{from:d.min+.75*e,to:d.min+.9*e}],d.redZones=[{from:d.min+.9*e,to:d.max}],a.gauge=new Gauge(b[0],d),a.gauge.render(),a.gauge.redraw(a.value),a.$watch("value",function(){a.gauge&&a.gauge.redraw(a.value)})}}})}(),function(){"us
 e strict";angular.module("widgets").directive("widgetsBarChart",function(){return{restrict:"A",scope:{data:"=",label:"@",onClick:"&"},link:function(a,b){var c=d3.select(b[0]).append("svg").attr("width","100%");window.onresize=function(){return a.$apply()},a.$watch(function(){return angular.element(window)[0].innerWidth},function(){return a.render(a.data)}),a.$watch("data",function(b){return a.render(b)},!0),a.render=function(d){c.selectAll("*").remove();var e,f,g;e=d3.select(b[0])[0][0].offsetWidth-20,f=35*a.data.length,g=98,c.attr("height",f),c.selectAll("rect").data(d).enter().append("rect").on("click",function(b){return a.onClick({item:b})}).attr("height",30).attr("width",0).attr("x",10).attr("y",function(a,b){return 35*b}).attr("width",function(a){var b=a.score/(g/e);return b>10?b:10}),c.selectAll("text").data(d).enter().append("text").attr("fill","#fff").attr("y",function(a,b){return 35*b+22}).attr("x",15).html(function(b){return b[a.label]})}}}})}(),function(){"use strict";ang
 ular.module("widgets").directive("widgetsStat",["$timeout","socket",function(a,b){return{restrict:"A",templateUrl:"views/stat.html",scope:{app:"=",label:"@",onClick:"&"},link:function(c){function d(){c.elapsed=e+(Date.now()-f),a(d,1e3)}c.totalEmitted=0,c.totalProcessed=0,c.elapsed=0;var e,f;c.$watch("app",function(a){if(a){e=parseInt(a.elapsedTime),f=Date.now(),d();var g="applications."+a.id;b.subscribe(g,function(a){var b=a.data;c.totalEmitted=b.tuplesEmittedPSMA,c.totalProcessed=b.totalTuplesProcessed,c.$apply()},c)}})}}}])}(),function(){"use strict";angular.module("widgets").filter("elapsed",function(){return function(a){var b={timeChunk:1*a,unixUptime:!0};_.defaults(b,{compareDate:+new Date,timeChunk:void 0,maxUnit:"year",unixUptime:!1,max_levels:3,timeStamp:a||0});var c=void 0!==b.timeChunk?b.timeChunk:b.compareDate-b.timeStamp,d="",e=", ",f=0,g=b.max_levels,h=1e3,i=60*h,j=60*i,k=24*j,l=7*k,m=4*l,n=365*k;if(b.unixUptime){var o=Math.floor(c/k);c-=o*k;var p=Math.floor(c/j);c-=p*j
 ;var q=Math.round(c/i);if(0===o){q=Math.floor(c/i),c-=q*i;var r=Math.round(c/1e3);d=(10>p?"0":"")+p+":"+(10>q?"0":"")+q+":"+(10>r?"0":"")+r}else d=o+" days, "+p.toString()+":"+(10>q?"0":"")+q.toString()}else{for(var s=[{plural:"years",singular:"year",ms:n},{plural:"months",singular:"month",ms:m},{plural:"weeks",singular:"week",ms:l},{plural:"days",singular:"day",ms:k},{plural:"hours",singular:"hour",ms:j},{plural:"minutes",singular:"minute",ms:i},{plural:"seconds",singular:"second",ms:h}],t=!1,u=0;u<s.length;u++)if(b.maxUnit===s[u].singular&&(t=!0),!(c<s[u].ms)&&t){f++;var v=Math.floor(c/s[u].ms),w=1===v?s[u].singular:s[u].plural;if(d+=v+" "+w+e,c%=s[u].ms,f>=g)break}d=d.substring(0,d.length-e.length)}return d}})}(),function(){"use strict";angular.module("twitter").controller("TwitterUrlsController",["$scope","rest",function(a,b){b.getApp(settings.twitterUrls.appName).then(function(b){a.app=b,a.appURL=settings.appsURL+b.id}),a.topic=settings.twitterUrls.topic,a.pageTitle="Twitter To
 p URLs",a.entity="URLs",a.gridTitle="Twitter Top URLs",a.chartTitle="Top 10 URLs Chart",a.colName="URL",a.formatter=function(a){return'<a class="svg-link" xlink:href="'+a+'">'+a+"</a>"}}]).controller("TwitterHashtagsController",["$scope","rest",function(a,b){b.getApp(settings.twitterHashtags.appName).then(function(b){a.app=b,a.appURL=settings.appsURL+b.id}),a.topic=settings.twitterHashtags.topic,a.pageTitle="Twitter Top Hashtags",a.entity="hashtags",a.gridTitle="Twitter Top Hashtags",a.chartTitle="Top 10 Hashtags Chart",a.colName="Hashtag",a.formatter=function(a){return'<a class="svg-link" xlink:href="https://twitter.com/search?q=%23'+encodeURIComponent(a)+'">'+a+"</a>"}}]).controller("TwitterGridControlller",["$scope","socket",function(a,b){b.subscribe(a.topic,function(b){var c=[];jQuery.each(b.data,function(a,b){c.push({name:a,value:parseInt(b,10)})}),c=_.sortBy(c,function(a){return-a.value}),a.topTen=c,a.$apply()},a),a.gridOptions={data:"topTen",enableColumnResize:!0,columnDefs:[
 {field:"name",displayName:a.colName,width:"75%",sortable:!1},{field:"value",displayName:"Count",width:"25%",sortable:!1}]}}]).controller("TwitterBarChartController",["$scope","socket",function(a,b){b.subscribe(a.topic,function(b){var c=[];jQuery.each(b.data,function(a,b){c.push({name:a,value:parseInt(b,10)})}),c=_.sortBy(c,function(a){return-a.value});var d=c[0].value;_.each(c,function(b){a.formatter&&(b.name=a.formatter(b.name)),b.name+=" - "+b.value,b.score=b.value/d*100}),a.twitterBarChartData=c,a.$apply()},a),a.twitterBarChartData=[]}])}(),function(){"use strict";function a(a){var b=a.location.match(/\((\d+),(\d+)/),c=parseInt(b[1],10),d=parseInt(b[2],10),e=parseInt(a.phone,10),f=37.40180101292334+.01*(e%4-2)-.005*c,g=-121.9966721534729+.01*(e%8-4)+.007*d;return{latitude:f,longitude:g,label:a.phone,phone:a.phone}}angular.module("mobile").controller("MobileController",["$scope","rest","socket",function(b,c,d){c.getApp(settings.mobile.appName).then(function(a){b.app=a,b.appURL=set
 tings.appsURL+a.id});var e={};d.subscribe(settings.mobile.topic.out,function(c){var d=c.data;if(d.hasOwnProperty("removed"))delete e[d.phone];else{var f=a(d);e[d.phone]=f}b.$broadcast("datachanged",e)},b)}]).controller("MobileGridControlller",["$scope","$filter","$timeout","socket",function(a,b,c,d){a.$on("datachanged",function(b,c){a.gridData=_.values(c)}),a.phone="",a.addPhone=function(){var b={command:"add",phone:a.phone},c={type:"publish",topic:settings.mobile.topic.in,data:b};d.send(c),a.phone=""},a.removePhone=function(a){var b={command:"del",phone:a},c={type:"publish",topic:settings.mobile.topic.in,data:b};d.send(c)},a.gridOptions={data:"gridData",enableColumnResize:!0,enableRowSelection:!1,columnDefs:[{field:"phone",displayName:"Phone",width:"30%",sortable:!1},{field:"latitude",displayName:"Latitude",cellFilter:"number:3",width:"30%",sortable:!1},{field:"longitude",displayName:"Longitude",cellFilter:"number:3",width:"30%",sortable:!1},{field:"phone",displayName:"",cellTempla
 te:'<div class="ngCellText" ng-class="col.colIndex()" ng-click="removePhone(COL_FIELD)"><i class="icon-trash"></i></div>',cellClass:"mobile-grid-remove",width:"10%",sortable:!1}]}}]).controller("MapController",["$scope","socket",function(a){google.maps.visualRefresh=!0,a.$on("datachanged",function(b,c){a.markersProperty=_.values(c)}),angular.extend(a,{position:{coords:{latitude:37.36197126180853,longitude:-121.92674696445465}},zoomProperty:12})}])}(),function(){"use strict";function a(a){return function(){var b=Date.now(),c=new Date(b),d=new Date(b-60*a.lookback*1e3),f=jQuery.extend({},e,{vAxis:{minValue:0,maxValue:100},hAxis:{viewWindow:{min:d,max:c}}});return f}}function b(a,b){return _.map(a,function(a){return{timestamp:a.timestamp,value:a[b]}})}function c(a){return{customer:a.customer.value,product:a.product.value,os:a.os.value,software1:a.software1.value,software2:a.software2.value,deviceId:a.deviceId.value,lookback:a.lookback}}function d(a,b,d){this.rest=a,this.scope=b,this.ma
 x=b.lookback,this.dataCache=null,this.callback=d,this.cancelled=!1,this.interval=null,this.timeout=null,this.params=c(this.scope)}var e={legend:"none",vAxis:{format:settings.machine.metricformat},chartArea:{top:20,height:240}};d.prototype={cancel:function(){this.cancelled=!0,this.scope.requestProgress=0,clearInterval(this.interval),clearTimeout(this.timeout)},responseStatus:function(){this.scope.requestProgress=Math.round((Date.now()-this.requestStartTime)/1e3),this.scope.$apply()},fetchMachineData:function(){this.dataCache&&this.dataCache.length&&(this.params.lastTimestamp=_.last(this.dataCache).timestamp);var a=this.max;this.requestStartTime=Date.now(),this.interval=setInterval(this.responseStatus.bind(this),250);var b=this;this.rest.getMachineData(this.params).then(function(c){if(!b.cancelled){b.scope.response=c;var d=c.minutes;b.scope.requestProgress=0,clearInterval(b.interval);var e=Date.now();if(b.scope.lastResponse=new Date(e),b.scope.responseTime=e-b.requestStartTime,b.dataC
 ache){if(d.length>0){b.scope.minutesCached=b.dataCache.length,b.scope.minutesReceived=d.length,b.dataCache.pop();var f=b.dataCache.length+d.length;f>a&&b.dataCache.splice(0,f-a),b.dataCache.push.apply(b.dataCache,d)}}else b.dataCache=d,b.scope.minutesCached=0,b.scope.minutesReceived=d.length;b.callback(b.dataCache);var g=settings.machine.pollInterval-(Date.now()-b.requestStartTime);g=Math.max(0,g),b.timeout=setTimeout(b.fetchMachineData.bind(b),g)}},function(){b.cancel()})}},angular.module("machine").controller("MachineController",["$scope","$timeout","$location","$routeParams","rest",function(f,g,h,i,j){function k(a,b){var c=f.range(a),d=_.map(c,function(a){return{value:String(a),label:b+" "+a}});d.splice(0,0,{value:"",label:"ALL "}),f.select[a]=d;var e=null;n[a]&&(e=_.findWhere(d,{value:n[a]})),f[a]=e?e:d[0]}function l(a){if(a&&a.length>0){var c=_.last(a);f.cpu=parseFloat(c.cpu),f.ram=parseFloat(c.ram),f.hdd=parseFloat(c.hdd)}f.cpuChart={data:b(a,"cpu"),options:e,emptyChartOptions
 :o},f.ramChart={data:b(a,"ram"),options:e,emptyChartOptions:o},f.hddChart={data:b(a,"hdd"),options:e,emptyChartOptions:o}}function m(){p&&p.cancel(),p=new d(j,f,l),p.fetchMachineData()}var n=new URI(window.location.href).query(!0),o=a(f);j.getApp(settings.machine.appName).then(function(a){f.app=a,f.appURL=settings.appsURL+a.id}),f.cpu=0,f.ram=0,f.hdd=0,f.range=function(a){var b=settings.machine.range[a];return _.range(b.start,b.stop+1)},f.select={},k("customer","Customer"),k("product","Product"),k("os","OS"),k("software1","Software1 Version"),k("software2","Software2 Version"),k("deviceId","Device ID"),f.lookback=n.lookback?parseInt(n.lookback,10):settings.machine.lookback,f.reload=function(){window.location.href=window.location.pathname+"?"+jQuery.param(c(f))},f.cpuChart={emptyChartOptions:o},f.ramChart={emptyChartOptions:o},f.hddChart={emptyChartOptions:o};var p=null;f.$watch("[customer, product, os, software1, software1, deviceId]",function(){m()},!0);var q,r=!0;f.$watch("lookbac
 k",function(){r?r=!1:(clearTimeout(q),q=setTimeout(m,500))}),f.$on("$destroy",function(){p&&p.cancel()}.bind(this))}])}(),function(){"use strict";function a(a){return function(){var b=Date.now(),c=new Date(b),d=new Date(b-60*a.lookback*1e3),e=jQuery.extend({},f,{vAxis:{minValue:0,maxValue:100},hAxis:{viewWindow:{min:d,max:c}}});return e}}function b(a,b){return _.map(a,function(a){return{timestamp:a.timestamp,value:a[b]}})}function c(a,b){return _.map(a,function(a){return{timestamp:a.timestamp,value:b(a)}})}function d(a){return{publisher:a.publisher.value,advertiser:a.advertiser.value,adunit:a.adunit.value,lookback:a.lookback,includeLastMinute:a.includeLastMinute}}function e(a,b,c){this.rest=a,this.scope=b,this.max=b.lookback,this.dataCache=null,this.callback=c,this.cancelled=!1,this.interval=null,this.timeout=null,this.params=d(this.scope)}var f={legend:"none",chartArea:{top:20,height:240}};e.prototype={cancel:function(){this.cancelled=!0,this.scope.requestProgress=0,clearInterval(t
 his.interval),clearTimeout(this.timeout)},responseStatus:function(){this.scope.requestProgress=Math.round((Date.now()-this.requestStartTime)/1e3),this.scope.$apply()},fetchDimensionsData:function(){this.dataCache&&this.dataCache.length&&(this.params.lastTimestamp=_.last(this.dataCache).timestamp);var a=this.max;this.requestStartTime=Date.now(),this.interval=setInterval(this.responseStatus.bind(this),250);var b=this;this.rest.getDimensionsData(this.params).then(function(c){if(!b.cancelled){b.scope.response=c;var d=c.minutes;b.scope.requestProgress=0,clearInterval(b.interval);var e=Date.now();if(b.scope.lastResponse=new Date(e),b.scope.responseTime=e-b.requestStartTime,b.dataCache){if(d.length>0){b.scope.minutesCached=b.dataCache.length,b.scope.minutesReceived=d.length,b.dataCache.pop();var f=b.dataCache.length+d.length;f>a&&b.dataCache.splice(0,f-a),b.dataCache.push.apply(b.dataCache,d)}}else b.dataCache=d,b.scope.minutesCached=0,b.scope.minutesReceived=d.length;b.callback(b.dataCach
 e);var g=1e3*b.scope.pollInterval-(Date.now()-b.requestStartTime);g=Math.max(0,g),b.timeout=setTimeout(b.fetchDimensionsData.bind(b),g)}},function(){b.cancel()})}},angular.module("dimensions").controller("DimensionsController",["$scope","$timeout","$location","$routeParams","rest",function(g,h,i,j,k){function l(a,b){var c=g.range(a),d=_.map(c,function(a){return{value:String(a),label:b+" "+a}});d.splice(0,0,{value:"",label:"ALL "}),g.select[a]=d;var e=null;p[a]&&(e=_.findWhere(d,{value:p[a]})),g[a]=e?e:d[0]}function m(a){g.costChart={data:b(a,"cost"),options:f,emptyChartOptions:q},g.revenueChart={data:b(a,"revenue"),options:f,emptyChartOptions:q},g.impressionsChart={data:b(a,"impressions"),options:f,emptyChartOptions:q},g.clicksChart={data:b(a,"clicks"),options:f,emptyChartOptions:q},g.ctrChart={data:c(a,function(a){return a.clicks/a.impressions*100}),options:f,emptyChartOptions:q},g.marginChart={data:c(a,function(a){return(a.cost-a.revenue)/a.revenue}),options:f,emptyChartOptions:q}
 }function n(){r&&r.cancel(),r=new e(k,g,m),r.fetchDimensionsData()}function o(a,b){var c,d=!0;g.$watch(a,function(){d?d=!1:(clearTimeout(c),c=setTimeout(n,b))})}var p=new URI(window.location.href).query(!0),q=a(g);k.getApp(settings.dimensions.appName).then(function(a){g.app=a,g.appURL=settings.appsURL+a.id}),g.pollInterval=settings.dimensions.pollInterval,g.includeLastMinute=!1,g.range=function(a){var b=settings.dimensions.range[a];return _.range(b.start,b.stop+1)},g.select={},l("publisher","Publisher"),l("advertiser","Advertiser"),l("adunit","Ad Unit"),g.lookback=p.lookback?parseInt(p.lookback,10):settings.dimensions.lookback,g.reload=function(){window.location.href=window.location.pathname+"?"+jQuery.param(d(g))},g.costChart={emptyChartOptions:q},g.revenueChart={emptyChartOptions:q},g.impressionsChart={emptyChartOptions:q},g.clicksChart={emptyChartOptions:q},g.ctrChart={emptyChartOptions:q},g.marginChart={emptyChartOptions:q};var r=null;g.$watch("[publisher, advertiser, adunit]",f
 unction(){n()},!0),o("lookback",500),o("pollInterval",500),o("includeLastMinute",0),g.$on("$destroy",function(){r&&r.cancel()}.bind(this))}])}(),function(){"use strict";angular.module("fraud").controller("FraudController",["$scope","rest","socket",function(a,b,c){function d(b){return a[b][Math.floor(Math.random()*a[b].length)]}function e(a){return Math.round(a)}function f(){var a=Math.floor(25*Math.random())+10;return a+"00 0000"}function g(){var a=Math.floor(4e5*Math.random())+1e7,b=a+"";return b.substring(0,4)+" "+b.substring(4)}function h(b){var c=a.alerts.push(b)-1,d=a.alertTypeTitles[b.alertType],e="";switch(b.alertType){case"smallThenLarge":e=['<article class="alert-msg low" style="display:none">',"<h1>"+d+"</h1>","<p>"+b.message+"</p>",'<div><a href="#" class="btn view-txn-btn" data-txidx="'+c+'">view details</a></div>',"</article>"].join("");break;case"sameBankId":console.log("same bank",b),e=['<article class="alert-msg high" style="display:none">',"<h1>"+d+"</h1>","<p>"+b.m
 essage+"</p>",'<div><a href="#" class="btn view-txn-btn" data-txidx="'+c+'">view details</a></div>',"</article>"].join("");break;default:e=['<article class="alert-msg medium" style="display:none">',"<h1>"+d+"</h1>","<p>"+b.message+"</p>",'<div><a href="#" class="btn view-txn-btn" data-txidx="'+c+'">view details</a></div>',"</article>"].join("")}var f=$(e);$("#alertDisplayBox").prepend(f),f.slideDown().animate({opacity:.5},180).animate({opacity:1},180).animate({opacity:.5},180).animate({opacity:1},180)}function i(a,b){c.publish(n,a),console.log("txn",a),b||$.pnotify({title:"Transaction Submitted",text:"<strong>card</strong>: "+a.bankIdNum+" "+a.ccNum+"<br/> <strong>amount</strong>: $"+k(a.amount)+"<br/> <strong>merchant</strong>: "+a.merchantId+", <strong>terminal</strong>: "+a.terminalId,type:"success"})}function j(a){var b="";switch(a.alertType){case"smallThenLarge":var c=a.alertData;b=["<strong>Card Number:</strong> "+c.fullCcNum+"<br/>","<strong>Zip Code:</strong> "+c.zipCode+"<b
 r/>","<strong>Merchant:</strong> "+c.merchantId+" ("+c.merchantType.toLowerCase().replace("_"," ")+")<br/>","<strong>Small Amount:</strong> $"+k(c.small)+"<br/>","<strong>Large Amount:</strong> $"+k(c.large)+"<br/>","<strong>Threshold:</strong> $"+k(c.threshold)+"<br/>","<strong>Time:</strong> "+new Date(1*c.time).toLocaleString()+"<br/>"].join("");break;case"sameBankId":var c=a.alertData;b=["<strong>Transaction Count:</strong> "+c.count+"<br/>","<strong>Bank ID Number:</strong> "+c.bankIdNum+"<br/>","<strong>Zip Code:</strong> "+c.zipCode+"<br/>","<strong>Merchant:</strong> "+c.merchantId+" ("+c.merchantType.toLowerCase().replace("_"," ")+")<br/>","<strong>Terminal:</strong> "+c.terminalId+"<br/>","<strong>Time:</strong> "+new Date(1*c.time).toLocaleString()+"<br/>"].join("");break;case"aboveAvg":var c=a.alertData;b=["<strong>Dollar Amount:</strong> $"+k(c.amount)+"<br/>","<strong>Last Average:</strong> $"+k(c.lastSmaValue)+"<br/>","<strong>Difference:</strong> $"+k(c.change)+"<br/
 >","<strong>Zip Code:</strong> "+c.zipCode+"<br/>","<strong>Merchant:</strong> "+c.merchantId+" ("+c.merchantType.toLowerCase().replace("_"," ")+")<br/>","<strong>Terminal:</strong> "+c.terminalId+"<br/>","<strong>Time:</strong> "+new Date(1*c.time).toLocaleString()+"<br/>"].join("")}return b}function k(a){return a=(1*a).toFixed(2),l(a)}function l(a){var b=a.toString().split(".");return b[0]=b[0].replace(/\B(?=(\d{3})+(?!\d))/g,","),b.join(".")}function m(){p||(a.startedTime?$.get("/fraud/alertCount?since="+a.startedTime).done(function(b){var c=_.find(a.stats,function(a){return"numFrauds"==a.id}),d=_.reduce(b,function(a,b){return a+b},0);c.value=l(d),setTimeout(m,2e3)}):setTimeout(m,2e3))}var n="demos.app.frauddetect.submitTransaction",o=b.getApp(settings.fraud.appName);o.then(function(b){a.app=b,a.appURL=settings.appsURL+b.id,a.startedTime=b.startedTime}),a.alertTypeTitles={smallThenLarge:"Suspicious Transaction Sequence",sameCard:"Same Card Multiple Times",sameBankId:"Same Bank Nu
 mber Multiple Times",aboveAvg:"Above Average Transaction"},a.stats=[{id:"totalTxns",topic:"demos.app.frauddetect.totalTransactions",value:0,label:"Total Txns"},{id:"amtInLastSecond",topic:"demos.app.frauddetect.txLastSecond",value:0,label:"Total Dollars / sec"},{id:"avgAmtInLastSecond",topic:"demos.app.frauddetect.avgLastSecond",value:0,label:"Avg Txn Amount / sec"},{id:"numFrauds",topic:"demos.app.frauddetect.totalFrauds",value:0,label:"No. of Anomalies Detected"}],a.merchants=["Wal-Mart","Target","Amazon","Apple","Sears","Macys","JCPenny","Levis"],a.terminals=[1,2,3,4,5,6,7,8],a.zips=[94086,94087,94088,94089,94090,94091,94092,94093],a.actions=[{id:1,subtitle:a.alertTypeTitles.smallThenLarge,severity:"low",description:"This anomaly is when one credit card is used for a small purchase, then immediately again for a larger purchase. The idea here is that a scammer will first try a small purchase to ensure that the card works, then proceed with a larger purchase upon success.",generate
 Txns:function(){var a=f(),b=g();i({zipCode:d("zips"),merchantId:d("merchants"),terminalId:d("terminals"),bankIdNum:a,ccNum:b,amount:5}),setTimeout(function(){i({zipCode:d("zips"),merchantId:d("merchants"),terminalId:d("terminals"),bankIdNum:a,ccNum:b,amount:600})},5e3)}},{id:2,subtitle:a.alertTypeTitles.sameBankId,severity:"high",description:"This anomaly is detected when several transactions are made by cards issued by the same bank at the same terminal ID over moving window of 30 sec.",generateTxns:function(){var a=f().replace(/\d{4}$/,"1111"),b=d("zips"),c=d("terminals"),h=d("merchants"),j=setInterval(function(){i({zipCode:b,merchantId:h,terminalId:c,bankIdNum:a,ccNum:g(),amount:e(100+10*Math.random())},!0)},200);$.pnotify({title:"Several Transactions Being Sent",text:"<strong>Bank ID:</strong> "+a+", <strong>Merchant:</strong> "+h,type:"success"}),setTimeout(function(){clearInterval(j)},11e3)}},{id:3,subtitle:a.alertTypeTitles.aboveAvg,severity:"medium",description:"This anomaly
  is when a transaction at a given merchant significantly exceeds that merchant's average transaction amount.",generateTxns:function(){console.log("getting randomStats"),$.pnotify({type:"info",title:"Retrieving Average Information"}),$.get("/fraud/randomStats").done(function(a){var b=(f(),a.merchantId),c=a.terminalId,d=a.zipCode,h=e(a.sma+1500);setTimeout(function(){i({zipCode:d,merchantId:b,terminalId:c,bankIdNum:f(),ccNum:g(),amount:h})},1e3)})}}],o.then(function(){c.subscribe("demos.app.frauddetect.fraudAlert",function(a){"aboveAvg"===a.data.alertType&&console.log("aboveAvg",a.data),("true"===a.data.userGenerated||a.data.userGenerated===!0)&&h(a.data)},a),c.subscribe("demos.app.frauddetect.txSummary",function(b){var c=b.data;_.each(["amtInLastSecond","avgAmtInLastSecond","totalTxns","txnsInLastSecond"],function(b){var d=_.find(a.stats,function(a){return a.id==b});d&&(d.value=["amtInLastSecond","avgAmtInLastSecond"].indexOf(b)>-1?"$"+k(c[b]):l(c[b]))}),a.$apply()},a)}),a.stats.forE
 ach(function(b){c.subscribe(b.topic,function(c){console.log("stat topic "+b.topic+" data received: ",c),b.value=c.value,a.$apply()},a)}),a.alerts=[];var p=!1;$("#alertDisplayBox").on("click",".view-txn-btn",function(b){b.preventDefault();var c=$(this).attr("data-txidx"),d=a.alerts[c];$("#txn-modal .modal-body").html(j(d)),$("#txn-modal").modal()}),m(),a.clearFrauds=function(){$("#alertDisplayBox").html("")},a.$on("$destroy",function(){p=!0}.bind(this))}])}();