From 058e57aed226f5559db654f91ea8c2f721f8d000 Mon Sep 17 00:00:00 2001 From: Oksana Shadura Date: Fri, 29 Nov 2024 18:17:48 +0100 Subject: [PATCH] Add challenge_area to people.schema.json --- _scripts/challenge_area.rb | 39 +++++++++++++++++++++++++++++++++++++ _scripts/people.schema.json | 5 +++++ 2 files changed, 44 insertions(+) create mode 100644 _scripts/challenge_area.rb diff --git a/_scripts/challenge_area.rb b/_scripts/challenge_area.rb new file mode 100644 index 000000000..013549a1b --- /dev/null +++ b/_scripts/challenge_area.rb @@ -0,0 +1,39 @@ +# frozen_string_literal: true + +require 'yaml' +require 'pathname' +require 'set' + +def ensure_array(arr) + return [] if arr.nil? + + arr.is_a?(Array) ? arr : [arr] +end + +project_files = Pathname.glob('pages/projects/*.md') +counter = {} +project_files.each do |fn| + proj = YAML.load_file fn + + fa = ensure_array proj['challenge-area'] + team = ensure_array proj['team'] + team.reject! { _1.include?(' ') }&.reject! { _1.include?('@') } + + fa.each { |a| team.each { |t| counter[t] = (counter[t] || Set.new) << a } } +end + +people_files = Pathname.glob('_data/people/*.yml') +people_files.each do |fn| + info = YAML.load_file fn + + user_fa = info['presentations']&.flat_map { ensure_array(_1['challenge-area']) }&.to_set&.delete('core') + proj_fa = counter[info['shortname']]&.delete('core') + puts "#{info['name']}: #{user_fa.to_a} | #{proj_fa.to_a}" + all_fa = (user_fa || Set.new) | (proj_fa || Set.new) + info['challenge-area'] = all_fa.to_a unless all_fa.empty? + + sorted = info.sort_by { _1 }.to_h + sorted['presentations'] = sorted.delete 'presentations' + + fn.write(sorted.to_yaml.lines[1..].join) +end diff --git a/_scripts/people.schema.json b/_scripts/people.schema.json index 85096cc06..ba9117c5e 100644 --- a/_scripts/people.schema.json +++ b/_scripts/people.schema.json @@ -11,6 +11,10 @@ "type": "array", "items": { "$ref": "#/definitions/focus_area" } }, + "challenge-area": { + "type": "array", + "items": { "$ref": "#/definitions/challenge_area" } + }, "inspire-id": { "type": "string" }, "institution": { "type": "string" }, "name": { "type": "string" }, @@ -62,6 +66,7 @@ "meeting": { "$ref": "#/definitions/empty_string" }, "meetingurl": { "$ref": "#/definitions/empty_string" }, "focus-area": { "$ref": "#/definitions/focus_areas" }, + "challenge-area": { "$ref": "#/definitions/challenge_area" }, "project": { "$ref": "#/definitions/string_or_array" }, "location": { "$ref": "#/definitions/empty_string" }, "comment": { "$ref": "#/definitions/empty_string" },