Commit 57d26244 authored by alexjubs's avatar alexjubs
Browse files

filtering v1

parent 2f68d534
......@@ -75,4 +75,44 @@ get_attributes_from_tablename = {
"course_offering_id",
"id"
]
}
attribute_type = {
"course_id": int,
"course_code": str,
"description" : str,
"assessment_id": int,
"course_offering_id": int,
"date": int,
"weight": int,
"assessment_type": str, # enum
"id_assessment" : int,
"id_student" : int,
"date_submitted" : int,
"is_banked" : bool,
"score": int,
"failed": bool,
"course_offering_length_in_days": int,
"year": int,
"semester": str, # enum
"highest_education": str,
"num_of_prev_attempts": int,
"studied_credits": int,
"age_range": str, # enum
"regionid": int,
"education_rank": int,
"gender": str, # enum
"imd_band": int,
"name": str,
"education_level": str,
"id_site": int,
"activity_type": str,
"week_from": int,
"week_to": int,
"id_unregistration": int,
"id_student": int,
"date_unregistration": int,
"id_registration": int,
"date_registration": int,
"interactions": int,
"id": int
}
\ No newline at end of file
......@@ -12,10 +12,14 @@ if __name__ == "__main__":
'''
Welcome to our ECE 356 final project client!
These are our base commands:
insert - inserts an entry into the table
modify - modifies an entry in a table by primary key
delete - deletes a row (or mulitple rows) from the table
get - fetches a set of rows from a table in the DB
These are the more 'user friendly' commands:
''')
while True:
......
import argparse
# the base table specifications - for the table at hand
# ========== INSERT ENTRY SECTION ==========
insert_entry_parser = argparse.ArgumentParser()
insert_entry_parser.add_argument(
"--table",
dest="table",
choices=[
tables=[
"courseInfo",
"assessments",
"studentAssessment",
......@@ -19,7 +13,14 @@ insert_entry_parser.add_argument(
"studentUnregistration",
"studentRegistration",
"studentVle"
],
]
# ========== INSERT ENTRY SECTION ==========
insert_entry_parser = argparse.ArgumentParser()
insert_entry_parser.add_argument(
"--table",
dest="table",
choices=tables,
help="specify the table to perform CRUD on",
required=True
)
......@@ -29,72 +30,27 @@ modify_table_parser = argparse.ArgumentParser()
modify_table_parser.add_argument(
"--table",
dest="table",
choices=[
"courseInfo",
"assessments",
"studentAssessment",
"courseOfferings",
"studentInfo",
"region",
"educationLevel",
"vle",
"studentUnregistration",
"studentRegistration",
"studentVle"
],
choices=tables,
help="specify the table to perform CRUD on",
required=True
)
# ========== DELETE ROW SECTION ==========
delete_row_parser = argparse.ArgumentParser()
delete_row_parser.add_argument(
# ========== DELETE SECTION ==========
delete_rows_parser = argparse.ArgumentParser()
delete_rows_parser.add_argument(
"--table",
dest="table",
choices=[
"courseInfo",
"assessments",
"studentAssessment",
"courseOfferings",
"studentInfo",
"region",
"educationLevel",
"vle",
"studentUnregistration",
"studentRegistration",
"studentVle"
],
choices=tables,
help="specify the table to perform CRUD on",
required=True
)
# ========== GET COURSES SECTION ==========
get_courses_parser = argparse.ArgumentParser()
get_courses_parser.add_argument(
"--course_id",
dest="course_id",
type=int,
help="course id, must be an int"
)
get_courses_parser.add_argument(
"--code_module",
dest="code_module",
help="unique to each module"
)
get_courses_parser.add_argument(
"--year_and_semester",
dest="time",
)
# ========== GET ASSESSMENTS SECTION ==========
get_assessments_parser = argparse.ArgumentParser()
# ========== GET VLE SECTION ==========
get_vle_parser = argparse.ArgumentParser()
# ========== GET STUDENTS SECTION ==========
get_students_parser = argparse.ArgumentParser()
# ========== GET SECTION ==========
get_rows_parser = argparse.ArgumentParser()
get_rows_parser.add_argument(
"--table",
dest="table",
choices=tables,
help="specify the table to perform CRUD on",
required=True
)
\ No newline at end of file
......@@ -38,6 +38,45 @@ def handle_collecting_modify_args(attributes, new_row):
new_row[attributes[i]] = input(f"specify {attributes[i]} (blank space for no change): ")
return 0
def handle_filtering_on_table(attributes, filters):
print(f"applying filters for {attributes}")
int_operators = ["=", ">", "<", ">=", "<=", "<>"]
string_operators = ["LIKE", "="]
bool_operators = ["="]
for i in range(len(attributes)):
should_filter = input(f"apply filter for `{attributes[i]}`? 'y' or 'yes': ")
if should_filter in {'y', 'yes'}:
print(f"Filtering on {attributes[i]}. The type is {attribute_type[attributes[i]]}")
if attribute_type[attributes[i]] == int:
operator = input(f"Enter the operator (in {int_operators}): ")
while operator not in int_operators:
operator = input(f"Enter the operator (in {int_operators}): ")
value = int(input("Enter the filtering value (must be int): "))
if attribute_type[attributes[i]] == str:
print("note: wildcard matching works on 'LIKE' operator")
operator = input(f"Pick an operator ({string_operators}): ")
while operator not in string_operators:
operator = input(f"Pick an operator ({string_operators}): ")
value = input("Enter the filtering value: ")
if attribute_type[attributes[i]] == bool:
operator = input(f"Pick an operator ({bool_operators}): ")
while operator not in bool_operators:
operator = input(f"Pick an operator ({bool_operators}): ")
value = input("Enter the filtering value (1 or 0): ")
while value not in {"0", "1"}:
value = input("Enter the filtering value (1 or 0): ")
filters[attributes[i]] = {
"value" : value,
"operator" : operator
}
else:
filters[attributes[i]] = None
def insert_base_func(command):
insert_entry_args = insert_entry_parser.parse_args(command[1:])
new_row = dict()
......@@ -63,9 +102,25 @@ def modify_base_func(command):
def delete_base_func(command):
delete_row_args = delete_row_parser.parse_args(command[1:])
delete_rows_args = delete_rows_parser.parse_args(command[1:])
filters = dict()
# branch based on the table
handle_filtering_on_table(
attributes=get_attributes_from_tablename[delete_rows_args.table],
filters=filters
)
print(f"DELETING rows from {delete_rows_args.table}: \n {filters} \n")
def get_base_func(command):
pass
get_rows_args = get_rows_parser.parse_args(command[1:])
filters = dict()
# apply filters
handle_filtering_on_table(
attributes=get_attributes_from_tablename[get_rows_args.table],
filters=filters
)
print(f"GETTING rows from {get_rows_args.table}: \n {filters} \n")
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment