Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
montecarlo_cw_files
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Someshwar, Rudra (PG/T - Comp Sci & Elec Eng)
montecarlo_cw_files
Commits
757aafb1
Commit
757aafb1
authored
2 years ago
by
Someshwar, Rudra (PG/T - Comp Sci & Elec Eng)
Browse files
Options
Downloads
Patches
Plain Diff
Update file ec2_function.py
parent
956c9419
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ec2_function.py
+38
-22
38 additions, 22 deletions
ec2_function.py
with
38 additions
and
22 deletions
ec2_function.py
+
38
−
22
View file @
757aafb1
from
flask
import
Flask
,
request
,
jsonify
import
boto3
import
json
import
random
import
math
app
=
Flask
(
__name__
)
s3
=
boto3
.
client
(
'
s3
'
)
@app.route
(
'
/
'
)
def
hello_world
():
return
'
Hello from Flask!
'
@app.route
(
'
/work
'
,
methods
=
[
'
POST
'
])
def
run_simulation
():
# Parse the JSON input data
input_json
=
request
.
json
def
main
(
input_key
,
output_key
):
# Read the input JSON data from the S3 bucket
input_bucket
=
'
ec2-function-input
'
output_bucket
=
'
instance-results
'
# input_key = event['key']
obj
=
s3
.
get_object
(
Bucket
=
input_bucket
,
Key
=
input_key
)
input_json
=
json
.
loads
(
obj
[
'
Body
'
].
read
().
decode
(
'
utf-8
'
))
# Extract the required parameters from the input data
minhistory
=
int
(
input_json
[
'
history
'
])
...
...
@@ -23,11 +22,6 @@ def run_simulation():
buy_signals
=
input_json
[
'
buy_signals
'
]
sell_signals
=
input_json
[
'
sell_signals
'
]
# print(minhistory, shots, signaltype, P)
# print(buy_signals)
# print(sell_signals)
# create empty lists to store the results
risk95_values
=
[]
risk99_values
=
[]
...
...
@@ -71,15 +65,37 @@ def run_simulation():
risk95_values
.
append
(
var95
)
risk99_values
.
append
(
var99
)
# Create a dictionary to store the simulation results
simulation_results
=
{
'
risk95_values
'
:
risk95_values
,
'
risk99_values
'
:
risk99_values
}
return
(
risk95_values
,
risk99_values
)
# # Write the simulation results to a JSON file
# with open('simulation_results.json', 'w') as f:
# json.dump(simulation_results, f)
# # Upload the output to S3 bucket
# s3.upload_file('simulation_results.json', bucket_name, output_key)
output_data_json
=
json
.
dumps
(
simulation_results
)
s3
.
put_object
(
Bucket
=
output_bucket
,
Key
=
output_key
,
Body
=
output_data_json
)
# # Return the results as a JSON response
# response_json = {
# 'result': result
# # Write the output to a new file in the S3 bucket
# output_bucket = event['output_bucket']
# output_key = key
# output_data = {
# 'risk95_values': risk95_values,
# 'risk99_values': risk99_values
# }
# return jsonify(response_json)
# s3.put_object(Bucket=output_bucket, Key=output_key, Body=json.dumps(output_data))
# # Return a success response
# response = {
# 'statusCode': 200,
# 'body': json.dumps('Simulation completed successfully!')
# }
# return response
return
(
risk95_values
,
risk99_values
)
# if __name__ == '__main__':
# app.run()
\ No newline at end of file
if
__name__
==
"
__main__
"
:
main
()
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment