make-mp-data 1.4.3 → 1.4.4
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/core/chart.js +11 -4
- package/core/cli.js +83 -5
- package/package.json +1 -1
package/core/chart.js
CHANGED
|
@@ -3,8 +3,15 @@ const fs = require('fs');
|
|
|
3
3
|
const u = require('ak-tools');
|
|
4
4
|
const dayjs = require('dayjs');
|
|
5
5
|
const { openFinder } = require('./utils');
|
|
6
|
+
const { existsSync } = fs;
|
|
7
|
+
const path = require('path');
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
let tempDir;
|
|
11
|
+
const dataFolder = path.resolve("./data");
|
|
12
|
+
if (existsSync(dataFolder)) tempDir = dataFolder;
|
|
13
|
+
else tempDir = path.resolve("./");
|
|
6
14
|
|
|
7
|
-
const tempDir = u.mkdir('./tmp');
|
|
8
15
|
|
|
9
16
|
// Function to count events per day
|
|
10
17
|
function countDailyEvents(eventData) {
|
|
@@ -168,9 +175,9 @@ async function generateLineChart(rawData, signupEvents = ["sign up"], fileName)
|
|
|
168
175
|
if (typeof fileName !== 'string') fileName = 'chart';
|
|
169
176
|
// @ts-ignore
|
|
170
177
|
const imageBuffer = await chartJSNodeCanvas.renderToBuffer(configuration);
|
|
171
|
-
const
|
|
172
|
-
const removed = await u.rm(
|
|
173
|
-
const file = await u.touch(
|
|
178
|
+
const filePath = path.join(tempDir, `${fileName}.png`);
|
|
179
|
+
const removed = await u.rm(filePath);
|
|
180
|
+
const file = await u.touch(filePath, imageBuffer);
|
|
174
181
|
|
|
175
182
|
console.log(`Chart saved as ${fileName}.png`);
|
|
176
183
|
openFinder(path)
|
package/core/cli.js
CHANGED
|
@@ -66,6 +66,18 @@ DATA MODEL: https://github.com/ak--47/make-mp-data/blob/main/default.js
|
|
|
66
66
|
describe: 'number of events to model',
|
|
67
67
|
type: 'number',
|
|
68
68
|
})
|
|
69
|
+
.option("epochStart", {
|
|
70
|
+
alias: 'start',
|
|
71
|
+
demandOption: false,
|
|
72
|
+
describe: 'start epoch time',
|
|
73
|
+
type: 'number',
|
|
74
|
+
})
|
|
75
|
+
.option("epochEnd", {
|
|
76
|
+
alias: 'end',
|
|
77
|
+
demandOption: false,
|
|
78
|
+
describe: 'end epoch time',
|
|
79
|
+
type: 'number',
|
|
80
|
+
})
|
|
69
81
|
.option("region", {
|
|
70
82
|
demandOption: false,
|
|
71
83
|
default: 'US',
|
|
@@ -105,16 +117,82 @@ DATA MODEL: https://github.com/ak--47/make-mp-data/blob/main/default.js
|
|
|
105
117
|
type: 'boolean',
|
|
106
118
|
coerce: boolCoerce
|
|
107
119
|
})
|
|
108
|
-
|
|
120
|
+
.option("verbose", {
|
|
121
|
+
alias: 'v',
|
|
122
|
+
demandOption: false,
|
|
123
|
+
describe: 'enable verbose logging',
|
|
124
|
+
type: 'boolean',
|
|
125
|
+
coerce: boolCoerce
|
|
126
|
+
})
|
|
127
|
+
.option("makeChart", {
|
|
128
|
+
alias: 'mc',
|
|
129
|
+
demandOption: false,
|
|
130
|
+
describe: 'create a PNG chart from data',
|
|
131
|
+
type: 'boolean',
|
|
132
|
+
coerce: boolCoerce
|
|
133
|
+
})
|
|
134
|
+
.option("hasAdSpend", {
|
|
135
|
+
alias: 'ads',
|
|
136
|
+
demandOption: false,
|
|
137
|
+
describe: 'include ad spend data',
|
|
138
|
+
type: 'boolean',
|
|
139
|
+
coerce: boolCoerce
|
|
140
|
+
})
|
|
141
|
+
.option("hasCampaigns", {
|
|
142
|
+
alias: 'camp',
|
|
143
|
+
demandOption: false,
|
|
144
|
+
describe: 'include campaign data',
|
|
145
|
+
type: 'boolean',
|
|
146
|
+
coerce: boolCoerce
|
|
147
|
+
})
|
|
148
|
+
.option("hasLocation", {
|
|
149
|
+
alias: 'loc',
|
|
150
|
+
demandOption: false,
|
|
151
|
+
describe: 'include location data',
|
|
152
|
+
type: 'boolean',
|
|
153
|
+
coerce: boolCoerce
|
|
154
|
+
})
|
|
155
|
+
.option("isAnonymous", {
|
|
156
|
+
alias: 'anon',
|
|
157
|
+
demandOption: false,
|
|
158
|
+
describe: 'generate anonymous data',
|
|
159
|
+
type: 'boolean',
|
|
160
|
+
coerce: boolCoerce
|
|
161
|
+
})
|
|
162
|
+
.option("hasBrowser", {
|
|
163
|
+
alias: 'browser',
|
|
164
|
+
demandOption: false,
|
|
165
|
+
describe: 'include browser data',
|
|
166
|
+
type: 'boolean',
|
|
167
|
+
coerce: boolCoerce
|
|
168
|
+
})
|
|
169
|
+
.option("hasAndroidDevices", {
|
|
170
|
+
alias: 'android',
|
|
171
|
+
demandOption: false,
|
|
172
|
+
describe: 'include Android device data',
|
|
173
|
+
type: 'boolean',
|
|
174
|
+
coerce: boolCoerce
|
|
175
|
+
})
|
|
176
|
+
.option("hasDesktopDevices", {
|
|
177
|
+
alias: 'desktop',
|
|
178
|
+
demandOption: false,
|
|
179
|
+
describe: 'include desktop device data',
|
|
180
|
+
type: 'boolean',
|
|
181
|
+
coerce: boolCoerce
|
|
182
|
+
})
|
|
183
|
+
.option("hasIOSDevices", {
|
|
184
|
+
alias: 'ios',
|
|
185
|
+
demandOption: false,
|
|
186
|
+
describe: 'include iOS device data',
|
|
187
|
+
type: 'boolean',
|
|
188
|
+
coerce: boolCoerce
|
|
189
|
+
})
|
|
109
190
|
.help()
|
|
110
191
|
.wrap(null)
|
|
111
192
|
.argv;
|
|
112
193
|
|
|
113
|
-
// if (args._.length === 0 && !args.type?.toLowerCase()?.includes('export')) {
|
|
114
|
-
// yargs.showHelp();
|
|
115
|
-
// process.exit();
|
|
116
|
-
// }
|
|
117
194
|
return args;
|
|
195
|
+
|
|
118
196
|
}
|
|
119
197
|
|
|
120
198
|
|