-
Notifications
You must be signed in to change notification settings - Fork 2
GMIM-353: Add utility method to fetch widget data... #79
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
yashdattsawant
wants to merge
47
commits into
master
Choose a base branch
from
GMI-353-async
base: master
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
47 commits
Select commit
Hold shift + click to select a range
5e7224c
GMI-353: get widget data from dashboard
yashdattsawant 5e97ebb
GMI-353: black format
yashdattsawant f1098a4
GMI-353: rename file
yashdattsawant ba88888
GMI-353: rename fields
yashdattsawant 0a44f64
GMI-353: Add compare by field to create share link
yashdattsawant 371a3b9
GMI-353: Black format files
yashdattsawant 028473f
GMI-353: Black format files
yashdattsawant 5eb6435
GMI-353: Black format files
yashdattsawant 0ee1247
GMI-353: Add in use flag in share link
yashdattsawant 2b422a1
GMIM-353: Add dashboard code
yashdattsawant 5666bea
GMIM-353: Add black code format
yashdattsawant 54a66ef
GMIM-353: Add dashboard code
yashdattsawant 75b05cf
GMIM-353: black format
yashdattsawant 71a5176
GMIM-353: Add support for line model and share link for lines model
yashdattsawant d2af978
GMIM-353: Black format code
yashdattsawant 40b9590
GMIM-353: Add support to analytics SingleValue, Event Timeline analytics
yashdattsawant c3eb788
GMIM-353: Black format the code
yashdattsawant 76c1161
GMIM-353: Add sharelink support to data viz analytics like Single Val…
yashdattsawant 795f995
GMIM-439: add UDF support in smsdk
yashdattsawant a1d9b5d
GMIM-439: add UDF support in smsdk
yashdattsawant 5dfe926
GMIM-439: Sightmachine SDK add method to call UDF
yashdattsawant dd42657
GMIM-439: Sightmachine SDK add method to call UDF
yashdattsawant 32da602
GMIM-439: Sightmachine SDK add method to call UDF
yashdattsawant 0345fa1
GMIM-439: Add utility method to list UDFs
yashdattsawant 16d35cc
GMIM-439: Add utility method to list UDFs
yashdattsawant cd44067
Clean up commits
yashdattsawant c18e4c9
Merge branch 'master' into GMI-353-async
yashdattsawant dd2b6a6
Black format files
yashdattsawant 58245f5
MyPy refactor code
yashdattsawant 6d1b31d
MyPy formating
yashdattsawant bc57208
MyPy formatting
yashdattsawant cda912c
Test case fixture
yashdattsawant 64c1f96
black format
yashdattsawant 6cb2b77
Mypy formatting
yashdattsawant 696da53
Mypy formatting
yashdattsawant 25d8cdf
Mypy formatting
yashdattsawant a5d9da6
Mypy formating for dev_udf
yashdattsawant 8011182
Mypy formating for dev_udf
yashdattsawant f5e949c
Mypy formating for dev_udf
yashdattsawant 15c7f5f
Mypy formating for dev_udf
yashdattsawant 2fe8cea
Mypy workspace.py
yashdattsawant 7b9af38
Mypy workspace.py
yashdattsawant bc7434e
Code cleanup
yashdattsawant 9615f73
GMIM-353: changes in code per comments
yashdattsawant dc4950e
GMIM-353: update code as per comments
yashdattsawant fa7807c
GMIM: resolve time sleep code into loop
yashdattsawant e819479
GMIM: resolve time sleep code into loop
yashdattsawant 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,3 +7,4 @@ mock>=4.0.2 | |
| importlib-resources>=3.0.0 | ||
| pathos>=0.2.7 | ||
| plotly==5.18.0 | ||
| beautifulsoup4>=4.12.3 | ||
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
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
Empty file.
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,41 @@ | ||
| from typing import List, Any, Dict, Tuple | ||
| import json | ||
|
|
||
| import importlib.resources as pkg_resources | ||
| from smsdk.tool_register import SmsdkEntities, smsdkentities | ||
| from smsdk.utils import module_utility | ||
| from smsdk import config | ||
| from smsdk.ma_session import MaSession | ||
| import logging | ||
|
|
||
| log = logging.getLogger(__name__) | ||
|
|
||
| ENDPOINTS = json.loads(pkg_resources.read_text(config, "api_endpoints.json")) | ||
|
|
||
|
|
||
| @smsdkentities.register("dashboard") | ||
| class DashboardData(SmsdkEntities, MaSession): | ||
| # Decorator to register a function as utility | ||
| # Only the registered utilites would be accessible | ||
| # to outside world via client.get_data() | ||
| mod_util = module_utility() | ||
| log = log | ||
|
|
||
| def __init__(self, session: Any, base_url: str) -> None: | ||
| self.session = session | ||
| self.base_url = base_url | ||
|
|
||
| @mod_util | ||
| def get_utilities( | ||
| self, *args: Tuple[Any, ...], **kwargs: Dict[str, Any] | ||
| ) -> List[Any]: | ||
| return [*self.mod_util.all] | ||
|
|
||
| @mod_util | ||
| def get_dashboards(self, dashboard_id: str) -> List[Any]: | ||
| """ | ||
| Utility function to get the panels data for dashboard | ||
| """ | ||
| url = "{}{}{}".format(self.base_url, "/v1/obj/dashboard/", dashboard_id) | ||
| panels: List[Any] = self._get_dashboard_panels(url, method="get") | ||
| return panels |
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 |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
| from datetime import datetime, timedelta | ||
| from typing import List | ||
| import uuid | ||
| from smsdk.Auth.auth import X_SM_WORKSPACE_ID | ||
|
|
||
| import numpy as np | ||
|
|
||
|
|
@@ -43,7 +44,16 @@ def get_utilities(self, *args, **kwargs) -> List: | |
|
|
||
| @mod_util | ||
| def create_share_link( | ||
| self, asset, chartType, yAxis, xAxis, model, time_selection, *args, **kwargs | ||
| self, | ||
| asset, | ||
| chartType, | ||
| yAxis, | ||
| xAxis, | ||
| model, | ||
| time_selection, | ||
| are_line_params_available=False, | ||
| *args, | ||
| **kwargs | ||
| ): | ||
| """ | ||
| Creates a share link | ||
|
|
@@ -52,6 +62,13 @@ def create_share_link( | |
| url_params = {} | ||
| url_params["state_hash"] = str(uuid.uuid4())[:8] | ||
| url_params["context"] = "/analysis/datavis" | ||
| try: | ||
| url_params["in_use_workspace"] = self.session.headers[X_SM_WORKSPACE_ID] | ||
| except: | ||
| print( | ||
| "Creating dashboard over prod since we didn't get WORKSPACE_ID from headers" | ||
| ) | ||
| pass | ||
| if time_selection["time_type"] == "relative": | ||
| dateRange = { | ||
| "mode": "relative", | ||
|
|
@@ -67,6 +84,8 @@ def create_share_link( | |
| "endDate": time_selection["end_time"], | ||
| "selectedTimeZone": time_selection["time_zone"], | ||
| } | ||
| else: | ||
| dateRange = {} | ||
| url_params["state"] = { | ||
| "dataModel": model, | ||
| "asset": asset, | ||
|
|
@@ -75,7 +94,7 @@ def create_share_link( | |
| "dateRange": dateRange, | ||
| } | ||
| url_params["state"].update(kwargs) | ||
| if model == "line": | ||
| if model == "line" and not are_line_params_available: | ||
| del url_params["state"]["asset"] | ||
| url_params["state"]["lineProcess"] = {} | ||
| if not isinstance(asset, List) and asset.get("assetOffsets"): | ||
|
|
@@ -138,6 +157,49 @@ def create_share_link( | |
| else: | ||
| url_params["state"]["yAxis"] = yAxis | ||
| response = getattr(self.session, "post")(url, json=url_params) | ||
| return "{}/#/analysis/datavis/s/{}".format( | ||
| self.base_url, response.json()["state_hash"] | ||
| return "{}/#{}/s/{}".format( | ||
| self.base_url, url_params["context"], response.json()["state_hash"] | ||
| ) | ||
|
|
||
| @mod_util | ||
| def get_dashboard_widget_data(self, model, *args, **kwargs): | ||
| """ | ||
| Takes a query params from the widget in dashboard | ||
| Returns Data info for that query | ||
| """ | ||
| is_analytics = False | ||
| if model == "line": | ||
| endpoint = ENDPOINTS["DataViz"]["line_task"] | ||
| elif model == "cycle": | ||
| endpoint = ENDPOINTS["DataViz"]["task"] | ||
| kwargs["model"] = model | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| else: | ||
| endpoint = ENDPOINTS["DataViz"]["analytics_task"] | ||
| is_analytics = True | ||
| kwargs["is_analytics"] = is_analytics | ||
| url = "{}{}".format(self.base_url, endpoint) | ||
| records = self._complete_async_task(url, **kwargs) | ||
|
|
||
| if not isinstance(records, List) and not is_analytics: | ||
| raise ValueError("Error - {}".format(records)) | ||
|
|
||
| return records | ||
|
|
||
| @mod_util | ||
| def create_widget_share_link(self, context, **kwargs): | ||
| url = "{}{}".format(self.base_url, ENDPOINTS["DataViz"]["share_link"]) | ||
| url_params = {} | ||
| url_params["state_hash"] = str(uuid.uuid4())[:8] | ||
yashdattsawant marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| url_params["context"] = context | ||
| try: | ||
| url_params["in_use_workspace"] = self.session.headers[X_SM_WORKSPACE_ID] | ||
| except: | ||
| print( | ||
| "Creating dashboard over prod since we didn't get WORKSPACE_ID from headers" | ||
| ) | ||
| pass | ||
yashdattsawant marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| url_params["state"] = kwargs | ||
| response = getattr(self.session, "post")(url, json=url_params) | ||
| return "{}/#{}/s/{}".format( | ||
| self.base_url, url_params["context"], response.json()["state_hash"] | ||
| ) | ||
Empty file.
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.