Skip to content

Commit

Permalink
Merge pull request #15 from seeq12/task/jh/spy-compatibility
Browse files Browse the repository at this point in the history
Task/jh/spy compatibility
  • Loading branch information
jameshiggie authored Aug 29, 2023
2 parents aa1b1dc + eb3013d commit 8db3256
Show file tree
Hide file tree
Showing 37 changed files with 281 additions and 45 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
/venv2
/dist
/build
/seeq_mps.egg-info
/seeq_mps.egg-info
/.vscode
*.pyc
Binary file added additional_content/mpsworkflowexample.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
66 changes: 66 additions & 0 deletions addon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"identifier": "com.seeq.addon.mps",
"name": "Multivariate Pattern Search",
"description": "Finds and measures similar events defined across multiple variables",
"version": "Input version here",
"license": "Apache-2.0 license",
"icon": "fa fa-leaf",
"tags": {"maintainer":"Seeq"},
"previews": [
"additional_content/mpsworkflowexample.png"
],
"elements": [
{
"name": "Multivariate Pattern Search",
"description": "Finds and measures similar events defined across multiple variables",
"identifier": "com.seeq.addon.mps.mps",
"type": "AddOnTool",
"path": "data-lab-functions",
"notebook_file_path": "multivariate_pattern_search_ui.ipynb",
"extensions": ["ipyvuetify", "widgetsnbextension","ipyvue"],
"configuration_schema": {
"type": "object",
"properties": {
"display": {
"type": "object",
"properties": {
"icon": {
"type": "string",
"default": "fa fa-leaf"
},
"linkType": {
"enum": ["window", "tab", "none"],
"default": "window"
},
"sortKey": {
"type": "string",
"default": "m"
},
"windowDetails": {
"type": "string",
"default": "toolbar=0,location=0,scrollbars=1,statusbar=0,menubar=0,resizable=1,height=900,width=600"
},
"reuseWindow": {
"type": "boolean",
"default": true
},
"includeWorkbookParameters": {
"type": "boolean",
"default": true
}
},
"required": [
"icon",
"linkType",
"sortKey",
"windowDetails",
"reuseWindow",
"includeWorkbookParameters"
]
}
},
"required": ["display"]
}
}
]
}
150 changes: 150 additions & 0 deletions build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
import sys
import os
import json
import zipfile
import pathlib
import shutil
import argparse
import subprocess
from pathlib import Path
from artifactory import ArtifactoryPath

parser = argparse.ArgumentParser()
parser.add_argument(
'-d', '--distribute',
help='Upload the built files to their distribution channels.',
action='store_true'
)
parser.add_argument(
'-c', '--compile',
help='Produce a compiled version of the code in addition to the source version',
action='store_true'
)
parser.add_argument(
'-a', '--addon',
help='Produce a zipped version for installation through the addon manager.',
action='store_true'
)
args = parser.parse_args()

# build the distribution
distribution_relative_dir = 'dist'
distribution_abs_dir = os.path.join(os.getcwd(), distribution_relative_dir)
if os.path.isdir(distribution_abs_dir):
shutil.rmtree(distribution_abs_dir)
build_command = ['python3.8', 'setup.py', 'bdist_wheel',
'-d', distribution_relative_dir,
f'--python-tag=py{sys.version_info.major}{sys.version_info.minor}']
subprocess.run(build_command, cwd=os.getcwd())
source_wheel = max(
[os.path.join(distribution_abs_dir, f) for f in os.listdir(distribution_abs_dir)],
key=os.path.getctime
)

source_wheel_name = os.path.split(source_wheel)[-1]
version = source_wheel_name.split('-')[1]

compiled_wheel = None
if args.compile:
print('Creating pyc file')
pyc_relative_dir = os.path.join(distribution_relative_dir, 'bin')
pyc_abs_dir = os.path.join(distribution_abs_dir, 'bin')
build_command = [sys.executable, 'setup.py', 'bdist_egg',
'-d', pyc_relative_dir,
'--exclude-source-files',
'-m', '+c']
build_result = subprocess.run(build_command, cwd=os.getcwd(), capture_output=True, text=True)
wheel_command = ['wheel', 'convert', os.path.join(pyc_relative_dir, '*.egg'), '-d', pyc_relative_dir]
wheel_result = subprocess.run(wheel_command, cwd=os.getcwd(), capture_output=True, text=True)

# move the pyc wheel file to the dist dir
path = Path('.')
wheel_file = list(path.glob('**/bin/*.whl'))[0]
wheel_file.rename(Path(wheel_file.parent.parent, wheel_file.name))
compiled_wheel = os.path.join(wheel_file.parent.parent, wheel_file.name)

# remove the bin dir
shutil.rmtree(pyc_abs_dir)

addon_manager_artifacts = []
if args.addon:
name = 'mps'
print(f'Creating {name}.addon')
# Ensure output folder exists
bin = os.path.join(os.getcwd(), 'bin')
if not os.path.exists(bin):
os.makedirs(bin)

with open('addon.json') as json_file:
parsed_json = json.load(json_file)
parsed_json['version'] = version

addon = os.path.join(bin, f'{name}.addon')
addon_meta = os.path.join(bin, f'{name}.addonmeta')

# Build addon
with zipfile.ZipFile(addon, 'w') as z:
z.write(source_wheel, arcname=os.path.join('data-lab-functions', source_wheel_name))
z.writestr('data-lab-functions/requirements.txt', f"./{source_wheel_name}")
with z.open("addon.json", "w") as c:
c.write(json.dumps(parsed_json, indent=2).encode("utf-8"))
directory = pathlib.Path("./seeq/addons/mps/deployment_notebook/")
for file in directory.rglob('*ipynb'):
z.write(file, arcname=os.path.join('data-lab-functions', file.name))
directory = pathlib.Path("./additional_content/")
for file in directory.iterdir():
z.write(file)
addon_manager_artifacts.append(addon)
# Build addonmeta
print(f'Creating {name}.addonmeta')
with zipfile.ZipFile(addon_meta, 'w') as z:
with z.open("addon.json", "w") as c:
c.write(json.dumps(parsed_json, indent=2).encode("utf-8"))
directory = pathlib.Path("./additional_content/")
for file in directory.iterdir():
z.write(file)
addon_manager_artifacts.append(addon_meta)

print('Successfully created.')

if args.distribute:

# THIS BLOCK OF CODE IS NO MORE IN USE BUT COULD LATER BE USED IN FUTURE PURPOSES
# if compiled_wheel is not None:
# print(f'Distributing compiled wheel {compiled_wheel} to pipy.seeq.com')
# command_distribute_compiled = \
# ['twine', 'upload',
# '--repository-url', 'https://pypi.seeq.com',
# '-u', username,
# '-p', password,
# compiled_wheel]
# result = subprocess.run(' '.join(command_distribute_compiled))
# if result.stderr:
# print(f'There was an error uploading the compiled version: {result.stderr}')
#
# print(f'Distributing source wheel {source_wheel} to pypi.seeq.com:8081')
# command_distribute_source = \
# ['twine', 'upload',
# '--repository-url', 'https://pypi.seeq.com:8081',
# '-u', username,
# '-p', password,
# source_wheel]
# result = subprocess.run(' '.join(command_distribute_source))
# if result.stderr:
# print(f'There was an error uploading the source version: {result.stderr}')

if addon_manager_artifacts:
print(f'Distributing addon manager artifacts to seeq.jfrog.io')
api_key = os.getenv('JFROG_API_KEY')
for artifact in addon_manager_artifacts:
_, file = os.path.split(artifact)
path = ArtifactoryPath(f"https://seeq.jfrog.io/artifactory/seeq-add-ons-prod-local/MPS/{file}",
apikey=api_key)
try:
path.deploy_file(artifact)
properties = path.properties
# Add identifier property
properties["identifier"] = "com.seeq.addon.mps"
path.properties = properties
except Exception as e:
print(e)
2 changes: 1 addition & 1 deletion docs/.buildinfo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Sphinx build info version 1
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
config: 453c5033e0073cec06bfc0c629464f62
config: edda4a5e011af0560c8e3a788a3bb741
tags: 645f666f9bcd5a90fca523b33c5a78b7
4 changes: 2 additions & 2 deletions docs/_modules/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Overview: module code &mdash; seeq-mps 0.3.4 documentation</title>
<title>Overview: module code &mdash; seeq-mps 0.3.5 documentation</title>
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="../_static/css/theme.css" type="text/css" />
<!--[if lt IE 9]>
Expand All @@ -26,7 +26,7 @@
<a href="../index.html" class="icon icon-home"> seeq-mps
</a>
<div class="version">
0.3.4
0.3.5
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
Expand Down
4 changes: 2 additions & 2 deletions docs/_modules/seeq/addons/mps/__main__.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>seeq.addons.mps.__main__ &mdash; seeq-mps 0.3.4 documentation</title>
<title>seeq.addons.mps.__main__ &mdash; seeq-mps 0.3.5 documentation</title>
<link rel="stylesheet" href="../../../../_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="../../../../_static/css/theme.css" type="text/css" />
<!--[if lt IE 9]>
Expand All @@ -26,7 +26,7 @@
<a href="../../../../index.html" class="icon icon-home"> seeq-mps
</a>
<div class="version">
0.3.4
0.3.5
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../../../search.html" method="get">
Expand Down
8 changes: 4 additions & 4 deletions docs/_modules/seeq/addons/mps/_mps.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>seeq.addons.mps._mps &mdash; seeq-mps 0.3.4 documentation</title>
<title>seeq.addons.mps._mps &mdash; seeq-mps 0.3.5 documentation</title>
<link rel="stylesheet" href="../../../../_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="../../../../_static/css/theme.css" type="text/css" />
<!--[if lt IE 9]>
Expand All @@ -26,7 +26,7 @@
<a href="../../../../index.html" class="icon icon-home"> seeq-mps
</a>
<div class="version">
0.3.4
0.3.5
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../../../search.html" method="get">
Expand Down Expand Up @@ -677,7 +677,7 @@ <h1>Source code for seeq.addons.mps._mps</h1><div class="highlight"><pre>
<span class="k">for</span> <span class="n">time_distort_</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span> <span class="o">+</span> <span class="n">time_distort</span><span class="p">,</span> <span class="mi">1</span><span class="p">):</span>
<span class="n">search_size_stretch</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">known</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">*</span> <span class="p">(</span><span class="n">time_distort_</span> <span class="o">/</span> <span class="mi">100</span><span class="p">))</span>
<span class="c1"># size of steps taken during dtw distance measurement across the dataset</span>
<span class="n">window_step</span> <span class="o">=</span> <span class="mi">1</span> <span class="c1">#round(len(known) * 0.05)</span>
<span class="n">window_step</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="nb">round</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">known</span><span class="p">)</span> <span class="o">*</span> <span class="mf">0.05</span><span class="p">))</span>
<span class="k">if</span> <span class="n">window_step</span> <span class="o">&lt;=</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">window_step</span> <span class="o">=</span> <span class="mi">1</span>
<span class="k">for</span> <span class="n">var</span> <span class="ow">in</span> <span class="n">data_pull</span><span class="o">.</span><span class="n">columns</span><span class="p">[:</span><span class="o">-</span><span class="mi">1</span><span class="p">]:</span>
Expand Down Expand Up @@ -772,7 +772,7 @@ <h1>Source code for seeq.addons.mps._mps</h1><div class="highlight"><pre>
<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">found_all_sorted</span><span class="o">.</span><span class="n">index</span><span class="p">:</span>
<span class="n">loc_c</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">var</span><span class="p">)</span> <span class="o">+</span> <span class="s1">&#39;_&#39;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">found_all_sorted</span><span class="p">[</span><span class="mi">3</span><span class="p">][</span><span class="n">i</span><span class="p">])[</span><span class="mi">0</span><span class="p">]</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">found_all_sorted</span><span class="p">[</span><span class="mi">4</span><span class="p">][</span><span class="n">i</span><span class="p">])[</span><span class="mi">0</span><span class="p">]</span>
<span class="n">loc_i</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">found_all_sorted</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="n">i</span><span class="p">])</span>
<span class="n">found_all_sorted</span><span class="p">[</span><span class="nb">len</span><span class="p">(</span><span class="n">found_all_sorted</span><span class="o">.</span><span class="n">columns</span><span class="p">)</span> <span class="o">-</span> <span class="mi">1</span><span class="p">][</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">meta_data</span><span class="p">[</span><span class="n">loc_c</span><span class="p">][</span><span class="n">loc_i</span> <span class="o">/</span> <span class="n">window_step</span><span class="p">]</span>
<span class="n">found_all_sorted</span><span class="p">[</span><span class="nb">len</span><span class="p">(</span><span class="n">found_all_sorted</span><span class="o">.</span><span class="n">columns</span><span class="p">)</span> <span class="o">-</span> <span class="mi">1</span><span class="p">][</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">meta_data</span><span class="p">[</span><span class="n">loc_c</span><span class="p">][</span><span class="nb">int</span><span class="p">(</span><span class="n">loc_i</span> <span class="o">/</span> <span class="n">window_step</span><span class="p">)]</span>

<span class="n">found_all_sorted</span><span class="p">[</span><span class="s1">&#39;sum&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">found_all_sorted</span><span class="o">.</span><span class="n">loc</span><span class="p">[:,</span> <span class="mi">5</span><span class="p">:]</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
<span class="k">if</span> <span class="n">found_all_sorted</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
Expand Down
4 changes: 2 additions & 2 deletions docs/_modules/seeq/addons/mps/_mps_sdl_ui.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>seeq.addons.mps._mps_sdl_ui &mdash; seeq-mps 0.3.4 documentation</title>
<title>seeq.addons.mps._mps_sdl_ui &mdash; seeq-mps 0.3.5 documentation</title>
<link rel="stylesheet" href="../../../../_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="../../../../_static/css/theme.css" type="text/css" />
<!--[if lt IE 9]>
Expand All @@ -26,7 +26,7 @@
<a href="../../../../index.html" class="icon icon-home"> seeq-mps
</a>
<div class="version">
0.3.4
0.3.5
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../../../search.html" method="get">
Expand Down
4 changes: 4 additions & 0 deletions docs/_sources/changelog.md.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

v0.3.5
---
Dtw improvments, fucntions to package MPS for use in addon manager

v0.3.4
---
Dtw bugfix, install bugfix for future SDL upgrades and pytest update
Expand Down
2 changes: 1 addition & 1 deletion docs/_static/documentation_options.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var DOCUMENTATION_OPTIONS = {
URL_ROOT: document.getElementById("documentation_options").getAttribute('data-url_root'),
VERSION: '0.3.4',
VERSION: '0.3.5',
LANGUAGE: 'en',
COLLAPSE_INDEX: false,
BUILDER: 'html',
Expand Down
4 changes: 2 additions & 2 deletions docs/add_on_installation.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="utf-8" /><meta name="generator" content="Docutils 0.19: https://docutils.sourceforge.io/" />

<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Add-on Installation &mdash; seeq-mps 0.3.4 documentation</title>
<title>Add-on Installation &mdash; seeq-mps 0.3.5 documentation</title>
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
<!--[if lt IE 9]>
Expand All @@ -29,7 +29,7 @@
<a href="index.html" class="icon icon-home"> seeq-mps
</a>
<div class="version">
0.3.4
0.3.5
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="search.html" method="get">
Expand Down
4 changes: 2 additions & 2 deletions docs/backend_calculations.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="utf-8" /><meta name="generator" content="Docutils 0.19: https://docutils.sourceforge.io/" />

<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Backend &mdash; seeq-mps 0.3.4 documentation</title>
<title>Backend &mdash; seeq-mps 0.3.5 documentation</title>
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
<!--[if lt IE 9]>
Expand All @@ -29,7 +29,7 @@
<a href="index.html" class="icon icon-home"> seeq-mps
</a>
<div class="version">
0.3.4
0.3.5
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="search.html" method="get">
Expand Down
Loading

0 comments on commit 8db3256

Please sign in to comment.