You've already forked fm-dx-webserver
mirror of
https://github.com/KubaPro010/fm-dx-webserver.git
synced 2026-02-27 14:33:52 +01:00
@@ -6,6 +6,9 @@ let cachedData = {};
|
|||||||
let lastFetchTime = 0;
|
let lastFetchTime = 0;
|
||||||
const fetchInterval = 3000;
|
const fetchInterval = 3000;
|
||||||
|
|
||||||
|
const esSwitchCache = {"lastCheck":0, "esSwitch":false};
|
||||||
|
const esFetchInterval = 300000;
|
||||||
|
|
||||||
// Fetch data from maps
|
// Fetch data from maps
|
||||||
function fetchTx(freq, piCode, rdsPs) {
|
function fetchTx(freq, piCode, rdsPs) {
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
@@ -46,6 +49,7 @@ function processData(data, piCode, rdsPs) {
|
|||||||
let maxScore = -Infinity; // Initialize maxScore with a very low value
|
let maxScore = -Infinity; // Initialize maxScore with a very low value
|
||||||
let txAzimuth;
|
let txAzimuth;
|
||||||
let maxDistance;
|
let maxDistance;
|
||||||
|
let esMode = checkEs();
|
||||||
|
|
||||||
for (const cityId in data.locations) {
|
for (const cityId in data.locations) {
|
||||||
const city = data.locations[cityId];
|
const city = data.locations[cityId];
|
||||||
@@ -53,7 +57,11 @@ function processData(data, piCode, rdsPs) {
|
|||||||
for (const station of city.stations) {
|
for (const station of city.stations) {
|
||||||
if (station.pi === piCode.toUpperCase() && !station.extra && station.ps && station.ps.toLowerCase().includes(rdsPs.replace(/ /g, '_').replace(/^_*(.*?)_*$/, '$1').toLowerCase())) {
|
if (station.pi === piCode.toUpperCase() && !station.extra && station.ps && station.ps.toLowerCase().includes(rdsPs.replace(/ /g, '_').replace(/^_*(.*?)_*$/, '$1').toLowerCase())) {
|
||||||
const distance = haversine(serverConfig.identification.lat, serverConfig.identification.lon, city.lat, city.lon);
|
const distance = haversine(serverConfig.identification.lat, serverConfig.identification.lon, city.lat, city.lon);
|
||||||
const score = (10*Math.log10(station.erp*1000)) / distance.distanceKm; // Calculate score
|
let weightDistance = distance.distanceKm
|
||||||
|
if (esMode && (distance.distanceKm > 200)) {
|
||||||
|
weightDistance = Math.abs(distance.distanceKm-1500);
|
||||||
|
}
|
||||||
|
const score = (10*Math.log10(station.erp*1000)) / weightDistance; // Calculate score
|
||||||
if (score > maxScore) {
|
if (score > maxScore) {
|
||||||
maxScore = score;
|
maxScore = score;
|
||||||
txAzimuth = distance.azimuth;
|
txAzimuth = distance.azimuth;
|
||||||
@@ -82,6 +90,37 @@ function processData(data, piCode, rdsPs) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function checkEs() {
|
||||||
|
const now = Date.now();
|
||||||
|
const url = "https://fmdx.org/includes/tools/get_muf.php";
|
||||||
|
let esSwitch = false;
|
||||||
|
|
||||||
|
if (now - esSwitchCache.lastCheck < esFetchInterval) {
|
||||||
|
esSwitch = esSwitchCache.esSwitch;
|
||||||
|
} else {
|
||||||
|
esSwitchCache.lastCheck = now;
|
||||||
|
fetch(url)
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(data => {
|
||||||
|
if (serverConfig.identification.lon < -32) {
|
||||||
|
if (data.north_america.max_frequency != "No data") {
|
||||||
|
esSwitch = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (data.europe.max_frequency != "No data") {
|
||||||
|
esSwitch = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
esSwitchCache.esSwitch = esSwitch;
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error("Error fetching data:", error);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return esSwitch;
|
||||||
|
}
|
||||||
|
|
||||||
function haversine(lat1, lon1, lat2, lon2) {
|
function haversine(lat1, lon1, lat2, lon2) {
|
||||||
const R = 6371; // Earth radius in kilometers
|
const R = 6371; // Earth radius in kilometers
|
||||||
const dLat = deg2rad(lat2 - lat1);
|
const dLat = deg2rad(lat2 - lat1);
|
||||||
|
|||||||
Reference in New Issue
Block a user