Skip to content

Commit

Permalink
fix: eew
Browse files Browse the repository at this point in the history
  • Loading branch information
whes1015 committed Nov 26, 2023
1 parent 90d73e9 commit f7207f2
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 21 deletions.
40 changes: 30 additions & 10 deletions src/core/index/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -537,41 +537,61 @@ function formatToChineseTime(dateTimeString) {

function eew_location_intensity(data, depth) {
const json = {};
let eew_max_pga = 0;
let count = 0;
let eew_max_i = 0;
for (const city of Object.keys(region)) {
for (const town of Object.keys(region[city])) {
const info = region[city][town];
const dist_surface = dis(data.lat, data.lon, info.lat, info.lon);
const dist = Math.sqrt(pow(dist_surface) + pow(data.depth));
const pga = 1.657 * Math.pow(Math.E, (1.533 * data.scale)) * Math.pow(dist, -1.607);
if (pga > eew_max_pga) {
eew_max_pga = pga;
let i = pga_to_float(pga);
if (i > 3) {
i = eew_i([data.lat, data.lon], [info.lat, info.lon], data.depth, data.scale);
}
if (pga > 0.8) {
count++;
if (i > eew_max_i) {
eew_max_i = i;
}
json[`${city} ${town}`] = {
dist,
pga,
i,
};
}
}
// console.log(data.type, " ", data.number, " ", count);
json.max_pga = eew_max_pga;
json.max_i = eew_max_i;
return json;
}

function eew_location_info(data) {
const dist_surface = dis(data.lat, data.lon, TREM.user.lat, TREM.user.lon);
const dist = Math.sqrt(pow(dist_surface) + pow(data.depth));
const pga = 1.657 * Math.pow(Math.E, (1.533 * data.scale)) * Math.pow(dist, -1.607) * (storage.getItem("site") ?? 1.751);
let i = pga_to_float(pga);
if (i > 3) {
i = eew_i([data.lat, data.lon], [TREM.user.lat, TREM.user.lon], data.depth, data.scale);
}
return {
dist,
pga,
i,
};
}

function eew_i(epicenterLocaltion, pointLocaltion, depth, magW) {
const long = 10 ** (0.5 * magW - 1.85) / 2;
const epicenterDistance = dis(epicenterLocaltion[0], epicenterLocaltion[1], pointLocaltion[0], pointLocaltion[1]);
const hypocenterDistance = (depth ** 2 + epicenterDistance ** 2) ** 0.5 - long;
const x = Math.max(hypocenterDistance, 3);
const gpv600 = 10 ** (
0.58 * magW +
0.0038 * depth - 1.29 -
Math.log10(x + 0.0028 * (10 ** (0.5 * magW))) -
0.002 * x
);
const arv = 1.0;
const pgv400 = gpv600 * 1.31;
const pgv = pgv400 * arv;
return 2.68 + 1.72 * Math.log10(pgv);
}

function dis(latA, lngA, latB, lngB) {
latA = latA * Math.PI / 180;
lngA = lngA * Math.PI / 180;
Expand Down
18 changes: 9 additions & 9 deletions src/core/index/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ function on_eew(data, type) {
TREM.eew = true;
let skip = false;
if (item_eew_level != -1) {
if (item_eew_level > pga_to_intensity(eew_location_info(data).pga)) {
if (item_eew_level > intensity_float_to_int(eew_location_info(data).i)) {
skip = true;
}
}
Expand Down Expand Up @@ -258,7 +258,7 @@ function on_eew(data, type) {
}
}
const eew = eew_location_intensity(data, data.depth);
data.max = pga_to_intensity(eew.max_pga);
data.max = intensity_float_to_int(eew.max_i);
TREM.EQ_list[data.id].loc = eew;
plugin.emit("trem.eew.on-eew-create", data);
} else {
Expand Down Expand Up @@ -299,9 +299,9 @@ function on_eew(data, type) {
TREM.audio.push("update");
}
const eew = eew_location_intensity(data, data.depth);
data.max = pga_to_intensity(eew.max_pga);
data.max = intensity_float_to_int(eew.max_i);
TREM.EQ_list[data.id].loc = eew;
TREM.EQ_list[data.id].eew = pga_to_intensity(TREM.EQ_list[data.id].loc.max_pga);
TREM.EQ_list[data.id].eew = intensity_float_to_int(TREM.EQ_list[data.id].loc.max_i);
plugin.emit("trem.eew.on-eew-update", data);
}
TREM.EQ_list[data.id].eew = data.max;
Expand Down Expand Up @@ -409,10 +409,10 @@ function on_eew(data, type) {
const _loc_list = TREM.EQ_list[data.id].loc;
let loc_list = "";
for (const loc of Object.keys(_loc_list)) {
if (loc == "max_pga") {
if (loc == "max_i") {
continue;
}
if (intensity_float_to_int(2 * Math.log10(_loc_list[loc].pga) + 0.7) >= 4) {
if (intensity_float_to_int(_loc_list[loc].i) >= 4) {
const city = loc.split(" ")[0];
if (!loc_list.includes(city)) {
loc_list += `${city},`;
Expand Down Expand Up @@ -473,7 +473,7 @@ function draw_intensity(skip) {
}
for (let d = 0; d < 1000; d++) {
const _dist = Math.sqrt(pow(d) + pow(TREM.EQ_list[_key].data.depth));
if (12.44 * Math.exp(1.33 * TREM.EQ_list[_key].data.scale) * Math.pow(_dist, -1.837) > 0.8) {
if ((1.657 * Math.pow(Math.E, (1.533 * TREM.EQ_list[_key].data.scale)) * Math.pow(_dist, -1.607)) > 0.8) {
if (d > TREM.dist) {
TREM.dist = d;
}
Expand All @@ -482,8 +482,8 @@ function draw_intensity(skip) {
}
}
for (const key of Object.keys(TREM.EQ_list[_key].loc)) {
if (key != "max_pga") {
const intensity = pga_to_intensity(TREM.EQ_list[_key].loc[key].pga);
if (key != "max_i") {
const intensity = intensity_float_to_int(TREM.EQ_list[_key].loc[key].i);
if ((location_intensity[key] ?? 0) < intensity) {
location_intensity[key] = intensity;
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/index/loop.js
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ setInterval(() => {
}
const _eew_location_info = eew_location_info(data);
const tr_time = _speed(data.depth, _eew_location_info.dist);
const intensity = pga_to_intensity(_eew_location_info.pga);
const intensity = intensity_float_to_int(_eew_location_info.i);
if (data.type == "eew-report") {
data.time = _now - (rts_replay_time - data.originTime);
}
Expand Down Expand Up @@ -553,7 +553,7 @@ setInterval(() => {
TREM.eew_bounds = L.latLngBounds();
let _count = 0;
for (const loc of Object.keys(TREM.EQ_list[key].loc)) {
if (TREM.EQ_list[key].loc[loc].pga > 0.8 && TREM.EQ_list[key].loc[loc].dist < s_dist / 1000) {
if (TREM.EQ_list[key].loc[loc].i > 1 && TREM.EQ_list[key].loc[loc].dist < s_dist / 1000) {
_count++;
const Loc = loc.split(" ");
TREM.eew_bounds.extend([region[Loc[0]][Loc[1]].lat, region[Loc[0]][Loc[1]].lon]);
Expand Down

0 comments on commit f7207f2

Please sign in to comment.