idx int64 0 63k | question stringlengths 53 5.28k | target stringlengths 5 805 |
|---|---|---|
34,300 | def to_dict ( self , nested = False ) : result = dict ( ) for key in self . columns : result [ key ] = getattr ( self , key ) if nested : for key in self . relations : obj = getattr ( self , key ) if isinstance ( obj , SerializeMixin ) : result [ key ] = obj . to_dict ( ) elif isinstance ( obj , Iterable ) : result [ k... | Return dict object with model s data . |
34,301 | def primary_keys_full ( cls ) : mapper = cls . __mapper__ return [ mapper . get_property_by_column ( column ) for column in mapper . primary_key ] | Get primary key properties for a SQLAlchemy cls . Taken from marshmallow_sqlalchemy |
34,302 | def save ( self ) : self . session . add ( self ) self . session . flush ( ) return self | Saves the updated model to the current entity db . |
34,303 | def get ( self , name , default = None ) : session = self . __get_session_from_db ( ) return session . get ( name , default ) | Gets the object for name or None if there s no such object . If default is provided return it if no object is found . |
34,304 | def delete ( self , * names ) : def change ( session ) : keys = session . keys ( ) names_in_common = [ name for name in names if name in keys ] for name in names_in_common : del session [ name ] self . __change_session ( change ) | Deletes the object with name from the session if exists . |
34,305 | def validate ( self , obj , ** kwargs ) : obj = stringify ( obj ) if obj is None : return False return self . DATE_RE . match ( obj ) is not None | Check if a thing is a valid date . |
34,306 | def _clean_datetime ( self , obj ) : if isinstance ( obj , datetime ) : if obj . tzinfo is not None : obj = obj . astimezone ( pytz . utc ) return obj . isoformat ( ) [ : self . MAX_LENGTH ] if isinstance ( obj , date ) : return obj . isoformat ( ) | Python objects want to be text . |
34,307 | def parse ( self ) : try : self . software = self . _find_software ( ) self . model_fittings = self . _find_model_fitting ( ) self . contrasts = self . _find_contrasts ( ) self . inferences = self . _find_inferences ( ) except Exception : self . cleanup ( ) raise | Parse a result directory to extract the pieces information to be stored in NIDM - Results . |
34,308 | def add_object ( self , nidm_object , export_file = True ) : if not export_file : export_dir = None else : export_dir = self . export_dir if not isinstance ( nidm_object , NIDMFile ) : nidm_object . export ( self . version , export_dir ) else : nidm_object . export ( self . version , export_dir , self . prepend_path ) ... | Add a NIDMObject to a NIDM - Results export . |
34,309 | def _get_model_fitting ( self , mf_id ) : for model_fitting in self . model_fittings : if model_fitting . activity . id == mf_id : return model_fitting raise Exception ( "Model fitting activity with id: " + str ( mf_id ) + " not found." ) | Retreive model fitting with identifier mf_id from the list of model fitting objects stored in self . model_fitting |
34,310 | def _get_contrast ( self , con_id ) : for contrasts in list ( self . contrasts . values ( ) ) : for contrast in contrasts : if contrast . estimation . id == con_id : return contrast raise Exception ( "Contrast activity with id: " + str ( con_id ) + " not found." ) | Retreive contrast with identifier con_id from the list of contrast objects stored in self . contrasts |
34,311 | def _add_namespaces ( self ) : self . doc . add_namespace ( NIDM ) self . doc . add_namespace ( NIIRI ) self . doc . add_namespace ( CRYPTO ) self . doc . add_namespace ( DCT ) self . doc . add_namespace ( DC ) self . doc . add_namespace ( NFO ) self . doc . add_namespace ( OBO ) self . doc . add_namespace ( SCR ) self... | Add namespaces to NIDM document . |
34,312 | def _create_bundle ( self , version ) : if not hasattr ( self , 'bundle_ent' ) : self . bundle_ent = NIDMResultsBundle ( nidm_version = version [ 'num' ] ) self . bundle = ProvBundle ( identifier = self . bundle_ent . id ) self . bundle_ent . export ( self . version , self . export_dir ) self . doc . entity ( self . bu... | Initialise NIDM - Results bundle . |
34,313 | def _get_model_parameters_estimations ( self , error_model ) : if error_model . dependance == NIDM_INDEPEDENT_ERROR : if error_model . variance_homo : estimation_method = STATO_OLS else : estimation_method = STATO_WLS else : estimation_method = STATO_GLS mpe = ModelParametersEstimation ( estimation_method , self . soft... | Infer model estimation method from the error_model . Return an object of type ModelParametersEstimation . |
34,314 | def save_prov_to_files ( self , showattributes = False ) : self . doc . add_bundle ( self . bundle ) ttl_file = os . path . join ( self . export_dir , 'nidm.ttl' ) ttl_txt = self . doc . serialize ( format = 'rdf' , rdf_format = 'turtle' ) ttl_txt , json_context = self . use_prefixes ( ttl_txt ) for namespace in self .... | Write - out provn serialisation to nidm . provn . |
34,315 | def clean_text ( self , number , countries = None , country = None , ** kwargs ) : for code in self . _clean_countries ( countries , country ) : try : num = parse_number ( number , code ) if is_possible_number ( num ) : if is_valid_number ( num ) : return format_number ( num , PhoneNumberFormat . E164 ) except NumberPa... | Parse a phone number and return in international format . |
34,316 | def validate ( self , ip , ** kwargs ) : if ip is None : return False ip = stringify ( ip ) if self . IPV4_REGEX . match ( ip ) : try : socket . inet_pton ( socket . AF_INET , ip ) return True except AttributeError : try : socket . inet_aton ( ip ) except socket . error : return False return ip . count ( '.' ) == 3 exc... | Check to see if this is a valid ip address . |
34,317 | def export ( self , nidm_version , export_dir , prepend_path ) : if self . path is not None : if export_dir is not None : new_file = os . path . join ( export_dir , self . filename ) if not self . path == new_file : if prepend_path . endswith ( '.zip' ) : with zipfile . ZipFile ( prepend_path ) as z : extracted = z . e... | Copy file over of export_dir and create corresponding triples |
34,318 | def export ( self , nidm_version , export_dir ) : if self . file is not None : self . add_attributes ( [ ( PROV [ 'type' ] , self . type ) , ( DCT [ 'format' ] , "image/png" ) , ] ) | Create prov entity . |
34,319 | def normalize ( self , address , ** kwargs ) : addresses = super ( AddressType , self ) . normalize ( address , ** kwargs ) return addresses | Make the address more compareable . |
34,320 | def clean_text ( self , url , ** kwargs ) : try : return normalize_url ( url ) except UnicodeDecodeError : log . warning ( "Invalid URL: %r" , url ) | Perform intensive care on URLs see urlnormalizer . |
34,321 | def clean_text ( self , country , guess = False , ** kwargs ) : code = country . lower ( ) . strip ( ) if code in self . names : return code country = countrynames . to_code ( country , fuzzy = guess ) if country is not None : return country . lower ( ) | Determine a two - letter country code based on an input . |
34,322 | def validate ( self , email , ** kwargs ) : email = stringify ( email ) if email is None : return if not self . EMAIL_REGEX . match ( email ) : return False mailbox , domain = email . rsplit ( '@' , 1 ) return self . domains . validate ( domain , ** kwargs ) | Check to see if this is a valid email address . |
34,323 | def clean_text ( self , email , ** kwargs ) : if not self . EMAIL_REGEX . match ( email ) : return None email = strip_quotes ( email ) mailbox , domain = email . rsplit ( '@' , 1 ) domain = self . domains . clean ( domain , ** kwargs ) if domain is None or mailbox is None : return return '@' . join ( ( mailbox , domain... | Parse and normalize an email address . |
34,324 | def fix_for_specific_versions ( self , rdf_data , to_replace ) : g = self . parse ( rdf_data ) query = sd = g . query ( query ) objects = dict ( ) if sd : for row in sd : argums = row . asdict ( ) if ( argums [ 'type' ] == NIDM_SPM_RESULTS_NIDM and ( argums [ 'version' ] . eq ( '12.6903' ) or argums [ 'version' ] . eq ... | Fixes of the RDF before loading the graph . All of these are workaround to circuvent known issues of the SPM and FSL exporters . |
34,325 | def _get_model_fitting ( self , con_est_id ) : for ( mpe_id , pe_ids ) , contrasts in self . contrasts . items ( ) : for contrast in contrasts : if contrast . estimation . id == con_est_id : model_fitting_id = mpe_id pe_map_ids = pe_ids break for model_fitting in self . model_fittings : if model_fitting . activity . id... | Retreive model fitting that corresponds to contrast with identifier con_id from the list of model fitting objects stored in self . model_fittings |
34,326 | def validate ( self , text , ** kwargs ) : cleaned = self . clean ( text , ** kwargs ) return cleaned is not None | Returns a boolean to indicate if this is a valid instance of the type . |
34,327 | def normalize ( self , text , cleaned = False , ** kwargs ) : if not cleaned : text = self . clean ( text , ** kwargs ) return ensure_list ( text ) | Create a represenation ideal for comparisons but not to be shown to the user . |
34,328 | def normalize_set ( self , items , ** kwargs ) : values = set ( ) for item in ensure_list ( items ) : values . update ( self . normalize ( item , ** kwargs ) ) return list ( values ) | Utility to normalize a whole set of values and get unique values . |
34,329 | def validate ( self , obj , ** kwargs ) : text = stringify ( obj ) if text is None : return False if '.' not in text : return False if '@' in text or ':' in text : return False if len ( text ) < 4 : return False return True | Check if a thing is a valid domain name . |
34,330 | def clean_text ( self , domain , ** kwargs ) : try : domain = urlparse ( domain ) . hostname or domain domain = domain . lower ( ) domain = domain . rsplit ( ':' , 1 ) [ 0 ] domain = domain . rstrip ( '.' ) domain = domain . encode ( "idna" ) . decode ( 'ascii' ) except ValueError : return None if self . validate ( dom... | Try to extract only the domain bit from the |
34,331 | def load ( filename , to_replace = dict ( ) ) : if not os . path . exists ( filename ) : raise IOException ( 'File does not exist: %s' % filename ) if filename . endswith ( '.json' ) : raise Exception ( 'Minimal json file: not handled yet' ) elif filename . endswith ( '.nidm.zip' ) : nidm = NIDMResults . load_from_pack... | Load NIDM - Results file given filename guessing if it is a NIDM - Results pack or a JSON file |
34,332 | def _find ( string , sub_string , start_index ) : result = string . find ( sub_string , start_index ) if result == - 1 : raise TokenError ( "expected '{0}'" . format ( sub_string ) ) return result | Return index of sub_string in string . |
34,333 | def builder_from_source ( source , filename , system_includes , nonsystem_includes , quiet = False ) : return ASTBuilder ( tokenize . get_tokens ( source ) , filename , system_includes , nonsystem_includes , quiet = quiet ) | Utility method that returns an ASTBuilder from source code . |
34,334 | def to_string ( self ) : suffix = '%s %s' % ( self . type , self . name ) if self . initial_value : suffix += ' = ' + self . initial_value return suffix | Return a string that tries to reconstitute the variable decl . |
34,335 | def _lookup_namespace ( self , symbol , namespace ) : for namespace_part in symbol . parts : namespace = namespace . get ( namespace_part ) if namespace is None : break if not isinstance ( namespace , dict ) : return namespace raise Error ( '%s not found' % symbol . name ) | Helper for lookup_symbol that only looks up variables in a namespace . |
34,336 | def _lookup_global ( self , symbol ) : assert symbol . parts namespace = self . namespaces if len ( symbol . parts ) == 1 : namespace = self . namespaces [ None ] try : return self . _lookup_namespace ( symbol , namespace ) except Error as orig_exc : try : namespace = self . namespaces [ None ] return self . _lookup_na... | Helper for lookup_symbol that only looks up global variables . |
34,337 | def _lookup_in_all_namespaces ( self , symbol ) : namespace = self . namespaces namespace_stack = [ ] for current in symbol . namespace_stack : namespace = namespace . get ( current ) if namespace is None or not isinstance ( namespace , dict ) : break namespace_stack . append ( namespace ) for namespace in reversed ( n... | Helper for lookup_symbol that looks for symbols in all namespaces . |
34,338 | def lookup_symbol ( self , name , namespace_stack ) : symbol = Symbol ( name , name . split ( '::' ) , namespace_stack ) assert symbol . parts if symbol . parts [ 0 ] == '' : symbol . parts = symbol . parts [ 1 : ] elif namespace_stack is not None : result = self . _lookup_in_all_namespaces ( symbol ) if result : retur... | Returns AST node and module for symbol if found . |
34,339 | def _add ( self , symbol_name , namespace , node , module ) : result = symbol_name in namespace namespace [ symbol_name ] = node , module return not result | Helper function for adding symbols . |
34,340 | def add_symbol ( self , symbol_name , namespace_stack , node , module ) : if namespace_stack : last_namespace = self . namespaces for namespace in namespace_stack : last_namespace = last_namespace . setdefault ( namespace , { } ) else : last_namespace = self . namespaces [ None ] return self . _add ( symbol_name , last... | Adds symbol_name defined in namespace_stack to the symbol table . |
34,341 | def get_namespace ( self , name_seq ) : namespaces = self . namespaces result = [ ] for name in name_seq : namespaces = namespaces . get ( name ) if not namespaces : break result . append ( name ) return result | Returns the prefix of names from name_seq that are known namespaces . |
34,342 | def _verify_forward_declarations_used ( self , forward_declarations , decl_uses , file_uses ) : for cls in forward_declarations : if cls in file_uses : if not decl_uses [ cls ] & USES_DECLARATION : node = forward_declarations [ cls ] msg = ( "'{}' forward declared, " 'but needs to be #included' . format ( cls ) ) self ... | Find all the forward declarations that are not used . |
34,343 | def _check_public_functions ( self , primary_header , all_headers ) : public_symbols = { } declared_only_symbols = { } if primary_header : for name , symbol in primary_header . public_symbols . items ( ) : if isinstance ( symbol , ast . Function ) : public_symbols [ name ] = symbol declared_only_symbols = dict . fromke... | Verify all the public functions are also declared in a header file . |
34,344 | def _find_unused_static_warnings ( filename , lines , ast_list ) : static_declarations = dict ( _get_static_declarations ( ast_list ) ) def find_variables_use ( body ) : for child in body : if child . name in static_declarations : static_use_counts [ child . name ] += 1 static_use_counts = collections . Counter ( ) for... | Warn about unused static variables . |
34,345 | def read_file ( filename , print_error = True ) : try : for encoding in [ 'utf-8' , 'latin1' ] : try : with io . open ( filename , encoding = encoding ) as fp : return fp . read ( ) except UnicodeDecodeError : pass except IOError as exception : if print_error : print ( exception , file = sys . stderr ) return None | Returns the contents of a file . |
34,346 | def map ( self , fn : Callable [ [ Any ] , Any ] ) -> 'Reader' : r def _compose ( x : Any ) -> Any : try : ret = fn ( self . run ( x ) ) except TypeError : ret = partial ( fn , self . run ( x ) ) return ret return Reader ( _compose ) | r Map a function over the Reader . |
34,347 | def bind ( self , fn : "Callable[[Any], Reader]" ) -> 'Reader' : r return Reader ( lambda x : fn ( self . run ( x ) ) . run ( x ) ) | r Bind a monadic function to the Reader . |
34,348 | def run ( self , * args , ** kwargs ) -> Callable : return self . fn ( * args , ** kwargs ) if args or kwargs else self . fn | Return wrapped function . |
34,349 | def asks ( cls , fn : Callable ) -> Reader : return cls . ask ( ) . bind ( Reader ( lambda x : cls . unit ( fn ( x ) ) ) ) | Given a function it returns a Reader which evaluates that function and returns the result . |
34,350 | def compose ( f : Callable [ [ Any ] , Monad ] , g : Callable [ [ Any ] , Monad ] ) -> Callable [ [ Any ] , Monad ] : r return lambda x : g ( x ) . bind ( f ) | r Monadic compose function . |
34,351 | def compose ( * funcs : Callable ) -> Callable : def _compose ( * args , ** kw ) : ret = reduce ( lambda acc , x : lambda f : f ( acc ( x ) ) , funcs [ : : - 1 ] , lambda f : f ( * args , ** kw ) ) return ret ( lambda x : x ) return _compose | Compose multiple functions right to left . |
34,352 | def run ( self , state : Any ) -> Tuple [ Any , Any ] : return self . _value ( state ) | Return wrapped state computation . |
34,353 | def map ( self , func : Callable [ [ Tuple [ Any , Log ] ] , Tuple [ Any , Log ] ] ) -> 'Writer' : a , w = self . run ( ) b , _w = func ( ( a , w ) ) return Writer ( b , _w ) | Map a function func over the Writer value . |
34,354 | def bind ( self , func : Callable [ [ Any ] , 'Writer' ] ) -> 'Writer' : a , w = self . run ( ) b , w_ = func ( a ) . run ( ) if isinstance ( w_ , Monoid ) : w__ = cast ( Monoid , w ) . append ( w_ ) else : w__ = w + w_ return Writer ( b , w__ ) | Flat is better than nested . |
34,355 | def apply_log ( a : tuple , func : Callable [ [ Any ] , Tuple [ Any , Log ] ] ) -> Tuple [ Any , Log ] : value , log = a new , entry = func ( value ) return new , log + entry | Apply a function to a value with a log . |
34,356 | def create ( cls , class_name : str , monoid_type = Union [ Monoid , str ] ) : def unit ( cls , value ) : if hasattr ( monoid_type , "empty" ) : log = monoid_type . empty ( ) else : log = monoid_type ( ) return cls ( value , log ) return type ( class_name , ( Writer , ) , dict ( unit = classmethod ( unit ) ) ) | Create Writer subclass using specified monoid type . |
34,357 | def map ( self , mapper : Callable [ [ Any ] , Any ] ) -> 'Identity' : value = self . _value try : result = mapper ( value ) except TypeError : result = partial ( mapper , value ) return Identity ( result ) | Map a function over wrapped values . |
34,358 | def run ( self , world : int ) -> IO : text , action = self . _value new_world = pure_print ( world , text ) return action ( world = new_world ) | Run IO action |
34,359 | def lift ( self , func ) : return self . bind ( lambda x : self . unit ( func ( x ) ) ) | Map function over monadic value . |
34,360 | def map ( self , mapper : Callable [ [ Any ] , Any ] ) -> 'Observable' : r source = self return Observable ( lambda on_next : source . subscribe ( compose ( on_next , mapper ) ) ) | r Map a function over an observable . |
34,361 | def filter ( self , predicate ) -> 'Observable' : source = self def subscribe ( on_next ) : def _next ( x ) : if predicate ( x ) : on_next ( x ) return source . subscribe ( _next ) return Observable ( subscribe ) | Filter the on_next continuation functions |
34,362 | def bind ( self , func : Callable [ [ Any ] , Maybe ] ) -> Maybe : value = self . _value return func ( value ) | Just x >> = f = f x . |
34,363 | def cons ( self , element : Any ) -> 'List' : tail = self . _get_value ( ) return List ( lambda sel : sel ( element , tail ) ) | Add element to front of List . |
34,364 | def head ( self ) -> Any : lambda_list = self . _get_value ( ) return lambda_list ( lambda head , _ : head ) | Retrive first element in List . |
34,365 | def tail ( self ) -> 'List' : lambda_list = self . _get_value ( ) return List ( lambda_list ( lambda _ , tail : tail ) ) | Return tail of List . |
34,366 | def map ( self , mapper : Callable [ [ Any ] , Any ] ) -> 'List' : try : ret = List . from_iterable ( [ mapper ( x ) for x in self ] ) except TypeError : ret = List . from_iterable ( [ partial ( mapper , x ) for x in self ] ) return ret | Map a function over a List . |
34,367 | def append ( self , other : 'List' ) -> 'List' : if self . null ( ) : return other return ( self . tail ( ) . append ( other ) ) . cons ( self . head ( ) ) | Append other list to this list . |
34,368 | def bind ( self , fn : Callable [ [ Any ] , 'List' ] ) -> 'List' : return List . concat ( self . map ( fn ) ) | Flatten and map the List . |
34,369 | def from_iterable ( cls , iterable : Iterable ) -> 'List' : iterator = iter ( iterable ) def recurse ( ) -> List : try : value = next ( iterator ) except StopIteration : return List . empty ( ) return List . unit ( value ) . append ( recurse ( ) ) return List . empty ( ) . append ( recurse ( ) ) | Create list from iterable . |
34,370 | def map ( self , fn : Callable [ [ Any ] , Any ] ) -> 'Cont' : r return Cont ( lambda c : self . run ( compose ( c , fn ) ) ) | r Map a function over a continuation . |
34,371 | def compress ( func ) : @ wraps ( func ) def wrapper ( * args , ** kwargs ) : result = func ( * args , ** kwargs ) if ( 'gzip' in bottle . request . headers . get ( 'Accept-Encoding' , '' ) and isinstance ( result , string_type ) and len ( result ) > 1024 ) : if isinstance ( result , unicode ) : result = result . encod... | Compress route return data with gzip compression |
34,372 | def set_trace ( host = '' , port = 5555 , patch_stdstreams = False ) : pdb = WebPdb . active_instance if pdb is None : pdb = WebPdb ( host , port , patch_stdstreams ) else : pdb . remove_trace ( ) pdb . set_trace ( sys . _getframe ( ) . f_back ) | Start the debugger |
34,373 | def post_mortem ( tb = None , host = '' , port = 5555 , patch_stdstreams = False ) : if tb is None : t , v , tb = sys . exc_info ( ) exc_data = traceback . format_exception ( t , v , tb ) else : exc_data = traceback . format_tb ( tb ) if tb is None : raise ValueError ( 'A valid traceback must be passed if no ' 'excepti... | Start post - mortem debugging for the provided traceback object |
34,374 | def catch_post_mortem ( host = '' , port = 5555 , patch_stdstreams = False ) : try : yield except Exception : post_mortem ( None , host , port , patch_stdstreams ) | A context manager for tracking potentially error - prone code |
34,375 | def do_quit ( self , arg ) : for name , fh in self . _backup : setattr ( sys , name , fh ) self . console . writeline ( '*** Aborting program ***\n' ) self . console . flush ( ) self . console . close ( ) WebPdb . active_instance = None return Pdb . do_quit ( self , arg ) | quit || exit || q Stop and quit the current debugging session |
34,376 | def _get_repr ( obj , pretty = False , indent = 1 ) : if pretty : repr_value = pformat ( obj , indent ) else : repr_value = repr ( obj ) if sys . version_info [ 0 ] == 2 : try : repr_value = repr_value . decode ( 'raw_unicode_escape' ) except UnicodeError : repr_value = repr_value . decode ( 'utf-8' , 'replace' ) retur... | Get string representation of an object |
34,377 | def get_current_frame_data ( self ) : filename = self . curframe . f_code . co_filename lines , start_line = inspect . findsource ( self . curframe ) if sys . version_info [ 0 ] == 2 : lines = [ line . decode ( 'utf-8' ) for line in lines ] return { 'dirname' : os . path . dirname ( os . path . abspath ( filename ) ) +... | Get all date about the current execution frame |
34,378 | def remove_trace ( self , frame = None ) : sys . settrace ( None ) if frame is None : frame = self . curframe while frame and frame is not self . botframe : del frame . f_trace frame = frame . f_back | Detach the debugger from the execution stack |
34,379 | def flush ( self ) : i = 0 while self . _frame_data . is_dirty and i < 10 : i += 1 time . sleep ( 0.1 ) | Wait until history is read but no more than 10 cycles in case a browser session is closed . |
34,380 | def solve_spectral ( prob , * args , ** kwargs ) : X = cvx . Semidef ( prob . n + 1 ) W = prob . f0 . homogeneous_form ( ) rel_obj = cvx . Minimize ( cvx . sum_entries ( cvx . mul_elemwise ( W , X ) ) ) W1 = sum ( [ f . homogeneous_form ( ) for f in prob . fs if f . relop == '<=' ] ) W2 = sum ( [ f . homogeneous_form (... | Solve the spectral relaxation with lambda = 1 . |
34,381 | def solve_sdr ( prob , * args , ** kwargs ) : X = cvx . Semidef ( prob . n + 1 ) W = prob . f0 . homogeneous_form ( ) rel_obj = cvx . Minimize ( cvx . sum_entries ( cvx . mul_elemwise ( W , X ) ) ) rel_constr = [ X [ - 1 , - 1 ] == 1 ] for f in prob . fs : W = f . homogeneous_form ( ) lhs = cvx . sum_entries ( cvx . mu... | Solve the SDP relaxation . |
34,382 | def get_qcqp_form ( prob ) : if not prob . objective . args [ 0 ] . is_quadratic ( ) : raise Exception ( "Objective is not quadratic." ) if not all ( [ constr . _expr . is_quadratic ( ) for constr in prob . constraints ] ) : raise Exception ( "Not all constraints are quadratic." ) if prob . is_dcp ( ) : logging . warni... | Returns the problem metadata in QCQP class |
34,383 | def make_request ( self , handle , value , timeout = DEFAULT_TIMEOUT , with_response = True ) : try : with self : _LOGGER . debug ( "Writing %s to %s with with_response=%s" , codecs . encode ( value , 'hex' ) , handle , with_response ) self . _conn . writeCharacteristic ( handle , value , withResponse = with_response )... | Write a GATT Command without callback - not utf - 8 . |
34,384 | def cli ( ctx , mac , debug ) : if debug : logging . basicConfig ( level = logging . DEBUG ) else : logging . basicConfig ( level = logging . INFO ) thermostat = Thermostat ( mac ) thermostat . update ( ) ctx . obj = thermostat if ctx . invoked_subcommand is None : ctx . invoke ( state ) | Tool to query and modify the state of EQ3 BT smart thermostat . |
34,385 | def temp ( dev , target ) : click . echo ( "Current target temp: %s" % dev . target_temperature ) if target : click . echo ( "Setting target temp: %s" % target ) dev . target_temperature = target | Gets or sets the target temperature . |
34,386 | def mode ( dev , target ) : click . echo ( "Current mode: %s" % dev . mode_readable ) if target : click . echo ( "Setting mode: %s" % target ) dev . mode = target | Gets or sets the active mode . |
34,387 | def boost ( dev , target ) : click . echo ( "Boost: %s" % dev . boost ) if target is not None : click . echo ( "Setting boost: %s" % target ) dev . boost = target | Gets or sets the boost mode . |
34,388 | def locked ( dev , target ) : click . echo ( "Locked: %s" % dev . locked ) if target is not None : click . echo ( "Setting lock: %s" % target ) dev . locked = target | Gets or sets the lock . |
34,389 | def window_open ( dev , temp , duration ) : click . echo ( "Window open: %s" % dev . window_open ) if temp and duration : click . echo ( "Setting window open conf, temp: %s duration: %s" % ( temp , duration ) ) dev . window_open_config ( temp , duration ) | Gets and sets the window open settings . |
34,390 | def presets ( dev , comfort , eco ) : click . echo ( "Setting presets: comfort %s, eco %s" % ( comfort , eco ) ) dev . temperature_presets ( comfort , eco ) | Sets the preset temperatures for auto mode . |
34,391 | def schedule ( dev ) : for d in range ( 7 ) : dev . query_schedule ( d ) for day in dev . schedule . values ( ) : click . echo ( "Day %s, base temp: %s" % ( day . day , day . base_temp ) ) current_hour = day . next_change_at for hour in day . hours : if current_hour == 0 : continue click . echo ( "\t[%s-%s] %s" % ( cur... | Gets the schedule from the thermostat . |
34,392 | def away ( dev , away_end , temperature ) : if away_end : click . echo ( "Setting away until %s, temperature: %s" % ( away_end , temperature ) ) else : click . echo ( "Disabling away mode" ) dev . set_away ( away_end , temperature ) | Enables or disables the away mode . |
34,393 | def state ( ctx ) : dev = ctx . obj click . echo ( dev ) ctx . forward ( locked ) ctx . forward ( low_battery ) ctx . forward ( window_open ) ctx . forward ( boost ) ctx . forward ( temp ) ctx . forward ( mode ) ctx . forward ( valve_state ) | Prints out all available information . |
34,394 | def parse_schedule ( self , data ) : sched = Schedule . parse ( data ) _LOGGER . debug ( "Got schedule data for day '%s'" , sched . day ) return sched | Parses the device sent schedule . |
34,395 | def update ( self ) : _LOGGER . debug ( "Querying the device.." ) time = datetime . now ( ) value = struct . pack ( 'BBBBBBB' , PROP_INFO_QUERY , time . year % 100 , time . month , time . day , time . hour , time . minute , time . second ) self . _conn . make_request ( PROP_WRITE_HANDLE , value ) | Update the data from the thermostat . Always sets the current time . |
34,396 | def set_schedule ( self , data ) : value = Schedule . build ( data ) self . _conn . make_request ( PROP_WRITE_HANDLE , value ) | Sets the schedule for the given day . |
34,397 | def target_temperature ( self , temperature ) : dev_temp = int ( temperature * 2 ) if temperature == EQ3BT_OFF_TEMP or temperature == EQ3BT_ON_TEMP : dev_temp |= 0x40 value = struct . pack ( 'BB' , PROP_MODE_WRITE , dev_temp ) else : self . _verify_temperature ( temperature ) value = struct . pack ( 'BB' , PROP_TEMPERA... | Set new target temperature . |
34,398 | def mode ( self , mode ) : _LOGGER . debug ( "Setting new mode: %s" , mode ) if self . mode == Mode . Boost and mode != Mode . Boost : self . boost = False if mode == Mode . Boost : self . boost = True return elif mode == Mode . Away : end = datetime . now ( ) + self . _away_duration return self . set_away ( end , self... | Set the operation mode . |
34,399 | def set_away ( self , away_end = None , temperature = EQ3BT_AWAY_TEMP ) : if not away_end : _LOGGER . debug ( "Disabling away, going to auto mode." ) return self . set_mode ( 0x00 ) _LOGGER . debug ( "Setting away until %s, temp %s" , away_end , temperature ) adapter = AwayDataAdapter ( Byte [ 4 ] ) packed = adapter . ... | Sets away mode with target temperature . When called without parameters disables away mode . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.