Skip to content

Commit

Permalink
Merge pull request #3 from ElemarJR/planned_vs_actual
Browse files Browse the repository at this point in the history
Planned vs actual
  • Loading branch information
ElemarJR authored Oct 21, 2024
2 parents 11f8cf2 + c57e420 commit a531b4f
Show file tree
Hide file tree
Showing 18 changed files with 1,006 additions and 344 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ downloads/
eggs/
.eggs/
lib/
!frontend/src/lib
lib64/
parts/
sdist/
Expand Down
18 changes: 13 additions & 5 deletions backend/api/datasets/timesheets.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from datetime import datetime
import pandas as pd
from typing import Dict, Any, List, Union
from api.utils.fields import get_requested_fields_from
Expand All @@ -16,7 +17,7 @@ def summarize(df: pd.DataFrame) -> Dict[str, Any]:

# Calculate statistics
total_hours = df["TimeInHs"].sum()
average_hours_per_entry = total_hours / len(df)
average_hours_per_entry = total_hours / len(df) if len(df) > 0 else 0

return {
"total_entries": len(df),
Expand Down Expand Up @@ -70,13 +71,15 @@ def summarize_by_group(df: pd.DataFrame, group_column: str, name_key: str = "nam
summaries = []
for group_value, group_df in df.groupby(group_column):
summary = summarize(group_df)
summary["by_kind"] = summarize_by_kind(group_df)
summary[name_key] = group_value

# Add support for squad, consulting, internal, and hands-on total hours
for kind in ['Squad', 'Consulting', 'Internal', 'HandsOn']:
summary[f"total_{kind.lower()}_hours"] = group_df[group_df['Kind'] == kind]['TimeInHs'].sum()


summary["by_kind"] = summarize_by_kind(group_df)
if group_column != 'Week':
summary['by_week'] = summarize_by_week(group_df)

summaries.append(summary)

summaries = sorted(summaries, key=lambda x: x["total_hours"], reverse=True)
Expand All @@ -101,7 +104,12 @@ def summarize_by_date(df: pd.DataFrame) -> List[Dict[str, Union[Dict[str, Any],
return summarize_by_group(df, 'Date', name_key="date")

def summarize_by_week(df: pd.DataFrame) -> List[Dict[str, Union[Dict[str, Any], Any]]]:
return summarize_by_group(df, 'Week', name_key="week")
summaries = summarize_by_group(df, 'Week', name_key="week")

# Sort the summaries based on the 'week' key
sorted_summaries = sorted(summaries, key=lambda x: datetime.strptime(x['week'].split(' - ')[0], '%d/%m'))

return sorted_summaries

def summarize_by_offer(df: pd.DataFrame) -> List[Dict[str, Union[Dict[str, Any], Any]]]:
return summarize_by_group(df, 'ProductsOrServices', name_key="name")
Expand Down
4 changes: 3 additions & 1 deletion backend/api/domain/clients.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import globals

def resolve_clients(_, info):
def resolve_clients(_, info, account_manager_name=None):
all_clients = sorted(globals.omni_models.clients.get_all().values(), key=lambda client: client.name)
if account_manager_name:
all_clients = [client for client in all_clients if client.account_manager and client.account_manager.name == account_manager_name]
return all_clients

def resolve_client(_, info, id=None, slug=None):
Expand Down
34 changes: 29 additions & 5 deletions backend/api/domain/user.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,33 @@
from models.domain import WorkerKind
import globals

def resolve_user(_, info, email=None):
if email is not None:
return globals.omni_models.workers.get_by_email(email)
else:
def resolve_user(_, info, email=None, slug=None):
if not email and not slug:
return None


worker = None
if email:
worker = globals.omni_models.workers.get_by_email(email)
elif slug:
worker = globals.omni_models.workers.get_by_slug(slug)

if not worker:
return None

result = {
"id": worker.id,
"name": worker.name,
"email": worker.email,
"slug": worker.slug,
"kind": worker.kind,
"position": worker.position,
"photo_url": worker.photo_url,
# Add other attributes as needed
}
kind_map = {
WorkerKind.ACCOUNT_MANAGER: "ACCOUNT_MANAGER",
WorkerKind.CONSULTANT: "CONSULTANT"
}
result["kind"] = kind_map.get(result["kind"], result["kind"])

return result
Loading

0 comments on commit a531b4f

Please sign in to comment.