# Test Data Database - Session Notes

## Session Date: 2026-01-13

## Project Overview
Created a SQLite database with Express.js web interface to consolidate, deduplicate, and search test data from multiple backup dates and test stations.

## Project Location
`C:\Shares\TestDataDB\`

## Original Request
- Search for serial numbers 176923-1 through 176923-26 in model DSCA38-1793
- Serial numbers were NOT found in any existing .DAT files (most recent logged: 173672-x, 173681-x from Feb 2025)
- User requested a database to consolidate all test data for easier searching

## Data Sources
- **HISTLOGS**: `C:\Shares\test\Ate\HISTLOGS\` (consolidated history)
- **Recovery-TEST**: `C:\Shares\Recovery-TEST\` (6 backup dates: 12-13-25 to 12-18-25)
- **Live Data**: `C:\Shares\test\` (~540K files)
- **Test Stations**: TS-1L, TS-3R, TS-4L, TS-4R, TS-8R, TS-10L, TS-11L

## File Types Imported
| Log Type | Description | Extension |
|----------|-------------|-----------|
| DSCLOG | DSC product line | .DAT |
| 5BLOG | 5B product line | .DAT |
| 7BLOG | 7B product line (CSV format) | .DAT |
| 8BLOG | 8B product line | .DAT |
| PWRLOG | Power tests | .DAT |
| SCTLOG | SCT product line | .DAT |
| VASLOG | VAS tests | .DAT |
| SHT | Human-readable test sheets | .SHT |

## Project Structure
```
TestDataDB/
â”œâ”€â”€ package.json           # Node.js dependencies
â”œâ”€â”€ server.js              # Express.js server (port 3000)
â”œâ”€â”€ database/
â”‚   â”œâ”€â”€ schema.sql         # SQLite schema with FTS
â”‚   â”œâ”€â”€ testdata.db        # SQLite database file
â”‚   â””â”€â”€ import.js          # Data import script
â”œâ”€â”€ parsers/
â”‚   â”œâ”€â”€ multiline.js       # Parser for multi-line DAT files
â”‚   â”œâ”€â”€ csvline.js         # Parser for 7BLOG CSV format
â”‚   â””â”€â”€ shtfile.js         # Parser for SHT test sheets
â”œâ”€â”€ public/
â”‚   â””â”€â”€ index.html         # Web search interface
â”œâ”€â”€ routes/
â”‚   â””â”€â”€ api.js             # API endpoints
â””â”€â”€ templates/
    â””â”€â”€ datasheet.js       # Datasheet generator
```

## API Endpoints
- `GET /api/search?serial=...&model=...&from=...&to=...&result=...&q=...`
- `GET /api/record/:id`
- `GET /api/datasheet/:id` - Generate printable datasheet
- `GET /api/stats`
- `GET /api/export?format=csv`

## How to Use

### Start the server:
```bash
cd C:\Shares\TestDataDB
node server.js
```
Then open http://localhost:3000 in a browser.

### Re-run import (if needed):
```bash
cd C:\Shares\TestDataDB
node database/import.js
```

## Database Schema
- Table: `test_records`
- Columns: id, log_type, model_number, serial_number, test_date, test_station, overall_result, raw_data, source_file, import_date
- Indexes on: serial_number, model_number, test_date, overall_result
- Full-text search (FTS5) for searching raw_data

## Features
1. **Search** - By serial number, model number, date range, pass/fail status
2. **Full-text search** - Search within raw test data
3. **Export** - CSV export of search results
4. **Datasheet generation** - Generate formatted test data sheets from any record
5. **Statistics** - Dashboard showing total records, pass/fail counts, date range

## Import Status - COMPLETE
- Started: 2026-01-13T21:32:59.401Z
- Completed: 2026-01-13T22:02:42.187Z
- **Total records: 1,030,940**

### Import Details:
| Source | Records Imported |
|--------|------------------|
| HISTLOGS | 576,416 |
| Recovery-TEST/12-18-25 | 454,383 |
| Recovery-TEST/12-17-25 | 82 |
| Recovery-TEST/12-16 to 12-13 | 0 (duplicates) |
| test | 59 |

### By Log Type:
- 5BLOG: 425,378
- 7BLOG: 262,404
- DSCLOG: 181,160
- 8BLOG: 135,858
- PWRLOG: 12,374
- VASLOG: 10,327
- SCTLOG: 3,439

### By Result:
- PASS: 1,029,046
- FAIL: 1,888
- UNKNOWN: 6

## Current Status
- Server running at: http://localhost:3000
- Database file: `C:\Shares\TestDataDB\database\testdata.db`

## Known Issues
- Model number parsing needs re-import to fix (parser was updated but requires re-import)
- To re-import: Delete testdata.db and run `node database/import.js`

## Search Results for Original Request
- Serial numbers 176923-1 through 176923-26: **NOT FOUND** (not yet tested)
- Most recent serial for DSCA38-1793: 173672-x and 173681-x (February 2025)

## Next Steps
1. Re-run import if model number search is needed (delete testdata.db first)
2. When serial numbers 176923-1 to 176923-26 are tested, they will appear in the database

## Notes
- TXT datasheets in `10D/datasheets/` are NOT imported (can be generated from DB)
- Deduplication uses: (log_type, model_number, serial_number, test_date, test_station)
- ~3,600 SHT files to import
- ~41,000+ DAT files across all log types

