def describe(self, fh=sys.stdout): # Prepare string representation of stats stats = self.descriptive_stats() s = '' s += 'METADATA:\n' for key, value in self.metadata.iteritems(): s += ' {} = {}\n'.format(key, value) s += '\n' s += 'NUMBER OF BUILDINGS: {:d}\n\n'.format(len(self.buildings)) s += 'NUMBER OF APPLIANCES PER BUILDING:\n' s += summary_stats_string(stats['n_appliances']) s += '\n' s += 'PROPORTION OF ENERGY SUBMETERED PER BUILDLING:\n' s += summary_stats_string(stats['energy_submetered']) s += '\n' s += 'DROPOUT RATE PER CHANNEL, INCLUDING LARGE GAPS:\n' s += summary_stats_string(stats['dropout_rate']) s += '\n' s += 'DROPOUT RATE PER CHANNEL, IGNORING LARGE GAPS:\n' s += summary_stats_string(stats['dropout_rate_ignoring_gaps']) s += 'MAINS UPTIME PER BUILDING (DAYS):\n' s += summary_stats_string(stats['uptime']) s += '\n' s += 'PROPORTION OF TIME SLICES WHERE > 70% ENERGY IS SUBMETERED:\n' s += summary_stats_string(stats['prop_timeslices']) s += '\n' fh.write(s)
# dataset.buildings[2].utility.electric.appliances = ( # dataset.buildings[2].utility.electric.remove_channels_from_appliances( # ['modem_router'])) print('Calculating stats for', ds_name) ds_stats = dataset.descriptive_stats() for col_short, col_long in COLUMNS.iteritems(): if col_short in ['energy_submetered', 'proportion_up', 'dropout_rate_ignoring_gaps', 'prop_timeslices']: fmt = '{:>.0%}' else: fmt = '{:>.0f}' s = "" if len(dataset.buildings) > 1: s += summary_stats_string(ds_stats[col_short], sep=""", """, stat_strings=['min', 'median', 'max'], minimal=True, fmt=fmt).replace('%', '') else: s += fmt.format((ds_stats[col_short][0])) stats_df[col_long][ds_name] = s if OUTPUT_LATEX: print("------------LATEX BEGINS-----------------") latex = stats_df.to_latex() latex = latex.replace(' ', '') n_columns = len(COLUMNS) + 1 latex = latex.replace('l' * n_columns, 'c' * n_columns) for str_to_replace in ['midrule', 'toprule', 'bottomrule']: latex = latex.replace(str_to_replace, 'hline') print(latex) print("------------LATEX ENDS-------------------")