Skip to content

Sourcery refactored master branch #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

sourcery-ai[bot]
Copy link

@sourcery-ai sourcery-ai bot commented Nov 5, 2022

Branch master refactored by Sourcery.

If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.

See our documentation here.

Run Sourcery locally

Reduce the feedback loop during development by using the Sourcery editor plugin:

Review changes via command line

To manually merge these changes, make sure you're on the master branch, then run:

git fetch origin sourcery/master
git merge --ff-only FETCH_HEAD
git reset HEAD^

Help us improve this pull request!

@sourcery-ai sourcery-ai bot requested a review from Alpha-github November 5, 2022 06:00
@sourcery-ai
Copy link
Author

sourcery-ai bot commented Nov 5, 2022

Sourcery Code Quality Report

❌  Merging this PR will decrease code quality in the affected files by 0.90%.

Quality metrics Before After Change
Complexity 3.92 ⭐ 3.29 ⭐ -0.63 👍
Method Length 69.57 🙂 71.00 🙂 1.43 👎
Working memory 8.00 🙂 8.71 🙂 0.71 👎
Quality 68.69% 🙂 67.79% 🙂 -0.90% 👎
Other metrics Before After Change
Lines 87 82 -5
Changed files Quality Before Quality After Quality Change
request_final.py 68.69% 🙂 67.79% 🙂 -0.90% 👎

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Working Memory Quality Recommendation
request_final.py user 3 ⭐ 171 😞 12 😞 54.22% 🙂 Try splitting into smaller methods. Extract out complex expressions
request_final.py test 7 ⭐ 137 😞 10 😞 57.45% 🙂 Try splitting into smaller methods. Extract out complex expressions

Legend and Explanation

The emojis denote the absolute quality of the code:

  • ⭐ excellent
  • 🙂 good
  • 😞 poor
  • ⛔ very poor

The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request.


Please see our documentation here for details on how these metrics are calculated.

We are actively working on this report - lots more documentation and extra metrics to come!

Help us improve this quality report!

data_path = os.getcwd() + "/data.json"
data_path = f"{os.getcwd()}/data.json"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 9-9 refactored with the following changes:

@app.route(base_url + "/")
@app.route(f"{base_url}/")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function all refactored with the following changes:

Comment on lines -19 to +27
@app.route(base_url + "/people/<int:t>")
@app.route(f"{base_url}/people/<int:t>")
def specific_id(t):
with open (data_path, 'r') as f:
user_data= json.load(f)
return jsonify(error = None, message = "Object with ID %s is displayed" % t , data = user_data['data'][t-1])
return jsonify(
error=None,
message=f"Object with ID {t} is displayed",
data=user_data['data'][t - 1],
)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function specific_id refactored with the following changes:

Comment on lines -26 to -54
@app.route(base_url + "/people" , methods = ["POST","GET"])
@app.route(f"{base_url}/people", methods = ["POST","GET"])
def test():
if request.method == "POST":
if request.method == "GET":
with open(data_path, 'r') as f:
user_data = json.load(f)
#print (user_data)
return jsonify({"error":None, "message":"Here is the required data", "data":user_data['data']})
elif request.method == "POST":
a = request.json

with open(data_path, 'r') as f: #'r' - shows that the file should be read
user_data = json.load(f) #json.load - used to deserialize/decode(convert json to py)

if len(a) == 0:
return jsonify(error = "present", message = "empty json obj")
return jsonify(error = "present", message = "empty json obj")
if a in user_data['data']:
return jsonify(error = "present", message = "duplication")
else:
if a in user_data['data']:
return jsonify(error = "present", message = "duplication")
else:
user_data['data'].append(a) #append - used to add an info in the existing dict


user_data['data'].append(a) #append - used to add an info in the existing dict


with open(data_path,'w') as f:
json.dump(user_data,f) #json.dump- used to serialize/encode(converting py to json)
#json.dump is used to write data to a file.| json.dumps() is used to write to a python string
# dump-converts dict of python to obj in json file.| dumps-converts dict obj of py to json string format
return jsonify(error=None, message = "received sucesully")


elif request.method == "GET":
with open(data_path, 'r') as f:
user_data = json.load(f)
#print (user_data)
return jsonify({"error":None, "message":"Here is the required data", "data":user_data['data']})
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function test refactored with the following changes:

Comment on lines -57 to 88
@app.route(base_url + "/people/data/<int:i>" , methods = ["PUT" , "GET","DELETE"])
@app.route(f"{base_url}/people/data/<int:i>", methods = ["PUT" , "GET","DELETE"])
def user(i):
if request.method == "PUT":
request_data = request.json

if request.method == "DELETE":
with open(data_path , 'r') as f:
user_data = json.load(f)

user_data['data'][i-1].update(request_data)

with open(data_path,'w') as f:
json.dump(user_data,f)
return jsonify(error = None, message = "Latest Obj Updated")
#return jsonify(info = user_data['data'][i-1])

elif request.method == "DELETE":

with open(data_path , 'r') as f:
user_data = json.load(f)

user_data['data'].pop(i-1)

with open(data_path,'w') as f:
json.dump(user_data,f)
return jsonify(error = None, message = "Obj with ID %s is DELETED" % i )
#return jsonify(info = user_data['data'][i-1])


return jsonify(error = None, message=f"Obj with ID {i} is DELETED")
elif request.method == "GET":
with open(data_path , 'r') as f:
user_data = json.load(f)
return jsonify({"error":None, "message":"Here is the required data", "data":user_data['data']})
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function user refactored with the following changes:

This removes the following comments ( why? ):

#return jsonify(info = user_data['data'][i-1])

Comment on lines -90 to +85
@app.route(base_url + "/people/count")
@app.route(f"{base_url}/people/count")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function count refactored with the following changes:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

0 participants