예제 #1
0
 def __init__(self, tup_from_changes_tbl):
     tup = data_tools.tup_to_readable_tup(tup_from_changes_tbl)
     self.id = tup[0]
     self.category = tup[1]
     self.unit = tup[2]
     self.approved_state = tup[3]
     self.change_to_approved_state = tup[4]
     self.total_change = tup[5]
예제 #2
0
def draw_all_cats(db):
    crsr = db.cursor()
    crsr.execute("""SELECT category, unit
        FROM meirim.plan_area_changes
        GROUP BY category, unit""")
    tup_from_db = crsr.fetchall()
    cats_and_units = [
        data_tools.tup_to_readable_tup(tup) for tup in tup_from_db
    ]
    [draw_cat_unit(db, tup[0], tup[1]) for tup in cats_and_units]
예제 #3
0
def description_to_df():
    def first_index_of_detail(detail):
        """
        Should be use the wipe out the start of details like '1. we do stuff' or '2- another stuff'
        :return: index in detail where we should start slicing
        """
        def find_index_end_of_seif_number():
            has_seen_non_space = False
            for i, char in enumerate(detail[:-1]):
                if char != ' ':
                    has_seen_non_space = True
                if has_seen_non_space and (char == '-' or char == '.' or char == ' ') and \
                        (ord('9') < ord(detail[i+1]) or ord(detail[i+1]) < ord('0')):
                    return i + 1
            return None

        ind_end_seif = find_index_end_of_seif_number()
        if ind_end_seif is None:
            return 0
        prev_was_revah = False
        for val in detail[:ind_end_seif]:
            if prev_was_revah and ord('א') <= ord(val) <= ord('ת'):
                return 0
            if val == ' ':
                prev_was_revah = True
            else:
                prev_was_revah = False
        return ind_end_seif

    db = data_tools.get_db()
    details = data_tools.get_vals(
        db, ['PL_NUMBER', 'PL_NAME', 'main_details_from_mavat'])
    details = [data_tools.tup_to_readable_tup(tup) for tup in details]
    split_tups = []
    for tup in details:
        if tup[2] is None:
            continue
        split_details = tup[2].split('<br>')
        for detail in split_details:
            sliced_detail = detail[first_index_of_detail(detail):]
            stripped_detail = sliced_detail.strip()
            if stripped_detail == '':
                continue
            tup_to_insert = (tup[0], tup[1], stripped_detail)
            split_tups.append(tup_to_insert)
    return pd.DataFrame(split_tups, columns=['PL_NUMBER', 'PL_NAME', 'detail'])
예제 #4
0
 def __init__(self, db, tup_from_plans_tbl):
     tup = data_tools.tup_to_readable_tup(tup_from_plans_tbl)
     self.id = tup[0]
     self.sent = tup[1]
     self.object_id = tup[2]
     self.county = tup[3]
     self.pl_number = tup[4]
     self.url = tup[5]
     self.jurisdiction = tup[6]
     self.status = tup[7]
     self.polygon = wkt.loads(tup[8])
     plan_area_changes_clms = [
         'changeId', 'category', 'unit', 'approvedState',
         'changeToApprovedState', 'totalChange'
     ]
     tups_from_db = data_tools.get_conditional_vals(
         db, plan_area_changes_clms, 'planId = %s', (self.id, ),
         Plan.PLAN_AREA_CHANGES_TBL_NM)
     self.area_changes = [AreaChange(tp) for tp in tups_from_db]
예제 #5
0
    def __init__(self, db, all_plans):
        self.all_plans = all_plans
        crsr = db.cursor()
        crsr.execute("""
        SELECT category, unit, AVG(totalChange), STDDEV(totalChange)
        FROM meirim.plan_area_changes
        GROUP BY category, unit""")
        cat_in_ans, unit_in_ans, avg_in_ans, stdev_in_ans = 0, 1, 2, 3
        stats = crsr.fetchall()
        self.stats_dict = {}
        for fetched_tup in stats:
            tup = data_tools.tup_to_readable_tup(fetched_tup)
            key = tup[cat_in_ans] + ' ' + str(tup[unit_in_ans])  # Category + ' ' + unit. for example: מגורים יח"ד
            self.stats_dict[key] = StatisticsInfo(tup[avg_in_ans], tup[stdev_in_ans])

        self.samples_dict = {}
        for plan in all_plans:
            for area_change in plan.area_changes:
                key = area_change.category + ' ' + area_change.unit
                if key not in self.samples_dict:
                    self.samples_dict[key] = []
                self.samples_dict[key].append(area_change.total_change)