content
stringlengths
42
6.51k
def _sort_key_max_confidence_sd(sample): """Samples sort key by the max. confidence_sd.""" max_confidence_sd = float("-inf") for inference in sample["inferences"]: confidence_sd = inference.get("confidence_sd", float("-inf")) if confidence_sd > max_confidence_sd: max_confidence_s...
def route(*ends) -> str: """Formats into a route. route("api", "botLogin") -> "https://analyticord.solutions/api/botLogin """ s = "https://analyticord.solutions" return "/".join((s, *ends))
def stringToPercentage(s) : """Converts a string describing a percentage to a float. The string s can be of any of the following forms: 60.2%, 60.2, or 0.602. All three of these will be treated the same. Without the percent sign, it is treated the same as with the percent sign if the value is gr...
def swap_values(x: int, y: int) -> tuple: """ Returns swap values """ temp = x x = y y = temp return x, y
def as_int(n): """ Convert the argument to a builtin integer. The return value is guaranteed to be equal to the input. ValueError is raised if the input has a non-integral value. Examples ======== >>> 3.0 3.0 >>> as_int(3.0) # convert to int and test for equality 3 >>> in...
def set_max_call_stack_size_to_capture(size: int) -> dict: """ Parameters ---------- size: int **Experimental** """ return {"method": "Runtime.setMaxCallStackSizeToCapture", "params": {"size": size}}
def create_marker_and_content(genome_property_flat_file_line): """ Splits a list of lines from a genome property file into marker, content pairs. :param genome_property_flat_file_line: A line from a genome property flat file line. :return: A tuple containing a marker, content pair. """ columns ...
def merged_codepoints(cps): """ return a list of codepoints (start, end) for inclusive ranges """ if not cps: return [] cps = sorted(cps, key=lambda cp: cp.codepoint) ranges = [(cps[0], cps[0])] for cp in cps[1:]: last_range = ranges[-1] if cp.codepoint == last_range[1].codepoint + 1: ranges...
def generate_freq_vector(index_vector, max_freq, number_of_freq_estimations): """building frequency vector""" return index_vector*max_freq/number_of_freq_estimations
def parse_keypair_lines(content, delim='|', kv_sep='='): """ Parses a set of entities, where each entity is a set of key-value pairs contained all on one line. Each entity is parsed into a dictionary and added to the list returned from this function. """ r = [] if content: for row i...
def hpo_genes_from_dynamic_gene_list(case_obj, is_clinical, clinical_symbols): """ Case where dynamic_panel_phenotypes is empty, perhaps because user has added custom genes to HPO panel Args: case_obj(dict): models.Case) is_clinical(bool): if True, only list genes from HPO that are among th...
def tf(seconds): """ Formats time in seconds to days, hours, minutes, and seconds. Parameters ---------- seconds : float The time in seconds. Returns ------- str The formatted time. """ days = seconds // (60*60*24) seconds -= days * 60*60*24 hours = sec...
def squote(text): """Return a string surrounded by single quotes""" return "'{}'".format(text)
def decision_boundary(prob): """ Convert a probability `prob` into a class and return 1 if `prob` >= 0.5, otherwise return 0 """ return 1 if prob >= .5 else 0
def define_body_for_add_ip_command(list_target, mask, ip_address, duration, note, tags): """ API docs: https://portal.f5silverline.com/docs/api/v1/ip_objects.md (POST section) prepares the body of a POST request in order to add an IP """ return \ { "list_target": list_target, ...
def hours_difference(time_1, time_2): """ (number, number) -> float Return the number of hours later that a time in seconds time_2 is than a time in seconds time_1. >>> hours_difference(1800.0, 3600.0) 0.5 >>> hours_difference(3600.0, 1800.0) -0.5 >>> hours_difference(1800.0, 2...
def get_acaddress(core_data): """ returns address for aircraft oem if it exists. """ if core_data != 'error': try: core_data = core_data[1] children = list(core_data.children) for i, child in enumerate(children): for t in child: ...
def masked_by_quotechar(data, quotechar, escapechar, test_char): """Test if a character is always masked by quote characters This function tests if a given character is always within quoted segments (defined by the quote character). Double quoting and escaping is supported. Parameters ---------- ...
def make_ks(reverse=False): """ks are the bits of the ints from 0 to 7, used as truth flags for vars in predicates. I.e. 0 means the denial of a var, 0 for var X means notX 1 for var X means X is true """ ks = [] for i in range(2): for j in range(2): for k in range(2): if reverse: ks.append((1-i,1-...
def filter_matching_fields(fields, other_fields): """return fields which are same as in other_fields list, ignoring the case""" other_fields_lowercase = set([f.lower() for f in other_fields]) return [f for f in fields if f.lower() in other_fields_lowercase]
def _as_windows_path(s): """Returns the input path as a Windows path (replaces all of "/" with "\").""" return s.replace("/", "\\")
def derivs1(t,x,v): """ Derivatives for simple harm. osc. (\"sliding block\") """ dxdt = v dvdt = -x return(dxdt, dvdt)
def stimulus(t): """ External Current | :param t: time | :return: step up to 10 uA/cm^2 at t>100 | step down to 0 uA/cm^2 at t>200 | step up to 35 uA/cm^2 at t>300 | step down to 0 uA/cm^2 at t>400 """ return 10 * (t > 100) - 10 * (t > 200) + 35 * (t ...
def preprocess_sents(sentences_list): """Clean up sentences predicted by TRAM""" prepocessed_sents = [] for s in sentences_list: # Replace any new lines separating parts of the sentence s = s.replace('\n', ' ') # Replace any double spaces which might result from previous step with a...
def get_max_digits(numbers): """ Return the amount of digits of the largest number. """ list_digits = [] for item in numbers: list_digits.append(int(len(str(item)))) return int(max(list_digits))
def string_search(lst, stringy): """returns true if any of the strings in lst are in the string stringy Args: lst: list list of strings to check stringy: string string to check Returns: mhm: boolean string ...
def apriori_gen(f_items): """ Create (k+1)-itemsets from all frequent k-itemsets. Those are candidates for frequent (k+1) itemsets. This step is known as 'candidate generation'. """ new_f_items = [] for i, itemset1 in enumerate(f_items): for itemset2 in f_items[i+1:]: # ...
def reverse(t): """Return a tuple with reversed order""" return tuple([t[i] for i in range(len(t)-1, 0, -1)])
def hamming(num): """Returns the nth hamming number""" h = [1] * num x2, x3, x5 = 2,3,5 i = j = k = 0 for n in range(1, num): h[n] = min(x2, x3, x5) if x2 == h[n]: i += 1 x2 = 2 * h[i] if x3 == h[n]: j += 1 x3 ...
def get_drug_targets_from_chembl(cursor, unification_table, user_entity_ids): """ Get the drug targets of a list of drug user entity IDs from ChEMBL """ query_chembl_targets = ("""SELECT U2.userEntityID, E2.type, DB.databaseName FROM {} U1, externalEntityRelationParticipan...
def is_substring_divisible(num): """Return True if a 10 digit numeral has substrings divisible by sequential prime numbers. """ num = str(num) divisibility_condition = (int(num[1:4]) % 2 == 0 and int(num[2:5]) % 3 == 0 and int(num[3:6]) % 5...
def hasmethod(obj, m): """Return ``True`` if object *obj* contains the method *m*.""" return hasattr(obj, m) and callable(getattr(obj, m))
def blocks(text): """Split the text into blocks deliminated by a blank line.""" return text.split("\n\n")
def common_elements(set_1, set_2): """ returns a set of common elements from two sets """ return ({ele for ele in set_1 if ele in set_2})
def run(action, *args, **kwargs): """ :doc: run :name: renpy.run :args: (action) Run an action or list of actions. A single action is called with no arguments, a list of actions is run in order using this function, and None is ignored. Returns the result of the first action to return a...
def calc_error_by_batches(model, data_size, batch_size): """Calculate error in batches using the given valid/test model.""" err = 0.0 beg = 0 while (beg < data_size): end = min(beg+batch_size, data_size) err += model(beg,end) * (end-beg) beg = end return err / data_size
def info(v, row, row_n, i_s, i_d, header_s, header_d, scratch, errors, accumulator): """ Print information about a value, and return the value. Prints out these values: - row_n: The row number - header_d: Schema header - type: The python type of the value - value: The value of the row, truncated to...
def to_bytes_string(value): # type: (...) -> bytes """Convert value to bytes if required.""" return value.encode("utf8") if isinstance(value, type(u"")) else value
def is_subdomain(domain, reference): """Tests if a hostname is a subdomain of a reference hostname e.g. www.domain.com is subdomain of reference @param domain: Domain to test if it is a subdomain @param reference: Reference "parent" domain """ index_of_reference = domain.find(reference) if ...
def is_unsigned_number(number): """ is_unsigned_number :rtype: boolean :param number: :return: """ is_unsigned = False try: number = float(number) except ValueError: is_unsigned = False if number >= 0: is_unsigned = True else: is_unsigned = Fal...
def toKelvin(temp): """ A function to convert given celsius temperature to kelvin. param temp: intger or float returns kelvin temperature """ kelvin = 273.15 + temp return kelvin
def get_array_names(symbols): """Given a set of symbols, return a set of source array names and a set of destination array names. """ src_arrays = set(x for x in symbols if x.startswith('s_') and x != 's_idx') dest_arrays = set(x for x in symbols if x.start...
def reduceQtyVars(nb_min_var:int, dict_values:dict, list_models_var): """ return a list of model_var that the quantities of each variable are upper than the np_min_ar :param nb_min_var: quantity of the minimum variables that you want to save :param dict_values: dictionary with the frequency variables ...
def div(a, b): """Return a divided by b and Raise exception for b==0""" if not b: raise ValueError("Cannot divide by zero!") return a / b
def undunder_keys(_dict): """Returns dict with the dunder keys converted back to nested dicts eg:: >>> undunder_keys({'a': 'hello', 'b__c': 'world'}) {'a': 'hello', 'b': {'c': 'world'}} :param _dict : (dict) flat dict :rtype : (dict) nested dict """ def f(key, value): ...
def merge_results(old_results, new_results): """Update results in new baseline with audit information from old baseline. Secrets only appear in old baseline are ignored. If secret exists in both old and new baselines, old baseline has audit (is_secret) info but new baseline does not, then audit info w...
def get_positions(start_idx, end_idx, length): """ Get subj/obj position sequence. """ return list(range(-start_idx, 0)) + [0]*(end_idx - start_idx + 1) + \ list(range(1, length-end_idx))
def fire_print(requested_print, completed_print): """Function that executes print jobs for requested models """ while requested_print: current_print = requested_print.pop() print(f"\n Currently printing {current_print}") completed_print.append(current_print) return completed_pr...
def sort_orbitals(element_pdos): """Sort the orbitals of an element's projected density of states. Sorts the orbitals based on a standard format. E.g. s < p < d. Will also sort lm decomposed orbitals. This is useful for plotting/saving. Args: element_pdos (dict): An element's pdos. Should be f...
def height(square: float, side3: float): """ Find height of triangle >>> print(height(48, 12)) 8.0 """ height = 2 * square / side3 return height
def max_activities(start: list, end: list) -> int: """ Since the activities are sorted by finish time, we can solve the problem in O(n) time """ return_value: int = 1 index: int = 1 length: int = len(start) prev_index: int = 0 while index < length: if start[index] >= end[prev_in...
def _compute_regularization(alpha, l1_ratio, regularization): """Compute L1 and L2 regularization coefficients for W and H""" alpha_H = 0. alpha_W = 0. if regularization in ('both', 'components'): alpha_H = float(alpha) if regularization in ('both', 'transformation'): alpha_W = float...
def quadratic_func(x, a): """ Define the quadratic function like this: y = 2x^2 + a -1 (read as y is equal to 2 x squared plus a minus 1) :param x: :return: """ y = 2*x**2+a-1 return y
def quick_sort_median(aList, startIndex=0, endIndex=None, comparisons=False): """Sort a list from least to greatest using quicksort Returns a sorted list If 'comparisons' is set to True, it returns the sorted list and the number of comparisons It chooses the median of the fi...
def parseNum(num): """0x or $ is hex, 0b is binary, 0 is octal. Otherwise assume decimal.""" num = str(num).strip() base = 10 if (num[0] == '0') & (len(num) > 1): if num[1] == 'x': base = 16 elif num[1] == 'b': base = 2 else: base = 8 elif num[0]=='$': base = 16 return int(...
def cons_tuple(head, tail): """Implement `cons_tuple`.""" return (head,) + tail
def is_palindrome(word): """Check if a given word is a palindrome.""" if not isinstance(word, str): raise ValueError('Word must be a string') n = len(word) # Edge cases if n == 0: raise ValueError('I still need convincing that empty string ' 'is a palindro...
def sort_peaks(peaks): """ Sort a list of peaks according to the score field """ peaks_sorted = sorted(peaks, key=lambda p: -p['score']) return peaks_sorted
def decode(number: str) -> bool: """Return if number is valid.""" if int(number) > 0 and int(number) < 27: return True return False
def str2bool(v): """Bodge around strange handling of boolean values in ArgumentParser.""" return v.lower() in ('yes', 'true', 't', '1')
def t(s): """Force Windows line endings to Unix line endings.""" return s.replace("\r\n", "\n")
def url(anchor, uri): """Return a Markdown URL.""" return f"[{anchor}]({uri})"
def HexToByte( hexStr ): """ Convert a string hex byte values into a byte string. The Hex Byte values may or may not be space separated. """ bytes = [] hexStr = ''.join( hexStr.split(" ") ) for i in range(0, len(hexStr), 2): bytes.append( chr( int (hexStr[i:i+2], 16 ) ) ) return ...
def adder(x, y): """ Adds two numbers together. >>> adder(3,5) 8 >>> adder(-1,50) 49 """ return x + y + 1
def pair(ratio): """Format a pair of numbers so JavaScript can read them in an attribute.""" return "%s %s" % ratio
def shorten_replication_tasks(replication_tasks): """Returns only relevent fields form replication_tasks object """ tasks = [] for task in replication_tasks: t1 = { "ReplicationTaskIdentifier": task['ReplicationTaskIdentifier'], "Status": task['Status'], "Replicat...
def should_filter(target, stem_mapping, filtered_phrases): """Determine if a noun phrase should be included in the tags list. @param target: The noun phrase in question. @type target: basestring @param stem_mapping: Renaming of noun phrases through which target should be translated before teste...
def energy_emc(mass,speedoflight): """Usage: energy_emc(mass of object, speed of light) - You can use the constant light_speed.""" return mass*speedoflight**2
def email_blacklist_offender(offender_d): """Offender part of a new/deleted blacklist email""" output = "Offender details:\n" output += "* address: %s\n" % offender_d['address'] output += "* cidr: %s\n" % offender_d['cidr'] output += "* score: %s\n" % offender_d['score'] if offender_d['hostname'...
def unpad(string): """Un pad string.""" return string[:-ord(string[len(string) - 1:])]
def reconstruct_full_path(entry): """ Create a unique string representation of a PathSpec object, starting at the root of the dfvfs input object :param entry: A dfvfs path_spec object :return: [str] Representation of the object's location as file path """ if not entry: return None ...
def calculate_max_power(panel_array): """ Returns the maximal product of positive and (odd) negative numbers.""" # Edge case 0: no panels :] if (len(panel_array) == 0): return 0 # Get positive panels positive_panels = list(filter(lambda x: x >0 , panel_array)) #print("positive_p...
def troll_troll_name(results): """ retrieve troll name from item """ name = results['by'] return name
def format_satoshis_plain_nofloat(x, decimal_point = 8): """Display a satoshi amount scaled. Always uses a '.' as a decimal point and has no thousands separator. Does not use any floating point representation internally, so no rounding ever occurs. """ x = int(x) xstr = str(abs(x)) if dec...
def pct_format(x, y): """ Returns x/y in percent as a formatted string with two decimal places. """ return "{:.2f} %".format((x / y) * 100)
def has_same_digits(num1: int, num2: int) -> bool: """ Return True if num1 and num2 have the same frequency of every digit, False otherwise. digits[] is a frequency table where the index represents the digit from 0-9, and the element stores the number of appearances. Increment the respec...
def format_msg(wiki_link: str): """Return html formatted email content.""" contents = f''' <!DOCTYPE html> <html> <body> <div style="text-align:center;"> <h1>Your Weekly Article:</h1> <a href="{wiki_link}">{wiki_link}</a> </div> </b...
def need_fake_wells(tsclass, well_model): """ Return boolean to see if fake wells are needed """ if well_model == 'fake': abst_rxn = bool('abstraction' in tsclass) # addn_rxn = bool('addition' in tsclass) subs_rxn = bool('substitution' in tsclass) need = bool(abst_rxn or subs...
def folders_paths(paths): """Return a list of only folders from a list of paths""" folders = [x for x in paths if x.is_dir()] return folders
def ax_in(ma, ga): """ Returns a dictionary with axion parameters. Parameters ---------- ma : axion mass [eV] ga : axion-photon coupling [GeV^-1] """ axion_input = {'ma': ma, 'ga': ga} return axion_input
def _occupation_set(index): """The bits whose parity stores the occupation of mode `index`.""" indices = set() # For bit manipulation we need to count from 1 rather than 0 index += 1 indices.add(index - 1) parent = index & (index - 1) index -= 1 while index != parent: indices.a...
def _strip(line): """Line endings variety shall not complicate the parser.""" return line.strip().rstrip('\r')
def generate_autopep8_command(file: str) -> str: """ Generate the autopep8 command for a file. Parameters ---------- file : str The file to fix. Returns ------- str The autopep8 command. """ cmd = f"autopep8 {file} -a -a -a -a -a -i -v" return cmd
def diff_list(first, second): """ Get difference of lists. """ second = set(second) return [item for item in first if item not in second]
def stop_list_to_link_list(stop_list): """ [a, b, c, d] -> [(a,b), (b,c), (c,d)] """ return list(zip(stop_list[:-1], stop_list[1:]))
def findByRef(ref="", dataset=[]): """Summary or Description of the Function Parameters: argument1 (int): Description of arg1 Returns: int:Returning value """ if ref=="": # logger.info("No Reference Supplied to findByRef function") return {"result": "error1"} if (...
def cast_int(str): """a helper method for converting strings to their integer value Args: str: a string containing a number Returns: the integer value of the string given or None if not an integer """ try: v = int(str) except: v = None return v
def sequences_add_end_id(sequences, end_id=888): """Add special end token(id) in the end of each sequence. Parameters ----------- sequences : list of list of int All sequences where each row is a sequence. end_id : int The end ID. Returns ---------- list of list of int ...
def xTrans(thing, transforms): """Applies set of transformations to a thing. :args: - thing: string; if None, then no processing will take place. - transforms: iterable that returns transformation function on each turn. Returns transformed thing.""" if thing == None: return N...
def get_ev(ev, keys=None, ikpt=1): """Get the correct list of the energies for this eigenvalue.""" res = False if keys is None: ener = ev.get('e') spin = ev.get('s') kpt = ev.get('k') if not kpt and ikpt == 1: kpt = True elif kpt and kpt != ikpt: ...
def key2num(key): """ Translates MIDI key to a number. """ key2num = {"C": 0, "Db": 1, "D": 2, "Eb": 3, "E": 4, "F": 5, "Gb": 6, "G": 7, "Ab": 8, "A": 9, "Bb": 10, "B": 11, "Cb": 11, "C#": 1, "D#": 3, "F#": 6, "G#": 8, "A#": 10, "B#": 0, "Cmin": 20, "Dbmin": 21, "Dmin": 22, "Ebmin": 23, "Emin": 24, "Fmin": ...
def getCasing(word): """ Returns the casing of a word""" if len(word) == 0: return 'other' elif word.isdigit(): #Is a digit return 'numeric' elif word.islower(): #All lower case return 'allLower' elif word.isupper(): #All upper case return 'allUpper' elif word[0...
def name_to_number(name): """ Converts a string called name to an integer. Otherwise, it sends an error message letting you know that an invalid choice was made. """ if name == "rock": return 0 elif name == "Spock": return 1 elif name == "paper": retu...
def sol(arr, m, n): """ The sliding approach """ l = 0 r = 0 c = 0 res = 0 # Intialize left right and zero count to 0 while r < n: if c <= m: if arr[r] == 0: c+=1 r+=1 # Keep moving right and if zero count is less than or equal to m...
def isValid(text): """ Returns True if input is related to the time. Arguments: text -- user-input, typically transcribed speech """ if text.lower() == "what time is it" or text.lower() == "what is the time": return True else: return False
def get_host_latency (host_url) : """ This call measures the base tcp latency for a connection to the target host. Note that port 22 is used for connection tests, unless the URL explicitly specifies a different port. If the used port is blocked, the returned latency can be wrong by orders of magn...
def get_download_url_path_for_minecraft_lib(descriptor): """ Gets the URL path for a library based on it's name :param descriptor: string, e.g. "com.typesafe.akka:akka-actor_2.11:2.3.3" :return: string """ ext = "jar" pts = descriptor.split(":") domain = pts[0] name = pts[1] la...
def get_the_trees(DTA): """ Get the bracket trees from the list of (winner, score, loser, score) tuples """ losers = set() winner_tree = {} loser_tree = {} for team1, score1, team2, score2 in DTA: tree = loser_tree if team1 in losers else winner_tree losers.add(team2) h = tre...
def performanceMinCalculator(count, avg, std, maxv, countref, avgref, stdref, maxvref): """ =========================================================================== Performance calculator function using max value This would be the worst case ======================================================...
def proc_alive(process): """Check if process is alive. Return True or False.""" return process.poll() is None if process else False