From the course: Code Clinic: Clojure
Unlock the full course today
Join today to access over 22,400 courses taught by industry experts or purchase this course individually.
Averages and medians - Clojure Tutorial
From the course: Code Clinic: Clojure
Averages and medians
- [Instructor] For our program we'll need one more query. This query will perform our averages and medians for our weather metrics across a given time span. The SQL string for this query is somewhat long, so I'll define it separately from the function, and I'll call it def avg-median-query for average median query. The select clause of this query will contain the average and median functions. So I'll use select avg, and then, in parentheses, wind_speed. This will average the wind speed values. Since the query function will use this select clause to determine the keys to set in its response, I'm gong to use as so that we can rename this key. I'll name it avg_wind_speed. Now when we get back the data, the keyword will be avg_wind_speed rather than the former one with parentheses in it. When a keyword has parentheses in it, you can't write it literally in Clojure, and it becomes a bit awkward to deal with. Now I'll hit comma and Enter, and I'll copy this select clause for several weather…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.