added ada

This commit is contained in:
ada-dmitry
2023-12-12 10:58:39 +03:00
parent 3835a1cb80
commit 873072487b
5 changed files with 107 additions and 14 deletions
+11
View File
@@ -0,0 +1,11 @@
{
"python.testing.unittestArgs": [
"-v",
"-s",
"./project",
"-p",
"*test.py"
],
"python.testing.pytestEnabled": false,
"python.testing.unittestEnabled": true
}
+81
View File
@@ -0,0 +1,81 @@
import psycopg2
class data_base:
def __init__(self):
self.db_params = {
"dbname": "postgres",
"user": "myuser",
"password": "qwerty",
"host": "localhost"
}
def connect(self):
return psycopg2.connect(**self.db_params)
def close(self, conn, cur):
if cur:
cur.close()
if conn:
conn.close()
class Employee:
def __init__(self, name, age, salary):
self.name = name
self.age = age
self.salary = salary
def display_info(self):
print(f"Name: {self.name}, Age: {self.age}, Salary: {self.salary}")
def add2db(self):
conn = None
cur = None
try:
conn = self.db.connect()
cur = conn.cursor()
cur.execute("INSERT INTO patient_db (pat_id, pat_fio, pat_born, medcard_id) VALUES (%s, %s, %s, %s)",\
(self.pat_id, self.pat_fio, self.pat_born, self.medcardc_id))
conn.commit()
finally:
self.db.close(conn, cur)
class Developer(Employee):
def __init__(self, name, age, salary, programming_languages):
super().__init__(name, age, salary)
self.programming_languages = programming_languages
def display_tech_stack(self):
print(f"{self.name}'s tech stack: {', '.join(self.programming_languages)}")
class Department:
def __init__(self, name, code, manager):
self.name = name
self.code = code
self.manager = manager
def get_manager_info(self):
return f"The manager of the department {self.name} is {self.manager}"
class Project:
def __init__(self, name):
self.name = name
def assign_team(self, team):
print(f"The team for project {self.name} has been assigned: {', '.join(team)}")
class ProgrammingLanguage:
def __init__(self, name, type):
self.name = name
self.type = type
def display_info(self):
print(f"Programming language: {self.name}, Type: {self.type}")
class Technology:
def __init__(self, name, description):
self.name = name
self.description = description
def display_tech_info(self):
print(f"Technology: {self.name}, Description: {self.description}")
+15 -14
View File
@@ -70,14 +70,13 @@ class doctor:
finally: finally:
self.db.close(conn, cur) self.db.close(conn, cur)
def workload_check(self, timetable): def workload_check(self, time_of_appoint): #как сделать?
conn = None conn = None
cur = None cur = None
try: try:
conn = self.db.connect() conn = self.db.connect()
cur = conn.cursor() cur = conn.cursor()
if (timetable.loanAmount <= 50000): if (self.time_of_appoint == time_of_appoint):
# что вместо апдейта?
cur.execute("UPDATE loan_applications SET status = %s WHERE application_id = %s", ('approved', timetable.applicationID)) cur.execute("UPDATE loan_applications SET status = %s WHERE application_id = %s", ('approved', timetable.applicationID))
else: else:
cur.execute("UPDATE loan_applications SET status = %s WHERE application_id = %s", ('rejected', timetable.applicationID)) cur.execute("UPDATE loan_applications SET status = %s WHERE application_id = %s", ('rejected', timetable.applicationID))
@@ -97,18 +96,19 @@ class DocAppointment:
self.appointment_id = appointment_id self.appointment_id = appointment_id
self.patient = patient self.patient = patient
self.status = status self.status = status
self.time_of_appoint
self.db = db self.db = db
def addToDatabase(self): # def addToDatabase(self):
conn = None # conn = None
cur = None # cur = None
try: # try:
conn = self.database.connect() # conn = self.database.connect()
cur = conn.cursor() # cur = conn.cursor()
cur.execute("INSERT INTO loan_applications (client_id, loan_amount, status) VALUES (%s, %s, %s)", (self.client.clientID, self.loanAmount, self.status)) # cur.execute("INSERT INTO appointment (client_id, loan_amount, status) VALUES (%s, %s, %s)", (self.client.clientID, self.loanAmount, self.status))
conn.commit() # conn.commit()
finally: # finally:
self.database.close(conn, cur) # self.database.close(conn, cur)
def del_appoint(self): def del_appoint(self):
conn = None conn = None
@@ -127,7 +127,8 @@ class DocAppointment:
try: try:
conn = self.database.connect() conn = self.database.connect()
cur = conn.cursor() cur = conn.cursor()
cur.execute("INSERT INTO appointment (appointment_id, patient, status) VALUES (%s, %s, %s)", self.appointment_id, self.patient, self.status) cur.execute("INSERT INTO appointment (appointment_id, patient, status, time_of_appoint) VALUES (%s, %s, %s, %s)",\
self.appointment_id, self.patient, self.status, self.time_of_appoint)
conn.commit() conn.commit()
finally: finally:
self.database.close(conn, cur) self.database.close(conn, cur)