Skip to content

Commit 7766d2d

Browse files
committed
Apps get apps
1 parent db6f1a7 commit 7766d2d

10 files changed

Lines changed: 237 additions & 156 deletions

File tree

dapi/apps/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from .apps import find_apps, get_app_version
2+
3+
__all__ = ["find_apps", "get_app_version"]

dapi/apps/apps.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
from tapipy.tapis import Tapis
2+
from typing import List, Dict, Any, Optional
3+
4+
5+
def find_apps(
6+
t: Tapis, search_term: str, list_type: str = "ALL", verbose: bool = True
7+
) -> List[Any]:
8+
"""
9+
Search for Tapis apps matching a search term.
10+
11+
Args:
12+
t (Tapis): Tapis client instance
13+
search_term (str): Name or partial name to search for
14+
list_type (str): One of 'OWNED', 'SHARED_PUBLIC', 'SHARED_DIRECT', 'READ_PERM', 'MINE', 'ALL'
15+
verbose (bool): If True, prints all found apps
16+
17+
Returns:
18+
List[Any]: List of matching app objects
19+
"""
20+
results = t.apps.getApps(search=f"(id.like.*{search_term}*)", listType=list_type)
21+
22+
if verbose:
23+
if not results:
24+
print(f"No apps found matching '{search_term}'")
25+
else:
26+
print(f"\nFound {len(results)} matching apps:")
27+
for app in results:
28+
print(f"- {app.id}")
29+
print()
30+
31+
return results
32+
33+
34+
def get_app_version(t: Tapis, app_id: str, verbose: bool = True) -> Optional[Any]:
35+
"""
36+
Get latest version info for a specific app ID.
37+
38+
Args:
39+
t (Tapis): Tapis client instance
40+
app_id (str): Exact app ID to look up
41+
verbose (bool): If True, prints basic app info
42+
43+
Returns:
44+
Optional[Any]: Latest version info for the app, or None if not found
45+
"""
46+
try:
47+
app_info = t.apps.getAppLatestVersion(appId=app_id)
48+
if verbose:
49+
print(f"App: {app_info.id}")
50+
print(f"Version: {app_info.version}")
51+
print(f"System: {app_info.jobAttributes.execSystemId}")
52+
return app_info
53+
except Exception as e:
54+
print(f"Error getting app info for '{app_id}': {str(e)}")
55+
print("\nCouldn't find exact match. Here are similar apps:")
56+
_ = find_apps(t, app_id)
57+
return None
Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
def DS_GetDir(cur_dir, t):
2-
3-
# cur_dir = os.getcwd()
2+
# cur_dir = os.getcwd()
43
if "jupyter/MyData" in cur_dir:
54
cur_dir = cur_dir.split("MyData").pop()
65
input_dir = t.username + cur_dir
76
input_uri = "tapis://{}/{}".format(storage_id, input_dir)
87
input_uri = input_uri.replace(" ", "%20")
9-
elif('jupyter/mydata' in cur_dir ):
8+
elif "jupyter/mydata" in cur_dir:
109
cur_dir = cur_dir.split("myData").pop()
1110
input_dir = t.username + cur_dir
1211
input_uri = "tapis://{}/{}".format(storage_id, input_dir)
1312
input_uri = input_uri.replace(" ", "%20")
1413

15-
elif('jupyter/MyProjects' in cur_dir):
14+
elif "jupyter/MyProjects" in cur_dir:
1615
cur_dir = cur_dir.split("MyProjects/").pop()
1716
PRJ = cur_dir.split("/")[0]
1817
cur_dir = cur_dir.split(PRJ).pop()
@@ -45,49 +44,50 @@ def DS_GetDir(cur_dir, t):
4544
input_dir = cur_dir
4645
input_uri = "tapis://designsafe.storage.community/{}".format(input_dir)
4746
input_uri = input_uri.replace(" ", "%20")
48-
47+
4948
return input_uri
50-
51-
def DS_GetStatus(t, mjobUuid, tlapse = 15):
5249

50+
51+
def DS_GetStatus(t, mjobUuid, tlapse=15):
5352
import time
53+
5454
print(" Job launched. Status provided below")
5555
print(
5656
" Can also check in DesignSafe portal under - Workspace > Tools & Application > Job Status"
5757
)
58-
58+
5959
status = t.jobs.getJobStatus(jobUuid=mjobUuid).status
6060
previous = ""
6161
while True:
62-
if status in ["FINISHED","FAILED","STOPPED"]:
62+
if status in ["FINISHED", "FAILED", "STOPPED"]:
6363
break
6464
status = t.jobs.getJobStatus(jobUuid=mjobUuid).status
6565
if status == previous:
6666
continue
67-
else :
67+
else:
6868
previous = status
6969
print(f"\tStatus: {status}")
70-
time.sleep(tlapse)
71-
return status
70+
time.sleep(tlapse)
71+
return status
72+
7273

7374
def DS_GetRuntime(t, mjobUuid):
74-
7575
from datetime import datetime
76-
76+
7777
print("\nRuntime Summary")
7878
print("---------------")
7979
hist = t.jobs.getJobHistory(jobUuid=mjobUuid)
80-
81-
time1 = datetime.strptime(hist[-1].created, "%Y-%m-%dT%H:%M:%S.%fZ")
82-
time0 = datetime.strptime(hist[0].created, "%Y-%m-%dT%H:%M:%S.%fZ")
80+
81+
time1 = datetime.strptime(hist[-1].created, "%Y-%m-%dT%H:%M:%S.%fZ")
82+
time0 = datetime.strptime(hist[0].created, "%Y-%m-%dT%H:%M:%S.%fZ")
8383
print("TOTAL time:", time1 - time0)
84-
84+
8585
for i in range(len(hist)):
86-
if hist[i].eventDetail == 'RUNNING' :
87-
time1 = datetime.strptime(hist[i+1].created, "%Y-%m-%dT%H:%M:%S.%fZ")
88-
time0 = datetime.strptime(hist[i].created, "%Y-%m-%dT%H:%M:%S.%fZ")
86+
if hist[i].eventDetail == "RUNNING":
87+
time1 = datetime.strptime(hist[i + 1].created, "%Y-%m-%dT%H:%M:%S.%fZ")
88+
time0 = datetime.strptime(hist[i].created, "%Y-%m-%dT%H:%M:%S.%fZ")
8989
print("RUNNING time:", time1 - time0)
90-
if hist[i].eventDetail == 'QUEUED' :
91-
time1 = datetime.strptime(hist[i+1].created, "%Y-%m-%dT%H:%M:%S.%fZ")
92-
time0 = datetime.strptime(hist[i].created, "%Y-%m-%dT%H:%M:%S.%fZ")
93-
print("QUEUED time:", time1 - time0)
90+
if hist[i].eventDetail == "QUEUED":
91+
time1 = datetime.strptime(hist[i + 1].created, "%Y-%m-%dT%H:%M:%S.%fZ")
92+
time0 = datetime.strptime(hist[i].created, "%Y-%m-%dT%H:%M:%S.%fZ")
93+
print("QUEUED time:", time1 - time0)

examples/opensees/interactiveplot.py

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,69 +5,79 @@
55

66
import matplotlib.pyplot as plt
77
from matplotlib import gridspec
8-
from ipywidgets import interactive
8+
from ipywidgets import interactive
99
import ipywidgets as widgets
1010
import numpy as np
1111

12+
1213
def pwpplot(timeStep):
13-
Step = int(timeStep / 0.01)-1
14+
Step = int(timeStep / 0.01) - 1
1415
plt.subplot(211)
1516
plt.plot(time, uu)
16-
plt.plot(time[Step],uu[Step],'ro')
17-
plt.ylabel('pwp(kPa)')
17+
plt.plot(time[Step], uu[Step], "ro")
18+
plt.ylabel("pwp(kPa)")
1819
plt.grid()
1920
plt.subplot(212)
20-
plt.plot(time,acc_input)
21-
plt.plot(time[Step],acc_input[Step],'ro')
22-
plt.xlabel('time(s)')
23-
plt.ylabel('acceleration(g)')
21+
plt.plot(time, acc_input)
22+
plt.plot(time[Step], acc_input[Step], "ro")
23+
plt.xlabel("time(s)")
24+
plt.ylabel("acceleration(g)")
2425
plt.grid()
2526

27+
2628
def dispplot(timeStep):
27-
Step = int(timeStep / 0.01)-1
29+
Step = int(timeStep / 0.01) - 1
2830
plt.figure(figsize=(7, 8))
2931
ax0 = plt.subplot(gs[0])
30-
ax0.plot(maxdisp[0, ::2], nodes[::2, 2], 'b--')
31-
ax0.plot(mindisp[0, ::2], nodes[::2, 2], 'b--')
32+
ax0.plot(maxdisp[0, ::2], nodes[::2, 2], "b--")
33+
ax0.plot(mindisp[0, ::2], nodes[::2, 2], "b--")
3234
ax0.plot(disp[Step, ::4], nodes[::2, 2])
33-
plt.xlabel('displacement(m)')
34-
plt.ylabel('Elevation(m)')
35+
plt.xlabel("displacement(m)")
36+
plt.ylabel("Elevation(m)")
3537
plt.grid()
3638
ax1 = plt.subplot(gs[1])
37-
ax1.plot(time,acc_input)
38-
ax1.plot(time[Step],acc_input[Step],'ro')
39-
plt.xlabel('time(s)')
40-
plt.ylabel('acceleration(g)')
39+
ax1.plot(time, acc_input)
40+
ax1.plot(time[Step], acc_input[Step], "ro")
41+
plt.xlabel("time(s)")
42+
plt.ylabel("acceleration(g)")
4143
plt.grid()
4244

45+
4346
def createpwpplot():
4447
global time, acc_input, uu
45-
pwp = np.loadtxt('porePressure.out')
46-
time = pwp[:,0]
48+
pwp = np.loadtxt("porePressure.out")
49+
time = pwp[:, 0]
4750
pwp = np.delete(pwp, 0, 1)
4851
uexcess = pwp - pwp[0, :]
49-
uu = uexcess[0:len(time), 12]
50-
acc = np.loadtxt('acceleration.out')
52+
uu = uexcess[0 : len(time), 12]
53+
acc = np.loadtxt("acceleration.out")
5154
acc_input = acc[:, 1]
5255

53-
return interactive(pwpplot,timeStep = widgets.FloatSlider(min = 0.01, max = time[-1], step = 0.01))
56+
return interactive(
57+
pwpplot, timeStep=widgets.FloatSlider(min=0.01, max=time[-1], step=0.01)
58+
)
5459

5560

5661
def createDispplot():
5762
global maxdisp, mindisp, nodes, disp, gs
58-
nodes = np.loadtxt('nodesInfo.dat')
59-
disp = np.loadtxt('displacement.out')
63+
nodes = np.loadtxt("nodesInfo.dat")
64+
disp = np.loadtxt("displacement.out")
6065
disp = np.delete(disp, 0, 1)
61-
disp = (disp.transpose() - disp[:,0]).transpose()
66+
disp = (disp.transpose() - disp[:, 0]).transpose()
6267
ndof = 2
6368
nnodes = nodes.shape[0]
6469
maxdisp = np.amax(disp, axis=0)
6570
mindisp = np.amin(disp, axis=0)
6671
maxdisp = maxdisp.reshape(ndof, nnodes, order="F")
6772
mindisp = mindisp.reshape(ndof, nnodes, order="F")
68-
gs = gridspec.GridSpec(2, 1, height_ratios=[6, 1])
73+
gs = gridspec.GridSpec(2, 1, height_ratios=[6, 1])
74+
75+
return interactive(
76+
dispplot,
77+
timeStep=widgets.FloatSlider(min=0.01, max=time[-1], step=0.01),
78+
continuous_update=False,
79+
)
6980

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

7282
if __name__ == "__main__":
73-
createpwpplot()
83+
createpwpplot()

0 commit comments

Comments
 (0)