def test_csv_import(self): # Check that data imported from CSV file has correct structure set_run_info(import_csv_path='csv/') data = Exchanger.import_data(ExchangeFormat.CSV) self.assertGreater(len(data), 0) self.assertGreater(len(data['lessons']), 0) self.assertGreater(len(data['days']), 0) self.assertGreater(len(data['time_slots']), 0) self.assertGreater(len(data['auditoriums']), 0) self.assertGreater(len(data['student_groups']), 0)
def test_json_import(self): # Check that data imported from JSON file has correct structure set_run_info(import_json_path='json/schedule_data.json') data = Exchanger.import_data(ExchangeFormat.JSON) self.assertGreater(len(data), 0) self.assertGreater(len(data['lessons']), 0) self.assertGreater(len(data['days']), 0) self.assertGreater(len(data['time_slots']), 0) self.assertGreater(len(data['auditoriums']), 0) self.assertGreater(len(data['student_groups']), 0)
def get_initial_population(data=None) -> (Population, dict): """Make initial population based on data from CSV/JSON (at the moment)""" if data is None: data = Exchanger.import_data(config['exchange_format']) data, uni_conf = DataProcessor.enumerate_data(data) initial_population = Population() for i in range(config['size_of_population']): lessons_list = [] for lesson in data['lessons']: day = choice(data['days']) time_slot = choice(data['time_slots']) auditorium = choice(data['auditoriums']) slot = Lesson(time_slot, (lesson[0], lesson[1]), lesson[2], day, auditorium, lesson[3]) lessons_list.append(slot) initial_population.add(individ=Schedule(lessons_list)) return initial_population, uni_conf