module automation_students.projects_repository
#
Short summary#
module ensae_teaching_cs.automation_students.projects_repository
Some automation helpers to grab mails from students about their projects.
Classes#
class |
truncated documentation |
---|---|
Handle a repository of students projects. See example Récupérer des mails d’étudiants en pièce jointe (1:1). … |
Properties#
property |
truncated documentation |
---|---|
Returns all available groups in the repository. |
|
Static Methods#
staticmethod |
truncated documentation |
---|---|
Creates a series of folders for groups of students. |
|
Retrieves data from file |
|
Tries to match a name among a list of mails. |
|
Tries to match a series of names among a list of mails. |
Methods#
method |
truncated documentation |
---|---|
Location of the repository. |
|
Converts all notebooks and python scripts into HTML for a group. |
|
Enumerates all mails sent by or sent to a given group. |
|
Enumerates all files in a group. |
|
Enumerates all mails sent by or sent to a given group. |
|
Retrieves student emails from file |
|
Returns the local folder associated to a group. |
|
Extracts sections from a filename used to follow a group of students. |
|
Retrieves student emails from file |
|
Returns the number of mails of a group. |
|
Removes a group. |
|
Unzips files and convert notebooks into HTML. |
|
Unzips files and convert notebooks into HTML. |
|
Writes a command script to run a server for this local content. The server runs the javascripts fetching for local … |
|
Produces a summary and uses a Jinja2 template. |
|
Zips a group. |
Documentation#
Some automation helpers to grab mails from students about their projects.
- class ensae_teaching_cs.automation_students.projects_repository.ProjectsRepository(location, suivi='suivi.rst', fLOG=<function noLOG>)#
Bases :
object
Handle a repository of students projects. See example Récupérer des mails d’étudiants en pièce jointe (1:1).
Location of the repository.
- Paramètres:
location – location of the repository
suivi – name of the file gathering information about each project
- property Groups#
Returns all available groups in the repository.
- property Location#
- Renvoie:
location of the repository
- __init__(location, suivi='suivi.rst', fLOG=<function noLOG>)#
Location of the repository.
- Paramètres:
location – location of the repository
suivi – name of the file gathering information about each project
- _default_template_summary = '<?xml version="1.0" encoding="utf-8"?>\n<head>\n<meta http-equiv="content-type" content="text/html; charset=utf-8" />\n</head>\n<body>\n<html>\n<head>\n<title>{{ title }}</title>\n<link rel="stylesheet" type="text/css" href="{{ css }}">\n</head>\n<body>\n<h1>{{ title }}</h1>\n<ol type="1">\n{% for ps in groups %}\n <li><a href="{{ ps["link"] }}">{{ ps["group"] }}</a><small><i>\n {{ ps["nb"] }} files - {{ format_size(ps["size"]) }} -\n {% if len(ps["emails"]) > 0 %}\n last mail {{ ps["emails"][-1]["date"] }} ---{% else %}\n No mail found. {% endif %}\n {{ len(ps["attachments"]) }} attachments</i></small>\n {% if len(ps["attachments"]) + len(ps["links"]) > 0 %}\n <ul>\n {% for day, att, data in ps["attachments"] %}\n <li>att: {{ day }} - <a href="{{ att }}">{{ os.path.split(att)[-1] }}</a></li>\n {% endfor %}\n {% for date, from_, url, domain, last in ps["links"] %}\n <li>link: {{ date }} <a href="{{ url }}">{{ domain }} // {{ last }}</a> from {{ from_ }}</li>\n {% endfor %}\n </ul>\n {% endif %}\n {% if len(ps["created_files"]) > 0 %}\n <ul>\n {% for name, relpath, size in ps["created_files"] %}\n <li>added: <a href="{{ relpath }}">{{ name }}</a> {{ size }}</li>\n {% endfor %}\n </ul>\n {% endif %}\n </li>\n{% endfor %}\n</ol>\n</body>\n</html>\n'#
- _email_regex = re.compile('[*] *e?mails? *: *([^*+\\n]+)')#
- _gitlab_regex = re.compile('[*] *gitlab *: *([^*+\\n]+[.]git)')#
- _known_strings = ['xavierdupre.fr', 'doodle', 'ensaenotebook', 'teralab', 'outlook.com', 'gohlke', 'support.google', 'help.github', 'api.jcdecaux']#
- _link_regex = re.compile('(https?[:][^ \\"<>)(]+)')#
- _regex_split = re.compile('[-;,. @]')#
- _video_regex = re.compile('[*] *videos? *: *([^*\\n]+)')#
- convert_files(group)#
Converts all notebooks and python scripts into HTML for a group.
- Paramètres:
group – group name
- Renvoie:
list of new files
- static create_folders_from_dataframe(df, root, report='suivi.rst', col_student=None, col_group='Groupe', col_subject='Sujet', col_mail='mail', overwrite=False, email_function=None, must_have_email=True, skip_if_nomail=False, skip_names=None, fLOG=<function noLOG>)#
Creates a series of folders for groups of students.
- Paramètres:
root – where to create the folders
col_student – column which contains the student name (firt name + last name), equal to col_mail if None
col_group – index of the group (it can be None if each student is a group)
col_subject – column which contains the subject
col_mail – if there is a column which contains the mail in the input dataframe
df – DataFrame
email_function – function which infers email from first and last names, see below
report – report file
overwrite – if False, skip if the report already exists
must_have_email – if True, raises an exception if no mail is found
skip_if_nomail – skip a name if no mail is found
skip_names – less checking for a given set of names
fLOG – logging function
- Renvoie:
list of creates folders
The function email_function has the following signature:
def email_function(names): # part of a names is a list of tokens # ... return list of mails, skip=boolean
The boolean tells the function to skip this group. email_function can be a list of mails. In that case, this function is replaced by
match_mails
.
- dump_group_mails(renderer, group, mailbox, subfolder, date=None, skip_function=None, max_dest=5, filename='index_mails.html', overwrite=False, skip_if_empty=False, convert_files=False)#
Enumerates all mails sent by or sent to a given group.
- Paramètres:
renderer – instance of class EmailMessageListRenderer
group – group
mailbox – mailbox (see pymmails)
subfolder – which subfolder of the mailbox to look into
date – date
skip_function – if not None, use this function on the header/body to avoid loading the entire message (and skip it)
max_dest – maximum number of receivers
filename – filename which gathers a link to every mail
overwrite – overwrite
skip_if_empty – skip if no mail?
convert_files – unzip and convert
- Renvoie:
list of files (see EmailMessageListRenderer.write)
zip, gz, rar, 7z can be uncompressed. It then convert .py and .ipynb into html.
- enumerate_group_files(group)#
Enumerates all files in a group.
- Paramètres:
group – group
- Renvoie:
iterator on files
- enumerate_group_mails(group, mailbox, subfolder, date=None, skip_function=None, max_dest=5)#
Enumerates all mails sent by or sent to a given group.
- Paramètres:
group – group (if None, goes through all mails)
mailbox –
mailbox (see pymmails)
subfolder – which subfolder of the mailbox to look into
date – date
skip_function – if not None, use this function on the header/body to avoid loading the entire message (and skip it)
max_dest – maximum number of receivers
- Renvoie:
iterator on mails
- get_emails(group, skip_if_empty=False)#
Retrieves student emails from file
suivi.rst
.- Paramètres:
group – group
skip_if_empty – skip if no mail?
- Renvoie:
list of mails
- get_group_location(group)#
Returns the local folder associated to a group.
- Paramètres:
group – group name
- Renvoie:
local folder
- static get_regex(path, regex, suivi='suivi.rst', skip_if_empty=False)#
Retrieves data from file
suivi.rst
using a regular expression.- Paramètres:
path – sub folder to look into
suivi – name of the file
suivi.rst
skip_if_empty – skip of no mail?
- Renvoie:
list of mails
- get_sections(group)#
Extracts sections from a filename used to follow a group of students.
- Paramètres:
group – group
- Renvoie:
dictionary { section : content }
Example of a file:
rapport +++++++ * bla 1 extrait +++++++ :: paragraphe 1 paragraphe 2
- get_videos(group)#
Retrieves student emails from file
suivi.rst
.- Paramètres:
group – group
- Renvoie:
list of videos
- list_mails(group)#
Returns the number of mails of a group.
- Paramètres:
group – group name
- Renvoie:
list of mails
- static match_mail(name, emails, threshold=3, exc=True)#
Tries to match a name among a list of mails.
- Paramètres:
name – a name (first name last name separated by a space)
emails – list of emails
threshold – above this threshold, mails and names don’t match
exc – raise an Exception if not found
- Renvoie:
list of available mails, boolean
The second results is True if no email were found in the list.
- static match_mails(names, emails, threshold=3, exc=True, skip_names=None)#
Tries to match a series of names among a list of mails.
- Paramètres:
names – list of names (first name last name separated by a space)
emails – list of emails
threshold – above this threshold, mails and names don’t match
exc – raise an Exception if not found
skip_names – the second boolean is True is one of the name belongs to this list
- Renvoie:
list of available mails, boolean
The second results is True if no email were found in the list.
- remove_group(group)#
Removes a group.
- Paramètres:
group – group
- Renvoie:
list of removed files
See remove_folder.
- unzip_convert(group)#
Unzips files and convert notebooks into HTML.
- Paramètres:
group – group name
- Renvoie:
list of new files
- unzip_files(group)#
Unzips files and convert notebooks into HTML.
- Paramètres:
group – group name
- Renvoie:
list of new filess
- write_run_command(filename=None, renderer=None)#
Writes a command script to run a server for this local content. The server runs the javascripts fetching for local files. The content is available at
http://localhost:9000/
.
- write_summary(renderer=None, link='index_mails.html', outfile='index.html', title='summary', nolink_if=None)#
Produces a summary and uses a Jinja2 template.
- Paramètres:
renderer – instance of EmailMessageRenderer), can be None
link – look for this file in each folder
outfile – output file
nolink_if – link containing those strings will be removed (if None, a default set will be assigned)
title – title
- Renvoie:
summary
The current default template is:
.. runpython::
from ensae_teaching_cs.automation_students.projects_repository import _default_template_summary_template print(_default_template_summary)
- zip_group(group, outfile, addition=None)#
Zips a group.
- Paramètres:
group – group
outfile – output file
addition – additional files (sequence)
- Renvoie:
list of zipped files