From 01d6ba2c5c5761143dd2fa4c2f3da128865ebd1f Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Mon, 19 Jul 2021 22:02:07 -0700 Subject: [PATCH] add community footprint --- app/controllers/data_controller.rb | 3 + app/services/green_service.rb | 67 +++++------ app/views/data/green.html.erb | 176 +++++++++++++++++++++++++++++ app/views/data/index.html.erb | 16 ++- config/routes.rb | 1 + 5 files changed, 229 insertions(+), 34 deletions(-) create mode 100644 app/views/data/green.html.erb diff --git a/app/controllers/data_controller.rb b/app/controllers/data_controller.rb index ac5737f4..f42eef7e 100644 --- a/app/controllers/data_controller.rb +++ b/app/controllers/data_controller.rb @@ -140,6 +140,9 @@ class DataController < ApplicationController @share_link = "https://www.notebook.ai/?referral=#{current_user.referral_code.code}" end + def green + end + private def set_sidenav_expansion diff --git a/app/services/green_service.rb b/app/services/green_service.rb index e6e39fea..73440ba9 100644 --- a/app/services/green_service.rb +++ b/app/services/green_service.rb @@ -1,53 +1,54 @@ class GreenService < Service AVERAGE_WORDS_PER_PAGE = 500 AVERAGE_TIMELINE_EVENTS_PER_PAGE = 3 + SHEETS_OF_PAPER_PER_TREE = 15_000 - def physical_pages_equivalent_for(worldbuilding_page_type) + def self.physical_pages_equivalent_for(worldbuilding_page_type) # TODO: This would be better estimated with [average] word counts from pages (or a real total), # but we don't have that data computed (and definitely don't want to do so on each page load). # Until we have a better solution, these page counts come from printing out notebook pages - # from http://www.notebook-paper.com/ + # from http://www.notebook-paper.com/ case worldbuilding_page_type - when "Universe" then 2 * Universe.last.id - when "Character" then 8 * Character.last.id - when "Location" then 4 * Location.last.id - when "Item" then 2 * Item.last.id - when "Building" then 8 * Building.last.id - when "Condition" then 4 * Condition.last.id - when "Continent" then 6 * Continent.last.id - when "Country" then 5 * Country.last.id - when "Creature" then 8 * Creature.last.id - when "Deity" then 5 * Deity.last.id - when "Flora" then 4 * Flora.last.id - when "Food" then 5 * Food.last.id - when "Government" then 6 * Government.last.id - when "Group" then 4 * Group.last.id - when "Job" then 4 * Job.last.id - when "Landmark" then 3 * Landmark.last.id - when "Language" then 5 * Language.last.id - when "Lore" then 10 * Lore.last.id - when "Magic" then 4 * Magic.last.id - when "Planet" then 6 * Planet.last.id - when "Race" then 4 * Race.last.id - when "Religion" then 3 * Religion.last.id - when "Scene" then 2 * Scene.last.id - when "School" then 6 * School.last.id - when "Sport" then 4 * Sport.last.id - when "Technology" then 4 * Technology.last.id - when "Town" then 4 * Town.last.id - when "Tradition" then 3 * Tradition.last.id - when "Vehicle" then 4 * Vehicle.last.id + when "Universe" then 2 + when "Character" then 8 + when "Location" then 4 + when "Item" then 2 + when "Building" then 8 + when "Condition" then 4 + when "Continent" then 6 + when "Country" then 5 + when "Creature" then 8 + when "Deity" then 5 + when "Flora" then 4 + when "Food" then 5 + when "Government" then 6 + when "Group" then 4 + when "Job" then 4 + when "Landmark" then 3 + when "Language" then 5 + when "Lore" then 10 + when "Magic" then 4 + when "Planet" then 6 + when "Race" then 4 + when "Religion" then 3 + when "Scene" then 2 + when "School" then 6 + when "Sport" then 4 + when "Technology" then 4 + when "Town" then 4 + when "Tradition" then 3 + when "Vehicle" then 4 else raise "Unknown green estimate: #{worldbuilding_page_type}" end end - def total_document_pages_equivalent + def self.total_document_pages_equivalent (Document.with_deleted.sum(:cached_word_count) / AVERAGE_WORDS_PER_PAGE.to_f).to_i end - def total_timeline_pages_equivalent + def self.total_timeline_pages_equivalent (TimelineEvent.last.id / AVERAGE_TIMELINE_EVENTS_PER_PAGE.to_f).to_i end end \ No newline at end of file diff --git a/app/views/data/green.html.erb b/app/views/data/green.html.erb new file mode 100644 index 00000000..4169a552 --- /dev/null +++ b/app/views/data/green.html.erb @@ -0,0 +1,176 @@ +

+ <%= link_to data_vault_path, class: 'grey-text tooltipped', style: 'position: relative; top: 4px;', data: { + position: 'bottom', + enterDelay: '500', + tooltip: "Back to your Data Vault" + } do %> + arrow_back + <% end %> + Your paper footprint +

+ +<% + total_pages_equivalent = 0 +%> + +
+
+
+ All the added functionality of Notebook.ai isn't the only benefit of going digital. Backing your ideas up in the cloud + instead of on paper also saves trees! +
+
+ +
+
+
+
Your personal paper footprint
+ + + + + + + + + + + <% @current_user_content.each do |content_type, content_list| %> + <% + content_list_count = content_list.count + + physical_page_equivalent = case content_type + when 'Timeline' + GreenService::AVERAGE_TIMELINE_EVENTS_PER_PAGE * TimelineEvent.where(timeline_id: content_list.map(&:id)).count + when 'Document' + [ + content_list.inject(0) { |sum, doc| sum + (doc.cached_word_count || 0) } / GreenService::AVERAGE_WORDS_PER_PAGE.to_f, + content_list_count + ].max + else + GreenService.physical_pages_equivalent_for(content_type) * content_list_count + end + + tree_equivalent = physical_page_equivalent.to_f / GreenService::SHEETS_OF_PAPER_PER_TREE + + total_pages_equivalent += physical_page_equivalent + %> + + + + + + <% end %> + + + + + + +
Digital contentEquivalent physical pagesEquivalent trees
+ + <%= content_class_from_name(content_type).icon %> + + <%= pluralize content_list_count, content_type.pluralize %> + + copy_all + <%= pluralize physical_page_equivalent, 'page' %> + + park + <%= pluralize tree_equivalent.round(5), 'tree' %> +
Totals + + copy_all + <%= pluralize total_pages_equivalent, 'page' %> + + + + park + <%= pluralize total_pages_equivalent.to_f / GreenService::SHEETS_OF_PAPER_PER_TREE.round(5), 'tree' %> + saved + +
+
+
+
+
+ + + + +<% + total_pages_equivalent = 0 +%> + +
+
+
+
+
Our community paper footprint
+

Across all Notebook.ai pages...

+ + + + + + + + + + + <% Rails.application.config.content_type_names[:all].each do |content_type| %> + <% + content_list_count = content_class_from_name(content_type).last.try(:id) || 0 + + physical_page_equivalent = case content_type + when 'Timeline' + GreenService.total_timeline_pages_equivalent + when 'Document' + GreenService.total_document_pages_equivalent + else + GreenService.physical_pages_equivalent_for(content_type) * content_list_count + end + + tree_equivalent = physical_page_equivalent.to_f / GreenService::SHEETS_OF_PAPER_PER_TREE + + total_pages_equivalent += physical_page_equivalent + %> + + + + + + <% end %> + + + + + + +
Digital contentEquivalent physical pagesEquivalent trees
+ + <%= content_class_from_name(content_type).icon %> + + <%= pluralize content_list_count, content_type.pluralize %> + + copy_all + <%= pluralize physical_page_equivalent, 'page' %> + + park + <%= pluralize tree_equivalent.round(5), 'tree' %> +
Totals + + copy_all + <%= pluralize total_pages_equivalent, 'page' %> + + + + park + <%= pluralize total_pages_equivalent.to_f / GreenService::SHEETS_OF_PAPER_PER_TREE.round(5), 'tree' %> + saved + +
+
+
+
+
diff --git a/app/views/data/index.html.erb b/app/views/data/index.html.erb index b1a3e4a6..1b891f83 100644 --- a/app/views/data/index.html.erb +++ b/app/views/data/index.html.erb @@ -111,6 +111,20 @@ <% end %> +
+ <%= link_to green_path, class: 'black-text' do %> +
+
+ public +
Eco footprint
+

+ How many trees have you saved by switching to digital? +

+
+
+ <% end %> +
+
<%= link_to discussions_path, class: 'black-text' do %>
@@ -182,7 +196,7 @@
<%# this could actually be a cool s12 banner if we flesh out the help center with guides and stuff %> -
+
<%= link_to help_center_path, class: 'black-text' do %>
diff --git a/config/routes.rb b/config/routes.rb index 6e45512b..ee88c9ab 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -139,6 +139,7 @@ Rails.application.routes.draw do get '/uploads', to: 'data#uploads' get '/discussions', to: 'data#discussions' get '/collaboration', to: 'data#collaboration' + get '/green', to: 'data#green' scope 'yearly' do get '/', to: 'data#yearly_index', as: :year_in_review get '/:year', to: 'data#review_year', as: :review_year