@naturalcycles/abba 1.17.2 → 1.18.0
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/abba.d.ts +3 -3
- package/dist/abba.js +14 -4
- package/package.json +1 -1
- package/readme.md +1 -1
- package/src/abba.ts +15 -5
package/dist/abba.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { AbbaConfig, Bucket, Experiment, ExperimentAssignmentStatistics, ExperimentWithBuckets, GeneratedUserAssignment, UserAssignment } from './types';
|
|
1
|
+
import { AbbaConfig, Bucket, Experiment, ExperimentAssignmentStatistics, ExperimentWithBuckets, GeneratedUserAssignment } from './types';
|
|
3
2
|
import { SegmentationData } from '.';
|
|
4
3
|
export declare class Abba {
|
|
5
4
|
cfg: AbbaConfig;
|
|
@@ -49,8 +48,9 @@ export declare class Abba {
|
|
|
49
48
|
* Get all existing user assignments.
|
|
50
49
|
* Hot method.
|
|
51
50
|
* Not cached, because Assignments are fast-changing.
|
|
51
|
+
* Only to be used for testing
|
|
52
52
|
*/
|
|
53
|
-
|
|
53
|
+
getAllExistingGeneratedUserAssignments(userId: string): Promise<GeneratedUserAssignment[]>;
|
|
54
54
|
/**
|
|
55
55
|
* Generate user assignments for all active experiments.
|
|
56
56
|
* Will return any existing and attempt to generate any new assignments if existingOnly is false.
|
package/dist/abba.js
CHANGED
|
@@ -116,7 +116,7 @@ class Abba {
|
|
|
116
116
|
if (experiment.status === types_1.AssignmentStatus.Inactive)
|
|
117
117
|
return null;
|
|
118
118
|
const buckets = await this.bucketDao.getBy('experimentId', experiment.id);
|
|
119
|
-
const existingAssignments = await this.
|
|
119
|
+
const existingAssignments = await this.userAssignmentDao.getBy('userId', userId);
|
|
120
120
|
const existing = existingAssignments.find(a => a.experimentId === experiment.id);
|
|
121
121
|
if (existing) {
|
|
122
122
|
return {
|
|
@@ -148,9 +148,19 @@ class Abba {
|
|
|
148
148
|
* Get all existing user assignments.
|
|
149
149
|
* Hot method.
|
|
150
150
|
* Not cached, because Assignments are fast-changing.
|
|
151
|
+
* Only to be used for testing
|
|
151
152
|
*/
|
|
152
|
-
async
|
|
153
|
-
|
|
153
|
+
async getAllExistingGeneratedUserAssignments(userId) {
|
|
154
|
+
const assignments = await this.userAssignmentDao.getBy('userId', userId);
|
|
155
|
+
return await (0, js_lib_1.pMap)(assignments, async (assignment) => {
|
|
156
|
+
const experiment = await this.experimentDao.requireById(assignment.experimentId);
|
|
157
|
+
const bucket = await this.bucketDao.getById(assignment.bucketId);
|
|
158
|
+
return {
|
|
159
|
+
...assignment,
|
|
160
|
+
experimentKey: experiment.key,
|
|
161
|
+
bucketKey: bucket?.key || null,
|
|
162
|
+
};
|
|
163
|
+
});
|
|
154
164
|
}
|
|
155
165
|
/**
|
|
156
166
|
* Generate user assignments for all active experiments.
|
|
@@ -159,7 +169,7 @@ class Abba {
|
|
|
159
169
|
*/
|
|
160
170
|
async generateUserAssignments(userId, segmentationData, existingOnly = false) {
|
|
161
171
|
const experiments = await this.getAllExperiments();
|
|
162
|
-
const existingAssignments = await this.
|
|
172
|
+
const existingAssignments = await this.userAssignmentDao.getBy('userId', userId);
|
|
163
173
|
const exclusionSet = (0, util_1.getUserExclusionSet)(experiments, existingAssignments);
|
|
164
174
|
const assignments = [];
|
|
165
175
|
const newAssignments = [];
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -293,7 +293,7 @@ Example segmentation data:
|
|
|
293
293
|
|
|
294
294
|
<div id="exclusion"></div>
|
|
295
295
|
|
|
296
|
-
## Mutual
|
|
296
|
+
## Mutual Exclusion
|
|
297
297
|
|
|
298
298
|
Mutual exclusion is configured per-experiment. If an experiment is listed as mutually exclusive with
|
|
299
299
|
another experiment(s) then new assignments will only be generated with one of the experiments and
|
package/src/abba.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _assert, _AsyncMemo, _shuffle, pMap
|
|
1
|
+
import { _assert, _AsyncMemo, _shuffle, pMap } from '@naturalcycles/js-lib'
|
|
2
2
|
import { LRUMemoCache } from '@naturalcycles/nodejs-lib'
|
|
3
3
|
import { bucketDao } from './dao/bucket.dao'
|
|
4
4
|
import { experimentDao } from './dao/experiment.dao'
|
|
@@ -164,7 +164,7 @@ export class Abba {
|
|
|
164
164
|
if (experiment.status === AssignmentStatus.Inactive) return null
|
|
165
165
|
|
|
166
166
|
const buckets = await this.bucketDao.getBy('experimentId', experiment.id)
|
|
167
|
-
const existingAssignments = await this.
|
|
167
|
+
const existingAssignments = await this.userAssignmentDao.getBy('userId', userId)
|
|
168
168
|
const existing = existingAssignments.find(a => a.experimentId === experiment.id)
|
|
169
169
|
if (existing) {
|
|
170
170
|
return {
|
|
@@ -200,9 +200,19 @@ export class Abba {
|
|
|
200
200
|
* Get all existing user assignments.
|
|
201
201
|
* Hot method.
|
|
202
202
|
* Not cached, because Assignments are fast-changing.
|
|
203
|
+
* Only to be used for testing
|
|
203
204
|
*/
|
|
204
|
-
async
|
|
205
|
-
|
|
205
|
+
async getAllExistingGeneratedUserAssignments(userId: string): Promise<GeneratedUserAssignment[]> {
|
|
206
|
+
const assignments = await this.userAssignmentDao.getBy('userId', userId)
|
|
207
|
+
return await pMap(assignments, async assignment => {
|
|
208
|
+
const experiment = await this.experimentDao.requireById(assignment.experimentId)
|
|
209
|
+
const bucket = await this.bucketDao.getById(assignment.bucketId)
|
|
210
|
+
return {
|
|
211
|
+
...assignment,
|
|
212
|
+
experimentKey: experiment.key,
|
|
213
|
+
bucketKey: bucket?.key || null,
|
|
214
|
+
}
|
|
215
|
+
})
|
|
206
216
|
}
|
|
207
217
|
|
|
208
218
|
/**
|
|
@@ -216,7 +226,7 @@ export class Abba {
|
|
|
216
226
|
existingOnly = false,
|
|
217
227
|
): Promise<GeneratedUserAssignment[]> {
|
|
218
228
|
const experiments = await this.getAllExperiments()
|
|
219
|
-
const existingAssignments = await this.
|
|
229
|
+
const existingAssignments = await this.userAssignmentDao.getBy('userId', userId)
|
|
220
230
|
const exclusionSet = getUserExclusionSet(experiments, existingAssignments)
|
|
221
231
|
const assignments: GeneratedUserAssignment[] = []
|
|
222
232
|
const newAssignments: UserAssignment[] = []
|