From 559d3c0d4c39e9734951a1e1028572644c9e818f Mon Sep 17 00:00:00 2001 From: Helena Rasche Date: Tue, 14 Nov 2023 15:37:47 +0100 Subject: [PATCH 1/4] add fetcher --- bin/fetch-categories.rb | 61 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 bin/fetch-categories.rb diff --git a/bin/fetch-categories.rb b/bin/fetch-categories.rb new file mode 100644 index 00000000000000..caf11926c67228 --- /dev/null +++ b/bin/fetch-categories.rb @@ -0,0 +1,61 @@ +#!/usr/bin/env ruby +require 'json' +require 'net/http' +require 'uri' +require 'yaml' + +# Get the list of toolcats +def fetch_toolcats(server) + uri = URI.parse("#{server}") + request = Net::HTTP::Get.new(uri) + req_options = { + use_ssl: uri.scheme == 'https', + } + response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http| + http.request(request) + end + + begin + JSON.parse(response.body) do |w| + w + end + rescue StandardError + {} + end +end + +# Parse the response +toolcats_eu = fetch_toolcats('https://usegalaxy-eu.github.io/usegalaxy-eu-tools/api/labels.json') +# toolcats_eu = File.open('/tmp/tmp.ccFYsrbAa5/usegalaxy-eu-tools/api/labels.json') { |f| YAML.safe_load(f) } +toolcats_org = fetch_toolcats('https://galaxyproject.github.io/usegalaxy-tools/api/labels.json') +toolcats_aus = fetch_toolcats('https://usegalaxy-au.github.io/usegalaxy-au-tools/api/labels.json') +# toolcats_aus = File.open('/tmp/tmp.ccFYsrbAa5/usegalaxy-au-tools/api/labels.json') { |f| YAML.safe_load(f) } +tool_ids = (toolcats_org.keys + toolcats_eu.keys + toolcats_aus.keys).uniq +# tool_ids = toolcats_org.keys +tool_ids.sort! + +toolcats = {} +# Cleanup the list +tool_ids.each do |k| + eu = toolcats_eu[k] || nil + org = toolcats_org[k] || nil + aus = toolcats_aus[k] || nil + + # We get N 'votes' for the categories + values = [eu, org, aus].compact + # values = [org].compact + + + # Majority answer wins + # set that value to toolcats[k] + # If there is no majority, pick one. + # print("#{k} - #{values.length} => #{values.uniq.compact.length}\n") + if values.length.positive? + toolcats[k] = values.max_by { |v| v['count'] } + else + toolcats[k] = nil + end +end + +# Write the list to a file +File.write('metadata/toolcats.yml', toolcats.to_yaml) From 0e3b581859b9f3a5903ebe4fbdbb9770dc0e159f Mon Sep 17 00:00:00 2001 From: Helena Rasche Date: Tue, 14 Nov 2023 15:38:29 +0100 Subject: [PATCH 2/4] add to make --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index 6a62062d6e9d39..40342246188c92 100644 --- a/Makefile +++ b/Makefile @@ -235,6 +235,7 @@ annotate: ## annotate the tutorials with usable Galaxy instances wget https://github.com/hexylena/toolshed-version-database/raw/main/guid-rev.json -O metadata/toolshed-revisions.json && \ python bin/supported-fetch.py bin/workflows-fetch.rb + bin/fetch-categories.rb .PHONY: annotate rebuild-search-index: ## Rebuild search index From 52c60574073b5b7b50df4992f92987578b2eb940 Mon Sep 17 00:00:00 2001 From: Helena Rasche Date: Tue, 14 Nov 2023 15:40:42 +0100 Subject: [PATCH 3/4] use new metadata source for categories --- _plugins/gtn/toolshed.rb | 4 ++-- _plugins/jekyll-topic-filter.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/_plugins/gtn/toolshed.rb b/_plugins/gtn/toolshed.rb index c292f2d0e72854..6d80ff9c162a43 100644 --- a/_plugins/gtn/toolshed.rb +++ b/_plugins/gtn/toolshed.rb @@ -13,7 +13,7 @@ module Toolshed # +topic+:: The topic to install the tools under # Returns: # +supported+:: A string of the admin install, ready for ephemeris - def self.format_admin_install(data, tool_list, topic) + def self.format_admin_install(data, tool_list, topic, tool_cats) # p "Calculating supported servers for this tool list" return {} if data.nil? || data.empty? @@ -23,7 +23,7 @@ def self.format_admin_install(data, tool_list, topic) 'name' => tool_info[1], 'owner' => tool_info[0], 'revisions' => tool_info[2], - 'tool_panel_section_label' => topic, + 'tool_panel_section_label' => tool_cats["#{tool_info[0]}/#{tool_info[1]}"] || topic, 'tool_shed_url' => 'https://toolshed.g2.bx.psu.edu/', } end diff --git a/_plugins/jekyll-topic-filter.rb b/_plugins/jekyll-topic-filter.rb index 5ca9edb9aacaa6..df8f716fdcf513 100644 --- a/_plugins/jekyll-topic-filter.rb +++ b/_plugins/jekyll-topic-filter.rb @@ -521,7 +521,7 @@ def self.resolve_material(site, material) topic_name_human = site.data[page_obj['topic_name']]['title'] page_obj['topic_name_human'] = topic_name_human # TODO: rename 'topic_name' and 'topic_name' to 'topic_id' admin_install = Gtn::Toolshed.format_admin_install(site.data['toolshed-revisions'], page_obj['tools'], - topic_name_human) + topic_name_human, site.data['toolcats']) page_obj['admin_install'] = admin_install page_obj['admin_install_yaml'] = admin_install.to_yaml From ce6c975b48b0c0cadbf09b31c9a8c907bb953891 Mon Sep 17 00:00:00 2001 From: Helena Rasche Date: Tue, 14 Nov 2023 15:47:55 +0100 Subject: [PATCH 4/4] expose in API --- _plugins/api.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/_plugins/api.rb b/_plugins/api.rb index 2a5c754abe1aa5..c088d001f98d95 100644 --- a/_plugins/api.rb +++ b/_plugins/api.rb @@ -143,6 +143,18 @@ def generate(site) page2.data['layout'] = nil site.pages << page2 + # Tool Categories + page2 = PageWithoutAFile.new(site, '', 'api/', 'toolcats.json') + page2.content = JSON.generate(site.data['toolcats']) + page2.data['layout'] = nil + site.pages << page2 + + # Tool Categories + page2 = PageWithoutAFile.new(site, '', 'api/', 'toolshed-revisions.json') + page2.content = JSON.generate(site.data['toolshed-revisions']) + page2.data['layout'] = nil + site.pages << page2 + # Contributors puts '[GTN/API] Contributors, Funders, Organisations' %w[contributors funders organisations].each do |type|