Skip to content

Commit

Permalink
Added support saving mcs0 template in xlsx. Fixed blank line issue wh…
Browse files Browse the repository at this point in the history
…en saved as csv.
  • Loading branch information
fuyans committed May 19, 2020
1 parent 1871c7a commit fae4624
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ tqdm>=4.36
xlrd>=1.2
plotly>=4.2
docopt>=0.6
pyside2>=5.12
pyside2>=5.12
openpyxl>=3.0.3
9 changes: 6 additions & 3 deletions sfeprapy/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,13 @@ def main():
mcs0_figure(fp_mcs0_out=arguments["<file_name>"])

elif arguments["template"]:
from sfeprapy.mcs0 import EXAMPLE_INPUT_CSV
from sfeprapy.mcs0 import EXAMPLE_INPUT_CSV, EXAMPLE_INPUT_DF

with open(arguments["<file_name>"], "w+") as f:
f.write(EXAMPLE_INPUT_CSV)
if arguments["<file_name>"].endswith('.xlsx'):
EXAMPLE_INPUT_DF.to_excel(arguments["<file_name>"])
else:
with open(arguments["<file_name>"], "w+", encoding='utf-8') as f:
f.write(EXAMPLE_INPUT_CSV)

else:
from sfeprapy.mcs0.__main__ import main as mcs0
Expand Down
14 changes: 11 additions & 3 deletions sfeprapy/mcs0/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# -*- coding: utf-8 -*-
import pandas as pd

from sfeprapy.func.mcs_gen import dict_flatten


def __example_config_dict():
Expand Down Expand Up @@ -169,19 +172,24 @@ def __example_input_dict():


def __example_input_csv(x: dict):
from sfeprapy.func.mcs_gen import dict_flatten
import pandas as pd
y = {k: dict_flatten(v) for k, v in x.items()}
y = pd.DataFrame.from_dict(y, orient="columns")
y.index.name = "PARAMETERS"
y = y.to_csv(index=True, line_terminator='\n')
return y


def __example_input_df(x: dict) -> pd.DataFrame:
y = {k: dict_flatten(v) for k, v in x.items()}
y = pd.DataFrame.from_dict(y, orient="columns")
y.index.name = "PARAMETERS"
y = y.to_csv(index=True)
return y


EXAMPLE_CONFIG_DICT = __example_config_dict()
EXAMPLE_INPUT_DICT = __example_input_dict()
EXAMPLE_INPUT_CSV = __example_input_csv(__example_input_dict())
EXAMPLE_INPUT_DF = __example_input_df(__example_input_dict())

if __name__ == "__main__":
print(EXAMPLE_CONFIG_DICT, "\n")
Expand Down

0 comments on commit fae4624

Please sign in to comment.