text_prompt stringlengths 157 13.1k | code_prompt stringlengths 7 19.8k ⌀ |
|---|---|
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def rename(self, new_folder_name):
"""Renames the Folder to the provided name. Args: new_folder_name: A string of the replacement name. Raises: AuthError: Raised... |
headers = self.headers
endpoint = 'https://outlook.office.com/api/v2.0/me/MailFolders/' + self.id
payload = '{ "DisplayName": "' + new_folder_name + '"}'
r = requests.patch(endpoint, headers=headers, data=payload)
if check_response(r):
return_folder = r.json()
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_subfolders(self):
"""Retrieve all child Folders inside of this Folder. Raises: AuthError: Raised if Outlook returns a 401, generally caused by an invalid... |
headers = self.headers
endpoint = 'https://outlook.office.com/api/v2.0/me/MailFolders/' + self.id + '/childfolders'
r = requests.get(endpoint, headers=headers)
if check_response(r):
return self._json_to_folders(self.account, r.json()) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def delete(self):
"""Deletes this Folder. Raises: AuthError: Raised if Outlook returns a 401, generally caused by an invalid or expired access token. """ |
headers = self.headers
endpoint = 'https://outlook.office.com/api/v2.0/me/MailFolders/' + self.id
r = requests.delete(endpoint, headers=headers)
check_response(r) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def move_into(self, destination_folder):
# type: (Folder) -> None """Move the Folder into a different folder. This makes the Folder provided a child folder of th... |
headers = self.headers
endpoint = 'https://outlook.office.com/api/v2.0/me/MailFolders/' + self.id + '/move'
payload = '{ "DestinationId": "' + destination_folder.id + '"}'
r = requests.post(endpoint, headers=headers, data=payload)
if check_response(r):
return_folde... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def create_child_folder(self, folder_name):
"""Creates a child folder within the Folder it is called from and returns the new Folder object. Args: folder_name: T... |
headers = self.headers
endpoint = 'https://outlook.office.com/api/v2.0/me/MailFolders/' + self.id + '/childfolders'
payload = '{ "DisplayName": "' + folder_name + '"}'
r = requests.post(endpoint, headers=headers, data=payload)
if check_response(r):
return_folder = ... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def gformat(val, length=11):
"""Format a number with '%g'-like format, except that a) the length of the output string will be the requested length. b) positive n... |
try:
expon = int(log10(abs(val)))
except (OverflowError, ValueError):
expon = 0
length = max(length, 7)
form = 'e'
prec = length - 7
if abs(expon) > 99:
prec -= 1
elif ((expon > 0 and expon < (prec+4)) or
(expon <= 0 and -expon < (prec-1))):
form = ... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
| def pack(window, sizer, expand=1.1):
"simple wxPython pack function"
tsize = window.GetSize()
msize = window.GetMinSize()
window.SetSizer(sizer)
sizer.Fit(window)
nsize = (10*int(expand*(max(msize[0], tsize[0])/10)),
10*int(expand*(max(msize[1], tsize[1])/10.)))
window.SetSize... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def Setup(self, event=None):
"""set up figure for printing. Using the standard wx Printer Setup Dialog. """ |
if hasattr(self, 'printerData'):
data = wx.PageSetupDialogData()
data.SetPrintData(self.printerData)
else:
data = wx.PageSetupDialogData()
data.SetMarginTopLeft( (15, 15) )
data.SetMarginBottomRight( (15, 15) )
dlg = wx.PageSetupDialog(None,... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def Preview(self, title=None, event=None):
""" generate Print Preview with wx Print mechanism""" |
if title is None:
title = self.title
if self.canvas is None:
self.canvas = self.parent.canvas
po1 = PrintoutWx(self.parent.canvas, title=title,
width=self.pwidth, margin=self.pmargin)
po2 = PrintoutWx(self.parent.canvas, title=title... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def set_float(val):
""" utility to set a floating value, useful for converting from strings """ |
out = None
if not val in (None, ''):
try:
out = float(val)
except ValueError:
return None
if numpy.isnan(out):
out = default
return out |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
| def SetAction(self, action, **kws):
"set callback action"
if hasattr(action,'__call__'):
self.__action = Closure(action, **kws) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
| def __GetMark(self):
" keep track of cursor position within text"
try:
self.__mark = min(wx.TextCtrl.GetSelection(self)[0],
len(wx.TextCtrl.GetValue(self).strip()))
except:
self.__mark = 0 |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
| def __SetMark(self, mark=None):
"set mark for later"
if mark is None:
mark = self.__mark
self.SetSelection(mark, mark) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
| def SetValue(self, value=None, act=True):
" main method to set value "
if value is None:
value = wx.TextCtrl.GetValue(self).strip()
self.__CheckValid(value)
self.__GetMark()
if value is not None:
wx.TextCtrl.SetValue(self, self.format % set_float(value))
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def OnChar(self, event):
""" on Character event""" |
key = event.GetKeyCode()
entry = wx.TextCtrl.GetValue(self).strip()
pos = wx.TextCtrl.GetSelection(self)
# really, the order here is important:
# 1. return sends to ValidateEntry
if key == wx.WXK_RETURN:
if not self.is_valid:
wx.TextCtrl.S... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
| def __CheckValid(self, value):
"check for validity of value"
val = self.__val
self.is_valid = True
try:
val = set_float(value)
if self.__min is not None and (val < self.__min):
self.is_valid = False
val = self.__min
if s... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def add_text(self, text, x, y, side='left', size=None, rotation=None, ha='left', va='center', family=None, **kws):
"""add text at supplied x, y position""" |
axes = self.axes
if side == 'right':
axes = self.get_right_axes()
dynamic_size = False
if size is None:
size = self.conf.legendfont.get_size()
dynamic_size = True
t = axes.text(x, y, text, ha=ha, va=va, size=size,
rotatio... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def add_arrow(self, x1, y1, x2, y2, side='left', shape='full', color='black', width=0.01, head_width=0.03, overhang=0, **kws):
"""add arrow supplied x, y positio... |
dx, dy = x2-x1, y2-y1
axes = self.axes
if side == 'right':
axes = self.get_right_axes()
axes.arrow(x1, y1, dx, dy, shape=shape,
length_includes_head=True,
fc=color, edgecolor=color,
width=width, head_width=head_width,... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
| def set_xylims(self, limits, axes=None, side='left'):
"set user-defined limits and apply them"
if axes is None:
axes = self.axes
if side == 'right':
axes = self.get_right_axes()
self.conf.user_limits[axes] = limits
self.unzoom_all() |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
| def toggle_deriv(self, evt=None, value=None):
"toggle derivative of data"
if value is None:
self.conf.data_deriv = not self.conf.data_deriv
expr = self.conf.data_expr or ''
if self.conf.data_deriv:
expr = "deriv(%s)" % expr
self.write_mess... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
| def toggle_legend(self, evt=None, show=None):
"toggle legend display"
if show is None:
show = not self.conf.show_legend
self.conf.show_legend = show
self.conf.draw_legend() |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
| def toggle_grid(self, evt=None, show=None):
"toggle grid display"
if show is None:
show = not self.conf.show_grid
self.conf.enable_grid(show) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def configure(self, event=None):
"""show configuration frame""" |
if self.win_config is not None:
try:
self.win_config.Raise()
except:
self.win_config = None
if self.win_config is None:
self.win_config = PlotConfigFrame(parent=self,
config=self.conf,
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _updateCanvasDraw(self):
""" Overload of the draw function that update axes position before each draw""" |
fn = self.canvas.draw
def draw2(*a,**k):
self._updateGridSpec()
return fn(*a,**k)
self.canvas.draw = draw2 |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_default_margins(self):
"""get default margins""" |
trans = self.fig.transFigure.inverted().transform
# Static margins
l, t, r, b = self.axesmargins
(l, b), (r, t) = trans(((l, b), (r, t)))
# Extent
dl, dt, dr, db = 0, 0, 0, 0
for i, ax in enumerate(self.fig.get_axes()):
(x0, y0),(x1, y1) = ax.get_po... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def update_line(self, trace, xdata, ydata, side='left', draw=False, update_limits=True):
""" update a single trace, for faster redraw """ |
x = self.conf.get_mpl_line(trace)
x.set_data(xdata, ydata)
datarange = [xdata.min(), xdata.max(), ydata.min(), ydata.max()]
self.conf.set_trace_datarange(datarange, trace=trace)
axes = self.axes
if side == 'right':
axes = self.get_right_axes()
if up... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
| def get_userid_by_email(self, email):
''' get userid by email '''
response, status_code = self.__pod__.Users.get_v2_user(
sessionToken=self.__session__,
email=email
).result()
self.logger.debug('%s: %s' % (status_code, response))
return status_code, respon... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
| def get_user_id_by_user(self, username):
''' get user id by username '''
response, status_code = self.__pod__.Users.get_v2_user(
sessionToken=self.__session__,
username=username
).result()
self.logger.debug('%s: %s' % (status_code, response))
return status... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
| def get_user_by_userid(self, userid):
''' get user by user id '''
response, status_code = self.__pod__.Users.get_v2_user(
sessionToken=self.__session__,
uid=userid
).result()
self.logger.debug('%s: %s' % (status_code, response))
return status_code, respons... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
| def get_user_presence(self, userid):
''' check on presence of a user '''
response, status_code = self.__pod__.Presence.get_v2_user_uid_presence(
sessionToken=self.__session__,
uid=userid
).result()
self.logger.debug('%s: %s' % (status_code, response))
retu... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
| def set_user_presence(self, userid, presence):
''' set presence of user '''
response, status_code = self.__pod__.Presence.post_v2_user_uid_presence(
sessionToken=self.__session__,
uid=userid,
presence=presence
).result()
self.logger.debug('%s: %s' % (s... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
| def list_features(self):
''' list features the pod supports '''
response, status_code = self.__pod__.System.get_v1_admin_system_features_list(
sessionToken=self.__session__
).result()
self.logger.debug('%s: %s' % (status_code, response))
return status_code, response |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
| def user_feature_update(self, userid, payload):
''' update features by user id '''
response, status_code = self.__pod__.User.post_v1_admin_user_uid_features_update(
sessionToken=self.__session__,
uid=userid,
payload=payload
).result()
self.logger.debug... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
| def get_user_avatar(self, userid):
''' get avatar by user id '''
response, status_code = self.__pod__.User.get_v1_admin_user_uid_avatar(
sessionToken=self.__session,
uid=userid
).result()
self.logger.debug('%s: %s' % (status_code, response))
return status_... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
| def user_avatar_update(self, userid, payload):
''' updated avatar by userid '''
response, status_code = self.__pod__.User.post_v1_admin_user_uid_avatar_update(
sessionToken=self.__session,
uid=userid,
payload=payload
).result()
self.logger.debug('%s: %... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
| def stream_members(self, stream_id):
''' get stream members '''
response, status_code = self.__pod__.Streams.get_v1_admin_stream_id_membership_list(
sessionToken=self.__session__,
id=stream_id
).result()
self.logger.debug('%s: %s' % (status_code, response))
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
| def connection_status(self, userid):
''' get connection status '''
response, status_code = self.__pod__.Connection.get_v1_connection_user_userId_info(
sessionToken=self.__session__,
userId=userid
).result()
self.logger.debug('%s: %s' % (status_code, response))
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
| def ib_group_member_list(self, group_id):
''' ib group member list '''
req_hook = 'pod/v1/admin/group/' + group_id + '/membership/list'
req_args = None
status_code, response = self.__rest__.GET_query(req_hook, req_args)
self.logger.debug('%s: %s' % (status_code, response))
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
| def ib_group_member_add(self, group_id, userids):
''' ib group member add '''
req_hook = 'pod/v1/admin/group/' + group_id + '/membership/add'
req_args = {'usersListId': userids}
req_args = json.dumps(req_args)
status_code, response = self.__rest__.POST_query(req_hook, req_args)
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
| def ib_group_policy_list(self):
''' ib group policy list '''
req_hook = 'pod/v1/admin/policy/list'
req_args = None
status_code, response = self.__rest__.GET_query(req_hook, req_args)
self.logger.debug('%s: %s' % (status_code, response))
return status_code, response |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def start_monitoring(self):
"""Enable periodically monitoring. """ |
if self.__monitoring is False:
self.__monitoring = True
self.__monitoring_action() |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
| def parse_MML(self, mml):
''' parse the MML structure '''
hashes_c = []
mentions_c = []
soup = BeautifulSoup(mml, "lxml")
hashes = soup.find_all('hash', {"tag": True})
for hashe in hashes:
hashes_c.append(hashe['tag'])
mentions = soup.find_all('mention... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
| def create_room(self, payload):
''' create a stream in a non-inclusive manner '''
response, status_code = self.__pod__.Streams.post_v2_room_create(
# V2RoomAttributes
payload=payload
).result()
self.logger.debug('%s: %s' % (status_code, response))
return s... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
| def stream_info(self, stream_id):
''' get stream info '''
response, status_code = self.__pod__.Streams.get_v2_room_id_info(
sessionToken=self.__session__,
id=stream_id
).result()
self.logger.debug('%s: %s' % (status_code, response))
return status_code, res... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
| def create_stream(self, uidList=[]):
''' create a stream '''
req_hook = 'pod/v1/im/create'
req_args = json.dumps(uidList)
status_code, response = self.__rest__.POST_query(req_hook, req_args)
self.logger.debug('%s: %s' % (status_code, response))
return status_code, respons... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
| def update_room(self, stream_id, room_definition):
''' update a room definition '''
req_hook = 'pod/v2/room/' + str(stream_id) + '/update'
req_args = json.dumps(room_definition)
status_code, response = self.__rest__.POST_query(req_hook, req_args)
self.logger.debug('%s: %s' % (sta... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
| def room_members(self, stream_id):
''' get list of room members '''
req_hook = 'pod/v2/room/' + str(stream_id) + '/membership/list'
req_args = None
status_code, response = self.__rest__.GET_query(req_hook, req_args)
self.logger.debug('%s: %s' % (status_code, response))
re... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
| def promote_owner(self, stream_id, user_id):
''' promote user to owner in stream '''
req_hook = 'pod/v1/room/' + stream_id + '/membership/promoteOwner'
req_args = '{ "id": %s }' % user_id
status_code, response = self.__rest__.POST_query(req_hook, req_args)
self.logger.debug('%s: ... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
| def list_streams(self, types=[], inactive=False):
''' list user streams '''
req_hook = 'pod/v1/streams/list'
json_query = {
"streamTypes": types,
"includeInactiveStreams": inactive
}
req_args = json.dumps(json_query)
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_unverified_claims(token):
"""Returns the decoded claims without verification of any kind. Args: token (str):
A signed JWT to decode the headers from. Re... |
try:
claims = jws.get_unverified_claims(token)
except:
raise JWTError('Error decoding token claims.')
try:
claims = json.loads(claims.decode('utf-8'))
except ValueError as e:
raise JWTError('Invalid claims string: %s' % e)
if not isinstance(claims, Mapping):
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _validate_at_hash(claims, access_token, algorithm):
""" Validates that the 'at_hash' parameter included in the claims matches with the access_token returned ... |
if 'at_hash' not in claims and not access_token:
return
elif 'at_hash' in claims and not access_token:
msg = 'No access_token provided to compare against at_hash claim.'
raise JWTClaimsError(msg)
elif access_token and 'at_hash' not in claims:
msg = 'at_hash claim missing fro... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
| def get_session_token(self):
''' get session token '''
# HTTP POST query to session authenticate API
try:
response = requests.post(self.__session_url__ + 'sessionauth/v1/authenticate',
cert=(self.__crt__, self.__key__), verify=True)
except... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
| def solar_spectrum(model='SOLAR-ISS'):
r'''Returns the solar spectrum of the sun according to the specified model.
Only the 'SOLAR-ISS' model is supported.
Parameters
----------
model : str, optional
The model to use; 'SOLAR-ISS' is the only model available, [-]
Returns
-------
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
| def qmax_boiling(rhol=None, rhog=None, sigma=None, Hvap=None, D=None, P=None,
Pc=None, Method=None, AvailableMethods=False):
r'''This function handles the calculation of nucleate boiling critical
heat flux and chooses the best method for performing the calculation.
Preferred methods a... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
| def Nu_vertical_cylinder(Pr, Gr, L=None, D=None, Method=None,
AvailableMethods=False):
r'''This function handles choosing which vertical cylinder free convection
correlation is used. Generally this is used by a helper class, but can be
used directly. Will automatically select the co... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
| def Nu_horizontal_cylinder(Pr, Gr, Method=None, AvailableMethods=False):
r'''This function handles choosing which horizontal cylinder free convection
correlation is used. Generally this is used by a helper class, but can be
used directly. Will automatically select the correlation to use if none is
provi... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
| def calc_Cmin(mh, mc, Cph, Cpc):
r'''Returns the heat capacity rate for the minimum stream
having flows `mh` and `mc`, with averaged heat capacities `Cph` and `Cpc`.
.. math::
C_c = m_cC_{p,c}
C_h = m_h C_{p,h}
C_{min} = \min(C_c, C_h)
Parameters
----------
mh : float... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
| def calc_Cmax(mh, mc, Cph, Cpc):
r'''Returns the heat capacity rate for the maximum stream
having flows `mh` and `mc`, with averaged heat capacities `Cph` and `Cpc`.
.. math::
C_c = m_cC_{p,c}
C_h = m_h C_{p,h}
C_{max} = \max(C_c, C_h)
Parameters
----------
mh : float... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
| def calc_Cr(mh, mc, Cph, Cpc):
r'''Returns the heat capacity rate ratio for a heat exchanger
having flows `mh` and `mc`, with averaged heat capacities `Cph` and `Cpc`.
.. math::
C_r=C^*=\frac{C_{min}}{C_{max}}
Parameters
----------
mh : float
Mass flow rate of hot stream, [kg/s... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
| def Pc(x, y):
r'''Basic helper calculator which accepts a transformed R1 and NTU1 as
inputs for a common term used in the calculation of the P-NTU method for
plate exchangers.
Returns a value which is normally used in other calculations before the
actual P1 is calculated. Nominally used in c... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
| def _NTU_from_P_solver(P1, R1, NTU_min, NTU_max, function, **kwargs):
'''Private function to solve the P-NTU method backwards, given the
function to use, the upper and lower NTU bounds for consideration,
and the desired P1 and R1 values.
'''
P1_max = _NTU_from_P_objective(NTU_max, R1, 0, function, *... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
| def _NTU_max_for_P_solver(data, R1):
'''Private function to calculate the upper bound on the NTU1 value in the
P-NTU method. This value is calculated via a pade approximation obtained
on the result of a global minimizer which calculated the maximum P1
at a given R1 from ~1E-7 to approximately 100. This ... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
| def Ntubes_VDI(DBundle=None, Ntp=None, Do=None, pitch=None, angle=30.):
r'''A rough equation presented in the VDI Heat Atlas for estimating
the number of tubes in a tube bundle of differing geometries and tube
sizes. No accuracy estimation given.
Parameters
----------
DBundle : float
Ou... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
| def D_for_Ntubes_VDI(N, Ntp, Do, pitch, angle=30):
r'''A rough equation presented in the VDI Heat Atlas for estimating
the size of a tube bundle from a given number of tubes, number of tube
passes, outer tube diameter, pitch, and arrangement.
No accuracy estimation given.
.. math::
OTL = \s... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
| def Ntubes_HEDH(DBundle=None, Do=None, pitch=None, angle=30):
r'''A rough equation presented in the HEDH for estimating
the number of tubes in a tube bundle of differing geometries and tube
sizes. No accuracy estimation given. Only 1 pass is supported.
.. math::
N = \frac{0.78(D_{bundle} - D_o)... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
| def DBundle_for_Ntubes_HEDH(N, Do, pitch, angle=30):
r'''A rough equation presented in the HEDH for estimating the tube bundle
diameter necessary to fit a given number of tubes.
No accuracy estimation given. Only 1 pass is supported.
.. math::
D_{bundle} = (D_o + (\text{pitch})\sqrt{\frac{1}{0... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
| def setup(self,
data,
view='hypergrid',
schema=None,
columns=None,
rowpivots=None,
columnpivots=None,
aggregates=None,
sort=None,
index='',
limit=-1,
computedcolumns=... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
| def R_cylinder(Di, Do, k, L):
r'''Returns the thermal resistance `R` of a cylinder of constant thermal
conductivity `k`, of inner and outer diameter `Di` and `Do`, and with a
length `L`.
.. math::
(hA)_{\text{cylinder}}=\frac{k}{\ln(D_o/D_i)} \cdot 2\pi L\\
R_{\text{cylinder}}=\frac{1}{... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
| def S_isothermal_pipe_to_isothermal_pipe(D1, D2, W, L=1.):
r'''Returns the Shape factor `S` of a pipe of constant outer temperature
and of outer diameter `D1` which is `w` distance from another infinite
pipe of outer diameter`D2`. Length `L` must be provided, but can be set to
1 to obtain a dimensionles... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
| def S_isothermal_pipe_to_two_planes(D, Z, L=1.):
r'''Returns the Shape factor `S` of a pipe of constant outer temperature
and of outer diameter `D` which is `Z` distance from two infinite
isothermal planes of equal temperatures, parallel to each other and
enclosing the pipe. Length `L` must be provided,... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
| def S_isothermal_pipe_eccentric_to_isothermal_pipe(D1, D2, Z, L=1.):
r'''Returns the Shape factor `S` of a pipe of constant outer temperature
and of outer diameter `D1` which is `Z` distance from the center of another
pipe of outer diameter`D2`. Length `L` must be provided, but can be set to
1 to obtain... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
| def LMTD(Thi, Tho, Tci, Tco, counterflow=True):
r'''Returns the log-mean temperature difference of an ideal counterflow
or co-current heat exchanger.
.. math::
\Delta T_{LMTD}=\frac{\Delta T_1-\Delta T_2}{\ln(\Delta T_1/\Delta T_2)}
\text{For countercurrent: } \\
\Delta T_1=T_... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def k2g(kml_path, output_dir, separate_folders, style_type, style_filename):
""" Given a path to a KML file, convert it to a a GeoJSON FeatureCollection file and... |
m.convert(kml_path, output_dir, separate_folders, style_type, style_filename) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def disambiguate(names, mark='1'):
""" Given a list of strings ``names``, return a new list of names where repeated names have been disambiguated by repeatedly a... |
names_seen = set()
new_names = []
for name in names:
new_name = name
while new_name in names_seen:
new_name += mark
new_names.append(new_name)
names_seen.add(new_name)
return new_names |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def build_rgb_and_opacity(s):
""" Given a KML color string, return an equivalent RGB hex color string and an opacity float rounded to 2 decimal places. EXAMPLE::... |
# Set defaults
color = '000000'
opacity = 1
if s.startswith('#'):
s = s[1:]
if len(s) == 8:
color = s[6:8] + s[4:6] + s[2:4]
opacity = round(int(s[0:2], 16)/256, 2)
elif len(s) == 6:
color = s[4:6] + s[2:4] + s[0:2]
elif len(s) == 3:
color = s[::-1]
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def build_svg_style(node):
""" Given a DOM node, grab its top-level Style nodes, convert every one into a SVG style dictionary, put them in a master dictionary o... |
d = {}
for item in get(node, 'Style'):
style_id = '#' + attr(item, 'id')
# Create style properties
props = {}
for x in get(item, 'PolyStyle'):
color = val(get1(x, 'color'))
if color:
rgb, opacity = build_rgb_and_opacity(color)
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def wait_for_available(self, locator):
""" Synchronization to deal with elements that are present, and are visible :raises: ElementVisiblityTimeout """ |
for i in range(timeout_seconds):
try:
if self.is_element_available(locator):
break
except:
pass
time.sleep(1)
else:
raise ElementVisiblityTimeout("%s availability timed out" % locator)
return Tru... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def wait_for_visible(self, locator):
""" Synchronization to deal with elements that are present, but are disabled until some action triggers their visibility. :r... |
for i in range(timeout_seconds):
try:
if self.driver.is_visible(locator):
break
except:
pass
time.sleep(1)
else:
raise ElementVisiblityTimeout("%s visibility timed out" % locator)
return True |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def wait_for_text(self, locator, text):
""" Synchronization on some text being displayed in a particular element. :raises: ElementVisiblityTimeout """ |
for i in range(timeout_seconds):
try:
e = self.driver.find_element_by_locator(locator)
if e.text == text:
break
except:
pass
time.sleep(1)
else:
raise ElementTextTimeout("%s value timed o... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def wait_for_element_not_present(self, locator):
""" Synchronization helper to wait until some element is removed from the page :raises: ElementVisiblityTimeout ... |
for i in range(timeout_seconds):
if self.driver.is_element_present(locator):
time.sleep(1)
else:
break
else:
raise ElementVisiblityTimeout("%s presence timed out" % locator)
return True |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def validate(tool_class, model_class):
""" Does basic ObjectTool option validation. """ |
if not hasattr(tool_class, 'name'):
raise ImproperlyConfigured("No 'name' attribute found for tool %s." % (
tool_class.__name__
))
if not hasattr(tool_class, 'label'):
raise ImproperlyConfigured("No 'label' attribute found for tool %s." % (
tool_class.__name__
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def construct_form(self, request):
""" Constructs form from POST method using self.form_class. """ |
if not hasattr(self, 'form_class'):
return None
if request.method == 'POST':
form = self.form_class(self.model, request.POST, request.FILES)
else:
form = self.form_class(self.model)
return form |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def has_permission(self, user):
""" Returns True if the given request has permission to use the tool. Can be overriden by the user in subclasses. """ |
return user.has_perm(
self.model._meta.app_label + '.' + self.get_permission()
) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def media(self, form):
""" Collects admin and form media. """ |
js = ['admin/js/core.js', 'admin/js/admin/RelatedObjectLookups.js',
'admin/js/jquery.min.js', 'admin/js/jquery.init.js']
media = forms.Media(
js=['%s%s' % (settings.STATIC_URL, u) for u in js],
)
if form:
for name, field in form.fields.items():
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _urls(self):
""" URL patterns for tool linked to _view method. """ |
info = (
self.model._meta.app_label, self.model._meta.model_name,
self.name,
)
urlpatterns = [
url(r'^%s/$' % self.name, self._view, name='%s_%s_%s' % info)
]
return urlpatterns |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def construct_context(self, request):
""" Builds context with various required variables. """ |
opts = self.model._meta
app_label = opts.app_label
object_name = opts.object_name.lower()
form = self.construct_form(request)
media = self.media(form)
context = {
'user': request.user,
'title': '%s %s' % (self.label, opts.verbose_name_plural.lowe... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _view(self, request, extra_context=None):
""" View wrapper taking care of houskeeping for painless form rendering. """ |
if not self.has_permission(request.user):
raise PermissionDenied
return self.view(request, self.construct_context(request)) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def randomRow(self):
""" Gets a random row from the provider :returns: List """ |
l = []
for row in self.data:
l.append(row)
return random.choice(l) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def verify_equal(self, first, second, msg=""):
""" Soft assert for equality :params want: the value to compare against :params second: the value to compare with ... |
try:
self.assert_equal(first, second, msg)
except AssertionError, e:
if msg:
m = "%s:\n%s" % (msg, str(e))
else:
m = str(e)
self.verification_erorrs.append(m) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def verify_not_equal(self, first, second, msg=""):
""" Soft assert for inequality :params want: the value to compare against :params second: the value to compare... |
try:
self.assert_not_equal(first, second, msg)
except AssertionError, e:
if msg:
m = "%s:\n%s" % (msg, str(e))
else:
m = str(e)
self.verification_erorrs.append(m) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def verify_true(self, expr, msg=None):
""" Soft assert for whether the condition is true :params expr: the statement to evaluate :params msg: (Optional) msg expl... |
try:
self.assert_true(expr, msg)
except AssertionError, e:
if msg:
m = "%s:\n%s" % (msg, str(e))
else:
m = str(e)
self.verification_erorrs.append(m) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def verify_false(self, expr, msg=None):
""" Soft assert for whether the condition is false :params expr: the statement to evaluate :params msg: (Optional) msg ex... |
try:
self.assert_false(expr, msg)
except AssertionError, e:
if msg:
m = "%s:\n%s" % (msg, str(e))
else:
m = str(e)
self.verification_erorrs.append(m) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def verify_is(self, first, second, msg=None):
""" Soft assert for whether the parameters evaluate to the same object :params want: the object to compare against ... |
try:
self.assert_is(first, second, msg)
except AssertionError, e:
if msg:
m = "%s:\n%s" % (msg, str(e))
else:
m = str(e)
self.verification_erorrs.append(m) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def verify_is_not(self, first, second, msg=None):
""" Soft assert for whether the parameters do not evaluate to the same object :params want: the object to compa... |
try:
self.assert_is_not(first, second, msg)
except AssertionError, e:
if msg:
m = "%s:\n%s" % (msg, str(e))
else:
m = str(e)
self.verification_erorrs.append(m) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def verify_is_none(self, expr, msg=None):
""" Soft assert for whether the expr is None :params want: the object to compare against :params second: the object to ... |
try:
self.assert_is_none(expr, msg)
except AssertionError, e:
if msg:
m = "%s:\n%s" % (msg, str(e))
else:
m = str(e)
self.verification_erorrs.append(m) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def verify_is_not_none(self, expr, msg=None):
""" Soft assert for whether the expr is not None :params want: the object to compare against :params second: the ob... |
try:
self.assert_is_not_none(expr, msg)
except AssertionError, e:
if msg:
m = "%s:\n%s" % (msg, str(e))
else:
m = str(e)
self.verification_erorrs.append(m) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def verify_in(self, first, second, msg=""):
""" Soft assert for whether the first is in second :params first: the value to check :params second: the container to... |
try:
self.assert_in(first, second, msg)
except AssertionError, e:
if msg:
m = "%s:\n%s" % (msg, str(e))
else:
m = str(e)
self.verification_erorrs.append(m) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def verify_not_in(self, first, second, msg=""):
""" Soft assert for whether the first is not in second :params first: the value to check :params second: the cont... |
try:
self.assert_not_in(first, second, msg)
except AssertionError, e:
if msg:
m = "%s:\n%s" % (msg, str(e))
else:
m = str(e)
self.verification_erorrs.append(m) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def verify_is_instance(self, obj, cls, msg=""):
""" Soft assert for whether the is an instance of cls :params obj: the object instance :params cls: the class to ... |
try:
self.assert_is_instance(obj, cls, msg)
except AssertionError, e:
if msg:
m = "%s:\n%s" % (msg, str(e))
else:
m = str(e)
self.verification_erorrs.append(m) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def verify_is_not_instance(self, obj, cls, msg=""):
""" Soft assert for whether the is not an instance of cls :params obj: the object instance :params cls: the c... |
try:
self.assert_is_not_instance(obj, cls, msg)
except AssertionError, e:
if msg:
m = "%s:\n%s" % (msg, str(e))
else:
m = str(e)
self.verification_erorrs.append(m) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.