Exemplo n.º 1
0
def modify_DF():
    """
		Replace a DF by a new DF
		:return: None
		"""
    print("old DF:\n")
    table_name = input("enter name of the table: ")
    lhs_tmp = input(
        "enter attributes on the left hand side separated by space: ")
    lhs = convert_lhs_to_array(lhs_tmp)
    rhs = input("enter one attribute on the right hand side: ")
    old_df = df.df(table_name, lhs, rhs)
    if isInDFList(old_df) == True:
        cursor = config.connection.cursor()
        cursor.execute(
            '''DELETE FROM FuncDep WHERE table_name = ? AND lhs = ? AND rhs = ?''',
            (table_name, lhs_tmp, rhs))
        removeFromDFList(old_df)
        print("new DF:\n")
        table_name = input("enter name of the table: ")
        lhs_tmp = input(
            "enter attributes on the left hand side separated by space: ")
        lhs = convert_lhs_to_array(lhs_tmp)
        rhs = input("enter one attribute on the right hand side: ")
        new_df = df.df(table_name, lhs, rhs)
        cursor.execute('''INSERT INTO FuncDep VALUES ( ? , ? , ?)''',
                       (table_name, lhs_tmp, rhs))
        #adding df to local storage
        config.all_dfs.append(new_df)
        config.connection.commit()
    else:
        print("Error : DF not found, can't replace it\n")
Exemplo n.º 2
0
def init():
    """
	Opens the connection to the database and reads all the DFs from the FuncDep table
		If the FuncDep table is not found, it creates it
	:return: None
	"""

    print(">>SGBD")
    #user has to enter the name of the database
    database = input("Enter the name of the database : ")
    #database="database"
    print("Type 'Help' to see a list of available commands")
    #creates a connection with the database
    config.connection = sqlite3.connect(database + '.db')

    cursor = config.connection.cursor()
    try:
        cursor.execute("SELECT * FROM FuncDep")
    except sqlite3.OperationalError:
        cursor.execute("""CREATE TABLE FuncDep(
							'table_name' text,
							'lhs' text,
							'rhs' text
			)""")
    #commits changes
    config.connection.commit()
    raw_data = cursor.fetchall()
    for i in range(len(raw_data)):
        table_name = raw_data[i][0]
        lhs = convert_lhs_to_array(raw_data[i][1])
        rhs = raw_data[i][2]
        config.all_dfs.append(df.df(table_name, lhs, rhs))
    #run the application until user wants to quit it
    runApp()
Exemplo n.º 3
0
def add_DF():
    """
		Allows the user to add a new DF to the database
		:return: None
		"""
    print("adding a new functional dependency: table_name lhs->rhs\n")
    table_name = input("enter name of the table: ")
    lhs_tmp = input(
        "enter attributes on the left hand side separated by space: ")
    lhs = convert_lhs_to_array(lhs_tmp)
    rhs = input("enter one attribute on the right hand side: ")
    new_df = df.df(table_name, lhs, rhs)
    if canAdd(new_df) == True:
        #adding df to local storage
        config.all_dfs.append(new_df)
        print(len(config.all_dfs))
        print(
            "===============================================\nYou added the following functional dependency:"
        )
        print(new_df.print_me())
        #adding df to database
        cursor = config.connection.cursor()
        cursor.execute('''INSERT INTO FuncDep VALUES (? , ? ,?)''',
                       (table_name, lhs_tmp, rhs))
        config.connection.commit()
    else:
        print("Can't add DF, Attributes are not in table " +
              new_df.table_name + "\n")
Exemplo n.º 4
0
def show_all_DF_not_satisfied():
	"""
	return a list of all the unsatisfied DF in the all_dfs
	:return: List of all the unsatisfied DF
	"""
	not_satisfied=[]
	for i in range(len(config.all_dfs)):
		if(not verify_DF_satisfied(config.all_dfs[i])):
			not_satisfied.append(df.df(config.all_dfs[i].table_name,config.all_dfs[i].lhs,config.all_dfs[i].rhs))		
	return not_satisfied
Exemplo n.º 5
0
def delete_DF():
    """
		Allows the user to delete a DF from the database
		:return: None
		"""
    print("delete a functional dependency\n")
    table_name = input("enter name of the table : ")
    lhs_tmp = input(
        "enter attributes on the left hand side separated by space: ")
    lhs = convert_lhs_to_array(lhs_tmp)
    rhs = input("enter one attribute on the right hand side: ")
    if isInDFList(df.df(table_name, lhs, rhs)) == True:
        cursor = config.connection.cursor()
        cursor.execute(
            '''DELETE FROM FuncDep WHERE table_name = ? AND lhs = ? AND rhs = ?''',
            (table_name, lhs_tmp, rhs))
        config.connection.commit()
        removeFromDFList(df.df(table_name, lhs, rhs))
    else:
        print("Error : DF not found\n")
Exemplo n.º 6
0
def f(x):
    return x * x * x


def integral(a, b):  #3-end
    dx = 1e-5
    intarr = []
    integ = 0
    xarr = []
    for d in np.arange(a, b, dx):
        x0 = d
        x1 = d + dx
        y0 = f(x0)
        integ = integ + y0 * (x1 - x0)
        intarr.append(integ)
        xarr.append(d)
    return xarr, intarr, integ


xarr, intarr, integ = integral(0, 5)
fx = []
dfx, dfxarr, xarr = df.df(5, 0, 5)
print(dfxarr)
print(dfx)
plt.plot(xarr, intarr, label="integral")
plt.plot(xarr1, fx, label="fonksiyon")
plt.plot(xarr1, dfxarr, label="türev")
plt.legend()
plt.show()