w-dwdata-tweqod 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 +24 -0
- package/SECURITY.md +5 -0
- package/babel.config.js +16 -0
- package/dist/w-dwdata-tweqod.umd.js +8 -0
- package/dist/w-dwdata-tweqod.umd.js.map +1 -0
- package/docs/WDwdataTweqod.mjs.html +445 -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 +779 -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 +21 -0
- package/g.mjs +60 -0
- package/package.json +33 -0
- package/script.txt +17 -0
- package/src/WDwdataTweqod.mjs +373 -0
- package/src/downloadEqs.mjs +168 -0
- package/test/WDwdataTweq.test.mjs +137 -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,168 @@
|
|
|
1
|
+
import get from 'lodash-es/get.js'
|
|
2
|
+
import each from 'lodash-es/each.js'
|
|
3
|
+
import isnum from 'wsemi/src/isnum.mjs'
|
|
4
|
+
import isearr from 'wsemi/src/isearr.mjs'
|
|
5
|
+
import isestr from 'wsemi/src/isestr.mjs'
|
|
6
|
+
import cstr from 'wsemi/src/cstr.mjs'
|
|
7
|
+
import strdelleft from 'wsemi/src/strdelleft.mjs'
|
|
8
|
+
import ot from 'dayjs'
|
|
9
|
+
import axios from 'axios'
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
let downloadEqs = async(token) => {
|
|
13
|
+
let errTemp = null
|
|
14
|
+
|
|
15
|
+
// 氣象開放資料平台(使用氣象署帳密)
|
|
16
|
+
// https://opendata.cwa.gov.tw/index
|
|
17
|
+
|
|
18
|
+
// 中央氣象署開放資料平臺之資料擷取API
|
|
19
|
+
// https://opendata.cwa.gov.tw/dist/opendata-swagger.html#/%E5%9C%B0%E9%9C%87%E6%B5%B7%E5%98%AF/get_v1_rest_pga_datastore_E_A0015_001
|
|
20
|
+
|
|
21
|
+
// 顯著有感地震報告資料-顯著有感地震報告API(GET):
|
|
22
|
+
// https://opendata.cwa.gov.tw/api/v1/rest/datastore/E-A0015-001?Authorization={token}
|
|
23
|
+
|
|
24
|
+
// 小區域有感地震報告資料-小區域有感地震報告API(GET):
|
|
25
|
+
// https://opendata.cwa.gov.tw/api/v1/rest/datastore/E-A0016-001?Authorization={token}
|
|
26
|
+
|
|
27
|
+
//get, 顯著有感地震
|
|
28
|
+
let rEqsL = await axios.get(`https://opendata.cwa.gov.tw/api/v1/rest/datastore/E-A0015-001?Authorization=${token}`)
|
|
29
|
+
.catch((err) => {
|
|
30
|
+
errTemp = err
|
|
31
|
+
})
|
|
32
|
+
// console.log('rEqsL', rEqsL)
|
|
33
|
+
|
|
34
|
+
//check
|
|
35
|
+
if (errTemp !== null) {
|
|
36
|
+
return //若連線取得資料有錯則直接跳出, 不報錯
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// //get, 小區域有感地震
|
|
40
|
+
// let rEqsS = await axios.get(`https://opendata.cwa.gov.tw/api/v1/rest/datastore/E-A0016-001?Authorization=${token}`)
|
|
41
|
+
// .catch((err) => {
|
|
42
|
+
// errTemp = err
|
|
43
|
+
// })
|
|
44
|
+
// // console.log('rEqsS', rEqsS)
|
|
45
|
+
|
|
46
|
+
// //check
|
|
47
|
+
// if (errTemp !== null) {
|
|
48
|
+
// return //若連線取得資料有錯則直接跳出, 不報錯
|
|
49
|
+
// }
|
|
50
|
+
|
|
51
|
+
//eqsL
|
|
52
|
+
let eqsL1 = get(rEqsL, 'data.records.earthquake', [])
|
|
53
|
+
let eqsL2 = get(rEqsL, 'data.records.Earthquake', [])
|
|
54
|
+
let eqsL = [...eqsL1, ...eqsL2]
|
|
55
|
+
if (!isearr(eqsL)) {
|
|
56
|
+
console.log('rEqsL', rEqsL)
|
|
57
|
+
throw new Error(`無法取得顯著有感地震之earthquake數據`)
|
|
58
|
+
}
|
|
59
|
+
// console.log('eqsL', eqsL)
|
|
60
|
+
|
|
61
|
+
// //eqsS
|
|
62
|
+
// let eqsS1 = get(rEqsS, 'data.records.earthquake', [])
|
|
63
|
+
// let eqsS2 = get(rEqsS, 'data.records.Earthquake', [])
|
|
64
|
+
// let eqsS = [...eqsS1, ...eqsS2]
|
|
65
|
+
// if (!isearr(eqsS)) {
|
|
66
|
+
// console.log('rEqsS', rEqsS)
|
|
67
|
+
// throw new Error(`無法取得小區域有感地震之earthquake數據`)
|
|
68
|
+
// }
|
|
69
|
+
// // console.log('eqsS', eqsS)
|
|
70
|
+
|
|
71
|
+
//ds
|
|
72
|
+
// let ds = [...eqsL, ...eqsS]
|
|
73
|
+
let ds = eqsL
|
|
74
|
+
// console.log(ds)
|
|
75
|
+
|
|
76
|
+
let eqs = []
|
|
77
|
+
each(ds, (v) => {
|
|
78
|
+
|
|
79
|
+
//originTime, '2025-06-15 05:07:13'
|
|
80
|
+
let originTime1 = get(v, 'earthquakeInfo.originTime', '')
|
|
81
|
+
let originTime2 = get(v, 'EarthquakeInfo.OriginTime', '') //氣象署2023-01-03新格式
|
|
82
|
+
let originTime = originTime1 || originTime2
|
|
83
|
+
if (!isestr(originTime)) {
|
|
84
|
+
console.log('v', v)
|
|
85
|
+
throw new Error(`無法取得originTime[${originTime}]`)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
//magnitudeType
|
|
89
|
+
let magnitudeType1 = get(v, 'earthquakeInfo.magnitude.magnitudeType', '')
|
|
90
|
+
let magnitudeType2 = get(v, 'EarthquakeInfo.EarthquakeMagnitude.MagnitudeType', '') //氣象署2023-01-03新格式
|
|
91
|
+
let magnitudeType = magnitudeType1 || magnitudeType2
|
|
92
|
+
if (!isestr(magnitudeType)) {
|
|
93
|
+
console.log('v', v)
|
|
94
|
+
throw new Error(`無法取得magnitudeType[${magnitudeType}]`)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
//magnitudeValue
|
|
98
|
+
let magnitudeValue1 = get(v, 'earthquakeInfo.magnitude.magnitudeValue', '')
|
|
99
|
+
let magnitudeValue2 = get(v, 'EarthquakeInfo.EarthquakeMagnitude.MagnitudeValue', '') //氣象署2023-01-03新格式
|
|
100
|
+
let magnitudeValue = magnitudeValue1 || magnitudeValue2
|
|
101
|
+
if (!isnum(magnitudeValue)) { //數據為值須用isnum偵測
|
|
102
|
+
console.log('v', v)
|
|
103
|
+
throw new Error(`無法取得magnitudeValue[${magnitudeValue}]`)
|
|
104
|
+
}
|
|
105
|
+
// console.log(originTime, magnitudeType, magnitudeValue)
|
|
106
|
+
|
|
107
|
+
//description
|
|
108
|
+
let description = get(v, 'ReportContent', '')
|
|
109
|
+
|
|
110
|
+
//ml
|
|
111
|
+
let ml = magnitudeValue
|
|
112
|
+
ml = cstr(ml)
|
|
113
|
+
|
|
114
|
+
//t
|
|
115
|
+
let t = ot(originTime)
|
|
116
|
+
|
|
117
|
+
//地震id
|
|
118
|
+
let id = get(v, 'EarthquakeNo', '')
|
|
119
|
+
id = cstr(id)
|
|
120
|
+
|
|
121
|
+
let number = strdelleft(id, 3) //剔除左側3位民國年
|
|
122
|
+
|
|
123
|
+
let timeRec = originTime
|
|
124
|
+
|
|
125
|
+
let time = t.format('YYYY-MM-DDTHH:mm:ssZ') //轉UTC時間
|
|
126
|
+
|
|
127
|
+
let timeTag = t.format('YYYYMMDDHHmmss')
|
|
128
|
+
|
|
129
|
+
let depth = get(v, 'EarthquakeInfo.FocalDepth', '')
|
|
130
|
+
depth = cstr(depth)
|
|
131
|
+
|
|
132
|
+
let location = get(v, 'EarthquakeInfo.Epicenter.Location', '')
|
|
133
|
+
|
|
134
|
+
let longitude = get(v, 'EarthquakeInfo.Epicenter.EpicenterLongitude', '')
|
|
135
|
+
longitude = cstr(longitude)
|
|
136
|
+
|
|
137
|
+
let latitude = get(v, 'EarthquakeInfo.Epicenter.EpicenterLatitude', '')
|
|
138
|
+
latitude = cstr(latitude)
|
|
139
|
+
|
|
140
|
+
//eq
|
|
141
|
+
let eq = {
|
|
142
|
+
id, //地震id
|
|
143
|
+
tag: '', //地震戳記
|
|
144
|
+
number, //當年地震編號
|
|
145
|
+
time, //地震UTC時間
|
|
146
|
+
timeRec, //地震顯示時間
|
|
147
|
+
timeTag, //地震戳記時間
|
|
148
|
+
ml, //芮式規模
|
|
149
|
+
depth, //深度(km)
|
|
150
|
+
description, //地震描述
|
|
151
|
+
location, //地震位置
|
|
152
|
+
intensity: '', //最大震度
|
|
153
|
+
longitude,
|
|
154
|
+
latitude,
|
|
155
|
+
data: v,
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
//push
|
|
159
|
+
eqs.push(eq)
|
|
160
|
+
|
|
161
|
+
})
|
|
162
|
+
// console.log('eqs', eqs)
|
|
163
|
+
|
|
164
|
+
return eqs
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
export default downloadEqs
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import fs from 'fs'
|
|
2
|
+
import _ from 'lodash-es'
|
|
3
|
+
import w from 'wsemi'
|
|
4
|
+
import assert from 'assert'
|
|
5
|
+
import WDwdataTweqod from '../src/WDwdataTweqod.mjs'
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
describe('WDwdataTweqod', function() {
|
|
9
|
+
|
|
10
|
+
let test = async() => {
|
|
11
|
+
|
|
12
|
+
let pm = w.genPm()
|
|
13
|
+
|
|
14
|
+
let ms = []
|
|
15
|
+
|
|
16
|
+
let j = fs.readFileSync('../_data/settings.json', 'utf8')
|
|
17
|
+
let st = JSON.parse(j)
|
|
18
|
+
let token = _.get(st, 'token')
|
|
19
|
+
|
|
20
|
+
//fdDwStorage
|
|
21
|
+
let fdDwStorage = `./_dwStorage`
|
|
22
|
+
w.fsCleanFolder(fdDwStorage)
|
|
23
|
+
|
|
24
|
+
//fdDwAttime
|
|
25
|
+
let fdDwAttime = `./_dwAttime`
|
|
26
|
+
w.fsCleanFolder(fdDwAttime)
|
|
27
|
+
|
|
28
|
+
//fdDwCurrent
|
|
29
|
+
let fdDwCurrent = `./_dwCurrent`
|
|
30
|
+
w.fsCleanFolder(fdDwCurrent)
|
|
31
|
+
|
|
32
|
+
//fdResult
|
|
33
|
+
let fdResult = './_result'
|
|
34
|
+
w.fsCleanFolder(fdResult)
|
|
35
|
+
|
|
36
|
+
//funDownloadEqs
|
|
37
|
+
let funDownloadEqs = async() => {
|
|
38
|
+
let eqs = [
|
|
39
|
+
{
|
|
40
|
+
'id': '114116',
|
|
41
|
+
'tag': '',
|
|
42
|
+
'number': '116',
|
|
43
|
+
'time': '2025-08-22T14:06:15+08:00',
|
|
44
|
+
'timeRec': '2025-08-22 14:06:15',
|
|
45
|
+
'timeTag': '20250822140615',
|
|
46
|
+
'ml': '5.4',
|
|
47
|
+
'depth': '15.1',
|
|
48
|
+
'description': '08/22-14:06臺南市南化區發生規模5.4有感地震,最大震度臺南市楠西、高雄市甲仙、嘉義縣大埔、雲林縣西螺、彰化縣二林4級。',
|
|
49
|
+
'location': '臺南市政府東北東方 42.0 公里 (位於臺南市南化區)',
|
|
50
|
+
'intensity': '',
|
|
51
|
+
'longitude': '120.55',
|
|
52
|
+
'latitude': '23.16'
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
'id': '114115',
|
|
56
|
+
'tag': '',
|
|
57
|
+
'number': '115',
|
|
58
|
+
'time': '2025-08-21T16:37:47+08:00',
|
|
59
|
+
'timeRec': '2025-08-21 16:37:47',
|
|
60
|
+
'timeTag': '20250821163747',
|
|
61
|
+
'ml': '5.1',
|
|
62
|
+
'depth': '10.4',
|
|
63
|
+
'description': '08/21-16:37嘉義縣大埔鄉發生規模5.1有感地震,最大震度嘉義縣大埔、臺南市曾文、高雄市甲仙、嘉義縣太保市4級。',
|
|
64
|
+
'location': '嘉義縣政府東南方 36.3 公里 (位於嘉義縣大埔鄉)',
|
|
65
|
+
'intensity': '',
|
|
66
|
+
'longitude': '120.58',
|
|
67
|
+
'latitude': '23.26'
|
|
68
|
+
}
|
|
69
|
+
]
|
|
70
|
+
return eqs
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
let opt = {
|
|
74
|
+
fdDwStorage,
|
|
75
|
+
fdDwAttime,
|
|
76
|
+
fdDwCurrent,
|
|
77
|
+
fdResult,
|
|
78
|
+
funDownloadEqs,
|
|
79
|
+
// funDownload,
|
|
80
|
+
// funGetCurrent,
|
|
81
|
+
// funRemove,
|
|
82
|
+
// funAdd,
|
|
83
|
+
// funModify,
|
|
84
|
+
}
|
|
85
|
+
let ev = await WDwdataTweqod(token, opt)
|
|
86
|
+
.catch((err) => {
|
|
87
|
+
console.log(err)
|
|
88
|
+
})
|
|
89
|
+
ev.on('change', (msg) => {
|
|
90
|
+
delete msg.type
|
|
91
|
+
delete msg.timeRunStart
|
|
92
|
+
delete msg.timeRunEnd
|
|
93
|
+
delete msg.timeRunSpent
|
|
94
|
+
// console.log('change', msg)
|
|
95
|
+
ms.push(msg)
|
|
96
|
+
if (msg.event === 'end') {
|
|
97
|
+
console.log('ms', ms)
|
|
98
|
+
pm.resolve(ms)
|
|
99
|
+
}
|
|
100
|
+
})
|
|
101
|
+
// change { event: 'start', msg: 'running...' }
|
|
102
|
+
// change { event: 'proc-callfun-download', msg: 'start...' }
|
|
103
|
+
// change { event: 'proc-callfun-download', msg: 'done' }
|
|
104
|
+
// change { event: 'proc-callfun-getCurrent', msg: 'start...' }
|
|
105
|
+
// change { event: 'proc-callfun-getCurrent', msg: 'done' }
|
|
106
|
+
// change { event: 'compare', msg: 'start...' }
|
|
107
|
+
// change { event: 'compare', msg: 'done' }
|
|
108
|
+
// change { event: 'proc-add-callfun-add', id: '114101', msg: 'start...' }
|
|
109
|
+
// change { event: 'proc-add-callfun-add', id: '114101', msg: 'done' }
|
|
110
|
+
// change { event: 'proc-add-callfun-add', id: '114102', msg: 'start...' }
|
|
111
|
+
// change { event: 'proc-add-callfun-add', id: '114102', msg: 'done' }
|
|
112
|
+
// ...
|
|
113
|
+
|
|
114
|
+
return pm
|
|
115
|
+
}
|
|
116
|
+
let ms = [
|
|
117
|
+
{ event: 'start', msg: 'running...' },
|
|
118
|
+
{ event: 'proc-callfun-download', msg: 'start...' },
|
|
119
|
+
{ event: 'proc-callfun-download', msg: 'done' },
|
|
120
|
+
{ event: 'proc-callfun-getCurrent', msg: 'start...' },
|
|
121
|
+
{ event: 'proc-callfun-getCurrent', msg: 'done' },
|
|
122
|
+
{ event: 'compare', msg: 'start...' },
|
|
123
|
+
{ event: 'compare', msg: 'done' },
|
|
124
|
+
{ event: 'proc-add-callfun-add', id: '114115', msg: 'start...' },
|
|
125
|
+
{ event: 'proc-add-callfun-add', id: '114115', msg: 'done' },
|
|
126
|
+
{ event: 'proc-add-callfun-add', id: '114116', msg: 'start...' },
|
|
127
|
+
{ event: 'proc-add-callfun-add', id: '114116', msg: 'done' },
|
|
128
|
+
{ event: 'end', msg: 'done' }
|
|
129
|
+
]
|
|
130
|
+
|
|
131
|
+
it('test in localhost', async () => {
|
|
132
|
+
let r = await test()
|
|
133
|
+
let rr = ms
|
|
134
|
+
assert.strict.deepEqual(r, rr)
|
|
135
|
+
})
|
|
136
|
+
|
|
137
|
+
})
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import rollupFiles from 'w-package-tools/src/rollupFiles.mjs'
|
|
2
|
+
import getFiles from 'w-package-tools/src/getFiles.mjs'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
let fdSrc = './src'
|
|
6
|
+
let fdTar = './dist'
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
rollupFiles({
|
|
10
|
+
fns: 'WDwdataTweqod.mjs',
|
|
11
|
+
fdSrc,
|
|
12
|
+
fdTar,
|
|
13
|
+
// nameDistType: 'kebabCase',
|
|
14
|
+
hookNameDist: () => {
|
|
15
|
+
return 'w-dwdata-tweqod'
|
|
16
|
+
},
|
|
17
|
+
globals: {
|
|
18
|
+
'path': 'path',
|
|
19
|
+
'fs': 'fs',
|
|
20
|
+
},
|
|
21
|
+
external: [
|
|
22
|
+
'path',
|
|
23
|
+
'fs',
|
|
24
|
+
],
|
|
25
|
+
})
|
|
26
|
+
|