derived PK: id 11 required 1 unique

Description

Derived entity storing calculated estimates of tangible advantages and benefits a peer mentor has accumulated through their volunteer activities, used in the Advantage Calculator feature within Achievements & Gamification.

15
Attributes
4
Indexes
4
Validation Rules
5
CRUD Operations

Data Structure

Name Type Description Constraints
id uuid Primary key
PKrequiredunique
user_id uuid Reference to the peer mentor this calculation belongs to
required
calculation_date datetime Timestamp when the calculation was performed or last refreshed
required
period_start datetime Start of the period this calculation covers
required
period_end datetime End of the period this calculation covers
required
total_activities integer Total number of logged activities in the period
required
total_hours decimal Total volunteer hours accumulated in the period
required
estimated_monetary_value decimal Estimated monetary value of volunteer effort in NOK, based on standard hourly rate
-
social_impact_score decimal Composite score representing estimated social impact of the peer mentor's activities
-
contacts_helped integer Number of unique contacts the peer mentor engaged with in the period
-
advantage_breakdown json Structured breakdown of individual advantage categories (e.g. travel savings, skill development, network growth) with values per category
-
calculation_version string Version identifier of the calculation algorithm used, for reproducibility and future recalculation
required
organization_id uuid Organization context for the calculation, used for org-specific advantage parameters
required
created_at datetime Record creation timestamp
required
updated_at datetime Record last update timestamp
required

Database Indexes

idx_advantage_calculations_user_id
btree

Columns: user_id

idx_advantage_calculations_user_period
btree

Columns: user_id, period_start, period_end

idx_advantage_calculations_calculation_date
btree

Columns: calculation_date

idx_advantage_calculations_organization_id
btree

Columns: organization_id

Validation Rules

period_start_before_end error

Validation failed

non_negative_totals error

Validation failed

valid_user_reference error

Validation failed

advantage_breakdown_schema warning

Validation failed

Business Rules

recalculate_on_activity_change
on_update

Advantage calculation must be refreshed whenever a new activity is logged or an existing one is modified or deleted for the user in the covered period

single_active_calculation_per_period
on_create

Only one calculation record should exist per user per period (year). If a recalculation is triggered, the existing record is updated rather than a duplicate created

peer_mentor_only
on_create

Advantage calculations are only generated for users with the Peer Mentor role; coordinators and admins are excluded

org_scoped_parameters
on_create

Monetary value estimates and advantage categories use organization-specific parameters (e.g. hourly rate, benefit categories) configured at the organization level

Storage Configuration

Storage Type
primary_table
Location
main_db
Partitioning
by_user
Retention
Permanent Storage