labzen package

Submodules

labzen.labzen module

labzen.labzen.check_mechanics(path: Optional[str] = None, token=None)[source]

Performs Mechanics Checks on a MDS Lab

This function checks that you…
  1. … have a Github repo link;

  2. … have pushed your latest commit; and

  3. … have at least three commit messages authored by you in

    your history.

Parameters
  • path (str) – A local path to a Github directory or an MDS lab file (.ipynb or .Rmd) within such a directory.

  • token (str) – A personal access token for https://github.ubc.ca. See create_github_token() for details.

Returns

A boolean whether all checks passed. The function also prints

informative messages as a side effect.

Return type

bool

Example

>>> from labzen import labzen as lz
>>>
>>> # Step 1: get a token
>>> lz.create_github_token()
>>>
>>> # Step 2: check mechanics
>>> file = "~/MDS/Block5/lab1/DSCI_599_lab1_jene3456"
>>> token = "544c96ce0d3dc9b66ac8d70b32c07bd0c46129db"
>>> lz.check_mechanics(file, token)
Check 1: Repository has at least 3 commits with the student
username JENE SMITH
Check 1: True
Check 2: Remote has the latest version of the repository
Check 2: True
Check 3: Repository link is included in the file
Check 3: True
>>>
>>> # Alternatively, just run the following from an MDS lab directory:
>>> lz.check_mechanics(token = token)
labzen.labzen.count_points(file_name: Optional[str] = None, margins: bool = True)[source]

Tally Available Points in Lab

Parameters
  • file_name (str) – A path or list of paths to MDS lab files (either .ipynb or .Rmd). If left blank, the function will recursively search for all labs in the working directory based on the file extension.

  • margins (bool) – A boolean indicating whether to add a row for the total number of points (optional + required). Defaults to True.

Returns

A tuple of DataFrames. The first is a section-by-section overview of points available. The second is a cross table summarising the number of optional, required, and total points per lab.

Return type

(pandas.core.frame.DataFrame, pandas.core.frame.DataFrame)

Example

>>> from labzen import labzen as lz
>>> import urllib.request
>>>
>>> # Download the demo files into the working directory
>>> baseurl = (
>>>     "https://raw.githubusercontent.com"
>>>     + "/UBC-MDS/labzen/main/data-raw"
>>> )
>>> labs = {
>>>     "dummylab.Rmd": f"{baseurl}/dummylab.Rmd",
>>>     "dummylab.ipynb": f"{baseurl}/dummylab.ipynb",
>>> }
>>> for name, url in labs.items():
>>>     urllib.request.urlretrieve(url, name)
>>>
>>> # for Jupyter notebooks:
>>> df, tab = lz.count_points("dummylab.ipynb")
>>> print(df[["rubric", "points", "type"]])
                rubric  points          type
0            [mechanics]     [5]  Non-Optional
1            [reasoning]     [4]  Non-Optional
2  [accuracy, reasoning]  [3, 2]  Non-Optional
3  [accuracy, reasoning]  [6, 4]      Optional
4  [accuracy, reasoning]  [7, 3]      Optional
5                  [viz]     [5]  Non-Optional
>>> print(tab)
           type  total  prop
0  Non-Optional     19  0.95
1      Optional     20  1.00
2           All     39  1.95
>>>
>>> # for Rmarkdown:
>>> df, tab = lz.count_points("dummylab.Rmd")
>>> print(tab)
        type  total      prop
0  Non-Optional     42  0.950000
1      Optional     12  0.271429
2           All     54  1.221429
>>>
>>> # Alternatively, navigate to a student assignment repo and run the
>>> # following code.
>>> df, tab = lz.count_points()
labzen.labzen.create_github_token(host='https://github.ubc.ca')[source]

Open A Browser to Generate a New Github Enterprise Token

Parameters

host (str) – The URL to the upstream host. Defaults to UBC Github Enterprise.

Returns

None

Examples

>>> from labzen import labzen as lz
>>> # Open a web browser
>>> lz.create_github_token()
labzen.labzen.parse_lab(notebook=None)[source]

Parse MDS lab files to return the markdown content

Parameters

notebook (str) – A path or list of paths to MDS lab files (either .ipynb or .Rmd). If left blank, the function will recursively search for all labs in the working directory based on the file extension.

Returns

Each element of list is a content of one markdown cell.

Return type

list

Example

>>> # Download the demo files into the working directory
>>> import urllib.request
>>> from labzen import labzen as lz
>>>
>>> baseurl = (
>>>     "https://raw.githubusercontent.com"
>>>     + "/UBC-MDS/labzen/main/data-raw"
>>> )
>>> labs = {
>>>     "dummylab.Rmd": f"{baseurl}/dummylab.Rmd",
>>>     "dummylab.ipynb": f"{baseurl}/dummylab.ipynb",
>>> }
>>>
>>> for name, url in labs.items():
>>>     urllib.request.urlretrieve(url, name)
>>>
>>> # parse the labs
>>> lz.parse_lab("dummylab.ipynb")
>>> lz.parse_lab("dummylab.Rmd")
>>>
>>> # Alternatively, navigate to a student assignment repo and
>>> # run the following code.
>>> lz.parse_lab()

Module contents