コード例 #1
0
ファイル: convert_for_R.py プロジェクト: rma/pg_guyton
def main(argv=None):
    """The main() function processes the command-line arguments and then
    converts the simulation results."""
    if argv is None:
        argv = sys.argv
    try:
        try:
            o_short = "o:t:h"
            o_long = ["output=", "time=", "help"]
            opts, args = getopt.getopt(argv[1:], o_short, o_long)
        except getopt.error, msg:
             raise Usage(msg)

        # The default output file.
        out_file = 'results.csv'
        # Which snapshot to record.
        nth_time = 4

        for o, a in opts:
            if o in ("-h", "--help"):
                print __doc__
                return 2
            elif o in ("-o", "--output"):
                out_file = a
            elif o in ("-t", "--time"):
                nth_time = int(a) - 1

        if len(args) != 1 or nth_time < 0 or nth_time > 4:
            print __doc__
            return 2

        p_interest = par_list().index('VV9') + 1
        v_interest = var_list().index('GFR') + 1

        p_name = lambda n: "p_" + n
        v_name = lambda n: "v_" + n
        p_names = map(p_name, par_list()[0:p_interest])
        v_names = map(v_name, var_list()[0:v_interest])

        with open(out_file, 'wb') as output:
            writer = csv.writer(output, delimiter=',')
            writer.writerow(p_names + v_names)

            settings = (writer, p_interest, v_interest, nth_time)
            with open(args[0]) as results:
                count = parse(results, convert, settings, warn=True)

        print count, "simulations were converted."
コード例 #2
0
ファイル: crawler.py プロジェクト: anvisha/codelet
def get_metrics(dirname):
	package_file = open('pypi_list.txt')
	exec(package_file) #package_list is name of the master list of public python modules
	std_package_file = open('std_packages.txt')
	exec(std_package_file) #std_package_list
	babies = crawl_dir(dirname) 
	filenames = []
	excluded=[]
	all_imports = {}
	for (root,f) in babies:
		print f,"hihi"
		file_imports = ip.parse(root+"/"+f)
		filenames.append(f[:-3])
		for m in file_imports.keys():
			if m in package_list or m in std_package_list:
				if m in all_imports:
					all_imports[m] += file_imports[m]
				else:
					all_imports[m] = file_imports[m]
			else:
				excluded.append(m)
	return all_imports
コード例 #3
0
ファイル: import_results.py プロジェクト: rma/pg_guyton
def connect_and_import(results_file, tags, host=None, user=None, password=None,
                       log_per=500):
    """Records the simulation results stored in results_file."""
    # Extract the database name from psql_conf.sh (this bit isn't pretty)
    p = subprocess.Popen(
        "grep '^DBNAME=' psql_conf.sh | sed 's/DBNAME/dbname/'",
        shell=True, stdout=subprocess.PIPE)
    conn_strs = map(lambda s: s.strip(), p.stdout.readlines())

    if host is not None:
        conn_strs.append("host='%s'" % (host,))
    if user is not None:
        conn_strs.append("user='******'" % (user,))
    if password is not None:
        conn_strs.append("password='******'" % (password,))
    conn_string = " ".join(conn_strs)

    try:
        conn = psycopg2.connect(conn_string)
        # The default isolation level is READ_COMMITTED, which is perfect
        cursor = conn.cursor()

        # TODO -- allow the model to be specified on the command line
        model_ID = 1

        # Retrieve parameter IDs
        param_IDs = {}
        cursor.execute("SELECT parameter.name, parameter.id "
                       "FROM parameter INNER JOIN defined_for "
                       "ON (defined_for.model = %s)", (model_ID,))
        for (p_name, p_id) in cursor:
            param_IDs[p_name] = p_id

        # Retrieve variable IDs
        var_IDs = {}
        cursor.execute("SELECT name, id FROM variable")
        for (v_name, v_id) in cursor:
            var_IDs[v_name] = v_id

        # Retrieve tag IDs, creating tags where necessary
        tag_IDs = {}
        if 'Perturbation' not in tags:
            tags.append('Perturbation')
        for tag_name in tags:
            cursor.execute("SELECT id FROM tag WHERE name = %s", (tag_name,))
            result = cursor.fetchone()
            if result is None or len(result) < 1:
                print >> sys.stderr, ("Creating tag '%s'" % (tag_name,))
                cursor.execute("INSERT INTO tag (name, description) "
                    "VALUES (%s, %s) RETURNING id", (tag_name, ''))
                tag_id = cursor.fetchone()[0]
            else:
                tag_id = result[0]
            tag_IDs[tag_name] = tag_id

        info = (cursor, conn, model_ID, param_IDs, var_IDs, tag_IDs, log_per)

        with open(results_file) as results:
            count = parse(results, import_result, info, warn=True)

        print count, "simulations were imported."
        conn.commit()
    except:
        exceptionType, exceptionValue, exceptionTraceback = sys.exc_info()
        sys.exit("%s" % (exceptionValue))
    finally:
        if locals().has_key('conn'):
            conn.close()