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)
def printvars(fname, ReportVariableDataDictionaryIndex, func=None, year=2001): """print the variables in csv format""" cursor = eplussql.getcursor(fname) varname = eplussql.get_variablename(cursor, ReportVariableDataDictionaryIndex) keyvalue = eplussql.get_keyvalue(cursor, ReportVariableDataDictionaryIndex) matrix = eplussql.get_variables(cursor, ReportVariableDataDictionaryIndex, func=func) yhours = date_functions.yeardateshours(year) outmat = [["datetime", varname]] + [["", keyvalue]] + zip(yhours, matrix) for row in outmat: print "%s, %s" % tuple(row)
def test_yeardateshours(): """py.test for yeardateshours""" data = ((2004, '2004-1-1 hr2:00', '2004-1-31 hr10:00', '2004-12-31 hr15:00', '2004-12-30 hr24:00'), # year, jan1h2, jan31h10, dec31h15, dec29h24 ) for year, jan1h2, jan31h10, dec31h15, dec29h24 in data: yd = date_functions.yeardateshours(year) assert yd[0 + 2 - 1] == jan1h2 assert yd[30 * 24 + 10 - 1] == jan31h10 assert yd[-1 * 24 + 15 - 1] == dec31h15 assert yd[-2 * 24 + 24 - 1] == dec29h24