Sourcery Starbot ⭐ refactored anebz/boulder - #40
SourceryAI wants to merge 1 commit into
Conversation
| distances = [abs(current_min - _min) for _min in minutes] | ||
| closest_min = minutes[distances.index(min(distances))] | ||
| current_time = dt.replace(':'+str(current_min), ':'+str(closest_min)) | ||
| current_time = dt.replace(f':{current_min}', f':{str(closest_min)}') |
There was a problem hiding this comment.
Function get_current_time refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation) - Remove unnecessary calls to
str()from formatted values in f-strings (remove-str-from-fstring)
| st.markdown(f""" | ||
| Does your gym show this occupancy data? Make a PR yourself or let us know and we'll add your gym 😎\n | ||
| Created by [anebz](https://github.com/anebz) and [AnglinaBhambra](https://github.com/AnglinaBhambra).\n | ||
| Follow us! [](https://www.twitter.com/anebzt) | ||
| [](https://www.twitter.com/_AnglinaB)""") | ||
| st.markdown( | ||
| """\x1f Does your gym show this occupancy data? Make a PR yourself or let us know and we'll add your gym 😎\\n\x1f Created by [anebz](https://github.com/anebz) and [AnglinaBhambra](https://github.com/AnglinaBhambra).\\n\x1f Follow us! [](https://www.twitter.com/anebzt)\x1f [](https://www.twitter.com/_AnglinaB)""" | ||
| ) | ||
|
|
There was a problem hiding this comment.
Lines 121-125 refactored with the following changes:
- Replace f-string with no interpolated values with string (
remove-redundant-fstring)
|
|
||
| # admin-ajax.php not working | ||
| page = requests.get(url) | ||
| if page.status_code != 200: | ||
| return 0 | ||
| try: | ||
| occupancy = int(float(re.search(r'style="margin-left:(.*?)%"', page.text).group(1))) | ||
| occupancy = int(float(re.search(r'style="margin-left:(.*?)%"', page.text)[1])) |
There was a problem hiding this comment.
Function get_occupancy_boulderwelt refactored with the following changes:
- Replace m.group(x) with m[x] for re.Match objects (
use-getitem-for-re-match-groups)
| occupancy = int(re.search(r'left: (\d*)%', str(soup.find_all("div", class_="pointer-image")[0]['style'])).group(1)) | ||
| occupancy = int( | ||
| re.search( | ||
| r'left: (\d*)%', | ||
| str(soup.find_all("div", class_="pointer-image")[0]['style']), | ||
| )[1] | ||
| ) | ||
|
|
There was a problem hiding this comment.
Function get_occupancy_boulderado refactored with the following changes:
- Replace m.group(x) with m[x] for re.Match objects (
use-getitem-for-re-match-groups)
| frame_soup = BeautifulSoup(response.content, 'html.parser') | ||
| occupancy = re.search(r'left: (\d+)%', str(frame_soup)).group(1) | ||
| frame_soup = BeautifulSoup(response.content, 'html.parser') | ||
| occupancy = re.search(r'left: (\d+)%', str(frame_soup))[1] |
There was a problem hiding this comment.
Function get_occupancy_einstein refactored with the following changes:
- Replace m.group(x) with m[x] for re.Match objects (
use-getitem-for-re-match-groups)
| for n in range(8): | ||
| for _ in range(8): |
There was a problem hiding this comment.
Function Testget_missing_aquisition_timestamps.test_fill_nan refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore)
| for n in range(8): | ||
| for _ in range(8): |
There was a problem hiding this comment.
Function Testget_missing_aquisition_timestamps.test_drop_additional refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore)
| for n in range(8): | ||
| for _ in range(8): | ||
| drop = df.index[random.randint(0, len(df)-1)] | ||
| dropped.append(df.loc[drop]) | ||
| df = df.drop([drop]) | ||
|
|
||
| df2 = add_missing_timestamps(df, | ||
| interval='20min', | ||
| sample_start='07:20', | ||
| sample_end='23:40') | ||
| df2 = fill_nan_values(df2) | ||
| #get the values it recovered: | ||
| recovered=[] | ||
| for n, drop in enumerate(dropped): | ||
| recovered.append(df2[(df2.gym_name == drop.gym_name)& | ||
| (df2.current_time == drop.current_time)]) | ||
| recovered = [ | ||
| df2[ | ||
| (df2.gym_name == drop.gym_name) | ||
| & (df2.current_time == drop.current_time) | ||
| ] | ||
| for drop in dropped | ||
| ] | ||
|
|
There was a problem hiding this comment.
Function Testget_missing_aquisition_timestamps.test_correct_value_recovered refactored with the following changes:
- Convert for loop into list comprehension (
list-comprehension) - Replace unused for index with underscore (
for-index-underscore) - Remove unnecessary calls to
enumeratewhen the index is not used (remove-unused-enumerate)
| chart = alt.Chart(df).mark_line(interpolate='basis').encode( | ||
| x=alt.X('time:N', axis=alt.Axis(grid=True)), | ||
| y=alt.Y('occupancy:Q', scale=alt.Scale(domain=[0, 100])), | ||
| color=alt.Color("name:N") | ||
| return ( | ||
| alt.Chart(df) | ||
| .mark_line(interpolate='basis') | ||
| .encode( | ||
| x=alt.X('time:N', axis=alt.Axis(grid=True)), | ||
| y=alt.Y('occupancy:Q', scale=alt.Scale(domain=[0, 100])), | ||
| color=alt.Color("name:N"), | ||
| ) | ||
| ) | ||
| return chart |
There was a problem hiding this comment.
Function plot_data refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| # convert to numpy array | ||
| X_today = [np.asarray(today_data)] | ||
| return X_today | ||
| return [np.asarray(today_data)] |
There was a problem hiding this comment.
Function preprocess_current_data refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
This removes the following comments ( why? ):
# convert to numpy array
Thanks for starring sourcery-ai/sourcery ✨ 🌟 ✨
Here's your pull request refactoring your most popular Python repo.
If you want Sourcery to refactor all your Python repos and incoming pull requests install our bot.
Review changes via command line
To manually merge these changes, make sure you're on the
mainbranch, then run: