Created
February 6, 2013 01:13
-
-
Save krishnanraman/4719339 to your computer and use it in GitHub Desktop.
Maximize your chances of hooking up, with Scalding :))
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Goal: You are a male between the age of (20,40). | |
| You want to hook up with a lady, perhaps get married. | |
| Where should you go to maximize your chances ? | |
| Scalding code: sexratio(2011,(20,40),people,fipspipe) | |
| where sexratio as below: | |
| def sexratio(baseYear:Int, agerange:(Int,Int), people:Pipe, fipspipe:Pipe) = { | |
| people.filter('year,'age) { | |
| yearage:(Int,Int) => | |
| val (year,age) = yearage | |
| (year == baseYear) && (age>=agerange._1) && (age<=agerange._2) // marriageable age | |
| }.groupBy('fips, 'isMale){ | |
| group => group.plus[Int]('population->'population) | |
| }.groupBy('fips) { | |
| val init = 0.0d | |
| type X = Double | |
| type T = (Int,Boolean) | |
| // foldLeft[X,T](fieldDef : (Fields,Fields))(init : X)(fn : (X,T) => X) | |
| group => group.foldLeft[X,T]( ('population,'isMale) -> ('sexratio))(init:X) { | |
| (x:X, t:T) => | |
| val ratio = x | |
| val (population,isMale) = t | |
| if(ratio==0.0) (population+0.0d) | |
| else { | |
| val sexratio = ratio/(population+0.0d) | |
| if (isMale) 1.0/sexratio else sexratio | |
| } | |
| } | |
| }.joinWithSmaller(('fips-> 'fips), fipspipe) | |
| .project('sexratio, 'state,'county) | |
| .groupAll(_.sortBy('sexratio)) | |
| .write(Tsv("sexratio"+baseYear+".txt")) | |
| } | |
| SORTED RESULTS: | |
| ------------- | |
| SEX RATIO (M/F), State, County | |
| 0.5809725158562368 Georgia Pulaski | |
| 0.6842327150084317 West Virginia Summers | |
| 0.6924882629107981 Wyoming Niobrara | |
| 0.7 Missouri Audrain | |
| 0.7070063694267515 Indiana Parke | |
| 0.7194008037997808 Missouri Livingston | |
| 0.7434895833333334 Virginia Fluvanna | |
| 0.764525993883792 North Dakota Hettinger | |
| 0.7655172413793103 Texas Oldham | |
| 0.7692307692307692 Texas Loving | |
| 0.7831548198636806 Ohio Union | |
| ....3000 more counties here ..... | |
| 3.4205729166666665 Georgia Wheeler | |
| 3.56390977443609 Colorado Bent | |
| 4.472380952380952 Pennsylvania Forest | |
| 4.957894736842105 Texas Concho | |
| 5.52020202020202 Colorado Crowley | |
| ------------- | |
| TL:DR; | |
| Pulaski County, Georgia has the most advantageous sex ratio of 0.58 ( Male/Female in the (20,40) agegroup) | |
| ~ Two women for every man! | |
| The absolute worst place to relocate to, otoh, is the maximum security prison community of Crowley, CO, with six guys per lady. | |
| Supporting proof from Google: http://bit.ly/Y8Vhbb | |
| Scalding FTW! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment