mirror of
https://github.com/indentlabs/notebook.git
synced 2025-10-26 11:19:22 +00:00
add community footprint
This commit is contained in:
parent
79415904b8
commit
01d6ba2c5c
@ -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
|
||||
|
||||
@ -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
|
||||
176
app/views/data/green.html.erb
Normal file
176
app/views/data/green.html.erb
Normal file
@ -0,0 +1,176 @@
|
||||
<h4 class="white-text">
|
||||
<%= 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 %>
|
||||
<i class="material-icons blue-text text-lighten-3">arrow_back</i>
|
||||
<% end %>
|
||||
Your paper footprint
|
||||
</h4>
|
||||
|
||||
<%
|
||||
total_pages_equivalent = 0
|
||||
%>
|
||||
|
||||
<div class="row">
|
||||
<div class="col s12">
|
||||
<div class="card-panel">
|
||||
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!
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col s12">
|
||||
<div class="card">
|
||||
<div class="card-content">
|
||||
<div class="card-title">Your personal paper footprint</div>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Digital content</th>
|
||||
<th>Equivalent physical pages</th>
|
||||
<th>Equivalent trees</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
<% @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
|
||||
%>
|
||||
<tr>
|
||||
<td>
|
||||
<i class="material-icons left <%= content_class_from_name(content_type).color %>-text">
|
||||
<%= content_class_from_name(content_type).icon %>
|
||||
</i>
|
||||
<%= pluralize content_list_count, content_type.pluralize %>
|
||||
</td>
|
||||
<td>
|
||||
<i class="material-icons left grey-text">copy_all</i>
|
||||
<%= pluralize physical_page_equivalent, 'page' %>
|
||||
</td>
|
||||
<td>
|
||||
<i class="material-icons left green-text">park</i>
|
||||
<%= pluralize tree_equivalent.round(5), 'tree' %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
<tr>
|
||||
<td>Totals</td>
|
||||
<td>
|
||||
<strong>
|
||||
<i class="material-icons left grey-text">copy_all</i>
|
||||
<%= pluralize total_pages_equivalent, 'page' %>
|
||||
</strong>
|
||||
</td>
|
||||
<td>
|
||||
<strong>
|
||||
<i class="material-icons left green-text">park</i>
|
||||
<%= pluralize total_pages_equivalent.to_f / GreenService::SHEETS_OF_PAPER_PER_TREE.round(5), 'tree' %>
|
||||
saved
|
||||
</strong>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
<%
|
||||
total_pages_equivalent = 0
|
||||
%>
|
||||
|
||||
<div class="row">
|
||||
<div class="col s12">
|
||||
<div class="card">
|
||||
<div class="card-content">
|
||||
<div class="card-title">Our community paper footprint</div>
|
||||
<p>Across all Notebook.ai pages...</p>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Digital content</th>
|
||||
<th>Equivalent physical pages</th>
|
||||
<th>Equivalent trees</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
<% 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
|
||||
%>
|
||||
<tr>
|
||||
<td>
|
||||
<i class="material-icons left <%= content_class_from_name(content_type).color %>-text">
|
||||
<%= content_class_from_name(content_type).icon %>
|
||||
</i>
|
||||
<%= pluralize content_list_count, content_type.pluralize %>
|
||||
</td>
|
||||
<td>
|
||||
<i class="material-icons left grey-text">copy_all</i>
|
||||
<%= pluralize physical_page_equivalent, 'page' %>
|
||||
</td>
|
||||
<td>
|
||||
<i class="material-icons left green-text">park</i>
|
||||
<%= pluralize tree_equivalent.round(5), 'tree' %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
<tr>
|
||||
<td>Totals</td>
|
||||
<td>
|
||||
<strong>
|
||||
<i class="material-icons left grey-text">copy_all</i>
|
||||
<%= pluralize total_pages_equivalent, 'page' %>
|
||||
</strong>
|
||||
</td>
|
||||
<td>
|
||||
<strong>
|
||||
<i class="material-icons left green-text">park</i>
|
||||
<%= pluralize total_pages_equivalent.to_f / GreenService::SHEETS_OF_PAPER_PER_TREE.round(5), 'tree' %>
|
||||
saved
|
||||
</strong>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -111,6 +111,20 @@
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<div class="col s12 m12 l6">
|
||||
<%= link_to green_path, class: 'black-text' do %>
|
||||
<div class="hoverable card green lighten-2">
|
||||
<div class="card-content">
|
||||
<i class="material-icons right blue-text text-lighten-1">public</i>
|
||||
<div class="card-title">Eco footprint</div>
|
||||
<p>
|
||||
How many trees have you saved by switching to digital?
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<div class="col s12 m12 l6">
|
||||
<%= link_to discussions_path, class: 'black-text' do %>
|
||||
<div class="hoverable card blue lighten-4">
|
||||
@ -182,7 +196,7 @@
|
||||
</div>
|
||||
|
||||
<%# this could actually be a cool s12 banner if we flesh out the help center with guides and stuff %>
|
||||
<div class="col s12 m12 l12">
|
||||
<div class="col s12 m12 l6">
|
||||
<%= link_to help_center_path, class: 'black-text' do %>
|
||||
<div class="hoverable card pink lighten-4">
|
||||
<div class="card-content">
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user