def get_manyvariables(cursor, ReportVariableDataDictionaryIndices, funcs=None): """get a matrix of variables listed in ReportVariableDataDictionaryIndices. Each column in the matrix will a different variable. Each variable can be modified by the corresponding func in cunction""" if funcs == None: funcs = [None] * len(ReportVariableDataDictionaryIndices) thevars = [] for ind, func in zip(ReportVariableDataDictionaryIndices, funcs): thevars.append(get_variables(cursor, ind, func)) return mycsv.transpose2d(thevars)
def comfort_matrix2(mat, comfunc, upspan=360, downspan=360, celsius=True): """do the comfort calcs on several rows""" tavgs = [] dbts = [dbt for dbt, tzone in mat] tzones = [tzone for dbt, tzone in mat] for i in range(len(mat)): tavgs.append(avg_around(i, dbts, upspan=upspan, downspan=downspan)) comfs = [comfunc(t, celsius=celsius) for t in tavgs] diffs = [c-t for t, c in zip(tzones, comfs)] outmat = [dbts] + [tzones] + [tavgs] + [comfs] + [diffs] return mycsv.transpose2d(outmat)
def test_get_manyvariables(): """py.test for get_manyvariables""" data = ( ("./eplussql_test/eplussql.sql", [6, 7], [None, None]), # fname, ReportVariableDataDictionaryIndices, funcs ) for fname, ReportVariableDataDictionaryIndices, funcs in data: cursor = eplussql.getcursor(fname) thevars = [] for ind, func in zip(ReportVariableDataDictionaryIndices, funcs): thevars.append(eplussql.get_variables(cursor, ind, func)) matrix = mycsv.transpose2d(thevars) result = eplussql.get_manyvariables(cursor, ReportVariableDataDictionaryIndices, funcs) assert result == matrix
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)