Overview
CoroNet provides seamless data export functionality, allowing users to download the complete vehicle registration database as a CSV file. This enables data analysis in spreadsheet applications, integration with third-party systems, and backup creation.Export Endpoint
The export functionality is implemented through a single, straightforward endpoint:- Route:
/descargar(Spanish for “download”) (app.py:154) - Method: GET request
- File validation: Calls
ensure_csv()to guarantee file exists (app.py:155) - Response: Streams the CSV file directly to the browser (app.py:156)
- Download name: File is saved as
registros.csvon the user’s device
The export endpoint uses Flask’s
send_file() function with as_attachment=True, which triggers a browser download dialog instead of displaying the file inline.CSV File Structure
The exported CSV follows a consistent seven-column format:Column Specifications
id - Unique Identifier
id - Unique Identifier
- Type: String (numeric)
- Format: Auto-incremented integer starting at 1
- Purpose: Unique identifier for each registration
- Usage: Can be used for record lookup, deletion, or updates
fecha_hora - Timestamp
fecha_hora - Timestamp
- Type: String (datetime)
- Format:
YYYY-MM-DD HH:MM:SS(ISO-like format) - Example:
2024-03-15 14:30:22 - Purpose: Records exact date and time of vehicle entry
- Usage: Chronological sorting, time-based filtering, audit trails
matricula - License Plate
matricula - License Plate
- Type: String (alphanumeric)
- Format: Uppercase, alphanumeric + hyphens only, max 10 characters
- Example:
ABC-123,XYZ789 - Source: Automatically detected via GPT-4o or Tesseract OCR
- Special value:
NO_DETECTADAwhen detection fails - Normalization: Spaces removed, uppercase conversion applied (app.py:74-75)
propietario - Vehicle Owner
propietario - Vehicle Owner
- Type: String (free text)
- Format: User-provided, supports UTF-8 characters
- Example:
Juan Pérez,María García - Purpose: Identifies the vehicle owner or driver
- Usage: Owner lookup, access control, contact information
tipo_vehiculo - Vehicle Type
tipo_vehiculo - Vehicle Type
- Type: String (free text)
- Format: User-provided category
- Examples:
Automóvil,Camioneta,Motocicleta,Camión - Purpose: Categorizes vehicles for reporting and analysis
- Usage: Vehicle type statistics, parking allocation, access rules
observacion - Notes/Observations
observacion - Notes/Observations
- Type: String (free text, optional)
- Format: User-provided notes
- Examples:
Vehículo oficial,Visitante,Entrega de paquetes - Purpose: Additional context or special conditions
- Usage: Security notes, visitor tracking, special permissions
imagen - Image Filename
imagen - Image Filename
- Type: String (filename)
- Format:
matricula_YYYYMMDD_HHMMSS.jpg - Example:
matricula_20240315_143022.jpg - Purpose: References the uploaded vehicle image
- Location: Physical file stored in
uploads/directory - Usage: Visual verification, evidence, manual plate verification
How the Export Works
Step-by-Step Process
- User Interaction
- Server Processing
- File Transfer
- User clicks the download/export button in the web interface
- Browser sends GET request to
/descargar - Server processes request and initiates file download
- Browser saves
registros.csvto the user’s download folder
File Validation
Before export, the system ensures data integrity:- The CSV file exists (creates it if missing)
- The file has proper headers
- Export never fails due to missing file
- Empty database exports as header-only CSV
If no registrations exist, the exported CSV will contain only the header row. This is valid CSV format and can be imported into spreadsheet applications.
Use Cases
Data Analysis
The exported CSV can be imported into analysis tools: Excel/Google Sheets:- Create pivot tables for vehicle type distribution
- Generate charts showing entries by date/time
- Calculate peak traffic hours
- Identify frequent visitors by license plate
Backup and Archive
Regular CSV exports provide a simple backup mechanism. The file includes all registration metadata but not the actual images (which remain in
uploads/).- Schedule regular exports (daily/weekly)
- Store CSV files with dated filenames
- Copy
uploads/directory for complete backup - Archive old records to reduce active database size
Integration with External Systems
The CSV format enables integration with:- Access control systems: Import plates into gate controllers
- Billing systems: Calculate parking fees based on entry times
- Security databases: Cross-reference with authorized vehicle lists
- Reporting tools: Generate compliance and audit reports
- Database systems: Bulk import into PostgreSQL, MySQL, etc.
Technical Implementation
Flask send_file() Function
CoroNet uses Flask’s built-insend_file() for optimal file delivery:
- Streaming: Large files are streamed without loading into memory
- Automatic headers: Sets correct Content-Type and Content-Disposition
- Cross-browser support: Works with all modern browsers
- Error handling: Handles missing files gracefully
Content-Type Header
Flask automatically sets the appropriate MIME type:- Recognize the file as CSV
- Trigger download instead of display
- Use the correct filename
Character Encoding
The CSV file uses UTF-8 encoding throughout:- International characters (Spanish accents, etc.) are preserved
- Compatibility with modern spreadsheet applications
- Data integrity during import/export cycles
UTF-8 vs. Latin-1 Encoding
UTF-8 vs. Latin-1 Encoding
Why UTF-8?
- Supports all Unicode characters (accents, emojis, Asian characters)
- Standard encoding for modern applications
- Compatible with Excel, Google Sheets, LibreOffice
- Older Excel versions may not auto-detect UTF-8
- Solution: Import via “Data > From Text/CSV” instead of double-clicking
- Or save as UTF-8 with BOM for better Excel compatibility
Export Limitations
Images Not Included
The CSV export contains only metadata about registrations:- ✅ License plate numbers
- ✅ Owner names
- ✅ Vehicle types
- ✅ Timestamps
- ✅ Image filenames
- ❌ Actual image data
uploads/ directory. To create a complete backup, you must:
- Export the CSV using
/descargar - Copy the entire
uploads/directory separately - Maintain the directory structure for image references to work
File Size Considerations
The CSV file size grows linearly with the number of registrations (approximately 100-200 bytes per record). A database with 10,000 entries would produce a ~1-2 MB CSV file.
- Small datasets (< 1,000 records): Instant download
- Medium datasets (1,000-10,000 records): Few seconds
- Large datasets (> 10,000 records): May take 10-30 seconds
- Very large datasets (> 100,000 records): Consider pagination or database migration
No Incremental Export
The current implementation exports the entire database every time:- Date range filtering
- Exporting only new records since last export
- Partial exports by vehicle type or owner
Security Considerations
Authentication Required
The current implementation does not include authentication. The
/descargar endpoint is publicly accessible. For production deployments, add authentication using Flask-Login or similar.Data Privacy
The exported CSV contains personally identifiable information (PII):- Vehicle owner names
- License plate numbers
- Entry timestamps
- Restricting export access to authorized personnel
- Encrypting exported files for transmission
- Implementing audit logging for export operations
- Providing data retention policies
Future Enhancements
Potential improvements to the export system:- Multiple formats: Add JSON, Excel, PDF export options
- Filtered exports: Date ranges, vehicle types, owner names
- Scheduled exports: Automatic daily/weekly exports via email
- Compressed archives: ZIP files containing CSV + all images
- API endpoint: RESTful API for programmatic data access
- Pagination: Export in chunks for very large datasets
- Custom column selection: Allow users to choose which fields to export
