forked from Adventech/sabbath-school-lessons
-
Notifications
You must be signed in to change notification settings - Fork 1
/
summary.js
executable file
ยท218 lines (179 loc) ยท 5.84 KB
/
summary.js
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
#!/usr/bin/env node
var fs = require("fs-extra");
var SOURCE_DIR = "src/",
LANGUAGE_EMOJI_MAPPER = {
"am": "๐ช๐น",
"af": "๐ฟ๐ฆ",
"ar": "๐ธ๐ฆ",
"bg": "๐ง๐ฌ",
"cs": "๐จ๐ฟ",
"da": "๐ฉ๐ฐ",
"de": "๐ฉ๐ช",
"el": "๐ฌ๐ท",
"en": "๐บ๐ธ",
"es": "๐ช๐ธ",
"et": "๐ช๐ช",
"fa": "๐ฎ๐ท",
"fj": "๐ซ๐ฏ",
"fi": "๐ซ๐ฎ",
"fr": "๐ซ๐ท",
"it": "๐ฎ๐น",
"is": "๐ฎ๐ธ",
"lt": "๐ฑ๐น",
"lv": "๐ฑ๐ป",
"he": "๐ฎ๐ฑ",
"hr": "๐ญ๐ท",
"hi": "๐ฎ๐ณ",
"hil": "๐ต๐ญ",
"hu": "๐ญ๐บ",
"hy": "๐ฆ๐ฒ",
"in": "๐ฎ๐ฉ",
"ilo": "๐ต๐ญ",
"ka": "๐ฌ๐ช",
"kin": "๐ท๐ผ",
"ko": "๐ฐ๐ท",
"km": "๐ฐ๐ญ",
"kn": "๐ฎ๐ณ",
"lo": "๐ฑ๐ฆ",
"mk": "๐ฒ๐ฐ",
"mg": "๐ฒ๐ฌ",
"ml": "๐ฎ๐ณ",
"mn": "๐ฒ๐ณ",
"ms": "๐ฒ๐พ",
"no": "๐ณ๐ด",
"ne": "๐ณ๐ต",
"nl": "๐ณ๐ฑ",
"ja": "๐ฏ๐ต",
"pl": "๐ต๐ฑ",
"pt": "๐ต๐น",
"ro": "๐ท๐ด",
"ru": "๐ท๐บ",
"run": "๐ท๐บ๐ณ",
"sk": "๐ธ๐ฐ",
"si": "๐ฑ๐ฐ",
"sl": "๐ธ๐ฎ",
"sn": "๐ฟ๐ผ",
"sr": "๐ท๐ธ",
"st": "๐ฟ๐ฆ",
"sq": "๐ฆ๐ฑ",
"sv": "๐ธ๐ช",
"sw": "๐ฐ๐ช",
"ta": "๐ฎ๐ณ",
"tl": "๐ต๐ญ",
"th": "๐น๐ญ",
"tr": "๐น๐ท",
"uk": "๐บ๐ฆ",
"vi": "๐ป๐ณ",
"xh": "๐ฟ๐ฆ",
"zh": "๐จ๐ณ",
"zu": "๐ฟ๐ฆ"
},
SOURCE_EXTENSION = "md",
SOURCE_EXTENSION_BIBLE = "bible",
MD_COMPLETE_THRESHOLD = 300;
var getQuarterlyPrefix = function(d) {
d = d || new Date();
var quarterIndex = (Math.ceil((d.getMonth()+1)/3));
return d.getFullYear() + "-0" + quarterIndex;
};
var l = {
"en": {
"2017-03": {
"01": {
"complete": "complete", // incomplete
"01": {
"text": "complete",
"bible": "complete"
}
}
}
}
};
/**
*
* @param lessonDir
* @param language
* @param quarterly
* @param week
*/
var scanAndReturnIfWeekIsComplete = function(weeksDir, week){
// scan all md files
// compare if amount of MD that are completed (size is more than X) is more or less of MD that are incomplete
// also check if Bible is not there but marked as completed
var days = fs.readdirSync(weeksDir),
ret = {};
var _complete = 0, _incomplete = 0;
for (var _day = 0; _day < days.length; _day++){
var extension = days[_day].split(".").pop();
if (extension !== SOURCE_EXTENSION) continue;
var sourceSize = Buffer.byteLength(fs.readFileSync(weeksDir + "/" + days[_day]), 'utf8'),
sourceBible = false;
try {
fs.lstatSync(weeksDir + "/" + days[_day] + "." + SOURCE_EXTENSION_BIBLE);
sourceBible = true;
} catch (err) {}
ret[days[_day]] = {
"text": sourceSize > MD_COMPLETE_THRESHOLD,
"bible": sourceBible
};
var _ = (sourceSize > MD_COMPLETE_THRESHOLD) ? _complete++ : _incomplete++;
}
ret["complete"] = _complete > _incomplete;
return ret;
};
var summaryMatrixToShortMd = function(summaryMatrix){
var lessons = [];
var output = "#### Current summary of lessons for " + getQuarterlyPrefix() + "\n\n";
output += "##### " + getQuarterlyPrefix() + "\n\n";
// Taking English to build header
output += "| |";
var _separator = "\n| ------------ |";
for (var lesson in summaryMatrix["en"][getQuarterlyPrefix()]){
lessons.push(lesson);
}
lessons.sort(function(x, y){
return parseInt(x) - parseInt(y);
});
for (var i = 0; i < lessons.length; i++){
output += " " + lessons[i] + " |";
_separator += " ------------ |";
}
output += _separator + "\n";
for (var language in summaryMatrix){
for (var quarterly in summaryMatrix[language]){
output += "| ";
output += (LANGUAGE_EMOJI_MAPPER.hasOwnProperty(language)) ? LANGUAGE_EMOJI_MAPPER[language] : language;
output += " " + quarterly.replace(getQuarterlyPrefix(), "").toUpperCase() + " | ";
for (var i = 0; i < lessons.length; i++){
lesson = lessons[i];
output += " ";
output += (summaryMatrix[language][quarterly][lesson].complete) ? "โ
|" : "โ |";
}
output += "\n";
}
}
console.log(output);
};
var summaryMatrixToFullyMd = function(summaryMatrix){
};
var languages = fs.readdirSync(SOURCE_DIR);
var summaryMatrix = {};
for (var i = 0; i < languages.length; i++){
var languageDir = SOURCE_DIR + languages[i];
if (!fs.lstatSync(languageDir).isDirectory()) continue;
var lessons = fs.readdirSync(languageDir);
summaryMatrix[languages[i]] = {};
for (var j = 0; j < lessons.length; j++){
var lessonsDir = languageDir + "/" + lessons[j];
if (!fs.lstatSync(lessonsDir).isDirectory() || lessons[j].indexOf(getQuarterlyPrefix()) !== 0) continue;
summaryMatrix[languages[i]][lessons[j]] = {};
var weeks = fs.readdirSync(lessonsDir);
for (var k = 0; k < weeks.length; k++){
var weeksDir = lessonsDir + "/" + weeks[k];
if (!fs.lstatSync(weeksDir).isDirectory()) continue;
summaryMatrix[languages[i]][lessons[j]][weeks[k]] = scanAndReturnIfWeekIsComplete(weeksDir, weeks[k]);
}
}
// console.log(JSON.stringify(summaryMatrix, null, 2));
}
summaryMatrixToShortMd(summaryMatrix);