meeting.js
Overview
This file defines the Meeting class, which encapsulates the core logic for managing the lifecycle, state, and cost calculations of a meeting session. It models a meeting as a sequence of discrete time increments, each capturing a snapshot of attendee count, average wage, elapsed time, and purpose. The class supports starting, stopping, resetting meetings, and dynamically updating parameters such as attendee count, average wage, and meeting purpose during an active session.
Meeting interacts closely with the Increment class (imported from increment.js), which represents individual time slices with associated cost calculations, and with a warehouse instance responsible for persistent storage of completed meeting increments.
This file is central to the functionality described in Real-Time Meeting Cost Tracking, Meeting Lifecycle Management, and Incremental Cost Calculation.
Class: Meeting
Properties
clockRunning(boolean): Indicates whether the meeting timer is currently active.increments(Increment[]): Array holding completed increments representing past time intervals of the meeting.currentIncrementStartTime(Date|string): Timestamp marking the start of the current increment; empty string if no increment ongoing.currentIncrementAttendeeCount(number): Number of attendees for the current increment.currentIncrementAverageWage(number): Average hourly wage for attendees during the current increment.purpose(string): Descriptive purpose or topic of the meeting.warehouse(object): External storage interface used for saving meeting increments.
Constructor
constructor(attendeeCount, averageWage, warehouse, increments = [], purposeInput = '')
Parameters:
attendeeCount(number): Initial attendee count for the meeting.averageWage(number): Initial average hourly wage.warehouse(object): Storage handler object for persisting increments.increments(Increment[], optional): Pre-existing increments (defaults to empty array).purposeInput(string, optional): Initial meeting purpose (defaults to empty string).
Description:
Initializes the meeting instance with provided attendee count, wage, warehouse interface, increments, and purpose.Example Usage:
const meeting = new Meeting(5, 20, warehouseInstance, [], 'Budget Planning');
Methods
startMeeting()
startMeeting()
Description:
Begins a new meeting session by clearing all previous increments, setting the clock running flag totrue, and recording the start time of the first increment as the current time.Usage Example:
meeting.startMeeting();
stopMeeting()
stopMeeting()
Description:
Stops the meeting timer, pushes the final increment capturing the elapsed time since the last increment started, and saves all increments to persistent storage via the warehouse interface.Implementation Detail:
CallspushIncrement()internally to close the current increment before saving.Usage Example:
meeting.stopMeeting();
resetMeeting()
resetMeeting()
Description:
Resets the meeting instance to its default state as defined by the staticdefaultObject. This clears all increments, stops the clock, and resets attendee count, wage, and purpose to defaults.Implementation Detail:
UsesObject.keysto iterate over default properties and assign them to the current instance.Usage Example:
meeting.resetMeeting();
changeAttendeeCount(newAttendeeCount)
changeAttendeeCount(newAttendeeCount)
Parameters:
newAttendeeCount(number): New attendee count to apply.
Description:
Updates the attendee count for the meeting. Before changing, it pushes the current increment to preserve the elapsed time and cost with the previous attendee count, then starts a new increment with the updated count.Usage Example:
meeting.changeAttendeeCount(6);
changeAverageWage(newAverageWage)
changeAverageWage(newAverageWage)
Parameters:
newAverageWage(number): New average hourly wage.
Description:
Similar tochangeAttendeeCount, this method pushes the current increment and then updates the average wage for the new increment.Usage Example:
meeting.changeAverageWage(22.5);
changePurpose(purpose)
changePurpose(purpose)
Parameters:
purpose(string): New meeting purpose.
Description:
Updates the purpose or description of the meeting. This does not affect increments or timing.Usage Example:
meeting.changePurpose('Quarterly Review');
getTotalCost()
getTotalCost() : number
Returns:
Total cost of the meeting so far as a floating-point number.Description:
Computes the total meeting cost by summing completed increments plus the ongoing increment cost if the meeting is running. Uses theIncrementclass to calculate the cost of the current active increment.Implementation Detail:
Retrieves the last increment's total cost as the base, then adds the current running increment's cost if active.Usage Example:
const cost = meeting.getTotalCost(); console.log(`Total meeting cost: $${cost.toFixed(2)}`);
getTotalTime()
getTotalTime() : number
Returns:
Total elapsed meeting time in seconds (including running increment if any).Description:
Sums elapsed time of all completed increments and adds the elapsed time of the current running increment.Usage Example:
const elapsedSeconds = meeting.getTotalTime();
getMaxAttendees()
getMaxAttendees() : number
Returns:
The maximum number of attendees recorded in any increment during the meeting.Description:
Iterates over all increments to find the highest attendee count.
burnPerSecond()
burnPerSecond() : number
Returns:
The current cost burn rate per second.Description:
Calculates the cost burn rate using the formula:[
\text{burnPerSecond} = \frac{\text{currentIncrementAttendeeCount} \times \text{currentIncrementAverageWage}}{3600}
]Where 3600 seconds = 1 hour.
burnPerMinute()
burnPerMinute() : number
Returns:
The current cost burn rate per minute.Description:
MultipliesburnPerSecond()by 60 seconds.
timeElapsedInSeconds(currentTime = new Date, pastTime = this.currentIncrementStartTime)
timeElapsedInSeconds(currentTime, pastTime) : number
Parameters:
currentTime(Date, optional): Reference end time; defaults to current time.pastTime(Date, optional): Reference start time; defaults tocurrentIncrementStartTime.
Returns:
Elapsed time in seconds betweenpastTimeandcurrentTime.Description:
Calculates the difference between two timestamps and converts from milliseconds to seconds.
pushIncrement()
pushIncrement()
Description:
Closes the current increment by creating a newIncrementobject fromcurrentIncrementStartTimeto now, with current attendee count, wage, and cumulative total cost. The new increment is appended to theincrementsarray. ThecurrentIncrementStartTimeis updated to now for the next increment.Implementation Details:
No action if
currentIncrementStartTimeis empty.Retrieves the last increment's total cost for cumulative calculation.
Passes meeting
purposeto the newIncrement.
Usage:
Called internally by lifecycle methods (stopMeeting, parameter changes) to segment meeting time accurately.
Static Properties
defaultObject
static get defaultObject()
Returns:
An object defining default property values for a meeting instance, including default attendee count, wage, empty increments, and stopped clock.Purpose:
Used byresetMeeting()to restore initial state.
Important Implementation Details
Incremental Time Segmentation:
The meeting time is segmented into discrete increments each time an attendee count or wage changes, or when the meeting stops. This enables precise cost tracking over varying parameters.Cumulative Cost Tracking:
EachIncrementstores its own cost and the cumulative total cost up to that point, allowing efficient retrieval of total meeting cost without recalculating all increments.Real-Time Cost Calculation:
getTotalCost()accounts for completed increments plus the ongoing increment calculated on-demand, enabling live updates of meeting cost.Storage Integration:
The meeting instance delegates persistence to thewarehouseobject, which saves increments when the meeting stops (Persistent Meeting History).
Interactions with Other System Components
Increment Class:
Meetingdepends onIncrementfor modeling individual time slices with cost calculation logic. This class is imported fromincrement.js.Warehouse Storage:
The warehouse parameter provides methods to save increments for persistence. This integration supports long-term meeting cost history reviewed via the persistent history module.User Interface and Event Handling:
External UI components (likely inindex.jsand view layers) invokeMeetingmethods such asstartMeeting,stopMeeting,changeAttendeeCount, andchangeAverageWagein response to user actions (User Interaction and Interface).Real-Time Updates:
Meetingprovides data for live cost and time visualization (Dynamic Cost Visualization).
Visual Diagram
classDiagram
class Meeting {
+boolean clockRunning
+Increment[] increments
+Date|string currentIncrementStartTime
+number currentIncrementAttendeeCount
+number currentIncrementAverageWage
+string purpose
+object warehouse
+constructor(attendeeCount, averageWage, warehouse, increments, purposeInput)
+startMeeting()
+stopMeeting()
+resetMeeting()
+changeAttendeeCount()
+changeAverageWage()
+changePurpose()
+getTotalCost()
+getTotalTime()
+getMaxAttendees()
+burnPerSecond()
+burnPerMinute()
+timeElapsedInSeconds()
-pushIncrement()
+static defaultObject
}
Meeting --> Increment : uses >
Additional Notes
The
pushIncrement()method is marked as "private-ish" in comments, indicating it is intended for internal use within the class to close increments correctly.Constants such as SECONDS_PER_MINUTE, SECONDS_PER_HOUR, and MILLISECONDS_TO_SECONDS are imported from a constants module to ensure clarity and maintainability of time unit conversions.
The
purposeproperty is carried through increments but can be updated independently without starting a new increment.The
getTotalCost()method carefully handles the case when there are no increments and when the meeting is running, returning zero or the current accumulated cost accordingly.
This file provides the foundational data model and logic for managing meetings in the application, supporting precise, real-time cost tracking as meetings progress and parameters evolve dynamically.