Skip to content

Instantly share code, notes, and snippets.

@samrocketman
Last active September 20, 2021 15:56
Show Gist options
  • Save samrocketman/765d46b12870e4eb26f1e7a0ae8ecd65 to your computer and use it in GitHub Desktop.
Save samrocketman/765d46b12870e4eb26f1e7a0ae8ecd65 to your computer and use it in GitHub Desktop.
import groovy.json.JsonSlurper
// criteria
String title_contains = 'DevOps' // required
String salary_currency = 'USD' // or null; example: CAD, CHF, DKK, EUR, GBP, HKD, INR, NZD, PHP, USD
String company_location = 'US' // or null; example: AT, BG, CA, CH, CR, DE, DK, ES, FR, GB, IL, IN, IT, LT, NL, NZ, PH, PT, RO, RU, US
Boolean display_usd = true // false for native currency
List salaries = new JsonSlurper().parse(new File('/home/sam/Downloads/salaries.json'))
//stuff
salaries.findAll {
(!company_location || it.company_location == company_location) &&
it.job_title.toLowerCase().contains(title_contains.toLowerCase()) &&
(!salary_currency || it.salary_currency == salary_currency)
}*.experience_level.sort().unique().each { experience_level ->
double average = 0.0
double max = 0.0
double min = 0.0
int dataset = 0
salaries.findAll {
(!company_location || it.company_location == company_location) &&
it.job_title.toLowerCase().contains(title_contains.toLowerCase()) &&
(!salary_currency || it.salary_currency == salary_currency) &&
it.experience_level == experience_level
}.with {
display_usd ? it*.salary_in_usd : it*.salary
}*.toInteger().with { s ->
average = s.sum() / s.size()
max = s.max()
min = s.min()
dataset = s.size()
}
println ("${experience_level}: min ${min}, max ${max}, average ${average} (${dataset} salary entr${(dataset == 1)?'y':'ies'})")
}
null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment