increment.js
Overview
This file defines the Increment class, which models a discrete time interval within a meeting for the purpose of calculating incremental costs based on attendee count and average wage. Each Increment instance represents a segment of time with fixed parameters, capturing the start and stop timestamps, elapsed time in seconds, number of attendees, average hourly wage, and the computed cost for that interval. It also maintains a running total cost that accumulates all prior increments' costs.
The Increment class is a fundamental building block within the Incremental Cost Calculation strategy of the Real-Time Meeting Cost Tracking module (79640). By encapsulating time slices and cost computations, it enables precise tracking of meeting expenses even as parameters change dynamically throughout the meeting lifecycle.
Class: Increment
Description
The Increment class encapsulates a single time slice of a meeting during which attendee count and average wage are constant. It calculates the elapsed time in seconds and derives the cost for that interval by prorating the hourly wage to a per-second rate.
Properties
Property | Type | Description |
|---|---|---|
|
| The start time of the increment interval. |
|
| The stop time of the increment interval. |
|
| The duration of the increment in seconds, computed as |
|
| Number of attendees present during this increment. |
|
| Average hourly wage of attendees during this increment. |
|
| The calculated cost for this increment interval based on attendees, wage, and elapsed time. |
|
| Cumulative total cost up to and including this increment. |
|
| Optional description or purpose of the meeting increment. |
Constructor
constructor(
currentIncrementStartTime,
currentIncrementStopTime,
currentIncrementAttendeeCount,
currentIncrementAverageWage,
previousIncrementTotalCost = 0.00,
purpose = ''
)
Parameters
Name | Type | Description |
|---|---|---|
|
| The start time of the increment interval. |
|
| The stop time of the increment interval. |
|
| The number of attendees during this increment. |
|
| The average hourly wage of the attendees during this increment. |
|
| The cumulative total cost from all prior increments; defaults to 0. |
|
| Optional string describing the purpose of the increment or meeting segment. |
Behavior
Computes
elapsedTimeas the difference between stop and start times in seconds.Calculates
costusing the formula:cost = attendeeCount × (averageWage / SECONDS_PER_HOUR) × elapsedTimeAdds this increment's
costtopreviousIncrementTotalCostto produce the currenttotalCost.Assigns the
purposestring.
Usage Example
import Increment from './increment.js';
import { SECONDS_PER_HOUR } from '../constants.js';
const startTime = new Date('2024-06-01T10:00:00Z');
const stopTime = new Date('2024-06-01T10:15:00Z');
const attendees = 5;
const avgWage = 60.00; // $60/hr
const previousTotal = 100.00; // prior increments total cost
const purpose = 'Project Planning';
const increment = new Increment(
startTime,
stopTime,
attendees,
avgWage,
previousTotal,
purpose
);
console.log(increment.elapsedTime); // 900 seconds (15 minutes)
console.log(increment.cost); // cost for this 15-minute increment
console.log(increment.totalCost); // cumulative cost including this increment
Implementation Details
Uses constants
SECONDS_PER_HOUR(3600) andMILLISECONDS_TO_SECONDS(1000) imported from../constants.jsto handle time unit conversions.Time difference calculation uses
(stopTime - startTime) / MILLISECONDS_TO_SECONDSto convert from milliseconds to seconds.Cost calculation prorates the average hourly wage to a per-second wage by dividing by
SECONDS_PER_HOUR.The class stores a cumulative total cost to facilitate quick retrieval of total meeting cost by referencing the last increment's total cost.
Designed for immutability post-construction: once an
Incrementinstance is created, its properties reflect a fixed historical segment.
Interaction with Other System Components
The
Incrementclass is instantiated primarily by theMeetingmodel (see Real-Time Meeting Cost Tracking) when recording discrete time slices during a meeting.The
Meetingclass maintains an array ofIncrementinstances to represent the full meeting duration broken into intervals where parameters remain constant.When attendee count or average wage changes, or when the meeting is stopped, the current increment is finalized using this class.
The
totalCostproperty of the last increment is used to efficiently calculate the overall meeting cost.Data from
Incrementinstances is eventually persisted via the storage abstraction outlined in Persistent Meeting History.UI components consuming cost data rely on these increments for accurate real-time and historical cost display, as covered in Dynamic Cost Visualization.
Mermaid Class Diagram
classDiagram
class Increment {
+startTime
+stopTime
+elapsedTime
+attendeeCount
+averageWage
+cost
+totalCost
+purpose
+constructor()
}
This diagram highlights that Increment is a single class with properties related to time, attendees, wage, cost calculation, and purpose.
Summary
The Increment class is a concise, focused data model representing a single timed segment of a meeting for granular cost calculation. It supports the accurate, incremental tracking of meeting expenses by encapsulating elapsed time, attendees, wage, and cost information. This design underpins the cost calculation mechanisms of the broader meeting lifecycle and visualization modules, enabling precise and flexible financial tracking of meetings over time.