survey-analytics
Version:
SurveyJS Dashboard is a UI component for visualizing and analyzing survey data. It interprets the form JSON schema to identify question types and renders collected responses using interactive charts and tables.
2 lines • 3.78 kB
JavaScript
/*! For license information please see survey.analytics.mongo.min.js.LICENSE.txt */
!function(t,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define("SurveyAnalyticsMongo",[],n):"object"==typeof exports?exports.SurveyAnalyticsMongo=n():t.SurveyAnalyticsMongo=n()}(this,(()=>(()=>{"use strict";var t={d:(n,e)=>{for(var o in e)t.o(e,o)&&!t.o(n,o)&&Object.defineProperty(n,o,{enumerable:!0,get:e[o]})},o:(t,n)=>Object.prototype.hasOwnProperty.call(t,n),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},n={};function e(t){var n={},e=0;return t.forEach((function(t){n[t._id]=t.count,e+=t.count})),{data:n,totalCount:e}}function o(t){return 0==t.length?{value:0,minValue:0,maxValue:0}:{data:{value:t[0].average,minValue:t[0].min,maxValue:t[0].max}}}t.r(n),t.d(n,{MongoDbAdapter:()=>u});var i={boolean:e,radiogroup:e,dropdown:e,checkbox:e,tagbox:e,number:o,rating:o,histogram:function(t){var n=[],e=0;return t.forEach((function(t){n.push(t.count),e+=t.count})),{data:n,intervals:t,totalCount:e}}},u=function(){function t(t,n){this.db=t,this.getId=n}return t.prototype.create=function(t,n){var e=this;return n.id=n.id||this.getId(),new Promise((function(o,i){e.db.collection(t).insertOne(n).then((function(t){o(n.id)})).catch((function(t){i(JSON.stringify(t))}))}))},t.prototype.retrieve=function(t,n){var e=this,o={};return(n=n||[]).forEach((function(t){return o[t.field]=t.value})),new Promise((function(n,i){e.db.collection(t).find(o).toArray().then((function(t){n(t)})).catch((function(t){i(JSON.stringify(t))}))}))},t.prototype.update=function(t,n){var e=this;return new Promise((function(o,i){e.db.collection(t).updateOne({id:n.id},{$set:n}).then((function(t){o(t)})).catch((function(t){i(JSON.stringify(t))}))}))},t.prototype.delete=function(t,n){var e=this;return new Promise((function(o,i){e.db.collection(t).deleteMany({id:n}).then((function(t){o(t)})).catch((function(t){i(JSON.stringify(t))}))}))},t.prototype.retrievePaginated=function(t,n,e,o,i){var u=this,r={};(n=n||[]).forEach((function(t){if(t.value){var n=t.value;r[t.field]=n}}));var a={};return e.forEach((function(t){a[t.field]="desc"==t.value?-1:1})),new Promise((function(n,e){u.db.collection(t).count(r).then((function(c){u.db.collection(t).find(r).sort(a).skip(o).limit(i).toArray().then((function(t){n({data:t,totalCount:c})})).catch((function(t){e(JSON.stringify(t))}))}))}))},t.prototype.retrieveSummary=function(t,n,e,o,u,r){var a=this,c=function(t,n,e,o){var i=[{$match:{postid:t}},{$project:{value:"$json."+n}},{$match:{value:{$exists:!0}}},{$group:{_id:"$value",count:{$sum:1}}}],u=[{$match:{postid:t}},{$project:{value:"$json."+n}},{$match:{value:{$exists:!0}}},{$unwind:"$value"},{$group:{_id:"$value",count:{$sum:1}}}],r=[{$match:{postid:t}},{$project:{value:"$json."+n}},{$match:{value:{$exists:!0}}},{$group:{_id:null,count:{$sum:1},average:{$avg:"$value"},min:{$min:"$value"},max:{$max:"$value"},values:{$push:"$value"}}}],a={boolean:i,radiogroup:i,dropdown:i,checkbox:u,tagbox:u,number:r,rating:r,histogram:[{$match:{postid:t}},{$project:{value:"$json."+n}},{$match:{value:{$exists:!0}}},{$bucketAuto:{groupBy:"$value",buckets:10,output:{count:{$sum:1},minValue:{$min:"$value"},maxValue:{$max:"$value"}}}},{$project:{_id:0,start:"$minValue",end:"$maxValue",label:{$concat:[{$toString:{$round:["$minValue",2]}}," - ",{$toString:{$round:["$maxValue",2]}}]},count:1}}]};return a[e]||a[o]||[]}(n,e,u,o);return new Promise((function(n,e){a.db.collection(t).aggregate(c).toArray().then((function(t){var e=(i[u]||i[o]||function(t){return t})(t);n(e)})).catch((function(t){e(JSON.stringify(t))}))}))},t}();return n})()));