Make some methods private

This commit is contained in:
Jose Gracia 2024-02-22 11:35:57 +01:00
parent 2436928e7a
commit bc6a5a3018

View file

@ -74,7 +74,7 @@ class Power:
self.by_node = by_node self.by_node = by_node
self.first_ts, self.last_ts = times[0], times[-1] self.first_ts, self.last_ts = times[0], times[-1]
self.warnings = "" # add check for warning, i.e. data gaps due to missing nodes self.warnings = "" # add check for warning, i.e. data gaps due to missing nodes
self.energy = self.summarize_energy() self.energy = self._summarize_energy()
def to_file(self, jobid, header=""): def to_file(self, jobid, header=""):
"""Dumps power data to file. Returns filename is succesfull and None if unsucessfull.""" """Dumps power data to file. Returns filename is succesfull and None if unsucessfull."""
@ -110,11 +110,11 @@ class Power:
_body += self.pretty_print(*self.summarize_epoch(epoch)) _body += self.pretty_print(*self.summarize_epoch(epoch))
return _body return _body
def summarize_time(self, ts): def _summarize_time(self, ts):
return Power.to_csv(ts, "") return Power.to_csv(ts, "")
@staticmethod @staticmethod
def summarize_values(df): def _summarize_values(df):
values = df['power'].values values = df['power'].values
head = values[0] head = values[0]
min, max = values.min(), values.max() min, max = values.min(), values.max()
@ -124,11 +124,11 @@ class Power:
def summarize_epoch(self, epoch): def summarize_epoch(self, epoch):
ts, values = epoch ts, values = epoch
return self.summarize_time(ts), \ return self._summarize_time(ts), \
self.summarize_values(values), \ self._summarize_values(values), \
self.all_values(values) self._all_values(values)
def all_values(self, values): def _all_values(self, values):
# reindex frame to get all nodes; introduces gaps # reindex frame to get all nodes; introduces gaps
values = values[['node', 'power']].set_index('node').reindex(self.nodes) values = values[['node', 'power']].set_index('node').reindex(self.nodes)
# hack to_csv() to transpose array # hack to_csv() to transpose array
@ -139,17 +139,17 @@ class Power:
def energy_total(self): def energy_total(self):
energy = None energy = None
if hasattr(self, "by_node"): if hasattr(self, "by_node"):
energy = self.by_node.apply(self.energy_node).sum() energy = self.by_node.apply(self._energy_node).sum()
return energy return energy
@staticmethod @staticmethod
def energy_node(group): def _energy_node(group):
"""Left-sided Riemann sum is enough, as time is lower bound of bucket""" """Left-sided Riemann sum is enough, as time is lower bound of bucket"""
delta_t = group["time"].diff().shift(-1)/1000. # in seconds delta_t = group["time"].diff().shift(-1)/1000. # in seconds
pow = group['power'] pow = group['power']
return (delta_t * pow).iloc[:-1].sum() return (delta_t * pow).iloc[:-1].sum()
def summarize_energy(self): def _summarize_energy(self):
return "# Total energy consumed by job: {energy:.0f} J\n".format(energy=self.energy_total()) return "# Total energy consumed by job: {energy:.0f} J\n".format(energy=self.energy_total())
@staticmethod @staticmethod