module Jekyll::Filters::TopicFilter
Public Instance Methods
# File _plugins/jekyll-topic-filter.rb, line 1566 def count_topic_materials_yearly(site, topic_name) flat_mats = list_materials_flat(site, topic_name) years = flat_mats.map{|x| x['pub_date'].year} + flat_mats.map{|x| x['mod_date'].year} # doesn't use identify_contributors because that excludes grants/orgs. topic_contribs = flat_mats.map{|x| x['contributions'] || {"all" => x['contributors']}}.map{|x| x.values.flatten}.flatten.uniq.sort pfo = ['contributors', 'grants', 'organisations'] r = Gtn::TopicFilter.all_date_sorted_resources(site) .select{|x| (x[3].include? topic_name) || (pfo.include?(x[1]) && topic_contribs.include?(x[2].title[1..]))} .map{|x| [x[0].year, x[1]]} # Only need year + type .group_by{|x| x[1]} # Group by type. .map{|k, v| [k, v.map{|vv| vv[0]}.tally]} .to_h years = (2015..Date.today.year).to_a # Fill in zeros for missing years r.map{|k, v| [k, years.map{|y| v[y] || 0} .cumulative_sum .map.with_index{|value, i| {"y" => value, "x" => "#{years[i]}-01-01"}}] }.to_h end
# File _plugins/jekyll-topic-filter.rb, line 1653 def edamify(term, site) site.data['EDAM'].select{|row| row['Class ID'] == "http://edamontology.org/#{term}"}.first.to_h end
Fetch a tutorial material’s metadata Parameters:
site
-
The
Jekyll::Site
object, used to get the list of pages. topic_name
-
The name of the topic
page_name
-
The name of the page
Returns:
Hash
-
The metadata for the tutorial material
Example:
{% assign material = site | fetch_tutorial_material:page.topic_name,page.tutorial_name%}
# File _plugins/jekyll-topic-filter.rb, line 1487 def fetch_tutorial_material(site, topic_name, page_name) Gtn::TopicFilter.fetch_tutorial_material(site, topic_name, page_name) end
# File _plugins/jekyll-topic-filter.rb, line 1491 def fetch_tutorial_material_by_id(site, id) Gtn::TopicFilter.fetch_tutorial_material(site, id.split('/')[0], id.split('/')[1]) end
# File _plugins/jekyll-topic-filter.rb, line 1617 def findDuration(duration) if ! duration.nil? eval(duration.gsub(/H/, ' * 3600 + ').gsub(/M/, ' * 60 + ').gsub(/S/, ' + ') + " 0") else 0 end end
# File _plugins/jekyll-topic-filter.rb, line 1644 def get_workflow(site, page, workflow) mat = to_material(site, page) mat['workflows'].select { |w| w['workflow'] == workflow }[0] end
# File _plugins/jekyll-topic-filter.rb, line 1600 def identify_contributors(materials, site) Gtn::TopicFilter.identify_contributors(materials, site) end
# File _plugins/jekyll-topic-filter.rb, line 1604 def identify_funders(materials, site) Gtn::TopicFilter.identify_funders_and_grants(materials, site) end
# File _plugins/jekyll-topic-filter.rb, line 1632 def list_draft_materials(site) Gtn::TopicFilter.list_all_materials(site).select { |k, _v| k['draft'] } end
Galaxy depends on the structure of this response, please do not change it, add a new API instead if you need to modify it significantly.
# File _plugins/jekyll-topic-filter.rb, line 1536 def list_materials_by_tool(site) Gtn::TopicFilter.list_materials_by_tool(site) end
# File _plugins/jekyll-topic-filter.rb, line 1544 def list_materials_flat(site, topic_name) Gtn::TopicFilter .list_materials_structured(site, topic_name) .map { |k, v| v['materials'] } .flatten .uniq { |x| x['id'] } end
# File _plugins/jekyll-topic-filter.rb, line 1540 def list_materials_structured(site, topic_name) Gtn::TopicFilter.list_materials_structured(site, topic_name) end
# File _plugins/jekyll-topic-filter.rb, line 1552 def list_topic_materials_yearly(site, topic_name) flat_mats = list_materials_flat(site, topic_name) years = flat_mats.map{|x| x['pub_date'].year} + flat_mats.map{|x| x['mod_date'].year} # doesn't use identify_contributors because that excludes grants/orgs. topic_contribs = flat_mats.map{|x| x['contributions'] || {"all" => x['contributors']}}.map{|x| x.values.flatten}.flatten.uniq.sort pfo = ['contributors', 'grants', 'organisations'] Gtn::TopicFilter.all_date_sorted_resources(site) .select{|x| (x[3].include? topic_name) || (pfo.include?(x[1]) && topic_contribs.include?(x[2].title[1..]))} .group_by{|x| x[0].year} .map{|k, v| [k, v.group_by{|z| z[1]}]} .to_h end
# File _plugins/jekyll-topic-filter.rb, line 1503 def list_topics_by_category(site, category) q = Gtn::TopicFilter.list_topics(site).map do |k| [k, site.data[k]] end # Alllow filtering by a category, or return "all" otherwise. if category == 'non-tag' q = q.select { |_k, v| v['tag_based'].nil? } elsif category == 'science' q = q.select { |_k, v| %w[use basics].include? v['type'] } elsif category == 'technical' q = q.select { |_k, v| %w[admin-dev data-science instructors].include? v['type'] } elsif category == 'science-technical' q = q.select { |_k, v| %w[use basics admin-dev data-science instructors].include? v['type'] } elsif category != 'all' q = q.select { |_k, v| v['type'] == category } end # Sort alphabetically by titles q.sort { |a, b| a[1]['title'] <=> b[1]['title'] } end
# File _plugins/jekyll-topic-filter.rb, line 1499 def list_topics_h(site) Gtn::TopicFilter.list_topics(site) end
# File _plugins/jekyll-topic-filter.rb, line 1495 def list_topics_ids(site) ['introduction'] + Gtn::TopicFilter.list_topics(site).filter { |k| k != 'introduction' } end
Just used for stats page.
# File _plugins/jekyll-topic-filter.rb, line 1610 def list_videos(site) Gtn::TopicFilter.list_all_materials(site) .select { |k, _v| k['recordings'] || k['slides_recordings'] } .map { |k, _v| (k['recordings'] || []) + (k['slides_recordings'] || []) } .flatten end
Just used for stats page.
# File _plugins/jekyll-topic-filter.rb, line 1627 def list_videos_total_time(site) vids = list_videos(site) vids.map { |v| findDuration(v['length']) }.sum / 3600.0 end
List the most recent contributors to the GTN. Parameters:
contributors
-
A hash of contributors
count
-
The number of contributors to return
Returns:
Hash
-
A hash of contributors
Example: most_recent_contributors
(contributors, 5)
> {¶ ↑
"hexylena" => { "name" => "Hexylena", "avatar" => "https://avatars.githubusercontent.com/u/458683?v=3", ... }
}
# File _plugins/jekyll-topic-filter.rb, line 1418 def most_recent_contributors(contributors, count) # Remove non-hof hof = contributors.reject { |_k, v| v.fetch('halloffame', 'yes') == 'no' } # Get keys + sort by joined date hof_k = hof.keys.sort do |x, y| hof[y].fetch('joined', '2016-01') <=> hof[x].fetch('joined', '2016-01') end # Transform back into hash hof_k.slice(0, count).to_h { |k| [k, hof[k]] } end
Find the most recently modified tutorials Parameters:
site
-
The
Jekyll::Site
object, used to get the list of pages. exclude_recently_published
-
Do not include ones that were recently published in the slice, to make it look a bit nicer.
Returns:
Array
-
An array of the 10 most recently modified pages
Example:
{% assign latest_tutorials = site | recently_modified_tutorials %}
# File _plugins/jekyll-topic-filter.rb, line 1440 def recently_modified_tutorials(site, exclude_recently_published: true) tutorials = site.pages.select { |page| page.data['layout'] == 'tutorial_hands_on' } latest = tutorials.sort do |x, y| Gtn::ModificationTimes.obtain_time(y.path) <=> Gtn::ModificationTimes.obtain_time(x.path) end latest_published = recently_published_tutorials(site) latest = latest.reject { |x| latest_published.include?(x) } if exclude_recently_published latest.slice(0, 10) end
Find the most recently published tutorials Parameters:
site
-
The
Jekyll::Site
object, used to get the list of pages.
Returns:
Array
-
An array of the 10 most recently published modified pages
Example:
{% assign latest_tutorials = site | recently_modified_tutorials %}
# File _plugins/jekyll-topic-filter.rb, line 1461 def recently_published_tutorials(site) tutorials = site.pages.select { |page| page.data['layout'] == 'tutorial_hands_on' } latest = tutorials.sort do |x, y| Gtn::PublicationTimes.obtain_time(y.path) <=> Gtn::PublicationTimes.obtain_time(x.path) end latest.slice(0, 10) end
# File _plugins/jekyll-topic-filter.rb, line 1657 def titlecase(term) term.split(' ').map(&:capitalize).join(' ') end
# File _plugins/jekyll-topic-filter.rb, line 1525 def to_keys(arr) arr.map { |k| k[0] } end
# File _plugins/jekyll-topic-filter.rb, line 1636 def to_material(site, page) topic = page['path'].split('/')[1] material = page['path'].split('/')[3] ret = Gtn::TopicFilter.fetch_tutorial_material(site, topic, material) Jekyll.logger.warn "Could not find material #{topic} #{material}" if ret.nil? ret end
# File _plugins/jekyll-topic-filter.rb, line 1529 def to_vals(arr) arr.map { |k| k[1] } end
# File _plugins/jekyll-topic-filter.rb, line 1649 def tool_version_support(site, tool) Gtn::Supported.calculate(site.data['public-server-tools'], [tool]) end
# File _plugins/jekyll-topic-filter.rb, line 1471 def topic_count(resources) # Count lines in the table except introduction slides resources.length end
# File _plugins/jekyll-topic-filter.rb, line 1592 def topic_filter(site, topic_name) Gtn::TopicFilter.topic_filter(site, topic_name) end
# File _plugins/jekyll-topic-filter.rb, line 1596 def topic_filter_tutorial_count(site, topic_name) Gtn::TopicFilter.topic_filter(site, topic_name).length end