Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
295 changes: 151 additions & 144 deletions extras/conda-linux-64.lock

Large diffs are not rendered by default.

264 changes: 135 additions & 129 deletions extras/conda-osx-64.lock

Large diffs are not rendered by default.

272 changes: 139 additions & 133 deletions extras/conda-win-64.lock

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions extras/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ dependencies:
- ipytest=0.12.*
- pandas=1.*.*
- plotly=5.*.*
- pip
- pip:
- pygount~=1.4.0
- statsmodels=0.*.*
# https://plotly.com/python/static-image-export/
- python-kaleido
Expand Down
122 changes: 61 additions & 61 deletions extras/pandas_crash_course.ipynb

Large diffs are not rendered by default.

59 changes: 20 additions & 39 deletions extras/scripts/hw_6_check.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
# Corresponds to the Requirements for homework 6. Requires cloc and nbconvert. Usage:
# Corresponds to the Requirements for homework 6. Usage:
#
# python3 ./extras/scripts/hw_6_check.py <assignment>.ipynb

import ast
import json
import os
import tempfile
import pandas as pd
from pygount import SourceAnalysis
import re
import shlex
import subprocess
import sys

sys.path.append(os.path.dirname(os.path.abspath(__file__)))
Expand Down Expand Up @@ -59,39 +58,9 @@ def visit_Call(self, node):
self.is_present = True


def handle_process_err(cmd, err):
if type(cmd) == list:
cmd = shlex.join(cmd)

output = err.stderr.decode("utf-8")
print(
f"{bcolors.FAIL}ERROR{bcolors.ENDC} while running\n\n\t{cmd}\n\n{output}",
file=sys.stderr,
)
sys.exit(err.returncode)


def get_cmd_output(cmd, input=None, shell=False):
try:
process = subprocess.run(
cmd,
capture_output=True,
check=True,
input=bytes(input, "utf-8"),
shell=shell,
)
except subprocess.CalledProcessError as err:
handle_process_err(cmd, err)

return process.stdout


def lines_of_code(code):
output = get_cmd_output(
"cloc --stdin-name=script.py --json -", input=code, shell=True
)
data = json.loads(output)
return data["SUM"]["code"]
def lines_of_code(file_path):
results = SourceAnalysis.from_file(file_path, "pygount")
return results.code_count


def code_contains(pattern, code):
Expand Down Expand Up @@ -164,12 +133,20 @@ def exit(results):
sys.exit(exit_code)


if __name__ == "__main__":
def write_to_tmp_file(content):
with tempfile.NamedTemporaryFile(delete=False, suffix=".py") as temp:
temp.write(bytes(content, "utf-8"))
return temp.name


def run():
notebook_path = sys.argv[1]

notebook = read_notebook(notebook_path)
script = notebook_to_script(notebook)
num_lines = lines_of_code(script)

script_path = write_to_tmp_file(script)
num_lines = lines_of_code(script_path)

# use pandas for outputting a table
results = pd.Series(
Expand All @@ -184,3 +161,7 @@ def exit(results):
outputs = results.apply(lambda val: pass_fail(val))
print(outputs.to_string())
exit(results)


if __name__ == "__main__":
run()
48 changes: 24 additions & 24 deletions hw_1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
"execution_count": 1,
"metadata": {
"execution": {
"iopub.execute_input": "2022-04-15T22:12:29.964974Z",
"iopub.status.busy": "2022-04-15T22:12:29.964437Z",
"iopub.status.idle": "2022-04-15T22:12:29.971924Z",
"shell.execute_reply": "2022-04-15T22:12:29.970791Z"
"iopub.execute_input": "2022-05-15T02:46:34.165768Z",
"iopub.status.busy": "2022-05-15T02:46:34.165299Z",
"iopub.status.idle": "2022-05-15T02:46:34.170365Z",
"shell.execute_reply": "2022-05-15T02:46:34.169705Z"
}
},
"outputs": [],
Expand All @@ -50,10 +50,10 @@
"execution_count": 2,
"metadata": {
"execution": {
"iopub.execute_input": "2022-04-15T22:12:29.976437Z",
"iopub.status.busy": "2022-04-15T22:12:29.976037Z",
"iopub.status.idle": "2022-04-15T22:12:29.979584Z",
"shell.execute_reply": "2022-04-15T22:12:29.978798Z"
"iopub.execute_input": "2022-05-15T02:46:34.173741Z",
"iopub.status.busy": "2022-05-15T02:46:34.173452Z",
"iopub.status.idle": "2022-05-15T02:46:34.176508Z",
"shell.execute_reply": "2022-05-15T02:46:34.175891Z"
}
},
"outputs": [],
Expand Down Expand Up @@ -90,10 +90,10 @@
"execution_count": 3,
"metadata": {
"execution": {
"iopub.execute_input": "2022-04-15T22:12:29.983689Z",
"iopub.status.busy": "2022-04-15T22:12:29.983252Z",
"iopub.status.idle": "2022-04-15T22:12:29.988091Z",
"shell.execute_reply": "2022-04-15T22:12:29.987036Z"
"iopub.execute_input": "2022-05-15T02:46:34.179746Z",
"iopub.status.busy": "2022-05-15T02:46:34.179449Z",
"iopub.status.idle": "2022-05-15T02:46:34.184073Z",
"shell.execute_reply": "2022-05-15T02:46:34.183377Z"
}
},
"outputs": [],
Expand All @@ -115,10 +115,10 @@
"execution_count": 4,
"metadata": {
"execution": {
"iopub.execute_input": "2022-04-15T22:12:29.994706Z",
"iopub.status.busy": "2022-04-15T22:12:29.994469Z",
"iopub.status.idle": "2022-04-15T22:12:29.997480Z",
"shell.execute_reply": "2022-04-15T22:12:29.996839Z"
"iopub.execute_input": "2022-05-15T02:46:34.187210Z",
"iopub.status.busy": "2022-05-15T02:46:34.186910Z",
"iopub.status.idle": "2022-05-15T02:46:34.189965Z",
"shell.execute_reply": "2022-05-15T02:46:34.189381Z"
}
},
"outputs": [],
Expand All @@ -141,10 +141,10 @@
"execution_count": 5,
"metadata": {
"execution": {
"iopub.execute_input": "2022-04-15T22:12:30.000974Z",
"iopub.status.busy": "2022-04-15T22:12:30.000718Z",
"iopub.status.idle": "2022-04-15T22:12:30.004068Z",
"shell.execute_reply": "2022-04-15T22:12:30.003403Z"
"iopub.execute_input": "2022-05-15T02:46:34.192806Z",
"iopub.status.busy": "2022-05-15T02:46:34.192563Z",
"iopub.status.idle": "2022-05-15T02:46:34.195104Z",
"shell.execute_reply": "2022-05-15T02:46:34.194616Z"
}
},
"outputs": [],
Expand Down Expand Up @@ -175,10 +175,10 @@
"execution_count": 6,
"metadata": {
"execution": {
"iopub.execute_input": "2022-04-15T22:12:30.008502Z",
"iopub.status.busy": "2022-04-15T22:12:30.008247Z",
"iopub.status.idle": "2022-04-15T22:12:30.011327Z",
"shell.execute_reply": "2022-04-15T22:12:30.010656Z"
"iopub.execute_input": "2022-05-15T02:46:34.197953Z",
"iopub.status.busy": "2022-05-15T02:46:34.197701Z",
"iopub.status.idle": "2022-05-15T02:46:34.200140Z",
"shell.execute_reply": "2022-05-15T02:46:34.199671Z"
}
},
"outputs": [],
Expand Down
Loading