instagram

(Also available in Pyret)

Students learn how to chain Transformers together, and define more sophisticated subsets.

Lesson Goals

Students will be able to…​

  • Use method chaining to write more sophisticated analyses using fewer clicks

  • Identify bugs introduced by chaining Transformers in the wrong order

Student-facing Lesson Goals

  • Let’s practice combining Transformers together.

Materials

Preparation

  • Make sure all materials have been gathered

  • Decide how students will be grouped in pairs

  • Computer for each student (or pair), with access to the internet.

  • Students should have Student workbook and something to write with.

🔗Design Recipe Practice 25 minutes

Overview

Students practice more of what they learned in the previous lesson, applying the Design Recipe to make Transformers with unique formula expressions that operate on rows of the Animals Dataset. These become the basis of the chaining activity that follows.

Launch

The Design Recipe is a powerful tool for solving problems by writing formula expressions. It’s important for this to be like second nature, so let’s get some more practice using it!

Investigate

Define the Transformers and formula expressions on Design Recipe and The Design Recipe.

Optional: Combining Booleans

Suppose we want to build a table of Animals that are fixed and old, or a table of animals that are cats or dogs?

By using the and and or operators, we can combine boolean tests on a single Transformer, like Filter. Once we’ve opened the Filter Transformer, we would tell CODAP to keep all rows that satisfy Species = "cat" and Species = "dog". This is handy for more complex programs! For example, we might want to ask if a character in a video game has run out of health points and if they have any more lives. We might want to know if someone’s ZIP Code puts them in Texas or New Mexico. When you go out to eat at a restaurant, you might ask what items on the menu have meat and cheese.

When we want to chain together different Transformers, however, this strategy will not work. We’ll need to find another way!

Synthesize

Did students find themselves getting faster at using the Design Recipe? Can students share any patterns they noticed, or shortcuts they used?

🔗Chaining 25 minutes

Overview

Students learn how to compose multiple table operations (sorting, filtering, building) on the same table - a technique called "chaining".

Launch

Now that we are doing more sophisticated analyses, we might find ourselves in a situation where we want to use a series of Transformers!

Let’s say that a journalist comes to the shelter. She wants to write a story about a successful pet adoption—​but she has a very specific set of criteria. The reporter wants to report on the adoption of an animal that weighs no more than 9 kilograms. She wants to consider all eligible animals in order from lightest to heaviest.

This reporter also informs you that it might take some time for her to find the perfect pet adoption scenario. Until she finds what she’s looking for, she wants a weekly updated list of the pets who meet her criteria.

Let’s break down the reporter’s specifications:

  • Give the weight in kilograms.

  • Include only animals that weigh no more than 9 kilograms.

  • Order weight in kilograms from lightest to heaviest.

  • Update the table weekly to reflect the changing population of the shelter.

The journalist has a lot of needs!

Fortunately, in CODAP, we can use the result of one Transformer as an input to another. In other words: Transformers can be chained, resulting in a sequence of datasets, each a transformed version of the previous. Any updates made to an input dataset will flow through and affect its outputs. If you have a chain of transformed datasets and you change the original dataset, the updates will flow through the chain.

As you chain together Transformers, it is important to remember the following:

Order matters: Build, Filter, Sort.

Suppose we want to build a column and then use it to filter our table. If we use the Transformers in the wrong order (trying to filter by a column that doesn’t exist yet), we might wind up crashing the program. Even worse, the program might work, but produce results that are incorrect!

Tip: Saving Transformers and Renaming Tables

Saving a particular configuration of a Transformer is useful so that the Transformer can be easily accessed in the future. When we save a Transformer, we want to give it a useful name and purpose statement, just like we practiced earlier in this lesson. Just as functions in algebra can be re-used with multiple inputs, Transformers can be re-used with multiple tables.

We also encourage students to rename tables descriptively. By the end of this exercise, the table students create will have quite a lengthy name: (Sort(Filter(BuildAttribute(Animals-Dataset)))). That’s a lot of parentheses! As an alternative, student might consider using the following table names in this activity: animals-in-kg, followed by light-animals-in-kg, and then ordered-light-animals-in-kg.

Let’s go through how we might meet the journalist’s needs.

  • Give the weight in kilograms.

For this step, we’ll use Build Attribute, which makes a new copy of the dataset, adding a Weight (kgs) column. (Hint: To get from pounds to kilograms, divide by 2.205.)

  • Include only animals that weigh no more than 9 kilograms.

We are going to Filter now, applying the Transformer to the dataset we created in the previous step. In the dropdown menu of datasets, our dataset is named (BuildAttribute(Animals-Dataset)). We will want to keep all rows where Weight (kgs) is less than or equal to 9.

  • Order weight in kilograms from lightest to heaviest.

Remember - we want to be able to easily create a table that meets the journalist’s specifications, so we’ll want to use the Sort Transformer here, rather than the Sort dropdown option that appears when we click Weight. Be sure to select the correct dataset to sort!

  • Update the table weekly to reflect the changing population of the shelter.

Because we’re using Transformers, each time the Animals Table is updated, the journalist’s table will be updated, too! Try adding or removing a row from the original table and observe the ripple effect in your chained tables.

Investigate

When chaining Transformers, it’s important to build first, then filter, and then order.

How well do you know your table methods? Complete Chaining Methods and Chaining Methods 2: Order Matters in your Student Workbook to find out.

Synthesize

As our analysis gets more complex, chaining is a great way to re-use work we’ve already done. And less duplicate work means a smaller chance of bugs. Chaining is a powerful way to work, so it’s critical to think carefully when we use it!

🔗Additional Exercises

These materials were developed partly through support of the National Science Foundation, (awards 1042210, 1535276, 1648684, and 1738598). CCbadge Bootstrap by the Bootstrap Community is licensed under a Creative Commons 4.0 Unported License. This license does not grant permission to run training or professional development. Offering training or professional development with materials substantially derived from Bootstrap must be approved in writing by a Bootstrap Director. Permissions beyond the scope of this license, such as to run training, may be available by contacting contact@BootstrapWorld.org.