Skip to content
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

feat: updated welcome file #227

Merged
merged 4 commits into from
Sep 26, 2023
Merged
Changes from 1 commit
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
98 changes: 73 additions & 25 deletions welcome-to-sourcery.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,76 @@

# Welcome to Sourcery!

# To get started log into your Sourcery account.
# Open the command palette (Ctrl/Cmd+Shift+P) and execute `Sourcery: login`.

# We're here to help you write cleaner, clearer code.
# When you log in to Sourcery you'll start to see parts
# of your code like this start to get underlined.
# This means Sourcery has a suggestion.
# Welcome to Sourcery! We're here to be your pair programmer
# anytime you're working in VS Code.

# To get started log into your Sourcery account. Click on
# the Sourcery logo (the hexagon) on your VS Code sidebar
# and click the button to log in.

# Or, open the command palette (Ctrl/Cmd+Shift+P) and
# execute `Sourcery: login`.
angrycaptain19 marked this conversation as resolved.
Show resolved Hide resolved

# Sourcery works in 2 ways:
# 1. Gives you instant suggestions for improvements and
# refactorings to your Python, JavaScript, and TypeScript
# code. All of this runs fully locally
angrycaptain19 marked this conversation as resolved.
Show resolved Hide resolved
# 2. Acts as a pair programmer allowing you to ask it
# questions, write new code, and interact with existing code.
angrycaptain19 marked this conversation as resolved.
Show resolved Hide resolved

# To start using the pair programmer seection of Sourcery,
# click the Sourcery sidebar option and clic the Opt In button.
angrycaptain19 marked this conversation as resolved.
Show resolved Hide resolved

# Now you can start asking Sourcery questions or asking it
# to interact with sections of your code. Let's take a look
# at a few examples:

# Above each function you'll see a few commands - these are
# Code Lenses that you can use to interact with Sourcery.
# Try clicking the "Ask Sourcery" Code Lens and asking it to
# update the code to use `dateutil`
angrycaptain19 marked this conversation as resolved.
Show resolved Hide resolved


def days_between_dates(date1, date2):
d1 = datetime.datetime.strptime(date1, '%Y-%m-%d').date()
d2 = datetime.datetime.strptime(date2, '%Y-%m-%d').date()
delta = d2 - d1
return delta.days

# With the Ask Sourcery command or the chat in the sidebar you
# can ask Sourcery questions, have it write new code for you, or
# update existing code.

# Sourcery has a series of built in "recipes" you can quickly use
# to interact with sections of code.

# Try clicking the Explain Code lens above this next function:
angrycaptain19 marked this conversation as resolved.
Show resolved Hide resolved

def calculate_weighted_moving_average(prices, weights):
if not prices or not weights:
raise ValueError("Both prices and weights must be provided.")

if len(weights) > len(prices):
raise ValueError("Length of weights must be less than or equal to length of prices.")

total_weight = sum(weights)
normalized_weights = [w / total_weight for w in weights]

wma = []
for i in range(len(prices) - len(weights) + 1):
weighted_sum = sum(prices[i + j] * normalized_weights[j] for j in range(len(weights)))
wma.append(weighted_sum)

return wma

# Now try clicking Generate Tests or Generate Docstrings for the
# same function!

# There are also recipes for Optimizing and Simplifying Code.
# You can access these by clicking Ask Sourcery and choosing them
# from the dropdown or by selecting a section of code and clicking
# the recipe button in the sidebar.

# In your code you'll also see sections start to get underlined.
# This means Sourcery has a suggestion to improve it.

def refactoring_example(spellbook):
result = []
Expand Down Expand Up @@ -53,25 +116,10 @@ def magical_hoist(magic):
# the VS Code window) to bring up the Sourcery Hub. Click on "Settings" and
# then you can toggle individual rule types on or off

# You can also have Sourcery review multiple files at once or check for
# duplicate code across your project. Right click on any file or folder
# in the Explorer window, choose the Sourcery menu item and choose
# "Scan for refactorings" or "Detect Clones".

# Both of these advanced features require you to login.
# Open the command palette (Ctrl/Cmd+Shift+P) and execute `Sourcery: login`.

# If you want to have Sourcery review more of your code at once you should check
# out the Sourcery CLI. Run `pip install sourcery-cli` to get started, then run
# `sourcery login` and finally run `sourcery review <path>` to have Sourcery
# check all of the files in that path

# For more details check out our documentation here:
# https://docs.sourcery.ai/

# Now open up some Python files and look out for the suggestions!

# Or if you want to play around a bit more, here are some more examples.
# If you want to play around a bit more, here are some more examples of Sourcery's in-line suggestions.
# These include cases where Sourcery has chained together suggestions to come
# up with more powerful refactorings.

Expand Down