Permalink
Browse files

add admin

  • Loading branch information...
Colin Roache
Colin Roache committed May 4, 2010
1 parent 9a333b2 commit a31ba4c19656fab39dd11335d099725c96bf9a10
Showing with 110 additions and 5 deletions.
  1. +27 −2 Server/db.py
  2. +25 −1 Server/dpgp.py
  3. +32 −0 Server/templates/admin/edit.html
  4. +24 −0 Server/templates/admin/index.html
  5. +2 −2 Server/templates/main.html
View
@@ -5,11 +5,36 @@
def getConnection():
return database.Connection("/tmp/mysql.sock", user="root", database="dpgpjs")
def getProblems():
c=getConnection()
problems = [problem for problem in c.query("SELECT * FROM problems")]
for problem in problems:
program = c.query("SELECT * FROM programs WHERE problem = %s ORDER BY fitness DESC LIMIT 1" % problem.id)
if(len(program) != 0):
problem.bestFitness = program[0].fitness
problem.bestProgram = program[0].program_string
else:
problem.bestFitness = "none"
problem.bestProgram = "none"
return problems
def getProblem(problem_id):
c=getConnection()
problem = c.query("SELECT * FROM problems WHERE id = %s" % problem_id)[0]
program = c.query("SELECT * FROM programs WHERE problem = %s ORDER BY fitness DESC LIMIT 1" % problem.id)
if(len(program) < 0):
problem.bestFitness = program.fitness
problem.bestProgram = program[0].program_string
else:
problem.bestFitness = "none"
problem.bestProgram = "none"
return problem
def updateProblem(problem_id,name,comments,start_population,max_population,tournament_size,crossover_probability,mutation_probability,clone_probability):
c=getConnection()
return [problem for problem in c.query("SELECT * FROM problems")]
return c.execute("UPDATE problems SET name = \"%s\", comments = \"%s\", start_population = \"%s\", max_population = \"%s\", tournament_size = \"%s\", crossover_probability = \"%s\", mutation_probability = \"%s\", clone_probability = \"%s\" WHERE id = %s LIMIT 1" % (name, comments, start_population,max_population,tournament_size,crossover_probability,mutation_probability, clone_probability, problem_id))
def getFitnessCases(problem_id):
c=getConnection()
View
@@ -16,6 +16,7 @@ def get(self):
self.render("templates/upload.html")
class UploadFormHandler(tornado.web.RequestHandler):
# TODO: after git merge, switch upload to admin
def get(self):
self.render("templates/error.html")
@@ -32,11 +33,32 @@ def get(self,worker_id):
class WorkerJSHandler(tornado.web.RequestHandler):
def get(self,worker_id):
self.render("templates/gp_worker.js", fitness_cases=db.getFitnessCases(worker_id))
class ResultsUploadHandler(tornado.web.RequestHandler):
def post(self):
# uploadedData = json.loads(self.ge)
print self.request.arguments
class AdminHandler(tornado.web.RequestHandler):
def get(self):
self.render("templates/admin/index.html",problems=db.getProblems())
class AdminEditHandler(tornado.web.RequestHandler):
def get(self,problem_id):
self.render("templates/admin/edit.html",problem=db.getProblem(problem_id))
def post(self,problem_id):
name = self.get_argument('name')
comments = self.get_argument('comments')
start_population = self.get_argument('start_population')
max_population = self.get_argument('max_population')
tournament_size = self.get_argument('tournament_size')
crossover_probability = self.get_argument('crossover_probability')
mutation_probability = self.get_argument('mutation_probability')
clone_probability = self.get_argument('clone_probability')
db.updateProblem(problem_id,name,comments,start_population,max_population,tournament_size,crossover_probability,mutation_probability,clone_probability)
self.render("templates/admin/edit.html", problem=db.getProblem(problem_id))
settings = {"static_path": os.path.join(os.path.dirname(__file__), "static") }
application = tornado.web.Application([
@@ -45,7 +67,9 @@ def post(self):
(r"/new_problem", UploadFormHandler),
(r"/gp_worker([0-9]+)\.js", WorkerJSHandler),
(r"/worker([0-9]+)", WorkerHandler),
(r"/uploadresults", ResultsUploadHandler)
(r"/uploadresults", ResultsUploadHandler),
(r"/admin", AdminHandler),
(r"/admin/edit([0-9]+)", AdminEditHandler)
], **settings)
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>dPGP.js Admin</title>
</head>
<body>
<a href="/">Back to index</a><br/>
<a href="/admin">Back to admin index</a>
<form action="/admin/edit{{ problem.id }}" method="post" accept-charset="utf-8">
<div style="border-style:solid;border-width:2px;padding:3px">
<div>Name: <input type="text" name="name" value="{{ problem.name}}" id="name" /><div>
<div>Comments: <input type="text" name="comments" value="{{ problem.comments }}" id="comments" /></div>
<div>Evaluated Stack: {{ problem.evaluated_stack }}</div>
<div>Start Population: <input type="text" name="start_population" value="{{ problem.start_population }}" id="start_population" /></div>
<div>Max Population: <input type="text" name="max_population" value="{{ problem.max_population }}" id="max_population" /></div>
<div>Tournament Size: <input type="text" name="tournament_size" value="{{ problem.tournament_size }}" id="tournament_size" /></div>
<div>Crossover Probability: <input type="text" name="crossover_probability" value="{{ problem.crossover_probability }}" id="crossover_probability" /></div>
<div>Mutation Probability: <input type="text" name="mutation_probability" value="{{ problem.mutation_probability }}" id="mutation_probability" /></div>
<div>Clone Probability: <input type="text" name="clone_probability" value="{{ problem.clone_probability }}" id="clone_probability" /></div>
<div>Best fitness: {{ problem.bestFitness }}</div>
<div><a href="/worker{{ problem.id }}">Worker link</a></div>
<div><input type="submit" value="Edit"></div>
</div>
</form>
</body>
</html>
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>dPGP.js Admin</title>
</head>
<body>
{% for problem in problems %}
<div style="border-style:solid;border-width:2px;padding:3px">
<div>Name: {{ problem.name }}</div>
<div>Comments: {{ problem.comments }}</div>
<div>Best fitness: {{ problem.bestFitness }}</div>
<div>Best program: {{ problem.bestProgram }}</div>
<div><a href="/worker{{ problem.id }}">Worker link</a></div>
<div><a href="/admin/edit{{ problem.id }}">Edit</a></div>
</div>
{% end %}
</body>
</html>
@@ -15,8 +15,8 @@ <h1>Distributed Push.</h1>
<div style="border-style:solid;border-width:2px;padding:3px">
<div>Name: {{ problem.name }}</div>
<div>Comments: {{ problem.comments }}</div>
<div>Best fitness: undefined</div>
<div>Best fitness: {{ problem.bestFitness }}</div>
<div>Best program: {{ problem.bestProgram }}</div>
<div><a href="/worker{{ problem.id }}">Worker link</a></div>
</div>

0 comments on commit a31ba4c

Please sign in to comment.