Class: RubyMaat::Analysis::CodeAge
- Inherits:
-
BaseAnalysis
- Object
- BaseAnalysis
- RubyMaat::Analysis::CodeAge
- Defined in:
- lib/ruby_maat/analysis/code_age.rb
Overview
Code age analysis - measures how long since each entity was last modified
Instance Method Summary collapse
Instance Method Details
#analyze(dataset, options = {}) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/ruby_maat/analysis/code_age.rb', line 7 def analyze(dataset, = {}) reference_date = [:age_time_now] || Date.today # Find the latest modification date for each entity entity_latest_dates = {} dataset.to_df.each_row do |row| entity = row["entity"] date = row["date"] entity_latest_dates[entity] = date if entity_latest_dates[entity].nil? || date > entity_latest_dates[entity] end # Calculate age in months for each entity results = entity_latest_dates.map do |entity, last_date| months_old = calculate_months_between(last_date, reference_date) { entity: entity, "age-months": months_old } end # Sort by age descending (oldest first) results.sort_by! { |r| -r[:"age-months"] } to_csv_data(results, %i[entity age-months]) end |