示例#1
0
    def test_map_to_segments(self):
        """Tests map_to_segments function."""

        segmenter = None

        test1 = [(1, 1.0), (2, 2.0), (3, 3.0)]
        expected1 = [('ULSA', 1.0), ('UENG', 2.0), ('UKIN', 3.0)]
        mock_student_wrapper1 = unittest.mock.MagicMock()
        mock_student_wrapper1.segment_student = unittest.mock.MagicMock(
            side_effect=['ULSA', 'UENG', 'UKIN'])
        actual1 = list(
            vertex_analysis.map_to_segments(test1, segmenter,
                                            mock_student_wrapper1))

        self.assertEqual(actual1, expected1)

        test2 = []
        expected2 = []
        mock_student_wrapper2 = unittest.mock.MagicMock()
        actual2 = list(
            vertex_analysis.map_to_segments(test2, segmenter,
                                            mock_student_wrapper2))
        self.assertEqual(actual2, expected2)
示例#2
0
            help='Directory containing the swig modules.',
            action=ReadableDirectory, required=True)

    parser.set_defaults()

    args = parser.parse_args()

    show_unnormalized = 'frequency' in args.distributions
    show_normalized = 'normalized' in args.distributions

    # segment the data
    vertex_lines = vertex_analysis.get_id_values(args.file)
    students_wrapper = StudentContainerWrapper(
            args.swig_module_path, args.student_archive_path)
    segmenter = StudentContainerWrapper.SEGMENTERS[args.segmenter]
    mapped_lines = vertex_analysis.map_to_segments(
            vertex_lines, segmenter, students_wrapper)
    segments = vertex_analysis.reduce_to_segments(mapped_lines)

    # filter out small segments
    filtered_segments = {segment: values for segment, values in segments.items()
                         if values.size >= args.threshold}

    # set up the histogram for various colors
    size = ((12, 8) if show_unnormalized and show_normalized
            else (12, 4))
    fig = matplotlib.pyplot.figure(figsize=size)
    #fig.subplots_adjust(hspace=0.4)

    # Create the non-normalized histogram.
    if show_unnormalized:
        if show_normalized:
示例#3
0
            '--swig-module-path', dest='swig_module_path',
            help='Directory containing the swig modules.',
            action=readable_directory.ReadableDirectory, required=True)

    args = parser.parse_args()

    unweighted = args.weightedness == 'unweighted'
    weighted = args.weightedness == 'weighted'

    # get container of students
    students = StudentContainerWrapper(
            args.swig_module_path, args.student_archive_path)

    # get the weights of individual segments
    lines = list(vertex_analysis.get_id_values(args.file))
    mapped_to_segments = vertex_analysis.map_to_segments(
            lines, StudentContainerWrapper.SEGMENTERS[args.field], students)
    reduced_data = vertex_analysis.reduce_to_in_out(
            mapped_to_segments, args.in_segment)
    if unweighted:
        actual_segments = {key: len(data) for key, data in reduced_data.items()}
    elif weighted:
        actual_segments = {key: sum(data) for key, data in reduced_data.items()}

    print(actual_segments)

    population_segments = segment.get_segment_counts(students, args.field)
    print(population_segments[args.in_segment])

    population = len(students)
    total_weight = sum(line[1] for line in lines) if weighted else len(lines)