Exemplo n.º 1
0
def choose_candidate(candidates, mgras, product_type_labels, max_units):
    # Filter
    filtered = apply_filters(candidates, product_type_labels)
    if len(filtered) < 1:
        print('out of suitable mgras for product type {}'.format(
            product_type_labels.product_type))
        print('evaluate filtering methods...\nexiting')
        return None

    # !
    # save_to_file(filtered, 'data/output', 'filtered_candidates.csv')
    # return

    # Sample
    weights = combine_weights(filtered.profit_margin, filtered.vacancy_cap)
    selected_candidate = filtered.sample(n=1, weights=weights)

    buildable_count = buildable_units(selected_candidate, product_type_labels,
                                      max_units)

    # develop buildable_count units by updating the MGRA in the original
    # dataframe
    removed_units_reference = update_mgra(mgras,
                                          selected_candidate,
                                          buildable_count,
                                          product_type_labels,
                                          scheduled_development=False)

    return mgras, buildable_count, removed_units_reference
Exemplo n.º 2
0
 def test_update_mgra(self):
     # print(self.test_mgras.iloc[1223, :])
     random_mgra = self.test_mgras.sample(random_state=19)
     self.assertIsNone(
         update_mgra(self.test_mgras,
                     random_mgra,
                     10,
                     self.product_type_labels,
                     scheduled_development=False))
Exemplo n.º 3
0
 def test_update_mgra(self):
     random_mgra = self.test_mgras.sample(random_state=19)
     self.assertIsNone(
         update_mgra(self.test_mgras,
                     random_mgra,
                     10,
                     self.product_type_labels,
                     scheduled_development=False))
     for label in self.vacant_labels:
         self.assertFalse(any(self.test_mgras[label] < 0))
Exemplo n.º 4
0
def add_to_mgra(mgras, site):
    '''
        mgras: the dataframe to update.
        site: expects a dataframe with one entry, including columns for MGRAID
        and the number of units to add
    '''
    mgra_id = site.MGRA.item()
    single_family_units = site.sfu.item()
    multi_family_units = site.mfu.item()
    employment_units = site.civEmp.item()

    if single_family_units > 0:
        # add single family units
        labels = ProductTypeLabels(SINGLE_FAMILY)
        update_mgra(mgras, mgra_id, single_family_units, labels)
        reduce_demand(labels.product_type, single_family_units)
    if multi_family_units > 0:
        # add multifamily units
        labels = ProductTypeLabels(MULTI_FAMILY)
        update_mgra(mgras, mgra_id, multi_family_units, labels)
        reduce_demand(labels.product_type, multi_family_units)
    if employment_units > 0:
        # add employment; determine which type to add
        mgra = mgras.loc[mgras[mgra_labels.MGRA] == mgra_id]
        labels = find_current_employment_type(mgras, mgra)
        update_mgra(mgras, mgra_id, employment_units, labels)

        reduce_demand(labels.product_type, employment_units)

    return
Exemplo n.º 5
0
def choose_candidate(candidates, mgras, product_type_labels, max_units):
    selected_candidate = candidates.select_candidate_for_product_type(
        product_type_labels.product_type)
    if selected_candidate is None:
        logging.error(
            'out of suitable mgra candidates for product type {}'.format(
                product_type_labels.product_type))
        logging.error('evaluate input data and/or filtering methods...')
        logging.error('setting remaining demand for {} to zero'.format(
            product_type_labels.product_type))
        return None, None
    logging.debug('selected candidate: {}'.format(selected_candidate))
    buildable_count = buildable_units(
        selected_candidate, product_type_labels, max_units)
    if buildable_count < 1:
        return 0, None
    # develop buildable_count units on the selected MGRA by updating it in the
    # original dataframe
    removed_units_reference = update_mgra(
        mgras, selected_candidate,
        buildable_count, product_type_labels,
        scheduled_development=False, candidates=candidates.candidates)

    return buildable_count, removed_units_reference