forked from pyrochlore/obsidian-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_generator.ts
296 lines (242 loc) · 8.54 KB
/
example_generator.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
import * as fs from "fs";
import * as path from "path";
import * as moment from "moment";
let root_folder = __dirname;
let subfolder = "diary";
let dateFormat = "YYYY-MM-DD";
let startDate = moment("2021-01-01", dateFormat);
let endDate = moment("2021-12-31", dateFormat);
let seed = 1;
function random() {
var x = Math.sin(seed++) * 10000;
return x - Math.floor(x);
}
function randomIntFromInterval(min: number, max: number) {
return Math.floor(random() * (max - min + 1) + min);
}
function randomFloatFromInterval(min: number, max: number) {
return random() * (max - min + 1) + min;
}
// Check subfolder exists
let subfolderPath = path.join(root_folder, subfolder);
if (!fs.existsSync(subfolderPath)) {
fs.mkdirSync(subfolderPath);
}
let dayCount = 0;
for (
let curDate = startDate.clone();
curDate <= endDate;
curDate.add(1, "days")
) {
dayCount++;
let fileName = curDate.format(dateFormat);
let filePath = path.join(subfolderPath, fileName + ".md");
let fh = fs.openSync(filePath, "w+");
let content: string = "";
// fontmatter
let frontmatter = "---\n";
// front matter tags
let weekday = curDate.weekday();
if (weekday == 0 || weekday == 6) {
frontmatter += "tags: " + "\n";
} else {
frontmatter += "tags: " + "work_log" + ", " + "work_log2" + "\n";
}
// frontmatter mood
let moodSymbols = ["😀", "🙂", "😐", "🙁", "😞"];
let indMood = randomIntFromInterval(0, 4);
frontmatter += "mood: " + moodSymbols[indMood] + "\n";
// blood pressure
let progress = dayCount;
if (progress > 100) {
progress = 100;
}
let systolicStart = 180;
let diastolicStart = 120;
let systolicEnd = 120;
let diastolicEnd = 100;
let systolicDeviation = randomIntFromInterval(-5, 5);
let diastolicDeviation = randomIntFromInterval(-2, 2);
let systolic =
((systolicEnd - systolicStart) * dayCount) / 100 +
systolicStart +
systolicDeviation;
let diastolic =
((diastolicEnd - diastolicStart) * dayCount) / 100 +
diastolicStart +
diastolicDeviation;
frontmatter += "bloodpressure: " + systolic + "/" + diastolic + "\n";
frontmatter += "bloodpressure1: " + systolic + ", " + diastolic + "\n";
frontmatter +=
"bloodpressure2: [" + systolic + ", " + diastolic + "]" + "\n";
frontmatter += "bp:" + "\n";
frontmatter += " systolic: " + systolic + "\n";
frontmatter += " diastolic: " + diastolic + "\n";
// clock-in clock-out, 24hr
let time_clock_in =
randomIntFromInterval(8, 10).toString() +
":" +
randomIntFromInterval(0, 59).toString();
let time_clock_out =
randomIntFromInterval(16, 20).toString() +
":" +
randomIntFromInterval(0, 59).toString();
frontmatter += "clock-in: " + time_clock_in + "\n";
frontmatter += "clock-out: " + time_clock_out + "\n";
// sleep, 12hr + am/pm
let time_in_bed =
randomIntFromInterval(9, 11).toString() +
":" +
randomIntFromInterval(0, 59).toString() +
" pm";
let time_out_of_bed =
randomIntFromInterval(5, 7).toString() +
":" +
randomIntFromInterval(0, 59).toString() +
" am";
frontmatter += "sleep: " + time_in_bed + "/" + time_out_of_bed + "\n";
// deep value
let deepValue = randomFloatFromInterval(0.0, 100.0);
frontmatter += "deepValue: " + "\n";
let indent = " ";
for (let ind = 0; ind < 5; ind++) {
frontmatter += indent + "very: " + "\n";
indent = indent + " ";
}
frontmatter += indent + "deep: " + deepValue.toFixed(1) + "\n";
// random character
frontmatter += "randchar: " + String.fromCharCode(65+indMood) + "\n";
frontmatter += "---\n";
content += frontmatter;
content += "\n";
// weight
let weight = randomFloatFromInterval(60.0, 80.0);
let tagWeight = "#weight:" + weight.toFixed(1) + "kg";
content += tagWeight + "\n";
content += "\n";
// excercise
// pushup
let numPushup = randomIntFromInterval(30, 50);
let tagPushup = "#exercise-pushup:" + numPushup;
content += tagPushup + "\n";
//plank
let numPlank = randomIntFromInterval(30, 120);
let tagPlank = "#exercise-plank:" + numPlank + "sec";
content += tagPlank + "\n";
content += "\n";
// meditation
let tagMeditation = "#meditation";
let missedMeditation = randomIntFromInterval(0, 1);
if (!missedMeditation) {
content += tagMeditation + "\n";
}
content += "\n";
// star
let textStar = "⭐";
let numStar = randomIntFromInterval(0, 5);
content += textStar.repeat(numStar) + "\n";
content += "\n";
// clean up
let tagCleanUp = "#clean-up";
let doCleanUp = randomIntFromInterval(0, 5);
if (doCleanUp === 1) {
content += tagCleanUp + "\n";
}
content += "\n";
// finance
let tagFinanceBank1 = "#finance/bank1";
let tagFinanceBank2 = "#finance/bank2";
let expense = randomFloatFromInterval(2.0, 3.0);
content += tagFinanceBank1 + ":-" + expense.toFixed(1) + "USD" + "\n";
if (dayCount % 30 == 0) {
content += tagFinanceBank2 + ":" + "200USD" + "\n";
content += tagFinanceBank2 + "/transfer:" + "-100USD" + "\n";
content += tagFinanceBank1 + "/transfer:" + "100USD" + "\n";
}
content += "\n";
// wiki links
content += "[[todo_family|To-Do @Family]]" + "\n";
content += "[[todo_work|To-Do @Work]]" + "\n";
content += "\n";
// searching text use regex
let addEmail1 = randomIntFromInterval(0, 1);
if (addEmail1) {
content += "[email protected]" + "\n";
}
let addEmail2 = randomIntFromInterval(0, 1);
if (addEmail2) {
content += "[email protected]" + "\n";
}
let addEmail3 = randomIntFromInterval(0, 1);
if (addEmail3) {
content += "[email protected]" + "\n";
}
content += "\n";
let countWeightLifting = randomIntFromInterval(10, 20);
let addWeightLifting = randomIntFromInterval(0, 5);
if (addWeightLifting > 0) {
content += "weightlifting: " + countWeightLifting + "\n";
}
content += "\n";
let dataviewValue = randomIntFromInterval(0, 100);
let dataviewValue1 = randomIntFromInterval(0, 50);
let dataviewValue2 = randomIntFromInterval(50, 100);
content += "dataviewTarget:: " + dataviewValue + "\n";
content += "- Make Progress:: " + dataviewValue1 + "\n";
content += "- Make-Progress:: " + dataviewValue2 + "\n";
content +=
"dataviewTarget1:: " + dataviewValue + "/" + dataviewValue1 + "\n";
content +=
"dataviewTarget2:: " + dataviewValue1 + " @ " + dataviewValue2 + "\n";
content +=
"dataviewTarget3:: " + dataviewValue1 + ", " + dataviewValue2 + "\n";
content += "\n";
// clock-in clock-out in dvField
let seconds = dataviewValue1;
content += "clock-in:: " + time_clock_in + ":" + seconds + "\n";
content += "clock-out:: " + time_clock_out + ":" + seconds +"\n";
content += "\n";
// sleep in dvField
content += "sleep:: " + time_in_bed + "/" + time_out_of_bed + "\n";
content += "\n";
let amplitude = 1.0;
let period = 30; // how many days to complete a sin period
let numSinValues = 9;
let initPhaseShift = -1.0;
let shiftPhase = 1.0;
let sinValues: Array<string> = [];
for (let ind = 0; ind < numSinValues; ind++) {
let shift = initPhaseShift + ind * shiftPhase;
let sinValue =
amplitude *
Math.sin(((2.0 * Math.PI) / period) * (dayCount + shift));
sinValues.push(sinValue.toFixed(5));
}
let tagSin = "#sin";
content += tagSin + ":" + sinValues.join("/") + "\n";
content += "\n";
let sinSquareValues: Array<string> = [];
for (let ind = 0; ind < numSinValues; ind++) {
let shift = initPhaseShift + ind * shiftPhase;
let sinSquareValue =
(amplitude *
Math.sin(((2.0 * Math.PI) / period) * (dayCount + shift))) **
2;
sinSquareValues.push(sinSquareValue.toFixed(5));
}
let tagSinSquare = "#sinsquare";
content += tagSinSquare + ":" + sinSquareValues.join("/") + "\n";
content += "\n";
// Tasks
let taskSayLove = "Say I love you";
let missedSayLove = randomIntFromInterval(0, 1);
if (!missedSayLove) {
content += "- [x] " + taskSayLove + "\n";
}
else {
content += "- [ ] " + taskSayLove + "\n";
}
content += "\n";
fs.writeFileSync(fh, content);
fs.closeSync(fh);
}