Esempio n. 1
0
    def analyze(self, extracts: Iterable[Tuple[str, Any]]) -> None:
        for company_id, company in extracts:
            zip_code = composites.get_property(company, self.source_zip_var)
            city = composites.get_property(company, self.source_city_var)
            state = composites.get_property(company, self.source_state_var)

            # Create a transient composite for the city. It will be processed into its final form in emit().
            if zip_code not in self.city_data:
                self.city_data[zip_code] = {
                    'invariant': {
                        "zip": zip_code,
                        "city": city,
                        "state": state
                    }
                }

            for period in composites.get_periods(company):
                if period not in self.city_data[zip_code]:
                    self.city_data[zip_code][period] = {
                        "n_companies": 0,
                        "tot_employees": 0,
                        "tot_revenue": 0.0
                    }

                p_dict = self.city_data[zip_code][period]
                p_dict["n_companies"] += 1
                p_dict["tot_employees"] += composites.get_observation(
                    company, period, self.n_employee_var)
                p_dict["tot_revenue"] += composites.get_observation(
                    company, period, self.revenue_var)
Esempio n. 2
0
 def __call__(self, composite: Dict):
     h_squared = composites.get_property(composite, self.height_var)**2
     for period, weight in composites.get_all_observations(
             composite, self.annual_weight_var):
         bmi = weight / h_squared * 703
         composites.put_observation(composite, period, self.annual_bmi_var,
                                    bmi)
Esempio n. 3
0
    def __call__(self, composite: Dict):
        zip_code: str = composites.get_property(composite, self.zip_var)

        city = self.lookups["zipcodes"][zip_code]["City"]
        composites.put_property(composite, self.city_var, city)

        state = self.lookups["zipcodes"][zip_code]["State"]
        composites.put_property(composite, self.state_var, state)
Esempio n. 4
0
 def get_rows(self, composite_id, composite):
     if self.invariant:
         data = {
             name: get_property(composite, var)
             for name, var in self.column_vars.items()
         }
         data['composite_id'] = composite_id
         yield [data]
     else:
         for period, value in composite.items():
             if period.isdigit():
                 row = {}
                 row['composite_id'] = composite_id
                 row['period'] = period
                 for name, var in self.column_vars.items():
                     row[name] = get_observation(composite, period, var,
                                                 True)
                 yield row
Esempio n. 5
0
 def passes(self, composite: Dict) -> bool:
     male: bool = composites.get_property(composite, self.male_flag)
     return not male
Esempio n. 6
0
 def extract(self, composite: Dict) -> Tuple[bool, float]:
     mean_bmi = composites.get_property(composite, self.mean_bmi_var)
     is_male = composites.get_property(composite, self.male_flag)
     return is_male, mean_bmi
Esempio n. 7
0
 def extract(self, composite: Dict) -> float:
     mean_bmi = composites.get_property(composite, self.mean_bmi_var)
     return mean_bmi