@monterosa/sdk-lvis 0.18.0 → 0.18.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.js +9 -65
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm2017.js +4 -54
- package/dist/index.esm2017.js.map +1 -1
- package/dist/index.esm5.js +4 -64
- package/dist/index.esm5.js.map +1 -1
- package/package.json +4 -4
package/dist/index.cjs.js
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
+
var sdkUtil = require('@monterosa/sdk-util');
|
|
5
6
|
var Enmasse = require('@monterosa/sdk-enmasse-kit');
|
|
6
7
|
var $script = require('scriptjs');
|
|
7
8
|
var Deferred = require('Deferred');
|
|
8
9
|
var xhr = require('xhr');
|
|
9
10
|
var Emitter = require('tiny-emitter');
|
|
10
11
|
var assignIn = require('lodash.assignin');
|
|
11
|
-
var sdkUtil = require('@monterosa/sdk-util');
|
|
12
12
|
var Cookie = require('js-cookie');
|
|
13
13
|
|
|
14
14
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
@@ -21,7 +21,7 @@ var Emitter__default = /*#__PURE__*/_interopDefaultLegacy(Emitter);
|
|
|
21
21
|
var assignIn__default = /*#__PURE__*/_interopDefaultLegacy(assignIn);
|
|
22
22
|
var Cookie__default = /*#__PURE__*/_interopDefaultLegacy(Cookie);
|
|
23
23
|
|
|
24
|
-
var version = "0.18.
|
|
24
|
+
var version = "0.18.1";
|
|
25
25
|
|
|
26
26
|
const LViSDate = new Emitter__default["default"]();
|
|
27
27
|
|
|
@@ -1157,65 +1157,6 @@ class Frame extends Entity {
|
|
|
1157
1157
|
}
|
|
1158
1158
|
}
|
|
1159
1159
|
|
|
1160
|
-
const calculatePercentage = (values) => {
|
|
1161
|
-
// create array of hashes
|
|
1162
|
-
const results = values.map((value, idx) => ({
|
|
1163
|
-
idx,
|
|
1164
|
-
votes: value,
|
|
1165
|
-
percentage: 0,
|
|
1166
|
-
}));
|
|
1167
|
-
|
|
1168
|
-
// Calculate sum of all votes
|
|
1169
|
-
const sum = results.reduce((memo, item) => memo + item.votes, 0);
|
|
1170
|
-
|
|
1171
|
-
// Calculate percentages
|
|
1172
|
-
results.forEach((item) => {
|
|
1173
|
-
item.percentage = Math.round((100 * item.votes) / sum) || 0;
|
|
1174
|
-
});
|
|
1175
|
-
|
|
1176
|
-
// Sum them all up - this can be less, equal or greater than a 100%
|
|
1177
|
-
let total = results.reduce((memo, item) => memo + item.percentage, 0);
|
|
1178
|
-
|
|
1179
|
-
total = total || 100;
|
|
1180
|
-
|
|
1181
|
-
// Calculate number of percent that we are missing or that we need to lose
|
|
1182
|
-
let delta = 100 - total;
|
|
1183
|
-
const sign = delta >= 0 ? 1 : -1;
|
|
1184
|
-
|
|
1185
|
-
// Order all options by number of votes
|
|
1186
|
-
results.sort((a, b) => {
|
|
1187
|
-
const result = sign * (b.votes - a.votes);
|
|
1188
|
-
|
|
1189
|
-
if (result !== 0) {
|
|
1190
|
-
return result;
|
|
1191
|
-
}
|
|
1192
|
-
|
|
1193
|
-
return sign * (a.idx - b.idx);
|
|
1194
|
-
});
|
|
1195
|
-
|
|
1196
|
-
// If we have percents to lose then take one percent off lowest options
|
|
1197
|
-
// If we are missing percents then add one percent to highest options
|
|
1198
|
-
let i = 0;
|
|
1199
|
-
while (delta !== 0) {
|
|
1200
|
-
if (results[i].votes > 0) {
|
|
1201
|
-
results[i].percentage += sign;
|
|
1202
|
-
delta -= sign;
|
|
1203
|
-
}
|
|
1204
|
-
|
|
1205
|
-
i++;
|
|
1206
|
-
}
|
|
1207
|
-
|
|
1208
|
-
// Restore options order
|
|
1209
|
-
results.sort((a, b) => a.idx - b.idx);
|
|
1210
|
-
|
|
1211
|
-
// Remove indices
|
|
1212
|
-
results.forEach((item) => {
|
|
1213
|
-
delete item.idx;
|
|
1214
|
-
});
|
|
1215
|
-
|
|
1216
|
-
return results.map((item) => item.percentage);
|
|
1217
|
-
};
|
|
1218
|
-
|
|
1219
1160
|
class Poll extends Frame {
|
|
1220
1161
|
static EXPIRE = 7 * 24 * 60 * 60;
|
|
1221
1162
|
|
|
@@ -1360,7 +1301,7 @@ class Poll extends Frame {
|
|
|
1360
1301
|
|
|
1361
1302
|
// TODO: Combine populateResults() and populateResultsFromSnapshot() methods
|
|
1362
1303
|
populateResults(results) {
|
|
1363
|
-
const percentage = calculatePercentage(results);
|
|
1304
|
+
const percentage = sdkUtil.calculatePercentage(results);
|
|
1364
1305
|
|
|
1365
1306
|
this.results = results.map((votes, idx) => ({
|
|
1366
1307
|
votes,
|
|
@@ -1372,7 +1313,7 @@ class Poll extends Frame {
|
|
|
1372
1313
|
this.resultsPerSource = results;
|
|
1373
1314
|
|
|
1374
1315
|
this.resultsPerSource.forEach((source) => {
|
|
1375
|
-
const percentage = calculatePercentage(source.results);
|
|
1316
|
+
const percentage = sdkUtil.calculatePercentage(source.results);
|
|
1376
1317
|
|
|
1377
1318
|
source.results = source.results.map((votes, idx) => ({
|
|
1378
1319
|
votes,
|
|
@@ -3399,7 +3340,7 @@ LViS.Sync = Sync;
|
|
|
3399
3340
|
LViS.Enmasse = Enmasse__default["default"];
|
|
3400
3341
|
LViS.ConnectionAdaptor = ConnectionAdaptor;
|
|
3401
3342
|
LViS.ConnectionManager = Enmasse__default["default"];
|
|
3402
|
-
LViS.calculatePercentage = calculatePercentage;
|
|
3343
|
+
LViS.calculatePercentage = sdkUtil.calculatePercentage;
|
|
3403
3344
|
|
|
3404
3345
|
LViS.BaseFactory = Base;
|
|
3405
3346
|
LViS.FrameFactory = FrameFactory;
|
|
@@ -3808,6 +3749,10 @@ LViS.unsetEvent = unsetEvent;
|
|
|
3808
3749
|
LViS.resetEvent = resetEvent;
|
|
3809
3750
|
LViS.init = init;
|
|
3810
3751
|
|
|
3752
|
+
Object.defineProperty(exports, 'calculatePercentage', {
|
|
3753
|
+
enumerable: true,
|
|
3754
|
+
get: function () { return sdkUtil.calculatePercentage; }
|
|
3755
|
+
});
|
|
3811
3756
|
Object.defineProperty(exports, 'ConnectionManager', {
|
|
3812
3757
|
enumerable: true,
|
|
3813
3758
|
get: function () { return Enmasse__default["default"]; }
|
|
@@ -3856,7 +3801,6 @@ exports.Trivia = Trivia;
|
|
|
3856
3801
|
exports.User = User;
|
|
3857
3802
|
exports.VERSION = version;
|
|
3858
3803
|
exports.bind = bind;
|
|
3859
|
-
exports.calculatePercentage = calculatePercentage;
|
|
3860
3804
|
exports["default"] = LViS;
|
|
3861
3805
|
exports.getAssets = getAssets;
|
|
3862
3806
|
exports.getEvent = getEvent;
|