Skip to content

Commit

Permalink
Updated dependencies; added docstrings.
Browse files Browse the repository at this point in the history
  • Loading branch information
toddbirchard committed Sep 12, 2024
1 parent 77676c0 commit d364b4a
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 2,269 deletions.
36 changes: 26 additions & 10 deletions clients/database.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
"""Database interaction module."""

import pandas as pd
from pandas import DataFrame
from pandas.core.groupby.generic import DataFrameGroupBy
from sqlalchemy import create_engine
from sqlalchemy.types import DateTime, Integer, String, Text

Expand All @@ -17,8 +20,14 @@ def engine(self):
"""Database connection engine"""
return create_engine(self.uri, connect_args=self.args)

def upload_dataframe(self, df: DataFrame):
"""Upload DataFrame database."""
def upload_dataframe(self, df: DataFrame) -> str:
"""
Upload DataFrame as database table.
:param DataFrame df: DataFrame to upload as updated SQL table.
:returns: str
"""
df.to_sql(
self.table,
self.engine,
Expand All @@ -35,20 +44,27 @@ def upload_dataframe(self, df: DataFrame):
response = f"Successfully uploaded {str(df.count)} rows."
return response

def get_table_data(self):
"""Fetch table from SQL database."""
def get_table_data(self) -> DataFrame:
"""
Fetch table from SQL database.
:returns: DataFrame
"""
table_df = pd.read_sql_table(
self.table,
con=self.engine,
index_col="id",
parse_dates="created_at",
self.table, con=self.engine, index_col="id", parse_dates="created_at", chunksize=None
)
table_df.sort_values("created_at", ascending=False, inplace=True)
table_df["created_at"] = table_df["created_at"].dt.strftime("%m/%d/%Y")
return table_df

@staticmethod
def column_dist_chart(table_df: DataFrame, column):
"""Aggregate column values"""
def column_dist_chart(table_df: DataFrame, column) -> DataFrameGroupBy:
"""
Aggregate values per column of a SQL table for data vis.
:param DataFrame table_df: DataFrame to aggregate.
:returns: DataFrameGroupBy
"""
grouped_column = table_df.groupby(column).count().sort_values(column, ascending=False)
return grouped_column
1 change: 0 additions & 1 deletion config.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,3 @@ class Config:


settings = Config()

2,202 changes: 0 additions & 2,202 deletions poetry.lock

This file was deleted.

2 changes: 1 addition & 1 deletion pythonmyadmin/static/dist/css/style.css

Large diffs are not rendered by default.

46 changes: 46 additions & 0 deletions pythonmyadmin/static/less/index.less
Original file line number Diff line number Diff line change
@@ -1,4 +1,50 @@
.home-template {

.container {
width: 800px;
max-width: 90%;
margin: auto;
border-radius: 4px;
box-shadow: 0 0 4px #cdd3e2;
padding: 30px;
background: white;
overflow: hidden;
@media(max-width: @tablet-breakpoint) {
width: 90vw;
padding: 5vw;
}

.database-host-name {
color: #afb7c3;
margin: 0;
font-size: .8em;

span {
white-space: nowrap;
}
}

.database-table-summary {
font-size: 1.2em;
margin-top: 5px;
color: #6d7277;
}

ul {
list-style: none;
padding: 0;

li {
margin-bottom: 5px;
text-decoration: none;

&:last-of-type {
margin-bottom: 0;
}
}
}
}

.database-host {
font-weight: bold;
}
Expand Down
45 changes: 0 additions & 45 deletions pythonmyadmin/static/less/main.less
Original file line number Diff line number Diff line change
Expand Up @@ -35,51 +35,6 @@ html {
}
}

.container {
width: 1000px;
max-width: 90%;
margin: auto;
border-radius: 4px;
box-shadow: 0 0 4px #cdd3e2;
padding: 30px;
background: white;
overflow: hidden;
@media(max-width: @tablet-breakpoint) {
width: 90vw;
padding: 5vw;
}

.database-host-name {
color: #afb7c3;
margin: 0;
font-size: .8em;

span {
white-space: nowrap;
}
}

.database-table-summary {
font-size: 1.2em;
margin-top: 5px;
color: #6d7277;
}

ul {
list-style: none;
padding: 0;

li {
margin-bottom: 5px;
text-decoration: none;

&:last-of-type {
margin-bottom: 0;
}
}
}
}

.link {
color: @theme-color;
}
Expand Down
3 changes: 2 additions & 1 deletion pythonmyadmin/static/less/nav.less
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ header {
display: flex;
align-items: center;
justify-content: space-between;
max-width: 1000px;
max-width: 800px;
max-width: 96vw;
margin: auto;

@media(max-width: 1000px) {
Expand Down
18 changes: 9 additions & 9 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
async-timeout==4.0.3 ; python_version >= "3.10" and python_full_version < "3.11.3"
black==24.8.0 ; python_version >= "3.10" and python_version < "4.0"
blinker==1.8.2 ; python_version >= "3.10" and python_version < "4.0"
build==1.2.1 ; python_version >= "3.10" and python_version < "4.0"
build==1.2.2 ; python_version >= "3.10" and python_version < "4.0"
cachecontrol[filecache]==0.14.0 ; python_version >= "3.10" and python_version < "4.0"
certifi==2024.8.30 ; python_version >= "3.10" and python_version < "4.0"
cffi==1.17.1 ; python_version >= "3.10" and python_version < "4.0" and (platform_python_implementation != "PyPy" or sys_platform == "darwin")
Expand All @@ -21,15 +21,15 @@ distlib==0.3.8 ; python_version >= "3.10" and python_version < "4.0"
dulwich==0.21.7 ; python_version >= "3.10" and python_version < "4.0"
exceptiongroup==1.2.2 ; python_version >= "3.10" and python_version < "3.11"
fastjsonschema==2.20.0 ; python_version >= "3.10" and python_version < "4.0"
filelock==3.15.4 ; python_version >= "3.10" and python_version < "4.0"
filelock==3.16.0 ; python_version >= "3.10" and python_version < "4.0"
flake8==7.1.1 ; python_version >= "3.10" and python_version < "4.0"
flask-assets==2.1.0 ; python_version >= "3.10" and python_version < "4.0"
flask-sqlalchemy==3.1.1 ; python_version >= "3.10" and python_version < "4.0"
flask==3.0.3 ; python_version >= "3.10" and python_version < "4.0"
greenlet==3.0.3 ; python_version < "3.13" and (platform_machine == "aarch64" or platform_machine == "ppc64le" or platform_machine == "x86_64" or platform_machine == "amd64" or platform_machine == "AMD64" or platform_machine == "win32" or platform_machine == "WIN32") and python_version >= "3.10"
greenlet==3.1.0 ; python_version < "3.13" and (platform_machine == "aarch64" or platform_machine == "ppc64le" or platform_machine == "x86_64" or platform_machine == "amd64" or platform_machine == "AMD64" or platform_machine == "win32" or platform_machine == "WIN32") and python_version >= "3.10"
gunicorn==23.0.0 ; python_version >= "3.10" and python_version < "4.0"
idna==3.8 ; python_version >= "3.10" and python_version < "4.0"
importlib-metadata==8.4.0 ; python_version >= "3.10" and python_version < "4.0"
importlib-metadata==8.5.0 ; python_version >= "3.10" and python_version < "4.0"
iniconfig==2.0.0 ; python_version >= "3.10" and python_version < "4.0"
installer==0.7.0 ; python_version >= "3.10" and python_version < "4.0"
isort==5.13.2 ; python_version >= "3.10" and python_version < "4.0"
Expand All @@ -44,7 +44,7 @@ loguru==0.7.2 ; python_version >= "3.10" and python_version < "4.0"
markupsafe==2.1.5 ; python_version >= "3.10" and python_version < "4.0"
mccabe==0.7.0 ; python_version >= "3.10" and python_version < "4.0"
more-itertools==10.5.0 ; python_version >= "3.10" and python_version < "4.0"
msgpack==1.0.8 ; python_version >= "3.10" and python_version < "4.0"
msgpack==1.1.0 ; python_version >= "3.10" and python_version < "4.0"
mypy-extensions==1.0.0 ; python_version >= "3.10" and python_version < "4.0"
nest-asyncio==1.6.0 ; python_version >= "3.10" and python_version < "4.0"
numpy==2.1.1 ; python_version >= "3.10" and python_version <= "3.11" or python_version >= "3.12" and python_version < "4.0"
Expand All @@ -53,7 +53,7 @@ pandas==2.2.2 ; python_version >= "3.10" and python_version < "4.0"
pathspec==0.12.1 ; python_version >= "3.10" and python_version < "4.0"
pexpect==4.9.0 ; python_version >= "3.10" and python_version < "4.0"
pkginfo==1.11.1 ; python_version >= "3.10" and python_version < "4.0"
platformdirs==4.2.2 ; python_version >= "3.10" and python_version < "4.0"
platformdirs==4.3.2 ; python_version >= "3.10" and python_version < "4.0"
plotly==5.24.0 ; python_version >= "3.10" and python_version < "4.0"
pluggy==1.5.0 ; python_version >= "3.10" and python_version < "4.0"
ply==3.11 ; python_version >= "3.10" and python_version < "4.0"
Expand All @@ -66,10 +66,10 @@ pycparser==2.22 ; python_version >= "3.10" and python_version < "4.0" and (platf
pyflakes==3.2.0 ; python_version >= "3.10" and python_version < "4.0"
pymysql==1.1.1 ; python_version >= "3.10" and python_version < "4.0"
pyproject-hooks==1.1.0 ; python_version >= "3.10" and python_version < "4.0"
pytest==8.3.2 ; python_version >= "3.10" and python_version < "4.0"
pytest==8.3.3 ; python_version >= "3.10" and python_version < "4.0"
python-dateutil==2.9.0.post0 ; python_version >= "3.10" and python_version < "4.0"
python-dotenv==1.0.1 ; python_version >= "3.10" and python_version < "4.0"
pytz==2024.1 ; python_version >= "3.10" and python_version < "4.0"
pytz==2024.2 ; python_version >= "3.10" and python_version < "4.0"
pywin32-ctypes==0.2.3 ; python_version >= "3.10" and python_version < "4.0" and sys_platform == "win32"
rapidfuzz==3.9.7 ; python_version >= "3.10" and python_version < "4.0"
redis==5.0.8 ; python_version >= "3.10" and python_version < "4.0"
Expand All @@ -88,7 +88,7 @@ trove-classifiers==2024.7.2 ; python_version >= "3.10" and python_version < "4.0
typing-extensions==4.12.2 ; python_version >= "3.10" and python_version < "4.0"
tzdata==2024.1 ; python_version >= "3.10" and python_version < "4.0"
urllib3==2.2.2 ; python_version >= "3.10" and python_version < "4.0"
virtualenv==20.26.3 ; python_version >= "3.10" and python_version < "4.0"
virtualenv==20.26.4 ; python_version >= "3.10" and python_version < "4.0"
webassets==2.0 ; python_version >= "3.10" and python_version < "4.0"
werkzeug==3.0.4 ; python_version >= "3.10" and python_version < "4.0"
win32-setctime==1.1.0 ; python_version >= "3.10" and python_version < "4.0" and sys_platform == "win32"
Expand Down

0 comments on commit d364b4a

Please sign in to comment.