Overview
ThesaveHourlySnapshot endpoint creates hourly snapshots of parking occupancy data for analytics and historical tracking. It’s designed to be triggered by Google Cloud Scheduler on an hourly basis, with support for development mode to generate historical mock data.
Endpoint
Authentication
CORS-enabled endpoint. In production, should be restricted to Cloud Scheduler service account.Request Methods
GET Request (Production)
Used by Cloud Scheduler to create real-time snapshots based on current parking data. No parameters required.POST Request (Development)
Used for generating historical snapshots with optional mock data for testing.Generate snapshot for X hours in the past. Used for backfilling historical data.
If
true, generates realistic mock occupancy data instead of reading from Firestore. Useful for testing and demonstrations.Response
Indicates whether the snapshot was saved successfully
Result message describing the operation
The hour identifier for this snapshot (format:
YYYY-MM-DD-HH)ISO 8601 timestamp of the snapshot
Number of old snapshots deleted by retention policy (>30 days)
Global occupancy statistics:
free: Available spotsoccupied: Occupied spotsreserved: Reserved spotstotal: Total spotsoccupancyPct: Occupancy percentage (0-100)
Number of zones included in the snapshot
Indicates if snapshot was generated in development mode
Success Response
- 200 OK - Snapshot saved successfully
- 204 No Content - OPTIONS preflight response
Error Responses
- 405 Method Not Allowed - Request method is not GET or POST
- 500 Internal Server Error - Database or server error
Cloud Scheduler Configuration
Schedule this function to run hourly:Code Examples
Production Trigger (GET)
Development Mode (POST)
Response Examples
Production Snapshot
Development Snapshot with Mock Data
Mock Data Patterns
The mock data generator creates realistic occupancy patterns based on:University Parking Patterns
Weekdays (Monday-Friday):- 8:00-10:00 Chile time: 70-85% occupancy (morning arrival)
- 11:00-15:00 Chile time: 85-95% occupancy (peak hours)
- 16:00-19:00 Chile time: 65-80% occupancy (afternoon classes)
- 20:00-22:00 Chile time: 40-55% occupancy (evening classes)
- 23:00-01:00 Chile time: 20-35% occupancy (late classes ending)
- 02:00-07:00 Chile time: 3-10% occupancy (overnight)
- 11:00-19:00 Chile time: 10-22% occupancy (minimal activity)
- Other hours: 1-5% occupancy (nearly empty)
Zone Configuration
The mock data includes two zones matching the real S-Parking deployment:- Federico Froebel (
zone_1764307623391): 20 spots (A-01 to A-20) - Interior DUOC (
zone_1764306251630): 16 spots (I-01 to I-16)
Firestore Data Structure
Snapshot documents inoccupancy_history collection:
Retention Policy
Every execution automatically deletes snapshots older than 30 days:- Storage costs remain predictable
- Query performance stays optimal
- Compliance with data retention policies
Idempotency
The function useshour_key as the document ID:
- Running the function multiple times for the same hour overwrites (updates) the snapshot
- Safe to retry on failures
- Prevents duplicate entries
Hour Key Format
The hour key uses UTC time with zero-padded format:- March 5, 2026 at 2:00 PM UTC →
2026-03-05-14 - December 31, 2025 at 11:00 PM UTC →
2025-12-31-23
Testing Strategy
Generate Test Dataset
Verify Snapshot Creation
Related Endpoints
- Get Occupancy History - Retrieve saved snapshots
- Get Parking Status - Real-time data source for production snapshots
- Get Zones - Zone definitions used in snapshots