-
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.
- Loading branch information
1 parent
f8dd63e
commit 8e586eb
Showing
6 changed files
with
807 additions
and
1 deletion.
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
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,41 @@ | ||
# BSD 3-Clause License | ||
|
||
# Copyright (c) 2019-2021, engageLively | ||
# All rights reserved. | ||
|
||
# Redistribution and use in source and binary forms, with or without | ||
# modification, are permitted provided that the following conditions are met: | ||
|
||
# 1. Redistributions of source code must retain the above copyright notice, this | ||
# list of conditions and the following disclaimer. | ||
|
||
# 2. Redistributions in binary form must reproduce the above copyright notice, | ||
# this list of conditions and the following disclaimer in the documentation | ||
# and/or other materials provided with the distribution. | ||
|
||
# 3. Neither the name of the copyright holder nor the names of its | ||
# contributors may be used to endorse or promote products derived from | ||
# this software without specific prior written permission. | ||
|
||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
""" | ||
The Python client for Galyleo Tables and JupyterLab. This client is used to form Galyleo Tables, the basis of charting and dashboards with the Galyleo environment, and send them through the Jupyter communications channel to the browser to be plotted. The library consists of several modules: | ||
1. galyleo_table. Defines a Galyleo Dashboard Table and associated export and import routines. Used to create a Galyleo Dashboard Table from any of a number of sources, and then generate an object that is suitable | ||
for storage (as a JSON file). A GalyleoTable is very similar to a Google Visualization data table, and can be | ||
converted to a Google Visualization Data Table on either the Python or the JavaScript side. | ||
Convenience routines provided here to import data from pandas, and json format. | ||
2. galyleo_constants: Constants that are used, primarily by galyleo_table | ||
3. galyleo_exceptions: Exceptions raised by the module. These notably include exceptions raised by galyleo_jupyter_client when a table is too large to be sent, and by galyleo_table when a table's schema and data don't match | ||
4. galyleo_jupyter_client: A clien that actually sends data to JupyterLab | ||
""" | ||
name = "galyleo" |
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 @@ | ||
# BSD 3-Clause License | ||
|
||
# Copyright (c) 2019-2021, engageLively | ||
# All rights reserved. | ||
|
||
# Redistribution and use in source and binary forms, with or without | ||
# modification, are permitted provided that the following conditions are met: | ||
|
||
# 1. Redistributions of source code must retain the above copyright notice, this | ||
# list of conditions and the following disclaimer. | ||
|
||
# 2. Redistributions in binary form must reproduce the above copyright notice, | ||
# this list of conditions and the following disclaimer in the documentation | ||
# and/or other materials provided with the distribution. | ||
|
||
# 3. Neither the name of the copyright holder nor the names of its | ||
# contributors may be used to endorse or promote products derived from | ||
# this software without specific prior written permission. | ||
|
||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
""" | ||
Constants that are used throughout the module. These include: | ||
1. Data types for a table (GALYLEO_STRING, GALYLEO_NUMBER, GALYLEO_BOOLEAN, GALYLEO_DATE, GALYLEO_DATETIME, GALYLEO_TIME_OF_DAY) | ||
2. GALYLEO_TYPES: The types in a list | ||
3. MAXIMUM_DATA_SIZE: Maximum size, in bytes, of a GalyleoTable | ||
4. MAX_TABLE_ROWS: Maximum number of rows in a GalyleoTable | ||
""" | ||
|
||
LIBRARY_VERSION = "2021.x.y" | ||
|
||
GALYLEO_STRING = 'string' | ||
GALYLEO_NUMBER = 'number' | ||
GALYLEO_BOOLEAN = 'boolean' | ||
GALYLEO_DATE = 'date' | ||
GALYLEO_DATETIME = 'datetime' | ||
GALYLEO_TIME_OF_DAY = 'timeofday' | ||
|
||
""" Types for a chart/dashboard table schema """ | ||
GALYLEO_SCHEMA_TYPES = ['string', 'number', 'boolean', 'date', 'datetime','timeofday'] | ||
|
||
""" Maximum size of a table being sent to the dashoard. Exceeding this will throw a DataSizeExceeded exception """ | ||
MAX_DATA_SIZE = 1*2**24 | ||
|
||
"""Maximum number of rows in a table""" | ||
MAX_TABLE_ROWS = 1000000 # 1 million rows per table at most. | ||
|
||
# Other constants | ||
MILLISECONDS_PER_SECOND = 1000 |
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,59 @@ | ||
# BSD 3-Clause License | ||
|
||
# Copyright (c) 2019-2021, engageLively | ||
# All rights reserved. | ||
|
||
# Redistribution and use in source and binary forms, with or without | ||
# modification, are permitted provided that the following conditions are met: | ||
|
||
# 1. Redistributions of source code must retain the above copyright notice, this | ||
# list of conditions and the following disclaimer. | ||
|
||
# 2. Redistributions in binary form must reproduce the above copyright notice, | ||
# this list of conditions and the following disclaimer in the documentation | ||
# and/or other materials provided with the distribution. | ||
|
||
# 3. Neither the name of the copyright holder nor the names of its | ||
# contributors may be used to endorse or promote products derived from | ||
# this software without specific prior written permission. | ||
|
||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
"""Galyleo specific exceptions""" | ||
|
||
# define Python user-defined exceptions | ||
class Error(Exception): | ||
"""Base class for other exceptions.""" | ||
pass | ||
|
||
class DataSizeExceeded(Error): | ||
""" | ||
Raised when the data volume is too large on a single request. The exact limitations are specified in README.md and in galyleo_constants | ||
""" | ||
def __str__(self): | ||
return "Data Size Exceeded" | ||
|
||
class DataSizeIsZero(Error): | ||
"""Raised when the data set is empty.""" | ||
|
||
def __str__(self): | ||
return "Data Size Is Zero" | ||
|
||
|
||
|
||
class InvalidDataException(Exception): | ||
''' | ||
An exception thrown when a data table (list of rows) doesn't match an accoompanying schema, | ||
or a bad schema is specified, or a table row is the wrong length, or.. | ||
''' | ||
pass |
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,71 @@ | ||
# BSD 3-Clause License | ||
|
||
# Copyright (c) 2019-2021, engageLively | ||
# All rights reserved. | ||
|
||
# Redistribution and use in source and binary forms, with or without | ||
# modification, are permitted provided that the following conditions are met: | ||
|
||
# 1. Redistributions of source code must retain the above copyright notice, this | ||
# list of conditions and the following disclaimer. | ||
|
||
# 2. Redistributions in binary form must reproduce the above copyright notice, | ||
# this list of conditions and the following disclaimer in the documentation | ||
# and/or other materials provided with the distribution. | ||
|
||
# 3. Neither the name of the copyright holder nor the names of its | ||
# contributors may be used to endorse or promote products derived from | ||
# this software without specific prior written permission. | ||
|
||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
from ipykernel.comm import Comm | ||
from galyleo.galyleo_table import GalyleoTable | ||
from galyleo.galyleo_exceptions import DataSizeExceeded | ||
from galyleo.galyleo_constants import MAX_DATA_SIZE, MAX_TABLE_ROWS | ||
|
||
|
||
|
||
class GalyleoClient: | ||
""" | ||
The Dashboard Client. This is the client which sends the tables to the dashboard | ||
and handles requests coming from the dashboard for tables. | ||
""" | ||
def __init__(self): | ||
"""Initialize the client. No parameters. This initializes communications with the JupyterLab Galyleo Communications Manager """ | ||
self._comm_ = Comm(target_name='galyleo_data', data={'foo': 1}) | ||
|
||
|
||
def send_data_to_dashboard(self, galyleo_table, dashboard_name:str = None)->None: | ||
""" | ||
The routine to send a GalyleoTable to the dashboard, optionally specifying a specific | ||
dashboard to send the data to. If None is specified, sends to all the dashboards. | ||
The table must not have more than galyleo_constants.MAX_NUMBER_ROWS, nor be (in JSON form) > galyleo_constants.MAX_DATA_SIZE. | ||
If either of these conditions apply, a DataSizeExceeded exception is thrown. | ||
NOTE: this sends data to one or more open dashboard editors in JupyterLab. If there are no dashboard editors open, it will have no effect. | ||
Args: | ||
galyleo_table: the table to send to the dashboard | ||
dashboard_name: name of the dashboard editor to send it to (if None, sent to all) | ||
""" | ||
# Very simple. Convert the table to a dictionary and send it to the dashboard | ||
# and wrap it in a payload to send to the dashboard | ||
if (len(galyleo_table.data) > MAX_TABLE_ROWS): | ||
raise DataSizeExceeded(f"{len(table.rows)} rows is greater than the maximum permitted, {MAX_TABLE_ROWS}") | ||
string_form = galyleo_table.to_json() | ||
if (len(string_form) > MAX_DATA_SIZE): | ||
raise DataSizeExceeded(f"{len(string_form)} bytes is greater than the maximum permitted, {MAX_DATA_SIZE}") | ||
table_record = galyleo_table.as_dictionary() | ||
if (dashboard_name): | ||
table_record["dashboard"] = dashboard_name | ||
self._comm_.send(table_record) |
Oops, something went wrong.