use context essentials2021 # Library for tables that goes with DCIC textbook include shared-gdrive("dcic-2021", "1wyQZj_L0qqV9Ekgr9au6RX2iqt2Ga8Ep") # Our table data for municipalities in NY State include shared-gdrive("municipalities.arr", "10LyywS8KYe0bfEHebDzCBYYq7XxDrvQn") #| Try evaluating the following in the interactions pane >>> municipalities >>> municipalities.row-n(0) >>> municipalities.row-n(0)["name"] |# fun population-decreased(r :: Row) -> Boolean: doc: "Return true if the municipality's population went down between 2010 and 2020" r["pop-2020"] < r["pop-2010"] end fun is-town(r :: Row) -> Boolean: doc: "Check if a row is for a town" r["kind"] == "Town" end #| Try evaluating to filter municipalities table: >>> filter-with(municipalities, population-decreased) >>> filter-with(municipalities, is-town) |# #| Order table by population (descending): >>> order-by(municipalities, "pop-2020", false) |# #| How would we get the town with the smallest population? (by composing an expression over tables!) order-by( filter-with(municipalities, is-town), "pop-2020", true).row-n(0) |# #| What are the fastest growing towns in New York? Break the problem up into subtasks: 1. Filtering out the cities 2a. Calculating percentage change in population 2b. Building a column for percentage change 3. Sorting on that column in descending order |# fun percent-change(r :: Row) -> Number: doc: "Compute the percentage change for the population of the given municipality between 2010 and 2020" (r["pop-2020"] - r["pop-2010"]) / r["pop-2010"] end # 1. towns = filter-with(municipalities, is-town) # 2a and 2b. towns-with-percent-change = build-column(towns, "percent-change", percent-change) # 3. fastest-growing-towns = order-by(towns-with-percent-change, "percent-change", false) # fastest-growing-towns