sort by time
This commit is contained in:
parent
63a4549a8d
commit
843e2bf749
@ -22,9 +22,6 @@ import com.sun.net.httpserver.HttpServer;
|
|||||||
|
|
||||||
public class BasketballServer {
|
public class BasketballServer {
|
||||||
|
|
||||||
private static JsonNode cachedData;
|
|
||||||
private static final Object lock = new Object();
|
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
fetchDataForDate("Sat Nov 01 2025 01:00:00 GMT+0100 (Central European Standard Time)"); // inicialní fetch
|
fetchDataForDate("Sat Nov 01 2025 01:00:00 GMT+0100 (Central European Standard Time)"); // inicialní fetch
|
||||||
|
|
||||||
@ -60,7 +57,6 @@ public class BasketballServer {
|
|||||||
|
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
JsonNode data = mapper.readTree(content.toString());
|
JsonNode data = mapper.readTree(content.toString());
|
||||||
synchronized (lock) { cachedData = data; }
|
|
||||||
System.out.println("Data fetched successfully for date: " + dateParam);
|
System.out.println("Data fetched successfully for date: " + dateParam);
|
||||||
return data;
|
return data;
|
||||||
|
|
||||||
|
|||||||
@ -65,7 +65,6 @@
|
|||||||
|
|
||||||
<label for="date">Vyber datum:</label>
|
<label for="date">Vyber datum:</label>
|
||||||
<input type="date" id="date" onchange="loadMatches()"/>
|
<input type="date" id="date" onchange="loadMatches()"/>
|
||||||
<button onclick="loadMatches()">Načíst zápasy</button>
|
|
||||||
|
|
||||||
<label for="league">Vyber ligu:</label>
|
<label for="league">Vyber ligu:</label>
|
||||||
<select id="league" onchange="filterMatches()">
|
<select id="league" onchange="filterMatches()">
|
||||||
@ -120,10 +119,11 @@ async function loadMatches() {
|
|||||||
let closestRow = null;
|
let closestRow = null;
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
|
|
||||||
|
const allMatches = [];
|
||||||
|
|
||||||
data.leagues.forEach(league => {
|
data.leagues.forEach(league => {
|
||||||
// --- kontrola, zda liga má alespoň jeden zápas s TV odkazem ---
|
|
||||||
const hasTV = league.matches.some(m => m.links.tvcom && m.links.tvcom.url);
|
const hasTV = league.matches.some(m => m.links.tvcom && m.links.tvcom.url);
|
||||||
if (!hasTV) return; // přeskočit ligu bez TV zápasů
|
if (!hasTV) return;
|
||||||
|
|
||||||
// přidat do select boxu
|
// přidat do select boxu
|
||||||
const option = document.createElement('option');
|
const option = document.createElement('option');
|
||||||
@ -132,12 +132,28 @@ async function loadMatches() {
|
|||||||
select.appendChild(option);
|
select.appendChild(option);
|
||||||
|
|
||||||
league.matches.forEach(match => {
|
league.matches.forEach(match => {
|
||||||
if (!match.links.live && !match.links.tvcom) return; // přeskočit zápasy bez Live a TV
|
if (!match.links.live && !match.links.tvcom) return;
|
||||||
|
|
||||||
|
allMatches.push({ league: league.name, match });
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// --- Seřadit podle času ---
|
||||||
|
allMatches.sort((a, b) => {
|
||||||
|
const parseTime = s => {
|
||||||
|
if (!s || !s.match(/^\d{1,2}:\d{2}$/)) return Infinity;
|
||||||
|
const [h, m] = s.split(':').map(Number);
|
||||||
|
return h * 60 + m;
|
||||||
|
};
|
||||||
|
return parseTime(a.match.status) - parseTime(b.match.status);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
// --- Vytvořit tabulku ---
|
||||||
|
allMatches.forEach(({ league, match }) => {
|
||||||
const tr = document.createElement('tr');
|
const tr = document.createElement('tr');
|
||||||
tr.dataset.league = league.name;
|
tr.dataset.league = league;
|
||||||
|
|
||||||
// doplnit https://cz.basketball pokud preview.url nezačíná http/https
|
|
||||||
let previewUrl = '';
|
let previewUrl = '';
|
||||||
if (match.links.preview && match.links.preview.url) {
|
if (match.links.preview && match.links.preview.url) {
|
||||||
previewUrl = match.links.preview.url;
|
previewUrl = match.links.preview.url;
|
||||||
@ -148,7 +164,7 @@ async function loadMatches() {
|
|||||||
|
|
||||||
tr.innerHTML = `
|
tr.innerHTML = `
|
||||||
<td>${match.status}</td>
|
<td>${match.status}</td>
|
||||||
<td>${league.name}</td>
|
<td>${league}</td>
|
||||||
<td>${match.home.name}</td>
|
<td>${match.home.name}</td>
|
||||||
<td>${match.away.name}</td>
|
<td>${match.away.name}</td>
|
||||||
<td>${previewUrl ? '<a href="'+previewUrl+'">Preview</a>' : ''}</td>
|
<td>${previewUrl ? '<a href="'+previewUrl+'">Preview</a>' : ''}</td>
|
||||||
@ -156,14 +172,11 @@ async function loadMatches() {
|
|||||||
<td>${match.links.tvcom && match.links.tvcom.url ? '<a href="'+match.links.tvcom.url+'" target="_blank">TV</a>' : ''}</td>
|
<td>${match.links.tvcom && match.links.tvcom.url ? '<a href="'+match.links.tvcom.url+'" target="_blank">TV</a>' : ''}</td>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
// zvýraznit zápasy s Nymburkem
|
|
||||||
if ((match.home.name && match.home.name.includes('Nymburk')) ||
|
if ((match.home.name && match.home.name.includes('Nymburk')) ||
|
||||||
(match.away.name && match.away.name.includes('Nymburk'))) {
|
(match.away.name && match.away.name.includes('Nymburk'))) {
|
||||||
tr.classList.add('nymburk');
|
tr.classList.add('nymburk');
|
||||||
}
|
}
|
||||||
|
|
||||||
// zvýraznit nejbližší zápas (Live zápasy)
|
|
||||||
if (match.links.live && match.links.live.url) {
|
|
||||||
const [hours, minutes] = match.status.split(':').map(Number);
|
const [hours, minutes] = match.status.split(':').map(Number);
|
||||||
if (!isNaN(hours) && !isNaN(minutes)) {
|
if (!isNaN(hours) && !isNaN(minutes)) {
|
||||||
const matchDate = new Date(now.getFullYear(), now.getMonth(), now.getDate(), hours, minutes);
|
const matchDate = new Date(now.getFullYear(), now.getMonth(), now.getDate(), hours, minutes);
|
||||||
@ -173,11 +186,9 @@ async function loadMatches() {
|
|||||||
closestRow = tr;
|
closestRow = tr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
tbody.appendChild(tr);
|
tbody.appendChild(tr);
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
if (closestRow) closestRow.classList.add('highlight');
|
if (closestRow) closestRow.classList.add('highlight');
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user