This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import win32com.client | |
| import os | |
| from datetime import datetime, timedelta | |
| # Initiate the Outlook Session | |
| outlook = win32com.client.Dispatch('outlook.application') | |
| mapi = outlook.GetNamespace("MAPI") | |
| # Select the folder 6 to get the emails | |
| inbox = mapi.GetDefaultFolder(6) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Message Object | |
| msg = MIMEMultipart() | |
| msg['Subject'] = 'Workload Report for {}'.format(WEEK) | |
| msg['From'] = from_mail | |
| msg['To'] = ', '.join([from_mail, to_mail]) | |
| msg.preamble = 'Workload Report for {}'.format(WEEK) | |
| # Attach the HTML code | |
| msg.attach(MIMEText(html_string, 'html', 'utf-8')) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Add the insights | |
| html_string = html_string.replace("WEEK", WEEK) | |
| html_string = html_string.replace("total_lines", total_lines) | |
| html_string = html_string.replace("busy_day", busy_day) | |
| html_string = html_string.replace("max_lines", max_lines) | |
| html_string = html_string.replace("avg_ratio", avg_ratio) | |
| html_string = html_string.replace("max_ratio", max_ratio) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Open the visual | |
| with open(file_img, 'rb') as fp: | |
| img = MIMEImage(fp.read()) | |
| img.add_header('Content-Disposition', 'attachment', filename=file_img) | |
| img.add_header('X-Attachment-Id', '0') | |
| img.add_header('Content-ID', '<0>') | |
| fp.close() | |
| msg.attach(img) | |
| # Open the header |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # save plot | |
| filename = 'visual' + ".png" | |
| path_plot = filename | |
| fig.savefig(path_plot, dpi=fig.dpi) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Lines per orders | |
| avg_ratio = '{:.2f} lines/order'.format(df_plot['LINES/ORDER'].mean()) | |
| max_ratio = '{:.2f} lines/order'.format(df_plot['LINES/ORDER'].max()) | |
| # Maximum Day Lines | |
| busy_day = dict_days[df_plot.set_index('DAY')['LINES'].idxmax()] | |
| max_lines = '{:,} lines'.format(df_plot['LINES'].max()) | |
| # Total Workload | |
| total_lines = '{:,} lines'.format(df_plot['LINES'].sum()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Bar Plot: Orders/Lines | |
| fig, ax = plt.subplots(figsize=(14, 7)) | |
| df_plot.plot.bar(figsize=(8, 6), edgecolor='black', x='DAY', y=['ORDERS', 'LINES'], | |
| color=['tab:blue', 'tab:red'], legend= True, ax = ax) | |
| plt.xlabel('DAY', fontsize = 12) | |
| plt.title('Workload per day (Lines/day)', fontsize = 12) | |
| plt.show() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| DATE | WEEK | DAY | ORDERS | LINES | PCS | SKU | CITIES | LINES/ORDER | |
|---|---|---|---|---|---|---|---|---|---|
| 2017-01-02 | WEEK-1 | MON | 776 | 1367 | 1595.0 | 487 | 174 | 1.7615979381443299 | |
| 2017-01-03 | WEEK-1 | TUE | 902 | 1550 | 1861.0 | 547 | 188 | 1.7184035476718404 | |
| 2017-01-04 | WEEK-1 | WED | 1476 | 2252 | 2856.0 | 513 | 205 | 1.5257452574525745 | |
| 2017-01-05 | WEEK-1 | THU | 909 | 1637 | 1972.0 | 519 | 175 | 1.800880088008801 | |
| 2017-01-06 | WEEK-1 | FRI | 1023 | 1720 | 1995.0 | 502 | 189 | 1.6813294232649072 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| DATE | WEEK | DAY | ORDERS | LINES | PCS | SKU | CITIES | |
|---|---|---|---|---|---|---|---|---|
| 2017-01-02 | WEEK-1 | MON | 776 | 1367 | 1595.0 | 487 | 174 | |
| 2017-01-03 | WEEK-1 | TUE | 902 | 1550 | 1861.0 | 547 | 188 | |
| 2017-01-04 | WEEK-1 | WED | 1476 | 2252 | 2856.0 | 513 | 205 | |
| 2017-01-05 | WEEK-1 | THU | 909 | 1637 | 1972.0 | 519 | 175 | |
| 2017-01-06 | WEEK-1 | FRI | 1023 | 1720 | 1995.0 | 502 | 189 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| import pandas as pd | |
| import matplotlib.pyplot as plt | |
| from PIL import Image, ImageDraw, ImageChops, ImageFont | |
| import io |