Module: ProjectsHelper
- Included in:
- ApplicationController
- Defined in:
- app/helpers/projects_helper.rb
Overview
A controller include, need to split out session methods versus those that aren’t
Constant Summary collapse
- CLASSIFIER =
{ nomenclature: [TaxonName, TaxonNameRelationship, TaxonNameClassification, TypeMaterial ], digitization: [CollectionObject, CollectingEvent, Loan, LoanItem, TaxonDetermination ], descriptive: [Otu, ControlledVocabularyTerm, Content, Observation, ObservationMatrix, Descriptor, Image, BiologicalAssociation, CharacterState, ObservationMatrixRow, ObservationMatrixColumn], literature: [ProjectSource, Citation, CitationTopic, Documentation, Document ], geospatial: [Georeference, AssertedDistribution], }
- CLASSIFIER_ANNOTATION =
[Identifier, Note, Tag, AlternateValue, Attribution, Confidence, Depiction ]
Instance Method Summary collapse
- #cumulative_gb_per_year(sums) ⇒ Object
-
#cumulative_projects_created_per_year ⇒ Object
Cumulative Projects Created per Year From chatGPT 5.0 default.
- #document_cumulative_gb_per_year ⇒ Object
- #document_gb_per_year ⇒ Object
- #gb_per_year(sums) ⇒ Object
- #image_cumulative_gb_per_year ⇒ Object
- #image_gb_per_year ⇒ Object
-
#invalid_object(object) ⇒ Object
Came from application_controller.
- #project_classification(project) ⇒ Object
- #project_link(project) ⇒ Object
- #project_matches(object) ⇒ Object
- #project_tag(project) ⇒ Object
- #projects_list(projects) ⇒ Object
- #projects_search_form ⇒ Object
- #sound_cumulative_gb_per_year ⇒ Object
- #sound_gb_per_year ⇒ Object
- #taxonworks_classification(project_cutoff: 1000) ⇒ Object
- #week_in_review_graphs(weeks) ⇒ Object
Instance Method Details
#cumulative_gb_per_year(sums) ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'app/helpers/projects_helper.rb', line 126 def cumulative_gb_per_year(sums) d = gb_per_year(sums) data = {} t = 0 d.each do |k,v| t = t + v data[k] = t end data end |
#cumulative_projects_created_per_year ⇒ Object
Cumulative Projects Created per Year From chatGPT 5.0 default
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'app/helpers/projects_helper.rb', line 153 def cumulative_projects_created_per_year years = Project.reorder(nil).pluck(:created_at).compact.map { |t| t.in_time_zone(Time.zone).year } return [['Year', 'Projects']] if years.empty? per_year = years.tally # TIL! min_year = years.min max_year = Time.zone.today.year cumulative = 0 rows = (min_year..max_year).map do |y| cumulative += (per_year[y] || 0) [y, cumulative] end [['Year', 'Projects']] + rows end |
#document_cumulative_gb_per_year ⇒ Object
139 140 141 |
# File 'app/helpers/projects_helper.rb', line 139 def document_cumulative_gb_per_year cumulative_gb_per_year(Document.group_by_year(:created_at, format: '%Y').sum(:document_file_file_size)) end |
#document_gb_per_year ⇒ Object
99 100 101 |
# File 'app/helpers/projects_helper.rb', line 99 def document_gb_per_year gb_per_year( Document.group_by_year(:created_at, format: '%Y').sum(:document_file_file_size)) end |
#gb_per_year(sums) ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'app/helpers/projects_helper.rb', line 113 def gb_per_year(sums) min = sums.keys.sort.first || 0 max = sums.keys.sort.last || 0 data = {} (min..max).each do |y| data[y] = sums[y].present? ? (sums[y].to_f / 1073741824.0).to_i : 0 end data end |
#image_cumulative_gb_per_year ⇒ Object
143 144 145 |
# File 'app/helpers/projects_helper.rb', line 143 def image_cumulative_gb_per_year cumulative_gb_per_year(Image.group_by_year(:created_at, format: '%Y').sum(:image_file_file_size)) end |
#image_gb_per_year ⇒ Object
103 104 105 |
# File 'app/helpers/projects_helper.rb', line 103 def image_gb_per_year gb_per_year( Image.group_by_year(:created_at, format: '%Y').sum(:image_file_file_size) ) end |
#invalid_object(object) ⇒ Object
Came from application_controller
39 40 41 |
# File 'app/helpers/projects_helper.rb', line 39 def invalid_object(object) !(!object.try(:project_id) || project_matches(object)) end |
#project_classification(project) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'app/helpers/projects_helper.rb', line 74 def project_classification(project) classification = Hash.new(0) CLASSIFIER.keys.each do |k| CLASSIFIER[k].each do |m| classification[k] += m.where(project_id: project.id).count end end # Add annotations to their respective class CLASSIFIER_ANNOTATION.each do |m| field = m.column_names.select{|n| n =~ /_type/}.first CLASSIFIER.keys.each do |k| CLASSIFIER[k].each do |s| classification[k] += m.where(project_id: project.id, field => s.name ).count end end end return { data: classification, total: classification.values.sum } end |
#project_link(project) ⇒ Object
25 26 27 28 29 30 31 |
# File 'app/helpers/projects_helper.rb', line 25 def project_link(project) return nil if project.nil? l = link_to(project.name, select_project_path(project)) project.id == sessions_current_project_id ? content_tag(:mark, l) : l end |
#project_matches(object) ⇒ Object
43 44 45 |
# File 'app/helpers/projects_helper.rb', line 43 def project_matches(object) object.try(:project_id) == sessions_current_project_id end |
#project_tag(project) ⇒ Object
16 17 18 19 |
# File 'app/helpers/projects_helper.rb', line 16 def project_tag(project) return nil if project.nil? project.name end |
#projects_list(projects) ⇒ Object
33 34 35 |
# File 'app/helpers/projects_helper.rb', line 33 def projects_list(projects) projects.collect { |p| content_tag(:li, project_link(p)) }.join.html_safe end |
#projects_search_form ⇒ Object
21 22 23 |
# File 'app/helpers/projects_helper.rb', line 21 def projects_search_form render('/projects/quick_search_form') end |
#sound_cumulative_gb_per_year ⇒ Object
147 148 149 |
# File 'app/helpers/projects_helper.rb', line 147 def sound_cumulative_gb_per_year cumulative_gb_per_year(Sound.group_by_year('sounds.created_at', format: '%Y').joins(sound_file_attachment: :blob).sum('active_storage_blobs.byte_size')) end |
#sound_gb_per_year ⇒ Object
107 108 109 110 111 |
# File 'app/helpers/projects_helper.rb', line 107 def sound_gb_per_year gb_per_year( Sound.joins(sound_file_attachment: :blob).group_by_year('sounds.created_at', format: '%Y').sum('active_storage_blobs.byte_size') ) end |
#taxonworks_classification(project_cutoff: 1000) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'app/helpers/projects_helper.rb', line 47 def taxonworks_classification(project_cutoff: 1000) result = {} data = Hash.new(0) CLASSIFIER.keys.each do |k| CLASSIFIER[k].each do |m| data[k] += m.count end end result[:taxonworks] = { data:, total: data.values.sum } result[:projects] = {} Project.all.each do |p| d = project_classification(p) next if d[:total] < project_cutoff result[:projects].merge!({ p.name => d }) end result end |
#week_in_review_graphs(weeks) ⇒ Object
170 171 172 |
# File 'app/helpers/projects_helper.rb', line 170 def week_in_review_graphs(weeks) content_tag(:div, '', 'data-weeks-ago': weeks, 'data-weeks-review': true) end |