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

feat: status report dashboard #8

Open
wants to merge 1 commit 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
12 changes: 10 additions & 2 deletions status_villain/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from rich.console import Console

from status_villain.database import database_connector
from status_villain.tasks.tasks import InitTask, ReportTask
from status_villain.tasks.tasks import DashboardTask, InitTask, ReportTask

# TODO: allow users to store credentials in a local file so that
# they do not have to authenticate every time they need to add to their standup.
Expand All @@ -22,7 +22,12 @@
init_subparser.set_defaults(cls=InitTask, which="init")

report_subparser = subparser.add_parser("report", help="Let's you write your status report.")
init_subparser.set_defaults(cls=InitTask, which="report")
init_subparser.set_defaults(cls=ReportTask, which="report")

dashboard_subparser = subparser.add_parser(
"dashboard", help="Shows everyone's today's status report"
)
dashboard_subparser.set_defaults(cls=DashboardTask, which="dashboard")


def handle(parser: argparse.ArgumentParser, test_cli_args: Optional[List[str]] = None):
Expand All @@ -44,6 +49,9 @@ def handle(parser: argparse.ArgumentParser, test_cli_args: Optional[List[str]] =
elif parsed_args.command == "report":
task = ReportTask()
task.run()
elif parsed_args.command == "dashboard":
task = DashboardTask()
task.run()
else:
print(f"{parsed_args.command} is not implemented")

Expand Down
17 changes: 6 additions & 11 deletions status_villain/models.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
from sqlalchemy import Boolean, Column, DateTime, String
from sqlalchemy.orm import relationship
from sqlalchemy.sql.schema import ForeignKey

from status_villain.database import SQLAlchemyBase

# users table
# # user_id PK
# # user_name
# # created_at


class User(SQLAlchemyBase):
__tablename__ = "users"
Expand All @@ -21,12 +17,8 @@ class User(SQLAlchemyBase):
last_name = Column(String)
created_at = Column(DateTime)


# standup messages table
# # message_id PK
# # user_id FK on users table
# # created_at
# # message_content
# relationships
status_reports = relationship("Message", back_populates="user")


class Message(SQLAlchemyBase):
Expand All @@ -38,5 +30,8 @@ class Message(SQLAlchemyBase):
yesterday_message = Column(String)
has_completed_yesterday = Column(Boolean)

# relationships
user = relationship("User", back_populates="status_reports")


# Orgnanisation Table?
70 changes: 70 additions & 0 deletions status_villain/tasks/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from rich.console import Console
from rich.markdown import Markdown
from sqlalchemy.exc import IntegrityError
from sqlalchemy.sql import func

from status_villain.commands import check_password, create_user
from status_villain.database import database_connector
Expand Down Expand Up @@ -106,6 +107,75 @@ def authenticate(self) -> bool:
return False


class DashboardTask(BaseTask):
def __init__(self):
self.attempt_login()

# query all the users latest reports
# # we want to make sure we're only printing yesterdays message
# ## at least not different dates in case someone didn't fill up their standup yesterday
# ## we don't want to show their yesterday yesterday standup -- Need to be somehow
# ## date aware...
# # we want to make sure we show all users? I.e. even if Joe doesn't have a standup
# # we want to show that they are yet to fill it in. --this means we need to know all the users
# ## not just querying from the status_reports table but rather from the users table and going down.
# # calculate streaks for each users (or at least to know if a user is on a streak)
# find a way to display everyone's messages in an "elegant" way... whataver that means
@staticmethod
def get_user_latest_today_message(user_id: str) -> Message:
with database_connector.session_manager() as session:
today_latest_report = (
session.query(Message)
.filter(
func.date(Message.created_at) == datetime.utcnow().date(),
Message.user_id == user_id,
)
.order_by(Message.created_at.desc())
.first()
)
return today_latest_report

def get_all_users_reports(self):
# TODO: we want to make sure we also show emtpy messages for users who
# did not fill yesterdays report (means we probably want to got parent > child)
with database_connector.session_manager() as session:
users = session.query(User.email, User.first_name, User.last_name).all()
user_shit = session.query(User.status_reports).first()
print(user_shit)
self.reports = []
for user in users:
report = self.get_user_latest_today_message(user_id=user.email)
if report is not None:
self.reports.append(
{
"user": f"{user.first_name} {user.last_name}",
"user_report_today": report.today_message,
"user_report_yesterday": report.yesterday_message,
}
)
else:
self.reports.append(
{
"user": f"{user.first_name} {user.last_name}",
"user_report_today": None,
"user_report_yesterday": None,
}
)

def display_reports(self):
for report in self.reports:
md_name_header = f"# {report['user']}"
console.print(Markdown(md_name_header))
console.print("[green][bold]TODAY:")
console.print(Markdown(f"{report['user_report_today']}"))
console.print("\n[yellow][bold]YESTERDAY:")
console.print(Markdown(f"{report['user_report_yesterday']}"))

def run(self):
self.get_all_users_reports()
self.display_reports()


class InitTask(BaseTask):
def __init__(
self, profiles_dir_path=DEFAULT_PROFILES_DIR, profiles_file_path=DEFAULT_PROFILES_FILE
Expand Down