def update(request, uid): """执行编辑信息""" mod = Model('admin') ob = mod.find("'" + uid + "'") import hashlib m = hashlib.md5() m.update(bytes(request.POST['old_password'], encoding='utf8')) if request.POST['password'] == request.POST['repassword'] and ob[0][ 'password'] == m.hexdigest(): mod = Model('admin') m = hashlib.md5() m.update(bytes(request.POST['password'], encoding='utf8')) kw = { 'no': uid, 'password': m.hexdigest(), } try: if mod.update(kw) > 0: context = {"info": "修改成功!"} else: context = {"info": "修改失败"} except Exception as err: print(err) context = {"info": "修改失败"} else: context = {"info": "修改失败"} return render(request, "myadmin/info.html", context)
def add(request): """加载添加页面""" teacher = Model('teacher') subject = Model('subject') list1 = teacher.findAll() list2 = subject.findAll() context = {"teacher": list1, 'subject': list2} return render(request, "myadmin/teaching/add.html", context)
def edit(request, uid): """加载编辑信息页面""" mod = Model('teacher') ob = mod.find(no=uid) mod = Model('faculty') title = mod.findAll() if ob is not None: context = {"user": ob, 'typelist': title} return render(request, "myadmin/users/edit.html", context) else: context = {"info": "没有找到要修改的信息!"} return render(request, "myadmin/info.html", context)
def teaching(request): """课程安排""" data = request.session['teacher'] uid = data.get('no') subject = Model('subject') teaching = Model('teaching') list2 = subject.findAll() list3 = teaching.find("'" + uid + "'") umod = [] for teaching in list3: dir = {} for subject in list2: if teaching.get('subject') == subject.get('no'): dir.update({ 'no': subject.get('no'), 'name': subject.get('name'), 'score': subject.get('score') }) break dir.update({'class': teaching.get('class')}) umod.append(dir) # 执行分页处理 pIndex = int(request.GET.get("p", 1)) page = Paginator(umod, 4) # 以50条每页创建分页对象 maxpages = page.num_pages # 最大页数 # 判断页数是否越界 if pIndex > maxpages: pIndex = maxpages if pIndex < 1: pIndex = 1 list2 = page.page(pIndex) # 当前页数据 # 获取页面列表信息 if maxpages < 5: plist = page.page_range # 页码数列表 else: if pIndex <= 3: plist = range(1, 6) elif pIndex >= maxpages - 3: plist = range(maxpages - 4, maxpages + 1) else: plist = range(pIndex - 2, pIndex + 3) context = { "list": list2, 'plist': plist, 'pIndex': pIndex, 'maxpages': maxpages } return render(request, "web/teacher/class.html", context)
def update(request, uid): """执行编辑信息""" mod = Model('teacher') uid = str(uid) ob = mod.find("'" + uid + "'") if request.POST['old_password'] == '': context = {"info": "请输入登录密码"} return render(request, "web/info.html", context) else: import hashlib m = hashlib.md5() m.update(bytes(request.POST['old_password'], encoding='utf8')) if ob[0]['password'] == m.hexdigest(): if request.POST['password'] != '' and request.POST[ 'password'] == request.POST['repassword']: mod = Model('teacher') m = hashlib.md5() m.update(bytes(request.POST['password'], encoding='utf8')) kw = { 'no': uid, 'password': m.hexdigest(), } try: if mod.update(kw) > 0: context = {"info": "修改成功!"} else: context = {"info": "修改失败"} except Exception as err: print(err) context = {"info": "修改失败"} elif request.POST['password'] == '' and request.POST['phone'] != '': kw = { 'no': uid, 'phone': request.POST['phone'], } try: if mod.update(kw) > 0: context = {"info": "修改成功!"} else: context = {"info": "修改失败"} except Exception as err: print(err) context = {"info": "修改失败"} else: context = {"info": "无修改信息"} else: context = {"info": "修改失败"} return render(request, "web/info.html", context)
def insert(request): """执行添加""" if request.POST['no'].replace(' ', '') != '': if request.POST['password'] == request.POST['repassword']: mod = Model('admin') # 获取密码并md5 import hashlib m = hashlib.md5() m.update( bytes(request.POST['password'].replace(' ', ''), encoding='utf8')) kw = { 'no': request.POST['no'].replace(' ', ''), 'password': m.hexdigest(), } if mod.save(kw) > 0: context = {"info": "添加成功!"} else: context = {"info": "添加失败"} else: context = {"info": "添加失败"} else: context = {"info": "添加失败"} return render(request, "myadmin/info.html", context)
def setUp(self): self.model = Model(20) self.model.load('../testdata/lda_model') self.vocabulary = Vocabulary() self.vocabulary.load('../testdata/vocabulary.dat') self.topic_words_stat = TopicWordsStat(self.model, self.vocabulary)
def pcajax_validate(request): if request.method == "POST": gt = GeetestLib(pc_geetest_id, pc_geetest_key) challenge = request.POST.get(gt.FN_CHALLENGE, '') validate = request.POST.get(gt.FN_VALIDATE, '') seccode = request.POST.get(gt.FN_SECCODE, '') status = request.session[gt.GT_STATUS_SESSION_KEY] user_id = request.POST.get('username') if status: result = gt.success_validate(challenge, validate, seccode, user_id) else: result = gt.failback_validate(challenge, validate, seccode) if result: teacher = Model('teacher') tdata = teacher.find("'" + request.POST.get('username') + "'") if tdata: import hashlib m = hashlib.md5() m.update(bytes(request.POST['password'], encoding='utf8')) if tdata[0]['password'] == m.hexdigest(): # 将当前登陆成功的用户信息以adminuser这个key放入到session中 request.session['teacher'] = tdata[0] result = {"status": "success"} # return redirect(reverse('teacher_index')) else: result = {"status": "fail"} else: result = {"status": "fail"} else: result = {"status": "fail"} return HttpResponse(json.dumps(result)) return HttpResponse("error")
def index(request): """管理后台首页""" umod = Model('teacher') mode2 = Model('faculty') faculty = mode2.findAll() list = [] for vo in faculty: dir = {} num = umod.count('faculty', vo['no'])[0]['num'] if num > 0: dir.update({'faculty': vo['name'], 'num': num}) list.append(dir) context = {'list': list} return render(request, "myadmin/index.html", context)
def setUp(self): model = Model(20) model.load('../testdata/lda_model') vocabulary = Vocabulary() vocabulary.load('../testdata/vocabulary.dat') self.sparselda_gibbs_sampler = \ SparseLDAGibbsSampler(model, vocabulary, 10, 5)
def setUp(self): self.model = Model(20) self.model.load('../testdata/lda_model') self.vocabulary = Vocabulary() self.vocabulary.load('../testdata/vocabulary.dat') self.model_evaluator = ModelEvaluator(self.model, self.vocabulary)
def setUp(self): model = Model(20) model.load('../testdata/lda_model') vocabulary = Vocabulary() vocabulary.load('../testdata/vocabulary.dat') self.multi_chain_gibbs_sampler = \ MultiChainGibbsSampler(model, vocabulary, 10, 10, 5)
def update(request, uid): """执行编辑信息""" if request.POST['password'] == request.POST['repassword']: mod = Model('teacher') # 获取密码并md5 import hashlib m = hashlib.md5() m.update(bytes(request.POST['password'], encoding='utf8')) kw = { 'no': uid, 'faculty': request.POST['faculty'], 'age': request.POST['age'], 'sex': request.POST['sex'], 'position': request.POST['position'], 'degree': request.POST['degree'], 'phone': request.POST['phone'], 'password': m.hexdigest(), } try: if mod.update(kw) > 0: context = {"info": "修改成功!"} else: context = {"info": "修改失败"} except Exception as err: print(err) context = {"info": "修改失败"} else: context = {"info": "修改失败"} return render(request, "myadmin/info.html", context)
def dologin(request): """执行登陆""" # 验证码判断 verifycode = request.session['verifycode'] code = request.POST['code'] if verifycode != code: context = {'info': '验证码错误!'} return render(request, "myadmin/login.html", context) try: # 根据登陆账号获取用户信息 user = Model('admin') user = user.find("'" + request.POST['username'] + "'") if user is not None: import hashlib m = hashlib.md5() m.update(bytes(request.POST['password'], encoding='utf8')) print(m.hexdigest()) # 校验密码是否正确 if user[0]['password'] == m.hexdigest(): # 将当前登陆成功的用户信息以adminuser这个key放入到session中 request.session['adminuser'] = user[0] return redirect(reverse('myadmin_index')) else: context = {'info': "登陆密码错误"} else: context = {'info': "此用户非后台管理账户"} except Exception as err: print(err) context = {'info': "登陆账号不存在"} return render(request, 'myadmin/login.html', context)
def insert(request): """执行添加""" mod = Model('teacher') # 获取密码并md5 import hashlib m = hashlib.md5(b'000000') try: kw = { 'no': request.POST['no'].strip(), 'faculty': request.POST['faculty'], 'name': request.POST['name'], 'age': request.POST['age'], 'sex': request.POST['sex'], 'position': request.POST['position'], 'degree': request.POST['degree'], 'phone': request.POST['phone'], 'password': m.hexdigest(), } if mod.save(kw) > 0: context = {"info": "添加成功!"} else: context = {"info": "添加失败"} except: context = {"info": "添加失败"} return render(request, "myadmin/info.html", context)
def delete(request, uid): """删除信息""" mod = Model('teaching') if mod.delete(id=uid) > 0: context = {"info": "删除成功"} else: context = {"info": "删除失败"} return render(request, "myadmin/info.html", context)
def index(request): data = request.session['teacher'] mod = Model('faculty') title = mod.findAll() for faculty in title: if data['faculty'] == faculty['no']: data['faculty'] = faculty['name'] data.pop('password') return render(request, "web/teacher/index.html", {'data': data})
def edit(request, uid): """加载编辑信息页面""" mod = Model('subject') ob = mod.find(no=uid) if ob is not None: context = {"user": ob} return render(request, "myadmin/subject/edit.html", context) else: context = {"info": "没有找到要修改的信息!"} return render(request, "myadmin/info.html", context)
def edit(request, uid): """加载编辑信息页面""" mod = Model('teacher') ob = mod.find("'" + str(uid) + "'") if ob is not None: context = {"teacher": ob} return render(request, "web/teacher/edit.html", context) else: context = {"info": "没有找到要修改的信息!"} return render(request, "web/info.html", context)
def edit(request, uid): """加载编辑信息页面""" mod = Model('teaching') ob = mod.find(no=uid) teacher = Model('teacher') subject = Model('subject') list1 = teacher.find(no=uid) list2 = subject.findAll() ob[0].update({'teacher': list1[0].get('name')}) print(ob) print(list2) if ob is not None: context = {"teaching": ob, 'subject': list2} return render(request, "myadmin/teaching/edit.html", context) else: context = {"info": "没有找到要修改的信息!"} return render(request, "myadmin/info.html", context)
def edit(request, uid): """加载编辑信息页面""" mod = Model('admin') ob = mod.find(no="'" + uid + "'") print(ob) if ob is not None: context = {"user": ob} return render(request, "myadmin/vip/edit.html", context) else: context = {"info": "没有找到要修改的信息!"} return render(request, "myadmin/info.html", context)
def test_model(): EXPECTED_MSG = repr( TypeError( "Can't instantiate abstract class Model with abstract methods __call__, __init__" )) # nopep8 has_type_error = False try: my_model = Model() except TypeError as e: msg = e.__repr__() has_type_error = True assert has_type_error assert msg == EXPECTED_MSG
def index(request): """浏览信息""" mod = Model('subject') umod = mod.findAll() mywhere = [] # 获取、判断并封装关keyword键搜索 kw = request.GET.get("keyword", None) if kw: # 查询账户中只要含有关键字的都可以 list = [] for vo in umod: if vo['no'].find(kw) >= 0 or vo['name'].find(kw) >= 0: list.append(vo) mywhere.append("keyword=" + kw) else: list = umod # 获取、判断并封装学分score搜索条件 score = request.GET.get('score', '') if score != '': temp = [] for vo in list: if vo['score'] == float(score): temp.append(vo) mywhere.append("score=" + kw) list = temp # 执行分页处理 pIndex = int(request.GET.get("p", 1)) page = Paginator(list, 4) # 以50条每页创建分页对象 maxpages = page.num_pages # 最大页数 # 判断页数是否越界 if pIndex > maxpages: pIndex = maxpages if pIndex < 1: pIndex = 1 list2 = page.page(pIndex) # 当前页数据 # 获取页面列表信息 if maxpages < 5: plist = page.page_range # 页码数列表 else: if pIndex <= 3: plist = range(1, 6) elif pIndex >= maxpages - 3: plist = range(maxpages - 4, maxpages + 1) else: plist = range(pIndex - 2, pIndex + 3) context = {"list": list2, 'plist': plist, 'pIndex': pIndex, 'maxpages': maxpages, 'mywhere': mywhere} return render(request, "myadmin/subject/index.html", context)
def insert(request): """执行添加""" mod = Model('teaching') print(request.POST['teacher']) kw = { 'no': request.POST['teacher'], 'subject': request.POST['subject'], 'class': request.POST['class'], } if mod.save(kw) > 0: context = {"info": "添加成功!"} else: context = {"info": "添加失败"} return render(request, "myadmin/info.html", context)
def create_model(self, name, model_object, y, X, model_algo, model_params, tag=""): db = self.fetch_model_db() curr_num = len(db) + 1 name = str(curr_num) + "_" + name #init Dataset model = Model(self.model_export_dir, name, model_object, y, X, model_algo, model_params, tag) #save {name: path} to model db model_path = model.get_model_path() db[name] = model_path self.save_model_db(db) #add to live models self.live_models.append(model) return model
def insert(request): """执行添加""" mod = Model('subject') try: kw = { 'no': request.POST['no'], 'name': request.POST['name'], 'score': request.POST['score'], } if mod.save(kw) > 0: context = {"info": "添加成功!"} else: context = {"info": "添加失败"} except: context = {"info": "添加失败"} return render(request, "myadmin/info.html", context)
def update(request, uid): """执行编辑信息""" mod = Model('teaching') kw = { 'no': uid, 'subject': request.POST['subject'], 'class': request.POST['class'], } try: if mod.update(kw) > 0: context = {"info": "修改成功!"} else: context = {"info": "修改失败"} except Exception as err: print(err) context = {"info": "修改失败"} return render(request, "myadmin/info.html", context)
def main(args): model = Model(0) model.load(args.model_dir) vocabulary = Vocabulary() vocabulary.load(args.vocabulary) multi_chain_gibbs_sampler = MultiChainGibbsSampler(model, vocabulary, args.num_markov_chains, args.total_iterations, args.burn_in_iterations) fp = open(args.documents, 'r') for doc_str in fp.readlines(): doc_str = doc_str.decode('gbk') doc_tokens = doc_str.strip().split('\t') topic_dist = multi_chain_gibbs_sampler.infer_topics(doc_tokens) print doc_str print topic_dist fp.close()
def createCharRNNSequence(cls, input_melody, measureInSec=None, elementsPerMeasure=None): print(input_melody) charSequence = [noteToChord[mel['pitch']] for mel in input_melody] charSequenceInput = ''.join(charSequence) if len(charSequenceInput) < sample: charSequence = charSequenceInput * math.ceil( sample / len(charSequenceInput)) charSequence = charSequence[:sample] tf.reset_default_graph() with open(os.path.join(save_dir, 'config.pkl'), 'rb') as f: saved_args = cPickle.load(f) with open(os.path.join(save_dir, 'chars_vocab.pkl'), 'rb') as f: chars, vocab = cPickle.load(f) model = Model(saved_args, training=False) with tf.Session() as sess: tf.global_variables_initializer().run() saver = tf.train.Saver(tf.global_variables()) ckpt = tf.train.get_checkpoint_state(save_dir) if ckpt and ckpt.model_checkpoint_path: saver.restore(sess, ckpt.model_checkpoint_path) newCharSeq = model.sample(sess, chars, vocab, n, charSequence, sample) print('newCharSeq', newCharSeq, newCharSeq[len(charSequence):]) newCharSeq = newCharSeq[len(charSequence):] newCharSeq = newCharSeq[:len(charSequenceInput)] print(charSequence, newCharSeq) newPitchs = [chordToNote[char] for char in newCharSeq] for idx, pitch in enumerate(newPitchs): input_melody[idx]['pitch'] = pitch return input_melody
def main(args): model = Model(args.num_topics, args.topic_prior, args.word_prior) vocabulary = Vocabulary() vocabulary.load(args.vocabulary_file) sparselda_train_gibbs_sampler = SparseLDATrainGibbsSampler( model, vocabulary) sparselda_train_gibbs_sampler.load_corpus(args.corpus_dir) rand = random.Random() for i in xrange(args.total_iterations): logging.info('sparselda trainer, gibbs sampling iteration %d.' % (i + 1)) sparselda_train_gibbs_sampler.gibbs_sampling(rand) # dump lda model if i == 0 or (i + 1) % args.save_model_interval == 0: logging.info('iteration %d start saving lda model.' % (i + 1)) sparselda_train_gibbs_sampler.save_model(args.model_dir, i + 1) topic_words_stat = TopicWordsStat(model, vocabulary) topic_words_stat.save( '%s/topic_top_words.%d' % (args.model_dir, i + 1), args.topic_word_accumulated_prob_threshold) logging.info('iteration %d save lda model ok.' % (i + 1)) # dump checkpoint if i == 0 or (i + 1) % args.save_checkpoint_interval == 0: logging.info('iteration %d start saving checkpoint.' % (i + 1)) sparselda_train_gibbs_sampler.save_checkpoint( args.checkpoint_dir, i + 1) logging.info('iteration %d save checkpoint ok.' % (i + 1)) # compute the loglikelihood if i == 0 or (i + 1) % args.compute_loglikelihood_interval == 0: logging.info('iteration %d start computing loglikelihood.' % (i + 1)) model_evaluator = ModelEvaluator(model, vocabulary) ll = model_evaluator.compute_loglikelihood( sparselda_train_gibbs_sampler.documents) logging.info('iteration %d loglikelihood is %f.' % (i + 1, ll))