Skip to content

Commit

Permalink
Apps get apps
Browse files Browse the repository at this point in the history
  • Loading branch information
kks32 committed Nov 12, 2024
1 parent db6f1a7 commit 7766d2d
Show file tree
Hide file tree
Showing 10 changed files with 237 additions and 156 deletions.
3 changes: 3 additions & 0 deletions dapi/apps/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .apps import find_apps, get_app_version

__all__ = ["find_apps", "get_app_version"]
57 changes: 57 additions & 0 deletions dapi/apps/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
from tapipy.tapis import Tapis
from typing import List, Dict, Any, Optional


def find_apps(
t: Tapis, search_term: str, list_type: str = "ALL", verbose: bool = True
) -> List[Any]:
"""
Search for Tapis apps matching a search term.
Args:
t (Tapis): Tapis client instance
search_term (str): Name or partial name to search for
list_type (str): One of 'OWNED', 'SHARED_PUBLIC', 'SHARED_DIRECT', 'READ_PERM', 'MINE', 'ALL'
verbose (bool): If True, prints all found apps
Returns:
List[Any]: List of matching app objects
"""
results = t.apps.getApps(search=f"(id.like.*{search_term}*)", listType=list_type)

if verbose:
if not results:
print(f"No apps found matching '{search_term}'")
else:
print(f"\nFound {len(results)} matching apps:")
for app in results:
print(f"- {app.id}")
print()

return results


def get_app_version(t: Tapis, app_id: str, verbose: bool = True) -> Optional[Any]:
"""
Get latest version info for a specific app ID.
Args:
t (Tapis): Tapis client instance
app_id (str): Exact app ID to look up
verbose (bool): If True, prints basic app info
Returns:
Optional[Any]: Latest version info for the app, or None if not found
"""
try:
app_info = t.apps.getAppLatestVersion(appId=app_id)
if verbose:
print(f"App: {app_info.id}")
print(f"Version: {app_info.version}")
print(f"System: {app_info.jobAttributes.execSystemId}")
return app_info
except Exception as e:
print(f"Error getting app info for '{app_id}': {str(e)}")
print("\nCouldn't find exact match. Here are similar apps:")
_ = find_apps(t, app_id)
return None
50 changes: 25 additions & 25 deletions examples/opensees/DS_GenFunctionsV3.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
def DS_GetDir(cur_dir, t):

# cur_dir = os.getcwd()
# cur_dir = os.getcwd()
if "jupyter/MyData" in cur_dir:
cur_dir = cur_dir.split("MyData").pop()
input_dir = t.username + cur_dir
input_uri = "tapis://{}/{}".format(storage_id, input_dir)
input_uri = input_uri.replace(" ", "%20")
elif('jupyter/mydata' in cur_dir ):
elif "jupyter/mydata" in cur_dir:
cur_dir = cur_dir.split("myData").pop()
input_dir = t.username + cur_dir
input_uri = "tapis://{}/{}".format(storage_id, input_dir)
input_uri = input_uri.replace(" ", "%20")

elif('jupyter/MyProjects' in cur_dir):
elif "jupyter/MyProjects" in cur_dir:
cur_dir = cur_dir.split("MyProjects/").pop()
PRJ = cur_dir.split("/")[0]
cur_dir = cur_dir.split(PRJ).pop()
Expand Down Expand Up @@ -45,49 +44,50 @@ def DS_GetDir(cur_dir, t):
input_dir = cur_dir
input_uri = "tapis://designsafe.storage.community/{}".format(input_dir)
input_uri = input_uri.replace(" ", "%20")

return input_uri

def DS_GetStatus(t, mjobUuid, tlapse = 15):


def DS_GetStatus(t, mjobUuid, tlapse=15):
import time

print(" Job launched. Status provided below")
print(
" Can also check in DesignSafe portal under - Workspace > Tools & Application > Job Status"
)

status = t.jobs.getJobStatus(jobUuid=mjobUuid).status
previous = ""
while True:
if status in ["FINISHED","FAILED","STOPPED"]:
if status in ["FINISHED", "FAILED", "STOPPED"]:
break
status = t.jobs.getJobStatus(jobUuid=mjobUuid).status
if status == previous:
continue
else :
else:
previous = status
print(f"\tStatus: {status}")
time.sleep(tlapse)
return status
time.sleep(tlapse)
return status


def DS_GetRuntime(t, mjobUuid):

from datetime import datetime

print("\nRuntime Summary")
print("---------------")
hist = t.jobs.getJobHistory(jobUuid=mjobUuid)
time1 = datetime.strptime(hist[-1].created, "%Y-%m-%dT%H:%M:%S.%fZ")
time0 = datetime.strptime(hist[0].created, "%Y-%m-%dT%H:%M:%S.%fZ")

time1 = datetime.strptime(hist[-1].created, "%Y-%m-%dT%H:%M:%S.%fZ")
time0 = datetime.strptime(hist[0].created, "%Y-%m-%dT%H:%M:%S.%fZ")
print("TOTAL time:", time1 - time0)

for i in range(len(hist)):
if hist[i].eventDetail == 'RUNNING' :
time1 = datetime.strptime(hist[i+1].created, "%Y-%m-%dT%H:%M:%S.%fZ")
time0 = datetime.strptime(hist[i].created, "%Y-%m-%dT%H:%M:%S.%fZ")
if hist[i].eventDetail == "RUNNING":
time1 = datetime.strptime(hist[i + 1].created, "%Y-%m-%dT%H:%M:%S.%fZ")
time0 = datetime.strptime(hist[i].created, "%Y-%m-%dT%H:%M:%S.%fZ")
print("RUNNING time:", time1 - time0)
if hist[i].eventDetail == 'QUEUED' :
time1 = datetime.strptime(hist[i+1].created, "%Y-%m-%dT%H:%M:%S.%fZ")
time0 = datetime.strptime(hist[i].created, "%Y-%m-%dT%H:%M:%S.%fZ")
print("QUEUED time:", time1 - time0)
if hist[i].eventDetail == "QUEUED":
time1 = datetime.strptime(hist[i + 1].created, "%Y-%m-%dT%H:%M:%S.%fZ")
time0 = datetime.strptime(hist[i].created, "%Y-%m-%dT%H:%M:%S.%fZ")
print("QUEUED time:", time1 - time0)
66 changes: 38 additions & 28 deletions examples/opensees/interactiveplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,69 +5,79 @@

import matplotlib.pyplot as plt
from matplotlib import gridspec
from ipywidgets import interactive
from ipywidgets import interactive
import ipywidgets as widgets
import numpy as np


def pwpplot(timeStep):
Step = int(timeStep / 0.01)-1
Step = int(timeStep / 0.01) - 1
plt.subplot(211)
plt.plot(time, uu)
plt.plot(time[Step],uu[Step],'ro')
plt.ylabel('pwp(kPa)')
plt.plot(time[Step], uu[Step], "ro")
plt.ylabel("pwp(kPa)")
plt.grid()
plt.subplot(212)
plt.plot(time,acc_input)
plt.plot(time[Step],acc_input[Step],'ro')
plt.xlabel('time(s)')
plt.ylabel('acceleration(g)')
plt.plot(time, acc_input)
plt.plot(time[Step], acc_input[Step], "ro")
plt.xlabel("time(s)")
plt.ylabel("acceleration(g)")
plt.grid()


def dispplot(timeStep):
Step = int(timeStep / 0.01)-1
Step = int(timeStep / 0.01) - 1
plt.figure(figsize=(7, 8))
ax0 = plt.subplot(gs[0])
ax0.plot(maxdisp[0, ::2], nodes[::2, 2], 'b--')
ax0.plot(mindisp[0, ::2], nodes[::2, 2], 'b--')
ax0.plot(maxdisp[0, ::2], nodes[::2, 2], "b--")
ax0.plot(mindisp[0, ::2], nodes[::2, 2], "b--")
ax0.plot(disp[Step, ::4], nodes[::2, 2])
plt.xlabel('displacement(m)')
plt.ylabel('Elevation(m)')
plt.xlabel("displacement(m)")
plt.ylabel("Elevation(m)")
plt.grid()
ax1 = plt.subplot(gs[1])
ax1.plot(time,acc_input)
ax1.plot(time[Step],acc_input[Step],'ro')
plt.xlabel('time(s)')
plt.ylabel('acceleration(g)')
ax1.plot(time, acc_input)
ax1.plot(time[Step], acc_input[Step], "ro")
plt.xlabel("time(s)")
plt.ylabel("acceleration(g)")
plt.grid()


def createpwpplot():
global time, acc_input, uu
pwp = np.loadtxt('porePressure.out')
time = pwp[:,0]
pwp = np.loadtxt("porePressure.out")
time = pwp[:, 0]
pwp = np.delete(pwp, 0, 1)
uexcess = pwp - pwp[0, :]
uu = uexcess[0:len(time), 12]
acc = np.loadtxt('acceleration.out')
uu = uexcess[0 : len(time), 12]
acc = np.loadtxt("acceleration.out")
acc_input = acc[:, 1]

return interactive(pwpplot,timeStep = widgets.FloatSlider(min = 0.01, max = time[-1], step = 0.01))
return interactive(
pwpplot, timeStep=widgets.FloatSlider(min=0.01, max=time[-1], step=0.01)
)


def createDispplot():
global maxdisp, mindisp, nodes, disp, gs
nodes = np.loadtxt('nodesInfo.dat')
disp = np.loadtxt('displacement.out')
nodes = np.loadtxt("nodesInfo.dat")
disp = np.loadtxt("displacement.out")
disp = np.delete(disp, 0, 1)
disp = (disp.transpose() - disp[:,0]).transpose()
disp = (disp.transpose() - disp[:, 0]).transpose()
ndof = 2
nnodes = nodes.shape[0]
maxdisp = np.amax(disp, axis=0)
mindisp = np.amin(disp, axis=0)
maxdisp = maxdisp.reshape(ndof, nnodes, order="F")
mindisp = mindisp.reshape(ndof, nnodes, order="F")
gs = gridspec.GridSpec(2, 1, height_ratios=[6, 1])
gs = gridspec.GridSpec(2, 1, height_ratios=[6, 1])

return interactive(
dispplot,
timeStep=widgets.FloatSlider(min=0.01, max=time[-1], step=0.01),
continuous_update=False,
)

return interactive(dispplot,timeStep = widgets.FloatSlider(min = 0.01, max = time[-1], step = 0.01), continuous_update=False)

if __name__ == "__main__":
createpwpplot()
createpwpplot()
Loading

0 comments on commit 7766d2d

Please sign in to comment.