Exemplo n.º 1
0
def get_default_surface_areas(settings, construction_number, surface_area,
                              floor_area):

    params = (
        construction_number,
        floor_area,
    )
    SQL = ''
    if surface_area == 'supply':
        SQL = """SELECT floor_area, supply FROM duct_load_default_surface_area WHERE construction_number = ? AND floor_area <= ? ORDER BY floor_area DESC LIMIT 1"""
    else:
        SQL = """SELECT floor_area, return FROM duct_load_default_surface_area WHERE construction_number = ? AND floor_area <= ? ORDER BY floor_area DESC LIMIT 1"""
    #endif
    SQL_vars = params
    lower_results = do_query(settings, SQL, SQL_vars)

    lower_info = []
    if len(lower_results) < 1:
        print("ERROR")
        lower_info = 'skip'
        sys.exit()
    else:
        lower_info = lower_results[0]
    #endif

    if surface_area == 'supply':
        SQL = """SELECT floor_area, supply FROM duct_load_default_surface_area WHERE construction_number = ? AND floor_area >= ? ORDER BY floor_area ASC LIMIT 1"""
    else:
        SQL = """SELECT floor_area, return FROM duct_load_default_surface_area WHERE construction_number = ? AND floor_area >= ? ORDER BY floor_area ASC LIMIT 1"""
    #endif
    upper_results = do_query(settings, SQL, SQL_vars)
    upper_info = []
    if len(upper_results) < 1:
        print("ERROR")
        upper_info = 'skip'
        sys.exit()
    else:
        upper_info = upper_results[0]
    #endif

    f_lower = lower_info[0]
    f_upper = upper_info[0]
    sa_lower = lower_info[1]
    sa_upper = upper_info[1]
    sa_interp = interpolate_val(sa_lower, sa_upper, f_lower, f_upper,
                                floor_area)

    return sa_interp
Exemplo n.º 2
0
def get_latent_gain_factor(settings, value, results):
    params = (
        results['construction_number'],
        results['grains_diff'],
        results['floor_area_cooling'],
    )
    SQL = ''
    #lower(upper)area_lower(upper)temp
    if value == "la_lt":
        SQL = """SELECT blg, floor_area, grains FROM duct_load_blg WHERE construction_number = ? AND grains <= ? AND floor_area <= ? ORDER BY grains DESC , floor_area DESC LIMIT 1"""
    elif value == "ua_lt":
        SQL = """SELECT blg, floor_area, grains FROM duct_load_blg WHERE construction_number = ? AND grains <= ? AND ? <= floor_area  ORDER BY grains DESC, floor_area ASC LIMIT 1"""
    elif value == "la_ut":
        SQL = """SELECT blg, floor_area, grains FROM duct_load_blg WHERE construction_number = ? AND grains >= ? AND floor_area <= ? ORDER BY grains DESC, floor_area ASC LIMIT 1"""
    elif value == "ua_ut":
        SQL = """SELECT blg, floor_area, grains FROM duct_load_blg WHERE construction_number = ? AND grains >= ? AND ? <= floor_area  ORDER BY grains DESC, floor_area ASC LIMIT 1"""
    #endif
    SQL_vars = params
    results = do_query(settings, SQL, SQL_vars)

    #print results

    info = []
    if len(results) < 1:
        print("ERROR")
        info = 'skip'
    else:
        info = results[0]
        #print "results: " + value
        #print results
    #endif

    return info
Exemplo n.º 3
0
def get_htm_cooling(construction_num, internal_shade, num_panes_thick,
                    direction, ctd, settings):

    rounded_ctd = round_ctd(
        ctd)  #for table 3 lookup, maybe should interpolate instead...

    glass_type = construction_num.split('-')[1]
    dire = get_dir(direction)

    SQL_vars = (
        glass_type,
        internal_shade,
        str(num_panes_thick),
        dire,
        rounded_ctd,
    )
    SQL = ''
    SQL = """SELECT htm FROM cooling_htm WHERE glass_type = ? AND shade = ? AND num_panes_thick = ? AND direction = ? AND ctd = ?"""
    results = do_query(settings, SQL, SQL_vars)

    if len(results) < 1:
        print("htm_cooling query not found - come check the database")
        sys.exit()
    #endif
    htm_res = results[0]
    htm = htm_res[0]

    return htm
Exemplo n.º 4
0
def get_sensible_gain_factor(settings, value, results):
    params = (
        results['construction_number'],
        results['outdoor_1per_db'],
        results['floor_area_cooling'],
    )
    SQL = ''
    #lower(upper)area_lower(upper)temp
    if value == "la_lt":
        SQL = """SELECT bsgf, floor_area, oat FROM duct_load_bsgf WHERE construction_number = ? AND oat <= ? AND floor_area <= ? ORDER BY oat DESC , floor_area DESC LIMIT 1"""
    elif value == "ua_lt":
        SQL = """SELECT bsgf, floor_area, oat FROM duct_load_bsgf WHERE construction_number = ? AND oat <= ? AND ? <= floor_area  ORDER BY oat DESC, floor_area ASC LIMIT 1"""
    elif value == "la_ut":
        SQL = """SELECT bsgf, floor_area, oat FROM duct_load_bsgf WHERE construction_number = ? AND oat >= ? AND floor_area <= ? ORDER BY oat DESC, floor_area ASC LIMIT 1"""
    elif value == "ua_ut":
        SQL = """SELECT bsgf, floor_area, oat FROM duct_load_bsgf WHERE construction_number = ? AND oat >= ? AND ? <= floor_area  ORDER BY oat DESC, floor_area ASC LIMIT 1"""
    #endif
    SQL_vars = params
    results = do_query(settings, SQL, SQL_vars)

    #print results

    info = []
    if len(results) < 1:
        print("ERROR")
        info = 'skip'
    else:
        info = results[0]
        #print "results: " + value
        #print results
    #endif

    return info
Exemplo n.º 5
0
def get_leakage_factor(settings, ctype, results):
    leakage = str(results['leakage_supply']) + '/' + str(
        results['leakage_return'])

    params = (
        results['construction_number'],
        leakage,
        results['rval'],
    )
    SQL = ''
    #lower(upper)area_lower(upper)temp
    if ctype == "heat_loss":
        SQL = """SELECT heat_loss_correction FROM duct_load_leakage WHERE construction_number = ? AND leakage = ? AND rval = ? """
    elif ctype == "sensible":
        SQL = """SELECT sensible_correction FROM duct_load_leakage WHERE construction_number = ? AND leakage = ? AND rval = ? """
    elif ctype == "latent":
        SQL = """SELECT latent_correction FROM duct_load_leakage WHERE construction_number = ? AND leakage = ? AND rval = ? """
    #endif
    SQL_vars = params
    results = do_query(settings, SQL, SQL_vars)

    #print results
    val = get_query_aux(results)

    return val
Exemplo n.º 6
0
def get_ends(settings, table, col, col_val, col2='', col2_val=''):
    SQL_vars = (col_val, )
    #get hi
    if col2 == '':
        SQL = """SELECT DISTINCT {col} FROM {table} WHERE {col} >= ? ORDER BY {col} ASC;"""
        SQL = SQL.format(col=col, table=table)
    else:
        SQL = """SELECT DISTINCT {col} FROM {table} WHERE {col} >= ? AND {col2} = {col2_val} ORDER BY {col} ASC;"""
        SQL = SQL.format(col=col, table=table, col2=col2, col2_val=col2_val)
    #endif

    results = do_query(settings, SQL, SQL_vars)
    #print "*" * 22

    #print col_val
    #print SQL
    #print results

    [hi_col1, hi_col2] = get_n_results(results, 2)
    hi_col = hi_col1

    #get low
    if col2 == '':
        SQL = """SELECT DISTINCT {col} FROM {table} WHERE {col} <= ? ORDER BY {col} DESC;"""
        SQL = SQL.format(col=col, table=table)
    else:
        SQL = """SELECT DISTINCT {col} FROM {table} WHERE {col} <= ? AND {col2} = {col2_val} ORDER BY {col} DESC;"""
        SQL = SQL.format(col=col, table=table, col2=col2, col2_val=col2_val)
    #endif
    results = do_query(settings, SQL, SQL_vars)
    #print results
    [low_col1, low_col2] = get_n_results(results, 2)
    low_col = low_col1

    #print hi_col2, hi_col1, col_val, low_col1, low_col2
    #print "*" * 22

    if hi_col1 == 999999:
        hi_col = low_col1
        low_col = low_col2
    elif low_col1 == 999999:
        hi_col = hi_col2
        low_col = hi_col1
    #endif
    return [hi_col, low_col]
Exemplo n.º 7
0
def interpolate_three_get_d(settings, SQL, col1_val, col2_val, col3_val,
                            col4_val):
    if col4_val == '':
        SQL_vars = (col1_val, col2_val, col3_val)
    else:
        SQL_vars = (col1_val, col2_val, col3_val, col4_val)
    #endif
    results = do_query(settings, SQL, SQL_vars)
    [d] = get_n_results(results, 1)
    return d
Exemplo n.º 8
0
def get_fenestration_performance(settings, construction_number, frame_type):
    SQL = """SELECT u, shgc FROM fenestration_performance WHERE construction_number = ? AND frame_type = ?"""

    SQL_vars = (
        construction_number,
        frame_type,
    )
    results = do_query(settings, SQL, SQL_vars)

    return results[0]  #[u, shgc] = results[0]
Exemplo n.º 9
0
def get_ach(settings, ach_type, construction, floor_area):
    ach = 0

    SQL = """SELECT """ + ach_type + """ FROM air_change_value WHERE construction = ? AND floor_area <= ? ORDER BY floor_area DESC LIMIT 1"""
    #    print(SQL)
    SQL_vars = (construction, floor_area)

    results = hvac_database.do_query(settings, SQL, SQL_vars)
    ach_res = results[0]
    ach = ach_res[0]
    #    print(ach)
    return ach  #get from table 5A
Exemplo n.º 10
0
def get_luminaire_description(settings, luminaire_id):
    SQL = """SELECT description FROM luminaire_info WHERE luminaire_id = ?"""
    SQL_vars = (luminaire_id, )
    results = do_query(settings, SQL, SQL_vars)

    description = ""
    if len(results) < 1:
        msg = "ERROR - description not found for " + luminaire_id
        exit()
    else:
        (description, ) = results[0]
    #endif

    return description
Exemplo n.º 11
0
def get_max_s_h(settings, luminaire_id):
    SQL = """SELECT max_s_mh FROM luminaire_info WHERE luminaire_id = ?"""
    SQL_vars = (luminaire_id, )
    results = do_query(settings, SQL, SQL_vars)

    max_s_mh = 1
    if len(results) < 1:
        msg = "ERROR - max_s_mh not found for " + luminaire_id
        exit()
    else:
        (max_s_mh, ) = results[0]
    #endif

    return max_s_mh
Exemplo n.º 12
0
def get_fireplace_cfm(settings, num_fireplaces, construction):
    SQL = """SELECT infiltration FROM fireplace_infiltration WHERE construction = ?"""
    SQL_vars = (construction, )

    results = hvac_database.do_query(settings, SQL, SQL_vars)
    cfm_res = results[0]
    cfm = cfm_res[0]

    if num_fireplaces == 2:
        cfm = cfm + 7
    elif num_fireplaces > 2:
        cfm = cfm + 10
    #endif

    return cfm
Exemplo n.º 13
0
def get_surface_area_factor(settings, construction_number, leakage_type,
                            leakage):
    params = (
        construction_number,
        leakage_type,
        leakage,
    )
    SQL = """SELECT k FROM duct_load_surface_area_factors WHERE construction_number = ? AND leakage_type = ? AND leakage = ? """
    SQL_vars = params
    results = do_query(settings, SQL, SQL_vars)

    #print results
    k = get_query_aux(results)

    return k
Exemplo n.º 14
0
def get_u_val(settings, construction_number):
    #    print(construction_number)

    SQL = """SELECT u_val, group_num FROM opaque_panel_performance_u WHERE construction_number = ?"""

    SQL_vars = (construction_number, )
    results = hvac_database.do_query(settings, SQL, SQL_vars)
    #print(results)

    if len(results) < 1:
        print("none found, come update u_val table")
        sys.exit()
    else:
        u_val_res = results[0]
    #endif
    return u_val_res
Exemplo n.º 15
0
def get_cltd(settings, group_num, rounded_ctd, daily_range, panel_subtype):
    print(group_num, rounded_ctd, daily_range, panel_subtype)
    #input("x")
    #sys.exit()
    if panel_subtype == 'partition':
        SQL = """SELECT cltd FROM opaque_panel_performance_cltd WHERE group_num = ? AND ctd = ? AND daily_range = ? AND construction_number = 'partition'"""
        SQL_vars = (
            group_num,
            rounded_ctd,
            daily_range,
        )
    elif len(
            panel_subtype
    ) > 0:  #has something other than partition - like above_grade or below_grade
        SQL = """SELECT cltd FROM opaque_panel_performance_cltd WHERE group_num = ? AND ctd = ? AND daily_range = ? AND (construction_number = 'wall' OR construction_number = '22')"""
        SQL_vars = (
            group_num,
            rounded_ctd,
            daily_range,
        )
    else:
        SQL = """SELECT cltd FROM opaque_panel_performance_cltd WHERE group_num = ? AND ctd = ? AND daily_range = ?"""
        SQL_vars = (
            group_num,
            rounded_ctd,
            daily_range,
        )
    #endif

    results = hvac_database.do_query(settings, SQL, SQL_vars)
    #print SQL, SQL_vars
    #for res in results:
    #    print res

    cltd = 44444
    if len(results) < 1:
        print("none found, come update cltd table")
    elif len(results) > 1:
        print("too many found, come update query")
    else:
        cltd_res = results[0]
        cltd = cltd_res[0]
    #endif
    #print cltd
    return cltd
Exemplo n.º 16
0
def get_slm(settings, latitude, direction):

    SQL = """SELECT slm FROM latitude_slm WHERE north_latitude = ? AND direction = ?"""

    n_lat = round_ctd(latitude)
    dir = get_dir(direction)

    SQL_vars = (
        n_lat,
        dir,
    )
    results = do_query(settings, SQL, SQL_vars)
    slm_res = results[0]
    slm = slm_res[0]

    #there should only be one

    return slm
Exemplo n.º 17
0
def get_ldd_consts(settings, luminaire_id, dirtiness):
    SQL = """SELECT a, b FROM luminaire_info INNER JOIN ldd ON luminaire_info.maint_cat = ldd.maint_cat WHERE luminaire_id = ? AND dirtiness = ?"""
    SQL_vars = (
        luminaire_id,
        dirtiness,
    )
    results = do_query(settings, SQL, SQL_vars)

    A = 1
    B = 1

    if len(results) < 1:
        msg = "ERROR - ldd constants not found for luminaire id" + luminaire_id
        exit()
    else:
        (A, B) = results[0]
    #endif

    return [A, B]
Exemplo n.º 18
0
def get_rval_correction(settings, ctype, results):
    params = (
        results['construction_number'],
        results['rval'],
    )
    SQL = ''
    #lower(upper)area_lower(upper)temp
    if ctype == "bhlf":
        SQL = """SELECT bhlf_correction FROM duct_load_rval_correction WHERE construction_number = ? AND rval = ? """
    elif ctype == "bsgf":
        SQL = """SELECT bsgf_correction FROM duct_load_rval_correction WHERE construction_number = ? AND rval = ? """
    #endif
    SQL_vars = params
    results = do_query(settings, SQL, SQL_vars)

    #print results
    rval = get_query_aux(results)

    return rval
Exemplo n.º 19
0
def get_ptdh(settings, construction_number, rounded_htd):
    print(construction_number, rounded_htd)
    SQL = """SELECT ptdh FROM opaque_panel_performance_ptdh WHERE construction_number = ? AND htd = ?"""
    SQL_vars = (construction_number, rounded_htd)

    results = hvac_database.do_query(settings, SQL, SQL_vars)

    ptdh = 77777
    if len(results) < 1:
        print("none found, come update ptdh table")
        sys.exit()
    elif len(results) > 1:
        print("too many found, come update query")
        sys.exit()
    else:
        ptdh_res = results[0]
        ptdh = ptdh_res[0]
    #endif

    return ptdh
Exemplo n.º 20
0
def get_cltd_4a(settings, group_num, ctd, daily_range):
    SQL = """SELECT cltd FROM opaque_panel_performance_cltd WHERE group_num = ? AND ctd = ? AND daily_range = ?"""
    SQL_vars = (
        group_num,
        ctd,
        daily_range,
    )

    results = hvac_database.do_query(settings, SQL, SQL_vars)

    cltd = 44444
    if len(results) < 1:
        print("none found, come update cltd table - cltd_4a")
        sys.exit()
    elif len(results) > 1:
        print("too many found, come update query - cltd_4a")
        sys.exit()
    else:
        cltd_res = results[0]
        cltd = cltd_res[0]
    #endif
    return cltd
Exemplo n.º 21
0
def get_lighting_type(settings, luminaire_id):
    SQL = """SELECT percent_lumens_up,percent_lumens_down FROM luminaire_info WHERE luminaire_id = ?"""
    SQL_vars = (luminaire_id, )
    results = do_query(settings, SQL, SQL_vars)

    if len(results) < 1:
        msg = "ERROR - description not found for " + luminaire_id
        exit()
    else:
        (
            up,
            down,
        ) = results[0]
    #endif

    if up + down != 100:
        both = (up + down)
        up = 100 * up / both
        down = 100 * down / both
    #endif

    lighting_type = ""
    if (90 <= down <= 100 or 0 <= up <= 10):
        lighting_type = "direct"
    elif (60 <= down <= 90 or 10 <= up <= 40):
        lighting_type = "semi-direct"
    elif (40 <= down <= 60 or 40 <= up <= 60):
        lighting_type = "general-diffuse"
#    elif(40 <= down <= 60 or 40 <= up <= 60): #special (non-CIE) cat within the classification see 10-12
#        lighting_type = "direct-indirect"
    elif (10 <= down <= 40 or 60 <= up <= 90):
        lighting_type = "semi-indirect"
    elif (0 <= down <= 10 or 90 <= up <= 100):
        lighting_type = "indirect"

    return lighting_type
Exemplo n.º 22
0
def get_altitude_info_aux(settings, value, elevation):
    SQL = ''
    extrapolate_dir = ''
    if value == "lower":
        SQL = """SELECT altitude, acf, lbpercf FROM altitude_info WHERE altitude <= ? ORDER BY altitude DESC LIMIT 1"""
        extrapolate_dir = 'backward'
        elevation_adjust = -1000
    elif value == "upper":
        SQL = """SELECT altitude, acf, lbpercf FROM altitude_info WHERE ? <= altitude ORDER BY altitude ASC LIMIT 1"""
        extrapolate_dir = 'forward'
        elevation_adjust = 1000
    #endif
    SQL_vars = (elevation, )
    results = hvac_database.do_query(settings, SQL, SQL_vars)

    altitude_info = []
    if len(results) < 1:
        msg = "WARNING - have to extrapolate " + extrapolate_dir + " to determine values at elevation: " + str(
            elevation)
        print(msg)
        altitude_info = ['extrapolate', (0, 0, 0)]
    else:
        res = results[0]
        for v in results[0]:
            if v == '':  #meaning value not in database (will only work if missing y-val: acf or air_den)
                adj_altitude_info = get_altitude_info_aux(
                    settings, value, elevation + elevation_adjust)
                res = adj_altitude_info[1]
            #endif
        #endfor

        altitude_info = ['interpolate', res]

    #endif

    return altitude_info
Exemplo n.º 23
0
def worksheet_a(settings, project):
    project_name = project.get('Location', 'project_name')
    state = project.get('Location', 'design_state')
    city = project.get('Location', 'design_city')

    SQL = """SELECT elevation, latitude, heating_99per_db, cooling_1per_db, concident_wb, \
                    design_grains_55per_rh, design_grains_50per_rh, design_grains_45per_rh, \
                    daily_range \
             FROM outdoor_design_cond WHERE state = ? AND city = ?"""
    SQL_vars = (
        state,
        city,
    )
    results = hvac_database.do_query(settings, SQL, SQL_vars)

    outdoor_design_cond = results[0]
    elevation = outdoor_design_cond[0]
    latitude = outdoor_design_cond[1]
    outdoor_99per_db = outdoor_design_cond[2]
    outdoor_1per_db = outdoor_design_cond[3]
    concident_wb = outdoor_design_cond[4]
    design_grains_55per_rh = outdoor_design_cond[5]
    design_grains_50per_rh = outdoor_design_cond[6]
    design_grains_45per_rh = outdoor_design_cond[7]
    daily_range = outdoor_design_cond[8]

    #TODO
    #use project address to lookup and see if the defaults are superceded by local code

    #Indoor Design Parameters for Cooling (maybe get from settings file) - use these unless superceded by local code
    #see fig3-1 p15
    indoor_cooling_db = 75

    #use design address to check to see/calculate if in wet-coil or dry-coil climate
    #maybe move this above to get only 1 design_grains...
    coil_climate = get_coil_climate(state, city)
    indoor_cooling_rh, grains_diff = get_humidity_info(coil_climate,
                                                       design_grains_55per_rh,
                                                       design_grains_50per_rh,
                                                       design_grains_45per_rh)

    #Indoor Design Parameters for Heating (maybe get from settings file) - use these unless superceded by local code
    #winter humidification is optional and the humidification level shall not cause visible or concealed condensation
    #see fig3-1 p15
    indoor_heating_db = 70
    indoor_heating_rh = ''

    #heating and cooling temperature difference
    htd = indoor_heating_db - outdoor_99per_db
    ctd = outdoor_1per_db - indoor_cooling_db

    #altitude correction
    acf, air_den = get_altitude_info(settings, elevation)

    results = {
        'project': project_name,
        'city': city,
        'state': state,
        'elevation': elevation,
        'latitude': latitude,
        'indoor_heating_db': indoor_heating_db,
        'indoor_heating_rh': indoor_heating_rh,
        'indoor_cooling_db': indoor_cooling_db,
        'indoor_cooling_rh': indoor_cooling_rh,
        'outdoor_99per_db': outdoor_99per_db,
        'outdoor_1per_db': outdoor_1per_db,
        'grains_diff': grains_diff,
        'daily_range': daily_range,
        'htd': htd,
        'ctd': ctd,
        'acf': acf,
        'air_den': air_den
    }

    output_worksheet_a(results)

    return results