Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Week2-project-v2 #21

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion w2/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 8 additions & 3 deletions w2/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ async def get() -> Dict:
"""

######################################## YOUR CODE HERE ##################################################

return {"status": "ok"}
######################################## YOUR CODE HERE ##################################################


Expand All @@ -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 ##################################################


Expand All @@ -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 ##################################################
33 changes: 31 additions & 2 deletions w2/utils/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ##################################################

Expand All @@ -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]:
Expand Down Expand Up @@ -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 ##################################################