Skip to content

Commit

Permalink
Merge branch 'feature/issue#2' into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
mooreniemi committed Jun 20, 2016
2 parents 7dadc88 + 3e0cf5c commit 3e60553
Show file tree
Hide file tree
Showing 17 changed files with 135 additions and 17 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ gem 'rake-progressbar'
gem 'awesome_print'
# we use Faker to create junk data sometimes on staging
gem 'faker'
gem 'zip-codes'

gem 'nested_form'
gem 'simple_form'
Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,7 @@ GEM
will_paginate (>= 3.0.3)
xpath (2.0.0)
nokogiri (~> 1.3)
zip-codes (0.2.1)

PLATFORMS
ruby
Expand Down Expand Up @@ -550,6 +551,7 @@ DEPENDENCIES
unicorn
will_paginate (~> 3.0)
will_paginate-bootstrap
zip-codes

RUBY VERSION
ruby 2.2.2p95
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
Transbucket.com (Transbucket_Rails)
===================================

Rails 4.2.6 (in Ruby 2.2.3), using [bower_rails](https://github.com/rharriso/bower-rails) to manage javascript dependencies.
Transbucket.com is a photo-sharing website for transgender patients. We have roughly 70k users, and average 1000 uniques per month. We're not a huge site, but we do have active users that rely on us. And we're the only site without any profit agenda: this site is by and for the community. We welcome [contributions](https://github.com/mooreniemi/Transbucket_Rails/issues).

The TL;DR of technical specs is: Rails 4.2.6 (in Ruby 2.2.3), using [bower_rails](https://github.com/rharriso/bower-rails) to manage Javascript dependencies, on Postgres database for storage, and with Sphinx indexing for search.

<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
Expand Down
4 changes: 4 additions & 0 deletions app/controllers/surgeons_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
class SurgeonsController < ApplicationController
def show
@surgeon = Surgeon.friendly.find(params[:id])
end

def new
@surgeon = Surgeon.new

Expand Down
1 change: 1 addition & 0 deletions app/forms/surgeon_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ class SurgeonForm < Reform::Form
property :url
property :procedure_list
property :notes
property :slug, writable: false
end
1 change: 0 additions & 1 deletion app/models/constants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,4 @@ module Constants
SURGEONS = Pin.uniq.pluck(:surgeon_id)

SCOPES = ["ftm", "mtf", "bottom", "top", "need_category"]

end
8 changes: 4 additions & 4 deletions app/models/pin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ class Pin < ActiveRecord::Base
validates :pin_images, presence: true

def self.mtf
where(['procedure_id in (?)', Constants::MTF_IDS.map(&:to_s)])
where(['procedure_id in (?)', Constants::MTF_IDS])
end

def self.ftm
where(['procedure_id in (?)', Constants::FTM_IDS.map(&:to_s)])
where(['procedure_id in (?)', Constants::FTM_IDS])
end

def self.top
where(['procedure_id in (?)', Constants::TOP_IDS.map(&:to_s)])
where(['procedure_id in (?)', Constants::TOP_IDS])
end

def self.bottom
where(['procedure_id in (?)', Constants::BOTTOM_IDS.map(&:to_s)])
where(['procedure_id in (?)', Constants::BOTTOM_IDS])
end

def self.need_category
Expand Down
10 changes: 10 additions & 0 deletions app/models/surgeon.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
class Surgeon < ActiveRecord::Base
include SanitizeNames
extend FriendlyId
friendly_id :full_name, use: :slugged
has_many :pins
has_many :skills
has_many :procedures, through: :skills
Expand All @@ -13,6 +15,14 @@ class Surgeon < ActiveRecord::Base
validates :last_name, uniqueness: { scope: :first_name }
validates :last_name, presence: true

def full_name
"#{last_name}-#{first_name}"
end

def satisfaction_by_procedure
Pin.where(surgeon_id: self.id).group([:procedure_id]).average(:satisfaction)
end

def to_s
first_name.nil? ? last_name : last_name.capitalize + ', ' + first_name.capitalize
end
Expand Down
12 changes: 11 additions & 1 deletion app/queries/pin_filter_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,17 @@ def initialize(keywords)
end

def filtered
if surgeons.present?
if surgeons.present? && procedures.present?
if general.present?
Rails.cache.fetch("very_specific:" + general.join('.') + [surgeons + procedures].join(',')) do
Pin.instance_eval { eval args }.by_surgeon([surgeons]).by_procedure([procedures])
end
else
Rails.cache.fetch("surgeons_by_procedures:" + [surgeons + procedures].join(',')) do
Pin.by_surgeon([surgeons]).by_procedure([procedures])
end
end
elsif surgeons.present?
Rails.cache.fetch("surgeons:" + [surgeons].join(',')) do
Pin.by_surgeon([surgeons])
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/pins/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<%= fa_icon "user-md" %> Surgeon
</dt>
<dd>
<%= link_to @pin.unknown_surgeon? ? 'unknown' : 'Dr. ' + @pin.surgeon.to_s, pins_path({surgeon: [@pin.surgeon.id]}) %>
<%= link_to @pin.unknown_surgeon? ? 'unknown' : 'Dr. ' + @pin.surgeon.to_s, surgeon_path(@pin.surgeon) %>
</dd>
<dt>
<%= fa_icon "plus-square" %> Procedure
Expand Down
11 changes: 6 additions & 5 deletions app/views/procedures/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<div class="panel panel-default">
<div class="panel-heading">
<%= @procedure.name %>
<%= link_to Pin.where(procedure_id: @procedure.id).count, pins_path(procedure: @procedure.id), { style: 'border-radius: 100%; background: #ffffcc; display:inline-block; padding:5px;' } %>
</div>
<div class="panel-body">
<%= @procedure.description %>
Expand All @@ -9,11 +10,11 @@
<ul class="list-group">
<li class="list-group-item">
Average sensation: <%= @procedure.avg_sensation %>
</li>
<li class="list-group-item">
Average satisfaction: <%= @procedure.avg_satisfaction %>
</li>
</li>
<li class="list-group-item">
Average satisfaction: <%= @procedure.avg_satisfaction %>
</li>
</ul>
</div>

<%= link_to "Back to procedures list", procedures_path %>
<%= link_to fa_icon("arrow-left") + " Back to Procedures list", procedures_path %>
40 changes: 40 additions & 0 deletions app/views/surgeons/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<% cache(@surgeon) do %>
<div class="media">
<div class="media-left">
<%= fa_icon "user-md", class: "fa-5x media-object" %>
</div>
<div class="media-body">
<h4 class="media-heading">
<%= link_to @surgeon.to_s, @surgeon.url %>
<br><%= (fa_icon('star') * Pin.where(surgeon_id: @surgeon.id).average(:satisfaction)).html_safe %>
</h4>
<address>
<%= @surgeon.address %><br>
<%= @surgeon.city %>, <%= @surgeon.state %> <%= @surgeon.zip %><br>
<%= @surgeon.country %><br>
</address>
<% if @surgeon.notes %>
<div class="panel panel-default">
<div class="panel-body">
Notes: <%= @surgeon.notes %></div>
</div>
<% end %>
<% @surgeon.satisfaction_by_procedure.each do |procedure_id, satisfaction| %>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><%= Procedure.find(procedure_id).name.to_s %>
<%= link_to Pin.where(surgeon_id: @surgeon.id).where(procedure_id: procedure_id).count, pins_path(procedure: procedure_id, surgeon: @surgeon.id), { style: 'border-radius: 100%; background: #ffffcc; display:inline-block; padding:5px;' } %>
</h3>
</div>
<div class="panel-body">
Average patient satisfaction is <%= satisfaction.to_i.to_s %>
<label class="label-with-popover" data-placement="right" data-content="Overall procedure satisfaction across all surgeons is: <%= Procedure.find(procedure_id).avg_satisfaction %>" data-title="Satisfaction Compared" data-trigger="hover" data-original-title="" title="">
<%= fa_icon("bar-chart") %>
</label>
</div>
</div>
<% end %>
</div>
</div>
<% end %>
6 changes: 6 additions & 0 deletions db/migrate/20160618190824_add_slug_to_surgeon.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddSlugToSurgeon < ActiveRecord::Migration
def change
add_column :surgeons, :slug, :string
add_index :surgeons, :slug, unique: true
end
end
9 changes: 9 additions & 0 deletions db/migrate/20160619174827_make_surgeon_zip_string.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class MakeSurgeonZipString < ActiveRecord::Migration
def up
change_column :surgeons, :zip, :string
end

def down
change_column :surgeons, :zip, 'integer USING CAST(zip AS integer)'
end
end
4 changes: 2 additions & 2 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20160619040925) do
ActiveRecord::Schema.define(version: 20160619174827) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -170,7 +170,7 @@
t.string "address"
t.string "city"
t.string "state"
t.integer "zip"
t.string "zip"
t.string "country"
t.string "phone", limit: 20
t.string "email"
Expand Down
26 changes: 26 additions & 0 deletions lib/tasks/populate_addresses.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
namespace :addresses do
desc "wherever we have a zipcode but lack other address info, fill it in"
task :populate => :environment do
require 'zip-codes'
require 'rake-progressbar'


surgeons_w_zips = Surgeon.where.not(zip: nil)
bar = RakeProgressbar.new(surgeons_w_zips.count)

surgeons_w_zips.find_each do |surgeon|
# zipcodes were stored as integers at one point
# which cut off leading zeroes we need
zipcode = surgeon.zip.rjust(5, '0')
address = ZipCodes.identify(zipcode)

next if address.nil?
bar.inc
surgeon.update_attributes!(
state: address[:state_code],
city: address[:city],
zip: zipcode
)
end
end
end
11 changes: 9 additions & 2 deletions spec/models/surgeon_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,19 @@

it 'last names can be dupe if first distinct' do
first_surgeon = create(:surgeon)
dupe_surgeon_attrs = first_surgeon.attributes.except("id", "first_name")
new_surgeon = Surgeon.create(dupe_surgeon_attrs)
new_surgeon = create(:surgeon, last_name: first_surgeon.last_name, first_name: "cthulu")
expect(new_surgeon.first_name).to_not eq(first_surgeon.first_name)
expect(new_surgeon.last_name).to eq(first_surgeon.last_name)
end

describe "#satisfaction_by_procedure" do
it 'gives procedure id and average satisfaction' do
pin = create(:pin, :with_surgeon_and_procedure)
expect(pin.surgeon.satisfaction_by_procedure).
to eq({ pin.procedure.id => pin.satisfaction})
end
end

describe "#to_s" do
it 'displays the surgeon name like Last, First' do
surgeon = build(:surgeon, first_name: "larry", last_name: "schmoe")
Expand Down

0 comments on commit 3e60553

Please sign in to comment.