def studentAverage(self, session, student, ca, subject): #get student class db = 'student_class' + str(session) cn = Db() cl = cn.selectn(db, '', 1, {'studentID': student}) scla = cl['classID'] clz = cn.selectn('datas', '', 1, {'id': scla}) scla = clz['subID'] ar = [] ar.append(scla) scl = StudentTable(session, [None], ar, [None]) #get all alass mates studentsIDs = scl.classStudent() student_id = [] for dx in studentsIDs: student_id.append(dx[0]) dat = self.allStudents(session, student_id, subject, ca) dy = pd.DataFrame.from_dict(dat) me = dy['score'].mean() co = dy['score'].count() dx = dy.set_index('studentID') dx = dx.sort_values('score', ascending=False) dx = dx.reset_index() dx = dx.index[dx['studentID'] == int(student)] dx = dx.values.tolist() ran = dx[0] + 1 arr = [round(me, 2), co, ran] return arr
def button_edit(self): row = self.getSelected() currentDate = QDate() if row: self.editrow = row g = Db() if self.sessionMain: data = g.selectn('session', '', 1, {'id': row}) data_name = str(data['name']) self.groupBox2.setTitle('Edit') self.sessionID = False else: data = g.selectn('terms', '', 1, {'id': row}) data_sess = g.selectn('session', '', 1, {'id': data['sessionID']}) data_name = str(data['name']) self.sessionID = data['sessionID'] self.groupBox2.setTitle('Edit ' + str(data_sess['name'])) try: self.le1.setText(data_name) except: self.le1.setText('') try: self.fromData.setDate(data['start_date']) except: self.fromData.setDate(currentDate.currentDate()) try: self.toData.setDate(data['end_date']) except: self.toData.setDate(currentDate.currentDate()) self.pb.hide() self.pb4.show()
def getClassName(self, a={}): self.a = a nm = '' g = Db() try: for re in self.a: si = g.selectn('datas', '', 1, {'id':re}) sii = g.selectn('datas', '', 1, {'id':si['subID']}) nm = nm+sii['abbrv']+' '+si['abbrv']+' ' except: nm = 'Class Error' return nm
def reloadBorrowed(self): self.getQuantity() _store = self.hold_store[self.storeData.currentIndex()] _session = self.session g = Db() db = 'school_stores' + str(_session) data = g.selectn(db, '', '', {'itemID': _store, 'state': 4}) fig = 0 self.borrowedData.clear() self.hold_borrowed = {} i = 0 for a in data: ret = g.selectStoreReturned(db, a['id']) if ret: retu = ret['qty'] else: retu = 0 fig = float(a['quantity']) - float(retu) damz = float(a['datepaid']) if float(fig) > 0: self.hold_borrowed[i] = a['id'] damt = datetime.utcfromtimestamp(damz).strftime('%d-%m-%Y') tex = str(damt) + " " + str( a['person']).upper() + " (" + str(fig).upper() + ")" self.borrowedData.addItem(tex) i += 1
def subjectAverage(self, session, student, ca, subject): #get student class db = 'student_class' + str(session) cn = Db() cl = cn.selectn(db, '', 1, {'studentID': student}) scla = cl['classID'] scl = StudentTable(session, student, [], scla) #get all alass mates studentsIDs = scl.classStudents() student_id = [] for dx in studentsIDs: student_id.append(dx[0]) dat = self.allSubjects(session, student_id, subject, ca) df = pd.DataFrame.from_dict(dat) ret = {} for x in subject: dy = df.loc[df['subjectID'] == x] me = dy['score'].mean() co = dy['score'].count() dx = dy.set_index('studentID') dx = dx.sort_values('score', ascending=False) dx = dx.reset_index() dx = dx.index[dx['studentID'] == int(student)] dx = dx.values.tolist() ran = dx[0] + 1 arr = [round(me, 2), co, ran] ret[x] = arr return ret
def editRow(self, a): _session = self.session g = Db() db = 'school_expenses' + str(_session) data = g.selectn(db, '', 1, {'id': a}) if len(data) > 0: self.editID = int(data['id']) if float(data['amount']) < 0: amt = float(data['amount']) * -1 self.amountData.setText(str(amt)) self.r1.setChecked(True) else: amt = float(data['amount']) self.amountData.setText(str(amt)) self.r2.setChecked(True) self.descriptionData.clear() self.descriptionData.insertPlainText(str(data['description'])) self.tellerData.setText(str(data['teller'])) acID = self.hold_account.keys()[self.hold_account.values().index( data['accountID'])] self.accountData.setCurrentIndex(acID) exID = self.hold_expenses.keys()[self.hold_expenses.values().index( data['expenseID'])] self.expenseData.setCurrentIndex(exID)
def button_click(self): tex = ' Please wait processing, do not cancel or close..' self.feesPop.setText(tex) _term = self.term _class = self.cla _students = self.students _amount = self.feesAmount.text() _fee = self.hol[self.feesCombo.currentIndex()] for j in _class: data = {} data['pubID'] = 'fee' data['subID'] = _term data['abbrv'] = _fee data['name'] = j cn = Db() feeStudent = self.feeStudents(_term, _students, _fee, _amount) check = cn.selectn('datas', '', 1, data) if (check and check['id'] == 0): pass else: data['description'] = _amount cn.insert('datas', data) ins = feeStudent tex = ' TOTAL of ' + str(ins) + ' inserted' self.feesPop.setText(tex)
def getSelection(self): self.le1.clear() currentDate = QDate() self.fromData.setDate(currentDate.currentDate()) self.toData.setDate(currentDate.currentDate()) self.sessionMain = False if self.hold_data_add['addnew'].isSelected(): self.groupBox2.setTitle('Add New') self.groupBox2.show() self.sessionMain = True self.sessionID = False else: self.sessionMain = False r = None for i in self.hold_data_add_item: if self.hold_data_add_item[i].isSelected(): r = i if r: g = Db() v = g.selectn('session', '', 1, {'id': r}) vname = str(v['name']).upper() + ' Session' self.groupBox2.setTitle('ADD ' + str(vname) + ' Term') self.sessionID = r self.groupBox2.show() else: self.groupBox2.setTitle('Add') self.sessionID = False self.groupBox2.hide()
def button_click(self): g = Db() g.createDatas() g.createStudent() g.createSession() g.createTerm() for z in self.sessions: g.createExpenses(z) g.createStores(z) g.createAwards(z) g.createConducts(z) g.createMails(z) g.createMedicals(z) arr = g.selectn('terms', '', '', {'id':z}) for t1 in arr: t = t1['id'] g.createClass(t) g.createSubject(t) g.createFee(t) g.createPay(t) g.createResult(t) g.createAffective(t) g.createPsychomoto(t) for c in self.list_data: try: g.replacePandas(c) except: pass off = OfflineDialog() off.clearFolder()
def pullFees(self): term = self.term student = self.student fee_id_array = [] cn = Db() db_fee = 'student_fee' + str(term) db_pay = 'student_pay' + str(term) fee = cn.selectn(db_fee, '', '', {'studentID': student}) pay = cn.selectn(db_pay, '', '', {'studentID': student}) #get all fees arr = {} arr1 = {} for r in fee: fee_id_array.append(int(r['feeID'])) arr[int(r['feeID'])] = {} for r in pay: fee_id_array.append(int(r['feeID'])) arr1[int(r['feeID'])] = {} for r in fee: get_mon = cn.selectn( 'datas', '', 1, { 'pubID': 'fee', 'subID': self.term, 'name': self.clasz, 'abbrv': r['feeID'] }) if arr[int(r['feeID'])] and isinstance(arr[int(r['feeID'])], dict): arr[int(r['feeID'])][int(r['id'])] = get_mon['description'] else: arr[int(r['feeID'])] = {} arr[int(r['feeID'])][int(r['id'])] = get_mon['description'] for r in pay: if arr1[int(r['feeID'])] and isinstance(arr1[int(r['feeID'])], dict): arr1[int(r['feeID'])][int(r['id'])] = r['amount'] else: arr1[int(r['feeID'])] = {} arr1[int(r['feeID'])][int(r['id'])] = r['amount'] fee_ids = list(set(fee_id_array)) fin = [fee_ids, arr, arr1] return fin
def getChecked(self, a): arr_hold = [] g = Db() for i in self.hold_data: if self.hold_data[i].checkState(0) == Qt.Checked: arr_hold.append(i) self.hold_data[i].setCheckState(0, Qt.Checked) g.update('terms', {'active': 0}, {'active': 1}) g.update('terms', {'active': 1}, {'id': i}) tt = g.selectn('terms', '', 1, {'id': i}) g.update('session', {'active': 0}, {'active': 1}) g.update('session', {'active': 1}, {'id': tt['sessionID']}) g.selectn('session', '', 1, {'id': tt['sessionID']}) else: self.hold_data[i].setCheckState(0, Qt.Unchecked) self.reloadTerm()
def getData(self, a=[]): self.a = a nm = {} g = Db() for re in self.a: si = g.selectn('datas', '', 1, {'id':re}) nm[re] = si['name'] return nm
def removeSubject(self, a, b): session = self.session db = 'student_subject' + str(session) g = Db() for i in a: for j in b: f = g.selectn(db, '', 1, {'studentID': i, 'subjectID': j}) if f and f['id'] > 0: g.delete(db, {'id': f['id']})
def button_template(self, b): template = self.lTemplate.text() template =template.lower() if(len(template) > 0): g = Db() Ch = g.selectn('datas', '', 1, {'abbrv':template, 'pubID': 'temp'}) if Ch and Ch['id'] > 0: self.rTemplate.setText('Failed: Name already exist.') else: set_arr = [] ass_arr = [] gra_arr = [] cla_arr = [] for i in self.set_arr: if self.set_arr[i].checkState(0) == Qt.Checked: set_arr.append(i) for i in self.ass_arr: if self.ass_arr[i].checkState(0) == Qt.Checked: ass_arr.append(i) for i in self.gra_arr: if self.gra_arr[i].checkState(0) == Qt.Checked: gra_arr.append(i) for i in self.cla_arr: if self.cla_arr[i].checkState(0) == Qt.Checked: cla_arr.append(i) title = self.titleData.text() themeColor = self.le5.text() themeFont = self.le6.text() cla_store = self.cla_arr cla_store = ','.join(str(x) for x in cla_store) set_arr = '::'.join(str(x) for x in set_arr) gra_arr = '::'.join(str(x) for x in gra_arr) ass_arr = '::'.join(str(x) for x in ass_arr) save1 = title.upper()+':::'+ themeColor+':::'+ themeFont+':::'+ass_arr+':::'+ gra_arr+':::'+set_arr try: if(len(title) > 0): y = { 'name':cla_store, 'subID':self.term, 'pubID':'temp', 'abbrv':template, 'description': save1, 'active':0} h = g.insert('datas', y) self.button_click() else: pass except: pass else: self.rTemplate.setText('Please give the template a name')
def getSubName(b=[]): store_sub_name = {} cn = Db() for subz in b: sub_name = None sub_name = cn.selectn('datas', '', 1, {'id': subz}) if sub_name: store_sub_name.update({subz: sub_name['name']}) return store_sub_name
def button_click(self): subject = self.getValue() #clasz = self.classCombo.itemData(self.classCombo.currentIndex()) clasz = self.class_arr[self.classCombo.currentIndex()] ## set class g = Db() sel = g.selectn(self.db_class, '', 1, {'studentID': self.student}) if sel and sel['id'] > 0: if int(sel['classID']) == clasz: pass else: g.update(self.db_class, {'classID': clasz}, {'id': sel['id']}) else: g.insert(self.db_class, { 'studentID': self.student, 'classID': clasz }) if len(subject[0]) > 0: for a in subject[0]: sel = g.selectn(self.db_subject, '', 1, { 'studentID': self.student, 'subjectID': a }) if sel and int(sel['id']) > 0: pass else: g.insert(self.db_subject, { 'studentID': self.student, 'subjectID': a }) if len(subject[1]) > 0: for a in subject[1]: g.delete(self.db_subject, { 'studentID': self.student, 'subjectID': a }) ## set subject self.accept()
def setSubject(self, a, b): session = self.session db = 'student_subject' + str(session) g = Db() for i in a: for j in b: f = g.selectn(db, '', 1, {'studentID': i, 'subjectID': j}) if f and f['id'] > 0: pass else: g.insert(db, {'studentID': i, 'subjectID': j})
def getClassUnit(self, a): self.a = a arr = [] g = Db() # confirm its nt a class unit si = g.selectn('datas', '', '', {'subID':self.a}) for s in si: arr.append(s['id']) return arr
def pullClass(self): cn = Db() dts = cn.selectn('datas', '', '', {'pubID': 3}) arr = {} try: for j in dts: arr[j['id']] = [j['name'], j['abbrv'], j['subID'], j['active']] except: pass return arr
def editRow(self, a): e = a.split('_') g = Db() self.mainrow = e[1] self.mainses = e[0] db = 'school_medicals' + str(e[0]) data = g.selectn(db, '', 1, {'id': e[1]}) if data and len(data) > 0: self.ailmentData.clear() self.ailmentData.insertPlainText(str(data['ailment'])) self.treatmentData.clear() self.treatmentData.insertPlainText(str(data['treatment']))
def editrow(self, a): e = a.split('_') g = Db() self.mainrow = e[1] self.mainses = e[0] db = 'school_conducts' + str(self.mainses) data = g.selectn(db, '', 1, {'id': self.mainrow}) if data and len(data) > 0: self.ailmentData.clear() self.ailmentData.insertPlainText(str(data['action'])) self.staffData.setText(str(data['staffname'])) self.treatmentData.clear() self.treatmentData.insertPlainText(str(data['reaction']))
def pullClass(self, a): self.a = a cn = Db() datas = cn.selectn('datas', '', '', {'subID': self.a}) arr = {} try: for j in datas: arr[j['id']] = [ j['name'], j['abbrv'], j['description'], j['active'] ] except: pass return arr
def button_click(self): session = self.getSelected() arr = [] g = Db() for a in session: arr.append('school_awards'+str(a)) arr.append('school_expenses'+str(a)) arr.append('school_mails'+str(a)) arr.append('school_medicals'+str(a)) arr.append('school_stores'+str(a)) terms = g.selectn('terms', '', '', {'sessionID': a}) for b in terms: arr.append('student_affective'+str(b['id'])) arr.append('student_class'+str(b['id'])) arr.append('student_fee'+str(b['id'])) arr.append('student_pay'+str(b['id'])) arr.append('student_psy'+str(b['id'])) arr.append('student_result'+str(b['id'])) arr.append('student_subject'+str(b['id'])) arr.append('session') arr.append('terms') arr.append('students') arr.append('datas') try: f = open('_temp/data.txt', "w") save_date = time.time() f.write('SAVED_DATE='+str(save_date)+'\n SAVED_TABLES='+str(arr)+'\n SAVED_IDS='+str(session)) f.close() except: pass for c in arr: try: df = g.selectPandas(c) df.to_csv('_temp/'+c+'.csv', index=False) except: pass fileName = QFileDialog.getSaveFileName(self, 'Save File as', '', '*.zip') achi_zip = zipfile.ZipFile(fileName+'.zip', 'w') for root, dirs, files in os.walk('_temp/'): for afile in files: achi_zip.write(os.path.join(root, afile), afile, compress_type = zipfile.ZIP_DEFLATED) achi_zip.close()
def pullGrade(self, a): cn = Db() data = cn.selectn('datas', '', '', {'subID': a}) arr = [] for f in data: des = f['description'].split(':') arrd = {} arrd['max'] = des[0] arrd['min'] = des[1] arrd['color'] = des[2] arrd['name'] = f['name'] arrd['abbrv'] = f['abbrv'] arr.append(arrd) return arr
def button_click(self): tex = ' Please wait processing, do not cancel or close..' self.feesPop.setText(tex) _term = self.term _class = self.cla _students = self.students _amount = self.feesAmount.text() _fee = self.hol[self.feesCombo.currentIndex()] feeStudent = 0 feeStudentUp = 0 ins = [] ups = [] for j in _class: st = self.getClassStudent([j]) post = StudentTable(self.term, [None], [None], [None]) _students = post.getIDs(st[1]) data = {} data['pubID'] = 'fee' data['subID'] = _term data['abbrv'] = _fee data['name'] = j cn = Db() check = cn.selectn('datas', '', 1, data) if (check and check['id'] > 0): if float(check['description']) == float(_amount): pass else: #update sid = cn.update('datas', {'description': _amount}, {'id': check['id']}) re = self.feeStudentsUpdate(_term, _students, _fee, _amount, check['id']) feeStudent = re[0] feeStudentUp = re[1] else: data['description'] = _amount sid = cn.insert('datas', data) if int(sid) > 0: feeStudent = self.feeStudents(_term, _students, _fee, _amount, sid) ins.append(int(feeStudent)) ups.append(int(feeStudentUp)) tex = ' TOTAL of ' + str(sum(ins)) + ' inserted ' + str( sum(ups)) + ' updated.' self.feesPop.setText(tex)
def getName(a, b=[]): store_sub_name = {} cn = Db() for subz in b: sub_name = None sub_name = cn.selectn('students', '', 1, {'id': subz}) if sub_name: if (a == 0): nam = str(sub_name['surname'] + ' ' + sub_name['firstname']).title() store_sub_name.update({subz: nam}) elif (a == 1): nm = str(sub_name['surname'] + ' ' + sub_name['firstname']).title() nam = [sub_name['schno'], nm] store_sub_name.update({subz: nam}) return store_sub_name
def feeStudents(self, session, students, fee, amount): db = 'student_fee' + str(session) cn = Db() fd = [] ed = [] for s in students: data = {} data['studentID'] = s[0] data['feeID'] = fee chk = cn.selectn(db, '', 1, data) if (chk and int(chk['id']) > 0): #confirm if money available pass else: #if money not set , set e = cn.insert(db, data) ed.append(e) return len(ed)
def button_click(self): fname = self.mainLink im1 = fname file1 = 'pic_thumb/' file2 = 'pic_main/' lnk = "logo.png" im1.thumbnail((128, 128)) im1.save(file1 + lnk, "PNG" ) im1.thumbnail((300, 300)) im1.save(file2 + lnk, "PNG") g = Db() sel = g.selectn('datas', '', 1, {'pubID':'datas', 'name':'logo'}) if sel and sel['id'] > 0: pass else: g.insert('datas', {'pubID':'datas', 'name':'logo', 'description': lnk}) self.setCurrentPix() self.button_close(self)
def editRow(self, a): _session = self.session g = Db() db = 'school_stores' + str(_session) data = g.selectn(db, '', 1, {'id': a}) if len(data) > 0: try: amt = float(data['amount']) qty = float(data['quantity']) if amt > 0 and qty > 0: cost = amt * qty else: cost = 0 except: cost = 0 amt = 0 qty = 0 if data['state'] == 1: self.r1.setChecked(True) elif data['state'] == 2: self.r2.setChecked(True) elif data['state'] == 3: self.r3.setChecked(True) elif data['state'] == 4: self.r4.setChecked(True) elif data['state'] == 5: self.r5.setChecked(True) self.amountData.setText(str(cost)) self.descriptionData.clear() self.descriptionData.insertPlainText(str(data['description'])) self.tellerData.setText(str(data['teller'])) self.periodData.setText(str(data['period'])) self.personData.setText(str(data['person'])) self.quantityData.setText(str(qty)) stID = self.hold_store.keys()[self.hold_store.values().index( data['itemID'])] self.storeData.setCurrentIndex(stID)
def button_edit(self): row = self.getSelected() self.sessionMain = 0 if row: self.groupBox2.setTitle('Edit') self.editrow = row g = Db() data = g.selectn('datas', '', 1, {'id': row}) if self.titleID == data['pubID']: self.sessionMain = 1 else: self.sessionMain = 0 try: self.le1.setText(data['name']) except: self.le1.setText('') try: self.le2.setText(data['abbrv']) except: self.le2.setText('') self.pb.hide() self.pb4.show()