コード例 #1
0
def main():
	course_content    = None
	student_info      = None
	courses_file_name = "data/car-f-92.crs"
	student_file_name = "data/car-f-92.stu"
	course_dict       = {}
	student_dict      = {}


	# leemos el archivo con la informacion de los cursos (id, cantidad de estudiantes)
	with open(courses_file_name, "r+") as f:
		course_content = [course.split() for course in [line.rstrip('\n') for line in f]]
	#print(studen_info)

	# leemos el archivo con la información de los estudiantes (lista de cursos a los que está inscrito)
	with open(student_file_name, "r+") as f:
		student_info = [student.split() for student in [line.rstrip('\n') for line in f]]
	#print(course_content)

	# generamos diccionarios de objetos que representan a los cursos y a los estudiantes con todos sus atributos
	course_dict, student_dict = Formatter(course_content, student_info).format()

	total_students  = len(student_dict)
	total_courses   = len(course_dict)
	conflict_matrix = np.zeros(total_courses * total_courses).reshape(total_courses, total_courses)
	conflicts = 0

	for course_id, course in course_dict.items():
		students = course.student_list
		for course_id2, course2 in course_dict.items():
			students2 = course2.student_list
			for student in students:
				for student2 in students2:
					if student.student_id == student2.student_id:
						conflict_matrix[course.get_numeric_id() - 1][course2.get_numeric_id() - 1] = 1
						conflicts += 1
						print(conflicts)

	print(conflict_matrix)
	print("Conflict density:", conflicts/(total_courses*total_courses))

	"""
	# imprime contenido de diccionario de cursos para probar
	for course_id, course in course_dict.items():
		print(course.course_id)
		print(course.no_students)
		for student in course.student_list:
			print(student.student_id)
	"""

	""" 
コード例 #2
0
    def build_dashboard(self,
                        input_data={},
                        aligment={},
                        params={},
                        title="Stock Closing Prices",
                        ylabel='Price',
                        ylabel_right={},
                        show=True,
                        column='adj_close',
                        height=[],
                        **kwargs_to_bokeh):
        plots = []
        _data, x_range, _names = Formatter().format_input_data(
            input_data, column)
        _params = Formatter().format_params(_data, params, _names)
        _aligment = Formatter().format_aligment(aligment, _names)
        _y_label_right = Formatter().format_y_label_right(
            ylabel_right, ylabel, _names)
        kwargs_to_bokeh['y_axis_label'] = ylabel
        if 'x_range' not in kwargs_to_bokeh:
            kwargs_to_bokeh['x_range'] = Range1d(x_range[0], x_range[-1])
        if not height:
            height = [(1. / len(_data))] * len(_data)
        else:
            assert len(height) == len(_data), (
                "Number of heights should be equal to the number of plots. " +
                "expected: %s, " % len(_data) +
                "found: %s, len(height)= %s. " % (height, len(height)))
            assert sum(height) == 1, ("All heights should sum up to 1, " +
                                      "found: %s, sum(height)=%s" %
                                      (height, sum(height)))
        for i, (plot_title, data) in enumerate(_data.items()):
            plots.append(
                self._plot_stock(data=data,
                                 names=_names[plot_title],
                                 title=plot_title,
                                 params=_params[plot_title],
                                 aligment=_aligment[plot_title],
                                 ylabel_right=_y_label_right[plot_title],
                                 height=height[i],
                                 **kwargs_to_bokeh))

        layout = gridplot(plots, plot_width=self.width, ncols=self.ncols)
        self.layout = layout
        if show:
            curdoc().add_root(layout)
            curdoc().title = title
        return curdoc