Permalink
Browse files

Remove/unremove mentions crowd sourcing.

  • Loading branch information...
1 parent 40dc143 commit 6590c3c822d94896a65c397fa54208fa38098a07 @paulmwatson committed Apr 29, 2009
@@ -1,5 +1,31 @@
class MentionsController < ApplicationController
layout 'base'
+
+ def removed_list
+ @mentions = RemovedMention.find(:all, :order => 'created_at desc', :limit => 50)
+ end
+
+ def unremove
+ mention_to_move = RemovedMention.find(params[:mention_id])
+ moved_mention = Mention.new(mention_to_move.attributes)
+ moved_mention.created_at = Time.now
+ if moved_mention.save
+ mention_to_move.destroy
+ end
+ redirect_to request.referrer
+ end
+
+ # Called from mentions/index button
+ def remove
+ mention_to_move = Mention.find(params[:mention_id])
+ moved_mention = RemovedMention.new(mention_to_move.attributes)
+ moved_mention.created_at = Time.now
+ if moved_mention.save
+ mention_to_move.destroy
+ end
+ redirect_to request.referrer
+ end
+
def index
@city = City.find :first, :conditions => {:name => params[:city]}
@phrase = Phrase.find :first, :conditions => {:title => params[:phrase]}
@@ -11,7 +37,7 @@ def index
@range_start = @range_center - (@range / 2)
@range_end = @range_center + (@range / 2)
- @mentions = Mention.find :all, :select => "DATE(mentioned_at) as mentioned_at_date, mentioned_at, substring_index(mentioner, ' (', 1) as mentioner_stripped, mentioner, link, exact_location", :group => 'mentioned_at_date, mentioner_stripped', :conditions => {:phrase_id => @phrase.id, :city_id => @city.id, :mentioned_at => ("#{@range_start.year}-#{@range_start.month.to_s.rjust(2, '0')}-#{@range_start.day.to_s.rjust(2, '0')} 00:00".."#{@range_end.year}-#{@range_end.month.to_s.rjust(2, '0')}-#{@range_end.day.to_s.rjust(2, '0')} 23:59")}, :order => :mentioned_at
+ @mentions = Mention.find :all, :select => "id, message, DATE(mentioned_at) as mentioned_at_date, mentioned_at, substring_index(mentioner, ' (', 1) as mentioner_stripped, mentioner, link, exact_location", :group => 'mentioned_at_date, mentioner_stripped', :conditions => {:phrase_id => @phrase.id, :city_id => @city.id, :mentioned_at => ("#{@range_start.year}-#{@range_start.month.to_s.rjust(2, '0')}-#{@range_start.day.to_s.rjust(2, '0')} 00:00".."#{@range_end.year}-#{@range_end.month.to_s.rjust(2, '0')}-#{@range_end.day.to_s.rjust(2, '0')} 23:59")}, :order => :mentioned_at
@twenty_four_hour_count = Mention.find :all, :select => "DATE(mentioned_at) as mentioned_at_date, mentioned_at, substring_index(mentioner, ' (', 1) as mentioner_stripped, mentioner, link, exact_location", :group => 'mentioner_stripped, mentioned_at_date', :conditions => {:phrase_id => @phrase.id, :city_id => @city.id, :mentioned_at => ("#{@range_center.year}-#{@range_center.month.to_s.rjust(2, '0')}-#{@range_center.day.to_s.rjust(2, '0')} 00:00".."#{@range_center.year}-#{@range_center.month.to_s.rjust(2, '0')}-#{@range_center.day.to_s.rjust(2, '0')} 23:59")}
begin
@graph_max = Mention.find(:first, :conditions => {:phrase_id => @phrase.id, :city_id => @city.id}, :group => 'mentioned_at_date, mentioner_stripped', :select => "substring_index(mentioner, ' (', 1) as mentioner_stripped, DATE(mentioned_at) as mentioned_at_date, count(id) as graph_max", :order => 'graph_max DESC').graph_max
@@ -0,0 +1,2 @@
+class RemovedMention < ActiveRecord::Base
+end
@@ -1,6 +1,6 @@
<html>
<head>
- <% if controller.controller_name == 'mentions' %>
+ <% if (controller.controller_name == 'mentions' && @phrase) %>
<title><%= @phrase.title %> in <%= @city.name %> on <%= @range_center.strftime('%B %d') %> - SickCity</title>
<% elsif controller.controller_name == 'phrases' %>
<title>Realtime disease detection for <%= @city.name %> - SickCity</title>
@@ -16,6 +16,7 @@
</head>
<body>
<div class="wrapper">
+ <%- if flash[:notice] %><p style="color: green"><%= flash[:notice] %></p><%- end %>
<%= yield %>
<style>
body
@@ -20,7 +20,7 @@
<a class="forward button home" href="/"><img src="/images/bk2l.png" /><img class="buttonimage" src="/images/logosmall.png" /></a>
<h1><%= @city.name %></h1>
</div>
-
+<p class="intro">Do these not belong in SickCity? Please help us improve our data by removing it for us.</p>
<ul id="tweets">
<% thirty_day_trend = Array.new((@range + 1),0) %>
<% hour_trend = Array.new(24,0) %>
@@ -33,8 +33,9 @@
%>
<% if published_date.to_date == @range_center %>
<li class="<%= cycle('odd','even')%>">
- <% username = mention.mentioner %>
- <span class="time"><%= published_date.strftime('%H:%M') %></span> <span class="location"><%= mention.exact_location.split(',')[0][0..10] %>...</span> <span class="user"><a href="<%= mention.link %>"><%= username %></a></span>
+ <input type="button" value="Remove" onclick="document.location = '/mention/remove/<%= mention.id %>';" />
+ <span class="time"><a target="_blank" href="<%= mention.link %>"><%= published_date.strftime('%H:%M') %></a></span>
+ <%= truncate(h(mention.message), :length => 70) %>
<% hour_trend[published_date.hour] = hour_trend[published_date.hour] + 1 %>
</li>
<% end %>
@@ -0,0 +1,10 @@
+<ul id="tweets">
+ <%- @mentions.each do |mention| -%>
+ <li class="<%= cycle('odd','even')%>">
+ <input type="button" value="Un-Remove" onclick="document.location = '/mention/unremove/<%= mention.id %>';" />
+ <span class="time"><a target="_blank" href="<%= mention.link %>"><%= mention.mentioned_at.strftime('%H:%M') %></a></span>
+ <%= truncate(h(mention.message), :length => 70) %>
+ </li>
+ <%- end -%>
+</ul>
+<p class="twitterpower"><a href="http://twitter.com"><img src="/images/powered-by-twitter-sig.gif" /></a><p>
View
@@ -1,4 +1,7 @@
ActionController::Routing::Routes.draw do |map|
+ map.connect '/removed_list/', :controller => 'mentions', :action => 'removed_list'
+ map.connect '/mention/remove/:mention_id', :controller => 'mentions', :action => 'remove'
+ map.connect '/mention/unremove/:mention_id', :controller => 'mentions', :action => 'unremove'
map.connect '/cities/check/', :controller => 'cities', :action => 'check'
map.connect '/cities/create/', :controller => 'cities', :action => 'create'
map.connect '/cities/add/', :controller => 'cities', :action => 'new'
@@ -0,0 +1,21 @@
+class CreateRemovedMentions < ActiveRecord::Migration
+ def self.up
+ create_table :removed_mentions do |t|
+ t.column 'mentioned_at', :timestamp
+ t.column 'link', :string
+ t.column 'exact_location', :string
+ t.column 'phrase_id', :integer
+ t.column 'city_id', :integer
+ t.column 'mentioner', :string
+ t.timestamps
+ end
+
+ add_column :removed_mentions, :message, :string
+ add_column :removed_mentions, :source_id, :integer
+ add_index :removed_mentions, :source_id, {:unique => true}
+ end
+
+ def self.down
+ drop_table :removed_mentions
+ end
+end
@@ -1,13 +0,0 @@
-class CreateCities < ActiveRecord::Migration
- def self.up
- create_table :cities do |t|
- t.column 'name', :string
- t.column 'country', :string
- t.timestamps
- end
- end
-
- def self.down
- drop_table :cities
- end
-end
@@ -1,13 +0,0 @@
-class CreatePhrases < ActiveRecord::Migration
- def self.up
- create_table :phrases do |t|
- t.column 'title', :string
- t.column 'search', :string
- t.timestamps
- end
- end
-
- def self.down
- drop_table :phrases
- end
-end
@@ -1,17 +0,0 @@
-class CreateMentions < ActiveRecord::Migration
- def self.up
- create_table :mentions do |t|
- t.column 'mentioned_at', :timestamp
- t.column 'link', :string
- t.column 'exact_location', :string
- t.column 'phrase_id', :integer
- t.column 'city_id', :integer
- t.column 'mentioner', :string
- t.timestamps
- end
- end
-
- def self.down
- drop_table :mentions
- end
-end
@@ -1,14 +0,0 @@
-class CreateLocations < ActiveRecord::Migration
- def self.up
- create_table :locations do |t|
- t.column 'name', :string
- t.column 'latitude', :string
- t.column 'longitude', :string
- t.timestamps
- end
- end
-
- def self.down
- drop_table :locations
- end
-end
@@ -1,14 +0,0 @@
-class CreateHistories < ActiveRecord::Migration
- def self.up
- create_table :histories do |t|
- t.column 'city_id', :integer
- t.column 'phrase_id', :integer
- t.column 'last_get', :timestamp
- t.timestamps
- end
- end
-
- def self.down
- drop_table :histories
- end
-end
@@ -1,16 +0,0 @@
-class CreatePhotos < ActiveRecord::Migration
- def self.up
- create_table :photos do |t|
- t.integer :city_id
- t.string :photographer
- t.string :url
- t.string :title
-
- t.timestamps
- end
- end
-
- def self.down
- drop_table :photos
- end
-end
@@ -1,10 +0,0 @@
-class MentionsIndexMessage < ActiveRecord::Migration
- def self.up
- add_column :mentions, :message, :string
- add_column :mentions, :source_id, :integer
- add_index :mentions, :source_id, {:unique => true}
- end
-
- def self.down
- end
-end
@@ -1,8 +0,0 @@
-class HideCity < ActiveRecord::Migration
- def self.up
- add_column :cities, :hidden, :boolean, :default => false
- end
-
- def self.down
- end
-end
@@ -1,12 +0,0 @@
-class CreateCounts < ActiveRecord::Migration
- def self.up
- create_table :counts do |t|
-
- t.timestamps
- end
- end
-
- def self.down
- drop_table :counts
- end
-end
@@ -1,12 +0,0 @@
-class CreateAllTweets < ActiveRecord::Migration
- def self.up
- create_table :all_tweets do |t|
-
- t.timestamps
- end
- end
-
- def self.down
- drop_table :all_tweets
- end
-end
@@ -1,12 +0,0 @@
-class CreateStats < ActiveRecord::Migration
- def self.up
- create_table :stats do |t|
-
- t.timestamps
- end
- end
-
- def self.down
- drop_table :stats
- end
-end
@@ -0,0 +1,21 @@
+class CreateRemovedMentions < ActiveRecord::Migration
+ def self.up
+ create_table :removed_mentions do |t|
+ t.column 'mentioned_at', :timestamp
+ t.column 'link', :string
+ t.column 'exact_location', :string
+ t.column 'phrase_id', :integer
+ t.column 'city_id', :integer
+ t.column 'mentioner', :string
+ t.timestamps
+ end
+
+ add_column :removed_mentions, :message, :string
+ add_column :removed_mentions, :source_id, :integer
+ add_index :removed_mentions, :source_id, {:unique => true}
+ end
+
+ def self.down
+ drop_table :removed_mentions
+ end
+end
View
@@ -9,7 +9,27 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20090317103447) do
+ActiveRecord::Schema.define(:version => 20090429170354) do
+
+ create_table "all_tweets", :force => true do |t|
+ t.datetime "mentioned_at"
+ t.string "link"
+ t.string "exact_location"
+ t.integer "city_id"
+ t.string "mentioner"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ t.string "message"
+ t.integer "source_id"
+ end
+
+ add_index "all_tweets", ["source_id"], :name => "index_mentions_on_source_id"
+ add_index "all_tweets", ["source_id"], :name => "source_id_index", :unique => true
+
+ create_table "blacklist", :force => true do |t|
+ t.integer "phrase_id", :null => false
+ t.string "term", :null => false
+ end
create_table "cities", :force => true do |t|
t.string "name"
@@ -19,6 +39,13 @@
t.boolean "hidden", :default => false
end
+ create_table "counts", :id => false, :force => true do |t|
+ t.integer "city_id", :null => false
+ t.date "date", :null => false
+ t.integer "last_found_id", :null => false
+ t.integer "count", :default => 0, :null => false
+ end
+
create_table "histories", :force => true do |t|
t.integer "city_id"
t.integer "phrase_id"
@@ -48,7 +75,8 @@
t.integer "source_id"
end
- add_index "mentions", ["source_id"], :name => "index_mentions_on_source_id", :unique => true
+ add_index "mentions", ["source_id"], :name => "index_mentions_on_source_id"
+ add_index "mentions", ["source_id"], :name => "source_id_index", :unique => true
create_table "photos", :force => true do |t|
t.integer "city_id"
@@ -66,4 +94,25 @@
t.datetime "updated_at"
end
+ create_table "removed_mentions", :force => true do |t|
+ t.datetime "mentioned_at"
+ t.string "link"
+ t.string "exact_location"
+ t.integer "phrase_id"
+ t.integer "city_id"
+ t.string "mentioner"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ t.string "message"
+ t.integer "source_id"
+ end
+
+ add_index "removed_mentions", ["source_id"], :name => "index_removed_mentions_on_source_id", :unique => true
+
+ create_table "stats", :primary_key => "city_id", :force => true do |t|
+ t.float "quotient", :default => 0.0, :null => false
+ end
+
+ add_index "stats", ["city_id"], :name => "city_id", :unique => true
+
end
Oops, something went wrong.

0 comments on commit 6590c3c

Please sign in to comment.