#!/usr/local/bin/python
#######################################################
# source code for webdecide.cgi, used with deciderata.cgi below, and also with
# webdecide.html found at http://www.awaretek.com/webdecide.html:
# runs on the server, reads form input, does calculations, prints html;
#######################################################
import cgi
import string
import sys
from string import *
sys.stderr = sys.stdout
form = cgi.FieldStorage() # parse form data
print "Content-type: text/html\n\n" # plus blank line
Options = form['options'].value.split(",")
Criteria = form['criteria'].value.split(",")
Weights = form['weights'].value.split(",")
Criteria = map(lambda x: strip(x), Criteria)
Options = map(lambda x: strip(x), Options)
Weights = map(lambda x: strip(x), Weights)
Criteria = [c for c in Criteria if c != ""]
Options = [option for option in Options if option != ""]
html = "
%s"
text = "Enter your score, or ranking, for each Criteria for each Option, using a number from 1 to 100, with 1 being a low score and 100 being the highest score "
text = text + """"
print html % text
########################################################
#######################################################
#!/usr/local/bin/python
#######################################################
# Second, seperate file; deciderata.cgi to be used with webdecide.cgi above
# and with webdecide.html
#######################################################
import cgi
import string
import sys
from string import *
sys.stderr = sys.stdout
form = cgi.FieldStorage() # parse form data
print "Content-type: text/html\n\n" # plus blank line
Options = form['Options'].value.split(",")
Criteria = form['Criteria'].value.split(",")
Weights = form['Weights'].value.split(",")
Criteria = [c.replace(" ", "") for c in Criteria]
Options = [option.replace(" ", "") for option in Options]
Importance = dict(zip(Criteria, Weights))
scores = {}
results ={}
for option in Options:
value = 0
for c in Criteria:
value = value + int(form[option + "Score" + c].value) * int(Importance[c])
scores[option] = value
html = """ %s """
results = scores.items()
results.sort(lambda x,y: -cmp(x[1], y[1]))
finis = ""
for option, result in results:
finis = finis + "
" + option + " scores " + str(result)
finis = finis +"" + "
" + str((results[0])[0]) + " is the right choice for you to make!"
text = finis
print html % text