From 149e4366735feea15f4a0b93d2561692ab3887a9 Mon Sep 17 00:00:00 2001 From: Trigg Allen Date: Thu, 11 Apr 2024 18:10:13 -0600 Subject: [PATCH 1/3] Added Python app with dataset --- converter_app.py | 113 +++++++++++++++++++++++++++++++++++++++++++++++ dataset.csv | 101 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 214 insertions(+) create mode 100644 converter_app.py create mode 100644 dataset.csv diff --git a/converter_app.py b/converter_app.py new file mode 100644 index 00000000..cad8f3d6 --- /dev/null +++ b/converter_app.py @@ -0,0 +1,113 @@ +import dash +from dash import dcc, html, Input, Output, State, dash_table +import pandas as pd +import base64 +import io +from dash.exceptions import PreventUpdate +import dash_bootstrap_components as dbc +# Add this import statement at the beginning of your Python script +import urllib.parse + + +app = dash.Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP]) + +app.layout = html.Div([ + dcc.Upload( + id='upload-data', + children=html.Div(['Drag and Drop or ', html.A('Select Files')]), + style={ + 'width': '100%', + 'height': '60px', + 'lineHeight': '60px', + 'borderWidth': '1px', + 'borderStyle': 'dashed', + 'borderRadius': '5px', + 'textAlign': 'center', + 'margin': '10px' + }, + multiple=False + ), + html.Button('Process Data', id='process-data', n_clicks=0), + html.Div(id='output-data-upload'), + dcc.Download(id='download-dataframe-csv') +]) + +def parse_contents(contents, filename): + content_type, content_string = contents.split(',') + decoded = base64.b64decode(content_string) + try: + if 'csv' in filename: + # Assume that the user uploaded a CSV file + df = pd.read_csv(io.StringIO(decoded.decode('utf-8'))) + elif 'xls' in filename: + # Assume that the user uploaded an excel file + df = pd.read_excel(io.BytesIO(decoded)) + except Exception as e: + return html.Div([ + 'There was an error processing this file: ' + str(e) + ]) + return df + +def hex_to_binary(hex_val): + return bin(int(hex_val, 16))[2:].zfill(16) + +def hex_to_decimal(hex_val): + return str(int(hex_val, 16)) + +def calculate_timestamp_difference(df): + df['Timestamp'] = pd.to_datetime(df['Timestamp']) + df['Timestamp Difference'] = df['Timestamp'].diff().fillna(pd.Timedelta(seconds=0)).dt.total_seconds() + return df + +@app.callback( + Output('output-data-upload', 'children'), + [Input('upload-data', 'contents'), + Input('process-data', 'n_clicks')], + [State('upload-data', 'filename')] +) +def update_output(contents, process_clicks, filename): + ctx = dash.callback_context + if not contents: + raise PreventUpdate + + df = parse_contents(contents, filename) + if df is None: + return html.Div("There was an error processing the file.") + + # Get the ID of the button that triggered the callback + trigger_id = ctx.triggered[0]['prop_id'].split('.')[0] + + if trigger_id == 'process-data' and process_clicks > 0: + df['Binary'] = df['Hex'].apply(hex_to_binary) + df['Decimal'] = df['Hex'].apply(hex_to_decimal) + df = calculate_timestamp_difference(df) + + data_table = dash_table.DataTable( + data=df.to_dict('records'), + columns=[{'name': i, 'id': i} for i in df.columns], + export_format="csv", + style_table={'overflowX': 'scroll'}, + style_cell={ + 'height': 'auto', + 'minWidth': '180px', 'width': '180px', 'maxWidth': '180px', + 'whiteSpace': 'normal' + } + ) + + # Update download-dataframe-csv data and trigger download + if trigger_id == 'process-data': + csv_string = df.to_csv(index=False, encoding='utf-8') + csv_string = "data:text/csv;charset=utf-8," + urllib.parse.quote(csv_string) + download_button = html.A( + "Download CSV", + id='download-link', + download="processed_data.csv", + href=csv_string, + target="_blank" + ) + return html.Div([data_table, download_button]) + + return html.Div([data_table]) + +if __name__ == '__main__': + app.run_server(debug=True) diff --git a/dataset.csv b/dataset.csv new file mode 100644 index 00000000..8786e617 --- /dev/null +++ b/dataset.csv @@ -0,0 +1,101 @@ +Timestamp,Hex +2024-04-01 00:00:00.000,0x0AAC +2024-04-01 00:00:00.500,0xAA2F +2024-04-01 00:00:01.000,0xA675 +2024-04-01 00:00:01.500,0xCCC0 +2024-04-01 00:00:02.000,0xB343 +2024-04-01 00:00:02.500,0x52FB +2024-04-01 00:00:03.000,0x76C3 +2024-04-01 00:00:03.500,0x7D67 +2024-04-01 00:00:04.000,0xA409 +2024-04-01 00:00:04.500,0xDED3 +2024-04-01 00:00:05.000,0x5115 +2024-04-01 00:00:05.500,0xD6F2 +2024-04-01 00:00:06.000,0xB724 +2024-04-01 00:00:06.500,0x3A57 +2024-04-01 00:00:07.000,0x3C46 +2024-04-01 00:00:07.500,0xBDD8 +2024-04-01 00:00:08.000,0x9A58 +2024-04-01 00:00:08.500,0xCD8C +2024-04-01 00:00:09.000,0x393A +2024-04-01 00:00:09.500,0x42C1 +2024-04-01 00:00:10.000,0x7DE6 +2024-04-01 00:00:10.500,0x4A27 +2024-04-01 00:00:11.000,0xA857 +2024-04-01 00:00:11.500,0xC8AE +2024-04-01 00:00:12.000,0x5E58 +2024-04-01 00:00:12.500,0x8B51 +2024-04-01 00:00:13.000,0xE6A5 +2024-04-01 00:00:13.500,0x4219 +2024-04-01 00:00:14.000,0x6B4D +2024-04-01 00:00:14.500,0x9848 +2024-04-01 00:00:15.000,0x1B09 +2024-04-01 00:00:15.500,0x9794 +2024-04-01 00:00:16.000,0x0873 +2024-04-01 00:00:16.500,0x13D0 +2024-04-01 00:00:17.000,0x92F3 +2024-04-01 00:00:17.500,0x1EC5 +2024-04-01 00:00:18.000,0x47FE +2024-04-01 00:00:18.500,0x074F +2024-04-01 00:00:19.000,0x1DAF +2024-04-01 00:00:19.500,0x09C0 +2024-04-01 00:00:20.000,0xBB52 +2024-04-01 00:00:20.500,0x6063 +2024-04-01 00:00:21.000,0xA7D8 +2024-04-01 00:00:21.500,0x7CB1 +2024-04-01 00:00:22.000,0x82F3 +2024-04-01 00:00:22.500,0x031D +2024-04-01 00:00:23.000,0xC293 +2024-04-01 00:00:23.500,0x0C93 +2024-04-01 00:00:24.000,0x3B8E +2024-04-01 00:00:24.500,0x61A7 +2024-04-01 00:00:25.000,0xDD20 +2024-04-01 00:00:25.500,0x3FC1 +2024-04-01 00:00:26.000,0xCD09 +2024-04-01 00:00:26.500,0x4AB9 +2024-04-01 00:00:27.000,0xD27F +2024-04-01 00:00:27.500,0xA220 +2024-04-01 00:00:28.000,0xDA1F +2024-04-01 00:00:28.500,0xC2CA +2024-04-01 00:00:29.000,0x48F4 +2024-04-01 00:00:29.500,0xE097 +2024-04-01 00:00:30.000,0xEAA3 +2024-04-01 00:00:30.500,0x79FE +2024-04-01 00:00:31.000,0x2DCB +2024-04-01 00:00:31.500,0xAB72 +2024-04-01 00:00:32.000,0x44B7 +2024-04-01 00:00:32.500,0xD81C +2024-04-01 00:00:33.000,0xE322 +2024-04-01 00:00:33.500,0xA880 +2024-04-01 00:00:34.000,0x6880 +2024-04-01 00:00:34.500,0xE7A4 +2024-04-01 00:00:35.000,0x5C35 +2024-04-01 00:00:35.500,0x1785 +2024-04-01 00:00:36.000,0x4E26 +2024-04-01 00:00:36.500,0x0DE8 +2024-04-01 00:00:37.000,0x62F4 +2024-04-01 00:00:37.500,0xF111 +2024-04-01 00:00:38.000,0x794F +2024-04-01 00:00:38.500,0xB184 +2024-04-01 00:00:39.000,0xC669 +2024-04-01 00:00:39.500,0xEC2A +2024-04-01 00:00:40.000,0xB5BA +2024-04-01 00:00:40.500,0xBA1F +2024-04-01 00:00:41.000,0x5378 +2024-04-01 00:00:41.500,0x5101 +2024-04-01 00:00:42.000,0xF541 +2024-04-01 00:00:42.500,0x6FE7 +2024-04-01 00:00:43.000,0xEFA9 +2024-04-01 00:00:43.500,0x6839 +2024-04-01 00:00:44.000,0x3923 +2024-04-01 00:00:44.500,0x2F66 +2024-04-01 00:00:45.000,0xEC77 +2024-04-01 00:00:45.500,0xBB0B +2024-04-01 00:00:46.000,0xA1AE +2024-04-01 00:00:46.500,0xDC52 +2024-04-01 00:00:47.000,0x505B +2024-04-01 00:00:47.500,0xF780 +2024-04-01 00:00:48.000,0xE98E +2024-04-01 00:00:48.500,0xCA63 +2024-04-01 00:00:49.000,0x2635 +2024-04-01 00:00:49.500,0x4B8C From 87e7944a5428ae6e967f25bee4f122c977648939 Mon Sep 17 00:00:00 2001 From: Barrett <112177669+HackBear44@users.noreply.github.com> Date: Thu, 11 Apr 2024 20:43:00 -0400 Subject: [PATCH 2/3] Update deploy.yml updated the S3 bucket and region --- .github/workflows/deploy.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index c32f050e..a57033be 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -5,8 +5,8 @@ on: env: applicationfolder: spring-boot-hello-world-example - AWS_REGION: ##region## - S3BUCKET: ##s3-bucket## + AWS_REGION: us-east-2 + S3BUCKET: unocodedeploystack-webappdeploymentbucket-jtaxf6t0zjwo jobs: From 1f1190737096cdb7734f47ce3c0f686ec110c86a Mon Sep 17 00:00:00 2001 From: Barrett <112177669+HackBear44@users.noreply.github.com> Date: Thu, 11 Apr 2024 20:44:22 -0400 Subject: [PATCH 3/3] Update after-install.sh Updated the S3 bucket info --- aws/scripts/after-install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aws/scripts/after-install.sh b/aws/scripts/after-install.sh index aefc504a..c8847a60 100644 --- a/aws/scripts/after-install.sh +++ b/aws/scripts/after-install.sh @@ -3,8 +3,8 @@ set -xe # Copy war file from S3 bucket to tomcat webapp folder -aws s3 cp s3://##s3-bucket##/SpringBootHelloWorldExampleApplication.war /usr/local/tomcat9/webapps/SpringBootHelloWorldExampleApplication.war +aws s3 cp s3://unocodedeploystack-webappdeploymentbucket-jtaxf6t0zjwo/SpringBootHelloWorldExampleApplication.war /usr/local/tomcat9/webapps/SpringBootHelloWorldExampleApplication.war # Ensure the ownership permissions are correct. -chown -R tomcat:tomcat /usr/local/tomcat9/webapps \ No newline at end of file +chown -R tomcat:tomcat /usr/local/tomcat9/webapps