def test_reduce_to_segments(self): """Tests reduce_to_segments function.""" test1 = [('ULSA', 1.0), ('UENG', 2.0), ('UKIN', 3.0), ('ULSA', 1.0)] expected1 = { 'ULSA': numpy.array([1.0, 1.0]), 'UENG': numpy.array([2.0]), 'UKIN': numpy.array([3.0]) } actual1 = vertex_analysis.reduce_to_segments(test1) self._test_dict_to_numpy_array_equal(actual1, expected1) test2 = [] expected2 = dict() actual2 = vertex_analysis.reduce_to_segments(test2) self._test_dict_to_numpy_array_equal(actual2, expected2) test3 = [('ULSA', 1.0), ('ULSA', 2.0), ('ULSA', 3.0), ('ULSA', 1.0)] expected3 = { 'ULSA': numpy.array([1.0, 2.0, 3.0, 1.0]), } actual3 = vertex_analysis.reduce_to_segments(test3) self._test_dict_to_numpy_array_equal(actual3, expected3)
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: ax1 = fig.add_subplot(2, 1, 1)