-
Notifications
You must be signed in to change notification settings - Fork 0
add projects page with some charts #14
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
Open
leon1995
wants to merge
2
commits into
main
Choose a base branch
from
feature/projects
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,12 @@ | ||
| from factorialhr_analysis.pages.index_page import index_page | ||
| from factorialhr_analysis.pages.oauth_page import authorize_oauth_page, start_oauth_process | ||
| from factorialhr_analysis.pages.projects_page import projects_page | ||
| from factorialhr_analysis.pages.working_time_verification_page import working_time_verification_page | ||
|
|
||
| __all__ = ['authorize_oauth_page', 'index_page', 'start_oauth_process', 'working_time_verification_page'] | ||
| __all__ = [ | ||
| 'authorize_oauth_page', | ||
| 'index_page', | ||
| 'projects_page', | ||
| 'start_oauth_process', | ||
| 'working_time_verification_page', | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,150 @@ | ||
| """Projects page for displaying project time calculations.""" | ||
|
|
||
| import reflex as rx | ||
|
|
||
| from factorialhr_analysis import components, templates | ||
| from factorialhr_analysis.states.project_state import ProjectSettingsState, ProjectState | ||
|
|
||
|
|
||
| @rx.memo | ||
| def render_date_inputs() -> rx.Component: | ||
| """Render the date input form.""" | ||
| return rx.hstack( | ||
| rx.hstack( | ||
| rx.text('Start date'), | ||
| rx.input( | ||
| type='date', | ||
| name='start_date', | ||
| value=ProjectSettingsState.start_date, | ||
| on_change=ProjectSettingsState.set_start_date, | ||
| ), | ||
| align='center', | ||
| spacing='1', | ||
| min_width='max-content', | ||
| ), | ||
| rx.hstack( | ||
| rx.text('End date'), | ||
| rx.input( | ||
| type='date', | ||
| name='end_date', | ||
| value=ProjectSettingsState.end_date, | ||
| on_change=ProjectSettingsState.set_end_date, | ||
| ), | ||
| align='center', | ||
| spacing='1', | ||
| min_width='max-content', | ||
| ), | ||
| rx.checkbox( | ||
| 'Only active projects', | ||
| default_checked=ProjectSettingsState.active, | ||
| on_change=ProjectSettingsState.set_active, | ||
| ), | ||
| rx.cond( | ||
| ProjectSettingsState.date_error, | ||
| rx.tooltip( | ||
| rx.button('Calculate', disabled=True), | ||
| content='End date must be after start date.', | ||
| ), | ||
| rx.button( | ||
| 'Calculate', | ||
| loading=ProjectState.is_loading_projects_times | ProjectState.is_loading_unrelated_minutes, | ||
| on_click=ProjectState.calculate, | ||
| ), | ||
| ), | ||
| spacing='3', | ||
| align='center', | ||
| width='100%', | ||
| ) | ||
|
|
||
|
|
||
| @rx.memo | ||
| def render_imputed_minutes_chart() -> rx.Component: | ||
| """Render vertical bar chart for imputed minutes with different colors per project.""" | ||
| return rx.cond( | ||
| ProjectState.project_times_data.length() > 0, | ||
| rx.vstack( | ||
| rx.heading('Project Time by Project', size='4'), | ||
| rx.recharts.bar_chart( | ||
| rx.recharts.bar( | ||
| data_key='total', | ||
| name='Total Minutes', | ||
| ), | ||
| rx.recharts.x_axis(type_='number'), | ||
| rx.recharts.y_axis(data_key='project', type_='category'), | ||
| rx.recharts.graphing_tooltip(), | ||
| rx.recharts.legend(), | ||
| data=ProjectState.project_times_data, | ||
| layout='vertical', | ||
| width='100%', | ||
| height=ProjectState.chart_height, | ||
| margin={'top': 20, 'right': 20, 'left': 150, 'bottom': 20}, | ||
| ), | ||
| width='100%', | ||
| spacing='4', | ||
| ), | ||
| rx.text('No data available. Click Calculate to load project data.'), | ||
| ) | ||
|
|
||
|
|
||
| @rx.memo | ||
| def render_unrelated_minutes_chart() -> rx.Component: | ||
| """Render bar chart for unrelated minutes.""" | ||
| return rx.cond( | ||
| ProjectState.unrelated_minutes_data.length() > 0, | ||
| rx.vstack( | ||
| rx.heading('Unrelated Minutes by Employee', size='4'), | ||
| rx.text( | ||
| rx.cond( | ||
| ProjectState.total_unrelated_minutes > 0, | ||
| f'Total unrelated minutes: {ProjectState.total_unrelated_minutes}', | ||
| 'Total unrelated minutes: 0', | ||
| ), | ||
| size='5', | ||
| weight='bold', | ||
| ), | ||
| rx.recharts.bar_chart( | ||
| rx.recharts.bar( | ||
| data_key='minutes', | ||
| # fill='#82ca9d', | ||
| name='Unrelated Minutes', | ||
| ), | ||
| rx.recharts.x_axis(data_key='employee'), | ||
| rx.recharts.y_axis(), | ||
| rx.recharts.graphing_tooltip(), | ||
| rx.recharts.legend(), | ||
| data=ProjectState.unrelated_minutes_data, | ||
| width='100%', | ||
| height=400, | ||
| ), | ||
| width='100%', | ||
| spacing='4', | ||
| ), | ||
| rx.text('No data available. Click Calculate to load unrelated minutes data.'), | ||
| ) | ||
|
|
||
|
|
||
| @components.requires_authentication | ||
| @templates.template | ||
| def projects_page() -> rx.Component: | ||
| """Projects page showing project time calculations.""" | ||
| return rx.vstack( | ||
| rx.heading('Project Time Analysis', size='6', weight='bold'), | ||
| render_date_inputs(), | ||
| rx.cond( | ||
| ProjectState.error_message.is_not_none(), | ||
| rx.callout.root( | ||
| rx.callout.icon(), | ||
| rx.callout.text(ProjectState.error_message), | ||
| color_scheme='red', | ||
| ), | ||
| rx.fragment(), | ||
| ), | ||
| rx.vstack( | ||
| render_imputed_minutes_chart(), | ||
| render_unrelated_minutes_chart(), | ||
| spacing='6', | ||
| width='100%', | ||
| ), | ||
| width='100%', | ||
| spacing='4', | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| from factorialhr_analysis.states.data_state import DataState | ||
| from factorialhr_analysis.states.oauth_state import OAuthSessionState | ||
| from factorialhr_analysis.states.project_state import ProjectSettingsState, ProjectState | ||
|
|
||
| __all__ = ['DataState', 'OAuthSessionState'] | ||
| __all__ = ['DataState', 'OAuthSessionState', 'ProjectSettingsState', 'ProjectState'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Stale Data After Clear: Inconsistent Refresh State
The
DataState.clear()method doesn't reset the newly added_time_records,_projects, and_project_workersfields. This can leave stale data in these fields whenrefresh_data()is called, leading to an inconsistent state.Additional Locations (1)
factorialhr_analysis/states/data_state.py#L16-L23