summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2009-10-20 20:53:08 -0400
committerJason A. Donenfeld <Jason@zx2c4.com>2009-10-20 20:53:08 -0400
commit9f9425559325a696ca9a8dbbe94e7f526b0d16d1 (patch)
tree20a7da41ef9fa33fa81f856b3900c97370cf660c
parentSupport actors with many roles. (diff)
downloadFramedPrototype-9f9425559325a696ca9a8dbbe94e7f526b0d16d1.tar.xz
FramedPrototype-9f9425559325a696ca9a8dbbe94e7f526b0d16d1.zip
Added statistics interface and added frame to answer store.
-rw-r--r--app.yaml4
-rw-r--r--framed.py72
-rw-r--r--mainpage.html10
3 files changed, 74 insertions, 12 deletions
diff --git a/app.yaml b/app.yaml
index 86c90f5..492fe36 100644
--- a/app.yaml
+++ b/app.yaml
@@ -16,5 +16,9 @@ handlers:
login: admin
script: framed.py
+- url: /statistics
+ login: admin
+ script: framed.py
+
- url: /.*
script: framed.py \ No newline at end of file
diff --git a/framed.py b/framed.py
index bdb6371..e754864 100644
--- a/framed.py
+++ b/framed.py
@@ -16,6 +16,7 @@ class Title(db.Model):
lastThumb = db.IntegerProperty()
class Answer(db.Model):
title = db.ReferenceProperty(Title)
+ frame = db.IntegerProperty()
answer = db.ListProperty(int)
class NewQuestion(webapp.RequestHandler):
@@ -23,18 +24,24 @@ class NewQuestion(webapp.RequestHandler):
self.response.headers['Content-Type'] = 'application/json'
titles = Title.all()
title = titles[randint(0, titles.count() - 1)]
- url = "http://img.anyclip.com/thumbnails/%s/tmb_%s_480.jpg" % (title.code, randint(1, title.lastThumb / 10) * 10) #frame hard-coded for now
+ frame = randint(1, title.lastThumb / 10) * 10
+ url = "http://img.anyclip.com/thumbnails/%s/tmb_%s_480.jpg" % (title.code, frame)
cast = ""
for i in range(len(title.actors)):
if i != 0:
cast += ","
cast += "[\"%s\",\"%s\"]" % (title.actors[i], title.characters[i])
- self.response.out.write("{\"title\":\"%s\",\"code\":\"%s\",\"frame\":\"%s\",\"cast\":[%s]}" % (title.title, title.code, url, cast))
+ self.response.out.write("{\"title\":\"%s\",\"code\":\"%s\",\"frame\":%s,\"image\":\"%s\",\"cast\":[%s]}" % (title.title, title.code, frame, url, cast))
class AnswerQuestion(webapp.RequestHandler):
def get(self):
code = self.request.get("code")
- answer = self.request.get("inframe")
+ answer = self.request.get("answer")
+ frame = self.request.get("frame")
+ try:
+ frame = int(frame)
+ except:
+ return
if code == "" or answer == "":
return
answers = answer.split(",")
@@ -46,13 +53,18 @@ class AnswerQuestion(webapp.RequestHandler):
except:
return
titleQuery = Title.all().filter('code = ', code).fetch(1)
- if len(titleQuery) != 1 or len(answers) == 0 or (answers[i] == -1 and len(answers) > 1):
+ if len(titleQuery) != 1 or len(answers) == 0 or (-1 in answers and len(answers) > 1):
return
+ maxAnswer = len(titleQuery[0].characters)
+ for ans in answers:
+ if ans >= maxAnswer:
+ return
answer = Answer()
answer.title = titleQuery[0]
answer.answer = answers;
+ answer.frame = frame
answer.put()
- self.response.out.write(str(answers) + "<br>" + code);
+ self.response.out.write(str(answers) + "<br>" + code + "<br>" + str(frame));
class LoadNewTitles(webapp.RequestHandler):
def __init__(self):
@@ -119,12 +131,58 @@ class LoadNewTitles(webapp.RequestHandler):
newTitle.actors = cast[0]
newTitle.characters = cast[1]
newTitle.put()
-
+
+class Statistics(webapp.RequestHandler):
+ def get(self):
+ self.response.out.write("<html><head><title>Statistics</title></head><body><h2>Statistics</h2>")
+ query = Answer.all().order("title").order("frame")
+ lastTitle = None
+ lastFrame = -1
+ frameAnswers = []
+ for answer in query:
+ if lastFrame != answer.frame or lastTitle == None or answer.title.key() != lastTitle.key():
+ if len(frameAnswers) != 0:
+ union = None
+ intersection = None
+ for frameAnswer in frameAnswers:
+ if union == None:
+ union = set(frameAnswer)
+ else:
+ union = union.union(set(frameAnswer))
+ if intersection == None:
+ intersection = set(frameAnswer)
+ else:
+ intersection = intersection.intersection(set(frameAnswer))
+ self.response.out.write("<li>Frame %s with %s answers:" % (lastFrame, len(frameAnswers)))
+ self.response.out.write("<ul><li>Union:<ul>")
+ for index in union:
+ if index == -1:
+ self.response.out.write("<li><i>Nobody</i></li>")
+ else:
+ self.response.out.write("<li>%s as %s</li>" % (lastTitle.actors[index], lastTitle.characters[index]))
+ self.response.out.write("</ul></li>")
+ self.response.out.write("<li>Intersection:<ul>")
+ for index in intersection:
+ if index == -1:
+ self.response.out.write("<li><i>Nobody</i></li>")
+ else:
+ self.response.out.write("<li>%s as %s</li>" % (lastTitle.actors[index], lastTitle.characters[index]))
+ self.response.out.write("</ul></li></ul>")
+ frameAnswers = []
+ lastFrame = answer.frame
+ frameAnswers.append(answer.answer)
+ if lastTitle == None or answer.title.key() != lastTitle.key():
+ if lastTitle != None:
+ self.response.out.write("</ul></ul>")
+ lastTitle = answer.title
+ self.response.out.write("<ul><li>%s</li><ul>" % answer.title.title)
+ self.response.out.write("</body></html>");
application = webapp.WSGIApplication(
[('/newquestion', NewQuestion),
('/loadnewtitles', LoadNewTitles),
- ('/answerquestion', AnswerQuestion)],
+ ('/answerquestion', AnswerQuestion),
+ ('/statistics', Statistics)],
debug=True)
def main():
diff --git a/mainpage.html b/mainpage.html
index d198ed4..ac72f7f 100644
--- a/mainpage.html
+++ b/mainpage.html
@@ -22,8 +22,8 @@ function fillQuestionQueue() {
}
var question = eval("(" + requestObj.responseText + ")");
var preloadImage = new Image();
- preloadImage.src = question.frame;
- question.frame = preloadImage;
+ preloadImage.src = question.image;
+ question.image = preloadImage;
questions.push(question);
if (!hasLoadedFirst) {
showNextQuestion();
@@ -42,7 +42,7 @@ function showNextQuestion() {
return;
}
currentQuestion = questions.shift();
- thumbnail.src = currentQuestion.frame.src;
+ thumbnail.src = currentQuestion.image.src;
title.innerHTML = currentQuestion.title;
var checkBoxes = "";
for (var i = 0; i < currentQuestion.cast.length; i++) {
@@ -62,12 +62,12 @@ function answerQuestion() {
alert("Please select the characters in the frame. If you do not know, press skip. If there are none, press none.");
return;
}
- answerObj.open("GET", "/answerquestion?code=" + currentQuestion.code + "&inframe=" + castInFrame.toString());
+ answerObj.open("GET", "/answerquestion?code=" + currentQuestion.code + "&frame=" + currentQuestion.frame.toString() + "&answer=" + castInFrame.toString());
answerObj.send(null);
showNextQuestion();
}
function emptyAnswer() {
- answerObj.open("GET", "/answerquestion?code=" + currentQuestion.code + "&inframe=-1");
+ answerObj.open("GET", "/answerquestion?code=" + currentQuestion.code + "&frame=" + currentQuestion.frame.toString() + "&answer=-1");
answerObj.send(null);
showNextQuestion();
}