Skip to content
This repository has been archived by the owner on Nov 22, 2020. It is now read-only.

Commit

Permalink
functional web interface
Browse files Browse the repository at this point in the history
  • Loading branch information
rouge8 committed May 22, 2010
1 parent dd444e6 commit 64e8f01
Show file tree
Hide file tree
Showing 53 changed files with 11,987 additions and 140 deletions.
Binary file modified 20q.db
Binary file not shown.
138 changes: 0 additions & 138 deletions 20q.py

This file was deleted.

12 changes: 12 additions & 0 deletions BRAINSTORM.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,15 @@ if right:


RENAME VALUE COLUMN IN DATA TO WEIGHT

half weights are positive and half are negative

sum of positives and negatives?
heap: good way of organizing
priority queue based on entropy
define a comparable function

compute entropies on the fly?
IF NOT:
store entropies with question - whenever you change anything with the question, store the weight
e.g. store positives and negatives
13 changes: 13 additions & 0 deletions TODO.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
IMPROVE LEARNING ON WRONG ANSWERS (cutting in half thing?)

adjust weights
ask/add more questions
clean up code (esp. select statements)
question suggestions
"I don't know" option
web interface

CHOOSING QUESTIONS

BETTER PICKING ALGORITHM FOR ANSWERS

2 changes: 1 addition & 1 deletion config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
# config.py

import web
web.config.debug = False
db = web.database(dbn='sqlite', db='20q.db')
debug = False
40 changes: 39 additions & 1 deletion model.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# model.py

import web
#import config
from config import db

def add_object(name, asked_questions = {}):
Expand All @@ -24,7 +25,7 @@ def add_question(question):
objects = get_objects()
for object in objects:
add_data(object.id, question_id)
return question_id

def add_data(object_id, question_id, value=0):
db.insert('data', object_id=object_id, question_id=question_id, value=value)
Expand Down Expand Up @@ -66,3 +67,40 @@ def get_object_by_name(name):
except IndexError:
return None

def get_object_by_id(id):
try:
return db.select('objects', vars=locals(), where='id = $id')[0]
except IndexError:
return None

def get_question_by_id(id):
try:
return db.select('questions', vars=locals(), where='id=$id')[0]
except IndexError:
return None

def get_question_by_text(text):
try:
return db.select('questions', vars=locals(), where='text=$text')[0]
except IndexError:
return None

def get_data_by_question_id(question_id):
try:
return db.select('data', vars=locals(), where='question_id=$question_id')
except IndexError:
return None

def get_data_by_object_id(object_id):
try:
return db.select('data', vars=locals(), where='object_id=$object_id')
except IndexError:
return None

def update_times_played(object_id):
current = db.select('objects', vars=locals(), where='id=$object_id')[0].times_played
try:
db.update('objects', where='id = $object_id', vars=locals(), times_played=current+1)
except TypeError:
current = 0
db.update('objects', where='id = $object_id', vars=locals(), times_played=current+1)
17 changes: 17 additions & 0 deletions templates/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
$def with (page)

<!DOCTYPE html>
<html lang="en">
<head>
<title>20 Questions</title>
<meta charset="utf-8" />
</head>
<body>
<header>
<hgroup>
<h1>Welcome to 20 Questions!</h1>
</hgroup>
</header>
$:page
</body>
</html>
15 changes: 15 additions & 0 deletions templates/guess.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
$def with (chosen)

$if chosen:
<p>I guess....</p>
<h1>$chosen.name</h1>
<p>Was I right?</p>
<form action="/guess/$chosen.id" method="post">
<input type="submit" name="answer" value="yes">
<input type="submit" name="answer" value="no">
</form>
$else:
<p>I've got nothing.</p>
<form action="/guess" method="post">
<input type="submit" name="answer" value="teach me">
</form>
20 changes: 20 additions & 0 deletions templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
$def with (question)


$if question == 'begin':
<h1>Think of a character...</h1>
<br />
<form action="/begin" method="post">
<input type="submit" value="Begin!">
</form>
$elif question:
<p>$question.text</p>
<form action="/answer/$question.id" method="post">
<input type="submit" name="answer" value="yes">
<br / >
<input type="submit" name="answer" value="unsure">
<br />
<input type="submit" name="answer" value="no">
</form>
$else:
<p>I DO NOT KNOW WHAT TO DO HERE. (guess)</p>
9 changes: 9 additions & 0 deletions templates/learn.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<form action="/learn" method="post">
<h1>Who were you thinking of?</h1>
<input type="text" name="name">
<br />
<h2>Suggest a question?</h2>
<input type="text" name="question">
<br />
<input type="submit" value="submit">
</form>
Loading

0 comments on commit 64e8f01

Please sign in to comment.