Skip to content

Instantly share code, notes, and snippets.

@khanimdad
Created May 24, 2011 12:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save khanimdad/988598 to your computer and use it in GitHub Desktop.
Save khanimdad/988598 to your computer and use it in GitHub Desktop.
SQL log fine
SQL (60.0ms) SELECT value FROM configurations WHERE name='overall_weight'
SQL (1.0ms) SELECT value FROM configurations WHERE name='friends_weight'
SQL (1.0ms) SELECT value FROM configurations WHERE name='artist_rating_weight'
SQL (0.0ms) SELECT value FROM configurations WHERE name='content_artist_weight'
SQL (0.0ms) SELECT value FROM configurations WHERE name='artist_weight'
SQL (0.0ms) SELECT value FROM configurations WHERE name='genre_weight'
SQL (43.0ms) DROP TABLE IF EXISTS top_movies_users_96
SQL (10342.0ms) CREATE TABLE top_movies_users_96
SELECT c.id AS content_id,
(c.youtoo_rating / 100.0 + c.youtoo_popularity / 100.0)/2.0 AS avg_rating,
0.5 AS count_rating,
c.youtoo_rating AS youtoo_rating,
c.date_of_release AS date_of_release,
c.genre_id AS genre_id
FROM top_movies AS c
WHERE NOT EXISTS (
SELECT * FROM user_ratings AS r
WHERE r.user_id = 96 AND
r.rating_type = 'MovieUserRating' AND
r.rateable_id = c.id
)
SQL (845.0ms) ALTER TABLE top_movies_users_96 add index (content_id)
SQL (304.0ms) INSERT INTO top_movies_users_96
SELECT c.content_id AS content_id,
SUM(r.user_rating) / (count(r.user_rating) + 0.3) AS avg_rating,
0.5 * count(r.user_rating) / (count(r.user_rating) + 2.0) AS count_rating,
c.youtoo_rating AS youtoo_rating,
c.date_of_release AS date_of_release,
c.genre_id AS genre_id
FROM `user_ratings` AS r, `user_distances` AS u, `top_movies_users_96` AS c
WHERE
u.user1_id = 96 AND
r.user_id = u.user2_id AND
r.rating_type = 'MovieUserRating' AND
r.rateable_id = c.content_id AND
r.user_rating > 0
GROUP BY c.content_id
SQL (191.0ms) CREATE TABLE IF NOT EXISTS artists_ids_96
SELECT r.rateable_id AS artist_id,
avg(r.user_rating) AS avg_user_rating,
1.0 AS count_rating
FROM user_ratings AS r
WHERE
r.user_id = 96 AND
r.rateable_type IN ('Artist') AND
r.rating_type IN ('DirectorUserRating', 'ActorUserRating') AND
r.user_rating > 0
GROUP BY
r.rateable_id
SQL (241.0ms) ALTER TABLE artists_ids_96 add index (artist_id)
SQL (6708.0ms) INSERT INTO artists_ids_96
SELECT p.artist_id AS artist_id,
avg(r.user_rating) AS avg_user_rating,
0.75 * count(r.user_rating) / (count(r.user_rating) + 5.0) AS count_rating
FROM user_ratings AS r, performances AS p
WHERE
r.user_id = 96 AND
r.rateable_type = 'Content' AND
r.user_rating > 0 AND
r.rateable_id = p.content_id AND
r.rating_type = 'MovieUserRating'
GROUP BY p.artist_id
SQL (2327.0ms) INSERT INTO top_movies_users_96
SELECT c.content_id AS content_id,
sum(i.avg_user_rating * i.count_rating) / (sum(i.count_rating) + 0.0001) AS avg_rating,
2.0 * sum(i.count_rating) / (sum(i.count_rating) + 1.0) AS count_rating,
c.youtoo_rating AS youtoo_rating,
c.date_of_release AS date_of_release,
c.genre_id AS genre_id
FROM artists_ids_96 AS i, performances AS p,
top_movies_users_96 AS c
WHERE i.artist_id = p.artist_id AND p.content_id = c.content_id
GROUP BY c.content_id
SQL (20.0ms) DROP TABLE IF EXISTS artists_ids_96
SQL (29.0ms) CREATE TABLE IF NOT EXISTS ratings_96 LIKE ratings
SQL (194.0ms) DELETE FROM ratings_96 WHERE rating_type = 'MovieRating'
SQL (0.0ms) DROP VIEW IF EXISTS ftable_96
SQL (92.0ms) CREATE VIEW ftable_96 AS
SELECT g.genre_id AS genre_id,
sum(f.user_rating) / (5.0 + count(f.user_rating))AS genre_avg_user_rating,
5.0 AS genre_user_rating_count
FROM favorite_items AS f, genre_subscriptions As g
WHERE
f.user_id = 96 AND
f.user_rating > 0 AND
f.favorite_item_type = 'FavoriteMovie' AND
g.genre_subscription_type = 'MovieGenreSubscription' AND
g.content_id = f.favorite_id AND
NOT isnull(g.genre_id)
GROUP BY
g.genre_id
SQL (1786.0ms) INSERT IGNORE INTO ratings_96 (
rateable_id,
rateable_type,
rating_type,
rating_type,
user_id,
genre0,
release_date,
youtoo_user_rating)
SELECT
t.content_id,
'Content',
'MovieRating',
'96',
t.genre_id,
t.date_of_release,
250 * ((sum(t.count_rating * t.avg_rating) + avg(IFNULL(f.genre_user_rating_count, 0))
* avg(IFNULL(f.genre_avg_user_rating, 0))))
/ (sum(t.count_rating) + avg(IFNULL(f.genre_user_rating_count,0)) + 0.75) AS youtoo_user_rating
FROM top_movies_users_96 AS t
LEFT JOIN genre_subscriptions AS g ON (t.content_id = g.content_id)
LEFT JOIN ftable_96 AS f ON (g.genre_id = f.genre_id)
WHERE g.genre_subscription_type = 'MovieGenreSubscription'
GROUP BY t.content_id
ORDER BY youtoo_user_rating DESC LIMIT 0, 500
SQL (76.0ms) INSERT IGNORE INTO ratings_96 (rateable_id, rateable_type, rating_type, user_id, genre0, release_date,
youtoo_user_rating)
SELECT rateable_id, rateable_type, rating_type, 96 AS user_id, genre0, release_date, youtoo_user_rating / 2.0
FROM ratings
WHERE rating_type = 'MovieRating'
AND rateable_id NOT IN (
SELECT r.rateable_id FROM user_ratings AS r
WHERE r.user_id = 96 AND
r.rating_type = 'MovieUserRating')
SQL (1.0ms) DROP VIEW ftable_96
SQL (46.0ms) DROP TABLE IF EXISTS top_movies_users_96
SQL (241.0ms) CREATE TABLE IF NOT EXISTS val_96
SELECT max(youtoo_user_rating) AS max, min(youtoo_user_rating) AS min
FROM ratings_96
WHERE rating_type = 'MovieRating' AND isnull(user_rating)
SQL (93.0ms) UPDATE ratings_96
SET youtoo_user_rating = 500.0 * (youtoo_user_rating) / (SELECT max(val_96.max) FROM val_96)
WHERE rating_type = 'MovieRating'
SQL (20.0ms) DROP TABLE IF EXISTS val_96
SQL (1.0ms) SELECT count(*) FROM ratings_96 WHERE rating_type = 'MovieRating' AND youtoo_user_rating > 300
SQL (13.0ms) DELETE FROM ratings_96 WHERE rating_type = 'MovieRating' AND youtoo_user_rating < 300
SQL (18.0ms) UPDATE `ratings_96` SET ranking = (@RANK:= @RANK + 1) WHERE ((@RANK:= 0) = 0) AND (rating_type= 'MovieRating') ORDER BY youtoo_user_rating DESC
SQL (18.0ms) UPDATE `ratings_96` SET created_at='2011-05-24 17:39:12' WHERE (rating_type='MovieRating')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment