Skip to content

Commit

Permalink
Merge pull request #80 from ElemarJR/ui-improvements-dez-2024
Browse files Browse the repository at this point in the history
UI improvements dez 2024
  • Loading branch information
ElemarJR authored Dec 26, 2024
2 parents a8191d9 + 2050243 commit 94d2c2f
Show file tree
Hide file tree
Showing 26 changed files with 704 additions and 512 deletions.
35 changes: 35 additions & 0 deletions backend/api/src/business_calendar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import holidays
from datetime import datetime, timedelta

def resolve_business_calendar(_, info, start, end):
return compute_business_calendar(start, end)

def compute_business_calendar(start, end):
if isinstance(start, str):
start = datetime.strptime(start, '%Y-%m-%d').date()
if isinstance(end, str):
end = datetime.strptime(end, '%Y-%m-%d').date()

br_holidays = holidays.BR()

working_days = []
current = start
while current <= end:
if current not in br_holidays and current.weekday() < 5:
working_days.append(current)
current += timedelta(days=1)

holidays_in_range = []
current = start
while current <= end:
if current in br_holidays:
holidays_in_range.append({
'date': current,
'reason': br_holidays.get(current)
})
current += timedelta(days=1)

return {
'working_days': working_days,
'holidays': holidays_in_range
}
1 change: 1 addition & 0 deletions backend/api/src/datasets/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ type TimesheetSummary implements ISummary {
byOffer: [NamedSummary!]!

appointments: [Appointment!]!
businessCalendar: BusinessCalendar!

filterableFields: [FilterableField]!
}
Expand Down
6 changes: 6 additions & 0 deletions backend/api/src/datasets/timesheets.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
from utils.fields import build_fields_map, get_requested_fields_from, get_selections_from_info
from omni_utils.helpers.slug import slugify

from business_calendar import compute_business_calendar

from omni_shared import globals


Expand Down Expand Up @@ -226,6 +228,7 @@ def compute_timesheet(map, slug: str=None, kind: str="ALL", filters = None):

timesheet = globals.omni_datasets.get_by_slug(slug)
source = globals.omni_datasets.get_dataset_source_by_slug(slug)
dates = globals.omni_datasets.get_dates(slug)
df = timesheet.data

# Filter the dataframe based on the 'kind' parameter
Expand All @@ -247,6 +250,9 @@ def compute_timesheet(map, slug: str=None, kind: str="ALL", filters = None):
# Base summary
if base_fields:
result.update(summarize(df))

if 'businessCalendar' in requested_fields:
result['business_calendar'] = compute_business_calendar(dates[0], dates[1])

# By kind
if 'byKind' in requested_fields:
Expand Down
2 changes: 2 additions & 0 deletions backend/api/src/queries.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from ariadne import QueryType, gql
from pathlib import Path

from business_calendar import resolve_business_calendar
from domain import setup_query_for_domain
from datasets import setup_query_for_datasets
from analytics import setup_query_for_analytics
Expand Down Expand Up @@ -42,6 +43,7 @@ def resolve_timesheet_cache(_, info, after = None, before = None):
return globals.omni_datasets.timesheets.memory.list_cache(after, before)


query.set_field('businessCalendar', resolve_business_calendar)
query.set_field('inconsistencies', resolve_inconsistencies)
query.set_field('cache', resolve_cache)
query.set_field('timesheetCache', resolve_timesheet_cache)
Expand Down
11 changes: 11 additions & 0 deletions backend/api/src/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ type Inconsistency {
description: String!
}

type BusinessCalendar {
workingDays: [Date!]!
holidays: [BusinessCalendarHoliday!]!
}

type BusinessCalendarHoliday {
date: Date!
reason: String!
}

type Query {
inconsistencies: [Inconsistency]!

Expand Down Expand Up @@ -49,6 +59,7 @@ type Query {

staleliness: Staleliness!

businessCalendar(start: Date!, end: Date!): BusinessCalendar!
cache: [CacheItem!]!
timesheetCache(after: Date, before: Date): [TimesheetCacheItem!]!
}
Expand Down
110 changes: 110 additions & 0 deletions backend/models/src/omni_models/omnidatasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,116 @@ def __init__(self, models: OmniModels = None):
self.insights = InsightsDataset(models)
self.tasks = TasksDataset(models)

def get_dates(self, slug: str) -> Tuple[datetime, datetime]:
if not slug:
return None, None

if slug.startswith('timesheet-') and len(slug.split('-')) == 7:
parts = slug.split('-')
start_day = int(parts[1])
start_month = int(parts[2])
start_year = int(parts[3])
end_day = int(parts[4])
end_month = int(parts[5])
end_year = int(parts[6])

start_date = datetime(start_year, start_month, start_day, 0, 0, 0, 0)
end_date = datetime(end_year, end_month, end_day, 23, 59, 59, 9999)

return start_date, end_date

if slug.startswith('timesheet-') and len(slug.split('-')) == 5:
parts = slug.split('-')
start_day = int(parts[1])
start_month = int(parts[2])
end_day = int(parts[3])
end_month = int(parts[4])

current_year = datetime.now().year

start_year = current_year
end_year = current_year
if start_month > end_month:
end_year = current_year + 1

start_date = datetime(start_year, start_month, start_day, 0, 0, 0, 0)
end_date = datetime(end_year, end_month, end_day, 23, 59, 59, 9999)

return start_date, end_date

if slug.startswith('timesheet-month-'):
parts = slug.split('-')
year = int(parts[-2])
month = int(parts[-1])

first, last = monthrange(year, month)
first_day = datetime(year, month, 1, 0, 0, 0, 0)
last_day = datetime(year, month, last, 23, 59, 59, 9999)

return first_day, last_day

if slug.startswith('timesheet-last-six-weeks') and slug != 'timesheet-last-six-weeks':
parts = slug.split('-')
year = parts[-3]
month = parts[-2]
day = parts[-1]
doi = datetime.strptime(f"{year}-{month}-{day}", "%Y-%m-%d")
return None, None # Special case handled by source.get_last_six_weeks(doi)

if slug.startswith('timesheet-s'):
semester_slug = get_time_part_from_slug(slug)
return get_semester_dates(semester_slug)

if slug.startswith('timesheet-q'):
quarter_slug = get_time_part_from_slug(slug)
return get_quarter_dates(quarter_slug)

if slug.endswith('this-month'):
now = datetime.now()
start = datetime(now.year, now.month, 1, hour=0, minute=0, second=0, microsecond=0)
end = datetime(
now.year, now.month, calendar.monthrange(now.year, now.month)[1],
hour=23, minute=59, second=59, microsecond=9999
)
return start, end

if slug.endswith('previous-month'):
now = datetime.now()
if now.month == 1:
previous_month = 12
year = now.year - 1
else:
previous_month = now.month - 1
year = now.year
start = datetime(year, previous_month, 1, hour=0, minute=0, second=0, microsecond=0)
end = datetime(
year, previous_month, calendar.monthrange(year, previous_month)[1],
hour=23, minute=59, second=59, microsecond=9999
)
return start, end

if slug.endswith('this-week'):
start, end = Weeks.get_current_dates()
return start, end

if slug.endswith('previous-week'):
start, end = Weeks.get_previous_dates(1)
return start, end

try:
month, year = slug.split('-')[-2:]
month = list(calendar.month_name).index(month.capitalize())
year = int(year)
first_day = datetime(year, month, 1, 0, 0, 0, 0)
last_day = datetime(
year, month, calendar.monthrange(year, month)[1],
23, 59, 59, 9999
)
return first_day, last_day
except:
return None, None


def get_dataset_source_by_slug(self, slug: str) -> OmniDataset:
if not slug:
return None
Expand Down
1 change: 1 addition & 0 deletions frontend/postcss.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
const config = {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
};

Expand Down
14 changes: 14 additions & 0 deletions frontend/src/app/about-us/account-managers/[slug]/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ export const GET_ACCOUNT_MANAGER = gql`
totalSquadHours
totalInternalHours
}
businessCalendar {
workingDays
holidays {
date
reason
}
}
}
timesheet2: timesheet(slug: $dataset2) {
Expand All @@ -112,6 +119,13 @@ export const GET_ACCOUNT_MANAGER = gql`
totalSquadHours
totalInternalHours
}
businessCalendar {
workingDays
holidays {
date
reason
}
}
}
timesheet(slug: $dataset) {
Expand Down
14 changes: 14 additions & 0 deletions frontend/src/app/about-us/cases/[slug]/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ export const GET_CASE_BY_SLUG = gql`
comment
timeInHs
}
businessCalendar {
holidays {
date
reason
}
workingDays
}
byDate {
date
totalHours
Expand All @@ -83,6 +90,13 @@ export const GET_CASE_BY_SLUG = gql`
comment
timeInHs
}
businessCalendar {
holidays {
date
reason
}
workingDays
}
byDate {
date
totalHours
Expand Down
29 changes: 25 additions & 4 deletions frontend/src/app/about-us/clients/[slug]/queries.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import { gql } from "@apollo/client";

export const GET_CLIENT_BY_SLUG = gql`
query GetClientBySlug($slug: String!, $dataset1: String!, $dataset2: String!) {
query GetClientBySlug(
$slug: String!
$dataset1: String!
$dataset2: String!
) {
client(slug: $slug) {
name
logoUrl
ontologyUrl
isStrategic
forecast {
forecast {
dateOfInterest
filterableFields {
field
Expand Down Expand Up @@ -44,6 +48,13 @@ export const GET_CLIENT_BY_SLUG = gql`
comment
timeInHs
}
businessCalendar {
holidays {
date
reason
}
workingDays
}
byDate {
date
totalHours
Expand All @@ -65,6 +76,13 @@ export const GET_CLIENT_BY_SLUG = gql`
comment
timeInHs
}
businessCalendar {
holidays {
date
reason
}
workingDays
}
byDate {
date
totalHours
Expand Down Expand Up @@ -112,12 +130,15 @@ export const GET_CLIENT_TIMESHEET = gql`
}
}
timesheet(slug: $datasetSlug, filters: [{ field: "ClientName", selectedValues: [$clientName] }]) {
timesheet(
slug: $datasetSlug
filters: [{ field: "ClientName", selectedValues: [$clientName] }]
) {
uniqueClients
uniqueCases
uniqueWorkers
totalHours
byKind {
consulting {
uniqueClients
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ export const GET_CONSULTANT = gql`
comment
timeInHs
}
businessCalendar {
holidays {
date
reason
}
workingDays
}
byDate {
date
totalHours
Expand All @@ -66,6 +73,13 @@ export const GET_CONSULTANT = gql`
comment
timeInHs
}
businessCalendar {
holidays {
date
reason
}
workingDays
}
byDate {
date
totalHours
Expand Down
Loading

0 comments on commit 94d2c2f

Please sign in to comment.