-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
1044 lines (941 loc) · 38.3 KB
/
index.html
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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="スマホで簡単地震観測!スマホ1台あれば、インストール不要で、地震の波形を見たり、震度の目安を確認したりできます。加速度・速度・変位といった、マニアにうれしい詳しい情報も表示します。地震観測配信などにもおすすめ。">
<title>Zero Quake 簡易地震計</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=BIZ+UDPGothic&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=M+PLUS+1p:wght@800&display=swap" rel="stylesheet">
<link rel="manifest" href="https://0quake.github.io/Seismometer/manifest.json">
<meta name="theme-color" content="#4285f4">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:site" content="@Zero_Quake">
<meta name="twitter:creator" content="@Zero_Quake">
<meta property="og:title" content="Zero Quake 簡易地震計">
<meta property="og:description" content="スマホで簡単地震観測!スマホ1台あれば、インストール不要で、地震の波形を見たり、震度の目安を確認したりできます。加速度・速度・変位といった、マニアにうれしい詳しい情報も表示します。地震観測配信などにもおすすめ。">
<meta property="og:image" content="https://0quake.github.io/Seismometer/img/ss2.png">
<link rel="icon" href="https://0quake.github.io/Seismometer/favicon.ico">
<link rel="icon" href="https://0quake.github.io/Seismometer/img/MiniLogo.svg" sizes="any" type="image/svg+xml">
<script>
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('sw.js').then(async (registration) => {
console.log('ServiceWorker registration successful with scope: ', registration.scope);
}).catch((err) => {
console.log('ServiceWorker registration failed: ', err);
});
}
</script>
<style>
#loading-wrap {
margin: 80px auto 0 auto;
text-align: center;
background-image: url(https://0quake.github.io/Seismometer/img/loading.png);
background-size: cover;
background-position: center;
width: 50px;
height: 50px;
}
#splash {
position: fixed;
inset: 0;
background: #202227;
color: #fff;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
z-index: 100000005;
}
.button_wrap {
text-align: center;
margin: 10px 0 0 0;
}
button {
background: #333;
color: #fff;
border: solid 2px rgb(149, 46, 46);
padding: 0.5em 0.7em;
vertical-align: middle;
border-radius: 10px;
cursor: pointer;
margin: 10px;
}
button:hover {
background-color: rgb(149, 46, 46);
color: #fff;
}
button:focus {
background-color: rgb(149, 46, 46);
color: #fff;
outline: solid 1px rgb(149, 46, 46);
outline-offset: 3px;
}
header {
text-align: center;
}
header img {
width: 70px;
vertical-align: middle;
margin: 0 20px;
}
h1 span {
display: inline-block;
white-space: nowrap;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100vw;
padding: 0;
margin: 0;
background: #222;
color: #fff;
color-scheme: dark;
font-family: "BIZ UDPGothic", sans-serif;
font-weight: 400;
font-style: normal;
line-height: 1.5;
overflow-x: hidden;
}
main {
position: relative;
}
#nodata {
position: absolute;
inset: 0;
background: rgba(125, 125, 125, 0.5);
display: flex;
justify-content: center;
align-items: center;
font-size: 20px;
backdrop-filter: blur(3px);
z-index: 100;
}
#canvas {
width: 100vw;
height: 50vh;
}
#progress {
position: absolute;
bottom: 0;
right: 0;
left: 0;
width: 100%;
height: 5px;
background-color: #aaa;
-webkit-appearance: none;
appearance: none;
}
#progress::-webkit-progress-bar {
background-color: #ccc;
}
#progress::-webkit-progress-value {
background-color: #888;
}
#progress::-moz-progress-bar {
background-color: #888;
}
.dataItem {
display: inline-block;
border-radius: 8px;
margin: 3px;
text-align: center;
min-width: 180px;
}
#detail_wrap {
margin-top: 20px;
text-align: center;
line-height: 1.5;
min-width: 60vw;
max-width: calc(100% - 20px);
padding: 10px;
}
#detail {
display: inline-block;
border-radius: 8px;
text-align: left;
padding: 20px;
background: #444;
}
#int_c {
padding: 3px 15px;
position: relative;
overflow: hidden;
}
#int_c * {
color: inherit;
}
#int {
display: inline-block;
font-size: 40px;
font-family: "M PLUS 1p", sans-serif;
font-weight: 800;
font-style: normal;
}
#int_d {
display: inline-block;
font-size: 18px;
opacity: 0.8;
}
#intCover {
position: absolute;
inset: 0;
display: flex;
align-items: center;
justify-content: center;
background: #ccc;
color: #333;
}
#infoWrap {
display: flex;
justify-content: center;
flex-wrap: wrap;
max-width: calc(100% - 20px);
padding: 5px;
margin: 10px;
}
#pga_c,
#pgv_c,
#pgd_c {
padding: 3px 15px;
background: #444;
flex-shrink: 2;
}
#pga,
#maxpga,
#maxpgv,
#maxpgd {
display: inline-block;
}
#maxpga_wrap,
#maxpgv_wrap,
#maxpgd_wrap {
color: #ccc;
}
#BtnWrap {
text-align: center;
margin-top: 20px;
}
#BtnWrap button {
font-size: 18px;
padding: 3px 8px;
}
#houiView {
display: inline-block;
width: 60px;
height: 60px;
margin: 20px;
}
#PGAPGVInt {
display: inline-block;
border-radius: 3px;
padding: 0 3px;
font-family: "M PLUS 1p", sans-serif;
font-weight: 800;
font-style: normal;
}
dialog {
background: #222;
outline: none;
border: none;
box-shadow: 3px 3px 5px #000;
border-radius: 8px;
text-align: center;
}
dialog::backdrop {
background-color: rgba(0, 0, 0, 0.5);
backdrop-filter: blur(5px);
}
#infoWrap {
display: flex;
}
.infoItem {
background: #333;
border-radius: 8px;
margin: 4px;
text-align: center;
padding: 15px;
}
.GUI_Wrap {
position: relative;
width: 70px;
height: 70px;
overflow: hidden;
border-radius: 8px;
font-size: 60px;
line-height: 70px;
text-align: center;
margin: 0 auto;
color: #777;
}
.success {
display: none;
position: absolute;
inset: 0;
background: #5ad14a;
color: #000;
text-align: center;
line-height: 70px;
font-size: 30px;
}
#Suijunpoint {
position: absolute;
left: 30px;
top: 30px;
width: 10px;
height: 10px;
border-radius: 5px;
background: #227cd6;
}
footer {
background: #333;
padding: 20px 10px;
text-align: center;
}
#pga,
#maxpga,
#maxpgv,
#maxpgd,
#int_d {
font-family: ui-monospace;
}
</style>
</head>
<body>
<div id="splash">
<img src="https://0quake.github.io/Seismometer/img/logo.svg" width="256" height="256">
<div id="loading-wrap"></div>
</div>
<header>
<h1><img src="./img/logo.svg" alt="Zero Quakeのロゴ"><span>Zero Quake</span> <span>簡易地震計</span></h1>
</header>
<main>
<div id="nodata">データがありません</div>
<canvas id="canvas"></canvas>
<div id="infoWrap">
<div id="int_c" class="dataItem">
震度
<div id="int">-</div>
<div id="int_d">(0.0)</div>
<div id="intCover">震度 計算中...
<progress id="progress" max="1" value="0"></progress>
</div>
</div>
<div id="pga_c" class="dataItem">
合成加速度 <div id="pga"> - </div>gal
<div id="maxpga_wrap">秒間最大<div id="maxpga"> - </div>gal</div>
</div>
<div id="pgv_c" class="dataItem">
速度
<div id="maxpgv_wrap">秒間最大 <div id="maxpgv"> - </div>cm/s</div>
</div>
<div id="pgd_c" class="dataItem">
変位
<div id="maxpgd_wrap">秒間最大 <div id="maxpgd"> - </div>cm</div>
</div>
</div>
</main>
<div id="detail_wrap">
<div id="detail">
<div id="permissions">「モーションセンサー」の権限を付与してください。<button onclick='settingPermissions()'>権限を設定</button></div>
<div>推定震度1 : <span id="PGAPGVInt"> - </span> ±0.2</div>
<div>サンプリング周波数 : <span id="sampleRate">-</span>Hz</div>
<div>
<button id="onepoint">精度を上げる</button>
<button id="ConnectSensor">外付けセンサー</button>
</div>
<hr style="border-color:#999;margin:25px 0;">
<details>
<summary style="color:#CCC;font-size:14px">参考文献など </summary>
<ul>
<li>藤本一雄・翠川三郎 (2005) : 近年の強震記録に基づく地震動強さ指標による計測震度推定法</li>
<li>【ネット記事】<a href="https://qiita.com/soshi1822/items/6ae0c2d14a72478c79a0">加速度から計測震度を計算してみる</a></li>
<li>【ネット記事】<a href="https://qiita.com/bellbind/items/ba7aa07f6c915d400000#7-javascript%E3%81%AB%E3%82%88%E3%82%8B%E3%83%AB%E3%83%BC%E3%83%97%E7%89%88fft%E5%AE%9F%E8%A3%85%E3%82%B3%E3%83%BC%E3%83%89">高速フーリエ変換FFTを理解する</a></li>
</ul>
</details>
<div style="color:#CCC;font-size:14px">
<div style="font-weight: bold;">ご注意</div>
<ul>
<li>気象庁検定を受けていない為、表示する震度は全て震度相当値となります。厳密には「震度計」</li>
<li>観測値を公表する際は、あくまでその地点での参考値と明記したうえで公表してください。</li>
<li>気象庁の震度計と同じ計算方法を使用しています。計算には1分間の波形が必要であるため、起動後1分間は震度が表示されません。</li>
<li>当サイトは無保証です。自己責任でご利用ください。</li>
<li>Android OS + Chrome 以外の環境での動作は確認しておりません。この環境をおすすめします。</li>
<li>[ingen084さんのseismometer](https://github.com/ingen084/seismometer)を書きこんだPiDAS, EQIS-1に対応しているはずです(自信無) USB接続後、「外付けセンサー」ボタンから接続してください。</li>
</div>
</div>
</div>
<dialog id="onepoint_d">
<div id="infoWrap">
<div class="infoItem">
<div class="GUI_Wrap">
<svg id="Nicon" xmlns="http://www.w3.org/2000/svg" height="40" viewBox="0 -960 960 960" width="40" fill="#FFF">
<path d="m200-120-40-40 320-720 320 720-40 40-280-120-280 120Z" />
</svg>
<div id="NiconSuccess" class="success">✅</div>
</div>
<div>端末を<br>北に向ける</div>
</div>
<div class="infoItem">
<div class="GUI_Wrap">
+
<div id="Suijunpoint"></div>
<div id="SuijunSuccess" class="success">✅</div>
</div>
<div>安定した<br>水平面に置く</div>
</div>
</div>
<div class="button_wrap"> <button id="onepoint_c">閉じる</button></div>
</dialog>
<dialog id="nosensor">
センサーが搭載されていない端末の可能性があります。お使いの端末を確認してください。
<div class="button_wrap"><button id="nosensor_c">閉じる</button></div>
</dialog>
<footer>
<small>©2024 Benidate</small>
</footer>
<script>
let port;
let reader;
let writer;
let connectionStatus = false;
document.getElementById("ConnectSensor").addEventListener("click", async function () {
//切断時にクリックされた場合
if (connectionStatus == false) {
try {
port = await navigator.serial.requestPort();
await port.open({ baudRate: 9600 });
//errorになったらcatch (error)に飛ぶ
connectionStatus = true;
console.log("connected")
document.getElementById('ConnectSensor').innerHTML = "外付けセンサー接続解除"
reader = port.readable.getReader();
//繋がっている最中の処理
//物理的に突然抜いた時port.readableがfalseになる
//ボタンを押してCloseした時はconnectionStatusがFalseにされる(切断処理は2回目のクリック側で行われる)
while (connectionStatus && port.readable) {
try {
while (true) {
const { value, done } = await reader.read();
if (done) {
addSerial("Canceled\n");
break;
}
const inputValue = new TextDecoder().decode(value);
addSerial(inputValue);
}
} catch (error) {
addSerial("Error Read: " + error + "\n");
}
}
} catch (error) {
addSerial("Error Open: " + error + "\n");
}
}
//接続時にクリックされた場合、もしくはconnectionStatus == trueの時に突然引き抜かれて上のループを抜けて流れてきた場合
if (connectionStatus == true) {
connectionStatus = false;
//readerのリリース(writerは都度リリースしている)
reader.cancel();//突然引き抜かれたケースではエラーになる
reader.releaseLock();
await port.close()
console.log("disconnected")
document.getElementById('ConnectSensor').innerHTML = "外付けセンサー接続"
}
})
//結果をmulti-inputに反映
var msgTmp = "";
function addSerial(msg) {
msgTmp += msg;
if (msg == "\n") {
Message = msgTmp.split(" ")
if(Message[0] !== "$XSACC") return;
acceleration = { x: Number(Message[1]), y: Number(Message[2]), z: Number(Message[3].split("*")[0]) }
if (interval != 100) {
document.getElementById("sampleRate").innerText = 100;
interval = 100;
}
if (acceleration.x !== null) {
i++;
if (!data) {
document.getElementById("nodata").style.display = "none"
data = true
}
ax = acceleration.y;
ay = acceleration.x;
az = acceleration.z;
console.log(acceleration)
gals[0].push(ax);
gals[1].push(ay);
gals[2].push(az);
if (permission_status !== "granted") {
document.getElementById("permissions").innerHTML = "外部センサー接続済み";
permission_status == "granted";
}
}
msgTmp = ""
}
}
window.addEventListener("load", function () {
document.getElementById("splash").style.display = "none";
init()
})
settingPermissions = function () {
if (DeviceMotionEvent.requestPermission) {
DeviceMotionEvent.requestPermission()
.then(result => {
permission_status = result
if (permission_status == "granted") Str = "権限:許可済み";
else if (permission_status == "denied") Str = "必要な権限が拒否されました。「モーションセンサー」の権限を付与してください。";
else Str = "「モーションセンサー」の権限を付与してください。<button onclick='settingPermissions()'>権限を設定</button>";
document.getElementById("permissions").innerHTML = Str;
})
}
}
var permission_status = ""
navigator.permissions.query({ name: "accelerometer" }).then((result) => {
permission_status = result.state
if (permission_status == "granted") Str = "権限:許可済み";
else if (permission_status == "denied") Str = "必要な権限が拒否されました。「モーションセンサー」の権限を付与してください。";
else Str = "「モーションセンサー」の権限を付与してください。<button onclick='settingPermissions()'>権限を設定</button>";
document.getElementById("permissions").innerHTML = Str;
result.onchange = (result) => {
permission_status = result.currentTarget.state
if (permission_status == "granted") Str = "権限:許可済み";
else if (permission_status == "denied") Str = "必要な権限が拒否されました。「モーションセンサー」の権限を付与してください。";
else Str = "「モーションセンサー」の権限を付与してください。<button onclick='settingPermissions()'>権限を設定</button>";
document.getElementById("permissions").innerHTML = Str;
}
})
const dpr = window.devicePixelRatio || 1;
const canvas = document.getElementById("canvas");
const c = canvas.getContext("2d");
const w = (canvas.width = (window.innerWidth / 4) * dpr);
const h = (canvas.height = (window.innerHeight / 4) * dpr);
let ax, ay, az;
let buf = [];
const ofsY = [1 / 6, 0.5, 5 / 6];
const scaleY = [0.01 * dpr, 0.01 * dpr, 0.01 * dpr];
const penColor = ["#cf4444", "#44cf49", "#4475cf"];
const maxN = w;
var nosensor_showed = false;
function init() {
timerFunc();
setInterval(function () {
requestAnimationFrame(timerFunc);
}, 100);
setInterval(function () {
calcshindo()
if (permission_status == "granted" && gals[0].length == 0 && !nosensor_showed) {
nosensor_showed = true;
document.getElementById("nosensor").showModal();
}
}, 1000);
}
function redraw() {
c.fillStyle = "#333";
c.fillRect(0, 0, w, h);
c.strokeStyle = "#666";
c.lineWidth = 1;
for (i = 0; i < 3; i++) {
c.beginPath();
c.moveTo(0, ofsY[i] * h);
c.lineTo(canvas.width, ofsY[i] * h);
c.stroke();
}
if (buf.length >= 2) {
for (let seq = 0; seq < 3; seq++) {
c.strokeStyle = penColor[seq];
c.beginPath();
c.lineWidth = 1;
c.lineCap = "round";
c.lineJoin = "round";
let y0 = ofsY[seq] * h;
let yA = scaleY[seq] * h;
c.moveTo(0, y0 - yA * buf[0][seq]);
for (let i = 0; i < buf.length; i++) {
c.lineTo(i, y0 - yA * buf[i][seq]);
}
c.stroke();
}
}
}
var interval;
var data = false;
var i = 0;
var detectInterval
window.addEventListener("devicemotion", function (event) {
if (connectionStatus) return;
if (interval != event.interval) {
document.getElementById("sampleRate").innerText = (1000 / event.interval).toFixed(2);
interval = event.interval;
}
if (event.acceleration.x !== null) {
i++;
if (!data) {
document.getElementById("nodata").style.display = "none"
data = true
}
ax = event.acceleration.y;
ay = event.acceleration.x;
az = event.acceleration.z;
gals[0].push(ax);
gals[1].push(ay);
gals[2].push(az);
if (permission_status !== "granted") {
document.getElementById("permissions").innerHTML = "権限:許可済み";
permission_status == "granted";
}
}
})
function timerFunc() {
if (ax !== null) buf.push([ax, ay, az]);
if (buf.length > maxN) {
buf.shift();
}
redraw();
//合成加速度
if (ax !== null) {
requestAnimationFrame(function () {
document.getElementById("pga").innerText = Math.sqrt(
ax ** 2 + ay ** 2 + az ** 2
).toFixed(2);
});
}
}
var gals = [[], [], []];
function calcshindo() {
var filterCoefficient = 0.9;
var lowpassValue = 0;
var highpassValue = 0;
var timeSpan = 0.1;
var oldAccel = 0;
var speed = 0;
var oldSpeed = 0;
var difference = 0;
var maxSpeed = 0;
var maxPGA = 0;
var maxPGD = 0;
gal = gals[0].map(function (elm, index) {
return Math.sqrt(
gals[0][index] ** 2 + gals[1][index] ** 2 + gals[2][index] ** 2
);
});
var gal_tmp = gal.slice(gal.length - Math.floor(1000 / interval));
for (i = 0; i < Math.floor(1000 / interval); i++) {
lowpassValue =
lowpassValue * filterCoefficient + gal_tmp[i] * (1 - filterCoefficient);
highpassValue = gal_tmp[i] - lowpassValue;
speed = ((highpassValue + oldAccel) * timeSpan) / 2 + speed;
oldAccel = highpassValue;
difference = ((speed + oldSpeed) * timeSpan) / 2 + difference;
oldSpeed = speed;
if (maxPGA < gal_tmp[i]) maxPGA = gal_tmp[i];
if (maxSpeed < speed) maxSpeed = speed;
if (maxPGD < difference) maxPGD = difference;
}
document.getElementById("maxpga").innerText = maxPGA.toFixed(2);
document.getElementById("maxpgv").innerText = maxSpeed.toFixed(2);
document.getElementById("maxpgd").innerText = maxPGD.toFixed(2);
var estInt = 1.291 + 1.017 * Math.log10(maxPGA * maxSpeed);
estInt = Math.max(0, estInt);
estInt = Math.min(7, estInt);
document.getElementById("PGAPGVInt").style.background = shindoConvert(
estInt,
2
)[0];
document.getElementById("PGAPGVInt").style.color = shindoConvert(
estInt,
2
)[1];
document.getElementById("PGAPGVInt").innerText = estInt.toFixed(2);
document.getElementById("progress").value =
(gals[0].length * interval) / 60000;
if (gals[0].length * interval > 60000)
document.getElementById("intCover").style.display = "none";
fftGals = gals.map(function (gal) {
gal = gal.slice(Math.floor(gal.length - 60000 / interval));
return fft(arrayPadding(gal).map((r) => [r, 0]));
});
const dt = interval / 1000;
const NF = fftGals[0].length;
const NF2 = NF / 2;
for (let i = 1; i <= NF2; i++) {
const frq = i / (NF * dt);
const x = frq / 10;
const fc = Math.sqrt(1 / frq);
const fh =
1 /
Math.sqrt(
1 +
0.694 * x ** 2 +
0.241 * x ** 4 +
0.0557 * x ** 6 +
0.009664 * x ** 8 +
0.00134 * x ** 10 +
0.000155 * x ** 12
);
const fl = (1 - Math.exp((-(frq / 0.5)) ** 3)) ** 0.5;
const fa = fc * fh * fl;
for (let lk = 0; lk < fftGals.length; lk++) {
const fs = [fftGals[lk][i][0] * fa, fftGals[lk][i][1] * fa];
fftGals[lk][i] = fs;
fftGals[lk][NF - i] = [fs[0], -fs[1]];
}
}
const filterGals = fftGals.map((fftGal) => ifft(fftGal));
const lenGals = [];
filterGals.forEach((gal, i) => {
gal.forEach(([gas], t) => {
(lenGals[t] || (lenGals[t] = [])).push(gas);
});
});
const syntheticGal = lenGals.map(([s1, s2, s3]) =>
Math.sqrt(s1 ** 2 + s2 ** 2 + s3 ** 2)
);
syntheticGal.sort((a, b) => b - a);
const top03 = Math.floor(0.3 / dt) - 1;
const int = 2 * (Math.log(syntheticGal[top03]) / Math.LN10) + 0.94;
var kInt = (Math.floor(Math.round(int * 100) / 10) / 10).toFixed(1);
document.getElementById("int").innerText = shindoConvert(kInt, 1);
if (!kInt || isNaN(kInt)) kInt = "-";
else if (kInt == -Infinity) kInt = "-∞";
document.getElementById("int_d").innerText = "(" + kInt + ")";
document.getElementById("int_c").style.background = shindoConvert(kInt, 2)[0];
document.getElementById("int_c").style.color = shindoConvert(kInt, 2)[1];
}
function arrayPadding(arr) {
let dips = 2;
while (dips <= arr.length) {
dips *= 2;
}
return arr.concat(new Array(dips - arr.length).fill(0));
}
function revBit(k, n) {
let r = 0;
for (let i = 0; i < k; i++) r = (r << 1) | ((n >>> i) & 1);
return r;
}
function expi(theta) {
return [Math.cos(theta), Math.sin(theta)];
}
function iadd([ax, ay], [bx, by]) {
return [ax + bx, ay + by];
}
function isub([ax, ay], [bx, by]) {
return [ax - bx, ay - by];
}
function imul([ax, ay], [bx, by]) {
return [ax * bx - ay * by, ax * by + ay * bx];
}
function isum(cs) {
return cs.reduce((s, c) => iadd(s, c), [0, 0]);
}
function fftin1(c, T, N) {
const k = Math.log2(N);
const rec = c.map((_, i) => c[revBit(k, i)]);
for (let Nh = 1; Nh < N; Nh *= 2) {
T /= 2;
for (let s = 0; s < N; s += Nh * 2) {
for (let i = 0; i < Nh; i++) {
const l = rec[s + i],
re = imul(rec[s + i + Nh], expi(T * i));
[rec[s + i], rec[s + i + Nh]] = [iadd(l, re), isub(l, re)];
}
}
}
return rec;
}
function fft(f) {
const N = f.length,
T = -2 * Math.PI;
return fftin1(f, T, N);
}
function ifft(F) {
const N = F.length,
T = 2 * Math.PI;
return fftin1(F, T, N).map(([r, i]) => [r / N, i / N]);
}
function shindoConvert(str, responseType) {
var ShindoTmp;
if (str === null || str === undefined) ShindoTmp = 11;
else if (isNaN(str)) {
str = String(str)
.replace(/[0-9]/g, function (s) {
return String.fromCharCode(s.charCodeAt(0) - 0xfee0);
})
.replaceAll("+", "+")
.replaceAll("-", "-")
.replaceAll("強", "+")
.replaceAll("弱", "-")
.replace(/\s+/g, "");
switch (str) {
case "1":
case "10":
ShindoTmp = 1;
break;
case "2":
case "20":
ShindoTmp = 2;
break;
case "3":
case "30":
ShindoTmp = 3;
break;
case "4":
case "40":
ShindoTmp = 4;
break;
case "5-":
case "45":
ShindoTmp = 5;
break;
case "5+":
case "50":
ShindoTmp = 6;
break;
case "6-":
case "55":
ShindoTmp = 7;
break;
case "6+":
case "60":
ShindoTmp = 8;
break;
case "7":
case "70":
ShindoTmp = 9;
break;
case "震度5-以上未入電":
case "5+?":
ShindoTmp = 10;
break;
case "-1":
case "?":
case "不明":
default:
ShindoTmp = 11;
}
} else {
if (str < 0.5) ShindoTmp = 0;
else if (str < 1.5) ShindoTmp = 1;
else if (str < 2.5) ShindoTmp = 2;
else if (str < 3.5) ShindoTmp = 3;
else if (str < 4.5) ShindoTmp = 4;
else if (str < 5) ShindoTmp = 5;
else if (str < 5.5) ShindoTmp = 6;
else if (str < 6) ShindoTmp = 7;
else if (str < 6.5) ShindoTmp = 8;
else if (6.5 <= str) ShindoTmp = 9;
else ShindoTmp = 11;
}
switch (responseType) {
case 1:
var ConvTable = [
"0",
"1",
"2",
"3",
"4",
"5弱",
"5強",
"6弱",
"6強",
"7",
"5弱以上未入電",
"?"
];
break;
case 2:
var ConvTable = [
["rgb(80, 86, 102)", "rgb(204, 204, 204)"],
["rgb(134, 168, 198)", "rgb(51, 51, 51)"],
["rgb(56, 120, 193)", "rgb(255, 255, 255)"],
["rgb(80, 186, 84)", "rgb(34, 34, 34)"],
["rgb(204, 209, 74)", "rgb(34, 34, 34)"],
["rgb(231, 150, 21)", "rgb(0, 0, 0)"],
["rgb(255, 91, 22)", "rgb(0, 0, 0)"],
["rgb(237, 0, 0)", "rgb(255, 255, 255)"],
["rgb(128, 9, 9)", "rgb(255, 255, 255)"],
["rgb(196, 0, 222)", "rgb(255, 255, 255)"],
["rgb(231, 150, 21)", "rgb(0, 0, 0)"],
["rgb(191, 191, 191)", "rgb(68, 68, 68)"]
];
break;
case 3:
var ConvTable = [
null,
"1",
"2",
"3",
"4",
"5m",
"5p",
"6m",
"6p",
"7",
"5p?",
null
];
break;
case 4:
var ConvTable = [0, 1, 2, 3, 4, 4.5, 5, 5.5, 6, 7, 4.5, null];
break;
case 5:
var ConvTable = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 4.5, 0];
break;
case 0:
default:
var ConvTable = [
"0",
"1",
"2",
"3",
"4",