Skip to content

Commit

Permalink
DataSetMaker start
Browse files Browse the repository at this point in the history
  • Loading branch information
AmadejTratnik committed Mar 7, 2024
1 parent 0d098cf commit e922ca7
Show file tree
Hide file tree
Showing 20 changed files with 508 additions and 723 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ $ (venv) python3 app/visualisation.py

### Measurements visualization of dataset FD001

[<img src="app/assets/eda.png"/>](app/assets/image.png)
[<img src="app/assets/eda.png" width=100% height=600/>](app/assets/eda.png)


710 changes: 0 additions & 710 deletions Untitled.ipynb

This file was deleted.

10 changes: 3 additions & 7 deletions app/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@
def get_callbacks(app):
@app.callback(
Output('interval', 'n_intervals'),
Output({'type':'graph','id':ALL}, 'data'),
Input('toggle-button','n_clicks'),
State('interval','n_intervals'),
State('interval','max_intervals'),
)
def start_interval_again(n,current_n,max_n):
if current_n == max_n:
return 0, [[] for _ in range(len(dash.callback_context.outputs_list[1]))]
return 0#, [[] for _ in range(len(dash.callback_context.outputs_list[1]))]
else:
raise dash.exceptions.PreventUpdate

Expand Down Expand Up @@ -107,9 +106,6 @@ def disable_dropdowns(n):
disabled =bool(n%2)
return disabled,disabled,disabled
raise dash.exceptions.PreventUpdate




@app.callback(
Output({'type':'graph','id':ALL}, 'extendData'),
Expand All @@ -118,11 +114,11 @@ def disable_dropdowns(n):
prevent_initial_call=True
)
def update_operational_setting_graph(n_intervals,data):
n_of_graphs = len(dash.callback_context.outputs_list)
output_graphs = (dash.callback_context.outputs_list)
if n_intervals==0:
raise dash.exceptions.PreventUpdate
s = []

result = [entry for entry in data if entry.get('time') == n_intervals][0]
for x in output_graphs:
current_value = x['id']['id'].split('graph-')[1]
Expand All @@ -135,7 +131,7 @@ def update_operational_setting_graph(n_intervals,data):
prevent_initial_call=True
)
def take_data(value):
return make_dataframe('./data/'+value)
return make_dataframe(value)

@app.callback(
Output('unit-slider', 'min'),
Expand Down
8 changes: 4 additions & 4 deletions app/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@
N = 6
df = pd.DataFrame()

directory_path = './data/'
directory_path = './data/raw/'
prefix_list = ['train_', 'test_']

layout = html.Div(
children=[
html.H2("Prediction of Remaining Useful Life of JET engine",style={"textAlign":"center"}),
html.H2("Fault Detection of a JET Engine",style={"textAlign":"center"}),
dbc.Row(
style={'margin':'1%'},
children=[
dbc.Col(width=2,className="dash-bootstrap",children=[
html.Label("FD choice"),
dcc.Dropdown(options = [{'label':x.replace('.txt', ''),'value':x} for x in get_files_with_prefix(directory_path, prefix_list)], id='fd-choice-dropdown'),
dcc.Dropdown(options = [{'label':x.replace('.txt', '').replace(directory_path,''),'value':x} for x in get_files_with_prefix(directory_path, prefix_list)], id='fd-choice-dropdown'),
]),
dbc.Col(width=4,children=[
html.Label("Unit choice"),
Expand Down Expand Up @@ -55,7 +55,7 @@
id="rul-and-operational",
style={'margin':'1%'},
children=[dbc.Col(width=6, children=[
html.P("RUL PREDICTION"),
html.P("FAULT DETECTION"),
dcc.Graph(
id = {'type':'graph','id':f'graph-RUL'},
config={'displayModeBar': False},
Expand Down
2 changes: 1 addition & 1 deletion app/visualisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@


if __name__ == '__main__':
app.run_server(port=1129, debug=False)
app.run_server(port=1129, debug=True)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
448 changes: 448 additions & 0 deletions eda.ipynb

Large diffs are not rendered by default.

51 changes: 51 additions & 0 deletions modelling/dataset_creation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import pandas as pd

class DataSetMaker:
def __init__(self,train_set:bool, path1:str, path2:str=None):
self.train_set = train_set
self.path1 = path1
self.path2 = path2

def make_dataframe(self) -> bool:
if self.train_set:
data = pd.read_csv(self.path1)


if __name__ == '__main__':
s = DataSetMaker(True,"a").make_dataframe()
print(s)



def make_dataframe(text_file_path):
column_names = ['unit_number','time','operational_setting_1','operational_setting_2','operational_setting_3']
N =24
column_names += [f'sensor_measurement_{i}' for i in range(1,N)]
df = pd.read_csv(text_file_path, sep=" ",header=None,names=column_names)
# deleting empty columns
df.dropna(how='all', axis=1, inplace=True)
#delete duplicates
df.drop_duplicates(inplace=True)
grouped_by = df.groupby(by='unit_number')
max_time = grouped_by['time'].max()
df = df.merge(max_time.to_frame(name='max_time'), left_on='unit_number', right_index=True)
df['RUL'] = df['max_time'] - df['time']
df['fault_detected'] = df.groupby('unit_number')['RUL'].transform(detect_fault)
return df.to_dict('records')

def detect_fault(series):
warning = 0.7
fault = 0.1
total_cycles = series.max() # Maximum cycle for the unit
threshold_warning = warning * total_cycles
threshold_fault = fault * total_cycles

def fault_detection(rul):
if rul > threshold_warning:
return 0 # Everything is ok
elif rul > threshold_fault:
return 1 # Warning
else:
return 2 # Fault detected

return series.apply(fault_detection)

0 comments on commit e922ca7

Please sign in to comment.