4 Commits

6 changed files with 167 additions and 59 deletions

View File

@@ -5,6 +5,33 @@ All notable changes to Terra-View will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [0.9.3] - 2026-03-28
### Added
- **Monitoring Session Detail Page**: New dedicated page for each session showing session info, data files (with View/Report/Download actions), an editable session panel, and report actions.
- **Session Calendar with Gantt Bars**: Monthly calendar view below the session list, showing each session as a Gantt-style bar. The dim bar represents the full device on/off window; the bright bar highlights the effective recording window. Bars extend edge-to-edge across day cells for sessions spanning midnight.
- **Configurable Period Windows**: Sessions now store `period_start_hour` and `period_end_hour` to define the exact hours that count toward reports, replacing hardcoded day/night defaults. The session edit panel shows a "Required Recording Window" section with a live preview (e.g. "7:00 AM → 7:00 PM") and a Defaults button that auto-fills based on period type.
- **Report Date Field**: Sessions can now store an explicit `report_date` to override the automatic target-date heuristic — useful when a device ran across multiple days but only one specific day's data is needed for the report.
- **Effective Window on Session Info**: Session detail and session cards now show an "Effective" row displaying the computed recording window dates and times in local time.
- **Vibration Project Redesign**: Vibration project detail page is stripped back to project details and monitoring locations only. Each location supports assigning a seismograph and optional modem. Sound-specific tabs (Schedules, Sessions, Data Files, Assigned Units) are hidden for vibration projects.
- **Modem Assignment on Locations**: Vibration monitoring locations now support an optional paired modem alongside the seismograph. The swap endpoint handles both assignments atomically, updating bidirectional pairing fields on both units.
- **Available Modems Endpoint**: New `GET /api/projects/{project_id}/available-modems` endpoint returning all deployed, non-retired modems for use in assignment dropdowns.
### Fixed
- **Active Assignment Checks**: Unified all `UnitAssignment` "active" checks from `status == "active"` to `assigned_until IS NULL` throughout `project_locations.py` and `projects.py` for consistency with the canonical active definition.
### Changed
- **Sound-Only Endpoint Guards**: FTP browser, RND viewer, Excel report generation, combined report wizard, and data upload endpoints now return HTTP 400 if called on a non-sound-monitoring project.
### Migration Notes
Run on each database before deploying:
```bash
docker compose exec terra-view python3 backend/migrate_add_session_period_hours.py
docker compose exec terra-view python3 backend/migrate_add_session_report_date.py
```
---
## [0.9.2] - 2026-03-27 ## [0.9.2] - 2026-03-27
### Added ### Added

View File

@@ -1,4 +1,4 @@
# Terra-View v0.9.2 # Terra-View v0.9.3
Backend API and HTMX-powered web interface for managing a mixed fleet of seismographs and field modems. Track deployments, monitor health in real time, merge roster intent with incoming telemetry, and control your fleet through a unified database and dashboard. Backend API and HTMX-powered web interface for managing a mixed fleet of seismographs and field modems. Track deployments, monitor health in real time, merge roster intent with incoming telemetry, and control your fleet through a unified database and dashboard.
## Features ## Features

View File

@@ -30,7 +30,7 @@ Base.metadata.create_all(bind=engine)
ENVIRONMENT = os.getenv("ENVIRONMENT", "production") ENVIRONMENT = os.getenv("ENVIRONMENT", "production")
# Initialize FastAPI app # Initialize FastAPI app
VERSION = "0.9.2" VERSION = "0.9.3"
if ENVIRONMENT == "development": if ENVIRONMENT == "development":
_build = os.getenv("BUILD_NUMBER", "0") _build = os.getenv("BUILD_NUMBER", "0")
if _build and _build != "0": if _build and _build != "0":

View File

@@ -1235,18 +1235,65 @@ async def get_sessions_calendar(
if loc: if loc:
loc_names[lid] = loc.name loc_names[lid] = loc.name
# Build day -> list of session dots # Build calendar grid bounds first (needed for session spanning logic)
# day key: date object first_day = _date(year, month, 1)
last_day = _date(year, month, monthrange(year, month)[1])
days_before = (first_day.isoweekday() % 7)
grid_start = first_day - _td(days=days_before)
days_after = 6 - (last_day.isoweekday() % 7)
grid_end = last_day + _td(days=days_after)
def _period_hours(s):
"""Return (start_hour, end_hour) for a session, falling back to period_type defaults."""
psh, peh = s.period_start_hour, s.period_end_hour
if psh is None or peh is None:
if s.period_type and "night" in s.period_type:
return 19, 7
if s.period_type and "day" in s.period_type:
return 7, 19
return psh, peh
# Build day -> list of gantt segments
day_sessions: dict = {} day_sessions: dict = {}
for s in sessions: for s in sessions:
if not s.started_at: if not s.started_at:
continue continue
local_start = utc_to_local(s.started_at) local_start = utc_to_local(s.started_at)
d = local_start.date() local_end = utc_to_local(s.stopped_at) if s.stopped_at else now_local
if d.year == year and d.month == month: span_start = local_start.date()
if d not in day_sessions: span_end = local_end.date()
day_sessions[d] = [] psh, peh = _period_hours(s)
day_sessions[d].append({
cur_d = span_start
while cur_d <= span_end:
if grid_start <= cur_d <= grid_end:
# Device bar bounds (hours 024 within this day)
dev_sh = (local_start.hour + local_start.minute / 60.0) if cur_d == span_start else 0.0
dev_eh = (local_end.hour + local_end.minute / 60.0) if cur_d == span_end else 24.0
# Effective window within this day
eff_sh = eff_eh = None
if psh is not None and peh is not None:
if psh < peh:
# Day window e.g. 7→19
eff_sh, eff_eh = float(psh), float(peh)
else:
# Night window crossing midnight e.g. 19→7
if cur_d == span_start:
eff_sh, eff_eh = float(psh), 24.0
else:
eff_sh, eff_eh = 0.0, float(peh)
# Format tooltip labels
def _fmt_h(h):
hh = int(h) % 24
mm = int((h % 1) * 60)
suffix = "AM" if hh < 12 else "PM"
return f"{hh % 12 or 12}:{mm:02d} {suffix}"
if cur_d not in day_sessions:
day_sessions[cur_d] = []
day_sessions[cur_d].append({
"session_id": s.id, "session_id": s.id,
"label": s.session_label or f"Session {s.id[:8]}", "label": s.session_label or f"Session {s.id[:8]}",
"location_id": s.location_id, "location_id": s.location_id,
@@ -1254,17 +1301,17 @@ async def get_sessions_calendar(
"color": loc_color.get(s.location_id, "#9ca3af"), "color": loc_color.get(s.location_id, "#9ca3af"),
"status": s.status, "status": s.status,
"period_type": s.period_type, "period_type": s.period_type,
# Gantt bar percentages (0100 scale across 24 hours)
"dev_start_pct": round(dev_sh / 24 * 100, 1),
"dev_width_pct": max(1.5, round((dev_eh - dev_sh) / 24 * 100, 1)),
"eff_start_pct": round(eff_sh / 24 * 100, 1) if eff_sh is not None else None,
"eff_width_pct": max(1.0, round((eff_eh - eff_sh) / 24 * 100, 1)) if eff_sh is not None else None,
"dev_start_label": _fmt_h(dev_sh),
"dev_end_label": _fmt_h(dev_eh),
"eff_start_label": f"{int(psh):02d}:00" if eff_sh is not None else None,
"eff_end_label": f"{int(peh):02d}:00" if eff_sh is not None else None,
}) })
cur_d += _td(days=1)
# Build calendar grid (MonSun weeks)
first_day = _date(year, month, 1)
last_day = _date(year, month, monthrange(year, month)[1])
# Start on Sunday before first_day (isoweekday: Mon=1 … Sun=7; weekday: Mon=0 … Sun=6)
days_before = (first_day.isoweekday() % 7) # Sun=0, Mon=1, …, Sat=6
grid_start = first_day - _td(days=days_before)
# End on Saturday after last_day
days_after = 6 - (last_day.isoweekday() % 7)
grid_end = last_day + _td(days=days_after)
weeks = [] weeks = []
cur = grid_start cur = grid_start

View File

@@ -1,7 +1,7 @@
<!-- Monthly Sessions Calendar --> <!-- Monthly Sessions Calendar — Gantt Style -->
<div class="bg-white dark:bg-slate-800 rounded-xl border border-gray-200 dark:border-gray-700 overflow-hidden"> <div class="sessions-cal-wrap bg-white dark:bg-slate-800 rounded-xl border border-gray-200 dark:border-gray-700 overflow-hidden">
<!-- Calendar header: month navigation --> <!-- Month navigation -->
<div class="px-5 py-3 border-b border-gray-200 dark:border-gray-700 flex items-center justify-between"> <div class="px-5 py-3 border-b border-gray-200 dark:border-gray-700 flex items-center justify-between">
<button hx-get="/api/projects/{{ project_id }}/sessions-calendar?month={{ prev_month }}&year={{ prev_year }}" <button hx-get="/api/projects/{{ project_id }}/sessions-calendar?month={{ prev_month }}&year={{ prev_year }}"
hx-target="#sessions-calendar" hx-target="#sessions-calendar"
@@ -12,9 +12,7 @@
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7"></path> <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7"></path>
</svg> </svg>
</button> </button>
<h3 class="text-sm font-semibold text-gray-800 dark:text-gray-200">{{ month_name }} {{ year }}</h3> <h3 class="text-sm font-semibold text-gray-800 dark:text-gray-200">{{ month_name }} {{ year }}</h3>
<button hx-get="/api/projects/{{ project_id }}/sessions-calendar?month={{ next_month }}&year={{ next_year }}" <button hx-get="/api/projects/{{ project_id }}/sessions-calendar?month={{ next_month }}&year={{ next_year }}"
hx-target="#sessions-calendar" hx-target="#sessions-calendar"
hx-swap="innerHTML" hx-swap="innerHTML"
@@ -26,9 +24,10 @@
</button> </button>
</div> </div>
<!-- Legend --> <!-- Legend + key -->
<div class="px-5 py-2 border-b border-gray-100 dark:border-gray-700 flex flex-wrap items-center gap-x-5 gap-y-1.5">
{% if legend %} {% if legend %}
<div class="px-5 py-2 border-b border-gray-100 dark:border-gray-700 flex flex-wrap gap-3"> <div class="flex flex-wrap gap-x-4 gap-y-1">
{% for loc in legend %} {% for loc in legend %}
<div class="flex items-center gap-1.5 text-xs text-gray-600 dark:text-gray-400"> <div class="flex items-center gap-1.5 text-xs text-gray-600 dark:text-gray-400">
<span class="w-2.5 h-2.5 rounded-full shrink-0" style="background-color: {{ loc.color }}"></span> <span class="w-2.5 h-2.5 rounded-full shrink-0" style="background-color: {{ loc.color }}"></span>
@@ -37,12 +36,24 @@
{% endfor %} {% endfor %}
</div> </div>
{% endif %} {% endif %}
<!-- Bar key -->
<div class="flex items-center gap-3 text-xs text-gray-400 dark:text-gray-500 ml-auto shrink-0">
<div class="flex items-center gap-1.5">
<div class="w-8 h-2 rounded-sm" style="background:rgba(100,100,100,0.25)"></div>
<span>Device on</span>
</div>
<div class="flex items-center gap-1.5">
<div class="w-8 h-2 rounded-sm bg-blue-500"></div>
<span>Effective window</span>
</div>
</div>
</div>
<!-- Day-of-week headers --> <!-- Day-of-week headers -->
<div class="grid grid-cols-7 border-b border-gray-100 dark:border-gray-700"> <div class="grid grid-cols-7 border-b border-gray-100 dark:border-gray-700">
{% for day_name in ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'] %} {% for day_name in ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'] %}
<div class="py-2 text-center text-xs font-medium text-gray-400 dark:text-gray-500 uppercase tracking-wide <div class="py-2 text-center text-xs font-medium uppercase tracking-wide
{% if loop.index == 1 or loop.index == 7 %}text-amber-500 dark:text-amber-400{% endif %}"> {% if loop.index == 1 or loop.index == 7 %}text-amber-500 dark:text-amber-400{% else %}text-gray-400 dark:text-gray-500{% endif %}">
{{ day_name }} {{ day_name }}
</div> </div>
{% endfor %} {% endfor %}
@@ -52,40 +63,62 @@
{% for week in weeks %} {% for week in weeks %}
<div class="grid grid-cols-7 {% if not loop.last %}border-b border-gray-100 dark:border-gray-700{% endif %}"> <div class="grid grid-cols-7 {% if not loop.last %}border-b border-gray-100 dark:border-gray-700{% endif %}">
{% for day in week %} {% for day in week %}
<div class="min-h-[72px] p-1.5 {% if not loop.last %}border-r border-gray-100 dark:border-gray-700{% endif %} <div class="min-h-[80px] p-1.5
{% if not loop.last %}border-r border-gray-100 dark:border-gray-700{% endif %}
{% if not day.in_month %}bg-gray-50 dark:bg-slate-800/50{% else %}bg-white dark:bg-slate-800{% endif %} {% if not day.in_month %}bg-gray-50 dark:bg-slate-800/50{% else %}bg-white dark:bg-slate-800{% endif %}
{% if day.is_today %}ring-1 ring-inset ring-seismo-orange{% endif %}"> {% if day.is_today %}ring-1 ring-inset ring-seismo-orange{% endif %}">
<!-- Date number --> <!-- Date number -->
<div class="text-right mb-1"> <div class="text-right mb-1.5">
<span class="text-xs {% if day.is_today %}font-bold text-seismo-orange{% elif day.in_month %}text-gray-700 dark:text-gray-300{% else %}text-gray-300 dark:text-gray-600{% endif %}"> <span class="text-xs {% if day.is_today %}font-bold text-seismo-orange{% elif day.in_month %}text-gray-700 dark:text-gray-300{% else %}text-gray-300 dark:text-gray-600{% endif %}">
{{ day.date.day }} {{ day.date.day }}
</span> </span>
</div> </div>
<!-- Session dots/chips --> <!-- Gantt bars -->
{% if day.sessions %} {% if day.sessions %}
<div class="space-y-0.5"> <div class="space-y-2">
{% for s in day.sessions[:4] %} {% for s in day.sessions %}
<a href="/api/projects/{{ project_id }}/sessions/{{ s.session_id }}/detail"
class="flex items-center gap-1 px-1 py-0.5 rounded text-xs truncate hover:opacity-80 transition-opacity" <a href="/api/projects/{{ project_id }}/sessions/{{ s.session_id }}/detail" class="block">
style="background-color: {{ s.color }}22; border-left: 2px solid {{ s.color }};"
title="{{ s.label }}"> <!-- 24-hour timeline bar -->
<span class="truncate text-gray-700 dark:text-gray-300" style="color: {{ s.color }}; font-size: 0.65rem; line-height: 1.2;"> <div class="relative overflow-hidden -mx-1.5" style="height:11px; background:rgba(128,128,128,0.08);">
{{ s.location_name }} <div class="absolute top-0 bottom-0 w-px" style="left:25%; background:rgba(128,128,128,0.18)"></div>
{% if s.period_type %} <div class="absolute top-0 bottom-0 w-px" style="left:50%; background:rgba(128,128,128,0.28)"></div>
<span class="opacity-60">{{ '☀' if 'day' in s.period_type else '☾' }}</span> <div class="absolute top-0 bottom-0 w-px" style="left:75%; background:rgba(128,128,128,0.18)"></div>
<div class="absolute top-0 bottom-0"
style="left:{{ s.dev_start_pct }}%; width:{{ s.dev_width_pct }}%; background-color:{{ s.color }}; opacity:0.28;"></div>
{% if s.eff_start_pct is not none %}
<div class="absolute"
style="left:{{ s.eff_start_pct }}%; width:{{ s.eff_width_pct }}%; top:1.5px; bottom:1.5px; background-color:{{ s.color }};"></div>
{% endif %} {% endif %}
</span> </div>
<!-- Label -->
<div class="truncate mt-0.5" style="color:{{ s.color }}; font-size:0.58rem; line-height:1.3;">
{{ s.location_name }} · {{ day.date.strftime('%-m/%-d') }} · {% if s.period_type %}{{ 'Night' if 'night' in s.period_type else 'Day' }}{% else %}—{% endif %}
</div>
</a> </a>
{% endfor %} {% endfor %}
{% if day.sessions|length > 4 %}
<div class="text-center text-xs text-gray-400 dark:text-gray-500">+{{ day.sessions|length - 4 }} more</div>
{% endif %}
</div> </div>
{% endif %} {% endif %}
</div> </div>
{% endfor %} {% endfor %}
</div> </div>
{% endfor %} {% endfor %}
<!-- Time scale footer hint -->
<div class="px-4 py-1.5 border-t border-gray-100 dark:border-gray-700 flex justify-between text-gray-300 dark:text-gray-600" style="font-size:0.6rem;">
<span>12 AM</span>
<span>6 AM</span>
<span>12 PM</span>
<span>6 PM</span>
<span>12 AM</span>
</div>
</div> </div>

View File

@@ -1842,5 +1842,6 @@ document.addEventListener('DOMContentLoaded', function() {
switchTab(hash); switchTab(hash);
} }
}); });
</script> </script>
{% endblock %} {% endblock %}