random samply sized
This commit is contained in:
parent
f26ab9c46c
commit
7db7606da5
|
@ -7,7 +7,7 @@ from base.orm import local_session
|
||||||
from base.resolvers import mutation, query
|
from base.resolvers import mutation, query
|
||||||
from auth.authenticate import login_required
|
from auth.authenticate import login_required
|
||||||
from sqlalchemy import and_
|
from sqlalchemy import and_
|
||||||
from numpy import random
|
import random
|
||||||
|
|
||||||
|
|
||||||
@query.field("topicsAll")
|
@query.field("topicsAll")
|
||||||
|
@ -85,7 +85,7 @@ def topic_unfollow(user, slug):
|
||||||
|
|
||||||
|
|
||||||
@query.field("topicsRandom")
|
@query.field("topicsRandom")
|
||||||
async def topics_random(_, info):
|
async def topics_random(_, info, amount=12):
|
||||||
topics = await TopicStorage.get_topics_all()
|
topics = await TopicStorage.get_topics_all()
|
||||||
normalized_topics = []
|
normalized_topics = []
|
||||||
for topic in topics:
|
for topic in topics:
|
||||||
|
@ -93,5 +93,4 @@ async def topics_random(_, info):
|
||||||
topic.stat = topic_stat
|
topic.stat = topic_stat
|
||||||
if topic_stat["shouts"] > 2:
|
if topic_stat["shouts"] > 2:
|
||||||
normalized_topics.push(topic)
|
normalized_topics.push(topic)
|
||||||
random.shuffle(normalized_topics)
|
return random.sample(normalized_topics, k=amount)
|
||||||
return normalized_topics[0:12]
|
|
||||||
|
|
|
@ -248,7 +248,7 @@ type Query {
|
||||||
|
|
||||||
# topics
|
# topics
|
||||||
topicsAll: [Topic]!
|
topicsAll: [Topic]!
|
||||||
topicsRandom: [Topic]!
|
topicsRandom(amount: Int): [Topic]!
|
||||||
topicsByCommunity(community: String!): [Topic]!
|
topicsByCommunity(community: String!): [Topic]!
|
||||||
topicsByAuthor(author: String!): [Topic]!
|
topicsByAuthor(author: String!): [Topic]!
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user