Skip to content

Conversation

@sourcery-ai
Copy link

@sourcery-ai sourcery-ai bot commented Aug 1, 2022

Branch main 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 main branch, then run:

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

Help us improve this pull request!

@sourcery-ai sourcery-ai bot requested a review from NipaDasGupta August 1, 2022 05:09
Comment on lines -62 to +64
print ("Quoted %s at (bid:%s, ask:%s, price:%s)" % (stock, bid_price, ask_price, price))
print(f"Quoted {stock} at (bid:{bid_price}, ask:{ask_price}, price:{price})")

print ("Ratio %s" % getRatio(prices['ABC'], prices['DEF']))
print(f"Ratio {getRatio(prices['ABC'], prices['DEF'])}")
Copy link
Author

Choose a reason for hiding this comment

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

Lines 62-64 refactored with the following changes:

REALTIME = True
SIM_LENGTH = timedelta(days = 365 * 5)
MARKET_OPEN = datetime.today().replace(hour = 0, minute = 30, second = 0)
MARKET_OPEN = datetime.now().replace(hour = 0, minute = 30, second = 0)
Copy link
Author

Choose a reason for hiding this comment

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

Lines 46-46 refactored with the following changes:

order, size, _ = buy[0]
new_book = clear_order(order, size, sell)
if new_book:
if new_book := clear_order(order, size, sell):
Copy link
Author

Choose a reason for hiding this comment

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

Function clear_book refactored with the following changes:

Comment on lines -194 to +204
if hasattr(handler, "__route__"):
if None != re.search(handler.__route__, req_handler.path):
req_handler.send_response(200)
req_handler.send_header('Content-Type', 'application/json')
req_handler.send_header('Access-Control-Allow-Origin', '*')
req_handler.end_headers()
params = read_params(req_handler.path)
data = json.dumps(handler(routes, params)) + '\n'
req_handler.wfile.write(bytes(data, encoding = 'utf-8'))
return
if (
hasattr(handler, "__route__")
and re.search(handler.__route__, req_handler.path) != None
):
req_handler.send_response(200)
req_handler.send_header('Content-Type', 'application/json')
req_handler.send_header('Access-Control-Allow-Origin', '*')
req_handler.end_headers()
params = read_params(req_handler.path)
data = json.dumps(handler(routes, params)) + '\n'
req_handler.wfile.write(bytes(data, encoding = 'utf-8'))
return
Copy link
Author

Choose a reason for hiding this comment

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

Function get refactored with the following changes:

Comment on lines -239 to +241
self._book_1 = dict()
self._book_2 = dict()
self._book_1 = {}
self._book_2 = {}
Copy link
Author

Choose a reason for hiding this comment

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

Function App.__init__ refactored with the following changes:

REALTIME = True
SIM_LENGTH = timedelta(days = 365 * 5)
MARKET_OPEN = datetime.today().replace(hour = 0, minute = 30, second = 0)
MARKET_OPEN = datetime.now().replace(hour = 0, minute = 30, second = 0)
Copy link
Author

Choose a reason for hiding this comment

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

Lines 46-46 refactored with the following changes:

order, size, _ = buy[0]
new_book = clear_order(order, size, sell)
if new_book:
if new_book := clear_order(order, size, sell):
Copy link
Author

Choose a reason for hiding this comment

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

Function clear_book refactored with the following changes:

Comment on lines -194 to +204
if hasattr(handler, "__route__"):
if None != re.search(handler.__route__, req_handler.path):
req_handler.send_response(200)
req_handler.send_header('Content-Type', 'application/json')
req_handler.send_header('Access-Control-Allow-Origin', '*')
req_handler.end_headers()
params = read_params(req_handler.path)
data = json.dumps(handler(routes, params)) + '\n'
req_handler.wfile.write(bytes(data, encoding = 'utf-8'))
return
if (
hasattr(handler, "__route__")
and re.search(handler.__route__, req_handler.path) != None
):
req_handler.send_response(200)
req_handler.send_header('Content-Type', 'application/json')
req_handler.send_header('Access-Control-Allow-Origin', '*')
req_handler.end_headers()
params = read_params(req_handler.path)
data = json.dumps(handler(routes, params)) + '\n'
req_handler.wfile.write(bytes(data, encoding = 'utf-8'))
return
Copy link
Author

Choose a reason for hiding this comment

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

Function get refactored with the following changes:

Comment on lines -239 to +241
self._book_1 = dict()
self._book_2 = dict()
self._book_1 = {}
self._book_2 = {}
Copy link
Author

Choose a reason for hiding this comment

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

Function App.__init__ refactored with the following changes:

Comment on lines -284 to +285
print ('Query received @ t%s' % t)
print(f'Query received @ t{t}')
Copy link
Author

Choose a reason for hiding this comment

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

Function App.handle_query refactored with the following changes:

@sourcery-ai
Copy link
Author

sourcery-ai bot commented Aug 1, 2022

Sourcery Code Quality Report

✅  Merging this PR will increase code quality in the affected files by 0.08%.

Quality metrics Before After Change
Complexity 3.23 ⭐ 3.06 ⭐ -0.17 👍
Method Length 56.46 ⭐ 56.49 ⭐ 0.03 👎
Working memory 6.97 🙂 7.01 🙂 0.04 👎
Quality 77.37% 77.45% 0.08% 👍
Other metrics Before After Change
Lines 775 778 3
Changed files Quality Before Quality After Quality Change
JPMC-tech-task-1-py3/client3.py 84.45% ⭐ 81.34% ⭐ -3.11% 👎
JPMC-tech-task-1-py3/server3.py 76.96% ⭐ 77.23% ⭐ 0.27% 👍
JPMC-tech-task-2-PY3/datafeed/server3.py 76.96% ⭐ 77.23% ⭐ 0.27% 👍
JPMC-tech-task-3-PY3/datafeed/server3.py 76.96% ⭐ 77.23% ⭐ 0.27% 👍

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

File Function Complexity Length Working Memory Quality Recommendation
JPMC-tech-task-1-py3/server3.py App.handle_query 8 ⭐ 179 😞 10 😞 52.27% 🙂 Try splitting into smaller methods. Extract out complex expressions
JPMC-tech-task-2-PY3/datafeed/server3.py App.handle_query 8 ⭐ 179 😞 10 😞 52.27% 🙂 Try splitting into smaller methods. Extract out complex expressions
JPMC-tech-task-3-PY3/datafeed/server3.py App.handle_query 8 ⭐ 179 😞 10 😞 52.27% 🙂 Try splitting into smaller methods. Extract out complex expressions
JPMC-tech-task-1-py3/server3.py get 4 ⭐ 97 🙂 12 😞 61.81% 🙂 Extract out complex expressions
JPMC-tech-task-2-PY3/datafeed/server3.py get 4 ⭐ 97 🙂 12 😞 61.81% 🙂 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!

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.

1 participant