|
4 | 4 | import sys
|
5 | 5 | import time
|
6 | 6 | import logging
|
| 7 | +import datetime |
7 | 8 |
|
8 | 9 | PROJECT_ROOT = os.path.realpath(os.path.join(__file__, '..', '..'))
|
9 | 10 | PROJECT_SRC = os.path.join(PROJECT_ROOT, 'src')
|
|
17 | 18 | import preprocessing as pp
|
18 | 19 | from prediction_age import AgePredictor
|
19 | 20 | import cluster_utils.dataset as cluster_dataset
|
20 |
| - |
21 |
| -logger = logging.getLogger(__name__) |
22 |
| -logger.setLevel(logging.INFO) |
| 21 | +import cluster_utils.slack_notifications as slack |
23 | 22 |
|
24 | 23 | COUNTRY = 'spain'
|
25 | 24 | N_CITIES = 4000
|
26 | 25 | CITIES = []
|
27 | 26 | DATA_DIR = '/p/projects/eubucco/data/2-database-city-level-v0_1'
|
28 | 27 | RESULT_DIR = '/p/tmp/floriann/ml-training'
|
29 | 28 |
|
| 29 | +start_time = time.time() |
| 30 | +logger = logging.getLogger(__name__) |
| 31 | +logger.setLevel(logging.INFO) |
| 32 | +slack_channel = os.environ.get('SLACK_CHANNEL') |
| 33 | +slack_token = os.environ.get('SLACK_TOKEN') |
| 34 | + |
30 | 35 | logger.info('Extracting features...')
|
31 | 36 | df = cluster_dataset.load(country_name=COUNTRY, path=DATA_DIR, cities=CITIES, n_cities=N_CITIES)
|
32 | 37 |
|
|
42 | 47 | timestr = time.strftime('%Y%m%d-%H-%M-%S')
|
43 | 48 | model_path = f'{RESULT_DIR}/model-{COUNTRY}-{N_CITIES or len(CITIES)}-{timestr}.pkl'
|
44 | 49 | predictor.save(model_path)
|
| 50 | + |
| 51 | +logger.info('Sending slack notification...') |
| 52 | +try: |
| 53 | + duration = str(datetime.timedelta(seconds=time.time() - start_time)).split('.')[0] |
| 54 | + slack.send_message(f'Model training for {COUNTRY} finished after {duration}. 🚀', slack_channel, slack_token) |
| 55 | +except Exception as e: |
| 56 | + logger.error(f'Failed to send Slack message: {e}') |
0 commit comments