content
stringlengths
35
416k
sha1
stringlengths
40
40
id
int64
0
710k
def max_size(resize_info): """ リサイズ情報から結合先として必要な画像サイズを計算して返す :param resize_info: リサイズ情報 :return: width, height """ max_w, max_h = 0, 0 for name, info in resize_info.items(): pos = info['pos'] size = info['size'] max_w = max(max_w, pos[0] + size[0]) max_h = max...
1e28f993b3b0fac077f234b6388a2d9042396f6b
5,879
def quicksort(lyst): """This is a quicksort """ def partition_helper(lyst, first, last): pivot = lyst[first] left = (first + 1) right = last done = False while not done: while left <= right and lyst[left] <= pivot: left += 1 whi...
33385c01b877a86a2970f33dc4d0bd9d456dc983
5,880
def _validate_time_mode(mode, **kwargs): """Validate time mode.""" return mode
e30fd9071bde102b4986fe9ef846a812f7c08ff7
5,881
async def root(): """ Dependency is "static". Value of Depends doesn't get passed into function we still get redirected half the time though """ return {"message": "Hello World"}
6d3b634444240275f56d30aa0c1fe3b3bb84ce24
5,883
def getLatest(df): """ This get the data of the last day from the dataframe and append it to the details """ df_info = df.iloc[:,0:5] df_last = df.iloc[:,-1] df_info['latest'] = df_last return df_info
f42cae0552a4ac791d3499fa2ca1417a80a970ac
5,884
def strip_long_text(text, max_len, append=u'…'): """Returns text which len is less or equal max_len. If text is stripped, then `append` is added, but resulting text will have `max_len` length anyway. """ if len(text) < max_len - 1: return text return text[:max_len - len(append)] + append
02ce128f1de1dbeb2a2dcef5bc2b6eb8745322d3
5,886
def jsonify_query_result(conn, query): """deprecated""" res = query.all() #res = conn.execute(query) #return [dict(r) for r in res] return [r._asdict() for r in res]
ca11226c6f6fc731089f1d257db02a6cb83bd145
5,888
def tuplify2d(x): """Convert ``x`` to a tuple of length two. It performs the following conversion: .. code-block:: python x => x if isinstance(x, tuple) and len(x) == 2 x => (x, x) if not isinstance(x, tuple) Args: x (any): the object to be converted Returns: tupl...
64170b14dbe7eb8885d21f45acff6b43979f1219
5,894
import os def get_scene_info(path): """Extract information about the landsat scene from the file name""" fname = os.path.basename(path) parts = fname.split('_') output = {} output['sensor'] = parts[0] output['lpath' ] = parts[2][0:3] output['lrow' ] = parts[2][3:6] output['date' ] ...
4a1bbad4d8b9b2b1ad21ca78ca7a046d92232699
5,895
def earlyon(time,duration,*args): """ Some lights have a slight delay before they turn on (capacitors that need to be charged up?). This takes the current time and subtracts that delay so the code looks like they turn on at the right time, but we really send the command a little bit early to give th...
5671d46ffe42bd456689cffc3ce3e1f6731101c8
5,896
def parse_id_as_interval(id_string, regex): """ The fasta ids contain the locus information. """ match = regex.match(id_string) genome = match.group("genome") seqid = match.group("seqid") start_tmp = int(match.group("start")) end_tmp = int(match.group("end")) start = min([start_tmp, end_tm...
7d35bdd7b4418d1edcd433cd39b9defc9050c6f6
5,898
def map_sentences_to_indices_of_vectors(sentences, word_to_index_glove, unknown_token): """ map senteces to integers that represent the index of each word in the glove vocabulary """ # the list to be returned mapped_sentences = [] # get the index of the unknown token unknown_token_index = word_to_...
04a27bd4ccd5ac9d0366218107ee36b61d4a7655
5,899
def updateShaderState(self): """Updates all shader program variables. """ if not self.ready(): return opts = self.opts self.shader.load() voxValXform = self.imageTexture.voxValXform voxValXform = [voxValXform[0, 0], voxValXform[0, 3], 0, 0] invNumLabels = 1.0 / (opts.lut.max() ...
611b093ce51e99e5c7c1e3da5dcc7cd1a8c07b01
5,900
def get_request_fixture_names(request): """Get list of fixture names for the given FixtureRequest. Get the internal and mutable list of fixture names in the enclosing scope of the given request object. Compatibility with pytest 3.0. """ return request._pyfuncitem._fixtureinfo.names_closure
665fff4538f3817b6eb882f9a873683d69003bfd
5,901
def check_version(stdout): """Check version of Ensembl-VEP. Example of the first part of an output from the command `vep --help`: #----------------------------------# # ENSEMBL VARIANT EFFECT PREDICTOR # #----------------------------------# Versions: ensembl : 104.1af1dce ...
5c3b716db7016f1b612f764fb54e3b25d970b0f2
5,902
import argparse def parse_cli_args(): """ These flags are the ones required by the Stream Deck SDK's registration procedure. They'll be set by the Stream Deck desktop software when it launches our plugin. """ parser = argparse.ArgumentParser( description='Stream Deck Google Meet Plugin') ...
adcad9860336482b2072ef8aecd398a2f4ce3b45
5,903
def left_join(ht1, ht2): """ :param ht1: left hash table :param ht2: right hash table :return: list of joined values from both hash tables """ results = [] for item in ht1.table: while item is not None: key = item.val[0] joined = [key, ht1.get(key), ht2.get(k...
8f34e03d055a32ea337b27cd800eeb393d136dfa
5,904
import os import glob import warnings def get_geos_install_prefix(): """Return GEOS installation prefix or None if not found.""" env_candidate = os.environ.get("GEOS_DIR", None) if env_candidate is not None: candidates = [env_candidate] else: candidates = [os.path.expanduser("~/local"...
79193b7a515f961dacdb666a6c25d038b3a14e0c
5,906
def _get_trip_from_id(trip_obj_list, trip_id): """ Get a trip from a list, based on a trip id """ found_trip_obj = None for trip_obj in trip_obj_list: if trip_obj.id == trip_id: found_trip_obj = trip_obj break return found_trip_obj
f2bbacfccda1e4ff778ba793ad238f744400f020
5,907
import os def countOriginals(subfolderPath): """return count of original vids""" items = os.listdir(subfolderPath) count = 0 for file in items: if file.startswith("Original_") and file.endswith(".description"): count = count + 1 return count
116ffa4fecf911d0dec436c5003acb2c9f42a673
5,908
def to_camel_case(string: str) -> str: """ Converts a ``snake_case`` string to ``camelCase``. :param string: A ``snake_case`` string. :return: A ``camelCase`` version of the input. """ components = string.split("_") return components[0] + "".join(x.capitalize() for x in components[1:])
ae0d82efd9a5a65ef16cc401a0fe302b4f04d524
5,909
def parse_qsub_defaults(parsed): """Unpack QSUB_DEFAULTS.""" d = parsed.split() if type(parsed) == str else parsed options={} for arg in d: if "=" in arg: k,v = arg.split("=") options[k.strip("-")] = v.strip() else: options[arg.strip("-")] = "" ...
a5c50aef405d88bcb018af48904a384b090d22a2
5,910
import collections def count_tweet_shed_words_freq(tweet_text, ind_shed_word_dict, shed_word_ind_dict, shed_words_set): """ Count the frequency of selected Hedonometer words in tweet text. param tweet_text: String of text field of tweet return: dict of shed_word_ind to shed_word_freq mapping...
129130f5b9def7320c6e3dd2d8ef82493d21eb8a
5,914
def posts(parsed): """Calculates number of every type of post""" num_t_post = 0 num_corner_post = 0 num_line_post = 0 num_end_post = 0 num_gate_posts = 0 for post in parsed.posts(): if not post.isRemoval: if post.postType == 'tPost': num_t_post += 1 ...
e8c5905a38ab560f0dba595eecf67865efc27121
5,915
def fasta(file_allname: str): """ 需要传入file_allname的路径 :param file_allname: :return: 返回fasta格式的序列list """ try: # file_allname = input("输入你要分析出的文件,包括后缀名\n") f = open(file_allname).read() fasts = f.split(">") fast_seq = [] index = 0 for fast in fasts:...
bbd03531a7d311c322fdbd66e401788fb6526120
5,917
def format_size(size): """ :param float size: :rtype: str """ size = float(size) unit = 'TB' for current_unit in ['bytes', 'KB', 'MB', 'GB']: if size < 1024: unit = current_unit break size /= 1024 return '{0:.2f}'.format(size).rstrip('0').rstrip('...
95470360fcc34df5a51a7cf354138413b41940aa
5,918
def rc_seq(seq=""): """Returns the reverse compliment sequence.""" rc_nt_ls = [] rc_dict = { "a": "t", "c": "g", "t": "a", "g": "c", "n": "n", "A": "T", "C": "G", "T": "A", "G": "C", "N": "N" } rc_nt_ls = [rc_dict[seq[i]...
827877a76d4ffbe61e40e4f00641afa4277f3ff5
5,919
import six def get_rotation(rotation): """ Return the text angle as float. The returned angle is between 0 and 360 deg. *rotation* may be 'horizontal', 'vertical', or a numeric value in degrees. """ try: angle = float(rotation) except (ValueError, TypeError): isString = is...
7ed0fd31f9a90ddb5743faa8e45e46f0d5cc08bd
5,920
def insert_with_key_enumeration(agent, agent_data: list, results: dict): """ Checks if agent with the same name has stored data already in the given dict and enumerates in that case :param agent: agent that produced data :param agent_data: simulated data :param results: dict to store data into :...
d2d653dcff20836c4eaf8cf55b31b1a1209a4ddd
5,922
import argparse def get_args(): """Get command-line arguments""" parser = argparse.ArgumentParser( description='First Bank of Change', formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser.add_argument('value', metavar='int', type=int, help='Sum') args = parser.parse_args()...
117ae5596c95154ac0dc10fd9b1793d89d471da8
5,923
def min__to__s(): """Convert minute to second""" return '6.0E+1{kind}*{var}'
2730af2cc79a6c4af6d1b18f79326623c0fd0289
5,924
def score_per_term(base_t, mis_t, special_t, metric): """Computes three distinct similarity scores for each list of terms. Parameters ---------- base_t, mismatch_t special_t: list of str Lists of toponym terms identified as base, mismatch or frequent (special) respectively. metric: str ...
55e5b9b0d9feaa359ab0907b399eb37514dcfacd
5,925
def do_simple_math(number1, number2, operator): """ Does simple math between two numbers and an operator :param number1: The first number :param number2: The second number :param operator: The operator (string) :return: Float """ ans = 0 if operator is "*": ans = number1 * nu...
eb745f9c3f3c1e18de30cbe6c564d68c29e39ff4
5,926
def snake(string): """snake_case""" return "_".join(string.split())
6bf99dede918937ad59ec9be14ffade8fadb5794
5,928
def generateKeys(): """ generates and returns a dictionary containing the original columns names from the LIDAR file as values and the currently used column names as corresponding keys ws_1 : Speed Value.1 dir_1 : Direction Value.1 h_1 : Node RT01 Lidar Height """ keys = {"ws_0" :...
9d0d55c3fdc32ddda46da4a9e876d4ce1ecde25d
5,929
def get_uniprot_homologs(rev=False): """As above, but exclusively uniprot => mouse uniprot""" homologs = {} with open('data/corum_mouse_homologs.txt') as infile: data = [line.strip().split('\t') for line in infile] for line in data: original = line[1].split('|')[1] uniprot = line...
969085375265b90b5501b4b86eaaed3e1c48795f
5,930
def is_intersection(g, n): """ Determine if a node is an intersection graph: 1 -->-- 2 -->-- 3 >>> is_intersection(g, 2) False graph: 1 -- 2 -- 3 | 4 >>> is_intersection(g, 2) True Parameters ---------- g : networkx DiGraph n : node id R...
415e5154095cd78112ef029b6c4d62c36da0b3b8
5,932
import typing def tokenize(data: typing.Union[str, typing.Sequence[str]]) -> list[str]: """break up string into tokens, tokens can be separated by commas or spaces creates separate tokens for: - "(" or "[" at beginning - ")" or "]" at end """ # break into tokens if isinstance(data, str):...
832343067c8777aa386c0c87c2c4e8202a7cb88f
5,934
def de_comma(string): """Remove any trailing commas >>> de_comma(',fred,,') == ',fred' True """ return string.rstrip(',')
453d615c1fbbef5139d05d6e4510731c969d6a86
5,935
import pickle def get_actual_data(base, n_run, log_path, subfolders): """ :param base: the sub folder name right before the _DATE_InstanceNumber :param n_run: the INSTANCE number in the subfolder name :param log_path: path to the main log folder containing all the runs of an experiment (e.g. ../data/C...
b9f76b14b90e3c187e19bcd0b8bbbfe865518fe7
5,936
def secs_to_str(secs): """Given number of seconds returns, e.g., `02h 29m 39s`""" units = (('s', 60), ('m', 60), ('h', 24), ('d', 7)) out = [] rem = secs for (unit, cycle) in units: out.append((rem % cycle, unit)) rem = int(rem / cycle) if not rem: break if re...
0918fd72fbaaa0adf8fe75bcb1ef39b4e9aba75b
5,937
def get_computed_response_text_value(response): """ extract the text message from the Dialogflow response, fallback: None """ try: if len(response.query_result.fulfillment_text): return response.query_result.fulfillment_text elif len(response.query_result.fulfillment_mes...
fa7410ac4b0ef2c0dea59b0e9d001a7893a56479
5,938
def stairmaster_mets(setting): """ For use in submaximal tests on the StairMaster 4000 PT step ergometer. Howley, Edward T., Dennis L. Colacino, and Thomas C. Swensen. "Factors Affecting the Oxygen Cost of Stepping on an Electronic Stepping Ergometer." Medicine & Science in Sports & Exercise 24.9 (1992): n...
1d6cc9fc846773cfe82dfacb8a34fb6f46d69903
5,940
def clean_cancer_dataset(df_training): """ Checks and cleans the dataset of any potential impossible values, e.g. bi-rads columns, the 1st only allows values in the range of 1-5, ordinal Age, 2nd column, cannot be negative, integer Shape, 3rd column, only allows values between 1 and 4, nominal M...
a30f377b48bb665f42f3efa58b15d289f7e7f9b3
5,941
def isvalid(gridstr, x, y, test_value): """ Check if it would be legal to place a in pos x,y """ sq_indexes = ((0, 1, 2), (3, 4, 5), (6, 7, 8)) group_indexes = [(x_ind, y_ind) for x_ind in sq_indexes[x // 3] for y_ind in sq_indexes[y // 3]] for index in range(9...
a8481bbb18409814e54ad669bbb14b71e32b1139
5,943
def findPowerPlant(mirror, name): """Return power plant agent, if it exists""" if name in mirror.ppDict: return mirror.ppDict[name] else: print("*** Power Plant '%s' not found." % name) return None
35e432c7ab6dbe57488e2d7f84c3b6d077f2079a
5,944
def check_threshold(service, config_high_threshold, config_low_threshold, curr_util): """ Checks whether Utilization crossed discrete threshold Args: service: Name of the micro/macroservice config_high_threshold: Upper limit threshold to utilization set in config file config_low_thresho...
80bf8ab4f5b2bbac35df7c48764114e213fba580
5,947
def ols_data(): """ draper and smith p.8 """ xs = [35.3, 29.7, 30.8, 58.8, 61.4, 71.3, 74.4, 76.7, 70.7, 57.5, 46.4, 28.9, 28.1, 39.1, 46.8, 48.5, 59.3, 70, 70, 74.5, 72.1, 58.1, 44.6, 33.4, 28.6] ys = [10.98, 11.13, 12.51, 8.4, 9.27, 8.73, 6.36, 8.50, 7.82, 9.14, 8.2...
d741195075a51d1485c9f98031ca405cadf1db93
5,948
def valid_field(obj, field): """Returns ``True`` if given object (BaseDocument subclass or an instance thereof) has given field defined.""" return object.__getattribute__(obj, 'nanomongo').has_field(field)
32e662c5c0e666b7455aacdd6809e31cd20017fe
5,949
def double_bin_pharmacophore_graph(distance, bins, delta): """ Assign two bin values to the distance between pharmacophoric points. Parameters ---------- distance : float The distance that will be binned. bins : np.ndarray Array of bins. It h...
b7dedf4f31b5cd08c9875139df837a57a8117001
5,950
import os def is_empty_dir(target_dir): """return is empty directory or not :param str target_dir: target dir """ for root, _, files in os.walk(target_dir): for f in files: if os.path.isfile(os.path.join(root, f)): return False return True
8de606b422703b7602d62df0fae5c0b341761236
5,951
def is_absolute_url(parsed_url): """ check if it is an absolute url """ return all([parsed_url.scheme, parsed_url.netloc])
578c1443ec18f9b741cd205763604cba2242ac48
5,952
def get_levelized_cost(solution, cost_class='monetary', carrier='power', group=None, locations=None, unit_multiplier=1.0): """ Get the levelized cost per unit of energy produced for the given ``cost_class`` and ``carrier``, optionally for a subset of technologie...
96b8f9a9fceaa932bcee72033e73ad8b9551759d
5,954
def reduce_range_overlaps(ranges): """Given a list with each element is a 2-tuple of min & max, returns a similar list simplified if possible. """ ranges = [ea for ea in ranges if ea] if len(ranges) < 2: return ranges first, *ranges_ordered = list(reversed(sorted(ranges, key=lambda ea: ea[1] - e...
fe62dd8bbb1fd0a985757cc417c9c230659294c5
5,956
import sys def exception_in_stack(): """Return true if we are currently in the process of handling an exception, ie one has been caught in a try block. https://docs.python.org/3/library/sys.html#sys.exc_info """ return sys.exc_info()[0] is not None
71f2076c956fa3bb92751778c29537df7bceac35
5,959
def meta_body(): """Ugoira page data.""" return '{"error":false,"message":"","body":{"src":"https:\/\/i.pximg.net\/img-zip-ugoira\/img\/2019\/04\/29\/16\/09\/38\/74442143_ugoira600x600.zip","originalSrc":"https:\/\/i.pximg.net\/img-zip-ugoira\/img\/2019\/04\/29\/16\/09\/38\/74442143_ugoira1920x1080.zip","mime_...
abf9e01371938467b12721373a0e5fc8fb926016
5,960
import re def format_comments(text="default", line_size=90): """ Takes a string of text and formats it based on rule 1 (see docs). """ # rules to detect fancy comments, if not text regex1 = r"^ *?####*$" # rules to detect fancy comments, if text regex2 = r"^ *?####*([^#\n\r]+)#*" # if ...
6eba4539aa7128d5654ddab7fe08a2e9df6dc738
5,961
def config_to_dict(plato_config): """ Convert the plato config (can be nested one) instance to the dict. """ # convert the whole to dict - OrderedDict plato_config_dict = plato_config._asdict() def to_dict(elem): for key, value in elem.items(): try: value = value._a...
9e68c2859dc33370554f8015f96bd501f827c1b2
5,963
def get_parameter(model, name): """ Finds the named parameter within the given model. """ for n, p in model.named_parameters(): if n == name: return p raise LookupError(name)
ba35b743d9189c94da0dcce27630bba311ea8a46
5,964
import os def _demo_home(options): """For convenience demo home is in the same folder as jar file""" bp, fn = os.path.split(options.jar_file) demo_home = os.path.join(bp, 'demo') assert os.path.isdir(demo_home), 'Folder does not exist: "%s"' % demo_home return demo_home
97cdb9a36e56539719cf3aab1e7a5d0c95d87a1d
5,966
def valid_tetrodes(tetrode_ids, tetrode_units): """ Only keep valid tetrodes with neuron units so that there is corresponding spike train data. :param tetrode_ids: (list) of tetrode ids in the order of LFP data :param tetrode_units: (dict) number of neuron units on each tetrode :return: (list) of t...
c887f5e5c29d841da63fe0cd56c41eda5ddde891
5,967
import os import json async def get_config(guildid): """ :param guildid: :return: Guild-Config as Json """ path = os.path.join("data", "configs", f"{guildid}.json") with open(path, "r") as f: data = json.load(f) return data
4057569c71ac546a504cabe1ec19d6778f6ab6fa
5,969
def rewrite_metadata(content, dic): """From content, which is the old text with the metadata and dic which has the new data, return new_txt which has data replaced by dic content, with relevant headers added """ #Splitting into headers and body. Technically, body is a list of paragraphs where first one is the ...
14f7da66f19c24d073f1fdee4b56d49d28320e71
5,970
def reverse_dict_old(dikt): """ takes a dict and return a new dict with old values as key and old keys as values (in a list) example _reverse_dict({'AB04a':'b', 'AB04b': 'b', 'AB04c':'b', 'CC04x': 'c'}) will return {'b': ['AB04a', 'AB04b', 'AB04c'], 'c': 'CC04x'} """ new_dikt = {...
50155858fbbe52dc8daae66e6a94c8885b80ba05
5,971
def Q(lambda_0, lambda_, eps_c, Delta, norm_zeta2, nu): """ Quadratic upper bound of the duality gap function initialized at lambda_0 """ lmd = lambda_ / lambda_0 Q_lambda = (lmd * eps_c + Delta * (1. - lmd) + 0.5 * nu * norm_zeta2 * (1. - lmd) ** 2) return Q_lambda
e7c624d822713efd9a63e92d40ecb9c13d5ee8d6
5,972
from typing import List import subprocess def import_template_ids() -> List[str]: """Return a list of all the supported template IDs.""" return subprocess.check_output(["meme", "-list-templates"]).decode("utf-8").splitlines()
89914e20965e87e9d9589955000854dc8f8d743b
5,974
def _scale_pot(pot, scale_coeff, numtors): """ Scale the potential """ print('scale_coeff test 0:', scale_coeff, numtors) scale_factor = scale_coeff**(2.0/numtors) print('scale_coeff test:', scale_coeff, numtors, scale_factor) new_pot = {} for idx, val in pot.items(): new_pot[i...
0e634b7766a5822d3b2e80fffa0b56dccee125ab
5,975
import pkg_resources def get_substation_file(): """Return the default substation file for the CONUS.""" return pkg_resources.resource_filename('cerf', 'data/hifld_substations_conus_albers.zip')
7628c7981dd9f82b4210a451ad62fffa72222fe8
5,976
def get_tracer(request): """ Utility function to retrieve the tracer from the given ``request``. It is meant to be used only for testing purposes. """ return request['__datadog_request_span']._tracer
facd1ff0922dcc7743814cfd738d022316ba5d6d
5,977
def build_permissions_response(): """ Build a response containing only speech """ output = "I'm sorry, I was not able to lookup your home town. "\ "With your permission, I can provide you with this information. "\ "Please check your companion app for details" return { 'outp...
4b01a0fa32958127f7c373b0cedf5d518074e29e
5,979
def get_card_names(cards): """ :param cards: List of card JSONs :return: List of card names (str) """ names = [] for card in cards: name = card.get("name") names.append(name) return names
a30ad1ef7d8beaab0451d6f498254b0b5df3cf6d
5,980
import platform def pyversion(ref=None): """Determine the Python version and optionally compare to a reference.""" ver = platform.python_version() if ref: return [ int(x) for x in ver.split(".")[:2] ] >= [ int(x) for x in ref.split(".")[:2] ] else: retur...
2e31c7710b171ad67e56f9dbc1181685e0f32de1
5,981
import os def _escape_space(program): """escape spaces in for windows""" if os.name == "nt" and ' ' in program: return '"' + program + '"' else: return program
67a8fa1544f524e9a2591c3221f48c2c130ef86b
5,982
import re def clean_value(value, suffix): """ Strip out copy suffix from a string value. :param value: Current value e.g "Test Copy" or "test-copy" for slug fields. :type value: `str` :param suffix: The suffix value to be replaced with an empty string. :type suffix: `str` :return: Strippe...
d2ec3b3affbf71411039f234c05935132205ae16
5,983
def list_devices_to_string(list_item): """Convert cfg devices into comma split format. Args: list_item (list): list of devices, e.g. [], [1], ["1"], [1,2], ... Returns: devices (string): comma split devices """ return ",".join(str(i) for i in list_item)
717f40d3fd0c24b93d5859491d3f9f16a2b0a069
5,984
def config_split(config): """ Splits a config dict into smaller chunks. This helps to avoid sending big config files. """ split = [] if "actuator" in config: for name in config["actuator"]: split.append({"actuator": {name: config["actuator"][name]}}) del(config["actua...
2006534ece382c55f1ba3914300f5b6960323e53
5,985
def find_next_square2(sq: int) -> int: """ This version is just more compact. """ sqrt_of_sq = sq ** (1/2) return -1 if sqrt_of_sq % 1 != 0 else int((sqrt_of_sq + 1) ** 2)
62246b78cc065b629961a7283671e776481a8659
5,986
import colorsys def hex_2_hsv(hex_col): """ convert hex code to colorsys style hsv >>> hex_2_hsv('#f77f00') (0.08569500674763834, 1.0, 0.9686274509803922) """ hex_col = hex_col.lstrip('#') r, g, b = tuple(int(hex_col[i:i+2], 16) for i in (0, 2 ,4)) return colorsys.rgb_to_hsv(r/255.0, g/255.0, b/255.0)
a80e9c5470dfc64c61d12bb4b823411c4a781bef
5,987
from pathlib import Path def _drivers_dir() -> str: """ ドライバ格納ディレクトリのパスを返します :return: ドライバ格納ディレクトリのパス """ return str(Path(__file__).absolute().parent.parent.joinpath('drivers'))
45b173099f6df24398791ec33332072a7651fa4f
5,988
def tousLesIndices(stat): """ Returns the indices of all the elements of the graph """ return stat.node2com.keys() #s=stat.node2com.values() global globAuthorIndex global globTfIdfTab #pprint(globAuthorIndex) #pprint(stat.node2com.values()) #glob node->index return [glo...
fa847ee3913d521778ee3462c8e946f0ff001c76
5,989
import os def list_files(root_dir, mindepth = 1, maxdepth = float('inf'), filter_ext=[], return_relative_path=False): """ Usage: d = get_all_files(rootdir, mindepth = 1, maxdepth = 2) This returns a list of all files of a directory, including all files in subdirectories. Full paths are returned....
8df0e009f40e77ef7ed86ef870a9f1e508d876d5
5,990
def location_descriptors(): """Provide possible templated_sequence input.""" return [ { "id": "NC_000001.11:15455", "type": "LocationDescriptor", "location": { "sequence_id": "ncbi:NC_000001.11", "interval": { "start...
da13824ff6f91caa635700759a29fb1f36aae1be
5,991
def calculate_gc(x): """Calculates the GC content of DNA sequence x. x: a string composed only of A's, T's, G's, and C's.""" x = x.upper() return float(x.count('G') + x.count('C')) / (x.count('G') + x.count('C') + x.count('A') + x.count('T'))
aae64ff550ef26e75518bdad8a12b7cda9e060d2
5,992
def no_float_zeros(v): """ if a float that is equiv to integer - return int instead """ if v % 1 == 0: return int(v) else: return v
a33321408c43d164a8ca2c7f1d1bc6270e5708ec
5,993
import torch def quat_mult(q_1, q_2): """Multiplication in the space of quaternions.""" a_1, b_1, c_1, d_1 = q_1[:, 0], q_1[:, 1], q_1[:, 2], q_1[:, 3] a_2, b_2, c_2, d_2 = q_2[:, 0], q_2[:, 1], q_2[:, 2], q_2[:, 3] q_1_q_2 = torch.stack( ( a_1 * a_2 - b_1 * b_2 - c_1 * c_2 - d_1...
dac82e246221f9af552f44ca26089443b8eaadd7
5,994
def _flip_dict_keys_and_values(d): """Switches the keys and values of a dictionary. The input dicitonary is not modified. Output: dict """ output = {} for key, value in d.items(): output[value] = key return output
b861fc3bd194d26ee05b9a56faad3394939064bf
5,995
def hasattrs(object, *names): """ Takes in an object and a variable length amount of named attributes, and checks to see if the object has each property. If any of the attributes are missing, this returns false. :param object: an object that may or may not contain the listed attributes :param n...
f3a2fc308d041ed0de79e3389e30e02660a1d535
5,997
import json def try_parse_json(json_): """Converts the string representation of JSON to JSON. :param str json_: JSON in str representation. :rtype: :class:`dict` if converted successfully, otherwise False. """ if not json_: return False try: return json.loads(json_) excep...
077819cf82e307aacf3e56b11fbba26a79559968
5,999
def field_paths(h5, key='externalFieldPath'): """ Looks for the External Fields """ if key not in h5.attrs: return [] fpath = h5.attrs[key].decode('utf-8') if '%T' not in fpath: return [fpath] path1 = fpath.split('%T')[0] tlist = list(h5[path1]) pa...
578e1a2d0971a94afa665f368e9b72c8f6e449d3
6,001
def get_quantifier(ch, input_iter): """ Parse a quantifier from the input, where "ch" is the first character in the quantifier. Return the minimum number of occurrences permitted by the quantifier and either None or the next character from the input_iter if the next character is not part of the...
36dea445aa416be79e86bb1e7c6f9dbe454c6c2a
6,002
def setup_config(quiz_name): """Updates the config.toml index and dataset field with the formatted quiz_name. This directs metapy to use the correct files Keyword arguments: quiz_name -- the name of the quiz Returns: True on success, false if fials to open file """ try: ...
28aba9399926f27da89953c8b0c6b41d95a12d96
6,003
def compute_protien_mass(protien_string): """ test case >>> compute_protien_mass('SKADYEK') 821.392 """ p={'A':'71.03711','C':'103.00919','D':'115.02694','E':'129.04259','F':'147.06841','G':'57.02146','H':'137.05891','I':'113.08406','K':'128.09496','L':'113.08406','M':'131.04049','N':'114.04293...
86a3ffd0ce3e95fcdf6d510d2865b35aeb93d779
6,004
import logging def find_duration(data): """Finds the duration of the ECG data sequence Finds the duration by looking at the last time value as the first value is always at time = 0 seconds :param data: 2D array of time sequences and voltage sequences :return: Time duration of data sequence ...
e65135457e23886c402e0671d720fe9c5ed257a1
6,005
from typing import Dict def _average_latency(row: Dict): """ Calculate average latency for Performance Analyzer single test """ avg_sum_fields = [ "Client Send", "Network+Server Send/Recv", "Server Queue", "Server Compute", "Server Compute Input", "Serve...
f321cb4d55af605298225f2f0146a9a71ee7895b
6,006
def to_vsizip(zipfn, relpth): """ Create path from zip file """ return "/vsizip/{}/{}".format(zipfn, relpth)
6f5baf380bd7ab8a4ea92111efbc0f660b10f6f8
6,007
def compute_F1(TP, TN, FP, FN): """ Return the F1 score """ numer = 2 * TP denom = 2 * TP + FN + FP F1 = numer/denom Acc = 100. * (TP + TN) / (TP + TN + FP + FN) return F1, Acc
6f012246337534af37ff233ad78d9645907739e3
6,009
def name_full_data(): """Full name data.""" return { "name": "Doe, John", "given_name": "John", "family_name": "Doe", "identifiers": [ { "identifier": "0000-0001-8135-3489", "scheme": "orcid" }, { "identifier...
ac590635dbe33e68dc88acd890d16dd3137befb2
6,010
def requires_moderation(page): """Returns True if page requires moderation """ return bool(page.get_moderator_queryset().count())
8f1cfa852cbeccfae6157e94b7ddf61d9597936e
6,011
from bs4 import BeautifulSoup def get_html_text(html): """ Return the raw text of an ad """ if html: doc = BeautifulSoup(html, "html.parser") return doc.get_text(" ") return ""
14353f368078ea6b1673d1066b0a529cc3e257d9
6,012
def valid_parentheses(string): """ Takes a string of parentheses, and determines if the order of the parentheses is valid. :param string: a string of parentheses and characters. :return: true if the string is valid, and false if it's invalid. """ stack = [] for x in string: if x == "...
e8438404c461b7a113bbbab6417190dcd1056871
6,013