Skip to content

Commit

Permalink
Started developing save functions
Browse files Browse the repository at this point in the history
  • Loading branch information
dmotte committed Dec 27, 2024
1 parent 3122f33 commit 80bfe50
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
48 changes: 48 additions & 0 deletions smartchg/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,54 @@ def load_data(file: TextIO, krate: str = 'Open'):
}


def save_data(data: list[dict], file: TextIO, fmt_days: str = '',
fmt_rate: str = '', fmt_simil: str = ''):
'''
Saves data into a CSV file
'''
func_days = str if fmt_days == '' else lambda x: fmt_days.format(x)
func_rate = str if fmt_rate == '' else lambda x: fmt_rate.format(x)
func_simil = str if fmt_simil == '' else lambda x: fmt_simil.format(x)

fields = {
'date': str,
'days': func_days,

'rate': func_rate,
'pred': func_rate,
'offset': func_rate,

'upper': func_rate,
'lower': func_rate,
'center': func_rate,

'simil': func_simil,
}

print(','.join(fields.keys()), file=file)
for x in data:
print(','.join(f(x[k]) for k, f in fields.items()), file=file)


def save_values(data: dict, file: TextIO, fmt_rate: str = '',
fmt_src: str = '', fmt_dst: str = ''):
pass # TODO
# - date_start (str)
# - date_end (str)
#
# - offset_mean (fmt_rate)
# - offset_stdev (fmt_rate)
# - offset_upper (fmt_rate)
# - offset_lower (fmt_rate)
#
# - sugg_src (fmt_src)
# - sugg_dst (fmt_dst)


def compute_stuff():
pass # TODO


def main(argv=None):
if argv is None:
argv = sys.argv
Expand Down
8 changes: 6 additions & 2 deletions test/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from datetime import date

from smartchg import load_data
from smartchg import load_data, save_data, save_values, compute_stuff


def test_load_data():
Expand Down Expand Up @@ -37,5 +37,9 @@ def test_save_data():
pass # TODO


def test_compute_stats():
def test_save_values():
pass # TODO


def test_compute_stuff():
pass # TODO

0 comments on commit 80bfe50

Please sign in to comment.