Skip to content

Add bulk import for expert opinions (CSV/JSON) #73

@caitlon

Description

@caitlon

User Story

As a project admin, I want to import multiple expert opinions at once via CSV or JSON file, so that I can efficiently set up projects with many experts without manual entry.

Problem Statement

Currently, admins must add expert opinions one by one through the UI. For projects with 20+ experts (like the budget and pendlers case studies), this manual process is time-consuming and error-prone.

Proposed Solution

Data Format Support

CSV Format:

expert_name,lower,peak,upper,comment
Expert1,5.0,10.0,15.0,Optional comment
Expert2,8.0,12.0,18.0,

JSON Format:

{
  "opinions": [
    {"name": "Expert1", "lower": 5.0, "peak": 10.0, "upper": 15.0, "comment": "Optional"},
    {"name": "Expert2", "lower": 8.0, "peak": 12.0, "upper": 18.0}
  ]
}

Backend Requirements

  • POST /api/v1/projects/{project_id}/opinions/bulk
  • Validate all opinions before inserting (atomic transaction)
  • Return detailed error report with row numbers for failed validations
  • Enforce fuzzy number constraint: lower <= peak <= upper
  • Respect project's scale_min and scale_max settings

Frontend Requirements

  • Drag-and-drop file upload component
  • Preview table showing parsed data before import
  • Progress indicator during import
  • Error summary with clickable row navigation
  • Download template button (CSV and JSON examples)

Acceptance Criteria

  • User can upload CSV file with expert opinions
  • User can upload JSON file with expert opinions
  • Preview shows all rows with validation status (valid/invalid)
  • Invalid rows are highlighted with error messages
  • User can fix invalid rows inline before submitting
  • Successful import adds all opinions atomically (all or nothing)
  • Failed import shows which rows failed and why
  • UI supports both English and Czech languages
  • API endpoint has 100% test coverage
  • API documentation updated in api/README.md

Definition of Done

  • PR passes all CI checks (lint, types, tests)
  • CodeRabbit review addressed
  • API tests cover success, validation errors, partial failures
  • Frontend tested manually on Chrome and Firefox
  • i18n translations added for both EN and CS

Technical Notes

  • Use existing OpinionService patterns from api/services/opinion_service.py
  • Follow validation patterns from api/schemas/validators.py
  • Frontend file upload can use native <input type="file"> with drag-drop wrapper

Related

  • Case study data format: examples/data/README.md
  • Opinion schema: api/schemas/opinion.py

Metadata

Metadata

Assignees

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions