def load_database(): ''' Initialize all objects stored in data/.. Close program if there is not enough database to function properly. Parameters, Returns: None Initialize: Student objs. Mentor objs. Employee objs. Manager objs. Assigments objs. Logins.list_of_logins ''' Assignment.get_assignments_from_file('assignments.csv') Attendance.get_attendance_from_file('attendance.csv') Student.get_codecoolers_from_file('students.csv') Employee.get_codecoolers_from_file('employees.csv') Mentor.get_codecoolers_from_file('mentors.csv') Manager.get_codecoolers_from_file('managers.csv') if len(Manager.list_of_managers) < 1 or len( Employee.list_of_employees) < 1: err_msg = 'There is no database stored. Contact our support at [email protected]' view.print_message(err_msg) sys.exit() Logins.from_codecoolers(Student.list_of_students, Employee.list_of_employees, Manager.list_of_managers, Mentor.list_of_mentors)
def delete(self): website = Manager(Website).get(pk=self.kwargs["pk"]) if website.customer.pk != self.customer.pk: return self.response({"error": "Not allowed"}) website.delete() return self.response({"deleted": "website deleted"})
def change_password(user): ''' Change old password to new. Save changes. Args: user - object ''' codecooler_controller.change_password(user) Manager.save_codecoolers_to_file('managers.csv', Manager.list_of_managers)
def train_cafe(): voca = load_voca() args.char_vocab_size = load_char_length() model = Manager(max_sequence=100, word_indice=voca, batch_size=args.batch_size, num_classes=3, vocab_size=1000, embedding_size=300, lstm_dim=1024) data = models.common.load_pickle("train_corpus.pickle") validate = models.common.load_pickle("dev_corpus") epochs = 30 model.train(epochs, data, validate)
def patch(self, data): website = Manager(Website).get(pk=self.kwargs["pk"]) if website.customer.pk != self.customer.pk: return self.response({"error": "Not allowed"}) if "url" not in data: return self.response({"error": "missing website url"}) website.url = data["url"] website.save() return self.response({"success": "website updated"})
def router(path: str, token): view = _get_view(path) if view.login_required: try: token = Manager(Token).get(token=token) except DoesNotExistsError: raise UnauthenticatedError() customer = Manager(Customer).get(pk=token.customer) view.customer = customer return view
def test_get(self): self.TestModel(test_field="instance1").save() self.TestModel(test_field="instance2").save() result = Manager(self.TestModel).get(test_field="instance1") self.assertIsInstance(result, self.TestModel) self.assertEqual(result.test_field, "instance1")
def post(self, data): if not self.customer.has_valid_subscription(): return self.response({"error": "no valid subscription"}) plan = Manager(Plan).get(pk=self.customer.plan) websites = Manager(Website).filter(customer=self.customer) if len(websites) >= int(plan.number_of_websites): return self.response( {"error": "maximum number of websites for your plan"}) if "url" not in data: return self.response({"error": "missing website url"}) website = Website(url=data["url"], customer=self.customer.pk) website.save() return self.response({"website": website.pk})
def test_success(self): data = {"name": "name", "password": "******", "email": "email"} view = RegisterView() response = view.post(data).decode("utf-8") response = json.loads(response) self.assertTrue("uid" in response) Manager(Customer).get(pk=response["uid"])
def post(self, data): password = data.get("password", "") customer: Customer = Manager(Customer).get(email=self.kwargs["email"]) if customer.verify_password(password): token = Token(customer=customer.pk, token=str(uuid4())) token.save() return self.response({"token": token.token}) else: return self.response({"error": "Invalid password"})
def setUp(self): self.manager = Manager() self.allocation = self.manager.allocation() self.manager.space_placing() self.manager.allocation() self.spaces = self.manager.list_spaces() self.office = OfficeSpace self.room = LivingSpace self.tongs = self.office('TONGS', 'OFFICE', 'STAFF') self.iroko = self.room('IROKO', 'ROOM', 'FEMALE')
def test_filter(self): self.TestModel(test_field="instance1").save() self.TestModel(test_field="instance2").save() self.TestModel(test_field="instance2").save() results = Manager(self.TestModel).filter(test_field="instance2") self.assertEqual(2, len(results)) for x in results: self.assertIsInstance(x, self.TestModel)
def test_login(self): password = "******" self.customer.set_password(password) self.customer.save() view = LoginView(email=self.customer.email) response = view.post({"password": password}).decode("utf-8") response = json.loads(response) self.assertTrue("token" in response) token = Manager(Token).get(token=response["token"]) self.assertEqual(token.customer, self.customer.pk)
def make_user(type, name, surname, middle_name, password=None, worker_type=None, login=None, ean13=None): if type == UserType.MANAGER: if not login or not password: return None user = User() user.type = UserType.MANAGER user.name = name user.surname = surname user.middle_name = middle_name user.manager = Manager() user.manager.login = login user.manager.password = (hashlib.sha256( (password + config['secure']['salt_password']).encode()).hexdigest()) user.manager.save() user.save() user.db_session.commit() print('Created manager {0} {1} with login {2}.'.format( name, surname, login)) return user else: if not ean13 or not worker_type: return None user = User() user.type = UserType.WORKER user.name = name user.surname = surname user.middle_name = middle_name user.worker = Worker() user.worker.type = worker_type user.worker.ean13 = ean13 user.worker.password = Worker.generate_worker_password() user.worker.save() user.save() user.db_session().commit() print('Created {0} {1} {2} with ean13 {3}.'.format( worker_type.name.swapcase(), name, surname, ean13)) return user
def test_save(self): with tempfile.TemporaryDirectory() as tmpdir: settings.data_dir = Path(tmpdir) value = "test4321" model = self.TestModel(test_field=value) model.save() pk = model.pk loader.clear_cache() self.assertEqual(loader.data, {}) loaded_model = Manager(self.TestModel).get(pk=pk) self.assertEqual(loaded_model.test_field, value)
class TestManager(unittest.TestCase): """Unittest for manager""" def setUp(self): self.manager = Manager() self.allocation = self.manager.allocation() self.manager.space_placing() self.manager.allocation() self.spaces = self.manager.list_spaces() self.office = OfficeSpace self.room = LivingSpace self.tongs = self.office('TONGS', 'OFFICE', 'STAFF') self.iroko = self.room('IROKO', 'ROOM', 'FEMALE') def test_that_office_spaces_can_be_created(self): self.assertIsInstance(self.tongs, self.office) self.assertEqual(self.tongs.space_type, 'OFFICE') self.assertEqual(self.tongs.occupant_type, 'STAFF') def test_that_living_spaces_can_be_created(self): self.assertIsInstance(self.iroko, self.room) self.assertEqual(self.iroko.space_type, 'ROOM') self.assertEqual(self.iroko.occupant_type, 'FEMALE') def test_that_spaces_are_available(self): self.assertTrue(self.spaces)
def test_delete(self): with tempfile.TemporaryDirectory() as tmpdir: settings.data_dir = Path(tmpdir) value = "test4321" model = self.TestModel(test_field=value) model.save() pk = model.pk model.delete() loader.clear_cache() self.assertEqual(loader.data, {}) with self.assertRaises(DoesNotExistsError): Manager(self.TestModel).get(pk=pk)
def run_adverserial(): voca = load_voca() manager = Manager(max_sequence=100, word_indice=voca, batch_size=args.batch_size, num_classes=3, vocab_size=1000, embedding_size=300, lstm_dim=1024) # Dev acc=0.6576999819278717 loss=0.8433943867683411 # manager.load("hdrop2/model-41418") manager.load("hdrop/model-42952") manager.run_adverserial(voca)
def testSoftmax(): conf = SoftmaxConfig() conf.EPOCH = 20 conf.SAVE_PER_EPOCH = 5 cifar10 = CIFAR10('data/') manager = Manager(conf, cifar10, softmax) manager.compile() manager.training()
def testGoogLeNet(): conf = GoogLeNetConfig() conf.EPOCH = 100 conf.SAVE_PER_EPOCH = 10 conf.LEARNING_RATE = 1e-2 cifar10 = CIFAR10('data/') manager = Manager(conf, cifar10, googlenet) manager.compile() manager.training()
def view_weights(): voca = load_voca() manager = Manager(max_sequence=100, word_indice=voca, batch_size=args.batch_size, num_classes=3, vocab_size=1000, embedding_size=300, lstm_dim=1024) # Dev acc=0.6576999819278717 loss=0.8433943867683411 manager.load("wattention/model-12272") validate = models.common.load_pickle("dev_corpus") manager.view_weights(validate)
def lrp_run(): voca = load_voca() manager = Manager(max_sequence=100, word_indice=voca, batch_size=args.batch_size, num_classes=3, vocab_size=1000, embedding_size=300, lstm_dim=1024) # Dev acc=0.6576999819278717 loss=0.8433943867683411 manager.load("hdrop2/model-41418") validate = models.common.load_pickle("dev_corpus") # manager.view_lrp(validate, reverse_index(voca)) # manager.lrp_3way(validate, reverse_index(voca)) manager.lrp_entangle(validate, models.common.reverse_index(voca))
def train_keep_cafe(): voca = load_voca() manager = Manager(max_sequence=100, word_indice=voca, batch_size=args.batch_size, num_classes=3, vocab_size=1000, embedding_size=300, lstm_dim=1024) # Dev acc=0.6576999819278717 loss=0.8433943867683411 data = models.common.load_pickle("train_corpus.pickle") validate = models.common.load_pickle("dev_corpus") manager.load("model-15340") manager.train(20, data, validate, True)
def post(self, data): if verify_payment(data["payment_token"]): plan_pk = data["plan"] try: Manager(Plan).get(pk=plan_pk) except DoesNotExistsError: return self.response({"error": "Plan does not exist"}) self.customer.plan = plan_pk today = dt.date.today() ends = dt.date(year=today.year + 1, month=today.month, day=today.day) self.customer.subscription = ends.strftime("%Y/%m/%d") self.customer.save() return self.response({"success": "subscribed"}) else: return self.response({"error": "payment failed"})
def save_managerdata(id): the_document = Employee.query.filter( Employee.id == id).order_by("id desc").first() reply = request.form.get('reply') manager_form = Manager( reply=reply, emp_table_id=the_document.id, IP_addr=request.remote_addr, Location=request.form.get('location'), UserAgent=request.user_agent.browser, OperatingSystem=request.user_agent.platform, Time=datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"), ) db.session.add(manager_form) db.session.commit() utils.send_manager_link_as_mail( email=email, emp_code1=emp_code1, ) return redirect('/success')
def post(self, data): try: name = data["name"] password = data["password"] email = data["email"] subscription = None plan = None except KeyError: return self.response({"error": "Missing required data"}) if any(Manager(Customer).filter(email=email)): return self.response({"error": "Email already in use"}) customer = Customer( name=name, password=password, email=email, subscription=subscription, plan=plan, ) customer.set_password(password) customer.save() return self.response({"uid": customer.pk})
def save_data(): emp_code = request.form.get('emp_code') rev_emp_code = request.form.get('rev_emp_code') emp_name = request.form.get('emp_name') emp_email = request.form.get('emp_email') reviewer_email = request.form.get('reviewer_email') department = request.form.get('department') period_of_review = request.form.get('period_of_review') reviewer = request.form.get('reviewer') reviewers_title = request.form.get('reviewers_title') job_Knowledge = request.form.get('job_Knowledge') productivity = request.form.get('productivity') work_quality = request.form.get('work_quality') technical_skills = request.form.get('technical_skills') work_consistency = request.form.get('work_consistency') enthusiasm = request.form.get('enthusiasm') cooperation = request.form.get('cooperation') attitude = request.form.get('attitude') initiative = request.form.get('initiative') work_relations = request.form.get('work_relations') creativity = request.form.get('creativity') punctuality = request.form.get('punctuality') attendance = request.form.get('attendance') dependability = request.form.get('dependability') communication_skills = request.form.get('communication_skills') overall_rating = request.form.get('overall_rating') opportunities = request.form.get('opportunities') reviewers_comments = request.form.get('reviewers_comments') job_Knowledge_comments = request.form.get('job_Knowledge_comments') productivity_comments = request.form.get('productivity_comments') work_quality_comments = request.form.get('work_quality_comments') technical_skills_comments = request.form.get('technical_skills_comments') work_consistency_comments = request.form.get('work_consistency_comments') enthusiasm_comments = request.form.get('enthusiasm_comments') cooperation_comments = request.form.get('cooperation_comments') attitude_comments = request.form.get('attitude_comments') initiative_comments = request.form.get('initiative_comments') work_relations_comments = request.form.get('work_relations_comments') creativity_comments = request.form.get('creativity_comments') punctuality_comments = request.form.get('punctuality_comments') attendance_comments = request.form.get('attendance_comments') dependability_comments = request.form.get('dependability_comments') communication_skills_comments = request.form.get( 'communication_skills_comments') overall_rating_comments = request.form.get('overall_rating_comments') signature = save_signature(request.form.get('signature'), request.form.get('reviewer'), 'signature') date = request.form.get('date') date1 = request.form.get('date1') manager_form = Manager( emp_code=emp_code, rev_emp_code=rev_emp_code, emp_name=emp_name, emp_email=emp_email, reviewer_email=reviewer_email, department=department, period_of_review=period_of_review, reviewer=reviewer, reviewers_title=reviewers_title, job_Knowledge=job_Knowledge, productivity=productivity, work_quality=work_quality, technical_skills=technical_skills, work_consistency=work_consistency, enthusiasm=enthusiasm, cooperation=cooperation, attitude=attitude, initiative=initiative, work_relations=work_relations, creativity=creativity, punctuality=punctuality, attendance=attendance, dependability=dependability, communication_skills=communication_skills, overall_rating=overall_rating, opportunities=opportunities, reviewers_comments=reviewers_comments, job_Knowledge_comments=job_Knowledge_comments, productivity_comments=productivity_comments, work_quality_comments=work_quality_comments, technical_skills_comments=technical_skills_comments, work_consistency_comments=work_consistency_comments, enthusiasm_comments=enthusiasm_comments, cooperation_comments=cooperation_comments, attitude_comments=attitude_comments, initiative_comments=initiative_comments, work_relations_comments=work_relations_comments, creativity_comments=creativity_comments, punctuality_comments=punctuality_comments, attendance_comments=attendance_comments, dependability_comments=dependability_comments, communication_skills_comments=communication_skills_comments, overall_rating_comments=overall_rating_comments, date=date, date1=date1, IP_addr=request.remote_addr, Location=request.form.get('location'), UserAgent=request.user_agent.browser, OperatingSystem=request.user_agent.platform, Time=datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"), signaturepath=signature) db.session.add(manager_form) db.session.commit() utils.send_link_as_mail(emp_name=emp_name, reviewer_email=reviewer_email, emp_email=emp_email, rev_emp_code=rev_emp_code, emp_code=emp_code) return redirect('/success')
def save_managerdata(): emp_code1 = request.form.get('emp_code1') reviewer_name1 = request.form.get('reviewer_name1') reviewer_code1 = request.form.get('reviewer_code1') manager_assessment1 = request.form.get('manager_assessment1') manager_assessment1_comment1 = request.form.get( 'manager_assessment1_comment1') total_score1 = request.form.get('total_score1') achieved_score1 = request.form.get('achieved_score1') manager_assessment2 = request.form.get('manager_assessment2') manager_assessment2_comment2 = request.form.get( 'manager_assessment2_comment2') total_score2 = request.form.get('total_score2') achieved_score2 = request.form.get('achieved_score2') manager_assessment3 = request.form.get('manager_assessment3') manager_assessment3_comment3 = request.form.get( 'manager_assessment3_comment3') total_score3 = request.form.get('total_score3') achieved_score3 = request.form.get('achieved_score3') manager_assessment4 = request.form.get('manager_assessment4') manager_assessment4_comment4 = request.form.get( 'manager_assessment4_comment4') total_score4 = request.form.get('total_score4') achieved_score4 = request.form.get('achieved_score4') manager_assessment5 = request.form.get('manager_assessment5') manager_assessment5_comment5 = request.form.get( 'manager_assessment5_comment5') total_score5 = request.form.get('total_score5') achieved_score5 = request.form.get('achieved_score5') manager_assessment6 = request.form.get('manager_assessment6') manager_assessment6_comment6 = request.form.get( 'manager_assessment6_comment6') total_score6 = request.form.get('total_score6') achieved_score6 = request.form.get('achieved_score6') rev_email1 = request.form.get('rev_email1') manager_form = Manager( emp_code1=emp_code1, reviewer_name1=reviewer_name1, reviewer_code1=reviewer_code1, manager_assessment1=manager_assessment1, manager_assessment1_comment1=manager_assessment1_comment1, total_score1=total_score1, achieved_score1=achieved_score1, manager_assessment2=manager_assessment2, manager_assessment2_comment2=manager_assessment2_comment2, total_score2=total_score2, achieved_score2=achieved_score2, manager_assessment3=manager_assessment3, manager_assessment3_comment3=manager_assessment3_comment3, total_score3=total_score3, achieved_score3=achieved_score3, manager_assessment4=manager_assessment4, manager_assessment4_comment4=manager_assessment4_comment4, total_score4=total_score4, achieved_score4=achieved_score4, manager_assessment5=manager_assessment5, manager_assessment5_comment5=manager_assessment5_comment5, total_score5=total_score5, achieved_score5=achieved_score5, manager_assessment6=manager_assessment6, manager_assessment6_comment6=manager_assessment6_comment6, total_score6=total_score6, achieved_score6=achieved_score6, IP_addr=request.remote_addr, Location=request.form.get('location'), UserAgent=request.user_agent.browser, OperatingSystem=request.user_agent.platform, Time=datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"), ) db.session.add(manager_form) db.session.commit() utils.send_manager_link_as_mail( rev_email1=rev_email1, reviewer_code1=reviewer_code1, emp_code1=emp_code1, ) return redirect('/success')
async def main(): manager = Manager() # Examples # Hotkey "alt+1": Left click 3 times (initial click + 2 repeat clicks) which should select the whole line for i in range(1, 6): manager.add_hotkey( f"alt+{i}", MouseCommand(mouse_action=MouseAction( manager, mouse_actions=[MouseInfo(click=Click.Left)], start_delay=1000, repeat_amount=2**(2 + i) - 1, ), ), ) # Hold down key F for 10 seconds manager.add_hotkey( "alt+f", KeyboardCommand( # TODO Simplify so that i dont hafve to pass 'manager' as parameter keyboard_action=KeyboardAction( manager, hotkeys_to_press=[KeyInfo("f", duration=10000)], start_delay=1000), ), ) # Hold down key F for 30 seconds manager.add_hotkey( "alt+g", KeyboardCommand( # TODO Simplify so that i dont hafve to pass 'manager' as parameter keyboard_action=KeyboardAction( manager, hotkeys_to_press=[KeyInfo("f", duration=30000)], start_delay=1000), ), ) # Press hotkey E 20 times manager.add_hotkey( "alt+e", KeyboardCommand( # TODO Simplify so that i dont hafve to pass 'manager' as parameter keyboard_action=KeyboardAction(manager, hotkeys_to_press=[KeyInfo("e")], start_delay=1000, repeat_amount=19), ), ) # Hotkey: "hello": Write text " whats up buddy" with 1 second delay after you typed the word "hello" # hotkey_text = "hello" # manager.add_hotkey( # ",".join(hotkey_text), # KeyboardCommand( # # TODO Simplify so that i dont have to pass 'manager' as parameter # keyboard_action=KeyboardAction( # manager, hotkeys_to_press=KeyInfo.from_text(" whats up buddy", key_delay=0), start_delay=1000 # ), # ), # ) # Pressing escape will terminate this script # Can also be "async def my_exit()" def my_exit(): logger.info(f"Ending program, escape was pressed!") manager.exit = True manager.add_hotkey( "alt+q", ScriptCommand(functions=[my_exit], start_delay=0), ) logger.info(f"Hotkey manager started") await manager.run()
def test_not_existing_pk(self): instance = self.TestModel(test_field="instance1") instance.save() with self.assertRaises(DoesNotExistsError): Manager(self.TestModel).get(pk=instance.pk + "l")
def initialize(self): self._manager = Manager.instance()
from repo.reports_generator import ReportsGenerator from repo.reports.html_generator import HTMLGenerator from repo.reports.markdown_generator import MarkdownGenerator from repo.reports.writer import ReportWriter from models.member import Member from models.manager import Manager if __name__ == '__main__': username = '******' response = GithubCliient.get_repos_by_user(username) if response['status_code'] == 200: repos = RepoParser.parse(response['body']) markdown_report = ReportsGenerator.build(MarkdownGenerator, repos) html_report = ReportsGenerator.build(HTMLGenerator, repos) ReportWriter.write(markdown_report) print(html_report) print(markdown_report) else: print(response['body']) member = Member('rafaelcamarda', '*****@*****.**') manager = Manager('manager', '*****@*****.**') print(member.members()) print(member.work()) print(manager.work())
""" All allocation results. """ from models.manager import Manager manager = Manager() manager.space_placing() spaces = manager.list_spaces() manager.allocation() class Allocations(object): def get_allocated_fellows(self): """Return of spaces populated with fellows and staff""" print "All allocated fellows and staff are as follows" for index in range(len(spaces)-1): if spaces[index].space_type == 'OFFICE': print spaces[index], "- OFFICE" print spaces[index].list_people() elif spaces[index].occupant_type == 'MALE': print spaces[index], "- MALE ROOM" print spaces[index].list_people() elif spaces[index].occupant_type == 'FEMALE': print spaces[index], "- FEMALE ROOM" print spaces[index].list_people() def get_unallocated_fellows(self): """Return unallocated fellows""" print "All unallocated staff are as follows:"