Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add total module duration + LOs per module in LPs #5624

Merged
merged 5 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions _layouts/learning-pathway.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,23 @@ <h3 id="st-{{ section.section | slugify }}">{{ section.section }}</h3>

{% if section.tutorials %}
{% assign material_list = site | convert_to_material_list: section.tutorials %}
<p><strong>{% icon time aria=false %} {{ locale['time-estimation'] | default: "Time estimation"}}:</strong> {{ material_list | sum_duration }}</p>
<details>
<summary>Learning Objectives</summary>
<ul>
{% if section.learning_objectives %}
{% for lo in section.learning_objectives %}
<li>{{ lo }}</li>
{% endfor %}
{% else %}
{% for material in material_list %}
{% for lo in material.objectives %}
<li>{{ lo }}</li>
{% endfor %}
{% endfor %}
{% endif %}
</ul>
</details>
{% include _includes/tutorial_list.html sub=material_list %}
{% endif %}
{% endfor %}
Expand Down
88 changes: 76 additions & 12 deletions _plugins/jekyll-duration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ module DurationFilter
# {{ "T1H30M" | duration_to_human }}
# => "1 hour 30 minutes"
def duration_to_human(duration)
# Match the different parts of the string, must match entire string or it will fail.
match = /^(?:([0-9]*)[Hh])*(?:([0-9]*)[Mm])*(?:([0-9.]*)[Ss])*$/.match(duration)

# If it doesn't match, pass through unedited so we don't cause unexpected issues.
if match.nil?
puts "Could not parse time: #{duration}"
seconds = parse_rfc3339(duration)
if seconds.nil?
return duration
end
return fmt_duration(seconds)
end

def fmt_duration(seconds)
d = resolve_hms(seconds)

# Otherwise append english terms for the various parts
duration_parts = []
Expand All @@ -37,22 +38,85 @@ def duration_to_human(duration)
end

# Hours
if !match[1].nil?
if match[1] == '1'
duration_parts.push("#{match[1]} " + hour)
if d[:hours] > 0
if d[:hours] == 1
duration_parts.push("#{d[:hours]} " + hour)
else
duration_parts.push("#{match[1]} " + hours)
duration_parts.push("#{d[:hours]} " + hours)
end
end

# Minutes - assuming no one uses `1 minute`
duration_parts.push("#{match[2]} " + minutes) if !match[2].nil?
duration_parts.push("#{d[:minutes]} " + minutes) if d[:minutes] > 0

# Hopefully no one uses seconds
duration_parts.push("#{match[3]} seconds") if !match[3].nil?
duration_parts.push("#{d[:seconds]} seconds") if d[:seconds] > 0

duration_parts.join(' ')
end

##
# Sum the durations correctly for multiple RFC3339 formatted durations.
# Params:
# +s+:: The RFC3339 formatted duration string
# Returns:
# +d+:: a number of seconds
def parse_rfc3339(s)
if s == 0
return 0
end

# Match the different parts of the string, must match entire string or it
# will fail.
match = /^T?(?:([0-9]*)[Hh])*(?:([0-9]*)[Mm])*(?:([0-9.]*)[Ss])*$/.match(s)

# If it doesn't match, pass through unedited so we don't cause unexpected
# issues.
if match.nil?
Jekyll.logger.debug "[GTN/Durations]:", "Could not parse time: #{s}"
return nil
end

return match[1].to_i * 3600 + match[2].to_i * 60 + match[3].to_i
end

##
# Turn a count of seconds into hours/minutes/seconds.
# Params:
# +Int+:: A number of seconds
# Returns:
# +Hash+:: A hash with keys for hours, minutes, and seconds
#
# Example:
# resolve_hms(5400)
# => { hours: 1, minutes: 30, seconds: 0 }
def resolve_hms(seconds)
# Normalize the total
minutes = seconds / 60
seconds = seconds % 60
hours = minutes / 60
minutes = minutes % 60

{ hours: hours, minutes: minutes, seconds: seconds }
end

##
# Sum the durations correctly for multiple RFC3339 formatted durations.
# Params:
# +materials+:: The GTN material objects
# Returns:
# +String+:: The human total duration
def sum_duration(materials)
Jekyll.logger.debug "[GTN/Durations]: sum durations with #{materials.length} materials."
total = 0
materials.each do |material|
if ! material['time_estimation'].nil?
Jekyll.logger.debug " [GTN/Durations]: #{material['time_estimation']} #{material['title']} -> #{parse_rfc3339(material['time_estimation'])}"
total += parse_rfc3339(material['time_estimation'])
end
end
fmt_duration(total)
end
end
end

Expand Down
17 changes: 17 additions & 0 deletions bin/schema-learning-pathway.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,23 @@ mapping:
required: true
description:
type: str
learning_objectives:
type: seq
sequence:
- type: str
required: true
description: |
List of Specific, Measurable, Achievable, Relevant, and Time-bound (SMART) learning objectives for the tutorial

A learning objective is a single sentence describing what a learner will be able to do once they have done the tutorial. Generally it is best to follow a 2C or 3C learning objective such as:

- Compute (Skill)
- multiple whole genome assemblies (Objective)
- in such a way to develop big data processing skills (Result)
_examples:
- Understand the basic concepts behind phylogenetic trees, as applied to *Mycobacterium tuberculosis*
- Explore Biodiversity data with taxonomic, temporal and geographical informations
- Generate a DotPlot emulating the original paper using a different analysis tool
tutorials:
type: seq
sequence:
Expand Down
2 changes: 1 addition & 1 deletion bin/schema-tutorial.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ mapping:
- type: str
required: true
description: |
list of learning objectives for the tutorial
List of Specific, Measurable, Achievable, Relevant, and Time-bound (SMART) learning objectives for the tutorial

A learning objective is a single sentence describing what a learner will be able to do once they have done the tutorial. Generally it is best to follow a 2C or 3C learning objective such as:

Expand Down
Loading