Databases 23/24 Assessed Exercise (Tick 2) Briefing

The second Tick work sheets will be ready before the start of 20th November 2023.

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

You will be asked to answer any two out of three questions.

Each question will involve you writing a TinyDB query embedded in Python. You should use the following template file as the basis of your answers: db2324-tick2-template-py.

You should extend this file with your answer and that version will be part of your submission.

For instance, your 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 would look like this:

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

Please make sure you are familiar with the other constructs in the relevant Tutorial. Answers can either use the TinyDB 'Query' construct or can be coded in ad-hoc Python.


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