#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from extractor.feature.feature import Feature

import logging


'''
The number of unique elements (either videos or problems)
'''
class CountUniqueElement(Feature):

    def __init__(self, data, settings):
        super().__init__('count_unique_elements', data, settings)

    def compute(self):
        assert 'course' in self.settings and self.settings['course'].has_schedule() and 'type' in self.settings

        if len(self.data.index) == 0:
            logging.debug('feature {} is invalid: empty dataframe'.format(self.name))
            return 0.0

        return self.data[self.settings['type'] + '_id'].nunique()
