def fetch_project(project: pd.Series) -> Project: """ Fetches project from series @param project: pandas Series @return: project """ return Project(datetime.combine(project.iloc[1].date(), time(hour=6)), project.iloc[2].to_pydatetime(), project.iloc[0])
def test_fetch_jobs_in_project(self): p = Project(id="D1108610_1-26", start_dt=datetime(2020, 11, 23, 6), expiration_dt=datetime(2021, 1, 8)) j1 = Job(duration=timedelta(hours=0), delay="1d", machine_id="1.VA.NAB", project=p, previous_machines=[]) j2 = Job(duration=timedelta(hours=0.798846154), delay="2d", machine_id="2.VA.RS", project=p, previous_machines=["1.VA.NAB"]) j3 = Job(duration=timedelta(hours=2.458461538), delay="1d", machine_id="3.VA.BKOM", project=p, previous_machines=[]) j4 = Job(duration=timedelta(hours=1.348076923), delay="2d", machine_id="4.VA.MKOM", project=p, previous_machines=["3.VA.BKOM"]) j5 = Job(duration=timedelta(hours=2.685), delay="1d", machine_id="5.VA.KOMWKŁ", project=p, previous_machines=[ '1.VA.NAB', '2.VA.RS', '3.VA.BKOM', '4.VA.MKOM' ]) j6 = Job(duration=timedelta(hours=3.174230769), delay="2d", machine_id="6.VA.MKONC", project=p, previous_machines=[ '1.VA.NAB', '2.VA.RS', '3.VA.BKOM', '4.VA.MKOM', '5.VA.KOMWKŁ' ]) j7 = Job(duration=timedelta(hours=0), delay="0d", machine_id="7.VA.OWIE", project=p, previous_machines=[ '1.VA.NAB', '2.VA.RS', '3.VA.BKOM', '4.VA.MKOM', '5.VA.KOMWKŁ', '6.VA.MKONC' ]) j8 = Job(duration=timedelta(hours=3.995), delay="1d", machine_id="8.VA.MBAT", project=p, previous_machines=[ '1.VA.NAB', '2.VA.RS', '3.VA.BKOM', '4.VA.MKOM', '5.VA.KOMWKŁ', '6.VA.MKONC', '7.VA.OWIE' ]) self.assertEqual([j1, j2, j3, j4, j5, j6, j7, j8], fetch_jobs_in_project(self.schedule.iloc[0]))
def setUp(self): self.project = Project(start_dt=datetime(2021, 3, 1, 6), expiration_dt=datetime(2021, 3, 1, 6), id="P1") self.scheduled_job_day_delay = ScheduledJob( duration=timedelta(hours=6), machine_id="M1", delay="2d", project=self.project, end_dt=datetime(2021, 4, 1, 6), start_dt=datetime(2021, 3, 28, 14), previous_machines=[]) self.scheduled_job_week_delay = ScheduledJob( duration=timedelta(hours=6), machine_id="M1", delay="1w", project=self.project, end_dt=datetime(2021, 4, 1, 6), start_dt=datetime(2021, 3, 28, 14), previous_machines=[])
def test_fetch_project(self): p = Project(id="D1108610_1-26", start_dt=datetime(2020, 11, 23, 6), expiration_dt=datetime(2021, 1, 8)) self.assertEqual(p, fetch_project(self.schedule.iloc[0]))
def test_fetch_jobs_dict_from_list(self): p1 = Project(id="D1108610_1-26", start_dt=datetime(2020, 11, 23, 6), expiration_dt=datetime(2021, 1, 8)) j1 = Job(duration=timedelta(hours=0), delay="1d", machine_id="1.VA.NAB", project=p1, previous_machines=[]) j2 = Job(duration=timedelta(hours=0.798846154), delay="2d", machine_id="2.VA.RS", project=p1, previous_machines=["1.VA.NAB"]) j3 = Job(duration=timedelta(hours=2.458461538), delay="1d", machine_id="3.VA.BKOM", project=p1, previous_machines=[]) j4 = Job(duration=timedelta(hours=1.348076923), delay="2d", machine_id="4.VA.MKOM", project=p1, previous_machines=["3.VA.BKOM"]) j5 = Job(duration=timedelta(hours=2.685), delay="1d", machine_id="5.VA.KOMWKŁ", project=p1, previous_machines=[ '1.VA.NAB', '2.VA.RS', '3.VA.BKOM', '4.VA.MKOM' ]) j6 = Job(duration=timedelta(hours=3.174230769), delay="2d", machine_id="6.VA.MKONC", project=p1, previous_machines=[ '1.VA.NAB', '2.VA.RS', '3.VA.BKOM', '4.VA.MKOM', '5.VA.KOMWKŁ' ]) j7 = Job(duration=timedelta(hours=0), delay="0d", machine_id="7.VA.OWIE", project=p1, previous_machines=[ '1.VA.NAB', '2.VA.RS', '3.VA.BKOM', '4.VA.MKOM', '5.VA.KOMWKŁ', '6.VA.MKONC' ]) j8 = Job(duration=timedelta(hours=3.995), delay="1d", machine_id="8.VA.MBAT", project=p1, previous_machines=[ '1.VA.NAB', '2.VA.RS', '3.VA.BKOM', '4.VA.MKOM', '5.VA.KOMWKŁ', '6.VA.MKONC', '7.VA.OWIE' ]) p2 = Project(id="D1108610_2-26", start_dt=datetime(2020, 11, 23, 6), expiration_dt=datetime(2021, 1, 8)) j9 = Job(duration=timedelta(hours=0), delay="1d", machine_id="1.VA.NAB", project=p2, previous_machines=[]) j10 = Job(duration=timedelta(hours=5.34), delay="2d", machine_id="2.VA.RS", project=p2, previous_machines=["1.VA.NAB"]) j11 = Job(duration=timedelta(hours=8.04), delay="1d", machine_id="3.VA.BKOM", project=p2, previous_machines=[]) j12 = Job(duration=timedelta(hours=1.5), delay="2d", machine_id="4.VA.MKOM", project=p2, previous_machines=["3.VA.BKOM"]) j13 = Job(duration=timedelta(hours=0.685), delay="1d", machine_id="5.VA.KOMWKŁ", project=p2, previous_machines=[ '1.VA.NAB', '2.VA.RS', '3.VA.BKOM', '4.VA.MKOM' ]) j14 = Job(duration=timedelta(hours=6.536), delay="2d", machine_id="6.VA.MKONC", project=p2, previous_machines=[ '1.VA.NAB', '2.VA.RS', '3.VA.BKOM', '4.VA.MKOM', '5.VA.KOMWKŁ' ]) j15 = Job(duration=timedelta(hours=7.215332), delay="0d", machine_id="7.VA.OWIE", project=p2, previous_machines=[ '1.VA.NAB', '2.VA.RS', '3.VA.BKOM', '4.VA.MKOM', '5.VA.KOMWKŁ', '6.VA.MKONC' ]) j16 = Job(duration=timedelta(hours=2.9), delay="1d", machine_id="8.VA.MBAT", project=p2, previous_machines=[ '1.VA.NAB', '2.VA.RS', '3.VA.BKOM', '4.VA.MKOM', '5.VA.KOMWKŁ', '6.VA.MKONC', '7.VA.OWIE' ]) jobs_list = [ j1, j2, j3, j4, j5, j6, j7, j8, j9, j10, j11, j12, j13, j14, j15, j16 ] jobs_dict = { p1: [j1, j2, j3, j4, j5, j6, j7, j8], p2: [j9, j10, j11, j12, j13, j14, j15, j16] } self.assertEqual(jobs_dict, fetch_jobs_dict_from_list(jobs_list))
def setUp(self): seed(2021) self.r1_m1 = Resource(start_dt=datetime(2021, 4, 1, 6), end_dt=datetime(2021, 4, 1, 14), worker_amount=1) self.r2_m1 = Resource(start_dt=datetime(2021, 4, 1, 14), end_dt=datetime(2021, 4, 1, 22), worker_amount=2) self.r3_m1 = Resource(start_dt=datetime(2021, 4, 1, 22), end_dt=datetime(2021, 4, 2, 6), worker_amount=3) self.r1_m2 = Resource(start_dt=datetime(2021, 4, 1, 6), end_dt=datetime(2021, 4, 1, 14), worker_amount=3) self.r2_m2 = Resource(start_dt=datetime(2021, 4, 1, 14), end_dt=datetime(2021, 4, 1, 22), worker_amount=2) self.r3_m2 = Resource(start_dt=datetime(2021, 4, 1, 22), end_dt=datetime(2021, 4, 2, 6), worker_amount=2) resources = { "M1": [self.r1_m1, self.r2_m1, self.r3_m1], "M2": [self.r1_m2, self.r2_m2, self.r3_m2] } self.resources = Resources(resources) self.p1 = Project(start_dt=datetime(2021, 3, 28, 6), expiration_dt=datetime(2021, 4, 10), id="P1") self.p2 = Project(start_dt=datetime(2021, 3, 28, 6), expiration_dt=datetime(2021, 4, 10), id="P2") self.j1 = ScheduledJob(start_dt=datetime(2021, 3, 28, 6), end_dt=datetime(2021, 3, 28, 14), duration=timedelta(hours=8), delay='0d', machine_id="M1", project=self.p1, previous_machines=[]) self.j2 = ScheduledJob(start_dt=datetime(2021, 3, 28, 6), end_dt=datetime(2021, 3, 28, 14), duration=timedelta(hours=8), delay='0d', machine_id="M2", project=self.p1, previous_machines=["M1"]) self.j3 = ScheduledJob(start_dt=datetime(2021, 4, 1, 6), end_dt=datetime(2021, 4, 1, 14), duration=timedelta(hours=8), delay='0d', machine_id="M1", project=self.p2, previous_machines=[]) self.j4 = ScheduledJob(start_dt=datetime(2021, 4, 1, 6), end_dt=datetime(2021, 4, 1, 10), duration=timedelta(hours=4), delay='0d', machine_id="M2", project=self.p2, previous_machines=["M1"]) self.jobs = [self.j1, self.j2, self.j3, self.j4] self.creatures = list(range(4)) self.genetic = GeneticScheduler(jobs=self.jobs, resources=self.resources)