idx
int64
0
63k
question
stringlengths
53
5.28k
target
stringlengths
5
805
61,200
def SetAction ( self , action , ** kws ) : "set callback action" if hasattr ( action , '__call__' ) : self . __action = Closure ( action , ** kws )
set callback action
61,201
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
keep track of cursor position within text
61,202
def __SetMark ( self , mark = None ) : "set mark for later" if mark is None : mark = self . __mark self . SetSelection ( mark , mark )
set mark for later
61,203
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 ) ) if self . is_valid and hasattr ( self . __action , '__call__' ) and act : self . __action ( value = self . __val ) elif not self . is_valid and self . bell_on_invalid : wx . Bell ( ) self . __SetMark ( )
main method to set value
61,204
def OnChar ( self , event ) : key = event . GetKeyCode ( ) entry = wx . TextCtrl . GetValue ( self ) . strip ( ) pos = wx . TextCtrl . GetSelection ( self ) if key == wx . WXK_RETURN : if not self . is_valid : wx . TextCtrl . SetValue ( self , self . format % set_float ( self . __bound_val ) ) else : self . SetValue ( entry ) return if ( key < wx . WXK_SPACE or key == wx . WXK_DELETE or key > 255 ) : event . Skip ( ) return has_minus = '-' in entry ckey = chr ( key ) if ( ( ckey == '.' and ( self . __prec == 0 or '.' in entry ) ) or ( ckey == '-' and ( has_minus or pos [ 0 ] != 0 ) ) or ( ckey != '-' and has_minus and pos [ 0 ] == 0 ) ) : return if chr ( key ) in self . __digits : event . Skip ( )
on Character event
61,205
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 self . __max is not None and ( val > self . __max ) : self . is_valid = False val = self . __max except : self . is_valid = False self . __bound_val = self . __val = val fgcol , bgcol = self . fgcol_valid , self . bgcol_valid if not self . is_valid : fgcol , bgcol = self . fgcol_invalid , self . bgcol_invalid self . SetForegroundColour ( fgcol ) self . SetBackgroundColour ( bgcol ) self . Refresh ( )
check for validity of value
61,206
def add_text ( self , text , x , y , side = 'left' , size = None , rotation = None , ha = 'left' , va = 'center' , family = None , ** kws ) : 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 , rotation = rotation , family = family , ** kws ) self . conf . added_texts . append ( ( dynamic_size , t ) ) self . draw ( )
add text at supplied x y position
61,207
def add_arrow ( self , x1 , y1 , x2 , y2 , side = 'left' , shape = 'full' , color = 'black' , width = 0.01 , head_width = 0.03 , overhang = 0 , ** kws ) : 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 , overhang = overhang , ** kws ) self . draw ( )
add arrow supplied x y position
61,208
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 ( )
set user - defined limits and apply them
61,209
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_message ( "plotting %s" % expr , panel = 0 ) self . conf . process_data ( )
toggle derivative of data
61,210
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 ( )
toggle legend display
61,211
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 )
toggle grid display
61,212
def configure ( self , event = None ) : 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 , trace_color_callback = self . trace_color_callback ) self . win_config . Raise ( )
show configuration frame
61,213
def _updateCanvasDraw ( self ) : fn = self . canvas . draw def draw2 ( * a , ** k ) : self . _updateGridSpec ( ) return fn ( * a , ** k ) self . canvas . draw = draw2
Overload of the draw function that update axes position before each draw
61,214
def get_default_margins ( self ) : trans = self . fig . transFigure . inverted ( ) . transform l , t , r , b = self . axesmargins ( l , b ) , ( r , t ) = trans ( ( ( l , b ) , ( r , t ) ) ) dl , dt , dr , db = 0 , 0 , 0 , 0 for i , ax in enumerate ( self . fig . get_axes ( ) ) : ( x0 , y0 ) , ( x1 , y1 ) = ax . get_position ( ) . get_points ( ) try : ( ox0 , oy0 ) , ( ox1 , oy1 ) = ax . get_tightbbox ( self . canvas . get_renderer ( ) ) . get_points ( ) ( ox0 , oy0 ) , ( ox1 , oy1 ) = trans ( ( ( ox0 , oy0 ) , ( ox1 , oy1 ) ) ) dl = min ( 0.2 , max ( dl , ( x0 - ox0 ) ) ) dt = min ( 0.2 , max ( dt , ( oy1 - y1 ) ) ) dr = min ( 0.2 , max ( dr , ( ox1 - x1 ) ) ) db = min ( 0.2 , max ( db , ( y0 - oy0 ) ) ) except : pass return ( l + dl , t + dt , r + dr , b + db )
get default margins
61,215
def update_line ( self , trace , xdata , ydata , side = 'left' , draw = False , update_limits = True ) : 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 update_limits : self . set_viewlimits ( ) if draw : self . draw ( )
update a single trace for faster redraw
61,216
def get_userid_by_email ( self , 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 , response
get userid by email
61,217
def get_user_id_by_user ( self , 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_code , response
get user id by username
61,218
def get_user_by_userid ( self , userid ) : 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 , response
get user by user id
61,219
def get_user_presence ( self , userid ) : 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 ) ) return status_code , response
check on presence of a user
61,220
def set_user_presence ( self , userid , presence ) : response , status_code = self . __pod__ . Presence . post_v2_user_uid_presence ( sessionToken = self . __session__ , uid = userid , presence = presence ) . result ( ) self . logger . debug ( '%s: %s' % ( status_code , response ) ) return status_code , response
set presence of user
61,221
def list_features ( self ) : 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
list features the pod supports
61,222
def user_feature_update ( self , userid , payload ) : response , status_code = self . __pod__ . User . post_v1_admin_user_uid_features_update ( sessionToken = self . __session__ , uid = userid , payload = payload ) . result ( ) self . logger . debug ( '%s: %s' % ( status_code , response ) ) return status_code , response
update features by user id
61,223
def get_user_avatar ( self , userid ) : 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_code , response
get avatar by user id
61,224
def user_avatar_update ( self , userid , payload ) : 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: %s' % ( status_code , response ) ) return status_code , response
updated avatar by userid
61,225
def stream_members ( self , stream_id ) : 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 ) ) return status_code , response
get stream members
61,226
def connection_status ( self , userid ) : 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 ) ) return status_code , response
get connection status
61,227
def ib_group_member_list ( self , group_id ) : 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 ) ) return status_code , response
ib group member list
61,228
def ib_group_member_add ( self , group_id , userids ) : 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 ) self . logger . debug ( '%s: %s' % ( status_code , response ) ) return status_code , response
ib group member add
61,229
def ib_group_policy_list ( self ) : 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
ib group policy list
61,230
def start_monitoring ( self ) : if self . __monitoring is False : self . __monitoring = True self . __monitoring_action ( )
Enable periodically monitoring .
61,231
def parse_MML ( self , mml ) : 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' , { "uid" : True } ) for mention in mentions : mentions_c . append ( mention [ 'uid' ] ) msg_string = soup . messageml . text . strip ( ) self . logger . debug ( '%s : %s : %s' % ( hashes_c , mentions_c , msg_string ) ) return hashes_c , mentions_c , msg_string
parse the MML structure
61,232
def create_room ( self , payload ) : response , status_code = self . __pod__ . Streams . post_v2_room_create ( payload = payload ) . result ( ) self . logger . debug ( '%s: %s' % ( status_code , response ) ) return status_code , response
create a stream in a non - inclusive manner
61,233
def stream_info ( self , stream_id ) : 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 , response
get stream info
61,234
def create_stream ( self , uidList = [ ] ) : 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 , response
create a stream
61,235
def update_room ( self , stream_id , 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' % ( status_code , response ) ) return status_code , response
update a room definition
61,236
def room_members ( self , stream_id ) : 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 ) ) return status_code , response
get list of room members
61,237
def promote_owner ( self , stream_id , user_id ) : 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: %s' % ( status_code , response ) ) return status_code , response
promote user to owner in stream
61,238
def list_streams ( self , types = [ ] , inactive = False ) : req_hook = 'pod/v1/streams/list' json_query = { "streamTypes" : types , "includeInactiveStreams" : inactive } req_args = json . dumps ( json_query ) status_code , response = self . __rest__ . POST_query ( req_hook , req_args ) self . logger . debug ( '%s: %s' % ( status_code , response ) ) return status_code , response
list user streams
61,239
def get_unverified_claims ( token ) : 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 ) : raise JWTError ( 'Invalid claims string: must be a json object' ) return claims
Returns the decoded claims without verification of any kind .
61,240
def _validate_at_hash ( claims , access_token , algorithm ) : 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 from token.' raise JWTClaimsError ( msg ) try : expected_hash = calculate_at_hash ( access_token , ALGORITHMS . HASHES [ algorithm ] ) except ( TypeError , ValueError ) : msg = 'Unable to calculate at_hash to verify against token claims.' raise JWTClaimsError ( msg ) if claims [ 'at_hash' ] != expected_hash : raise JWTClaimsError ( 'at_hash claim does not match access_token.' )
Validates that the at_hash parameter included in the claims matches with the access_token returned alongside the id token as part of the authorization_code flow .
61,241
def get_session_token ( self ) : try : response = requests . post ( self . __session_url__ + 'sessionauth/v1/authenticate' , cert = ( self . __crt__ , self . __key__ ) , verify = True ) except requests . exceptions . RequestException as err : self . logger . error ( err ) raise if response . status_code == 200 : data = json . loads ( response . text ) self . logger . debug ( data ) session_token = data [ 'token' ] else : raise Exception ( 'BAD HTTP STATUS: %s' % str ( response . status_code ) ) self . logger . debug ( session_token ) return session_token
get session token
61,242
def solar_spectrum ( model = 'SOLAR-ISS' ) : r if model == 'SOLAR-ISS' : pth = os . path . join ( folder , 'solar_iss_2018_spectrum.dat' ) data = np . loadtxt ( pth ) wavelengths , SSI , uncertainties = data [ : , 0 ] , data [ : , 1 ] , data [ : , 2 ] wavelengths = wavelengths * 1E-9 SSI = SSI * 1E9 uncertainties [ uncertainties == - 1 ] = np . nan uncertainties = uncertainties * 1E9 return wavelengths , SSI , uncertainties
r Returns the solar spectrum of the sun according to the specified model . Only the SOLAR - ISS model is supported .
61,243
def qmax_boiling ( rhol = None , rhog = None , sigma = None , Hvap = None , D = None , P = None , Pc = None , Method = None , AvailableMethods = False ) : r def list_methods ( ) : methods = [ ] if all ( ( sigma , Hvap , rhol , rhog , D ) ) : methods . append ( 'Serth-HEDH' ) if all ( ( sigma , Hvap , rhol , rhog ) ) : methods . append ( 'Zuber' ) if all ( ( P , Pc ) ) : methods . append ( 'HEDH-Montinsky' ) return methods if AvailableMethods : return list_methods ( ) if not Method : methods = list_methods ( ) if methods == [ ] : raise Exception ( 'Insufficient property or geometry data for any ' 'method.' ) Method = methods [ 0 ] if Method == 'Serth-HEDH' : return Serth_HEDH ( D = D , sigma = sigma , Hvap = Hvap , rhol = rhol , rhog = rhog ) elif Method == 'Zuber' : return Zuber ( sigma = sigma , Hvap = Hvap , rhol = rhol , rhog = rhog ) elif Method == 'HEDH-Montinsky' : return HEDH_Montinsky ( P = P , Pc = Pc ) else : raise Exception ( "Correlation name not recognized; options are " "'Serth-HEDH', 'Zuber' and 'HEDH-Montinsky'" )
r This function handles the calculation of nucleate boiling critical heat flux and chooses the best method for performing the calculation . Preferred methods are Serth - HEDH when a tube diameter is specified and Zuber otherwise .
61,244
def Nu_vertical_cylinder ( Pr , Gr , L = None , D = None , Method = None , AvailableMethods = False ) : r def list_methods ( ) : methods = [ ] for key , values in vertical_cylinder_correlations . items ( ) : if values [ 4 ] or all ( ( L , D ) ) : methods . append ( key ) if 'Popiel & Churchill' in methods : methods . remove ( 'Popiel & Churchill' ) methods . insert ( 0 , 'Popiel & Churchill' ) elif 'McAdams, Weiss & Saunders' in methods : methods . remove ( 'McAdams, Weiss & Saunders' ) methods . insert ( 0 , 'McAdams, Weiss & Saunders' ) return methods if AvailableMethods : return list_methods ( ) if not Method : Method = list_methods ( ) [ 0 ] if Method in vertical_cylinder_correlations : if vertical_cylinder_correlations [ Method ] [ 4 ] : return vertical_cylinder_correlations [ Method ] [ 0 ] ( Pr = Pr , Gr = Gr ) else : return vertical_cylinder_correlations [ Method ] [ 0 ] ( Pr = Pr , Gr = Gr , L = L , D = D ) else : raise Exception ( "Correlation name not recognized; see the " "documentation for the available options." )
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 correlation to use if none is provided ; returns None if insufficient information is provided .
61,245
def Nu_horizontal_cylinder ( Pr , Gr , Method = None , AvailableMethods = False ) : r def list_methods ( ) : methods = [ ] for key , values in horizontal_cylinder_correlations . items ( ) : methods . append ( key ) if 'Morgan' in methods : methods . remove ( 'Morgan' ) methods . insert ( 0 , 'Morgan' ) return methods if AvailableMethods : return list_methods ( ) if not Method : Method = list_methods ( ) [ 0 ] if Method in horizontal_cylinder_correlations : return horizontal_cylinder_correlations [ Method ] ( Pr = Pr , Gr = Gr ) else : raise Exception ( "Correlation name not recognized; see the " "documentation for the available options." )
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 provided ; returns None if insufficient information is provided .
61,246
def calc_Cmin ( mh , mc , Cph , Cpc ) : r Ch = mh * Cph Cc = mc * Cpc return min ( Ch , Cc )
r Returns the heat capacity rate for the minimum stream having flows mh and mc with averaged heat capacities Cph and Cpc .
61,247
def calc_Cmax ( mh , mc , Cph , Cpc ) : r Ch = mh * Cph Cc = mc * Cpc return max ( Ch , Cc )
r Returns the heat capacity rate for the maximum stream having flows mh and mc with averaged heat capacities Cph and Cpc .
61,248
def calc_Cr ( mh , mc , Cph , Cpc ) : r Ch = mh * Cph Cc = mc * Cpc Cmin = min ( Ch , Cc ) Cmax = max ( Ch , Cc ) return Cmin / Cmax
r Returns the heat capacity rate ratio for a heat exchanger having flows mh and mc with averaged heat capacities Cph and Cpc .
61,249
def Pc ( x , y ) : r try : term = exp ( - x * ( 1. - y ) ) return ( 1. - term ) / ( 1. - y * term ) except ZeroDivisionError : return x / ( 1. + x )
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 counterflow calculations
61,250
def _NTU_from_P_solver ( P1 , R1 , NTU_min , NTU_max , function , ** kwargs ) : P1_max = _NTU_from_P_objective ( NTU_max , R1 , 0 , function , ** kwargs ) P1_min = _NTU_from_P_objective ( NTU_min , R1 , 0 , function , ** kwargs ) if P1 > P1_max : raise ValueError ( 'No solution possible gives such a high P1; maximum P1=%f at NTU1=%f' % ( P1_max , NTU_max ) ) if P1 < P1_min : raise ValueError ( 'No solution possible gives such a low P1; minimum P1=%f at NTU1=%f' % ( P1_min , NTU_min ) ) to_solve = lambda NTU1 : _NTU_from_P_objective ( NTU1 , R1 , P1 , function , ** kwargs ) return ridder ( to_solve , NTU_min , NTU_max )
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 .
61,251
def _NTU_max_for_P_solver ( data , R1 ) : offset_max = data [ 'offset' ] [ - 1 ] for offset , p , q in zip ( data [ 'offset' ] , data [ 'p' ] , data [ 'q' ] ) : if R1 < offset or offset == offset_max : x = R1 - offset return _horner ( p , x ) / _horner ( q , x )
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 should suffice for engineering applications . This value is needed to bound the solver .
61,252
def Ntubes_VDI ( DBundle = None , Ntp = None , Do = None , pitch = None , angle = 30. ) : r if Ntp == 1 : f2 = 0. elif Ntp == 2 : f2 = 22. elif Ntp == 4 : f2 = 70. elif Ntp == 8 : f2 = 105. elif Ntp == 6 : f2 = 90. else : raise Exception ( 'Only 1, 2, 4 and 8 passes are supported' ) if angle == 30 or angle == 60 : f1 = 1.1 elif angle == 45 or angle == 90 : f1 = 1.3 else : raise Exception ( 'Only 30, 60, 45 and 90 degree layouts are supported' ) DBundle , Do , pitch = DBundle * 1000 , Do * 1000 , pitch * 1000 t = pitch Ntubes = ( - ( - 4 * f1 * t ** 4 * f2 ** 2 * Do + 4 * f1 * t ** 4 * f2 ** 2 * DBundle ** 2 + t ** 4 * f2 ** 4 ) ** 0.5 - 2 * f1 * t ** 2 * Do + 2 * f1 * t ** 2 * DBundle ** 2 + t ** 2 * f2 ** 2 ) / ( 2 * f1 ** 2 * t ** 4 ) return int ( Ntubes )
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 .
61,253
def D_for_Ntubes_VDI ( N , Ntp , Do , pitch , angle = 30 ) : r if Ntp == 1 : f2 = 0. elif Ntp == 2 : f2 = 22. elif Ntp == 4 : f2 = 70. elif Ntp == 6 : f2 = 90. elif Ntp == 8 : f2 = 105. else : raise Exception ( 'Only 1, 2, 4 and 8 passes are supported' ) if angle == 30 or angle == 60 : f1 = 1.1 elif angle == 45 or angle == 90 : f1 = 1.3 else : raise Exception ( 'Only 30, 60, 45 and 90 degree layouts are supported' ) Do , pitch = Do * 1000 , pitch * 1000 Dshell = ( f1 * N * pitch ** 2 + f2 * N ** 0.5 * pitch + Do ) ** 0.5 return Dshell / 1000.
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 .
61,254
def Ntubes_HEDH ( DBundle = None , Do = None , pitch = None , angle = 30 ) : r if angle == 30 or angle == 60 : C1 = 13 / 15. elif angle == 45 or angle == 90 : C1 = 1. else : raise Exception ( 'Only 30, 60, 45 and 90 degree layouts are supported' ) Dctl = DBundle - Do N = 0.78 * Dctl ** 2 / C1 / pitch ** 2 return int ( N )
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 .
61,255
def DBundle_for_Ntubes_HEDH ( N , Do , pitch , angle = 30 ) : r if angle == 30 or angle == 60 : C1 = 13 / 15. elif angle == 45 or angle == 90 : C1 = 1. else : raise Exception ( 'Only 30, 60, 45 and 90 degree layouts are supported' ) return ( Do + ( 1. / .78 ) ** 0.5 * pitch * ( C1 * N ) ** 0.5 )
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 .
61,256
def setup ( self , data , view = 'hypergrid' , schema = None , columns = None , rowpivots = None , columnpivots = None , aggregates = None , sort = None , index = '' , limit = - 1 , computedcolumns = None , settings = True , embed = False , dark = False , * args , ** kwargs ) : self . view = validate_view ( view ) self . schema = schema or { } self . sort = validate_sort ( sort ) or [ ] self . index = index self . limit = limit self . settings = settings self . embed = embed self . dark = dark self . rowpivots = validate_rowpivots ( rowpivots ) or [ ] self . columnpivots = validate_columnpivots ( columnpivots ) or [ ] self . aggregates = validate_aggregates ( aggregates ) or { } self . columns = validate_columns ( columns ) or [ ] self . computedcolumns = validate_computedcolumns ( computedcolumns ) or [ ] self . load ( data )
Setup perspective base class
61,257
def R_cylinder ( Di , Do , k , L ) : r hA = k * 2 * pi * L / log ( Do / Di ) return 1. / hA
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 .
61,258
def S_isothermal_pipe_to_isothermal_pipe ( D1 , D2 , W , L = 1. ) : r return 2. * pi * L / acosh ( ( 4 * W ** 2 - D1 ** 2 - D2 ** 2 ) / ( 2. * D1 * D2 ) )
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 dimensionless shape factor used in some sources .
61,259
def S_isothermal_pipe_to_two_planes ( D , Z , L = 1. ) : r return 2. * pi * L / log ( 8. * Z / ( pi * D ) )
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 but can be set to 1 to obtain a dimensionless shape factor used in some sources .
61,260
def S_isothermal_pipe_eccentric_to_isothermal_pipe ( D1 , D2 , Z , L = 1. ) : r return 2. * pi * L / acosh ( ( D2 ** 2 + D1 ** 2 - 4. * Z ** 2 ) / ( 2. * D1 * D2 ) )
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 a dimensionless shape factor used in some sources .
61,261
def LMTD ( Thi , Tho , Tci , Tco , counterflow = True ) : r if counterflow : dTF1 = Thi - Tco dTF2 = Tho - Tci else : dTF1 = Thi - Tci dTF2 = Tho - Tco return ( dTF2 - dTF1 ) / log ( dTF2 / dTF1 )
r Returns the log - mean temperature difference of an ideal counterflow or co - current heat exchanger .
61,262
def k2g ( kml_path , output_dir , separate_folders , style_type , style_filename ) : m . convert ( 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 save it to the given output directory .
61,263
def disambiguate ( names , mark = '1' ) : 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
Given a list of strings names return a new list of names where repeated names have been disambiguated by repeatedly appending the given mark .
61,264
def build_rgb_and_opacity ( s ) : 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 ] return '#' + color , opacity
Given a KML color string return an equivalent RGB hex color string and an opacity float rounded to 2 decimal places .
61,265
def build_svg_style ( node ) : d = { } for item in get ( node , 'Style' ) : style_id = '#' + attr ( item , 'id' ) props = { } for x in get ( item , 'PolyStyle' ) : color = val ( get1 ( x , 'color' ) ) if color : rgb , opacity = build_rgb_and_opacity ( color ) props [ 'fill' ] = rgb props [ 'fill-opacity' ] = opacity props [ 'stroke' ] = rgb props [ 'stroke-opacity' ] = opacity props [ 'stroke-width' ] = 1 fill = valf ( get1 ( x , 'fill' ) ) if fill == 0 : props [ 'fill-opacity' ] = fill elif fill == 1 and 'fill-opacity' not in props : props [ 'fill-opacity' ] = fill outline = valf ( get1 ( x , 'outline' ) ) if outline == 0 : props [ 'stroke-opacity' ] = outline elif outline == 1 and 'stroke-opacity' not in props : props [ 'stroke-opacity' ] = outline for x in get ( item , 'LineStyle' ) : color = val ( get1 ( x , 'color' ) ) if color : rgb , opacity = build_rgb_and_opacity ( color ) props [ 'stroke' ] = rgb props [ 'stroke-opacity' ] = opacity width = valf ( get1 ( x , 'width' ) ) if width is not None : props [ 'stroke-width' ] = width for x in get ( item , 'IconStyle' ) : icon = get1 ( x , 'Icon' ) if not icon : continue props = { } props [ 'iconUrl' ] = val ( get1 ( icon , 'href' ) ) d [ style_id ] = props return d
Given a DOM node grab its top - level Style nodes convert every one into a SVG style dictionary put them in a master dictionary of the form
61,266
def wait_for_available ( self , locator ) : 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 True
Synchronization to deal with elements that are present and are visible
61,267
def wait_for_visible ( self , locator ) : 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
Synchronization to deal with elements that are present but are disabled until some action triggers their visibility .
61,268
def wait_for_text ( self , locator , text ) : 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 out" % locator ) return True
Synchronization on some text being displayed in a particular element .
61,269
def wait_for_element_not_present ( self , locator ) : 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
Synchronization helper to wait until some element is removed from the page
61,270
def validate ( tool_class , model_class ) : 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__ ) ) if not hasattr ( tool_class , 'view' ) : raise NotImplementedError ( "No 'view' method found for tool %s." % ( tool_class . __name__ ) )
Does basic ObjectTool option validation .
61,271
def construct_form ( self , request ) : 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
Constructs form from POST method using self . form_class .
61,272
def has_permission ( self , user ) : return user . has_perm ( self . model . _meta . app_label + '.' + self . get_permission ( ) )
Returns True if the given request has permission to use the tool . Can be overriden by the user in subclasses .
61,273
def media ( self , form ) : 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 ( ) : media = media + field . widget . media return media
Collects admin and form media .
61,274
def _urls ( self ) : 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
URL patterns for tool linked to _view method .
61,275
def construct_context ( self , request ) : 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 . lower ( ) ) , 'tool' : self , 'opts' : opts , 'app_label' : app_label , 'media' : media , 'form' : form , 'changelist_url' : reverse ( 'admin:%s_%s_changelist' % ( app_label , object_name ) ) } if hasattr ( form , 'fieldsets' ) : admin_form = helpers . AdminForm ( form , form . fieldsets , { } ) context [ 'adminform' ] = admin_form return context
Builds context with various required variables .
61,276
def _view ( self , request , extra_context = None ) : if not self . has_permission ( request . user ) : raise PermissionDenied return self . view ( request , self . construct_context ( request ) )
View wrapper taking care of houskeeping for painless form rendering .
61,277
def randomRow ( self ) : l = [ ] for row in self . data : l . append ( row ) return random . choice ( l )
Gets a random row from the provider
61,278
def verify_equal ( self , first , second , msg = "" ) : 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 )
Soft assert for equality
61,279
def verify_not_equal ( self , first , second , msg = "" ) : 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 )
Soft assert for inequality
61,280
def verify_true ( self , expr , msg = None ) : 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 )
Soft assert for whether the condition is true
61,281
def verify_false ( self , expr , msg = None ) : 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 )
Soft assert for whether the condition is false
61,282
def verify_is ( self , first , second , msg = None ) : 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 )
Soft assert for whether the parameters evaluate to the same object
61,283
def verify_is_not ( self , first , second , msg = None ) : 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 )
Soft assert for whether the parameters do not evaluate to the same object
61,284
def verify_is_none ( self , expr , msg = None ) : 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 )
Soft assert for whether the expr is None
61,285
def verify_is_not_none ( self , expr , msg = None ) : 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 )
Soft assert for whether the expr is not None
61,286
def verify_in ( self , first , second , msg = "" ) : 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 )
Soft assert for whether the first is in second
61,287
def verify_not_in ( self , first , second , msg = "" ) : 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 )
Soft assert for whether the first is not in second
61,288
def verify_is_instance ( self , obj , cls , msg = "" ) : 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 )
Soft assert for whether the is an instance of cls
61,289
def verify_is_not_instance ( self , obj , cls , msg = "" ) : 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 )
Soft assert for whether the is not an instance of cls
61,290
def obj ( self ) : if self . _wrapped is not self . Null : return self . _wrapped else : return self . object
Returns passed object but if chain method is used returns the last processed result
61,291
def _wrap ( self , ret ) : if self . chained : self . _wrapped = ret return self else : return ret
Returns result but ig chain method is used returns the object itself so we can chain
61,292
def _toOriginal ( self , val ) : if self . _clean . isTuple ( ) : return tuple ( val ) elif self . _clean . isList ( ) : return list ( val ) elif self . _clean . isDict ( ) : return dict ( val ) else : return val
Pitty attempt to convert itertools result into a real object
61,293
def map ( self , func ) : ns = self . Namespace ( ) ns . results = [ ] def by ( value , index , list , * args ) : ns . results . append ( func ( value , index , list ) ) _ ( self . obj ) . each ( by ) return self . _wrap ( ns . results )
Return the results of applying the iterator to each element .
61,294
def reduceRight ( self , func ) : x = self . obj [ : ] x . reverse ( ) return self . _wrap ( functools . reduce ( func , x ) )
The right - associative version of reduce also known as foldr .
61,295
def find ( self , func ) : self . ftmp = None def test ( value , index , list ) : if func ( value , index , list ) is True : self . ftmp = value return True self . _clean . any ( test ) return self . _wrap ( self . ftmp )
Return the first value which passes a truth test . Aliased as detect .
61,296
def filter ( self , func ) : return self . _wrap ( list ( filter ( func , self . obj ) ) )
Return all the elements that pass a truth test .
61,297
def reject ( self , func ) : return self . _wrap ( list ( filter ( lambda val : not func ( val ) , self . obj ) ) )
Return all the elements for which a truth test fails .
61,298
def all ( self , func = None ) : if func is None : func = lambda x , * args : x self . altmp = True def testEach ( value , index , * args ) : if func ( value , index , * args ) is False : self . altmp = False self . _clean . each ( testEach ) return self . _wrap ( self . altmp )
Determine whether all of the elements match a truth test .
61,299
def any ( self , func = None ) : if func is None : func = lambda x , * args : x self . antmp = False def testEach ( value , index , * args ) : if func ( value , index , * args ) is True : self . antmp = True return "breaker" self . _clean . each ( testEach ) return self . _wrap ( self . antmp )
Determine if at least one element in the object matches a truth test .