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.
7 lines (6 loc) • 3.42 kB
JavaScript
/*!
surveyjs - SurveyJS Dashboard library v2.5.35
Copyright (c) 2015-2026 Devsoft Baltic OÜ - http://surveyjs.io/
License: SEE LICENSE IN LICENSE
*/
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((t="undefined"!=typeof globalThis?globalThis:t||self).SurveyAnalyticsMongo={})}(this,function(t){"use strict";function n(t){var n={},e=0;return t.forEach(function(t){n[t._id]=t.count,e+=t.count}),{data:n,totalCount:e}}function e(t){return 0==t.length?{value:0,minValue:0,maxValue:0}:{data:{value:t[0].average,minValue:t[0].min,maxValue:t[0].max}}}var o={boolean:n,radiogroup:n,dropdown:n,checkbox:n,tagbox:n,number:e,rating:e,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}}};var i=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,a={};(n=n||[]).forEach(function(t){if(t.value){var n=t.value;a[t.field]=n}});var r={};return e.forEach(function(t){r[t.field]="desc"==t.value?-1:1}),new Promise(function(n,e){u.db.collection(t).count(a).then(function(c){u.db.collection(t).find(a).sort(r).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,i,u,a){var r=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}}}],a=[{$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"}}}],r={boolean:i,radiogroup:i,dropdown:i,checkbox:u,tagbox:u,number:a,rating:a,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 r[e]||r[o]||[]}(n,e,u,i);return new Promise(function(n,e){r.db.collection(t).aggregate(c).toArray().then(function(t){var e=(o[u]||o[i]||function(t){return t})(t);n(e)}).catch(function(t){e(JSON.stringify(t))})})},t}();t.MongoDbAdapter=i});