Skip to content
Extraits de code Groupes Projets
Valider b61df3cc rédigé par Sybil's avatar Sybil
Parcourir les fichiers

As far as I remember :

- Pagination
- Database reworking
- Using of rake migration and seed
parent 788e6389
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Affichage de
avec 94 ajouts et 94 suppressions
......@@ -21,13 +21,16 @@ gem 'rack-cors'
#Add Serializer class to choose json fields
gem 'active_model_serializers'
#Because we're using a shitty database designed by a fuckin' drug addict
gem 'composite_primary_keys'
#gem 'composite_primary_keys'
#Framework for background job processing : managing the database transformation between servers
gem 'sidekiq'
#Framework for distributed schedulinh
#Framework for distributed scheduling
gem 'sidetiq'
#new relic
gem 'newrelic_rpm'
# Use jquery as the JavaScript library
#gem 'jquery-rails'
......
......@@ -31,14 +31,17 @@ GEM
tzinfo (~> 1.1)
arel (5.0.1.20140414130214)
builder (3.2.2)
celluloid (0.16.0)
timers (~> 4.0.0)
coderay (1.1.0)
composite_primary_keys (7.0.10)
activerecord (~> 4.1.4)
connection_pool (2.1.0)
daemons (1.1.9)
erubis (2.7.0)
eventmachine (1.0.3)
hike (1.2.3)
hitimes (1.2.2)
i18n (0.6.11)
ice_cube (0.11.1)
jbuilder (2.1.3)
activesupport (>= 3.0.0, < 5)
multi_json (~> 1.2)
......@@ -54,6 +57,7 @@ GEM
minitest (5.4.0)
multi_json (1.10.1)
mysql2 (0.3.16)
newrelic_rpm (3.9.9.275)
polyglot (0.3.5)
pry (0.10.1)
coderay (~> 1.1.0)
......@@ -84,9 +88,22 @@ GEM
rake (10.3.2)
rdoc (4.1.1)
json (~> 1.4)
redis (3.2.0)
redis-namespace (1.5.1)
redis (~> 3.0, >= 3.0.4)
sdoc (0.4.1)
json (~> 1.7, >= 1.7.7)
rdoc (~> 4.0)
sidekiq (3.3.0)
celluloid (>= 0.16.0)
connection_pool (>= 2.0.0)
json
redis (>= 3.0.6)
redis-namespace (>= 1.3.1)
sidetiq (0.6.3)
celluloid (>= 0.14.1)
ice_cube (= 0.11.1)
sidekiq (>= 3.0.0)
slop (3.6.0)
spring (1.1.3)
sprockets (2.11.0)
......@@ -105,6 +122,8 @@ GEM
thor (0.19.1)
thread_safe (0.3.4)
tilt (1.4.1)
timers (4.0.1)
hitimes
treetop (1.4.15)
polyglot
polyglot (>= 0.3.1)
......@@ -116,14 +135,16 @@ PLATFORMS
DEPENDENCIES
active_model_serializers
composite_primary_keys
jbuilder (~> 2.0)
kaminari
mysql2
newrelic_rpm
pry
rack-cors
rails (= 4.1.5)
rails-api
sdoc (~> 0.4.0)
sidekiq
sidetiq
spring
thin
web: bundle exec rails s -p 3002
class ApplicationController < ActionController::API
include ActionController::Serialization
before_filter :get_tags, :get_users, :get_channels
def get_channels
channels = Channel.all
@channels = Array.new
channels.each do |channel|
if @channels.include?(channel.chan) == false
@channels.push(channel.chan)
end
end
end
def get_tags
tags = Tag.all
@tags = Hash.new
tags.each do |tag|
@tags[tag.tag] ||= 0.0
@tags[tag.tag] += 1.0
end
max_weight = @tags.values.max
@tags.each do |tag, occ|
if occ == 1
@tags.delete(tag)
else
@tags[tag] = occ / max_weight
end
end
end
def get_users
users = Channel.all
@users = Hash.new
users.each do |user|
@users[user.sender_irc] ||= 0.0
@users[user.sender_irc] += 1.0
end
max_weight = @users.values.max
@users.each do |user, occ|
@users[user] = occ / max_weight
end
end
end
class ChannelsController < ApplicationController
def index_users
get_users()
render json: @users, status: 200
end
def index
get_channels()
render json: @channels, status: 200
end
def show_user
@tracks = Track.joins(:channel).where(playbot_chan: {sender_irc: params[:user]})
render json: @user, status: 200
end
def show_channel
@tracks = Track.joins(:channel).where(playbot_chan: {chan: "#"+params[:channel]})
render json: @channel, status:200
end
end
......@@ -4,8 +4,4 @@ class TagsController < ApplicationController
render json: @tags, status: 200
end
def show
@tracks = Track.joins(:tags).where(playbot_tags: {tag: params[:tag]})
render json: @tag, status: 200
end
end
......@@ -8,7 +8,10 @@ class TracksController < ApplicationController
end
def index
@tracks = Track.includes(:channel, :tags)
#@tracks = Track.includes(irc_posts: [:channel, :user], tag_assignations: :tag).all #includes(irc_posts: [{ :channels, :users}]) #includes(:channels,:tags,:users)
#t = Track.all.joins('inner join irc_posts i ON tracks.track_id = i.track_id inner join channels c on i.channel_id = c.channel_id inner join gnations ti on tracks.track_id = ti.track_id inner join tags ta on ta.tag_id = ti.tag_id').select('tracks.name as t_name, u.name as u_name, c.name as c_name, ta.name as t_name')
#t.first.c_name
@tracks = Track.page params[:page]
filters :tag, :channel, :user
render json: @tracks, status: 200
end
......
class Channel < ActiveRecord::Base
self.table_name = "playbot_chan"
belongs_to :track
def self.with_channel(channel)
where("chan = ?", channel)
end
has_many :irc_posts
has_many :tracks, through: :irc_posts
def self.with_user(user)
where("irc_sender = ?", user)
def self.with_channel(channel)
where("name = ?", channel)
end
end
class IrcPost < ActiveRecord::Base
belongs_to :track
belongs_to :user
belongs_to :channel
end
class OldDatabase::Playbot < ActiveRecord::Base
self.table_name = "playbot"
self.inheritance_column = "inheritance_type"
end
class OldDatabase::PlaybotChan < ActiveRecord::Base
self.table_name = "playbot_chan"
end
class OldDatabase::PlaybotTag < ActiveRecord::Base
self.table_name = "playbot_tags"
end
class Tag < ActiveRecord::Base
self.table_name = :playbot_tags
self.primary_keys = :id, :tag
belongs_to :track
has_many :tag_assignations
has_many :tracks, through: :tag_assignation
end
class TagAssignation < ActiveRecord::Base
belongs_to :track
belongs_to :tag
end
class Track < ActiveRecord::Base
self.table_name = :playbot
self.inheritance_column = :inheritance_type
paginates_per 50
#default_scope includes(:channels,:users,:tags)
has_many :tags, primary_key: :id, foreign_key: :id
has_one :channel, primary_key: :id, foreign_key: :content
has_many :irc_posts
has_many :tag_assignations
has_many :tags, through: :tag_assignations
has_many :channels, through: :irc_posts
has_many :users, through: :irc_posts
def self.with_tag(tag)
self.joins(:tags).where("tag = ?", tag )
self.joins(:tags).where("tags.name = ?", tag )
#self.includes(:tags)
#self.where("tag = ?", tag)
end
def self.with_channel(channel)
self.joins(:channel).where("chan = ?", "##{channel}")
self.joins(:channels).where("channels.name = ?", "##{channel}")
end
def self.with_user(user)
self.joins(:channel).where("playbot_chan.sender_irc = ?", user)
self.joins(:users).where("users.name = ?", user)
end
end
class User < ActiveRecord::Base
has_many :irc_posts
has_many :tracks, through: :irc_posts
def self.with_user(user)
where("name = ?", user)
end
end
class View::ViewTrack < ActiveRecord::Base
end
class ChannelSerializer < ActiveModel::Serializer
attributes :sender_irc, :chan
attributes :id, :name
#has_many :tracks
#has_many :users
end
class TagSerializer < ActiveModel::Serializer
attributes :tag
attributes :id, :name
#belongs_to :track
end
class TrackSerializer < ActiveModel::Serializer
attributes :id, :title, :url, :type
attributes :id, :name, :url, :provider, :author, :channel
#embed :ids, include: true
embed :ids, include: true
has_one :channel
has_many :channels
has_many :tags
has_many :users
end
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter