Loading

Paste #pwiavkdhb

  1.     def industries_using_cargo(self, cargo):
  2.         # segmented by economy
  3.         result = {}
  4.         for economy in self.get_economies_sorted_by_name():
  5.             accepted_by = self.industry_find_industries_active_in_economy_for_cargo(cargo, economy, 'accept_cargo_types')
  6.             produced_by = self.industry_find_industries_active_in_economy_for_cargo(cargo, economy, 'prod_cargo_types')
  7.             if len(list(accepted_by) + list(produced_by)) > 0:
  8.                 result[economy] = {'accepted_by':accepted_by, 'produced_by':produced_by}
  9.         return result
  10.  
  11.     def cargo_unique_industry_combinations(self, cargo):
  12.         result = {}
  13.         for economy in self.get_economies_sorted_by_name():
  14.             economy_industries = []
  15.             accepted_by = self.industry_find_industries_active_in_economy_for_cargo(cargo, economy, 'accept_cargo_types')
  16.             produced_by = self.industry_find_industries_active_in_economy_for_cargo(cargo, economy, 'prod_cargo_types')
  17.             for industry in accepted_by:
  18.                 economy_industries.append(industry)
  19.             for industry in produced_by:
  20.                 economy_industries.append(industry)
  21.             if len(economy_industries) > 0:
  22.                 industry_key = tuple(sorted(economy_industries))
  23.                 result.setdefault(industry_key, {'accepted_by': accepted_by, 'produced_by': produced_by})
  24.                 result[industry_key].setdefault('economies',[]).append(economy)
  25.                  # convenient to have items sorted
  26.                 result[industry_key]['economies'] = sorted(result[industry_key]['economies'], key=lambda economy: self.get_economy_name(economy))
  27.         # return a list, sorted by economies (only need first economy entry in each list of economies)
  28.         return sorted(result.values(), key = lambda combo: self.get_economy_name(combo['economies'][0]))

Comments