def daily(): username = session['username'] user = User.objects(user=username).first() today = date.today() wordlearned = Count.objects(user=user.user, create_at=today).all() wordlist = [] countwords = Count.objects(user=user.user).all() for word in countwords: if word.word not in wordlist: wordlist.append(word.word) length = len(wordlist) quests = { '0': "(daily)Sign in evertday--5 points", '1': "(daily)Learn 10 more words--5 points", '2': "(daily)Learn 20 more words--15 points", '3': "(daily)Learn 50 more words--30 poitns", "4": "(only once)Acomplish collections of 100 words -- 100 points", "5": "(only once)Acomplish collections of 500 words -- 500 points" } return (render_template("daily.html", quests=quests, username=user.user, times=user.times, wordlearned=len(wordlearned), wordcollect=length))
def bonus(): username = session['username'] index = request.form['index'] today = date.today() user = User.objects(user=username).first() tasks = Task.objects(index=index, user=username, create_at=today).all() oncetasks = Task.objects(index=index, user=username).all() words = Count.objects(user=user.user, create_at=today).all() wordlist = [] countwords = Count.objects(user=user.user).all() for word in countwords: if word.word not in wordlist: wordlist.append(word.word) length = len(wordlist) if index == '0': if len(tasks) == 0: user.update(times=user.times + 5) Task(user=username, index=index).save() return jsonify({'status': '1'}) elif index == '1': if len(words) >= 10 and len(tasks) == 0: user.update(times=user.times + 5) Task(user=username, index=index).save() return jsonify({'status': '1'}) elif index == '2': if len(words) >= 20 and len(tasks) == 0: user.update(times=user.times + 15) Task(user=username, index=index).save() return jsonify({'status': '1'}) elif index == '3': if len(words) >= 50 and len(tasks) == 0: user.update(times=user.times + 30) Task(user=username, index=index).save() return jsonify({'status': '1'}) elif index == '4' and len(oncetasks) == 0: if length >= 100: Task(user=username, index=index).save() user.update(times=user.times + 100) return jsonify({'status': '1'}) elif index == '5' and len(oncetasks) == 0: if length >= 500: Task(user=username, index=index).save() user.update(times=user.times + 100) return jsonify({'status': '1'}) return jsonify({'status': '0'})
def post(self, request): context = {"form": ""} user = User.objects.get(id=request.user.id) form = NewMRFForm(request.POST) if form.is_valid(): requisition_number = form.cleaned_data['requisition_number'] department = form.cleaned_data['department'] designation = form.cleaned_data['designation'] specialization = form.cleaned_data['specialization'] manager = form.cleaned_data['manager'] count = form.cleaned_data['count'] position = Position.objects.filter(department=department, designation=designation, specialization=specialization) requisitionnocheck = MRF.objects.filter( requisition_number=requisition_number) if position and not requisitionnocheck: MRF(requisition_number=requisition_number, position=position[0], manager=manager).save() mrf = MRF.objects.filter(requisition_number=requisition_number) Count(requisition_number=mrf[0], recruiter=user, count=count).save() context['success'] = "Requsition number saved" else: context['error'] = "Requsition number is already present." context["form"] = form return render(request, "newmrfform.html", context)
def update_province_area_state(res): """ 更新各省级数据 :return: """ now = datetime.now().strftime("%Y-%m-%d %H:%M:%S") data = session.query(Count).filter(Count.area_type == 'province').all() map_data = {} for count in data: map_data[count.area_name] = count for o in res: comment = o['comment'] key = o['provinceShortName'] count = map_data.get(key) if not count: count = Count() count.from_source = 'dxy' count.area_name = key count.area_type = 'province' count.province = key session.add(count) json_to_model(count, o) if comment != '': num_data = format_data(comment) filter_data(num_data, count) count.update_time = now session.commit()
def mywordlist(): if 'username' in session: username = session['username'] user = User.objects(user=username).first() wordlist = [] words = Count.objects(user=user.user).all() for word in words: if word.word not in wordlist: wordlist.append(word.word) wordlist.sort() return (render_template("mywordlist.html", words=wordlist, length=len(wordlist), username=user.user, times=user.times))
def redirect_to_old(alias): new = Url.query.filter_by(alias=alias).first() if new is None: abort(404) else: new.counts += 1 date = int(datetime.datetime.today().strftime('%Y%m%d')) count = Count.query.filter_by(url_id=new.id, date=date).first() if count is None: count = Count(url_id=new.id, date=date) else: count.counts += 1 db.session.add_all([new, count]) db.session.commit() return redirect(new.origin)
def update_count(date, count): """ Returns False if already in datastore and has the same count """ c = Count.get_by_key_name(str(date)) if not c: c = Count(key_name=str(date)) else: if c.count == count: return False c.count = count c.date = date c.put() return True
def save_country_data(res): """ 保存全国的数据 :return: """ count = session.query(Count).filter(Count.area_name == '全国').first() if not count: count = Count() count.area_type = 'country' count.area_name = '全国' count.from_source = 'dxy' session.add(count) filter_data(res, count) now = datetime.now().strftime("%Y-%m-%d %H:%M:%S") count.update_time = now session.commit()
def post(self, request): context = {"form": ""} form = MRFForm(request.POST) user = User.objects.get(id=request.user.id) if form.is_valid(): requisition_number = form.cleaned_data['requisition_number'] count = form.cleaned_data['count'] mrfentry = Count.objects.filter( requisition_number=requisition_number, recruiter=request.user.id) if mrfentry: mrfentry = mrfentry[0] mrfentry.count = count mrfentry.save() context['success'] = "Requsition number updated" else: Count(requisition_number=requisition_number, recruiter=user, count=count).save() context['success'] = "Requsition number updated" context["form"] = form return render(request, "mrfform.html", context)
def update_city_area_state(res): data = session.query(Count).filter(Count.area_type == 'city').all() map_data = {} now = datetime.now().strftime("%Y-%m-%d %H:%M:%S") for count in data: map_data["city_" + count.province + "_" + count.area_name] = count for province in res: cities = province['cities'] province = province['provinceShortName'] for city in cities: city_key = city['cityName'] city_count = map_data.get("city_" + province + "_" + city_key) if not city_count: city_count = Count() city_count.from_source = 'dxy' city_count.area_name = city_key city_count.area_type = 'city' city_count.province = province session.add(city_count) json_to_model(city_count, city) city_count.update_time = now session.commit()
def get(self): changesets = Changeset.all().order('-created_at').fetch(20) counts = Count.all().order('-date').fetch(30) counts_list = [c.count for c in counts] counts_list.reverse() counts_list_str = ','.join(map(str,counts_list)) config = get_config() description = Description.get_or_insert('description').text options = { 'url': self.request.url, 'config': config, 'changesets': changesets, 'description': description, } if counts_list: options.update({ 'counts_list': counts_list_str, 'max_count': max(counts_list), 'average': sum(counts_list)/len(counts_list), }) path = os.path.join(os.path.dirname(__file__), 'templates/index.html') page = template.render(path,options) self.response.out.write(page)
def __init__(self, model=None): self.app_conf = db_conn() self.model = model or Count.select()
def set_c3(i): count_list = Count.query().fetch() count_list[0].c3 = i count_list[0].put() return
def get_c3(): count_list = Count.query().fetch() return count_list[0].c3
def index(): if 'username' in session: wordindex = request.args.get('wordindex') username = session['username'] user = User.objects(user=username).first() if user.times < 0: return (render_template("recharge.html", username=user.user, times=user.times)) else: user.update(times=user.times - 1) questlists = pd.read_json(Result.objects().to_json()) wordroot = pd.read_json(Roots.objects().to_json())['root'] rlength = len(wordroot) length = len(questlists['word']) if wordindex == None: num1 = random.randint(0, length - 1) else: num1 = questlists[( questlists.word == wordindex)].index.tolist()[0] question = questlists.take([num1]) word = question['word'][num1] hints = question['hint'][num1] #roots roots = question['root'][num1].strip('[').strip(']') roots = roots.split(',') root2 = [] for root in roots: root = root.strip(" ") root2.append(root.strip().strip("'").strip('"')) answers = "".join(root2) while len(root2) <= 5: num2 = random.randint(0, rlength - 1) temword = wordroot[num2] if temword not in root2: root2.append(temword) root2.sort() Count(word=word, user=user.user).save() #wordcounts wordcounts = len(Count.objects(word=word).all()) #hints th = hints.split(']') com = (th[0]).split(';') t1 = com[0].split('[') t2 = com[-1].split('→') wordg = '' for i in range(len(word)): wordg += '_ ' component = [wordg, t1[1]] for c in com[1:-1]: component.append(c) for t in t2: component.append(t) hint = th[1].split('。') today = date.today() wordlearned = len( Count.objects(user=user.user, create_at=today).all()) return (render_template("index.html", word=word, roots=root2, component=component, hints=hint, itemid=num1, answer=question['origin'][num1], wordcounts=wordcounts, answers=answers, username=user.user, times=user.times, wordlearned=wordlearned)) else: return render_template('login.html')