diff --git a/challenges/LukeGavelWork/README.txt b/challenges/LukeGavelWork/README.txt new file mode 100644 index 000000000..261339016 --- /dev/null +++ b/challenges/LukeGavelWork/README.txt @@ -0,0 +1,11 @@ +Hello, this is my work on the backend and database problem. + +It was the first time I coded API related software and was struggling to find +a way to test it while flask was running. I believe it is set up correctly, +but I'm not familiar enough with flask to trigger the post or get commands + +Next I have a layout of relational model version of the NOSQL model. Again, +not extremely familiar with databases so from looking at examples of relational database +I think I understand the gist: grouping data based on its relation with each other. +Apologies if I missed the mark on that. I did not have enough time to work on +the second half of the challenge. \ No newline at end of file diff --git a/challenges/LukeGavelWork/RelationalModel.PNG b/challenges/LukeGavelWork/RelationalModel.PNG new file mode 100644 index 000000000..d8e0d4e9d Binary files /dev/null and b/challenges/LukeGavelWork/RelationalModel.PNG differ diff --git a/challenges/LukeGavelWork/restAPI.py b/challenges/LukeGavelWork/restAPI.py new file mode 100644 index 000000000..41062d5bf --- /dev/null +++ b/challenges/LukeGavelWork/restAPI.py @@ -0,0 +1,32 @@ +from flask import Flask, request, jsonify + +restAPI = Flask(__name__) + +data_pool = [ + +] + + +@restAPI.post("/data") +def sendData(): + if type(request) != list: + return {"Error": "list of numbers not submitted"}, 415 + elif len(request) != 500: + return {"Error": "incorrect number of data entries"}, 415 + elif not(all(item.isdigit() for item in request)): + return {"Error": "list contains none numeric values"}, 415 + elif not(request.is_json): + return {"Error": "Request must be JSON"} , 415 + else: + data = request.get_json() + data["id"] = _find_next_id() + data_pool.append(data) + + +@restAPI.get("/data") +def getData(): + return jsonify(data_pool) + +#@restAPI.patch("/data") + + diff --git a/challenges/LukeGavelWork/restAPI_test.py b/challenges/LukeGavelWork/restAPI_test.py new file mode 100644 index 000000000..dc2525f56 --- /dev/null +++ b/challenges/LukeGavelWork/restAPI_test.py @@ -0,0 +1,16 @@ +from restAPI import restAPI +from flask import json +from random import randint + +def test_add(): + d = [] + for i in range(500): + d.append(i) + + + response = restAPI.test_client().post("/data", data = jsonify(d), content_type='application/json',) + + data = json.loads(response.get_data(as_test=True)) + + assert response.status_code == 200 + assert data['1'] == d diff --git a/interviews/python/Solve.py b/interviews/python/Solve.py index e69de29bb..3dc2eac09 100644 --- a/interviews/python/Solve.py +++ b/interviews/python/Solve.py @@ -0,0 +1,20 @@ +#values added to dictionary recursively to save some time over iterative +def encode(arr,dictionary,ind): + #if gone through whole array + if ind == len(arr): + return dictionary + #if the letter/number has been seen before and exists in dictionary, increase the value by 1 + elif arr[ind] in dictionary: + dictionary[arr[ind]] = dictionary.get(arr[ind]) + 1 + encode(arr,dictionary,ind+1) + #the value is not in the dictionary and therefore needs to be added + else: + dictionary[arr[ind]] = 1 + encode(arr,dictionary,ind+1) + +#empty dictionary and data set +dictionary = {} +data = ['t','t','t','t','b','c','c','a','a','d','r','r','r','r','d','y','x','x','y','j','q','u','i'] + +encode(data,dictionary,0) +print(dictionary)