Commit 6f9f3ca6 authored by Stefan Vercillo's avatar Stefan Vercillo
Browse files

cli

parent 9ba59836
DB_USER=snvercil
DB_PASSWORD=32darklink
DB_HOST=127.0.0.1
DB_NAME=EDUCATION
......@@ -6,6 +6,7 @@ name = "pypi"
[packages]
flask-sqlalchemy = "*"
mysql-connector-python = "*"
sqlalchemy = "*"
[dev-packages]
......
{
"_meta": {
"hash": {
"sha256": "ac278844c905b417e23c2441fe1bb7edcfd7bf297fd020baef88337d7646c070"
"sha256": "53a9b6cd40ded12dfe07a052c8300d69e9e2cbe874dd380b5dd25204c6487cda"
},
"pipfile-spec": 6,
"requires": {
......@@ -241,43 +241,45 @@
},
"sqlalchemy": {
"hashes": [
"sha256:08e39d65b38d4c3f77c4c9bf090b0ba4ec5721a6e0a74b63d2a9781cdcacf142",
"sha256:2019b332cf4f9a513133fdf056dc4cecec7fbae7016ebc574d0f310103eed7ee",
"sha256:261fcb3ff8c59e17ec44f9e61713a44ceaa97ae816da978d5cd1dc2c36f32478",
"sha256:29d10796e5604ab7bc067eda7231a2d2411a51eda43082673641245a49d1c4bb",
"sha256:387365c157e96eceacdd6c5468815ad05a523ba778680de4c8139a029e1fe044",
"sha256:38df997ffa9007e953ad574f2263f61b9b683fd63ae397480ea4960be9bda0fd",
"sha256:3b64f5d1c1d0e5f2ed4aa66f2b65ff6bdcdf4c5cc83b71c4bbf69695b09e9e19",
"sha256:41a02030f8934b0de843341e7014192a0c16ee2726a06da154c81153fbe56b33",
"sha256:4490b10f83cd56ca2cdcd94b140d89911ac331e42a727b79157963b1b04fdd0c",
"sha256:4999b03daa6c9afb9a0bf9e3b8769128ef1880557dacfca86fa7562920c49f6b",
"sha256:525e962af8f25fc24ce019e6f237d49f8720d757a8a56c9b4caa2d91e2c66111",
"sha256:555d56b71f61b4c9fa55fe203fe6e1e561c9385fa97c5849783ae050a89113af",
"sha256:5639800f1cfe751569af2242041b30a08a6c0b9e5d95ed674ec8082d381eff13",
"sha256:5d91dce14ac3347bce301062ca825e7fb7e15c133f3909f15989e94878b1082f",
"sha256:61965abc63c8b54038574698888e91a126753a4bdc0ec001397acb14501834e0",
"sha256:6dd6fa51cf08d9433d28802228d2204e175324f1a284c4492e4af2dd36a2d485",
"sha256:7fdb7b775fb0739d3e71461509f978beb788935bc0aa9e47df14837cb33e5226",
"sha256:83ee7f6fa5faed23996c67044376d46815f65183ad6d744d94d68b18cdef060b",
"sha256:853de08e881dae0305647dd61b4429758f11d1bf02a9faf02793cad44bb2e0d5",
"sha256:b5541355b8d4970753d4f7292f73a320704b20406e06cd29b469d156f0a484d8",
"sha256:b72744fed32ecf2bf786d2e2f6756c04126c323ba939f47177b9722775626889",
"sha256:bb2d8530b7cc94b7fd9341843c3e49b6db48ea22313a8db9df21c41615b5e7b1",
"sha256:bf2c1d64c4ee0f30e08e1844ff0acf3c1b6c4277c0e89ec3e8bf1722d245b108",
"sha256:c3497cd63c5f90112b8882ea4dd694052166f779ce9055cd5c4305e0b76d72d9",
"sha256:c85ead1d17acc5e8b282c578394dba253728bcbcbeb66e4ef0e25f4bab53935a",
"sha256:c90b21360cf14d33c8a004f991aa336c7906a8db825d4ec38722c5ff1c47dada",
"sha256:ca500f30619daf863ab1c66d57d53a0987361a8f3266454290198aabd18f2599",
"sha256:ce4f2b34378561bc2e42635888fe86efe13d104ba1d95b5ca67b4d60d8e53e67",
"sha256:cf3a3c2f32d53a4166b2eb8de35f93bcb640e51c32033024af500017d8e8a8c9",
"sha256:daddcd6ba1706cc5fcc9cfaa913aa4bf331172dc7efd385fe3ee1feae3b513bc",
"sha256:dd041324328cece3ccdf70cfbd71b5ab968e564a22318ffd88b054f5eadeb9be",
"sha256:dfa093bd8ecfceafff62078910178567323005e44fbe4d7933e6cbce4512cea2",
"sha256:e659f256b7d402338563913bdeba53bf1eadd4c09e6f6dc93cc47938f7962a8f",
"sha256:f25c02991e22ddce134ef1093ef5a9d5de448fc87b91432e4f879826e93cd1c7",
"sha256:f667a947378bcb12a371ab38bed1b708f3a682d1ba30176422652082919285a2"
"sha256:0072f9887aabe66db23f818bbe950cfa1b6127c5cb769b00bcc07935b3adb0ad",
"sha256:027f356c727db24f3c75828c7feb426f87ce1241242d08958e454bd025810660",
"sha256:08cfd35eecaba79be930c9bfd2e1f0c67a7e1314355d83a378f9a512b1cf7587",
"sha256:0fc4eec2f46b40bdd42112b3be3fbbf88e194bcf02950fbb88bcdc1b32f07dc7",
"sha256:101d2e100ba9182c9039699588e0b2d833c54b3bad46c67c192159876c9f27ea",
"sha256:15b65887b6c324cad638c7671cb95985817b733242a7eb69edd7cdf6953be1e0",
"sha256:37b46bfc4af3dc226acb6fa28ecd2e1fd223433dc5e15a2bad62bf0a0cbb4e8b",
"sha256:56d9d62021946263d4478c9ca012fbd1805f10994cb615c88e7bfd1ae14604d8",
"sha256:5919e647e1d4805867ea556ed4967c68b4d8b266059fa35020dbaed8ffdd60f3",
"sha256:5a717c2e70fd1bb477161c4cc85258e41d978584fbe5522613618195f7e87d9b",
"sha256:5e9cd33459afa69c88fa648e803d1f1245e3caa60bfe8b80a9595e5edd3bda9c",
"sha256:621854dbb4d2413c759a5571564170de45ef37299df52e78e62b42e2880192e1",
"sha256:78abc507d17753ed434b6cc0c0693126279723d5656d9775bfcac966a99a899b",
"sha256:7dd0502cb091660ad0d89c5e95a29825f37cde2a5249957838e975871fbffaad",
"sha256:804e22d5b6165a4f3f019dd9c94bec5687de985a9c54286b93ded9f7846b8c82",
"sha256:878daecb6405e786b07f97e1c77a9cfbbbec17432e8a90c487967e32cfdecb33",
"sha256:886359f734b95ad1ef443b13bb4518bcade4db4f9553c9ce33d6d04ebda8d44e",
"sha256:9ce960a1dc60524136cf6f75621588e2508a117e04a6e3eedb0968bd13b8c824",
"sha256:ad618d687d26d4cbfa9c6fa6141d59e05bcdfc60cb6e1f1d3baa18d8c62fef5f",
"sha256:c5de7adfb91d351f44062b8dedf29f49d4af7cb765be65816e79223a4e31062b",
"sha256:ceac84dd9abbbe115e8be0c817bed85d9fa639b4d294e7817f9e61162d5f766c",
"sha256:da64423c05256f4ab8c0058b90202053b201cbe3a081f3a43eb590cd554395ab",
"sha256:dc27dcc6c72eb38be7f144e9c2c4372d35a3684d3a6dd43bd98c1238358ee17c",
"sha256:dd49d21d1f03c81fbec9080ecdc4486d5ddda67e7fbb75ebf48294465c022cdc",
"sha256:debaf09a823061f88a8dee04949814cf7e82fb394c5bca22c780cb03172ca23b",
"sha256:e027bdf0a4cf6bd0a3ad3b998643ea374d7991bd117b90bf9982e41ceb742941",
"sha256:e4ddd4f2e247128c58bb3dd4489922874afce157d2cff0b2295d67fcd0f22494",
"sha256:e5f6959466a42b6569774c257e55f9cd85200d5b0ba09f0f5d8b5845349c5822",
"sha256:e89347d3bd2ef873832b47e85f4bbd810a5e626c5e749d90a07638da100eb1c8",
"sha256:e9cc6d844e24c307c3272677982a9b33816aeb45e4977791c3bdd47637a8d810",
"sha256:eb8c993706e86178ce15a6b86a335a2064f52254b640e7f53365e716423d33f4",
"sha256:eeaebceb24b46e884c4ad3c04f37feb178b81f6ce720af19bfa2592ca32fdef7",
"sha256:f3909194751bb6cb7c5511dd18bcf77e6e3f0b31604ed4004dffa9461f71e737",
"sha256:f74d6c05d2d163464adbdfbc1ab85048cc15462ff7d134b8aed22bd521e1faa5",
"sha256:fa2bad14e1474ba649cfc969c1d2ec915dd3e79677f346bbfe08e93ef9020b39",
"sha256:fbc6e63e481fa323036f305ada96a3362e1d60dd2bfa026cac10c3553e6880e9"
],
"version": "==1.4.28"
"index": "pypi",
"version": "==1.4.29"
},
"werkzeug": {
"hashes": [
......
import argparse
import sys
sys.path.insert(0, "..") # import parent folde
from controller import Controller
from error_handler import ErrorHandler
class CliTool:
actions = ["get", 'modify', "insert", "delete"]
def __init__(self) -> None:
self.controller = Controller()
self.__parser__init__()
def __parser__init__(self):
self.parser = argparse.ArgumentParser(description="Process some integers.")
self.parser.add_argument(
"action", help="select an action item from [get, modify, insert, delete]"
)
self.parser.add_argument(
"--relation",
choices=self.controller.relations_list(),
help=f"specify the table to perform action on",
required=True,
)
args = self.parser.parse_args()
print(args)
def run(self):
while True:
self.process_line()
def process_line(self):
line = input()
print("Starting CLI .... ")
CliTool().run()
from models.studentUnregistration import StudentUnregistration
from models.assessments import Assessments
from models.courseOfferings import CourseOfferings
from models.studentAssements import StudentAssessments
from models.studentInfo import StudentInfo
from models.studentRegistration import StudentRegistration
class Controller:
relation_2_class_map = {}
joinable_tables_map = {}
def __init__(self):
self.relation_2_class_map[Assessments.__tablename__] = Assessments
self.relation_2_class_map[CourseOfferings.__tablename__] = CourseOfferings
self.relation_2_class_map[StudentAssessments.__tablename__] = StudentAssessments
self.relation_2_class_map[StudentInfo.__tablename__] = StudentInfo
# self.relation_2_class_map[
# StudentRegistration.__tablename__
# ] = StudentRegistration
# JOINABLE TABLES
self.joinable_tables_map[Assessments.__tablename__] = set(
[StudentAssessments, CourseOfferings]
)
self.joinable_tables_map[CourseOfferings.__tablename__] = set(
[StudentAssessments, Assessments, StudentInfo, StudentRegistration, StudentUnregistration]
) # TODO add course info
self.joinable_tables_map[StudentAssessments.__tablename__] = set(
[Assessments, StudentInfo]
)
self.joinable_tables_map[StudentInfo.__tablename__] = set(
[CourseOfferings, StudentAssessments]
)
def relations_list(self):
return list(self.relation_2_class_map.keys())
import os
import uuid
from sqlalchemy import create_engine
from sqlalchemy.sql.sqltypes import Integer
from sqlalchemy.dialects.postgresql import UUID
from models.base_model import BaseModel
from models import db # import from __init__ file
class Assessments(BaseModel, db.Model):
class Assessments(BaseModel):
__tablename__ = "assessments"
course_offering_id = None
assessment_id = None
assessment_type = None
date = None
weight = None
def __init__(
self,
course_offering_id,
assessment_id,
assessment_type,
date,
weight,
course_offering_id=None,
assessment_id=None,
assessment_type=None,
date=None,
weight=None,
skip_creation=False,
):
self.course_offering_id = course_offering_id
......@@ -29,14 +31,22 @@ class Assessments(BaseModel, db.Model):
@staticmethod
def _get_columns() -> list:
return ["course_offering_id", "assessment_id", "assessment_type", "date", "weight"]
return [
"assessment_id",
"assessment_type",
"course_offering_id",
"date",
"weight",
]
def __as_small_dict__(self):
return {"course_offering_id": str(self.course_offering_id), "assessment_id": str(self.assessment_id)}
return {
"course_offering_id": str(self.course_offering_id),
"assessment_id": str(self.assessment_id),
}
def __repr__(self):
return f"< Assessment id {self.course_offering_id}, num_blobs {self.assessment_id} >"
return f"< Assessment course_offering_id {self.course_offering_id}, assessment_id {self.assessment_id} >"
def __str__(self):
return f"< Assessment id {self.course_offering_id}, num_blobs {self.assessment_id} >"
return f"< Assessment course_offering_id {self.course_offering_id}, assessment_id {self.assessment_id} >"
......@@ -46,8 +46,6 @@ class BaseModel(SQLObject, AbstractBaseClass):
os.environ["PRODUCTION_DB_URI"],
echo=not (os.environ["PRODUCTION"] and os.environ["PRODUCTION"] == "True"),
)
Session = sessionmaker(bind=self.engine)
self.session = Session()
def __as_small_dict__(self):
pass
......
from models.base_model import BaseModel
class CourseInfo(BaseModel):
__tablename__ = "courseInfo"
course_offering_id = None
course_offering_length_in_days = None
semester = None
year = None
def __init__(
self,
course_offering_length_in_days=None,
semester=None,
year=None,
skip_creation=False,
):
self.course_offering_length_in_days = course_offering_length_in_days
self.semester = semester
self.year = year
if not skip_creation:
self._create_self(self)
@staticmethod
def _get_columns() -> list:
return [
"course_offering_length_in_days",
"course_offering_id",
"semester",
"year",
]
def __as_small_dict__(self):
return {
"course_offering_id": self.course_offering_id,
}
def __repr__(self):
return f"< CourseOfferings course_offering_id {self.course_offering_id} >"
def __str__(self):
return f"< CourseOfferings course_offering_id {self.course_offering_id} >"
from models.base_model import BaseModel
class CourseOfferings(BaseModel):
__tablename__ = "courseOfferings"
course_offering_id = None
course_offering_length_in_days = None
semester = None
year = None
def __init__(
self,
course_offering_length_in_days=None,
semester=None,
year=None,
skip_creation=False,
):
self.course_offering_length_in_days = course_offering_length_in_days
self.semester = semester
self.year = year
if not skip_creation:
self._create_self(self)
@staticmethod
def _get_columns() -> list:
return [
"course_offering_length_in_days",
"course_offering_id",
"semester",
"year",
]
def __as_small_dict__(self):
return {
"course_offering_id": self.course_offering_id,
}
def __repr__(self):
return f"< CourseOfferings course_offering_id {self.course_offering_id} >"
def __str__(self):
return f"< CourseOfferings course_offering_id {self.course_offering_id} >"
from models.base_model import BaseModel
class StudentAssessments(BaseModel):
__tablename__ = "studentAssessments"
id_assessment = None
id_student = None
date_submitted = None
is_banked = None
score = None
failed = None
def __init__(
self,
id_student=None,
date_submitted=None,
is_banked=None,
score=None,
failed=None,
skip_creation=False,
):
self.id_student = id_student
self.date_submitted = date_submitted
self.is_banked = is_banked
self.score = score
self.failed = failed
if not skip_creation:
self._create_self(self)
@staticmethod
def _get_columns() -> list:
return [
"id_assessment",
"id_student",
"date_submitted",
"is_banked",
"score",
"failed",
]
def __repr__(self):
return f"< StudentAssessments id_assessment : {self.id_assessment}, id_student : {self.id_student} >"
def __str__(self):
return f"< StudentAssessments id_assessment : {self.id_assessment}, id_student : {self.id_student} >"
from api.models import studentAssements
from models.base_model import BaseModel
class StudentInfo(BaseModel):
__tablename__ = "studentInfo"
id_student = None
highest_education = None
num_of_prev_attempts = None
studied_credits = None
course_offering_id = None
age_range = None
regionid = None
education_rank = None
gender = None
imd_band = None
def __init__(
self,
highest_education=None,
num_of_prev_attempts=None,
studied_credits=None,
course_offering_id=None,
age_range=None,
regionid=None,
education_rank=None,
gender=None,
imd_band=None,
skip_creation=False,
):
self.highest_education = highest_education
self.num_of_prev_attempts = num_of_prev_attempts
self.studied_credits = studied_credits
self.course_offering_id = course_offering_id
self.age_range = age_range
self.regionid = regionid
self.education_rank = education_rank
self.gender = gender
self.imd_band = imd_band
if not skip_creation:
self._create_self(self)
@staticmethod
def _get_columns() -> list:
return [
"id_student",
"highest_education",
"num_of_prev_attempts",
"studied_credits",
"course_offering_id",
"age_range",
"regionid",
"education_rank",
"gender",
"imd_band",
]
def __as_small_dict__(self):
return {"id_student": self.id_student}
def __repr__(self):
return f"< StudentInfo id_student {self.id_student} >"
def __str__(self):
return f"< StudentInfo id_student {self.id_student} >"
from models.base_model import BaseModel
class StudentRegistration(BaseModel):
__tablename__ = "studentRegistration"
id_registration = None
id_student = None
date_registration = None
course_offering_id = None
def __init__(
self,
id_student=None,
date_registration=None,
course_offering_id=None,
skip_creation=False,
):
self.id_student = id_student
self.date_registration = date_registration
self.course_offering_id = course_offering_id
if not skip_creation:
self._create_self(self)
@staticmethod
def _get_columns() -> list:
return [
"id_registration",
"id_student",
"date_registration",
"course_offering_id",
]
def __as_small_dict__(self):
return {"id_student": self.id_student}
def __repr__(self):
return f"< StudentRegistration id_registration : {self.id_registration}, id_student : {self.id_student}>"
def __str__(self):
return f"< StudentRegistration id_registration : {self.id_registration}, id_student : {self.id_student}>"
from models.base_model import BaseModel
class StudentUnregistration(BaseModel):
__tablename__ = "studentUnregistration"
id_unregistration = None
id_student = None
date_unregistration = None
course_offering_id = None
id_registration = None
def __init__(
self,
id_student=None,
date_unregistration=None,
course_offering_id=None,
id_registration=None,
skip_creation=False,
):
self.id_student = id_student
self.date_unregistration = date_unregistration
self.id_registration = id_registration
self.course_offering_id = course_offering_id
if not skip_creation:
self._create_self(self)
@staticmethod
def _get_columns() -> list:
return [
"id_unregistration",
"id_student",
"date_unregistration",
"course_offering_id",
"id_registration",
]
def __as_small_dict__(self):
return {"id_student": self.id_student}
def __repr__(self):
return f"< studentUnregistration id_unregistration : {self.id_registration}, id_student : {self.id_student}>"
def __str__(self):
return f"< studentUnregistration id_unregistration : {self.id_registration}, id_student : {self.id_student}>"
import mysql.connector
# import MySQLdb._mysql
import sys
sys.path.insert(0, "../..")
from utils.app_config import AppConfig
......
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