""" Updates the Fcui values in the DW based on an input file. """ # Copyright 2005, 2006 EIAO Consoritum # This program is distributed under the terms of the GNU General # Public License. # # This file is part of the European Internet Accessibility Observatory # (EIAO) # # EIAO is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # EIAO is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with EIAO; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, # MA 02110-1301 USA import getopt import getpass import sys import psycopg __author__ = "Christian Thomsen" __maintainer__ = "Christian Thomsen" __version__ = 0.9901 def updateFcuiValues(inputfile, database, user, password): """ Performs the updating of the Fcui values in the DW. inputfile is a string holding the name of the file to read new values from. This file should have a header (which is ignored when updating the values), and lines with the data. Such a line has the barrier compuation name followed by TAB followed by the barrier probability for the first user group folllowed by the barrier probability for the sencond user group and so on until the sixth barrier probability. database is the name of the database holding the DW. user is the name of the database user to connect as. password is the password to use when connecting to the database. """ conn = psycopg.connect(user=user, database=database, password=password) cur = conn.cursor() cur.execute("SET search_path TO eiaodw"); # First we build a dictionary with all the IDs we need. # Then we don't have to look them up each time idmap = {} cur.execute("SELECT DISTINCT BarrierComputationID, BarrierComputationName FROM BarrierComputationVersion_T") results = cur.fetchall() for (id, name) in results: idmap[name] = id # Now we process the input file input = open(inputfile, 'rU', 4096) input.readline() # Ignore the header for line in input.readlines(): line = line.strip() values = line.split("\t") name = values[0] id = idmap[name] for i in range(1,7): cur.execute("UPDATE DisabilityGroupRelevance_Fcui_T SET BarrierProbability=%f WHERE BarrierComputationID=%d AND DisabilityGroupID=%d" % (float(values[i]), id, i-1)) # We're done input.close() conn.commit() cur.close() conn.close() def usage(): """Prints usage information to the standard output stream""" print "python updatefcuivalues [-h | --help] [{-i | --input} INPUTFILE]" print " [{-d | --database} DATABASE]" print " [{-u | --user} USER]" print " [{-p | --password} PASSWORD]" print print "The input file should have the following format:" print " " print " " print "where the Fcui values are given in the order" print "1) Complete failure mode set" print "2) Functional blindness" print "3) Partial sight" print "4) Dyslexia or literacy problems" print "5) Physical disabilities" print "6) Deafness or hard of hearing" print "The first line in the file (the header) is ignored." def main(argv): """The main method of the program. Parses arguments and invokes updateFcuiValues""" database = user = password = None try: opts, args = getopt.getopt(argv, "hd:u:p:i:", ["help", "database", "user", "password", "input"]) except getopt.GetoptError: usage(); sys.exit(1) database = user = password = input = None for opt, arg in opts: if opt in ("-h", "--help"): usage() sys.exit() elif opt in ("-d", "--database"): database = arg elif opt in ("-u", "--user"): user = arg elif opt in ("-p", "--password"): password = arg elif opt in ("-i", "--input"): input = arg else: print "Unknown parameter: %s" % opt if input is None: input = raw_input("Input file: ") if database is None: database = raw_input("Database: ") if user is None: user = raw_input("Username: ") if password is None: password = getpass.getpass() updateFcuiValues(input, database, user, password) if __name__ == "__main__": main(sys.argv[1:])