idx int64 0 252k | question stringlengths 48 5.28k | target stringlengths 5 1.23k |
|---|---|---|
229,400 | def nic_v2 ( msg , NICa , NICbc ) : if typecode ( msg ) < 5 or typecode ( msg ) > 22 : raise RuntimeError ( "%s: Not a surface position message (5<TC<8), \ airborne position message (8<TC<19), \ or airborne position with GNSS height (20<TC<22)" % msg ) tc = typecode ( msg ) NIC = uncertainty . TC_... | Calculate NIC navigation integrity category for ADS - B version 2 |
229,401 | def nic_s ( msg ) : tc = typecode ( msg ) if tc != 31 : raise RuntimeError ( "%s: Not a status operation message, expecting TC = 31" % msg ) msgbin = common . hex2bin ( msg ) nic_s = int ( msgbin [ 75 ] ) return nic_s | Obtain NIC supplement bit TC = 31 message |
229,402 | def nic_b ( msg ) : tc = typecode ( msg ) if tc < 9 or tc > 18 : raise RuntimeError ( "%s: Not a airborne position message, expecting 8<TC<19" % msg ) msgbin = common . hex2bin ( msg ) nic_b = int ( msgbin [ 39 ] ) return nic_b | Obtain NICb navigation integrity category supplement - b |
229,403 | def nac_p ( msg ) : tc = typecode ( msg ) if tc not in [ 29 , 31 ] : raise RuntimeError ( "%s: Not a target state and status message, \ or operation status message, expecting TC = 29 or 31" % msg ) msgbin = common . hex2bin ( msg ) if tc == 29 : NACp = common . bin2int ( msgbin [ 71 : 75 ] ) e... | Calculate NACp Navigation Accuracy Category - Position |
229,404 | def nac_v ( msg ) : tc = typecode ( msg ) if tc != 19 : raise RuntimeError ( "%s: Not an airborne velocity message, expecting TC = 19" % msg ) msgbin = common . hex2bin ( msg ) NACv = common . bin2int ( msgbin [ 42 : 45 ] ) try : HFOMr = uncertainty . NACv [ NACv ] [ 'HFOMr' ] VFOMr = uncertainty . NACv [ NACv ] [ 'VFO... | Calculate NACv Navigation Accuracy Category - Velocity |
229,405 | def sil ( msg , version ) : tc = typecode ( msg ) if tc not in [ 29 , 31 ] : raise RuntimeError ( "%s: Not a target state and status messag, \ or operation status message, expecting TC = 29 or 31" % msg ) msgbin = common . hex2bin ( msg ) if tc == 29 : SIL = common . bin2int ( msgbin [ 76 : 78... | Calculate SIL Surveillance Integrity Level |
229,406 | def roll50 ( msg ) : d = hex2bin ( data ( msg ) ) if d [ 0 ] == '0' : return None sign = int ( d [ 1 ] ) value = bin2int ( d [ 2 : 11 ] ) if sign : value = value - 512 angle = value * 45.0 / 256.0 return round ( angle , 1 ) | Roll angle BDS 5 0 message |
229,407 | def trk50 ( msg ) : d = hex2bin ( data ( msg ) ) if d [ 11 ] == '0' : return None sign = int ( d [ 12 ] ) value = bin2int ( d [ 13 : 23 ] ) if sign : value = value - 1024 trk = value * 90.0 / 512.0 if trk < 0 : trk = 360 + trk return round ( trk , 3 ) | True track angle BDS 5 0 message |
229,408 | def gs50 ( msg ) : d = hex2bin ( data ( msg ) ) if d [ 23 ] == '0' : return None spd = bin2int ( d [ 24 : 34 ] ) * 2 return spd | Ground speed BDS 5 0 message |
229,409 | def tas50 ( msg ) : d = hex2bin ( data ( msg ) ) if d [ 45 ] == '0' : return None tas = bin2int ( d [ 46 : 56 ] ) * 2 return tas | Aircraft true airspeed BDS 5 0 message |
229,410 | def ias53 ( msg ) : d = hex2bin ( data ( msg ) ) if d [ 12 ] == '0' : return None ias = bin2int ( d [ 13 : 23 ] ) return ias | Indicated airspeed DBS 5 3 message |
229,411 | def mach53 ( msg ) : d = hex2bin ( data ( msg ) ) if d [ 23 ] == '0' : return None mach = bin2int ( d [ 24 : 33 ] ) * 0.008 return round ( mach , 3 ) | MACH number DBS 5 3 message |
229,412 | def tas53 ( msg ) : d = hex2bin ( data ( msg ) ) if d [ 33 ] == '0' : return None tas = bin2int ( d [ 34 : 46 ] ) * 0.5 return round ( tas , 1 ) | Aircraft true airspeed BDS 5 3 message |
229,413 | def read_skysense_buffer ( self ) : SS_MSGLENGTH = 24 SS_STARTCHAR = 0x24 if len ( self . buffer ) <= SS_MSGLENGTH : return None messages = [ ] while len ( self . buffer ) > SS_MSGLENGTH : i = 0 if self . buffer [ i ] == SS_STARTCHAR and self . buffer [ i + SS_MSGLENGTH ] == SS_STARTCHAR : i += 1 if ( self . buffer [ i... | Skysense stream format . |
229,414 | def is10 ( msg ) : if allzeros ( msg ) : return False d = hex2bin ( data ( msg ) ) if d [ 0 : 8 ] != '00010000' : return False if bin2int ( d [ 9 : 14 ] ) != 0 : return False if d [ 14 ] == '1' and bin2int ( d [ 16 : 23 ] ) < 5 : return False if d [ 14 ] == '0' and bin2int ( d [ 16 : 23 ] ) > 4 : return False return Tr... | Check if a message is likely to be BDS code 1 0 |
229,415 | def is17 ( msg ) : if allzeros ( msg ) : return False d = hex2bin ( data ( msg ) ) if bin2int ( d [ 28 : 56 ] ) != 0 : return False caps = cap17 ( msg ) if 'BDS20' not in caps : return False return True | Check if a message is likely to be BDS code 1 7 |
229,416 | def cap17 ( msg ) : allbds = [ '05' , '06' , '07' , '08' , '09' , '0A' , '20' , '21' , '40' , '41' , '42' , '43' , '44' , '45' , '48' , '50' , '51' , '52' , '53' , '54' , '55' , '56' , '5F' , '60' , 'NA' , 'NA' , 'E1' , 'E2' ] d = hex2bin ( data ( msg ) ) idx = [ i for i , v in enumerate ( d [ : 28 ] ) if v == '1' ] ca... | Extract capacities from BDS 1 7 message |
229,417 | def get_aircraft ( self ) : acs = self . acs icaos = list ( acs . keys ( ) ) for icao in icaos : if acs [ icao ] [ 'lat' ] is None : acs . pop ( icao ) return acs | all aircraft that are stored in memeory |
229,418 | def altitude_diff ( msg ) : tc = common . typecode ( msg ) if tc != 19 : raise RuntimeError ( "%s: Not a airborne velocity message, expecting TC=19" % msg ) msgbin = common . hex2bin ( msg ) sign = - 1 if int ( msgbin [ 80 ] ) else 1 value = common . bin2int ( msgbin [ 81 : 88 ] ) if value == 0 or value == 127 : return... | Decode the differece between GNSS and barometric altitude |
229,419 | def is50or60 ( msg , spd_ref , trk_ref , alt_ref ) : def vxy ( v , angle ) : vx = v * np . sin ( np . radians ( angle ) ) vy = v * np . cos ( np . radians ( angle ) ) return vx , vy if not ( bds50 . is50 ( msg ) and bds60 . is60 ( msg ) ) : return None h50 = bds50 . trk50 ( msg ) v50 = bds50 . gs50 ( msg ) if h50 is No... | Use reference ground speed and trk to determine BDS50 and DBS60 . |
229,420 | def infer ( msg , mrar = False ) : df = common . df ( msg ) if common . allzeros ( msg ) : return 'EMPTY' if df == 17 : tc = common . typecode ( msg ) if 1 <= tc <= 4 : return 'BDS08' if 5 <= tc <= 8 : return 'BDS06' if 9 <= tc <= 18 : return 'BDS05' if tc == 19 : return 'BDS09' if 20 <= tc <= 22 : return 'BDS05' if tc... | Estimate the most likely BDS code of an message . |
229,421 | def is40 ( msg ) : if allzeros ( msg ) : return False d = hex2bin ( data ( msg ) ) if wrongstatus ( d , 1 , 2 , 13 ) : return False if wrongstatus ( d , 14 , 15 , 26 ) : return False if wrongstatus ( d , 27 , 28 , 39 ) : return False if wrongstatus ( d , 48 , 49 , 51 ) : return False if wrongstatus ( d , 54 , 55 , 56 )... | Check if a message is likely to be BDS code 4 0 |
229,422 | def alt40fms ( msg ) : d = hex2bin ( data ( msg ) ) if d [ 13 ] == '0' : return None alt = bin2int ( d [ 14 : 26 ] ) * 16 return alt | Selected altitude FMS |
229,423 | def p40baro ( msg ) : d = hex2bin ( data ( msg ) ) if d [ 26 ] == '0' : return None p = bin2int ( d [ 27 : 39 ] ) * 0.1 + 800 return p | Barometric pressure setting |
229,424 | def is44 ( msg ) : if allzeros ( msg ) : return False d = hex2bin ( data ( msg ) ) if wrongstatus ( d , 5 , 6 , 23 ) : return False if wrongstatus ( d , 35 , 36 , 46 ) : return False if wrongstatus ( d , 47 , 48 , 49 ) : return False if wrongstatus ( d , 50 , 51 , 56 ) : return False if bin2int ( d [ 0 : 4 ] ) > 4 : re... | Check if a message is likely to be BDS code 4 4 . |
229,425 | def wind44 ( msg ) : d = hex2bin ( data ( msg ) ) status = int ( d [ 4 ] ) if not status : return None speed = bin2int ( d [ 5 : 14 ] ) direction = bin2int ( d [ 14 : 23 ] ) * 180.0 / 256.0 return round ( speed , 0 ) , round ( direction , 1 ) | Wind speed and direction . |
229,426 | def p44 ( msg ) : d = hex2bin ( data ( msg ) ) if d [ 34 ] == '0' : return None p = bin2int ( d [ 35 : 46 ] ) return p | Static pressure . |
229,427 | def is60 ( msg ) : if allzeros ( msg ) : return False d = hex2bin ( data ( msg ) ) if wrongstatus ( d , 1 , 2 , 12 ) : return False if wrongstatus ( d , 13 , 14 , 23 ) : return False if wrongstatus ( d , 24 , 25 , 34 ) : return False if wrongstatus ( d , 35 , 36 , 45 ) : return False if wrongstatus ( d , 46 , 47 , 56 )... | Check if a message is likely to be BDS code 6 0 |
229,428 | def hdg60 ( msg ) : d = hex2bin ( data ( msg ) ) if d [ 0 ] == '0' : return None sign = int ( d [ 1 ] ) value = bin2int ( d [ 2 : 12 ] ) if sign : value = value - 1024 hdg = value * 90 / 512.0 if hdg < 0 : hdg = 360 + hdg return round ( hdg , 3 ) | Megnetic heading of aircraft |
229,429 | def mach60 ( msg ) : d = hex2bin ( data ( msg ) ) if d [ 23 ] == '0' : return None mach = bin2int ( d [ 24 : 34 ] ) * 2.048 / 512.0 return round ( mach , 3 ) | Aircraft MACH number |
229,430 | def vr60baro ( msg ) : d = hex2bin ( data ( msg ) ) if d [ 34 ] == '0' : return None sign = int ( d [ 35 ] ) value = bin2int ( d [ 36 : 45 ] ) if value == 0 or value == 511 : return 0 value = value - 512 if sign else value roc = value * 32 return roc | Vertical rate from barometric measurement this value may be very noisy . |
229,431 | def is45 ( msg ) : if allzeros ( msg ) : return False d = hex2bin ( data ( msg ) ) if wrongstatus ( d , 1 , 2 , 3 ) : return False if wrongstatus ( d , 4 , 5 , 6 ) : return False if wrongstatus ( d , 7 , 8 , 9 ) : return False if wrongstatus ( d , 10 , 11 , 12 ) : return False if wrongstatus ( d , 13 , 14 , 15 ) : retu... | Check if a message is likely to be BDS code 4 5 . |
229,432 | def ws45 ( msg ) : d = hex2bin ( data ( msg ) ) if d [ 3 ] == '0' : return None ws = bin2int ( d [ 4 : 6 ] ) return ws | Wind shear . |
229,433 | def wv45 ( msg ) : d = hex2bin ( data ( msg ) ) if d [ 12 ] == '0' : return None ws = bin2int ( d [ 13 : 15 ] ) return ws | Wake vortex . |
229,434 | def p45 ( msg ) : d = hex2bin ( data ( msg ) ) if d [ 26 ] == '0' : return None p = bin2int ( d [ 27 : 38 ] ) return p | Average static pressure . |
229,435 | def rh45 ( msg ) : d = hex2bin ( data ( msg ) ) if d [ 38 ] == '0' : return None rh = bin2int ( d [ 39 : 51 ] ) * 16 return rh | Radio height . |
229,436 | def vsound ( H ) : T = temperature ( H ) a = np . sqrt ( gamma * R * T ) return a | Speed of sound |
229,437 | def distance ( lat1 , lon1 , lat2 , lon2 , H = 0 ) : phi1 = np . radians ( 90.0 - lat1 ) phi2 = np . radians ( 90.0 - lat2 ) theta1 = np . radians ( lon1 ) theta2 = np . radians ( lon2 ) cos = np . sin ( phi1 ) * np . sin ( phi2 ) * np . cos ( theta1 - theta2 ) + np . cos ( phi1 ) * np . cos ( phi2 ) cos = np . where (... | Compute spherical distance from spherical coordinates . |
229,438 | def tas2mach ( Vtas , H ) : a = vsound ( H ) Mach = Vtas / a return Mach | True Airspeed to Mach number |
229,439 | def mach2tas ( Mach , H ) : a = vsound ( H ) Vtas = Mach * a return Vtas | Mach number to True Airspeed |
229,440 | def tas2eas ( Vtas , H ) : rho = density ( H ) Veas = Vtas * np . sqrt ( rho / rho0 ) return Veas | True Airspeed to Equivalent Airspeed |
229,441 | def cas2tas ( Vcas , H ) : p , rho , T = atmos ( H ) qdyn = p0 * ( ( 1. + rho0 * Vcas * Vcas / ( 7. * p0 ) ) ** 3.5 - 1. ) Vtas = np . sqrt ( 7. * p / rho * ( ( 1. + qdyn / p ) ** ( 2. / 7. ) - 1. ) ) return Vtas | Calibrated Airspeed to True Airspeed |
229,442 | def mach2cas ( Mach , H ) : Vtas = mach2tas ( Mach , H ) Vcas = tas2cas ( Vtas , H ) return Vcas | Mach number to Calibrated Airspeed |
229,443 | def cas2mach ( Vcas , H ) : Vtas = cas2tas ( Vcas , H ) Mach = tas2mach ( Vtas , H ) return Mach | Calibrated Airspeed to Mach number |
229,444 | def markdown_search_user ( request ) : data = { } username = request . GET . get ( 'username' ) if username is not None and username != '' and ' ' not in username : users = User . objects . filter ( Q ( username__icontains = username ) ) . filter ( is_active = True ) if users . exists ( ) : data . update ( { 'status' :... | Json usernames of the users registered & actived . |
229,445 | def handleMatch ( self , m ) : username = self . unescape ( m . group ( 2 ) ) if MARTOR_ENABLE_CONFIGS [ 'mention' ] == 'true' : if username in [ u . username for u in User . objects . exclude ( is_active = False ) ] : url = '{0}{1}/' . format ( MARTOR_MARKDOWN_BASE_MENTION_URL , username ) el = markdown . util . etree... | Makesure username is registered and actived . |
229,446 | def markdownify ( markdown_content ) : try : return markdown . markdown ( markdown_content , safe_mode = MARTOR_MARKDOWN_SAFE_MODE , extensions = MARTOR_MARKDOWN_EXTENSIONS , extension_configs = MARTOR_MARKDOWN_EXTENSION_CONFIGS ) except Exception : raise VersionNotCompatible ( "The markdown isn't compatible, please re... | Render the markdown content to HTML . |
229,447 | def get_entry_url ( entry , blog_page , root_page ) : if root_page == blog_page : return reverse ( 'entry_page_serve' , kwargs = { 'year' : entry . date . strftime ( '%Y' ) , 'month' : entry . date . strftime ( '%m' ) , 'day' : entry . date . strftime ( '%d' ) , 'slug' : entry . slug } ) else : blog_path = strip_prefix... | Get the entry url given and entry page a blog page instances . It will use an url or another depending if blog_page is the root page . |
229,448 | def get_feeds_url ( blog_page , root_page ) : if root_page == blog_page : return reverse ( 'blog_page_feed' ) else : blog_path = strip_prefix_and_ending_slash ( blog_page . specific . last_url_part ) return reverse ( 'blog_page_feed_slug' , kwargs = { 'blog_path' : blog_path } ) | Get the feeds urls a blog page instance . It will use an url or another depending if blog_page is the root page . |
229,449 | def install_dependencies ( dependencies , verbose = False ) : if not dependencies : return stdout = stderr = None if verbose else subprocess . DEVNULL with tempfile . TemporaryDirectory ( ) as req_dir : req_file = Path ( req_dir ) / "requirements.txt" with open ( req_file , "w" ) as f : for dependency in dependencies :... | Install all packages in dependency list via pip . |
229,450 | def install_translations ( config ) : if not config : return from . import _translation checks_translation = gettext . translation ( domain = config [ "domain" ] , localedir = internal . check_dir / config [ "localedir" ] , fallback = True ) _translation . add_fallback ( checks_translation ) | Add check translations according to config as a fallback to existing translations |
229,451 | def hash ( file ) : exists ( file ) log ( _ ( "hashing {}..." ) . format ( file ) ) with open ( file , "rb" ) as f : sha256 = hashlib . sha256 ( ) for block in iter ( lambda : f . read ( 65536 ) , b"" ) : sha256 . update ( block ) return sha256 . hexdigest ( ) | Hashes file using SHA - 256 . |
229,452 | def exists ( * paths ) : for path in paths : log ( _ ( "checking that {} exists..." ) . format ( path ) ) if not os . path . exists ( path ) : raise Failure ( _ ( "{} not found" ) . format ( path ) ) | Assert that all given paths exist . |
229,453 | def import_checks ( path ) : dir = internal . check_dir / path file = internal . load_config ( dir ) [ "checks" ] mod = internal . import_file ( dir . name , ( dir / file ) . resolve ( ) ) sys . modules [ dir . name ] = mod return mod | Import checks module given relative path . |
229,454 | def _raw ( s ) : if isinstance ( s , list ) : s = "\n" . join ( _raw ( item ) for item in s ) if s == EOF : return "EOF" s = repr ( s ) s = s [ 1 : - 1 ] if len ( s ) > 15 : s = s [ : 15 ] + "..." return s | Get raw representation of s truncating if too long . |
229,455 | def _copy ( src , dst ) : try : shutil . copy ( src , dst ) except IsADirectoryError : if os . path . isdir ( dst ) : dst = os . path . join ( dst , os . path . basename ( src ) ) shutil . copytree ( src , dst ) | Copy src to dst copying recursively if src is a directory . |
229,456 | def stdin ( self , line , prompt = True , timeout = 3 ) : if line == EOF : log ( "sending EOF..." ) else : log ( _ ( "sending input {}..." ) . format ( line ) ) if prompt : try : self . process . expect ( ".+" , timeout = timeout ) except ( TIMEOUT , EOF ) : raise Failure ( _ ( "expected prompt for input, found none" )... | Send line to stdin optionally expect a prompt . |
229,457 | def reject ( self , timeout = 1 ) : log ( _ ( "checking that input was rejected..." ) ) try : self . _wait ( timeout ) except Failure as e : if not isinstance ( e . __cause__ , TIMEOUT ) : raise else : raise Failure ( _ ( "expected program to reject input, but it did not" ) ) return self | Check that the process survives for timeout . Useful for checking whether program is waiting on input . |
229,458 | def import_file ( name , path ) : spec = importlib . util . spec_from_file_location ( name , path ) mod = importlib . util . module_from_spec ( spec ) spec . loader . exec_module ( mod ) return mod | Import a file given a raw file path . |
229,459 | def compile ( * files , exe_name = None , cc = CC , ** cflags ) : if not files : raise RuntimeError ( _ ( "compile requires at least one file" ) ) if exe_name is None and files [ 0 ] . endswith ( ".c" ) : exe_name = Path ( files [ 0 ] ) . stem files = " " . join ( files ) flags = CFLAGS . copy ( ) flags . update ( cfla... | Compile C source files . |
229,460 | def valgrind ( command , env = { } ) : xml_file = tempfile . NamedTemporaryFile ( ) internal . register . after_check ( lambda : _check_valgrind ( xml_file ) ) return run ( f"valgrind --show-leak-kinds=all --xml=yes --xml-file={xml_file.name} -- {command}" , env = env ) | Run a command with valgrind . |
229,461 | def _check_valgrind ( xml_file ) : log ( _ ( "checking for valgrind errors..." ) ) xml = ET . ElementTree ( file = xml_file ) reported = set ( ) for error in xml . iterfind ( "error" ) : kind = error . find ( "kind" ) . text what = error . find ( "xwhat/text" if kind . startswith ( "Leak_" ) else "what" ) . text msg = ... | Log and report any errors encountered by valgrind . |
229,462 | def _timeout ( seconds ) : def _handle_timeout ( * args ) : raise Timeout ( seconds ) signal . signal ( signal . SIGALRM , _handle_timeout ) signal . alarm ( seconds ) try : yield finally : signal . alarm ( 0 ) signal . signal ( signal . SIGALRM , signal . SIG_DFL ) | Context manager that runs code block until timeout is reached . |
229,463 | def run ( self , files , working_area ) : results = { name : None for name in self . check_names } checks_root = working_area . parent with futures . ProcessPoolExecutor ( ) as executor : not_done = set ( executor . submit ( run_check ( name , self . checks_spec , checks_root ) ) for name , _ in self . child_map [ None... | Run checks concurrently . Returns a list of CheckResults ordered by declaration order of the checks in the imported module |
229,464 | def append_code ( original , codefile ) : with open ( codefile ) as code , open ( original , "a" ) as o : o . write ( "\n" ) o . writelines ( code ) | Append the contents of one file to another . |
229,465 | def import_ ( path ) : exists ( path ) log ( _ ( "importing {}..." ) . format ( path ) ) name = Path ( path ) . stem try : return internal . import_file ( name , path ) except Exception as e : raise Failure ( str ( e ) ) | Import a Python program given a raw file path |
229,466 | def compile ( file ) : log ( _ ( "compiling {} into byte code..." ) . format ( file ) ) try : py_compile . compile ( file , doraise = True ) except py_compile . PyCompileError as e : log ( _ ( "Exception raised: " ) ) for line in e . msg . splitlines ( ) : log ( line ) raise Failure ( _ ( "{} raised while compiling {} ... | Compile a Python program into byte code |
229,467 | def get ( self , route , data = None , params = None , follow_redirects = True ) : return self . _send ( "GET" , route , data , params , follow_redirects = follow_redirects ) | Send GET request to app . |
229,468 | def post ( self , route , data = None , params = None , follow_redirects = True ) : return self . _send ( "POST" , route , data , params , follow_redirects = follow_redirects ) | Send POST request to app . |
229,469 | def status ( self , code = None ) : if code is None : return self . response . status_code log ( _ ( "checking that status code {} is returned..." ) . format ( code ) ) if code != self . response . status_code : raise Failure ( _ ( "expected status code {}, but got {}" ) . format ( code , self . response . status_code ... | Check status code in response returned by application . If code is not None assert that code is returned by application else simply return the status code . |
229,470 | def raw_content ( self , output = None , str_output = None ) : return self . _search_page ( output , str_output , self . response . data , lambda regex , content : regex . search ( content . decode ( ) ) ) | Searches for output regex match within content of page regardless of mimetype . |
229,471 | def content ( self , output = None , str_output = None , ** kwargs ) : if self . response . mimetype != "text/html" : raise Failure ( _ ( "expected request to return HTML, but it returned {}" ) . format ( self . response . mimetype ) ) with warnings . catch_warnings ( ) : warnings . filterwarnings ( "ignore" , category... | Searches for output regex within HTML page . kwargs are passed to BeautifulSoup s find function to filter for tags . |
229,472 | def _send ( self , method , route , data , params , ** kwargs ) : route = self . _fmt_route ( route , params ) log ( _ ( "sending {} request to {}" ) . format ( method . upper ( ) , route ) ) try : self . response = getattr ( self . _client , method . lower ( ) ) ( route , data = data , ** kwargs ) except BaseException... | Send request of type method to route . |
229,473 | def compile ( checks ) : out = [ "import check50" ] for name , check in checks . items ( ) : out . append ( _compile_check ( name , check ) ) return "\n\n" . join ( out ) | Returns compiled check50 checks from simple YAML checks in path . |
229,474 | def days_at_time ( days , t , tz , day_offset = 0 ) : days = pd . DatetimeIndex ( days ) . tz_localize ( None ) if len ( days ) == 0 : return days . tz_localize ( UTC ) delta = pd . Timedelta ( days = day_offset , hours = t . hour , minutes = t . minute , seconds = t . second , ) return ( days + delta ) . tz_localize (... | Create an index of days at time t interpreted in timezone tz . |
229,475 | def weekend_boxing_day ( start_date = None , end_date = None , observance = None ) : return Holiday ( "Weekend Boxing Day" , month = 12 , day = 28 , days_of_week = ( MONDAY , TUESDAY ) , start_date = start_date , end_date = end_date , observance = observance , ) | If boxing day is saturday then Monday 28th is a holiday If boxing day is sunday then Tuesday 28th is a holiday |
229,476 | def is_holiday_or_weekend ( holidays , dt ) : one_day = timedelta ( days = 1 ) for h in holidays : if dt in h . dates ( dt - one_day , dt + one_day ) or dt . weekday ( ) in WEEKENDS : return True return False | Given a list of holidays return whether dt is a holiday or it is on a weekend . |
229,477 | def next_non_holiday_weekday ( holidays , dt ) : day_of_week = dt . weekday ( ) if day_of_week == SUNDAY : while is_holiday_or_weekend ( holidays , dt ) : dt += timedelta ( 1 ) return dt | If a holiday falls on a Sunday observe it on the next non - holiday weekday . |
229,478 | def compute_all_minutes ( opens_in_ns , closes_in_ns ) : deltas = closes_in_ns - opens_in_ns daily_sizes = ( deltas // NANOSECONDS_PER_MINUTE ) + 1 num_minutes = daily_sizes . sum ( ) pieces = [ ] for open_ , size in zip ( opens_in_ns , daily_sizes ) : pieces . append ( np . arange ( open_ , open_ + size * NANOSECONDS_... | Given arrays of opens and closes both in nanoseconds return an array of each minute between the opens and closes . |
229,479 | def get_calendar ( self , name ) : canonical_name = self . resolve_alias ( name ) try : return self . _calendars [ canonical_name ] except KeyError : pass try : factory = self . _calendar_factories [ canonical_name ] except KeyError : raise InvalidCalendarName ( calendar_name = name ) calendar = self . _calendars [ can... | Retrieves an instance of an TradingCalendar whose name is given . |
229,480 | def register_calendar ( self , name , calendar , force = False ) : if force : self . deregister_calendar ( name ) if self . has_calendar ( name ) : raise CalendarNameCollision ( calendar_name = name ) self . _calendars [ name ] = calendar | Registers a calendar for retrieval by the get_calendar method . |
229,481 | def register_calendar_type ( self , name , calendar_type , force = False ) : if force : self . deregister_calendar ( name ) if self . has_calendar ( name ) : raise CalendarNameCollision ( calendar_name = name ) self . _calendar_factories [ name ] = calendar_type | Registers a calendar by type . |
229,482 | def register_calendar_alias ( self , alias , real_name , force = False ) : if force : self . deregister_calendar ( alias ) if self . has_calendar ( alias ) : raise CalendarNameCollision ( calendar_name = alias ) self . _aliases [ alias ] = real_name try : self . resolve_alias ( alias ) except CyclicCalendarAlias : del ... | Register an alias for a calendar . |
229,483 | def resolve_alias ( self , name ) : seen = [ ] while name in self . _aliases : seen . append ( name ) name = self . _aliases [ name ] if name in seen : seen . append ( name ) raise CyclicCalendarAlias ( cycle = " -> " . join ( repr ( k ) for k in seen ) ) return name | Resolve a calendar alias for retrieval . |
229,484 | def deregister_calendar ( self , name ) : self . _calendars . pop ( name , None ) self . _calendar_factories . pop ( name , None ) self . _aliases . pop ( name , None ) | If a calendar is registered with the given name it is de - registered . |
229,485 | def clear_calendars ( self ) : self . _calendars . clear ( ) self . _calendar_factories . clear ( ) self . _aliases . clear ( ) | Deregisters all current registered calendars |
229,486 | def _overwrite_special_dates ( midnight_utcs , opens_or_closes , special_opens_or_closes ) : if not len ( special_opens_or_closes ) : return len_m , len_oc = len ( midnight_utcs ) , len ( opens_or_closes ) if len_m != len_oc : raise ValueError ( "Found misaligned dates while building calendar.\n" "Expected midnight_utc... | Overwrite dates in open_or_closes with corresponding dates in special_opens_or_closes using midnight_utcs for alignment . |
229,487 | def is_open_on_minute ( self , dt ) : return is_open ( self . market_opens_nanos , self . market_closes_nanos , dt . value ) | Given a dt return whether this exchange is open at the given dt . |
229,488 | def next_open ( self , dt ) : idx = next_divider_idx ( self . market_opens_nanos , dt . value ) return pd . Timestamp ( self . market_opens_nanos [ idx ] , tz = UTC ) | Given a dt returns the next open . |
229,489 | def next_close ( self , dt ) : idx = next_divider_idx ( self . market_closes_nanos , dt . value ) return pd . Timestamp ( self . market_closes_nanos [ idx ] , tz = UTC ) | Given a dt returns the next close . |
229,490 | def previous_open ( self , dt ) : idx = previous_divider_idx ( self . market_opens_nanos , dt . value ) return pd . Timestamp ( self . market_opens_nanos [ idx ] , tz = UTC ) | Given a dt returns the previous open . |
229,491 | def previous_close ( self , dt ) : idx = previous_divider_idx ( self . market_closes_nanos , dt . value ) return pd . Timestamp ( self . market_closes_nanos [ idx ] , tz = UTC ) | Given a dt returns the previous close . |
229,492 | def next_minute ( self , dt ) : idx = next_divider_idx ( self . _trading_minutes_nanos , dt . value ) return self . all_minutes [ idx ] | Given a dt return the next exchange minute . If the given dt is not an exchange minute returns the next exchange open . |
229,493 | def previous_minute ( self , dt ) : idx = previous_divider_idx ( self . _trading_minutes_nanos , dt . value ) return self . all_minutes [ idx ] | Given a dt return the previous exchange minute . |
229,494 | def next_session_label ( self , session_label ) : idx = self . schedule . index . get_loc ( session_label ) try : return self . schedule . index [ idx + 1 ] except IndexError : if idx == len ( self . schedule . index ) - 1 : raise ValueError ( "There is no next session as this is the end" " of the exchange calendar." )... | Given a session label returns the label of the next session . |
229,495 | def previous_session_label ( self , session_label ) : idx = self . schedule . index . get_loc ( session_label ) if idx == 0 : raise ValueError ( "There is no previous session as this is the" " beginning of the exchange calendar." ) return self . schedule . index [ idx - 1 ] | Given a session label returns the label of the previous session . |
229,496 | def minutes_for_session ( self , session_label ) : return self . minutes_in_range ( start_minute = self . schedule . at [ session_label , 'market_open' ] , end_minute = self . schedule . at [ session_label , 'market_close' ] , ) | Given a session label return the minutes for that session . |
229,497 | def execution_minutes_for_session ( self , session_label ) : return self . minutes_in_range ( start_minute = self . execution_time_from_open ( self . schedule . at [ session_label , 'market_open' ] , ) , end_minute = self . execution_time_from_close ( self . schedule . at [ session_label , 'market_close' ] , ) , ) | Given a session label return the execution minutes for that session . |
229,498 | def sessions_in_range ( self , start_session_label , end_session_label ) : return self . all_sessions [ self . all_sessions . slice_indexer ( start_session_label , end_session_label ) ] | Given start and end session labels return all the sessions in that range inclusive . |
229,499 | def minutes_in_range ( self , start_minute , end_minute ) : start_idx = searchsorted ( self . _trading_minutes_nanos , start_minute . value ) end_idx = searchsorted ( self . _trading_minutes_nanos , end_minute . value ) if end_minute . value == self . _trading_minutes_nanos [ end_idx ] : end_idx += 1 return self . all_... | Given start and end minutes return all the calendar minutes in that range inclusive . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.