Module data

Module data

General requirements

  1. Data is saved as an UTF-8 encoded JSON file.
  2. The portfolio should use the fields project_id, project_name, start_date, end_date, course_id, course_name, techniques_used, description, long_description, image, external_link.
  3. The data module must only depend on the fields project_id, project_name, and techniques_used existing.
  4. Dates in the data should use the ISO 8601 format.
Functions
list
load(filename)
Loads JSON formatted project data from a file and returns a list of all projects, sorted after number.
number
get_project_count(db)
Retrieves the number of projects in a project list.
dict
get_project(db, id)
Fetches the project with the specified id from the specified list.
list
search(db, sort_by='start_date', sort_order='desc', techniques=None, search=None, search_fields=None)
Fetches and sorts projects matching criteria from the specified list.
list
get_techniques(db)
Fetches a list of all the techniques from the specified project list in lexicographical order.
dict
get_technique_stats(db)
Collects and returns statistics for all techniques in the specified project list.
Variables
  __package__ = None
Function Details

load(filename)

 

Loads JSON formatted project data from a file and returns a list of all projects, sorted after number.

load reads objects from a UTF-8 encoded JSON file, and returns a list of projects.

On errors, None is returned.

Parameters:
  • filename (string) - The filename containing project data.
Returns: list
All the project data from the read file, or None.

get_project_count(db)

 

Retrieves the number of projects in a project list.

Parameters:
  • db (list) - A list as returned by load.
Returns: number
The number of projects in the list.

get_project(db, id)

 

Fetches the project with the specified id from the specified list.

If the specified project id does not exist, None is returned.

Parameters:
  • db (list) - A list as returned by load.
  • id (number) - The ID of the wanted project.
Returns: dict
All project data for the specified project, or None.

search(db, sort_by='start_date', sort_order='desc', techniques=None, search=None, search_fields=None)

 

Fetches and sorts projects matching criteria from the specified list.

Parameters:
  • db (list) - A list as returned by load.
  • sort_by (string) - The name of the field to sort by.
  • sort_order (string) - The order to sort in. 'asc' for ascending, 'desc' for descending.
  • techniques (list) - List of techniques that projects must have to be returned. An empty list means this field is ignored
  • search (string) - Free text search string.
  • search_fields (list) - The fields to search for search in. If search_fields is empty, no results are returned. If search_fields is None, all fields are searched.
Returns: list
A list containing dictionaries for all the projects conforming to the specified search criteria.

get_techniques(db)

 

Fetches a list of all the techniques from the specified project list in lexicographical order.

Parameters:
  • db (list) - A list as returned by load.
Returns: list
A alphabetically sorted list containing the names of all techniques in db.

get_technique_stats(db)

 

Collects and returns statistics for all techniques in the specified project list.

The key of each entry in the returned dictionary is the technique name, and the value is a list of dictionaries for each of the projects using the technique.

Each of those dictionaries representing a project has the keys:

  • id (int): Project ID
  • name (string): Name of the project

An example is:

>>> retrieve_technique_stats()
{
 'python': [{'id': 42, 'name': 'TDP003'}, {'id': 17, 'name': 'TDP002'}],
 'c++': [{'id': 3, 'name': 'TDP005'}]
}
Parameters:
  • db (list) - A list as returned by load.
Returns: dict
Technique stats (see above).