Module: EarnedValueCalculator

Extended by:
ActiveModel::Validations
Defined in:
lib/earned_value_calculator.rb,
lib/earned_value_calculator/version.rb,
lib/earned_value_calculator/validator.rb

Overview

This module represents a project metric with Earned Value Management.

Defined Under Namespace

Classes: Validator

Constant Summary collapse

VERSION =
"0.1.6"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.actual_costObject

Returns the value of attribute actual_cost.



15
16
17
# File 'lib/earned_value_calculator.rb', line 15

def actual_cost
  @actual_cost
end

.actual_cost_varianceObject

Returns the value of attribute actual_cost_variance.



15
16
17
# File 'lib/earned_value_calculator.rb', line 15

def actual_cost_variance
  @actual_cost_variance
end

.budgetObject

Returns the value of attribute budget.



15
16
17
# File 'lib/earned_value_calculator.rb', line 15

def budget
  @budget
end

.cost_performance_indexObject

Returns the value of attribute cost_performance_index.



15
16
17
# File 'lib/earned_value_calculator.rb', line 15

def cost_performance_index
  @cost_performance_index
end

.current_lengthObject

Returns the value of attribute current_length.



15
16
17
# File 'lib/earned_value_calculator.rb', line 15

def current_length
  @current_length
end

.earned_valueObject

Returns the value of attribute earned_value.



15
16
17
# File 'lib/earned_value_calculator.rb', line 15

def earned_value
  @earned_value
end

.estimate_at_completionObject

Returns the value of attribute estimate_at_completion.



15
16
17
# File 'lib/earned_value_calculator.rb', line 15

def estimate_at_completion
  @estimate_at_completion
end

.estimate_to_completionObject

Returns the value of attribute estimate_to_completion.



15
16
17
# File 'lib/earned_value_calculator.rb', line 15

def estimate_to_completion
  @estimate_to_completion
end

.planned_valueObject

Returns the value of attribute planned_value.



15
16
17
# File 'lib/earned_value_calculator.rb', line 15

def planned_value
  @planned_value
end

.project_lengthObject

Returns the value of attribute project_length.



15
16
17
# File 'lib/earned_value_calculator.rb', line 15

def project_length
  @project_length
end

.rateObject

Returns the value of attribute rate.



15
16
17
# File 'lib/earned_value_calculator.rb', line 15

def rate
  @rate
end

.schedule_performance_indexObject

Returns the value of attribute schedule_performance_index.



15
16
17
# File 'lib/earned_value_calculator.rb', line 15

def schedule_performance_index
  @schedule_performance_index
end

.schedule_varianceObject

Returns the value of attribute schedule_variance.



15
16
17
# File 'lib/earned_value_calculator.rb', line 15

def schedule_variance
  @schedule_variance
end

.variance_at_completionObject

Returns the value of attribute variance_at_completion.



15
16
17
# File 'lib/earned_value_calculator.rb', line 15

def variance_at_completion
  @variance_at_completion
end

Class Method Details

.calculate_earned_valuesObject



68
69
70
71
72
73
74
75
76
77
78
# File 'lib/earned_value_calculator.rb', line 68

def calculate_earned_values
  @earned_value = (@budget * (@rate.to_f / 100)).to_i
  @planned_value = (@budget * @current_length / @project_length.to_f).to_i
  @schedule_variance =  @earned_value - @planned_value
  @actual_cost_variance = @earned_value - @actual_cost
  @cost_performance_index = @earned_value.to_f / @actual_cost
  @schedule_performance_index = @earned_value.to_f / @planned_value
  @estimate_at_completion = @actual_cost + (@budget - @planned_value) / @cost_performance_index
  @estimate_to_completion = @estimate_at_completion - @actual_cost
  @variance_at_completion = @budget - @estimate_at_completion
end

.call(start_date, end_date, current_date, budget, rate, actual_cost) ⇒ EarnedValueCalculator

Returns The object.

Parameters:

  • start_date (Date)

    The project start date.

  • end_date (Date)

    The project deadline.

  • current_date (Date)

    The current date.

  • budget (Integer)

    The Budget At Completion of the project.

  • rate (Integer)

    The actual rate of progression.

  • actual_cost (Integer)

    The actual full actual_cost of the project.

Returns:

Raises:

  • (ArgumentError)


54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/earned_value_calculator.rb', line 54

def call(start_date, end_date, current_date, budget, rate, actual_cost)
  validator = EarnedValueCalculator::Validator
              .new(start_date, end_date, current_date, budget, rate, actual_cost)
  raise ArgumentError, validator.errors.messages unless validator.valid?

  @project_length = (start_date..end_date).select(&:workday?).size
  @current_length = (start_date..current_date).select(&:workday?).size
  @budget = budget
  @rate = rate
  @actual_cost = actual_cost
  calculate_earned_values
  self
end