Databases Assessed Exercise (Tick) 2 Briefing

This work will use the TinyDB document database, explained here Document Tutorial.

There are three questions to answer for this Assessed Exercise. All three questions should be answered from the candidate's private worksheet.

The following template file should be the basis of answers: db2324-tick2-template-py.

Extend/modify a fresh copy of this file for each of the three questions. Make sure field ordering and file names match those expected by the validator and automarker.

The provided 'display_ans' subroutine must be used to create the result files submitted. This tops and tails the output with -ANSWER-START- and -ANSWER-END-. Answers typically involve using the TinyDB 'Query' construct, but the lookup can be partly or fully coded in ad-hoc Python, as seems best.

Some questions may include follow-up answers or require estimating or counting reports. Instrument the code as seems best and make sure these additional answers and result values are put after the -ANSWER-END- tag in the submitted file in free-text form.

Make sure the current year's IMDB snapshot is being used (ie not necessarily the 23/24 one).

Example

For instance, the question might be:
Generate a table with two columns, actor name and count, for the number of films in our snapshot that that actor has acted in, where the actors are 'Hugh Bonneville', 'Hugh Grant', 'Ben Whishaw', 'Julie Andrews'.

In which case, an appropriate answer could be

  #####################################
  # write your query code here ...
  my_actors = [ 'Hugh Bonneville',    'Hugh Grant',    'Ben Whishaw',    'Julie Andrews' ]

  def demo1_question():
	ans = []
	for actor in my_actors:
	    count = tdb_movies.count(Query().actors.any(Query().name == actor))
	    line = f'{actor}, {count}'
	    ans.append(line)
	display_ans(ans)

    demo1_question()
  # eof

and the output file could look like this (dependent on the IMDB snapshot in use):

python3 demo1.py  /home/djg11/dbase-json-location
-ANSWER-START-
Ben Whishaw, 3
Hugh Bonneville, 2
Hugh Grant, 5
Julie Andrews, 3
-ANSWER-END-
Returned 4 records

The submitted answer table should not contain json. It should contain the requested fields only, separated with a punctuation character, such as a comma.

Submission

Submission uses a zip file uploaded to Moodle. Details are specified in the worksheet. Remember to include the AI and originality warranty/declaration.


This page is : https://www.cl.cam.ac.uk/teaching/2324/Databases/djg-materials/t2-briefing.html