<html> <h1 id=“assignment-2-ads-take-aim”>Assignment 2: Ads Take Aim</h1> <p><strong>Due:</strong> Thursday September 23, 2021 at 11:59PM ET.</p> <p><img src=“https://www.cs.vassar.edu/~cs101/images/targeted-ad.jpeg” alt=“Targeted Advertising”></p> <h2 id=“setup-and-handin”>Setup and Handin</h2> <h3 id=“setup”>Setup</h3> <ul> <li>Create a new file on <a href=“https://code.pyret.org/”>Pyret</a>.</li> <li>Unlike with Assignment 1, we are writing examples for this assignment! Write examples for each function you implement using a
where
block. Here is a sample:</li> </ul> <pre>
fun <span class="hljs-keyword">add</span><span class="bash">-one(n :: Number) -> Number: </span> n + <span class="hljs-number">1</span> where: <span class="hljs-keyword">add</span><span class="bash">-one(1) is 2 </span> <span class="hljs-keyword">add</span><span class="bash">-one(3) is 4 </span> <span class="hljs-keyword">add</span><span class="bash">-one(-1) is 0 </span>end
</pre><ul> <li>Try to write your examples before filling in your functions so you can quickly tell if they are working correctly.</li> <li>You will be graded on having examples that cover a variety of situations, so take a look at the <a href=“https://www.cs.vassar.edu/~cs101/1/pyret.html”>Testing and Style Guidelines</a>. </li> <li>Do not put your name anywhere in any file.</li> </ul> <h3 id=“handin”>Handin</h3> <ul> <li>Make sure your file is called
asmt2-code.arr
. Hand in your work on Gradescope.</li> <li>You may submit as many times as you want before the deadline. Only your latest submission will be graded.</li> </ul> <h2 id=“helpful-things”>Helpful Things</h2> <h3 id=“documentation”>Documentation</h3> <p>The <a href=“https://www.pyret.org/docs/latest/”>Pyret documentation</a> is accessible from the Pirate button in the top left corner of <a href=“http://code.pyret.org/”>code.pyret.org</a>.</p> <p>For this assignment, you will find the <a href=“https://www.pyret.org/docs/latest/strings.html”>strings documentation</a> useful. We recommend briefly browsing this page before working on these problems!</p> <h3 id=“staff-assistance”>Staff Assistance</h3> <p>Your friendly coaches and professor are here to help with this assignment! Check your section's homepage for information on office and coaching hours.</p> <p>If you have any questions, please post on <a href=“https://campuswire.com/c/G916D3D51/feed”>Campuswire</a>. Make sure you’re following the syllabus's guidelines for Campuswire, including not posting any code.</p> <h2 id=“the-coding-assignment”>The Coding Assignment</h2> <p>Giselle has been the proud owner of a sporting goods store in Oatman for the past few months, but recently she has seen advertisements for a competitor all over town. Afraid of losing much of her business, Giselle hires the Oatman Ad Agency in her town.</p> <p>The Oatman Ad Agency recommends targeting people living nearby who would be able to get to a store in downtown Oatman. They decide specifically to target people with sporting interests in their twenties. The Ad Agency already has data on locals’ age, hobbies, town, and whether they have a car.</p> <p><strong>Task: Copy and paste these definitions into the top of your code.</strong></p> <pre>
<span class="hljs-attr">TARGET-AGE</span> = <span class="hljs-number">25</span> <span class="hljs-attr">TARGET-TOWN</span> = <span class="hljs-string">"oatman"</span> <span class="hljs-attr">TARGET-HOBBIES</span> = <span class="hljs-string">"running, biking, walking, swimming"</span>
</pre><p>Let’s help the Ad Agency figure out what customers fit Giselle’s criteria. We want to write a function that takes a person’s age, hobby, town, and car status and determines whether or not Giselle should send them an ad.</p> <p>In order to figure out whether or not someone should get an ad, we need to first figure out some more basic information about them.</p> <h2 id=“part-1-targeted-ads”>Part 1: Targeted ads</h2> <h3 id=“1a-criteria-functions”>1A: Criteria functions</h3> <p>To decide if someone is a good potential customer to advertise to, we'll write a series of predicates (functions that return a
Boolean
).</p> <ol> <li>Let’s start by writing a function to see if any potential customer is within 5 years of Giselle’s target age.<br><br> <strong>Task:</strong> Write a the function called
within-5
. This function should take in a
Number
representing a person’s age and return a
Boolean
which is
true
if target
TARGET-AGE
is within five years of the input, and
false
if not.<br><br> This should be an inclusive comparison, meaning that if the target age is exactly five years older or younger than the target, the function should return
true
.<br><br> <em>Note: Check out the <a href=“https://www.pyret.org/docs/latest/numbers.html”>Number documentation</a>!</em><br><br> <em>Hint: Make sure to write type annotations, a docstring, and examples first.</em><br><br></li> <li>Since Giselle is looking for a variety of interests that customers might have, we want to see if a customer’s interest is one of her target hobbies.<br><br> <strong>Task:</strong> Write a function called
hobby-relates
, which takes in a
String
representing a person’s hobby and returns a
Boolean
which is
true
when the definition
TARGET-HOBBIES
contains the input hobby in it, and
false
otherwise. It might be useful to take a look at Pyret’s
String
documentation to figure out how to do this.<br><br></li> <li>Giselle wants to be able to see if a person’s town is within the general area of her store. However,
TARGET-TOWN
only gives us a specific place! To solve this issue, we need to write a function to check if a certain location is in the target town or its surrounding area.<br><br> <strong>Task:</strong> Write in the function
in-area
, which takes in a
String
representing a town and returns a
Boolean
which is
true
if the input is
"kingman"
,
"needles"
,
"oatman"
, or
"topock"
(the towns around her store), and
false
otherwise.<br><br></li> <li>Now we can find out if someone lives in the area, but Giselle knows that people can only get to her store if they live in the target town itself or if they can drive to the target town from another town in the area.<br><br> <strong>Task:</strong> Write in the function
in-range
, which takes in a
String
representing a customer’s town and a
Boolean
representing if the person has a car or not. It should return a
Boolean
which is
true
if the place is
TARGET-TOWN
or both the input place is in the target area and the person has a car. Otherwise, the function should return
false
.<br><br></li> </ol> <h3 id=“1b-combining-criteria”>1B: Combining criteria</h3> <p>Now it’s time to put all the criteria together to determine whether an ad should be shown to a potential customer or not!<br><br> <strong>Task:</strong> Write a function called
show-ad
. The inputs are a
Number
representing a customer’s age, a
String
representing their town, a
String
representing their hobby, and a
Boolean
representing if they have a car. The output is a
Boolean
which is
true
when their age is within five years of the target age (inclusive), their town is within the area with a car or in
TARGET-TOWN
itself, and
TARGET-HOBBIES
contains their hobby. The output is
false
otherwise.<br><br></p> <h3 id=“1c-using-keywords”>1C: Using keywords</h3> <p>A different way of targeting ads is looking at keywords in the text of the advertisement rather than specific criteria like Giselle’s target definitions.<br><br></p> <p><strong>Task:</strong> Fill in the function
show-ad2
, which takes in a
String
representing the text of an ad and a
Number
representing a person’s age, and returns a
Boolean
. This Boolean will be
true
if <strong>any</strong> of the following conditions are met, and
false
otherwise:</p> <ul> <li>The customer’s age is 35 or younger and the ad contains the word “active”</li> <li>The customer’s age is 65 or older and the ad contains the word “healthy”</li> <li>The ad text contains the word “sport”</li> </ul> <h2 id=“part-2-clarifying-the-ad-prices”>Part 2: Clarifying the ad prices</h2> <p>Giselle finally places her ad with the Oatman Ad Agency! However, the code for pricing is really unclear, so she can’t figure out how much an ad will cost based on the length of its text. 😤</p> <p>The code is completely functional, but it looks like this:</p> <pre>
fun ad-charge(<span class="hljs-keyword">text</span>): <span class="hljs-keyword">short</span>-<span class="hljs-built_in">length</span> = <span class="hljs-number">10</span> medium-<span class="hljs-built_in">length</span> = <span class="hljs-number">40</span> <span class="hljs-keyword">long</span>-<span class="hljs-built_in">length</span> = <span class="hljs-number">70</span> <span class="hljs-keyword">if</span> ((<span class="hljs-keyword">string</span>-<span class="hljs-built_in">length</span>(<span class="hljs-keyword">text</span>) >= <span class="hljs-keyword">short</span>-<span class="hljs-built_in">length</span>) <span class="hljs-keyword">and</span> (<span class="hljs-keyword">string</span>-<span class="hljs-built_in">length</span>(<span class="hljs-keyword">text</span>) < medium-<span class="hljs-built_in">length</span>)): (<span class="hljs-keyword">string</span>-<span class="hljs-built_in">length</span>(<span class="hljs-keyword">text</span>) * (<span class="hljs-keyword">short</span>-<span class="hljs-built_in">length</span> / <span class="hljs-number">2</span>)) + (<span class="hljs-keyword">string</span>-<span class="hljs-built_in">length</span>(<span class="hljs-keyword">text</span>) * <span class="hljs-number">5</span>) <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> ((<span class="hljs-keyword">string</span>-<span class="hljs-built_in">length</span>(<span class="hljs-keyword">text</span>) >= medium-<span class="hljs-built_in">length</span>) <span class="hljs-keyword">and</span> (<span class="hljs-keyword">string</span>-<span class="hljs-built_in">length</span>(<span class="hljs-keyword">text</span>) < <span class="hljs-keyword">long</span>-<span class="hljs-built_in">length</span>)): (<span class="hljs-keyword">string</span>-<span class="hljs-built_in">length</span>(<span class="hljs-keyword">text</span>) * (medium-<span class="hljs-built_in">length</span> / <span class="hljs-number">2</span>)) + (<span class="hljs-keyword">string</span>-<span class="hljs-built_in">length</span>(<span class="hljs-keyword">text</span>) * <span class="hljs-number">5</span>) <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (<span class="hljs-keyword">string</span>-<span class="hljs-built_in">length</span>(<span class="hljs-keyword">text</span>) >= <span class="hljs-keyword">long</span>-<span class="hljs-built_in">length</span>) : (<span class="hljs-keyword">string</span>-<span class="hljs-built_in">length</span>(<span class="hljs-keyword">text</span>) * (<span class="hljs-keyword">long</span>-<span class="hljs-built_in">length</span> / <span class="hljs-number">2</span>)) + (<span class="hljs-keyword">string</span>-<span class="hljs-built_in">length</span>(<span class="hljs-keyword">text</span>) * <span class="hljs-number">5</span>) <span class="hljs-keyword">else</span>: <span class="hljs-number">0</span> <span class="hljs-function"><span class="hljs-keyword">end</span> <span class="hljs-title">where</span>:</span> ad-charge(<span class="hljs-string">"Go VC!"</span>) is <span class="hljs-number">0</span> ad-charge(<span class="hljs-string">"GoBrewers!"</span>) is <span class="hljs-number">100</span> ad-charge(<span class="hljs-string">"GoBrewers!GoBrewers!GoBrewers!GoBrewers!"</span>) is <span class="hljs-number">1000</span> ad-charge(<span class="hljs-string">"GoBrewers!GoBrewers!GoBrewers!GoBrewers!GoBrewers!GoBrewers!GoBrewers!"</span>) is <span class="hljs-number">2800</span> <span class="hljs-keyword">end</span>
</pre><p>Take a minute to read the code all the way through and figure out what it’s doing. Try working through one of the examples provided to see how the answer was derived. This will make it a lot easier to do the task.</p> <p><strong>Task:</strong> Rewrite the code so it’s clearer and cleaner in order to help Giselle! In fact, it should be clear enough that it meets all of the Design and Clarity requirements of the <a href=“https://www.cs.vassar.edu/~cs101/1/pyret.html”>Style Guidelines</a>. Feel free to copy and edit it, but it might be easier to just start from scratch.</p> <p>It’s important to make sure that the code still works the way it originally did.</p> <p><em>Note: Feel free to copy over the same four examples from the original version of this function. It’s important to have some examples to make sure the code still functions the same way, but we’re not grading your examples here. Instead, we’re just grading your style.</em></p> <h2 id=“part-3-personal-data-and-privacy”>Part 3: Personal Data and Privacy</h2> <p>Beyond teaching you technical skills around computing and data, CMPU 101 also wants to help you think about the broader societal issues surrounding them. </p> <p><strong>Goal:</strong> Students should begin to think about how data collection impacts technology users regardless of users’ technical knowledge, and articulate ways in which issues in technology can cause different people to react.</p> <p><strong>Task:</strong> Read this <a href=“https://www.nytimes.com/2019/04/21/opinion/computational-inference.html”>short article on computational inference</a> on how companies can infer information about people based on their online activities. </p> <p>Using a multi-line comment </p> <pre>
#| ... multi line comment... |#
</pre><p>in your program, describe your thoughts about the reading and how real online tracking compares with the simple version implemented in this assignment. Your response should be approximately one paragraph. There are no right or wrong answers here. Our goal is to get you thinking about the context of the technical content of the course. </p> <h2 id=“autograder-notes”>Autograder Notes</h2> <ul> <li>We've enabled the autograder for this assignment. </li> <li><strong><em>This is a trial run.</em></strong> </li> <li>Be sure to use the filename (
asmt2-code.arr
) and function names exactly as indicated above.</li> <li>If you do not, the autograder will not work.</li> <li>Please let us know if you encounter anything out of the ordinary. </li> </ul> <h2 id=“acknowledgments”>Acknowledgments</h2> <p>This lab includes material adapted from Kathi Fisler and colleagues at Brown University.</p>
</html>