def test_get_variableunit():
    """py.test for get_variablename"""
    data = (("./eplussql_test/eplussql.sql", 6, "C"),)  # fname, ReportVariableDataDictionaryIndex, unit
    for fname, ReportVariableDataDictionaryIndex, unit in data:
        cursor = eplussql.getcursor(fname)
        result = eplussql.get_variableunit(cursor, ReportVariableDataDictionaryIndex)
        assert result == unit
def comfort_headers(cursor, dbtId, tzoneId):
    """get the comfort matrix headers"""
    dbts = eplussql.get_variablename(cursor, dbtId)
    tzones = eplussql.get_variablename(cursor, tzoneId)
    unit = eplussql.get_variableunit(cursor, dbtId)
    header = [[dbts, tzones, 'tavgs', 'comfs', 'diffs'], [unit,] * 5]
    return header
def getabovedays(fname, varindex, aboveval, year=2001, convertc2f=False):
    """return variable name, max and min of the variable"""
    cursor = eplussql.getcursor(fname)
    # startpoint = eplussql.get_wfilestart(cursor)
    varunit = eplussql.get_variableunit(cursor, varindex) # var units
    varname = eplussql.get_variablename(cursor, varindex) # varname
    keyvalue = eplussql.get_keyvalue(cursor, varindex) # get keyvalue
    if convertc2f and varunit == u'C': # conversion
        func = eplussql.c2f
        varunit = u'F'
    else:
        func = None
    matrix = eplussql.get_variables(cursor, varindex, func=func) # gets vars
    yhours = date_functions.yeardateshours(year) # yeardates
    matrix = zip(yhours, matrix)
    # days = split2days(matrix, hrs=24) # splits it into 24 hr blocks
    # filtering of days take place below
    # daysabove = filterdaysabove(days, aboveval)
    daysabove = date_functions.filterdays(matrix, -1, aboveval,
                                        date_functions.gt, hrs=24)
    return varname, keyvalue, varunit, daysabove
    
# fname = './eplussql_test/hup01_23_pytest.sql'
# varname, keyvalue, varunit, daysabove = getabovedays(fname, 386, 88, convertc2f=True)
# for day in daysabove:
#     for d, val in day:
#         print '%s, %s' % (d, val)
예제 #4
0
def getmaxmin(fname, varindex, convertc2f=False):
    """return variable name, max and min of the variable"""
    cursor = eplussql.getcursor(fname)
    # startpoint = eplussql.get_wfilestart(cursor)
    varunit = eplussql.get_variableunit(cursor, varindex)
    if convertc2f and varunit == u"C":
        func = eplussql.c2f
        varunit = u"F"
    else:
        func = None
    matrix = eplussql.get_variables(cursor, varindex, func=func)
    varname = eplussql.get_variablename(cursor, varindex)
    keyvalue = eplussql.get_keyvalue(cursor, varindex)
    return varname, keyvalue, varunit, min(matrix), max(matrix)
def getabove(fname, varindex, aboveval, convertc2f=False):
    """return variable name, max and min of the variable"""# TODO incorrect __doc__
    cursor = eplussql.getcursor(fname)
    # startpoint = eplussql.get_wfilestart(cursor)
    varunit = eplussql.get_variableunit(cursor, varindex)
    if convertc2f and varunit == u'C':
        func = eplussql.c2f
        varunit = u'F'
    else:
        func = None
    matrix = eplussql.get_variables(cursor, varindex, func=func)
    varname = eplussql.get_variablename(cursor, varindex)
    keyvalue = eplussql.get_keyvalue(cursor, varindex)
    abovenums = [val for val in matrix if val > aboveval]
    return varname, keyvalue, varunit, len(abovenums)
예제 #6
0
def vars2csv(fname, variables, convertc2f=False):
    """print the vars in csvformat"""
    matrix = []
    cursor = eplussql.getcursor(fname)
    for varindex in variables:
        varunit = eplussql.get_variableunit(cursor, varindex)
        if varunit == u'C' and convertc2f:
            func = eplussql.c2f
            varunit = u'F'
        else:
            func = None
        varlist = eplussql.get_variables(cursor, varindex, func=func)
        varname = eplussql.get_variablename(cursor, varindex)
        varkeyvalue = eplussql.get_keyvalue(cursor, varindex)
        headerandlist = [varname] + [varkeyvalue] + [varunit] + varlist
        matrix.append(headerandlist)

    matrix = mycsv.transpose2d(matrix)
    for row in matrix:
        row = [str(item) for item in row]
        print ','.join(row)
def comfort_headers(cursor, tzoneId):
    """get the comfort matrix headers"""
    tzones = eplussql.get_variablename(cursor, tzoneId)
    unit = eplussql.get_variableunit(cursor, tzoneId)
    header = [["ET*", tzones, "tavgs", "comfs", "diffs"], [unit] * 5]
    return header