refactoring datasource to make subclassing easier
This commit is contained in:
parent
fd917bb59b
commit
5c57d262d5
|
@ -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()])
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user