import logging _logger = logging.getLogger(__name__) STYLE_RESOURCE_MAP = { 'visual': ['video', 'pdf', 'interactive'], 'auditory': ['video', 'interactive'], 'reading': ['pdf', 'document'], 'kinesthetic': ['interactive'], } class StyleMatcher: """Ranks learning resources based on student's learning style preference.""" @classmethod def rank_resources(cls, learning_style, resources): """Sort resources so that types matching the student's style come first. Args: learning_style: str, one of visual/auditory/reading/kinesthetic resources: recordset of encoach.resource Returns: sorted list of resource records """ preferred_types = STYLE_RESOURCE_MAP.get(learning_style, []) return sorted(resources, key=lambda r: (r.type not in preferred_types, r.id)) @classmethod def filter_by_style(cls, learning_style, resources): """Return only resources matching the learning style (with fallback to all).""" preferred_types = STYLE_RESOURCE_MAP.get(learning_style, []) matched = [r for r in resources if r.type in preferred_types] return matched if matched else list(resources)