This commit is contained in:
@@ -42,7 +42,7 @@ class AuthorsBy(TypedDict, total=False):
|
||||
🔢 Базовые метрики: "shouts" (публикации), "followers" (подписчики)
|
||||
🏷️ Контент: "topics" (темы), "comments" (комментарии)
|
||||
👥 Социальные: "coauthors" (соавторы), "replies_count" (ответы на контент)
|
||||
⭐ Рейтинг: "rating" (общий), "rating_shouts" (публикации), "rating_comments" (комментарии)
|
||||
⭐ Рейтинг: "rating_shouts" (публикации), "rating_comments" (комментарии)
|
||||
👁️ Вовлечённость: "viewed_shouts" (просмотры)
|
||||
📝 Алфавит: "name" (по имени)
|
||||
|
||||
@@ -112,7 +112,7 @@ async def get_authors_with_stats(
|
||||
- topics: Уникальные темы участия
|
||||
- coauthors: Количество соавторов
|
||||
- followers: Подписчики
|
||||
- rating: Общий рейтинг (rating_shouts + rating_comments)
|
||||
- authors: Количество авторов, на которых подписан
|
||||
- rating_shouts: Рейтинг публикаций (реакции)
|
||||
- rating_comments: Рейтинг комментариев (реакции)
|
||||
- comments: Созданные комментарии
|
||||
@@ -161,7 +161,6 @@ async def get_authors_with_stats(
|
||||
if order_value in [
|
||||
"shouts",
|
||||
"followers",
|
||||
"rating",
|
||||
"comments",
|
||||
"topics",
|
||||
"coauthors",
|
||||
@@ -476,46 +475,16 @@ async def get_authors_with_stats(
|
||||
comments_stats = {row[0]: row[1] for row in session.execute(text(comments_stats_query), params)}
|
||||
logger.debug(f"Comments stats retrieved: {comments_stats}")
|
||||
|
||||
# 💬 Статистика по вызванным комментариям (ответы на комментарии + комментарии на посты)
|
||||
logger.debug("Executing replies_count statistics query")
|
||||
|
||||
# Ответы на комментарии автора
|
||||
replies_to_comments_query = f"""
|
||||
SELECT r1.created_by as author_id, COUNT(DISTINCT r2.id) as replies_count
|
||||
FROM reaction r1
|
||||
JOIN reaction r2 ON r1.id = r2.reply_to AND r2.deleted_at IS NULL
|
||||
WHERE r1.created_by IN ({placeholders}) AND r1.deleted_at IS NULL
|
||||
AND r1.kind IN ('COMMENT', 'QUOTE')
|
||||
AND r2.kind IN ('COMMENT', 'QUOTE')
|
||||
GROUP BY r1.created_by
|
||||
# 👥 Статистика по количеству уникальных авторов, на которых подписан данный автор
|
||||
logger.debug("Executing authors statistics query")
|
||||
authors_stats_query = f"""
|
||||
SELECT follower, COUNT(DISTINCT following) as authors_count
|
||||
FROM author_follower
|
||||
WHERE follower IN ({placeholders})
|
||||
GROUP BY follower
|
||||
"""
|
||||
replies_to_comments_stats = {
|
||||
row[0]: row[1] for row in session.execute(text(replies_to_comments_query), params)
|
||||
}
|
||||
logger.debug(f"Replies to comments stats retrieved: {replies_to_comments_stats}")
|
||||
|
||||
# Комментарии на посты автора
|
||||
comments_on_posts_query = f"""
|
||||
SELECT sa.author as author_id, COUNT(DISTINCT r.id) as replies_count
|
||||
FROM shout_author sa
|
||||
JOIN shout s ON sa.shout = s.id AND s.deleted_at IS NULL AND s.published_at IS NOT NULL
|
||||
JOIN reaction r ON s.id = r.shout AND r.deleted_at IS NULL
|
||||
WHERE sa.author IN ({placeholders})
|
||||
AND r.kind IN ('COMMENT', 'QUOTE')
|
||||
GROUP BY sa.author
|
||||
"""
|
||||
comments_on_posts_stats = {
|
||||
row[0]: row[1] for row in session.execute(text(comments_on_posts_query), params)
|
||||
}
|
||||
logger.debug(f"Comments on posts stats retrieved: {comments_on_posts_stats}")
|
||||
|
||||
# Объединяем статистику
|
||||
replies_count_stats = {}
|
||||
for author_id in author_ids:
|
||||
replies_to_comments = replies_to_comments_stats.get(author_id, 0)
|
||||
comments_on_posts = comments_on_posts_stats.get(author_id, 0)
|
||||
replies_count_stats[author_id] = replies_to_comments + comments_on_posts
|
||||
logger.debug(f"Combined replies count stats: {replies_count_stats}")
|
||||
authors_stats = {row[0]: row[1] for row in session.execute(text(authors_stats_query), params)}
|
||||
logger.debug(f"Authors stats retrieved: {authors_stats}")
|
||||
|
||||
# ⭐ Статистика по рейтингу публикаций (сумма реакций на публикации автора)
|
||||
logger.debug("Executing rating_shouts statistics query")
|
||||
@@ -557,14 +526,46 @@ async def get_authors_with_stats(
|
||||
}
|
||||
logger.debug(f"Rating comments stats retrieved: {rating_comments_stats}")
|
||||
|
||||
# 📈 Общий рейтинг (сумма рейтингов публикаций и комментариев)
|
||||
logger.debug("Calculating overall rating")
|
||||
overall_rating_stats = {}
|
||||
# 💬 Статистика по вызванным комментариям (ответы на комментарии + комментарии на посты)
|
||||
logger.debug("Executing replies_count statistics query")
|
||||
|
||||
# Ответы на комментарии автора
|
||||
replies_to_comments_query = f"""
|
||||
SELECT r1.created_by as author_id, COUNT(DISTINCT r2.id) as replies_count
|
||||
FROM reaction r1
|
||||
JOIN reaction r2 ON r1.id = r2.reply_to AND r2.deleted_at IS NULL
|
||||
WHERE r1.created_by IN ({placeholders}) AND r1.deleted_at IS NULL
|
||||
AND r1.kind IN ('COMMENT', 'QUOTE')
|
||||
AND r2.kind IN ('COMMENT', 'QUOTE')
|
||||
GROUP BY r1.created_by
|
||||
"""
|
||||
replies_to_comments_stats = {
|
||||
row[0]: row[1] for row in session.execute(text(replies_to_comments_query), params)
|
||||
}
|
||||
logger.debug(f"Replies to comments stats retrieved: {replies_to_comments_stats}")
|
||||
|
||||
# Комментарии на посты автора
|
||||
comments_on_posts_query = f"""
|
||||
SELECT sa.author as author_id, COUNT(DISTINCT r.id) as replies_count
|
||||
FROM shout_author sa
|
||||
JOIN shout s ON sa.shout = s.id AND s.deleted_at IS NULL AND s.published_at IS NOT NULL
|
||||
JOIN reaction r ON s.id = r.shout AND r.deleted_at IS NULL
|
||||
WHERE sa.author IN ({placeholders})
|
||||
AND r.kind IN ('COMMENT', 'QUOTE')
|
||||
GROUP BY sa.author
|
||||
"""
|
||||
comments_on_posts_stats = {
|
||||
row[0]: row[1] for row in session.execute(text(comments_on_posts_query), params)
|
||||
}
|
||||
logger.debug(f"Comments on posts stats retrieved: {comments_on_posts_stats}")
|
||||
|
||||
# Объединяем статистику
|
||||
replies_count_stats = {}
|
||||
for author_id in author_ids:
|
||||
shouts_rating = rating_shouts_stats.get(author_id, 0)
|
||||
comments_rating = rating_comments_stats.get(author_id, 0)
|
||||
overall_rating_stats[author_id] = shouts_rating + comments_rating
|
||||
logger.debug(f"Overall rating stats calculated: {overall_rating_stats}")
|
||||
replies_to_comments = replies_to_comments_stats.get(author_id, 0)
|
||||
comments_on_posts = comments_on_posts_stats.get(author_id, 0)
|
||||
replies_count_stats[author_id] = replies_to_comments + comments_on_posts
|
||||
logger.debug(f"Combined replies count stats: {replies_count_stats}")
|
||||
|
||||
# 👁️ Статистика по просмотрам публикаций (используем ViewedStorage для получения агрегированных данных)
|
||||
logger.debug("Calculating viewed_shouts statistics from ViewedStorage")
|
||||
@@ -601,7 +602,7 @@ async def get_authors_with_stats(
|
||||
"topics": topics_stats.get(author.id, 0),
|
||||
"coauthors": coauthors_stats.get(author.id, 0),
|
||||
"followers": followers_stats.get(author.id, 0),
|
||||
"rating": overall_rating_stats.get(author.id, 0),
|
||||
"authors": authors_stats.get(author.id, 0),
|
||||
"rating_shouts": rating_shouts_stats.get(author.id, 0),
|
||||
"rating_comments": rating_comments_stats.get(author.id, 0),
|
||||
"comments": comments_stats.get(author.id, 0),
|
||||
|
||||
Reference in New Issue
Block a user