-
Notifications
You must be signed in to change notification settings - Fork 4
feat: new data provider extension #715
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
Draft
Ismir11
wants to merge
11
commits into
main
Choose a base branch
from
feat/data-providers-extensions
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.
Draft
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
fedb74e
Add files via upload
Ismir11 20575ec
Merge branch 'main' into feat/data-providers-extensions
Ismir11 6712016
chore: adding changelog file 715.added.md [dependabot-skip]
pyansys-ci-bot 8c97bb8
Merge branch 'main' into feat/data-providers-extensions
jwinkle8 d198464
fix: run and apply code-style formatting
jwinkle8 3ec7625
Merge branch 'feat/data-providers-extensions' of https://github.com/a…
jwinkle8 0fca5f3
fix: fix casing of enumeration
jwinkle8 d776ff4
Merge branch 'main' into feat/data-providers-extensions
jwinkle8 3957512
fix: more casing fixes
jwinkle8 5cfcbd1
test: add pytest snippet for data provider extension
jwinkle8 5acdf3e
chore: adding changelog file 715.added.md [dependabot-skip]
pyansys-ci-bot 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
104 changes: 104 additions & 0 deletions
104
extensions/src/ansys/stk/extensions/data_provider_extension.py
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,104 @@ | ||
| from asyncio.windows_events import NULL | ||
| import ansys.stk.core.stkobjects | ||
| import ansys.stk.core.vgt | ||
| from ansys.stk.core.stkobjects import IStkObject, DATA_PROVIDER_TYPE, Access | ||
| import pandas as pd | ||
|
|
||
|
|
||
| class data_provider_extension(object): | ||
| def __init__(self, base_object:IStkObject) -> None: | ||
| self.BaseObject = base_object | ||
| pass | ||
|
|
||
| def _get_fixed_data(self, provider_name, elements = None, pre_data = None): | ||
| fixed_data_provider = self.BaseObject.data_providers.item(provider_name) | ||
| if pre_data != None: | ||
| fixed_data_provider.pre_data = pre_data | ||
| if elements == None: | ||
| fixed_result = fixed_data_provider.execute() | ||
| else: | ||
| fixed_result = fixed_data_provider.execute_elements(elements) | ||
| fixed_result_data = fixed_result.data_sets.to_pandas_dataframe() | ||
| return fixed_result_data | ||
|
|
||
| def _get_interval_data(self,provider_name,start_time,stop_time, elements = None, pre_data = None): | ||
| interval_data_provider = self.BaseObject.data_providers.item(provider_name) | ||
| if pre_data != None: | ||
| interval_data_provider.pre_data = pre_data | ||
| if elements == None: | ||
| interval_result = interval_data_provider.execute(start_time, stop_time) | ||
| else: | ||
| interval_result = interval_data_provider.execute_elements(start_time, stop_time, elements) | ||
| interval_result_data = interval_result.data_sets.to_pandas_dataframe() | ||
| return interval_result_data | ||
|
|
||
| def _get_time_data(self,provider_name,start_time,stop_time,time_step, elements = None, pre_data = None): | ||
| time_data_provider = self.BaseObject.data_providers.get_data_provider_time_varying_from_path(provider_name) | ||
| if pre_data != None: | ||
| time_data_provider.pre_data = pre_data | ||
| if elements == None: | ||
| time_result = time_data_provider.execute(start_time, stop_time, time_step) | ||
| else: | ||
| time_result = time_data_provider.execute_elements(start_time, stop_time, time_step, elements) | ||
| if (time_result.sections.count > 0): | ||
| #Process sections | ||
| for x in range(0, time_result.sections.count): | ||
| for y in range(0, time_result.sections[x].intervals.count): | ||
| row_data = time_result.sections[x].intervals[y].data_sets.to_pandas_dataframe(); | ||
| row_data.insert(0,'Section','') | ||
| row_data['Section'] = time_result.sections[x].title | ||
| #print(row_data) | ||
| if x==0 and y==0: | ||
| panda = row_data | ||
| else: | ||
| panda = pd.concat([panda,row_data], ignore_index=True) | ||
| time_result_data = panda | ||
| else: | ||
| if (time_result.intervals.count > 0): | ||
| for i in range(0,time_result.intervals.count): | ||
| row = time_result.intervals[i].data_sets.to_pandas_dataframe() | ||
| if i > 0: | ||
| panda = pd.concat([panda,row], ignore_index=True) | ||
| else: | ||
| panda = row | ||
| time_result_data = panda | ||
| else: | ||
| time_result_data = time_result.data_sets.to_pandas_dataframe() | ||
| return time_result_data | ||
|
|
||
| def get_pandas(self,provider_path,start_time = None,stop_time = None,time_step = None, elements = None, pre_data = None): | ||
| if isinstance(self.BaseObject,Access): | ||
| root = self.BaseObject.target.root | ||
| else: | ||
| root = self.BaseObject.root | ||
| scenario = root.current_scenario | ||
| # To do: check if exists | ||
| provider_info = self.BaseObject.data_providers.get_data_provider_information_from_path(provider_path) | ||
| panda = None | ||
| match provider_info.type: | ||
| case DATA_PROVIDER_TYPE.FIXED: | ||
| panda = self._get_fixed_data(self, provider_path, elements, pre_data) | ||
| pass | ||
| case DATA_PROVIDER_TYPE.INTERVAL: | ||
| if start_time == None: | ||
| start_time = scenario.start_time | ||
| if stop_time == None: | ||
| stop_time = scenario.stop_time | ||
| panda = self._get_interval_data(self, provider_path, start_time, stop_time, elements, pre_data) | ||
| pass | ||
| case DATA_PROVIDER_TYPE.TIME_VARYING: | ||
| if start_time == None: | ||
| start_time = scenario.start_time | ||
| if stop_time == None: | ||
| stop_time = scenario.stop_time | ||
| if time_step == None: | ||
| time_step = 60.0 | ||
| #panda = self._get_time_data(self, provider_path, start_time, stop_time, time_step, elements, pre_data) | ||
| panda = self._get_time_data(provider_path, start_time, stop_time, time_step, elements, pre_data) | ||
| pass | ||
|
|
||
| return panda | ||
|
|
||
| def get_value_at_time(time): | ||
| pass | ||
|
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.