def requirement(self): user = users.get_current_user() if user: operation = self.request.get('operation', default_value=None) if operation == 'create': project_key = ndb.Key(urlsafe=self.request.get('project-key')) new_requirement_id = str( int(Requirement.max_id(project_key)) + 1) requirement = Requirement(parent=project_key, author=user, id=new_requirement_id, title=None, content=None) elif operation == 'edit': requirement_key = ndb.Key( urlsafe=self.request.get('requirement-key')) #project_key = requirement_key.parent() requirement = requirement_key.get() #html = self.render_str("dynamic/requirement.body.html", project = project_key.get(), requirement = requirement) html = self.render_str("dynamic/requirement.body.html", requirement=requirement) dict = { 'id': requirement.id, 'title': requirement.title, 'content': requirement.content, 'html': html } else: dict = {'message': 'please log in'} self.response.write(json.dumps(dict))
def update_requirements(**kwargs): #print(kwargs) for requirement in select_requirements(**{key : kwargs[key] for key in kwargs if kwargs[key] and key not in ['set_name', 'expansions', 'excesses']}): if 'set_name' in kwargs and kwargs['set_name']: requirement.name = kwargs['set_name'] #print(kwargs) if 'expansions' in kwargs and kwargs['expansions']: #print(kwargs) for specialization in kwargs['expansions'].split(ID_DELIMITER): id, quantity = specialization.split(REQ_COMPONENT_DELIMITER) parced_id = Requirement.specialization_id_to_neo4j_format(id) remove_requirement_fragment(requirement, parced_id) #print({'ident' : Requirement.specialization_id_to_neo4j_format(id), 'quantity' : int(quantity)}) requirement.content.append({'ident' : parced_id, 'quantity' : int(quantity)}) if 'excesses' in kwargs and kwargs['excesses']: #print(kwargs) for specialization_id in kwargs['excesses'].split(ID_DELIMITER): remove_requirement_fragment(requirement, Requirement.specialization_id_to_neo4j_format(specialization_id)) requirement.save()
def test_task(self): delete_db.delete_data_in_db() user = self.create_user_and_login() project = Project(user.get_cookie(), user.get_user_id(),"1") project.create_project() req = Requirement(user.get_cookie(), project.get_id()) req.add_req(project.get_id()) task = Task(user.get_cookie(), req.get_id()) task.add_task() task.update_task() task.get_task() task.get_all_task() task.delete_task()
def test_task(self): delete_db.delete_data_in_db() user = self.create_user_and_login() project = Project(user.get_cookie(), user.get_user_id(), "1") project.create_project() req = Requirement(user.get_cookie(), project.get_id()) req.add_req(project.get_id()) task = Task(user.get_cookie(), req.get_id()) task.add_task() task.update_task() task.get_task() task.get_all_task() task.delete_task()
def tasks(self, project_urlString): user = users.get_current_user() if user: project_key = ndb.Key(urlsafe=project_urlString) project = project_key.get() requirement_container_list = [] for requirement in Requirement.all(project.key): requirement_container = RequirementContainer( requirement=requirement, userstories=[]) for userstory in UserStory.all(requirement.key): requirement_container.userstories.append( UserStoryContainer(userstory=userstory, tasks=Task.all(userstory.key))) requirement_container_list.append(requirement_container) html = self.render_str( "dynamic/tasks.body.html", project=project, requirement_container_list=requirement_container_list) dict = {'content': html} else: dict = {"message": "please log in"} self.response.write(json.dumps(dict))
def tasks_old(self, project_urlString): user = users.get_current_user() if user: project_key = ndb.Key(urlsafe=project_urlString) project = project_key.get() requirements = Requirement.all(project.key) userstory_titles = {} tasks = [] for requirement in requirements: userstories = UserStory.all(requirement.key) for userstory in userstories: some_tasks = Task.all(userstory.key) for task in some_tasks: userstory_titles[task.key.id()] = userstory.title tasks += some_tasks html = self.render_str("dynamic/tasks.body.html", project=project, userstory_titles=userstory_titles, tasks=tasks) requirement_dict = {'content': html} self.response.write(json.dumps(requirement_dict)) else: self.response.write('{ "message": "please log in" }')
def make_schedule(requirements, taken_courses=[], max_credits=15): """Given a list of required course CRN's (or requirements), and taken course CRN's return a list of courses to take or False if it's not possible""" # Turn non-requirements into requirements for i, item in enumerate(requirements): if isinstance(item, basestring): requirements[i] = Requirement([item]) # Remove taken courses from required courses requirements = [ item for item in requirements if not item.satisfied(taken_courses) ] # Sort required by the number of courses offered (fewer courses offered = more constrained) sorted(requirements, cmp=lambda a, b: a.get_worst_crn() < b.get_worst_crn()) print "requirements: ", requirements print "taken_courses: ", taken_courses def __make_schedule(requirements, current_schedule): if len(requirements) == 0: return current_schedule requirement = requirements[0] requirements = requirements[1:] for course in requirement.valid_courses: if len(Course.get_all_by_crn(course)) == 0: raise Exception("No class in catalog; %s" % course) for c in Course.get_all_by_crn(course): # Check to see if this course conflicts with anything conflicts = False for c2 in current_schedule: if c.timeslot.conflicts(c2.timeslot): conflicts = True break if not conflicts: # Make sure we can take it, then recurse schedule = [] if not c.can_take(current_schedule, credit_hour_limit=max_credits): schedule = __make_schedule(requirements, current_schedule) if schedule == False: continue # If we still can't take it, continue if not c.can_take(schedule, credit_hour_limit=max_credits): continue schedule += [c] else: schedule = __make_schedule(requirements, current_schedule + [c]) if schedule != False: return schedule return False return __make_schedule(requirements, [])
def parse_requirements(self, signature, offset): prev = self.f.tell() true_offset = signature.offset + offset self.f.seek(true_offset) magic = get_int(self.f) if magic != dictionary.signatures['REQUIREMENTS']: data = { 'offset': true_offset, 'magic': hex(magic), 'expected': hex(dictionary.signatures['REQUIREMENTS']) } a = Abnormality(title='BAD MAGIC - REQUIREMENTS', data=data) self.add_abnormality(a) self.f.seek(prev) return # Skip size self.f.read(4) count = get_int(self.f) while count > 0: req_type = dictionary.requirements[get_int(self.f)] offset = get_int(self.f) requirement = Requirement(req_type=req_type, offset=offset) self.parse_requirement(requirement, true_offset) signature.add_requirement(requirement) count -= 1 self.f.seek(prev)
def create_requirement(name, content): requirement_parts = [] for requirement_str_part in content.split(ID_DELIMITER): specialization, quantity = requirement_str_part.split( REQ_COMPONENT_DELIMITER) requirement_parts.append({ 'ident': specialization, 'quantity': quantity }) return Requirement(name=name, content=requirement_parts).save()
def get(self, project_urlString): user = users.get_current_user() if user: project_key = ndb.Key(urlsafe = project_urlString) project = project_key.get() requirements = Requirement.all(project.key) html_text = self.render_str("dynamic/requirements.body.html", project = project, requirements = requirements) requirement_dict = { 'content': html_text } self.response.write(json.dumps(requirement_dict)) else: self.response.write('{ "message": "please log in" }')
def fillTask(task_source): task = Task() # print("{}".format(task_source["success_requirements"])) # print("=========================================\n{}".format(task_source)) map(lambda req: task.add_success_requirement( Requirement(eval(req))), task_source["success_requirements"]) map(lambda req: task.add_failure_requirement( Requirement(eval(req))), task_source["failure_requirements"]) map(lambda action: task.add_success_action( Action(eval(action))), task_source["success_actions"]) map(lambda action: task.add_failure_action( Action(eval(action))), task_source["failure_actions"]) task.title = task_source["title"] if "title" in task_source else "No title" task.id = task_source["id"] if "showOnMonitor" in task_source: task.showOnMonitor = task_source["showOnMonitor"] if "type" in task_source: task.type = task_source["type"] # print("task id: {}".format(task.id)) return task
def __init__(self, task_percept): self.name = task_percept.name self.deadline = task_percept.deadline self.expired = False self.completed = False # Assume tasks only have one required block x = task_percept.requirements[0].pos.x y = task_percept.requirements[0].pos.y # Remove 'b' block_type = int(task_percept.requirements[0].type[1:]) self.requirement = Requirement(x, y, block_type)
def _get_requirements(self, project): user = users.get_current_user() if user: html = "" requirements = Requirement.all(project.key) for requirement in requirements: userstories = self._get_userstories(requirement) html += self.render_str("dynamic/overview.requirement.html", requirement=requirement, userstories=userstories) return html else: return None
def get(self, project_urlString): user = users.get_current_user() if user: project_key = ndb.Key(urlsafe=project_urlString) project = project_key.get() requirements = Requirement.all(project.key) html_text = self.render_str("dynamic/requirements.body.html", project=project, requirements=requirements) requirement_dict = {'content': html_text} self.response.write(json.dumps(requirement_dict)) else: self.response.write('{ "message": "please log in" }')
def update_requirements(**kwargs): #print(kwargs) for requirement in select_requirements( **{ key: kwargs[key] for key in kwargs if kwargs[key] and key not in ['set_name', 'expansions', 'excesses'] }): if 'set_name' in kwargs and kwargs['set_name']: requirement.name = kwargs['set_name'] #print(kwargs) if 'expansions' in kwargs and kwargs['expansions']: #print(kwargs) for specialization in kwargs['expansions'].split(ID_DELIMITER): id, quantity = specialization.split(REQ_COMPONENT_DELIMITER) parced_id = Requirement.specialization_id_to_neo4j_format(id) remove_requirement_fragment(requirement, parced_id) #print({'ident' : Requirement.specialization_id_to_neo4j_format(id), 'quantity' : int(quantity)}) requirement.content.append({ 'ident': parced_id, 'quantity': int(quantity) }) if 'excesses' in kwargs and kwargs['excesses']: #print(kwargs) for specialization_id in kwargs['excesses'].split(ID_DELIMITER): remove_requirement_fragment( requirement, Requirement.specialization_id_to_neo4j_format( specialization_id)) requirement.save()
def test_project(self): delete_db.delete_data_in_db() user = self.create_user_and_login() user.add_user() project = Project(user.get_cookie(), user.get_user_id(), "1") project.create_project() project.create_project() project.update_project() project.add_dev_to_projects("2") project.get_users_per_project() project.get_users_ranking() project.remove_dev_to_projects() project.get_project() project.get_all_projects_for_user() sprint = Sprint(user.get_cookie(), project.get_id()) sprint.add_sprint() req = Requirement(user.get_cookie(), project.get_id()) req.add_req(project.get_id()) task = Task(user.get_cookie(), req.get_id()) task.add_task() project.get_current_sprint() project.get_progress() project.get_backlog() project.delete_project()
def post(self, id): user = users.get_current_user() if user: #################################################################################################################################################### # #post = Post(parent = Post.post_db_key(), author = user, content = self.request.get("content")) #post.put() #requirement_dict = { 'success': True, 'content': post.content, 'created': post.created.strftime("%d.%m.%Y %H:%M:%S"), 'user': user.nickname() } # #################################################################################################################################################### # #requirement_dict = { 'success': True } #self.response.write(json.dumps(requirement_dict)) # #################################################################################################################################################### # # TODO: hier könnte man das Requirement in der DB checken, ob jemand anderes es schon bearbeitet hat, mit einem Hash oder einem last modified date # oder wie im Wiki oder oder ... Für den Augenblick bleibt's ganz billig. Ich will die Daten eher bei Github im Bugtracker speichern. requirements = Requirement.query(Requirement.id == id).fetch() if len(requirements) > 0: # existing requirement requirement = requirements[0] else: # new requirement project_key = ndb.Key(urlsafe=self.request.get('urlsafe')) requirement = Requirement(parent=project_key, id=id) requirement.author = user requirement.title = self.request.get('title') requirement.content = self.request.get('content') requirement.put() requirement_dict = {'success': True} self.write(json.dumps(requirement_dict)) # #################################################################################################################################################################################################### else: requirement_dict = {'success': False, 'message': 'not logged in'} self.response.write(json.dumps(requirement_dict))
def test_simple_schedule_with_electives(self): ts1 = Timeslot('FA12', { 'M': ['09:00', '11:00'], 'R': ['09:00', '11:00'] }) ts2 = Timeslot('FA13', { 'M': ['09:00', '11:00'], 'R': ['09:00', '11:00'] }) ts3 = Timeslot('FA14', { 'M': ['09:00', '11:00'], 'R': ['09:00', '11:00'] }) ts4 = Timeslot('FA11', { 'M': ['09:00', '11:00'], 'R': ['09:00', '11:00'] }) ts5 = Timeslot('FA11', { 'T': ['09:00', '11:00'], 'F': ['09:00', '11:00'] }) ts6 = Timeslot('FA11', { 'T': ['09:00', '11:00'], 'F': ['09:00', '11:00'] }) c1 = Course("CS101", ts1) c2 = Course("CS201", ts2, ["CS101"]) c3 = Course("CS301", ts3, ["CS201"]) c4 = Course("CS301", ts4, ["CS201"]) c5 = Course("HU101", ts5) c5 = Course("HU102", ts6) schedule = make_schedule( ["CS101", "CS201", "CS301", Requirement(["HU101", "HU102"])], []) self.assertTrue(schedule != False) required_courses = ["CS101", "CS201", "CS301", "HU101"] self.assertEqual(len(schedule), len(required_courses)) for c in schedule: required_courses.remove(c.CRN) self.assertEqual(len(required_courses), 0)
def post(self, id): user = users.get_current_user() if user: #################################################################################################################################################### # #post = Post(parent = Post.post_db_key(), author = user, content = self.request.get("content")) #post.put() #requirement_dict = { 'success': True, 'content': post.content, 'created': post.created.strftime("%d.%m.%Y %H:%M:%S"), 'user': user.nickname() } # #################################################################################################################################################### # #requirement_dict = { 'success': True } #self.response.write(json.dumps(requirement_dict)) # #################################################################################################################################################### # # TODO: hier könnte man das Requirement in der DB checken, ob jemand anderes es schon bearbeitet hat, mit einem Hash oder einem last modified date # oder wie im Wiki oder oder ... Für den Augenblick bleibt's ganz billig. Ich will die Daten eher bei Github im Bugtracker speichern. requirements = Requirement.query(Requirement.id == id).fetch() if len(requirements) > 0: # existing requirement requirement = requirements[0] else: # new requirement project_key = ndb.Key(urlsafe = self.request.get('urlsafe')) requirement = Requirement(parent = project_key, id = id) requirement.author = user requirement.title = self.request.get('title') requirement.content = self.request.get('content') requirement.put() requirement_dict = { 'success': True } self.write(json.dumps(requirement_dict)) # #################################################################################################################################################################################################### else: requirement_dict = { 'success': False, 'message': 'not logged in' } self.response.write(json.dumps(requirement_dict))
def get(self, project_urlString): user = users.get_current_user() if user: project_key = ndb.Key(urlsafe = project_urlString) project = project_key.get() requirements = Requirement.all(project.key) userstory_titles = {} tasks = [] for requirement in requirements: userstories = UserStory.all(requirement.key) for userstory in userstories: some_tasks = Task.all(userstory.key) for task in some_tasks: userstory_titles[task.key.id()] = userstory.title tasks += some_tasks html_text = self.render_str("dynamic/overview.body.html", project = project) requirement_dict = { 'content': html_text } self.response.write(json.dumps(requirement_dict)) else: self.response.write('{ "message": "please log in" }')
#depp.controller.connect(buzz) ##print(Operation.nodes.get()) #oper = Operation(name = 'Kindred').save() #print(oper.start) #print(Operation.nodes.get(ident = '328a0b1d8a784289a4afb33ad70ee5c1').end) #sh = Shift().save() #print(sh.ident) req = Requirement(name='best team', content=[{ "ident": '000000000000000000000002', 'quantity': 100 }, { "ident": '000000000000000000000003', 'quantity': 100 }]).save() print(req.content) #print(req.operations) ''' woody = Person(ident = 2).save() jessie = Person(ident = 3).save() dangerous_operation = Operation().save() buzz.executor.connect(dangerous_operation) woody.executor.connect(dangerous_operation) jessie.head.connect(dangerous_operation) hamm = Person(ident = 4).save()