Skip to content

Commit

Permalink
OpenSees example
Browse files Browse the repository at this point in the history
  • Loading branch information
kks32 committed Oct 1, 2024
1 parent a4586d3 commit 309fc64
Show file tree
Hide file tree
Showing 13 changed files with 9,794 additions and 0 deletions.
93 changes: 93 additions & 0 deletions examples/opensees/DS_GenFunctionsV3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
def DS_GetDir(cur_dir, t):

# 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 ):
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):
cur_dir = cur_dir.split("MyProjects/").pop()
PRJ = cur_dir.split("/")[0]
cur_dir = cur_dir.split(PRJ).pop()
import requests

resp = requests.get(
f"https://designsafe-ci.org/api/projects/v2/{PRJ}",
headers={"x-tapis-token": t.access_token.access_token},
)
project_uuid = resp.json()["baseProject"]["uuid"]
input_dir = cur_dir
input_uri = "tapis://project-{}{}".format(project_uuid, cur_dir)
input_uri = input_uri.replace(" ", "%20")
elif "jupyter/projects" in cur_dir:
cur_dir = cur_dir.split("projects/").pop()
PRJ = cur_dir.split("/")[0]
cur_dir = cur_dir.split(PRJ).pop()
import requests

resp = requests.get(
f"https://designsafe-ci.org/api/projects/v2/{PRJ}",
headers={"x-tapis-token": t.access_token.access_token},
)
project_uuid = resp.json()["baseProject"]["uuid"]
input_dir = cur_dir
input_uri = "tapis://project-{}{}".format(project_uuid, cur_dir)
input_uri = input_uri.replace(" ", "%20")
elif "jupyter/CommunityData" in cur_dir:
cur_dir = cur_dir.split("jupyter/CommunityData").pop()
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):

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"]:
break
status = t.jobs.getJobStatus(jobUuid=mjobUuid).status
if status == previous:
continue
else :
previous = status
print(f"\tStatus: {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")
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")
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)
Loading

0 comments on commit 309fc64

Please sign in to comment.