Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 40 additions & 16 deletions dashboard/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,45 @@ function dataBranchUrl(i) {
return `https://github.com/nullhack/src-disaster-awareness/tree/data/incidents/${treeId}`;
}

function _logEntryHtml(log) {
return `
<li class="log-entry">
<details>
<summary>
<span class="log-entry__head">
<span class="log-entry__date">${fmtDateTime(log.log_date) || ""}</span>
<span class="log-entry__count">${log.news.length} article(s)</span>
</span>
<div class="log-entry__summary">${esc(log.summary)}</div>
</summary>
${log.news.length ? `<ul class="drawer__news">${log.news.map((n) => `
<li><a href="${esc(n.url)}" target="_blank" rel="noopener">${esc(n.headline)}</a>
<div class="meta">${fmtDate(n.published_date) || ""} · ${esc(n.outlet || "")}</div></li>`).join("")}</ul>` : `<p class="muted">No linked news.</p>`}
</details>
</li>`;
}

function _timelineHtml(logs, logsTotal) {
if (!logs || !logs.length) return "";
const total = logsTotal || logs.length;
const trimmed = total > logs.length;
const reversed = logs.slice().reverse();
let entries;
if (trimmed && reversed.length > 1) {
const recent = reversed.slice(0, -1);
const genesis = reversed[reversed.length - 1];
entries = recent.map(_logEntryHtml).join("")
+ `<li class="log-entry--gap" title="${total - logs.length} log(s) hidden">⋮</li>`
+ _logEntryHtml(genesis);
} else {
entries = reversed.map(_logEntryHtml).join("");
}
const header = trimmed
? `Timeline · ${logs.length} of ${total} log(s)`
: `Timeline · ${logs.length} log(s)`;
return `<div class="drawer__section"><h3>${header}</h3><ul class="drawer__logs">${entries}</ul></div>`;
}

function openDrawer(id) { const i = STATE.digest.incidents.find((x) => x.incident_id === id);
if (!i) return;
$("#drawerTitle").textContent = i.canonical_name;
Expand Down Expand Up @@ -841,22 +880,7 @@ function openDrawer(id) { const i = STATE.digest.incidents.find((x) => x.incide
${L.url ? `</a>` : `</span>`}</li>`).join("")}
</ul>` : `<p class="muted">No deep links available for this incident.</p>`}
</div>
${(i.logs && i.logs.length) ? `<div class="drawer__section"><h3>Timeline · ${i.logs.length} log(s)</h3>
<ul class="drawer__logs">${i.logs.slice().reverse().map((log, idx) => `
<li class="log-entry">
<details>
<summary>
<span class="log-entry__head">
<span class="log-entry__date">${fmtDateTime(log.log_date) || ""}</span>
<span class="log-entry__count">${log.news.length} article(s)</span>
</span>
<div class="log-entry__summary">${esc(log.summary)}</div>
</summary>
${log.news.length ? `<ul class="drawer__news">${log.news.map((n) => `
<li><a href="${esc(n.url)}" target="_blank" rel="noopener">${esc(n.headline)}</a>
<div class="meta">${fmtDate(n.published_date) || ""} · ${esc(n.outlet || "")}</div></li>`).join("")}</ul>` : `<p class="muted">No linked news.</p>`}
</details>
</li>`).join("")}</ul></div>` : ""}
${_timelineHtml(i.logs, i.logs_total)}
${(i.news && i.news.length && !(i.logs && i.logs.length)) ? `<div class="drawer__section"><h3>News · ${i.news_total} linked (${i.news.length} shown)</h3>
<ul class="drawer__news">${i.news.map((n) => `
<li><a href="${esc(n.url)}" target="_blank" rel="noopener">${esc(n.headline)}</a>
Expand Down
1 change: 1 addition & 0 deletions dashboard/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,7 @@ code { font-family: var(--mono); font-size: .9em; }
.log-entry__date { color: var(--rc-ink); white-space: nowrap; }
.log-entry__count { color: var(--rc-muted); font-weight: 400; font-size: 11px; white-space: nowrap; }
.log-entry__summary { font-size: 13px; line-height: 1.55; color: var(--rc-slate); padding: 4px 0 0 18px; }
.log-entry--gap { text-align: center; color: var(--rc-muted); font-size: 16px; letter-spacing: 2px; padding: 6px 0; list-style: none; cursor: default; border-bottom: 1px solid var(--rc-line); }
.keys { display: flex; flex-wrap: wrap; gap: 5px; }
.keys code {
font-size: 11px; background: var(--rc-bg); padding: 2px 7px; border-radius: 4px; color: var(--rc-slate);
Expand Down
31 changes: 21 additions & 10 deletions scripts/generate_dashboard_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@
from disaster_report._country_names import country_name
from disaster_report.store.content import ContentStore

SCHEMA_VERSION = "1.4"
SCHEMA_VERSION = "1.5"
TRACKING_WINDOW_DAYS = 7
DEFAULT_TRACKING_WINDOW_DAYS = 7
MIN_SEVERITY = "LOW"
MAX_RECENT_LOGS = 3

SEVERITY_RANK = {"LOW": 1, "MEDIUM": 2, "HIGH": 3, "CRITICAL": 4}
SEVERITY_NAMES = {v: k for k, v in SEVERITY_RANK.items()}
Expand Down Expand Up @@ -390,6 +391,9 @@ def build_incident_object(store: ContentStore, inc: dict, as_of_date: datetime)
news_count = len(news)
latest_summary = load_latest_log(store, incident_id)
logs = load_logs_for_incident(store, incident_id)
logs_total = len(logs)
if logs_total > MAX_RECENT_LOGS + 1:
logs = [logs[0]] + logs[-MAX_RECENT_LOGS:]

genesis = None
for r in reports:
Expand Down Expand Up @@ -577,15 +581,21 @@ def build_incident_object(store: ContentStore, inc: dict, as_of_date: datetime)
"gdacs_population": gdacs_pop if gdacs_pop else None,
}

news_items = [
{
"headline": n["headline"] or "",
"url": n["url"],
"outlet": n["outlet"] or "",
"published_date": n["published_date"],
}
for n in news
]
if logs:
news_items = [
{"headline": n["headline"] or "", "published_date": n["published_date"]}
for n in news
]
else:
news_items = [
{
"headline": n["headline"] or "",
"url": n["url"],
"outlet": n["outlet"] or "",
"published_date": n["published_date"],
}
for n in news
]

if lat is None and iso2 and iso2 in ISO2_CENTROIDS:
lat, lon = ISO2_CENTROIDS[iso2]
Expand Down Expand Up @@ -626,6 +636,7 @@ def build_incident_object(store: ContentStore, inc: dict, as_of_date: datetime)
"news": news_items,
"news_total": news_count,
"logs": logs,
"logs_total": logs_total,
}


Expand Down
Loading