def get_explore_recommendations(user, request):
 data = generate_recommendation_data()
 exercise_parents_table = get_exercise_parents_lookup_table()
 recent_exercises = get_most_recent_exercises(user)
 recent_subtopics = list(set([exercise_parents_table[ex]['subtopic_id'] for ex in recent_exercises if (ex in exercise_parents_table)]))
 sampleNum = min(len(recent_subtopics), settings.TOPIC_RECOMMENDATION_DEPTH)
 random_subtopics = random.sample(recent_subtopics, sampleNum)
 added = []
 final = []
 for subtopic_id in random_subtopics:
  related_subtopics = data[subtopic_id]['related_subtopics'][2:7]
  recommended_topic = next((topic for topic in related_subtopics if ((topic not in added) and (topic not in recent_subtopics))))
  if recommended_topic:
   final.append({'suggested_topic': (get_content_item(language=request.language, content_id=recommended_topic, topic=True) or {}), 'interest_topic': (get_content_item(language=request.language, content_id=subtopic_id, topic=True) or {})})
   added.append(recommended_topic)
 return final

def get_explore_recommendations ( user , request ) : data = generate_recommendation_data ( ) exercise_parents_table = get_exercise_parents_lookup_table ( ) recent_exercises = get_most_recent_exercises ( user ) recent_subtopics = list ( set ( [ exercise_parents_table [ ex ] [ 'subtopic_id' ] for ex in recent_exercises if ( ex in exercise_parents_table ) ] ) ) sampleNum = min ( len ( recent_subtopics ) , settings . TOPIC_RECOMMENDATION_DEPTH ) random_subtopics = random . sample ( recent_subtopics , sampleNum ) added = [ ] final = [ ] for subtopic_id in random_subtopics : related_subtopics = data [ subtopic_id ] [ 'related_subtopics' ] [ 2 : 7 ] recommended_topic = next ( ( topic for topic in related_subtopics if ( ( topic not in added ) and ( topic not in recent_subtopics ) ) ) ) if recommended_topic : final . append ( { 'suggested_topic' : ( get_content_item ( language = request . language , content_id = recommended_topic , topic = True ) or { } ) , 'interest_topic' : ( get_content_item ( language = request . language , content_id = subtopic_id , topic = True ) or { } ) } ) added . append ( recommended_topic ) return final
get the recommendations for the explore section .