Pulley Forecast Takehome #1
Open
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.
Project Forecast Solution
Overview
The
getPermitForecastfunction in our application calculates forecasted submission (submitDate) and approval (approvalDate) dates for a set of permits, considering their dependencies.Screen.Recording.2024-01-16.at.12.37.16.AM.mov
Functionality
Dependency Sorting
Permits are sorted based on their dependencies using the
sortPermitsByDependenciesfunction. This sorting ensures that each permit is processed only after all its dependencies have been processed.Date Calculation
For each permit, if it has dependencies, the
submitDateis set to the day the latestapprovalDateof all its dependencies. If there are no dependencies,submitDateis set to the project's kickoff date. TheapprovalDateis calculated by adding theestimatedDurationof the permit to itssubmitDate.Testing Strategy
Unit Tests: Comprehensive unit tests are written for
getPermitForecastto ensure accuracy in various scenarios: permits with no dependencies, permits with multiple dependencies, and permits with sequential dependencies.Edge Cases: Tests include handling edge cases like zero duration permits or permits with dependencies that have not yet been resolved.
Mock Data: Mock permit data is used in tests to simulate real-world scenarios. This data helps validate the accuracy of date calculations and dependency resolution.
Runtime Complexity
The runtime complexity of the
getPermitForecastfunction depends on two primary factors:Sorting by Dependencies: The
sortPermitsByDependenciesfunction performs topological sorting, which has a complexity of O(V + E), where V is the number of permits and E is the number of dependencies.Date Calculation: Iterating through each permit to calculate dates has a complexity of O(N), where N is the number of permits.
Overall, the complexity is O(V + E + N), which is generally efficient for practical use-cases.
Future Improvements (if more time were available)
If more time were available, several improvements could be considered:
Optimization: Performance optimization could be explored to make the calculation even more efficient for large datasets.
Parallel Processing: Depending on the requirements, parallel processing of permits could be investigated to speed up calculations.
Visualization: Creating a visualization of the permit approval workflow could be beneficial for project planning and monitoring.
Other Approaches Not Pursued
One alternative approach would be to use a graph-based data structure to model permit dependencies explicitly. This could simplify the dependency resolution process but might require more memory and complexity in managing the graph.
Another approach could involve a more iterative dependency resolution process that repeatedly scans the permits to check for resolved dependencies until all permits are processed. However, this might not be as efficient as the topological sorting method used in the current implementation.