KYOS UTILS¶
Kyos utils is a collection of small functions and classes which make common patterns shorter and easier.
Changelog¶
Version | Description |
---|---|
5.2.3 | Minor adjustments to the function send_email_notification() . |
5.2.1 | Minor adjustments to the function send_email_notification() . |
5.2.0 | Added the function send_email_notification() . |
5.0.5 | Added the function add_to_log() . |
4.0.0 | Added the function stop_model() . |
2.3.0 | Module kyos_utils created, and a function dict_merge() added. |
Documentation¶
add_to_log(message)
¶
Short function to add a message and the message's timestamp to the log file RunLog.txt.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
message
|
str
|
Message to add to the logs. |
required |
dict_merge(initial_dict, *args, overwrite_existing=False)
¶
Instead of updating only top-level keys, dict_merge recurses down into dicts nested
to an arbitrary depth, updating keys. The merge_dct
is merged into dct
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
initial_dict
|
dict
|
Dict onto which the merge is executed |
required |
*args
|
dict
|
Any number of dictonaries to be merged into initial_dict |
()
|
overwrite_existing
|
bool
|
Display the column name in bold font when showing it in the platform front-end |
False
|
Returns:
Name | Type | Description |
---|---|---|
rtn_dct |
dict
|
merged dictonary |
Examples:
>>> initial = {"accumulator": {"knock_out_price": 150, "trigger_price": 130, "accumulation_price": 110}}
>>> new_key_dict = {"accumulator": {"sim": {"id": 10}}}
>>> final = dict_merge(initial, new_key_dict)
{"accumulator": {"knock_out_price": 150, "trigger_price": 130, "accumulation_price": 110, "sim": {"id": 10}}}
matlab_datenum_to_datetime(datenums)
¶
Parameters:
Name | Type | Description | Default |
---|---|---|---|
datenums
|
list or 1d np.array
|
Vector of matlab datenums. |
required |
Returns:
Type | Description |
---|---|
list
|
List of dates in datetime format. |
send_email_notification(subject, message, sender, receivers, token, customer_name='customer', server_name=None)
¶
Function to send out an email notification to a specified list of receivers.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
subject
|
str
|
Subject of the email. |
required |
message
|
list
|
Body of the email, provided as a list of strings. A line break will be inserted after every item in the list. Use empty strings ("") to create blank lines. |
required |
sender
|
str
|
Email address that will send the message. |
required |
receivers
|
list
|
List of email addresses that will receive the message. |
required |
token
|
str
|
Token to connect to the smtp server. |
required |
customer_name
|
str
|
Name to append at the beginning of the message after "Dear"; defaults to "customer" if not provided |
'customer'
|
server_name
|
str
|
Name of the server to specify at the end of the message; defaults to None if not provided |
None
|
stop_model(msg=None, exception=Exception)
¶
Stops the current model run and prints the user-input error. The error message is also stored in a Status.txt file so that PHP can display it in the front end.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
msg
|
str
|
Error message. |
None
|
exception
|
Exception
|
Python exception (e.g. ValueError, ImportError, etc.). |
Exception
|
Raises:
Type | Description |
---|---|
Exception
|
Raises the user-input exception and error message. |