-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from rogers-obrien-rad/feature/13/changelog
Feature/13/changelog
- Loading branch information
Showing
7 changed files
with
210 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -217,4 +217,5 @@ replay_pid* | |
*.code-workspace | ||
|
||
# Directories | ||
*reference* | ||
*reference* | ||
*reports* |
This file contains 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 @@ | ||
requests | ||
pytest | ||
python-dotenv | ||
matplotlib | ||
matplotlib | ||
pandas |
This file contains 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,48 @@ | ||
from smartpm.client import SmartPMClient | ||
from smartpm.decorators import api_wrapper, utility | ||
from smartpm.utils import plot_schedule_changes | ||
from smartpm.logging_config import logger | ||
|
||
class Changes: | ||
def __init__(self, client: SmartPMClient): | ||
self.client = client | ||
|
||
@api_wrapper | ||
def get_changes_summary(self, project_id, scenario_id): | ||
""" | ||
Retrieve summary information about the changes that have happened to a scenario over time: https://developers.smartpmtech.com/#operation/get-change-log-sumamry | ||
Parameters | ||
---------- | ||
project_id : str | ||
The Project ID containing the scenario for which you would like to pull the changes summary from | ||
scenario_id : str | ||
The Scenario ID for which you would like to pull the changes summary from | ||
Returns | ||
------- | ||
<response.json> : dict | ||
Changes summary data as a JSON object | ||
""" | ||
logger.debug(f"Fetching changes summary for project_id: {project_id}, scenario_id: {scenario_id}") | ||
|
||
endpoint = f'v1/projects/{project_id}/scenarios/{scenario_id}/change-log-summary' | ||
response = self.client._get(endpoint=endpoint) | ||
|
||
return response | ||
|
||
@utility | ||
def plot_changes_summary(self, project_id, scenario_id): | ||
""" | ||
Retrieve the changes summary data and plot it. | ||
Reproduces this figure from SmartPM: https://help.smartpmtech.com/trends-schedule-changes-over-time | ||
Parameters | ||
---------- | ||
project_id : str | ||
ID of the project containing the scenario | ||
scenario_id : str | ||
ID of the scenario to retrieve the percent complete curve for | ||
""" | ||
logger.debug(f"Plotting changes summary for project_id: {project_id}, scenario_id: {scenario_id}") | ||
curve_data = self.get_changes_summary(project_id, scenario_id) | ||
plot_schedule_changes(curve_data) |
This file contains 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 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 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,58 @@ | ||
import os | ||
import sys | ||
import json | ||
|
||
# Add the package root directory to the sys.path | ||
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '../'))) | ||
|
||
from dotenv import load_dotenv | ||
load_dotenv() # Load environment variables from .env file | ||
|
||
from smartpm.client import SmartPMClient | ||
from smartpm.endpoints.projects import Projects # import projects to get project IDs | ||
from smartpm.endpoints.scenarios import Scenarios | ||
from smartpm.endpoints.changes import Changes | ||
|
||
API_KEY = os.getenv("API_KEY") | ||
COMPANY_ID = os.getenv("COMPANY_ID") | ||
|
||
def main(): | ||
# Setup SDK | ||
client = SmartPMClient(API_KEY, COMPANY_ID) | ||
projects_api = Projects(client) | ||
scenarios_api = Scenarios(client) | ||
changes_api = Changes(client) | ||
|
||
# Get Changes Summary | ||
# ------------------- | ||
# Find project by name | ||
name_to_find = "212096 - 401 FIRST STREET (College Station)" # replace with your project name | ||
project = projects_api.find_project_by_name(name=name_to_find) | ||
project_id = project["id"] | ||
|
||
# Find scenario by name | ||
scenario_to_find = "Full Schedule" # replace with your scenario name | ||
matching_scenarios = scenarios_api.find_scenario_by_name( | ||
project_id=project_id, | ||
scenario_name=scenario_to_find | ||
) | ||
scenario_id = matching_scenarios[-1].get("id") | ||
|
||
print("Get Summary Changes") | ||
changes_summary = changes_api.get_changes_summary( | ||
project_id=project_id, | ||
scenario_id=scenario_id | ||
) | ||
print("Example changes summary entry:") | ||
print(json.dumps(changes_summary[0], indent=4)) | ||
# ------------------- | ||
|
||
# Plot Changes Summary | ||
# -------------------- | ||
changes_api.plot_changes_summary( | ||
project_id=project_id, | ||
scenario_id=scenario_id | ||
) | ||
|
||
if __name__ == "__main__": | ||
main() |
This file contains 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