refactoring datasource to make subclassing easier

This commit is contained in:
evilchili 2023-12-19 21:29:39 -08:00
parent fd917bb59b
commit 5c57d262d5

View File

@ -44,16 +44,22 @@ class DataSource:
""" """
if self.data: if self.data:
return return
self.read_source()
self.init_headers()
self.init_frequencies()
def read_source(self) -> None:
self.data = yaml.safe_load(self.source) self.data = yaml.safe_load(self.source)
self.metadata = self.data.pop('metadata', {}) self.metadata = self.data.pop('metadata', {})
num_keys = len(self.data.keys()) def init_headers(self) -> None:
default_freq = num_keys / 100
if 'headers' in self.metadata: if 'headers' in self.metadata:
self.headers = self.metadata['headers'] self.headers = self.metadata['headers']
def init_frequencies(self) -> None:
num_keys = len(self.data.keys())
default_freq = num_keys / 100
frequencies = { frequencies = {
'default': dict([(k, default_freq) for k in self.data.keys()]) 'default': dict([(k, default_freq) for k in self.data.keys()])
} }