Skip to content

Commit

Permalink
fix: make 801 more consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
terryyz committed May 4, 2024
1 parent 43ef655 commit 64208b5
Show file tree
Hide file tree
Showing 691 changed files with 722 additions and 3,563 deletions.
7 changes: 3 additions & 4 deletions data/clean/f_801_wenhao.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
import re


def f_801(text, seed=None):
def f_801(text, seed=0):
"""
Scramble the letters in each word of a given text, keeping the first and last letters of each word intact.
Parameters:
text (str): The text to be scrambled.
seed (int, optional): A seed for the random number generator to ensure reproducible results.
Defaults to None (not set).
Defaults to 0.
Returns:
str: The scrambled text.
Expand All @@ -28,8 +28,7 @@ def f_801(text, seed=None):
>>> f_801("Programming is fun, isn't it?", 42)
"Prmiangmrog is fun, isn't it?"
"""
if seed is not None:
random.seed(seed)
random.seed(seed)

def scramble_word(match):
word = match.group(0)
Expand Down
1,426 changes: 713 additions & 713 deletions data/open-eval.jsonl

Large diffs are not rendered by default.

Binary file modified data/open-eval.jsonl.gz
Binary file not shown.
5 changes: 0 additions & 5 deletions data/processed/f_1700_hanhu_wo_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,11 @@ def f_428(host):
"""
if not host:
raise ValueError("Host must be a non-empty string.")

try:
# Fetch IP address
ip_address = socket.gethostbyname(host)

# Fetch geolocation
response = requests.get(f"https://ipinfo.io/{ip_address}")
response.raise_for_status()
geolocation = response.json()

return {
'ip_address': ip_address,
'geolocation': geolocation
Expand Down
2 changes: 0 additions & 2 deletions data/processed/f_1708_hanhu_wo_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,10 @@ def f_335(request, session_expire_time):
- string
"""
session_key = ''.join(random.choices(string.ascii_letters + string.digits, k=20))

has_digit = any(char.isdigit() for char in session_key)
has_letter = any(char.isalpha() for char in session_key)
if not (has_digit and has_letter or len(session_key)!=20):
raise ValueError("Session key should contain both letters and digits")

response = HttpResponse('Session key generated successfully.')
response.set_cookie('session_key', session_key, max_age=session_expire_time)
return response
Expand Down
3 changes: 0 additions & 3 deletions data/processed/f_1709_hanhu_wo_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,7 @@ def f_288(data):
password = base64.b64decode(data['password']).decode()
except (KeyError, UnicodeDecodeError, binascii.Error, ValueError):
return HttpResponseBadRequest('Bad Request')

hashed_password = hashlib.sha256(password.encode()).digest()

# Dummy authentication logic
if username == 'admin' and hashed_password == hashlib.sha256('password'.encode()).digest():
return HttpResponse('Login successful.')
else:
Expand Down
2 changes: 0 additions & 2 deletions data/processed/f_1710_hanhu_wo_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,8 @@ def f_400(request, header, csv_data):
writer.writerow(header)
writer.writerows(csv_data)
csv_io.seek(0)

response = FileResponse(csv_io, as_attachment=True, filename='data.csv')
response['Content-Type'] = 'text/csv'

return response

import unittest
Expand Down
3 changes: 0 additions & 3 deletions data/processed/f_1711_hanhu_wo_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,12 @@ def f_236(request, file_paths):
'attachment; filename="files.zip"'
"""
zip_io = io.BytesIO()

with zipfile.ZipFile(zip_io, 'w') as zip_file:
for file_path in file_paths:
zip_file.writestr(file_path, 'This is the content of {}.'.format(file_path))

zip_io.seek(0) # Reset the file pointer to the start of the stream
response = FileResponse(zip_io, as_attachment=True, filename='files.zip')
response['Content-Type'] = 'application/zip'

return response

import unittest
Expand Down
3 changes: 0 additions & 3 deletions data/processed/f_1712_hanhu_wo_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,12 @@ def f_475(template_folder):
>>> 'POST' in app.url_map.bind('').match('/', method='POST')
False
"""

app = Flask(__name__, template_folder=template_folder)

@app.route('/', methods=['POST'])
def handle_post():
data = request.get_json()
logging.info(json.dumps(data))
return render_template('index.html', data=data)

return app

import unittest
Expand Down
3 changes: 0 additions & 3 deletions data/processed/f_1714_hanhu_wo_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,12 @@ def f_42(api_url, template_folder):
"""
app = Flask(__name__, template_folder=template_folder)
api = Api(app)

class DataResource(Resource):
def get(self):
response = requests.get(api_url)
data = response.json()
return data

api.add_resource(DataResource, '/data')

return app

import unittest
Expand Down
11 changes: 0 additions & 11 deletions data/processed/f_1715_hanhu_wo_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,46 +41,35 @@ def f_306(secret_key, template_folder):
>>> app.config['SECRET_KEY'] == 'mysecretkey'
True
"""

app = Flask(__name__, template_folder=template_folder)
app.config['SECRET_KEY'] = secret_key

login_manager.init_app(app)

class User(UserMixin):
def __init__(self, username, password):
self.id = username
self.password_hash = generate_password_hash(password)

def check_password(self, password):
return check_password_hash(self.password_hash, password)

@app.route('/login', methods=['GET', 'POST'])
def login():
form = LoginForm()
if form.validate_on_submit():
user = User(form.username.data, form.password.data)
login_user(user)
return redirect(url_for('protected'))

return render_template('login.html', form=form)

@app.route('/logout')
@login_required
def logout():
logout_user()
return redirect(url_for('login'))

@app.route('/protected')
@login_required
def protected():
return 'Logged in as: ' + current_user.id

# Mock user loader for testing
@login_manager.user_loader
def load_user(user_id):
return User(user_id, 'password')

return app

import unittest
Expand Down
4 changes: 0 additions & 4 deletions data/processed/f_1716_hanhu_wo_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,14 @@ def f_548(smtp_server, smtp_port, smtp_user, smtp_password, template_folder):
app.config['MAIL_USERNAME'] = smtp_user
app.config['MAIL_PASSWORD'] = smtp_password
app.config['MAIL_USE_TLS'] = True

mail = Mail()
mail.init_app(app)

@app.route('/send_mail')
def send_mail():
msg = Message('Hello', sender='[email protected]', recipients=['[email protected]'])
msg.body = 'Hello Flask message sent from Flask-Mail'
mail.send(msg)

return 'Mail sent!'

return app

import unittest
Expand Down
13 changes: 0 additions & 13 deletions data/processed/f_1723_hanhu_w_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,34 +40,21 @@ def f_503(data, column, outlier_z_score):
>>> isinstance(f_503(data, column, 3.0)[2], tuple)
True
"""
# Copy the data to avoid modifying the original array
data_copy = np.copy(data)
column_data = data_copy[:, column]

# Standardize the data to have a mean of 0 and a standard deviation of 1
scaler = StandardScaler()
standardized_data = scaler.fit_transform(column_data.reshape(-1, 1))

# Calculate the Z-scores
z_scores = np.abs(stats.zscore(standardized_data))

# Identify the outliers
outliers = np.where(z_scores > outlier_z_score)
data_without_outliers = np.delete(data_copy, outliers, axis=0)

# Plot the data before and after the removal of outliers
plt.figure(figsize=(10, 5))

plt.subplot(1, 2, 1)
plt.scatter(data_copy[:, 0], data_copy[:, 1])
plt.title('Data with Outliers')

plt.subplot(1, 2, 2)
plt.scatter(data_without_outliers[:, 0], data_without_outliers[:, 1])
plt.title('Data without Outliers')

plt.show()

return data_copy, data_without_outliers, outliers

import unittest
Expand Down
2 changes: 0 additions & 2 deletions data/processed/f_1728_hanhu_w_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,12 @@ def f_334(mean, std_dev, num_samples):
samples = np.random.normal(mean, std_dev, num_samples)
fig, ax = plt.subplots()
ax.hist(samples, bins=30, density=True, alpha=0.6, color='g')

xmin, xmax = ax.get_xlim()
x = np.linspace(xmin, xmax, 100)
p = norm.pdf(x, mean, std_dev)
ax.plot(x, p, 'k', linewidth=2)
title = "Fit results: mean = %.2f, std = %.2f" % (mean, std_dev)
ax.set_title(title)

return samples, fig

import unittest
Expand Down
3 changes: 0 additions & 3 deletions data/processed/f_1729_hanhu_wo_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,12 @@ def f_57(csv_file, csv_delimiter):
True
"""
words = []

with open(csv_file, 'r') as f:
reader = csv.reader(f, delimiter=csv_delimiter)
for row in reader:
words.extend(row)

word_counter = Counter(words)
most_common_words = sorted(word_counter.items(), key=operator.itemgetter(1), reverse=True)

return most_common_words

import unittest
Expand Down
2 changes: 0 additions & 2 deletions data/processed/f_1730_hanhu_w_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,11 @@ def f_230(numbers):
True
"""
sum_log_products = 0

for r in range(1, len(numbers) + 1):
combinations = itertools.combinations(numbers, r)
for combination in combinations:
product = reduce(lambda x, y: x * y, combination)
sum_log_products += math.log(product)

return sum_log_products

import unittest
Expand Down
1 change: 0 additions & 1 deletion data/processed/f_1731_hanhu_w_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ def f_415(num_strings, string_length):
characters = ''.join(strings)
character_counter = Counter(characters)
most_common_characters = character_counter.most_common()

return most_common_characters

import unittest
Expand Down
5 changes: 0 additions & 5 deletions data/processed/f_1749_hanhu_wo_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,16 @@ def f_478(my_dict, keys):
"""
if len(set(keys)) != 10:
raise ValueError("keys parameter must contain exactly 10 unique elements")

for key in keys:
my_dict[key] = random.randint(1, 100)

json_filename = "updated_dictionary.json"
txt_filename = "key_frequencies.txt"

with open(json_filename, 'w') as json_file:
json.dump(my_dict, json_file, indent=4)

key_counts = Counter(my_dict.keys())
with open(txt_filename, 'w') as txt_file:
for key, count in key_counts.items():
txt_file.write(f"{key}: {count}\n")

return my_dict, json_filename, txt_filename

import unittest
Expand Down
3 changes: 0 additions & 3 deletions data/processed/f_1750_hanhu_w_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,10 @@ def f_482(my_dict):
"""
if not isinstance(my_dict["array"], np.ndarray):
raise TypeError

SCALER = MinMaxScaler()
array = my_dict['array'].reshape(-1, 1)
normalized_array = SCALER.fit_transform(array).reshape(-1)

my_dict['normalized_array'] = normalized_array

return my_dict

import unittest
Expand Down
3 changes: 0 additions & 3 deletions data/processed/f_1753_hanhu_w_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,12 @@ def f_239(mu, sigma, sample_size):
True
"""
samples = np.random.normal(mu, sigma, sample_size)

# Plotting the histogram of the samples
plt.hist(samples, bins=30, alpha=0.75, color='blue')
plt.title('Histogram of Generated Samples')
plt.xlabel('Sample values')
plt.ylabel('Frequency')
plt.grid(True)
plt.show()

return samples

import unittest
Expand Down
3 changes: 0 additions & 3 deletions data/processed/f_1754_hanhu_wo_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,14 @@ def f_441(directory, backup_directory):
True
"""
copied_files = []

if not os.path.exists(backup_directory):
os.makedirs(backup_directory)

for filename in os.listdir(directory):
if filename.endswith('.json'):
src = os.path.join(directory, filename)
dst = os.path.join(backup_directory, filename)
shutil.copy(src, dst)
copied_files.append(dst)

return copied_files

import unittest
Expand Down
1 change: 0 additions & 1 deletion data/processed/f_1756_hanhu_w_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ def f_405():
"""
X = np.linspace(-10, 10, 400)
Y = X**2

plt.figure()
plt.plot(X, Y)
plt.title('y = x^2')
Expand Down
2 changes: 0 additions & 2 deletions data/processed/f_1759_hanhu_w_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,8 @@ def f_5(my_list):
"""
random_number = random.randint(0, 100)
my_list.append(random_number)

size = sum(my_list)
random_array = np.random.rand(size)

return random_array

import unittest
Expand Down
3 changes: 0 additions & 3 deletions data/processed/f_1763_hanhu_wo_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,12 @@ def f_199(LETTERS, n):
"""
combinations = list(itertools.combinations(LETTERS, n))
letter_counts = defaultdict(int)

for combination in combinations:
for letter in combination:
letter_counts[letter] += 1

filename = f'letter_combinations_{random.randint(1, 100)}.json'
with open(filename, 'w') as f:
json.dump(letter_counts, f)

return filename

import unittest
Expand Down
1 change: 0 additions & 1 deletion data/processed/f_1764_hanhu_wo_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ def f_668(ROOT_DIR, DEST_DIR, SPECIFIC_HASH):
True
"""
files_moved = 0

os.makedirs(DEST_DIR, exist_ok=True)
for filename in glob.glob(os.path.join(ROOT_DIR, '*')):
if not os.path.exists(filename) or os.path.isdir(filename):
Expand Down
Loading

0 comments on commit 64208b5

Please sign in to comment.