def add(request): # if get_client_ip(request) != "162.243.149.218": # return HttpResponse("NO AUTH\n"); package = request.POST['package'] repo = request.POST['repo'] try: r = Result.objects.get(package=package, repo__name=repo) except Result.DoesNotExist: rep = Repo.objects.get(name=repo) r = Result(package=package, repo=rep) r.status = -1 r.save() return HttpResponse("OK")
def class_result_update(request, slug): subject = Subject.objects.get(slug=slug) if request.user != subject.teacher.user: return HttpResponse( "<h1>You are not allowed to access the given details<h1>") students = Student.objects.filter( current_standard=subject.standard).order_by('roll_number') examinations = Examination.objects.filter(standard=subject.standard) if request.method == 'POST': for student in students: for examination in examinations: exam = examination.name result = Result.objects.get(student=student, subject=subject, examination=examination) x = str(student.roll_number) + " " + exam.name marks = request.POST.get(x) try: result.marks_secured = int(marks) except: result.marks_secured = None result.save() return redirect('teachers:home') results = {} for student in students: results[student] = {} for examination in examinations: try: result = Result.objects.get(student=student, subject=subject, examination=examination) except Result.DoesNotExist: result = Result(student=student, subject=subject, examination=examination) result.save() results[student][examination] = result my_dict = { 'results': results, 'subject': subject, 'students': students, 'examinations': examinations, 'size': str(len(examinations)) } return render(request, 'teachers/update_result.html', context=my_dict)
def valid_result_given_debate(debate): result = Result(debate=debate) result.ogsp1, result.ogsp2 = 90, 90 result.oosp1, result.oosp2 = 80, 80 result.cgsp1, result.cgsp2 = 70, 70 result.cosp1, result.cosp2 = 60, 60 result.og, result.oo, result.cg, result.co = 3, 2, 1, 0 result.save() return result
def publish(request, qid): try: Naire = Questions() Naire.clean() Naire.qid = qid Naire.read(get_object_or_404(Questionnaire, pk=qid).contents) result = [] for x in xrange(1,Naire.count+1): if Naire.questionList[x-1].qtype == 'single': result.append([str(request.POST[str(x)])]) elif Naire.questionList[x-1].qtype == 'multiply': rlist = request.REQUEST.getlist(str(x)) if len(rlist)==0: raise Exception() m = [] for r in rlist: m .append(r) result.append(m) elif Naire.questionList[x-1].qtype == 'judge': result.append([str(request.POST[str(x)])]) elif Naire.questionList[x-1].qtype == 'essay': if str(request.POST[str(x)]) != '' or str(request.POST[str(x)]) !=' ': result.append([str(request.POST[str(x)])]) auth = Authentication(request) user = auth.get_user() if user == None: user = "******" Questionnaire_answered = Questionnaire.objects.get(pk=qid) r = Result(questionnaire_id=Questionnaire_answered,participant_id=user,answer=str(result)) #print str(result) r.save() return render(request, "homepage/message.html", {"message": AlertMessage("success", "Success!", "You have already posted your answers", "/naire"+str(qid)+"/results"),}) except: q = get_object_or_404(Questionnaire, pk=qid) Naire = Questions() Naire.clean() Naire.qid = qid Naire.read(get_object_or_404(Questionnaire, pk=qid).contents) return render(request, 'results/answer.html',{'Questionnaire':q ,'naire':Naire ,'qid':qid, 'errorMsg':'Not finished yet!'})
def brand_by_brand(request): current = 'brand' child = 'brand' if request.method == 'POST': sinfo = request.POST['begin_date'] start = datetime.date(int(sinfo[:4]), int(sinfo[4:6]), int(sinfo[6:])) einfo = request.POST['end_date'] real_end = datetime.date(int(einfo[:4]), int(einfo[4:6]), int(einfo[6:])) end = real_end + datetime.timedelta(days=1) else: start = datetime.datetime.now().date() real_end = start end = real_end + datetime.timedelta(days=1) lastest_day = start brands = Brand.objects.all() for brand in brands: brand.rank = -1 results = brand.results.filter(update_time__range=(start, end)) if results: x = 0 num = 0 for r in results: num += 1 x += int(r.result['pop_rank']) x /= num brand.rank = x brand.ranks = [] brand.hots = [] brand.blog_s = [] brand.mblog_s = [] #for rank and hot for rank_key in brand.rank_keys.all(): results = rank_key.results.filter(update_time__range=(start, end)) if results: x = Result(rankkey = rank_key, update_time = start, result = {'baidu_rank' : 0, 'google_rank' : 0}) b_num = 0 g_num = 0 for r in results: if r.result['baidu_rank'] != -1: x.result['baidu_rank'] += r.result['baidu_rank'] b_num += 1 if r.result['google_rank'] != -1: x.result['google_rank'] += r.result['google_rank'] g_num += 1 if b_num == 0: x.result['baidu_rank'] = -1 else: x.result['baidu_rank'] /= b_num if g_num == 0: x.result['google_rank'] = -1 else: x.result['google_rank'] /= g_num brand.ranks.append(x) for hot_key in brand.hot_keys.all(): results = hot_key.results.filter(update_time__range=(start, end)) if results: x = Result(hotkey = hot_key, update_time = start, result = {'baidu_hot' : 0, 'google_hot' : 0}) b_num = 0 g_num = 0 for r in results: if r.result['baidu_hot'] != -1: x.result['baidu_hot'] += r.result['baidu_hot'] b_num += 1 if r.result['google_hot'] != -1: x.result['google_hot'] += r.result['google_hot'] g_num += 1 if b_num == 0: x.result['baidu_hot'] = -1 else: x.result['baidu_hot'] /= b_num if g_num == 0: x.result['google_hot'] = -1 else: x.result['google_hot'] /= g_num brand.hots.append(x) # for miniblogs for mblog in brand.mblogs.all(): results = mblog.results.filter(update_time__range=(start, end)) if results: x = Result(mblog = mblog, update_time = start, result = { 'followers' : 0, 'friends' : 0, 'statuses' : 0}) num = 0 for r in results: num += 1 x.result['followers'] += int(r.result['followers']) x.result['friends'] += int(r.result['friends']) x.result['statuses'] += int(r.result['statuses']) x.result['followers'] /= num x.result['friends'] /= num x.result['statuses'] /= num brand.mblog_s.append(x) #for Blogs information for blog in brand.blogs.all(): results = blog.results.filter(update_time__range=(start, end)) if results: x = Result(blog = blog, update_time = start, result = { 'grade' : 0, 'score' : 0, 'pv' : 0, 'fans': 0}) num = 0 for r in results: num += 1 x.result['grade'] += int(r.result['grade']) x.result['score'] += int(r.result['score']) x.result['pv'] += int(r.result['pv']) x.result['fans'] += int(r.result['fans']) x.result['grade'] /= num x.result['score'] /= num x.result['pv'] /= num x.result['fans'] /= num brand.blog_s.append(x) title = [u'品牌', u'排名(谷/百)', u'热度(谷/百)', u'微博(粉/关/博)', u'博客(等/粉/分/pv)', u'网站排名'] f = Workbook() s = f.add_sheet('Data') if start == real_end: s.write(0, 0, start.strftime("%Y-%m-%d")) else: s.write(0, 0, start.strftime("%Y-%m-%d") + "-" + real_end.strftime("%Y-%m-%d")) for col, t in enumerate(title): s.write(1, col, t) for row, brand in enumerate(brands): s.write(row+2, 0, brand.brand_name) str = '' for rank in brand.ranks: str += '%s(%s/%s)\n' % (rank.rankkey.keyword, rank.result["google_rank"], rank.result["baidu_rank"]) s.write(row+2, 1, str) str = '' for hot in brand.hots: str += '%s(%s/%s)\n' % (hot.hotkey.keyword, hot.result["google_hot"], hot.result["baidu_hot"]) s.write(row+2, 2, str) str = '' for mblog in brand.mblog_s: str += '%s(%s/%s/%s)\n' % (mblog.mblog.type, mblog.result["followers"], mblog.result["friends"], mblog.result["statuses"]) s.write(row+2, 3, str) str = '' for blog in brand.blog_s: str += '%s(%s/%s/%s/%s)\n' % (blog.blog.type, blog.result["grade"], blog.result["fans"], blog.result["score"], blog.result["pv"]) s.write(row+2, 4, str) s.write(row+2, 5, brand.rank) f.save('/Users/Pioneer/www/markpro/media/brands_by_brand.xls') f.save(TemporaryFile()) return { 'brands' : brands, 'current' : current, 'child' : child, 'start' : start, 'end': real_end}
def valid_result_with_debate(): debate = valid_debate() debate.save() result = Result(debate=debate) result.og = 0 result.oo = 1 result.cg = 2 result.co = 3 result.ogsp1 = 65 result.ogsp2 = 66 result.oosp1 = 67 result.oosp2 = 68 result.cgsp1 = 69 result.cgsp2 = 70 result.cosp1 = 71 result.cosp2 = 72 result.save() return result
def load_data_results(electiondate_arg, live_arg, test_arg, all_arg): ## load from ResultStage... results = ResultStage.objects.filter(electiondate=electiondate_arg) ## ...unless for some reason there are none there, then load via Elex if all_arg and results.count() == 0: results = election_connection(electiondate_arg, live_arg, test_arg).results # elif not all_arg and results.count() == 0: ## load from json # from subprocess import call # import json # import os # file_path = os.environ["SAVER_PATH"] # json_file = file_path + "/tmp/results.json" # results = json.loads(json_file) # mcc_id = unicode(result_item.candidateid) + '-' + unicode(result_item.reportingunitid) + '-' + unicode(result_item.level) result_list = [ ## this one uses datetime_parser Result( dataentry="automated", datasource="Associated Press", ballotorder=result_item.ballotorder, candidateid=result_item.candidateid, # delegatecount=result_item.delegatecount, description=result_item.description, electiondate=result_item.electiondate, fipscode=result_item.fipscode, first=result_item.first, # id=mcc_id, # unique_id=result_item.unique_id, incumbent=result_item.incumbent, initialization_data=result_item.initialization_data, is_ballot_measure=result_item.is_ballot_measure, last=result_item.last, level=result_item.level, # mccelectionid=mccelectionid_constructor, national=result_item.national, officeid=result_item.officeid, officename=result_item.officename, party=result_item.party, polid=result_item.polid, polnum=result_item.polnum, precinctsreporting=result_item.precinctsreporting, precinctsreportingpct=result_item.precinctsreportingpct, precinctstotal=result_item.precinctstotal, raceid=result_item.raceid, racetype=result_item.racetype, racetypeid=result_item.racetypeid, reportingunitid=result_item.reportingunitid, reportingunitname=result_item.reportingunitname, runoff=result_item.runoff, seatname=result_item.seatname, seatnum=result_item.seatnum, statename=result_item.statename, statepostal=result_item.statepostal, test=result_item.test, uncontested=result_item.uncontested, lastupdated=result_item.lastupdated, votecount=result_item.votecount, votepct=result_item.votepct, winner=result_item.winner) for result_item in results ] results_length = len(result_list) ## bulk create method Result.objects.bulk_create(result_list) # import pdb; pdb.set_trace() message = "Loaded:\t\t\t" + str(results_length) + " results" slackbot(message)
def publish(request, qid): try: Naire = Questions() Naire.clean() Naire.qid = qid q = get_object_or_404(Questionnaire, pk=qid) if q.closed or not q.released: return render(request, "homepage/message.html", {"message": AlertMessage("danger", "Page 404!", "You have no right to answer this questionnaire!", "/"),}) auth = Authentication(request) user = auth.get_user() if q.anonymous_limit and user == None: return render(request, "homepage/message.html", {"message": AlertMessage("danger", "Page 404!", "You have no right to answer this questionnaire!", "/"),}) elif user != None: if q.permitobjects_limit != '[]': limitlist = eval(q.permitobjects_limit) if user.email in limitlist: pass else: return render(request, "homepage/message.html", {"message": AlertMessage("danger", "Page 404!", "You have no right to answer this questionnaire!", "/"),}) if q.forbidobjects_limit != '[]': limitlist = eval(q.forbidobjects_limit) if user.email not in limitlist: pass else: return render(request, "homepage/message.html", {"message": AlertMessage("danger", "Page 404!", "You have no right to answer this questionnaire!", "/"),}) rts = Result.objects.filter(questionnaire_id=qid) for r in rts: if r.participant_id == user.email: return render(request, "homepage/message.html", {"message": AlertMessage("warning", "Don't answer same naire twice!", "You've already answered this Questionnaire", "/"),}) Naire.read(q.contents) result = [] for x in xrange(1,Naire.count+1): if Naire.questionList[x-1].qtype == 'single': result.append([str(request.POST[str(x)])]) elif Naire.questionList[x-1].qtype == 'multiply': rlist = request.REQUEST.getlist(str(x)) if len(rlist)==0: raise Exception() m = [] for r in rlist: m .append(r) result.append(m) elif Naire.questionList[x-1].qtype == 'judge': result.append([str(request.POST[str(x)])]) elif Naire.questionList[x-1].qtype == 'essay': if str(request.POST[str(x)]) != '' or str(request.POST[str(x)]) !=' ': result.append([str(request.POST[str(x)])]) email = '' if user == None: email = "*****@*****.**" Questionnaire_answered = Questionnaire.objects.get(pk=qid) r = Result(questionnaire_id=Questionnaire_answered,participant_id=email,answer=str(result)) r.save() print email return render(request, "homepage/message.html", {"message": AlertMessage("success", "Success!", "You have already posted your answers", "/naire"+str(qid)+"/results"),}) elif user != None: rts = Result.objects.filter(questionnaire_id=qid) for r in rts: if r.participant_id == user.email: print user.email return render(request, "homepage/message.html", {"message": AlertMessage("warning", "Don't answer same naire twice!", "You've already answered this Questionnaire", "/"),}) Questionnaire_answered = Questionnaire.objects.get(pk=qid) r = Result(questionnaire_id=Questionnaire_answered,participant_id=user.email,answer=str(result)) r.save() print user.email return render(request, "homepage/message.html", {"message": AlertMessage("success", "Success!", "You have already posted your answers", "/naire"+str(qid)+"/results"),}) except: q = get_object_or_404(Questionnaire, pk=qid) Naire = Questions() Naire.clean() Naire.qid = qid Naire.read(get_object_or_404(Questionnaire, pk=qid).contents) # print 'f**k' return render(request, 'results/answer.html',{'Questionnaire':q ,'naire':Naire ,'qid':qid, 'errorMsg':'Not finished yet!'})