From dd5f0f20f0ba44f2fbbd83e145cbef82492a749f Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Tue, 20 Jul 2021 17:20:49 -0700 Subject: [PATCH] add public site-wide green report --- app/controllers/main_controller.rb | 25 ++++++ app/services/green_service.rb | 13 ++- app/views/data/green.html.erb | 2 +- app/views/main/paper.html.erb | 126 +++++++++++++++++++++++++++++ config/routes.rb | 1 + 5 files changed, 165 insertions(+), 2 deletions(-) create mode 100644 app/views/main/paper.html.erb diff --git a/app/controllers/main_controller.rb b/app/controllers/main_controller.rb index bbee013a..00de0c7c 100644 --- a/app/controllers/main_controller.rb +++ b/app/controllers/main_controller.rb @@ -35,6 +35,31 @@ class MainController < ApplicationController def sascon end + def paper + @navbar_color = '#4CAF50' + + @total_notebook_pages = 0 + @total_pages_equivalent = 0 + @total_trees_saved = 0 + + @per_page_savings = {} + + (Rails.application.config.content_types[:all] + [Timeline, Document]).each do |content_type| + physical_page_equivalent = GreenService.total_physical_pages_equivalent(content_type) + tree_equivalent = physical_page_equivalent.to_f / GreenService::SHEETS_OF_PAPER_PER_TREE + + @per_page_savings[content_type.name] = { + digital: content_type.last.try(:id) || 0, + pages: physical_page_equivalent, + trees: tree_equivalent + } + + @total_notebook_pages += @per_page_savings.dig(content_type.name, :digital) + @total_pages_equivalent += @per_page_savings.dig(content_type.name, :pages) + @total_trees_saved += @per_page_savings.dig(content_type.name, :trees) + end + end + def prompts @sidenav_expansion = 'writing' @navbar_color = '#FF9800' diff --git a/app/services/green_service.rb b/app/services/green_service.rb index d68b3301..d1be14d9 100644 --- a/app/services/green_service.rb +++ b/app/services/green_service.rb @@ -45,10 +45,21 @@ class GreenService < Service end def self.total_document_pages_equivalent - (Document.with_deleted.sum(:cached_word_count) / AVERAGE_WORDS_PER_PAGE.to_f).round + (Document.with_deleted.where.not(body: ["", nil]).sum(:cached_word_count) / AVERAGE_WORDS_PER_PAGE.to_f).round end def self.total_timeline_pages_equivalent (TimelineEvent.last.id / AVERAGE_TIMELINE_EVENTS_PER_PAGE.to_f).to_i end + + def self.total_physical_pages_equivalent(content_type) + case content_type.name + when 'Timeline' + GreenService.total_timeline_pages_equivalent + when 'Document' + GreenService.total_document_pages_equivalent + else + GreenService.physical_pages_equivalent_for(content_type.name) * (content_type.last.try(:id) || 0) + end + end end \ No newline at end of file diff --git a/app/views/data/green.html.erb b/app/views/data/green.html.erb index 7fb0e7c7..3e369cbb 100644 --- a/app/views/data/green.html.erb +++ b/app/views/data/green.html.erb @@ -122,7 +122,7 @@ - <% Rails.application.config.content_type_names[:all].each do |content_type| %> + <% (Rails.application.config.content_type_names[:all] + ["Timeline", "Document"]).each do |content_type| %> <% content_list_count = content_class_from_name(content_type).last.try(:id) || 0 diff --git a/app/views/main/paper.html.erb b/app/views/main/paper.html.erb new file mode 100644 index 00000000..ce9f8623 --- /dev/null +++ b/app/views/main/paper.html.erb @@ -0,0 +1,126 @@ +
+
+
+
+ <%= + image_tag 'tristan/small.png', class: 'right hide-on-small-only', style: 'margin-left: 2em' + %> + +
Going digital saves paper and trees!
+
+

+ It's well-known that Notebook.ai offers a wide variety of features that just aren't + possible with traditional paper notebooks. However, those aren't the only benefits of + going digital! +

+
+

+ Whether you're worldbuilding with our specialized notebook pages, outlining story + timelines, or writing your next novel, every page you create in Notebook.ai directly + contributes to less paper being used — and fewer trees cut down! +

+
+
+
+
+ +
+
+

<%= number_with_delimiter @total_notebook_pages %>

+ digital ideas stored +
+
+
+
+

<%= number_with_delimiter @total_pages_equivalent %>

+ equivalent physical pages +
+
+
+
+ park +

<%= number_with_delimiter @total_trees_saved.round %>

+ trees saved +
+
+ +
+
+

+ park + Note: The average 40-foot pine tree typically yields between 10,000 and 20,000 notebook-quality sheets of paper. + For the estimations on this page, we're using a conservative estimate of + <%= number_with_delimiter GreenService::SHEETS_OF_PAPER_PER_TREE %> pages per tree. +

+
+
+
+ +
+
+
+
+
Our community paper footprint
+ + + + + + + + + + + + <% (Rails.application.config.content_type_names[:all] + ["Timeline", "Document"]).each do |content_type| %> + <% + content_list_count = @per_page_savings.dig(content_type, :digital) + physical_page_equivalent = @per_page_savings.dig(content_type, :pages) + tree_equivalent = @per_page_savings.dig(content_type, :trees) + %> + + + + + + <% end %> + + + + + + +
Digital contentEquivalent physical pagesEquivalent trees
+ + <%= content_class_from_name(content_type).icon %> + + <%= number_with_delimiter content_list_count %> + <%= content_type.pluralize content_list_count %> + + copy_all + <%= number_with_delimiter physical_page_equivalent %> + <%= 'page'.pluralize physical_page_equivalent %> + + park + <%= number_with_delimiter tree_equivalent.round(5) %> + <%= 'tree'.pluralize tree_equivalent %> +
Totals + + copy_all + <%= number_with_delimiter @total_pages_equivalent %> + <%= 'page'.pluralize @total_pages_equivalent %> + + + + park + <%= number_with_delimiter @total_trees_saved.round(5) %> + <%= 'tree'.pluralize @total_trees_saved %> + saved + +
+
+
+
+
+ +notebook paper link \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index ee88c9ab..81bb58fd 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -168,6 +168,7 @@ Rails.application.routes.draw do # Info pages scope '/about' do + get '/paper', to: 'main#paper', as: :green_paper get '/privacy', to: 'main#privacyinfo', as: :privacy_policy end