Skip to content

Commit 978face

Browse files
committed
added slack notification
1 parent cd20eac commit 978face

File tree

5 files changed

+32
-40
lines changed

5 files changed

+32
-40
lines changed

proj/environment/manager.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from proj.animation.animate import animate_from_images
1515
from proj.plotting.results import plot_results
1616
from proj.utils.dropbox import DropBoxUtils, upload_folder
17+
from proj.utils.slack import send_slack_message
1718

1819
FORMAT = "%(message)s"
1920
logging.basicConfig(
@@ -26,8 +27,9 @@ def __init__(self, model, winstor=False):
2627
"""
2728
This class manages paths, saving of results etc.
2829
"""
29-
self.model = model
30+
self.simstart = timestamp()
3031

32+
self.model = model
3133
self.exp_name = f'{model.trajectory["name"]}_{timestamp()}_{np.random.randint(low=0, high=10000)}'
3234

3335
# get main folder
@@ -158,3 +160,16 @@ def conclude(self):
158160
# Upload results to dropbox
159161
if self.winstor:
160162
self._upload_to_dropbox()
163+
else:
164+
logging.info("Did not upload to dropbox")
165+
166+
logging.info("Sending slack message")
167+
send_slack_message(
168+
f"""
169+
\n
170+
Completed simulation
171+
Start time: {self.simstart}
172+
End time: {timestamp()}
173+
Data folder: {self.datafolder}
174+
"""
175+
)

proj/run/runner.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ def run_experiment(
9292
environment.itern = itern
9393
environment.update_world(g_xs, elapsed=itern * model.dt)
9494

95-
# log
96-
if itern % 25 == 0:
95+
# log status once a second
96+
if itern % int(1 / model.dt) == 0:
9797
log.info(
9898
f"Iteration {itern}/{n_steps}. Current cost: {environment.curr_cost}."
9999
)

proj/utils/slack.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from slack import WebClient
2+
from slack.errors import SlackApiError
3+
4+
from proj.secrets import SLACK_TOKEN, SLACK_USER_ID
5+
6+
7+
def send_slack_message(message):
8+
client = WebClient(token=SLACK_TOKEN)
9+
10+
try:
11+
client.chat_postMessage(channel=SLACK_USER_ID, text=message)
12+
except SlackApiError as e:
13+
print(f"Got an error: {e.response['error']}")

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"rich",
1717
"sklearn",
1818
"fancylog",
19+
"dropbox",
1920
]
2021

2122
setup(

workspace.py

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +0,0 @@
1-
# %%
2-
from proj.utils.dropbox import DropBoxUtils
3-
4-
db = DropBoxUtils()
5-
6-
7-
# %%
8-
from pathlib import Path
9-
10-
fld = Path("/Users/federicoclaudi/Documents/Github/pysical_locomotion/proj")
11-
12-
13-
# %%
14-
def upload_folder(dbx, fld, base):
15-
fld = Path(fld)
16-
base = Path(base)
17-
18-
# loop subfolders
19-
for subf in fld.glob("*"):
20-
if not subf.is_dir():
21-
continue
22-
upload_folder(dbx, subf, base / subf.name)
23-
24-
for f in fld.glob("*.*"):
25-
if not f.is_file():
26-
continue
27-
28-
dest = base / f.name
29-
dbx.upload_file(f, dest)
30-
31-
32-
base = ""
33-
upload_folder(db, fld, "test")
34-
# %%
35-
db.upload_folder(fld, "test2")
36-
37-
# %%

0 commit comments

Comments
 (0)