def makeWidget(): root = Tk() root.title("Простой OPC клиент") app = Application(master=root) app.mainloop() app.opc.client.close() root.destroy()
def thread_import_application_data(lines): for line in lines: username = line[0] college = line[1].strip() status = line[2].capitalize() # find the student by username # find the college by name try: account = Account.objects.get(username=username, type="Student") student = StudentProfile.objects.get(student=account) except DoesNotExist as e: print("Student Doesn't Exist: "+username) continue try: university = College.objects.get(name=college) except Exception as e: # DoesNotExist as e: print(e) print("College Doesn't Exist: "+college) continue verification = "Approved" if (status == "Accepted" and detect_questionable_acceptance(university, student) < 50): verification = "Pending" duplicate = False try: app = Application.objects.get(student=student,college=university) print("Application already exists, moving on") continue except: duplicate = False ID = hash_utils.sha_hash(username+"+=+"+college) app = Application(ID=ID, student=student, college=university, status=status, verification=verification, timestamp=str(time())) try: app.save() except Exception as e: print("There was a problem with this application") print(e) print(line[0]+" "+line[1]) continue
def get_similar_profiles(): # Check if logged in if 'username' not in session or session['username'] is None: return jsonify(status=400, result="Not Logged In") info = request.json if info is None: info = request.form if 'college_name' in info: college_name = info['college_name'] college = None try: college = College.objects.get(name=college_name) except: return jsonify(status=400, result="College Not Found") student = StudentProfile.objects.get(student=Account.objects.get( username=session['username'])) grades = student.grades applications = Application.objects( Q(college=college) & Q(student__ne=student)) students = [] for application in applications: students.append(application.student) def get_score(s): s_grades = s.grades score = 0 if student.gpa not in {None, ''} and s.gpa not in {None, ''}: diff = abs(float(student.gpa) - float(s.gpa)) score += (100 - diff * 75) * .3 if ('sat_math' in grades and 'sat_math' in s_grades and grades['sat_math'] is not None and s_grades['sat_math'] is not None): diff = abs(int(grades['sat_math']) - int(s_grades['sat_math'])) score += (100 - diff / 2) * .15 if ('sat_ebrw' in grades and 'sat_ebrw' in s_grades and grades['sat_ebrw'] is not None and s_grades['sat_ebrw'] is not None): diff = abs(int(grades['sat_ebrw']) - int(s_grades['sat_ebrw'])) score += (100 - diff / 2) * .15 if ('act_composite' in grades and 'act_composite' in grades and grades['act_composite'] is not None and s_grades['act_composite'] is not None): diff = abs( int(grades['act_composite']) - int(s_grades['act_composite'])) score += (100 - diff * (60 / 7)) * .30 return score students.sort(reverse=True, key=get_score) students = students[0:10] profiles = [] for student in students: profile = get_profile_dict(student) profiles.append(profile) return jsonify(status=200, result="OK", profiles=profiles) return jsonify(status=400, result="Missing Fields")
def submit_admission_decision(): # Check if logged in if 'username' not in session or session['username'] is None: return jsonify(status=400, result="Not Logged In") # Get student profile student = StudentProfile.objects.get(student=Account.objects.get( username=session['username'])) info = request.json if info is None: info = request.form if 'college_name' in info and 'status' in info: try: username = session['username'] college_name = info['college_name'] status = info['status'] try: college = College.objects.get(name=college_name) except: return jsonify(status=400, result="College Not Found") application = None try: application = Application.objects.get( Q(student=student) & Q(college=college)) except: print("Application Not Found") application = None verification = "Approved" timestamp = str(time()) if status == "Accepted" and algorithms.detect_questionable_acceptance( college, student) < 50: verification = "Pending" if application is not None: application.update(set__status=status) application.update(set__verification=verification) application.update(set__timestamp=timestamp) return jsonify(status=200, result="OK", verification=verification) else: print("is none") ID = hash_utils.sha_hash(username + "+=+" + college_name) Application(ID=ID, student=student, college=college, status=status, verification=verification, timestamp=timestamp).save() return jsonify(status=200, result="OK", verification=verification) except Exception as e: print(e) return jsonify(status=400, result="Submission Failed") return jsonify(status=400, result="Missing Fields")
def get_questionable_decisions(): if 'username' not in session or session['username'] is None: return jsonify(status=400, result="Not Logged In") if Account.objects.get(username=session['username']).type != "Admin": return jsonify(status=400, result="Unauthorized Access") apps = Application.objects(verification='Pending') data = [] for app in apps: profile = app.student s_data = get_profile_dict(profile) coll = app.college c_data = dict(coll.to_mongo()) del c_data['_id'] del c_data['majors'] # print(c_data) d = {'student': s_data, 'college': c_data, 'timestamp': app.timestamp} data.append(d) return jsonify(status=200, result=data)
def get_admission_decision(): # Check if logged in if 'username' not in session or session['username'] is None: return jsonify(status=400, result="Not Logged In") # Get student profile try: student = StudentProfile.objects.get(student=Account.objects.get( username=session['username'])) applications = Application.objects(student=student) admission_decisions = [] for application in applications: admission = { 'college': application.college.name, 'status': application.status, 'verification': application.verification, } admission_decisions.append(admission) return jsonify(status=200, result="OK", admission_decisions=admission_decisions) except: return jsonify(status=400, result="Get Admission Decisions Failed")
import pygame from classes import Application pygame.init() app = Application('SpaceX', [360, 480], 60) app.run()
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Python Project Manager v1.3.0 # # # # Copyright 2016, PedroHenriques # # http://www.pedrojhenriques.com # # https://github.com/PedroHenriques # # # # Free to use under the MIT license. # # http://www.opensource.org/licenses/mit-license.php # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # import traceback, os from classes import Application # code that starts the entire application try: # instantiate the application's main class app = Application.Application( os.path.dirname(os.path.realpath(__file__)) + "\\data") except Exception as e: traceback.print_exc() print("\n")
def setup_sim(sim_param): # Create Job Profiles num_app_types = sim_param.num_apps low_mean = sim_param.low_mean_jobs high_mean = sim_param.high_mean_jobs lt = sim_param.latency_threshold job_profiles = [] for i in range(num_app_types): job_profiles += [ Job_Profile(job_name=str(i), latency_req=np.random.randint(lt[0], lt[1]), offload_mean=np.random.uniform(low_mean, high_mean)) ] # System physical Boundaries - All action takes within this boundaries = np.array([[0, sim_param.x_length], [0, sim_param.y_length]]) # Generate Servers num_resource = 1 weak_range = sim_param.server_weak_range strong_range = sim_param.server_strong_range # Generate Server servers = [] idx_counter = 0 for i in range(sim_param.num_servers): servers.append(Server(boundaries, level=2, rand_locs=True, locs=None)) servers[-1].server_resources(num_resource, weak_range, strong_range) servers[-1].assign_id(idx_counter) idx_counter += 1 # Generate Users users = [] idx_counter = 0 for i in range(sim_param.num_users): users += [ User(boundaries, sim_param.big_ts, 2, sim_param.user_lamdas, sim_param.user_max_speed) ] users[-1].generate_MC(servers) users[-1].assign_id(idx_counter) idx_counter += 1 # Generate Apps num_apps = len(users) app_id = np.random.choice(num_app_types, num_apps) apps = [] for i in range(len(app_id)): apps += [ Application(job_type=app_id[i], user_id=i, time_steps=sim_param.big_ts, job_profiles=job_profiles, mode=sim_param.app_mode, dist_n=sim_param.dist_n, dist_p=sim_param.dist_p, user=users[i], ts_big=sim_param.big_ts, ts_small=sim_param.small_ts) ] # Generate Containers - in dictionary indexed by {(server,app)} containers = {} for s in range(len(servers)): for a in range(num_app_types): service_rate = np.random.uniform(sim_param.container_service_low, sim_param.container_service_high) latency_restriction = job_profiles[a].latency_req containers[(s, a)] = Container(a, s, service_rate, latency_restriction) return servers, users, containers, apps
def track_applications_plot(): # Check if logged in if 'username' not in session or session['username'] is None: return jsonify(status=400, result="Not Logged In") info = request.json if info is None: info = request.form if 'college_name' in info and 'test_type' in info: college_name = info['college_name'] college = None try: college = College.objects.get(name=college_name) except: return jsonify(status=400, result="College Not Found") applications = Application.objects( Q(college=college) & Q(verification="Approved")) test_type = info['test_type'] coordinates = [] for application in applications: application_status = application.status student = application.student if not track_applications_filter(info, application, student): continue grades = student.grades test_score = None if test_type == "SAT": if ('sat_math' in grades and grades['sat_math'] not in {None, ""} and 'sat_ebrw' in grades and grades['sat_ebrw'] not in {None, ""}): test_score = int(grades['sat_math']) + int( grades['sat_ebrw']) if test_type == "ACT": if 'act_composite' in grades and grades[ 'act_composite'] not in {None, ""}: test_score = int(grades['act_composite']) if test_type == "SAT_ACT": test_count = 0 total = 0 if ('sat_math' in grades and grades['sat_math'] not in {None, ""} and 'sat_ebrw' in grades and grades['sat_ebrw'] not in {None, ""}): test_count += 1 total += (int(grades['sat_math']) + int(grades['sat_ebrw'])) if ('act_composite' in grades and grades['act_composite'] not in {None, ""}): test_count += 1 adjusted = 400 + round( (int(grades['act_composite']) - 1) * (240 / 7), -1) total += adjusted if not test_count: continue remainder = total / test_count weighted_subjects = 0 remaining_weight = 1.0 for field in grades: if ('sat_' in field and field not in {'sat_math', 'sat_ebrw'}): if grades[field] not in {None, ""}: weighted_subjects += int(grades[field]) * 0.1 remaining_weight -= 0.05 test_score = weighted_subjects + remainder * remaining_weight if test_score is None: continue coordinate = { 'x': test_score, 'y': student.gpa, 'status': application_status } coordinates.append(coordinate) return jsonify(status=200, result="OK", coordinates=coordinates) return jsonify(status=400, result="Missing Fields")
def track_applications_list(): # Check if logged in if 'username' not in session or session['username'] is None: return jsonify(status=400, result="Not Logged In") info = request.json if info is None: info = request.form if 'college_name' in info: college_name = info['college_name'] college = None try: college = College.objects.get(name=college_name) except: return jsonify(status=400, result="College Not Found") applications = Application.objects( Q(college=college) & Q(verification="Approved")) profiles = [] sum_gpa = 0 count_gpa = 0 sum_sat_ebrw = 0 count_sat_ebrw = 0 sum_sat_math = 0 count_sat_math = 0 sum_act = 0 count_act = 0 for application in applications: application_status = application.status student = application.student if not track_applications_filter(info, application, student): continue profile = get_profile_dict(student) profile['application_status'] = application_status profiles.append(profile) grades = student.grades if student.gpa not in {None, ""}: sum_gpa += student.gpa count_gpa += 1 if 'sat_ebrw' in grades and grades['sat_ebrw'] not in {None, ""}: sum_sat_ebrw += int(grades['sat_ebrw']) count_sat_ebrw += 1 if 'sat_math' in grades and grades['sat_math'] not in {None, ""}: sum_sat_math += int(grades['sat_math']) count_sat_math += 1 if 'act_composite' in grades and grades['act_composite'] not in { None, "" }: sum_act += int(grades['act_composite']) count_act += 1 summary = { 'avg_gpa': None, 'avg_sat_ebrw': None, 'avg_sat_math': None, 'avg_act': None, } if profiles == []: return jsonify(status=200, result="OK", profiles=profiles) if count_gpa: summary['avg_gpa'] = round(sum_gpa / count_gpa, 2) if count_sat_ebrw: summary['avg_sat_ebrw'] = round(sum_sat_ebrw / count_sat_ebrw, 2) if count_sat_math: summary['avg_sat_math'] = round(sum_sat_math / count_sat_math, 2) if count_act: summary['avg_act'] = round(sum_act / count_act, 2) def get_status(p): return p['application_status'] profiles.sort(key=get_status) return jsonify(status=200, result="OK", profiles=profiles, summary=summary) return jsonify(status=400, result="Missing Fields")
def save_profile(): # Check if logged in if 'username' not in session or session['username'] is None: return jsonify(status=400, result="Not Logged In") # Get student account try: account = Account.objects.get(username=session['username']) # Get student profile student = StudentProfile.objects.get(student=account) except: return jsonify(status=400, result="Profile Not Found") info = request.json if info is None: info = request.form grades = {} name = None city = None state = None for field in info: if field == 'password': digest = hash_utils.hmac_hash(info["password"], account.salt) account.update(set__hashed_password=digest) elif field == 'residence_state': residence_state = info["residence_state"] elif field == 'gpa': gpa = info["gpa"] elif field == 'high_school_name': name = info["high_school_name"] if name is not None: name = name.title().replace(".", "") elif field == 'high_school_city': city = info["high_school_city"] if city is not None: city = city.title() elif field == 'high_school_state': state = info["high_school_state"] elif field == 'college_class': college_class = info["college_class"] elif field == 'major_1': major_1 = info["major_1"] elif field == 'major_2': major_2 = info["major_2"] else: grades[field] = info[field] if (name not in {None, ""} and city not in {None, ""} and state not in {None, ""} and highschool_exists(name, city, state)): try: student.update(set__residence_state=residence_state, set__gpa=gpa, set__high_school_name=name, set__high_school_city=city, set__high_school_state=state, set__college_class=college_class, set__major_1=major_1, set__major_2=major_2, set__grades=grades) applications = Application.objects( Q(student=student) & Q(status='Accepted')) student = StudentProfile.objects.get(student=account) for application in applications: if algorithms.detect_questionable_acceptance( application.college, student) < 50: application.update(set__verification="Pending") application.update(set__timestamp=str(time())) elif application.verification == "Pending": application.update(set__verification="Approved") application.update(set__timestamp=str(time())) return jsonify(status=200, result="OK") except Exception as e: print(e) return jsonify(status=400, result="Save Failed") elif (name in {None, ""} and city in {None, ""} and state in {None, ""}): try: student.update(set__residence_state=residence_state, set__gpa=gpa, set__high_school_name=None, set__high_school_city=None, set__high_school_state=None, set__college_class=college_class, set__major_1=major_1, set__major_2=major_2, set__grades=grades) applications = Application.objects( Q(student=student) & Q(status='Accepted')) student = StudentProfile.objects.get(student=account) for application in applications: print(student.grades) if algorithms.detect_questionable_acceptance( application.college, student) < 50: application.update(set__verification="Pending") application.update(set__timestamp=str(time())) elif application.verification == "Pending": # if you're >= 50, and pending, you're now approved application.update(set__verification="Approved") application.update(set__timestamp=str(time())) return jsonify(status=200, result="OK") except Exception as e: print(e) return jsonify(status=400, result="Save Failed") return jsonify(status=400, result="High School Not Found")
def main(): root = Tk() application = Application.Application(root) application.mainloop() # let it run root.destroy()
def calc_academic_similarity(college, student): # c = College.objects.get(name=college) # acc = Account.objects.get(username=student) # profile = StudentProfile.objects.get(student=acc) profile = student # pass in as parameter applications = Application.objects(college=college) grades = { 'Accepted': { 'gpa_avg': [], 'sat_avg': [], 'act_avg': [] }, 'Not Accepted': { 'gpa_avg': [], 'sat_avg': [], 'act_avg': [] } } for s in applications: status = s.status if s.status == 'Accepted' else 'Not Accepted' s = s.student if 'gpa' in s and s.gpa is not None: grades[status]['gpa_avg'].append(s.gpa) if 'grades' not in s: continue if 'act_composite' in s.grades and s.grades['act_composite'] is not None: grades[status]['act_avg'].append(s.grades['act_composite']) if 'sat_ebrw' in s.grades and s.grades['sat_ebrw'] is not None: grades[status]['sat_avg'].append(s.grades['sat_ebrw']) if 'sat_math' in s.grades and s.grades['sat_math'] is not None: grades[status]['sat_avg'].append(s.grades['sat_math']) for status in grades: for grade_type in grades[status]: for x in range(0, len(grades[status][grade_type])): if grades[status][grade_type][x] is not None: grades[status][grade_type][x] = int(grades[status][grade_type][x]) percent = { 'Accepted': { 'gpa': None, 'sat': None, 'act': None }, 'Not Accepted': { 'gpa': None, 'sat': None, 'act': None } } for status in grades: if 'gpa' in profile: g = grades[status]['gpa_avg'] g.append(profile.gpa) g.sort(reverse=True) # not going to count the number of same grades, just the location # NOTE: reverse sort goes from high to low, 100th to 0th percent[status]['gpa'] = g.index(profile.gpa) / 1.0 / len(g) * 100 percent[status]['gpa'] = 100 - percent[status]['gpa'] # print(profile.gpa) # print(g) # print(percent[status]['gpa']) if 'act_composite' in profile.grades and profile.grades['act_composite'] is not None: g = grades[status]['act_avg'] print(g) score = int(profile.grades['act_composite']) g.append(score) g.sort(reverse=True) percent[status]['act'] = 100 - g.index(score) / 1.0 / len(g) * 100 if 'sat_math' in profile.grades or 'sat_ebrw' in profile.grades: g = grades['Accepted']['sat_avg'] score = 0 count = 0 if 'sat_math' in profile.grades and profile.grades['sat_math'] is not None: score += int(profile.grades['sat_math'])/2.0 count += 1 if 'sat_ebrw' in profile.grades and profile.grades['sat_ebrw'] is not None: score += int(profile.grades['sat_ebrw'])/2.0 count += 1 if count == 1: score = score * 2 g.append(score) g.sort(reverse=True) percent[status]['sat'] = 100 - g.index(score) / 1.0 / len(g) * 100 print() print(percent) accept_exam = [percent['Accepted']['sat'], percent['Accepted']['act']] not_accept_exam = [percent['Not Accepted']['gpa'], percent['Not Accepted']['act']] if accept_exam != [None, None]: if accept_exam[0] == None: accept_exam = accept_exam[1] * 2 # grow value remaining elif accept_exam[1] == None: accept_exam = accept_exam[0] * 2 else: accept_exam = sum(accept_exam) else: accept_exam = None if not_accept_exam != [None, None]: if not_accept_exam[0] == None: not_accept_exam = not_accept_exam[1] * 2 elif not_accept_exam[1] == None: not_accept_exam = not_accept_exam[0] * 2 else: not_accept_exam = sum(not_accept_exam) else: not_accept_exam = None score = 0 score_weight = 0 if accept_exam is not None: score += 0.15 * accept_exam score_weight += 0.15 if not_accept_exam is not None: score += 0.1 * accept_exam score_weight += 0.1 if percent['Accepted']['gpa'] is not None: score += 0.3 * percent['Accepted']['gpa'] score_weight += 0.3 if percent['Not Accepted']['gpa'] is not None: score += 0.2 * percent['Not Accepted']['gpa'] score_weight += 0.2 if score_weight == 0: return -1 # -1 instead of None print(score / 1.0 / score_weight) return score / 1.0 / score_weight