Exporting from the Records Page
The easiest way to export your data is through the records viewer interface:Navigate to Records
Go to the records page by clicking ”📜 Ver Registros” from the home page, or navigate directly to
/registros.Click Download CSV
At the bottom of the records page, click the “Descargar CSV” button (Download CSV). This button features an upload icon and is styled as a primary action button.
Export Implementation
The export functionality is handled by the/descargar route (app.py:153-156):
- Ensures the CSV file exists before attempting download
- Sends the file directly from the data directory (
data/registros.csv) - Uses Flask’s
send_file()withas_attachment=Trueto trigger a browser download - Names the downloaded file
registros.csvfor consistency
CSV File Structure
The exported CSV file contains the following columns:Column Headers
| Column | Description | Example |
|---|---|---|
| id | Unique sequential record identifier | 1, 2, 3… |
| fecha_hora | Timestamp when the record was created | 2024-03-04 15:30:45 |
| matricula | Detected license plate number | ABC123, XYZ789 |
| propietario | Vehicle owner name (optional) | John Doe |
| tipo_vehiculo | Vehicle type classification (optional) | Sedan, Truck, Motorcycle |
| observacion | Additional notes or observations (optional) | Red color, Damaged bumper |
| imagen | Filename of the stored image | matricula_20240304_153045.jpg |
Sample CSV Output
Empty fields appear as consecutive commas in the CSV file. This is standard CSV format and will be handled correctly by spreadsheet applications.
Using Exported Data
Opening in Spreadsheet Applications
The exported CSV file can be opened in:- Microsoft Excel: Double-click the file or use File > Open
- Google Sheets: Use File > Import > Upload > Select the CSV file
- LibreOffice Calc: Open directly or use File > Open
- Apple Numbers: Import via File > Import
Ensure your spreadsheet application is set to UTF-8 encoding when opening the file to properly display special characters in names and observations.
Data Analysis Use Cases
Traffic Analysis
Use the exported data to:- Count vehicle visits by license plate number
- Identify peak hours using the
fecha_horatimestamps - Analyze vehicle type distribution
- Track repeat visitors
Record Keeping
The CSV export is useful for:- Creating backup copies of your detection records
- Archiving historical data before system maintenance
- Sharing records with other departments or systems
- Compliance and audit trails
Integration with Other Systems
Import the CSV data into:- Database management systems (MySQL, PostgreSQL)
- Business intelligence tools (Tableau, Power BI)
- Custom Python scripts for advanced analysis
- Access control systems for automated gate management
Direct File Access
If you need programmatic access to the CSV file:File Location
The CSV file is stored at:Reading with Python
You can directly read the CSV file using Python’s built-in csv module:API Access
The/descargar endpoint can also be accessed programmatically:
Export Best Practices
Regular Backups
Recommended backup schedule:- Daily: For high-traffic deployments with frequent new records
- Weekly: For moderate usage scenarios
- Monthly: For low-volume or archival purposes
Data Validation
After exporting, verify your data:- Open the CSV file to ensure all records exported correctly
- Check that the row count matches your expectations
- Verify that special characters display properly
- Confirm that all columns contain expected data
File Management
Organize your exported files:- Use descriptive filenames with dates:
registros_2024-03-04.csv - Store exports in a dedicated backup directory
- Consider compression for long-term storage:
zip registros_2024-03-04.csv - Maintain at least 3 backup copies in different locations
Limitations and Considerations
Images Not Included
The CSV export contains only metadata and references to image files:- Image filenames are included in the
imagencolumn - The actual image files remain in the
uploads/directory - To create a complete backup, copy both the CSV file and the entire
uploads/directory
For a complete system backup, use the backup command:
tar -czf backup.tar.gz data/registros.csv uploads/Live Data Export
The export always reflects the current state of the database:- Any records deleted after export won’t appear in the file
- New records added after export require a fresh download
- The export is a point-in-time snapshot, not a live sync
Large Datasets
For systems with thousands of records:- Export files may take a few seconds to generate
- Large CSV files may open slowly in spreadsheet applications
- Consider splitting historical data into separate files by date range
Troubleshooting Export Issues
Download Not Starting
If clicking the download button doesn’t trigger a file download:- Check that the
data/registros.csvfile exists - Verify the Flask application has read permissions for the data directory
- Check your browser’s download settings and permissions
- Try accessing
/descargardirectly in your browser
Empty CSV File
If the exported file contains only headers:- Verify that records exist in the database (check the records page)
- Ensure records were successfully saved during upload
- Check the CSV file directly at
data/registros.csv
File Encoding Issues
If special characters appear corrupted:- The CSV file uses UTF-8 encoding (app.py:28, 33, 38)
- Ensure your spreadsheet application is set to UTF-8 when opening
- In Excel, use “Data > From Text/CSV” and specify UTF-8 encoding
Permission Errors
If you see permission denied errors:- Verify the Flask application has read access to
data/registros.csv - Check filesystem permissions:
ls -l data/registros.csv - Ensure the web server user has appropriate file access rights
