Skip to content
This repository was archived by the owner on Oct 25, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions FEEDBACK.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
# Feedback

1. Your team:
2. Name of each individual participating:
3. How many unit tests were you able to pass?
1. Your team: GCU_CS
2. Name of each individual participating: Kyungchan Im and Gabriel Teixeira Lima Aracena
3. How many unit tests were you able to pass? 13
4. Document and describe any enhancements included to help the judges properly grade your submission.
- Example One
- Example Two
- Example Three
- We created a new function in the simple_data_tool.py file to map the regional disaster type. We saw the definitions of the region on top of the page that were not being utilized to we thought it would be a good idea to use it for something.
- We created a new function in the simple_data_tool.py file to map the regional total claim. We wanted to do further data analysis project for this competition, so we added extra function that we needed to calculate.
- We then created a jupyter notabook that enables the visualization of that data and implements some data analysis to our dataset. We initially thought about creating a neural network and implementing a deep learning program but the dataset is too small for that.
- We implemented a REST API in the application.py file that can be used to interact and access the data. We used it locally but one could use Postman to interact with it (that's what's more common in the industry)


5. Any feedback for the coding competition? Things you would like to see in future events?
We had a lot of fun completing it! I just think the project itself would be more descriptive, it took us the first hour just to understand what we were supposed to accomplish.

This form can also be emailed to [codingcompetition@statefarm.com](mailto:codingcompetition@statefarm.com). Just make sure that you include a link to your GitHub pull requests.
149 changes: 148 additions & 1 deletion python/application.py
Original file line number Diff line number Diff line change
@@ -1 +1,148 @@
print("I'm working")
# This is the implementation of our simple API to interact with the JSON data files
# We enabled GET for every JSON. 1 to access all the data e.g: '/claims' (this can be used when displaying a list)
# and another one to see one sepcific data e.g: 'claim/claim_id' (this can be used when searching for a data and looking for details)
# We also created PUT and POST for disasters and claims, we thought it would make sense to enable the creation and update of those
# One could use '/disasters' as a POST to create a new disaster and '/disaster/disaster_id' as a PUT to update an existing one

from flask import Flask, jsonify, request
import json

app = Flask(__name__)

# File paths
AGENTS_FILEPATH = 'data/sfcc_2023_agents.json'
CLAIM_HANDLERS_FILEPATH = 'data/sfcc_2023_claim_handlers.json'
CLAIMS_FILEPATH = 'data/sfcc_2023_claims.json'
DISASTERS_FILEPATH = 'data/sfcc_2023_disasters.json'

# Utility function to load data from a given filepath
def load_data(filepath):
with open(filepath, 'r') as file:
return json.load(file)

# Utility function to save data to a given filepath
def save_data(filepath, data):
with open(filepath, 'w') as file:
json.dump(data, file)

@app.route('/claims', methods=['GET'])
def get_claims():
return jsonify(load_data(CLAIMS_FILEPATH))

@app.route('/claim/<int:claim_id>', methods=['GET'])
def get_claim_by_id(claim_id):
claims = load_data(CLAIMS_FILEPATH)
claim = next((claim for claim in claims if claim["id"] == claim_id), None)

if claim:
return jsonify(claim)
else:
return jsonify({"error": f"No claim found with ID {claim_id}"}), 404

@app.route('/claims', methods=['POST'])
def add_claim():
claims = load_data(CLAIMS_FILEPATH)
new_claim = request.json
claims.append(new_claim)
save_data(CLAIMS_FILEPATH, claims)
return jsonify({"message": "New claim added successfully!"})

@app.route('/claims/<int:claim_id>', methods=['PUT'])
def update_claim(claim_id):
claims = load_data(CLAIMS_FILEPATH)
claim_to_update = next((claim for claim in claims if claim["id"] == claim_id), None)

if claim_to_update:
updated_data = request.json
for key, value in updated_data.items():
claim_to_update[key] = value
save_data(CLAIMS_FILEPATH, claims)
return jsonify({"message": f"Claim with ID {claim_id} updated successfully!"})
else:
return jsonify({"error": f"No claim found with ID {claim_id}"}), 404

@app.route('/claim_handlers', methods=['GET'])
def get_claim_handlers():
return jsonify(load_data(CLAIM_HANDLERS_FILEPATH))

@app.route('/claim_handler/<int:handler_id>', methods=['GET'])
def get_claim_handler_by_id(handler_id):
claim_handlers = load_data(CLAIM_HANDLERS_FILEPATH)
handler = next((handler for handler in claim_handlers if handler["id"] == handler_id), None)

if handler:
return jsonify(handler)
else:
return jsonify({"error": f"No claim handler found with ID {handler_id}"}), 404

@app.route('/agents', methods=['GET'])
def get_agents():
return jsonify(load_data(AGENTS_FILEPATH))

@app.route('/agent/<int:agent_id>', methods=['GET'])
def get_agent_by_id(agent_id):
agents = load_data(AGENTS_FILEPATH)
agent = next((agent for agent in agents if agent["id"] == agent_id), None)

if agent:
return jsonify(agent)
else:
return jsonify({"error": f"No agent found with ID {agent_id}"}), 404

@app.route('/disasters', methods=['GET'])
def get_disasters():
return jsonify(load_data(DISASTERS_FILEPATH))

@app.route('/disaster/<int:disaster_id>', methods=['GET'])
def get_disaster_by_id(disaster_id):
# Load existing disasters
disasters = load_data(DISASTERS_FILEPATH)

# Find the disaster with the specified ID
disaster = next((disaster for disaster in disasters if disaster["id"] == disaster_id), None)

if disaster:
return jsonify(disaster)
else:
return jsonify({"error": f"No disaster found with ID {disaster_id}"}), 404

@app.route('/disasters', methods=['POST'])
def add_disaster():
# Load existing disasters
disasters = load_data(DISASTERS_FILEPATH)

# Retrieve the new disaster data from the request
new_disaster = request.json

# Add the new disaster to the existing list
disasters.append(new_disaster)

# Save the updated disasters list back to the file
save_data(DISASTERS_FILEPATH, disasters)

return jsonify({"message": "New disaster added successfully!"})

@app.route('/disasters/<int:disaster_id>', methods=['PUT'])
def update_disaster(disaster_id):
# Load existing disasters
disasters = load_data(DISASTERS_FILEPATH)

# Find the disaster to update
disaster_to_update = next((disaster for disaster in disasters if disaster["id"] == disaster_id), None)

if disaster_to_update:
# Update the found disaster with data from the request
updated_data = request.json
for key, value in updated_data.items():
disaster_to_update[key] = value

# Save the updated disasters list back to the file
save_data(DISASTERS_FILEPATH, disasters)

return jsonify({"message": f"Disaster with ID {disaster_id} updated successfully!"})
else:
return jsonify({"error": f"No disaster found with ID {disaster_id}"}), 404


if __name__ == '__main__':
app.run(debug=True)
Loading