content stringlengths 35 416k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
import json
import yaml
def list_to_yaml(table_list, filename):
"""
Convert a list of strings to YAML file format
"""
X = [x[0].split('||') for x in table_list]
timeseries = [x[1] for x in table_list]
d = {}
for index in range(len(X)):
path = X[index]
current_level = d
... | e31ff812bc1b1f1759c465a226a75c2a6c386a38 | 29,859 |
def column2list(matrix: list, column_idx: int) -> list:
"""
Convert column from features 2D matrix to 1D list of
that feature.
:param matrix: 2D square array of number
:param column_idx: column index in the matrix
:return:
"""
if len(matrix) <= 1:
return matrix if matrix else []
... | 841baf8f6cf6b78c9f41dc90a9ff1759a8285cc8 | 29,860 |
def __join_with_or(times):
"""Returns 'a', 'a or b', or 'a, b, or c'."""
if not times:
return ""
if len(times) == 1:
return times[0]
if len(times) == 2:
return " or ".join(times)
return ", or ".join([", ".join(times[:-1]), times[-1]]) | eec8adc3bf0b013cda315ed81c0ddf1a0a7511c6 | 29,861 |
def parseBool(txt):
"""
Parser for boolean options
:param str txt: String from config file to parse.
:returns: ``True`` if the string is 'True', ``False`` otherwise.
:rtype: boolean
"""
return txt == 'True' | 267c6c09c665735ac3ae766a9fd5259768ff3d40 | 29,862 |
def seq_to_subset(seq_sol, m, n):
"""Convert sequence solution (e.g.: ['r2','c3']) into subset solution (e.g.: [[0,1],[0,0,1]])"""
assert isinstance(seq_sol, list)
subset_sol = [[0]*m,[0]*n]
for e in seq_sol:
if e[0] == 'r':
subset_sol[0][int(e[1:])-1] = (1-subset_sol[0][int(e[1:])-1... | 345e3fab339edbdb059611b2b542917bc43bd6ef | 29,863 |
def fit_FC(model, data):
""" Convenience function to fit a flow curve
Args:
model: rheology model (e.g. HB_model)
data: pandas DataFrame with column 'Shear rate' and 'Stress'
Returns:
lmfit.fitresult
"""
return model.fit(data["Stress"], x=data["Shear rate"], weigh... | 6fca8cf3d2ea965e55b667be27aeaf4bb4fbc402 | 29,864 |
import os
import glob
def make_log_list(log_root_dir, log_type):
"""
Builds a list of Bro log files by recursively searching all subdirectories under
the root directory.
:param top_level_dir: Root directory for the recursive search
:param log_type: Name of the Bro log file to load (e.g., dns)
... | 951107e24f6e9a9411ed426a147446816fbdae1d | 29,866 |
import os
import inspect
def module_relative_path(path):
"""return an absolute path from a given path which
is relative to the calling module"""
if os.path.isabs(path):
return path
calling_file = inspect.stack()[1][1]
calling_dir = os.path.abspath(os.path.dirname(calling_file))
return... | 032942241b67ce5685d237475e1a52c39bb9ebf2 | 29,867 |
def set_cover(universe, subsets):
"""Find a family of subsets that covers the universal set"""
elements = set(e for s in subsets for e in s)
# Check the subsets cover the universe
if elements != universe:
return None
covered = set()
cover = []
# Greedily add the subsets with the most... | 63a56ae709d766ec8cc57d3053f06032e84b7187 | 29,868 |
def get_constraints(cursor, table_name):
"""
Retrieves any constraints or keys (unique, pk, fk, check, index) across one or more columns.
"""
constraints = {}
# Loop over the key table, collecting things as constraints
# This will get PKs, FKs, and uniques, but not CHECK
cursor.execute("""
... | 8d6895fa03e57aeabed774dbc26fb44f12565fe6 | 29,870 |
import os
def random_salt(length = 32):
"""随机生成盐: 32字节
Cryptographically Secure Pseudo-Random Number Generator (CSPRNG)
"""
return os.urandom(length) | 511ff570ac1dc31465e581c40217d3942534c7af | 29,871 |
def GenerateWIUpdateMsgString(membership, issuer_url, resource_name,
cluster_name):
"""Generates user message with information about enabling/disabling Workload Identity.
We do not allow updating issuer url from one non-empty value to another.
Args:
membership: membership resour... | 75a54be804d5012e94587c4d5094936dc1f770da | 29,874 |
import random
def choice_optional(lst):
"""" Returns random.choice if there are elements, None otherwise """
if len(lst) > 0:
return random.choice(lst)
return None | 778561f1a42952d9f2af9692adeadd57917a4ea3 | 29,875 |
def find_all_paths(graph, start, end, path):
"""
:param graph: the graph that's traversed
:param start: starting node
:param end: end node
:param path: currently found paths
:return: all possible paths
"""
path = path + [start]
if start == end:
return [path]
if str(start)... | 51382317493191193e822fa819998ee7aa749122 | 29,876 |
def intron_gff_iterator(df, intron, intron_found, real_introns, read, args):
"""
Iterates over the intron.gff3 and checks whether the given deletion is an
intron.
"""
df = df.loc[df["start"] > intron[0] - args.wobble - 1]
for index, row in df.iterrows():
intron_found = False
if i... | 07b256576cb3cecf44252ac84305b575747c6da2 | 29,881 |
def update_claims(session, about, provider_info, old_claims=None):
"""
:param session:
:param about: userinfo or id_token
:param old_claims:
:return: claims or None
"""
if old_claims is None:
old_claims = {}
req = None
try:
req = session["authn_req"]
except Key... | 4983b5dd225b690685f4d73d3cc746632e1c8d52 | 29,882 |
def getFolder():
""" return the folder where this module is located"""
folderWithFileName = __file__
if(folderWithFileName[-1]=='c'):
fileName = __name__+".pyc"
else :
fileName = __name__+".py"
folderLength = len(folderWithFileName) - len(fileName)
folderWithoutFileName = fo... | 204bb6c2aa4e693e6461b108bd354844cf229363 | 29,883 |
import json
def read_json_file(path=r'web_crawler\scrapped_data\all_scraped_data.json'):
"""reads Json file
Args:
path: the path to the json file
"""
with open(path, 'r') as data_file:
return json.load(data_file) | 1f82ae07906d554a227aa653a2fe1bffc6a46a9b | 29,884 |
def grep(*matches):
"""Returns a generator function that operates on an iterable:
filters items in the iterable that match any of the patterns.
match: a callable returning a True value if it matches the item
>>> import re
>>> input = ["alpha\n", "beta\n", "gamma\n", "delta\n"]
>>> list(gre... | 9a28efd6416c0f8e02532072d9c366747dc52291 | 29,885 |
import os
def clear_console_screen():
"""Clears the console screen. Returns None."""
os.system('cls' if os.name=='nt' else 'clear')
return None | 6b9b4310a68f13ea13e1d28224c1d75e08aac0a8 | 29,887 |
from unicodedata import normalize
def unicodify(s, encoding='utf-8', norm=None):
"""Ensure string is Unicode.
.. versionadded:: 1.31
Decode encoded strings using ``encoding`` and normalise Unicode
to form ``norm`` if specified.
Args:
s (str): String to decode. May also be Unicode.
... | ee4882dd7450ba0b146e3fb9ddabf9deaf0e7903 | 29,888 |
import collections
def eval_step(test_batch, snlds_model, num_samples, temperature):
"""Runs evaluation of model on the test set and returns evaluation metrics.
Args:
test_batch: a batch of the test data.
snlds_model: tf.keras.Model, SNLDS model to be evaluated.
num_samples: int, number of samples pe... | 2a7ec12f43925aecf266048c6eaa0b331641a4fe | 29,890 |
def exception_to_dict(error):
"""Takes in an exception and outputs its details, excluding the stacktrace, to a dict
Args:
error (Exception): The exception to serialize
Returns:
dict: The serialized exception
"""
return {"type": str(type(error).__name__), "message": str(error)} | a677e151079a7b0005a7da1065f08b49cbf559be | 29,891 |
import time
def crete_tag_time():
"""
Create local tag time
:return: str: local time structure
"""
s = time.localtime(time.time())
year = str(s[0])
month = s[1]
if month < 10:
month = "0" + str(month)
day = s[2]
if day < 10:
day = "0" + str(day)
hours = s[3... | ac8a5a94f39c682bd17d7beb1b1eff98a1271a56 | 29,894 |
def normalized_bases(classes):
"""Remove redundant base classes from `classes`"""
candidates = []
for m in classes:
for n in classes:
if issubclass(n, m) and m is not n:
break
else:
# m has no subclasses in 'classes'
if m in candidates:
... | b355d438bfbd946dc5d73423e33b77b107121e0b | 29,895 |
def generate_window(keys, key_index, steps):
"""Generates a list (window) steps distance to the left and right of a given peak
Args:
keys (List): The keys for the compressed depths dictionary
key_index (int): The index in the keys list of the peak_key key
steps (int): How many steps le... | 7c712c18a8ce031f0ba9cfa86f9e3b34611d48a9 | 29,896 |
def transform_play_to_column(play):
"""Return position of the column where the play was made.
Parameters:
play (int): bit board representation of a piece
Returns:
int : column position"""
return [2 ** i for i in range(49)].index(play) // 7 | aa0e0298ead19d9f1375092f6b06f95ff2829f0f | 29,897 |
import binascii
def get_internal_name(cache_key):
"""Converts a cache key into an internal space module name."""
package, version = cache_key
return 'multiversion.space.%s___%s' % (package, binascii.hexlify(version)) | a34c3c746135f3913f9577238f8a8d6b13398d5d | 29,899 |
def to_char_arrays(text, w):
"""sets the words from input string into one or more character
arrays of length w
:param text: input string
:param w: maximum length of array
:type text: str
:type w: int
:return list of character arrays
:rtype list of str
"""
words = text.split()
... | 6c2a3dc9957c1409dfebef23874bf39df530b776 | 29,900 |
def counting_sort(a, k, reverse=False):
"""
计数排序
基本思想:对每一条记录,计算小于这条记录的记录个数。利用这一信息,就可以直接确定该记录的位置。
当有几条记录相同时,则需要调整一下位置。
记录值分布在0-k之间,建立C[0...k],根据记录值找到在C中的位置,该位置计数器+1。
数组C中某个位置Ci,C[0...i-1]的所有值相加,即为小于i的记录的个数。依次计算C[1...k]的值,即C[i]=C[i]+C[i-1]。
根据C中数据重新确定待排序列中记录的位置。
:param a:
:param k:
... | 20d4a26d9541a397645890ce22a384efe6fe8427 | 29,901 |
def checkSignedFeatureList(vocabularyList, inputWords):
"""
测试输入的文本向量中的文本是否在文档集合中有,并标记。
返回文档集合标记的列表,可理解为特征值列表
:type vocabularyList: list
:param vocabularyList:
:param inputWords:
:return:
"""
# 创建固定长度的list
signedFeatureList = [0] * len(vocabularyList)
for word in inputWords:
... | ba32774d6295169352ddf08cf954debd29dfa589 | 29,902 |
def parse_block(block, metric=[], labels={}):
"""Parse_block.
Parse a 'block' of results (a level of a for example)
and transform into a suitable list with labels and all
"""
result = []
# Give a dict of lists of labels which will be concatenated into a single
# label per item. These co... | 6080db9e8a9045b254258312aa866757bd4fdc1c | 29,903 |
def variants(sublist, int_list=False):
"""Find all supported variants of items in the sublist"""
result = []
result.append(sublist)
if int_list:
if len(sublist) == 3:
result.append([sublist[0], ",", sublist[1], ",", sublist[2]])
result.append([sublist[0], "x", sublist[1],... | 078626408d0f0d74fea8062c80b1d1843993a0c6 | 29,905 |
import os
def open_read_numpy_files(folder_path):
"""
opens each activations/gradients numpy file and calculates the
product of the activations/gradients per layer
"""
# change directories
os.chdir(folder_path)
grad_files_list = []
activ_files_list = []
file_name = None
# Read... | 048393ce4854076346039ce0f74da1f9b946a9a3 | 29,909 |
def build_index(data: list) -> tuple:
"""
Create an index with items and shops for faster lookup. Format -
{
'product1': 'shops': set([1, 3, 5]),
...
}
{
shop1: [
(price1, [item1, item2, ...]),
...
],
...
}
:param data: List of ... | 64b8f75553bf1968e922dd06a2cc3c75e44e9bf6 | 29,911 |
def bst_contains(node, value):
"""
Return whether tree rooted at node contains value.
Assume node is the root of a Binary Search Tree
@param BinaryTree|None node: node of a Binary Search Tree
@param object value: value to search for
@rtype: bool
>>> bst_contains(None, 5)
False
>>>... | bf1c875d9a3b4c5b8af42fb63465aa0f10039b49 | 29,912 |
def invert_dict(d):
"""Return an 'inverted' dictionary, swapping keys against values.
Parameters
----------
d : dict-like
The dictionary to invert
Returns
--------
inv_d : dict()
The inverted dictionary.
Notes
------
If the key-mapping is not one-to-one, then t... | 4a5d56cbf7ac4dc8c787635f7fbc8b4608b6532e | 29,913 |
import os
def get_path_basename(urlpath):
"""
Helper function to derive file basename
:param urlpath: URL path
:returns: string of basename of URL path
"""
return os.path.basename(urlpath) | 9477b1d67d8a061505c961821fce7fe99092f196 | 29,915 |
import numpy as np
def interbin_fft(freq, fft):
"""Interbinning, a la van der Klis 1989.
Allows to recover some sensitivity in a power density spectrum when
the pulsation frequency is close to a bin edge. Here we oversample
the Fourier transform that will be used to calculate the PDS, adding
inte... | cb3f38171c29477f1c1614cd3d9cd744d20f8faf | 29,916 |
def reduce_boxes(boxes, n_o_b):
"""
Reduces the number of boxes by combining them. Combine the closesd boxes
:param boxes: List[List[int]] = List of bboxes of the chars
:param n_o_b: int = wanted number of boxes
:return: List[List[int]] = modified boxes
"""
while len(boxes) > n_o_b:
... | 480078aa179161105d206cdfd4454d72d1ffd8e6 | 29,917 |
def c_uchar(i):
"""
Convert arbitrary integer to c unsigned char type range as if casted in c.
>>> c_uchar(0x12345678)
120
>>> (c_uchar(-123), c_uchar(-1), c_uchar(255), c_uchar(256))
(133, 255, 255, 0)
"""
return i & 0xFF | 937b683505282eb8577affb14236515ecdda20be | 29,919 |
def _groups_intersect( groups_A, groups_B ):
""" Return true if any of the groups in A are also in B (or size
of intersection > 0). If both are empty for now we will allow it """
ga = set(groups_A)
gb = set(groups_B)
return len( ga.intersection( gb ) ) > 0 | 7162b8aae5c4eaacad1596b93f8ece1624fd6945 | 29,920 |
def is_same_shape(T1, T2):
"""
Two partial latin squares T1, T2 have the same shape if T1[r, c] =
0 if and only if T2[r, c] = 0.
EXAMPLES::
sage: from sage.combinat.matrices.latin import *
sage: is_same_shape(elementary_abelian_2group(2), back_circulant(4))
True
sage: i... | 4602f7cb2a093393445f7e23f2d9f539021d2f7a | 29,921 |
def condition_str(condition, phase, component):
"""
Returns a string representation of a condition for a specific phase and component.
"""
if phase!=None:
return condition + '(' + phase + ',' + component + ')'
else:
return condition + '(' + component + ')' | ef7432bf1a7ca25ffb6bf7a9c1dc033dd53918af | 29,922 |
def rename_columns(df):
"""
function to rename columns to allow for easier plotting
of mri audio recordings compared to ansl output
"""
df.rename(columns={'dBFS':'Level (dBFS)'}, inplace=True)
df['Frequency (Hz)'].astype(float)
return df | 27dfb10ce9717da3ea10b414a7a64ca5c5d059d0 | 29,923 |
from typing import Iterator
def range_(values):
"""Calculates the range of the values.
:param values: The values.
:return: The range of the values.
"""
return range_(tuple(values)) if isinstance(values, Iterator) else max(values) - min(values) | 28ce7a97db16e8a1e718f391b299457e42d556e2 | 29,924 |
from pathlib import Path
def output_is_golden(out: str, golden_file: Path, update_golden: bool) ->bool:
"""Check that out string matches the contents of the golden file."""
__tracebackhide__ = True # pylint: disable=unused-variable
if update_golden:
with open(golden_file, "w") as file:
file.write(out)
# Ou... | e0a110ae466f28aa18a0163d8ca0bab1b6c548cb | 29,925 |
def list_to_string(l: list, s: str = "\n") -> str:
"""Transforms a list into a string.
The entries of the list are seperated by a seperator.
Args:
l (list): the list
s (str, optional): the seperator. Defaults to "\\n".
Returns:
str: the list representation with seperator
"""
r = ""
f... | ca04ba59c2edf740aa29b7e2ef79b8562c7d071c | 29,926 |
def crop_boxes(boxes, crop_shape):
"""
Crop boxes according given crop shape
"""
crop_x1 = crop_shape[0]
crop_y1 = crop_shape[1]
crop_x2 = crop_shape[2]
crop_y2 = crop_shape[3]
l0 = boxes[:, 0] >= crop_x1
l1 = boxes[:, 1] >= crop_y1
l2 = boxes[:, 2] <= crop_x2
l3 = boxes[:,... | a84e68f7d05bf56ac615e829c862dfe5fe3712a5 | 29,927 |
def _parse_idd_type(epbunch, name):
"""Parse the fieldvalue type into a python type.
Possible types are:
- integer -> int
- real -> float
- alpha -> str (arbitrary string),
- choice -> str (alpha with specific list of choices, see \key)
- object-list -> ... | bbf86c41ad685c2fb44f24671d22cf6601794cc1 | 29,929 |
def check_stream_status(stream, results_dict, ref_dict):
"""
:param stream: 'ecg' | 'ppg'
:param results_dict:
:param ref_dict:
:return:
"""
status = True
if stream == 'ecg':
ref_hr = ref_dict['ref_hr']
ref_qrs_amp = ref_dict['ref_qrs_amp']
qrs_amp = float(results... | 1ff50f60b8b575c9b92c68cb65d9a7b25ee80c27 | 29,930 |
import numpy
import itertools
def pm(n, a):
"""Return all combinations of [+a, -a] with length n (with repetition).
len(out) == 2**n.
"""
return numpy.array(list(itertools.product([+a, -a], repeat=n))) | baa781200466c44c2f17ee667a005582e132ccf8 | 29,933 |
import os
import json
def generate_dashboard(name, dashboards, datasource):
"""
Given the dashboard name, the dashboards part of the configuration, and the
default datasource, generate a dashboard. We use the skeleton.json file, and
fill it with given panels and template variables.
Rows have titl... | 71e57469b9064d3f2dca26ef699b762fb6e77875 | 29,934 |
def dot_in_stripe(dot, stripe):
"""True if dot.y is in horizontal stripe."""
return stripe[0] < dot.y <= stripe[1] | a742ea3dd7d4dc9ed32d6df3bf2cb358fda2fda7 | 29,935 |
def parse_agents(args):
"""
Each element is a class name like "Peer", with an optional
count appended after a comma. So either "Peer", or "Peer,3".
Returns an array with a list of class names, each repeated the
specified number of times.
"""
ans = []
for c in args:
s = c.split('... | e62aef22c20a449ae670bd517e3cb6f64375d792 | 29,939 |
import os
def get_object_name(path):
"""
Given a path with a basename of the form xx-object.c, return Object
"""
(fdir, basename) = os.path.split(path)
(base, ext) = os.path.splitext(basename)
return base[3:].capitalize() | db920fdffd81b6af697306ee38351a3a35e99d38 | 29,940 |
import math
from sys import stderr
import time
def retry(tries, delay=3, backoff=2):
"""Retries a function or method until it succedes
Note:
This assume the function succeded if no exception was thrown
Args:
tries(int): Number of attempts of the function. Must be >= 0
delay(int):... | 059d7a02cbabdbecc772fcd76e98fc602af0b6e7 | 29,942 |
import os
def is_file_in_folder(filename, folder_path):
""" Returns True if file is in the folder (not checking subfolders). Else False"""
for f in os.listdir(folder_path):
if f == filename:
return True
return False | 6b7cdb5d2538ea3eda4d528ce47f6357e6c76319 | 29,943 |
import math
def A000010(n: int) -> int:
"""Euler totient function phi(n): count numbers <= n and prime to n."""
numbers = []
i = 0
for i in range(n):
if math.gcd(i, n) == 1:
numbers.append(i)
return len(numbers) | 46b28b077f78965666eb34e0f4e7892e95b4162b | 29,946 |
import numpy as np
def arc2px(x_arc, y_arc, header):
"""Converts x and y arcsec coords into px."""
try:
xpx = [0] * len(x_arc)
ypx = [0] * len(y_arc)
except TypeError:
xpx = [0]
ypx = [0]
x_arc = [x_arc]
y_arc = [y_arc]
for i in range(0, len(xpx)):
... | fd1d893f41a889bd880c7f6c5971c3724615c5cf | 29,947 |
def session_start(interp, args_w):
"""Start new or resume existing session"""
if interp.session.is_active():
interp.notice("A session had already been "
"started - ignoring session_start()")
return interp.space.w_True
res = interp.session.start(interp)
return inte... | 0b33802668a74c17bd991d4c3923889c3da8c3aa | 29,948 |
import math
def CalcDistance(p1, p2):
"""
Function to calculate distance in space between two points (p)
p1, p2: (f) lists of coordinates for point1 and point2
"""
dist = math.sqrt((p2[0]-p1[0])**2 + (p2[1]-p1[1])**2 + (p2[2]-p2[2])**2)
return(dist) | 099512d41acafa7832a425cb8fbe60a6c4be8ecf | 29,951 |
import hashlib
def password_hash(password: str):
"""
Hash a password for storing.
Args:
password (str): the password to hash.
Returns:
str: the hashed password.
"""
sha512_1 = hashlib.sha512(password.encode("utf-8")).hexdigest()
sha512_2 = hashlib.sha512(sha512_1.encode("... | 9d0a4ebc9d309aa5902ff39e9d4bd630ec215be5 | 29,954 |
def _get_lights(guess: dict, truth: dict) -> int:
"""
Return the number of lights that we would observe.
"""
correct = 0
for p in guess:
if guess[p] == truth[p]:
correct += 1
# Adjust for double counting
return int(correct / 2) | 920b8305118293bceffbffad423cb32001c8862a | 29,955 |
import os
import stat
import shutil
def copyTree(src, dst, excludeExt=[], renameDict={}, renameExtDict={}, includeExt=None):
"""
Copy a directory to another one, overwritting files if necessary.
copy_tree from distutils and copytree from shutil fail on Windows (in particular on git files)
INPUTS:
... | 55a73050864e2bd0b368ea5f3b3266076971c37b | 29,956 |
def getlambda(pixel, lo, hi):
#-----------------------------------------------------------------------------
"""
Small utility to calculate lambda on a line for given position
in pixels
"""
#-----------------------------------------------------------------------------
if pixel is None:
return 0.5
... | 6245ff3ec09db39d913175e58b9cec08888aa66e | 29,957 |
def array_pyxll_function_1(x):
"""returns the sum of a range of floats"""
total = 0.0
# x is a list of lists - iterate through the rows:
for row in x:
# each row is a list of floats
for element in row:
total += element
return total | 8ebd50b6025f59cd2c161fea79e7eb47d0e76337 | 29,958 |
def sort_by_name(dicts):
"""
Sorting of a list of dicts. The sorting is based on the name field.
Args:
list: The list of dicts to sort.
Returns:
Sorted list.
"""
return sorted(dicts, key=lambda k: k.get("name", "").lower()) | 3364995d2cbc55e87a6f60d054861eadec9e0dda | 29,959 |
import re
def alphanum_string(input_string):
"""
Removes all non-alphanumeric characters from the given string.
"""
pattern = re.compile(r'[\W_]+')
return pattern.sub('', input_string) | 3e27c52b02d85c3374a82d5cc909b8a305a8c67a | 29,961 |
def getConstants():
"""Returns a list of constants for NXT brick. """
out = []
api = __import__('api')
for constant in dir(api):
if constant[0].isupper():
id = getattr(api, constant)
if type(id).__name__ not in ["function", "type"]:
out.append(c... | c99053cba5d1e88b028e6b62e9b2c2d68bb00d42 | 29,964 |
def preprocess_doi(line):
"""
Removes doi.org prefix if full URL was pasted, then strips unnecessary slashes
"""
(_, _, doi) = line.rpartition('doi.org')
return doi.strip('/') | 55badcf6fb55d19dcdcaba0d6ece706978001d7f | 29,965 |
def point_in_rectangle(point, rect_top_left, rect_sides):
"""
Checks if point is in rectangle
Parameters
----------
point : (float, float)
(x,y) coordinates of point
rect_top_left : (float, float)
(x,y) coordinates of rectangle top left corner
rect_sides : (float, float)
... | 49fe7980f32d4716e38b2591bbfe8d1d8910c11e | 29,968 |
import requests
def zone_headers(zone, date):
"""
Get query headers for querying intra-zone flows
"""
area_map={
'JP-HKD':1,
'JP-TH':2,
'JP-TK':3,
'JP-CB':4,
'JP-HR':5,
'JP-KN':6,
'JP-CG':7,
'JP-SK':8,
'JP-KY':9,
'JP-ON':10
}
payload = {
'aja... | 01fd230dbb06cb465df1ef2cf88b79a0b4634686 | 29,969 |
def do_default(default_value=u'', boolean=False):
"""
If the value is undefined it will return the passed default value,
otherwise the value of the variable:
.. sourcecode:: jinja
{{ my_variable|default('my_variable is not defined') }}
This will output the value of ``my_variable`` if the ... | 433615685cb9edcaff2ae435bf2e71d4ffd68158 | 29,970 |
def merge_config(config, environment):
"""
:param config: Dictionary
:param environment: Dictionary
:return: Dictionary
"""
keys = ['HTTP_PROXY', 'HTTPS_PROXY', 'NO_PROXY']
for key in keys:
if config.get(key.lower(), '') == '' and \
config.get(key, '') == '':
... | 4fabb193fc50241cb22ea1e30bcce0de7361c611 | 29,971 |
def prefix_dash_dash(params):
""" Add -- for keys in gdmix tfjob params. """
if isinstance(params, dict):
newParams = {}
for k, v in params.items():
newParams["--{}".format(k)] = v
return newParams
else:
raise ValueError("job params can only be dict") | 85170ccf0adeb83718394c572949a420108d0e03 | 29,972 |
import importlib
def get_from_module(module, attr_name):
""" Return a reference from a module.
The attribute name must exist in the module, it could be a variable,
a callable or a class.
If reference name doesn't exists in the module it will return None.
Example:
>>> get_from_module("my.modu... | b4e95ee167d71035241bc0df2ab87c25bb45b4ac | 29,973 |
def get_equipments(): # noqa: E501
"""gets information on all recorded test equipment
Returns information on all test equipment. # noqa: E501
:rtype: List[Equipment]
"""
return 'do some magic!' | c3a7e0232ecb2b624971f29774ae1576494daaed | 29,974 |
def get_S_ref_comp_out(S_ref_comp_in):
"""圧縮機吐出比エントロピー (4)
圧縮機吐出比エントロピーは圧縮機吸入比エントロピーに等しいとする。
Args:
S_ref_comp_in(float): 圧縮機吸入比エントロピー (kJ/kg・K)
Returns:
float: 圧縮機吐出比エントロピー (kJ/kg・K)
"""
return S_ref_comp_in | 5aacd8d35d1039f28fa30b3102d7f3823206b9c2 | 29,975 |
import math
def split_line_geometry(linegeometry, split_value, split_method="LENGTH", best_fit_bool=True):
"""This function will take an ArcPolyline, a split value, a split method of either 'LENGTH' or 'SEGMENT COUNT', and
boolean that determines if the lines split are the best of fit based on the length. The... | 9c720ca4211e80fae6e3a1b107b888b02fe6f7b9 | 29,976 |
import os
def list_files(folder):
"""
:type folder: str
:rtype: list of str
"""
file_list = []
for file_name in os.listdir(folder):
full_file_name = os.path.join(folder, file_name)
if os.path.isdir(full_file_name):
file_list.extend(list_files(full_file_name))
... | 3a0819e4f31bf1b2f7aefd64662cf6c993069800 | 29,977 |
def nullWrapper(message):
"""
This method returns the message that was sent to it. It is used in situations
where you just want to post the raw text to the log.
"""
return message | 7db3e8791ed8399856fefdcf9fece2466ddbcecd | 29,978 |
import torch
def get_nmse(x_hat, x):
"""
Calculate ||x_hat - x|| / ||x||
"""
sse = torch.sum((x_hat - x)**2, dim=[1,2,3]) #shape [N] - sse per image
denom = torch.sum(x**2, dim=[1,2,3]) #shape [N] - squared l2 norm per ground truth image
nmse_val = sse / denom
return nmse_val.cpu().numpy... | edda096ebc8d8932cde975a07e579c2cfca8051f | 29,979 |
def update(playbook_configuration_id, global_vars, inventory, name, model,
client, **kwargs):
"""Updates playbook configuration.
Since playbook configuration is complex, there are the rules on
update:
\b
1. If 'model' or '--edit-model' field is set, it will be used
for update... | 60f5216eab26fa9ac1072386725a810d13cc64b6 | 29,980 |
def convert_to_table(header, rows):
"""
Create an HTML table out of the sample data.
Args:
header (str): The table header
rows (List[str]): A list of rows as strings
Returns:
A dataset sample in the form of an HTML <table>
"""
header_html = '<tr><th>{}</th></tr>'.format... | cf7c861015135b940d2a011da106f40d0aa31ba5 | 29,982 |
def looksLikeVestLutFile(path):
"""Returns ``True`` if the given ``path`` looks like a VEST LUT file,
``False`` otherwise.
"""
with open(path, 'rt') as f:
lines = []
for i in range(10):
line = f.readline()
if line is None: break
else: lines... | c1e8006b6b81d949d353f773d2a41164c26eec98 | 29,984 |
from typing import Dict
import csv
def load_subjects(csvfile: str) -> Dict:
"""Load a list of subjects from a csv file along with metadata
Subject,Age,Gender,Acquisition,Release
195041,31-35,F,Q07,S500
...
Return a dictionary with Subjects as keys and Age as the value
"""
result: Di... | e9249ce7a04869e6b565238aa06c65063becb361 | 29,985 |
import torch
def fedavg(baseline_weights,
local_deltas_updates,
num_samples_list,
server_lr=1):
"""
Server aggregation with learning rate of alpha.
"""
avg_update = [
torch.zeros(x.size()) # pylint: disable=no-member
for _, x in local_deltas_updat... | e983689ac4a7b47ab9380ec6a2f01662c5bbad47 | 29,986 |
def _mai(a: int, n: int) -> int:
"""
Modular Additive Inverse (MAI) of a mod n.
"""
return (n - a) % n | 634af47425e9bd3afec12742782755a3f0f4ac1f | 29,987 |
def filter_obs(filt):
""" Observes the specified coordinates """
def inner(x):
if len(x.shape) == 4:
return x[:, :, :, filt]
elif len(x.shape) == 3:
return x[:, :, filt]
else:
return x[:, filt]
return inner | 6ce49337a845fd0c4f360310be5f707076522fcc | 29,990 |
import subprocess
import pathlib
def get_changed_files():
"""
Return pathlib.Paths for files changed in the last
git commit.
"""
args = ['git', 'diff', '--name-only', 'HEAD~1']
paths = subprocess.check_output(args, text=True)
paths = paths.splitlines()
paths = {pathlib.Path(path) for p... | c87cce0693ba6bf28991c9496a944caa210efdd7 | 29,991 |
import re
def get_model_presets(config, model):
"""Collect all the parameters model from the UI and return them as a dict.
Args:
config (dict): Recipe config dictionary obtained with dataiku.customrecipe.get_recipe_config().
model (str): Model name found in the UI.
Returns:
Dicti... | 492079ef55f7d1c3a621f2228f1e22b14765575d | 29,992 |
def stay_on_track(params):
"""
Example of rewarding the agent to stay inside the two borders of the track
"""
# Read input parameters
all_wheels_on_track = params['all_wheels_on_track']
distance_from_center = params['distance_from_center']
track_width = params['track_width']
# Give a v... | fd8d94e4895a8129d559c10120a477987f9f0ccc | 29,994 |
def _get_name(index, hdf5_data):
"""Retrieves the image file name from hdf5 data for a specific index.
Args:
index (int): Index of image.
hdf5_data (obj): h5py file containing bounding box information.
Returns:
(str): Image file name.
"""
ref = hdf5_data['/digitStruct/name... | 7b65d6f6aede25265865734dae6a94def8b3524f | 29,995 |
import re
from datetime import datetime
import time
def extract_date(str_date):
"""Find the first %Y-%m-%d string
and return the datetime and the remainder of the string
"""
rgx = re.compile('\d{4}-\d{2}-\d{2}')
o_match = rgx.search(str_date)
if o_match is not None:
i_start = o_matc... | 3f3407490eec4e3d65e289b5e2ebef3246c9c63f | 29,996 |
import operator
def freeze_dict(dict_):
"""Freezes ``dict`` into ``tuple``.
A typical usage is packing ``dict`` into hashable.
e.g.::
>>> freeze_dict({'a': 1, 'b': 2})
(('a', 1), ('b', 2))
"""
pairs = dict_.items()
key_getter = operator.itemgetter(0)
return tuple(sorted(... | 0694f264419bb426597bc1fe6a4d0a7d3ae89fc5 | 29,997 |
from functools import reduce
def multiply(*xs):
"""
>>> multiply(1, 2, 3)
6
"""
return reduce(lambda x, y: x*y, xs) | c2de9a74f174cbc8d36923247bb12a2dd2d028d4 | 29,998 |
def expand_evar(s, env, expr):
"""search through a string to find any environment variable expressions and expand into s"""
vars = expr.findall(s)
for v in vars:
vname = v[2:-1]
if vname in env:
s = s.replace(v, env[vname])
else:
pass
return s | eeeff89c73441f07d1ce0bf8a999146e5030eb96 | 29,999 |
import pandas
def table_sort(df: pandas.DataFrame, sort_fun) -> pandas.DataFrame:
"""
对表格排序
:param df: 待排序表格
:param sort_fun: 排序算法
:return: 排序后的表格
"""
return sort_fun(df) | 07bce9a08b7c04a78d4eaa8796c7c50cef22b698 | 30,000 |
from collections import Counter
def password_philosophy(password_record):
"""Validates passwords according to the rules"""
valid_1 = 0
valid_2 = 0
for line in password_record:
prefix, suffix = line.split("-")
min_count = int(prefix)
max_count = int(suffix[:suffix.find(" ")])
... | 17966486349651aca9d9a13c942a2b2d387b2728 | 30,002 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.