Skip to content

Commit faa9ad5

Browse files
author
David Tang
committed
fix: csv format header for bokeh
1 parent e709f49 commit faa9ad5

File tree

6 files changed

+40
-51
lines changed

6 files changed

+40
-51
lines changed

backend/ccfatigue/analyzer.py

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -48,36 +48,21 @@ def run_python(
4848
return output_tmp_file.read()
4949

5050

51-
def create_dataframe(output: bytes, method: SnCurveMethod) -> DataFrame:
52-
if method in [SnCurveMethod.LIN_LOG, SnCurveMethod.LOG_LOG]:
53-
widths = [17, 12, 12, 12, 12]
54-
columns = [
55-
DataKey.R_RATIO,
56-
DataKey.N_CYCLES,
57-
DataKey.STRESS_PARAM,
58-
DataKey.LOW,
59-
DataKey.HIGH,
60-
]
61-
elif method in [SnCurveMethod.SENDECKYJ, SnCurveMethod.WHITNEY]:
62-
widths = [17, 12, 12]
63-
columns = [DataKey.R_RATIO, DataKey.N_CYCLES, DataKey.STRESS_PARAM]
64-
else:
65-
raise ValueError(f"unknown {method.name}")
66-
df: DataFrame = pd.read_fwf(io.BytesIO(output), widths=widths, header=None)
67-
df.columns = [column.key for column in columns]
51+
def create_dataframe(output: bytes) -> DataFrame:
52+
df: DataFrame = pd.read_csv(io.BytesIO(output))
6853
return df.fillna("")
6954

7055

7156
def create_line(output: bytes, method: SnCurveMethod, r_ratio: float) -> Any:
72-
df = create_dataframe(output, method)
57+
df = create_dataframe(output)
7358
round_df = df.round({DataKey.R_RATIO.key: ROUND_DECIMAL})
7459
selected_df = round_df[round_df[DataKey.R_RATIO.key] == r_ratio]
7560
n_cycles = selected_df[DataKey.N_CYCLES.key].to_list()
76-
stress_param = selected_df[DataKey.STRESS_PARAM.key].to_list()
61+
stress_param = selected_df[DataKey.STRESS.key].to_list()
7762
return Line(
7863
data={
7964
DataKey.N_CYCLES: n_cycles,
80-
DataKey.STRESS_PARAM: stress_param,
65+
DataKey.STRESS: stress_param,
8166
},
8267
legend_label=f"{method.value} {r_ratio}",
8368
color=None,
@@ -92,8 +77,8 @@ def run_sn_curve(
9277
plot = Plot(
9378
title="S-N Curves",
9479
x_axis=DataKey.N_CYCLES,
95-
y_axis=DataKey.STRESS_PARAM,
96-
tooltips=[DataKey.N_CYCLES, DataKey.STRESS_PARAM],
80+
y_axis=DataKey.STRESS,
81+
tooltips=[DataKey.N_CYCLES, DataKey.STRESS],
9782
x_axis_type="log",
9883
)
9984
outputs: Dict[SnCurveMethod, bytes] = {}

backend/ccfatigue/dashboarder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from ccfatigue import plotter
1212
from ccfatigue.plotter import DataKey, Line, Plot
1313

14-
DATA_DIRECTORY: str = "../data/"
14+
DATA_DIRECTORY: str = "../Data/"
1515

1616
INTERVAL: int = 10
1717
LOOP_SPACING: int = 1000

backend/ccfatigue/modules/sn_curve_linlog.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
""" CCFatigue - Module 2 - sn_curve_linlog.py
33
This code takes in AGG data and outputs SNC data
44
5-
Translated from https://github.com/EPFL-ENAC/CCFatiguePlatform/blob/develop/CCFatigue_modules/2_S-NCurves/S-N-Curve-LinLog.for
5+
Translated from
6+
https://github.com/EPFL-ENAC/CCFatiguePlatform/blob/develop/CCFatigue_modules/2_S-NCurves/S-N-Curve-LinLog.for
67
78
It applies a linear regression on log(number of cycles) and stress ratios
89
as described in
@@ -39,7 +40,8 @@ def get_linlog_stress_at_failure(
3940
) -> float:
4041
"""
4142
Calculate stress at failure.
42-
Translated from: https://github.com/EPFL-ENAC/CCFatiguePlatform/blob/develop/CCFatigue_modules/2_S-NCurves/S-N-Curve-LinLog.for#L397
43+
Translated from:
44+
https://github.com/EPFL-ENAC/CCFatiguePlatform/blob/develop/CCFatigue_modules/2_S-NCurves/S-N-Curve-LinLog.for#L397
4345
Parameters
4446
----------
4547
aa: float
@@ -110,20 +112,20 @@ def get_linlog_lsst(
110112

111113

112114
def execute(
113-
input_file: FilePath or ReadBuffer,
114-
output_json_file: FilePath or WriteBuffer,
115-
output_csv_file: FilePath or WriteBuffer,
115+
input_file: FilePath | ReadBuffer,
116+
output_json_file: FilePath | WriteBuffer,
117+
output_csv_file: FilePath | WriteBuffer,
116118
confidence: int = 95,
117119
) -> None:
118120
"""
119121
Execute the LinLog algorithm
120122
Parameters
121123
----------
122-
input_file: FilePath or ReadBuffer
124+
input_file: FilePath | ReadBuffer
123125
AGG input file
124-
output_json_file: FilePath or WriteBuffer
126+
output_json_file: FilePath | WriteBuffer
125127
SNC json file
126-
output_csv_file: FilePath or WriteBuffer
128+
output_csv_file: FilePath | WriteBuffer
127129
SNC csv file
128130
confidence: float
129131
Confidence={95|99}

backend/ccfatigue/modules/sn_curve_loglog.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
""" CCFatigue - Module 2 - sn_curve_loglog.py
33
This code takes in AGG data and outputs SNC data
44
5-
Translated from https://github.com/EPFL-ENAC/CCFatiguePlatform/blob/develop/CCFatigue_modules/2_S-NCurves/S-N-Curve-LogLog.for
5+
Translated from
6+
https://github.com/EPFL-ENAC/CCFatiguePlatform/blob/develop/CCFatigue_modules/2_S-NCurves/S-N-Curve-LogLog.for
67
78
It applies a linear regression on log(number of cycles) and log(stress ratios)
89
as described in
@@ -38,7 +39,8 @@ def get_loglog_stress_at_failure(
3839
) -> float:
3940
"""
4041
Calculate stress at failure.
41-
Translated from: https://github.com/EPFL-ENAC/CCFatiguePlatform/blob/develop/CCFatigue_modules/2_S-NCurves/S-N-Curve-LinLog.for#L397
42+
Translated from:
43+
https://github.com/EPFL-ENAC/CCFatiguePlatform/blob/develop/CCFatigue_modules/2_S-NCurves/S-N-Curve-LinLog.for#L397
4244
Parameters
4345
----------
4446
aa: float
@@ -109,21 +111,21 @@ def get_loglog_lsst(
109111

110112

111113
def execute(
112-
input_file: FilePath or ReadBuffer,
113-
output_json_file: FilePath or WriteBuffer,
114-
output_csv_file: FilePath or WriteBuffer,
114+
input_file: FilePath | ReadBuffer,
115+
output_json_file: FilePath | WriteBuffer,
116+
output_csv_file: FilePath | WriteBuffer,
115117
reliability_level: float = 50,
116118
confidence: int = 95,
117119
) -> None:
118120
"""
119121
Execute the LogLog algorithm
120122
Parameters
121123
----------
122-
input_file: FilePath or ReadBuffer
124+
input_file: FilePath | ReadBuffer
123125
AGG input file
124-
output_json_file: FilePath or WriteBuffer
126+
output_json_file: FilePath | WriteBuffer
125127
SNC json file
126-
output_csv_file: FilePath or WriteBuffer
128+
output_csv_file: FilePath | WriteBuffer
127129
SNC csv file
128130
reliability_level: float
129131
Reliability level P(N)

backend/ccfatigue/modules/sn_curve_utils.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
def equation_ycar(slope: float, intercept: float, stress_parameter: float) -> float:
1515
"""
1616
Calculate ycar TODO check with Tassos for a meaningful name: estimated_y?
17-
Translated from: https://github.com/EPFL-ENAC/CCFatiguePlatform/blob/develop/CCFatigue_modules/2_S-NCurves/S-N-Curve-LinLog.for#L314
17+
Translated from:
18+
https://github.com/EPFL-ENAC/CCFatiguePlatform/blob/develop/CCFatigue_modules/2_S-NCurves/S-N-Curve-LinLog.for#L314
1819
Parameters
1920
----------
2021
slope: float
@@ -95,9 +96,9 @@ def stress_at_failure_bounds(
9596

9697
def execute_linlog_loglog(
9798
use_logarithm: bool,
98-
input_file: FilePath or ReadBuffer,
99-
output_json_file: FilePath or WriteBuffer,
100-
output_csv_file: FilePath or WriteBuffer,
99+
input_file: FilePath | ReadBuffer,
100+
output_json_file: FilePath | WriteBuffer,
101+
output_csv_file: FilePath | WriteBuffer,
101102
list_cycles_to_failure: list[int],
102103
get_stress_at_failure,
103104
get_a_b,
@@ -113,11 +114,11 @@ def execute_linlog_loglog(
113114
----------
114115
use_logarithm: bool
115116
Use log10(stress_max) if True (LogLog) or stress_max if False (LinLog)
116-
input_file: FilePath or ReadBuffer
117+
input_file: FilePath | ReadBuffer
117118
AGG input file
118-
output_json_file: FilePath or WriteBuffer
119+
output_json_file: FilePath | WriteBuffer
119120
SNC json file
120-
output_csv_file: FilePath or WriteBuffer
121+
output_csv_file: FilePath | WriteBuffer
121122
SNC csv file
122123
list_cycles_to_failure: list[int]
123124
List of cycles_to_failure in SNC output

backend/ccfatigue/plotter.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,14 @@
1515

1616
class DataKey(Enum):
1717
CREEP = ("creep", "Creep")
18-
HIGH = ("high", "High")
18+
HIGH = ("stress_upperbound", "High")
1919
HYST_AREA = ("hyst_area", "Hysteresis area")
20-
LOW = ("low", "Low")
21-
N_CYCLES = ("n_cycles", "Number of cycles")
22-
R_RATIO = ("r_ratio", "R ratio")
20+
LOW = ("stress_lowerbound", "Low")
21+
N_CYCLES = ("cycles_to_failure", "Number of cycles")
22+
R_RATIO = ("stress_ratio", "R ratio")
2323
STIFNESS = ("stiffness", "Stiffness")
2424
STRAIN = ("strain", "Strain")
2525
STRESS = ("stress", "Stress")
26-
STRESS_PARAM = ("stress_parameter", "Maximum Cyclic Stress")
2726

2827
def __init__(self, key: str, label: str):
2928
self.key = key

0 commit comments

Comments
 (0)