Created
September 6, 2013 00:27
-
-
Save StephenOTT/6458046 to your computer and use it in GitHub Desktop.
Analysis methods for Mongodb for Health Data
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
def analyzeRestaurantNameCount | |
return restaurantNameCount = @coll.aggregate([ | |
{ "$project" => {doc:{str:{fs_fnm: 1}}}}, | |
{ "$group" => {_id: "$doc.str.fs_fnm", number: { "$sum" => 1 }}}, | |
{ "$sort" => {"_id" => 1 }} | |
]) | |
end | |
def analyzeRestaurantCategoryCount | |
restaurantCategoryCount = @coll.aggregate([ | |
{ "$project" => {doc:{str:{fs_ft_en: 1}}}}, | |
{ "$group" => {_id: "$doc.str.fs_ft_en", number: { "$sum" => 1 }}}, | |
{ "$sort" => {"_id" => 1 }} | |
]) | |
# TODO clean up hash creation code with better namming | |
newHash={} | |
restaurantCategoryCount.each do |x| | |
newHash[x["_id"][0]] = x["number"] | |
end | |
return newHash | |
end | |
def analyzeRestaurantStreetCount | |
return restaurantStreetCount = @coll.aggregate([ | |
{ "$project" => {doc:{str:{fs_fss: 1}}}}, | |
{ "$group" => {_id: "$doc.str.fs_fss", number: { "$sum" => 1 }}}, | |
{ "$sort" => {"_id" => 1 }} | |
]) | |
end | |
def analyzeRestaurantCreationDateCount | |
return restaurantCreationDateCount = @coll.aggregate([ | |
{ "$project" => {doc:{str:{fs_fcr_date: 1}}}}, | |
{ "$group" => {_id: "$doc.str.fs_fcr_date", number: { "$sum" => 1 }}}, | |
{ "$sort" => {"_id" => 1 }} | |
]) | |
end | |
def analyzeRestaurantsCreatedPerMonth | |
return restaurantsCreatedPerMonth = @coll.aggregate([ | |
{ "$project" => {created_month: {"$month" => "$doc.str.fs_fcr_date"}}}, | |
{ "$group" => {_id: {"created_month" => "$doc.str.fs_fcr_date"}, number: { "$sum" => 1 }}}, | |
{ "$sort" => {"_id.created_month" => 1}} | |
]) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment