Exemple #1
0
    def post_process_one(self, m, search_name, get_details=False, force=False):
        house_details = None
        if get_details:
            house_details = self.rfapi.get_house_details(m,
                                                         force=force,
                                                         cache_time_format="")

        #logging.debug("post_process(get_details={})=>{}".format(get_details, house_details))
        RFAPI.generate_url_for_house(m)
        ha = RFAPI.house_address_parts(m)
        scores = None
        try:
            scores = self.get_scores(m, house_details)
        except:
            logging.error("house : {}, throw {}".format(
                json.dumps(m), traceback.format_exc()))
        if scores is None:
            return m

        m['scores'] = scores
        is_good, message = HouseScore.get_house_score_message(m)

        if is_good:
            if house_details is None:
                house_details = self.rfapi.get_house_details(
                    m, force=force, cache_time_format="")
                scores = self.get_scores(m, house_details)
            house_neighborhoods = RFAPI.house_neighborhoods(m, house_details)
            m['scores'] = scores
            is_good, message = HouseScore.get_house_score_message(m)

            logging.info(message)
            # getting city data takes a long time, will do it only for winning houses!
            """
            self.city_data.get_data(
                house_address= ha['display']
                , city=ha['city']     # Everett
                , state_short=ha['state']
                , zip_code=ha['zip']
                , house_neighborhoods=house_neighborhoods
                , force=force)
            """
        else:
            logging.debug(message)

        return m
Exemple #2
0
    def get_scores(self, house, details=None):
        scores = {}
        total_score = 0.0
        for k in self.default_fields:
            if k == "value": continue
            method = getattr(self, k, None)
            if method is None: continue
            result = method(house, details)
            scores[k] = dict(**result._asdict())
            total_score += result.money
            if not result.accepted:
                scores["cutoff"] = ",".join(
                    filter(None, [scores.get("cutoff"), k]))

        # value evaluation must be run last
        result = self.value(house, details, total_score)
        scores["value"] = dict(**result._asdict())
        if not result.accepted:
            scores["cutoff"] = ",".join(
                filter(None, [scores.get("cutoff"), "value"]))

        scores["facts"] = {
            "build":
            house.get("year_built", -1),
            "full_address":
            RFAPI.house_address(house),
            "beds":
            house["beds"],
            "sqft":
            house["sqft"] if house.get("sqft") is not None else 0.0,
            "baths":
            house.get("baths", 0),
            "price":
            house["price"],
            "County":
            RFAPI.house_county(house, details),
            "photo":
            RFAPI.house_photo_url(house, details),
            "neighborhoods":
            RFAPI.house_neighborhoods(house, details)
            if details is not None else []
        }
        return scores