|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +if Gem.ruby_version < Gem::Version.new('2.7.0') |
| 4 | + # Add filter_map |
| 5 | + require 'ruby-next' |
| 6 | + using RubyNext |
| 7 | +end |
| 8 | + |
| 9 | +def process_projects(projects) |
| 10 | + projects.filter_map do |project| |
| 11 | + project['start-date'] && { |
| 12 | + title: project['title'], |
| 13 | + focus_area: [*project['focus-area']], |
| 14 | + start: project['start-date'], |
| 15 | + end: project['end-date'] || Date.today, |
| 16 | + maturity: project['maturity'], |
| 17 | + status: MAT_TO_KW[project['maturity']] |
| 18 | + } |
| 19 | + end |
| 20 | +end |
| 21 | + |
| 22 | +MAT_TO_KW = { |
| 23 | + 'Development' => 'done', |
| 24 | + 'Exploratory' => 'done', |
| 25 | + 'Testing' => 'done', |
| 26 | + 'Unknown' => 'done', |
| 27 | + 'Deployed' => 'active', |
| 28 | + 'Archived' => 'crit' |
| 29 | +}.freeze |
| 30 | + |
| 31 | +def make_section(projects) |
| 32 | + projects.map do |p| |
| 33 | + format(' %<title>-34s :%<status>-7s, %<start>s, %<end>s', p) |
| 34 | + end.join("\n") |
| 35 | +end |
| 36 | + |
| 37 | +# IRIS-HEP modules |
| 38 | +module IrisHep |
| 39 | + # IRIS-HEP project gantt charts |
| 40 | + module GanttFilters |
| 41 | + def gantt_projects(projects_raw) |
| 42 | + projects = process_projects(projects_raw) |
| 43 | + result = "<div class=\"mermaid\"> |
| 44 | +gantt |
| 45 | + title IRIS-HEP project lifecyles |
| 46 | + dateFormat YYYY-MM-DD |
| 47 | + axisFormat %Y |
| 48 | +" |
| 49 | + ia = projects.filter { |p| p[:focus_area].include?('ia') } |
| 50 | + doma = projects.filter { |p| p[:focus_area].include?('doma') || p[:focus_area].include?('osglhc') } |
| 51 | + as = projects - ia - doma |
| 52 | + { ia: ia, doma: doma, as: as }.each do |sec, val| |
| 53 | + result += "\n section #{sec}\n" |
| 54 | + result += make_section(val) |
| 55 | + end |
| 56 | + result += "\n</div>" |
| 57 | + result |
| 58 | + end |
| 59 | + |
| 60 | + def gantt_project(projects_raw, name) |
| 61 | + projects = process_projects(projects_raw) |
| 62 | + result = "<div class=\"mermaid\"> |
| 63 | +gantt |
| 64 | + title #{name} project lifecyles |
| 65 | + dateFormat YYYY-MM-DD |
| 66 | + axisFormat %Y |
| 67 | +" |
| 68 | + result += make_section(projects) |
| 69 | + result += '</div>' |
| 70 | + result |
| 71 | + end |
| 72 | + end |
| 73 | +end |
| 74 | + |
| 75 | +Liquid::Template.register_filter(IrisHep::GanttFilters) |
0 commit comments