make-mp-data 1.3.4 → 1.4.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/testCases.mjs ADDED
@@ -0,0 +1,229 @@
1
+ const TEST_CASES = [
2
+ //defaults
3
+ {
4
+ name: "default",
5
+ mean: 0,
6
+ deviation: 2,
7
+ peaks: 5,
8
+ },
9
+
10
+ // test deviation low to high
11
+ {
12
+ name: "dev-negative",
13
+ mean: 0,
14
+ deviation: -2,
15
+ peaks: 5,
16
+ },
17
+ {
18
+ name: "dev-one",
19
+ mean: 0,
20
+ deviation: 1,
21
+ peaks: 5,
22
+ },
23
+ {
24
+ name: "dev-high",
25
+ mean: 0,
26
+ deviation: 10,
27
+ peaks: 5,
28
+ },
29
+ {
30
+ name: "dev-one-half",
31
+ mean: 0,
32
+ deviation: .5,
33
+ peaks: 5,
34
+ },
35
+ {
36
+ name: "dev-small-decimal",
37
+ mean: 0,
38
+ deviation: .01,
39
+ peaks: 5,
40
+ },
41
+
42
+ // test mean low to high
43
+ {
44
+ name: "mean-negative",
45
+ mean: -2,
46
+ deviation: 2,
47
+ peaks: 5,
48
+ },
49
+ {
50
+ name: "mean-zero",
51
+ mean: 0,
52
+ deviation: 2,
53
+ peaks: 5,
54
+ },
55
+ {
56
+ name: "mean-positive",
57
+ mean: 2,
58
+ deviation: 2,
59
+ peaks: 5,
60
+ },
61
+ {
62
+ name: "mean-high",
63
+ mean: 10,
64
+ deviation: 2,
65
+ peaks: 5,
66
+ },
67
+ {
68
+ name: "mean-decimal",
69
+ mean: .01,
70
+ deviation: 2,
71
+ peaks: 5,
72
+ },
73
+ {
74
+ name: "mean-one-half",
75
+ mean: .05,
76
+ deviation: 2,
77
+ peaks: 5,
78
+ },
79
+
80
+ // test peaks low to high
81
+ {
82
+ name: "peaks-zero",
83
+ mean: 0,
84
+ deviation: 2,
85
+ peaks: 0,
86
+ },
87
+ {
88
+ name: "peaks-positive",
89
+ mean: 0,
90
+ deviation: 2,
91
+ peaks: 5,
92
+ },
93
+ {
94
+ name: "peaks-high",
95
+ mean: 0,
96
+ deviation: 2,
97
+ peaks: 10,
98
+ },
99
+ // Extreme Deviation and Low Peaks
100
+ {
101
+ name: "extreme-deviation-low-peaks",
102
+ mean: 0,
103
+ deviation: 50,
104
+ peaks: 2,
105
+ },
106
+
107
+ // Negative Mean and Low Deviation
108
+ {
109
+ name: "negative-mean-low-deviation",
110
+ mean: -10,
111
+ deviation: 0.5,
112
+ peaks: 3,
113
+ },
114
+
115
+ // Positive Mean and High Peaks
116
+ {
117
+ name: "positive-mean-high-peaks",
118
+ mean: 10,
119
+ deviation: 2,
120
+ peaks: 20,
121
+ },
122
+
123
+ // Small Decimal Mean and Deviation
124
+ {
125
+ name: "small-decimal-mean-deviation",
126
+ mean: 0.01,
127
+ deviation: 0.01,
128
+ peaks: 10,
129
+ },
130
+
131
+ // Large Mean and One Peak
132
+ {
133
+ name: "large-mean-one-peak",
134
+ mean: 100,
135
+ deviation: 1,
136
+ peaks: 1,
137
+ },
138
+
139
+ // Multiple Peaks with Moderate Deviation
140
+ {
141
+ name: "multiple-peaks-moderate-deviation",
142
+ mean: 5,
143
+ deviation: 5,
144
+ peaks: 10,
145
+ },
146
+
147
+ // High Mean with High Deviation
148
+ {
149
+ name: "high-mean-high-deviation",
150
+ mean: 50,
151
+ deviation: 25,
152
+ peaks: 5,
153
+ },
154
+
155
+ // Zero Mean with High Deviation and High Peaks
156
+ {
157
+ name: "zero-mean-high-deviation-high-peaks",
158
+ mean: 0,
159
+ deviation: 10,
160
+ peaks: 30,
161
+ },
162
+
163
+ // Negative Mean with High Deviation and Low Peaks
164
+ {
165
+ name: "negative-mean-high-deviation-low-peaks",
166
+ mean: -20,
167
+ deviation: 15,
168
+ peaks: 2,
169
+ },
170
+
171
+ // Mixed Values
172
+ {
173
+ name: "mixed-values",
174
+ mean: 3,
175
+ deviation: 7,
176
+ peaks: 12,
177
+ },
178
+
179
+ // Minimal Deviation and Numerous Peaks
180
+ {
181
+ name: "minimal-deviation-numerous-peaks",
182
+ mean: 0,
183
+ deviation: 0.1,
184
+ peaks: 50,
185
+ },
186
+
187
+ // Single Peak with Zero Deviation
188
+ {
189
+ name: "single-peak-huge-deviation",
190
+ mean: 0,
191
+ deviation: 20,
192
+ peaks: 1,
193
+ },
194
+
195
+ // Negative Mean, High Deviation, Multiple Peaks
196
+ {
197
+ name: "negative-mean-high-deviation-multiple-peaks",
198
+ mean: -5,
199
+ deviation: 20,
200
+ peaks: 8,
201
+ },
202
+
203
+ // Positive Mean, Low Deviation, Single Peak
204
+ {
205
+ name: "positive-mean-low-deviation-single-peak",
206
+ mean: 5,
207
+ deviation: 0.5,
208
+ peaks: 1,
209
+ },
210
+
211
+ // Very High Mean and Peaks
212
+ {
213
+ name: "very-high-mean-and-peaks",
214
+ mean: 100,
215
+ deviation: 10,
216
+ peaks: 100,
217
+ },
218
+
219
+ // High Mean with Low Peaks
220
+ {
221
+ name: "high-mean-low-peaks",
222
+ mean: 25,
223
+ deviation: 5,
224
+ peaks: 3,
225
+ }
226
+
227
+ ];
228
+
229
+ module.exports = TEST_CASES;
package/testSoup.mjs ADDED
@@ -0,0 +1,27 @@
1
+ import { generateLineChart } from './chart.js';
2
+ import { TimeSoup } from './utils.js';
3
+ import dayjs from 'dayjs';
4
+ import { progress } from 'ak-tools';
5
+ import TEST_CASES from './testCases.mjs';
6
+ import execSync from 'child_process';
7
+
8
+ async function genViz(soup) {
9
+ const { mean = 0, deviation = 2, peaks = 5, name } = soup;
10
+ const data = [];
11
+ const start = dayjs().subtract(90, 'd').unix();
12
+ const end = dayjs().unix();
13
+ console.log(`\n\nTEST CASE: ${name}\n\n`);
14
+ for (let i = 0; i < 100_000; i++) {
15
+ progress('processing', i);
16
+ const time = TimeSoup(start, end, peaks, deviation, mean);
17
+ data.push({ time });
18
+ }
19
+
20
+ const chart = await generateLineChart(data, [], name);
21
+ return chart;
22
+ }
23
+
24
+ execSync.execSync('npm run prune');
25
+ // @ts-ignore
26
+ await Promise.all(TEST_CASES.map(genViz));
27
+ // await genViz(TEST_CASES[0]);
package/tests/e2e.test.js CHANGED
@@ -8,9 +8,9 @@ require('dotenv').config();
8
8
  const { execSync } = require("child_process");
9
9
  const u = require('ak-tools');
10
10
 
11
- const simple = require('../models/simple.js');
12
- const complex = require('../models/complex.js');
13
- const deep = require('../models/deepNest.js');
11
+ const simple = require('../schemas/simple.js');
12
+ const complex = require('../schemas/complex.js');
13
+ const deep = require('../schemas/deepNest.js');
14
14
 
15
15
  const timeout = 60000;
16
16
  const testToken = process.env.TEST_TOKEN;
@@ -25,7 +25,7 @@ describe('module', () => {
25
25
  expect(groupProfilesData.length).toBe(0);
26
26
  expect(lookupTableData.length).toBe(0);
27
27
  expect(scdTableData.length).toBe(0);
28
- expect(userProfilesData.length).toBe(100);
28
+ expect(userProfilesData.length).toBe(100);
29
29
 
30
30
  }, timeout);
31
31
 
@@ -68,12 +68,19 @@ describe('module', () => {
68
68
 
69
69
  test('fails with invalid configuration', async () => {
70
70
  try {
71
- await generate({ numUsers: -10 });
71
+ await generate({ numUsers: -10 });
72
72
  } catch (e) {
73
- expect(e).toBeDefined();
73
+ expect(e).toBeDefined();
74
74
  }
75
- }, timeout);
76
-
75
+ }, timeout);
76
+
77
+
78
+ test('works with no params', async () => {
79
+ const { eventData, userProfilesData, groupProfilesData, files, importResults, lookupTableData, mirrorEventData, scdTableData } = await generate({ writeToDisk: false });
80
+ debugger;
81
+ }, timeout);
82
+
83
+
77
84
 
78
85
 
79
86
  });
@@ -99,7 +106,7 @@ describe('cli', () => {
99
106
 
100
107
  test('works as CLI (custom)', async () => {
101
108
  console.log('custom CLI TEST');
102
- const run = execSync(`node ./index.js ./models/deepNest.js`);
109
+ const run = execSync(`node ./index.js ./schemas/deepNest.js`);
103
110
  expect(run.toString().trim().includes('have a wonderful day :)')).toBe(true);
104
111
  const csvs = (await u.ls('./data')).filter(a => a.includes('.csv'));
105
112
  expect(csvs.length).toBe(2);
@@ -113,22 +120,22 @@ describe('options + tweaks', () => {
113
120
  test('creates sessionIds', async () => {
114
121
  const results = await generate({ writeToDisk: false, numEvents: 1000, numUsers: 100, sessionIds: true });
115
122
  const { eventData } = results;
116
- const sessionIds = eventData.map(a => a.$session_id).filter(a => a);
123
+ const sessionIds = eventData.map(a => a.session_id).filter(a => a);
117
124
  expect(sessionIds.length).toBe(eventData.length);
118
125
  }, timeout);
119
126
 
120
127
  test('no sessionIds', async () => {
121
128
  const results = await generate({ writeToDisk: false, numEvents: 1000, numUsers: 100, sessionIds: false });
122
129
  const { eventData } = results;
123
- const sessionIds = eventData.map(a => a.$session_id).filter(a => a);
130
+ const sessionIds = eventData.map(a => a.session_id).filter(a => a);
124
131
  expect(sessionIds.length).toBe(0);
125
132
  }, timeout);
126
133
 
127
134
  test('creates anonymousIds', async () => {
128
135
  const results = await generate({ writeToDisk: false, numEvents: 1000, numUsers: 100, anonIds: true });
129
136
  const { eventData } = results;
130
- const anonIds = eventData.map(a => a.$device_id).filter(a => a);
131
- const userIds = eventData.map(a => a.$user_id).filter(a => a);
137
+ const anonIds = eventData.map(a => a.device_id).filter(a => a);
138
+ const userIds = eventData.map(a => a.user_id).filter(a => a);
132
139
  expect(anonIds.length).toBe(eventData.length);
133
140
  expect(userIds.length).toBeLessThan(anonIds.length);
134
141
  }, timeout);
@@ -136,14 +143,14 @@ describe('options + tweaks', () => {
136
143
  test('no anonymousIds', async () => {
137
144
  const results = await generate({ writeToDisk: false, numEvents: 1000, numUsers: 100, anonIds: false });
138
145
  const { eventData } = results;
139
- const anonIds = eventData.map(a => a.$device_id).filter(a => a);
146
+ const anonIds = eventData.map(a => a.device_id).filter(a => a);
140
147
  expect(anonIds.length).toBe(0);
141
148
  }, timeout);
142
149
 
143
150
  test('sends data to mixpanel', async () => {
144
151
  console.log('NETWORK TEST');
145
152
  const results = await generate({ verbose: true, writeToDisk: false, numEvents: 1100, numUsers: 100, seed: "deal with it", token: testToken });
146
- const { events, users, groups } = results.import;
153
+ const { events, users, groups } = results.importResults;
147
154
  expect(events.success).toBeGreaterThan(980);
148
155
  expect(users.success).toBe(100);
149
156
  expect(groups.length).toBe(0);
@@ -193,18 +200,18 @@ function clearData() {
193
200
 
194
201
  function validateEvent(event) {
195
202
  if (!event.event) return false;
196
- if (!event.$device_id && !event.$user_id) return false;
203
+ if (!event.device_id && !event.user_id) return false;
197
204
  if (!event.time) return false;
198
- if (!event.$insert_id) return false;
205
+ if (!event.insert_id) return false;
199
206
  return true;
200
207
  }
201
208
 
202
209
 
203
210
  function validateUser(user) {
204
211
  if (!user.distinct_id) return false;
205
- if (!user.$name) return false;
206
- if (!user.$email) return false;
207
- if (!user.$created) return false;
212
+ if (!user.name) return false;
213
+ if (!user.email) return false;
214
+ if (!user.created) return false;
208
215
  return true;
209
216
  }
210
217
 
@@ -0,0 +1,30 @@
1
+
2
+
3
+ const isDebugMode = process.env.NODE_OPTIONS?.includes('--inspect') || process.env.NODE_OPTIONS?.includes('--inspect-brk');
4
+
5
+ /** @type {import('jest').Config} */
6
+ const jestConfig = {
7
+ verbose: isDebugMode,
8
+ watch: false,
9
+ projects: [
10
+ {
11
+ "displayName": "e2e",
12
+ "testMatch": [
13
+ "<rootDir>/tests/e2e.test.js"
14
+ ],
15
+ // @ts-ignore
16
+ maxWorkers: 1
17
+
18
+ },
19
+ {
20
+ displayName: "unit",
21
+ testMatch: [
22
+ "<rootDir>/tests/unit.test.js"
23
+ ],
24
+ // @ts-ignore
25
+ maxWorkers: "50%"
26
+ }
27
+ ]
28
+ };
29
+
30
+ module.exports = jestConfig;