w-dwdata-tweq 1.0.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/.editorconfig +9 -0
- package/.eslintignore +3 -0
- package/.eslintrc.js +55 -0
- package/.jsdoc +25 -0
- package/LICENSE +21 -0
- package/README.md +48 -0
- package/SECURITY.md +5 -0
- package/babel.config.js +16 -0
- package/dist/w-dwdata-tweq.umd.js +8 -0
- package/dist/w-dwdata-tweq.umd.js.map +1 -0
- package/docs/WDwdataTweq.mjs.html +318 -0
- package/docs/fonts/Montserrat/Montserrat-Bold.eot +0 -0
- package/docs/fonts/Montserrat/Montserrat-Bold.ttf +0 -0
- package/docs/fonts/Montserrat/Montserrat-Bold.woff +0 -0
- package/docs/fonts/Montserrat/Montserrat-Bold.woff2 +0 -0
- package/docs/fonts/Montserrat/Montserrat-Regular.eot +0 -0
- package/docs/fonts/Montserrat/Montserrat-Regular.ttf +0 -0
- package/docs/fonts/Montserrat/Montserrat-Regular.woff +0 -0
- package/docs/fonts/Montserrat/Montserrat-Regular.woff2 +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.eot +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.svg +978 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.ttf +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff2 +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.eot +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.svg +1049 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.ttf +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff2 +0 -0
- package/docs/global.html +781 -0
- package/docs/index.html +84 -0
- package/docs/scripts/collapse.js +39 -0
- package/docs/scripts/commonNav.js +28 -0
- package/docs/scripts/linenumber.js +25 -0
- package/docs/scripts/nav.js +12 -0
- package/docs/scripts/polyfill.js +4 -0
- package/docs/scripts/prettify/Apache-License-2.0.txt +202 -0
- package/docs/scripts/prettify/lang-css.js +2 -0
- package/docs/scripts/prettify/prettify.js +28 -0
- package/docs/scripts/search.js +99 -0
- package/docs/styles/jsdoc.css +776 -0
- package/docs/styles/prettify.css +80 -0
- package/g.downloadEqs.mjs +16 -0
- package/g.mjs +53 -0
- package/g.parseData.mjs +26 -0
- package/package.json +34 -0
- package/script.txt +17 -0
- package/src/WDwdataTweq.mjs +246 -0
- package/src/cropPic.mjs +15 -0
- package/src/downloadEqs.mjs +124 -0
- package/src/downloadFile.mjs +77 -0
- package/src/downloadPics.mjs +57 -0
- package/src/parseData.mjs +152 -0
- package/test/WDwdataTweq.test.mjs +150 -0
- package/toolg/addVersion.mjs +4 -0
- package/toolg/cleanFolder.mjs +4 -0
- package/toolg/gDistRollup.mjs +26 -0
- package/toolg/modifyReadme.mjs +4 -0
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
|
|
5
|
+
<meta charset="utf-8">
|
|
6
|
+
<title>WDwdataTweq.mjs - Documentation</title>
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
<script src="scripts/prettify/prettify.js"></script>
|
|
10
|
+
<script src="scripts/prettify/lang-css.js"></script>
|
|
11
|
+
<!--[if lt IE 9]>
|
|
12
|
+
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
|
13
|
+
<![endif]-->
|
|
14
|
+
<link type="text/css" rel="stylesheet" href="styles/prettify.css">
|
|
15
|
+
<link type="text/css" rel="stylesheet" href="styles/jsdoc.css">
|
|
16
|
+
<script src="scripts/nav.js" defer></script>
|
|
17
|
+
|
|
18
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
19
|
+
</head>
|
|
20
|
+
<body>
|
|
21
|
+
|
|
22
|
+
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
|
|
23
|
+
<label for="nav-trigger" class="navicon-button x">
|
|
24
|
+
<div class="navicon"></div>
|
|
25
|
+
</label>
|
|
26
|
+
|
|
27
|
+
<label for="nav-trigger" class="overlay"></label>
|
|
28
|
+
|
|
29
|
+
<nav >
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
<h2><a href="index.html">Home</a></h2><h3>Global</h3><ul><li><a href="global.html#WDwdataTweq">WDwdataTweq</a></li></ul>
|
|
33
|
+
|
|
34
|
+
</nav>
|
|
35
|
+
|
|
36
|
+
<div id="main">
|
|
37
|
+
|
|
38
|
+
<h1 class="page-title">WDwdataTweq.mjs</h1>
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
<section>
|
|
47
|
+
<article>
|
|
48
|
+
<pre class="prettyprint source linenums"><code>import fs from 'fs'
|
|
49
|
+
import get from 'lodash-es/get.js'
|
|
50
|
+
import each from 'lodash-es/each.js'
|
|
51
|
+
import reverse from 'lodash-es/reverse.js'
|
|
52
|
+
import isestr from 'wsemi/src/isestr.mjs'
|
|
53
|
+
import isfun from 'wsemi/src/isfun.mjs'
|
|
54
|
+
import fsIsFolder from 'wsemi/src/fsIsFolder.mjs'
|
|
55
|
+
import fsCleanFolder from 'wsemi/src/fsCleanFolder.mjs'
|
|
56
|
+
import fsCreateFolder from 'wsemi/src/fsCreateFolder.mjs'
|
|
57
|
+
import fsDeleteFolder from 'wsemi/src/fsDeleteFolder.mjs'
|
|
58
|
+
import fsTreeFolder from 'wsemi/src/fsTreeFolder.mjs'
|
|
59
|
+
import WDwdataBuilder from 'w-dwdata-builder/src/WDwdataBuilder.mjs'
|
|
60
|
+
import downloadEqs from './downloadEqs.mjs'
|
|
61
|
+
import parseData from './parseData.mjs'
|
|
62
|
+
import downloadPics from './downloadPics.mjs'
|
|
63
|
+
import cropPic from './cropPic.mjs'
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* 下載台灣氣象署地震資料
|
|
68
|
+
*
|
|
69
|
+
* @param {Integer} yearStart 輸入數據開始年整數
|
|
70
|
+
* @param {Integer} yearEnd 輸入數據結束年整數
|
|
71
|
+
* @param {Object} [opt={}] 輸入設定物件,預設{}
|
|
72
|
+
* @param {String} [opt.keyId] 輸入各筆數據之主鍵字串,預設keyId
|
|
73
|
+
* @param {String} [opt.fdDwAttime] 輸入當前下載數據資料夾字串,預設'./_dwAttime'
|
|
74
|
+
* @param {String} [opt.fdDwCurrent] 輸入已下載數據資料夾字串,預設'./_dwCurrent'
|
|
75
|
+
* @param {String} [opt.fdResult] 輸入已下載數據所連動生成數據資料夾字串,預設'./_result'
|
|
76
|
+
* @param {String} [opt.fdTaskCpSrc] 輸入任務狀態之來源端資料夾字串,預設'./_taskCpSrc'
|
|
77
|
+
* @param {Function} [opt.funDownload] 輸入自定義下載函數,回傳資料陣列
|
|
78
|
+
* @param {Function} [opt.funGetCurrent] 輸入自定義取得當前資料函數,回傳資料陣列
|
|
79
|
+
* @param {Function} [opt.funAdd] 輸入當有新資料時,需要連動處理之函數
|
|
80
|
+
* @param {Function} [opt.funModify] 輸入當有資料需更新時,需要連動處理之函數
|
|
81
|
+
* @param {Function} [opt.funRemove] 輸入當有資料需刪除時,需要連動處理之函數
|
|
82
|
+
* @returns {Object} 回傳事件物件,可呼叫函數on監聽change事件
|
|
83
|
+
* @example
|
|
84
|
+
*
|
|
85
|
+
* import WDwdataTweq from './src/WDwdataTweq.mjs'
|
|
86
|
+
*
|
|
87
|
+
* let yearStart = 2022
|
|
88
|
+
* let yearEnd = 2022
|
|
89
|
+
* let opt = {}
|
|
90
|
+
* let ev = await WDwdataTweq(yearStart, yearEnd, opt)
|
|
91
|
+
* .catch((err) => {
|
|
92
|
+
* console.log(err)
|
|
93
|
+
* })
|
|
94
|
+
* ev.on('change', (msg) => {
|
|
95
|
+
* delete msg.type
|
|
96
|
+
* console.log('change', msg)
|
|
97
|
+
* })
|
|
98
|
+
* // change { event: 'start', msg: 'running...' }
|
|
99
|
+
* // change { event: 'proc-callfun-download', msg: 'start...' }
|
|
100
|
+
* // change { event: 'proc-callfun-download', msg: 'done' }
|
|
101
|
+
* // change { event: 'proc-callfun-getCurrent', msg: 'start...' }
|
|
102
|
+
* // change { event: 'proc-callfun-getCurrent', msg: 'done' }
|
|
103
|
+
* // change { event: 'compare', msg: 'start...' }
|
|
104
|
+
* // change { event: 'compare', msg: 'done' }
|
|
105
|
+
* // change { event: 'proc-add-callfun-add', id: '111001', msg: 'start...' }
|
|
106
|
+
* // change { event: 'proc-add-callfun-add', id: '111001', msg: 'done' }
|
|
107
|
+
* // change { event: 'proc-add-callfun-add', id: '111002', msg: 'start...' }
|
|
108
|
+
* // change { event: 'proc-add-callfun-add', id: '111002', msg: 'done' }
|
|
109
|
+
* // ...
|
|
110
|
+
*
|
|
111
|
+
*/
|
|
112
|
+
let WDwdataTweq = async(yearStart, yearEnd, opt = {}) => {
|
|
113
|
+
|
|
114
|
+
//keyId
|
|
115
|
+
let keyId = get(opt, 'keyId')
|
|
116
|
+
if (!isestr(keyId)) {
|
|
117
|
+
keyId = `id`
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
//fdDwAttime
|
|
121
|
+
let fdDwAttime = get(opt, 'fdDwAttime')
|
|
122
|
+
if (!isestr(fdDwAttime)) {
|
|
123
|
+
fdDwAttime = `./_dwAttime`
|
|
124
|
+
}
|
|
125
|
+
if (!fsIsFolder(fdDwAttime)) {
|
|
126
|
+
fsCreateFolder(fdDwAttime)
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
//fdDwCurrent
|
|
130
|
+
let fdDwCurrent = get(opt, 'fdDwCurrent')
|
|
131
|
+
if (!isestr(fdDwCurrent)) {
|
|
132
|
+
fdDwCurrent = `./_dwCurrent`
|
|
133
|
+
}
|
|
134
|
+
if (!fsIsFolder(fdDwCurrent)) {
|
|
135
|
+
fsCreateFolder(fdDwCurrent)
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
//fdResult
|
|
139
|
+
let fdResult = get(opt, 'fdResult')
|
|
140
|
+
if (!isestr(fdResult)) {
|
|
141
|
+
fdResult = './_result'
|
|
142
|
+
}
|
|
143
|
+
if (!fsIsFolder(fdResult)) {
|
|
144
|
+
fsCreateFolder(fdResult)
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
//fdTaskCpSrc
|
|
148
|
+
let fdTaskCpSrc = get(opt, 'fdTaskCpSrc')
|
|
149
|
+
if (!isestr(fdTaskCpSrc)) {
|
|
150
|
+
fdTaskCpSrc = './_taskCpSrc'
|
|
151
|
+
}
|
|
152
|
+
if (!fsIsFolder(fdTaskCpSrc)) {
|
|
153
|
+
fsCreateFolder(fdTaskCpSrc)
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
//funDownload
|
|
157
|
+
let funDownload = get(opt, 'funDownload')
|
|
158
|
+
|
|
159
|
+
//funGetCurrent
|
|
160
|
+
let funGetCurrent = get(opt, 'funGetCurrent')
|
|
161
|
+
|
|
162
|
+
//funAdd
|
|
163
|
+
let funAdd = get(opt, 'funAdd')
|
|
164
|
+
|
|
165
|
+
//funModify
|
|
166
|
+
let funModify = get(opt, 'funModify')
|
|
167
|
+
|
|
168
|
+
//funRemove
|
|
169
|
+
let funRemove = get(opt, 'funRemove')
|
|
170
|
+
|
|
171
|
+
//funDownloadDef
|
|
172
|
+
let funDownloadDef = async() => {
|
|
173
|
+
|
|
174
|
+
//downloadEqs
|
|
175
|
+
let v = await downloadEqs(yearStart, yearEnd)
|
|
176
|
+
// console.log('downloadEqs', v)
|
|
177
|
+
|
|
178
|
+
//parseData
|
|
179
|
+
let eqs = parseData(v)
|
|
180
|
+
// console.log('eqsAtt', eqsAtt, size(eqsAtt))
|
|
181
|
+
|
|
182
|
+
//reverse
|
|
183
|
+
eqs = reverse(eqs)
|
|
184
|
+
|
|
185
|
+
each(eqs, (v) => {
|
|
186
|
+
|
|
187
|
+
let fp = `${fdDwAttime}/${v[keyId]}.json`
|
|
188
|
+
|
|
189
|
+
fs.writeFileSync(fp, JSON.stringify(v), 'utf8')
|
|
190
|
+
|
|
191
|
+
})
|
|
192
|
+
|
|
193
|
+
return eqs
|
|
194
|
+
}
|
|
195
|
+
if (!isfun(funDownload)) {
|
|
196
|
+
funDownload = funDownloadDef
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
//funGetCurrentDef
|
|
200
|
+
let funGetCurrentDef = async() => {
|
|
201
|
+
|
|
202
|
+
//vfps
|
|
203
|
+
let vfps = fsTreeFolder(fdDwCurrent, 1)
|
|
204
|
+
// console.log('vfps', vfps)
|
|
205
|
+
|
|
206
|
+
//eqs
|
|
207
|
+
let eqs = []
|
|
208
|
+
each(vfps, (v) => {
|
|
209
|
+
|
|
210
|
+
let j = fs.readFileSync(v.path, 'utf8')
|
|
211
|
+
let eq = JSON.parse(j)
|
|
212
|
+
|
|
213
|
+
eqs.push(eq)
|
|
214
|
+
|
|
215
|
+
})
|
|
216
|
+
|
|
217
|
+
return eqs
|
|
218
|
+
}
|
|
219
|
+
if (!isfun(funGetCurrent)) {
|
|
220
|
+
funGetCurrent = funGetCurrentDef
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
//funRemoveDef
|
|
224
|
+
let funRemoveDef = async(v) => {
|
|
225
|
+
|
|
226
|
+
let fd = `${fdResult}/${v[keyId]}`
|
|
227
|
+
|
|
228
|
+
if (fsIsFolder(fd)) {
|
|
229
|
+
fsDeleteFolder(fd)
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
}
|
|
233
|
+
if (!isfun(funRemove)) {
|
|
234
|
+
funRemove = funRemoveDef
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
//funAddDef
|
|
238
|
+
let funAddDef = async(v) => {
|
|
239
|
+
|
|
240
|
+
let fd = `${fdResult}/${v[keyId]}`
|
|
241
|
+
|
|
242
|
+
if (fsIsFolder(fd)) {
|
|
243
|
+
fsCleanFolder(fd)
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
await downloadPics(fd, v)
|
|
247
|
+
|
|
248
|
+
let fnIn = 'picEqReport.gif'
|
|
249
|
+
let fpIn = `${fd}/${fnIn}`
|
|
250
|
+
let fnOut = 'picEqIntensityList.gif'
|
|
251
|
+
let fpOut = `${fd}/${fnOut}`
|
|
252
|
+
await cropPic(fpIn, fpOut, 364, 199, 276, 204)
|
|
253
|
+
|
|
254
|
+
}
|
|
255
|
+
if (!isfun(funAdd)) {
|
|
256
|
+
funAdd = funAddDef
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
//funModifyDef
|
|
260
|
+
let funModifyDef = async(v) => {
|
|
261
|
+
|
|
262
|
+
let fd = `${fdResult}/${v[keyId]}`
|
|
263
|
+
|
|
264
|
+
if (fsIsFolder(fd)) {
|
|
265
|
+
fsCleanFolder(fd)
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
await downloadPics(fd, v)
|
|
269
|
+
|
|
270
|
+
}
|
|
271
|
+
if (!isfun(funModify)) {
|
|
272
|
+
funModify = funModifyDef
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
//WDwdataBuilder
|
|
276
|
+
let optBdr = {
|
|
277
|
+
fdDwAttime,
|
|
278
|
+
fdDwCurrent,
|
|
279
|
+
fdResult,
|
|
280
|
+
fdTaskCpSrc,
|
|
281
|
+
funDownload,
|
|
282
|
+
funGetCurrent,
|
|
283
|
+
funRemove,
|
|
284
|
+
funAdd,
|
|
285
|
+
funModify,
|
|
286
|
+
}
|
|
287
|
+
let ev = await WDwdataBuilder(optBdr)
|
|
288
|
+
|
|
289
|
+
return ev
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
export default WDwdataTweq
|
|
294
|
+
</code></pre>
|
|
295
|
+
</article>
|
|
296
|
+
</section>
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
</div>
|
|
304
|
+
|
|
305
|
+
<br class="clear">
|
|
306
|
+
|
|
307
|
+
<footer>
|
|
308
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.4</a> on Sat Aug 23 2025 22:29:56 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
309
|
+
</footer>
|
|
310
|
+
|
|
311
|
+
<script>prettyPrint();</script>
|
|
312
|
+
<script src="scripts/polyfill.js"></script>
|
|
313
|
+
<script src="scripts/linenumber.js"></script>
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
</body>
|
|
318
|
+
</html>
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|