Beispiel #1
0
    def test_volumes(self):
        self.learning_component_yr.hourly_volume_partial = 0
        self.entity_component_yr.hourly_volume_total = 15
        data = learning_unit_year_with_context.volume_learning_component_year(self.learning_component_yr,
                                                                              self.entity_components_yr)
        self.assertEqual(data.get(learning_unit_year_with_context.TOTAL_VOLUME_KEY), 15)
        self.assertEqual(data.get(learning_unit_year_with_context.VOLUME_QUARTER_KEY), _('remaining'))
        self.assertEqual(data.get(learning_unit_year_with_context.VOLUME_PARTIAL_KEY), 0)
        self.assertEqual(data.get(learning_unit_year_with_context.VOLUME_REMAINING_KEY), 15)

        self.learning_component_yr.hourly_volume_partial=15
        data = learning_unit_year_with_context.volume_learning_component_year(self.learning_component_yr,
                                                                              self.entity_components_yr)
        self.assertEqual(data.get(learning_unit_year_with_context.TOTAL_VOLUME_KEY), 15)
        self.assertEqual(data.get(learning_unit_year_with_context.VOLUME_PARTIAL_KEY), 15)
        self.assertEqual(data.get(learning_unit_year_with_context.VOLUME_QUARTER_KEY), _('partial'))
        self.assertEqual(data.get(learning_unit_year_with_context.VOLUME_REMAINING_KEY), 0)

        self.learning_component_yr.hourly_volume_partial=12
        data = learning_unit_year_with_context.volume_learning_component_year(self.learning_component_yr,
                                                                              self.entity_components_yr)
        self.assertEqual(data.get(learning_unit_year_with_context.TOTAL_VOLUME_KEY), 15)
        self.assertEqual(data.get(learning_unit_year_with_context.VOLUME_QUARTER_KEY), _('partial_remaining'))
        self.assertEqual(data.get(learning_unit_year_with_context.VOLUME_PARTIAL_KEY), 12)
        self.assertEqual(data.get(learning_unit_year_with_context.VOLUME_REMAINING_KEY), 3)
    def test_volume_learning_component_year(self):
        self.entity_component_yr.hourly_volume_total = 15

        self.learning_component_yr.hourly_volume_partial = 0
        data = learning_unit_year_with_context.volume_learning_component_year(
            self.learning_component_yr, self.entity_components_yr)
        self.assertEqual(data.get('VOLUME_TOTAL'), 15)
        self.assertEqual(data.get('VOLUME_QUARTER'), _('remaining'))
        self.assertEqual(data.get('VOLUME_Q1'), 0)
        self.assertEqual(data.get('VOLUME_Q2'), 15)

        self.learning_component_yr.hourly_volume_partial = 15
        data = learning_unit_year_with_context.volume_learning_component_year(
            self.learning_component_yr, self.entity_components_yr)
        self.assertEqual(data.get('VOLUME_TOTAL'), 15)
        self.assertEqual(data.get('VOLUME_QUARTER'), _('partial'))
        self.assertEqual(data.get('VOLUME_Q1'), 15)
        self.assertEqual(data.get('VOLUME_Q2'), 0)

        self.learning_component_yr.hourly_volume_partial = 12
        data = learning_unit_year_with_context.volume_learning_component_year(
            self.learning_component_yr, self.entity_components_yr)
        self.assertEqual(data.get('VOLUME_TOTAL'), 15)
        self.assertEqual(data.get('VOLUME_QUARTER'), _('partial_remaining'))
        self.assertEqual(data.get('VOLUME_Q1'), 12)
        self.assertEqual(data.get('VOLUME_Q2'), 3)

        self.learning_component_yr.hourly_volume_partial = None
        data = learning_unit_year_with_context.volume_learning_component_year(
            self.learning_component_yr, self.entity_components_yr)
        self.assertEqual(data.get('VOLUME_TOTAL'), 15)
        self.assertEqual(data.get('VOLUME_QUARTER'), None)
        self.assertEqual(data.get('VOLUME_Q1'), None)
        self.assertEqual(data.get('VOLUME_Q2'), None)
Beispiel #3
0
def get_components_identification(learning_unit_yr):
    a_learning_container_yr = learning_unit_yr.learning_container_year
    components = []
    additionnal_entities = {}

    if a_learning_container_yr:
        learning_component_year_list = mdl_base.learning_component_year.find_by_learning_container_year(
            a_learning_container_yr)

        for learning_component_year in learning_component_year_list:
            if mdl_base.learning_unit_component.search(
                    learning_component_year, learning_unit_yr).exists():
                entity_components_yr = EntityComponentYear.objects.filter(
                    learning_component_year=learning_component_year)
                if not additionnal_entities:
                    additionnal_entities = _get_entities(entity_components_yr)

                components.append({
                    'learning_component_year':
                    learning_component_year,
                    'entity_component_yr':
                    entity_components_yr.first(),
                    'volumes':
                    volume_learning_component_year(learning_component_year,
                                                   entity_components_yr)
                })

    return _compose_components_dict(components, additionnal_entities)
Beispiel #4
0
def get_same_container_year_components(learning_unit_year):
    learning_container_year = learning_unit_year.learning_container_year
    components = []

    learning_components_year = LearningComponentYear.objects.filter(
        learning_unit_year__learning_container_year=learning_container_year
    ).prefetch_related(Prefetch(
        'learningclassyear_set',
        to_attr="classes"), ).select_related('learning_unit_year').order_by(
            'type', 'acronym')

    additionnal_entities = get_entities(learning_container_year)

    for learning_component_year in learning_components_year:
        if learning_component_year.classes:
            for learning_class_year in learning_component_year.classes:
                learning_class_year.used_by_learning_units_year = learning_unit_year.acronym
                learning_class_year.is_used_by_full_learning_unit_year = _is_used_by_full_learning_unit_year(
                    learning_class_year)

        used_by_learning_unit = learning_component_year.learning_unit_year == learning_unit_year

        components.append({
            'learning_component_year':
            learning_component_year,
            'volumes':
            volume_learning_component_year(learning_component_year),
            'learning_unit_usage':
            _learning_unit_usage(learning_component_year.learning_unit_year),
            'used_by_learning_unit':
            used_by_learning_unit
        })
    components = sorted(components, key=itemgetter('learning_unit_usage'))
    return compose_components_dict(components, additionnal_entities)
Beispiel #5
0
def get_same_container_year_components(learning_unit_year, with_classes=False):
    learning_container_year = learning_unit_year.learning_container_year
    components = []
    learning_components_year = mdl_base.learning_component_year.find_by_learning_container_year(learning_container_year,
                                                                                                with_classes)
    additionnal_entities = {}

    for indx, learning_component_year in enumerate(learning_components_year):
        if learning_component_year.classes:
            for learning_class_year in learning_component_year.classes:
                learning_class_year.used_by_learning_units_year = _learning_unit_usage_by_class(learning_class_year)
                learning_class_year.is_used_by_full_learning_unit_year = _is_used_by_full_learning_unit_year(
                    learning_class_year)

        used_by_learning_unit = mdl_base.learning_unit_component.search(learning_component_year, learning_unit_year)

        entity_components_yr = EntityComponentYear.objects.filter(learning_component_year=learning_component_year)
        if indx == 0:
            additionnal_entities = _get_entities(entity_components_yr)

        components.append({'learning_component_year': learning_component_year,
                           'volumes': volume_learning_component_year(learning_component_year, entity_components_yr),
                           'learning_unit_usage': _learning_unit_usage(learning_component_year),
                           'used_by_learning_unit': used_by_learning_unit
                           })

    components = sorted(components, key=itemgetter('learning_unit_usage'))
    return _compose_components_dict(components, additionnal_entities)
Beispiel #6
0
def get_components_identification(learning_unit_yr):
    components = []
    additional_entities = {}

    learning_component_year_list_from_luy = LearningComponentYear.objects.filter(
        learning_unit_year=learning_unit_yr
    ).order_by('type', 'acronym').prefetch_related('entitycomponentyear_set')

    for learning_component_year in learning_component_year_list_from_luy:
        entity_components_yr = learning_component_year.entitycomponentyear_set.all()

        if not additional_entities:
            additional_entities = get_entities(entity_components_yr)

        components.append(
            {
                'learning_component_year': learning_component_year,
                'entity_component_yr': entity_components_yr.first(),
                'volumes': volume_learning_component_year(
                    learning_component_year,
                    entity_components_yr
                )
            }
        )

    return compose_components_dict(components, additional_entities)
Beispiel #7
0
def get_same_container_year_components(learning_unit_year):
    learning_container_year = learning_unit_year.learning_container_year
    components = []

    learning_components_year = LearningComponentYear.objects.filter(
        learning_unit_year__learning_container_year=learning_container_year
    ).prefetch_related(
        Prefetch('learningclassyear_set', to_attr="classes"),
    ).select_related('learning_unit_year').order_by('type', 'acronym')

    additionnal_entities = {}

    for indx, learning_component_year in enumerate(learning_components_year):
        if learning_component_year.classes:
            for learning_class_year in learning_component_year.classes:
                learning_class_year.used_by_learning_units_year = learning_unit_year.acronym
                learning_class_year.is_used_by_full_learning_unit_year = _is_used_by_full_learning_unit_year(
                    learning_class_year)

        used_by_learning_unit = learning_component_year.learning_unit_year == learning_unit_year

        entity_components_yr = learning_component_year.entitycomponentyear_set.all()
        if indx == 0:
            additionnal_entities = get_entities(entity_components_yr)

        components.append(
            {
                'learning_component_year': learning_component_year,
                'volumes': volume_learning_component_year(learning_component_year, entity_components_yr),
                'learning_unit_usage': _learning_unit_usage(learning_component_year.learning_unit_year),
                'used_by_learning_unit': used_by_learning_unit
            }
        )
    components = sorted(components, key=itemgetter('learning_unit_usage'))
    return compose_components_dict(components, additionnal_entities)
Beispiel #8
0
def get_same_container_year_components(learning_unit_year, with_classes=False):
    learning_container_year = learning_unit_year.learning_container_year
    components = []
    learning_components_year = mdl.learning_component_year.find_by_learning_container_year(
        learning_container_year, with_classes)

    for learning_component_year in learning_components_year:
        if learning_component_year.classes:
            for learning_class_year in learning_component_year.classes:
                learning_class_year.used_by_learning_units_year = _learning_unit_usage_by_class(
                    learning_class_year)
                learning_class_year.is_used_by_full_learning_unit_year = _is_used_by_full_learning_unit_year(
                    learning_class_year)

        used_by_learning_unit = mdl.learning_unit_component.search(
            learning_component_year, learning_unit_year)

        entity_components_yr = EntityComponentYear.objects.filter(
            learning_component_year=learning_component_year)

        components.append({
            'learning_component_year':
            learning_component_year,
            'volumes':
            volume_learning_component_year(learning_component_year,
                                           entity_components_yr),
            'learning_unit_usage':
            _learning_unit_usage(learning_component_year),
            'used_by_learning_unit':
            used_by_learning_unit
        })
    return components
Beispiel #9
0
    def test_volume_learning_component_year(self):
        self.entity_component_yr.repartition_volume = 15

        self.learning_component_yr.hourly_volume_total_annual = 15
        self.learning_component_yr.hourly_volume_partial_q1 = 10
        self.learning_component_yr.hourly_volume_partial_q2 = 5
        data = learning_unit_year_with_context.volume_learning_component_year(
            self.learning_component_yr, self.entity_components_yr)
        self.assertEqual(data.get('VOLUME_TOTAL'), 15)
        self.assertEqual(data.get('VOLUME_Q1'), 10)
        self.assertEqual(data.get('VOLUME_Q2'), 5)
        self.assertEqual(data.get('VOLUME_REQUIREMENT_ENTITY'), 15)
Beispiel #10
0
    def test_volumes_unknwon_quadrimester(self):
        self.learning_component_yr.hourly_volume_partial = -1
        self.entity_component_yr.hourly_volume_total = 30

        data = learning_unit_year_with_context.volume_learning_component_year(self.learning_component_yr,
                                                                              self.entity_components_yr)
        self.assertEqual(data.get(learning_unit_year_with_context.TOTAL_VOLUME_KEY), 30)
        self.assertEqual(data.get(learning_unit_year_with_context.VOLUME_QUARTER_KEY), _('partial_or_remaining'))
        self.assertEqual(data.get(learning_unit_year_with_context.VOLUME_PARTIAL_KEY),
                         learning_unit_year_with_context.VOLUME_FOR_UNKNOWN_QUADRIMESTER)
        self.assertEqual(data.get(learning_unit_year_with_context.VOLUME_REMAINING_KEY),
                         learning_unit_year_with_context.VOLUME_FOR_UNKNOWN_QUADRIMESTER)
Beispiel #11
0
    def test_volume_learning_component_year(self):
        self.learning_component_yr.repartition_volume_requirement_entity = 15

        self.learning_component_yr.hourly_volume_total_annual = 15
        self.learning_component_yr.hourly_volume_partial_q1 = 10
        self.learning_component_yr.hourly_volume_partial_q2 = 5
        data = learning_unit_year_with_context.volume_learning_component_year(
            self.learning_component_yr)
        self.assertEqual(data.get(VOLUME_TOTAL), 15)

        self.assertEqual(data.get(VOLUME_Q1), 10)
        self.assertEqual(data.get(VOLUME_Q2), 5)
        self.assertEqual(data.get(VOLUME_REQUIREMENT_ENTITY), 15)
Beispiel #12
0
    def test_volumes_undefined(self):
        self.learning_component_yr.hourly_volume_partial = None
        self.entity_component_yr.hourly_volume_total = 15

        data = learning_unit_year_with_context.volume_learning_component_year(self.learning_component_yr,
                                                                              self.entity_components_yr)
        self.assertEqual(data.get(learning_unit_year_with_context.TOTAL_VOLUME_KEY), 15)
        self.assertEqual(data.get(learning_unit_year_with_context.VOLUME_QUARTER_KEY),
                         learning_unit_year_with_context.UNDEFINED_VALUE)
        self.assertEqual(data.get(learning_unit_year_with_context.VOLUME_PARTIAL_KEY),
                         learning_unit_year_with_context.UNDEFINED_VALUE)
        self.assertEqual(data.get(learning_unit_year_with_context.VOLUME_REMAINING_KEY),
                         learning_unit_year_with_context.UNDEFINED_VALUE)
Beispiel #13
0
def get_components_identification(learning_unit_yr):
    components = []
    additional_entities = get_entities(
        learning_unit_yr.learning_container_year)

    learning_component_year_list_from_luy = LearningComponentYear.objects.filter(
        learning_unit_year=learning_unit_yr).order_by('type', 'acronym')

    for learning_component_year in learning_component_year_list_from_luy:
        components.append({
            'learning_component_year':
            learning_component_year,
            'volumes':
            volume_learning_component_year(learning_component_year)
        })

    return compose_components_dict(components, additional_entities)
Beispiel #14
0
def get_components_identification(learning_unit_yr):
    a_learning_container_yr = learning_unit_yr.learning_container_year
    components = []
    if a_learning_container_yr:
        learning_component_year_list = mdl_base.learning_component_year.find_by_learning_container_year(
            a_learning_container_yr)

        for learning_component_year in learning_component_year_list:
            if mdl_base.learning_unit_component.search(learning_component_year, learning_unit_yr).exists():
                entity_components_yr = EntityComponentYear.objects.filter(
                    learning_component_year=learning_component_year)

                components.append({'learning_component_year': learning_component_year,
                                   'entity_component_yr': entity_components_yr.first(),
                                   'volumes': volume_learning_component_year(learning_component_year,
                                                                             entity_components_yr)})
    return components
Beispiel #15
0
def get_same_container_year_components(learning_unit_year):
    learning_container_year = learning_unit_year.learning_container_year
    components = []

    learning_components_year = learning_container_year.learningcomponentyear_set.prefetch_related(
        Prefetch('learningclassyear_set', to_attr="classes"),
        'learningunityear_set').order_by('type', 'acronym')

    additionnal_entities = {}

    for indx, learning_component_year in enumerate(learning_components_year):
        if learning_component_year.classes:
            for learning_class_year in learning_component_year.classes:
                learning_class_year.used_by_learning_units_year = _learning_unit_usage_by_class(
                    learning_class_year)
                learning_class_year.is_used_by_full_learning_unit_year = _is_used_by_full_learning_unit_year(
                    learning_class_year)

        used_by_learning_unit = mdl_base.learning_unit_component.search(
            learning_component_year, learning_unit_year)

        entity_components_yr = learning_component_year.entitycomponentyear_set.all(
        )
        if indx == 0:
            additionnal_entities = get_entities(entity_components_yr)

        components.append({
            'learning_component_year':
            learning_component_year,
            'volumes':
            volume_learning_component_year(learning_component_year,
                                           entity_components_yr),
            'learning_unit_usage':
            _learning_unit_usage(learning_component_year),
            'used_by_learning_unit':
            used_by_learning_unit
        })
    components = sorted(components, key=itemgetter('learning_unit_usage'))
    return compose_components_dict(components, additionnal_entities)