Skip to content

Instantly share code, notes, and snippets.

@kf0jvt
Created January 30, 2014 19:16
Show Gist options
  • Select an option

  • Save kf0jvt/8716623 to your computer and use it in GitHub Desktop.

Select an option

Save kf0jvt/8716623 to your computer and use it in GitHub Desktop.
def aggregateIndustry(inArray):
returnArray = [{'_id':'31-33','friendly_name':'Manufacturing','count':0},
{'_id':'44-45','friendly_name':'Retail','count':0},
{'_id':'48-49','friendly_name':'Transportation','count':0}]
for eachIndustry in inArray:
if eachIndustry['_id'] in ['31','32','33']:
returnArray[0]['count'] += eachIndustry['count']
continue
if eachIndustry['_id'] in ['44','45']:
returnArray[1]['count'] += eachIndustry['count']
continue
if eachIndustry['_id'] in ['48','49']:
returnArray[2]['count'] += eachIndustry['count']
continue
try:
eachIndustry['friendly_name'] = apiconstants.industry_remap[eachIndustry['_id']]
returnArray.append(eachIndustry)
except:
eachIndustry['friendly_name'] = 'Error'
returnArray.append(eachIndustry)
returnArray = sorted(returnArray,key=itemgetter('count'),reverse=True)
return returnArray
@krmaxwell

Copy link
Copy Markdown

You'll need to add that to your import call, naturally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment