Overview
The application maintains a processing history that tracks the last 10 file uploads, storing filenames, timestamps, and key statistics. History is stored in Flask sessions and survives between page refreshes.Core Function
History tracking is implemented in thesalvar_historico() function from app.py:75:
How It Works
Retrieve Existing History
Fetches the current history list from Flask session, defaulting to empty list if none exists:
History Entry Structure
Each history entry contains exactly 4 fields:arquivo
Original uploaded filename (preserved as-is)
data
Brazilian date/time format (DD/MM/YYYY HH:MM)
encontrados
Number of tasks matching filter keywords
total
Total records in the uploaded file
Integration in Upload Flow
History is saved automatically during file processing in the/upload route:
History is saved after successful processing but before rendering results. This ensures only successfully processed files appear in history.
Viewing History
The history is accessible via the/historico route:
Template Integration
The history list is passed tohistorico.html as the historico variable, which can iterate over entries:
Storage Mechanism
Flask Session Storage Details
Flask Session Storage Details
- Backend: Flask’s session system (signed cookies by default)
- Encryption: Signed with
SECRET_KEYfrom environment variables - Persistence: Survives page refreshes and navigation
- Lifetime: Expires when browser closes (unless
SESSION_PERMANENTis set) - Size limit: Typically 4KB for cookie-based sessions
- Security: Not visible/modifiable by clients without the secret key
Date Formatting
Timestamps use Brazilian Portuguese format:| Code | Meaning | Example |
|---|---|---|
| %d | Day (zero-padded) | 09 |
| %m | Month (zero-padded) | 03 |
| %Y | 4-digit year | 2024 |
| %H | Hour (24-hour, zero-padded) | 14 |
| %M | Minute (zero-padded) | 32 |
09/03/2024 14:32
FIFO Queue Behavior
Example Sequence
Statistics Extraction
Only two statistics are stored from the full stats dictionary:The percentage (
percentual) and per-keyword breakdown (por_palavra) are not stored in history to minimize session size. These can be recalculated from encontrados and total if needed.Use Cases
Audit Trail
Track which files have been processed and when
Quick Reference
See statistics from previous runs without reprocessing
Pattern Detection
Identify trends in task occurrence rates over time
Duplicate Prevention
Spot if the same file is being uploaded multiple times
Limitations
Edge Cases
Empty History
If no files have been processed:Identical Filenames
If the same filename is uploaded multiple times, each processing creates a separate history entry:Future Enhancements
Potential improvements to the history system:- Database persistence for permanent history
- User-specific history with authentication
- Ability to re-run previous processing with same keywords
- Export history to CSV/JSON
- Detailed statistics including per-keyword breakdown
- Filtering/searching within history