<jupyter_start><jupyter_text>T81-558: Applications of Deep Neural Networks* Instructor: [<NAME>](https://sites.wustl.edu/jeffheaton/), School of Engineering and Applied Science, [Washington University in St. Louis](https://engineering.wustl.edu/Programs/Pages/default.aspx)* For more information visit the [class website](https://sites.wustl.edu/jeffheaton/t81-558/).**Module 1 Assignment: How to Submit an Assignment****Student Name: mapleshilc**  Assignment InstructionsAssignments are submitted using the **submit** function that is defined earlier in this document.  When you submit an assignment, you are sending both your source code and data.  A computer program will automatically check your data, and it will inform youof how closely your data matches up with my solution file.  You are allowed to submit as many times as you like, so if you see some issues with your first submission, you are allowed to make changes and resubmit.  You may resubmit as many times as you like, I will only count your final submission towards your grade.When you first signed up for the course, I emailed you a student key.  You can see a sample key below.  If you use this key, you will get an error.  It is not the current key.  **Use YOUR student key, that I provided in the email.**You must also provide a filename and assignment number.  The filename is the source file that you wish to submit.  Your data is a Pandas dataframe. **Assignment 1 is  easy!** To complete assignment one, all you have to do is add your student key and make sure that the **file** variable contains the path to your source file.  Your source file will most likely end in **.pynb** if you are using a Jupyter notebook; however, it might also end in **.py** if you are using a Python script.Run the code below, and if you are successful, you should see something similar to:```Success: Submitted assignment 1 for jheaton:You have submitted this assignment 2 times. (this is fine)No warnings on your data. You will probably do well, but no guarantee. :-)```If there is an issue with your data, you will get a warning.**Common Problem 1: Bad student key**If you use an invalid student key, you will see:```Failure: {"message":"Forbidden"}```You should also make sure that **_class** appears somewhere in your filename. For example, for assignment 1, you should have **_class1** somewhere in your filename. If not, you will get an error.  This check ensures that you do not submit the wrong assignment, with the incorrect file.  If you do have a mismatch, you will get an error such as:**Common Problem 2: Must have class1 (or another number) as part of the filename**```Exception: _class1 must be part of the filename.```The following video covers assignment submission: [assignment submission video](http://www.yahoo.com).**Common Problem 3: Can't find source file**You might get an error similar to this:```FileNotFoundError: [Errno 2] No such file or directory: '/Users/jeffh/projects/t81_558_deep_learning/t81_558_class1_intro_python.ipynb'```This error means your **file** path is wrong.  Make sure the path matches where your file is stored.  See my hints below in the comments for paths in different environments.**Common Problem 4: ??? **If you run into a problem not listed here, just let me know.  If you cannot solve the file not found error, try running the code provided later in this file to list every file in your notebooks folder.  Google CoLab InstructionsIf you are using Google CoLab, it will be necessary to mount your GDrive so that you can send your notebook during the submit process.  Running the following code will map your GDrive to ```/content/drive```.<jupyter_code>try:
    from google.colab import drive
    drive.mount('/content/drive', force_remount=True)
    COLAB = True
    print("Note: using Google CoLab")
    %tensorflow_version 2.x
except:
    print("Note: not using Google CoLab")
    COLAB = False<jupyter_output>Note: not using Google CoLab<jupyter_text>If you are running this notebook with CoLab, the following command will show you your notebooks. You will need to know the location of your notebook when you submit your assignment.<jupyter_code>!ls /content/drive/My\ Drive/Colab\ Notebooks<jupyter_output><empty_output><jupyter_text>Assignment Submit FunctionYou will submit the ten programming assignments electronically.  The following **submit** function can be used to do this.  My server will perform a basic check of each assignment and let you know if it sees any underlying problems. **It is unlikely that should need to modify this function.**<jupyter_code>import base64
import os
import numpy as np
import pandas as pd
import requests
from PIL import Image
import PIL
import PIL.Image

import io

# This function submits an assignment.  You can submit an assignment as much as you like, only the final
# submission counts.  The paramaters are as follows:
# data - List of pandas dataframes or images.
# key - Your student key that was emailed to you.
# no - The assignment class number, should be 1 through 1.
# source_file - The full path to your Python or IPYNB file.  This must have "_class1" as part of its name.  
# .             The number must match your assignment number.  For example "_class2" for class assignment #2.
def submit(data,key,no,source_file=None):
    if source_file is None and '__file__' not in globals(): raise Exception('Must specify a filename when a Jupyter notebook.')
    if source_file is None: source_file = __file__
    suffix = '_class{}'.format(no)
    if suffix not in source_file: raise Exception('{} must be part of the filename.'.format(suffix))
    with open(source_file, "rb") as image_file:
        encoded_python = base64.b64encode(image_file.read()).decode('ascii')
    ext = os.path.splitext(source_file)[-1].lower()
    if ext not in ['.ipynb','.py']: raise Exception("Source file is {} must be .py or .ipynb".format(ext))
    payload = []
    for item in data:
        if type(item) is PIL.Image.Image:
            buffered = BytesIO()
            item.save(buffered, format="PNG")
            payload.append({'PNG':base64.b64encode(buffered.getvalue()).decode('ascii')})
        elif type(item) is pd.core.frame.DataFrame:
            payload.append({'CSV':base64.b64encode(item.to_csv(index=False).encode('ascii')).decode("ascii")})
    r= requests.post("https://api.heatonresearch.com/assignment-submit",
        headers={'x-api-key':key}, json={ 'payload': payload,'assignment': no, 'ext':ext, 'py':encoded_python})
    if r.status_code==200:
        print("Success: {}".format(r.text))
    else: print("Failure: {}".format(r.text))<jupyter_output><empty_output><jupyter_text>Assignment 1 Sample CodeFor assignment 1, you only must change two things.  The key must be modified to be your key, and the file path must be modified to be the path to your local file.  Once you have that, just run it, and your assignment is submitted.<jupyter_code># This is your student key that I emailed to you at the beginnning of the semester.
key = "<KEY>"  # This is an example key and will not work.

# You must also identify your source file.  (modify for your local setup)
# file='/content/drive/My Drive/Colab Notebooks/assignment_yourname_class1.ipynb'  # Google CoLab
file='C:\\Users\\Tokiha\\Documents\\GitHub\\t81_558_deep_learning\\assignments\\assignment_yourname_class1.ipynb'  # Windows
# file='/Users/jheaton/projects/t81_558_deep_learning/assignments/assignment_yourname_class1.ipynb'  # Mac/Linux

df = pd.DataFrame({'a' : [0, 0, 1, 1], 'b' : [0, 1, 0, 1], 'c' : [0, 1, 1, 0]})

submit(source_file=file,data=[df],key=key,no=1)<jupyter_output>Success: Submitted Assignment 1 for mapleshilc-:
You have submitted this assignment 2 times. (this is fine)
No errors, warnings, or notes on your data. Rock on! You will probably do well, but no guarantee. :-)<jupyter_text>Checking Your SubmissionYou can always double-check to make sure my program correctly received your submission.  The following utility code will help with that.<jupyter_code>import requests
import pandas as pd
import base64
import os

def list_submits(key):
    r = requests.post("https://api.heatonresearch.com/assignment-submit",
                      headers={'x-api-key': key},
                      json={})
    if r.status_code == 200:
        print("Success: \n{}".format(r.text))
    else:
        print("Failure: {}".format(r.text))

def display_submit(key,no):
    r = requests.post("https://api.heatonresearch.com/assignment-submit",
                      headers={'x-api-key': key},
                      json={'assignment':no})
    if r.status_code == 200:
        print("Success: \n{}".format(r.text))
    else:
        print("Failure: {}".format(r.text))

# Show a listing of all submitted assignments.

key = "<KEY>"

list_submits(key)
# Show one assignment, by number.

display_submit(key,1)<jupyter_output>Success: 
Assignment 1: Submitted 2 times, last on: 2020-10-26T22:47:13.599858+00:00
*** Check ***
No errors, warnings, or notes on your data. Rock on! You will probably do well, but no guarantee. :-)<jupyter_text>Can't Find Your File in CoLab?The following code will list every file in your Google Colab Notebooks directory along with a true/false indicator of if the file could be opened.  You SHOULD see all true's.  Copy/paste the filename (along with the quotes) and use it as the name of your submitted notebook.<jupyter_code>from os import listdir
from os.path import isfile, join
import base64

if COLAB:
    PATH = "/content/drive/My Drive/Colab Notebooks/"
    for f in listdir(PATH):
      full_path = join(PATH, f)
      if isfile(full_path):
        try:
          with open(full_path, "rb") as image_file:
            encoded_python = base64.b64encode(image_file.read()).decode('ascii')
            success = True
        except FileNotFoundError:
          success = False

        report = full_path.replace('\\','\\\\')
        report = report.replace('\"','\\\"')
        report = report.replace('\'','\\\'')
        print(f'[{success}] - "{report}"')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09890764647467726, 'fraction_numerical': 0.012810327706057598, 'mean_word_length': 4.000496524329692, 'pattern_counts': {'":': 1, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 6, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '36549', 'license': 'Apache-2.0', 'n_tokens_mistral': 2964, 'n_tokens_neox': 2812, 'n_words': 1215, 'path': 'assignments/assignment_yourname_class1.ipynb', 'repo_name': 'SakamotoYuki/t81_558_deep_learning', 'size': '10145'}