def test_schedule_project(self): # Assignees person_id1 = 101 person_id2 = 102 person_id3 = 103 # Projects p1 = Project(1) p1_w1 = util.construct_work(1, "p1 w1", 1.0, [], person_id1, None) p1_w2 = util.construct_work(2, "p1 w2", 1.0, [], person_id1, None) p1_w3 = util.construct_work(5, "p1 w3", 0.1, [], person_id1, util.nov15) p1.work = [p1_w1, p1_w2, p1_w3] p2 = Project(2) p2_w1 = util.construct_work(3, "p2 w1", 1.0, [], person_id2, None) p2_w2 = util.construct_work(4, "p2 w2", 1.0, [2], person_id3, None) p2.work = [p2_w1, p2_w2] # Scheduler scheduler = Scheduler(util.nov1) projects = scheduler.schedule_projects([p1, p2]) # Check work end dates self.assertEqual(util.nov2, p1_w1.est_end_date()) self.assertEqual(util.nov5, p1_w2.est_end_date()) self.assertEqual(util.nov2, p2_w1.est_end_date()) self.assertEqual(util.nov6, p2_w2.est_end_date()) # Check project end dates self.assertEqual(util.nov15, p1.est_end_date) self.assertEqual(util.nov6, p2.est_end_date) return
def get_projects_for_scheduling(connection): project_ids = select_all_project_ids(connection) result = [] for project_id in project_ids: p = Project(project_id) p.work = work_db.select_work_for_project(connection, p.project_id) result.append(p) return result
def test_schedule_with_key_date_in_past(self): # Assignees person_id1 = 101 # Projects p1 = Project(1) p1_w3 = util.construct_work(5, "p1 w3", 0.1, [], person_id1, util.nov1) p1.work = [p1_w3] # Scheduler scheduler = Scheduler(util.nov15) projects = scheduler.schedule_projects([p1]) self.assertEqual(util.nov15, p1.est_end_date) return
def data_to_projects(connection, data): result = [] for row in data: p = Project(row['id']) p.name = row['name'] p.target_date = dovetail.util.condition_date(row['target_date']) p.est_start_date = dovetail.util.condition_date(row['est_start_date']) p.est_end_date = dovetail.util.condition_date(row['est_end_date']) p.value = row['value'] p.work = work_db.select_work_for_project(connection, row['id']) p.key_work = work_db.select_key_work_for_project(connection, row['id']) result.append(p) return result
def test_sort_work(self): # Assignees person_id1 = 101 person_id2 = 102 person_id3 = 103 # Projects p1 = Project(1) p1_w1 = construct_work(1, "p1 w1", 1.0, [6], person_id1, None) p1_w2 = construct_work(2, "p1 w2", 1.0, [], person_id1, None) p1_w3 = construct_work(5, "p1 w3", 0.1, [2, 1], person_id1, None) p1_w4 = construct_work(6, "p1 w4", 0.1, [], person_id1, None) p1.work = [p1_w1, p1_w2, p1_w3, p1_w4] p1.topo_sort_work() self.assertTrue(p1.work.index(p1_w1) < p1.work.index(p1_w3)) self.assertTrue(p1.work.index(p1_w4) < p1.work.index(p1_w1)) return
def select_project(connection, project_id): result = Project(project_id) data = connection.execute( database.projects.select( database.projects.c.id == project_id)).first() result.name = data['name'] # NOTE: We don't need to condition them because we're not doing an explicit select # SqlAlchemy takes care of the date manipulation for us result.target_date = data['target_date'] result.est_end_date = data['est_end_date'] result.participants = people_db.select_project_participants( connection, project_id) result.work = work_db.select_work_for_project(connection, project_id) return result
def edit_project(project_id): name = request.values['name'] target_date = dovetail.util.parse_date(request.values['target_date']) worklines = request.values['worklines'].split('\n') original_work_ids = set(json.loads(request.values['original_work_ids'])) work = [] for workline in worklines: try: work_data = projects_util.parse_workline(g.connection, workline) fields = work_data['fields'] fields.update(project_id=project_id) # Save any changes to the work items # TOOD: Separate topo sort work so we only have to write to database once work_db.update_work(g.connection, work_data) fields.update(id=work_data['id']) work.append(work_db.fields_to_work_object(fields)) except: # TODO: log something pass # Mark missing work as done returned_work_ids = set([w.work_id for w in work]) done_work_ids = original_work_ids - returned_work_ids work_db.mark_work_done(g.connection, done_work_ids) project = Project(project_id) project.name = name project.target_date = target_date project.work = work project.topo_sort_work() work_db.update_work_topo_order(g.connection, project.work) #dovetail.scheduler.reschedule_world(g.connection) # Update project info projects_db.update_project(g.connection, project) response_data = {} result = Response(json.dumps(response_data), status=200, mimetype='application/json') return result
def edit_project(project_id): name = request.values['name'] target_date = dovetail.util.parse_date(request.values['target_date']) worklines = request.values['worklines'].split('\n') original_work_ids = set(json.loads(request.values['original_work_ids'])) work = [] for workline in worklines: try: work_data = projects_util.parse_workline(g.connection, workline) fields = work_data['fields'] fields.update(project_id = project_id) # Save any changes to the work items # TOOD: Separate topo sort work so we only have to write to database once work_db.update_work(g.connection, work_data) fields.update(id = work_data['id']) work.append(work_db.fields_to_work_object(fields)) except: # TODO: log something pass # Mark missing work as done returned_work_ids = set([w.work_id for w in work]) done_work_ids = original_work_ids - returned_work_ids work_db.mark_work_done(g.connection, done_work_ids) project = Project(project_id) project.name = name project.target_date = target_date project.work = work project.topo_sort_work() work_db.update_work_topo_order(g.connection, project.work) #dovetail.scheduler.reschedule_world(g.connection) # Update project info projects_db.update_project(g.connection, project) response_data = {} result = Response(json.dumps(response_data), status=200, mimetype='application/json') return result
def parse_project_line(line, value): parts = line.split() result = Project(parts[0]) result.value = value return result