From 7cbb273f652d8f4e2afd3c41b2453c19be288916 Mon Sep 17 00:00:00 2001 From: gola077 Date: Mon, 22 May 2023 17:31:04 +0000 Subject: [PATCH 1/4] test --- w2/server.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/w2/server.py b/w2/server.py index 9ee44a0..67179ce 100644 --- a/w2/server.py +++ b/w2/server.py @@ -42,7 +42,7 @@ async def get() -> Dict: """ ######################################## YOUR CODE HERE ################################################## - + test ######################################## YOUR CODE HERE ################################################## From 2b4f426ec7e4cfd4c622ddc2579a26aff69c41a5 Mon Sep 17 00:00:00 2001 From: gola077 Date: Mon, 22 May 2023 17:33:00 +0000 Subject: [PATCH 2/4] test --- w2/server.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/w2/server.py b/w2/server.py index 67179ce..d1192f3 100644 --- a/w2/server.py +++ b/w2/server.py @@ -42,7 +42,7 @@ async def get() -> Dict: """ ######################################## YOUR CODE HERE ################################################## - test + return {"status": "ok"} ######################################## YOUR CODE HERE ################################################## From 34f96b776df60dce68194f542e76eed95af08bce Mon Sep 17 00:00:00 2001 From: gola077 Date: Mon, 22 May 2023 17:47:07 +0000 Subject: [PATCH 3/4] week2-project-complete --- w2/server.py | 9 +++++++-- w2/utils/database.py | 33 +++++++++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/w2/server.py b/w2/server.py index d1192f3..c58d65f 100644 --- a/w2/server.py +++ b/w2/server.py @@ -53,7 +53,7 @@ async def get() -> HTMLResponse: should render the HTML file - index.html when a user goes to http://127.0.0.1:8000/ """ ######################################## YOUR CODE HERE ################################################## - + return HTMLResponse(content=open("index.html").read(),status_code=200) ######################################## YOUR CODE HERE ################################################## @@ -64,5 +64,10 @@ async def get() -> List[ProcessStatus]: Get all the records from the process table and return it using the pydantic model ProcessStatus """ ######################################## YOUR CODE HERE ################################################## - + # get records + process_statuses = [] + for process in process_data: + process_status = ProcessStatus(**process) + process_statuses.append(process_status) + return process_statuses ######################################## YOUR CODE HERE ################################################## diff --git a/w2/utils/database.py b/w2/utils/database.py index 86af309..a5a51e7 100644 --- a/w2/utils/database.py +++ b/w2/utils/database.py @@ -45,6 +45,22 @@ def create_table(self) -> None: Read more about datatypes in Sqlite here -> https://www.sqlite.org/datatype3.html """ ######################################## YOUR CODE HERE ################################################## + # here create a table + self._connection.execute( + f'''CREATE TABLE IF NOT EXISTS {self._table_name} + ( + process_id TEXT PRIMARY KEY NOT NULL, + file_name TEXT DEFAULT NULL, + file_path TEXT DEFAULT NULL, + description TEXT DEFAULT NULL, + start_time TEXT NOT NULL, + end_time TEXT DEFAULT NULL, + percentage REAL DEFAULT NULL + )''' + ) + + # Save changes + self._connection.commit() ######################################## YOUR CODE HERE ################################################## @@ -63,7 +79,15 @@ def insert(self, process_id, start_time, file_name=None, file_path=None, :return: None """ ######################################## YOUR CODE HERE ################################################## - + # Insert into table + self._connection.execute( + f'''INSERT INTO {self._table_name} + (process_id, start_time, file_name, file_path, description, end_time, percentage) + VALUES (?, ?, ?, ?, ?, ?, ?)''', + (process_id, start_time, file_name, file_path, description, end_time, percentage)) + + # Save (commit) the changes + self._connection.commit() ######################################## YOUR CODE HERE ################################################## def read_all(self) -> List[Dict]: @@ -95,7 +119,12 @@ def update_percentage(self, process_id, percentage): :return: None """ ######################################## YOUR CODE HERE ################################################## - + # update the record + self._connection.execute( + f'''UPDATE {self._table_name} SET percentage='{percentage}' + WHERE process_id='{process_id}';''') + + self._connection.commit() ######################################## YOUR CODE HERE ################################################## From 2b7f8e1ae411173ce04966e9bdfa45cd9055895b Mon Sep 17 00:00:00 2001 From: gola077 Date: Mon, 22 May 2023 17:49:02 +0000 Subject: [PATCH 4/4] week2-project-completion --- w2/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/w2/main.py b/w2/main.py index e1ad78e..3aa4bf4 100644 --- a/w2/main.py +++ b/w2/main.py @@ -57,7 +57,7 @@ def aggregate(self, column_name: str) -> float: # get generator from data_reader data_reader_gen = (row for row in self.data_reader) - # skip first row as it is the column name + # skip first row as it is the column name test _ = next(data_reader_gen) aggregate = 0