def set_attribute(self, payload): cols = [ 'student_name', 'gender', 'aadhar', 'dob', 'class_std', 'father_name', 'father_occupation', 'mother_name', 'mother_occupation', 'contact', 'isactive', 'register_date', 'modified_date', 'modified_by' ] for col in cols: if col in payload.keys(): setattr(self, col, payload[col]) if 'cluster_name' in payload.keys(): cluster = ClusterModel.find_by_cluster_name( payload['cluster_name']) if not cluster: return { "message": f"Cluster name not found for the student" }, 401 self.cluster_id = cluster.id if 'kalika_kendra_name' in payload.keys(): kalika_kendra = KalikaKendraModel.find_by_kalika_kendra_name( payload['kalika_kendra_name']) if not kalika_kendra: return { "message": f"Kalika Kendra name not found for the student" }, 401 self.kalika_kendra_id = cluster.id
def json(self): return {'kalika_kendra_name': self.kalika_kendra_name, 'cluster_id': self.cluster_id, 'cluster_name': ClusterModel.find_by_cluster_id(self.cluster_id).cluster_name, 'isactive': self.isactive, 'isdeprecated': self.isdeprecated, "id":self.id }
def __init__(self, **kwargs): cols = [ 'teacher_name', 'teacher_code', 'isactive', 'bank_account_no', 'bank_name', 'ifsc', 'teacher_category', 'creation_date', 'modified_date' ] for col in cols: setattr(self, col, None) for col in kwargs.keys(): if col in cols: setattr(self, col, kwargs[col]) kalika_kendra = KalikaKendraModel.find_by_kalika_kendra_name( kwargs['kalika_kendra_name']) # print(kalika_kendra.json()) if not kalika_kendra: return { "message": f"Kalika Kendra name not found for the teacher" }, 401 cluster = ClusterModel.find_by_cluster_name(kwargs['cluster_name']) if not cluster: return {"message": f"Cluster name not found for the teacher"}, 401 print(cluster.json()) self.kalika_kendra_id = kalika_kendra.id self.cluster_id = cluster.id return None
def json(self): return { 'teacher_id': self.id, 'teacher_name': self.teacher_name, 'teacher_code': self.teacher_code, 'kalika_kendra_id': self.kalika_kendra_id, 'cluster_id': self.cluster_id, 'kalika_kendra_name': KalikaKendraModel.find_by_kalika_kendra_id( self.kalika_kendra_id).kalika_kendra_name if KalikaKendraModel.find_by_kalika_kendra_id( self.kalika_kendra_id) else None, 'cluster_name': ClusterModel.find_by_cluster_id(self.cluster_id).cluster_name, 'isactive': self.isactive, 'bank_account_no': self.bank_account_no, 'bank_name': self.bank_name, 'ifsc': self.ifsc, 'teacher_category': self.teacher_category, 'creation_date': str(self.creation_date), 'modified_date': str(self.modified_date) }
def post(self): claims = get_jwt_claims() if not claims['is_admin']: return {'message': 'Admin privilege required.'}, 401 data = _kalika_kendra_parser.parse_args() kalika_kendra_name = data["kalika_kendra_name"] if KalikaKendraModel.find_by_kalika_kendra_name(kalika_kendra_name): return { 'message': f"A Kalika Kendra with name '{kalika_kendra_name}' already exists." }, 400 cluster = ClusterModel.find_by_cluster_name(data['cluster_name']) if not cluster: return { "message": f"Cluster name not found for the Kalika Kendra" }, 401 kalika_kendra = KalikaKendraModel(**data) try: kalika_kendra.save_to_db() except Exception as e: return { "message": f"An error occurred inserting the Kalika Kendra. Error: {repr(e)}" }, 500 return kalika_kendra.json(), 201
def set_attribute(self, payload): cols = [ 'teacher_name', 'teacher_code', 'isactive', 'bank_account_no', 'bank_name', 'ifsc', 'teacher_category', 'modified_date' ] for col in cols: if col in payload.keys(): setattr(self, col, payload[col]) if 'cluster_name' in payload.keys(): cluster = ClusterModel.find_by_cluster_name( payload['cluster_name']) if not cluster: return { "message": f"Cluster name not found for the teacher" }, 401 self.cluster_id = cluster.id if 'kalika_kendra_name' in payload.keys(): kalika_kendra = KalikaKendraModel.find_by_kalika_kendra_name( payload['kalika_kendra_name']) if not kalika_kendra: return { "message": f"Kalika Kendra name not found for the teacher" }, 401 self.kalika_kendra_id = cluster.id print(self.json())
def find_by_any(cls, **kwargs): cols = [ 'teacher_id', 'teacher_name', 'teacher_code', 'cluster_id', 'kalika_kendra_id', 'cluster_name', 'kalika_kendra_name', 'isactive', 'bank_account_no', 'bank_name', 'ifsc', 'teacher_category' ] filter_str = 'cls.query' if 'bank_account_no' in kwargs.keys(): filter_str = filter_str + '.filter_by(bank_account_no="' + str( kwargs['bank_account_no']) + '")' if 'bank_name' in kwargs.keys(): filter_str = filter_str + '.filter_by(bank_name="' + str( kwargs['bank_name']) + '")' if 'ifsc' in kwargs.keys(): filter_str = filter_str + '.filter_by(ifsc="' + str( kwargs['ifsc']) + '")' if 'teacher_category' in kwargs.keys(): filter_str = filter_str + '.filter_by(teacher_category="' + str( kwargs['teacher_category']) + '")' if 'creation_date' in kwargs.keys(): filter_str = filter_str + '.filter_by(creation_date="' + str( kwargs['creation_date']) + '")' if 'modified_date' in kwargs.keys(): filter_str = filter_str + '.filter_by(modified_date="' + str( kwargs['modified_date']) + '")' if 'teacher_id' in kwargs.keys(): filter_str = filter_str + '.filter_by(id="' + str( kwargs['teacher_id']) + '")' if 'teacher_name' in kwargs.keys(): filter_str = filter_str + '.filter_by(teacher_name="' + str( kwargs['teacher_name']) + '")' if 'teacher_code' in kwargs.keys(): filter_str = filter_str + '.filter_by(teacher_code="' + str( kwargs['teacher_code']) + '")' if 'cluster_id' in kwargs.keys(): filter_str = filter_str + '.filter_by(cluster_id="' + str( kwargs['cluster_id']) + '")' if 'kalika_kendra_id' in kwargs.keys(): filter_str = filter_str + '.filter_by(kalika_kendra_id="' + str( kwargs['kalika_kendra_id']) + '")' if 'kalika_kendra_name' in kwargs.keys(): kalika_kendra = KalikaKendraModel.find_by_kalika_kendra_name( kwargs['kalika_kendra_name']) if kalika_kendra: kalika_kendra_id = kalika_kendra.id filter_str = filter_str + '.filter_by(kalika_kendra_id="' \ + str(kalika_kendra_id) + '")' if 'cluster_name' in kwargs.keys(): cluster = ClusterModel.find_by_cluster_name(kwargs['cluster_name']) if cluster: cluster_id = cluster.id filter_str = filter_str + '.filter_by(cluster_id="' \ + str(cluster_id) + '")' if 'isactive' in kwargs.keys(): filter_str = filter_str + '.filter_by(isactive="' + str( kwargs['isactive']) + '")' filter_str = filter_str + '.all()' return eval(filter_str)
def json(self): student = StudentModel.find_by_student_id(self.student_id) cluster = ClusterModel.find_by_cluster_id(student.cluster_id) kalika_kendra = KalikaKendraModel.find_by_kalika_kendra_id( student.kalika_kendra_id) return { 'result_id': self.id, 'attempt_id': self.attempt_id, 'student_id': self.student_id, 'student_name': student.student_name if student else None, 'cluster_id': cluster.id if cluster else None, 'cluster_name': cluster.cluster_name if cluster else None, 'kalika_kendra_id': kalika_kendra.id if kalika_kendra else None, 'kalika_kendra_name': kalika_kendra.kalika_kendra_name if kalika_kendra else None, 'subject_id': self.subject_id, 'subject_name': SubjectModel.find_by_subject_id(self.subject_id).subject_name, 'assessment_category_id': self.category_id, 'assessment_category_name': AssessmentCategoryModel.find_by_category_id( self.category_id).category_name, 'assessment_skill_id': self.skill_id, 'assessment_skill_name': AssessmentSkillModel.find_by_skill_id(self.skill_id).skill_name if AssessmentSkillModel.find_by_skill_id(self.skill_id) else None, 'assessment_period_id': self.period_id, 'assessment_year': self.year, 'assessment_month': self.month, 'assessment_day': self.day, 'assessment_session': self.session, 'assessment_score': self.score, 'assessment_full_score': self.full_score, 'assessment_grade': self.grade, 'creation_date': str(self.creation_date), 'modified_date': str(self.modified_date), 'modified_by': self.modified_by }
def __init__(self, kalika_kendra_name, cluster_name, isactive=1, isdeprecated=0): self.kalika_kendra_name = kalika_kendra_name cluster = ClusterModel.find_by_cluster_name(cluster_name) if not cluster: return {"message": f"Cluster name not found for the Kalika Kendra"}, 401 self.cluster_id = cluster.id self.isactive = isactive self.isdeprecated = isdeprecated
def set_attribute(self, payload): cols = ['isactive', 'isdeprecated'] for col in cols: if col in payload.keys(): setattr(self, col, payload[col]) if 'cluster_name' in payload.keys(): cluster = ClusterModel.find_by_cluster_name(payload['cluster_name']) if not cluster: return {"message": f"Cluster name not found for the Kalika Kendra"}, 401 self.cluster_id = cluster.id
def delete(self): claims = get_jwt_claims() if not claims['is_admin']: return {'message': 'Admin privilege required.'}, 401 data = _cluster_parser.parse_args() cluster_name = data["cluster_name"] cluster = ClusterModel.find_by_cluster_name(cluster_name) if cluster: cluster.delete_from_db() return {'message': 'Cluster deleted.'} return {'message': 'Cluster not found.'}, 404
def get(self): data = request.args # data = _cluster_parser.parse_args() cluster_name = data["cluster_name"] claims = get_jwt_claims() if claims['is_admin']: cluster = ClusterModel.find_by_cluster_name(cluster_name) if cluster: return cluster.json() return {'message': 'Cluster not found'}, 404 return {'message': 'User not authorized to view'}
def get(self): claims = get_jwt_claims() if not claims['is_admin']: return {'message': 'User not authorized to view.'}, 401 data = request.args clusters = ClusterModel.find_by_any(**data) if clusters: resp = [] for cluster in clusters: resp.append(cluster.json()) return resp else: return {'message': 'Cluster not found'}
def json(self): return { 'student_id': self.id, 'student_name': self.student_name, 'gender': self.gender, 'aadhar': self.aadhar, 'dob': self.dob, 'class_std': self.class_std, 'kalika_kendra_id': self.kalika_kendra_id, 'kalika_kendra_name': KalikaKendraModel.find_by_kalika_kendra_id( self.kalika_kendra_id).kalika_kendra_name if KalikaKendraModel.find_by_kalika_kendra_id( self.kalika_kendra_id) else None, 'cluster_name': ClusterModel.find_by_cluster_id(self.cluster_id).cluster_name, 'cluster_id': self.cluster_id, 'father_name': self.father_name, 'father_occupation': self.father_occupation, 'mother_name': self.mother_name, 'mother_occupation': self.mother_occupation, 'contact': self.contact, 'isactive': self.isactive, 'register_date': str(self.register_date), 'modified_date': str(self.modified_date), 'modified_by': self.modified_by }
def find_by_any(cls, **kwargs): filter_str = 'cls.query' cols = ['isactive', 'isdeprecated', 'cluster_name', 'cluster_id'] if 'cluster_id' in kwargs.keys(): filter_str = filter_str + '.filter_by(cluster_id="' + str( kwargs['cluster_id']) + '")' if 'cluster_name' in kwargs.keys(): cluster = ClusterModel.find_by_cluster_name(kwargs['cluster_name']) if cluster: cluster_id = cluster.id filter_str = filter_str + '.filter_by(cluster_id="' + str(cluster_id) + '")' if 'isactive' in kwargs.keys(): filter_str = filter_str + '.filter_by(isactive="' + str( kwargs['isactive']) + '")' if 'isdeprecated' in kwargs.keys(): filter_str = filter_str + '.filter_by(isdeprecated="' + str( kwargs['isdeprecated']) + '")' filter_str = filter_str + '.all()' return eval(filter_str)
def post(self): claims = get_jwt_claims() if not claims['is_admin']: return {'message': 'Admin privilege required.'}, 401 data = _cluster_parser.parse_args() cluster_name = data["cluster_name"] if ClusterModel.find_by_cluster_name(cluster_name): return {'message': f"A cluster with name '{cluster_name}' already exists."}, 400 cluster = ClusterModel(**data) try: cluster.save_to_db() except Exception as e: return {"message": f"An error occurred inserting the cluster. Error: {repr(e)}"}, 500 return cluster.json(), 201
def put(self): claims = get_jwt_claims() if not claims['is_admin']: return {'message': 'Admin privilege required.'}, 401 data = _cluster_parser.parse_args() for key in data.keys(): if str(data[key]).lower() in ('none', 'null', ''): data[key] = None cluster_name = data["cluster_name"] cluster = ClusterModel.find_by_cluster_name(cluster_name) if cluster: cluster.set_attribute(data) else: cluster = ClusterModel(**data) cluster.save_to_db() return cluster.json()
def post(self, name): if ClusterModel.find_by_name(name): return { "message": f"A cluster with name {name} already exists." }, 400 data = Cluster.parser.parse_args() data.update({'name': name}) cluster = ClusterModel(**data) try: cluster.save_to_db() except: return { "message": "An error occurred while creating the cluster." }, 500 return cluster.json(), 201
def __init__(self, **kwargs): cols = [ 'student_name', 'gender', 'aadhar', 'dob', 'class_std', 'father_name', 'father_occupation', 'mother_name', 'mother_occupation', 'contact', 'isactive', 'register_date', 'modified_date', 'modified_by', 'kalika_kendra_id', 'cluster_id' ] for col in cols: setattr(self, col, None) for col in kwargs.keys(): if col in cols: setattr(self, col, kwargs[col]) if kwargs.get('kalika_kendra_name'): kalika_kendra = KalikaKendraModel.find_by_kalika_kendra_name( kwargs['kalika_kendra_name']) if kalika_kendra: self.kalika_kendra_id = kalika_kendra.id if kwargs.get('cluster_name'): cluster = ClusterModel.find_by_cluster_name(kwargs['cluster_name']) if cluster: self.cluster_id = cluster.id return None
def find_by_cluster_name(cls, cluster_name): cluster = ClusterModel.find_by_cluster_name(cluster_name) if cluster: return cls.query.filter_by(cluster_id=cluster.id).first()
def train_cluster(self, train_row_data): model = ClusterModel(dimension=EMB_DIM, k=600) model.fit(train_row_data, self.paper_embs) model.save(join(PROJ_DIR, "temp", "cluster_model"))
def delete(self, name): cluster = ClusterModel.find_by_name(name) if cluster: cluster.delete_from_db() return {"message": "Cluster deleted."}
def get(self, name): cluster = ClusterModel.find_by_name(name) if cluster: return cluster.json() return {'message': 'Cluster not found'}, 404
def predict_cluster(self, pub_data, X): model = ClusterModel(dimension=EMB_DIM, k=600) model.load(join(PROJ_DIR, "temp", "cluster_model")) paper_embs, _, _, _ = self.generate_embedding(pub_data) return model.predict(X, paper_embs)
def find_by_student_by_any(cls, **kwargs): print(kwargs) filter_str = 'cls.query' if 'contact' in kwargs.keys(): filter_str = filter_str + '.filter_by(contact="' + str( kwargs['contact']) + '")' if 'isactive' in kwargs.keys(): filter_str = filter_str + '.filter_by(isactive="' + str( kwargs['isactive']) + '")' if 'register_date' in kwargs.keys(): filter_str = filter_str + '.filter_by(register_date="' + str( kwargs['register_date']) + '")' if 'modified_date' in kwargs.keys(): filter_str = filter_str + '.filter_by(modified_date="' + str( kwargs['modified_date']) + '")' if 'modified_by' in kwargs.keys(): filter_str = filter_str + '.filter_by(modified_by="' + str( kwargs['modified_by']) + '")' if 'class_std' in kwargs.keys(): filter_str = filter_str + '.filter_by(class_std="' + str( kwargs['class_std']) + '")' if 'kalika_kendra_id' in kwargs.keys(): filter_str = filter_str + '.filter_by(kalika_kendra_id="' + str( kwargs['kalika_kendra_id']) + '")' if 'cluster_id' in kwargs.keys(): filter_str = filter_str + '.filter_by(cluster_id="' + str( kwargs['cluster_id']) + '")' if 'kalika_kendra_name' in kwargs.keys(): kalika_kendra = KalikaKendraModel.find_by_kalika_kendra_name( kwargs["kalika_kendra_name"]) print(kalika_kendra.json()) if kalika_kendra: kalika_kendra_id = kalika_kendra.id filter_str = filter_str + '.filter_by(kalika_kendra_id="' + str( kalika_kendra_id) + '")' if 'cluster_name' in kwargs.keys(): cluster = ClusterModel.find_by_cluster_name(kwargs["cluster_name"]) if cluster: cluster_id = cluster.id filter_str = filter_str + '.filter_by(cluster_id="' + str( kwargs['cluster_id']) + '")' if 'father_occupation' in kwargs.keys(): filter_str = filter_str + '.filter_by(father_occupation="' + str( kwargs['father_occupation']) + '")' if 'mother_name' in kwargs.keys(): filter_str = filter_str + '.filter_by(mother_name="' + str( kwargs['mother_name']) + '")' if 'mother_occupation' in kwargs.keys(): filter_str = filter_str + '.filter_by(mother_occupation="' + str( kwargs['mother_occupation']) + '")' if 'student_id' in kwargs.keys(): filter_str = filter_str + '.filter_by(student_id="' + str( kwargs['student_id']) + '")' if 'student_name' in kwargs.keys(): filter_str = filter_str + '.filter_by(student_name="' + str( kwargs['student_name']) + '")' if 'gender' in kwargs.keys(): filter_str = filter_str + '.filter_by(gender="' + str( kwargs['gender']) + '")' if 'aadhar' in kwargs.keys(): filter_str = filter_str + '.filter_by(aadhar="' + str( kwargs['aadhar']) + '")' if 'dob' in kwargs.keys(): filter_str = filter_str + '.filter_by(dob="' + str( kwargs['dob']) + '")' filter_str = filter_str + '.all()' return eval(filter_str)