Skip to content

Commit

Permalink
fill in some metric views
Browse files Browse the repository at this point in the history
  • Loading branch information
drusepth committed Jan 19, 2019
1 parent af09ace commit f3d175a
Show file tree
Hide file tree
Showing 15 changed files with 53 additions and 21 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ gem 'material_icons'

# Design
gem 'materialize-sass', '~> 1.0.0'
gem 'd3-rails'
gem 'd3-cloud-rails'

# NLP
gem 'birch', github: 'billthompson/birch', branch: 'birch-ruby22'
Expand Down
9 changes: 8 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ GEM
thor (~> 0.19.4)
tins (~> 1.6)
crass (1.0.4)
d3-cloud-rails (0.0.2)
d3-rails (~> 4.10)
rails (~> 5.0)
d3-rails (4.13.0)
railties (>= 3.1)
database_cleaner (1.7.0)
debugger-linecache (1.2.0)
devise (4.5.0)
Expand Down Expand Up @@ -132,7 +137,7 @@ GEM
thor (>= 0.14, < 2.0)
json (2.1.0)
jwt (2.1.0)
libv8 (6.7.288.46.1-x86_64-linux)
libv8 (6.7.288.46.1)
loggability (0.14.0)
loofah (2.2.3)
crass (~> 1.0.2)
Expand Down Expand Up @@ -307,6 +312,8 @@ DEPENDENCIES
byebug (= 3.4.0)
coffee-rails
coveralls
d3-cloud-rails
d3-rails
database_cleaner
devise
docx-html
Expand Down
3 changes: 0 additions & 3 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,5 @@
// about supported directives.
//
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require medium-editor
//= require materialize
//= require_tree .
10 changes: 5 additions & 5 deletions app/assets/stylesheets/theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@ body {
font-size: 12pt;
}

thead {
background: #F9CE55;
font-weight: bold;
}

pre {
white-space: pre-wrap;
}
Expand Down Expand Up @@ -68,3 +63,8 @@ pre {
height: 100%;
resize: vertical;
}

.word-badge {
margin: 0;
padding: 2px 5px;
}
2 changes: 1 addition & 1 deletion app/jobs/metrics_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def compute(corpus, metric_group, computations_to_do)

puts "Done in #{(finish - start).round(5)} seconds. Saving result."
metric = metric_group.metrics.find_or_create_by(name: method)
metric.update!(value: result, format_style: format_style)
metric.update!(value: result.to_json, format_style: format_style)
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/jobs/word_frequency_metrics_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def perform(book_id, *args)
[WordFrequencyService, :word_count, :integer],
[WordFrequencyService, :words_per_paragraph],
[WordFrequencyService, :words_per_sentence],
[WordFrequencyService, :one_syllable_words],
[WordFrequencyService, :one_syllable_words, :integer],
])
end
end
3 changes: 2 additions & 1 deletion app/models/concerns/has_parts_of_speech.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def numbers
@numbers ||= text.strip
.split(' ')
.select { |w| is_numeric?(w) }
.uniq
end

def prepositions
Expand All @@ -34,7 +35,7 @@ def pronouns
end

def stop_words
words.select { |word| I18n.t('stop-words').include? word }
words.select { |word| I18n.t('stop-words').include? word }.uniq
end

def verbs
Expand Down
6 changes: 3 additions & 3 deletions app/views/books/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@
<%= @book.last_indexed %>
</p>

<ul class="collapsible">
<ul class="collapsible popout">
<% @book.metric_groupings.order(:name).each do |metric_grouping| %>
<li>
<div class="collapsible-header amber">
<div class="collapsible-header amber darken-1">
<i class="material-icons">subdirectory_arrow_right</i>
<%= metric_grouping.name %>
(<%= metric_grouping.metrics.count %>)
</div>
<div class="collapsible-body">
<div class="collapsible-body white">
<% metric_grouping.metrics.order(:name).each do |metric| %>
<div class="row">
<div class="col s12 m4">
Expand Down
2 changes: 1 addition & 1 deletion app/views/metrics/_age_estimate.html.erb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
age estimate
<%= pluralize metric.value.to_f.round, 'year' %> old
21 changes: 20 additions & 1 deletion app/views/metrics/_frequency_table.html.erb
Original file line number Diff line number Diff line change
@@ -1 +1,20 @@
frequency table
<% json = JSON.parse(metric.value) %>

<div class="row">
<div class="col s12">
<ul class="tabs tabs-fixed-width">
<li class="tab col s3"><a href="#ft-wordcloud-<%= metric.id %>" class="active">Wordcloud</a></li>
<li class="tab col s3"><a href="#ft-table-<%= metric.id %>">Table</a></li>
</ul>
</div>
<div id="ft-wordcloud-<%= metric.id %>" class="col s12">
word cloud here
</div>
<div id="ft-table-<%= metric.id %>" class="col s12" style="max-height: 240px; overflow-y: auto;">
<% json.each do |word, frequency| %>
<div>
<span class="blue word-badge"><%= word %></span> <span class="grey-text">x<%= frequency %></span>
</div>
<% end %>
</div>
</div>
2 changes: 1 addition & 1 deletion app/views/metrics/_grade_level_scale.html.erb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
grace level scale
grade level scale
2 changes: 1 addition & 1 deletion app/views/metrics/_integer.html.erb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
integer
<%= number_with_delimiter(metric.value.to_f.round, :delimiter => ',') %>
1 change: 1 addition & 0 deletions app/views/metrics/_readability_scale.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
readability scale
7 changes: 6 additions & 1 deletion app/views/metrics/_word_list.html.erb
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
word list
<% word_list_json = JSON.parse(metric.value) %>
<div style="max-height: 240px; overflow-y: auto;">
<% word_list_json.each do |word| %>
<span class="blue white-text word-badge"><%= word %></span>
<% end %>
</div>
2 changes: 1 addition & 1 deletion app/views/metrics/_word_singular.html.erb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
singular word
<span class="blue badge left white-text"><%= metric.value %></span>

0 comments on commit f3d175a

Please sign in to comment.