hexsha
stringlengths
40
40
size
int64
10
1.01M
ext
stringclasses
8 values
lang
stringclasses
1 value
max_stars_repo_path
stringlengths
4
237
max_stars_repo_name
stringlengths
5
113
max_stars_repo_head_hexsha
stringlengths
40
41
max_stars_repo_licenses
list
max_stars_count
int64
1
95.2k
max_stars_repo_stars_event_min_datetime
stringlengths
24
24
max_stars_repo_stars_event_max_datetime
stringlengths
24
24
max_issues_repo_path
stringlengths
4
237
max_issues_repo_name
stringlengths
5
113
max_issues_repo_head_hexsha
stringlengths
40
41
max_issues_repo_licenses
list
max_issues_count
int64
1
67k
max_issues_repo_issues_event_min_datetime
stringlengths
24
24
max_issues_repo_issues_event_max_datetime
stringlengths
24
24
max_forks_repo_path
stringlengths
4
237
max_forks_repo_name
stringlengths
5
113
max_forks_repo_head_hexsha
stringlengths
40
41
max_forks_repo_licenses
list
max_forks_count
int64
1
33.1k
max_forks_repo_forks_event_min_datetime
stringlengths
24
24
max_forks_repo_forks_event_max_datetime
stringlengths
24
24
content
stringlengths
10
1.01M
avg_line_length
float64
2.26
46k
max_line_length
int64
3
990k
alphanum_fraction
float64
0.1
1
label
int64
0
2
cost
float64
0
5.77
embedding
list
8a91ba22fcba12ba8237fcf117a449485cdd3de1
31,466
py
Python
pandas/core/indexes/range.py
mujtahidalam/pandas
526468c8fe6fc5157aaf2fce327c5ab2a3350f49
[ "PSF-2.0", "Apache-2.0", "BSD-3-Clause-No-Nuclear-License-2014", "MIT", "MIT-0", "ECL-2.0", "BSD-3-Clause" ]
2
2017-12-14T19:50:52.000Z
2020-04-07T16:47:23.000Z
pandas/core/indexes/range.py
mujtahidalam/pandas
526468c8fe6fc5157aaf2fce327c5ab2a3350f49
[ "PSF-2.0", "Apache-2.0", "BSD-3-Clause-No-Nuclear-License-2014", "MIT", "MIT-0", "ECL-2.0", "BSD-3-Clause" ]
1
2021-07-24T17:35:03.000Z
2021-07-24T17:35:03.000Z
pandas/core/indexes/range.py
mujtahidalam/pandas
526468c8fe6fc5157aaf2fce327c5ab2a3350f49
[ "PSF-2.0", "Apache-2.0", "BSD-3-Clause-No-Nuclear-License-2014", "MIT", "MIT-0", "ECL-2.0", "BSD-3-Clause" ]
1
2018-01-26T08:33:54.000Z
2018-01-26T08:33:54.000Z
from __future__ import annotations from datetime import timedelta import operator from sys import getsizeof from typing import ( TYPE_CHECKING, Any, Callable, Hashable, List, cast, ) import warnings import numpy as np from pandas._libs import index as libindex from pandas._libs.lib import no_default from pandas._typing import Dtype from pandas.compat.numpy import function as nv from pandas.util._decorators import ( cache_readonly, doc, ) from pandas.util._exceptions import rewrite_exception from pandas.core.dtypes.common import ( ensure_platform_int, ensure_python_int, is_float, is_integer, is_scalar, is_signed_integer_dtype, is_timedelta64_dtype, ) from pandas.core.dtypes.generic import ABCTimedeltaIndex from pandas.core import ops import pandas.core.common as com from pandas.core.construction import extract_array import pandas.core.indexes.base as ibase from pandas.core.indexes.base import maybe_extract_name from pandas.core.indexes.numeric import ( Float64Index, Int64Index, NumericIndex, ) from pandas.core.ops.common import unpack_zerodim_and_defer if TYPE_CHECKING: from pandas import Index _empty_range = range(0) class RangeIndex(NumericIndex): """ Immutable Index implementing a monotonic integer range. RangeIndex is a memory-saving special case of Int64Index limited to representing monotonic ranges. Using RangeIndex may in some instances improve computing speed. This is the default index type used by DataFrame and Series when no explicit index is provided by the user. Parameters ---------- start : int (default: 0), range, or other RangeIndex instance If int and "stop" is not given, interpreted as "stop" instead. stop : int (default: 0) step : int (default: 1) dtype : np.int64 Unused, accepted for homogeneity with other index types. copy : bool, default False Unused, accepted for homogeneity with other index types. name : object, optional Name to be stored in the index. Attributes ---------- start stop step Methods ------- from_range See Also -------- Index : The base pandas Index type. Int64Index : Index of int64 data. """ _typ = "rangeindex" _engine_type = libindex.Int64Engine _dtype_validation_metadata = (is_signed_integer_dtype, "signed integer") _can_hold_na = False _range: range # -------------------------------------------------------------------- # Constructors def __new__( cls, start=None, stop=None, step=None, dtype: Dtype | None = None, copy: bool = False, name: Hashable = None, ) -> RangeIndex: cls._validate_dtype(dtype) name = maybe_extract_name(name, start, cls) # RangeIndex if isinstance(start, RangeIndex): return start.copy(name=name) elif isinstance(start, range): return cls._simple_new(start, name=name) # validate the arguments if com.all_none(start, stop, step): raise TypeError("RangeIndex(...) must be called with integers") start = ensure_python_int(start) if start is not None else 0 if stop is None: start, stop = 0, start else: stop = ensure_python_int(stop) step = ensure_python_int(step) if step is not None else 1 if step == 0: raise ValueError("Step must not be zero") rng = range(start, stop, step) return cls._simple_new(rng, name=name) @classmethod def from_range( cls, data: range, name=None, dtype: Dtype | None = None ) -> RangeIndex: """ Create RangeIndex from a range object. Returns ------- RangeIndex """ if not isinstance(data, range): raise TypeError( f"{cls.__name__}(...) must be called with object coercible to a " f"range, {repr(data)} was passed" ) cls._validate_dtype(dtype) return cls._simple_new(data, name=name) @classmethod def _simple_new(cls, values: range, name: Hashable = None) -> RangeIndex: result = object.__new__(cls) assert isinstance(values, range) result._range = values result._name = name result._cache = {} result._reset_identity() return result # -------------------------------------------------------------------- @cache_readonly def _constructor(self) -> type[Int64Index]: """ return the class to use for construction """ return Int64Index @cache_readonly def _data(self) -> np.ndarray: """ An int array that for performance reasons is created only when needed. The constructed array is saved in ``_cache``. """ return np.arange(self.start, self.stop, self.step, dtype=np.int64) @cache_readonly def _cached_int64index(self) -> Int64Index: return Int64Index._simple_new(self._data, name=self.name) @property def _int64index(self) -> Int64Index: # wrap _cached_int64index so we can be sure its name matches self.name res = self._cached_int64index res._name = self._name return res def _get_data_as_items(self): """ return a list of tuples of start, stop, step """ rng = self._range return [("start", rng.start), ("stop", rng.stop), ("step", rng.step)] def __reduce__(self): d = self._get_attributes_dict() d.update(dict(self._get_data_as_items())) return ibase._new_Index, (type(self), d), None # -------------------------------------------------------------------- # Rendering Methods def _format_attrs(self): """ Return a list of tuples of the (attr, formatted_value) """ attrs = self._get_data_as_items() if self.name is not None: attrs.append(("name", ibase.default_pprint(self.name))) return attrs def _format_data(self, name=None): # we are formatting thru the attributes return None def _format_with_header(self, header: list[str], na_rep: str = "NaN") -> list[str]: if not len(self._range): return header first_val_str = str(self._range[0]) last_val_str = str(self._range[-1]) max_length = max(len(first_val_str), len(last_val_str)) return header + [f"{x:<{max_length}}" for x in self._range] # -------------------------------------------------------------------- _deprecation_message = ( "RangeIndex.{} is deprecated and will be " "removed in a future version. Use RangeIndex.{} " "instead" ) @property def start(self) -> int: """ The value of the `start` parameter (``0`` if this was not supplied). """ # GH 25710 return self._range.start @property def _start(self) -> int: """ The value of the `start` parameter (``0`` if this was not supplied). .. deprecated:: 0.25.0 Use ``start`` instead. """ warnings.warn( self._deprecation_message.format("_start", "start"), FutureWarning, stacklevel=2, ) return self.start @property def stop(self) -> int: """ The value of the `stop` parameter. """ return self._range.stop @property def _stop(self) -> int: """ The value of the `stop` parameter. .. deprecated:: 0.25.0 Use ``stop`` instead. """ # GH 25710 warnings.warn( self._deprecation_message.format("_stop", "stop"), FutureWarning, stacklevel=2, ) return self.stop @property def step(self) -> int: """ The value of the `step` parameter (``1`` if this was not supplied). """ # GH 25710 return self._range.step @property def _step(self) -> int: """ The value of the `step` parameter (``1`` if this was not supplied). .. deprecated:: 0.25.0 Use ``step`` instead. """ # GH 25710 warnings.warn( self._deprecation_message.format("_step", "step"), FutureWarning, stacklevel=2, ) return self.step @cache_readonly def nbytes(self) -> int: """ Return the number of bytes in the underlying data. """ rng = self._range return getsizeof(rng) + sum( getsizeof(getattr(rng, attr_name)) for attr_name in ["start", "stop", "step"] ) def memory_usage(self, deep: bool = False) -> int: """ Memory usage of my values Parameters ---------- deep : bool Introspect the data deeply, interrogate `object` dtypes for system-level memory consumption Returns ------- bytes used Notes ----- Memory usage does not include memory consumed by elements that are not components of the array if deep=False See Also -------- numpy.ndarray.nbytes """ return self.nbytes @property def dtype(self) -> np.dtype: return np.dtype(np.int64) @property def is_unique(self) -> bool: """ return if the index has unique values """ return True @cache_readonly def is_monotonic_increasing(self) -> bool: return self._range.step > 0 or len(self) <= 1 @cache_readonly def is_monotonic_decreasing(self) -> bool: return self._range.step < 0 or len(self) <= 1 def __contains__(self, key: Any) -> bool: hash(key) try: key = ensure_python_int(key) except TypeError: return False return key in self._range @property def inferred_type(self) -> str: return "integer" # -------------------------------------------------------------------- # Indexing Methods @doc(Int64Index.get_loc) def get_loc(self, key, method=None, tolerance=None): if method is None and tolerance is None: if is_integer(key) or (is_float(key) and key.is_integer()): new_key = int(key) try: return self._range.index(new_key) except ValueError as err: raise KeyError(key) from err raise KeyError(key) return super().get_loc(key, method=method, tolerance=tolerance) def _get_indexer( self, target: Index, method: str | None = None, limit: int | None = None, tolerance=None, ) -> np.ndarray: # -> np.ndarray[np.intp] if com.any_not_none(method, tolerance, limit): return super()._get_indexer( target, method=method, tolerance=tolerance, limit=limit ) if self.step > 0: start, stop, step = self.start, self.stop, self.step else: # GH 28678: work on reversed range for simplicity reverse = self._range[::-1] start, stop, step = reverse.start, reverse.stop, reverse.step if not is_signed_integer_dtype(target): # checks/conversions/roundings are delegated to general method return super()._get_indexer(target, method=method, tolerance=tolerance) target_array = np.asarray(target) locs = target_array - start valid = (locs % step == 0) & (locs >= 0) & (target_array < stop) locs[~valid] = -1 locs[valid] = locs[valid] / step if step != self.step: # We reversed this range: transform to original locs locs[valid] = len(self) - 1 - locs[valid] return ensure_platform_int(locs) # -------------------------------------------------------------------- def repeat(self, repeats, axis=None) -> Int64Index: return self._int64index.repeat(repeats, axis=axis) def delete(self, loc) -> Int64Index: # type: ignore[override] return self._int64index.delete(loc) def take( self, indices, axis: int = 0, allow_fill: bool = True, fill_value=None, **kwargs ) -> Int64Index: with rewrite_exception("Int64Index", type(self).__name__): return self._int64index.take( indices, axis=axis, allow_fill=allow_fill, fill_value=fill_value, **kwargs, ) def tolist(self) -> list[int]: return list(self._range) @doc(Int64Index.__iter__) def __iter__(self): yield from self._range @doc(Int64Index._shallow_copy) def _shallow_copy(self, values, name: Hashable = no_default): name = self.name if name is no_default else name if values.dtype.kind == "f": return Float64Index(values, name=name) return Int64Index._simple_new(values, name=name) def _view(self: RangeIndex) -> RangeIndex: result = type(self)._simple_new(self._range, name=self._name) result._cache = self._cache return result @doc(Int64Index.copy) def copy( self, name: Hashable = None, deep: bool = False, dtype: Dtype | None = None, names=None, ): name = self._validate_names(name=name, names=names, deep=deep)[0] new_index = self._rename(name=name) if dtype: warnings.warn( "parameter dtype is deprecated and will be removed in a future " "version. Use the astype method instead.", FutureWarning, stacklevel=2, ) new_index = new_index.astype(dtype) return new_index def _minmax(self, meth: str): no_steps = len(self) - 1 if no_steps == -1: return np.nan elif (meth == "min" and self.step > 0) or (meth == "max" and self.step < 0): return self.start return self.start + self.step * no_steps def min(self, axis=None, skipna: bool = True, *args, **kwargs) -> int: """The minimum value of the RangeIndex""" nv.validate_minmax_axis(axis) nv.validate_min(args, kwargs) return self._minmax("min") def max(self, axis=None, skipna: bool = True, *args, **kwargs) -> int: """The maximum value of the RangeIndex""" nv.validate_minmax_axis(axis) nv.validate_max(args, kwargs) return self._minmax("max") def argsort(self, *args, **kwargs) -> np.ndarray: """ Returns the indices that would sort the index and its underlying data. Returns ------- np.ndarray[np.intp] See Also -------- numpy.ndarray.argsort """ ascending = kwargs.pop("ascending", True) # EA compat nv.validate_argsort(args, kwargs) if self._range.step > 0: result = np.arange(len(self), dtype=np.intp) else: result = np.arange(len(self) - 1, -1, -1, dtype=np.intp) if not ascending: result = result[::-1] return result def factorize( self, sort: bool = False, na_sentinel: int | None = -1 ) -> tuple[np.ndarray, RangeIndex]: codes = np.arange(len(self), dtype=np.intp) uniques = self if sort and self.step < 0: codes = codes[::-1] uniques = uniques[::-1] return codes, uniques def equals(self, other: object) -> bool: """ Determines if two Index objects contain the same elements. """ if isinstance(other, RangeIndex): return self._range == other._range return super().equals(other) # -------------------------------------------------------------------- # Set Operations def _intersection(self, other: Index, sort=False): if not isinstance(other, RangeIndex): # Int64Index return super()._intersection(other, sort=sort) if not len(self) or not len(other): return self._simple_new(_empty_range) first = self._range[::-1] if self.step < 0 else self._range second = other._range[::-1] if other.step < 0 else other._range # check whether intervals intersect # deals with in- and decreasing ranges int_low = max(first.start, second.start) int_high = min(first.stop, second.stop) if int_high <= int_low: return self._simple_new(_empty_range) # Method hint: linear Diophantine equation # solve intersection problem # performance hint: for identical step sizes, could use # cheaper alternative gcd, s, _ = self._extended_gcd(first.step, second.step) # check whether element sets intersect if (first.start - second.start) % gcd: return self._simple_new(_empty_range) # calculate parameters for the RangeIndex describing the # intersection disregarding the lower bounds tmp_start = first.start + (second.start - first.start) * first.step // gcd * s new_step = first.step * second.step // gcd new_range = range(tmp_start, int_high, new_step) new_index = self._simple_new(new_range) # adjust index to limiting interval new_start = new_index._min_fitting_element(int_low) new_range = range(new_start, new_index.stop, new_index.step) new_index = self._simple_new(new_range) if (self.step < 0 and other.step < 0) is not (new_index.step < 0): new_index = new_index[::-1] if sort is None: new_index = new_index.sort_values() return new_index def _min_fitting_element(self, lower_limit: int) -> int: """Returns the smallest element greater than or equal to the limit""" no_steps = -(-(lower_limit - self.start) // abs(self.step)) return self.start + abs(self.step) * no_steps def _max_fitting_element(self, upper_limit: int) -> int: """Returns the largest element smaller than or equal to the limit""" no_steps = (upper_limit - self.start) // abs(self.step) return self.start + abs(self.step) * no_steps def _extended_gcd(self, a: int, b: int) -> tuple[int, int, int]: """ Extended Euclidean algorithms to solve Bezout's identity: a*x + b*y = gcd(x, y) Finds one particular solution for x, y: s, t Returns: gcd, s, t """ s, old_s = 0, 1 t, old_t = 1, 0 r, old_r = b, a while r: quotient = old_r // r old_r, r = r, old_r - quotient * r old_s, s = s, old_s - quotient * s old_t, t = t, old_t - quotient * t return old_r, old_s, old_t def _union(self, other: Index, sort): """ Form the union of two Index objects and sorts if possible Parameters ---------- other : Index or array-like sort : False or None, default None Whether to sort resulting index. ``sort=None`` returns a monotonically increasing ``RangeIndex`` if possible or a sorted ``Int64Index`` if not. ``sort=False`` always returns an unsorted ``Int64Index`` .. versionadded:: 0.25.0 Returns ------- union : Index """ if isinstance(other, RangeIndex) and sort is None: start_s, step_s = self.start, self.step end_s = self.start + self.step * (len(self) - 1) start_o, step_o = other.start, other.step end_o = other.start + other.step * (len(other) - 1) if self.step < 0: start_s, step_s, end_s = end_s, -step_s, start_s if other.step < 0: start_o, step_o, end_o = end_o, -step_o, start_o if len(self) == 1 and len(other) == 1: step_s = step_o = abs(self.start - other.start) elif len(self) == 1: step_s = step_o elif len(other) == 1: step_o = step_s start_r = min(start_s, start_o) end_r = max(end_s, end_o) if step_o == step_s: if ( (start_s - start_o) % step_s == 0 and (start_s - end_o) <= step_s and (start_o - end_s) <= step_s ): return type(self)(start_r, end_r + step_s, step_s) if ( (step_s % 2 == 0) and (abs(start_s - start_o) <= step_s / 2) and (abs(end_s - end_o) <= step_s / 2) ): return type(self)(start_r, end_r + step_s / 2, step_s / 2) elif step_o % step_s == 0: if ( (start_o - start_s) % step_s == 0 and (start_o + step_s >= start_s) and (end_o - step_s <= end_s) ): return type(self)(start_r, end_r + step_s, step_s) elif step_s % step_o == 0: if ( (start_s - start_o) % step_o == 0 and (start_s + step_o >= start_o) and (end_s - step_o <= end_o) ): return type(self)(start_r, end_r + step_o, step_o) return self._int64index._union(other, sort=sort) def _difference(self, other, sort=None): # optimized set operation if we have another RangeIndex self._validate_sort_keyword(sort) self._assert_can_do_setop(other) other, result_name = self._convert_can_do_setop(other) if not isinstance(other, RangeIndex): return super()._difference(other, sort=sort) res_name = ops.get_op_result_name(self, other) first = self._range[::-1] if self.step < 0 else self._range overlap = self.intersection(other) if overlap.step < 0: overlap = overlap[::-1] if len(overlap) == 0: return self.rename(name=res_name) if len(overlap) == len(self): return self[:0].rename(res_name) if not isinstance(overlap, RangeIndex): # We won't end up with RangeIndex, so fall back return super()._difference(other, sort=sort) if overlap.step != first.step: # In some cases we might be able to get a RangeIndex back, # but not worth the effort. return super()._difference(other, sort=sort) if overlap[0] == first.start: # The difference is everything after the intersection new_rng = range(overlap[-1] + first.step, first.stop, first.step) elif overlap[-1] == first[-1]: # The difference is everything before the intersection new_rng = range(first.start, overlap[0], first.step) else: # The difference is not range-like return super()._difference(other, sort=sort) new_index = type(self)._simple_new(new_rng, name=res_name) if first is not self._range: new_index = new_index[::-1] return new_index def symmetric_difference(self, other, result_name: Hashable = None, sort=None): if not isinstance(other, RangeIndex) or sort is not None: return super().symmetric_difference(other, result_name, sort) left = self.difference(other) right = other.difference(self) result = left.union(right) if result_name is not None: result = result.rename(result_name) return result # -------------------------------------------------------------------- def _concat(self, indexes: list[Index], name: Hashable) -> Index: """ Overriding parent method for the case of all RangeIndex instances. When all members of "indexes" are of type RangeIndex: result will be RangeIndex if possible, Int64Index otherwise. E.g.: indexes = [RangeIndex(3), RangeIndex(3, 6)] -> RangeIndex(6) indexes = [RangeIndex(3), RangeIndex(4, 6)] -> Int64Index([0,1,2,4,5]) """ if not all(isinstance(x, RangeIndex) for x in indexes): return super()._concat(indexes, name) elif len(indexes) == 1: return indexes[0] rng_indexes = cast(List[RangeIndex], indexes) start = step = next_ = None # Filter the empty indexes non_empty_indexes = [obj for obj in rng_indexes if len(obj)] for obj in non_empty_indexes: rng = obj._range if start is None: # This is set by the first non-empty index start = rng.start if step is None and len(rng) > 1: step = rng.step elif step is None: # First non-empty index had only one element if rng.start == start: values = np.concatenate([x._values for x in rng_indexes]) result = Int64Index(values) return result.rename(name) step = rng.start - start non_consecutive = (step != rng.step and len(rng) > 1) or ( next_ is not None and rng.start != next_ ) if non_consecutive: result = Int64Index(np.concatenate([x._values for x in rng_indexes])) return result.rename(name) if step is not None: next_ = rng[-1] + step if non_empty_indexes: # Get the stop value from "next" or alternatively # from the last non-empty index stop = non_empty_indexes[-1].stop if next_ is None else next_ return RangeIndex(start, stop, step).rename(name) # Here all "indexes" had 0 length, i.e. were empty. # In this case return an empty range index. return RangeIndex(0, 0).rename(name) def __len__(self) -> int: """ return the length of the RangeIndex """ return len(self._range) @property def size(self) -> int: return len(self) def __getitem__(self, key): """ Conserve RangeIndex type for scalar and slice keys. """ if isinstance(key, slice): new_range = self._range[key] return self._simple_new(new_range, name=self._name) elif is_integer(key): new_key = int(key) try: return self._range[new_key] except IndexError as err: raise IndexError( f"index {key} is out of bounds for axis 0 with size {len(self)}" ) from err elif is_scalar(key): raise IndexError( "only integers, slices (`:`), " "ellipsis (`...`), numpy.newaxis (`None`) " "and integer or boolean " "arrays are valid indices" ) # fall back to Int64Index return super().__getitem__(key) def _getitem_slice(self: RangeIndex, slobj: slice) -> RangeIndex: """ Fastpath for __getitem__ when we know we have a slice. """ res = self._range[slobj] return type(self)._simple_new(res, name=self._name) @unpack_zerodim_and_defer("__floordiv__") def __floordiv__(self, other): if is_integer(other) and other != 0: if len(self) == 0 or self.start % other == 0 and self.step % other == 0: start = self.start // other step = self.step // other stop = start + len(self) * step new_range = range(start, stop, step or 1) return self._simple_new(new_range, name=self.name) if len(self) == 1: start = self.start // other new_range = range(start, start + 1, 1) return self._simple_new(new_range, name=self.name) return self._int64index // other # -------------------------------------------------------------------- # Reductions def all(self, *args, **kwargs) -> bool: return 0 not in self._range def any(self, *args, **kwargs) -> bool: return any(self._range) # -------------------------------------------------------------------- def _cmp_method(self, other, op): if isinstance(other, RangeIndex) and self._range == other._range: # Both are immutable so if ._range attr. are equal, shortcut is possible return super()._cmp_method(self, op) return super()._cmp_method(other, op) def _arith_method(self, other, op): """ Parameters ---------- other : Any op : callable that accepts 2 params perform the binary op """ if isinstance(other, ABCTimedeltaIndex): # Defer to TimedeltaIndex implementation return NotImplemented elif isinstance(other, (timedelta, np.timedelta64)): # GH#19333 is_integer evaluated True on timedelta64, # so we need to catch these explicitly return op(self._int64index, other) elif is_timedelta64_dtype(other): # Must be an np.ndarray; GH#22390 return op(self._int64index, other) if op in [ operator.pow, ops.rpow, operator.mod, ops.rmod, ops.rfloordiv, divmod, ops.rdivmod, ]: return op(self._int64index, other) step: Callable | None = None if op in [operator.mul, ops.rmul, operator.truediv, ops.rtruediv]: step = op # TODO: if other is a RangeIndex we may have more efficient options other = extract_array(other, extract_numpy=True, extract_range=True) attrs = self._get_attributes_dict() left, right = self, other try: # apply if we have an override if step: with np.errstate(all="ignore"): rstep = step(left.step, right) # we don't have a representable op # so return a base index if not is_integer(rstep) or not rstep: raise ValueError else: rstep = left.step with np.errstate(all="ignore"): rstart = op(left.start, right) rstop = op(left.stop, right) result = type(self)(rstart, rstop, rstep, **attrs) # for compat with numpy / Int64Index # even if we can represent as a RangeIndex, return # as a Float64Index if we have float-like descriptors if not all(is_integer(x) for x in [rstart, rstop, rstep]): result = result.astype("float64") return result except (ValueError, TypeError, ZeroDivisionError): # Defer to Int64Index implementation return op(self._int64index, other) # TODO: Do attrs get handled reliably?
32.777083
88
0.556664
1
1.9836
[ -0.040395818650722504, 0.04361541196703911, -0.0037216106429696083, -0.008694946765899658, -0.01640172116458416, -0.010347414761781693, -0.0013271147618070245, -0.024952609091997147, -0.02471179887652397, 0.017271658405661583, -0.003479535458609462, 0.011521718464791775, 0.03222230449318886, -0.001084853196516633, -0.04275457188487053, 0.01470657903701067, 0.037279460579156876, -0.031644921749830246, 0.008987708948552608, 0.007223167922347784, -0.004417890682816505, 0.02449852041900158, -0.038567088544368744, 0.016218045726418495, 0.014082798734307289, -0.027869081124663353, 0.04199226200580597, 0.023201266303658485, 0.02142513170838356, -0.021983712911605835, -0.016042346134781837, -0.016456155106425285, -0.005958941765129566, -0.031833261251449585, -0.00753544457256794, -0.0009649977437220514, 0.018542392179369926, -0.041725318878889084, -0.012210885062813759, 0.039647769182920456, 0.01776907593011856, -0.04586036875844002, 0.004525435622781515, -0.015562339685857296, 0.02351992204785347, 0.007054414600133896, -0.015398220159113407, 0.030607158318161964, -0.055844198912382126, 0.015319153666496277, 0.005292713176459074, 0.017198514193296432, 0.05635655298829079, -0.02578870765864849, -0.014007546938955784, -0.047185156494379044, -0.018981877714395523, 0.009893427602946758, -0.06260523945093155, 0.05078687146306038, 0.031276602298021317, 0.005335225723683834, 0.018709246069192886, -0.03201477602124214, 0.05708180367946625, -0.013206765986979008, 0.027857353910803795, 0.004441957920789719, -0.05888194218277931, -0.01771807111799717, 0.0005795246106572449, 0.026800241321325302, -0.010660069063305855, 0.06814854592084885, 0.011216141283512115, 0.008285816758871078, -0.011567635461688042, -0.02161766029894352, -0.018584437668323517, 0.024566451087594032, -0.0013150860322639346, 0.06661179661750793, 0.020967328920960426, -0.006589318159967661, 0.006154288072139025, 0.031652938574552536, 0.04920748248696327, -0.055040694773197174, 0.020648738369345665, 0.005262961611151695, -0.015032048337161541, 0.04504625126719475, 0.00046651315642520785, 0.008263238705694675, -0.05806594341993332, -0.07570000737905502, 0.028079619631171227, 0.022248482331633568, -0.006247707176953554, 0.0001760086161084473, 0.04635243117809296, 0.0029375299345701933, 0.0030381130054593086, 0.0028677263762801886, -0.004888096358627081, -0.02402426302433014, -0.07215727865695953, 0.0028917589224874973, -0.0045460294932127, -0.03198670968413353, -0.004551167134195566, -0.014455216005444527, 0.00283602112904191, -0.012580160051584244, 0.004020990803837776, -0.009461632929742336, -0.030866418033838272, 0.007644390221685171, -0.015441827476024628, 0.055247753858566284, -0.026571137830615044, -0.02484206110239029, 0.008054535835981369, -0.03706160560250282, -0.016860876232385635, 0.09138708561658859, -0.014189072884619236, -0.01229398138821125, 0.043757837265729904, -0.010508987121284008, -0.012958734296262264, 0.0003925755445379764, 0.002937943208962679, -0.018873441964387894, -0.012739785015583038, -0.024840304628014565, 0.020252937451004982, -0.015534893609583378, -0.023867063224315643, 0.013188720680773258, 0.014464552514255047, -0.031786318868398666, 0.00458019133657217, -0.02168041653931141, -0.020845388993620872, -0.05582622438669205, -0.036339275538921356, -0.0026103039272129536, 0.006639139726758003, -0.006165022496134043, -0.013398581184446812, -0.03164300322532654, -0.009004220366477966, 0.01945856213569641, 0.00554910022765398, -0.020085172727704048, -0.0072808824479579926, -0.07360001653432846, 0.004317094571888447, 0.0029720780439674854, -0.03055589273571968, 0.007976742461323738, -0.01367406640201807, -0.014934693463146687, -0.01813442073762417, 0.05098267272114754, -0.03808692842721939, 0.022430799901485443, -0.03932889550924301, 0.035210225731134415, -0.008785239420831203, 0.003016162198036909, -0.008247289806604385, -0.033826373517513275, -0.02906014397740364, -0.00925446953624487, 0.007475181017071009, 0.013781614601612091, 0.012716013006865978, 0.005818629637360573, 0.005415007937699556, 0.010745832696557045, 0.015361055731773376, 0.03728847950696945, 0.02788320556282997, -0.0033291385043412447, 0.016880230978131294, -0.02420651726424694, -0.007674196269363165, -0.03340357169508934, -0.035195864737033844, 0.028047796338796616, -0.01587045006453991, -0.019543901085853577, 0.02541997842490673, 0.005528028588742018, 0.044494353234767914, -0.0011867102002725005, -0.007410028018057346, 0.0201594065874815, -0.00806828960776329, -0.015768764540553093, 0.007810663431882858, 0.01128221582621336, -0.022241687402129173, -0.020105088129639626, -0.6702520251274109, 0.05133678764104843, 0.02788410149514675, -0.01881837472319603, 0.0374300479888916, 0.042730677872896194, -0.03815292567014694, 0.02613060548901558, -0.07364290207624435, 0.07661242038011551, 0.010869469493627548, 0.009319414384663105, -0.028149234130978584, 0.0106267798691988, 0.037755440920591354, -0.02476438879966736, 0.02757827378809452, 0.01853657141327858, 0.02133885957300663, 0.015180720016360283, 0.028171516954898834, -0.014073825441300869, -0.000646633212454617, -0.00835989136248827, 0.03986968472599983, 0.005357869900763035, 0.03865702450275421, 0.01646961085498333, 0.014481402933597565, -0.020402349531650543, 0.0006341225234791636, -0.018503151834011078, 0.02823832258582115, -0.04332506284117699, 0.017538225278258324, 0.01725475862622261, -0.027064690366387367, -0.014037035405635834, 0.0006765519501641393, 0.0047454023733735085, 0.005537942983210087, -0.03202890604734421, -0.02784734219312668, -0.05402592942118645, -0.03349192813038826, 0.014688761904835701, -0.06700804084539413, -0.053914669901132584, 0.034928612411022186, 0.010974704287946224, -0.041790563613176346, 0.038216978311538696, 0.014397618360817432, -0.036709975451231, 0.000612578063737601, 0.004423307254910469, -0.039254579693078995, -0.03426464647054672, -0.0033738124184310436, 0.00856192409992218, 0.02749919332563877, -0.017758585512638092, -0.036361776292324066, 0.0009259618236683309, -0.0008682395564392209, 0.020892716944217682, 0.09526649862527847, -0.0013049859553575516, -0.014665410853922367, 0.01739342510700226, -0.04134950414299965, 0.0035426022950559855, -0.020923152565956116, 0.11773595213890076, -0.01221083290874958, -0.003193577053025365, 0.004579566419124603, 0.023393740877509117, -0.01456929836422205, 0.005335772410035133, 0.005134101957082748, -0.019583186134696007, -0.031301893293857574, -0.005350039806216955, -0.028222275897860527, 0.03047936223447323, -0.005290671717375517, -0.022585604339838028, -0.0025641683023422956, 0.011144876480102539, 0.023100504651665688, 0.07699248194694519, 0.019363077357411385, -0.01661614328622818, 0.012066815979778767, 0.03136688843369484, 0.003600852796807885, 0.006452752277255058, 0.02107592113316059, 0.0207997877150774, -0.05534512549638748, 0.014957236126065254, 0.012306922115385532, 0.05104949325323105, 0.026995066553354263, 0.015673553571105003, -0.03870387375354767, 0.010229420848190784, 0.043456923216581345, -0.012048370204865932, -0.013767380267381668, -0.020766180008649826, 0.0005895977956242859, 0.02204819582402706, -0.05235613137483597, -0.020969660952687263, 0.02052801474928856, -0.045987024903297424, 0.009155971929430962, 0.00012969656381756067, -0.04914938658475876, -0.02140379697084427, 0.033021315932273865, -0.003596767783164978, -0.018545974045991898, -0.0151808587834239, -0.014470327645540237, -0.010265771299600601, -0.007077558897435665, 0.026182381436228752, -0.04196903109550476, -0.0174732469022274, -0.022107787430286407, -0.000927406654227525, 0.010150314308702946, -0.02206086739897728, -0.021510984748601913, -0.03149921074509621, -0.008048748597502708, -0.013494129292666912, -0.01043869461864233, -0.020330116152763367, 0.01590779796242714, -0.04080577939748764, -0.004606320057064295, -0.019501764327287674, 0.003506364766508341, 0.02460828237235546, -0.018179478123784065, 0.022883594036102295, -0.020440585911273956, -0.008471653796732426, -0.0009036908159032464, -0.029918283224105835, -0.011090206913650036, 0.04443112015724182, -0.01570812053978443, -0.005517466459423304, 0.025903265923261642, 0.00794347282499075, -0.02099091000854969, -0.02417435310781002, -0.0288151316344738, 0.018461983650922775, 0.015478754416108131, -0.011540209874510765, 0.010001233778893948, 0.04439409822225571, 0.01405120175331831, -0.006274254992604256, 0.002190199913457036, 0.0057773166336119175, 0.03421078994870186, -0.009375927038490772, -0.01968822069466114, 0.011067379266023636, -0.0026741744950413704, -0.07526667416095734, -0.005181135144084692, -0.0073356847278773785, 0.01041471678763628, 0.02048513852059841, -0.0014170900685712695, -0.014782021753489971, 0.002219386165961623, 0.02635173872113228, -0.0013836320722475648, 0.01147424802184105, 0.0449591763317585, 0.02759973518550396, -0.0037816213443875313, 0.03565968573093414, 0.01587907411158085, -0.015044488944113255, -0.023698516190052032, -0.012728303670883179, -0.03479892015457153, -0.016811031848192215, -0.02830645628273487, -0.033089712262153625, 0.013554460369050503, 0.006531903054565191, 0.00904699508100748, -0.004932632204145193, 0.013288391754031181, 0.034818798303604126, 0.0327722392976284, -0.03337124362587929, -0.011591613292694092, 0.009440057910978794, 0.030910318717360497, -0.028571829199790955, 0.021282324567437172, -0.00276013882830739, -0.0061094267293810844, -0.01257649902254343, -0.05676964670419693, 0.02817494608461857, 0.018135884776711464, -0.027415534481406212, 0.00430800998583436, -0.005675614345818758, 0.018851380795240402, 0.0016969713615253568, 0.033706460148096085, -0.0054637715220451355, -0.04831782355904579, 0.009858718141913414, -0.028144758194684982, -0.023030951619148254, 0.004601260647177696, 0.004437894094735384, 0.004275497514754534, -0.016875652596354485, -0.011993483640253544, -0.003631299827247858, -0.03086465783417225, -0.015649020671844482, -0.009414850734174252, -0.02178838662803173, 0.0074761295691132545, -0.025485964491963387, -0.005875143688172102, 0.018344735726714134, 0.02868286892771721, 0.009963414631783962, -0.010500307194888592, -0.024967217817902565, -0.051468752324581146, -0.005093610379844904, -0.06399589776992798, 0.0491393618285656, -0.014959173277020454, 0.012891081161797047, -0.00371953216381371, 0.04193960875272751, -0.00466980691999197, 0.041053127497434616, 0.024029849097132683, 0.015262092463672161, 0.001249721390195191, -0.0002033748314715922, -0.011015236377716064, 0.027894213795661926, -0.00398028502240777, 0.03852633014321327, -0.0025405739434063435, -0.0038592745549976826, 0.012188700959086418, 0.010601331479847431, -0.008381500840187073, 0.032881960272789, -0.03366612270474434, 0.01752687618136406, -0.011391379870474339, -0.023143475875258446, -0.025866996496915817, -0.07506874203681946, 0.0005307822139002383, 0.005713893566280603, -0.03838491812348366, 0.03518032282590866, 0.0023384715896099806, 0.03245604783296585, 0.0111576272174716, -0.004340002313256264, 0.04203401505947113, -0.01761810854077339, -0.038746245205402374, -0.0005403726827353239, -0.028209423646330833, -0.01620853878557682, -0.010373260825872421, -0.040356118232011795, -0.0021076961420476437, 0.03054312989115715, 0.014472468756139278, 0.0022439961321651936, 0.02390807494521141, 0.006970728747546673, 0.04721660539507866, 0.003208096604794264, 0.021286560222506523, 0.0058344327844679356, 0.028158294036984444, -0.025006594136357307, 0.03132057562470436, -0.06435193121433258, 0.037541188299655914, 0.022293997928500175, 0.010985991917550564, 0.0356488898396492, 0.007065825164318085, 0.02476940117776394, 0.0048690070398151875, 0.007328380830585957, 0.03422631695866585, 0.043170977383852005, 0.011128636077046394, 0.023984547704458237, -0.03188801184296608, -0.015604419633746147, -0.0025403746403753757, -0.044473253190517426, 0.014207150787115097, -0.012459021992981434, -0.04448835551738739, -0.00037171848816797137, -0.010491766035556793, 0.02198096178472042, -0.022840198129415512, 0.022400595247745514, 0.03122659958899021, -0.002478665905073285, 0.009779750369489193, -0.03327666595578194, 0.0037727118469774723, 0.039923328906297684, 0.028107134625315666, 0.01016527134925127, -0.021679842844605446, 0.009028643369674683, -0.006045658607035875, 0.004042498767375946, 0.010751788504421711, 0.030371546745300293, 0.061793334782123566, 0.07864750921726227, 0.056030068546533585, 0.021376006305217743, 0.043365780264139175, -0.03643926605582237, -0.019377609714865685, -0.009198888204991817, 0.010697134770452976, 0.01355902198702097, -0.04258014261722565, -0.0007645587902516127, 0.01749747060239315, -0.002514695981517434, 0.009890022687613964, 0.02839992567896843, -0.0005212536198087037, -0.0118149658665061, 0.0002008071169257164, -0.021336058154702187, -0.000190670951269567, -0.011548354290425777, -0.01464164163917303, 0.04569488763809204, -0.009488515555858612, -0.045965708792209625, -0.015570560470223427, 0.0025218019727617502, -0.00016190357564482838, 0.018675867468118668, 0.05677764490246773, -0.020840834826231003, -0.00933121982961893, 0.04209606349468231, -0.03276413679122925, -0.013645550236105919, 0.02646421641111374, -0.005426236893981695, 0.0092562111094594, -0.010904352180659771, 0.008910519070923328, 0.01525808684527874, 0.010151057504117489, -0.023908264935016632, -0.008268413133919239, -0.013631469570100307, -0.004079661797732115, 0.021024279296398163, -0.02968755178153515, -0.013190495781600475, -0.0297747440636158, -0.026835989207029343, -0.01076586078852415, 0.02751736529171467, -0.02504211850464344, 0.0059707872569561005, 0.015261229127645493, -0.023758994415402412, 0.01092561800032854, -0.004914982710033655, 0.03483613580465317, 0.013843636959791183, -0.029551496729254723, 0.03413953632116318, 0.002127793151885271, 0.00195981003344059, -0.01493929885327816, -0.013992373831570148, 0.010143396444618702, -0.03935922309756279, 0.011192712932825089, -0.0004990147426724434, -0.006581190973520279, -0.010859065689146519, -0.044550973922014236, -0.033788248896598816, 0.0034086210653185844, -0.010817590169608593, 0.024966156110167503, 0.023226875811815262, 0.02992667630314827, 0.0007348685176111758, 0.024308186024427414, 0.015384304337203503, -0.013647337444126606, 0.012606385163962841, -0.017865505069494247, -0.005759376101195812, 0.018218878656625748, -0.038479022681713104, 0.015241784043610096, -0.015810998156666756, -0.017793579027056694, 0.03208747133612633, -0.008396725170314312, -0.006051136180758476, -0.007962707430124283, 0.02713884599506855, -0.025456732138991356, 0.05637117475271225, 0.042473696172237396, 0.014679774641990662, -0.011436747387051582, -0.0004917689366266131, 0.0199943445622921, 0.027940422296524048, 0.03161949664354324, 0.02803296595811844, 0.0003095063439104706, 0.034895338118076324, 0.04291241616010666, 0.012938753701746464, -0.028318308293819427, -0.0010979257058352232, -0.023039288818836212, 0.011034892871975899, -0.043726712465286255, 0.04278092831373215, -0.012534001842141151, 0.032804813235998154, 0.002252369886264205, -0.028785619884729385, -0.011834532953798771, -0.04048808664083481, 0.03514179214835167, 0.028464043512940407, -0.040358059108257294, -0.011728482320904732, -0.0004896582686342299, -0.003644356271252036, -0.025580335408449173, 0.005021965131163597, 0.024233048781752586, -0.026350848376750946, -0.0035116691142320633, -0.0005419385270215571, 0.018495455384254456, -0.007337694987654686, -0.007857730612158775, -0.02474014274775982, -0.02400621585547924, 0.021431922912597656, 0.008622157387435436, -0.009880202822387218, 0.00044783324119634926, -0.011241239495575428, -0.018576014786958694, 0.020227530971169472, -0.002463334007188678, -0.001100757741369307, 0.012239377945661545, -0.0337839312851429, 0.05543965473771095, -0.006802471354603767, -0.03792378678917885, -0.03898340091109276, -0.028929028660058975, -0.036286622285842896, 0.010330431163311005, 0.03780299797654152, 0.11534303426742554, 0.02875399962067604, -0.0037433418910950422, -0.0026516029611229897, -0.01763947680592537, -0.001903571654111147, -0.0668644905090332, 0.006563213653862476, 0.0002656887227203697, 0.008324292488396168, 0.047038733959198, -0.03266450762748718, -0.0005564232706092298, 0.05550834536552429, 0.03028319962322712, 0.011007772758603096, -0.03289454057812691, 0.00023819725902285427, 0.010953854769468307, -0.026155926287174225, -0.041776057332754135, -0.010134350508451462, 0.030302461236715317, 0.01236678846180439, -0.027624037116765976, 0.0015612832503393292, -0.028424814343452454, 0.02481507882475853, -0.0022731495555490255, -0.03846476599574089, 0.014155001379549503, 0.017244139686226845, -0.03131920099258423, 0.012050973251461983, 0.036982811987400055, 0.022726310417056084, 0.015570053830742836, -0.03765101730823517, -0.00841766782104969, 0.002232104539871216, -0.0005732231074944139, -0.0025209574960172176, 0.014025410637259483, 0.005517830606549978, -0.01618085242807865, -0.01809718832373619, 0.017676586285233498, 0.009889938868582249, -0.022581342607736588, -0.012022549286484718, 0.007982590235769749, 0.045629289001226425, -0.02548220194876194, -0.03355846181511879, 0.017389116808772087, 0.001752719865180552 ]
8a921ddf5fe02b1831b2b73b31bdcdcfebea2ba6
708
py
Python
model.py
Hasanweight/pytorch-chatbot-master
7a3b58af7e5284f1f3f7f7b0aeb3f19d9ee3cbc1
[ "MIT" ]
null
null
null
model.py
Hasanweight/pytorch-chatbot-master
7a3b58af7e5284f1f3f7f7b0aeb3f19d9ee3cbc1
[ "MIT" ]
null
null
null
model.py
Hasanweight/pytorch-chatbot-master
7a3b58af7e5284f1f3f7f7b0aeb3f19d9ee3cbc1
[ "MIT" ]
1
2020-11-17T07:04:35.000Z
2020-11-17T07:04:35.000Z
import torch import torch.nn as nn class NeuralNet(nn.Module): def __init__(self, input_size, hidden_size, num_classes): super(NeuralNet, self).__init__() self.l1 = nn.Linear(input_size, hidden_size) self.l2 = nn.Linear(hidden_size, hidden_size) self.l3 = nn.Linear(hidden_size, hidden_size) self.l4 = nn.Linear(hidden_size, num_classes) self.relu = nn.ReLU() def forward(self, x): out = self.l1(x) out = self.relu(out) out = self.l2(out) out = self.relu(out) out = self.l3(out) out = self.relu(out) out = self.l4(out) # no activation and no softmax at the end return out
30.782609
61
0.59887
1
0.8871
[ 0.002463976852595806, 0.02339756116271019, 0.010629347525537014, 0.0005284104845486581, 0.004418433643877506, -0.0030937055125832558, -0.007170871365815401, 0.0021226948592811823, -0.007780101615935564, 0.003740154206752777, 0.0019108799751847982, 0.007416895590722561, 0.010395833291113377, -0.013424566946923733, -0.0004136317002121359, 0.01973664201796055, -0.053774431347846985, 0.0038506321143358946, -0.003143720794469118, 0.0010893273865804076, -0.0053657423704862595, 0.007569769863039255, 0.006715578492730856, 0.006917104125022888, 0.004993501119315624, -0.0017245053313672543, 0.012146185152232647, -0.0004857574822381139, -0.007136248517781496, -0.002293287543579936, -0.0030710541177541018, -0.003451744792982936, -0.0027072604279965162, -0.007128410041332245, 0.008601040579378605, -0.00791139155626297, 0.00459251319989562, -0.01850111223757267, 0.008961042389273643, -0.006636518985033035, -0.00029404473025351763, -0.015501013956964016, -0.0048490846529603004, 0.0006604428635910153, -0.009367633610963821, 0.006221011746674776, -0.008402322418987751, 0.0004113757750019431, -0.009347221814095974, 0.00459281587973237, -0.00953156128525734, 0.008499258197844028, 0.01422758586704731, 0.000880808976944536, -0.007857249118387699, -0.00903354026377201, 0.014409979805350304, 0.002537813503295183, -0.011067706160247326, 0.001962237525731325, -0.0037061371840536594, 0.0006481342134065926, 0.005569243337959051, -0.0006237922352738678, -0.018065322190523148, -0.008501779288053513, -0.0056402962654829025, 0.003109486075118184, -0.00624973326921463, 0.00602110568434, 0.0025888520758599043, -0.0008631804957985878, 0.008583946153521538, 0.005865554325282574, 0.005532525945454836, -0.002264101291075349, -0.004298957530409098, 0.0005096153472550213, 0.010014480911195278, 0.0013653639471158385, 0.00025314188678748906, -0.008300223387777805, 0.004046838264912367, 0.01038961112499237, 0.017249533906579018, 0.011493728496134281, 0.014914801344275475, -0.013001165352761745, 0.04578370973467827, 0.007245596498250961, -0.009488295763731003, 0.0050684320740401745, -0.011482229456305504, -0.0037620277144014835, -0.005650956649333239, -0.03244287148118019, 0.005118997301906347, -0.005895645823329687, 0.00009858753037406132, 0.0029517163056880236, 0.005013349000364542, 0.008462450467050076, 0.00034784729359671474, -0.006013175006955862, -0.010766872204840183, 0.012783621437847614, -0.014728222042322159, -0.005353958811610937, 0.008225993253290653, 0.0034672701731324196, -0.013118005357682705, 0.0006467182538472116, -0.0031667472794651985, -0.015526706352829933, 0.0031954855658113956, 0.0053185694850981236, -0.004621158353984356, 0.05346360802650452, -0.0023528863675892353, 0.012325978837907314, -0.006852343678474426, -0.004873024299740791, 0.0010995065094903111, 0.0017231503734365106, 0.014289981685578823, -0.0010393583215773106, 0.01141782384365797, 0.0017251274548470974, 0.003551471047103405, 0.008470052853226662, -0.0028400279115885496, 0.00399502320215106, -0.001173781231045723, -0.00029152832576073706, -0.0035367654636502266, -0.007057188544422388, 0.004748908337205648, -0.0015259913634508848, -0.006108400411903858, 0.0035588922910392284, -0.003224513493478298, -0.01147524919360876, -0.00411599176004529, 0.0012378026731312275, 0.004320997279137373, -0.013592027127742767, -0.008549923077225685, -0.002191980602219701, -0.006575685925781727, 0.005336659029126167, 0.003864436177536845, 0.009828677400946617, 0.004044799134135246, -0.0013001078041270375, -0.008649918250739574, 0.0032201551366597414, -0.005497467238456011, -0.0010565833654254675, 0.006180827505886555, 0.006491317413747311, -0.013477464206516743, -0.005681994836777449, 0.0014059962704777718, 0.004575623665004969, 0.00007238262332975864, -0.00007854798604967073, -0.0048271468840539455, 0.00811202172189951, 0.0004679347912315279, 0.004007576033473015, 0.01209605298936367, -0.0057272035628557205, 0.0003399152774363756, -0.0007037468021735549, 0.0029498860239982605, -0.00006678923091385514, 0.0071495878510177135, 0.008971129544079304, -0.001516881980933249, -0.003969927784055471, 0.009817903861403465, 0.004870213568210602, 0.00822073221206665, 0.0059941597282886505, -0.0033919468987733126, -0.00026998852263204753, -0.007578270044177771, -0.0009748840820975602, 0.011561586521565914, -0.005611775908619165, 0.005592587869614363, 0.002145652659237385, -0.014843964017927647, -0.007248475681990385, -0.0021875386592000723, -0.0070948428474366665, 0.002229517325758934, 0.015386473387479782, 0.011712411418557167, -0.00212308531627059, -0.00016981613589450717, -0.01303093507885933, -0.0036669450346380472, 0.009097181260585785, 0.00010963500244542956, -0.011200383305549622, -0.9552503228187561, 0.011788458563387394, 0.0024903472512960434, -0.005140135996043682, 0.007345861755311489, -0.004018404986709356, 0.0012628413969650865, 0.003785207401961088, 0.011631147935986519, -0.004945159424096346, -0.004253509920090437, -0.010454820469021797, -0.01421024277806282, -0.0000457439455203712, -0.008018147200345993, -0.0018236716277897358, -0.0032753548584878445, -0.005296322517096996, -0.006110989488661289, -0.002700548153370619, -0.0036572578828781843, 0.010595313273370266, -0.003922662697732449, 0.0032906406559050083, 0.003794408403337002, 0.003383604809641838, -0.0023754294961690903, -0.0006148018292151392, 0.001547277090139687, -0.0013625253923237324, -0.006224514450877905, -0.01216901559382677, -0.0012553384294733405, -0.001401374931447208, 0.009547481313347816, -0.0007304140017367899, 0.004348015412688255, -0.002757427515462041, 0.00557669997215271, -0.010927422903478146, 0.007892251946032047, 0.002728222170844674, 0.004555882420390844, -0.02661772631108761, 0.0013035816373303533, 0.001950650243088603, -0.008674443699419498, 0.006824548356235027, 0.004794011358171701, -0.0030534639954566956, -0.002969519468024373, -0.01012449525296688, 0.013360178098082542, -0.0047507076524198055, 0.01108507625758648, -0.0060759009793400764, -0.00795858446508646, -0.005338848568499088, -0.003768244059756398, -0.0007942751399241388, 0.005372920539230108, -0.0025386144407093525, -0.001848313957452774, -0.006548500154167414, 0.0031335034873336554, 0.0033713113516569138, 0.0020009803120046854, -0.026394512504339218, -0.01013312116265297, -0.0013326193438842893, 0.004930395632982254, 0.0007480625645257533, -0.006782179232686758, 0.005217030178755522, -0.006183954421430826, 0.005429122596979141, 0.0042233215644955635, -0.001692026387900114, -0.008255650289356709, 0.0017062465194612741, -0.013555596582591534, -0.005881215445697308, 0.007250525522977114, -0.006406746804714203, -0.006207785569131374, -0.0004234648367855698, 0.0083797387778759, 0.007409689016640186, -0.00584330502897501, 0.00294463406316936, 0.007788765709847212, 0.0011406734120100737, -0.010063025169074535, 0.005783591885119677, 0.009160846471786499, 0.006973758339881897, -0.004406700376421213, 0.0054335943423211575, 0.004005218390375376, 0.007657802198082209, 0.005428284872323275, 0.01241648755967617, 0.00732705183327198, 0.012331158854067326, -0.0010557974455878139, 0.00016856110596563667, -0.002724439837038517, 0.0005143905873410404, -0.006011187564581633, 0.0019308262271806598, -0.0046026818454265594, -0.005750664975494146, -0.011359114199876785, -0.007780296728014946, -0.01016212161630392, 0.00040921109030023217, 0.0017300061881542206, -0.008287273347377777, -0.0032764184288680553, 0.00017947214655578136, 0.009618667885661125, -0.00026804531808011234, -0.004444807767868042, 0.00342758116312325, 0.003623519791290164, -0.0038624790031462908, 0.01729828491806984, -0.016983479261398315, 0.010066688060760498, 0.0009321579709649086, -0.018327899277210236, 0.0030052191577851772, 0.005912675056606531, -0.009771524928510189, 0.0003878134011756629, 0.0004848476964980364, -0.000444650708232075, -0.004533611703664064, -0.006902310531586409, 0.0005718012107536197, -0.019847728312015533, 0.0012599831679835916, 0.018902014940977097, -0.0009895992698147893, 0.010994409210979939, 0.010358617641031742, -0.00201564677990973, 0.001954387640580535, 0.003763520857319236, -0.0004535163170658052, 0.014897271990776062, -0.011232733726501465, 0.0006191239226609468, 0.0027725279796868563, -0.007683923467993736, 0.0013222545385360718, 0.006028496660292149, 0.0022851128596812487, 0.0027451515197753906, 0.004708189517259598, -0.0019878181628882885, -0.003151961835101247, -0.014626584015786648, -0.003571012755855918, 0.01507140789180994, -0.0024172388948500156, 0.0038040303625166416, -0.007988828234374523, 0.0035687475465238094, 0.004547778517007828, 0.013057163916528225, 0.0004052142321597785, -0.00035911117447540164, 0.004931813571602106, 0.009247921407222748, -0.008005466312170029, 0.002220460679382086, 0.0051001934334635735, 0.003735495964065194, -0.003128511132672429, 0.005889419000595808, -0.00894711259752512, -0.003613521112129092, -0.00008153470844263211, 0.0038616100791841745, 0.0008681692415848374, -0.0017194881802424788, -0.0045593781396746635, -0.008313232101500034, 0.007234545890241861, -0.002070466987788677, 0.0004866296658292413, 0.0029942456167191267, 0.002412582514807582, -0.009712034836411476, 0.0006679990910924971, -0.004805297125130892, -0.007147013675421476, 0.010595140978693962, -0.0024558240547776222, 0.005135837476700544, 0.014997921884059906, 0.007474725134670734, -0.015762807801365852, 0.007828987203538418, 0.007597784977406263, -0.002623662818223238, 0.008398223668336868, 0.006855251267552376, -0.001395552884787321, -0.02591194026172161, -0.005814306437969208, -0.00901374313980341, 0.004166449420154095, -0.001701463246718049, 0.006487639155238867, -0.006508437916636467, 0.003804336301982403, 0.004756683949381113, -0.0121873514726758, -0.007467553485184908, -0.008229578845202923, 0.006963971070945263, -0.0017880311934277415, 0.004671002738177776, -0.005966691765934229, -0.0038096648640930653, -0.004049213603138924, -0.0024157059378921986, -0.0035741215106099844, 0.00811731442809105, 0.0034667826257646084, -0.00772535614669323, 0.00243967492133379, -0.0006118242163211107, -0.0007802841137163341, -0.0027796579524874687, -0.007964614778757095, 0.0002836398780345917, 0.004159150179475546, 0.00010507624392630532, -0.0049214293248951435, 0.0016369047807529569, -0.003979183733463287, -0.005699828267097473, -0.013059391640126705, -0.00858481414616108, -0.0018360537942498922, -0.006799214985221624, -0.008431646972894669, -0.004711038898676634, -0.0086978729814291, 0.004774667788296938, -0.009337338618934155, 0.009284821338951588, 0.006425368599593639, -0.007121538743376732, 0.005174332298338413, -0.004160329699516296, 0.005342268384993076, 0.0016481397906318307, 0.003930931910872459, 0.00085352425230667, -0.007251831237226725, -0.005795624572783709, 0.014541066251695156, -0.009797556325793266, 0.0028180221561342478, 0.014254814013838768, 0.004557556938380003, 0.005074672866612673, -0.005108992103487253, 0.0007436834857799113, 0.0012821994023397565, 0.004699571989476681, -0.016532052308321, 0.003122985363006592, -0.0057474165223538876, 0.0020958848763257265, 0.006777410861104727, -0.004884124267846346, 0.0011762632057070732, 0.009580639190971851, 0.0041817426681518555, -0.0092190932482481, 0.0001947394630406052, -0.002949350979179144, 0.003981517627835274, -0.008980940096080303, 0.0015899838181212544, -0.001234808354638517, -0.005134103819727898, -0.000988358398899436, -0.006424822378903627, 0.004139585420489311, 0.004584531765431166, -0.0012167288223281503, 0.004473314620554447, -0.00108813785482198, -0.009623312391340733, 0.01362289022654295, -0.003860400291159749, -0.0048764594830572605, 0.003965077456086874, 0.002205528551712632, -0.003588587511330843, -0.0025421264581382275, -0.0004273596568964422, 0.004509073682129383, 0.003412596182897687, -0.004625909496098757, -0.001885201665572822, 0.00016662087000440806, -0.0014422644162550569, -0.014094404876232147, 0.0004400921461638063, 0.013470377773046494, -0.004907242953777313, 0.004011832177639008, -0.0022342975717037916, -0.008555641397833824, -0.013920196332037449, 0.04852764680981636, 0.0027789007872343063, 0.0036201204638928175, 0.003840562654659152, -0.004446270409971476, -0.004941219929605722, 0.002429054118692875, 0.00976558867841959, -0.004652818664908409, -0.010212598368525505, 0.010218712501227856, -0.005372703541070223, -0.0010095717152580619, 0.0056572952307760715, 0.0008579795248806477, 0.019832251593470573, -0.0023084452841430902, -0.015063322149217129, -0.01851150207221508, 0.008456162177026272, -0.006978450808674097, -0.006023495923727751, 0.01090026181191206, -0.0024271723814308643, -0.0038681828882545233, 0.004333462566137314, 0.008427051827311516, -0.0010469977278262377, -0.00045043035061098635, -0.003554541850462556, -0.00444424245506525, 0.006619322579354048, -0.0008368034032173455, 0.002998658921569586, 0.014234899543225765, -0.0009373627253808081, 0.007917419075965881, 0.003555231261998415, -0.003953444771468639, -0.003810795722529292, 0.004722000099718571, 0.00627760449424386, -0.004386326763778925, -0.006153513677418232, 0.0014360790373757482, 0.001367155578918755, 0.0032474722247570753, 0.011999208480119705, 0.0017106453888118267, -0.006537632085382938, 0.008713469840586185, 0.004716693889349699, 0.0008986627799458802, 0.016093403100967407, 0.00222742254845798, 0.004361285362392664, 0.005952106323093176, -0.011369639076292515, -0.013429177924990654, -0.001919760718010366, 0.009783672168850899, 0.01014633383601904, -0.0012429995695129037, -0.00009470585064264014, 0.00034313014475628734, -0.0016590208979323506, -0.011973879300057888, -0.008374975062906742, -0.00711857108399272, 0.0035338501911610365, 0.005103331990540028, 0.06692881137132645, -0.00892497319728136, -0.003997486550360918, -0.007580152712762356, 0.002438267460092902, -0.0009308065637014806, -0.003919654525816441, 0.0009313506889156997, -0.0013986221747472882, 0.005864881910383701, -0.00007244510925374925, -0.011278407648205757, -0.012178190052509308, -0.000044914802856510505, 0.002067522844299674, -0.0012014508247375488, 0.003930965904146433, 0.003939596936106682, -0.009778795763850212, 0.0024817173834890127, -0.01377458032220602, -0.0037084331270307302, -0.0001644452422624454, -0.01428979728370905, -0.0034534770529717207, -0.003841988043859601, 0.005715521518141031, 0.003929120488464832, 0.002821637550368905, -0.004618784412741661, 0.006815811153501272, -0.0030078282579779625, 0.00343753257766366, -0.00003125210423604585, -0.003273947164416313, -0.008825468830764294, 0.011270622722804546, 0.0033115344122052193, -0.020998526364564896, -0.00494779646396637, 0.0003878357820212841, 0.0025107183028012514, -0.005690590478479862, 0.006476073991507292, -0.0038729722145944834, 0.008120252750813961, -0.004306938499212265, 0.0026037644129246473, -0.004816572647541761, 0.005713127087801695, -0.011649047955870628, 0.007012977264821529, -0.1744139939546585, 0.014268883503973484, 0.0036108545027673244, -0.006839365232735872, -0.0036717066541314125, -0.011658215895295143, -0.013939017429947853, 0.007184919901192188, 0.010955560021102428, 0.004361910745501518, -0.00031747849425300956, -0.002881168620660901, 0.008897089399397373, 0.001783735235221684, -0.0006791470223106444, -0.011994536966085434, 0.003263172460719943, -0.005761310458183289, 0.001547380117699504, 0.008309528231620789, 0.005419664550572634, 0.012329748831689358, 0.0007842403138056397, 0.004092696588486433, 0.0015808421885594726, -0.000754867447540164, 0.002128992462530732, 0.00003526084401528351, 0.006140031851828098, -0.006677093915641308, -0.006525250617414713, -0.007740936242043972, -0.0023496574722230434, 0.00334672792814672, 0.0023092497140169144, 0.004799033515155315, 0.007877933792769909, -0.0004942590603604913, -0.011330530047416687, 0.006772936321794987, -0.010407022200524807, 0.028595654293894768, 0.002993764588609338, 0.004329535644501448, 0.004460534546524286, -0.008321256376802921, -0.004545324947685003, 0.007644753437489271, 0.0033891911152750254, 0.01139778271317482, -0.017603866755962372, -0.0037087807431817055, 0.0002151125663658604, 0.02082599326968193, -0.004781288094818592, -0.013167021796107292, -0.005726788192987442, -0.0047761183232069016, -0.0012473794631659985, 0.009930298663675785, 0.013332226313650608, -0.0022723479196429253, 0.006634193938225508, -0.004470932297408581, -0.023578274995088577, 0.0010199591051787138, 0.001458038343116641, -0.0061673251911997795, -0.00012246159894857556, 0.004990185145288706, 0.009716758504509926, -0.0015391239430755377, 0.006497816648334265, 0.001527754357084632, 0.004500868730247021, -0.005659046582877636, 0.004556075669825077, -0.0017546688904985785, 0.007128654979169369, -0.010323181748390198, 0.009316216222941875, -0.012055326253175735, -0.0026736429426819086, 0.004047011025249958, -0.006007219664752483, 0.007447889540344477, 0.00865810178220272, -0.004264356568455696, -0.0038011104334145784, -0.009711060672998428, -0.002077784389257431, 0.0027453459333628416, 0.00025320309214293957, -0.009595670737326145, 0.0036689816042780876, -0.0004924001405015588, 0.0008869334124028683, 0.00828342791646719, -0.010727353394031525, 0.009768889285624027, 0.004537041764706373, -0.008676933124661446, -0.0007059175404720008, -0.004055173136293888, 0.009118779562413692, 0.0035004629753530025, -0.007929015904664993, -0.0069155944511294365, 0.004030225332826376, -0.006610692013055086, -0.002280518878251314, 0.003402081551030278, -0.009011663496494293, -0.01374671421945095, -0.001105761039070785, -0.01213331613689661, -0.0005075759836472571 ]
8a9277485abaa1ad23562bb5f41c412cb9cb7cd7
6,927
py
Python
jwql/utils/logging_functions.py
hover2pi/jwql
0a97fe618c007883ffbced88ac1cb45a667fcb3c
[ "BSD-3-Clause" ]
null
null
null
jwql/utils/logging_functions.py
hover2pi/jwql
0a97fe618c007883ffbced88ac1cb45a667fcb3c
[ "BSD-3-Clause" ]
null
null
null
jwql/utils/logging_functions.py
hover2pi/jwql
0a97fe618c007883ffbced88ac1cb45a667fcb3c
[ "BSD-3-Clause" ]
null
null
null
""" Logging functions for the ``jwql`` automation platform. This module provides decorators to log the execution of modules. Log files are written to the ``logs/`` directory in the ``jwql`` central storage area, named by module name and timestamp, e.g. ``monitor_filesystem/monitor_filesystem_2018-06-20-15:22:51.log`` Authors ------- - Catherine Martlin 2018 - Alex Viana, 2013 (WFC3 QL Version) Use --- To log the execution of a module, use: :: import os import logging from jwql.logging.logging_functions import configure_logging from jwql.logging.logging_functions import log_info from jwql.logging.logging_functions import log_fail @log_info @log_fail def my_main_function(): pass if __name__ == '__main__': module = os.path.basename(__file__).replace('.py', '') configure_logging(module) my_main_function() Dependencies ------------ The user must have a configuration file named ``config.json`` placed in the ``utils`` directory. References ---------- This code is adopted and updated from python routine ``logging_functions.py`` written by Alex Viana, 2013 for the WFC3 Quicklook automation platform. """ import datetime import getpass import importlib import logging import os import pwd import socket import sys import time import traceback from functools import wraps from jwql.utils.permissions import set_permissions from jwql.utils.utils import get_config, ensure_dir_exists LOG_FILE_LOC = '' PRODUCTION_BOOL = '' def configure_logging(module, production_mode=True, path='./'): """Configure the log file with a standard logging format. Parameters ---------- module : str The name of the module being logged. production_mode : bool Whether or not the output should be written to the production environement. path : str Where to write the log if user-supplied path; default to working dir. """ # Determine log file location if production_mode: log_file = make_log_file(module) else: log_file = make_log_file(module, production_mode=False, path=path) global LOG_FILE_LOC global PRODUCTION_BOOL LOG_FILE_LOC = log_file PRODUCTION_BOOL = production_mode # Create the log file and set the permissions logging.basicConfig(filename=log_file, format='%(asctime)s %(levelname)s: %(message)s', datefmt='%m/%d/%Y %H:%M:%S %p', level=logging.INFO) set_permissions(log_file) def make_log_file(module, production_mode=True, path='./'): """Create the log file name based on the module name. The name of the ``log_file`` is a combination of the name of the module being logged and the current datetime. Parameters ---------- module : str The name of the module being logged. production_mode : bool Whether or not the output should be written to the production environment. path : str Where to write the log if user-supplied path; default to working dir. Returns ------- log_file : str The full path to where the log file will be written to. """ timestamp = datetime.datetime.now().strftime('%Y-%m-%d-%H-%M') filename = '{0}_{1}.log'.format(module, timestamp) user = pwd.getpwuid(os.getuid()).pw_name settings = get_config() admin_account = settings['admin_account'] log_path = settings['log_dir'] exempt_modules = [] if user != admin_account and module not in exempt_modules and production_mode: module = os.path.join('dev', module) if production_mode: log_file = os.path.join(log_path, module, filename) else: log_file = os.path.join(path, filename) ensure_dir_exists(os.path.dirname(log_file)) return log_file def log_info(func): """Decorator to log useful system information. This function can be used as a decorator to log user environment and system information. Future packages we want to track can be added or removed as necessary. Parameters ---------- func : func The function to decorate. Returns ------- wrapped : func The wrapped function. """ @wraps(func) def wrapped(*a, **kw): # Log environment information logging.info('User: ' + getpass.getuser()) logging.info('System: ' + socket.gethostname()) logging.info('Python Version: ' + sys.version.replace('\n', '')) logging.info('Python Executable Path: ' + sys.executable) # Read in setup.py file to build list of required modules settings = get_config() setup_file_name = settings['setup_file'] with open(setup_file_name) as setup: for line in setup: if line[0:8] == "REQUIRES": module_required = line[12:-2] module_list = module_required.split(',') # Clean up the module list module_list = [module.replace('"', '').replace("'", '').replace(' ', '') for module in module_list] module_list = [module.split('=')[0] for module in module_list] # Log common module version information for module in module_list: try: mod = importlib.import_module(module) logging.info(module + ' Version: ' + mod.__version__) logging.info(module + ' Path: ' + mod.__path__[0]) except ImportError as err: logging.warning(err) # Call the function and time it t1_cpu = time.clock() t1_time = time.time() func(*a, **kw) t2_cpu = time.clock() t2_time = time.time() # Log execution time hours_cpu, remainder_cpu = divmod(t2_cpu - t1_cpu, 60 * 60) minutes_cpu, seconds_cpu = divmod(remainder_cpu, 60) hours_time, remainder_time = divmod(t2_time - t1_time, 60 * 60) minutes_time, seconds_time = divmod(remainder_time, 60) logging.info('Elapsed Real Time: {0:.0f}:{1:.0f}:{2:f}'.format(hours_time, minutes_time, seconds_time)) logging.info('Elapsed CPU Time: {0:.0f}:{1:.0f}:{2:f}'.format(hours_cpu, minutes_cpu, seconds_cpu)) return wrapped def log_fail(func): """Decorator to log crashes in the decorated code. Parameters ---------- func : func The function to decorate. Returns ------- wrapped : func The wrapped function. """ @wraps(func) def wrapped(*a, **kw): try: # Run the function func(*a, **kw) logging.info('Completed Successfully') except Exception: logging.critical(traceback.format_exc()) logging.critical('CRASHED') return wrapped
28.044534
111
0.627111
0
0
[ -0.052679549902677536, 0.03987332060933113, 0.01019772607833147, 0.0029725891072303057, 0.0035553928464651108, -0.0053427997045218945, -0.0273183174431324, -0.00968110654503107, -0.017403606325387955, 0.005112793762236834, 0.014099565334618092, 0.0179139394313097, -0.02110310085117817, -0.04764017462730408, -0.03429890424013138, -0.011348419822752476, 0.1659969985485077, 0.00999879278242588, -0.011183423921465874, 0.007628645282238722, 0.00842155423015356, -0.0015291579766198993, 0.014297704212367535, -0.013042068108916283, 0.012694631703197956, 0.022180570289492607, -0.002416092436760664, -0.002876016078516841, -0.008517668582499027, -0.002659108955413103, -0.0050282664597034454, 0.004981278441846371, -0.03903908655047417, 0.012036383152008057, -0.0009377622045576572, -0.00014079510583542287, -0.006592862773686647, 0.016873132437467575, 0.015781674534082413, -0.006239079404622316, -0.04458416998386383, 0.026706283912062645, -0.01201708149164915, 0.03271585330367088, 0.015968576073646545, -0.018828079104423523, 0.00003601724893087521, 0.01157354936003685, -0.03832244127988815, 0.02649877592921257, 0.026314672082662582, 0.017943017184734344, -0.0021665801759809256, -0.008899005129933357, 0.013081398792564869, -0.011066397652029991, 0.022790955379605293, 0.02020432986319065, -0.012776941992342472, 0.012979084625840187, -0.021886436268687248, 0.0005709366523660719, 0.0061240363866090775, 0.02909715101122856, 0.0036281736101955175, 0.004971456713974476, -0.00955906230956316, -0.018610753118991852, 0.0029955636709928513, 0.04085893929004669, -0.025424828752875328, 0.012032069265842438, -0.04405015707015991, 0.012376531958580017, 0.010757091455161572, -0.0317898690700531, 0.027388276532292366, -0.00028219883097335696, 0.003515617921948433, 0.009143619798123837, 0.00753311300650239, 0.022072982043027878, 0.0048882849514484406, -0.004803506191819906, 0.025349847972393036, 0.014258979819715023, 0.0394168458878994, -0.021884052082896233, 0.05237692594528198, 0.02127164788544178, -0.016443412750959396, 0.027427654713392258, 0.013250356540083885, -0.013491547666490078, 0.0007582092075608671, -0.022447532042860985, 0.012545854784548283, -0.015608920715749264, 0.024554355069994926, 0.028348810970783234, 0.017987947911024094, -0.0037790010683238506, -0.02908025123178959, -0.005057918839156628, -0.015986474230885506, -0.02956237643957138, 0.017106004059314728, -0.03182161971926689, -0.020081542432308197, -0.011251674965023994, -0.0030355865601450205, -0.005997838918119669, -0.018203195184469223, -0.025145146995782852, -0.04507092386484146, -0.000030020359190530144, 0.01770329475402832, -0.007021466735750437, -0.0017320082988590002, 0.027395790442824364, 0.00003996431041741744, -0.014112674631178379, 0.004770854488015175, 0.007054888643324375, -0.013012094423174858, 0.05143601819872856, 0.03171829506754875, 0.01719527505338192, 0.015537732280790806, -0.013332761824131012, 0.031183524057269096, 0.024536559358239174, -0.011846804060041904, -0.03437791392207146, -0.02201933041214943, 0.050972212105989456, -0.013839175924658775, 0.0028104500379413366, -0.037202224135398865, -0.0068837362341582775, 0.02434728667140007, 0.012925480492413044, 0.004445603117346764, 0.028423167765140533, 0.0049668061546981335, -0.027408072724938393, -0.03563383221626282, 0.0029594714287668467, 0.009709023870527744, -0.00934790913015604, 0.020032545551657677, 0.016861403360962868, 0.03962041810154915, 0.005140150431543589, -0.04234189912676811, -0.006180587224662304, 0.01391656044870615, 0.03114473633468151, -0.00578033272176981, 0.021366512402892113, -0.0176771841943264, 0.026035649701952934, 0.005111278034746647, 0.028239762410521507, 0.028736555948853493, -0.04784988611936569, -0.031396981328725815, 0.018342630937695503, -0.0139946099370718, -0.008088663220405579, -0.0018320096423849463, -0.015747928991913795, 0.001976701430976391, -0.0023847343400120735, 0.022257482632994652, -0.005686678923666477, 0.02218279428780079, -0.02497597597539425, -0.0025565000250935555, -0.005788872949779034, 0.0369846411049366, -0.03061329573392868, 0.03533202409744263, -0.00774195184931159, -0.02416599728167057, 0.012483431026339531, -0.03912051022052765, -0.029764078557491302, 0.04902924597263336, 0.005706982221454382, 0.005026987288147211, 0.02038825862109661, 0.0042620692402124405, -0.037591561675071716, 0.0034460679162293673, -0.0340496189892292, -0.036721792072057724, -0.00452403724193573, -0.015719229355454445, 0.026440251618623734, 0.030697260051965714, -0.004496843554079533, 0.01626618020236492, 0.01598682813346386, 0.0073184366337955, 0.0029097488150000572, -0.7477492690086365, 0.030066369101405144, 0.0031328313052654266, -0.004349200055003166, 0.04368199035525322, -0.008635456673800945, -0.05601677671074867, 0.024543987587094307, -0.04656968265771866, -0.011320609599351883, -0.025349054485559464, 0.0067109414376318455, -0.047474149614572525, 0.008653692901134491, 0.007712442893534899, 0.006094564218074083, 0.011209271848201752, -0.03282102942466736, 0.0015833245124667883, 0.04295634105801582, -0.017420228570699692, -0.051330629736185074, 0.007200874853879213, -0.014328725636005402, 0.024645566940307617, 0.03230370208621025, 0.008925399743020535, 0.033170171082019806, -0.02852282114326954, -0.02408634126186371, -0.027763081714510918, 0.010687427595257759, -0.0031773585360497236, -0.02443942241370678, 0.029939215630292892, 0.004177737515419722, -0.010219286195933819, -0.005631244275718927, -0.03173783794045448, -0.0005680338945239782, 0.03610244765877724, -0.016897080466151237, 0.017211155965924263, -0.041691213846206665, -0.027360625565052032, -0.020976532250642776, -0.061965763568878174, 0.022648504003882408, 0.0023631667718291283, 0.014363938942551613, -0.04423583298921585, -0.021602151915431023, 0.016281133517622948, -0.022550972178578377, 0.037683047354221344, 0.01274236012250185, 0.0008687042281962931, 0.0282902792096138, -0.016898592934012413, -0.03367586061358452, 0.001132669858634472, -0.05487007647752762, -0.004686060361564159, 0.02820863015949726, -0.015906326472759247, -0.01062768418341875, 0.04573430120944977, 0.008995735086500645, -0.023919418454170227, 0.01105581782758236, -0.043032534420490265, -0.010366142727434635, 0.01796153001487255, -0.04443557187914848, 0.015719374641776085, 0.02318572998046875, -0.005171593744307756, -0.003056067507714033, -0.027560273185372353, 0.002724277088418603, -0.004858199041336775, -0.019241178408265114, 0.017159612849354744, -0.031583406031131744, -0.00048104944289661944, -0.01226782239973545, -0.015969518572092056, 0.02175130695104599, -0.015633199363946915, -0.008039673790335655, 0.03824957087635994, -0.0406411774456501, 0.00939248502254486, -0.0118247140198946, 0.032215435057878494, -0.005128536839038134, 0.0389755479991436, 0.021248281002044678, -0.005953316111117601, 0.026411905884742737, 0.00829171109944582, -0.010033681988716125, -0.031186120584607124, -0.0005433803307823837, 0.02425532229244709, -0.004503245465457439, -0.0035585493315011263, 0.00047548770089633763, 0.02646828256547451, -0.045019276440143585, -0.022070208564400673, 0.011165820062160492, 0.0017290165415033698, 0.0030893853399902582, -0.006981613580137491, 0.0019151471788063645, -0.024009976536035538, -0.014659496024250984, 0.01851828396320343, 0.0008052908233366907, -0.02208450250327587, 0.0061480882577598095, 0.07411264628171921, 0.03414122015237808, -0.0070505207404494286, -0.019908811897039413, 0.00251559354364872, -0.0509667806327343, 0.002142072655260563, -0.008915513753890991, 0.022448422387242317, -0.027920885011553764, -0.004329071845859289, 0.009802062064409256, 0.03430147096514702, 0.03756939247250557, -0.0025504359509795904, -0.002938865916803479, -0.032583191990852356, -0.05258158594369888, 0.0036354016046971083, -0.011402858421206474, 0.0011840855004265904, -0.04976615309715271, 0.018695786595344543, 0.030071523040533066, -0.020162703469395638, 0.02374311164021492, -0.0412135124206543, -0.017133556306362152, -0.027087600901722908, 0.014771700836718082, 0.02673353999853134, -0.0231942068785429, -0.05156252533197403, -0.01963503658771515, -0.0778038278222084, -0.0010507541010156274, 0.005429775454103947, 0.0062992931343615055, -0.01792973466217518, -0.001306020189076662, -0.02124251425266266, -0.004423039965331554, 0.04189065098762512, 0.004839769564568996, 0.016339119523763657, -0.020470917224884033, 0.006876708008348942, 0.0026269613299518824, 0.012569439597427845, -0.04366970434784889, -0.002217979868873954, 0.02412300370633602, -0.0005329127889126539, -0.009359048679471016, 0.006588540505617857, -0.013587110675871372, 0.03591509535908699, -0.006434877403080463, 0.003945696633309126, -0.002637960249558091, -0.03444845601916313, -0.034609485417604446, 0.010212103836238384, -0.06612911075353622, -0.042327623814344406, -0.022409889847040176, -0.004597632680088282, -0.013853783719241619, 0.0015916065312922, 0.05091878026723862, -0.011758691631257534, 0.011304561980068684, 0.00322712236084044, 0.0005023625562898815, 0.02572273090481758, 0.001733010052703321, 0.00579698896035552, -0.020647553727030754, 0.018480105325579643, -0.02337547391653061, -0.04847482219338417, -0.0025841528549790382, 0.015904409810900688, 0.004313129466027021, -0.02799024060368538, -0.011508564464747906, -0.012008113786578178, 0.03465867415070534, 0.03314545005559921, 0.00950622372329235, -0.038074295967817307, -0.022597985342144966, 0.0015586126828566194, -0.0047728256322443485, -0.017508873715996742, 0.00042344717076048255, 0.0012061403831467032, -0.0057836794294416904, -0.013391820713877678, -0.003834665985777974, 0.018519327044487, -0.021015312522649765, -0.008205804042518139, -0.0019486399833112955, -0.008749498054385185, 0.02722746692597866, -0.020992830395698547, -0.03417302668094635, 0.03479691967368126, 0.02310129627585411, -0.0018227680120617151, 0.01096457988023758, -0.03685944527387619, 0.03760441020131111, -0.024918630719184875, -0.012159746140241623, -0.0030612479895353317, 0.02679409831762314, -0.010695782490074635, -0.013021772727370262, 0.0002042454289039597, -0.02017749287188053, -0.01553698442876339, 0.007855609059333801, -0.016521738842129707, 0.02368347905576229, -0.022578492760658264, 0.02913067303597927, -0.03404005989432335, 0.0014672093093395233, -0.014969679526984692, -0.0307511854916811, 0.0024915491230785847, -0.015500008128583431, 0.0024424379225820303, 0.010526441037654877, -0.01622464507818222, 0.015948155894875526, 0.015692852437496185, -0.04659046232700348, 0.0010781687451526523, 0.0029616376850754023, 0.009265493601560593, -0.002228604629635811, 0.010582861490547657, -0.008212028071284294, -0.043198004364967346, 0.03348216414451599, 0.012713388539850712, -0.01458266843110323, 0.009087965823709965, -0.02185848169028759, 0.007986617274582386, 0.054655786603689194, 0.022571954876184464, 0.01834244467318058, 0.03767608478665352, 0.012801842764019966, 0.019280752167105675, 0.0201407577842474, -0.007765003014355898, -0.019300904124975204, -0.005782906897366047, 0.014250732958316803, 0.023022571578621864, -0.020354926586151123, 0.0009598294855095446, 0.005769782699644566, 0.010531299747526646, -0.04155144467949867, 0.008494674228131771, 0.014688177965581417, -0.0014148635091260076, 0.005892347078770399, -0.013664853759109974, -0.010053013451397419, 0.05519329011440277, -0.014706358313560486, 0.03079608455300331, -0.015111851505935192, -0.01365540362894535, -0.014989259652793407, 0.00889661442488432, -0.003509816015139222, -0.009107711724936962, -0.050094012171030045, -0.0006813021609559655, 0.0001382374030072242, 0.01980806142091751, 0.0199434757232666, 0.015885794535279274, 0.026633048430085182, 0.022088035941123962, 0.019002765417099, -0.005245826672762632, 0.03467075899243355, 0.026639262214303017, -0.013675304129719734, -0.015687763690948486, 0.02194168232381344, -0.01864764653146267, 0.03603789955377579, -0.008271733298897743, 0.02794595994055271, -0.019359063357114792, 0.021179985255002975, 0.004383689258247614, -0.029789309948682785, -0.0476619116961956, -0.005558670032769442, -0.0017322837375104427, 0.01643710769712925, 0.01503026019781828, -0.03840186074376106, 0.016811173409223557, -0.01810898818075657, 0.023209379985928535, 0.023576103150844574, 0.013429642654955387, 0.012356176972389221, -0.008799384348094463, 0.013754679821431637, 0.0007504509994760156, 0.004974053706973791, 0.0002968413464259356, 0.04527924954891205, -0.02325723133981228, 0.0045053670182824135, -0.02442808263003826, -0.02387036569416523, -0.002049994422122836, 0.012590066529810429, 0.015721678733825684, 0.025413107126951218, 0.0032479746732860804, 0.004591826349496841, 0.025570597499608994, -0.003672253806143999, -0.03162253275513649, 0.00120158854406327, 0.019016973674297333, 0.00451275147497654, -0.01723303645849228, -0.021477757021784782, 0.023404931649565697, 0.0005899532698094845, 0.027200229465961456, 0.015192645601928234, 0.023809146136045456, 0.011305280961096287, 0.008147007785737514, -0.009137759916484356, -0.0018497975543141365, 0.009502599947154522, 0.021492760628461838, 0.013987765647470951, -0.04095491021871567, -0.01659511774778366, -0.029582194983959198, 0.032046593725681305, -0.011387096717953682, -0.0002147044870071113, -0.004866061732172966, -0.015931596979498863, 0.009334538131952286, 0.0220544021576643, -0.02500968985259533, -0.0009739603847265244, -0.01044575497508049, -0.02366998977959156, 0.006056598853319883, 0.036946091800928116, -0.033585842698812485, 0.020936058834195137, 0.0004552429891191423, 0.020998787134885788, -0.049441635608673096, 0.0013485078234225512, -0.0014883209951221943, 0.007455919403582811, 0.006040951702743769, -0.012232314795255661, 0.021487563848495483, -0.03652874752879143, -0.02005011774599552, 0.00413591880351305, 0.023024730384349823, -0.04633448272943497, 0.04000425338745117, -0.014416537247598171, -0.0321228988468647, 0.0008744622464291751, -0.010635579004883766, 0.003071705810725689, -0.04538571089506149, -0.00048348880955018103, 0.020201079547405243, -0.00036133744288235903, 0.0075456020422279835, -0.007826574146747589, 0.002853550249710679, -0.00033835170324891806, -0.015182426199316978, -0.02158653363585472, 0.01480741798877716, -0.05175056681036949, 0.022187603637576103, -0.00474554393440485, 0.031637292355298996, 0.022609764710068703, 0.003266296349465847, -0.019058873876929283, 0.039498135447502136, -0.053400516510009766, -0.0018689355347305536, 0.0026795524172484875, -0.004813570994883776, -0.0047303494065999985, 0.02714208886027336, -0.005399910733103752, 0.002897907281294465, -0.021323930472135544, -0.015424178913235664, -0.14210127294063568, -0.010669015347957611, -0.018874138593673706, -0.010229505598545074, -0.00999495666474104, -0.0019561732187867165, 0.01347599271684885, 0.01040294487029314, 0.01631312631070614, -0.010615822859108448, -0.0043337647803127766, 0.006289765238761902, -0.000003368563056938001, -0.003938551060855389, -0.029761115089058876, -0.01537518110126257, -0.021730564534664154, 0.03050997294485569, -0.0005367266712710261, 0.011692790314555168, 0.02000928670167923, -0.010559172369539738, -0.02389933168888092, -0.021628927439451218, 0.017159076407551765, -0.021062197163701057, 0.006191212218254805, -0.006050442811101675, -0.0008544119773432612, 0.004024461377412081, 0.03661930561065674, 0.013986744917929173, 0.010530952364206314, 0.030958401039242744, 0.0006519719026982784, -0.014782638289034367, 0.0011315190931782126, 0.03825347498059273, 0.008420203812420368, 0.02055240049958229, 0.02830575779080391, 0.012466199696063995, 0.006935322657227516, 0.0023291257675737143, -0.0084779541939497, 0.007148627191781998, -0.0012115596327930689, 0.0032577032689005136, 0.010852259583771229, 0.017757171764969826, -0.014743790030479431, -0.008396429009735584, -0.022152811288833618, -0.0041259899735450745, 0.016153421252965927, 0.027643155306577682, -0.06477638334035873, 0.025404900312423706, 0.028332114219665527, 0.024611786007881165, 0.0442085936665535, 0.0031536452006548643, 0.039984218776226044, 0.023009469732642174, 0.015121884644031525, 0.0011801911750808358, -0.0014174606185406446, 0.023388005793094635, 0.041588228195905685, 0.034299805760383606, 0.008832985535264015, 0.0018073482206091285, 0.04786281660199165, 0.028760869055986404, -0.007690206170082092, -0.001964699476957321, -0.019900603219866753, -0.002745124278590083, -0.016888417303562164, -0.01703062653541565, 0.004515166860073805, -0.039963725954294205, -0.008266943506896496, -0.0032896986231207848, 0.013357297517359257, 0.0077507877722382545, 0.000684991420712322, -0.006799888797104359, -0.03088069148361683, 0.005764686036854982, -0.013900666497647762, 0.01505045685917139, 0.005416852422058582, -0.04387001693248749, 0.01933390088379383, 0.06772784888744354, 0.02431148663163185, 0.018945690244436264, 0.021201465278863907, -0.009129882790148258, -0.011434141546487808, 0.0034193038009107113, 0.023954926058650017, 0.030836747959256172, 0.01036918256431818, -0.011290859431028366, -0.040145277976989746, 0.015589701943099499, 0.005026233848184347, -0.010938995517790318, -0.07454532384872437, -0.000419981632148847, -0.004731389693915844, 0.02676042541861534, 0.005047488026320934, -0.017854956910014153, 0.014446684159338474 ]
8a928ed1a44855a651b9670429234df930921f0a
125
py
Python
api/services/http.py
takos22/API-1
261ecd34648d610169caf27b3712256f757b100d
[ "MIT" ]
null
null
null
api/services/http.py
takos22/API-1
261ecd34648d610169caf27b3712256f757b100d
[ "MIT" ]
null
null
null
api/services/http.py
takos22/API-1
261ecd34648d610169caf27b3712256f757b100d
[ "MIT" ]
null
null
null
from aiohttp import ClientSession from typing import Optional session: Optional[ClientSession] = None __all__ = (session,)
17.857143
39
0.8
1
0.6636
[ 0.001523888553492725, 0.025382839143276215, 0.009078274480998516, 0.0013466232921928167, 0.005175439175218344, -0.0029999995604157448, -0.011735450476408005, 0.005358062218874693, -0.006175852846354246, -0.0020312517881393433, 0.0031231981702148914, 0.005895331036299467, 0.010241677053272724, -0.01699002832174301, 0.0010493184672668576, 0.01835928112268448, -0.05717994645237923, 0.003545468905940652, -0.0068807839415967464, 0.0021835153456777334, -0.007755436934530735, 0.008370752446353436, 0.009818700142204762, 0.007857966236770153, 0.007306610234081745, 0.002478797221556306, 0.01033131405711174, 0.006220746785402298, -0.009002186357975006, -0.00655971746891737, 0.0009079584269784391, -0.00025289400946348906, -0.0037072382401674986, -0.010338499210774899, 0.00835332553833723, -0.002120592864230275, 0.0014902163529768586, -0.01805845834314823, 0.013132203370332718, -0.006682114209979773, -0.006799818482249975, -0.018721848726272583, 0.0017281451728194952, 0.004249319899827242, -0.013344273902475834, 0.0038940387312322855, -0.0012343433918431401, 0.003924067132174969, -0.01123064011335373, 0.004708384163677692, -0.010061955079436302, 0.003968421835452318, 0.012638688087463379, -0.0007510957075282931, -0.004598879721015692, -0.007107485085725784, 0.009874165989458561, 0.00030612744740210474, -0.014395580627024174, -0.0016081351786851883, -0.005554105155169964, -0.002079905942082405, 0.0060997530817985535, 0.006783053278923035, -0.019800633192062378, -0.006310679949820042, -0.002134486334398389, 0.0031343575101345778, -0.00016554188914597034, 0.004898836370557547, 0.0007174063357524574, -0.0038291076198220253, 0.00802814681082964, 0.0040540993213653564, 0.005538140423595905, -0.004245260264724493, -0.0031657363288104534, 0.004134041257202625, 0.009848843328654766, 0.0024592257104814053, 0.005646776407957077, -0.010962423868477345, 0.007239221129566431, 0.014736694283783436, 0.01650005206465721, 0.010523933917284012, 0.018405959010124207, -0.012371961958706379, 0.04354308173060417, 0.00739109143614769, -0.008229403756558895, -0.001093451981432736, -0.009687039069831371, -0.0018704758258536458, -0.0006887431372888386, -0.03166797384619713, 0.001170553732663393, -0.006981781218200922, 0.004378905054181814, 0.004985217936336994, -0.0017953296191990376, 0.006409655790776014, -0.0013344225008040667, -0.0032970195170491934, -0.00967929232865572, 0.015192274004220963, -0.008720440790057182, -0.001823939266614616, 0.007788211107254028, 0.0033688866533339024, -0.011665625497698784, -0.001744980807416141, 0.006806997582316399, -0.01212588045746088, 0.006051335018128157, 0.0008732955902814865, -0.005852441769093275, 0.058981265872716904, 0.0016981250373646617, 0.0024009167682379484, -0.004030907526612282, -0.007467430550605059, 0.0001531775778857991, 0.007612548302859068, 0.008236854337155819, -0.005472732707858086, 0.012305759824812412, 0.0055847628973424435, 0.003708514152094722, 0.008212766610085964, 0.0017150872154161334, 0.009126397781074047, -0.0041869934648275375, -0.0017178007401525974, 0.0008281138725578785, -0.008751319721341133, 0.00763844745233655, -0.0012157291639596224, -0.004265415016561747, -0.00322545925155282, 0.0005991364014334977, -0.012261126190423965, 0.00004717697447631508, -0.005564265418797731, 0.0008311645942740142, -0.014643496833741665, -0.004668358713388443, -0.004030185751616955, -0.0050277975387871265, 0.0027628238312900066, 0.007347229402512312, 0.0020570955239236355, 0.002949164714664221, -0.006732978858053684, -0.008092494681477547, -0.00409635528922081, -0.006233665626496077, 0.0017352834111079574, 0.010514785535633564, 0.0010000400943681598, -0.006721289362758398, -0.0006829193443991244, 0.004611562471836805, 0.0035601062700152397, 0.0005950405029579997, -0.000639537232927978, -0.007529214024543762, 0.007107475306838751, 0.0002664392231963575, 0.0018719373038038611, 0.010664454661309719, -0.0033787055872380733, -0.0018065194599330425, -0.00037657885695807636, 0.0018030951032415032, -0.00018775640637613833, 0.005089085549116135, 0.009366607293486595, -0.008535410277545452, -0.007544698193669319, 0.003634713590145111, 0.0034237306099385023, 0.012258748523890972, 0.009640167467296124, -0.0030220544431358576, 0.0023016363848000765, -0.0003017789276782423, -0.0004568881122395396, 0.0037630898877978325, -0.005672777537256479, 0.008481699973344803, 0.004407822620123625, -0.014039848931133747, -0.007559382822364569, -0.00026532605988904834, -0.009303351864218712, 0.0002964516752399504, 0.014627153985202312, 0.010435616597533226, 0.0013693398796021938, 0.0023304575588554144, -0.009008586406707764, -0.0006777258822694421, 0.004898299928754568, 0.002283100737258792, -0.012955360114574432, -0.952997624874115, 0.0030679956544190645, 0.001331703388132155, 0.0005684689385816455, 0.00024839004618115723, -0.0009827004978433251, 0.0011505589354783297, 0.0015152315609157085, 0.01659872941672802, -0.008587458170950413, -0.008304872550070286, -0.012291815131902695, -0.010108273476362228, 0.002136028604581952, -0.007502000778913498, -0.004414445720613003, -0.0027455103117972612, -0.009082246571779251, -0.002365209860727191, -0.0035399063490331173, -0.0030963290482759476, 0.014098896645009518, -0.0006052783573977649, 0.0036825574934482574, 0.0027198591269552708, 0.0026530330069363117, -0.0043723550625145435, -0.0010386405047029257, 0.0010175921488553286, -0.002241085981950164, -0.003979720175266266, -0.017735350877046585, -0.005214123521000147, -0.003944295458495617, 0.015087899751961231, -0.000999542186036706, 0.007253305520862341, 0.00045018939999863505, 0.001406839699484408, -0.008869586512446404, 0.006710315588861704, 0.0005925812874920666, 0.0019028456881642342, -0.030994120985269547, 0.00303612370043993, -0.002469149185344577, -0.008018428459763527, 0.008056319318711758, 0.0018162117339670658, -0.00015600844926666468, -0.0021063254680484533, -0.004020961932837963, 0.01064151432365179, -0.009223303757607937, 0.007054760120809078, -0.0066615561954677105, -0.004469714127480984, -0.0019068052060902119, -0.009697441942989826, 0.003747443435713649, 0.0031021779868751764, -0.004398806486278772, -0.004317323211580515, -0.003515647491440177, 0.0010814896086230874, 0.0009448823402635753, -0.0012472711969166994, -0.017960235476493835, -0.004143350291997194, -0.001641906681470573, 0.00504445331171155, -0.001069326070137322, -0.0008718247408978641, 0.004625367932021618, -0.009011571295559406, 0.007078884169459343, 0.003907918930053711, 0.005909213330596685, -0.011180886067450047, 0.0010154051706194878, -0.007384036667644978, -0.010886208154261112, 0.006676470395177603, -0.005069474224001169, -0.003415771061554551, 0.003672192106023431, 0.003693386446684599, 0.007602838799357414, -0.00427652383223176, 0.0013286520261317492, 0.010277856141328812, -0.004494044464081526, -0.009837349876761436, 0.008989647962152958, 0.00412635738030076, -0.0013444365467876196, -0.0007515983306802809, -0.000027005313313566148, 0.008411481976509094, 0.007368340156972408, 0.0024510726798325777, 0.004405610263347626, -0.00020567176397889853, 0.012607048265635967, -0.0012336865765973926, 0.004912576638162136, -0.0003241059312131256, -0.0030701053328812122, -0.006062806583940983, 0.0009114974527619779, -0.003858227515593171, 0.00007126160198822618, -0.014727704226970673, -0.010769001208245754, -0.0036578138824552298, 0.0005557913100346923, 0.0017729212995618582, -0.002003537956625223, -0.0008504600264132023, 0.0013062908546999097, 0.011001072824001312, 0.002924747997894883, -0.0040024323388934135, 0.003306824713945389, 0.006524492055177689, -0.010394079610705376, 0.013117250055074692, -0.012976526282727718, 0.006203115452080965, -0.0014338180189952254, -0.016999099403619766, 0.008854182437062263, 0.009657764807343483, -0.007894584909081459, 0.003939471207559109, 0.003629774320870638, 0.007016494404524565, 0.001065885298885405, -0.006642969325184822, -0.0027908403426408768, -0.019134249538183212, -0.0006343196146190166, 0.019391868263483047, 0.005081083159893751, 0.010679038241505623, 0.012717180885374546, -0.003066580044105649, 0.003582974197342992, 0.006929924711585045, 0.000932713330257684, 0.015423787757754326, -0.010475805029273033, -0.0009369184845127165, 0.0026964538265019655, -0.0042883409187197685, 0.003463027300313115, 0.0030202644411474466, 0.0028471893165260553, -0.0038233452942222357, 0.0007417177548632026, -0.005980098154395819, -0.004793565254658461, -0.014800583943724632, -0.0009338155505247414, 0.006796636618673801, -0.004264279268682003, 0.0036101762671023607, -0.012407957576215267, 0.0061913360841572285, 0.0048166560009121895, -0.0011802222579717636, 0.0003678393259178847, 0.002125474624335766, 0.006754352245479822, 0.012156185694038868, -0.007326766848564148, 0.005655420478433371, -0.0014812356093898416, -0.0022177251521497965, 0.005260087549686432, 0.006353356875479221, -0.00922603253275156, -0.008312239311635494, 0.004212504718452692, 0.0028893759008497, 0.0022550642024725676, -0.0063872202299535275, -0.006721286568790674, -0.0021823907736688852, 0.005317583214491606, -0.007840245962142944, 0.004031212534755468, 0.004380800295621157, 0.003277827752754092, -0.00939895212650299, 0.00026406938559375703, -0.0019786646589636803, -0.009965110570192337, 0.011276233941316605, -0.004103632178157568, 0.0045290254056453705, 0.014866601675748825, 0.0042212773114442825, -0.013045021332800388, 0.007111379876732826, 0.0072165061719715595, -0.006528608966618776, 0.005156757775694132, 0.004664287902414799, -0.0061319200322031975, -0.024122580885887146, 0.0007667752215638757, -0.01738516055047512, 0.008873608894646168, -0.0048651425167918205, 0.0010036865714937449, -0.005791401956230402, 0.01034481730312109, 0.0010672115022316575, -0.013018540106713772, -0.004357462748885155, -0.009054223075509071, 0.007939943112432957, -0.002412237925454974, -0.0013101804070174694, -0.0030417589005082846, -0.0008748803520575166, -0.005497219506651163, -0.0017946772277355194, -0.0009062327444553375, 0.0030483799055218697, 0.0030046964529901743, -0.0035962180700153112, 0.002082307357341051, -0.006052631419152021, -0.0003032006206922233, 0.0036476266104727983, -0.012451819144189358, 0.003657400840893388, 0.008413995616137981, -0.0038124588318169117, -0.006463763769716024, 0.00024281733203679323, 0.0003611869178712368, -0.0062881517224013805, -0.011785210110247135, -0.002582607790827751, -0.006436007097363472, -0.004336769692599773, -0.01050869282335043, -0.00541008822619915, -0.007432214915752411, 0.005078362300992012, -0.008359408006072044, 0.008631179109215736, 0.0044010598212480545, -0.0038908293936401606, 0.006429910194128752, -0.00042133196257054806, 0.004727601073682308, 0.005352032836526632, 0.006678609177470207, -0.002864115871489048, -0.007876238785684109, -0.011651517823338509, 0.011183049529790878, -0.011069520376622677, -0.0019369780784472823, 0.013036677613854408, 0.0033041348215192556, 0.009110814891755581, -0.0005615231348201632, -0.0011841735104098916, 0.006126574240624905, 0.01022899430245161, -0.01511516235768795, 0.001837045419961214, -0.0033373795449733734, -0.00026563202845864, 0.006598830688744783, -0.004515022970736027, 0.006455624010413885, 0.007040854077786207, 0.003793903859332204, -0.008132918737828732, -0.004220528528094292, 0.0012205949751660228, 0.004824185743927956, -0.011609218083322048, -0.0007612352492287755, -0.00601550517603755, -0.002920909086242318, -0.005365265998989344, -0.0016317081172019243, -0.0008311484707519412, 0.006574976723641157, -0.005599214229732752, 0.0062959264032542706, 0.0005726994131691754, -0.001067162025719881, 0.016111427918076515, -0.005146775394678116, -0.006749778985977173, 0.004183592274785042, 0.00249049486592412, -0.0028087070677429438, -0.0074286023154854774, -0.0021374558564275503, 0.001915503409691155, 0.002375463955104351, -0.0012500787852331996, -0.011295227333903313, -0.002816963940858841, 0.0019249998731538653, -0.005465433932840824, 0.0007174204802140594, 0.007116781547665596, -0.0005266020889393985, 0.003999622073024511, 0.00006929145456524566, -0.004586886148899794, -0.016281429678201675, 0.05497963726520538, -0.0030145130585879087, 0.0024801576510071754, 0.006887621711939573, -0.010475010611116886, -0.001955670304596424, -0.005161003675311804, 0.00487649766728282, -0.006386458873748779, -0.004125522915273905, 0.00833963230252266, -0.0050062076188623905, 0.0022110992576926947, 0.00018516986165195704, -0.004799197427928448, 0.01591244339942932, -0.005169604904949665, -0.01811566762626171, -0.016845393925905228, 0.0061980378814041615, -0.00588902598246932, -0.006525650154799223, 0.007030882406979799, -0.0025506382808089256, -0.0032685238402336836, 0.0019009013194590807, 0.0075452737510204315, -0.0005090956692583859, -0.0010830378159880638, -0.004038168117403984, -0.0014336103340610862, 0.001296790549531579, 0.0027764770202338696, 0.008601403795182705, 0.008737798780202866, -0.00381358340382576, 0.005117928609251976, -0.0020983905997127295, -0.0005154743557795882, 0.00042379903607070446, 0.003673671977594495, 0.00553312711417675, -0.00014062463014852256, -0.004267111886292696, 0.005454381927847862, 0.0062425569631159306, -0.0011942976852878928, 0.012025970965623856, 0.0011374667519703507, -0.0028410139493644238, 0.008309824392199516, 0.009876018390059471, 0.0008982457802630961, 0.0041191247291862965, -0.0035624399315565825, 0.003026749473065138, 0.00013704024604521692, -0.005568618420511484, -0.013205683790147305, -0.0010822433978319168, 0.005653100088238716, 0.011843724176287651, 0.00026182510191574693, 0.002888893010094762, -0.002600759267807007, -0.0030496453400701284, -0.00848410464823246, -0.004536088556051254, -0.0022445302456617355, -0.0013074004091322422, 0.003970598801970482, 0.0716807097196579, -0.006828764919191599, -0.0018172890413552523, -0.008856594562530518, -0.001071196049451828, -0.003076622262597084, -0.001226653577759862, -0.0008901943219825625, -0.0011923842830583453, 0.0037518583703786135, 0.005550341680645943, -0.009088222868740559, -0.009637224487960339, 0.004036980215460062, 0.000410545093473047, -0.0016381075838580728, 0.0007174333441071212, 0.008039398118853569, -0.00764318834990263, 0.004497574642300606, -0.010359506122767925, -0.003808168461546302, -0.0030190676916390657, -0.007428192999213934, -0.004184503573924303, -0.003851216286420822, 0.0029920884408056736, 0.0028373661916702986, 0.00570997828617692, -0.004179725423455238, 0.005236386321485043, -0.00013770170335192233, 0.0021081387531012297, -0.0020586063619703054, -0.0005469038151204586, -0.004678784869611263, 0.006242964416742325, 0.00198364001698792, -0.00947850663214922, -0.005485168192535639, -0.0027243057265877724, -0.00397605961188674, -0.005037721246480942, 0.009300239384174347, 0.0009797586826607585, 0.00719921151176095, -0.003300541313365102, 0.0026878530625253916, -0.00369309657253325, -0.0008384182583540678, -0.011402597650885582, 0.0013546240516006947, -0.18761718273162842, 0.010165915824472904, 0.0028695128858089447, -0.004722665064036846, -0.0031849669758230448, -0.016165250912308693, -0.008540107868611813, 0.005710838362574577, 0.0104411281645298, -0.0001677029940765351, -0.0008934627403505147, -0.004875956103205681, 0.007421538233757019, 0.0037102224305272102, -0.002820075023919344, -0.003440357046201825, 0.0020559881813824177, -0.0023642133455723524, 0.0016567104030400515, 0.006262165028601885, 0.0038568226154893637, 0.008855929598212242, 0.0028121578507125378, -0.00011474380153231323, -0.001842057565227151, -0.004621110390871763, 0.0031342078000307083, -0.0014670398086309433, 0.007084345910698175, -0.009411544539034367, -0.0017721230397000909, -0.006372008938342333, -0.005681047216057777, 0.0024479904677718878, 0.005046176258474588, -0.003353991312906146, 0.005584207363426685, 0.0022040705662220716, -0.006240233778953552, 0.006648197304457426, -0.010202965699136257, 0.033107925206422806, 0.007225255481898785, 0.009729119017720222, -0.0009997028391808271, -0.0038299751468002796, -0.002170058898627758, 0.009938698261976242, 0.004939685575664043, 0.012352165766060352, -0.011897548101842403, -0.00788230262696743, 0.002528377342969179, 0.01876489445567131, -0.006403770763427019, -0.008588834665715694, -0.007295266725122929, -0.00669892830774188, 0.004738207906484604, 0.009361977688968182, 0.012086710892617702, -0.0064728762954473495, 0.008926170878112316, -0.004321766085922718, -0.02356363646686077, 0.005257933400571346, -0.0033291219733655453, -0.009349445812404156, 0.0033221268095076084, 0.005874766036868095, 0.013338755816221237, -0.0003853222297038883, 0.007337995804846287, -0.001549363718368113, 0.00432027131319046, -0.0026372550055384636, 0.008751079440116882, -0.004672056529670954, 0.0041216579265892506, -0.008489688858389854, 0.011463361792266369, -0.008254829794168472, -0.0025493637658655643, 0.0017436189809814095, -0.0038311113603413105, 0.010286375880241394, 0.005220761988312006, -0.0027616810984909534, 0.002114781877025962, -0.01336132176220417, -0.0021842538844794035, 0.00015991371765267104, 0.0025395024567842484, -0.01034548506140709, 0.0032063026446849108, -0.003165117697790265, 0.0065411897376179695, 0.00708736153319478, -0.007614045403897762, 0.005157263483852148, 0.005815824959427118, -0.010313805192708969, 0.002203252399340272, -0.004850535653531551, 0.0016538923373445868, 0.0017971827182918787, -0.006807344499975443, -0.008481938391923904, 0.004661956802010536, -0.007464095950126648, -0.006136361509561539, 0.004496365785598755, -0.009087194688618183, -0.005623876582831144, 0.0024715617764741182, -0.011702488176524639, 0.001038699527271092 ]
8a92d260f5ba3c3243955569573ecad3cecaf8e9
2,079
py
Python
bcloud-snap/bcloud-3.9.1/bcloud/hasher.py
jiaxiaolei/my_snap_demo
0444077c763e029eb67af7242537cebb3c3d6aa4
[ "Apache-2.0" ]
null
null
null
bcloud-snap/bcloud-3.9.1/bcloud/hasher.py
jiaxiaolei/my_snap_demo
0444077c763e029eb67af7242537cebb3c3d6aa4
[ "Apache-2.0" ]
4
2019-11-20T02:45:19.000Z
2019-12-03T03:14:15.000Z
bcloud-snap/bcloud-3.9.1/bcloud/hasher.py
jiaxiaolei/my_snap_demo
0444077c763e029eb67af7242537cebb3c3d6aa4
[ "Apache-2.0" ]
null
null
null
# Copyright (C) 2014-2015 LiuLang <gsushzhsosgsu@gmail.com> # Use of this source code is governed by GPLv3 license that can be found # in http://www.gnu.org/licenses/gpl-3.0.html import hashlib import os import zlib CHUNK = 2 ** 20 def crc(path): _crc = 0 fh = open(path, 'rb') while True: chunk = fh.read(CHUNK) if not chunk: break _crc = zlib.crc32(chunk, _crc) fh.close() return '%X' % (_crc & 0xFFFFFFFF) def md5(path, start=0, stop=-1): _md5 = hashlib.md5() fh = open(path, 'rb') if start > 0: fh.seek(start) if stop == -1: stop = os.path.getsize(path) pos = start while pos < stop: size = min(CHUNK, stop - pos) chunk = fh.read(size) if not chunk: break pos += len(chunk) _md5.update(chunk) fh.close() return _md5.hexdigest() def sha1(path): _sha1 = hashlib.sha1() fh = open(path, 'rb') while True: chunk = fh.read(CHUNK) if not chunk: break _sha1.update(chunk) fh.close() return _sha1.hexdigest() def sha224(path): _sha224 = hashlib.sha224() fh = open(path, 'rb') while True: chunk = fh.read(CHUNK) if not chunk: break _sha224.update(chunk) fh.close() return _sha224.hexdigest() def sha256(path): _sha256 = hashlib.sha256() fh = open(path, 'rb') while True: chunk = fh.read(CHUNK) if not chunk: break _sha256.update(chunk) fh.close() return _sha256.hexdigest() def sha384(path): _sha384 = hashlib.sha384() fh = open(path, 'rb') while True: chunk = fh.read(CHUNK) if not chunk: break _sha384.update(chunk) fh.close() return _sha384.hexdigest() def sha512(path): _sha512 = hashlib.sha512() fh = open(path, 'rb') while True: chunk = fh.read(CHUNK) if not chunk: break _sha512.update(chunk) fh.close() return _sha512.hexdigest()
21.65625
72
0.556037
1
1.4841
[ 0.0015734868356958032, 0.022298691794276237, 0.0077940174378454685, 0.0027554454281926155, 0.0037809531204402447, 0.0009849040070548654, -0.009643858298659325, -0.0005515902885235846, -0.0065388865768909454, 0.003938465379178524, 0.0028484861832112074, 0.005902300123125315, 0.005245829466730356, -0.015084914863109589, 0.0014496258227154613, 0.015387458726763725, -0.049555134028196335, -0.00009024221071740612, -0.0035035167820751667, 0.0020638396963477135, -0.006819653790444136, 0.00890320260077715, 0.007653553504496813, 0.0051769171841442585, 0.0071136183105409145, -0.0019256453961133957, 0.010868682526051998, 0.0007397588924504817, -0.005331911612302065, -0.006292729172855616, -0.0008217354188673198, -0.0012962935725226998, -0.005576586816459894, -0.007461821660399437, 0.006238101050257683, -0.004665409214794636, 0.0002286271337652579, -0.020800629630684853, 0.01264249812811613, -0.0033445823937654495, -0.007071144413203001, -0.012997087091207504, -0.00008730479021323845, 0.00047870492562651634, -0.009356447495520115, 0.00013446490629576147, -0.005494548007845879, 0.003317686030641198, -0.01168952789157629, 0.0062943268567323685, -0.007634283043444157, 0.00709858862683177, 0.013568708673119545, 0.0036151453386992216, -0.005584617145359516, -0.006744685582816601, 0.012510730884969234, -0.0009516610880382359, -0.010325165465474129, -0.0002816082560457289, -0.0013799394946545362, -0.00401841476559639, 0.003971772734075785, 0.0026018633507192135, -0.013059498742222786, -0.007635872345417738, -0.004971724469214678, 0.0016105620888993144, -0.0012473742244765162, 0.007839889265596867, -0.00014105360605753958, -0.001119953696615994, 0.00818046648055315, 0.0057256571017205715, 0.005940708331763744, -0.004515746608376503, -0.0017430644948035479, -0.0021265861578285694, 0.009679390117526054, 0.0037166683468967676, 0.003913917578756809, -0.006118621677160263, 0.006603526417165995, 0.007099565118551254, 0.0154885184019804, 0.009388191625475883, 0.020020056515932083, -0.010129477828741074, 0.04955626279115677, 0.009349950589239597, -0.007462639827281237, 0.003588211489841342, -0.009921039454638958, -0.0019901369232684374, -0.00783609040081501, -0.027849823236465454, 0.0012891680235043168, -0.003216923912987113, 0.002394316717982292, 0.002976324176415801, -0.0006994662107899785, 0.007189085707068443, -0.001173368189483881, -0.002638639183714986, -0.00873568095266819, 0.008182748220860958, -0.008350623771548271, -0.0038300559390336275, 0.005748522002249956, 0.0024120963644236326, -0.01115340180695057, -0.0026430394500494003, 0.0005796077311970294, -0.013106380589306355, 0.0030133763793855906, 0.004064674023538828, -0.0038045751862227917, 0.05316603183746338, -0.0004801429167855531, 0.0042448085732758045, -0.004896726459264755, 0.0011277968296781182, 0.002474328735843301, 0.0031532207503914833, 0.009258835576474667, -0.002014963887631893, 0.011195319704711437, 0.008532137610018253, 0.0022796967532485723, 0.009580596350133419, -0.003377105575054884, 0.006558856461197138, -0.003065325552597642, -0.00401639100164175, 0.0014471523463726044, -0.008089611306786537, 0.00643155537545681, -0.002154933987185359, -0.008712784387171268, 0.0015671506989747286, -0.00010643215500749648, -0.007388494908809662, 0.00030487231560982764, -0.0044504133984446526, 0.006724936421960592, -0.010006305761635303, -0.0031558454502373934, -0.004068576265126467, -0.004899718798696995, 0.001538084470666945, 0.010636062361299992, 0.003944219555705786, 0.002798784291371703, -0.004240174312144518, -0.009091794490814209, 0.0011304393410682678, -0.004125795792788267, -0.0002997184346895665, 0.005585191305726767, 0.0033527195919305086, -0.01094532385468483, -0.0010060823988169432, 0.0032174347434192896, 0.0030742876697331667, -0.00020580443379003555, 0.0026480527594685555, -0.007103790063410997, 0.005505766719579697, -0.0008137939730659127, 0.0058878143317997456, 0.011956007219851017, -0.005225141998380423, -0.0005478150560520589, 0.0012174401199445128, 0.002605890389531851, -0.00004582186011248268, 0.005897819995880127, 0.010357017628848553, -0.002693478250876069, -0.0029230935033410788, 0.004421624355018139, 0.005987914279103279, 0.008754434064030647, 0.0050017694011330605, -0.00397348590195179, -0.00016669972683303058, -0.006146209314465523, -0.003168820170685649, 0.008031284436583519, -0.0028454416897147894, 0.00517609529197216, 0.003970411140471697, -0.011912201531231403, -0.00853023212403059, 0.0010722934966906905, -0.00496721314266324, 0.0014222357422113419, 0.0140540124848485, 0.01278664730489254, -0.005999793764203787, 0.002136555267497897, -0.009179487824440002, -0.0014498980017378926, 0.006765278056263924, 0.0008220993913710117, -0.012380662374198437, -0.9601950645446777, 0.007927174679934978, 0.003319725627079606, -0.002080925740301609, 0.0064614019356667995, 0.004681998398154974, 0.0018502662423998117, 0.005145976785570383, 0.014802445657551289, -0.007182906847447157, -0.005919334013015032, -0.011593013070523739, -0.010084440931677818, -0.0013879878679290414, -0.006660482846200466, -0.005232738796621561, -0.005737075582146645, -0.007451162673532963, -0.0031146120745688677, -0.0015801556874066591, -0.0034659886732697487, 0.00738344993442297, -0.0006163623766042292, 0.0059524173848330975, 0.00281539442948997, 0.004804322961717844, -0.005419022869318724, -0.002504957839846611, -0.0008450153982266784, -0.0031993002630770206, -0.0062832958064973354, -0.014367600902915001, -0.003020311938598752, -0.0011346706887707114, 0.010510187596082687, 0.0028609635774046183, 0.008327847346663475, -0.0007685283781029284, 0.002164549892768264, -0.006195222958922386, 0.00607501994818449, 0.00004318790524848737, 0.002072697039693594, -0.030355507507920265, -0.0012207624968141317, 0.0005348725826479495, -0.01044508907943964, 0.00838559027761221, 0.002028925810009241, 0.0006400959682650864, -0.001828733249567449, -0.0056862253695726395, 0.009480729699134827, -0.007702342700213194, 0.0038632946088910103, -0.0045851487666368484, -0.010291784070432186, -0.003058882663026452, -0.00726040406152606, -0.0000025826332148426445, 0.0047443020157516, -0.003768764901906252, -0.005072158295661211, -0.004329387564212084, 0.0018572609405964613, 0.0018097904976457357, 0.0024293814785778522, -0.019133495166897774, -0.0074218567460775375, 0.0010208325693383813, -0.001129476586356759, -0.0033626030199229717, -0.003785272827371955, 0.005897336173802614, -0.008690325543284416, 0.006391248665750027, 0.002621728926897049, -0.0016571993473917246, -0.011736360378563404, 0.00025377082056365907, -0.007814738899469376, -0.0059259263798594475, -0.00008164249447872862, -0.004388344474136829, -0.006190554238855839, -0.000010862126146093942, 0.0000394663838960696, 0.006932221353054047, -0.005207095295190811, 0.003110423916950822, 0.011565674096345901, -0.0029672798700630665, -0.007621614262461662, 0.005324410740286112, 0.0075800116173923016, 0.0005713418358936906, -0.003399094333872199, 0.004296971019357443, 0.00781452190130949, 0.009156244806945324, 0.002670825691893697, 0.003965430427342653, -0.0001781048340490088, 0.008899334818124771, -0.001458779675886035, 0.0005538050318136811, -0.004180372692644596, -0.0008288910612463951, -0.0032952362671494484, 0.0017771671991795301, -0.00654203025624156, -0.0034871024545282125, -0.014940591529011726, -0.008381065912544727, -0.002065158449113369, -0.0012484407052397728, 0.0033778769429773092, -0.005757943727076054, -0.0009556375443935394, 0.0013103935634717345, 0.006899354979395866, -0.0015892540104687214, -0.001951568410731852, -0.00006893854879308492, 0.0014943062560632825, -0.006172769237309694, 0.014041404239833355, -0.011238213628530502, 0.006538854446262121, 0.0006706943968310952, -0.01514326874166727, 0.005883228965103626, 0.010303035378456116, -0.007807594258338213, 0.0037948056124150753, 0.005783745087683201, 0.0025745134335011244, -0.0016529046697542071, -0.005943711847066879, -0.00317280157469213, -0.01578497514128685, 0.0018423532601445913, 0.02034546621143818, -0.000042026083974633366, 0.009722847491502762, 0.01047808863222599, -0.003624381497502327, 0.0017935286741703749, 0.00536069180816412, 0.0008831577142700553, 0.012626041658222675, -0.006182061042636633, -0.0013566957786679268, 0.0025507346726953983, -0.00913956481963396, -0.00008162461745087057, 0.005763222463428974, 0.006081458181142807, -0.0010744617320597172, 0.0047402516938745975, -0.008997170254588127, -0.004185038153082132, -0.01743490993976593, -0.006468588020652533, 0.007208110298961401, -0.004240481182932854, 0.007524179294705391, -0.013773449696600437, 0.005925548262894154, 0.006004243157804012, 0.00664451764896512, -0.001983202761039138, 0.0000727357401046902, 0.0058137825690209866, 0.011327149346470833, -0.005578620359301567, 0.000720193434972316, 0.0028735266532748938, -0.001220423262566328, -0.0033052731305360794, 0.00843106210231781, -0.006134363356977701, -0.004092675168067217, 0.0027464015875011683, 0.005885637830942869, -0.00024309895525220782, -0.003390578320249915, -0.007580670062452555, -0.004552179016172886, 0.004554519895464182, -0.006201057229191065, 0.004062934312969446, 0.0002341409563086927, 0.003535010851919651, -0.006814106367528439, -0.0035599020775407553, -0.0047444673255085945, -0.012479692697525024, 0.011165273375809193, -0.003726744093000889, 0.002498531946912408, 0.013867607340216637, 0.0060643949545919895, -0.012316437438130379, 0.0034636855125427246, 0.007890932261943817, -0.0010346494382247329, 0.0029525873251259327, 0.0077426317147910595, -0.0054822578094899654, -0.020276103168725967, -0.003791391383856535, -0.012936437502503395, 0.005874849855899811, -0.0015376642113551497, 0.006136837415397167, -0.008057632483541965, 0.006626518443226814, 0.008754470385611057, -0.01340717077255249, -0.006197480950504541, -0.0069454447366297245, 0.008309823460876942, 0.0015767464647069573, -0.0004096275079064071, -0.0022762513253837824, -0.000461011310108006, -0.003018084680661559, -0.0030494239181280136, -0.004359154962003231, 0.004063447937369347, 0.0027807739097625017, -0.0030930221546441317, 0.0002773169835563749, -0.002742970595136285, 0.0010864741634577513, 0.0011560828424990177, -0.009898661635816097, 0.002721138298511505, 0.004086267668753862, -0.0026394242886453867, -0.0018149074167013168, -0.00026304094353690743, -0.00002168301034544129, -0.006267637014389038, -0.0092984763905406, -0.0030358717776834965, -0.003250937908887863, -0.0013803103938698769, -0.01361682079732418, -0.0011120449053123593, -0.007008410524576902, 0.00665538664907217, -0.007624755147844553, 0.007329190615564585, 0.005398477893322706, -0.006153454072773457, 0.007448398973792791, -0.0017045442946255207, 0.0057672723196446896, 0.002267709467560053, 0.003930703271180391, 0.002957467921078205, -0.00540269585326314, -0.011670034378767014, 0.013439379632472992, -0.0067953672260046005, 0.0023827659897506237, 0.013144359923899174, 0.00551860174164176, 0.009756829589605331, -0.0015935056144371629, 0.00012889316712971777, 0.0014129813062027097, 0.00540333054959774, -0.01266880426555872, 0.0013662523124366999, -0.0036626120563596487, 0.001621857052668929, 0.00322839361615479, -0.004415058996528387, 0.001394065679050982, 0.008211000822484493, -0.00013234377547632903, -0.0070857275277376175, -0.0009294965420849621, 0.001341638038866222, 0.004083548206835985, -0.013246146030724049, 0.001111340243369341, -0.002645030152052641, -0.006708591710776091, -0.002297566272318363, -0.002474898472428322, 0.0012188439723104239, 0.004738898482173681, -0.001294339308515191, 0.005494238808751106, 0.0019522568909451365, -0.006111996714025736, 0.013035055249929428, -0.0060091749764978886, -0.0026897508651018143, 0.0033942987211048603, 0.00335132097825408, -0.0018821798730641603, -0.004827513825148344, -0.0027417552191764116, 0.004033740609884262, 0.006065258290618658, -0.003813892835751176, -0.003375086933374405, -0.0002593298559077084, 0.0019235407235100865, -0.010034129954874516, -0.0009533340344205499, 0.013981454074382782, -0.005099758505821228, 0.005627593025565147, -0.0019112019799649715, -0.01023164577782154, -0.014381268993020058, 0.050298042595386505, -0.0008306050440296531, 0.002817515516653657, 0.0029886013362556696, -0.008079451508820057, 0.0004956110497005284, -0.00228445278480649, 0.009075169451534748, -0.007191086187958717, -0.007476096041500568, 0.008250744082033634, -0.0029816499445587397, 0.005965554155409336, 0.0027465152088552713, 0.000011977359463344328, 0.01474634651094675, -0.003313956083729863, -0.01390909031033516, -0.01832474023103714, 0.007403772324323654, -0.005245358683168888, -0.009242306463420391, 0.01075305137783289, -0.00530331302434206, -0.003848729655146599, 0.0017217221902683377, 0.006418665871024132, 0.00021750754967797548, 0.00017976683739107102, -0.0025136847980320454, -0.0035197469405829906, -0.0006918167928233743, 0.0022456045262515545, 0.005546866916120052, 0.00709456205368042, -0.004029636271297932, 0.0031239541713148355, -0.002149339998140931, -0.002471522893756628, -0.0018601473420858383, 0.0035441170912235975, 0.007105215918272734, -0.0017653567483648658, -0.0031773135997354984, 0.005766077898442745, 0.0029544830322265625, 0.003161047352477908, 0.01051904447376728, -0.00045320173376239836, -0.006810768507421017, 0.009499933570623398, 0.004432294517755508, -0.0008684773347340524, 0.011560027487576008, -0.0021210836712270975, 0.006678247824311256, 0.0028239029925316572, -0.00732099125161767, -0.019098717719316483, -0.005162739660590887, 0.008188820444047451, 0.008306651376187801, -0.00019931717542931437, -0.001380300265736878, -0.003951604012399912, -0.0018290745792910457, -0.00549333868548274, -0.00810844637453556, -0.003381948219612241, 0.0028387599159032106, 0.003038035938516259, 0.06901009380817413, -0.007631590124219656, -0.0014163785381242633, -0.009492005221545696, -0.002801648573949933, -0.0027453440707176924, -0.0017614229582250118, 0.003132614539936185, -0.001967186341062188, 0.0025208378210663795, -0.001959080807864666, -0.010585345327854156, -0.010155566968023777, 0.000115814502350986, 0.0011409915750846267, -0.003789033740758896, 0.003590710461139679, 0.005897817201912403, -0.011504189111292362, 0.00139532214961946, -0.012334231287240982, -0.003950333688408136, -0.0012975750723853707, -0.010175781324505806, -0.003681197529658675, -0.0038543683476746082, 0.007379966322332621, 0.0019720797426998615, 0.005471978802233934, -0.0023070746101439, 0.005375547334551811, -0.003837628522887826, 0.0003038611321244389, -0.007352511398494244, -0.002379658631980419, -0.005929744802415371, 0.009827244095504284, -0.0005029307794757187, -0.009698704816401005, -0.004972037859261036, 0.0011780333006754518, 0.0005674241692759097, -0.003872242523357272, 0.0028812731616199017, -0.0014331613201647997, 0.002094518393278122, -0.0018738055368885398, 0.0002482862619217485, -0.006377892103046179, 0.004218681249767542, -0.011465699411928654, 0.005025516729801893, -0.16738170385360718, 0.011446463875472546, 0.004512370098382235, -0.006567766424268484, -0.005498637445271015, -0.012518188916146755, -0.004237224347889423, 0.0033233165740966797, 0.009136254899203777, 0.001601109397597611, -0.0027131857350468636, -0.0009119216701947153, 0.006106991786509752, 0.0031217748764902353, -0.0003237223136238754, -0.0059009031392633915, 0.0035799818579107523, -0.002687757136300206, 0.002842277754098177, 0.002783240983262658, 0.004425367806106806, 0.010419155471026897, -0.000054591422667726874, 0.0036183043848723173, -0.001421676017343998, -0.0049753617495298386, 0.008662386797368526, -0.001949298894032836, 0.005760941654443741, -0.010676468722522259, -0.0025849672965705395, -0.004746950231492519, -0.005550103262066841, -0.00047398440074175596, 0.007146092131733894, -0.0023042818065732718, 0.008903862908482552, 0.00302348961122334, -0.008244560100138187, 0.009276305325329304, -0.008269678801298141, 0.02836407534778118, 0.0015342321712523699, 0.0061919488944113255, 0.0006664579268544912, -0.007671795319765806, -0.005444582086056471, 0.00880159717053175, -0.0007315377006307244, 0.012397932820022106, -0.013039824552834034, 0.00023031319142319262, 0.0039349086582660675, 0.02092156559228897, -0.004720177501440048, -0.009133192710578442, -0.006332239136099815, -0.0023994464427232742, 0.0005935268709436059, 0.008716368116438389, 0.011120210401713848, -0.0027046031318604946, 0.008706904947757721, -0.002520528854802251, -0.021661898121237755, 0.002480754628777504, -0.004667013883590698, -0.004901181440800428, -0.00001293669811275322, 0.005040997639298439, 0.00978093408048153, -0.00014262404874898493, 0.0019206786528229713, -0.0012680201325565577, 0.005832578055560589, -0.0005686025833711028, 0.006834876723587513, -0.00013002460764255375, 0.006892970763146877, -0.009826375171542168, 0.007023382931947708, -0.010666280053555965, -0.003152452176436782, 0.003960075788199902, -0.003783430904150009, 0.010012263432145119, 0.0024774393532425165, -0.002395245246589184, -0.0015097163850441575, -0.009510349482297897, -0.0033728494308888912, 0.0009607215761207044, 0.002745992736890912, -0.007677068933844566, 0.0033260423224419355, 0.002296826569363475, 0.0047018337063491344, 0.004158198833465576, -0.009561261162161827, 0.0047021410427987576, 0.006197725888341665, -0.0031456374563276768, 0.0018142962362617254, -0.005432675126940012, 0.0038974678609520197, 0.002568701282143593, -0.0038909988943487406, -0.005731827579438686, 0.003980305511504412, -0.006019520107656717, -0.004488850943744183, 0.007509232964366674, -0.007279947865754366, -0.009135851636528969, -0.002334575867280364, -0.011097260750830173, 0.000486040924442932 ]
8a92dd9cacd718af3ee73590efc1c1d73a3833aa
12,093
py
Python
beansdbadmin/core/client.py
ariesdevil/beansdbadmin
3165087ef57b7511ab84fbc50cf16eb8f54d83cd
[ "BSD-3-Clause" ]
11
2018-08-28T09:16:02.000Z
2021-11-08T09:39:15.000Z
beansdbadmin/core/client.py
ariesdevil/beansdbadmin
3165087ef57b7511ab84fbc50cf16eb8f54d83cd
[ "BSD-3-Clause" ]
2
2019-08-29T03:27:24.000Z
2020-07-24T02:45:39.000Z
beansdbadmin/core/client.py
ariesdevil/beansdbadmin
3165087ef57b7511ab84fbc50cf16eb8f54d83cd
[ "BSD-3-Clause" ]
4
2019-05-10T12:10:31.000Z
2020-07-17T03:22:02.000Z
#!/usr/bin/python # encoding: utf-8 '''a rich client 1. for one server (instead of multi like in libmc.Client) 2. encapsulate @, ?, gc ... use is instead of libmc.Client ''' import telnetlib import logging import libmc import string import urllib import itertools import warnings from collections import defaultdict from beansdbadmin.core.hint import parse_new_hint_body from beansdbadmin.core.data import parse_records from beansdbadmin.core.hash import get_khash64 def get_url_content(url): return urllib.urlopen(url).read() def check_bucket(bucket): assert 0 <= bucket < 16 def dir_to_dict(dir_str): d = dict() if dir_str: for line in [x for x in dir_str.split('\n') if x]: key_or_bucket, _hash, ver_or_count = line.split(' ') d[key_or_bucket] = int(_hash) & 0xffff, int(ver_or_count) return d def get_bucket_keys_count(store, bucket, depth=1): cmd = "@" sub = bucket if depth == 2: cmd = "@%x" % (bucket/16) sub = bucket % 16 result = store.get(cmd) if result: lines = result.split('\n') for line in lines: if len(line) == 0: continue d, _, c = line.split() if d.endswith('/'): bucket_ = int(d[0], 16) if bucket_ == sub: return int(c) raise Exception('get %s from %s, reply = [%s], bucket %x not found' % (cmd, store, result, bucket)) def get_buckets_keys_count(store): """ return dict: buckets -> count """ st = {} try: for line in (store.get('@') or '').split('\n'): if line: d, _, c = line.split(' ') if not d.endswith('/'): continue st[int(d[0], 16)] = int(c) return st except IOError: raise Exception("cannot get @ from %s" % (store)) def get_primary_buckets(store): """ return possible primary buckets, might be wrong on temporary nodes, result is list of buckets in integer """ ss = get_buckets_keys_count(store) bucket_list = ss.items() bucket_list = [x for x in bucket_list if x[1] > 0] if not bucket_list: return None bucket_list.sort(lambda a, b: cmp(a[1], b[1]), reverse=True) result = [bucket_list[0]] for i in bucket_list[1:]: if result[-1][1] / i[1] >= 2: break result.append(i) return [x[0] for x in result] def get_key_info_disk(store, key): '''return ver, vhash, flag, vsz, ts, fid, pos''' info = store.get('??' + key) if info: return [int(x) for x in info.split()] def is_gc_running(ip, port): s = get_gc_status(ip, port) if s and s.find('running') >= 0: return True return False def get_gc_status(ip, port): t = telnetlib.Telnet(ip, port) t.write('optimize_stat\r\n') out = t.read_until('\n') t.write('quit\r\n') t.close() return out.strip("\r\n") def connect(server, **kwargs): comp_threshold = kwargs.pop('comp_threshold', 0) prefix = kwargs.pop('prefix', None) if prefix is not None: warnings.warn('"prefix" is deprecated. ' 'use douban.wrapper.Prefix instead.') c = libmc.Client([server], do_split=0, comp_threshold=comp_threshold, prefix=prefix) c.config(libmc.MC_CONNECT_TIMEOUT, 300) # 0.3s c.config(libmc.MC_POLL_TIMEOUT, 3000) # 3s c.config(libmc.MC_RETRY_TIMEOUT, 5) # 5s return c class MCStore(object): IGNORED_LIBMC_RET = frozenset([ libmc.MC_RETURN_OK, libmc.MC_RETURN_INVALID_KEY_ERR ]) def __init__(self, addr): self.addr = addr self.host, port = addr.split(":") self.port = int(port) self.mc = connect(addr) def __repr__(self): return '<MCStore(addr=%s)>' % repr(self.addr) def __str__(self): return self.addr def set(self, key, data, rev=0): return bool(self.mc.set(key, data, rev)) def set_raw(self, key, data, rev=0, flag=0): if rev < 0: raise Exception(str(rev)) return self.mc.set_raw(key, data, rev, flag) def set_multi(self, values, return_failure=False): return self.mc.set_multi(values, return_failure=return_failure) def _check_last_error(self): last_err = self.mc.get_last_error() if last_err not in self.IGNORED_LIBMC_RET: raise IOError(last_err, self.mc.get_last_strerror()) def get(self, key): try: r = self.mc.get(key) if r is None: self._check_last_error() return r except ValueError: self.mc.delete(key) def get_raw(self, key): r, flag = self.mc.get_raw(key) if r is None: self._check_last_error() return r, flag def get_multi(self, keys): r = self.mc.get_multi(keys) self._check_last_error() return r def delete(self, key): return bool(self.mc.delete(key)) def delete_multi(self, keys, return_failure=False): return self.mc.delete_multi(keys, return_failure=return_failure) def exists(self, key): return bool(self.mc.get('?' + key)) def incr(self, key, value): return self.mc.incr(key, int(value)) class DBClient(MCStore): def __init__(self, addr): MCStore.__init__(self, addr) self._is_old = None def stats(self): stats = self.mc.stats() return stats.values()[0] if stats else None def is_old(self): if self._is_old is None: ver = self.get_server_version() self._is_old = (ver.strip().split(".")[0] == "0") return self._is_old def get_collision_summary(self, bucket): check_bucket(bucket) raw = self.get("@collision_%x" % bucket) if raw is None: return None count, hcount, khash, data_size = raw.split() return (int(count), int(hcount), int(khash, 16), int(data_size)) def get_collision(self, bucket): check_bucket(bucket) collisions = defaultdict(dict) hint_data = self.get("@collision_all_%x" % bucket) if hint_data is None: return dict() for key, meta, _ in parse_new_hint_body(hint_data): khash_str, _, ver, vhash = meta collisions[khash_str][key] = (vhash, ver) return dict(collisions) def get_records_by_khash_raw(self, khash): if self.is_old(): return [] if not isinstance(khash, str): khash = "%016x" % khash return self.get("@@" + khash) def get_records_by_khash(self, khash_str): raw = self.get_records_by_khash_raw(khash_str) if raw: return parse_records(raw, False) else: return [] def start_gc(self, bucket='', start_fid=0, end_fid=None): """ bucket must be in 0 or 00 string """ if bucket: assert isinstance(bucket, basestring) and len(bucket) <= 2 t = telnetlib.Telnet(self.host, self.port) tree = '@%s' % bucket if end_fid is None: gc_cmd = 'gc {} {}\n'.format(tree, start_fid) else: gc_cmd = 'gc {} {} {}\n'.format(tree, start_fid, end_fid) t.write(gc_cmd) out = t.read_until('\n').strip('\r\n') assert out == 'OK' t.write('quit\n') t.close() def start_gc_all_buckets(self, db_depth): hex_digits = string.digits + 'abcdef' buckets_iter = itertools.product(*[hex_digits for _ in range(db_depth)]) buckets = [''.join(i) for i in buckets_iter] self.start_gc_buckets(buckets) def start_gc_buckets(self, buckets): for b in buckets: self.start_gc(bucket=b) while True: status = self.get_gc_status() if status.find('running') >= 0: continue elif status == 'success': print "bucket %s gc done" % b break elif status == 'fail': return self.fail("optimize_stat = fail") else: self.fail(status) def get_gc_status(self): return get_gc_status(self.host, self.port) def get_version(self, key): meta = self.get("?" + key) if meta: return int(meta.split()[0]) def item_count(self): s = self.stats() if s is None: return None return int(s['total_items']) def get_key_info_mem(self, key, khash64=None): ''' return (vhash, ver) or None''' if khash64 is None: khash64 = get_khash64(key) khash32_str = "@%08x" % (khash64 >> 32) _dir = self.get_dir(khash32_str) if self.is_old(): return _dir.get(key, None) else: return _dir.get("%016x" % khash64, None) def get_khash_info_mem(self, khash): ''' return [(key, (vhash, ver))], key is "" for v2.''' khash32 = "@%08x" % (khash >> 32) _dir = self.get_dir(khash32) ret = [] if self.is_old(): for k, (vhash, ver) in _dir.iteritems(): if get_khash64(k) == khash: ret.append((k, (vhash, ver))) else: for k, (vhash, ver) in _dir.iteritems(): if int(k, 16) == khash: return [("", (int(vhash), ver))] return ret def get_server_version(self): try: st = self.stats() if st: return st["version"] except IOError: logging.error("fail to get version %s", self) except KeyError: logging.error("fail to get version %s %s", self, st) def get_dir(self, path): ''' return dict case1: map dir(0-f) to (hash, count), like {'0/': (1471, 27784005), ... }, case2: map key(or khash) to (vhash, version), like {'3000000377e9c2ad': (22212, 1), ... }''' try: content = self.get(path) except IOError: content = '' return dir_to_dict(content) def list_dir(self, d): # FIXME: d should not need prefix @? '''list all KEY in the dir! not use it if dir is large!''' for path, (vhash, ver) in sorted(self.get_dir(d).items()): if path.endswith('/') and len(path) == 2: for v in self.list_dir(d + path[:-1]): yield v else: yield path, int(vhash), int(ver) def get_bucket_keys_count(self, bucket, depth=1): return get_bucket_keys_count(self, bucket, depth) def get_key_info_disk(self, key): '''return ver, vhash, flag, vsz, ts, fid, pos''' return get_key_info_disk(self, key) def prepare(self, data): return libmc.encode_value(data, self.mc.comp_threshold) def close(self): pass def test_new(addr, bucket): b = bucket c = DBClient(addr) print "stats:", c.stats() print 'version:', c.get_server_version() print "isold:", c.is_old() print "dir root:", c.get_dir("@") print "bucket key count:", c.get_bucket_keys_count(int(b)) print "item_count:", c.item_count() print "primary_buckets", get_primary_buckets(c) leaf = c.get_dir("@" + b + "000000") print "a dir leaf:", leaf khash_str = list(leaf)[0] print "a khash_str", khash_str r = c.get_records_by_khash(khash_str)[0] k = r[0] print "key, len(value), (flag, tstamp, ver):", k, r[1], r[3:] print "key info mem:", c.get_key_info_mem(k) print "key info disk(ver, vhash, flag, vsz, ts, fid, pos):", \ c.get_key_info_disk(k) print "key version:", c.get_version(k) print "collision_summary", c.get_collision_summary(int(b)) print "gc status:", c.get_gc_status() if __name__ == '__main__': test_new("rosa3a:7900", '3')
30.308271
103
0.561399
1
2.2386
[ -0.03565246984362602, -0.008340626023709774, -0.008076305501163006, -0.007861997932195663, -0.03859325870871544, 0.023859331384301186, 0.010162224061787128, -0.015428433194756508, -0.020369837060570717, -0.011661849915981293, 0.010377580299973488, 0.04181748256087303, 0.017626885324716568, -0.003102397546172142, -0.012402401305735111, -0.02395055629312992, -0.053547587245702744, -0.014996594749391079, -0.007804465480148792, 0.0032776729203760624, -0.006186631042510271, -0.007640758063644171, 0.003548853797838092, -0.0010675603989511728, 0.03206052631139755, 0.0406147725880146, -0.042442914098501205, 0.012357635423541069, 0.007175268139690161, 0.01480608619749546, 0.004571167286485434, -0.0007740120636299253, -0.029516229405999184, -0.02765677683055401, -0.012623390182852745, 0.012437311932444572, 0.009929747320711613, -0.05600608140230179, 0.03699085861444473, -0.0037742897402495146, -0.005579287186264992, 0.010001728311181068, 0.005571695510298014, -0.016700902953743935, 0.019502390176057816, 0.008098168298602104, 0.0224523413926363, 0.01708269491791725, -0.026353057473897934, 0.0009090070379897952, -0.022437257692217827, 0.02498376928269863, 0.014568672515451908, -0.018880289047956467, -0.021650848910212517, -0.027830956503748894, 0.01030756626278162, 0.005685865413397551, -0.01575809344649315, -0.01765899918973446, 0.0005065099685452878, -0.009404698386788368, 0.02281981147825718, 0.029596317559480667, 0.014111554250121117, -0.015542317181825638, 0.0021484363824129105, 0.013210888020694256, -0.04555749148130417, -0.012269889004528522, 0.03237035498023033, 0.008101200684905052, 0.02302563562989235, 0.03766985610127449, 0.03842694312334061, 0.00400928221642971, -0.01444159634411335, -0.012772392481565475, -0.020061174407601357, 0.01074394304305315, -0.02018585614860058, 0.021084491163492203, 0.009886656887829304, 0.012023488990962505, -0.011274141259491444, -0.0002518193214200437, 0.023715950548648834, -0.006977576296776533, 0.030311042442917824, 0.00003440373984631151, -0.019839879125356674, 0.013411564752459526, 0.0014536979142576456, -0.01654764637351036, -0.040011320263147354, -0.0410233736038208, -0.0057829092256724834, 0.023413926362991333, 0.014286056160926819, 0.005958112422376871, 0.00810516718775034, -0.002102851402014494, 0.00014631122758146375, -0.005598544143140316, 0.00790135096758604, -0.03450934216380119, -0.03628350421786308, -0.009101677685976028, -0.010378378443419933, -0.029972856864333153, -0.025729641318321228, -0.009583408012986183, -0.009797303006052971, -0.009220059029757977, -0.012063287198543549, -0.0055060009472072124, 0.01945841871201992, 0.005517984740436077, 0.007148288190364838, 0.10720658302307129, 0.0019250173354521394, -0.04714436084032059, 0.007100221700966358, -0.011074759997427464, -0.03206736966967583, 0.03854651749134064, -0.00581648712977767, -0.024103974923491478, 0.0066912355832755566, 0.02113681100308895, -0.024656563997268677, -0.00009583109931554645, 0.008079343475401402, 0.008550661616027355, 0.010621034540235996, -0.021124912425875664, 0.029230337589979172, 0.003375524887815118, -0.039453063160181046, 0.02155807800590992, 0.040008995682001114, -0.057041771709918976, 0.03428972512483597, 0.01136262807995081, 0.009567547589540482, -0.0035869311541318893, 0.01004709955304861, -0.008240255527198315, -0.0007346236379817128, -0.004902521148324013, 0.004652006085962057, -0.0230418611317873, 0.03165367245674133, -0.002220242517068982, -0.006464826874434948, 0.001057903398759663, -0.017654767259955406, -0.05207756534218788, 0.010344091802835464, -0.005429879762232304, -0.02251594327390194, -0.010150568559765816, 0.001434072619304061, 0.005581665318459272, 0.010581444948911667, -0.018299177289009094, -0.031702108681201935, 0.013691555708646774, 0.008849923498928547, 0.009804599918425083, -0.004922438878566027, 0.029564406722784042, 0.013874625787138939, 0.00419480400159955, -0.06024192273616791, -0.0017684955382719636, 0.010226169601082802, 0.017001530155539513, 0.00211451668292284, 0.019153263419866562, -0.029938502237200737, 0.0008739056065678596, -0.019687315449118614, -0.0033800771925598383, -0.005366052966564894, -0.02714265137910843, -0.022596579045057297, -0.024494148790836334, -0.0015629392582923174, -0.016714727506041527, -0.008114686235785484, -0.015613970346748829, -0.008449873887002468, 0.03205757215619087, -0.01470851805061102, 0.010584567673504353, 0.007711885496973991, -0.010916098952293396, -0.0065013449639081955, 0.0008010801393538713, -0.016760436818003654, -0.021986618638038635, -0.008569812402129173, 0.018686173483729362, -0.0009184207301586866, 0.011343034915626049, -0.8178080320358276, -0.014146286994218826, 0.013840031810104847, 0.012127738445997238, 0.006142823025584221, 0.008951135911047459, -0.03593358024954796, -0.004892668686807156, -0.03812035918235779, -0.03502345085144043, 0.012830293737351894, 0.012248191982507706, -0.019434524700045586, 0.020955078303813934, 0.004719555377960205, -0.0012080429587513208, 0.015971176326274872, 0.017517268657684326, 0.015153227373957634, 0.03701886534690857, 0.013365834951400757, -0.03728684037923813, -0.016204630956053734, 0.026661841198801994, 0.007154486142098904, 0.015668870881199837, 0.03901298716664314, 0.014417039230465889, 0.007140649016946554, -0.019094569608569145, 0.0331503227353096, -0.032734792679548264, 0.009402080439031124, -0.03881298750638962, 0.026669327169656754, 0.03317107632756233, 0.013452287763357162, -0.02072315663099289, -0.028628448024392128, -0.01509274821728468, -0.010777323506772518, -0.0017899683443829417, -0.04020126163959503, -0.04891835153102875, -0.021465526893734932, 0.020012404769659042, -0.001820311532355845, -0.03917214274406433, 0.011530625633895397, 0.007930702529847622, -0.04073460027575493, 0.019627338275313377, 0.031521961092948914, -0.0183112695813179, -0.00010984692198690027, 0.006493334658443928, -0.0012326487340033054, -0.03194963559508324, 0.011812672950327396, 0.027055498212575912, -0.004809212405234575, 0.012072965502738953, -0.028866872191429138, 0.020997043699026108, -0.006702035199850798, -0.0014731584815308452, 0.03992478922009468, -0.03537360578775406, 0.007547949440777302, -0.02417152188718319, -0.052548762410879135, -0.010728463530540466, -0.02696392685174942, 0.069773368537426, 0.018552610650658607, -0.002658180193975568, -0.011430377140641212, -0.020062051713466644, -0.05879533663392067, 0.013273846358060837, -0.005460029002279043, -0.013388914056122303, -0.019137650728225708, 0.029861073940992355, 0.010365542024374008, -0.009109029546380043, 0.006822599563747644, 0.028289420530200005, -0.004934778902679682, 0.015612594783306122, 0.03903960436582565, -0.01750127226114273, 0.02763177454471588, 0.01822417974472046, -0.011616810224950314, 0.04844330623745918, 0.0007436668965965509, 0.04534382373094559, -0.017412323504686356, 0.0023809417616575956, 0.007658852264285088, 0.008270185440778732, 0.002904699882492423, 0.0036157206632196903, -0.007004458922892809, 0.020802563056349754, -0.0024432761128991842, 0.005366578232496977, 0.02507874183356762, -0.017361978068947792, 0.030492354184389114, -0.019720548763871193, -0.0008023515110835433, -0.004742244258522987, 0.03419588506221771, -0.01684567704796791, -0.011413871310651302, -0.003918920177966356, 0.018819330260157585, 0.004786044359207153, -0.001981545239686966, -0.013379892334342003, -0.025704890489578247, 0.0037257238291203976, 0.0024229937698692083, 0.05455121397972107, -0.044511809945106506, 0.0076518007554113865, 0.0022572586312890053, 0.012468990869820118, -0.01896681636571884, -0.01551299262791872, 0.005273160524666309, -0.033123575150966644, -0.0009770296746864915, 0.014480835758149624, 0.022546537220478058, -0.012406772933900356, -0.0068763308227062225, -0.030465222895145416, 0.0049094343557953835, -0.0375903844833374, 0.011084278114140034, -0.04798420891165733, 0.008383408188819885, -0.026748791337013245, 0.004114994779229164, -0.02397082932293415, 0.016434835270047188, 0.007133198902010918, -0.0036455155350267887, 0.0392010323703289, 0.001988957403227687, 0.03524663299322128, -0.020350437611341476, 0.006443177815526724, -0.011233273893594742, 0.03560248389840126, 0.03269379213452339, -0.00893132109194994, -0.017860740423202515, -0.01341097243130207, -0.018532583490014076, 0.008107226341962814, -0.012624268420040607, -0.00014234553964342922, -0.0013826959766447544, 0.01187183242291212, -0.011542215943336487, 0.00031179795041680336, -0.02854182943701744, -0.0063211494125425816, 0.0021959322039037943, 0.01856069639325142, -0.02155296877026558, -0.006339918356388807, -0.0036691613495349884, -0.05328144505620003, 0.033110059797763824, -0.006391232833266258, -0.027972638607025146, -0.009383367374539375, -0.013924702070653439, -0.006257320754230022, -0.008687932044267654, 0.02561751939356327, 0.01414402388036251, 0.018880777060985565, 0.023956241086125374, -0.024293722584843636, 0.006485636346042156, 0.012509358115494251, -0.006929520983248949, -0.0013596321223303676, -0.009707344695925713, -0.011048085987567902, -0.03092069923877716, 0.01839870773255825, 0.00008349748532054946, -0.030529262498021126, 0.018866268917918205, 0.030810628086328506, -0.00666846102103591, 0.008609285578131676, 0.008156929165124893, -0.0003230490256100893, -0.0018447330221533775, -0.016271235421299934, -0.0062860157340765, -0.02602764591574669, 0.02028929814696312, -0.009607174433767796, 0.003010138403624296, -0.002776505658403039, 0.002664211904630065, 0.036900267004966736, -0.0025187190622091293, 0.021456368267536163, -0.02365734428167343, -0.010607188567519188, 0.013020483776926994, -0.038980692625045776, 0.004903183318674564, 0.018401499837636948, 0.0033992466051131487, -0.006974081974476576, 0.0005798639613203704, -0.02120569348335266, -0.012469061650335789, -0.035160936415195465, -0.018799254670739174, 0.008616525679826736, 0.0003108635719399899, -0.016956880688667297, -0.004084497690200806, -0.015357064083218575, 0.022567572072148323, -0.031758829951286316, 0.013362721540033817, -0.02067619562149048, -0.02141820453107357, -0.012553575448691845, -0.004550860729068518, 0.024359581992030144, 0.025088302791118622, -0.030135318636894226, 0.013275048695504665, -0.0313168428838253, -0.009962713345885277, -0.010226893238723278, -0.044691238552331924, 0.020178014412522316, -0.0027630729600787163, -0.006386701948940754, 0.011880914680659771, 0.007884970866143703, -0.006418321747332811, 0.05573689937591553, 0.03142588213086128, -0.0022285946179181337, -0.004478989169001579, -0.010859249159693718, -0.011874559335410595, 0.0007581192767247558, -0.009777362458407879, -0.006487579550594091, -0.030904019251465797, -0.010410320945084095, -0.056465648114681244, 0.031885433942079544, 0.04254006966948509, 0.004081360995769501, 0.020499201491475105, -0.007317621726542711, -0.004780754912644625, 0.016240740194916725, -0.010044516995549202, 0.013418070040643215, 0.04546002298593521, -0.009372703731060028, -0.023891562595963478, 0.015049757435917854, 0.013247417286038399, 0.00283857062458992, 0.0023509636521339417, 0.02017759159207344, 0.028387004509568214, 0.022105295211076736, -0.02053825557231903, 0.0036757499910891056, 0.019523316994309425, -0.0105824526399374, 0.0065099094063043594, 0.011697153560817242, 0.0005712740821763873, 0.02274096943438053, 0.004925897344946861, 0.011351099237799644, 0.014980290085077286, 0.001402414171025157, 0.03282090649008751, -0.012799407355487347, -0.0028369606006890535, 0.008783828467130661, -0.00033888808684423566, -0.01086779497563839, -0.00744505925104022, 0.0029169328045099974, 0.022714991122484207, 0.031531523913145065, -0.007696771062910557, 0.01297357864677906, -0.0003685299016069621, 0.016501406207680702, 0.04613122344017029, -0.0033479684498161077, 0.026020724326372147, 0.021036317571997643, 0.025501789525151253, -0.029064880684018135, -0.02606477029621601, 0.034940823912620544, -0.017314326018095016, -0.021917441859841347, -0.01452142745256424, -0.01632045954465866, -0.03805016726255417, -0.029568614438176155, 0.0016722651198506355, 0.024516819044947624, 0.013054444454610348, -0.018885312601923943, 0.0321657657623291, 0.006909776479005814, 0.02670314535498619, 0.011282914318144321, -0.012635777704417706, 0.030229588970541954, 0.03163774684071541, -0.02876584604382515, 0.014029157347977161, 0.02686179056763649, 0.006833008490502834, -0.006979153025895357, 0.016136953607201576, 0.014621819369494915, 0.023200230672955513, 0.014465861022472382, -0.007008381187915802, 0.01165955699980259, 0.002829443197697401, -0.02386191487312317, -0.006500876042991877, 0.006047986913472414, -0.01099969819188118, 0.0077310120686888695, 0.01893809251487255, -0.0076523590832948685, -0.004687107168138027, -0.02868255041539669, 0.05242709442973137, -0.01791303977370262, -0.038613468408584595, -0.020676646381616592, -0.011482960544526577, -0.023527689278125763, -0.01396355964243412, -0.013823178596794605, -0.005600860342383385, 0.006679791025817394, -0.008636591956019402, -0.01145701389759779, 0.017834721133112907, -0.016161516308784485, 0.01851768046617508, -0.02914523147046566, 0.026023389771580696, 0.0011088347528129816, 0.020691750571131706, -0.00273219496011734, -0.018727565184235573, 0.0033589631784707308, -0.011105528101325035, 0.008267948403954506, 0.026696251705288887, -0.0424991250038147, 0.005395370535552502, 0.005628814920783043, -0.0032434999011456966, 0.0019926216918975115, -0.006607328075915575, -0.00346577656455338, -0.011785341426730156, -0.014217962510883808, -0.0037068056408315897, -0.0010860543698072433, -0.0002286366216139868, -0.0016174113843590021, 0.02632407657802105, -0.015937596559524536, -0.016855044290423393, 0.018065400421619415, -0.00011691870167851448, -0.02180410362780094, 0.027496883645653725, -0.015423804521560669, 0.01705332100391388, -0.0036074125673621893, 0.025563202798366547, -0.010161359794437885, 0.003459006315097213, -0.006093890871852636, -0.009461495094001293, -0.007160542067140341, -0.00452455086633563, 0.025688933208584785, -0.015360025689005852, -0.004844730254262686, -0.0003931953979190439, 0.011358456686139107, 0.016414817422628403, 0.024988004937767982, -0.01676798425614834, 0.00833360105752945, -0.024285629391670227, 0.007636217400431633, 0.018740853294730186, 0.015368185937404633, 0.001451576128602028, 0.013323171995580196, -0.015681304037570953, -0.012215150520205498, -0.011998480185866356, 0.0013599779922515154, 0.010866657830774784, 0.014765086583793163, -0.006997051183134317, 0.0179896280169487, -0.02614315040409565, -0.009728780947625637, 0.012253760360181332, -0.004864685237407684, 0.018169671297073364, 0.013901760801672935, 0.03760116547346115, -0.015781203284859657, 0.019280873239040375, -0.005762745626270771, -0.014136182144284248, 0.020452868193387985, -0.0008799295756034553, -0.0027936487458646297, 0.013119310140609741, -0.003537333570420742, 0.02729378081858158, 0.0320662260055542, 0.019678691402077675, 0.004500608425587416, -0.007680270355194807, 0.011060898192226887, -0.006786643527448177, 0.019843073561787605, -0.028141414746642113, -0.0206951592117548, 0.01955610327422619, 0.011389858089387417, 0.01212175190448761, 0.013154801912605762, 0.00535435089841485, -0.01711030676960945, 0.009163699112832546, -0.00838442798703909, -0.02505432441830635, -0.0009614757727831602, -0.010798433795571327, 0.008368006907403469, 0.002213448518887162, 0.009619714692234993, 0.013797781430184841, 0.026375990360975266, 0.017963126301765442, 0.011253965087234974, 0.012968827039003372, -0.0030529263895004988, 0.029103364795446396, 0.016047539189457893, -0.0032579766120761633, 0.003748514922335744, 0.02357991598546505, 0.009741048328578472, -0.042148832231760025, -0.0009371036430820823, -0.031524285674095154, 0.01625818945467472, -0.009792552329599857, -0.031006088480353355, 0.0004591647884808481, -0.011267932131886482, 0.02416013926267624, 0.027682600542902946, 0.032381322234869, -0.03404708206653595, -0.021723203361034393, 0.0044844974763691425, 0.06043489649891853, 0.002915617311373353, 0.02739308960735798, 0.011704561300575733, -0.029662299901247025, 0.007051804102957249, -0.029036207124590874, -0.012897705659270287, 0.009185543283820152, 0.0034264945425093174, 0.037069033831357956, -0.01151477824896574, -0.03271203488111496, -0.03238661214709282, 0.013418379239737988, -0.0009607961401343346, 0.022991277277469635, -0.0028051305562257767, 0.0360327810049057, -0.018320485949516296, -0.011913220398128033, -0.00949548278003931, -0.007593175396323204, -0.06055149435997009, 0.021906832233071327, -0.0052515785209834576, -0.01655193604528904, 0.0035872480366379023, -0.025023480877280235, 0.008375589735805988, -0.007309924345463514, -0.015031537972390652, 0.016217639669775963, 0.02328592725098133, -0.009295127354562283, -0.0149679658934474, 0.031040744855999947, 0.01624862290918827, -0.021446416154503822, 0.006611044518649578, 0.004136916249990463, 0.02113983780145645, 0.0016763738822191954, -0.01736271195113659, 0.013167375698685646, -0.016576450318098068, 0.004280661232769489, -0.013482071459293365, 0.021538501605391502, -0.00047629352775402367, -0.0011190306395292282, -0.0060486258007586, -0.00457509933039546, -0.0011515890946611762, 0.0050267609767615795, -0.04651949182152748, 0.005057406611740589, 0.01244061253964901 ]
8a963372962a426bfe2a29c3f4ef8694684f359b
1,448
py
Python
Simulator/Geometry/RectOverlap.py
cuixiongyi/RBE595
fc5c6aa6c479eb14186a9168e47724b7b3d06cde
[ "MIT" ]
null
null
null
Simulator/Geometry/RectOverlap.py
cuixiongyi/RBE595
fc5c6aa6c479eb14186a9168e47724b7b3d06cde
[ "MIT" ]
null
null
null
Simulator/Geometry/RectOverlap.py
cuixiongyi/RBE595
fc5c6aa6c479eb14186a9168e47724b7b3d06cde
[ "MIT" ]
null
null
null
import matplotlib.pyplot __author__ = 'xiongyi' line1 = [(200, 100), (200, 400)] line2 = [(190, 190), (210, 210)] def overlap(): l1p1x = line1[0][0] l1p1y = line1[0][1] l1p2x = line1[1][0] l1p2y = line1[1][1] # make sure p1x < p2x if l1p1x > l1p2x: tmp = l1p1x l1p1x = l1p2x l1p2x = tmp # make sure p1y < p2y if l1p1y > l1p2y: tmp = l1p1y l1p1y = l1p2y l1p2y = tmp l2p1x = line2[0][0] l2p1y = line2[0][1] l2p2x = line2[1][0] l2p2y = line2[1][1] # make sure p1x < p2x if l2p1x > l2p2x: tmp = l2p1x l2p1x = l2p2x l2p2x = tmp # make sure p1y < p2y if l2p1y > l2p2y: tmp = l2p1y l2p1y = l2p2y l2p2y = tmp # line2 rectangle is inside line1 rect if l1p1x < l2p2x and l1p2x > l2p1x and l1p1y < l2p2y and l1p2y > l2p1y: return True # line2 rectangle is inside line1 rect if l1p1x > l2p2x and l1p2x < l2p1x and l1p1y > l2p2y and l1p2y < l2p1y: return True if l1p1x > l2p2x or l1p2x < l2p1x: return False if l1p1y > l2p2y or l1p2y < l2p1y: return False return True if __name__ == '__main__': matplotlib.pyplot.plot((line1[0][0],line1[1][0]),(line1[0][1],line1[1][1])) matplotlib.pyplot.hold(True) matplotlib.pyplot.plot((line2[0][0],line2[1][0]),(line2[0][1],line2[1][1])) print(overlap()) matplotlib.pyplot.show()
26.814815
79
0.566989
1
1.6311
[ 0.0024784605484455824, 0.026172583922743797, 0.005119554698467255, -0.0005295587470754981, 0.006142686121165752, -0.002807304495945573, -0.008824953809380531, 0.0026357523165643215, -0.00908049289137125, 0.001891834894195199, 0.0036451490595936775, 0.004410258028656244, 0.010979185812175274, -0.01624491438269615, 0.000972066365648061, 0.018466968089342117, -0.05132724717259407, -0.0009429207420907915, -0.003538351971656084, 0.00242407713085413, -0.011536654084920883, 0.010714269243180752, 0.008898030035197735, 0.008276055566966534, 0.006999317090958357, -0.002276626182720065, 0.010380634106695652, 0.002584264148026705, -0.008776028640568256, -0.007910097017884254, -0.0015094014815986156, -0.0021803597919642925, -0.004422973375767469, -0.009812244214117527, 0.004730343818664551, -0.004351490177214146, -0.0026550358161330223, -0.019075535237789154, 0.011729695834219456, -0.00582283828407526, -0.007360298652201891, -0.014345884323120117, 0.0018868532497435808, 0.0058616893365979195, -0.011589075438678265, 0.0017032190226018429, -0.0033347744029015303, 0.0009995588334277272, -0.009597161784768105, 0.006715428549796343, -0.013664014637470245, 0.00043449585791677237, 0.01224495843052864, 0.0030784413684159517, -0.0032694567926228046, -0.007470759563148022, 0.011162004433572292, -0.0006899443105794489, -0.011894800700247288, 0.00038017917540855706, -0.0007761137676425278, -0.002166988328099251, 0.0033103658352047205, 0.0012720139930024743, -0.016102733090519905, -0.005478755105286837, -0.006667577661573887, 0.0033305438701063395, 0.0007012906135059893, 0.004670970141887665, 0.0012042730813845992, 0.0008324002264998853, 0.0071033271960914135, 0.003132256679236889, 0.0033611829858273268, -0.004438574425876141, -0.0032518429215997458, 0.0032717811409384012, 0.008401615545153618, 0.004639850929379463, 0.003167057177051902, -0.00738180847838521, 0.005274451803416014, 0.012816711328923702, 0.01149630919098854, 0.006185401231050491, 0.015671970322728157, -0.01439877413213253, 0.04575956612825394, 0.007962260395288467, -0.009430350735783577, 0.001986583461984992, -0.010535220615565777, -0.0014896547654643655, -0.004053361248224974, -0.029454654082655907, 0.0008316211169585586, -0.004213983193039894, 0.0004931609146296978, 0.0033235775772482157, 0.0002526398457121104, 0.00960715301334858, -0.0014448283473029733, -0.004312701057642698, -0.00966824870556593, 0.014521326869726181, -0.007250095717608929, -0.0021244788076728582, 0.007423906121402979, 0.0004743674071505666, -0.011110043153166771, -0.0015428544720634818, 0.0017621297156438231, -0.013989098370075226, 0.004626980982720852, 0.0012014931999146938, -0.006963239051401615, 0.057999059557914734, -0.0009268879075534642, 0.0016567836282774806, -0.005856039933860302, -0.0011867722496390343, 0.0035545299760997295, 0.009682458825409412, 0.009285757318139076, -0.0037659108638763428, 0.010861619375646114, 0.006974433083087206, 0.005124293267726898, 0.007920303381979465, -0.00036938616540282965, 0.008137190714478493, -0.005287288688123226, -0.001684841699898243, 0.0019533170852810144, -0.008150693029165268, 0.008915950544178486, -0.0004465287202037871, -0.006992707960307598, 0.002850119723007083, -0.00213611894287169, -0.012969022616744041, 0.00116460002027452, -0.005222088657319546, 0.003879897529259324, -0.01115802675485611, -0.0013658892130479217, -0.002700305311009288, -0.0049737002700567245, 0.0008104383014142513, 0.012927468866109848, 0.003946141339838505, 0.0036657950840890408, -0.0065086605027318, -0.008165235631167889, -0.003471155883744359, -0.006734183523803949, 0.002243675058707595, 0.008278165012598038, 0.004769851919263601, -0.009942143224179745, 0.000797330227214843, 0.0032004727981984615, 0.0029940588865429163, -0.002059222897514701, 0.005015843082219362, -0.007108713500201702, 0.011957612819969654, 0.0007843018393032253, 0.003282903926447034, 0.01494376640766859, -0.005698332563042641, -0.0004823007620871067, -0.0002743831428233534, 0.0016462447820231318, 0.0029952903278172016, 0.0052080764435231686, 0.010320387780666351, -0.004080841317772865, -0.005388327874243259, 0.006991203874349594, 0.003123534843325615, 0.00630936911329627, 0.004895401187241077, -0.0020526295993477106, 0.0014852200401946902, -0.005271475296467543, -0.0003899846342392266, 0.008074270561337471, -0.003858411218971014, 0.006306927651166916, 0.00592002971097827, -0.016295868903398514, -0.010649438947439194, -0.003789118491113186, -0.008775034919381142, 0.0017378348857164383, 0.015743618831038475, 0.009371009655296803, -0.0017514710780233145, 0.004093277268111706, -0.01276654377579689, 0.0010665305890142918, 0.008940204046666622, 0.003763684071600437, -0.012764770537614822, -0.9559529423713684, 0.005783409811556339, 0.005938909016549587, -0.0012360508553683758, 0.0054893470369279385, 0.002262625377625227, 0.0010404137428849936, 0.0026729071978479624, 0.012085461989045143, -0.008975660428404808, -0.007126308511942625, -0.012081562541425228, -0.009603597223758698, -0.001756848767399788, -0.006167848594486713, -0.0046817585825920105, -0.00600558752194047, -0.007085248827934265, -0.004117117729038, -0.0030961469747126102, -0.0026970107574015856, 0.010137931443750858, -0.0004556244530249387, 0.0046143424697220325, 0.005649746395647526, 0.0030236938036978245, -0.0048012034967541695, -0.0029020034708082676, -0.0022374605759978294, -0.004049805458635092, -0.008124090731143951, -0.014879003167152405, -0.004664518404752016, 0.0011363103985786438, 0.010936266742646694, 0.0026708398945629597, 0.009566973894834518, -0.001636248896829784, 0.0003124933282379061, -0.009357430040836334, 0.005108930636197329, 0.002632646821439266, 0.002859932603314519, -0.03062346763908863, 0.0001856096350820735, -0.0008046556613408029, -0.008259317837655544, 0.009128216654062271, 0.0049642533995211124, 0.0008865298586897552, -0.003956815227866173, -0.0038510726299136877, 0.010967408306896687, -0.005328731145709753, 0.0027431827038526535, -0.0047207181341946125, -0.006304529029875994, -0.0008793442975729704, -0.0071128359995782375, 0.0028272285126149654, 0.004321202170103788, -0.003579258220270276, -0.002855677856132388, -0.004107907880097628, 0.004600261803716421, 0.0007246942259371281, 0.003944693598896265, -0.01942000538110733, -0.006146145984530449, -0.0016083872178569436, 0.0003263062972109765, 0.0010352955432608724, -0.005154390819370747, 0.0017214613035321236, -0.010435656644403934, 0.004754286725074053, -0.002617190359160304, 0.001995175378397107, -0.012579545378684998, -0.0007247125031426549, -0.009482290595769882, -0.008342723362147808, 0.0042746360413730145, -0.005213259719312191, -0.003455509664490819, 0.0013424312928691506, 0.00200414820574224, 0.00891204085201025, -0.0070759630762040615, 0.0006541414186358452, 0.01251694280654192, -0.00029609183548018336, -0.009161151014268398, 0.007730975281447172, 0.006047949660569429, 0.0019113706657662988, -0.00315483589656651, 0.0030281131621450186, 0.008544583804905415, 0.008876252919435501, 0.00017652566020842642, 0.004695087671279907, 0.0000698520234436728, 0.01056640688329935, -0.0010865560034289956, 0.0003100650501437485, -0.003472296753898263, 0.0004880279302597046, -0.001700081629678607, -0.0029798848554491997, -0.006197633687406778, -0.0009207039838656783, -0.012143900617957115, -0.011602163314819336, -0.004835692699998617, 0.0007640632684342563, -0.0005473330966196954, -0.005446614697575569, 0.0008352541481144726, -0.0005249565583653748, 0.009609130211174488, 0.0025173714384436607, -0.006844382267445326, 0.00017561677668709308, 0.00047533633187413216, -0.008077260106801987, 0.013934001326560974, -0.011482162401080132, 0.007318408228456974, 0.00017944526916835457, -0.016434479504823685, 0.006589540280401707, 0.008253983221948147, -0.007758742198348045, 0.0015467553166672587, 0.002129222732037306, 0.002205745317041874, -0.0010867727687582374, -0.006387973204255104, -0.004481904208660126, -0.014498409815132618, -0.0008167787455022335, 0.02042049914598465, 0.002054691081866622, 0.009812559932470322, 0.01415164303034544, -0.004787198267877102, 0.005004596430808306, 0.006323636043816805, -0.0007458685431629419, 0.014748255722224712, -0.007179453037679195, 0.0010795615380629897, 0.001363882445730269, -0.006636446341872215, 0.0018682426307350397, 0.0033837698865681887, 0.004622824024409056, -0.004613297525793314, 0.0020851611625403166, -0.006874762941151857, -0.004351335112005472, -0.01920422725379467, -0.003191275056451559, 0.005011966452002525, -0.004502146504819393, 0.006166757084429264, -0.014671474695205688, 0.005616968031972647, 0.005750302225351334, 0.003978031687438488, -0.00024364991986658424, 0.0031439056620001793, 0.006806237157434225, 0.010102465748786926, -0.004897669423371553, 0.0013533616438508034, 0.004441563505679369, -0.0030195596627891064, 0.001210687798447907, 0.0070387227460742, -0.008039805106818676, -0.005121476948261261, 0.0013648346066474915, 0.0032901917584240437, 0.0009103701449930668, -0.005997973959892988, -0.009284595027565956, -0.0038082199171185493, 0.0016051321290433407, -0.008191583678126335, 0.004175855778157711, 0.0014221108285710216, 0.00426054559648037, -0.008973601274192333, -0.0002162600721931085, 0.0008530003833584487, -0.009446967393159866, 0.012014086358249187, -0.0033093555830419064, 0.002502613002434373, 0.012154586613178253, 0.0044855098240077496, -0.0133135374635458, 0.00765089550986886, 0.007505826186388731, -0.005133581813424826, 0.003994787577539682, 0.007844284176826477, -0.005907965824007988, -0.02169390395283699, -0.0012942113680765033, -0.012354445643723011, 0.006295610684901476, -0.0031856298446655273, 0.0037041306495666504, -0.008710348978638649, 0.00670391833409667, 0.009247181005775928, -0.014606848359107971, -0.0028400644659996033, -0.010392922908067703, 0.00890322681516409, -0.0013591002207249403, -0.001878912327811122, -0.0030497959814965725, -0.004095864947885275, -0.0022434957791119814, -0.0013186655705794692, -0.0013293155934661627, 0.0020978692919015884, 0.0009948418010026217, -0.0018516384297981858, 0.0012796185910701752, -0.0007024303777143359, 0.003963632043451071, 0.000009312552720075473, -0.009455529972910881, 0.003561741905286908, 0.005225228611379862, -0.004763483535498381, -0.0032743681222200394, 0.002408733358606696, -0.0007003011996857822, -0.008240322582423687, -0.00998561829328537, -0.002255937783047557, -0.005523992236703634, -0.0016819977900013328, -0.012394816614687443, -0.002599239582195878, -0.007072878070175648, 0.009334319271147251, -0.006396317854523659, 0.00840118620544672, 0.004933963529765606, -0.007413164712488651, 0.00885105598717928, -0.004722703248262405, 0.0018789746100082994, 0.0012425468303263187, 0.0059987460263073444, -0.0010459800250828266, -0.008615461178123951, -0.0098082534968853, 0.011125399731099606, -0.008331001736223698, 0.0011061179684475064, 0.015742119401693344, 0.005886826664209366, 0.009494896046817303, -0.00043762012501247227, -0.0006523827323690057, 0.002772899344563484, 0.007749974261969328, -0.011653806082904339, 0.004076997749507427, -0.005109659396111965, 0.00043256994104012847, 0.004225048236548901, -0.004627442453056574, 0.00250485772266984, 0.010572994127869606, 0.000964769278652966, -0.0068714008666574955, -0.0010598371736705303, 0.002911654533818364, 0.0038099735975265503, -0.013956696726381779, 0.00009346906881546602, -0.003453157376497984, -0.004231897182762623, -0.0003873659297823906, -0.000573577475734055, -0.001304458943195641, 0.004390240181237459, -0.004683665931224823, 0.00587613508105278, 0.0010661553824320436, -0.000743657408747822, 0.014090009033679962, -0.0034986422397196293, -0.0026309627573937178, 0.002607276663184166, 0.0022414815612137318, -0.0012468004133552313, -0.00693969801068306, -0.004207571502774954, 0.0018649562261998653, 0.006435713265091181, -0.0027032240759581327, -0.005264392122626305, -0.0024469676427543163, 0.001969468779861927, -0.0074944812804460526, 0.00188010826241225, 0.012599016539752483, -0.0028823562897741795, 0.004839005880057812, 0.0008340098429471254, -0.008115440607070923, -0.01384375337511301, 0.05399034544825554, -0.00037980315391905606, 0.0021600890904664993, 0.005790436640381813, -0.004489641170948744, 0.0010370989330112934, -0.0023151091299951077, 0.0072043524123728275, -0.008008833043277264, -0.008434073068201542, 0.007387193385511637, -0.0020917272195219994, 0.003326896345242858, 0.0018606267403811216, -0.0004576376231852919, 0.017446408048272133, -0.004905646201223135, -0.018022380769252777, -0.015976453199982643, 0.004561291541904211, -0.004942848347127438, -0.007088360842317343, 0.008204127661883831, -0.0028848371002823114, -0.0017851347802206874, 0.0017820093780755997, 0.008233695290982723, 0.0003919404116459191, -0.0013984540710225701, -0.002315263729542494, 0.0004664302396122366, -0.00015356919902842492, 0.0033459910191595554, 0.005752233788371086, 0.006419152021408081, -0.002643910702317953, 0.005197550635784864, -0.0023999663535505533, 0.00012068125215591863, -0.00484596798196435, 0.0019046125235036016, 0.008161534555256367, -0.0033535207621753216, -0.00515845837071538, 0.004320081789046526, 0.0037032365798950195, 0.002518978202715516, 0.010143041610717773, -0.0007513973978348076, -0.00584678677842021, 0.007709241937845945, 0.005796255078166723, -0.0017114817164838314, 0.007257511373609304, -0.0016694854712113738, 0.010005085729062557, 0.0021312101744115353, -0.009437455795705318, -0.012713219039142132, -0.0019363282481208444, 0.00895246583968401, 0.008446210995316505, -0.0028390209190547466, 0.001155960955657065, 0.001359339221380651, -0.003419711487367749, -0.00919889286160469, -0.008045170456171036, -0.00014794862363487482, 0.002468567108735442, 0.003315622452646494, 0.07342082262039185, -0.005356547888368368, -0.0008192619425244629, -0.010399073362350464, 0.0005764676607213914, -0.002381387632340193, -0.0009986984077841043, -0.0022094447631388903, 0.0014081723056733608, 0.004147490486502647, 0.0037918954622000456, -0.009631657041609287, -0.01031964085996151, 0.00441096443682909, 0.0016226100269705057, -0.002193159656599164, 0.005128337536007166, 0.007220924366265535, -0.004659397527575493, -0.0000898523794603534, -0.010824154131114483, -0.0004963313695043325, -0.0002541902649682015, -0.007963422685861588, -0.0027359649538993835, -0.0036233817227184772, 0.0032564408611506224, 0.0019626941066235304, 0.0036802212707698345, -0.0034270614851266146, 0.003046911908313632, -0.0034081919584423304, -0.000013997538189869374, -0.0034984799567610025, -0.0006203745142556727, -0.007233223877847195, 0.0067686839029192924, 0.0007721019792370498, -0.010145285166800022, -0.00563969137147069, -0.0014908405719324946, -0.00024062555166892707, -0.008286340162158012, 0.003095808904618025, -0.004558935295790434, 0.008133910596370697, -0.002667228225618601, 0.0029226194601505995, -0.004095117095857859, -0.0002876369981095195, -0.013341519981622696, 0.0013626596191897988, -0.17964771389961243, 0.009720014408230782, 0.0012768212473019958, -0.004018949344754219, -0.002333477372303605, -0.014213389717042446, -0.006888885982334614, 0.00287574902176857, 0.010469844564795494, 0.0033458503894507885, -0.0008189897052943707, -0.0031207953579723835, 0.004145320970565081, 0.0038463769014924765, -0.0031811061780899763, -0.0027889753691852093, 0.0054132514633238316, -0.0050199697725474834, -0.0004366601351648569, 0.004889597184956074, 0.006340407766401768, 0.009006405249238014, 0.002235869877040386, 0.0020500123500823975, -0.0017600316787138581, -0.006451400462538004, 0.008346183225512505, -0.003577670082449913, 0.0065148561261594296, -0.010621728375554085, -0.004180355928838253, -0.00747861759737134, -0.002192300045862794, 0.0008878757362253964, 0.0038439698982983828, -0.0019705775193870068, 0.005915359128266573, 0.004291204269975424, -0.007852792739868164, 0.008604040369391441, -0.007757978048175573, 0.03311699256300926, 0.003074871376156807, 0.008760913275182247, -0.0001909542625071481, -0.003890546038746834, -0.005084244534373283, 0.01068372093141079, 0.001645745593123138, 0.016190610826015472, -0.013222159817814827, -0.003194428514689207, 0.0032696351408958435, 0.020695121958851814, -0.002160941017791629, -0.008153756149113178, -0.008960013277828693, -0.006473949179053307, 0.0038906466215848923, 0.011458851397037506, 0.012082432396709919, -0.005512924864888191, 0.007168404292315245, -0.003245481289923191, -0.021661657840013504, 0.0030274863820523024, -0.004503473173826933, -0.007255233824253082, -0.001176183926872909, 0.005351549480110407, 0.011114533990621567, -0.0010539322393015027, 0.0062049985863268375, -0.0015675615286454558, 0.00415421836078167, -0.0017965727020055056, 0.00456595653668046, -0.0028106102254241705, 0.00485668471083045, -0.007957972586154938, 0.007928390055894852, -0.008459973149001598, -0.001263700076378882, 0.003869980340823531, -0.003148561343550682, 0.009025603532791138, 0.005823061801493168, -0.0043473741970956326, 0.000035452827432891354, -0.008635744452476501, -0.004127596039324999, 0.0031779829878360033, 0.001438093837350607, -0.006892052013427019, 0.0018717864295467734, 0.0011917597148567438, 0.00571273872628808, 0.007348791696131229, -0.008854363113641739, 0.004386325366795063, 0.007455016952008009, -0.006793180480599403, -0.00010973005555570126, -0.0035102509427815676, 0.002463452983647585, 0.003969903569668531, -0.005315893795341253, -0.008766090497374535, 0.0033234418369829655, -0.006987330038100481, -0.004972369410097599, 0.0018018060363829136, -0.007925390265882015, -0.0097024105489254, 0.00020704245253000408, -0.011098033748567104, -0.00019640025857370347 ]
8a96a020d6c369841c24ae3ddad9a09c8b54550c
4,434
py
Python
gino/loader.py
p4l1ly/gino
bbe63ed841bf989a0f47b6cae64db85b0b606794
[ "BSD-3-Clause" ]
null
null
null
gino/loader.py
p4l1ly/gino
bbe63ed841bf989a0f47b6cae64db85b0b606794
[ "BSD-3-Clause" ]
null
null
null
gino/loader.py
p4l1ly/gino
bbe63ed841bf989a0f47b6cae64db85b0b606794
[ "BSD-3-Clause" ]
null
null
null
from sqlalchemy import select from sqlalchemy.schema import Column from .declarative import Model class Loader: @classmethod def get(cls, value): from .crud import Alias if isinstance(value, Loader): rv = value elif isinstance(value, type) and issubclass(value, Model): rv = ModelLoader(value) elif isinstance(value, Alias): rv = AliasLoader(value) elif isinstance(value, Column): rv = ColumnLoader(value) elif isinstance(value, tuple): rv = TupleLoader(value) elif callable(value): rv = CallableLoader(value) else: rv = ValueLoader(value) return rv @property def query(self): rv = select(self.get_columns()) from_clause = self.get_from() if from_clause is not None: rv = rv.select_from(from_clause) return rv.execution_options(loader=self) def do_load(self, row, context): raise NotImplementedError def get_columns(self): return [] def get_from(self): return None def __getattr__(self, item): return getattr(self.query, item) class ModelLoader(Loader): def __init__(self, model, *column_names, **extras): self.model = model self._distinct = None if column_names: self.columns = [getattr(model, name) for name in column_names] else: self.columns = model self.extras = dict((key, self.get(value)) for key, value in extras.items()) self.on_clause = None def _do_load(self, row): rv = self.model() for c in self.columns: if c in row: rv.__values__[c.name] = row[c] return rv def do_load(self, row, context): distinct = True if self._distinct: if context is None: context = {} ctx = context.setdefault(self._distinct, {}) key = tuple(row[col] for col in self._distinct) if key == (None,) * len(key): return None, None rv = ctx.get(key) if rv is None: rv = self._do_load(row) ctx[key] = rv else: distinct = False else: rv = self._do_load(row) for key, value in self.extras.items(): value, distinct_ = value.do_load(row, context) if distinct_ is not None: setattr(rv, key, value) return rv, distinct def get_columns(self): yield from self.columns for subloader in self.extras.values(): yield from subloader.get_columns() def get_from(self): rv = self.model for key, subloader in self.extras.items(): from_clause = subloader.get_from() if from_clause is not None: rv = rv.outerjoin(from_clause, getattr(subloader, 'on_clause', None)) return rv def load(self, *column_names, **extras): if column_names: self.columns = [getattr(self.model, name) for name in column_names] self.extras.update((key, self.get(value)) for key, value in extras.items()) return self def on(self, on_clause): self.on_clause = on_clause return self def distinct(self, *columns): self._distinct = columns return self class AliasLoader(ModelLoader): def __init__(self, alias, *column_names, **extras): super().__init__(alias, *column_names, **extras) class ColumnLoader(Loader): def __init__(self, column): self.column = column def do_load(self, row, context): return row[self.column], True class TupleLoader(Loader): def __init__(self, values): self.loaders = (self.get(value) for value in values) def do_load(self, row, context): return tuple(loader.do_load(row, context)[0] for loader in self.loaders), True class CallableLoader(Loader): def __init__(self, func): self.func = func def do_load(self, row, context): return self.func(row, context), True class ValueLoader(Loader): def __init__(self, value): self.value = value def do_load(self, row, context): return self.value, True
28.063291
79
0.570591
1
1.9266
[ -0.025890089571475983, 0.04456643760204315, 0.029253322631120682, -0.036579679697752, -0.011875679716467857, 0.03857416287064552, -0.01921766810119152, -0.027923520654439926, -0.04419419914484024, 0.03536367788910866, 0.0048097772523760796, 0.0023408313281834126, 0.01598314568400383, -0.02407231740653515, -0.037621788680553436, 0.012417769990861416, 0.17210768163204193, -0.02783709019422531, 0.018851103261113167, 0.0026599843986332417, -0.007801383268088102, -0.004257555585354567, -0.046993810683488846, 0.039177365601062775, 0.026018556207418442, 0.005326306447386742, 0.07502193003892899, -0.0042673805728554726, -0.0018388408934697509, -0.015665141865611076, 0.014943857677280903, 0.009354791603982449, 0.026431117206811905, 0.04543731361627579, 0.004762229975312948, 0.010416594333946705, -0.0016491689020767808, -0.033222392201423645, -0.03308321535587311, 0.007595312315970659, -0.009593762457370758, -0.009477813728153706, -0.003718471387401223, -0.025491541251540184, 0.00851033627986908, -0.020703185349702835, -0.030128605663776398, 0.02557094395160675, -0.02416573092341423, 0.02629123441874981, 0.02713662199676037, 0.05532251298427582, 0.03453918173909187, -0.03456791862845421, -0.0015241949586197734, -0.07412433624267578, 0.03574632853269577, -0.027858687564730644, -0.028521927073597908, 0.020666033029556274, -0.04661554843187332, 0.01803913526237011, 0.01865175925195217, -0.018521053716540337, 0.016710694879293442, -0.009133966639637947, -0.027125874534249306, -0.02227269858121872, -0.017216045409440994, -0.023716630414128304, -0.045896463096141815, -0.0023963924031704664, -0.004269516561180353, 0.07148195058107376, 0.031186601147055626, 0.003974040038883686, -0.03950558230280876, -0.014790721237659454, 0.022474244236946106, 0.03512120619416237, -0.033528443425893784, 0.04364795610308647, 0.029368771240115166, 0.01343523245304823, -0.01117971446365118, 0.047306034713983536, 0.06363628804683685, -0.03322156146168709, 0.07369758188724518, 0.028420506045222282, -0.035344988107681274, 0.03956824913620949, -0.056431129574775696, 0.008157064206898212, -0.0740007758140564, -0.040625572204589844, 0.02319401502609253, 0.0024237241595983505, 0.0011183073511347175, 0.02470201440155506, 0.034740425646305084, -0.02573886327445507, 0.03893876448273659, -0.0017572598299011588, -0.02572942152619362, 0.027597911655902863, -0.07696297764778137, 0.010581843554973602, 0.012553968466818333, -0.010650156065821648, -0.03452534228563309, -0.02704201266169548, -0.00274416571483016, -0.026874596253037453, -0.00553382420912385, -0.032711222767829895, 0.03307158872485161, 0.03445637971162796, -0.012726358138024807, 0.06652911752462387, 0.007827140390872955, 0.00012868930934928358, 0.037508536130189896, -0.026015879586338997, -0.027878468856215477, 0.10288215428590775, -0.010753849521279335, 0.008693259209394455, 0.0640624463558197, 0.005350293125957251, 0.003710298566147685, 0.04505801573395729, -0.02545011043548584, -0.023785382509231567, 0.0038543883711099625, -0.002812375547364354, -0.007187751587480307, 0.023549651727080345, -0.05023307725787163, -0.010924047790467739, -0.01523186918348074, -0.06026057153940201, 0.008942750282585621, -0.0034624047111719847, -0.0033896686509251595, -0.06734336912631989, -0.0119937127456069, 0.021824374794960022, -0.02272023633122444, -0.0044705308973789215, 0.01013368833810091, 0.016823025420308113, -0.03457061946392059, 0.004369622562080622, -0.025681572034955025, 0.0072888717986643314, 0.009083868935704231, -0.04948964715003967, -0.003271854715421796, 0.002417008625343442, -0.019190171733498573, 0.023171482607722282, 0.004400771111249924, -0.01641533151268959, -0.005712075624614954, 0.07373882085084915, -0.03216462582349777, -0.0035718821454793215, -0.0333748385310173, -0.020494526252150536, 0.016756394878029823, -0.027463313192129135, -0.018613073974847794, -0.014386752620339394, -0.03505192697048187, -0.00805072020739317, 0.038423243910074234, 0.006775183603167534, -0.030218828469514847, -0.025841929018497467, 0.016232488676905632, 0.0038844451773911715, 0.018972741439938545, 0.03442976251244545, 0.027127917855978012, 0.004328455775976181, -0.06113952025771141, -0.016656531020998955, 0.0015616988530382514, -0.020415470004081726, -0.012861493043601513, 0.06133584678173065, -0.011145154945552349, -0.020469188690185547, 0.04112279787659645, -0.017999157309532166, 0.027217762544751167, 0.018718883395195007, -0.024301225319504738, -0.03210556134581566, -0.013033377937972546, 0.006425832398235798, -0.03901563957333565, -0.020466221496462822, -0.016148995608091354, -0.022552020847797394, -0.6105831265449524, 0.011357673443853855, 0.05713852122426033, -0.018745651468634605, 0.0312935933470726, 0.04506911337375641, -0.024182932451367378, 0.025916054844856262, -0.03153703734278679, -0.02124713361263275, 0.008554617874324322, -0.03868553414940834, -0.0331960991024971, -0.028396615758538246, 0.03316871449351311, -0.03562312573194504, -0.017490334808826447, -0.004258853383362293, -0.048509467393159866, 0.05323373153805733, 0.039580121636390686, -0.01455223374068737, -0.012599284760653973, 0.026766976341605186, -0.019872836768627167, 0.003400269662961364, -0.0011797142215073109, 0.017164260149002075, -0.01013511884957552, -0.009650503285229206, -0.016518425196409225, -0.015498468652367592, -0.003913943190127611, -0.012472390197217464, -0.005665669683367014, -0.0108243552967906, 0.01783377304673195, -0.022065075114369392, 0.024032263085246086, -0.00755996722728014, -0.0320187546312809, -0.0037758280523121357, 0.0318203940987587, -0.04469640925526619, -0.04563242942094803, 0.008575006388127804, -0.091970294713974, -0.002012505428865552, 0.02217908203601837, 0.019812462851405144, 0.003171571297571063, 0.04769499972462654, 0.03237675875425339, -0.0028583628591150045, -0.0027758595533668995, -0.008923279121518135, -0.026207465678453445, 0.0019396707648411393, -0.005848858039826155, 0.01676045171916485, 0.042963746935129166, 0.02885519713163376, -0.019873445853590965, 0.008939864113926888, -0.0028379904106259346, 0.0189018864184618, 0.050294697284698486, 0.005695907399058342, -0.021670501679182053, 0.02802249975502491, -0.051606349647045135, -0.02164800465106964, -0.045415401458740234, 0.17170418798923492, -0.009244576096534729, 0.011933626607060432, 0.0020634320098906755, 0.01796886883676052, 0.012831171974539757, 0.0005638996954075992, 0.0021311042364686728, 0.009556310251355171, -0.014327272772789001, 0.003141924040392041, -0.09286881983280182, -0.02034793235361576, 0.006223949603736401, 0.01905464567244053, -0.016964834183454514, 0.03254690766334534, 0.055606383830308914, 0.04481704160571098, 0.0313417874276638, -0.0010282887378707528, 0.05153657868504524, 0.021671712398529053, 0.0001699921122053638, -0.003108630422502756, 0.0286769587546587, 0.058286625891923904, -0.03759687393903732, 0.027908457443118095, -0.00018992435070686042, -0.01128008309751749, 0.024024903774261475, -0.012831540778279305, 0.018478624522686005, -0.014933066442608833, 0.035811588168144226, -0.0673578530550003, -0.026178834959864616, -0.021529925987124443, -0.03392107039690018, 0.03328763321042061, 0.02014172077178955, 0.001577050075866282, 0.008596333675086498, -0.04847794771194458, 0.02964630350470543, 0.00021819726680405438, -0.011431079357862473, -0.0772552415728569, 0.013823715038597584, 0.006890204735100269, 0.005391066428273916, -0.0009799005929380655, -0.04041348770260811, 0.010807111859321594, 0.03473997488617897, 0.04958462342619896, -0.008722158148884773, -0.010597163811326027, -0.006220892537385225, -0.00402257451787591, -0.005986933130770922, -0.020612526684999466, -0.006542466580867767, -0.04159971699118614, 0.002759336493909359, -0.029654832556843758, -0.030420996248722076, -0.020038409158587456, -0.003877089126035571, -0.04383087903261185, 0.0017834396567195654, 0.007214819081127644, 0.01316450908780098, -0.002250986872240901, -0.0060205282643437386, -0.03291052579879761, -0.017769426107406616, 0.041360389441251755, -0.009771591052412987, 0.02727954089641571, 0.015431961975991726, -0.020031258463859558, -0.010333575308322906, 0.01831364817917347, 0.049015484750270844, 0.02183803729712963, 0.011179378256201744, -0.019281992688775063, -0.0387086495757103, 0.03739788010716438, 0.01841697469353676, -0.0266567375510931, -0.002818291075527668, 0.029369469732046127, 0.037260230630636215, 0.06084117665886879, 0.012402423657476902, -0.0383215993642807, 0.023299861699342728, 0.004789556842297316, 0.00754441786557436, -0.004215784836560488, 0.027988284826278687, -0.04688999056816101, 0.013147232122719288, -0.0045021348632872105, 0.004741170443594456, 0.0008108780602924526, -0.028948543593287468, -0.026650188490748405, 0.011826803907752037, 0.014272530563175678, -0.0009194221347570419, -0.010190040804445744, 0.021208196878433228, -0.00022670031466986984, 0.007387759163975716, 0.027280867099761963, -0.045474376529455185, 0.036446332931518555, -0.02620841935276985, -0.014585628174245358, 0.00860643945634365, -0.03961147740483284, 0.007764454931020737, 0.0008753370493650436, 0.033706363290548325, -0.01697637513279915, 0.002175441011786461, -0.02721179649233818, -0.015697935596108437, 0.03520841524004936, 0.031357042491436005, -0.047770582139492035, 0.016161635518074036, -0.016559811308979988, 0.005636230111122131, 0.0008262270712293684, 0.02720808982849121, -0.02172626368701458, -0.07287704944610596, 0.010648342780768871, -0.03778237849473953, 0.013887126930058002, -0.005155924707651138, -0.03598342090845108, -0.009472311474382877, -0.019680077210068703, 0.016274502500891685, 0.009526442736387253, -0.010839706286787987, -0.02165178209543228, -0.010212448425590992, 0.02412785030901432, -0.01535783801227808, 0.0017856161575764418, 0.03567053750157356, -0.010320672765374184, 0.005014113150537014, 0.012187136337161064, -0.0034330461639910936, 0.037738606333732605, -0.0641339048743248, -0.04205150157213211, 0.001929642166942358, -0.0031063321512192488, 0.06382426619529724, 0.005041718482971191, 0.017724111676216125, 0.009950016625225544, 0.004067390225827694, 0.008758014999330044, -0.002424598904326558, -0.00125792995095253, -0.001049456768669188, 0.0015052284579724073, 0.007232319563627243, 0.05121999979019165, -0.0141032375395298, 0.016703270375728607, 0.0045424560084939, 0.02593052387237549, -0.009536771103739738, 0.014780319295823574, 0.02270752377808094, 0.015060081146657467, 0.002306092996150255, -0.018586868420243263, -0.02217540331184864, 0.02580760419368744, -0.008870834484696388, -0.017745988443493843, 0.017490314319729805, -0.02403523027896881, -0.016969909891486168, -0.009424266405403614, 0.01640770211815834, -0.03407963365316391, -0.02699391171336174, 0.01094119343906641, -0.02131093107163906, -0.009646719321608543, -0.005748982075601816, -0.029138026759028435, -0.010214509442448616, 0.04262307658791542, -0.014727363362908363, -0.007386434823274612, 0.014410888776183128, 0.0343913771212101, -0.010836197063326836, -0.003308656858280301, -0.02281944267451763, -0.0015004024608060718, -0.03213188052177429, 0.0008764498634263873, 0.012667328119277954, -0.02546207420527935, -0.03843885287642479, 0.01606338657438755, -0.020513586699962616, -0.020819876343011856, -0.017356006428599358, 0.012433472089469433, 0.03281136229634285, -0.011081678792834282, 0.0552486926317215, -0.02554546296596527, 0.02500787191092968, -0.005585227627307177, -0.0009533464326523244, -0.01897631213068962, 0.03472430258989334, -0.02919696271419525, 0.03909096494317055, 0.012455475516617298, 0.017294930294156075, 0.007655818480998278, 0.021617665886878967, -0.024254539981484413, 0.01576923578977585, 0.000017538792235427536, 0.05689769610762596, -0.009074305184185505, 0.02777770720422268, 0.01201601605862379, -0.022777248173952103, 0.013993066735565662, 0.007423719856888056, -0.0005797994672320783, -0.02857336215674877, -0.0339849591255188, -0.04929616302251816, -0.0253792442381382, -0.015623914077877998, 0.01080595888197422, -0.015773901715874672, -0.024869510903954506, 0.0088161900639534, 0.021211441606283188, 0.01735711097717285, -0.028877127915620804, 0.023934325203299522, 0.02836674638092518, 0.018557529896497726, 0.017613347619771957, -0.0049509950913488865, 0.03595200553536415, -0.03689892217516899, -0.01988697424530983, 0.022409390658140182, 0.019320037215948105, -0.020755089819431305, 0.02365943044424057, 0.02300160378217697, 0.0458381213247776, 0.023578908294439316, -0.007550199516117573, -0.009330947883427143, 0.03306995704770088, 0.0008283188799396157, -0.024806516245007515, -0.017922740429639816, 0.0394819937646389, 0.010279175825417042, -0.017179960384964943, 0.0024954809341579676, -0.008662576787173748, 0.00955981109291315, -0.020096326246857643, 0.024626940488815308, -0.02414580248296261, 0.03644021600484848, -0.020157692953944206, -0.0014368578558787704, 0.027973590418696404, -0.013759911060333252, -0.04338758811354637, -0.004441378638148308, 0.0064971959218382835, 0.015493379905819893, 0.02543705143034458, 0.025786176323890686, 0.010682156309485435, -0.026278937235474586, -0.014156137593090534, -0.017528973519802094, -0.04566970095038414, -0.008944262750446796, -0.0780164897441864, 0.021918077021837234, -0.0749846026301384, -0.005883724428713322, 0.012035241350531578, -0.003266730811446905, -0.005470480769872665, -0.017426179721951485, 0.01315439771860838, 0.031526897102594376, 0.025750882923603058, -0.020175939425826073, -0.006025037728250027, -0.03055807203054428, -0.01697877049446106, -0.00654473016038537, 0.026637105271220207, -0.0028263600543141365, 0.004649281967431307, -0.00540862837806344, -0.03410140424966812, 0.0046328590251505375, -0.010656745173037052, 0.015189915895462036, -0.018305044621229172, 0.014547625556588173, 0.057025246322155, 0.025243684649467468, 0.01696988381445408, 0.009191932156682014, -0.04512781649827957, 0.0016590935410931706, 0.0058386544696986675, -0.0493394210934639, 0.014731146395206451, 0.0161039549857378, 0.014271588064730167, -0.06460750848054886, -0.0025079071056097746, 0.007532171905040741, -0.007926051504909992, 0.001005689729936421, -0.02409682236611843, -0.0012575349537655711, 0.01345107052475214, 0.013977979309856892, 0.0076762656681239605, 0.004163652658462524, 0.003127823816612363, -0.011640086770057678, 0.026807313784956932, -0.004725336097180843, -0.06552264839410782, -0.004744026344269514, -0.024896521121263504, -0.014100705273449421, 0.03137696534395218, -0.004641193430870771, -0.014713644050061703, -0.007058106362819672, -0.0025599601212888956, -0.0010841542389243841, -0.050455961376428604, 0.035108547657728195, 0.002373523311689496, -0.017259154468774796, 0.023773323744535446, 0.01421947218477726, 0.02956017665565014, 0.01329631358385086, 0.016210690140724182, 0.023721057921648026, 0.02149028144776821, 0.011191610246896744, 0.010168284177780151, 0.01593955047428608, 0.03548525646328926, -0.0020213776733726263, 0.035260554403066635, -0.008535055443644524, -0.001899716560728848, 0.015892857685685158, 0.02066897414624691, 0.018960347399115562, -0.013129482977092266, -0.019387293606996536, -0.004431852605193853, -0.020190101116895676, -0.0060890973545610905, -0.021518416702747345, 0.01687006652355194, 0.0052465349435806274, 0.0072296904399991035, -0.01759534701704979, -0.00805504061281681, 0.02224954217672348, 0.004096564836800098, -0.06244282051920891, -0.007923735305666924, -0.007787532173097134, 0.019639454782009125, 0.007510831113904715, 0.006269857753068209, -0.00774605805054307, 0.0014290795661509037, -0.004516175948083401, 0.03540446236729622, -0.012975083664059639, -0.04142170399427414, -0.013774712570011616, 0.03455689176917076, 0.015728697180747986, 0.02816523052752018, -0.008101842366158962, 0.01226306613534689, 0.03437569737434387, -0.007735629566013813, -0.03999477997422218, -0.04493972286581993, -0.0020865092519670725, -0.025470983237028122, 0.04680950939655304, 0.02515963837504387, 0.08418861776590347, 0.005245601758360863, -0.04427902773022652, 0.013692806474864483, -0.03369970992207527, -0.020342357456684113, -0.018438931554555893, 0.006951343733817339, 0.007538417354226112, 0.015492413192987442, 0.045343998819589615, -0.026118217036128044, 0.037119071930646896, 0.005730845034122467, 0.013905803672969341, 0.011025642976164818, -0.007319728843867779, -0.04020088165998459, -0.01499455701559782, 0.001313980552367866, -0.08311238884925842, 0.016557570546865463, 0.02350529283285141, -0.008876764215528965, 0.014109883457422256, -0.01625649817287922, -0.020097628235816956, -0.006941752042621374, 0.004054768476635218, -0.037599433213472366, 0.012981787323951721, 0.03882099688053131, -0.02286144159734249, -0.03982442989945412, 0.03907372057437897, 0.02394505962729454, -0.027706101536750793, -0.012211967259645462, -0.013442577794194221, -0.03376365825533867, 0.004188904073089361, 0.025593392550945282, -0.0015734137268736959, -0.020361077040433884, -0.034429240971803665, -0.003826756263151765, -0.015692107379436493, 0.010584505274891853, -0.004094201605767012, -0.03625478968024254, -0.018456656485795975, 0.01800626702606678, -0.018490727990865707, -0.028641249984502792, -0.03805357217788696, 0.0172748863697052 ]
8a9705a2e78a0cfbf1bbd48dd0bfdf9b979f2917
3,751
py
Python
emission/clients/choice/choice.py
Andrew-Tan/e-mission-server
91d59bee86e63d803e401f10f4b6a2502effedda
[ "BSD-3-Clause" ]
null
null
null
emission/clients/choice/choice.py
Andrew-Tan/e-mission-server
91d59bee86e63d803e401f10f4b6a2502effedda
[ "BSD-3-Clause" ]
1
2017-08-31T19:54:16.000Z
2017-08-31T19:54:16.000Z
emission/clients/choice/choice.py
Andrew-Tan/e-mission-server
91d59bee86e63d803e401f10f4b6a2502effedda
[ "BSD-3-Clause" ]
null
null
null
# Standard imports import logging import math import json from uuid import UUID from datetime import datetime, timedelta import time # Our imports from emission.core.get_database import get_trip_db, get_section_db import emission.analysis.result.carbon as carbon import emission.core.common as common import emission.net.api.stats as stats from emission.core.wrapper.user import User from emission.clients.leaderboard import leaderboard from emission.clients.gamified import gamified from emission.clients.recommendation import recommendation from emission.clients.commontrips import commontrips from emission.clients.data import data # TODO: Consider subclassing to provide client specific user functions def setCurrView(uuid, newView): user = User.fromUUID(uuid) user.setClientSpecificProfileFields({'curr_view': newView}) stats.storeResultEntry(uuid, stats.STAT_VIEW_CHOICE, time.time(), newView) def getCurrView(uuid): user = User.fromUUID(uuid) profile = user.getProfile() if profile is None: logging.debug("profile is None, returning data") return "data" logging.debug("profile.get('curr_view', 'dummy') is %s" % profile.get("curr_view", "data")) return profile.get("curr_view", "data") def switchResultDisplay(params): logging.debug("params = %s" % (params)) print "params = %s" % (params['uuid']) try: uuid = UUID(params['uuid']) except: uuid = "temp" ## For testing purposes newView = params['new_view'] logging.debug("Changing choice for user %s to %s" % (uuid, newView)) setCurrView(uuid, newView) # TODO: Add stats about the switch as part of the final stats-adding pass return {'curr_view': newView } def getResult(user_uuid): # This is in here, as opposed to the top level as recommended by the PEP # because then we don't have to worry about loading bottle in the unit tests from bottle import template import base64 from dao.user import User from dao.client import Client user = User.fromUUID(user_uuid) renderedTemplate = template("clients/choice/result_template.html", variables = json.dumps({'curr_view': getCurrView(user_uuid), 'uuid': str(user_uuid), 'client_key': Client("choice").getClientKey()}), gameResult = base64.b64encode(gamified.getResult(user_uuid)), leaderboardResult = base64.b64encode(leaderboard.getResult(user_uuid)), dataResult = base64.b64encode(data.getResult(user_uuid)), commonTripsResult = base64.b64encode(commontrips.getResult(user_uuid)), recommendationResult = base64.b64encode(recommendation.getResult(user_uuid))) return renderedTemplate # These are copy/pasted from our first client, the carshare study def getSectionFilter(uuid): # We are not planning to do any filtering for this study. Bring on the worst! return [] def clientSpecificSetters(uuid, sectionId, predictedModeMap): return None def getClientConfirmedModeField(): return None # TODO: Simplify this. runBackgroundTasks are currently only invoked from the # result precomputation code. We could change that code to pass in the day, and # remove this interface. Extra credit: should we pass in the day, or a date # range? Passing in the date range could make it possible for us to run the # scripts more than once a day... def runBackgroundTasks(uuid): today = datetime.now().date() runBackgroundTasksForDay(uuid, today) def runBackgroundTasksForDay(uuid, today): leaderboard.runBackgroundTasksForDay(uuid, today) gamified.runBackgroundTasksForDay(uuid, today) data.runBackgroundTasksForDay(uuid, today)
39.484211
103
0.724607
1
1.8636
[ 0.00190359924454242, 0.022309400141239166, 0.00777431158348918, 0.00260358490049839, 0.003883838187903166, -0.0015684131067246199, -0.006971624679863453, 0.0015100683085620403, -0.007075855508446693, 0.00439473195001483, 0.003458266844972968, 0.004940809682011604, 0.005327348597347736, -0.016342490911483765, -0.001972213853150606, 0.01339017041027546, -0.04976775869727135, 0.0021213036961853504, -0.004303795285522938, 0.00158169015776366, -0.006846962496638298, 0.009448381140828133, 0.008721177466213703, 0.0034230079036206007, 0.00382263888604939, -0.0010939151979982853, 0.008702844381332397, 0.0008219638839364052, -0.005129341501742601, -0.006739400327205658, 0.0003381385758984834, -0.0024342406541109085, -0.006093685980886221, -0.006072614341974258, 0.0035999633837491274, -0.006235143635421991, -0.001466600107960403, -0.019306771457195282, 0.0135191660374403, -0.0025452987756580114, -0.00464612478390336, -0.011996902525424957, 0.002691430738195777, 0.003988172393292189, -0.008030625991523266, 0.0008283695206046104, -0.005054845008999109, 0.003417704254388809, -0.011483055539429188, 0.006416982971131802, -0.006121334154158831, 0.005438920576125383, 0.014976903796195984, 0.0028774510137736797, -0.005640700925141573, -0.006272303871810436, 0.013871288858354092, 0.0002920067636296153, -0.009794119745492935, -0.001120106433518231, -0.005609634332358837, -0.0030291310977190733, 0.0033672330901026726, 0.000915137177798897, -0.01261949073523283, -0.006544622592628002, -0.0032546930015087128, 0.002993304980918765, -0.001551195397041738, 0.007430969271808863, 0.0016070009442046285, 0.0002591785159893334, 0.006773940287530422, 0.005215529818087816, 0.0027375081554055214, -0.006248085293918848, -0.00047770154196769, -0.0010918586049228907, 0.008664334192872047, 0.005049368366599083, 0.005360451526939869, -0.006477028597146273, 0.005278768949210644, 0.006817803718149662, 0.01314159482717514, 0.008048824034631252, 0.019414624199271202, -0.0110606225207448, 0.04612988233566284, 0.008051222190260887, -0.006290886551141739, 0.0030609534587711096, -0.008641193620860577, -0.0019969604909420013, -0.007147303316742182, -0.02629948779940605, -0.002096642507240176, -0.003866777056828141, -0.0007010078988969326, 0.0031204030383378267, -0.0014578717527911067, 0.0075312708504498005, -0.00036636018194258213, -0.004332474898546934, -0.00626459950581193, 0.008488068357110023, -0.007197179365903139, -0.003721128450706601, 0.005763037130236626, 0.001473455922678113, -0.014516030438244343, -0.0025399266742169857, 0.0032056381460279226, -0.012364656664431095, 0.0014381789369508624, 0.002809276105836034, -0.004714153707027435, 0.051419131457805634, -0.0027524493634700775, 0.0023795689921826124, -0.003160744672641158, 0.004247619304805994, 0.0031079519540071487, 0.005470932926982641, 0.009604262188076973, -0.0022776497062295675, 0.014121065847575665, 0.009039745666086674, 0.0038328138180077076, 0.008992846123874187, -0.0015928936190903187, 0.007292841095477343, -0.003050324274227023, -0.0030808786395937204, 0.0014673433033749461, -0.006576906889677048, 0.008098585531115532, -0.004375588148832321, -0.010471203364431858, 0.0034528060350567102, 0.0010590507881715894, -0.007985382340848446, 0.0010198975214734674, -0.0038223760202527046, 0.007507044821977615, -0.00854342058300972, -0.0029888092540204525, -0.005578124895691872, -0.003176980884745717, 0.002865435089915991, 0.010056071914732456, 0.0017803170485422015, 0.0013943681260570884, -0.005361128132790327, -0.008273689076304436, 0.002081849379464984, -0.0022003448102623224, 0.00023988237080629915, 0.007168089039623737, 0.003082500770688057, -0.011346264742314816, 0.001226831111125648, 0.002494185697287321, 0.0021626423113048077, -0.002482401905581355, 0.0023656475823372602, -0.008043192327022552, 0.006805200129747391, -0.0005260229809209704, 0.005828619934618473, 0.010994174517691135, -0.0030439994297921658, 0.00043478107545524836, -0.0016548334388062358, 0.002027863636612892, -0.002123844111338258, 0.005571669898927212, 0.009657073765993118, -0.0029862723313272, -0.004012034274637699, 0.003627926576882601, 0.0059376610442996025, 0.008622975088655949, 0.0038409987464547157, -0.0028822997119277716, 0.003317562397569418, -0.005211704410612583, -0.00313351908698678, 0.005860304459929466, -0.003658558940514922, 0.004884185269474983, 0.0023594640661031008, -0.008807068690657616, -0.007854772731661797, 0.0016517407493665814, -0.00646170461550355, 0.0023989775218069553, 0.01169484481215477, 0.010700794868171215, -0.002850250108167529, 0.004873167257755995, -0.009086224250495434, -0.00003826600004686043, 0.007685966324061155, 0.0032509907614439726, -0.01277758926153183, -0.9625073075294495, 0.008687174879014492, 0.003760773688554764, -0.0020455862395465374, 0.004201387986540794, 0.0032340369652956724, 0.003285482758656144, 0.005443936679512262, 0.012879249639809132, -0.008203052915632725, -0.004915593657642603, -0.010599673725664616, -0.009991971775889397, -0.0032191246282309294, -0.007892327383160591, -0.0012310008751228452, -0.006451231427490711, -0.00578752625733614, -0.002763459226116538, -0.001831807428970933, -0.0015507712960243225, 0.009161019697785378, -0.0013950868742540479, 0.00533481128513813, 0.0015152567066252232, 0.003140024608001113, -0.004458338487893343, -0.0013352790847420692, -0.004300842527300119, -0.003387084696441889, -0.005337556358426809, -0.01191191840916872, -0.0037440876476466656, -0.001158418832346797, 0.007862248457968235, 0.00006522941112052649, 0.009175448678433895, -0.003457651473581791, 0.0027731426525861025, -0.007624636869877577, 0.0050641391426324844, -0.0021781453397125006, 0.0012821182608604431, -0.029285525903105736, -0.0011947103776037693, 0.0001756846613716334, -0.006924377288669348, 0.006449895910918713, -0.0011991853825747967, 0.0005281822523102164, -0.003800811478868127, -0.006199063267558813, 0.00775802182033658, -0.007580197416245937, 0.0023795508313924074, -0.0045541757717728615, -0.009183005429804325, -0.0013308057095855474, -0.007663192227482796, 0.0005742390058003366, 0.0032332215923815966, -0.002615287434309721, -0.003643854521214962, -0.003873562440276146, 0.0023834146559238434, 0.0019513732986524701, 0.0012856597313657403, -0.01716654561460018, -0.0072592939250171185, 0.002590757794678211, 0.0003351950435899198, -0.0045228819362819195, -0.0023216167464852333, 0.0027121349703520536, -0.009170956909656525, 0.006626226473599672, 0.0012098443694412708, -0.0020244913175702095, -0.013003354892134666, -0.0033409539610147476, -0.008947506546974182, -0.007705132942646742, 0.0009532419499009848, -0.0058336397632956505, -0.005340477451682091, -0.0013425893848761916, -0.0009428007178939879, 0.0075494698248803616, -0.0035976357758045197, 0.0038483361713588238, 0.013019210658967495, -0.0018573332345113158, -0.008611503057181835, 0.00441046291962266, 0.006827160716056824, 0.00024071376537904143, -0.0024983456823974848, 0.002335503464564681, 0.006245526019483805, 0.007619816809892654, 0.0020388453267514706, 0.004356067162007093, -0.0007267901673913002, 0.012488123960793018, -0.00198447541333735, -0.0022715930826961994, -0.005076294764876366, -0.0010193225461989641, -0.0035257814452052116, -0.0008748473483137786, -0.003809973131865263, -0.003240858670324087, -0.012908130884170532, -0.00859256461262703, -0.0011895139468833804, -0.001912858453579247, 0.0032828182447701693, -0.0036062891595065594, 0.0008138134144246578, 0.0026897992938756943, 0.00511923898011446, -0.00032211514189839363, -0.0008288166136480868, -0.0014629967045038939, 0.0017147848848253489, -0.003919200040400028, 0.014555967412889004, -0.011132304556667805, 0.00626696553081274, -0.00029594788793474436, -0.0129413902759552, 0.007060178089886904, 0.009631482884287834, -0.008249510079622269, 0.002648866968229413, 0.0026038477662950754, 0.00364195485599339, -0.0017670569941401482, -0.004341398365795612, -0.0007948690326884389, -0.017123058438301086, -0.0005660041351802647, 0.01727844960987568, 0.0004302981251385063, 0.010838685557246208, 0.011869204230606556, -0.001024531782604754, 0.0002177047572331503, 0.006209110375493765, 0.001488410052843392, 0.0108338613063097, -0.00916380900889635, -0.00023021630477160215, 0.0014353197766467929, -0.006149771623313427, -0.0008915964863263071, 0.006433010566979647, 0.005157774314284325, -0.004291757009923458, 0.0030368466395884752, -0.008550028316676617, -0.006788943894207478, -0.018174193799495697, -0.005137743894010782, 0.007591697387397289, -0.005956987850368023, 0.005264690611511469, -0.013405816629529, 0.00478519219905138, 0.003997343592345715, 0.004157883580774069, -0.0006036274135112762, -0.0007498417980968952, 0.005284392274916172, 0.013145474717020988, -0.005776748061180115, 0.0025374670512974262, 0.0031310287304222584, -0.001721691805869341, 0.0010046518873423338, 0.009652253240346909, -0.006381047423928976, -0.005439021624624729, 0.003550939727574587, 0.00485576968640089, 0.00004897762482869439, -0.003650630358606577, -0.008160741999745369, -0.002714262343943119, 0.0018128707306459546, -0.00547247938811779, 0.004004969261586666, 0.00013064293307252228, 0.003806028049439192, -0.006479534320533276, -0.0037117202300578356, -0.003687317715957761, -0.01440022885799408, 0.009973016567528248, -0.0022918623872101307, 0.0032748107332736254, 0.01385379210114479, 0.0031560049392282963, -0.010951751843094826, 0.005445925518870354, 0.010999591089785099, -0.0016504201339557767, 0.0032080202363431454, 0.005439211614429951, -0.006976812146604061, -0.02067488804459572, -0.004217807203531265, -0.014526220969855785, 0.0037597322370857, -0.002239900641143322, 0.002747916616499424, -0.0067349872551858425, 0.00701631186529994, 0.005739853251725435, -0.01419143471866846, -0.005769616924226284, -0.007229525130242109, 0.010025648400187492, 0.0013249339535832405, 0.0003348524041939527, -0.004349300637841225, -0.0007860505138523877, -0.0008138824487105012, -0.004656439181417227, -0.002939970698207617, 0.00414238590747118, 0.0032203197479248047, -0.0014403314562514424, 0.001603882061317563, -0.003914774861186743, 0.00039211384137161076, -0.0008438762160949409, -0.011546849273145199, 0.002132933586835861, 0.0032171683851629496, -0.0016460971673950553, -0.0031427342910319567, 0.0022052943240851164, -0.00283497734926641, -0.00864171888679266, -0.012252625077962875, -0.00555436359718442, -0.004702052101492882, -0.0029188741464167833, -0.012620915658771992, -0.002202733187004924, -0.007993354462087154, 0.007443463429808617, -0.005190301686525345, 0.008667265065014362, 0.0050799609161913395, -0.0065147834829986095, 0.0063841561786830425, -0.00025345999165438116, 0.0036605875939130783, 0.0022788438946008682, 0.0036083199083805084, 0.0020313647110015154, -0.004766843281686306, -0.013355575501918793, 0.010028567165136337, -0.007159724831581116, 0.0016378365689888597, 0.01307195145636797, 0.0056334263645112514, 0.007866021245718002, -0.003189018229022622, -0.00016623808187432587, 0.0011364443926140666, 0.0065071373246610165, -0.013573529198765755, 0.004141900222748518, -0.004481066484004259, -0.0003321434778627008, 0.0018649339908733964, -0.0026351504493504763, 0.0018526195781305432, 0.00919364020228386, 0.003059761831536889, -0.006717347539961338, -0.0029422903899103403, 0.0013164562406018376, 0.0021778997033834457, -0.01175894495099783, 0.0014379695057868958, -0.0025820236187428236, -0.003470473689958453, -0.0032213563099503517, -0.0020455371122807264, 0.0014232898829504848, 0.002661189530044794, -0.0010827238438650966, 0.005560224410146475, 0.0013130715815350413, -0.006413990166038275, 0.014372243545949459, -0.004916205070912838, -0.0028872713446617126, 0.0031244379933923483, 0.0028878962621092796, -0.0023764697834849358, -0.0060935309156775475, -0.0015576031291857362, 0.002740869065746665, 0.008517387323081493, -0.003845426021143794, -0.003820394864305854, -0.00034184122341684997, -0.0017146673053503036, -0.011114976368844509, 0.0008242745534516871, 0.012370830401778221, -0.004906200338155031, 0.005797599907964468, -0.002352870302274823, -0.008668730966746807, -0.011853552423417568, 0.051193635910749435, -0.00021235880558378994, 0.0038247769698500633, 0.004165990278124809, -0.007770253345370293, -0.003024359932169318, -0.002621350809931755, 0.007108274847269058, -0.0051925028674304485, -0.005883802194148302, 0.007554734591394663, -0.0035030622966587543, 0.003921628464013338, 0.004687630571424961, -0.0020039973314851522, 0.016188781708478928, -0.001507062348537147, -0.015230055898427963, -0.018368007615208626, 0.007884621620178223, -0.004596729762852192, -0.007893703877925873, 0.010733011178672314, -0.004675217438489199, -0.006248000543564558, 0.001334001892246306, 0.005448896437883377, 0.0012745170388370752, -0.000866817485075444, -0.003030744381248951, -0.0014037565561011434, -0.0030167035292834044, 0.0016139753861352801, 0.004355327226221561, 0.007343195378780365, -0.003953383304178715, 0.0029803819488734007, -0.0028477483429014683, -0.003436814295127988, -0.0023022093810141087, 0.00487035745754838, 0.007121535483747721, -0.001765884575434029, -0.0014759518671780825, 0.0077780368737876415, 0.004482741933315992, 0.00253062741830945, 0.010340909473598003, 0.00021410507906693965, -0.0054397741332650185, 0.00855838693678379, 0.007583630736917257, 0.0017879161750897765, 0.010183090344071388, -0.00039642828051000834, 0.006706627551466227, 0.0008490533800795674, -0.007108103949576616, -0.0159575417637825, -0.0032331987749785185, 0.008360479027032852, 0.007548169698566198, -0.0035317931324243546, 0.00020140569540672004, -0.002907204208895564, -0.003218534868210554, -0.005878584459424019, -0.007247513625770807, -0.001401128014549613, 0.0040357718244194984, 0.004758497234433889, 0.06975600868463516, -0.008099803701043129, 0.00028851840761490166, -0.008708528243005276, -0.0009382003918290138, -0.0027266014367341995, 0.00012006572796963155, 0.001607068465091288, -0.0005363145028240979, 0.001683304668404162, -0.000012136507393734064, -0.008014156483113766, -0.011380393989384174, -0.002782398136332631, 0.003675136948004365, -0.003664950141683221, 0.0024910275824368, 0.0061986977234482765, -0.010020725429058075, 0.0012978730956092477, -0.01037264708429575, -0.0007499105995520949, -0.0005826296401210129, -0.00918501615524292, -0.003612298285588622, -0.003337678499519825, 0.0061818636022508144, 0.004106755834072828, 0.004939615726470947, -0.002323655877262354, 0.006097013130784035, -0.0017764467047527432, -0.0016206048894673586, -0.006940189749002457, -0.0018793083727359772, -0.0037124098744243383, 0.007506985682994127, 0.0015796819934621453, -0.009848960675299168, -0.006470132619142532, 0.0009143835050053895, 0.0011402606032788754, -0.005005003418773413, 0.003495015436783433, 0.0015709021827206016, 0.0034118175972253084, -0.004040911328047514, -0.00016892730491235852, -0.0072157122194767, 0.002711295150220394, -0.010776771232485771, 0.00846434198319912, -0.15985405445098877, 0.010915892198681831, 0.004694326315075159, -0.005477382801473141, -0.002134895185008645, -0.015048574656248093, -0.002483511809259653, 0.00345978862605989, 0.0075439875945448875, 0.0028544520027935505, -0.0030400115065276623, 0.0011745723895728588, 0.003529733046889305, 0.004466111771762371, -0.002999498974531889, -0.002567511983215809, 0.0018257322954013944, -0.0035214920062571764, 0.001231648144312203, 0.003766814013943076, 0.0030755603220313787, 0.008207391016185284, 0.0004514819011092186, 0.0020575441885739565, -0.002501779468730092, -0.004237815737724304, 0.005199727136641741, -0.0015695206820964813, 0.003669769736006856, -0.01224732119590044, -0.003168707014992833, -0.003643960691988468, -0.004230814054608345, -0.0000400502685806714, 0.00660261744633317, 0.00013049801054876298, 0.01077816542237997, 0.003084073541685939, -0.006929153576493263, 0.007813826203346252, -0.006777225062251091, 0.02743947133421898, 0.005883412901312113, 0.005274694878607988, -0.001743822474963963, -0.007843255065381527, -0.005671883933246136, 0.009334186092019081, 0.0019226263975724578, 0.012525108642876148, -0.013242825865745544, 0.002837611362338066, 0.005210432223975658, 0.01880701445043087, -0.006131334695965052, -0.009175376035273075, -0.005518592894077301, -0.002153647830709815, 0.0008309510303661227, 0.006668289192020893, 0.009988674893975258, -0.0035987868905067444, 0.010601046495139599, -0.0017737930174916983, -0.02021612785756588, 0.004088530316948891, -0.00438289437443018, -0.006056114099919796, 0.003161936765536666, 0.008385604247450829, 0.008619096130132675, -0.0012884383322671056, 0.0027625372167676687, -0.0007687156903557479, 0.00746519397944212, 0.0016132175223901868, 0.0064841085113584995, -0.0005509365582838655, 0.005960138514637947, -0.008487588725984097, 0.00573363434523344, -0.008733698166906834, -0.0022730110213160515, 0.004022074863314629, -0.004396465141326189, 0.012202108278870583, 0.004716888070106506, -0.0019645916763693094, -0.0011191650992259383, -0.00970921665430069, -0.0010644582798704505, 0.0013863224303349853, 0.0024922844022512436, -0.008016303181648254, 0.0025548553094267845, 0.0032060686498880386, 0.006433232221752405, 0.006694790441542864, -0.012351123616099358, 0.00920779537409544, 0.0051032779738307, -0.004648493602871895, 0.00006927168578840792, -0.004943732172250748, 0.0007498330087400973, 0.004992271773517132, -0.00452134944498539, -0.005648482125252485, 0.004027632065117359, -0.005649197846651077, -0.005210493225604296, 0.006639840546995401, -0.008777456358075142, -0.009120038710534573, -0.002294359728693962, -0.008207962848246098, -0.00011984924640273675 ]
8a975211bf46410d2e2a9a98de298bed52013baa
6,589
py
Python
lib/formatter/text.py
ylafon/redbot
87f4edcc8ccda35f556331abd1e76d5e9b79cdd0
[ "Unlicense" ]
null
null
null
lib/formatter/text.py
ylafon/redbot
87f4edcc8ccda35f556331abd1e76d5e9b79cdd0
[ "Unlicense" ]
null
null
null
lib/formatter/text.py
ylafon/redbot
87f4edcc8ccda35f556331abd1e76d5e9b79cdd0
[ "Unlicense" ]
1
2021-06-01T12:08:29.000Z
2021-06-01T12:08:29.000Z
#!/usr/bin/env python """ HAR Formatter for REDbot. """ __author__ = "Jerome Renard <jerome.renard@gmail.com>" __copyright__ = """\ Copyright (c) 2008-2010 Mark Nottingham Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ import operator import nbhttp.error as nberr import redbot.speak as rs from redbot.formatter import Formatter nl = u"\n" # TODO: errors and status on stderr with CLI? class BaseTextFormatter(Formatter): """ Base class for text formatters.""" media_type = "text/plain" msg_categories = [ rs.c.GENERAL, rs.c.CONNECTION, rs.c.CONNEG, rs.c.CACHING, rs.c.VALIDATION, rs.c.RANGE ] link_order = [ ('link', 'Head Links'), ('script', 'Script Links'), ('frame', 'Frame Links'), ('iframe', 'IFrame Links'), ('img', 'Image Links'), ] error_template = "Error: %s\n" def __init__(self, *args, **kw): Formatter.__init__(self, *args, **kw) def start_output(self): pass def feed(self, red, chunk): pass def status(self, msg): pass def finish_output(self): "Fill in the template with RED's results." if self.red.res_complete: self.output(self.format_headers(self.red) + nl + nl) self.output(self.format_recommendations(self.red) + nl) else: if self.red.res_error == None: pass elif self.red.res_error['desc'] == nberr.ERR_CONNECT['desc']: self.output(self.error_template % "Could not connect to the server (%s)" % \ self.red.res_error.get('detail', "unknown")) elif self.red.res_error['desc'] == nberr.ERR_URL['desc']: self.output(self.error_template % self.red.res_error.get( 'detail', "RED can't fetch that URL.")) elif self.red.res_error['desc'] == nberr.ERR_READ_TIMEOUT['desc']: self.output(self.error_template % self.red.res_error['desc']) elif self.red.res_error['desc'] == nberr.ERR_HTTP_VERSION['desc']: self.output(self.error_template % "<code>%s</code> isn't HTTP." % \ self.red.res_error.get('detail', '')[:20]) else: raise AssertionError, "Unidentified incomplete response error." def format_headers(self, red): out = [u"HTTP/%s %s %s" % ( red.res_version, red.res_status, red.res_phrase)] return nl.join(out + [u"%s:%s" % h for h in red.res_hdrs]) def format_recommendations(self, red): return "".join([self.format_recommendation(red, category) \ for category in self.msg_categories]) def format_recommendation(self, red, category): messages = [msg for msg in red.messages if msg.category == category] if not messages: return "" out = [] if [msg for msg in messages]: out.append(u"* %s:" % category) for m in messages: out.append( u" * %s" % (self.colorize(m.level, m.summary["en"] % m.vars)) ) smsgs = [msg for msg in getattr(m.subrequest, "messages", []) if msg.level in [rs.l.BAD]] if smsgs: out.append("") for sm in smsgs: out.append( u" * %s" % (self.colorize(sm.level, sm.summary["en"] % sm.vars)) ) out.append(nl) out.append(nl) return nl.join(out) @staticmethod def colorize(level, string): # info color_start = u"\033[0;32m" color_end = u"\033[0;39m" if level == "good": color_start = u"\033[1;32m" color_end = u"\033[0;39m" if level == "bad": color_start = u"\033[1;31m" color_end = u"\033[0;39m" if level == "warning": color_start = u"\033[1;33m" color_end = u"\033[0;39m" if level == "uri": color_start = u"\033[1;34m" color_end = u"\033[0;39m" return color_start + string + color_end class TextFormatter(BaseTextFormatter): """ Format a RED object as text. """ name = "txt" media_type = "text/plain" def __init__(self, *args, **kw): BaseTextFormatter.__init__(self, *args, **kw) def finish_output(self): BaseTextFormatter.finish_output(self) self.done() class TextListFormatter(BaseTextFormatter): """ Format multiple RED responses as a textual list. """ name = "txt" media_type = "text/plain" can_multiple = True def __init__(self, *args, **kw): BaseTextFormatter.__init__(self, *args, **kw) def finish_output(self): "Fill in the template with RED's results." BaseTextFormatter.finish_output(self) sep = "=" * 78 for hdr_tag, heading in self.link_order: droids = [d[0] for d in self.red.link_droids if d[1] == hdr_tag] self.output("%s\n%s (%d)\n%s\n" % ( sep, heading, len(droids), sep )) if droids: droids.sort(key=operator.attrgetter('uri')) for droid in droids: self.output(self.format_uri(droid) + nl + nl) self.output(self.format_headers(droid) + nl + nl) self.output(self.format_recommendations(droid) + nl + nl) self.done() def format_uri(self, red): return self.colorize("uri", red.uri)
33.277778
101
0.587039
1
2.0121
[ -0.007237415760755539, 0.033691346645355225, 0.005839675664901733, 0.012798720970749855, -0.021640578284859657, 0.023892570286989212, -0.03873373568058014, -0.02653755061328411, -0.017081135883927345, 0.019181063398718834, 0.017663046717643738, -0.0034956089220941067, 0.016768641769886017, -0.015953930094838142, -0.01852014847099781, -0.022323990240693092, 0.0845656469464302, 0.010264260694384575, -0.048219289630651474, 0.008771681226789951, -0.0015121626202017069, -0.02038581669330597, -0.0006148758693598211, 0.05304822325706482, 0.006910867057740688, -0.04606614261865616, 0.025830784812569618, 0.020259324461221695, 0.0017127892933785915, -0.03288482129573822, -0.03791249915957451, 0.01904500089585781, -0.008362059481441975, 0.017393486574292183, -0.022471578791737556, 0.018132291734218597, 0.03134786710143089, -0.0017966942396014929, 0.009641995653510094, -0.00643191859126091, 0.0033777274657040834, 0.021394671872258186, -0.06918533891439438, -0.029899613931775093, 0.021569088101387024, -0.01065383292734623, -0.001971869496628642, -0.04731646925210953, 0.01453368365764618, -0.0008352923323400319, 0.028085945174098015, 0.020257655531167984, 0.02281968668103218, -0.0015089156804606318, 0.02050558663904667, -0.053135812282562256, -0.01534523069858551, -0.00976252555847168, -0.013207015581429005, -0.00950942188501358, -0.030911622568964958, 0.007520994637161493, 0.012429078109562397, -0.015474974177777767, 0.017788497731089592, 0.002702716737985611, 0.015919193625450134, 0.00029105760040692985, -0.03657200187444687, -0.025507982820272446, -0.008469096384942532, -0.04247736930847168, 0.03953848406672478, 0.0513664148747921, 0.03532065078616142, 0.018855847418308258, -0.02811376191675663, -0.013039088808000088, 0.010384728200733662, 0.008691775612533092, -0.03884590044617653, 0.044782452285289764, 0.003161887638270855, 0.012156332843005657, -0.006580736488103867, -0.00016945389506872743, 0.025591323152184486, -0.04397048428654671, 0.03400604426860809, 0.010884134098887444, -0.02017580159008503, 0.06347835063934326, -0.010566286742687225, 0.013702593743801117, -0.024938266724348068, -0.03412126004695892, 0.025819970294833183, -0.010756414383649826, 0.036490149796009064, 0.028022704645991325, 0.03758631646633148, -0.020666657015681267, 0.039483096450567245, -0.05974370241165161, -0.0474369116127491, 0.004335667937994003, -0.05335140973329544, 0.012532948516309261, -0.004370270762592554, -0.011198662221431732, -0.05803205817937851, -0.012800533324480057, 0.02345074899494648, -0.017719553783535957, -0.008016638457775116, -0.03718879818916321, 0.012071418575942516, 0.0033015082590281963, -0.002575347200036049, -0.0000445476034656167, 0.029635310173034668, 0.02538393996655941, 0.014385046437382698, 0.03174176812171936, -0.052524663507938385, 0.06173921003937721, 0.030110683292150497, 0.00282976939342916, 0.03616957738995552, -0.016830235719680786, -0.03353729099035263, 0.015904614701867104, -0.02709338068962097, -0.02906227298080921, 0.030777979642152786, -0.06374774128198624, 0.00602809339761734, -0.008874733000993729, -0.021830348297953606, 0.02572268806397915, -0.014694957062602043, -0.03777198866009712, -0.010680985637009144, -0.038370463997125626, 0.027109907940030098, -0.04709978401660919, -0.04221305996179581, -0.007231797557324171, 0.003417765023186803, 0.01816326379776001, 0.07460924237966537, 0.0006475220434367657, -0.00015405799786094576, 0.020693467929959297, -0.033165980130434036, 0.01107957772910595, 0.02533016726374626, -0.02764875814318657, -0.011450430378317833, 0.012063882313668728, -0.035709064453840256, 0.03636994957923889, -0.005436682142317295, 0.03564554825425148, 0.016034122556447983, 0.04297678545117378, -0.010728999972343445, -0.005863141734153032, -0.02026599831879139, -0.010384716093540192, 0.02732880227267742, 0.0070320917293429375, -0.025372382253408432, -0.0010288896737620234, -0.009887726977467537, 0.0014510686742141843, 0.024650104343891144, -0.0466565266251564, -0.036003679037094116, -0.056146614253520966, 0.041672348976135254, 0.01607496477663517, 0.023015890270471573, 0.03698386624455452, 0.003661049297079444, -0.024956952780485153, 0.0014084612485021353, -0.024713419377803802, -0.008709937334060669, 0.004806388635188341, -0.027805419638752937, 0.02927718125283718, 0.0033921708818525076, -0.050588179379701614, 0.02705979160964489, 0.04848821833729744, -0.020592227578163147, -0.02489670179784298, -0.020220478996634483, 0.04116005823016167, 0.009620534256100655, -0.0019583147950470448, -0.0039638434536755085, 0.02958405204117298, 0.011919400654733181, 0.009303653612732887, -0.6825186610221863, 0.053978368639945984, 0.04647534340620041, 0.01496180146932602, -0.009950323961675167, 0.007628416642546654, -0.029678598046302795, 0.04477287083864212, -0.0236821211874485, -0.013712448999285698, 0.01013314537703991, -0.0030736925546079874, -0.04213510453701019, -0.006372177042067051, 0.03955167159438133, -0.028940020129084587, 0.01506128255277872, 0.014791864901781082, -0.0062556699849665165, 0.014146343804895878, 0.0018354926723986864, -0.02660141885280609, -0.011513402685523033, 0.014681622385978699, -0.0025258976966142654, -0.023061653599143028, -0.028442688286304474, 0.03491320461034775, 0.02005178853869438, -0.020113734528422356, -0.01018808875232935, -0.038440439850091934, 0.03243971988558769, 0.00051634490955621, -0.03285129740834236, 0.032679036259651184, 0.017214659601449966, -0.025636572390794754, 0.001987869618460536, 0.013448121026158333, -0.042179178446531296, 0.02451016753911972, 0.010658501647412777, -0.047256361693143845, -0.05557052046060562, -0.015140547417104244, -0.006032404489815235, 0.004831906408071518, 0.015856396406888962, 0.037688110023736954, -0.0462166965007782, 0.011027351953089237, 0.03130732849240303, -0.030427364632487297, 0.0005386758712120354, -0.018520839512348175, -0.005484979599714279, -0.018571950495243073, -0.013436758890748024, -0.01565544493496418, -0.005839167628437281, -0.023182328790426254, -0.027407750487327576, 0.01256931759417057, -0.033261287957429886, 0.01815992221236229, 0.053547024726867676, -0.025610091164708138, -0.007535622455179691, 0.04723241180181503, -0.007092066574841738, -0.003085995325818658, -0.039153456687927246, 0.07897986471652985, -0.005443583708256483, 0.005105597898364067, -0.014161624014377594, 0.013290023431181908, -0.016730230301618576, -0.016352053731679916, 0.024744942784309387, -0.010584835894405842, -0.012044575065374374, 0.012056219391524792, -0.02635485678911209, 0.0012544903438538313, -0.016937989741563797, 0.022986002266407013, 0.0005054998910054564, 0.052327532321214676, 0.06543373316526413, 0.02091134712100029, 0.016340598464012146, -0.017266804352402687, 0.022036205977201462, -0.013580437749624252, -0.003432715544477105, 0.08747883886098862, 0.02139291726052761, 0.055471230298280716, -0.005454422906041145, 0.019305530935525894, 0.003860875265672803, -0.003730074968189001, 0.040429797023534775, 0.0014160674763843417, -0.07442059367895126, -0.007218486163765192, 0.016833579167723656, 0.003386519616469741, -0.01988828182220459, 0.021572502329945564, -0.04564015567302704, 0.007928038015961647, -0.013749564997851849, -0.007191209588199854, 0.0005498680984601378, -0.03317931294441223, -0.02456393651664257, -0.0064503783360123634, -0.01603653095662594, 0.012397640384733677, 0.007175352890044451, -0.02112613245844841, 0.03464484587311745, 0.004334650002419949, -0.018139120191335678, 0.006122778169810772, 0.01702783815562725, 0.013607902452349663, -0.012400445528328419, -0.03396430239081383, -0.016044514253735542, -0.009025669656693935, 0.013479327782988548, -0.046509768813848495, -0.01755201444029808, 0.002827407093718648, -0.027750229462981224, -0.0053957379423081875, -0.006300128996372223, 0.005635504145175219, 0.004780554212629795, -0.02039860188961029, 0.010784454643726349, 0.03124033659696579, 0.03405368700623512, 0.021881483495235443, 0.02045799233019352, -0.024969713762402534, 0.0067609092220664024, -0.0226559117436409, -0.01878279447555542, 0.012937800027430058, -0.021887291222810745, 0.007011748850345612, -0.009059247560799122, 0.007981667295098305, 0.000026519155653659254, 0.005441478919237852, -0.033359892666339874, -0.026674766093492508, 0.009901695884764194, 0.03576382249593735, 0.008954272605478764, -0.02483132854104042, -0.007938368245959282, -0.016729464754462242, 0.068013995885849, 0.003523664316162467, 0.06936194747686386, -0.02188905142247677, 0.018616044893860817, 0.016018744558095932, -0.02153105102479458, 0.016266895458102226, -0.007925501093268394, -0.03128426522016525, -0.0239874254912138, -0.030862214043736458, -0.05544237419962883, -0.015764636918902397, 0.010606080293655396, -0.031049909070134163, 0.018557041883468628, -0.004022631328552961, -0.031226670369505882, 0.009801064617931843, 0.03712012991309166, -0.016381485387682915, 0.003109538462013006, 0.008146964944899082, 0.006340181455016136, 0.017574386671185493, -0.05609503015875816, -0.012421607971191406, 0.0038651085924357176, -0.038269899785518646, -0.03222394734621048, -0.022065065801143646, 0.027257172390818596, 0.0025128815323114395, 0.014170564711093903, -0.037367336452007294, 0.0186258926987648, 0.08493736386299133, 0.003805107669904828, 0.006906041409820318, 0.043076835572719574, 0.004853454418480396, 0.01694522611796856, -0.0004589740128722042, 0.02359100803732872, -0.04678456485271454, -0.02595599740743637, -0.0009087375365197659, -0.041841816157102585, -0.029098793864250183, -0.025921057909727097, -0.04893459379673004, 0.0314754992723465, -0.015305668115615845, 0.05401870235800743, 0.01278955303132534, -0.006223456934094429, -0.00737704848870635, -0.040891580283641815, 0.042706456035375595, -0.010042511858046055, -0.042983993887901306, 0.026663031429052353, -0.0028772768564522266, 0.034774258732795715, -0.024619722738862038, -0.011447083204984665, 0.03202201798558235, -0.04627704620361328, -0.030985059216618538, 0.0007429058314301074, -0.026702865958213806, -0.004324829671531916, -0.045806530863046646, 0.01731148734688759, 0.05484849587082863, -0.0223897285759449, -0.01268506795167923, -0.0024668031837791204, -0.06378638744354248, -0.01221244316548109, -0.023056717589497566, 0.008918924257159233, -0.0011443267576396465, 0.01110574696213007, -0.012429465539753437, 0.006588856689631939, 0.01717444509267807, -0.03437114879488945, -0.0069195725955069065, -0.0010325543116778135, 0.009490295313298702, -0.005038505885750055, -0.017907679080963135, 0.00555405393242836, 0.031021147966384888, -0.012190116569399834, 0.005705337505787611, 0.018516862764954567, 0.01124267466366291, -0.01948186755180359, 0.018567485734820366, 0.02218174934387207, -0.011425848118960857, -0.03175241872668266, -0.02198059670627117, 0.0005754880257882178, -0.008452479727566242, 0.010394439101219177, -0.032639652490615845, 0.013249386101961136, 0.04776303470134735, -0.032772764563560486, 0.017892226576805115, 0.03898045793175697, 0.009185746312141418, 0.006059760227799416, -0.005416466388851404, -0.025400850921869278, -0.048636533319950104, -0.040818244218826294, -0.044588007032871246, 0.02941785380244255, -0.016661038622260094, 0.041933637112379074, 0.03286951407790184, 0.009188871830701828, 0.0031355980318039656, 0.0017301026964560151, 0.0017244948539882898, 0.015398235991597176, 0.011431166902184486, 0.03149216249585152, 0.025611093267798424, 0.0026789114344865084, -0.03468894958496094, -0.010440204292535782, -0.020738232880830765, 0.03772030398249626, -0.053152915090322495, 0.04250439256429672, 0.006046860013157129, -0.018368620425462723, 0.01409344282001257, -0.01165248267352581, -0.043460194021463394, 0.02582509256899357, -0.0267605260014534, 0.033846236765384674, -0.009386022575199604, 0.012901880778372288, -0.02146904543042183, -0.0152956023812294, 0.01981966942548752, -0.008014936931431293, 0.007298556622117758, 0.016163954511284828, 0.012725116685032845, -0.03681935369968414, 0.0216960571706295, -0.013566925190389156, -0.03463699296116829, -0.03066200204193592, -0.024971885606646538, -0.003170036943629384, -0.018226362764835358, 0.03249938786029816, -0.030050737783312798, 0.01964634284377098, 0.048667918890714645, -0.003712998004630208, 0.020676515996456146, 0.02754618227481842, 0.015484834089875221, -0.027731750160455704, 0.04530070349574089, 0.02900112234055996, 0.049385230988264084, -0.01684315875172615, 0.016264723613858223, 0.006502215750515461, 0.025588249787688255, 0.0012058410793542862, -0.010403238236904144, -0.01198548823595047, -0.007241605315357447, -0.002745881909504533, -0.0002117840776918456, -0.02274332009255886, 0.03532375767827034, 0.01395336352288723, -0.0009530293755233288, 0.026421770453453064, -0.029168466106057167, 0.012957083992660046, -0.029941659420728683, 0.016924899071455002, -0.03276532515883446, 0.064099982380867, 0.010705707594752312, -0.013423659838736057, 0.0285591259598732, -0.04330607131123543, -0.00096202886197716, 0.023322245106101036, 0.00034424755722284317, -0.007498926017433405, 0.032910943031311035, 0.00831691175699234, 0.02874569594860077, -0.0162179134786129, -0.033329546451568604, 0.005272729322314262, 0.032579272985458374, 0.01154536847025156, -0.00029140536207705736, 0.012332193553447723, -0.004611929412931204, 0.005010711029171944, -0.04255145788192749, -0.016879653558135033, -0.029614169150590897, -0.0017144617158919573, 0.015268545597791672, -0.01668310910463333, 0.031230434775352478, 0.01746535301208496, 0.008102008141577244, -0.02928898110985756, 0.0053075687028467655, -0.013529632240533829, 0.022148415446281433, 0.0019662221893668175, 0.006882983259856701, -0.02598663792014122, -0.03674567863345146, 0.05006242170929909, -0.0027772451285272837, -0.016371918842196465, 0.010195553302764893, 0.006194055080413818, 0.04070610925555229, 0.0034534286241978407, -0.009248165413737297, -0.025087492540478706, -0.006029525771737099, -0.035845186561346054, -0.005090853199362755, -0.002567893359810114, 0.01018658559769392, -0.007414448074996471, 0.0059693846851587296, -0.013709510676562786, -0.03668125346302986, 0.012755011208355427, -0.0020022208336740732, 0.011483121663331985, -0.014184615574777126, -0.009800015017390251, 0.00008757243631407619, 0.004485695157200098, 0.024497732520103455, -0.04774414002895355, -0.010799042880535126, -0.03570038825273514, -0.0031886326614767313, 0.028940372169017792, -0.04239857196807861, -0.016119739040732384, 0.013929742388427258, -0.0003213210729882121, 0.02132660336792469, 0.030006060376763344, 0.009407596662640572, 0.03189990669488907, -0.004031208343803883, 0.03630839288234711, 0.01995326764881611, 0.012632339261472225, -0.021333608776330948, 0.00574972340837121, 0.004497130401432514, 0.006135130766779184, 0.029125045984983444, -0.023012425750494003, -0.03153866529464722, -0.012812824919819832, -0.028977936133742332, -0.015191663056612015, 0.030910445377230644, 0.01999122090637684, 0.03613889217376709, 0.04481144994497299, 0.0184809360653162, 0.0038097191136330366, 0.03151596337556839, 0.06010426580905914, -0.0033441476989537477, -0.0026644947938621044, 0.003313256660476327, 0.013127772137522697, -0.016664745286107063, -0.010485273785889149, 0.021257955580949783, -0.028049679473042488, 0.012990678660571575, -0.03789689391851425, 0.015852291136980057, -0.03720778971910477, -0.0015125193167477846, -0.017583616077899933, 0.015773117542266846, -0.05089666321873665, 0.03973950445652008, -0.022938130423426628, -0.034650567919015884, -0.017065558582544327, -0.007640482857823372, -0.006947607267647982, -0.008157680742442608, 0.004484903533011675, 0.0012765623396262527, -0.01638074591755867, -0.018939180299639702, -0.0028451592661440372, 0.006569433957338333, 0.007839659228920937, -0.009573394432663918, -0.018065018579363823, 0.0472407191991806, 0.06779767572879791, 0.01727471873164177, -0.010727878659963608, -0.012953292578458786, 0.020087629556655884, 0.0018495890544727445, 0.051465220749378204, 0.0010432404233142734, 0.0646829903125763, -0.0001714716199785471, 0.02364020049571991, -0.03706648200750351, 0.003605326870456338, 0.0010149283334612846, -0.001198634854517877, -0.023710669949650764, 0.04959170147776604, 0.054968882352113724, 0.03845489025115967, -0.010966962203383446, -0.03161729499697685, -0.004325468093156815, -0.001444036839529872, 0.017202604562044144, -0.0020412448793649673, -0.030789168551564217, -0.003147587412968278, -0.01851866953074932, -0.03838368505239487, 0.019818522036075592, 0.026189109310507774, -0.00004033512595924549, 0.021644046530127525, -0.008745628409087658, 0.01439238153398037, -0.01497498620301485, 0.044391218572854996, -0.04041893035173416, 0.005232304334640503, 0.028913140296936035, -0.03119562193751335, -0.009496632032096386, 0.04964006692171097, -0.005675934255123138, -0.016357552260160446, -0.03723746910691261, -0.011081687174737453, -0.008789481595158577, 0.011131689883768559, 0.03280781954526901, -0.009972147643566132, 0.0027284196112304926, -0.015163918025791645, 0.021528441458940506, -0.0052360650151968, 0.021671194583177567, -0.005426858086138964, -0.04913224279880524, -0.042205147445201874, 0.02812282182276249, -0.007557190954685211, -0.03201552852988243, -0.019762124866247177, 0.008166967891156673 ]
8a9862396c2189c4e0deacb6232ab6ab3fc808e2
5,999
py
Python
lib/ioe_pot.py
ifurusato/ros
77b1361e78f68f00ba2d3e3db908bb5ce0f973f5
[ "MIT" ]
9
2020-10-12T08:49:55.000Z
2021-07-23T14:20:05.000Z
lib/ioe_pot.py
fanmuzhi/ros
04534a35901341c4aaa9084bff3d46851795357d
[ "MIT" ]
12
2020-07-22T19:08:58.000Z
2022-02-03T03:17:03.000Z
lib/ioe_pot.py
fanmuzhi/ros
04534a35901341c4aaa9084bff3d46851795357d
[ "MIT" ]
3
2020-07-19T20:43:19.000Z
2022-03-02T09:15:51.000Z
#!/usr/bin/env python3 # -*- coding: utf-8 -*- # # Copyright 2020-2021 by Murray Altheim. All rights reserved. This file is part # of the Robot Operating System project, released under the MIT License. Please # see the LICENSE file included as part of this package. # # author: Murray Altheim # created: 2020-09-19 # modified: 2020-09-19 # import sys, colorsys import ioexpander as io from colorama import init, Fore, Style init() from lib.logger import Logger # .............................................................................. class Potentiometer(object): ''' Configures an IO Expander Potentiometer breakout, returning an analog value scaled to a specified range. For a center-zero pot simply specify the minimum value as (-1.0 * out_max). ''' def __init__(self, config, level): super().__init__() self._log = Logger('ioe', level) if config is None: raise ValueError('no configuration provided.') _config = config['ros'].get('ioe_potentiometer') # 0x18 for IO Expander, 0x0E for the potentiometer breakout # self._i2c_addr = 0x0E self._i2c_addr = _config.get('i2c_address') self._pin_red = _config.get('pin_red') self._pin_green = _config.get('pin_green') self._pin_blue = _config.get('pin_blue') self._log.info("pins: red: {}; green: {}; blue: {}".format(self._pin_red, self._pin_green, self._pin_blue)) self._pot_enc_a = 12 self._pot_enc_b = 3 self._pot_enc_c = 11 self._max_value = 3.3 # maximum voltage (3.3v supply) self._brightness = _config.get('brightness') # effectively max fraction of period LED will be on self._period = int(255 / self._brightness) # add a period large enough to get 0-255 steps at the desired brightness _in_min = _config.get('in_min') # minimum analog value from IO Expander _in_max = _config.get('in_max') # maximum analog value from IO Expander self.set_input_limits(_in_min, _in_max) _out_min = _config.get('out_min') # minimum scaled output value _out_max = _config.get('out_max') # maximum scaled output value self.set_output_limits(_out_min, _out_max) # now configure IO Expander self._ioe = io.IOE(i2c_addr=self._i2c_addr) self._ioe.set_mode(self._pot_enc_a, io.PIN_MODE_PP) self._ioe.set_mode(self._pot_enc_b, io.PIN_MODE_PP) self._ioe.set_mode(self._pot_enc_c, io.ADC) self._ioe.output(self._pot_enc_a, 1) self._ioe.output(self._pot_enc_b, 0) self._ioe.set_pwm_period(self._period) self._ioe.set_pwm_control(divider=2) # PWM as fast as we can to avoid LED flicker self._ioe.set_mode(self._pin_red, io.PWM, invert=True) self._ioe.set_mode(self._pin_green, io.PWM, invert=True) self._ioe.set_mode(self._pin_blue, io.PWM, invert=True) self._log.info("running LED with {} brightness steps.".format(int(self._period * self._brightness))) self._log.info("ready.") # .......................................................................... def set_input_limits(self, in_min, in_max): self._in_min = in_min self._in_max = in_max self._log.info('input range:\t{:>5.2f}-{:<5.2f}'.format(self._in_min, self._in_max)) # .......................................................................... def set_output_limits(self, out_min, out_max): self._out_min = out_min self._out_max = out_max self._log.info('output range:\t{:>5.2f}-{:<5.2f}'.format(self._out_min, self._out_max)) # .......................................................................... def get_value(self): value = self._max_value - self._ioe.input(self._pot_enc_c) self._log.debug(Fore.BLACK + 'value: {:<5.2f}'.format(value)) return value # .......................................................................... def set_rgb(self, value): h = value / self._max_value # time.time() / 10.0 r, g, b = [int(c * self._period * self._brightness) for c in colorsys.hsv_to_rgb(h, 1.0, 1.0)] self._ioe.output(self._pin_red, r) self._ioe.output(self._pin_green, g) self._ioe.output(self._pin_blue, b) self._log.debug('value: {:<5.2f}; rgb: {},{},{}'.format(value, r, g, b)) # .......................................................................... def get_scaled_value(self, update_led=True): ''' Return a scaled value while also updating the RGB LED if the argument is True (the default). ''' _value = self.get_value() if update_led: self.set_rgb(_value) return self.scale_value(_value) # as float # # .......................................................................... # def x_get_scaled_value(self): # ''' # (out_max - out_min)(value - in_min) # f(x) = ----------------------------------- + out_min # in_max - in_min # where: a = 0.0, b = 1.0, min = 0, max = 330. # ''' # return (( self._out_max - self._out_min ) * ( self.get_value() - self._in_min ) / ( self._in_max - self._in_min )) + self._out_min # .......................................................................... def scale_value(self, value): ''' (out_max - out_min)(value - in_min) f(x) = ----------------------------------- + out_min in_max - in_min where e.g.: a = 0.0, b = 1.0, min = 0, max = 330. ''' return (( self._out_max - self._out_min ) * ( value - self._in_min ) / ( self._in_max - self._in_min )) + self._out_min # return (( self._out_max - self._out_min ) * ( self.get_value() - self._in_min ) / ( self._in_max - self._in_min )) + self._out_min #EOF
44.437037
138
0.543091
1
2.2026
[ 0.01448922511190176, 0.053179144859313965, -0.013071405701339245, 0.018447259441018105, -0.0031827290076762438, 0.009250531904399395, -0.021427910774946213, -0.013171418569982052, -0.007389609236270189, 0.017192097380757332, 0.004755187314003706, -0.01508715096861124, 0.015401607379317284, 0.044583603739738464, -0.013305708765983582, 0.028654320165514946, 0.031304702162742615, -0.011056719347834587, -0.004435762297362089, -0.01838863268494606, -0.00789743009954691, 0.013080141507089138, -0.029616529121994972, -0.02008906379342079, 0.02176489308476448, 0.021931102499365807, 0.05270335078239441, 0.017774291336536407, 0.001090429024770856, -0.01577935554087162, 0.018952613696455956, -0.026230463758111, -0.06089334189891815, 0.028525905683636665, -0.004071069415658712, 0.014624981209635735, 0.01831642910838127, -0.014605065807700157, 0.033320941030979156, -0.018781112506985664, -0.037596143782138824, -0.07581184059381485, -0.025341136381030083, -0.0012777559459209442, 0.011030825786292553, 0.0005313465371727943, 0.0015011171344667673, 0.025109928101301193, -0.015016152523458004, 0.033413320779800415, -0.030123822391033173, 0.028249552473425865, -0.00939219817519188, -0.053294941782951355, -0.04192780703306198, -0.024680299684405327, 0.01807365007698536, 0.0194590725004673, -0.0007973137544468045, 0.023564470931887627, -0.013410784304141998, 0.029916446655988693, 0.03279435262084007, 0.0005196996498852968, 0.02223867177963257, 0.01327464822679758, -0.0029149039182811975, 0.009022205136716366, -0.005349490325897932, 0.02062201127409935, 0.012527908198535442, 0.03269965574145317, 0.0817301869392395, 0.1342177391052246, 0.022460386157035828, -0.003857663832604885, -0.028149709105491638, -0.028274379670619965, -0.03384079039096832, 0.01933828927576542, -0.01020436454564333, -0.0018904224270954728, 0.0017113210633397102, -0.026830032467842102, -0.01876518689095974, -0.030508723109960556, 0.0327555276453495, -0.008368073962628841, 0.057577554136514664, 0.01746896095573902, -0.045381076633930206, -0.04366569221019745, 0.01923220418393612, -0.0037313420325517654, -0.020690038800239563, -0.04495709389448166, 0.016414878889918327, -0.024047791957855225, 0.042937200516462326, 0.021717136725783348, 0.008346838876605034, 0.0034987153485417366, 0.03153020516037941, 0.017758337780833244, 0.00469571677967906, -0.0006783189601264894, -0.007227689027786255, -0.0037066505756229162, -0.018851155415177345, -0.022407876327633858, 0.028367817401885986, 0.04054616764187813, 0.0040727765299379826, -0.014354151673614979, -0.062206167727708817, -0.007797293830662966, -0.021074203774333, 0.03172624111175537, 0.02063601277768612, 0.03842455893754959, 0.01793799176812172, -0.02968670055270195, 0.0026590730994939804, -0.041548170149326324, -0.009832463227212429, 0.13991232216358185, -0.05891293287277222, -0.014783959835767746, 0.013438977301120758, -0.0021786000579595566, -0.006552457809448242, -0.015309812501072884, -0.010426212102174759, 0.015131775289773941, -0.015202362090349197, 0.006345711648464203, -0.004022514913231134, 0.01880168356001377, -0.014116320759057999, 0.03191438317298889, 0.018011799082159996, -0.019584082067012787, 0.031249884516000748, 0.019283315166831017, -0.008633969351649284, -0.021557843312621117, -0.03461574763059616, -0.025480031967163086, -0.04327617213129997, 0.029452668502926826, 0.0032940206583589315, 0.010333593934774399, -0.002011891221627593, 0.006197168957442045, 0.004480820149183273, 0.04828677698969841, -0.01825523003935814, -0.062015362083911896, 0.002479776507243514, -0.0067660147324204445, -0.03984668478369713, 0.031202055513858795, 0.035430874675512314, -0.03238769248127937, -0.024067416787147522, -0.03872953727841377, -0.021738022565841675, -0.008244791068136692, -0.019853906705975533, 0.05084647610783577, -0.016387945041060448, -0.032947711646556854, 0.03796745464205742, -0.014800747856497765, 0.041429657489061356, -0.02379448153078556, 0.008269543759524822, -0.039274752140045166, -0.026867827400565147, -0.019094007089734077, -0.018742937594652176, -0.0026542257983237505, -0.02362069860100746, -0.00270898942835629, 0.009312299080193043, -0.048467498272657394, 0.0018128410447388887, 0.02215258777141571, -0.009021211415529251, -0.017346465960144997, -0.01928899995982647, -0.012370740994811058, -0.0204958226531744, 0.020516661927103996, -0.03478752076625824, -0.0006580466870218515, 0.009488904848694801, 0.004798369016498327, -0.006737297400832176, -0.038538917899131775, -0.002258874475955963, 0.002979897428303957, 0.011585673317313194, 0.004143744707107544, 0.0002669900131877512, 0.005435665138065815, -0.5751044750213623, 0.001513047725893557, -0.019238613545894623, -0.009713844396173954, -0.05112201347947121, 0.0005702551570720971, -0.04315713793039322, 0.02783416211605072, 0.06364832818508148, 0.025237051770091057, -0.02621477283537388, 0.009624197147786617, -0.039468634873628616, 0.019407885149121284, 0.024758661165833473, -0.035861413925886154, -0.007500312756747007, -0.02085387147963047, 0.007706045638769865, 0.03334587812423706, 0.000808794517070055, -0.026112519204616547, 0.013283029198646545, 0.004673643037676811, 0.06922167539596558, 0.04390599951148033, 0.027369391173124313, 0.00007494858436984941, -0.0035906832199543715, 0.000060502905398607254, 0.006586173083633184, 0.03183864429593086, -0.001114925486035645, -0.025769690051674843, 0.0023692313116043806, -0.002680236240848899, -0.01046638935804367, -0.008078075014054775, -0.044252749532461166, -0.0342271625995636, -0.002297244966030121, -0.02284505032002926, -0.005283105652779341, -0.04467374086380005, 0.006070572882890701, -0.022480549290776253, -0.022598247975111008, -0.01819942146539688, 0.03182007744908333, -0.01669280417263508, -0.059359144419431686, 0.02003183774650097, 0.028179598972201347, 0.02307409606873989, 0.029956938698887825, 0.03337429091334343, -0.011251906864345074, -0.045034486800432205, 0.02104550041258335, 0.005786491557955742, -0.007108963560312986, -0.007099699229001999, -0.00284702074714005, -0.0284768994897604, -0.06716636568307877, 0.0016566640697419643, 0.07159490883350372, -0.03798409178853035, -0.02506382390856743, 0.03367945924401283, -0.04822121560573578, 0.01891297847032547, -0.026956262066960335, 0.10047761350870132, 0.016296284273266792, 0.01621479168534279, -0.034217558801174164, 0.003997081890702248, -0.049571435898542404, 0.022260885685682297, 0.0040879142470657825, 0.015106910839676857, 0.0400848388671875, -0.039178065955638885, -0.004733555018901825, -0.016634942963719368, -0.015162348747253418, 0.003455996047705412, -0.020134609192609787, 0.04272855445742607, 0.0040275161154568195, 0.030843298882246017, -0.024570198729634285, -0.014628056436777115, 0.008311987854540348, 0.05311494693160057, -0.0042680418118834496, 0.00009168720862362534, -0.011240446008741856, -0.007247326895594597, 0.019038496538996696, 0.049730222672224045, -0.021252602338790894, 0.06785858422517776, -0.03089023008942604, -0.034546010196208954, -0.02721080370247364, -0.057969070971012115, 0.0018867431208491325, 0.005299828015267849, 0.06311686336994171, -0.017161326482892036, -0.0315994955599308, -0.026379473507404327, -0.02558601275086403, -0.04330652579665184, -0.004526798147708178, -0.0560128428041935, 0.02125907503068447, 0.0059297820553183556, -0.016173848882317543, 0.039603251963853836, 0.026974229142069817, -0.01630149595439434, -0.013010375201702118, -0.003024992300197482, 0.004236998036503792, -0.023670339956879616, 0.006695856340229511, 0.015538351610302925, 0.050775330513715744, 0.008877407759428024, -0.03169716149568558, 0.05185653641819954, -0.01904463954269886, -0.025674408301711082, 0.01697300188243389, -0.006784697063267231, -0.024219056591391563, -0.018168527632951736, -0.026071684435009956, 0.03522522747516632, -0.012537108734250069, -0.0656372606754303, 0.0037209903821349144, 0.008898332715034485, -0.05204778537154198, 0.03899569436907768, -0.0029871826991438866, -0.013691425323486328, 0.009764731861650944, 0.019766200333833694, 0.021679582074284554, 0.010582451708614826, -0.015384619124233723, 0.008355078287422657, -0.012620835565030575, 0.015863822773098946, 0.010556217283010483, 0.04075472056865692, 0.023969942703843117, -0.026322778314352036, -0.025275470688939095, 0.005207184702157974, 0.007221837993711233, 0.023711437359452248, 0.02670878916978836, 0.0015077170683071017, -0.003390241414308548, 0.004752559121698141, -0.005789509043097496, 0.027216317132115364, -0.027222899720072746, 0.05126069486141205, 0.0008764328085817397, -0.0321417935192585, -0.050870101898908615, -0.006688090041279793, -0.05695907771587372, 0.05395494028925896, -0.013583756983280182, 0.0021182438358664513, -0.002555317245423794, -0.0329446941614151, -0.017407193779945374, 0.07807237654924393, -0.05507794767618179, -0.027699945494532585, 0.023810699582099915, 0.048244912177324295, -0.005051552318036556, 0.008702056482434273, -0.012385325506329536, 0.01831001415848732, -0.04286511242389679, -0.009829866699874401, 0.031075211241841316, 0.016690202057361603, 0.0660448968410492, -0.014170235022902489, -0.0026605490129441023, 0.015545480884611607, 0.01784905418753624, -0.020374804735183716, -0.014328229241073132, 0.024039970710873604, 0.026693962514400482, 0.03545210137963295, 0.0068854293785989285, -0.0015148614766076207, 0.06159541755914688, -0.047210048884153366, -0.02110980451107025, 0.0004655465600080788, -0.01225325744599104, 0.06430881470441818, 0.003597045550122857, -0.008830549195408821, -0.018849624320864677, -0.004535752814263105, -0.02975887805223465, -0.02255263179540634, 0.010411717928946018, 0.015076544135808945, -0.010658998973667622, 0.05018148198723793, -0.0017936461372300982, 0.030604781582951546, -0.022312095388770103, 0.011680631898343563, -0.006911803036928177, -0.033736713230609894, -0.017536858096718788, 0.024945540353655815, -0.00916918832808733, -0.000613020732998848, -0.0027749035507440567, 0.015914311632514, -0.002602451015263796, 0.045118220150470734, -0.04100837931036949, -0.0482037179172039, 0.018003949895501137, 0.056696437299251556, 0.010132168419659138, 0.013051941990852356, -0.033591024577617645, -0.044693801552057266, -0.05078659579157829, -0.00029322272166609764, -0.026658063754439354, -0.010610773228108883, -0.01956883631646633, -0.023816952481865883, -0.024051275104284286, 0.028776681050658226, -0.004860673099756241, -0.003166321897879243, 0.013615348376333714, 0.01132945902645588, -0.02028466947376728, 0.0182839073240757, -0.03718592971563339, -0.034658282995224, -0.00906383153051138, 0.012467730790376663, 0.018795082345604897, 0.005459968000650406, 0.008452157489955425, 0.00030273429001681507, 0.03605789318680763, -0.0472591333091259, -0.038649480789899826, -0.0015799123793840408, 0.008322658948600292, -0.07063672691583633, -0.004689833614975214, -0.006361184176057577, -0.020864438265562057, -0.015177082270383835, -0.011995036154985428, 0.05244622007012367, 0.03789876773953438, -0.012873510830104351, -0.022206969559192657, -0.007110586389899254, 0.06594312936067581, 0.05937381088733673, 0.010266540572047234, 0.007254967000335455, -0.009194478392601013, -0.02142823301255703, 0.03499029949307442, -0.047295961529016495, 0.030778484418988228, 0.04562940448522568, -0.03122955560684204, 0.008536095730960369, 0.02996358461678028, -0.0022143356036394835, 0.045631058514118195, 0.017679037526249886, -0.014276626519858837, -0.03451068699359894, 0.013872820883989334, -0.037491004914045334, 0.015163352712988853, -0.02240140177309513, 0.04141229763627052, 0.029186774045228958, 0.009240590035915375, 0.07372505962848663, -0.021679911762475967, 0.029130348935723305, 0.006789220031350851, -0.007153801154345274, 0.06930947303771973, -0.06011871621012688, 0.02382678911089897, -0.011711005121469498, -0.05672071874141693, -0.02635168842971325, -0.009498907253146172, -0.05427331477403641, -0.0225692018866539, -0.03712945431470871, -0.06676168739795685, -0.019066903740167618, 0.020107068121433258, 0.02996044047176838, -0.007648445665836334, 0.0333922915160656, 0.024567654356360435, 0.03169997036457062, -0.005616690963506699, 0.03941694647073746, 0.011088659055531025, 0.03986517712473869, -0.010379517450928688, 0.014049164950847626, 0.009751895442605019, 0.033330854028463364, -0.011211143806576729, -0.04996166005730629, 0.03565326705574989, 0.018271273002028465, 0.045611657202243805, 0.0166038665920496, 0.009481476619839668, -0.011962687596678734, 0.011646036058664322, -0.004548472352325916, -0.0192472692579031, 0.06649509817361832, -0.014799604192376137, 0.018548205494880676, -0.014454342424869537, 0.03655163571238518, 0.03140171617269516, -0.03508499637246132, 0.00498114712536335, 0.0019245287403464317, -0.009087889455258846, -0.037878986448049545, -0.048594359308481216, -0.06090664118528366, 0.02483246475458145, -0.036823853850364685, -0.0017125962767750025, 0.03355681896209717, -0.027381757274270058, -0.038402535021305084, 0.041612669825553894, -0.019180072471499443, 0.00676817586645484, 0.030995003879070282, -0.0050617605447769165, 0.019529519602656364, 0.018865032121539116, -0.04041482135653496, -0.01538416463881731, -0.027836211025714874, 0.02065754309296608, -0.016250096261501312, -0.03457694500684738, -0.053764987736940384, 0.026997923851013184, 0.012905163690447807, -0.004101959057152271, -0.02776665985584259, 0.05910849571228027, -0.014414014294743538, 0.050857119262218475, 0.038851141929626465, -0.016282524913549423, 0.02518891543149948, -0.026087729260325432, -0.03305510804057121, 0.02216976508498192, -0.0039053952787071466, 0.013694040477275848, -0.0221298485994339, -0.027797576040029526, -0.0011915594805032015, -0.007480863481760025, -0.016381125897169113, 0.017663419246673584, 0.014857697300612926, 0.023431235924363136, -0.011799636296927929, 0.03854600340127945, 0.037194445729255676, -0.05080625042319298, -0.020098211243748665, 0.0673307552933693, 0.022276027128100395, -0.034825168550014496, 0.03017147071659565, -0.027791550382971764, 0.006816462147980928, -0.03781149163842201, -0.020953984931111336, -0.043938301503658295, 0.0027914312668144703, -0.02248712070286274, 0.01005855854600668, -0.03431257978081703, -0.017017632722854614, 0.02767207846045494, 0.009274711832404137, -0.03477705642580986, -0.00629466911777854, -0.0681423470377922, 0.011574131436645985, -0.024144046008586884, 0.0026187472976744175, 0.002703028032556176, 0.011161071248352528, -0.0060212258249521255, 0.034029535949230194, -0.05639689415693283, -0.03863426670432091, 0.010174469090998173, 0.05253658816218376, -0.014075728133320808, -0.03265226259827614, -0.024992510676383972, 0.011528972536325455, 0.009207744151353836, -0.005825603846460581, -0.025258511304855347, 0.033574026077985764, 0.026166468858718872, 0.026087643578648567, -0.04307663068175316, -0.021363327279686928, -0.013508902862668037, 0.004116468131542206, 0.009806372225284576, -0.002050402108579874, 0.027713358402252197, 0.04237114638090134, -0.0315786637365818, 0.04420502483844757, -0.020642215386033058, 0.03282264620065689, -0.02749662846326828, 0.002431955188512802, -0.03360886871814728, 0.015159702859818935, 0.016869869083166122, 0.01777544803917408, -0.0476861335337162, -0.012490407563745975, 0.004350193310528994, 0.012557080015540123, -0.045322440564632416, 0.024709464982151985, 0.029354119673371315, 0.08332397788763046, 0.044210441410541534, 0.0033741500228643417, 0.060736969113349915, -0.0028742405120283365, -0.032156988978385925, -0.05775963515043259, 0.025652745738625526, 0.03715457022190094, 0.01801668107509613, -0.0352611318230629, -0.026034167036414146, -0.009727555327117443, -0.009894144721329212, 0.0036579349543899298, 0.019533196464180946, -0.02895260602235794, -0.037215083837509155, -0.06663110852241516, 0.011477581225335598, -0.016870742663741112, 0.025052176788449287, -0.039382580667734146, 0.03268596529960632, -0.004679488949477673, -0.008717494085431099, 0.06370418518781662, 0.029027389362454414, -0.016063105314970016, -0.02174505405128002, -0.028589913621544838, -0.013060399331152439, -0.027176085859537125, -0.011712886393070221, 0.0193063635379076, -0.038190919905900955, 0.05651260167360306, 0.020638493821024895, -0.008916221559047699, 0.007584146689623594, -0.02961939573287964, 0.04155558720231056, 0.005563233979046345, -0.019629942253232002, -0.030223220586776733, -0.006983343046158552, 0.0012235332978889346, -0.012010931968688965, -0.04205256327986717, 0.006039526779204607, 0.011747929267585278, 0.02811821922659874, -0.011556061916053295, -0.025580281391739845, -0.026224898174405098, 0.024928957223892212, 0.00037219899240881205, 0.05311235412955284, 0.014088473282754421, -0.01064980961382389, -0.03467908874154091, 0.02803867869079113, 0.03289139270782471, -0.02485274337232113, -0.02201753854751587, 0.01745932176709175, -0.019170183688402176, -0.053663939237594604, 0.02072352170944214, -0.004754737485200167, 0.017304029315710068, 0.016627592965960503, 0.0027883125003427267, 0.025178125128149986, -0.036586612462997437, 0.022355519235134125, -0.02130008488893509, -0.0031267337035387754, 0.01218411885201931, 0.028981516137719154, -0.03857606276869774, -0.008088557980954647, 0.01750374771654606 ]
8a98a3e8f4fe8ffe2c483dbdada681b7ff1782e2
490
py
Python
stubs/micropython-esp32-1_12/urequests.py
RonaldHiemstra/micropython-stubs
d97f879b01f6687baaebef1c7e26a80909c3cff3
[ "MIT" ]
38
2020-10-18T21:59:44.000Z
2022-03-17T03:03:28.000Z
stubs/micropython-esp32-1_12/urequests.py
RonaldHiemstra/micropython-stubs
d97f879b01f6687baaebef1c7e26a80909c3cff3
[ "MIT" ]
176
2020-10-18T14:31:03.000Z
2022-03-30T23:22:39.000Z
stubs/micropython-esp32-1_12/urequests.py
RonaldHiemstra/micropython-stubs
d97f879b01f6687baaebef1c7e26a80909c3cff3
[ "MIT" ]
6
2020-12-28T21:11:12.000Z
2022-02-06T04:07:50.000Z
""" Module: 'urequests' on esp32 1.12.0 """ # MCU: (sysname='esp32', nodename='esp32', release='1.12.0', version='v1.12 on 2019-12-20', machine='ESP32 module (spiram) with ESP32') # Stubber: 1.3.2 class Response: '' def close(): pass content = None def json(): pass text = None def delete(): pass def get(): pass def head(): pass def patch(): pass def post(): pass def put(): pass def request(): pass usocket = None
12.564103
135
0.563265
1
0.8556
[ -0.0004808027879334986, 0.02679026871919632, 0.006280883681029081, 0.0016205579740926623, 0.006970399059355259, -0.0035202628932893276, -0.012939260341227055, 0.00393596151843667, -0.0069772182032465935, -0.001608148799277842, 0.002346083289012313, 0.009024900384247303, 0.008051461540162563, -0.015519068576395512, 0.0009530324605293572, 0.016456831246614456, -0.056754015386104584, 0.001925935037434101, -0.005877360235899687, 0.0015055184485390782, -0.005566259380429983, 0.010475441813468933, 0.008552227169275284, 0.007322072051465511, 0.006601876113563776, 0.0015848500188440084, 0.0075453585013747215, 0.005205023102462292, -0.007637377828359604, -0.0052328226156532764, 0.0016340536531060934, -0.0024171953555196524, -0.00582681130617857, -0.009642863646149635, 0.00706813670694828, -0.0027241259813308716, 0.0016891557024791837, -0.02127579227089882, 0.013118398375809193, -0.0048402524553239346, -0.00913162250071764, -0.017780357971787453, -0.0007415850413963199, 0.005430656019598246, -0.009956932626664639, 0.0010491720167919993, -0.004447021055966616, 0.005439369939267635, -0.01053490862250328, 0.005501108709722757, -0.007666741497814655, 0.005324102472513914, 0.013426077552139759, 0.0016368817305192351, -0.006129660177975893, -0.008555925451219082, 0.01177772507071495, -0.0009078201837837696, -0.012377976439893246, 0.0007943336386233568, -0.0018984844209626317, -0.0040803467854857445, 0.0034403414465487003, 0.005733533762395382, -0.017737073823809624, -0.004126615356653929, -0.005192925687879324, 0.001471316209062934, -0.0031042261980473995, 0.0053844875656068325, 0.0006450120126828551, 0.00013551526353694499, 0.007979609072208405, 0.003030594205483794, 0.0035960536915808916, -0.0004313079989515245, 0.0003948005032725632, 0.003969408106058836, 0.00737937493249774, 0.0008828250574879348, 0.00679151201620698, -0.007943122647702694, 0.00796694215387106, 0.010234708897769451, 0.013130010105669498, 0.008357754908502102, 0.017563365399837494, -0.01094084419310093, 0.04423864930868149, 0.006346484646201134, -0.012087298557162285, 0.0028434121049940586, -0.005698747932910919, -0.0046295966021716595, -0.002683604834601283, -0.02920304238796234, -0.0018360062967985868, -0.004912061616778374, 0.00030359666561707854, 0.0050231460481882095, -0.0011517932871356606, 0.00702024856582284, -0.0015897740377113223, -0.004022834822535515, -0.011641068384051323, 0.016396010294556618, -0.011742240749299526, -0.003718635533004999, 0.00581239303573966, 0.001187886344268918, -0.012728394009172916, -0.00264807534404099, 0.00306894164532423, -0.01019374094903469, 0.004332294687628746, 0.003469215938821435, -0.005587688181549311, 0.05567687377333641, 0.0001321365125477314, 0.0036095231771469116, -0.004007570445537567, 0.000006759762527508428, 0.0014909075107425451, 0.005875093396753073, 0.009680741466581821, -0.005581615958362818, 0.012731188908219337, 0.008730357512831688, 0.004539418034255505, 0.010822709649801254, -0.0027918359264731407, 0.009156267158687115, -0.0036205658689141273, -0.0010752941016107798, -0.0006652260199189186, -0.006468302570283413, 0.007017030380666256, -0.0016530250431969762, -0.0031746658496558666, 0.0014904186828061938, -0.001588234445080161, -0.011750172823667526, 0.0028640718664973974, -0.0019436025759205222, 0.003932537045329809, -0.012158744968473911, -0.003517623757943511, -0.0034098492469638586, -0.0033798941876739264, 0.0024103799369186163, 0.007852801121771336, 0.0050178105011582375, 0.003297220915555954, -0.007229710929095745, -0.007936641573905945, -0.003296389477327466, -0.005167674273252487, 0.002391355810686946, 0.009952345862984657, 0.002456823829561472, -0.008085652254521847, -0.0022747947368770838, 0.004228534642606974, 0.0019046139204874635, -0.0012753326445817947, -0.0012741218088194728, -0.006897783372551203, 0.008246772922575474, -0.0007559845689684153, 0.004367597866803408, 0.010721555911004543, -0.005130801349878311, 0.0013976185582578182, 0.0006989528774283826, 0.0018652043072506785, -0.002543400274589658, 0.005844437517225742, 0.009449370205402374, -0.0027613926213234663, -0.0036979448050260544, 0.004759118426591158, 0.002726835897192359, 0.009292962960898876, 0.007822411134839058, -0.001211102120578289, 0.00275389919988811, -0.001957067521288991, -0.0007416292792186141, 0.0044892216101288795, -0.0024563500192016363, 0.007896927185356617, 0.0038623635191470385, -0.014615585096180439, -0.007614758796989918, 0.0006183187942951918, -0.011642605066299438, 0.0015677025076001883, 0.014410537667572498, 0.0111140888184309, -0.003153858706355095, 0.0035765343345701694, -0.009270654059946537, 0.0023472108878195286, 0.0060636489652097225, 0.0016792776295915246, -0.011388611979782581, -0.9565090537071228, 0.003276462433859706, 0.002762875519692898, 0.0002016736107179895, 0.0051483577117323875, -0.0002936399541795254, 0.003329043509438634, 0.0036866595037281513, 0.014769123867154121, -0.010737910866737366, -0.008180039934813976, -0.008801388554275036, -0.01190735399723053, -0.00197068159468472, -0.00851393025368452, -0.0031613539904356003, -0.006460986565798521, -0.008427541702985764, -0.0030925930477678776, -0.0032866750843822956, -0.0018340040696784854, 0.010334315709769726, -0.001247763866558671, 0.005656679626554251, 0.0037871431559324265, 0.0024502247106283903, -0.006859804503619671, 0.0006571492413058877, 0.00015233135491143912, -0.003231954062357545, -0.0018035774119198322, -0.014111265540122986, -0.006224806420505047, -0.0005773957236669958, 0.01296407263725996, -0.0006134149734862149, 0.00791010819375515, 0.0005178266437724233, 0.00001256377527170116, -0.010133367963135242, 0.007325547747313976, 0.004320024978369474, 0.0012722123647108674, -0.03074190579354763, 0.00047561319661326706, -0.0010103777749463916, -0.007914703339338303, 0.00853727012872696, 0.0003639099304564297, -0.0018825079314410686, -0.0019217893714085221, -0.0039298683404922485, 0.009196382947266102, -0.008635547943413258, 0.005009953863918781, -0.007860666140913963, -0.006656786892563105, -0.003930026199668646, -0.009814133867621422, 0.0005693515995517373, 0.002770120045170188, -0.003854157403111458, -0.002087903441861272, -0.0027698101475834846, 0.0035657885018736124, 0.002959346631541848, 0.0011615778785198927, -0.01921997405588627, -0.0037579021882265806, -0.0004114695475436747, 0.005130655597895384, -0.0018194179283455014, -0.0028235409408807755, 0.007148680742830038, -0.009901893325150013, 0.0058852070942521095, 0.0013693521032109857, 0.002403292106464505, -0.012280878610908985, 0.002437074901536107, -0.008120075799524784, -0.008803147822618484, 0.0025809593498706818, -0.0033932889346033335, -0.00373692624270916, 0.0033046563621610403, 0.0036863796412944794, 0.005353898741304874, -0.00331162940710783, 0.004402225371450186, 0.010511447675526142, -0.003333642613142729, -0.008590610697865486, 0.006451621185988188, 0.007350396364927292, 0.0018336664652451873, -0.0016341228038072586, 0.001573399524204433, 0.007852095179259777, 0.00810849666595459, 0.002217883476987481, 0.0030907499603927135, 0.0006248987629078329, 0.011235611513257027, 0.0006040041917003691, 0.0015049295034259558, 0.00038163940189406276, -0.001710947253741324, -0.0029630304779857397, -0.0009647086262702942, -0.004025667440146208, -0.0009821359999477863, -0.011832230724394321, -0.010438750497996807, -0.00206967000849545, 0.0008339542546309531, 0.0017109133768826723, -0.004404601640999317, -0.0003732555196620524, 0.0008719247998669744, 0.009554204531013966, 0.00026091784820891917, -0.004399928729981184, -0.000722115277312696, 0.003694977844133973, -0.0032875812612473965, 0.013803300447762012, -0.011989585123956203, 0.0065769534558057785, -0.0009967968799173832, -0.015451006591320038, 0.008933363482356071, 0.009858912788331509, -0.007193024270236492, 0.0034661462996155024, 0.0005422593094408512, 0.004054044373333454, 0.0016495261806994677, -0.004259681794792414, -0.004189451690763235, -0.015718748793005943, 0.0016444356879219413, 0.02153908833861351, 0.0009983577765524387, 0.009740880690515041, 0.00974769052118063, -0.002218229230493307, 0.000469463731860742, 0.009062973782420158, 0.003043125383555889, 0.012156491167843342, -0.0055847493931651115, -0.0021845330484211445, -0.000531491357833147, -0.0068179708905518055, 0.0018514127004891634, 0.003297660266980529, 0.006956835277378559, -0.003983901347965002, 0.0015771727776154876, -0.004888436757028103, -0.0059411791153252125, -0.01562543585896492, -0.002084416104480624, 0.007644775323569775, -0.0057659149169921875, 0.005098422989249229, -0.012384066358208656, 0.0043408810161054134, 0.006667596288025379, 0.002163333585485816, -0.0004271049692761153, 0.0007775144185870886, 0.006687634624540806, 0.010157333686947823, -0.007526039145886898, 0.002583284629508853, 0.0011706124059855938, -0.003007375868037343, 0.003476665820926428, 0.005400928668677807, -0.006854631006717682, -0.0060143060982227325, 0.002844280796125531, 0.002760514849796891, -0.000010229657164018136, -0.004622478038072586, -0.011243137530982494, -0.004727842751890421, 0.0037244597915560007, -0.007188647985458374, 0.004248145967721939, 0.003537449287250638, 0.0038761780597269535, -0.0119566535577178, -0.001116655534133315, -0.006997182033956051, -0.010404296219348907, 0.011695927940309048, -0.0026367150712758303, 0.004522728733718395, 0.012270336039364338, 0.0038395205046981573, -0.012360517866909504, 0.00462718540802598, 0.006486879196017981, -0.005801270715892315, 0.004234032239764929, 0.005658742971718311, -0.004479605704545975, -0.02205309271812439, -0.002348550595343113, -0.016166668385267258, 0.005859874654561281, -0.0013452057028189301, 0.0056101493537425995, -0.00810987874865532, 0.009441479109227657, 0.0053772395476698875, -0.01046636514365673, -0.0020713284611701965, -0.009097583591938019, 0.007795413956046104, -0.0007423637434840202, -0.0027922012377530336, -0.00292306300252676, -0.0005145175964571536, -0.0026661274023354053, -0.0027726744301617146, -0.0008639578009024262, 0.004940554033964872, 0.002049426082521677, -0.005669384729117155, 0.0028588788118213415, -0.003551479196175933, -0.00001323941341979662, 0.004513365216553211, -0.013302762992680073, -0.0006486066849902272, 0.0101741012185812, -0.0005115652456879616, -0.003243537386879325, -0.0002269867982249707, -0.002000643638893962, -0.006558294873684645, -0.008729038760066032, -0.0021251272410154343, -0.005498524289578199, -0.003660497022792697, -0.009194239042699337, 0.00004542078386293724, -0.009149444289505482, 0.00838822778314352, -0.007240035571157932, 0.007376565132290125, 0.006466547027230263, -0.004667988978326321, 0.00769620668143034, -0.0016741561703383923, 0.004363646265119314, 0.0027510151267051697, 0.0038325043860822916, -0.0011325656669214368, -0.006059834733605385, -0.010606944561004639, 0.011677726171910763, -0.009831649251282215, 0.0029477339703589678, 0.015072879381477833, 0.006613881327211857, 0.007118804380297661, -0.0023278689477592707, -0.001811042777262628, 0.0032967820297926664, 0.00841573067009449, -0.013877451419830322, 0.0014631891390308738, -0.0017807872500270605, -0.001113130827434361, 0.00626079086214304, -0.004355571698397398, 0.00245138187892735, 0.008569139987230301, 0.0009221818181686103, -0.007993800565600395, -0.002491035033017397, 0.0006433591479435563, 0.0022826045751571655, -0.01203229371458292, 0.001016406575217843, -0.004807465244084597, -0.0029521130491048098, -0.00376817281357944, -0.001370282843708992, 0.0003214159223716706, 0.006085866596549749, -0.002154515590518713, 0.004845025949180126, 0.00013478350592777133, -0.0039961631409823895, 0.016506513580679893, -0.004622891079634428, -0.006189865060150623, 0.0017612857045605779, -0.00008908564632292837, -0.00042609142838045955, -0.006704250350594521, -0.0028474642895162106, 0.0002105197636410594, 0.006170901004225016, -0.003077571978792548, -0.007400342263281345, -0.00510989036411047, -0.000038147292798385024, -0.0069314828142523766, -0.00012522628821898252, 0.010628084652125835, -0.0016605318523943424, 0.005130245350301266, -0.0029923799447715282, -0.004165884107351303, -0.014436185359954834, 0.05652153119444847, -0.0018817516975104809, 0.004876317456364632, 0.004599553532898426, -0.00933439563959837, -0.0015802317066118121, -0.0011246033245697618, 0.0062842839397490025, -0.007675359956920147, -0.0062921540811657906, 0.009961471892893314, -0.0032965741120278835, 0.0029439020436257124, -0.0015239318599924445, -0.0018588814418762922, 0.011560051701962948, -0.003970281686633825, -0.015423445962369442, -0.015143060125410557, 0.00641880976036191, -0.0057996828109025955, -0.008067948743700981, 0.007061185780912638, -0.002387329703196883, -0.004045384936034679, 0.0008111367933452129, 0.006186988204717636, -0.0019631756003946066, -0.0008144490420818329, -0.003957659937441349, -0.0025194967165589333, 0.0008606474148109555, 0.002324120607227087, 0.004866443574428558, 0.008266672492027283, -0.0045955427922308445, 0.003966857213526964, -0.003266535699367523, -0.0011077538365498185, -0.0005671692197211087, 0.0047133807092905045, 0.007187152747064829, -0.0020350380800664425, -0.004082531668245792, 0.005528394132852554, 0.004150973167270422, 0.0027790230233222246, 0.01241968758404255, 0.0007597895455546677, -0.004443483892828226, 0.00689478637650609, 0.008412784896790981, -0.0020238286815583706, 0.009751128032803535, -0.003934380132704973, 0.0037540073972195387, 0.0025769516360014677, -0.005436610896140337, -0.0163293294608593, -0.002895897254347801, 0.004789635539054871, 0.00784969050437212, -0.0037450820673257113, 0.0014051501639187336, -0.004009018186479807, -0.0034415004774928093, -0.008559215813875198, -0.006413519848138094, -0.0014953825157135725, 0.0009637345792725682, 0.007117198780179024, 0.07032844424247742, -0.005794505123049021, -0.0014244640478864312, -0.008513454347848892, -0.000657675031106919, -0.001207389635965228, -0.0012141866609454155, -0.0016792288515716791, -0.0009328385931439698, 0.0007277854019775987, 0.002735511865466833, -0.008617785759270191, -0.009033909067511559, 0.000511139864102006, 0.0028817164711654186, -0.0027015116065740585, 0.004511796869337559, 0.004962461534887552, -0.009544345550239086, 0.0037252986803650856, -0.012475884519517422, -0.0002631506067700684, -0.003671285230666399, -0.009055550210177898, -0.005536810960620642, -0.004800489638000727, 0.006186050828546286, 0.004601080436259508, 0.007815130054950714, -0.004785034339874983, 0.008345086127519608, -0.001033034990541637, 0.0024759129155427217, -0.005638238973915577, 0.0001463598891859874, -0.00686350604519248, 0.006572092417627573, 0.0041833920404314995, -0.012266067788004875, -0.005997053813189268, -0.0024124695919454098, -0.0030125631019473076, -0.004409917164593935, 0.006861567497253418, 0.002153861802071333, 0.008087222464382648, -0.004083733540028334, 0.00042842020047828555, -0.006052544340491295, 0.0016655975487083197, -0.012910678051412106, 0.005324285943061113, -0.17959940433502197, 0.012645363807678223, 0.0027076154947280884, -0.005332487169653177, -0.004855849780142307, -0.015102595090866089, -0.00752588314935565, 0.004081482533365488, 0.010854440741240978, -0.000020986122763133608, -0.0007502200314775109, -0.002113698050379753, 0.004369958769530058, 0.0030288498383015394, 0.0004760372103191912, -0.002979918848723173, 0.001894584042020142, -0.003951935097575188, -0.000644270156044513, 0.006182472221553326, 0.004998913034796715, 0.007153976708650589, 0.0007824915228411555, 0.002506209071725607, -0.002229090081527829, -0.003449129406362772, 0.0033715039025992155, -0.00003145505252177827, 0.0037872358225286007, -0.010296976193785667, -0.002739085117354989, -0.005867526400834322, -0.005898293107748032, 0.0001874612644314766, 0.006105766166001558, -0.0003842498699668795, 0.008061602711677551, 0.001928348676301539, -0.006722839083522558, 0.0048350258730351925, -0.006880548316985369, 0.026527442038059235, 0.005452019162476063, 0.008526445366442204, 0.0009416104876436293, -0.004721473436802626, -0.004121460951864719, 0.011252195574343204, 0.00023012416204437613, 0.012709482572972775, -0.010091693140566349, -0.005051604937762022, 0.0016816032584756613, 0.01804349012672901, -0.004518471658229828, -0.00787681806832552, -0.007471952587366104, -0.005857392679899931, 0.006214183755218983, 0.012278402224183083, 0.010513060726225376, -0.005729201715439558, 0.00908317044377327, -0.003301833523437381, -0.021625205874443054, 0.0038667996414005756, -0.0037215817719697952, -0.007213178556412458, 0.0025425320491194725, 0.006503245793282986, 0.011659817770123482, -0.002495455089956522, 0.001737989136017859, -0.0009375021327286959, 0.000787976838182658, -0.0017355959862470627, 0.0057709719985723495, -0.0035799923352897167, 0.0059556919150054455, -0.007748173084110022, 0.010246139951050282, -0.010555381886661053, -0.002432148903608322, 0.004253458697348833, -0.005007746163755655, 0.01108579896390438, 0.006012681871652603, -0.0014994604280218482, 0.0007087910198606551, -0.011740734800696373, -0.0025398072320967913, -0.000005113725819683168, 0.004864901769906282, -0.00991753302514553, 0.0036266290117055178, -0.0023886000271886587, 0.005287629086524248, 0.00619225949048996, -0.007310471963137388, 0.004460361786186695, 0.003946898505091667, -0.008069857954978943, 0.0006592512363567948, -0.0070852478966116905, 0.0007671729545108974, 0.004026131238788366, -0.006384199485182762, -0.00972120650112629, 0.003927918151021004, -0.006137357093393803, -0.006380487699061632, 0.003982167690992355, -0.009292504750192165, -0.0068328287452459335, -0.0005588344065472484, -0.011777462437748909, 0.0025144610553979874 ]
8a995f399ed25fbe111acb3f8ad5749b538eef0a
433
py
Python
python/re_user.py
seckcoder/lang-learn
1e0d6f412bbd7f89b1af00293fd907ddb3c1b571
[ "Unlicense" ]
1
2017-10-14T04:23:45.000Z
2017-10-14T04:23:45.000Z
python/re_user.py
seckcoder/lang-learn
1e0d6f412bbd7f89b1af00293fd907ddb3c1b571
[ "Unlicense" ]
null
null
null
python/re_user.py
seckcoder/lang-learn
1e0d6f412bbd7f89b1af00293fd907ddb3c1b571
[ "Unlicense" ]
null
null
null
#!/usr/bin/env python #-*- coding=utf-8 -*- # # Copyright 2012 Jike Inc. All Rights Reserved. # Author: liwei@jike.com import re from urlparse import urlparse def parse1(): p = re.compile(r"/(?P<uid>\d+)/(?P<mid>\w+)") o = urlparse("http://weibo.com/2827699110/yz62AlEjF") m = p.search(o.path) print m.group('uid') print m.group('mid') def parse2(): exc_type_str = "<type 'exceptions.IndexError'>" parse1()
22.789474
57
0.637413
1
0.8256
[ 0.0037080259062349796, 0.026715965941548347, 0.007662884425371885, 0.00273848045617342, 0.005143814720213413, -0.0018014583038166165, -0.011137868277728558, 0.004027861170470715, -0.006373136304318905, 0.000213976702070795, 0.001464715925976634, 0.0034227147698402405, 0.007376377936452627, -0.01499906089156866, 0.0010676879901438951, 0.01708609238266945, -0.05526386946439743, 0.003627580590546131, -0.007467175368219614, 0.002452933695167303, -0.009364467114210129, 0.010577064007520676, 0.0071718525141477585, 0.0060765501111745834, 0.005834041628986597, 0.001033772830851376, 0.009430229663848877, 0.003767787478864193, -0.009325707331299782, -0.006017335224896669, -0.00037014042027294636, -0.00030269118724390864, -0.004410366993397474, -0.006525254342705011, 0.005288582760840654, -0.0016765217296779156, -0.00008877490472514182, -0.020305363461375237, 0.010459392331540585, -0.005771522410213947, -0.008572119288146496, -0.017242474481463432, -0.0012405065353959799, 0.0032830454874783754, -0.010143822059035301, 0.0015526501229032874, -0.005044902209192514, 0.0017348629189655185, -0.010364243760704994, 0.004320712760090828, -0.008631467819213867, 0.0035773422569036484, 0.012879249639809132, 0.004835524130612612, -0.005703653208911419, -0.006983964238315821, 0.011937522329390049, -0.0001598009985173121, -0.010206385515630245, -0.00035742775071412325, -0.005186876747757196, -0.0031310615595430136, 0.004174910485744476, 0.0036817153450101614, -0.01916380412876606, -0.00747639499604702, -0.005118942353874445, 0.00020240755111444741, -0.0010072356089949608, 0.0062173581682145596, 0.0016525201499462128, -0.0019314741948619485, 0.008700188249349594, 0.0015505892224609852, 0.005019023083150387, -0.0013294966192916036, 0.00008886987052392215, 0.0018617829773575068, 0.00745539553463459, 0.002328682690858841, 0.005751366727054119, -0.008259924128651619, 0.007516517303884029, 0.009062252938747406, 0.012667576782405376, 0.007667690981179476, 0.0176413431763649, -0.011867069639265537, 0.045384474098682404, 0.0070511470548808575, -0.009059736505150795, 0.0026496881619095802, -0.009721260517835617, -0.0022357809357345104, -0.004448771942406893, -0.03002058155834675, 0.00024276613839901984, -0.004094521980732679, 0.00119637546595186, 0.003385823220014572, -0.0003619858471211046, 0.005892620421946049, -0.0015733138425275683, -0.004237608518451452, -0.009047104977071285, 0.01405506394803524, -0.009292276576161385, -0.0016562092350795865, 0.0066041951067745686, 0.002079545985907316, -0.01063395757228136, -0.0026369313709437847, 0.0015614612493664026, -0.012523036450147629, 0.003649067133665085, 0.0005107651231810451, -0.0016522075748071074, 0.05519820749759674, -0.0008827772689983249, 0.0027046375907957554, -0.0036156184505671263, -0.0010873801074922085, 0.00030371066532097757, 0.0076418472453951836, 0.010929741896688938, -0.004238648805767298, 0.00924935657531023, 0.006553042680025101, 0.00461177434772253, 0.007848741486668587, -0.00314278993755579, 0.007846240885555744, -0.004689404740929604, -0.0016744420863687992, 0.0011743843788281083, -0.006591258104890585, 0.00890337210148573, -0.001263644895516336, -0.002888309769332409, 0.002802350325509906, -0.0028610422741621733, -0.011369405314326286, 0.0018156473524868488, -0.0027773205656558275, 0.003431816352531314, -0.009098789654672146, -0.0030411386396735907, -0.002811435144394636, -0.005000849720090628, 0.002665249863639474, 0.00875147245824337, 0.002866461407393217, 0.0035590159241110086, -0.004232681356370449, -0.006860267370939255, -0.0028510841075330973, -0.0024287051055580378, 0.0023893830366432667, 0.006152723450213671, 0.0024583390913903713, -0.009472902864217758, 0.00016022099589463323, 0.003570353612303734, 0.0036471413914114237, -0.0011629107175394893, -0.00025421485770493746, -0.008716397918760777, 0.007262576371431351, 0.000651868584100157, 0.005982099566608667, 0.013281993567943573, -0.002476668683812022, -0.0031102693174034357, -0.00020649834186770022, 0.002052954165264964, -0.0004999566008336842, 0.00597606785595417, 0.00932010542601347, -0.006759119685739279, -0.0038670676294714212, 0.0032184794545173645, 0.004861593712121248, 0.008918561972677708, 0.006310600787401199, -0.00032589107286185026, 0.0022682184353470802, -0.007040724158287048, -0.0005249567329883575, 0.0056604077108204365, -0.004394203890115023, 0.00881657563149929, 0.004889075178653002, -0.013928975909948349, -0.0057601616717875, -0.002683834871277213, -0.008639009669423103, 0.00019272744248155504, 0.01386465784162283, 0.010801412165164948, -0.00003970671241404489, 0.006486379541456699, -0.010693389922380447, -0.0011533752549439669, 0.0046290447935462, 0.0019651642069220543, -0.011830153875052929, -0.9582244753837585, 0.003526485525071621, 0.004366362001746893, -0.0020892589818686247, 0.0067796865478158, -0.0011002622777596116, 0.0013296047691255808, 0.003617237089201808, 0.011067540384829044, -0.009980124421417713, -0.006024026311933994, -0.010051694698631763, -0.01240498572587967, -0.0016886083176359534, -0.0064220791682600975, -0.004457290284335613, -0.0056210728362202644, -0.007161280140280724, -0.001569701242260635, -0.002736377064138651, -0.0031154672615230083, 0.009251143783330917, 0.000036533918319037184, 0.005537362769246101, 0.002232937840744853, 0.003783942200243473, -0.005975903011858463, -0.0016044903313741088, -0.0007067973492667079, -0.0020540475379675627, -0.0037743477150797844, -0.013434037566184998, -0.005858392454683781, 0.0010978428181260824, 0.011867443099617958, 0.0004390442918520421, 0.009698739275336266, -0.00007222910062409937, 0.001313983928412199, -0.010381398722529411, 0.0058678812347352505, 0.0019419901072978973, 0.004650300834327936, -0.031104279682040215, 0.0006357250385917723, -0.00045186420902609825, -0.007207334507256746, 0.00924240704625845, 0.000753368076402694, -0.0013911245623603463, -0.003549161832779646, -0.004708501510322094, 0.011037597432732582, -0.007899613119661808, 0.003495055716484785, -0.003331154817715287, -0.0063064428977668285, -0.0020804288797080517, -0.009125479497015476, 0.0019013350829482079, 0.004324017092585564, -0.0034968273248523474, -0.003284845966845751, -0.004378980491310358, 0.001771558541804552, 0.0025009997189044952, 0.0011759402696043253, -0.017802780494093895, -0.0058414023369550705, -0.002641383558511734, 0.0021459017880260944, -0.0013999327784404159, -0.0027936692349612713, 0.0026161500718444586, -0.010070647113025188, 0.008014648221433163, 0.0025508073158562183, 0.0023937958758324385, -0.011686545796692371, -0.0003408650809433311, -0.008928804658353329, -0.009932881221175194, 0.0007482212968170643, -0.0054499804973602295, -0.0050367084331810474, 0.0010702027939260006, 0.003043047385290265, 0.004769038874655962, -0.004491390194743872, 0.0021418025717139244, 0.011759079992771149, -0.000460437877336517, -0.007925717160105705, 0.004180593881756067, 0.006540730129927397, -0.00008298287139041349, -0.002793133957311511, 0.00671152351424098, 0.00900182593613863, 0.009155386127531528, -0.0001412644487572834, 0.00547107495367527, 0.0005259392783045769, 0.011724501848220825, -0.00042449613101780415, 0.000031815881811780855, -0.0007147003780119121, -0.0001475592580391094, -0.00198915577493608, -0.0014614446554332972, -0.004070328548550606, -0.0026405486278235912, -0.012888655066490173, -0.008609072305262089, -0.0030934391543269157, 0.0019992911256849766, 0.0032256932463496923, -0.0030432657804340124, 0.0003479170554783195, 0.0022214006166905165, 0.010830014944076538, 0.004712054505944252, -0.0030468199402093887, -0.0006998861208558083, 0.00188178732059896, -0.006401177495718002, 0.014346322044730186, -0.010408219881355762, 0.006788942497223616, -0.0021073075477033854, -0.014450816437602043, 0.00838436372578144, 0.009117730893194675, -0.007547768298536539, 0.003399064764380455, 0.0036348546855151653, 0.003485575783997774, -0.0027980105951428413, -0.006026216316968203, -0.004440874792635441, -0.01574128493666649, 0.0012884746538475156, 0.02008882537484169, 0.00000833464309835108, 0.010886565782129765, 0.011756190098822117, -0.0023729733657091856, 0.0026361241471022367, 0.007757960353046656, 0.0008950387127697468, 0.013335492461919785, -0.007611784152686596, -0.0016494040610268712, 0.001455171499401331, -0.006933456752449274, 0.0007857554592192173, 0.003556479001417756, 0.0047332365065813065, -0.0014576315879821777, 0.0020873313769698143, -0.007025968749076128, -0.0036500105634331703, -0.016919748857617378, -0.00331346713937819, 0.006557080894708633, -0.0049253772012889385, 0.002046971581876278, -0.01325618289411068, 0.004231120925396681, 0.00646193278953433, 0.004155244678258896, -0.00017883794498629868, 0.0018646082608029246, 0.005742660723626614, 0.00907426979392767, -0.008504064753651619, 0.004569374490529299, 0.002911330433562398, -0.0008442344260402024, 0.0003001354343723506, 0.008761022239923477, -0.006047186441719532, -0.005525824148207903, 0.0024708667770028114, 0.0023422399535775185, -0.0018153977580368519, -0.0038581478875130415, -0.007778566796332598, -0.00353302457369864, 0.00323657994158566, -0.007967284880578518, 0.004389308858662844, 0.0016392015386372805, 0.0028823090251535177, -0.00844546128064394, -0.0026282556354999542, -0.002845949260517955, -0.010956639423966408, 0.00916827842593193, -0.002532385289669037, 0.0010542625095695257, 0.012471471913158894, 0.004445904400199652, -0.012054267339408398, 0.006818546913564205, 0.00816621445119381, -0.0055282930843532085, 0.0029949666932225227, 0.008454837836325169, -0.0035169492475688457, -0.01974445767700672, -0.0023437640629708767, -0.014567951671779156, 0.004662603605538607, -0.0018341969698667526, 0.005125065799802542, -0.006758102681487799, 0.009291201829910278, 0.006711217109113932, -0.012803333811461926, -0.002205028897151351, -0.010075133293867111, 0.008291276171803474, -0.0013427812373265624, -0.0022889687679708004, -0.004537008702754974, -0.0018271575681865215, -0.002630945760756731, -0.001266470761038363, 0.000006874545761093032, 0.0030708767008036375, 0.0019488277612254024, -0.004466557409614325, 0.0016840653261169791, -0.0031247413717210293, 0.0018455804092809558, 0.003417130559682846, -0.010852319188416004, 0.002833132166415453, 0.006465883459895849, -0.003930850885808468, -0.003051015315577388, -0.0002744136727415025, 0.000983319478109479, -0.007691245060414076, -0.009852683171629906, -0.0038601423148065805, -0.004185279365628958, -0.004105123225599527, -0.012145571410655975, -0.0024717531632632017, -0.008544222451746464, 0.007582725957036018, -0.006852717138826847, 0.009571255184710026, 0.005893535912036896, -0.006601863075047731, 0.007951566949486732, -0.0008748892578296363, 0.0052991993725299835, 0.005040433723479509, 0.00393031956627965, -0.0005665567587129772, -0.004936178680509329, -0.010474457405507565, 0.013013459742069244, -0.010437387973070145, 0.0011642478639259934, 0.014569345861673355, 0.004757274407893419, 0.011047662235796452, -0.0015481621958315372, -0.0022807596251368523, 0.0016223150305449963, 0.007959525100886822, -0.012723876163363457, 0.0030852598138153553, -0.002593220677226782, -0.0012503835605457425, 0.005837223958224058, -0.005032089073210955, 0.001690226374194026, 0.00908599328249693, 0.0019078523619100451, -0.006701220758259296, -0.0009669263381510973, -0.001889786683022976, 0.002104602986946702, -0.013340967707335949, 0.0006424878956750035, -0.0058256350457668304, -0.002951275324448943, -0.002168777398765087, -0.0017301569459959865, -0.001037497422657907, 0.005745504051446915, -0.0009740868699736893, 0.0062379492446780205, 0.0017599359853193164, -0.004870646633207798, 0.015937289223074913, -0.0050011370331048965, -0.004804493393748999, 0.001553031150251627, 0.0018101446330547333, -0.0009247894049622118, -0.009345407597720623, -0.0027111407835036516, 0.0028970888815820217, 0.007272695191204548, -0.00037898379378020763, -0.005814042873680592, -0.002133970847353339, -0.00014397043560165912, -0.007831377908587456, 0.00245000422000885, 0.012287825345993042, -0.0017659002915024757, 0.004338954109698534, -0.0019759589340537786, -0.007631849963217974, -0.012237818911671638, 0.05608505755662918, -0.00019384780898690224, 0.0017933843191713095, 0.006489902269095182, -0.0070139337331056595, -0.000019942262952099554, -0.002967364154756069, 0.0051299105398356915, -0.007609518710523844, -0.006778289098292589, 0.009121205657720566, -0.0020618820562958717, 0.0034990927670150995, 0.0017881985986605287, -0.0034027157817035913, 0.014678901061415672, -0.007091955281794071, -0.01594107784330845, -0.014906702563166618, 0.0067324345000088215, -0.003850926412269473, -0.008914143778383732, 0.00900264922529459, -0.002984159393236041, -0.00407310901209712, 0.0030084436293691397, 0.004875292535871267, -0.002653056988492608, 0.0005993900122120976, -0.003155216109007597, -0.0022369343787431717, 0.0020542496349662542, 0.001003781333565712, 0.004511214792728424, 0.009837743826210499, -0.0029796003364026546, 0.003054508240893483, -0.001422640634700656, -0.0013552570017054677, -0.0009798207320272923, 0.004989174660295248, 0.006715389899909496, -0.00388200837187469, -0.0034444062039256096, 0.004117093048989773, 0.003253853414207697, 0.0010480138007551432, 0.01240065973252058, 0.0019138545030727983, -0.0051217591390013695, 0.00676471134647727, 0.009070420637726784, -0.0017839412903413177, 0.008082709275186062, -0.0025605594273656607, 0.006309944204986095, 0.0015502372989431024, -0.009235414676368237, -0.014070883393287659, -0.0026414752937853336, 0.004575419705361128, 0.007672821171581745, -0.0005527434987016022, 0.0014267750084400177, 0.00037407156196422875, -0.002653646282851696, -0.007131148129701614, -0.00834420695900917, -0.0039407555013895035, -0.0004505990073084831, 0.00347640342079103, 0.06968741863965988, -0.005708548706024885, 0.0003581270866561681, -0.008138628676533699, 0.000024910479623940773, -0.0013226887676864862, -0.0006235882756300271, 0.0010770121589303017, -0.0008734870352782309, 0.0017612605588510633, 0.0019776865374296904, -0.008647910319268703, -0.011662321165204048, 0.001469970098696649, 0.003830882254987955, -0.0017670673551037908, 0.0024860543198883533, 0.006331606302410364, -0.007200172636657953, 0.0023356066085398197, -0.011588272638618946, 0.0008648960501886904, -0.001017198315821588, -0.010686758905649185, -0.003655719570815563, -0.003921832423657179, 0.005270162131637335, 0.007613368332386017, 0.0036753248423337936, -0.002430014545097947, 0.007373889908194542, -0.001418583677150309, 0.00015003829321358353, -0.00667105708271265, -0.0010268841870129108, -0.006010622717440128, 0.005043090786784887, -0.00008655066631035879, -0.010316562838852406, -0.005193599034100771, -0.0011314457515254617, 0.0008417686331085861, -0.008164057508111, 0.004685583990067244, -0.000049047179345507175, 0.0072874752804636955, -0.002066367771476507, 0.0016146732959896326, -0.004249757155776024, 0.000500255438964814, -0.013538427650928497, 0.006381314247846603, -0.1741577684879303, 0.013729345984756947, 0.002104084473103285, -0.005795981269329786, -0.005692938342690468, -0.013672950677573681, -0.006043039262294769, 0.002347951987758279, 0.010726788081228733, 0.0003831080684904009, -0.0025276970118284225, -0.0003777158563025296, 0.005510535091161728, 0.0036261326167732477, -0.001938133267685771, -0.0033867612946778536, 0.0005878346273675561, -0.002405298873782158, -0.0015497627900913358, 0.0050658658146858215, 0.004956794902682304, 0.009611128829419613, 0.0019937781617045403, 0.0018218602053821087, -0.0016888391692191362, -0.00595858646556735, 0.004537210799753666, -0.0022976866457611322, 0.00708481902256608, -0.010067434050142765, -0.002988224383443594, -0.007006616331636906, -0.005691125523298979, 0.0012114167911931872, 0.0041753207333385944, -0.003372045699506998, 0.008798792026937008, 0.0020081091206520796, -0.005548924207687378, 0.006539179012179375, -0.007859596982598305, 0.028475703671574593, 0.004839968867599964, 0.00849093310534954, 0.0007488743867725134, -0.0032258823048323393, -0.0046888235956430435, 0.008794878609478474, 0.0016574912006035447, 0.010777110233902931, -0.01270460058003664, -0.00431780144572258, 0.0018086152849718928, 0.019502419978380203, -0.004887208808213472, -0.008283589966595173, -0.007875718176364899, -0.004097721539437771, 0.003584556747227907, 0.00928789097815752, 0.011095041409134865, -0.002723101293668151, 0.0060472008772194386, -0.004137231037020683, -0.02059525065124035, 0.002887820126488805, -0.00384821486659348, -0.008455597795546055, 0.0010651573538780212, 0.005194910801947117, 0.011602530255913734, -0.002069935668259859, 0.006127359811216593, -0.000499976275023073, 0.00419205566868186, -0.0005099447444081306, 0.006787647493183613, -0.004907731898128986, 0.005163326393812895, -0.007516138721257448, 0.009278244338929653, -0.010950454510748386, -0.001105812843888998, 0.0025785923935472965, -0.0047430070117115974, 0.011255965568125248, 0.005988599732518196, 0.0011858014622703195, -0.001063929172232747, -0.008994171395897865, -0.004270545672625303, 0.00014720979379490018, 0.004969298839569092, -0.007777123712003231, 0.005230701994150877, -0.00005885637801839039, 0.004785998724400997, 0.006420789286494255, -0.006763473618775606, 0.004999853670597076, 0.004271685611456633, -0.007813462056219578, 0.003900360083207488, -0.006349600851535797, -0.0003223523963242769, 0.004155771806836128, -0.007064979523420334, -0.007430978585034609, 0.002514646388590336, -0.005354385357350111, -0.006923899985849857, 0.0015818284591659904, -0.009543984197080135, -0.009953576140105724, -0.0023095414508134127, -0.013725508004426956, 0.0007970468141138554 ]
8a9978555063ed5f44aba19723290d6745163dd2
2,806
py
Python
TransactionBook/gui_kivy/generic/MultiSelectPopUp.py
LukHad/AccountBook
8da3ebbd2a824efb9d50f7695ceaaa6cf2370cd8
[ "MIT" ]
null
null
null
TransactionBook/gui_kivy/generic/MultiSelectPopUp.py
LukHad/AccountBook
8da3ebbd2a824efb9d50f7695ceaaa6cf2370cd8
[ "MIT" ]
null
null
null
TransactionBook/gui_kivy/generic/MultiSelectPopUp.py
LukHad/AccountBook
8da3ebbd2a824efb9d50f7695ceaaa6cf2370cd8
[ "MIT" ]
null
null
null
from kivy.uix.gridlayout import GridLayout from kivy.uix.label import Label from kivy.uix.textinput import TextInput from kivy.garden.matplotlib.backend_kivyagg import FigureCanvasKivyAgg from kivy.uix.anchorlayout import AnchorLayout from kivy.uix.boxlayout import BoxLayout from kivy.uix.button import Button import matplotlib.pyplot as plt import matplotlib import datetime from TransactionBook.model.Filter import Filter from datetime import datetime from kivy.uix.popup import Popup from kivy.properties import NumericProperty, ReferenceListProperty from kivy.uix.checkbox import CheckBox from kivy.core.window import Window class MultiSelectPopUp(Popup): pHint_x = NumericProperty(0.7) pHint_y = NumericProperty(0.7) pHint = ReferenceListProperty(pHint_x, pHint_y) def __init__(self, title, option_list, option_init=None, callback=None, multiselect=True, **kwargs): super().__init__(**kwargs) self.title = title self.callback = callback self.main_layout = AnchorLayout() if option_init is None: option_init = [True] * len(option_list) self.grid = GridLayout(cols=1) self.opt_boxes = [] self.labels = [] for i, opt in enumerate(option_list): box = BoxLayout(orientation='horizontal') check_box = CheckBox(active=option_init[i]) if not multiselect: check_box.group = "Single_Select_Only_Group" label = Label(text=str(opt)) self.opt_boxes.append(check_box) self.labels.append(label) box.add_widget(check_box) box.add_widget(label) self.grid.add_widget(box) cancel_button = Button(text="Cancel") cancel_button.bind(on_press=self.cancel_callback) ok_button = Button(text="Ok") ok_button.bind(on_press=self.ok_callback) box = BoxLayout(orientation='horizontal') box.add_widget(cancel_button) box.add_widget(ok_button) self.grid.add_widget(box) self.main_layout.add_widget(self.grid) self.content = self.main_layout self.size_hint = self.pHint Window.release_all_keyboards() self.open() def ok_callback(self, _): selection = [] for i, check_box in enumerate(self.opt_boxes): if check_box.active: selection.append(self.labels[i].text) self.callback(selection) self.dismiss() def cancel_callback(self, _): self.dismiss() if __name__ == "__main__": from kivy.base import runTouchApp def cb(list_of_selection): print(list_of_selection) c = MultiSelectPopUp(title="Test", option_list=["Item1", "Item2", "Item3"], callback=cb, option_init=[True, False, True]) runTouchApp(c)
35.075
125
0.679259
1
1.5411
[ 0.0027971058152616024, 0.021997028961777687, 0.009416873566806316, 0.0027911404613405466, 0.0050543444231152534, -0.0004543445538729429, -0.007709110621362925, 0.0010927349794656038, -0.0072433678433299065, 0.00544830271974206, 0.001853953581303358, 0.006373841315507889, 0.008074667304754257, -0.015069867484271526, -0.00014382883091457188, 0.015253083780407906, -0.050513770431280136, -0.0012136419536545873, -0.002674207789823413, 0.0023249436635524035, -0.00774361053481698, 0.008571125566959381, 0.006299032364040613, 0.0032152666244655848, 0.005233049392700195, -0.002645139116793871, 0.00950757134705782, 0.0031189387664198875, -0.007098586298525333, -0.007216313388198614, -0.002979226876050234, -0.0012863129377365112, -0.0038460097275674343, -0.008282801136374474, 0.002622198313474655, -0.004458940122276545, -0.0013770434306934476, -0.018602043390274048, 0.011150316335260868, -0.0016912396531552076, -0.0035466670524328947, -0.010484323836863041, -0.001200984581373632, 0.0020869772415608168, -0.006003956310451031, 0.00396868446841836, -0.006922772154211998, 0.0013478335458785295, -0.01206792239099741, 0.005894956644624472, -0.008515387773513794, 0.005435791797935963, 0.013438068330287933, 0.0012939950684085488, -0.00427792826667428, -0.007952462881803513, 0.014536458998918533, -0.0006471748929470778, -0.00914050918072462, 0.0006827566539868712, -0.0019616158679127693, -0.0005169045180082321, 0.004853190388530493, 0.002250243676826358, -0.014938920736312866, -0.006600033957511187, -0.004520414862781763, 0.004899091087281704, -0.0019172964384779334, 0.004874214064329863, 0.0024469862692058086, -0.002151259919628501, 0.006505073048174381, 0.003247940680012107, 0.0037362913135439157, -0.00468681612983346, 0.0002968423650600016, -0.0015050206566229463, 0.007934126071631908, 0.005331533029675484, 0.004964923951774836, -0.004834213759750128, 0.005425927694886923, 0.00680259894579649, 0.012626217678189278, 0.009241415187716484, 0.017629867419600487, -0.011997662484645844, 0.0470910370349884, 0.006698588840663433, -0.009816935285925865, 0.00510072335600853, -0.009648031555116177, -0.0029428249690681696, -0.006547070574015379, -0.025950029492378235, -0.0005952764768153429, -0.002869702409952879, 0.0014846306294202805, 0.003353349631652236, 0.001859229989349842, 0.00960666686296463, -0.002385795582085848, -0.0033700107596814632, -0.00938898604363203, 0.0075693693943321705, -0.008255983702838421, -0.0043942611664533615, 0.006656557787209749, 0.0015647662803530693, -0.0115879001095891, -0.0010339559521526098, 0.0013184086419641972, -0.013833455741405487, 0.003909089602530003, 0.006419165059924126, -0.005012750159949064, 0.051731742918491364, 0.0009678698261268437, 0.005433503072708845, -0.004393640905618668, 0.0034942550119012594, 0.002075962955132127, 0.006042021326720715, 0.0071884202770888805, -0.002009703777730465, 0.011057134717702866, 0.007121581584215164, 0.0022523074876517057, 0.009286143817007542, -0.0017118079122155905, 0.006038086488842964, -0.0035930396988987923, -0.0019154967740178108, 0.0007779332809150219, -0.0069709778763353825, 0.006573258899152279, -0.0035191900096833706, -0.008923371322453022, 0.0031517031602561474, -0.0011097063543274999, -0.01155294943600893, 0.002203563926741481, -0.003924191929399967, 0.006730375811457634, -0.010317145846784115, -0.0016551499720662832, -0.004580521024763584, -0.0046819644048810005, 0.002693586517125368, 0.009046241641044617, 0.004306321498006582, 0.003036998677998781, -0.005123501643538475, -0.007842193357646465, 0.000469563266960904, -0.0045128087513148785, -0.0012738533550873399, 0.007704904768615961, 0.004910357296466827, -0.009137284010648727, 0.0012913859682157636, 0.0011695086723193526, 0.002708602463826537, -0.00016394809063058347, 0.005126762669533491, -0.006657002028077841, 0.007662964053452015, -0.0007036600727587938, 0.005589096806943417, 0.00923925545066595, -0.0032572890631854534, 0.001062099589034915, -0.0021898839622735977, 0.002308954717591405, -0.0007572310278192163, 0.006077426485717297, 0.012056469917297363, -0.003963808063417673, -0.004023648798465729, 0.004817222710698843, 0.004728115629404783, 0.009325250051915646, 0.003120503155514598, -0.002018514322116971, 0.0008173941751010716, -0.0033170117530971766, -0.0025213416665792465, 0.0069300890900194645, -0.005962585099041462, 0.006760108284652233, 0.0035147119779139757, -0.012753876857459545, -0.009651755914092064, -0.00021886710601393133, -0.008698854595422745, 0.002601129934191704, 0.013367888517677784, 0.01178508996963501, -0.004455507267266512, 0.0029691059608012438, -0.009954199194908142, 0.0019067352404817939, 0.009514840319752693, 0.001783332321792841, -0.013437788933515549, -0.9611555933952332, 0.0075546978041529655, 0.004094269592314959, -0.0010890740668401122, 0.0038516621571034193, 0.0018539105076342821, 0.003414918202906847, 0.005699626170098782, 0.01323661208152771, -0.007317870855331421, -0.004311832599341869, -0.009554680436849594, -0.011825298890471458, -0.004056079313158989, -0.006296372041106224, -0.002780427224934101, -0.007678477093577385, -0.005822810344398022, -0.004989203065633774, -0.0013274822849780321, -0.0023600126150995493, 0.0069571430794894695, -0.0003822259895969182, 0.005992188584059477, 0.003131136065348983, 0.003637911519035697, -0.00042499712435528636, -0.0023284906055778265, -0.0032589903566986322, -0.00367559096775949, -0.007009006105363369, -0.012739337980747223, -0.004199422430247068, -0.001759190228767693, 0.008504938334226608, 0.0038645495660603046, 0.008980139158666134, -0.004195848014205694, 0.005275642964988947, -0.009130737744271755, 0.004887494258582592, 0.0002059715479845181, 0.0017465075943619013, -0.029297754168510437, -0.00044234638335183263, -0.0001832292036851868, -0.007466826122254133, 0.011160620488226414, 0.001353574451059103, 0.00017678468429949135, -0.004605370573699474, -0.0040449220687150955, 0.006954585667699575, -0.007275970187038183, 0.005635976791381836, -0.0037638801150023937, -0.008325085043907166, -0.0032174880616366863, -0.009096219204366207, 0.0026122722774744034, 0.0044558229856193066, -0.002004282781854272, -0.002499715192243457, -0.004929572343826294, 0.0025028178934007883, 0.001708471099846065, 0.0021742575336247683, -0.018869662657380104, -0.007908155210316181, 0.0006369973416440189, -0.0005790319410152733, -0.0017818488413468003, -0.0057926056906580925, 0.004657129757106304, -0.008635090664029121, 0.005079090595245361, 0.0025838674046099186, 0.000632596667855978, -0.0103781558573246, -0.001474949880503118, -0.01159728318452835, -0.006832770071923733, -0.00023536462686024606, -0.006815612781792879, -0.0041869888082146645, 0.000262247835053131, 0.0013422194169834256, 0.007677095476537943, -0.004009572323411703, 0.002798247616738081, 0.012631401419639587, -0.0025781949516385794, -0.006773041561245918, 0.0057205031625926495, 0.007798151578754187, 0.0020453326869755983, -0.0009574700379744172, 0.004782138392329216, 0.006778346840292215, 0.008552276529371738, 0.002942990744486451, 0.006946702487766743, 0.002573761623352766, 0.009536894969642162, -0.001431276905350387, -0.0019495104206725955, -0.006468849256634712, 0.0005396849592216313, -0.004204700235277414, -0.0006548354285769165, -0.0027240437921136618, -0.0019171375315636396, -0.011644558049738407, -0.010202608071267605, -0.0037993350997567177, -0.00212122336961329, 0.0033253540750592947, -0.004886418115347624, -0.0018993607955053449, 0.0026226993650197983, 0.007796273101121187, 0.00045493902871385217, -0.0034467042423784733, 0.00012990219693165272, 0.002568963449448347, -0.0036455532535910606, 0.015229565091431141, -0.011279911734163761, 0.00800049677491188, 0.0007747546187601984, -0.01417186576873064, 0.005253762472420931, 0.009338495321571827, -0.008461273275315762, -0.001930142636410892, 0.005554754287004471, 0.0018803796265274286, -0.002686033258214593, -0.0048642088659107685, -0.0013218946987763047, -0.01652330718934536, 0.0018104426562786102, 0.018434101715683937, 0.0019426604267209768, 0.009377558715641499, 0.010451417416334152, -0.0034860470332205296, 0.0009933769470080733, 0.00554026011377573, -0.0006895645055919886, 0.012874646112322807, -0.006441622506827116, 0.0003106434305664152, 0.003014356130734086, -0.006602135952562094, 0.002097603864967823, 0.007039361633360386, 0.004069625400006771, -0.0021892189979553223, 0.0014503812417387962, -0.006550388876348734, -0.004467344842851162, -0.01743702031672001, -0.00508129270747304, 0.009881919249892235, -0.003026627004146576, 0.006092458497732878, -0.012119860388338566, 0.004677262622863054, 0.005879614036530256, 0.008660928346216679, 0.0018362496048212051, 0.001292150467634201, 0.005488794296979904, 0.008666249923408031, -0.005930681712925434, 0.001629793900065124, 0.0036074090749025345, -0.00023073601187206805, 0.0005143156740814447, 0.008331071585416794, -0.00629632081836462, -0.006778826471418142, 0.0030371802859008312, 0.005456363782286644, 0.0004023832152597606, -0.003601428586989641, -0.007700827904045582, -0.0034996920730918646, 0.003214250784367323, -0.006423049606382847, 0.0031923954375088215, 0.001426814473234117, 0.0043638600036501884, -0.006349840201437473, -0.0013463401701301336, -0.0024372299667447805, -0.013291760347783566, 0.011480354703962803, -0.0035165774170309305, 0.0026240304578095675, 0.013510383665561676, 0.005498197861015797, -0.013944379054009914, 0.006722527556121349, 0.00876118615269661, -0.0025610027369111776, 0.005051143933087587, 0.005095303058624268, -0.006331081502139568, -0.02356339804828167, -0.004150214605033398, -0.011498156934976578, 0.004669488407671452, -0.002296796999871731, 0.003938682377338409, -0.007501553278416395, 0.004720337223261595, 0.007242762017995119, -0.014234226197004318, -0.003882759250700474, -0.009655906818807125, 0.008000989444553852, -0.0009619022021070123, 0.00021885664318688214, -0.005985081661492586, -0.0010521725052967668, -0.0012881633592769504, -0.005518755875527859, -0.003756121266633272, 0.00637019332498312, 0.001027751131914556, -0.001563964644446969, 0.00326165440492332, -0.0041787149384617805, 0.001446008333005011, 0.00010719912097556517, -0.009822461754083633, 0.0025486210361123085, 0.0009188384283334017, -0.0031747817993164062, -0.0022796890698373318, 0.0013754614628851414, -0.0025372838135808706, -0.008466355502605438, -0.010593519546091557, -0.004223176743835211, -0.0026332661509513855, -0.003748249029740691, -0.012619405053555965, -0.003172169905155897, -0.009706608951091766, 0.006939104292541742, -0.00815829448401928, 0.00876331701874733, 0.006258638575673103, -0.007529111113399267, 0.007177925202995539, -0.0024792358744889498, 0.003126247087493539, 0.0030534949619323015, 0.007675231900066137, 0.000977416057139635, -0.004950187634676695, -0.009214285761117935, 0.011334063485264778, -0.00835095439106226, 0.0003072319086641073, 0.014194832183420658, 0.0047951615415513515, 0.00891018658876419, 0.00022980821086093783, -0.002158257644623518, 0.0003655955079011619, 0.008046277798712254, -0.012162876315414906, 0.0046679130755364895, -0.0049396539106965065, -0.00012492173118516803, 0.003898183349519968, -0.0037753265351057053, 0.0005636619171127677, 0.009446073323488235, 0.001268989173695445, -0.006568555254489183, -0.0021095762494951487, 0.0017282833578065038, 0.0039919535629451275, -0.013057397678494453, 0.000937959470320493, -0.002956890733912587, -0.004892547614872456, -0.0026557918172329664, -0.0027661325875669718, 0.00022679948597215116, 0.004357152618467808, -0.004523085430264473, 0.004661876242607832, 0.0015846521127969027, -0.006498764269053936, 0.012314978986978531, -0.005127365700900555, -0.0032850883435457945, 0.003200590144842863, 0.002710675122216344, -0.0029161148704588413, -0.005224848166108131, -0.0042874678038060665, 0.00412607379257679, 0.0051854331977665424, -0.0037141519133001566, -0.0031730937771499157, -0.0011373821180313826, -0.0016008361708372831, -0.009676634334027767, -0.0007156934589147568, 0.011884868144989014, -0.0062581016682088375, 0.005766694899648428, -0.002252761973068118, -0.008195426315069199, -0.012003418058156967, 0.05172980949282646, -0.0008400696679018438, 0.003764805383980274, 0.002710141008719802, -0.005221844185143709, -0.0018682207446545362, -0.0015727580757811666, 0.007531908806413412, -0.005060846451669931, -0.007268794812262058, 0.009329651482403278, -0.004597863182425499, 0.003681219182908535, 0.004912613891065121, 0.00027944653993472457, 0.019311657175421715, -0.0007996053318493068, -0.015304137952625751, -0.01773562841117382, 0.005594747606664896, -0.003301817923784256, -0.008867769502103329, 0.010233691893517971, -0.003936257679015398, -0.0066909571178257465, 0.001459820312447846, 0.007060826290398836, 0.0007877848693169653, 0.0002770138962659985, -0.002959120785817504, -0.001986996503546834, -0.0004760231531690806, 0.0007000296609476209, 0.005607708357274532, 0.0072547090239822865, -0.003366941586136818, 0.004628211725503206, -0.0006844414165243506, -0.004103105515241623, -0.0030442632269114256, 0.0034029746893793344, 0.009598404169082642, -0.0017997444374486804, -0.0020858459174633026, 0.0039415485225617886, 0.0024081754963845015, 0.0023945511784404516, 0.010868746787309647, 0.000485140917589888, -0.006359277758747339, 0.006782150361686945, 0.005447548348456621, 0.00018800912948790938, 0.009951610118150711, -0.00022326939506456256, 0.00715444004163146, 0.004364084452390671, -0.008341477252542973, -0.01663128286600113, -0.0016274238005280495, 0.008517234586179256, 0.007686295080929995, 0.00004524799078353681, 0.0027905944734811783, -0.0025743471924215555, -0.0015861033461987972, -0.007195382844656706, -0.008783146739006042, -0.001966658513993025, 0.001019597053527832, 0.0053545753471553326, 0.06970630586147308, -0.00687514990568161, -0.0007990192389115691, -0.008432191796600819, 0.00038893509190529585, -0.001543466467410326, -0.0015772271435707808, 0.00295455870218575, -0.001082735019735992, 0.0026264525949954987, 0.002207475481554866, -0.006755569018423557, -0.013162694871425629, 0.00005781010986538604, 0.0018849630141630769, -0.0019859839230775833, 0.003236557822674513, 0.006798233836889267, -0.0113197211176157, 0.001081316266208887, -0.011091251857578754, -0.0015460326103493571, -0.0008780264179222286, -0.009742342866957188, -0.004436758812516928, -0.0033469228073954582, 0.00583347212523222, 0.005250981077551842, 0.0028638707008212805, -0.003596868133172393, 0.005185212939977646, -0.0027940564323216677, 0.0009243909153155982, -0.0038870691787451506, -0.0015401894925162196, -0.005006260704249144, 0.00802544690668583, 0.0014991490170359612, -0.011323733255267143, -0.0033503856975585222, -0.0012701308587566018, 0.0003485253837425262, -0.0050049531273543835, 0.0037876293063163757, -0.001972086727619171, 0.0030095663387328386, -0.003577095689252019, 0.0012958060251548886, -0.005388096906244755, 0.004206837620586157, -0.009245564229786396, 0.004415411036461592, -0.16383768618106842, 0.00981756392866373, 0.0036176443099975586, -0.006715551018714905, -0.003605281701311469, -0.01666114665567875, -0.007565781008452177, 0.003578083822503686, 0.009598352946341038, 0.0040202694945037365, -0.003577288007363677, -0.0024137436412274837, 0.0048014139756560326, 0.003520200727507472, -0.002288068877533078, -0.006312278565019369, 0.0023256265558302402, -0.007079288363456726, 0.00011738007742678747, 0.0032887703273445368, 0.005413722712546587, 0.012398667633533478, -0.0006420312565751374, 0.0013159518130123615, -0.0008648691000416875, -0.00541288685053587, 0.006123707629740238, -0.0032936986535787582, 0.003322192234918475, -0.009261604398488998, -0.005498315207660198, -0.0023149868939071894, -0.0023917662911117077, 0.0015185088850557804, 0.004234872758388519, 0.0002567523915786296, 0.00810077041387558, 0.0014530910411849618, -0.008674132637679577, 0.005699549801647663, -0.005811887327581644, 0.027508430182933807, 0.005753207486122847, 0.005998015403747559, 0.00013426541408989578, -0.007968120276927948, -0.006265138741582632, 0.009502902626991272, 0.0010424678912386298, 0.012688812799751759, -0.014731007628142834, 0.0014629884390160441, 0.002514507621526718, 0.01785297505557537, -0.005437305662781, -0.00876539759337902, -0.006917119491845369, -0.005275649484246969, -0.00043299945537000895, 0.008482038974761963, 0.012219381518661976, -0.001326628727838397, 0.008406423963606358, -0.004069948103278875, -0.020806334912776947, 0.001494658412411809, -0.002179230796173215, -0.006466803140938282, -0.0013838531449437141, 0.008423669263720512, 0.008771425113081932, 0.0009696913184598088, -0.0001230910129379481, -0.0011806456604972482, 0.0056243594735860825, -0.0012924601323902607, 0.006455539725720882, -0.0008050858741626143, 0.006519096437841654, -0.01021315436810255, 0.0042208279483020306, -0.0079567339271307, -0.0024367505684494972, -0.000244203838519752, -0.004002409055829048, 0.010482938028872013, 0.004389094654470682, -0.003628714242950082, -0.003705389564856887, -0.00992217194288969, -0.0015856673708185554, 0.003066181903705001, 0.003381372196599841, -0.010474532842636108, 0.003814565483480692, 0.0018390693003311753, 0.003950439393520355, 0.007978532463312149, -0.009973341599106789, 0.006454471033066511, 0.005079276394098997, -0.00606495002284646, 0.0007682672585360706, -0.004543791525065899, 0.005263037048280239, 0.004960005171597004, -0.008148044347763062, -0.007736699189990759, 0.002635076642036438, -0.006863636430352926, -0.006543458439409733, 0.006978696212172508, -0.008243762888014317, -0.011073408648371696, 0.00036473438376560807, -0.009689205326139927, 0.00013760798901785165 ]
8a9a247a499b63acd31b3bc3a6e73d3d156a0e43
1,903
py
Python
Assignment1/Part2/Bridge2.py
MormonJesus69420/Knowledge-Based-Systems-Project
8b1e330c64dd58743513f3e48efb6569457beb94
[ "WTFPL" ]
null
null
null
Assignment1/Part2/Bridge2.py
MormonJesus69420/Knowledge-Based-Systems-Project
8b1e330c64dd58743513f3e48efb6569457beb94
[ "WTFPL" ]
null
null
null
Assignment1/Part2/Bridge2.py
MormonJesus69420/Knowledge-Based-Systems-Project
8b1e330c64dd58743513f3e48efb6569457beb94
[ "WTFPL" ]
null
null
null
from dataclasses import dataclass, field from typing import List from Car2 import Car @dataclass class Bridge: """Bridge class simulating the behaviour of bridge in simulation. On can set specific length and capacity for the bridge to change the overall behaviour of bridge in the simulation and see how it impacts the scores for cars. """ capacity: int = field(default=5) """Set amount of cars that the bridge can accommodate before collapsing.""" length: int = field(default=10) """Length of bridge deciding how much time a car will use to cross it.""" cars: List[Car] = field(default_factory=list, repr=False, init=False) """List of all of the cars that are currently on the bridge.""" def has_collapsed(self) -> bool: """Simple method to check if bridge has collapsed. Returns: bool: True if bridge has collapsed, False otherwise. """ return len(self.cars) > self.capacity def move_cars(self) -> List[Car]: """ Moves cars across the bridge and returns cars that have crossed it. Returns: List[Car]: List of cars that have crossed the bridge this turn. """ finished_cars = list() for c in self.cars: c.distance_on_bridge += c.speed if c.distance_on_bridge >= self.length: c.distance_on_bridge = 0 finished_cars.append(c) self.cars = [c for c in self.cars if c not in finished_cars] return finished_cars def collapse_bridge(self) -> List[Car]: """Returns a list of all cars on bridge and sets cars to empty list. Returns: List[Car]: List of cars that were on bridge when it collapsed. """ temp = self.cars for c in temp: c.distance_on_bridge = 0 self.cars = list() return temp
28.833333
80
0.62743
0
0
[ 0.00028851881506852806, 0.023105967789888382, 0.0075750406831502914, -0.0004661802377086133, 0.006525018252432346, -0.0034364687744528055, -0.010187727399170399, 0.0007950454019010067, -0.0068130153231322765, 0.002421250334009528, 0.0024527518544346094, 0.006605654023587704, 0.0072178710252046585, -0.016527706757187843, -0.00036207406083121896, 0.017586132511496544, -0.05090373009443283, 0.0005902750417590141, -0.0025630013551563025, 0.0013840574538335204, -0.007159308530390263, 0.010433213785290718, 0.008888897486031055, 0.00731043191626668, 0.007980398833751678, 0.00016254732327070087, 0.009764159098267555, 0.00422722939401865, -0.008734273724257946, -0.005476727616041899, -0.0023356848396360874, -0.0031261236872524023, -0.008516019210219383, -0.008207588456571102, 0.005178214516490698, -0.0034180209040641785, -0.0009498447179794312, -0.02167442813515663, 0.011913000606000423, -0.0034572400618344545, -0.006704927887767553, -0.01515220571309328, -0.0012203287333250046, 0.002902762033045292, -0.009784135967493057, 0.0025470468681305647, -0.005463524255901575, 0.004848253447562456, -0.01054411567747593, 0.005810000468045473, -0.0101699810475111, 0.007420501206070185, 0.014634281396865845, 0.004799598827958107, -0.006984729785472155, -0.007278229109942913, 0.013257843442261219, 0.0019825429189950228, -0.01010169554501772, 0.0005446632858365774, -0.0031920031178742647, -0.0027347311843186617, 0.0057422444224357605, 0.0015923177124932408, -0.01761813834309578, -0.0069465916603803635, -0.005753794685006142, 0.0028826151974499226, -0.0016024563228711486, 0.0053703137673437595, -0.0013314656680449843, -0.0013328524073585868, 0.006223936565220356, 0.005395329091697931, 0.004482579883188009, -0.00397750549018383, -0.002230053534731269, 0.0006137529271654785, 0.008351156488060951, 0.0033254337031394243, 0.006739131174981594, -0.007553633768111467, 0.006300739943981171, 0.008035949431359768, 0.014094717800617218, 0.010349535383284092, 0.019383758306503296, -0.011442855931818485, 0.04735622927546501, 0.007486043032258749, -0.009540881961584091, 0.0027153685223311186, -0.010736647993326187, -0.002117316471412778, -0.005047073122113943, -0.02744087018072605, -0.000172760512214154, -0.003680463880300522, 0.000269318901700899, 0.003502094652503729, -0.0006555155850946903, 0.007228098344057798, -0.002747318707406521, -0.0007818825542926788, -0.0101883290335536, 0.013439581729471684, -0.010755553841590881, -0.003332596505060792, 0.00862192828208208, 0.001030021463520825, -0.011252744123339653, -0.0007943249656818807, 0.00010946954716928303, -0.011861836537718773, 0.0028986649122089148, 0.0005690304096788168, -0.006652117241173983, 0.053741294890642166, -0.001002614269964397, 0.007628401275724173, -0.00671722088009119, 0.0008107940666377544, 0.0006006752955727279, 0.005671210121363401, 0.009015331044793129, -0.0028914313297718763, 0.011356938630342484, 0.006903554778546095, 0.00241091032512486, 0.010636615566909313, -0.003652796149253845, 0.006418511737138033, -0.003919670358300209, -0.0032248948700726032, -0.00022873397392686456, -0.0066012232564389706, 0.004352879244834185, -0.0009429179481230676, -0.006433308124542236, 0.0037977162282913923, -0.0017846133559942245, -0.009223381988704205, 0.0006228722631931305, -0.0020312343258410692, 0.0060701388865709305, -0.010872852057218552, -0.0031273115891963243, -0.0031412749085575342, -0.002774876542389393, 0.0028533218428492546, 0.009250376373529434, 0.006095439195632935, 0.002032038290053606, -0.005646002013236284, -0.008089608512818813, -0.00042862616828642786, -0.005510617978870869, 0.00032339224708266556, 0.00878833420574665, 0.004798618145287037, -0.012836696580052376, -0.0008635774138383567, 0.0027932727243751287, 0.0026134243234992027, -0.003013600129634142, 0.005238457582890987, -0.007474575191736221, 0.00760286208242178, -0.0000966363659244962, 0.004919846076518297, 0.011626876890659332, -0.005760421045124531, -0.0013257049722597003, -0.0010795473353937268, 0.00226707779802382, -0.00034264425630681217, 0.004966116510331631, 0.010369167663156986, -0.003942397423088551, -0.005248452536761761, 0.005838806740939617, 0.003342375857755542, 0.009418437257409096, 0.005508919712156057, -0.00381252053193748, 0.001071029924787581, -0.004420730285346508, -0.0011842282256111503, 0.006511086132377386, -0.005889504216611385, 0.005944414995610714, 0.004273656755685806, -0.014305477030575275, -0.009856033138930798, -0.00033274898305535316, -0.008656180463731289, 0.0008921517292037606, 0.0159799512475729, 0.011551283299922943, -0.004120029974728823, 0.002086436143144965, -0.007764251437038183, 0.0007027384708635509, 0.007456943858414888, 0.0017154952511191368, -0.011654909700155258, -0.9568355083465576, 0.0066583226434886456, 0.00357124418951571, -0.0018566297367215157, 0.004376122262328863, 0.0044988710433244705, 0.005009707063436508, 0.003176899626851082, 0.017598163336515427, -0.007679427973926067, -0.007188850082457066, -0.011192191392183304, -0.013255057856440544, 0.0025638421066105366, -0.00889407005161047, -0.0038257737178355455, -0.006876632105559111, -0.008026499301195145, -0.00405730027705431, -0.003112482838332653, -0.001656083739362657, 0.008083265274763107, 0.0009527947404421866, 0.005436834879219532, 0.004557969514280558, 0.007600625976920128, -0.004993875045329332, -0.0012957153376191854, -0.00134739326313138, 0.00038096291245892644, -0.007205422967672348, -0.011738299392163754, -0.004340090323239565, -0.0026246621273458004, 0.012195535935461521, 0.000424336816649884, 0.006181386765092611, -0.0022644244600087404, 0.0028467937372624874, -0.008905808441340923, 0.004998538177460432, 0.0008858733344823122, 0.003521236125379801, -0.02910376712679863, 0.001415550708770752, -0.0008485891739837825, -0.012044740840792656, 0.008655357174575329, 0.0013453596038743854, -0.0013944244710728526, -0.0033537461422383785, -0.005402701441198587, 0.00930206011980772, -0.006048811133950949, 0.005320211872458458, -0.002053237287327647, -0.00938722025603056, -0.0025599664077162743, -0.008167431689798832, 0.00023730834072921425, 0.0055563426576554775, -0.004002089146524668, -0.0033973255194723606, -0.001861807075329125, 0.0039171879179775715, 0.0018015006789937615, 0.00665951007977128, -0.019589701667428017, -0.0077478159219026566, 0.002939813304692507, 0.003101853420957923, -0.003222176805138588, -0.004699218086898327, 0.0067346361465752125, -0.008368806913495064, 0.0050952257588505745, 0.0029617752879858017, 0.0018255385803058743, -0.014020653441548347, 0.0013336773263290524, -0.011050641536712646, -0.007332114968448877, 0.001567658968269825, -0.00503146555274725, -0.006463842932134867, 0.00025747279869392514, 0.002967366948723793, 0.005774497985839844, -0.003380734473466873, 0.004478067625313997, 0.007302762009203434, -0.0032779895700514317, -0.007303283084183931, 0.007802342064678669, 0.008261319249868393, -0.00023028149735182524, -0.003733085235580802, 0.004129099193960428, 0.007174957077950239, 0.007353664375841618, 0.0017392575973644853, 0.006702554412186146, 0.002433996181935072, 0.00791127048432827, -0.0002457100199535489, 0.0019702943973243237, -0.004696778953075409, 0.0008062879787757993, -0.004735125694423914, -0.0023766006343066692, -0.004876208025962114, -0.0032428139820694923, -0.01225120946764946, -0.007212805561721325, -0.004115026444196701, 0.0008390641887672246, 0.00221045664511621, -0.007117261178791523, -0.0006703618564642966, 0.0012837797403335571, 0.008266069926321507, -0.0017535784281790257, -0.0021912872325628996, -0.0005780262290500104, 0.0033596805296838284, -0.0073501053266227245, 0.013703562319278717, -0.010950836353003979, 0.007767822127789259, 0.0015023453161120415, -0.01635570451617241, 0.005338017363101244, 0.010253554210066795, -0.009665867313742638, 0.0035375875886529684, 0.0008425968699157238, 0.0038902699016034603, -0.0022070161066949368, -0.004694116767495871, -0.0030546733178198338, -0.017498020082712173, 0.00023209031496662647, 0.021822186186909676, 0.0018335306085646152, 0.011178070679306984, 0.008947713300585747, -0.004780787508934736, 0.002283526584506035, 0.005058215465396643, 0.00042254026629962027, 0.013295592740178108, -0.008390498347580433, -0.00029432380688376725, 0.002268037758767605, -0.006103344727307558, 0.0030972289387136698, 0.004716061055660248, 0.00518837571144104, -0.0031137866899371147, 0.0017659185687080026, -0.005673821084201336, -0.0054239388555288315, -0.015756791457533836, -0.0021434517111629248, 0.00891075748950243, -0.005316054914146662, 0.008434850722551346, -0.01000303030014038, 0.005100267473608255, 0.0053411368280649185, 0.0023325136862695217, -0.001039394992403686, -0.0009491216624155641, 0.005467353854328394, 0.011460687965154648, -0.006147898733615875, 0.00008294222789118066, 0.0032971890177577734, -0.0029685255140066147, -0.001615974004380405, 0.007396924775093794, -0.007323641330003738, -0.005029124673455954, 0.0012939571170136333, 0.0036461306735873222, -0.0005702219204977155, -0.003134793136268854, -0.009656228125095367, -0.003968920558691025, 0.005252145696431398, -0.006481262389570475, 0.0041670529171824455, 0.0016070589190348983, 0.00286126509308815, -0.0066520171239972115, -0.00023276482534129173, -0.005801677703857422, -0.012316869571805, 0.012710546143352985, -0.0037239291705191135, 0.0034402841702103615, 0.013719710521399975, 0.005356697365641594, -0.013533849269151688, 0.00875748973339796, 0.006889087613672018, -0.004403905011713505, 0.004732546862214804, 0.003938149660825729, -0.004304969683289528, -0.022357454523444176, -0.004148578736931086, -0.014041636139154434, 0.006072708405554295, -0.00271433824673295, 0.004297347739338875, -0.007522057741880417, 0.007021613419055939, 0.006406683009117842, -0.012167317792773247, -0.005515406373888254, -0.009094090200960636, 0.008317586034536362, -0.0000839532440295443, -0.0008929240866564214, -0.004372782073915005, -0.0021144042257219553, -0.0018878099508583546, -0.0025890888646245003, -0.0028994542080909014, 0.0066387467086315155, 0.004486368969082832, -0.002979741897433996, 0.0014075275976210833, -0.005263646598905325, -0.0011846510460600257, 0.0008666765061207116, -0.010509710758924484, 0.0019375021802261472, 0.0036352856550365686, -0.0019779286812990904, -0.0005315963644534349, -0.0005824342370033264, -0.002007080940529704, -0.007151531986892223, -0.009553924202919006, -0.0037326845340430737, -0.0047342851758003235, -0.002901120111346245, -0.009946348145604134, -0.003362864488735795, -0.010222860611975193, 0.0068583302199840546, -0.008430331945419312, 0.0060501666739583015, 0.006457755342125893, -0.0038267120253294706, 0.008170046843588352, -0.0000799696717876941, 0.003609076142311096, 0.000595169491134584, 0.0055086310021579266, 0.0015727608697488904, -0.006881134118884802, -0.008514721877872944, 0.012403300032019615, -0.009289148263633251, 0.00027485829195939004, 0.014129113405942917, 0.0032212554942816496, 0.00851677730679512, 0.00024568260414525867, -0.000012234535461175255, 0.004645160865038633, 0.00720316031947732, -0.014360979199409485, 0.006023019552230835, -0.004276718012988567, 0.00004865546725341119, 0.003717392683029175, -0.0038146849256008863, -0.00010472535359440371, 0.009629888460040092, 0.0016316146356984973, -0.006619906518608332, -0.0020634934771806, 0.001124839996919036, 0.005422850139439106, -0.011941972188651562, 0.0006987053784541786, -0.005024649202823639, -0.005420302040874958, -0.0036589677911251783, -0.0026967243757098913, 0.0016409719828516245, 0.0051501174457371235, -0.0021305293776094913, 0.006520428694784641, 0.00006964431668166071, -0.004838067572563887, 0.014148102141916752, -0.005124249495565891, -0.00464896485209465, 0.0025373604148626328, 0.002054816111922264, -0.004772590473294258, -0.007714478764683008, -0.004485649988055229, 0.0017925831489264965, 0.006348751951009035, 0.00031453644623979926, -0.004491458181291819, -0.00242401659488678, -0.00046615515020675957, -0.009779384359717369, 0.0034149710554629564, 0.013120284304022789, -0.004767256323248148, 0.005697545129805803, -0.0017811545403674245, -0.00749231455847621, -0.015110884793102741, 0.05355245620012283, -0.0006037579150870442, 0.004080663900822401, 0.0032315540593117476, -0.007928289473056793, -0.0019173293840140104, -0.0005293875001370907, 0.010100169107317924, -0.006130163557827473, -0.008189909160137177, 0.008348965086042881, -0.0033397988881915808, 0.0024966972414404154, 0.0042701237834990025, 0.00019578923820517957, 0.014586509205400944, -0.00476682186126709, -0.016050133854150772, -0.01671420782804489, 0.00896492600440979, -0.0028871239628642797, -0.007194404024630785, 0.010085256770253181, -0.0019513472216203809, -0.004143590107560158, 0.002267078962177038, 0.007070712745189667, -0.0001874092995421961, 0.0023257387802004814, -0.004870627075433731, -0.0021798734087496996, 0.0008432934409938753, 0.0035179504193365574, 0.006485560908913612, 0.006465031765401363, -0.0027511001098901033, 0.00294505269266665, -0.001883261022157967, -0.000563984620384872, -0.003131820820271969, 0.006072350312024355, 0.008142017759382725, -0.0004434203146956861, -0.0022462953347712755, 0.0037505540531128645, 0.004987836349755526, 0.0034317343961447477, 0.012132597155869007, 0.001087552634999156, -0.00808004755526781, 0.00932346936315298, 0.005650521256029606, -0.00048439722741022706, 0.009809193201363087, -0.0034358666744083166, 0.005873780231922865, 0.002188735408708453, -0.007243973668664694, -0.01675933599472046, -0.0005417942884378135, 0.009295850992202759, 0.008715825155377388, -0.0019325630273669958, -0.000002528953700675629, -0.0024307589046657085, 0.00010054937592940405, -0.0073472075164318085, -0.00846691895276308, -0.003670537145808339, -0.00024934299290180206, 0.00572581822052598, 0.06916844844818115, -0.006954851094633341, -0.0032777960877865553, -0.009717077016830444, 0.002258570631965995, -0.002581913722679019, -0.0013687973842024803, 0.000922627339605242, -0.0025575957261025906, 0.005457543767988682, 0.0006201891228556633, -0.008436731062829494, -0.011275586672127247, 0.002735346322879195, 0.0007879132754169405, -0.002522990806028247, 0.0035699796862900257, 0.0061125182546675205, -0.009212804958224297, 0.002601596526801586, -0.012655351310968399, -0.0032999427057802677, -0.002978996839374304, -0.009482461027801037, -0.0047228396870195866, -0.004789744038134813, 0.004971848800778389, 0.0017558978870511055, 0.006487717851996422, -0.005382746923714876, 0.004945485386997461, -0.0032637212425470352, 0.0010266813915222883, -0.004624688066542149, 0.0017315365839749575, -0.007082081399857998, 0.007624584715813398, 0.004058884456753731, -0.012880884110927582, -0.005553700029850006, -0.0001638176618143916, -0.0012096576392650604, -0.0052394806407392025, 0.007720657624304295, -0.00029044944676570594, 0.007242266554385424, -0.003785267472267151, 0.001521331607364118, -0.005683545023202896, 0.002660484751686454, -0.014188027009367943, 0.005252615083009005, -0.17873439192771912, 0.007982057519257069, 0.00209127482958138, -0.007093111518770456, -0.0037772401701658964, -0.015854453667998314, -0.00810143630951643, 0.00598847446963191, 0.009311811067163944, 0.0025242248084396124, -0.00031291760387830436, -0.001769543974660337, 0.004613211844116449, 0.003946519456803799, -0.0005679085734300315, -0.007284089922904968, 0.003620715346187353, -0.005418297369033098, 0.0003256287891417742, 0.0035192721989005804, 0.005750603508204222, 0.012259220704436302, -0.001148055074736476, 0.002188996644690633, -0.0010915983002632856, -0.004301370121538639, 0.00604829890653491, -0.0008053192868828773, 0.006028053816407919, -0.01081143505871296, -0.004518561530858278, -0.004887305665761232, -0.0035111422184854746, 0.0017689535161480308, 0.0036741241347044706, -0.0001202850544359535, 0.008545697666704655, 0.0033885964658111334, -0.00835807528346777, 0.00838698260486126, -0.007155528292059898, 0.027352841570973396, 0.006308459211140871, 0.00800042413175106, 0.0033025082666426897, -0.0067805456928908825, -0.004869798664003611, 0.007595027796924114, -0.00003537076918291859, 0.013636807911098003, -0.013772862032055855, -0.003133338876068592, 0.002283623442053795, 0.01836799457669258, -0.004102711100131273, -0.009960323572158813, -0.006215523462742567, -0.0018636230379343033, 0.0011324724182486534, 0.00970743503421545, 0.01029379665851593, -0.004243860486894846, 0.006867002695798874, -0.003874746849760413, -0.022001273930072784, 0.0031634632032364607, -0.0030684885568916798, -0.007736548315733671, 0.0021534741390496492, 0.007430500816553831, 0.007712360937148333, -0.000894424389116466, 0.0026359031908214092, 0.0007426573429256678, 0.0049390895292162895, -0.0010909492848441005, 0.005269796587526798, 0.00019431934924796224, 0.005290416069328785, -0.011245861649513245, 0.01016289833933115, -0.010491814464330673, -0.0019547755364328623, 0.0016342061571776867, -0.003922971431165934, 0.012443304993212223, 0.005050519481301308, -0.0035817064344882965, -0.001688693417236209, -0.008966720663011074, -0.0024273530580103397, 0.0034113354049623013, -0.00008814086322672665, -0.009064225479960442, 0.0005671124090440571, -0.00015831856580916792, 0.004754752852022648, 0.006020418368279934, -0.00637245737016201, 0.007026455830782652, 0.00476464768871665, -0.00769830821081996, 0.0035818980541080236, -0.005333364475518465, 0.004554308485239744, 0.004962762352079153, -0.006021702662110329, -0.005492222961038351, 0.0033810515888035297, -0.006185692269355059, -0.007282074075192213, 0.008016442880034447, -0.009018355049192905, -0.010426602326333523, -0.00032875375472940505, -0.013705810531973839, 0.002043280517682433 ]
8a9ada50ee04b4224d0c5731fe46fe28317d335c
19,192
py
Python
lib/tuner_interface.py
jefflundberg/locast2plex
3ab747a13c47888507c08f17d0afacad09894019
[ "MIT" ]
null
null
null
lib/tuner_interface.py
jefflundberg/locast2plex
3ab747a13c47888507c08f17d0afacad09894019
[ "MIT" ]
null
null
null
lib/tuner_interface.py
jefflundberg/locast2plex
3ab747a13c47888507c08f17d0afacad09894019
[ "MIT" ]
null
null
null
import subprocess import threading import time import errno import socket import urllib import pathlib from io import StringIO from http.server import BaseHTTPRequestHandler, HTTPServer import lib.stations as stations import lib.epg2xml as epg2xml import lib.channels_m3u as channels_m3u from lib.templates import templates # with help from https://www.acmesystems.it/python_http # and https://stackoverflow.com/questions/21631799/how-can-i-pass-parameters-to-a-requesthandler class PlexHttpHandler(BaseHTTPRequestHandler): # using class variables since this should only be set once config = None hdhr_station_scan = False rmg_station_scans = [] local_locast = None location = None def do_GET(self): base_url = self.config['main']['plex_accessible_ip'] + ':' + self.config['main']['plex_accessible_port'] contentPath = self.path queryData = {} if self.path.find('?') != -1: contentPath = self.path[0:self.path.find('?')] getdata = self.path[(self.path.find('?') + 1):] getdataElements = getdata.split('&') for getdataItem in getdataElements: getdataItemSplit = getdataItem.split('=') if len(getdataItemSplit) > 1: queryData[getdataItemSplit[0]] = getdataItemSplit[1] # paths and logic mostly pulled from telly:routes.go: https://github.com/tellytv/telly if (contentPath == '/') and (not self.config['main']['use_old_plex_interface']): self.do_response(200, 'application/xml', templates['xmlRmgIdentification'].format(self.config['main']['reporting_friendly_name'])) elif (contentPath == '/') or (contentPath == '/device.xml'): templateName = 'xmlDiscover' if self.config['main']['use_old_plex_interface']: templateName = 'xmlDiscoverOld' self.do_response(200, 'application/xml', templates[templateName].format(self.config['main']['reporting_friendly_name'], self.config['main']['reporting_model'], self.config['main']['uuid'], base_url)) elif contentPath == '/discover.json': self.do_response(200, 'application/json', templates['jsonDiscover'].format(self.config['main']['reporting_friendly_name'], self.config['main']['reporting_model'], self.config['main']['reporting_firmware_name'], self.config['main']['tuner_count'], self.config['main']['reporting_firmware_ver'], self.config['main']['uuid'], base_url)) elif contentPath == '/lineup_status.json': if self.hdhr_station_scan: returnJSON = templates['jsonLineupStatus'] else: returnJSON = templates['jsonLineupComplete'].replace("Antenna", self.config['main']['tuner_type']) self.do_response(200, 'application/json', returnJSON) elif contentPath == '/lineup.json': # TODO station_list = stations.get_dma_stations_and_channels(self.config, self.location) returnJSON = '' for index, list_key in enumerate(station_list): sid = str(list_key) returnJSON = returnJSON + templates['jsonLineupItem'].format(station_list[sid]['channel'], station_list[sid]['friendlyName'], base_url + '/watch/' + sid) if (index + 1) != len(station_list): returnJSON = returnJSON + ',' returnJSON = "[" + returnJSON + "]" self.do_response(200, 'application/json', returnJSON) elif contentPath == '/lineup.xml': # TODO station_list = stations.get_dma_stations_and_channels(self.config, self.location) returnXML = '' for list_key in station_list: sid = str(list_key) returnXML = returnXML + templates['xmlLineupItem'].format(station_list[sid]['channel'], station_list[sid]['friendlyName'], base_url + '/watch/' + sid) returnXML = "<Lineup>" + returnXML + "</Lineup>" self.do_response(200, 'application/xml', returnXML) elif contentPath.startswith('/watch'): self.do_tuning(contentPath.replace('/watch/', '')) elif contentPath.startswith('/auto/v'): self.do_tuning(contentPath.replace('/auto/v', '')) elif ((contentPath.startswith('/devices/' + self.config['main']['uuid'] + '/media/')) and (not self.config['main']['use_old_plex_interface'])): channel_no = contentPath.replace('/devices/' + self.config['main']['uuid'] + '/media/', '') channel_no = urllib.parse.unquote(channel_no).replace('id://', '').replace('/', '') station_list = stations.get_dma_stations_and_channels(self.config, self.location) for sid in station_list: if station_list[sid]['channel'] == channel_no: break self.do_tuning(sid) elif contentPath == '/xmltv.xml': self.do_response(200, 'application/xml', epg2xml.get_epg(self.config, self.location)) elif contentPath == '/channels.m3u': self.do_response(200, 'application/vnd.apple.mpegurl', channels_m3u.get_channels_m3u(self.config, self.location, base_url)) elif contentPath == '/debug.json': self.do_response(200, 'application/json') elif ((contentPath == '/devices/' + self.config['main']['uuid']) and (not self.config['main']['use_old_plex_interface'])): tuner_list = "" for index, scan_status in enumerate(self.rmg_station_scans): if scan_status == 'Idle': tuner_list = tuner_list + templates['xmlRmgTunerIdle'].format(str(index)) elif scan_status == 'Scan': tuner_list = tuner_list + templates['xmlRmgTunerScanning'].format(str(index)) else: # otherwise, we're streaming, and the value will be the channel triplet formatted_xml = templates['xmlRmgTunerStreaming'].format(str(index), scan_status) tuner_list = tuner_list + formatted_xml self.do_response(200, 'application/xml', templates['xmlRmgDeviceIdentity'].format(self.config['main']['uuid'], self.config['main']['reporting_friendly_name'], self.config['main']['reporting_model'], self.config['main']['tuner_count'], base_url, tuner_list)) elif((contentPath == '/devices/' + self.config['main']['uuid'] + '/channels') and (not self.config['main']['use_old_plex_interface'])): station_list = stations.get_dma_stations_and_channels(self.config, self.location) channelXML = '' for index, list_key in enumerate(station_list): sid = str(list_key) tmpXML = templates['xmlRmgDeviceChannelItem'].format(station_list[sid]['channel'], station_list[sid]['friendlyName']) channelXML = channelXML + tmpXML self.do_response(200, 'application/xml', templates['xmlRmgDeviceChannels'].format(index + 1, channelXML)) elif ((contentPath == '/devices/' + self.config['main']['uuid'] + '/scanners') and (not self.config['main']['use_old_plex_interface'])): self.do_response(200, 'application/xml', templates['xmlRmgScanProviders'].format(self.location['city'])) else: print("Unknown request to " + contentPath) self.do_response(501, 'text/html', templates['htmlError'].format('501 - Not Implemented')) return def do_POST(self): base_url = self.config['main']['plex_accessible_ip'] + ':' + self.config['main']['plex_accessible_port'] contentPath = self.path queryData = {} if self.headers.get('Content-Length') != '0': postdata = self.rfile.read(int(self.headers.get('Content-Length'))) postdataElements = postdata.split('&') for postdataItem in postdataElements: postdataItemSplit = postdataItem.split('=') if len(postdataItemSplit) > 1: queryData[postdataItemSplit[0]] = postdataItemSplit[1] if self.path.find('?') != -1: contentPath = self.path[0:self.path.find('?')] getdata = self.path[(self.path.find('?') + 1):] getdataElements = getdata.split('&') for getdataItem in getdataElements: getdataItemSplit = getdataItem.split('=') if len(getdataItemSplit) > 1: queryData[getdataItemSplit[0]] = getdataItemSplit[1] if contentPath == '/lineup.post': if queryData['scan'] == 'start': self.hdhr_station_scan = True for index, scan_status in enumerate(self.rmg_station_scans): if scan_status == 'Idle': self.rmg_station_scans[index] = "Scan" self.do_response(200, 'text/html') # putting this here after the response on purpose stations.refresh_dma_stations_and_channels(self.config, self.locast, self.location) self.hdhr_station_scan = False for index, scan_status in enumerate(self.rmg_station_scans): if scan_status == 'Scan': self.rmg_station_scans[index] = "Idle" elif queryData['scan'] == 'abort': self.do_response(200, 'text/html') self.hdhr_station_scan = False for index, scan_status in enumerate(self.rmg_station_scans): if scan_status == 'Scan': self.rmg_station_scans[index] = "Idle" else: print("Unknown scan command " + queryData['scan']) self.do_response(400, 'text/html', templates['htmlError'].format(queryData['scan'] + ' is not a valid scan command')) elif ((contentPath.startswith('/devices/discover') or contentPath.startswith('/devices/probe')) and (not self.config['main']['use_old_plex_interface'])): self.do_response(200, 'application/xml', templates['xmlRmgDeviceDiscover'].format(self.config['main']['uuid'], self.config['main']['reporting_friendly_name'], self.config['main']['reporting_model'], self.config['main']['tuner_count'], base_url)) elif ((contentPath == '/devices/' + self.config['main']['uuid'] + '/scan') and (not self.config['main']['use_old_plex_interface'])): self.hdhr_station_scan = True for index, scan_status in enumerate(self.rmg_station_scans): if scan_status == 'Idle': self.rmg_station_scans[index] = "Scan" self.do_response(200, 'application/xml', templates['xmlRmgScanStatus']) # putting this here after the response on purpose stations.refresh_dma_stations_and_channels(self.config, self.local_locast, self.location) self.hdhr_station_scan = False for index, scan_status in enumerate(self.rmg_station_scans): if scan_status == 'Scan': self.rmg_station_scans[index] = "Idle" else: print("Unknown request to " + contentPath) return def do_DELETE(self): base_url = self.config['main']['plex_accessible_ip'] + ':' + self.config['main']['plex_accessible_port'] contentPath = self.path queryData = {} if self.headers.get('Content-Length') != '0': postdata = self.rfile.read(int(self.headers.get('Content-Length'))) postdataElements = postdata.split('&') for postdataItem in postdataElements: postdataItemSplit = postdataItem.split('=') if len(postdataItemSplit) > 1: queryData[postdataItemSplit[0]] = postdataItemSplit[1] if self.path.find('?') != -1: contentPath = self.path[0:self.path.find('?')] getdata = self.path[(self.path.find('?') + 1):] getdataElements = getdata.split('&') for getdataItem in getdataElements: getdataItemSplit = getdataItem.split('=') if len(getdataItemSplit) > 1: queryData[getdataItemSplit[0]] = getdataItemSplit[1] if ((contentPath == '/devices/' + self.config['main']['uuid'] + '/scan') and (not self.config['main']['use_old_plex_interface'])): self.hdhr_station_scan = False for index, scan_status in enumerate(self.rmg_station_scans): if scan_status == 'Scan': self.rmg_station_scans[index] = "Idle" def do_tuning(self, sid): channelUri = self.local_locast.get_station_stream_uri(sid) station_list = stations.get_dma_stations_and_channels(self.config, self.location) tuner_found = False # keep track of how many tuners we can use at a time for index, scan_status in enumerate(self.rmg_station_scans): # the first idle tuner gets it if scan_status == 'Idle': self.rmg_station_scans[index] = station_list[sid]['channel'] tuner_found = True break if tuner_found: self.send_response(200) self.send_header('Content-type', 'video/mpeg; codecs="avc1.4D401E') self.end_headers() ffmpeg_command = [self.config['main']['ffmpeg_path'], "-i", channelUri, "-c:v", "copy", "-c:a", "copy", "-f", "mpegts", "-nostats", "-hide_banner", "-loglevel", "warning", "pipe:1"] ffmpeg_proc = subprocess.Popen(ffmpeg_command, stdout=subprocess.PIPE) # get initial videodata. if that works, then keep grabbing it videoData = ffmpeg_proc.stdout.read(int(self.config['main']['bytes_per_read'])) while True: if not videoData: break else: # from https://stackoverflow.com/questions/9932332 try: self.wfile.write(videoData) time.sleep(0.1) except IOError as e: # Check we hit a broken pipe when trying to write back to the client if e.errno in [errno.EPIPE, errno.ECONNABORTED, errno.ECONNRESET, errno.ECONNREFUSED]: break else: raise videoData = ffmpeg_proc.stdout.read(int(self.config['main']['bytes_per_read'])) # Send SIGTERM to shutdown ffmpeg ffmpeg_proc.terminate() try: # ffmpeg writes a bit of data out to stderr after it terminates, # need to read any hanging data to prevent a zombie process. ffmpeg_proc.communicate() except ValueError: print("Connection Closed") self.rmg_station_scans[index] = 'Idle' else: self.send_response(400, 'All tuners already in use.') self.send_header('Content-type', 'text/html') self.end_headers() reply_str = templates['htmlError'].format('All tuners already in use.') self.wfile.write(reply_str.encode('utf-8')) def do_response(self, code, mime, reply_str): self.send_response(code) self.send_header('Content-type', mime) self.end_headers() if reply_str: self.wfile.write(reply_str.encode('utf-8')) # mostly from https://github.com/ZeWaren/python-upnp-ssdp-example # and https://stackoverflow.com/questions/46210672/python-2-7-streaming-http-server-supporting-multiple-connections-on-one-port class PlexHttpServer(threading.Thread): def __init__(self, serverSocket, config, locast_service, location): threading.Thread.__init__(self) PlexHttpHandler.config = config self.bind_ip = config["main"]["bind_ip"] self.bind_port = config["main"]["bind_port"] PlexHttpHandler.stations = stations PlexHttpHandler.local_locast = locast_service PlexHttpHandler.location = location # init station scans tmp_rmg_scans = [] for x in range(int(config['main']['tuner_count'])): tmp_rmg_scans.append('Idle') PlexHttpHandler.rmg_station_scans = tmp_rmg_scans self.socket = serverSocket self.daemon = True self.start() def run(self): httpd = HTTPServer((self.bind_ip, int(self.bind_port)), PlexHttpHandler, False) httpd.socket = self.socket httpd.server_bind = self.server_close = lambda self: None httpd.serve_forever() def start(config, locast, location): serverSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) serverSocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) serverSocket.bind((config["main"]['bind_ip'], int(config["main"]['bind_port']))) serverSocket.listen(int(config["main"]["concurrent_listeners"])) print("Now listening for requests.") for i in range(int(config["main"]["concurrent_listeners"])): PlexHttpServer(serverSocket, config, locast, location)
43.12809
169
0.546321
1
1.7721
[ -0.01321098580956459, 0.08486993610858917, 0.010417581535875797, 0.0004897629842162132, -0.011891674250364304, -0.0013448348036035895, -0.024848531931638718, 0.015278535895049572, -0.06033771485090256, 0.007868298329412937, 0.03937172517180443, 0.012331318110227585, -0.0012005176395177841, -0.006174021400511265, 0.03885272517800331, 0.03351941332221031, 0.12888455390930176, -0.02773059532046318, 0.007482179906219244, 0.005042902659624815, 0.02482929825782776, 0.01321091316640377, 0.024006355553865433, 0.01620510034263134, 0.0017941680271178484, 0.039194006472826004, 0.01588159240782261, 0.011751145124435425, -0.0020484686829149723, -0.04239029437303543, -0.02237483486533165, 0.00012976006837561727, -0.03101174905896187, -0.022086340934038162, 0.021025819703936577, 0.008144075982272625, 0.00992470234632492, -0.049079779535532, -0.018899688497185707, 0.018381694331765175, -0.03710317611694336, -0.005819112528115511, 0.0356014184653759, -0.013174103572964668, 0.05694166198372841, -0.024139348417520523, -0.002111252397298813, -0.017142431810498238, -0.024222904816269875, -0.00019270121993031353, -0.06001949682831764, 0.047174036502838135, 0.047145336866378784, -0.0293851550668478, 0.0018205217784270644, -0.0025245212018489838, -0.0020611798390746117, 0.012754869647324085, -0.030810587108135223, -0.0017181203002110124, -0.016218019649386406, 0.024302059784531593, 0.055696647614240646, 0.018379829823970795, -0.04448840022087097, 0.010196737945079803, -0.021040242165327072, -0.013910992071032524, -0.036575134843587875, -0.04001956805586815, -0.01953844726085663, 0.034991297870874405, 0.028508475050330162, 0.057173870503902435, -0.021308941766619682, 0.004875132814049721, -0.05476157367229462, -0.027217324823141098, -0.022515272721648216, -0.02359621785581112, 0.018974611535668373, 0.07453490793704987, -0.0014661230379715562, -0.006185170263051987, 0.024136342108249664, -0.03373130410909653, 0.06559771299362183, -0.04620416834950447, 0.04558020085096359, 0.03742209076881409, -0.01097281463444233, 0.017904529348015785, -0.09807782620191574, -0.0063676428981125355, 0.0006488327635452151, -0.0794832855463028, 0.013038468547165394, -0.028195608407258987, -0.06093064323067665, 0.004411203321069479, 0.007025627885013819, 0.01629815623164177, 0.027203412726521492, -0.0026551668997853994, 0.03024860844016075, -0.016957201063632965, -0.02802395634353161, -0.01877746731042862, 0.03171265497803688, -0.032353632152080536, -0.007552179973572493, 0.00794291403144598, -0.040060561150312424, -0.05309249460697174, 0.000406586448661983, 0.024676714092493057, 0.018604349344968796, 0.014069677330553532, -0.05464155599474907, 0.06590607762336731, 0.002452204469591379, -0.017829280346632004, 0.031038779765367508, -0.03432629257440567, -0.009546658955514431, 0.056557055562734604, -0.04598301276564598, -0.02725263684988022, 0.009186435490846634, 0.009824768640100956, 0.055336855351924896, -0.0033168818335980177, -0.004289980046451092, -0.0008472343906760216, 0.01500509213656187, -0.0018968251533806324, -0.007151271682232618, -0.004281665198504925, -0.025990499183535576, 0.036121152341365814, -0.022778484970331192, -0.014699782244861126, -0.015590950846672058, 0.04290793091058731, -0.018407242372632027, -0.05001303553581238, -0.014476194977760315, -0.04061586409807205, 0.011853585951030254, 0.01603556238114834, 0.0088875163346529, 0.0030855871737003326, 0.015366042032837868, -0.020166954025626183, -0.051118455827236176, -0.0014191808877512813, -0.012023845687508583, -0.00023325775691773742, -0.033884093165397644, 0.046825751662254333, -0.008747236803174019, -0.02792118676006794, -0.006466715130954981, -0.002121307887136936, 0.0030023709405213594, 0.017865492030978203, 0.02025710418820381, 0.0538116991519928, -0.02023329772055149, 0.0006185070378705859, 0.019045725464820862, -0.02010514959692955, -0.017892345786094666, 0.00013226401642896235, -0.015910234302282333, -0.03640848398208618, 0.045708898454904556, 0.021579183638095856, -0.024903904646635056, -0.0021490866784006357, 0.0507737398147583, -0.003316545393317938, 0.031528014689683914, -0.006669045425951481, 0.011864758096635342, -0.027211470529437065, -0.07979753613471985, -0.05915023013949394, 0.03302842006087303, 0.006353976670652628, -0.03012903966009617, -0.0072776242159307, 0.0034213110338896513, -0.05503733456134796, 0.009586379863321781, -0.06191975623369217, -0.08424089103937149, 0.011995951645076275, 0.012148626148700714, -0.013826949521899223, -0.007326497696340084, -0.006616994738578796, 0.004265687894076109, 0.011855054646730423, -0.009974622167646885, -0.022248422726988792, -0.590972900390625, 0.05551200732588768, 0.009910862892866135, -0.002539421897381544, 0.06865829229354858, 0.022484758868813515, -0.017217116430401802, 0.038672659546136856, -0.023498887196183205, -0.01573834754526615, 0.008511394262313843, 0.018914107233285904, -0.010996385477483273, -0.0154421990737319, 0.028132250532507896, 0.011084689758718014, 0.007003478240221739, -0.04727582260966301, -0.0073085869662463665, 0.00014723926142323762, 0.02668795734643936, -0.058780521154403687, -0.02190399169921875, 0.027169901877641678, -0.0009260708466172218, 0.04063685983419418, 0.029146166518330574, 0.013547684997320175, -0.051778290420770645, -0.00827085692435503, 0.0076048546470701694, -0.0008626956841908395, 0.001290061860345304, -0.028426943346858025, -0.013664777390658855, 0.0049781580455601215, 0.008809351362287998, -0.0011931052431464195, 0.010738812386989594, 0.042578041553497314, -0.015996053814888, -0.006609685253351927, -0.026398073881864548, -0.04870698228478432, -0.05700191482901573, -0.00661536306142807, -0.023648565635085106, 0.01845761202275753, 0.006458735559135675, 0.021900299936532974, -0.031125281006097794, 0.0008731477428227663, 0.03100583329796791, -0.021449146792292595, -0.04645879566669464, -0.0007681944407522678, -0.05197550728917122, -0.013315215706825256, -0.003274393267929554, -0.03125078231096268, -0.002747415332123637, 0.011726588942110538, -0.03591665253043175, 0.018191758543252945, 0.019380899146199226, 0.010352074168622494, 0.062229007482528687, -0.0343153141438961, -0.006040223408490419, 0.05235666781663895, -0.05821748822927475, -0.012310341000556946, -0.037679340690374374, 0.02004639431834221, 0.035800594836473465, 0.02597970701754093, -0.0004019681364297867, -0.0013070943532511592, -0.07367301732301712, -0.004274839535355568, 0.013464548625051975, 0.006492090877145529, 0.01978369802236557, -0.022840024903416634, -0.024474112316966057, 0.018324606120586395, -0.034213386476039886, 0.007310214918106794, -0.0099026495590806, -0.023663021624088287, 0.030494315549731255, 0.016238031908869743, -0.015207416377961636, 0.028237296268343925, -0.00634389091283083, 0.05167374014854431, -0.01099371537566185, 0.07214962691068649, -0.006009435281157494, 0.06042895093560219, 0.01631924696266651, 0.0009799099061638117, -0.052455753087997437, 0.027851562947034836, -0.05444934219121933, -0.024064168334007263, -0.03046293929219246, -0.01460100244730711, 0.02273830771446228, 0.006356455851346254, 0.029297877103090286, -0.010929154232144356, -0.00921495072543621, -0.0052348291501402855, -0.04234246909618378, 0.002153897425159812, -0.012883477844297886, -0.03522670269012451, 0.037464678287506104, 0.010383588261902332, -0.007627576123923063, 0.013867144472897053, -0.002218218520283699, 0.030349191278219223, -0.000435850874055177, -0.02762395702302456, -0.0005235247081145644, -0.031871497631073, 0.022237000986933708, -0.020352419465780258, -0.007081727031618357, -0.030945273116230965, 0.017637422308325768, 0.00017560558626428246, 0.013268668204545975, 0.027518700808286667, 0.013347548432648182, 0.0013174376217648387, -0.014450137503445148, -0.01744666136801243, -0.03148948773741722, -0.0005026949802413583, 0.043244630098342896, -0.035377297550439835, -0.024692663922905922, 0.03568132221698761, 0.0676165297627449, 0.033137936145067215, -0.02935333363711834, -0.0348236970603466, 0.012505313381552696, -0.02402588538825512, 0.045405395328998566, 0.0067357164807617664, -0.0038031600415706635, 0.0010906727984547615, -0.03648095577955246, 0.034006670117378235, 0.03685672953724861, -0.0030899483244866133, 0.001522706006653607, -0.03760024905204773, 0.045634716749191284, -0.014742166735231876, 0.04049179330468178, -0.005229986272752285, -0.011715549975633621, 0.01313246414065361, 0.055330097675323486, 0.014715402387082577, -0.0057641323655843735, 0.04966610297560692, 0.047290023416280746, 0.0053497846238315105, 0.01016031764447689, -0.007079541217535734, -0.001196101657114923, -0.01934300735592842, 0.02833319641649723, 0.016011647880077362, -0.019196130335330963, -0.0019184909760951996, -0.026858370751142502, 0.015648437663912773, 0.0015215378953143954, -0.0558871366083622, -0.028693601489067078, -0.037179891020059586, -0.03748752176761627, -0.042599812150001526, -0.006098759360611439, 0.04021638631820679, -0.03640160709619522, 0.01693556271493435, -0.05059537664055824, 0.021780161187052727, 0.062210336327552795, -0.013429388403892517, 0.006656507961452007, -0.013240770436823368, 0.04833981394767761, 0.00801506731659174, 0.032079823315143585, -0.004492845851927996, 0.036764971911907196, 0.02916758321225643, -0.010503577068448067, 0.015092740766704082, -0.011679578572511673, -0.007517597638070583, -0.007636307273060083, -0.014830785803496838, -0.025526652112603188, 0.007999691180884838, -0.02805439569056034, 0.0024812500923871994, -0.040378183126449585, -0.018794935196638107, 0.008606051094830036, -0.01530800573527813, -0.020783036947250366, -0.041069820523262024, 0.013969690538942814, -0.005888010840862989, -0.017042219638824463, -0.0010527917183935642, -0.017540108412504196, 0.03363500162959099, -0.056085746735334396, 0.002496441127732396, 0.014861072413623333, 0.018101269379258156, 0.007692950777709484, -0.004206990823149681, 0.00669045140966773, -0.02581125870347023, -0.04478610306978226, -0.014963516965508461, 0.007526255678385496, 0.005926948972046375, -0.00003317130176583305, -0.021115820854902267, 0.02646712213754654, -0.015692614018917084, 0.007713427767157555, 0.020908018574118614, -0.07504941523075104, -0.0032854832243174314, -0.01832675188779831, 0.031475599855184555, 0.017751026898622513, 0.019938739016652107, -0.019598811864852905, -0.022584835067391396, -0.007989906705915928, 0.018570080399513245, 0.0035031158477067947, -0.0026102224364876747, 0.013794883154332638, 0.023584546521306038, 0.015869293361902237, -0.01895860768854618, 0.009350650012493134, 0.040776871144771576, -0.0047454084269702435, 0.01225409284234047, -0.04763951525092125, -0.02965851128101349, -0.038554124534130096, -0.016443828120827675, 0.027562255039811134, 0.025626251474022865, 0.016472915187478065, -0.005285989958792925, 0.003596687689423561, 0.039074596017599106, -0.004167053382843733, -0.03827034309506416, 0.03397785872220993, 0.08346802741289139, -0.020506249740719795, -0.018467141315340996, 0.0015619134064763784, 0.003417622996494174, -0.02423759177327156, -0.0008898855303414166, 0.023259514942765236, 0.014572227373719215, -0.03905873000621796, -0.016639260575175285, 0.0205245241522789, -0.02321251668035984, 0.030103327706456184, -0.024434752762317657, -0.005615075584501028, 0.023312609642744064, -0.017382193356752396, -0.015252092853188515, 0.019320525228977203, -0.02218603901565075, -0.0012703745160251856, 0.009147994220256805, -0.02082853578031063, -0.04400002956390381, 0.009181134402751923, -0.012323426082730293, 0.025760099291801453, -0.05292573943734169, 0.03936012089252472, 0.020089207217097282, -0.0031903767958283424, 0.012845426797866821, 0.01586059480905533, 0.013545609079301357, -0.031121166422963142, -0.028270145878195763, 0.04560118168592453, 0.016945701092481613, -0.011608876287937164, -0.045286986976861954, -0.030254829674959183, 0.04506716504693031, 0.01371593214571476, -0.0027151715476065874, -0.02148684300482273, -0.013079582713544369, -0.026867251843214035, -0.01584376022219658, -0.005273821298032999, 0.04434988275170326, 0.025876391679048538, -0.041107989847660065, 0.026764018461108208, 0.013531592674553394, -0.0024827898014336824, 0.013673791661858559, 0.0214640311896801, 0.022325392812490463, 0.010226327925920486, -0.03742362931370735, -0.01953957788646221, 0.03202939033508301, -0.022312814369797707, 0.012334801256656647, -0.0023884207475930452, 0.016901470720767975, 0.011974307708442211, -0.02962476573884487, 0.008910734206438065, 0.029803838580846786, 0.01231283787637949, -0.01104733906686306, 0.00400680722668767, 0.007596289739012718, -0.029447505250573158, -0.0034677765797823668, -0.017323514446616173, 0.009273676201701164, -0.002229133155196905, -0.004660567734390497, -0.01975777931511402, 0.006873505190014839, 0.01664748042821884, 0.0031744325533509254, -0.02057681791484356, -0.036237385123968124, 0.024694085121154785, 0.02379176765680313, -0.018690068274736404, 0.08706018328666687, 0.04247523099184036, -0.06360139697790146, 0.010985278524458408, 0.041171859949827194, -0.0006255352636799216, 0.02556825429201126, -0.01629938744008541, -0.030863041058182716, 0.021721292287111282, 0.057442519813776016, -0.02971133589744568, -0.023884540423750877, 0.0023533813655376434, -0.02056145668029785, -0.0031409040093421936, 0.00215307273901999, -0.009396837092936039, 0.025524623692035675, -0.02353518083691597, -0.02522166445851326, 0.018651561811566353, -0.03845977783203125, 0.0069176689721643925, -0.011989827267825603, -0.05973116308450699, 0.009347690269351006, -0.02910562977194786, 0.0036573901306837797, -0.018112216144800186, 0.030315302312374115, 0.017778730019927025, 0.05169346556067467, -0.011178020387887955, 0.003932048100978136, -0.04502306133508682, -0.03626692295074463, -0.0003176928439643234, -0.0177808478474617, 0.02461681142449379, 0.052997294813394547, 0.024204475805163383, -0.00832718051970005, -0.0010263769654557109, -0.0450153574347496, 0.04750014841556549, -0.006635907106101513, -0.02291981317102909, -0.02792125754058361, -0.053911980241537094, -0.012105442583560944, -0.06458766013383865, -0.06192270293831825, 0.010179582051932812, -0.008207586593925953, -0.03933270275592804, 0.00960580725222826, 0.0013984136749058962, -0.006349704694002867, 0.007413927000015974, 0.03372564911842346, -0.001500575803220272, 0.014970039948821068, -0.050312019884586334, -0.008475987240672112, 0.026999270543456078, 0.020687362179160118, 0.02875056490302086, 0.015050237998366356, -0.006510467734187841, -0.038219090551137924, 0.003935558255761862, -0.012137561105191708, 0.011538306251168251, -0.0010054062586277723, 0.03877979889512062, -0.0869179368019104, 0.023516342043876648, -0.02525312639772892, -0.039007753133773804, -0.03863969072699547, -0.004198744427412748, 0.03319418802857399, 0.02492370828986168, 0.001822667196393013, 0.031374502927064896, -0.03372252359986305, -0.010066766291856766, -0.007466347888112068, 0.04906746372580528, 0.04939597472548485, 0.02703595720231533, 0.011539507657289505, -0.002028227550908923, 0.049157626926898956, -0.023733094334602356, 0.043577175587415695, 0.03235480561852455, -0.015861796215176582, 0.02597419172525406, 0.01357935555279255, 0.0056175347417593, -0.004454593174159527, 0.014660323038697243, 0.01891959458589554, 0.014269838109612465, -0.0028098789043724537, 0.0183895044028759, 0.02865689992904663, 0.004985339008271694, 0.01857035793364048, -0.014410951174795628, -0.030260182917118073, 0.0007620003307238221, -0.002726130187511444, 0.030907269567251205, 0.014850311912596226, 0.020739100873470306, 0.019009949639439583, 0.012013326399028301, 0.014520322903990746, -0.053390324115753174, -0.014711870811879635, 0.0035012185107916594, 0.015057182870805264, 0.007455847226083279, -0.02087331935763359, 0.03071315959095955, 0.010039490647614002, 0.041740208864212036, 0.008906307630240917, 0.03090595081448555, -0.05540781468153, -0.02644002065062523, -0.010824469849467278, 0.044826045632362366, 0.047577086836099625, 0.07318587601184845, 0.06412189453840256, 0.038479000329971313, 0.0027262303046882153, -0.011488075368106365, -0.010445070452988148, 0.0010522417724132538, 0.016923977062106133, 0.00018854197696782649, 0.01330412644892931, 0.038423653692007065, -0.05579308420419693, 0.0008643033797852695, -0.01361116487532854, 0.01689264550805092, 0.0019100223435088992, -0.011406674981117249, 0.012434509582817554, -0.0038601085543632507, -0.012942143715918064, -0.03613843768835068, -0.015309463255107403, 0.009654950350522995, -0.034345075488090515, 0.04022099822759628, -0.01404452696442604, -0.02617112547159195, 0.0012901241425424814, -0.005240424070507288, -0.03663576766848564, 0.052489787340164185, 0.029440967366099358, -0.039755962789058685, -0.036593224853277206, 0.0881737545132637, 0.0266044232994318, -0.0002967434120364487, -0.035279568284749985, -0.014929184690117836, -0.005222175270318985, -0.01978965289890766, -0.012969018891453743, 0.005110644735395908, -0.007992555387318134, 0.036271728575229645, 0.026820145547389984, 0.024666938930749893, 0.014436003752052784, -0.046996936202049255, -0.050197504460811615, -0.006940494757145643, 0.04174691438674927, -0.01823831908404827, -0.004322757013142109, -0.0538768544793129, 0.0019455236615613103 ]
8a9cd2106529aad0ea2a1405ec139e1af2cab3e4
1,130
py
Python
{{ cookiecutter.project_name }}/{{ cookiecutter.project_name }}/local/pages/views.py
dcs3spp/cookiecutter-django-api
d575dda07930743c05a27eb968489867831d97de
[ "Apache-1.1" ]
null
null
null
{{ cookiecutter.project_name }}/{{ cookiecutter.project_name }}/local/pages/views.py
dcs3spp/cookiecutter-django-api
d575dda07930743c05a27eb968489867831d97de
[ "Apache-1.1" ]
null
null
null
{{ cookiecutter.project_name }}/{{ cookiecutter.project_name }}/local/pages/views.py
dcs3spp/cookiecutter-django-api
d575dda07930743c05a27eb968489867831d97de
[ "Apache-1.1" ]
null
null
null
from django import template from django.contrib.auth.decorators import login_required from django.http import HttpResponse from django.template import loader @login_required(login_url="/login/") def index(request): context = {} context["segment"] = "index" html_template = loader.get_template("index.html") return HttpResponse(html_template.render(context, request)) @login_required(login_url="/login/") def pages(request): context = {} # All resource paths end in .html. # Pick out the html file name from the url. And load that template. try: load_template = request.path.split("/")[-1] context["segment"] = load_template html_template = loader.get_template(load_template) return HttpResponse(html_template.render(context, request)) except template.TemplateDoesNotExist: html_template = loader.get_template("page-404.html") return HttpResponse(html_template.render(context, request)) except: # noqa: E722 html_template = loader.get_template("page-500.html") return HttpResponse(html_template.render(context, request))
35.3125
71
0.718584
1
0.9486
[ 0.003844865830615163, 0.023924198001623154, 0.009556540288031101, 0.0032597272656857967, 0.0041865399107337, -0.003303590463474393, -0.011811486445367336, 0.003544540610164404, -0.00670430064201355, 0.00251889624632895, 0.004425371997058392, 0.002413454931229353, 0.007226483430713415, -0.017312517389655113, 0.001569677027873695, 0.01571546494960785, -0.052325841039419174, 0.0036099895369261503, -0.004285098053514957, 0.0014359100023284554, -0.007303136400878429, 0.009559638798236847, 0.009477932006120682, 0.004059924278408289, 0.006017168518155813, -0.00038928751018829644, 0.009812871925532818, 0.0006539103342220187, -0.0077849277295172215, -0.00617934949696064, -0.0012921429006382823, -0.002041114028543234, -0.003346821991726756, -0.005606511607766151, 0.005425409413874149, -0.0038331898394972086, -0.0003037296119146049, -0.020786752924323082, 0.010678363963961601, -0.003161939326673746, -0.009219422936439514, -0.018681803718209267, -0.0010739516001194715, 0.0021514776162803173, -0.011798814870417118, 0.002561915898695588, -0.005262404214590788, 0.00462837191298604, -0.013654873706400394, 0.007367302663624287, -0.008008702658116817, 0.006276899483054876, 0.013964003883302212, 0.001992700854316354, -0.004917874466627836, -0.007481335196644068, 0.012907901778817177, -0.0008117903489619493, -0.011350980028510094, 0.0014876755885779858, -0.004750493448227644, -0.0037213291507214308, 0.004022714216262102, 0.0024259425699710846, -0.01831936091184616, -0.004957460332661867, -0.003713614773005247, 0.0020731668919324875, 0.0006696235504932702, 0.006637650541961193, 0.0010160566307604313, -0.0024080609437078238, 0.008272348903119564, 0.005483879707753658, 0.0058038798160851, -0.004428663291037083, -0.00011630708468146622, 0.00021153244597371668, 0.008769962936639786, 0.00326274405233562, 0.005425027571618557, -0.0078602135181427, 0.006623012945055962, 0.009945848025381565, 0.012197516858577728, 0.006676060147583485, 0.022683298215270042, -0.011761658824980259, 0.047976054251194, 0.008477212861180305, -0.007472151890397072, 0.003277413547039032, -0.008105142042040825, -0.0026212192606180906, -0.005734729114919901, -0.030878432095050812, -0.00006451485387515277, -0.006180016789585352, -0.00012158205208834261, 0.002371825510635972, -0.0003138032916467637, 0.006251019425690174, -0.0019816297572106123, -0.002421933226287365, -0.009616700932383537, 0.015578584745526314, -0.01205331739038229, -0.0023081107065081596, 0.006517566740512848, 0.0033201086334884167, -0.011844874359667301, -0.00185720797162503, 0.0018900894792750478, -0.011546260677278042, 0.005038644652813673, 0.0022120513021945953, -0.004024701192975044, 0.05666496604681015, -0.0002431156754028052, 0.0019905585795640945, -0.005633092485368252, -0.0003328345192130655, 0.000546496594324708, 0.007748735137283802, 0.00878920778632164, -0.0028010557871311903, 0.011888592503964901, 0.005705874413251877, 0.0035473417956382036, 0.007943261414766312, -0.002175108063966036, 0.007928368635475636, -0.006608912721276283, -0.0027723319362848997, 0.0020506568253040314, -0.006624697241932154, 0.007604373153299093, -0.0018246846739202738, -0.007461601868271828, -0.001143734552897513, 0.00026232056552544236, -0.009337644092738628, 0.0008512933272868395, -0.0031498505268245935, 0.0021903205197304487, -0.012401586398482323, -0.004135587718337774, -0.004071781877428293, -0.008083177730441093, 0.0034011309035122395, 0.009998221881687641, 0.0036925552412867546, 0.0028278182726353407, -0.005310515407472849, -0.008789965882897377, -0.0008610991644673049, -0.005558286793529987, 0.0013545340625569224, 0.006560118868947029, 0.003496079705655575, -0.009268026798963547, 0.0007413113489747047, 0.0050173853524029255, 0.002860728418454528, -0.0007446902454830706, 0.0012464935425668955, -0.007916842587292194, 0.007355969399213791, 0.00013733237574342638, 0.00648773368448019, 0.010866985656321049, -0.004466827027499676, -0.0010607092408463359, -0.001766329980455339, 0.003203707979992032, -0.0010766778141260147, 0.003995964303612709, 0.010594036430120468, -0.006032031029462814, -0.005953575484454632, 0.0058016227558255196, 0.005434571299701929, 0.011389678344130516, 0.004795166198164225, -0.0009434843086637557, 0.0012823240831494331, -0.005679743364453316, -0.00153870799113065, 0.005197793710976839, -0.005550768226385117, 0.005893449764698744, 0.006309583783149719, -0.014064652845263481, -0.006707309745252132, 0.003090349491685629, -0.007015544921159744, 0.0006467893836088479, 0.014087707735598087, 0.01211389061063528, -0.0037360412534326315, 0.0030102282762527466, -0.011314434930682182, -0.00023082738334778696, 0.0054827164858579636, 0.0036379240918904543, -0.01187229249626398, -0.9568575024604797, 0.006624117493629456, 0.0035833369474858046, 0.0000040423897189612035, 0.00595339247956872, 0.00334554654546082, 0.0029794538859277964, 0.00555772939696908, 0.014546865597367287, -0.009849824011325836, -0.0048520504496991634, -0.01243412122130394, -0.0094464011490345, -0.0018975830171257257, -0.0067239427007734776, -0.0037003615871071815, -0.004900394938886166, -0.005504857283085585, -0.0034165664110332727, -0.0044270167127251625, -0.0029014917090535164, 0.00910685770213604, -0.00016633595805615187, 0.005517328158020973, 0.0031755061354488134, 0.005170673131942749, -0.0038164968136698008, 0.00009020165452966467, -0.001427483162842691, -0.0016054784646257758, -0.005825374275445938, -0.015674090012907982, -0.003504627849906683, 0.00030905441963113844, 0.010548509657382965, -0.0012062983587384224, 0.010541466996073723, -0.001155379693955183, 0.0020678213331848383, -0.008653700351715088, 0.004984473809599876, -0.00024091378145385534, 0.0021691815927624702, -0.030131159350275993, 0.00029970367904752493, -0.0010359627194702625, -0.006914325058460236, 0.010103928856551647, 0.000028672240659943782, -0.000004389708465168951, -0.003192480653524399, -0.003329699393361807, 0.011453945189714432, -0.006904965732246637, 0.003636315930634737, -0.00400244165211916, -0.0065011861734092236, -0.0028892236296087503, -0.008518277667462826, 0.0016248226165771484, 0.0049170455895364285, -0.003664430696517229, -0.0037500164471566677, -0.006472312845289707, 0.0017910611350089312, 0.0007421532645821571, 0.00010373682744102553, -0.018787534907460213, -0.007761238608509302, 0.0010401870822533965, -0.003429893171414733, -0.0031831550877541304, -0.0031539855990558863, 0.001983391586691141, -0.011250839568674564, 0.00881763081997633, 0.0020722178742289543, -0.0009213474113494158, -0.011845406144857407, 0.0011841257801279426, -0.006909369025379419, -0.009630097076296806, 0.0019645472057163715, -0.006786509416997433, -0.005711596924811602, -0.00009826853056438267, 0.0020973889622837305, 0.008958029560744762, -0.004300922155380249, 0.004284844268113375, 0.010963470675051212, -0.0020821979269385338, -0.006998690776526928, 0.008221003226935863, 0.007545951753854752, -0.00022952197468839586, -0.0023297066800296307, 0.0008828909485600889, 0.009243258275091648, 0.006920843385159969, 0.0004170353931840509, 0.004011802840977907, -0.0010650668991729617, 0.01069991197437048, 0.00011907674343092367, 0.0013714729575440288, -0.003832253161817789, -0.000761982228141278, -0.003169007133692503, -0.000010599890629237052, -0.004042031709104776, -0.002791054779663682, -0.012613779865205288, -0.008396390825510025, -0.003780750324949622, 0.0007544789114035666, 0.0030892889481037855, -0.004013892728835344, -0.0002902478154283017, 0.0028813881799578667, 0.008233234286308289, 0.0033625245559960604, -0.0023980983532965183, 0.001996914856135845, 0.0032634849194437265, -0.01016452070325613, 0.015983328223228455, -0.014048573561012745, 0.005818190984427929, -0.0004990947782061994, -0.018066756427288055, 0.007956571877002716, 0.010116519406437874, -0.007901460863649845, 0.0028073713183403015, 0.005448417738080025, 0.003982314374297857, -0.0023306049406528473, -0.0059167612344026566, -0.003337207715958357, -0.015068834647536278, -0.00017332909919787198, 0.01982494443655014, 0.00014919757086317986, 0.011270943097770214, 0.012117914855480194, -0.0029404968954622746, 0.00195820233784616, 0.007793408818542957, -0.0001226041786139831, 0.013892979361116886, -0.008013132959604263, -0.0013965889811515808, 0.00213991804048419, -0.006167893297970295, -0.0005242645274847746, 0.00431231502443552, 0.0029754769057035446, -0.0008907567244023085, 0.004968020133674145, -0.007424754556268454, -0.0056976014748215675, -0.01804640330374241, -0.004801114555448294, 0.008171426132321358, -0.005246579647064209, 0.002943241037428379, -0.011112676002085209, 0.007995142601430416, 0.0059857782907783985, 0.0051802038215100765, -0.00021327189460862428, 0.0008584479219280183, 0.006632484029978514, 0.012575186789035797, -0.006146758329123259, 0.003497738391160965, 0.0019283932633697987, -0.00007980065129231662, 0.0004347947833593935, 0.008856179192662239, -0.008738596923649311, -0.006759255193173885, 0.004246207419782877, 0.0035993284545838833, -0.0013857452431693673, -0.004220657050609589, -0.008016897365450859, -0.005181528627872467, 0.004365780856460333, -0.006814384367316961, 0.004206562880426645, 0.004982631653547287, 0.003417044412344694, -0.005324945319443941, -0.0012249465798959136, -0.0015357132069766521, -0.011229421943426132, 0.010127682238817215, -0.0017744877841323614, 0.002506137825548649, 0.01225646585226059, 0.003891052445396781, -0.012104515917599201, 0.005035830195993185, 0.007760139182209969, -0.004924209788441658, 0.004842121619731188, 0.007857166230678558, -0.005924950819462538, -0.02261151745915413, -0.002103399485349655, -0.014972083270549774, 0.007561857812106609, -0.0025646621361374855, 0.005097980145365, -0.006614282261580229, 0.005601390264928341, 0.005974967498332262, -0.014849165454506874, -0.004396232310682535, -0.009390488266944885, 0.011039884760975838, -0.0009715615306049585, -0.001980011584237218, -0.0038072909228503704, -0.0005360568757168949, -0.003262443235144019, -0.005291858687996864, -0.0026027837302535772, 0.005451733712106943, 0.002620946615934372, -0.0038010820280760527, 0.002720249816775322, -0.004296831786632538, 0.00013354714610613883, 0.0015576097648590803, -0.011735951527953148, 0.001511045848019421, 0.0035006320104002953, -0.002720537595450878, -0.0037477861624211073, 0.0016143822576850653, 0.0027879446279257536, -0.009295018389821053, -0.010554725304245949, -0.002770740306004882, -0.004052071366459131, -0.0031675929203629494, -0.012463958002626896, -0.0026217319536954165, -0.007252390496432781, 0.005295071750879288, -0.007629742845892906, 0.0080258185043931, 0.0059336042031645775, -0.006425995379686356, 0.008254323154687881, -0.0009358038660138845, 0.003928855527192354, 0.005095964763313532, 0.006375906523317099, 0.001636158674955368, -0.0036665552761405706, -0.01298514474183321, 0.011594953946769238, -0.007327457889914513, -0.00035010624560527503, 0.014892639592289925, 0.0066576446406543255, 0.009265203960239887, 0.0009804562432691455, -0.001397087238729, 0.0025455125141888857, 0.005405582953244448, -0.014555011875927448, 0.0008025947608985007, -0.0015676592011004686, -0.0005134429084137082, 0.005004424601793289, -0.005927079822868109, 0.001520599820651114, 0.009861374273896217, 0.004181440453976393, -0.007600530982017517, -0.0023072329349815845, 0.0008314938168041408, 0.0043480852618813515, -0.013562079519033432, -0.0005579946446232498, -0.0042617786675691605, -0.003915669396519661, -0.0027941358275711536, -0.005285867489874363, 0.000939228106290102, 0.008630583994090557, -0.0006497388822026551, 0.006811852101236582, 0.0016776971751824021, -0.002681156387552619, 0.015052392147481441, -0.0030880358535796404, -0.006018865387886763, 0.0036442517302930355, 0.0037659823428839445, -0.0005566467298194766, -0.00607856223359704, -0.0011102892458438873, 0.003851560642942786, 0.006441954988986254, -0.0018632592400535941, -0.008219629526138306, 0.0004684656742028892, -0.0007230945047922432, -0.008651302196085453, 0.0011189606739208102, 0.011883046478033066, -0.0033383374102413654, 0.004533195868134499, -0.0024310541339218616, -0.009432843886315823, -0.01595773920416832, 0.052467428147792816, -0.002489526988938451, 0.0054780058562755585, 0.0054489243775606155, -0.0066167134791612625, -0.0024058965500444174, -0.0027207639068365097, 0.006339219398796558, -0.005841289646923542, -0.00689443526789546, 0.006396138109266758, -0.0020072166807949543, 0.0031168756540864706, 0.0019176555797457695, -0.001691240817308426, 0.01549633126705885, -0.007839588448405266, -0.01458954531699419, -0.016728712245821953, 0.00946047343313694, -0.005118159577250481, -0.01074311975389719, 0.009316586889326572, -0.004170985426753759, -0.006104966159909964, 0.002877012826502323, 0.0076118214055895805, 0.00021264124370645732, -0.0010132455499842763, -0.002499793656170368, -0.003595953807234764, -0.0004272060177754611, 0.0026469577569514513, 0.004350307397544384, 0.007655475754290819, -0.0014491851907223463, 0.003974306862801313, -0.001946614240296185, -0.003330784384161234, 0.00039408725569956005, 0.004695030394941568, 0.007901064120233059, -0.00129840022418648, -0.002856998238712549, 0.004707495216280222, 0.005169353447854519, -0.00040671820170246065, 0.010460772551596165, 0.0006008176715113223, -0.005682507064193487, 0.00770203024148941, 0.007251966744661331, -0.00025922662462107837, 0.008782305754721165, -0.002602769760414958, 0.006486785598099232, 0.0016943447990342975, -0.006766138132661581, -0.015046984888613224, -0.0044796047732234, 0.004880628082901239, 0.008784961886703968, -0.0007311556255444884, 0.0022301976568996906, -0.0010896524181589484, -0.004112183582037687, -0.007478937041014433, -0.007088976912200451, -0.0037293427158147097, -0.00022381510643754154, 0.0023282815236598253, 0.06967324018478394, -0.009832487441599369, -0.0018640663474798203, -0.00884065218269825, -0.0004065569955855608, 0.00005487762246048078, 0.0013593916082754731, 0.0027437028475105762, -0.004111900459975004, 0.0013346404302865267, 0.00179566559381783, -0.007847847416996956, -0.011324568651616573, -0.0011339974589645863, 0.0028107273392379284, -0.0012468092609196901, 0.002881586318835616, 0.006032525561749935, -0.01080336794257164, 0.00046236978960223496, -0.01094844937324524, -0.003984733019024134, -0.0025081157218664885, -0.009739475324749947, -0.002877395134419203, -0.0023864845279604197, 0.0028226252179592848, 0.004556408617645502, 0.006566318683326244, -0.0034121007192879915, 0.0062740761786699295, -0.0015224888920783997, 0.00014939936227165163, -0.004850884433835745, -0.003727339208126068, -0.00533630233258009, 0.007836606353521347, 0.000770279613789171, -0.0100351981818676, -0.004029815085232258, -0.0020651835948228836, 0.0008366222027689219, -0.006918693892657757, 0.0026807663962244987, -0.0007900979835540056, 0.00589772779494524, -0.002698823343962431, 0.0004848698736168444, -0.005552675575017929, 0.0038700075820088387, -0.015249188989400864, 0.004837003070861101, -0.1771223545074463, 0.009865841828286648, 0.004699305631220341, -0.005165252834558487, -0.003669397672638297, -0.013641397468745708, -0.005254854913800955, 0.003957298584282398, 0.008548703044652939, -0.00010532326268730685, -0.0022269096225500107, 0.00015429771156050265, 0.00316805811598897, 0.0046647051349282265, -0.0014135998208075762, -0.004633433651179075, 0.0019624093547463417, -0.004119000397622585, -0.00009677447087597102, 0.004164739977568388, 0.004492349922657013, 0.009516719728708267, 0.002114257775247097, 0.002859701169654727, -0.001174152479507029, -0.003841451136395335, 0.006828979589045048, -0.004151757340878248, 0.004203100688755512, -0.01069481298327446, -0.0028327673207968473, -0.00519515061751008, -0.005687290802598, 0.003679282031953335, 0.005672583356499672, -0.0009196160244755447, 0.009441304951906204, 0.0027781357057392597, -0.007719581015408039, 0.009838945232331753, -0.00976055022329092, 0.02749740146100521, 0.0058155357837677, 0.006762482691556215, 0.00004712890222435817, -0.007084304466843605, -0.004577467683702707, 0.00809301808476448, 0.0018852946814149618, 0.012177838012576103, -0.011890552006661892, -0.0024883137084543705, 0.002132209250703454, 0.02050771750509739, -0.0058545442298054695, -0.008804891258478165, -0.007138012442737818, -0.0027923504821956158, 0.002536207903176546, 0.00904276967048645, 0.009646502323448658, -0.0035619374830275774, 0.0079718716442585, -0.002258389024063945, -0.0223979651927948, 0.0048733847215771675, -0.003537863027304411, -0.0064823622815310955, 0.0025812529493123293, 0.004355620592832565, 0.009471053257584572, -0.001045260694809258, 0.0028324697632342577, 0.0005102834547869861, 0.004498339723795652, -0.000026035175324068405, 0.007635054644197226, -0.0036083401646465063, 0.006383522413671017, -0.008215283043682575, 0.007288629189133644, -0.009799052029848099, -0.0015970362583175302, 0.002853789832442999, -0.003946731332689524, 0.010993110947310925, 0.004203741904348135, -0.0018696029437705874, 0.001205457840114832, -0.009961084462702274, -0.0019442859338596463, 0.001337422989308834, 0.0031163827516138554, -0.007994934916496277, 0.00353004178032279, -0.0008566392352804542, 0.006656388286501169, 0.005909366067498922, -0.00976388156414032, 0.0070679341442883015, 0.00547913508489728, -0.0066156452521681786, 0.0018015612149611115, -0.006867627147585154, 0.0012033339589834213, 0.004053754266351461, -0.006594439968466759, -0.006160811986774206, 0.0031211143359541893, -0.006010590121150017, -0.003967577125877142, 0.006278418004512787, -0.008778526447713375, -0.010019225999712944, -0.0015421062707901, -0.01133937668055296, 0.0013528888812288642 ]
8a9d019bec9e50c7c8d759ea60e658149d43ef2a
2,561
py
Python
audiomentations/core/utils.py
jeongyoonlee/audiomentations
7f0112ae310989430e0ef7eb32c4116114810966
[ "MIT" ]
1
2021-02-03T19:12:04.000Z
2021-02-03T19:12:04.000Z
audiomentations/core/utils.py
jeongyoonlee/audiomentations
7f0112ae310989430e0ef7eb32c4116114810966
[ "MIT" ]
null
null
null
audiomentations/core/utils.py
jeongyoonlee/audiomentations
7f0112ae310989430e0ef7eb32c4116114810966
[ "MIT" ]
1
2021-07-08T07:33:10.000Z
2021-07-08T07:33:10.000Z
import os from pathlib import Path import numpy as np AUDIO_FILENAME_ENDINGS = (".aiff", ".flac", ".m4a", ".mp3", ".ogg", ".opus", ".wav") def get_file_paths( root_path, filename_endings=AUDIO_FILENAME_ENDINGS, traverse_subdirectories=True ): """Return a list of paths to all files with the given filename extensions in a directory. Also traverses subdirectories by default. """ file_paths = [] for root, dirs, filenames in os.walk(root_path): filenames = sorted(filenames) for filename in filenames: input_path = os.path.abspath(root) file_path = os.path.join(input_path, filename) if filename.lower().endswith(filename_endings): file_paths.append(Path(file_path)) if not traverse_subdirectories: # prevent descending into subfolders break return file_paths def calculate_rms(samples): """Given a numpy array of audio samples, return its Root Mean Square (RMS).""" return np.sqrt(np.mean(np.square(samples), axis=-1)) def calculate_desired_noise_rms(clean_rms, snr): """ Given the Root Mean Square (RMS) of a clean sound and a desired signal-to-noise ratio (SNR), calculate the desired RMS of a noise sound to be mixed in. Based on https://github.com/Sato-Kunihiko/audio-SNR/blob/8d2c933b6c0afe6f1203251f4877e7a1068a6130/create_mixed_audio_file.py#L20 :param clean_rms: Root Mean Square (RMS) - a value between 0.0 and 1.0 :param snr: Signal-to-Noise (SNR) Ratio in dB - typically somewhere between -20 and 60 :return: """ a = float(snr) / 20 noise_rms = clean_rms / (10 ** a) return noise_rms def convert_decibels_to_amplitude_ratio(decibels): return 10 ** (decibels / 20) def is_waveform_multichannel(samples): """ Return bool that answers the question: Is the given ndarray a multichannel waveform or not? :param samples: numpy ndarray :return: """ return len(samples.shape) > 1 def is_spectrogram_multichannel(spectrogram): """ Return bool that answers the question: Is the given ndarray a multichannel spectrogram? :param samples: numpy ndarray :return: """ return len(spectrogram.shape) > 2 and spectrogram.shape[-1] > 1 def convert_float_samples_to_int16(y): """Convert floating-point numpy array of audio samples to int16.""" if not issubclass(y.dtype.type, np.floating): raise ValueError("input samples not floating-point") return (y * np.iinfo(np.int16).max).astype(np.int16)
31.617284
132
0.689184
0
0
[ 0.0012014225358143449, 0.02289920300245285, 0.010015868581831455, 0.00022356935369316489, 0.003364453325048089, -0.002697504125535488, -0.010418365709483624, 0.00364602985791862, -0.006431910675019026, 0.002445909893140197, 0.0026498474180698395, 0.0035591835621744394, 0.00897812657058239, -0.019755693152546883, -0.002075081691145897, 0.015570281073451042, -0.05258408933877945, 0.00038072155439294875, -0.004130651243031025, 0.005170183721929789, -0.006865378934890032, 0.009100198745727539, 0.007488762028515339, 0.005792166106402874, 0.006412901915609837, -0.00413521146401763, 0.012127557769417763, 0.0004847139061894268, -0.006400641985237598, -0.006157462950795889, -0.0006397352553904057, -0.002417620737105608, -0.007468369789421558, -0.009071123786270618, 0.006528431084007025, -0.003336807480081916, 0.00022382373572327197, -0.01934286393225193, 0.011474321596324444, -0.00361993839032948, -0.007440311834216118, -0.015127543359994888, 0.00011351285502314568, 0.0036641405895352364, -0.009541193023324013, 0.0007848127861507237, -0.00483222771435976, -0.0000019485055418044794, -0.010924534872174263, 0.005852697882801294, -0.009105037897825241, 0.006400939542800188, 0.015793954953551292, 0.0040077571757137775, -0.0070359548553824425, -0.00823542382568121, 0.01432372722774744, 0.0005511952913366258, -0.011389411054551601, -0.001204950618557632, -0.002183940727263689, -0.0013188704615458846, 0.005100624170154333, 0.004779471084475517, -0.014738408848643303, -0.008241805247962475, -0.005238507408648729, 0.002657259814441204, -0.0014619590947404504, 0.006591088604182005, 0.0027414392679929733, -0.001803060295060277, 0.009458807297050953, 0.005020159296691418, 0.0032075392082333565, -0.004153316840529442, -0.001481164013966918, -0.0026003937236964703, 0.007930719293653965, 0.003712077857926488, 0.0038372150156646967, -0.006390231661498547, 0.0045030624605715275, 0.009463786147534847, 0.01444108597934246, 0.010732807219028473, 0.021760884672403336, -0.009728490374982357, 0.04878788813948631, 0.009779895655810833, -0.008739443495869637, 0.0012352647027000785, -0.011181490495800972, -0.001845278195105493, -0.004877239465713501, -0.028520403429865837, 0.0004791530955117196, -0.004929307382553816, -0.0018903244053944945, 0.004871543031185865, 0.0005070966435596347, 0.007337701506912708, -0.0018992332043126225, -0.002332261297851801, -0.008433584123849869, 0.010207894258201122, -0.008748217485845089, -0.0034336792305111885, 0.006227379664778709, 0.0030927301850169897, -0.012106209993362427, -0.0013038695324212313, 0.0006450213259086013, -0.012505595572292805, 0.0034086343366652727, 0.002703179605305195, -0.004525310825556517, 0.05558692663908005, -0.002018402796238661, 0.00276742922142148, -0.003984655719250441, -0.00016964852693490684, 0.004120451398193836, 0.005869459360837936, 0.00937374122440815, -0.0031103817746043205, 0.011782514862716198, 0.00843520276248455, 0.004014025907963514, 0.00914032943546772, -0.0023337961174547672, 0.006962654646486044, -0.00344088370911777, -0.003651636652648449, 0.00042112398659810424, -0.007607622072100639, 0.007920272648334503, -0.001575598493218422, -0.008614696562290192, 0.0023439896758645773, 0.0004821367037948221, -0.007958116009831429, 0.0010169044835492969, -0.004772489424794912, 0.0043357182294130325, -0.010250256396830082, -0.005465716123580933, -0.00371512770652771, -0.003635937348008156, 0.0028629133012145758, 0.011820264160633087, 0.004837373737245798, 0.003149748547002673, -0.005424628034234047, -0.008344405330717564, 0.00025667125009931624, -0.00523344473913312, 0.0014897729270160198, 0.00795678049325943, 0.0035607581958174706, -0.012497322633862495, -0.0035564866848289967, 0.0033278530463576317, 0.0052055977284908295, -0.001823844388127327, 0.00225536129437387, -0.00930929183959961, 0.007368740625679493, -0.0008573501836508512, 0.003222373081371188, 0.012027780525386333, -0.005522583611309528, 0.00028012963593937457, 0.00036183156771585345, 0.0030168872326612473, -0.0016684491420164704, 0.006389828398823738, 0.011315015144646168, -0.004862683825194836, -0.005374726839363575, 0.005273216404020786, 0.005669348873198032, 0.008157855831086636, 0.007031291723251343, -0.005026326980441809, 0.0008983073639683425, -0.004491198342293501, -0.0015825910959392786, 0.006869079079478979, -0.0050667361356318, 0.004570916760712862, 0.0043708086013793945, -0.012512012384831905, -0.007903079502284527, -0.0008556682150810957, -0.005858051124960184, 0.0017945488216355443, 0.014081555418670177, 0.011807357892394066, -0.002789135091006756, 0.002276022220030427, -0.010166939347982407, 0.0009352554334327579, 0.0066155558452010155, 0.0027861199341714382, -0.013803577981889248, -0.9579502940177917, 0.0074084000661969185, 0.00465094018727541, -0.0037211028393357992, 0.005360750947147608, 0.0034577446058392525, 0.004015645012259483, 0.0037800518330186605, 0.01684914529323578, -0.005499111954122782, -0.006158000789582729, -0.01031393650919199, -0.012753615155816078, -0.0017169516067951918, -0.0069272187538445, -0.003834878094494343, -0.006645305547863245, -0.007495873142033815, -0.002700253389775753, -0.004152351524680853, -0.0034591732546687126, 0.00879680085927248, -0.0020678681321442127, 0.004299459513276815, 0.003604678437113762, 0.0035785946529358625, -0.004830594174563885, -0.0024019444826990366, -0.001993698300793767, -0.0027539776638150215, -0.006522892974317074, -0.01539238914847374, -0.0014813854359090328, -0.001756352256052196, 0.008646607398986816, 0.0015640484634786844, 0.008739428594708443, -0.0018441154388710856, 0.0012501415330916643, -0.0069297743029892445, 0.004914517980068922, 0.0005886476719751954, 0.0029608875047415495, -0.029581639915704727, -0.001618333742953837, -0.000356789561919868, -0.009193768724799156, 0.007608119398355484, -0.00013988226419314742, 0.0009713862091302872, -0.0034774832893162966, -0.006731550674885511, 0.008493819274008274, -0.007673034444451332, 0.005285029299557209, -0.006141826044768095, -0.009858286939561367, -0.001334148459136486, -0.009610646404325962, -0.0005563358427025378, 0.003417660016566515, -0.0036675119772553444, -0.005096442066133022, -0.0037106312811374664, 0.0024959526490420103, 0.003827974433079362, 0.001611356157809496, -0.02047799713909626, -0.008381311781704426, 0.0036363627295941114, 0.0005803646636195481, -0.0036364435218274593, -0.0034676147624850273, 0.0038172856438905, -0.009401815943419933, 0.006533894222229719, 0.0022998983040452003, -0.0009936339920386672, -0.01118213776499033, -0.0008031351026147604, -0.008771241642534733, -0.00832503940910101, 0.0025148328859359026, -0.0052025774493813515, -0.004556945525109768, -0.0014138572150841355, -0.0012897881679236889, 0.007720622234046459, -0.0030983686447143555, 0.004821453243494034, 0.010666277259588242, -0.0021314271725714207, -0.00856838934123516, 0.005984456278383732, 0.006211101543158293, 0.0006630817661061883, -0.002943864557892084, 0.001913721556775272, 0.00785231776535511, 0.006551362574100494, 0.0017414725152775645, 0.004504840821027756, 0.00014707178343087435, 0.009643372148275375, -0.000794474792201072, 0.000988425686955452, -0.002457911614328623, -0.0006128830136731267, -0.006729125045239925, -0.0004665010201279074, -0.006490074098110199, -0.004023250192403793, -0.012290027923882008, -0.008586028590798378, -0.0035888657439500093, -0.0024940255098044872, 0.004005807917565107, -0.005755725782364607, 0.0003258761717006564, 0.0010253444779664278, 0.007782820612192154, -0.0018136096186935902, -0.002390227746218443, 0.0012987438822165132, 0.0012613828293979168, -0.004747022874653339, 0.013777738437056541, -0.011714212596416473, 0.005129657685756683, -0.00024157411826308817, -0.016246933490037918, 0.008502829819917679, 0.009941205382347107, -0.006082901731133461, 0.0009929692605510354, 0.0034728345926851034, 0.003506097011268139, -0.00005541708378586918, -0.006229770369827747, -0.0026532113552093506, -0.016251258552074432, 0.0012299607042223215, 0.019494516775012016, 0.0028746402822434902, 0.010137559846043587, 0.011129199527204037, -0.004449338186532259, 0.0015508215874433517, 0.006257462315261364, 0.0016501727513968945, 0.014341611415147781, -0.008473780006170273, -0.00042983051389455795, 0.0013531682780012488, -0.008274019695818424, 0.001593280816450715, 0.007151735480874777, 0.004402946215122938, -0.003124043345451355, 0.0037555599119514227, -0.007632648106664419, -0.004657657817006111, -0.01746777817606926, -0.003901079762727022, 0.008144566789269447, -0.006348179187625647, 0.007660317700356245, -0.009429938159883022, 0.00469635846093297, 0.00643299613147974, 0.0042662364430725574, 0.0010080882348120213, 0.0010678968392312527, 0.004806241020560265, 0.012743636034429073, -0.006910427939146757, 0.002103316131979227, 0.002929059322923422, -0.0017630666261538863, -0.0022563179954886436, 0.009467307478189468, -0.007978270761668682, -0.004793099593371153, 0.002593369921669364, 0.0040046521462500095, 0.0024329032748937607, -0.003440969390794635, -0.00912412442266941, -0.003366148332133889, 0.0023981889244168997, -0.005606642458587885, 0.0038846852257847786, 0.0015165016520768404, 0.00337175652384758, -0.006078843027353287, 0.0004430940025486052, -0.0035294261761009693, -0.012180850841104984, 0.01190662570297718, -0.002535143867135048, 0.00331750325858593, 0.012920413166284561, 0.003761088475584984, -0.013097468763589859, 0.004595180973410606, 0.008789841085672379, -0.003205232322216034, 0.004478602670133114, 0.006818614434450865, -0.004886641167104244, -0.023075232282280922, -0.0023024410475045443, -0.013597474433481693, 0.00678600138053298, -0.0016909493133425713, 0.004038919694721699, -0.006479077972471714, 0.00728521216660738, 0.007782953791320324, -0.012641345150768757, -0.005973777733743191, -0.008566168136894703, 0.008345156908035278, -0.0005187829956412315, -0.001054519321769476, -0.0027294920291751623, -0.002565086120739579, -0.0021985513158142567, -0.0044211638160049915, -0.0037413127720355988, 0.004513334017246962, 0.0007539165671914816, -0.00212268834002316, 0.0032235390972346067, -0.004257200751453638, 0.001338709844276309, -0.000688693777192384, -0.010617516934871674, 0.0022712622303515673, 0.00472839642316103, -0.0025963408406823874, -0.003232790855690837, 0.00020597988623194396, -0.0023002063389867544, -0.006199314258992672, -0.010400866158306599, -0.004717146046459675, -0.004135102964937687, -0.002532710786908865, -0.012755394913256168, -0.002715335926041007, -0.010508280247449875, 0.006438001058995724, -0.0070117805153131485, 0.00890928041189909, 0.006059329491108656, -0.005446233320981264, 0.006877489387989044, -0.0017447894206270576, 0.005728365387767553, 0.0014695615973323584, 0.005314729642122984, 0.0001477283803978935, -0.005134609993547201, -0.011868518777191639, 0.012915857136249542, -0.008201484568417072, 0.00199422356672585, 0.012394883669912815, 0.002921350998803973, 0.009183642454445362, 0.0002055227814707905, -0.00019665043510030955, 0.0014784676022827625, 0.008279775269329548, -0.013764433562755585, 0.003925727680325508, -0.002630067290738225, 0.0012574715074151754, 0.004284369759261608, -0.002578610321506858, 0.0025454601272940636, 0.010131324641406536, 0.002187243662774563, -0.007315410766750574, -0.002435201546177268, 0.0036061974242329597, 0.003640261944383383, -0.014322985894978046, -0.0017146274913102388, -0.0016944875242188573, -0.004746769089251757, -0.0031914415303617716, -0.0025099723134189844, 0.0010653457138687372, 0.005759125575423241, -0.0018557311268523335, 0.006363022606819868, 0.0023747500963509083, -0.006322634872049093, 0.01536675076931715, -0.0055697704665362835, -0.0051346709951758385, 0.0043549067340791225, 0.004720319528132677, -0.00246306206099689, -0.006029563490301371, -0.0022582130040973425, 0.0024104746989905834, 0.006855741608887911, -0.002795271575450897, -0.003109474666416645, -0.0016673528589308262, 0.00024026120081543922, -0.010744125582277775, 0.0011485876748338342, 0.014036188833415508, -0.004250779282301664, 0.006901932880282402, -0.001003758516162634, -0.007636722642928362, -0.013255172409117222, 0.05362672358751297, -0.0006737394724041224, 0.002315300749614835, 0.005572051741182804, -0.008392572402954102, -0.00015883261221460998, -0.0027945181354880333, 0.008684364147484303, -0.007365035824477673, -0.006710958667099476, 0.008156110532581806, -0.004960610065609217, 0.0049541243351995945, 0.004559868481010199, -0.0017103865975514054, 0.01769779995083809, -0.0017137505346909165, -0.015037490986287594, -0.017808035016059875, 0.006540835835039616, -0.005158949643373489, -0.00586773082613945, 0.009593509137630463, -0.0031011286191642284, -0.0035230438224971294, 0.0015674518654122949, 0.007524130865931511, 0.0012969927629455924, -0.00028552880394272506, -0.0018051995430141687, -0.0009778100065886974, -0.0006403750739991665, 0.001752282027155161, 0.006171125452965498, 0.0077851442620158195, -0.002491788240149617, 0.003998213447630405, 0.0017472733743488789, -0.0009904608596116304, -0.0020631372462958097, 0.004738066345453262, 0.006462614051997662, -0.0015133272390812635, -0.002963826758787036, 0.007004277314990759, 0.004636283032596111, 0.0025882096961140633, 0.012145734392106533, 0.0008144289604388177, -0.007735311985015869, 0.009632092900574207, 0.004531298764050007, 0.00023809465346857905, 0.008986418135464191, -0.002748190425336361, 0.005142287351191044, 0.0013645242433995008, -0.007094439584761858, -0.016018174588680267, -0.0012175430310890079, 0.006630769465118647, 0.009841326624155045, -0.0018486770568415523, -0.00017942018166650087, -0.0017844634130597115, -0.002297183033078909, -0.007485551293939352, -0.007295300252735615, -0.003237323137000203, 0.002403185935690999, 0.002445894293487072, 0.07267487049102783, -0.007099422160536051, -0.001754836062900722, -0.010161620564758778, -0.0005152987432666123, -0.0020909204613417387, -0.001152797951363027, 0.0008644413901492953, -0.002735808026045561, 0.0026077425573021173, 0.0004991531604900956, -0.0088249072432518, -0.012247749604284763, 0.00003437454142840579, 0.0025791460648179054, -0.002636975608766079, 0.0057593174278736115, 0.007271233014762402, -0.009270294569432735, 0.00012225258979015052, -0.01226314902305603, -0.0022860225290060043, -0.00093076127814129, -0.00812219362705946, -0.005286690313369036, -0.0034450951498001814, 0.005580189172178507, 0.0025949447881430387, 0.006658751517534256, -0.002836608560755849, 0.006438404321670532, -0.004959451500326395, -0.001507570967078209, -0.004465526435524225, -0.001727658323943615, -0.006971200928092003, 0.007846777327358723, 0.00016395571583416313, -0.011380159296095371, -0.0044925701804459095, 0.000507734774146229, -0.0010188947198912501, -0.003897499991580844, 0.0037884076591581106, -0.000012722667634079698, 0.004599346313625574, -0.003399783978238702, -0.0002585541224107146, -0.008228832855820656, 0.003244123188778758, -0.013195861130952835, 0.005617799703031778, -0.17158156633377075, 0.009911278262734413, 0.0049874852411448956, -0.006831714417785406, -0.0035636720713227987, -0.014285435900092125, -0.005594214890152216, 0.0037319865077733994, 0.011152297258377075, 0.0003147157549392432, -0.0018951812526211143, 0.0002256857551401481, 0.005308246240019798, 0.002943296916782856, -0.0011419352376833558, -0.004230620805174112, 0.006458846852183342, -0.0031778288539499044, 0.0019613339100033045, 0.00511195557191968, 0.003279473166912794, 0.008030790835618973, 0.0018151121912524104, 0.002023995853960514, -0.0020622205920517445, -0.005196412559598684, 0.007629468105733395, -0.002498455112800002, 0.004750545136630535, -0.010529731400310993, -0.002372386399656534, -0.004201824311167002, -0.005386019125580788, 0.0014818910276517272, 0.006124446634203196, -0.0036886590532958508, 0.008590496145188808, 0.0020143885631114244, -0.008088881149888039, 0.006202050484716892, -0.009337942115962505, 0.02782009355723858, 0.005777428392320871, 0.004525556694716215, -0.00031842393218539655, -0.0070571694523096085, -0.004203035030514002, 0.008761480450630188, 0.0023092131596058607, 0.01179890614002943, -0.012122439220547676, 0.0006074522971175611, 0.0046380553394556046, 0.018833454698324203, -0.006716212723404169, -0.010864964686334133, -0.0059712352231144905, -0.0025690628681331873, 0.00153905909974128, 0.006933493074029684, 0.010607512667775154, -0.0031003577169030905, 0.010276160202920437, -0.0014024883275851607, -0.022931450977921486, 0.0033096978440880775, -0.004598379600793123, -0.007755590602755547, 0.0018404547590762377, 0.007336331531405449, 0.008311208337545395, 0.0009537989390082657, 0.0038063463289290667, -0.0012600165791809559, 0.005949647165834904, 0.00009730457531986758, 0.006727474741637707, -0.002014342462643981, 0.0052080522291362286, -0.009541140869259834, 0.007234918884932995, -0.010697314515709877, -0.00419625174254179, 0.0010009922552853823, -0.00368888839147985, 0.009018161334097385, 0.006232953630387783, -0.0006810416234657168, -0.001510155969299376, -0.008269675076007843, -0.002421271987259388, 0.0004544529365375638, 0.0026249291840940714, -0.00802901666611433, 0.001884670928120613, 0.0005220016464591026, 0.005555387120693922, 0.0072435312904417515, -0.00864551030099392, 0.004994281567633152, 0.005681595299392939, -0.0049411156214773655, 0.0005231350660324097, -0.003031092695891857, 0.003006050596013665, 0.0027378383092582226, -0.003705360693857074, -0.005553072784096003, 0.003741748631000519, -0.00842064805328846, -0.004719076212495565, 0.008720326237380505, -0.010000483132898808, -0.007919362746179104, -0.001877694041468203, -0.011674381792545319, -0.0006946123321540654 ]
8a9d4177e423a6db85599cff72c82ba14d5a1522
883
py
Python
algorithm/python/LeetCode/isValid.py
HoneyS2/meaningful
78659de1ed74121db4ade211f6565ddc6d117041
[ "MIT" ]
null
null
null
algorithm/python/LeetCode/isValid.py
HoneyS2/meaningful
78659de1ed74121db4ade211f6565ddc6d117041
[ "MIT" ]
null
null
null
algorithm/python/LeetCode/isValid.py
HoneyS2/meaningful
78659de1ed74121db4ade211f6565ddc6d117041
[ "MIT" ]
null
null
null
s = "([}}])" stack = [] if len(s) % 2 == 1: print(False) exit() for i in s: if i == "(": stack.append("(") elif i == "[": stack.append("[") elif i == "{": stack.append("{") elif i == ")": if len(stack) < 1: print(False) exit() if stack[-1] == "(": stack.pop() else: print(False) exit() elif i == "]": if len(stack) < 1: print(False) exit() if stack[-1] == "[": stack.pop() else: print(False) exit() elif i == "}": if len(stack) < 1: print(False) exit() if stack[-1] == "{": stack.pop() else: print(False) exit() if len(stack) == 0: print(True) else: print(False)
18.395833
28
0.347678
0
0
[ 0.00025001121684908867, 0.027218084782361984, 0.009003907442092896, -0.001191262505017221, 0.005834088195115328, -0.0035035342443734407, -0.011946188285946846, 0.004747104365378618, -0.004457881208509207, 0.001064256764948368, 0.0018252622103318572, 0.005543661303818226, 0.0064614806324243546, -0.01755196787416935, -0.0002619758015498519, 0.017921563237905502, -0.05230697989463806, 0.00013506606046576053, -0.002235849853605032, 0.0029876914341002703, -0.008405245840549469, 0.009551558643579483, 0.009856022894382477, 0.006436929106712341, 0.006570176221430302, 0.0019913907162845135, 0.006529375445097685, 0.001977948471903801, -0.00794826727360487, -0.006884567905217409, -0.00047283509047701955, -0.0026593944057822227, -0.005477157887071371, -0.009026344865560532, 0.004456485155969858, -0.0036413518246263266, -0.0015640471829101443, -0.019781796261668205, 0.01190230157226324, -0.004022540524601936, -0.007724992465227842, -0.017245786264538765, -0.0005216567078605294, 0.005475583020597696, -0.010029339231550694, 0.0036765600088983774, -0.004662889055907726, 0.0019707067403942347, -0.011550079099833965, 0.004805097822099924, -0.011217492632567883, 0.0042830295860767365, 0.014895348809659481, 0.0025236071087419987, -0.004464257042855024, -0.005967371631413698, 0.011692456901073456, -0.0012028204509988427, -0.009898538701236248, -0.0024325756821781397, -0.00353727163746953, -0.0015456395922228694, 0.006024639122188091, 0.0017147883772850037, -0.017312629148364067, -0.0075199054554104805, -0.006949995178729296, 0.0017311787232756615, -0.0014737967867404222, 0.004852637182921171, 0.0015303605468943715, -0.002084119478240609, 0.004843204747885466, 0.004136502277106047, 0.001572318491525948, -0.003169863484799862, -0.002190803876146674, 0.001374981366097927, 0.009247618727385998, 0.002318331738933921, 0.0030705356039106846, -0.007667877245694399, 0.00638278853148222, 0.00964786671102047, 0.013147423043847084, 0.0057104178704321384, 0.018909743055701256, -0.010991735383868217, 0.04449447989463806, 0.007250586990267038, -0.008272209204733372, 0.002895187819376588, -0.010223589837551117, -0.003936344292014837, -0.004660954233258963, -0.030005760490894318, 0.00026564643485471606, -0.004691249690949917, -0.0007864883518777788, 0.0031998232007026672, -0.0005129800993017852, 0.007729456759989262, -0.000016899919501156546, -0.002380635356530547, -0.011143817566335201, 0.011394870467483997, -0.011680354364216328, -0.0022783922031521797, 0.008141486905515194, 0.0033660794142633677, -0.01228935457766056, -0.0022793777752667665, 0.004371369257569313, -0.011902041733264923, 0.004729090258479118, 0.002653355011716485, -0.004576872102916241, 0.055277206003665924, 0.0008617626735940576, 0.0022866660729050636, -0.004754059482365847, 0.00014765484957024455, 0.0009880674770101905, 0.006382852792739868, 0.009191116318106651, -0.0050758616998791695, 0.010762478224933147, 0.00611932622268796, 0.0040354481898248196, 0.005400124005973339, -0.0020685286726802588, 0.007426918484270573, -0.006141542922705412, 0.00004431023626239039, -0.0007326487102545798, -0.008191228844225407, 0.008256416767835617, -0.0020437773782759905, -0.002655932679772377, 0.0008574455277994275, -0.0015209383564069867, -0.011632146313786507, 0.002279894659295678, -0.003838674630969763, 0.005320370197296143, -0.00981941819190979, -0.004139488562941551, -0.0018496551783755422, -0.005393694620579481, 0.000676591123919934, 0.011072481982409954, 0.005255614407360554, 0.002215201500803232, -0.005575067363679409, -0.008565721102058887, 0.00039417322841472924, -0.00650741346180439, 0.0029387057293206453, 0.008199431002140045, 0.006160916294902563, -0.009716776199638844, -0.002719438634812832, 0.003011632477864623, 0.0007753435638733208, 0.0012576008448377252, 0.0038363237399607897, -0.008069639094173908, 0.007271699141710997, -0.0006015351973474026, 0.0046005346812307835, 0.0120831448584795, -0.004673098213970661, -0.00019500601047184318, 0.000250148557825014, 0.0008473032503388822, 0.002072232775390148, 0.005461411084979773, 0.00905134342610836, -0.005377117078751326, -0.003599179442971945, 0.005915574263781309, 0.003695904044434428, 0.008921142667531967, 0.0038926510605961084, -0.001268067047931254, 0.00019897162565030158, -0.0045508164912462234, -0.0007928289123810828, 0.007646522019058466, -0.004952728748321533, 0.007558346726000309, 0.007754701655358076, -0.015547213144600391, -0.008903875015676022, 0.0007827407098375261, -0.011081401258707047, 0.00009050048538483679, 0.015556090511381626, 0.010824334807693958, -0.0023960755206644535, 0.0009834725642576814, -0.01373428013175726, 0.0010102177038788795, 0.009374711662530899, -0.00017064464918803424, -0.009941242635250092, -0.9563757181167603, 0.0051284306682646275, 0.004576482810080051, -0.0006192976143211126, 0.006380442529916763, 0.0023520763497799635, 0.004590433090925217, 0.003930880222469568, 0.01447749137878418, -0.009179733693599701, -0.0061880480498075485, -0.009778027422726154, -0.011153883300721645, -0.000364526902558282, -0.0058309659361839294, -0.0024945936165750027, -0.007330143358558416, -0.008159274235367775, -0.0029107953887432814, -0.0032204044982790947, -0.0016869851388037205, 0.007272628135979176, 0.0002423112455289811, 0.00504530593752861, 0.002705857390537858, 0.0028734514489769936, -0.005675832740962505, -0.0029807097744196653, 0.00011671730317175388, -0.0021009021438658237, -0.007192361168563366, -0.013289295136928558, -0.004248360171914101, 0.00034687682637013495, 0.01048874668776989, 0.0004410412802826613, 0.007975786924362183, -0.0032512929756194353, 0.00004376191282062791, -0.007378364447504282, 0.0040337140671908855, 0.0015972587279975414, 0.0032713888213038445, -0.030608240514993668, 0.00026291224639862776, -0.0005128563498146832, -0.007699543610215187, 0.008971287868916988, 0.0029282078612595797, -0.0006935274577699602, -0.003211090574041009, -0.005003505386412144, 0.01018460188060999, -0.006544969044625759, 0.00432835565879941, -0.004519632551819086, -0.008061402477324009, -0.00222387770190835, -0.008091539144515991, 0.002471528947353363, 0.004304456990212202, -0.005619690753519535, -0.004851477220654488, -0.005453332792967558, 0.003362061455845833, 0.0008546060416847467, 0.003961490001529455, -0.018751712515950203, -0.008353255689144135, -0.0013913974398747087, 0.003663970623165369, 0.0002989980566781014, -0.0045446427538990974, 0.003205040469765663, -0.008616642095148563, 0.005488720256835222, 0.0014005950652062893, 0.00009053538815351203, -0.012192051857709885, -0.00011963523866143078, -0.008829213678836823, -0.00887942686676979, 0.0025757953990250826, -0.0039531816728413105, -0.0044380491599440575, -0.0006814436637796462, 0.005158752202987671, 0.0058847893960773945, -0.0035791753325611353, 0.003578248666599393, 0.007940473034977913, -0.00035060240770690143, -0.009527753107249737, 0.007697237189859152, 0.007622861303389072, 0.0008724713698029518, -0.0004206922894809395, 0.003804930951446295, 0.009890501387417316, 0.007485220208764076, 0.0019490938866510987, 0.004721065983176231, 0.001664665061980486, 0.010004495270550251, -0.000255898165050894, 0.0016751979710534215, -0.0033806455321609974, -0.0005395904299803078, -0.004985702224075794, -0.000819320441223681, -0.0066847908310592175, -0.0011053300695493817, -0.014200123026967049, -0.009862213395535946, -0.0013939831405878067, 0.0030597576405853033, 0.0008548381738364697, -0.00536808418110013, 0.0001632873754715547, 0.0005215091514401138, 0.008824686519801617, -0.002148034516721964, -0.005581560544669628, 0.0011901457328349352, 0.0024464072193950415, -0.006469948682934046, 0.01508073229342699, -0.013116504997015, 0.008197231218218803, 0.000027809650418930687, -0.015570389106869698, 0.006227131467312574, 0.009998601861298084, -0.008922310546040535, 0.0016048054676502943, 0.00009762748231878504, 0.0038502707611769438, 0.0015461657894775271, -0.003861468518152833, -0.005089768208563328, -0.018355069682002068, -0.0005287392414174974, 0.02042095921933651, 0.002874464262276888, 0.010439896024763584, 0.012485737912356853, -0.004854756873100996, 0.0034180879592895508, 0.007495129480957985, 0.0007097534253261983, 0.014971354976296425, -0.006517467554658651, -0.0022081423085182905, 0.0034306009765714407, -0.006570978090167046, 0.0028167127165943384, 0.0041087353602051735, 0.0034697181545197964, -0.0035383892245590687, 0.0035560496617108583, -0.005139677785336971, -0.002712871413677931, -0.016399959102272987, -0.0034137843176722527, 0.006795791443437338, -0.0023021255619823933, 0.003806415945291519, -0.01299583911895752, 0.0071355439722537994, 0.0068660276010632515, 0.004510311409831047, 0.00026558712124824524, 0.0033073455560952425, 0.006327167619019747, 0.011057882569730282, -0.004147217143326998, 0.0031863662879914045, 0.0033319147769361734, 0.0003848569467663765, 0.001117984764277935, 0.005088369362056255, -0.008352775126695633, -0.004449909087270498, 0.0013558461796492338, 0.004279023036360741, -0.0013480833731591702, -0.0026861904188990593, -0.010232710279524326, -0.0038449219428002834, 0.004350186791270971, -0.008491815067827702, 0.0012241862714290619, -0.00023678790603298694, 0.004837485961616039, -0.007618642877787352, 0.0003036256821360439, -0.002628209302201867, -0.012292028404772282, 0.010005448944866657, -0.004172132816165686, 0.003613024018704891, 0.013423113152384758, 0.007543027866631746, -0.011999131180346012, 0.005029213149100542, 0.00990777462720871, -0.0076719122007489204, 0.0031000140588730574, 0.00709709944203496, -0.006930968724191189, -0.024210738018155098, -0.0027281467337161303, -0.01339779980480671, 0.007398130837827921, -0.0018388214521110058, 0.003950996790081263, -0.008994905278086662, 0.007736568804830313, 0.005091239232569933, -0.012646331451833248, -0.005858428776264191, -0.008767848834395409, 0.00899108499288559, -0.0009065665071830153, -0.0027472602669149637, -0.0027067784685641527, -0.000872677774168551, -0.002112467773258686, -0.002324402565136552, -0.002671373775228858, 0.005395508836954832, 0.0022439013700932264, -0.005109334364533424, 0.0027727962005883455, -0.00216498295776546, 0.0020492980256676674, 0.0030153095722198486, -0.00991525873541832, 0.003037366084754467, 0.004515626467764378, -0.0027372913900762796, -0.0027915893588215113, 0.0020814521703869104, -0.0005978759145364165, -0.007495441474020481, -0.010545732453465462, -0.0029882099479436874, -0.004044868517667055, -0.003527733264490962, -0.011984113603830338, -0.0027133836410939693, -0.009496728889644146, 0.007066804450005293, -0.00835928414016962, 0.008744267746806145, 0.00802299752831459, -0.005411065649241209, 0.00937765371054411, -0.001544258208014071, 0.003369398880749941, 0.0009111881372518837, 0.006198465824127197, 0.00004569933298625983, -0.005119632929563522, -0.011115132831037045, 0.013085095211863518, -0.008473523892462254, 0.00009585535735823214, 0.015022234991192818, 0.005718751810491085, 0.009320011362433434, 0.0022008041851222515, -0.0010226002195850015, 0.0025707234162837267, 0.008606605231761932, -0.013028252869844437, 0.0037197787314653397, -0.003670644713565707, -0.00015147618250921369, 0.004394720774143934, -0.005471938755363226, 0.0007998793153092265, 0.008525103330612183, -0.0007385155186057091, -0.007351905573159456, -0.002933347597718239, 0.0016975302714854479, 0.0016904823714867234, -0.013674241490662098, -0.0012458562850952148, -0.006017201114445925, -0.006671985611319542, -0.002090688794851303, -0.001246514730155468, -0.0005798449856229126, 0.0043907323852181435, -0.0004267701879143715, 0.006873040925711393, 0.004628946539014578, -0.0027675610035657883, 0.014765279367566109, -0.003063892014324665, -0.0030735887121409178, 0.005487100686877966, 0.0013118002098053694, -0.00042152201058343053, -0.004441115539520979, -0.004230530466884375, 0.0018816364463418722, 0.005852065049111843, -0.0017687288345769048, -0.0048095532692968845, -0.004976664204150438, 0.0007357915164902806, -0.008688329719007015, 0.0004758424765896052, 0.012564685195684433, -0.005999308079481125, 0.00628625089302659, -0.0004723417805507779, -0.008886420167982578, -0.016239745542407036, 0.053551800549030304, 0.0003014456306118518, 0.006055659614503384, 0.005056866444647312, -0.006030627992004156, 0.0004606710863299668, -0.000007898972398834303, 0.008006390184164047, -0.006067429669201374, -0.006149869412183762, 0.009621863253414631, -0.004967477172613144, 0.001981006469577551, 0.001699427841231227, 0.0012597953900694847, 0.01393920835107565, -0.004117448348551989, -0.01910337433218956, -0.013570480979979038, 0.007590847089886665, -0.0024514568503946066, -0.006032994482666254, 0.007975036278367043, -0.006233994849026203, -0.0025825072079896927, 0.00270395097322762, 0.006826070602983236, 0.00012595363659784198, 0.0010819912422448397, -0.0024554170668125153, -0.003161582164466381, 0.0008738224860280752, 0.002766850870102644, 0.0036983229219913483, 0.007951490581035614, -0.0011371425352990627, 0.005278882570564747, -0.0013006564695388079, -0.0013221283443272114, -0.001395525992847979, 0.004102112725377083, 0.008010586723685265, -0.00041500534280203283, -0.0029361294582486153, 0.004268342163413763, 0.0054856338538229465, 0.001280587282963097, 0.012593559920787811, -0.0016595390625298023, -0.0069174268282949924, 0.007425482384860516, 0.007530524395406246, -0.0003292124019935727, 0.009435020387172699, -0.0006645345129072666, 0.005454515106976032, 0.0016839251620694995, -0.008888696320354939, -0.014958163723349571, -0.002024679211899638, 0.007252795156091452, 0.008146857842803001, -0.0030889681074768305, 0.0014478623634204268, -0.0016964769456535578, -0.0030244344379752874, -0.008831022307276726, -0.007307872176170349, -0.002762432675808668, 0.0018883149605244398, 0.0043594432063400745, 0.07082977145910263, -0.005995201878249645, -0.0029421737417578697, -0.009712914004921913, -0.0016770907677710056, -0.0018857792019844055, 0.00012050770601490512, 0.00021420179109554738, 0.0010068468982353806, 0.002231125021353364, -0.00029667935450561345, -0.007686655502766371, -0.010792067274451256, 0.0001351323735434562, 0.0024090404622256756, -0.0030547159258276224, 0.0039511010982096195, 0.008122212253510952, -0.006852210033684969, 0.0019483747892081738, -0.011230320669710636, -0.002922561950981617, -0.003264680039137602, -0.010476155206561089, -0.003389475168660283, -0.0037217922508716583, 0.003918241243809462, 0.0030367765575647354, 0.0071030911058187485, -0.007271398790180683, 0.005855931434780359, -0.0008185242768377066, 0.000015761896065669134, -0.004294463898986578, 0.0015839512925595045, -0.005781346932053566, 0.00888428371399641, 0.003018168034031987, -0.012630141340196133, -0.006610714830458164, -0.0009467490599490702, 0.00029970292234793305, -0.005666391458362341, 0.005878507159650326, -0.0014501218684017658, 0.006484020501375198, -0.0033548795618116856, -0.0012180539779365063, -0.0064558894373476505, 0.005745739676058292, -0.012971863150596619, 0.0022728925105184317, -0.18040649592876434, 0.011979717761278152, 0.002420357894152403, -0.005173239856958389, -0.001133603509515524, -0.01626964472234249, -0.00899350643157959, 0.0016696780221536756, 0.00936475582420826, -0.00034065687214024365, -0.0011298175668343902, -0.003500930964946747, 0.009160549379885197, 0.0020371435675770044, -0.0006966367363929749, -0.0043695117346942425, 0.0039700353518128395, -0.0033455609809607267, -0.0007753569516353309, 0.002610563999041915, 0.006459730677306652, 0.008970868773758411, 0.003746150294318795, 0.0030093269888311625, -0.000708781648427248, -0.004961145576089621, 0.005595425143837929, -0.001569317770190537, 0.005552172195166349, -0.011018924415111542, -0.004035092890262604, -0.007138695102185011, -0.0035034900065511465, -0.000895086966920644, 0.005382911767810583, -0.00021265276882331818, 0.00866676401346922, 0.004073441959917545, -0.00709519675001502, 0.007559692021459341, -0.008449108339846134, 0.02985433116555214, 0.004278516862541437, 0.009143898263573647, 0.0018790882313624024, -0.004797634668648243, -0.005324540194123983, 0.009715540334582329, 0.00048038357635959983, 0.012703269720077515, -0.012263765558600426, -0.0034419656731188297, 0.00195533805526793, 0.019115371629595757, -0.00409720977768302, -0.01203451119363308, -0.006043098866939545, -0.004076790530234575, 0.003578429576009512, 0.0113506019115448, 0.010619080625474453, -0.006037578452378511, 0.007064823992550373, -0.0026430159341543913, -0.019543183967471123, 0.0045727021060884, -0.005921270698308945, -0.007891442626714706, 0.00003552426278474741, 0.007424099836498499, 0.01231713779270649, -0.0010143695399165154, 0.0052396152168512344, -0.0011776202591136098, 0.0031375179532915354, -0.0011615573894232512, 0.0057571264915168285, -0.0018345301505178213, 0.006371313240379095, -0.010279946029186249, 0.009051048196852207, -0.009252319112420082, -0.0012900667497888207, 0.001993127167224884, -0.004668990150094032, 0.009408427402377129, 0.003952683415263891, -0.0024415168445557356, -0.0015496815321967006, -0.010204894468188286, -0.0030475419480353594, 0.0011480125831440091, 0.004769142717123032, -0.007146020419895649, 0.0013518795603886247, -0.0024929014034569263, 0.004935209173709154, 0.006039799191057682, -0.010433058254420757, 0.0052503300830721855, 0.006421979051083326, -0.00663240859284997, 0.0009174069273285568, -0.004161525052040815, 0.001238916302099824, 0.0032908685971051455, -0.0063333818688988686, -0.008368595503270626, 0.0037270374596118927, -0.006352737080305815, -0.005578103940933943, 0.005336022470146418, -0.008941054344177246, -0.00654124841094017, -0.002136754570528865, -0.010227675549685955, 0.0007209687610156834 ]
8a9d8f1b16e1dbb065ddd8280ce1c889563a6417
4,831
py
Python
JupyterHTMLSlides/core.py
williamegomezo/JupyterSlides
403fe15e360eb1d79bf813b923eb569a81ab0934
[ "MIT" ]
1
2019-07-26T20:59:47.000Z
2019-07-26T20:59:47.000Z
JupyterHTMLSlides/core.py
williamegomezo/JupyterSlides
403fe15e360eb1d79bf813b923eb569a81ab0934
[ "MIT" ]
null
null
null
JupyterHTMLSlides/core.py
williamegomezo/JupyterSlides
403fe15e360eb1d79bf813b923eb569a81ab0934
[ "MIT" ]
null
null
null
import random import string import os from IPython.display import display, HTML from .utils import html_loader from .utils import get_content from jinja2 import Template class JupyterSlides: def __init__( self, content_path='./content.yaml', table_contents=False ): self.set_base_dirs() self.set_source_dirs() self.content = get_content(content_path) self.render_init_templates() if table_contents: self.render_table_contents() def set_base_dirs(self): self.module_path = os.path.dirname(os.path.realpath(__file__)) self.base_template_dir = f'{self.module_path}/src/templates' self.base_css_dir = f'{self.module_path}/src/assets/css' self.base_js_dir = f'{self.module_path}/src/js' def set_source_dirs(self): self.called_from_path = os.getcwd() folders = self.called_from_path.split('/') self.source_path = '/'.join(folders[:folders.index('talks')]) self.template_dir = f'{self.source_path}/src/templates' self.css_dir = f'{self.source_path}/src/css' self.js_dir = f'{self.source_path}/src/js' def render_init_templates(self): self.render( template='init', data={'dir': self.module_path}, template_dir=self.base_template_dir ) if os.path.isfile(f'{self.template_dir}/init.html'): self.render( template=f'init', data=self.content.get('init_vars', {}) ) id = JupyterSlides.randomUUID() self.render( template='eye', data={'eye_id': id}, template_dir=self.base_template_dir ) def render_table_contents(self): if os.path.isfile(f'{self.template_dir}/table-contents.html'): contents_template_dir = self.template_dir else: contents_template_dir = self.base_template_dir self.render( template='table-contents', data=self.generate_table_contents(), template_dir=contents_template_dir, render_type='slide' ) def parse_template(self, template=None, data={}, template_dir=None, render_type=None): if not template_dir: if os.path.isfile(f'{self.template_dir}/{template}.html'): html = html_loader(f'file:{self.template_dir}/{template}.html') else: template = 'basic-slide' html = html_loader(f'file:{self.base_template_dir}/{template}.html') else: if not os.path.isfile(f'{template_dir}/{template}.html'): template = 'basic-slide' template_dir = self.base_template_dir html = html_loader( f'file:{template_dir}/{template}.html') if render_type == 'slide': html = '<div id="{{ data["slide_id"] }}" class="slide-container">' + \ html + '</div>' tm = Template(html) return tm.render(data=data) def render(self, template=None, data={}, navigation=False, template_dir=None, render_type=None): html = self.parse_template( template=template, data=data, template_dir=template_dir, render_type=render_type ) if navigation: navigation_template = self.parse_template( template='navigation', template_dir=template_dir ) html += navigation_template display(HTML(html)) def render_content(self, key): data = self.content.get(key) id = JupyterSlides.randomUUID() self.render( template='eye', data={'eye_id': id}, template_dir=self.base_template_dir ) if data.get('slides'): for el in data.get('slides'): template = el.get('template') self.render(template=template, data=el, render_type='slide') @staticmethod def randomUUID(stringLength=20): """Generate a random string of fixed length """ letters = string.ascii_lowercase return ''.join(random.choice(letters) for i in range(stringLength)) def generate_table_contents(self): table = {} items = [] for _, item in self.content.items(): for sub_item in item['slides']: sub_item['slide_id'] = \ str(item['indice']) + '.' + str(sub_item['indice']) +\ sub_item['content_title'] item['slide_id'] = item['slides'][0]['slide_id'] items.append(item) table['title'] = 'Table of Contents' table['eyebrow'] = 'Table of Contents' table['items'] = items return table
33.783217
100
0.580211
2
1.8516
[ -0.024916592985391617, 0.06826528161764145, 0.008265865035355091, 0.007076490204781294, 0.023155780509114265, 0.014154943637549877, -0.0424262098968029, -0.016006840392947197, 0.044577401131391525, -0.03543413057923317, 0.03814501315355301, -0.013641893863677979, 0.04822833463549614, 0.016699843108654022, -0.00501910550519824, -0.026515204459428787, -0.0056634028442204, -0.001466437359340489, -0.03163497522473335, -0.009127155877649784, 0.0433594174683094, 0.04255284368991852, 0.03719066083431244, 0.008509809151291847, -0.002819731133058667, -0.011807680130004883, 0.02414117194712162, -0.023936308920383453, 0.003468959592282772, -0.043756164610385895, -0.01665690913796425, -0.013269983232021332, -0.03491641953587532, -0.04712250828742981, 0.010972552001476288, -0.03073132038116455, -0.024057850241661072, 0.009855205193161964, -0.01314274501055479, -0.053762372583150864, 0.035614676773548126, -0.004088485613465309, -0.005102671217173338, 0.010956195183098316, 0.02311595156788826, 0.022719137370586395, -0.021906550973653793, 0.0020879926159977913, 0.009522350504994392, 0.011664140038192272, -0.035856153815984726, 0.007234148681163788, 0.023393942043185234, -0.02372339367866516, -0.025061674416065216, -0.027474144473671913, -0.000051543727749958634, -0.006419321987777948, -0.024249857291579247, -0.029087284579873085, -0.014397232793271542, 0.011052321642637253, 0.007810238283127546, 0.01413782499730587, -0.06631918251514435, -0.03160340338945389, -0.020385202020406723, 0.02293483540415764, -0.017066529020667076, -0.004717603791505098, -0.025059131905436516, 0.023697586730122566, -0.03923465311527252, 0.03924237936735153, 0.02631239779293537, -0.0049260463565588, -0.030248194932937622, -0.03390980511903763, 0.002625351073220372, -0.034451987594366074, 0.023166297003626823, 0.04264131560921669, 0.031716153025627136, -0.0014354169834405184, 0.00675966264680028, 0.029431898146867752, 0.004119716584682465, -0.02478908561170101, 0.035394251346588135, 0.02339998632669449, -0.016487136483192444, 0.021284906193614006, -0.08600499480962753, 0.00390878738835454, -0.05770200863480568, -0.0014055680949240923, 0.015857424587011337, -0.04463096335530281, -0.0014773306902498007, 0.009570459835231304, -0.021897634491324425, -0.01718492992222309, 0.015251006931066513, -0.013950088992714882, 0.008526875637471676, -0.01302586030215025, -0.0031827001366764307, -0.0583612322807312, -0.0010327249765396118, -0.029938936233520508, -0.021054565906524658, -0.000010239999028271995, -0.04537186026573181, -0.01711280643939972, -0.013868618756532669, -0.01336002815514803, -0.002980489982292056, 0.03306988626718521, 0.019288569688796997, 0.0353112556040287, 0.00912826880812645, 0.010825020261108875, 0.0084233982488513, 0.022611422464251518, 0.018064016476273537, 0.00952941458672285, 0.023484794422984123, -0.006387421395629644, -0.02527107670903206, -0.004479547962546349, 0.01882082223892212, 0.005403237883001566, -0.015333575196564198, -0.010784747079014778, -0.011351115070283413, -0.029421353712677956, 0.025396795943379402, -0.01851840130984783, -0.03940587490797043, -0.016572704538702965, 0.018003560602664948, -0.01892034336924553, -0.022814705967903137, 0.038989149034023285, 0.0008177197305485606, -0.054999690502882004, -0.005776626989245415, 0.0060399300418794155, -0.00034826903720386326, 0.010103163309395313, 0.028660522773861885, 0.014781644567847252, 0.01170842070132494, 0.046254757791757584, -0.04675870016217232, -0.015225084498524666, 0.040416114032268524, 0.005841752514243126, 0.0022392268292605877, 0.03421175852417946, -0.009289604611694813, 0.012155741453170776, 0.011641908437013626, 0.055136390030384064, 0.015622464008629322, 0.019479136914014816, 0.041153814643621445, 0.027071209624409676, 0.014620937407016754, -0.006841249298304319, 0.026061998680233955, 0.004340159706771374, -0.03170023858547211, 0.018205072730779648, 0.004637441132217646, -0.04961412400007248, 0.023258168250322342, 0.0451069138944149, 0.010520425625145435, -0.00891523715108633, 0.012022582814097404, -0.05633296072483063, 0.06210358813405037, 0.03955169767141342, -0.023890189826488495, 0.0028826941270381212, 0.03654489293694496, 0.01356123760342598, 0.01494589727371931, -0.02449377253651619, -0.0163713525980711, -0.02479509450495243, 0.00480227405205369, -0.016299162060022354, -0.005848661530762911, -0.018138306215405464, -0.01918972283601761, -0.026575446128845215, -0.0008150690118782222, -0.004604560323059559, 0.017045484855771065, 0.04121599718928337, -0.032798200845718384, -0.002477913396432996, 0.0041219312697649, 0.02894107811152935, -0.6519699096679688, 0.022800493985414505, 0.05343376845121384, -0.031091421842575073, 0.06998464465141296, 0.015452778898179531, -0.009262182749807835, 0.04177827760577202, 0.05934986472129822, 0.002298991661518812, 0.006122547201812267, -0.00974151398986578, -0.05114422366023064, -0.0003008199855685234, 0.008587862364947796, 0.020004509016871452, -0.019509749487042427, -0.0193790253251791, 0.00734189385548234, 0.030445823445916176, 0.019007083028554916, -0.07265790551900864, -0.01927071250975132, 0.0013317437842488289, 0.03062514215707779, 0.022218024358153343, -0.015948431566357613, 0.04967687278985977, -0.01928878016769886, 0.03237820416688919, -0.006413385737687349, -0.029294472187757492, 0.020877793431282043, 0.02179773896932602, -0.021755503490567207, -0.027244649827480316, 0.03685441613197327, 0.02168377675116062, -0.02918623760342598, -0.027294641360640526, -0.013614880852401257, -0.005160184111446142, 0.02494877763092518, -0.03164244070649147, -0.026302393525838852, -0.013906009495258331, 0.0027863909490406513, 0.03161342442035675, 0.025834618136286736, 0.007130718789994717, -0.006219082977622747, 0.002831985242664814, 0.0343494638800621, -0.033850040286779404, -0.003776716999709606, -0.005354184657335281, -0.038448967039585114, 0.011606904678046703, -0.029730377718806267, -0.04473863169550896, -0.021232910454273224, -0.01158276665955782, 0.00016581999079789966, 0.021008402109146118, -0.01040748879313469, -0.04081200435757637, 0.0225289948284626, -0.016086623072624207, -0.050382256507873535, 0.020608235150575638, 0.01041483785957098, -0.006440050434321165, 0.021360158920288086, -0.03530270233750343, -0.004346954636275768, 0.01624022237956524, 0.03419061005115509, -0.05433688312768936, -0.0395132414996624, -0.04187871143221855, 0.021746305748820305, -0.022512590512633324, 0.02441762574017048, -0.06513949483633041, 0.0004227004246786237, 0.012695563957095146, -0.029601026326417923, -0.012048151344060898, -0.02957240305840969, 0.0022247161250561476, 0.012426252476871014, 0.004766628611832857, 0.013632197864353657, 0.051038097590208054, 0.051018472760915756, 0.016216851770877838, 0.042132310569286346, 0.005138632841408253, -0.015417342074215412, 0.012910977937281132, 0.01799282804131508, 0.024388747289776802, -0.00011670157255139202, 0.011397290974855423, -0.04281756281852722, 0.00008071499178186059, -0.011020421050488949, 0.01960177905857563, -0.021491941064596176, 0.012272017076611519, -0.05312662571668625, -0.023184241726994514, 0.021463513374328613, 0.0003248004650231451, 0.01974404975771904, -0.0212382934987545, 0.0020719377789646387, -0.02403486892580986, 0.005553413648158312, 0.007724950555711985, -0.04152407869696617, 0.08129244297742844, 0.05225009471178055, -0.002006478374823928, -0.013451574370265007, -0.000267019378952682, 0.012369654141366482, -0.036812469363212585, 0.0009348809253424406, 0.05370258912444115, 0.0012523914920166135, -0.002933365758508444, 0.02046246826648712, -0.04480813443660736, 0.00805701408535242, 0.016751959919929504, -0.0251215361058712, 0.014931298792362213, 0.000300796702504158, -0.02743777632713318, 0.0034229368902742863, 0.036796677857637405, 0.0468456894159317, -0.04682907834649086, 0.015595505945384502, 0.03135082125663757, 0.03323373198509216, 0.020998945459723473, -0.06058454513549805, -0.012767685577273369, -0.052881885319948196, 0.004736707080155611, 0.035634107887744904, 0.01354184839874506, 0.006430633831769228, -0.003940690774470568, 0.0058505176566541195, 0.025358280166983604, -0.023029254749417305, 0.031436242163181305, -0.008263100869953632, -0.03209322690963745, 0.02781921997666359, -0.029863329604268074, 0.0011300977785140276, 0.0022558069322258234, -0.048065975308418274, -0.06278013437986374, 0.02452317625284195, 0.04914136230945587, 0.0008071119664236903, 0.015169426798820496, -0.03481554239988327, 0.009256107732653618, 0.03319940343499184, -0.011286841705441475, 0.048119571059942245, -0.015881724655628204, -0.0110118817538023, -0.008613274432718754, 0.001304343342781067, 0.0007539137732237577, -0.036101166158914566, -0.0012845356250181794, -0.03142618387937546, 0.017690123990178108, -0.026711689308285713, -0.021279621869325638, -0.008972512558102608, 0.004010493867099285, -0.029525814577937126, -0.005444815848022699, -0.022053522989153862, 0.03229864686727524, -0.02331644669175148, -0.009282078593969345, 0.02651282027363777, -0.03533674031496048, -0.012460828758776188, 0.005174408666789532, -0.012966766953468323, 0.0107400668784976, -0.0015833013458177447, -0.026640281081199646, -0.06397121399641037, 0.025468168780207634, -0.02131984569132328, -0.018557893112301826, 0.0065261078998446465, 0.0060598417185246944, -0.011206766590476036, 0.011709706857800484, 0.04725058004260063, -0.004219707101583481, -0.024756167083978653, 0.0009012979571707547, -0.03185581788420677, 0.028771523386240005, 0.01541229896247387, 0.012977972626686096, -0.019977573305368423, -0.01058387104421854, 0.010660268366336823, -0.03814201429486275, 0.022770553827285767, -0.013959777541458607, -0.03311533480882645, -0.015964316204190254, -0.03292454779148102, -0.03147125989198685, 0.011152083054184914, -0.018999207764863968, 0.0006485304911620915, 0.006090518552809954, -0.0008638306171633303, -0.0018294526962563396, -0.03638709709048271, -0.026841670274734497, 0.045384056866168976, 0.0230404119938612, 0.018167052417993546, -0.029983164742588997, 0.0005201866733841598, -0.0006608809344470501, -0.034942690283060074, 0.034277353435754776, 0.06466367840766907, 0.010716790333390236, -0.006836544722318649, 0.01693282648921013, -0.009506773203611374, -0.006346453446894884, -0.02040964737534523, -0.04276388883590698, 0.030200976878404617, -0.002775158965960145, 0.012205935083329678, 0.001052401727065444, 0.003126050578430295, 0.02280549891293049, 0.016236279159784317, -0.03935815766453743, -0.0072913821786642075, 0.0435819998383522, -0.01165666151791811, 0.007866568863391876, -0.01376995537430048, -0.02414727583527565, -0.022725192829966545, 0.03174052760004997, -0.028721021488308907, -0.009686155244708061, 0.006520238239318132, 0.0337311215698719, 0.021350907161831856, 0.006398784462362528, 0.009536301717162132, -0.008291177451610565, 0.011176945641636848, 0.04200940206646919, -0.0229754988104105, -0.012910695746541023, -0.036308396607637405, 0.018880443647503853, -0.025934819132089615, 0.014836045913398266, 0.061743736267089844, -0.02741815149784088, -0.03117723949253559, -0.0058728731237351894, 0.01623551920056343, -0.03173954412341118, -0.01834280602633953, 0.04449867829680443, 0.00584574555978179, 0.01341470330953598, -0.0003968306118622422, 0.001151456730440259, 0.026422029361128807, -0.0290176160633564, 0.024715809151530266, 0.010298963636159897, 0.00023950600007083267, 0.011586932465434074, -0.01921321079134941, 0.004617038182914257, -0.017145711928606033, -0.024350278079509735, -0.0018825294682756066, -0.03326331824064255, 0.04505462571978569, -0.02163071744143963, -0.01748819090425968, -0.013843454420566559, -0.01218610443174839, -0.03655079007148743, 0.013371576555073261, 0.02477387897670269, 0.04125666245818138, 0.009228639304637909, 0.03961726650595665, -0.022428223863244057, -0.0007732363301329315, -0.0145215829834342, -0.037175193428993225, -0.004459337331354618, -0.039602186530828476, -0.004924941807985306, 0.010692020878195763, -0.010803147219121456, 0.0008607687777839601, -0.059014808386564255, 0.02393263950943947, 0.020772332325577736, 0.03247331082820892, -0.03771333023905754, 0.0008364180102944374, 0.03965763375163078, 0.038994740694761276, 0.02166702225804329, -0.0340590663254261, 0.026424191892147064, -0.042655471712350845, -0.020123062655329704, 0.020917775109410286, 0.005627594888210297, -0.06043217331171036, 0.022926654666662216, 0.035011857748031616, 0.0361151397228241, -0.0245375819504261, -0.02471267804503441, -0.00682616513222456, 0.0183172095566988, 0.01222395058721304, -0.004435509908944368, -0.017866456881165504, -0.006176874972879887, 0.04610886797308922, 0.02601410634815693, 0.020907413214445114, 0.029836764559149742, 0.0017527001909911633, -0.003209899179637432, -0.005436841864138842, -0.0716099962592125, 0.03359777107834816, -0.0251768771559, 0.01006194669753313, 0.0010307529009878635, -0.04190434515476227, -0.011224682442843914, 0.018219763413071632, 0.002615089761093259, 0.028365524485707283, 0.02950301393866539, 0.004026758950203657, 0.024743976071476936, -0.001297083916142583, 0.0009023573948070407, -0.01982049271464348, 0.000746813602745533, -0.05247221142053604, 0.04288669675588608, -0.0074866414070129395, -0.03100832924246788, 0.010492219589650631, 0.024084245786070824, 0.0038799557369202375, -0.020405372604727745, 0.02207290753722191, 0.020556563511490822, -0.0022509582340717316, 0.011608057655394077, -0.016701729968190193, -0.010434519499540329, -0.025270240381360054, -0.017202528193593025, -0.014410141855478287, 0.003987062256783247, 0.017867041751742363, 0.000813621620181948, -0.024895619601011276, -0.049757830798625946, -0.06971979886293411, -0.0005794349126517773, 0.021213402971625328, 0.025447579100728035, 0.002626922680065036, -0.017264533787965775, 0.014207040891051292, -0.002799032721668482, -0.039285290986299515, -0.005505080334842205, 0.021458741277456284, 0.001958364387974143, -0.011582202278077602, 0.0353226400911808, -0.036175016313791275, 0.017679953947663307, -0.02132106013596058, 0.014703653752803802, 0.011188419535756111, -0.010850050486624241, -0.016722604632377625, 0.0034805256873369217, 0.00987658929079771, -0.002438434399664402, -0.04692327603697777, 0.027558062225580215, 0.0016668477328494191, 0.03276776894927025, -0.0044504557736217976, 0.0273783840239048, -0.009484396316111088, 0.03795716166496277, -0.0086531862616539, 0.02255939319729805, 0.016714317724108696, 0.030136656016111374, 0.009042249992489815, 0.007196055259555578, 0.009299117140471935, -0.018337516114115715, 0.0068090190179646015, -0.14520461857318878, -0.0434471033513546, -0.001789628411643207, -0.011659934185445309, -0.04398464784026146, -0.07989799976348877, 0.007124221418052912, -0.026735013350844383, 0.010478214360773563, 0.013861252926290035, 0.048327453434467316, -0.008624491281807423, -0.06901919096708298, 0.008109335787594318, 0.03281588852405548, -0.020226866006851196, -0.0019188383594155312, -0.010404753498733044, -0.027514103800058365, 0.07235485315322876, 0.008848801255226135, 0.06277154386043549, 0.0026925746351480484, 0.01545693725347519, -0.001835531904362142, 0.06570520251989365, 0.02317909523844719, 0.014140253886580467, 0.0006875497638247907, -0.050225481390953064, -0.003447964321821928, -0.0024589048698544502, 0.007263774052262306, 0.059259552508592606, 0.032794296741485596, -0.02012513391673565, 0.004697832278907299, 0.0499085932970047, -0.014545858837664127, -0.0025726312305778265, 0.01568102277815342, -0.036519795656204224, 0.0033771046437323093, 0.012563261203467846, -0.011716224253177643, 0.009293480776250362, -0.028312265872955322, -0.01537120807915926, 0.0383225679397583, 0.009991716593503952, 0.04389159381389618, 0.016373736783862114, -0.04443889483809471, 0.029382627457380295, -0.06640689074993134, 0.02466006949543953, -0.026876283809542656, -0.01870729774236679, 0.016440102830529213, 0.011567486450076103, 0.04532822594046593, 0.006873530335724354, 0.05907522141933441, -0.045349471271038055, 0.004608273971825838, 0.015098423697054386, 0.01884174719452858, 0.01532450970262289, -0.04341914504766464, -0.022007744759321213, -0.008805149234831333, 0.005483970977365971, -0.01907574012875557, 0.028108105063438416, 0.0032655925024300814, -0.008964776992797852, 0.009204352274537086, -0.004992659669369459, 0.016749823465943336, -0.016925711184740067, 0.006327946670353413, -0.004918287042528391, -0.038763973861932755, -0.004743392113596201, 0.0059603312984108925, 0.0015984191559255123, -0.008336955681443214, 0.03216513618826866, -0.004597598686814308, -0.00020535255316644907, -0.030133267864584923, -0.0025232627522200346, 0.03920295834541321, -0.012528669089078903, -0.010643868707120419, 0.0736512839794159, 0.023682238534092903, -0.0017951343907043338, -0.026289386674761772, -0.02742781490087509, -0.025564102455973625, -0.022065842524170876, 0.01869540847837925, 0.02684618905186653, 0.007628845516592264, -0.0138075090944767, 0.0003595530870370567, 0.09943919628858566, 0.0228143148124218, -0.023921404033899307, -0.010519314557313919, -0.0005477553931996226, 0.009914059191942215, -0.015348964370787144, -0.01816912181675434, -0.006899651139974594, 0.022261910140514374 ]
8a9e11dd86387cdd76e5db9dfd7ce9770e952aef
30,203
py
Python
tests/test_wallet.py
NickeZ/lightning
f376a9c24cc71d139393196dea86b5a39aee7db8
[ "MIT" ]
1
2020-05-07T22:28:20.000Z
2020-05-07T22:28:20.000Z
tests/test_wallet.py
satoshinakamoto007/lightning
ff968e773074061d6f76cb81c6c61a1047ffaef1
[ "MIT" ]
1
2020-05-03T00:56:31.000Z
2020-05-03T00:56:31.000Z
tests/test_wallet.py
satoshinakamoto007/lightning
ff968e773074061d6f76cb81c6c61a1047ffaef1
[ "MIT" ]
null
null
null
from decimal import Decimal from fixtures import * # noqa: F401,F403 from fixtures import TEST_NETWORK from flaky import flaky # noqa: F401 from pyln.client import RpcError, Millisatoshi from utils import ( only_one, wait_for, sync_blockheight, EXPERIMENTAL_FEATURES, COMPAT, VALGRIND ) import os import pytest import subprocess import time import unittest @unittest.skipIf(TEST_NETWORK != 'regtest', "Test relies on a number of example addresses valid only in regtest") def test_withdraw(node_factory, bitcoind): amount = 1000000 # Don't get any funds from previous runs. l1 = node_factory.get_node(random_hsm=True) l2 = node_factory.get_node(random_hsm=True) addr = l1.rpc.newaddr()['bech32'] # Add some funds to withdraw later for i in range(10): l1.bitcoin.rpc.sendtoaddress(addr, amount / 10**8 + 0.01) bitcoind.generate_block(1) wait_for(lambda: len(l1.rpc.listfunds()['outputs']) == 10) # Reach around into the db to check that outputs were added assert l1.db_query('SELECT COUNT(*) as c FROM outputs WHERE status=0')[0]['c'] == 10 waddr = l1.bitcoin.rpc.getnewaddress() # Now attempt to withdraw some (making sure we collect multiple inputs) with pytest.raises(RpcError): l1.rpc.withdraw('not an address', amount) with pytest.raises(RpcError): l1.rpc.withdraw(waddr, 'not an amount') with pytest.raises(RpcError): l1.rpc.withdraw(waddr, -amount) with pytest.raises(RpcError, match=r'Cannot afford transaction'): l1.rpc.withdraw(waddr, amount * 100) out = l1.rpc.withdraw(waddr, 2 * amount) # Make sure bitcoind received the withdrawal unspent = l1.bitcoin.rpc.listunspent(0) withdrawal = [u for u in unspent if u['txid'] == out['txid']] assert(withdrawal[0]['amount'] == Decimal('0.02')) l1.bitcoin.generate_block(1) sync_blockheight(l1.bitcoin, [l1]) # Check that there are no unconfirmed outputs (change should be confirmed) for o in l1.rpc.listfunds()['outputs']: assert o['status'] == 'confirmed' # Now make sure two of them were marked as spent assert l1.db_query('SELECT COUNT(*) as c FROM outputs WHERE status=2')[0]['c'] == 2 # Now send some money to l2. # lightningd uses P2SH-P2WPKH waddr = l2.rpc.newaddr('bech32')['bech32'] l1.rpc.withdraw(waddr, 2 * amount) bitcoind.generate_block(1) # Make sure l2 received the withdrawal. wait_for(lambda: len(l2.rpc.listfunds()['outputs']) == 1) outputs = l2.db_query('SELECT value FROM outputs WHERE status=0;') assert only_one(outputs)['value'] == 2 * amount # Now make sure an additional two of them were marked as spent assert l1.db_query('SELECT COUNT(*) as c FROM outputs WHERE status=2')[0]['c'] == 4 # Simple test for withdrawal to P2WPKH # Address from: https://bc-2.jp/tools/bech32demo/index.html waddr = 'bcrt1qw508d6qejxtdg4y5r3zarvary0c5xw7kygt080' with pytest.raises(RpcError): l1.rpc.withdraw('xx1qw508d6qejxtdg4y5r3zarvary0c5xw7kxpjzsx', 2 * amount) with pytest.raises(RpcError): l1.rpc.withdraw('tb1pw508d6qejxtdg4y5r3zarvary0c5xw7kdl9fad', 2 * amount) with pytest.raises(RpcError): l1.rpc.withdraw('tb1qw508d6qejxtdg4y5r3zarvary0c5xw7kxxxxxx', 2 * amount) l1.rpc.withdraw(waddr, 2 * amount) bitcoind.generate_block(1) # Now make sure additional two of them were marked as spent assert l1.db_query('SELECT COUNT(*) as c FROM outputs WHERE status=2')[0]['c'] == 6 # Simple test for withdrawal to P2WSH # Address from: https://bc-2.jp/tools/bech32demo/index.html waddr = 'bcrt1qrp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3qzf4jry' with pytest.raises(RpcError): l1.rpc.withdraw('xx1qrp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3q0sl5k7', 2 * amount) with pytest.raises(RpcError): l1.rpc.withdraw('tb1prp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3qsm03tq', 2 * amount) with pytest.raises(RpcError): l1.rpc.withdraw('tb1qrp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3qxxxxxx', 2 * amount) l1.rpc.withdraw(waddr, 2 * amount) bitcoind.generate_block(1) # Now make sure additional two of them were marked as spent assert l1.db_query('SELECT COUNT(*) as c FROM outputs WHERE status=2')[0]['c'] == 8 # failure testing for invalid SegWit addresses, from BIP173 # HRP character out of range with pytest.raises(RpcError): l1.rpc.withdraw(' 1nwldj5', 2 * amount) # overall max length exceeded with pytest.raises(RpcError): l1.rpc.withdraw('an84characterslonghumanreadablepartthatcontainsthenumber1andtheexcludedcharactersbio1569pvx', 2 * amount) # No separator character with pytest.raises(RpcError): l1.rpc.withdraw('pzry9x0s0muk', 2 * amount) # Empty HRP with pytest.raises(RpcError): l1.rpc.withdraw('1pzry9x0s0muk', 2 * amount) # Invalid witness version with pytest.raises(RpcError): l1.rpc.withdraw('BC13W508D6QEJXTDG4Y5R3ZARVARY0C5XW7KN40WF2', 2 * amount) # Invalid program length for witness version 0 (per BIP141) with pytest.raises(RpcError): l1.rpc.withdraw('BC1QR508D6QEJXTDG4Y5R3ZARVARYV98GJ9P', 2 * amount) # Mixed case with pytest.raises(RpcError): l1.rpc.withdraw('tb1qrp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3q0sL5k7', 2 * amount) # Non-zero padding in 8-to-5 conversion with pytest.raises(RpcError): l1.rpc.withdraw('tb1qrp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3pjxtptv', 2 * amount) # Should have 6 outputs available. assert l1.db_query('SELECT COUNT(*) as c FROM outputs WHERE status=0')[0]['c'] == 6 # Test withdrawal to self. l1.rpc.withdraw(l1.rpc.newaddr('bech32')['bech32'], 'all', minconf=0) bitcoind.generate_block(1) assert l1.db_query('SELECT COUNT(*) as c FROM outputs WHERE status=0')[0]['c'] == 1 l1.rpc.withdraw(waddr, 'all', minconf=0) assert l1.db_query('SELECT COUNT(*) as c FROM outputs WHERE status=0')[0]['c'] == 0 # This should fail, can't even afford fee. with pytest.raises(RpcError, match=r'Cannot afford transaction'): l1.rpc.withdraw(waddr, 'all') # Add some funds to withdraw for i in range(10): l1.bitcoin.rpc.sendtoaddress(addr, amount / 10**8 + 0.01) bitcoind.generate_block(1) wait_for(lambda: len(l1.rpc.listfunds()['outputs']) == 10) # Try passing in a utxo set utxos = [utxo["txid"] + ":" + str(utxo["output"]) for utxo in l1.rpc.listfunds()["outputs"]][:4] withdrawal = l1.rpc.withdraw(waddr, 2 * amount, utxos=utxos) decode = bitcoind.rpc.decoderawtransaction(withdrawal['tx']) assert decode['txid'] == withdrawal['txid'] # Check that correct utxos are included assert len(decode['vin']) == 4 vins = ["{}:{}".format(v['txid'], v['vout']) for v in decode['vin']] for utxo in utxos: assert utxo in vins def test_minconf_withdraw(node_factory, bitcoind): """Issue 2518: ensure that ridiculous confirmation levels don't overflow The number of confirmations is used to compute a maximum height that is to be accepted. If the current height is smaller than the number of confirmations we wrap around and just select everything. The fix is to clamp the maxheight parameter to a positive small number. """ amount = 1000000 # Don't get any funds from previous runs. l1 = node_factory.get_node(random_hsm=True) addr = l1.rpc.newaddr()['bech32'] # Add some funds to withdraw later for i in range(10): l1.bitcoin.rpc.sendtoaddress(addr, amount / 10**8 + 0.01) bitcoind.generate_block(1) wait_for(lambda: len(l1.rpc.listfunds()['outputs']) == 10) with pytest.raises(RpcError): l1.rpc.withdraw(destination=addr, satoshi=10000, feerate='normal', minconf=9999999) def test_addfunds_from_block(node_factory, bitcoind): """Send funds to the daemon without telling it explicitly """ # Previous runs with same bitcoind can leave funds! l1 = node_factory.get_node(random_hsm=True) addr = l1.rpc.newaddr()['bech32'] bitcoind.rpc.sendtoaddress(addr, 0.1) bitcoind.generate_block(1) wait_for(lambda: len(l1.rpc.listfunds()['outputs']) == 1) outputs = l1.db_query('SELECT value FROM outputs WHERE status=0;') assert only_one(outputs)['value'] == 10000000 # The address we detect must match what was paid to. output = only_one(l1.rpc.listfunds()['outputs']) assert output['address'] == addr # Send all our money to a P2WPKH address this time. addr = l1.rpc.newaddr("bech32")['bech32'] l1.rpc.withdraw(addr, "all") bitcoind.generate_block(1) time.sleep(1) # The address we detect must match what was paid to. output = only_one(l1.rpc.listfunds()['outputs']) assert output['address'] == addr @unittest.skipIf(not COMPAT, "needs COMPAT=1") def test_deprecated_txprepare(node_factory, bitcoind): """Test the deprecated old-style: txprepare {destination} {satoshi} {feerate} {minconf} """ amount = 10**4 l1 = node_factory.get_node(options={'allow-deprecated-apis': True}) addr = l1.rpc.newaddr()['bech32'] for i in range(7): l1.fundwallet(10**8) bitcoind.generate_block(1) sync_blockheight(bitcoind, [l1]) wait_for(lambda: len(l1.rpc.listfunds()['outputs']) == 7) # Array type with pytest.raises(RpcError, match=r'.* should be an amount in satoshis or all, not .*'): l1.rpc.call('txprepare', [addr, 'slow']) with pytest.raises(RpcError, match=r'Need set \'satoshi\' field.'): l1.rpc.call('txprepare', [addr]) with pytest.raises(RpcError, match=r'Could not parse destination address.*'): l1.rpc.call('txprepare', [Millisatoshi(amount * 100), 'slow', 1]) l1.rpc.call('txprepare', [addr, Millisatoshi(amount * 100), 'slow', 1]) l1.rpc.call('txprepare', [addr, Millisatoshi(amount * 100), 'normal']) l1.rpc.call('txprepare', [addr, Millisatoshi(amount * 100), None, 1]) l1.rpc.call('txprepare', [addr, Millisatoshi(amount * 100)]) # Object type with pytest.raises(RpcError, match=r'Need set \'outputs\' field.'): l1.rpc.call('txprepare', {'destination': addr, 'feerate': 'slow'}) with pytest.raises(RpcError, match=r'Need set \'outputs\' field.'): l1.rpc.call('txprepare', {'satoshi': Millisatoshi(amount * 100), 'feerate': '10perkw', 'minconf': 2}) l1.rpc.call('txprepare', {'destination': addr, 'satoshi': Millisatoshi(amount * 100), 'feerate': '2000perkw', 'minconf': 1}) l1.rpc.call('txprepare', {'destination': addr, 'satoshi': Millisatoshi(amount * 100), 'feerate': '2000perkw'}) l1.rpc.call('txprepare', {'destination': addr, 'satoshi': Millisatoshi(amount * 100)}) def test_txprepare_multi(node_factory, bitcoind): amount = 10000000 l1 = node_factory.get_node(random_hsm=True) bitcoind.rpc.sendtoaddress(l1.rpc.newaddr()['bech32'], amount / 10**8) bitcoind.generate_block(1) wait_for(lambda: len(l1.rpc.listfunds()['outputs']) == 1) outputs = [] for i in range(9): outputs.append({l1.rpc.newaddr()['bech32']: Millisatoshi(amount * 100)}) prep = l1.rpc.txprepare(outputs=outputs) l1.rpc.txdiscard(prep['txid']) def test_txprepare(node_factory, bitcoind, chainparams): amount = 1000000 l1 = node_factory.get_node(random_hsm=True) addr = chainparams['example_addr'] # Add some funds to withdraw later: both bech32 and p2sh for i in range(5): bitcoind.rpc.sendtoaddress(l1.rpc.newaddr()['bech32'], amount / 10**8) bitcoind.rpc.sendtoaddress(l1.rpc.newaddr('p2sh-segwit')['p2sh-segwit'], amount / 10**8) bitcoind.generate_block(1) wait_for(lambda: len(l1.rpc.listfunds()['outputs']) == 10) prep = l1.rpc.txprepare(outputs=[{addr: Millisatoshi(amount * 3 * 1000)}]) decode = bitcoind.rpc.decoderawtransaction(prep['unsigned_tx']) assert decode['txid'] == prep['txid'] # 4 inputs, 2 outputs (3 if we have a fee output). assert len(decode['vin']) == 4 assert len(decode['vout']) == 2 if not chainparams['feeoutput'] else 3 # One output will be correct. outnum = [i for i, o in enumerate(decode['vout']) if o['value'] == Decimal(amount * 3) / 10**8][0] for i, o in enumerate(decode['vout']): if i == outnum: assert o['scriptPubKey']['type'] == 'witness_v0_keyhash' assert o['scriptPubKey']['addresses'] == [addr] else: assert o['scriptPubKey']['type'] in ['witness_v0_keyhash', 'fee'] # Now prepare one with no change. prep2 = l1.rpc.txprepare([{addr: 'all'}]) decode = bitcoind.rpc.decoderawtransaction(prep2['unsigned_tx']) assert decode['txid'] == prep2['txid'] # 6 inputs, 1 outputs. assert len(decode['vin']) == 6 assert len(decode['vout']) == 1 if not chainparams['feeoutput'] else 2 # Some fees will be paid. assert decode['vout'][0]['value'] < Decimal(amount * 6) / 10**8 assert decode['vout'][0]['value'] > Decimal(amount * 6) / 10**8 - Decimal(0.0002) assert decode['vout'][0]['scriptPubKey']['type'] == 'witness_v0_keyhash' assert decode['vout'][0]['scriptPubKey']['addresses'] == [addr] # If I cancel the first one, I can get those first 4 outputs. discard = l1.rpc.txdiscard(prep['txid']) assert discard['txid'] == prep['txid'] assert discard['unsigned_tx'] == prep['unsigned_tx'] prep3 = l1.rpc.txprepare([{addr: 'all'}]) decode = bitcoind.rpc.decoderawtransaction(prep3['unsigned_tx']) assert decode['txid'] == prep3['txid'] # 4 inputs, 1 outputs. assert len(decode['vin']) == 4 assert len(decode['vout']) == 1 if not chainparams['feeoutput'] else 2 # Some fees will be taken assert decode['vout'][0]['value'] < Decimal(amount * 4) / 10**8 assert decode['vout'][0]['value'] > Decimal(amount * 4) / 10**8 - Decimal(0.0002) assert decode['vout'][0]['scriptPubKey']['type'] == 'witness_v0_keyhash' assert decode['vout'][0]['scriptPubKey']['addresses'] == [addr] # Cannot discard twice. with pytest.raises(RpcError, match=r'not an unreleased txid'): l1.rpc.txdiscard(prep['txid']) # Discard everything, we should now spend all inputs. l1.rpc.txdiscard(prep2['txid']) l1.rpc.txdiscard(prep3['txid']) prep4 = l1.rpc.txprepare([{addr: 'all'}]) decode = bitcoind.rpc.decoderawtransaction(prep4['unsigned_tx']) assert decode['txid'] == prep4['txid'] # 10 inputs, 1 outputs. assert len(decode['vin']) == 10 assert len(decode['vout']) == 1 if not chainparams['feeoutput'] else 2 # Some fees will be taken assert decode['vout'][0]['value'] < Decimal(amount * 10) / 10**8 assert decode['vout'][0]['value'] > Decimal(amount * 10) / 10**8 - Decimal(0.0003) assert decode['vout'][0]['scriptPubKey']['type'] == 'witness_v0_keyhash' assert decode['vout'][0]['scriptPubKey']['addresses'] == [addr] l1.rpc.txdiscard(prep4['txid']) # Try passing in a utxo set utxos = [utxo["txid"] + ":" + str(utxo["output"]) for utxo in l1.rpc.listfunds()["outputs"]][:4] prep5 = l1.rpc.txprepare([{addr: Millisatoshi(amount * 3.5 * 1000)}], utxos=utxos) decode = bitcoind.rpc.decoderawtransaction(prep5['unsigned_tx']) assert decode['txid'] == prep5['txid'] # Check that correct utxos are included assert len(decode['vin']) == 4 vins = ["{}:{}".format(v['txid'], v['vout']) for v in decode['vin']] for utxo in utxos: assert utxo in vins # We should have a change output, so this is exact assert len(decode['vout']) == 3 if chainparams['feeoutput'] else 2 assert decode['vout'][1]['value'] == Decimal(amount * 3.5) / 10**8 assert decode['vout'][1]['scriptPubKey']['type'] == 'witness_v0_keyhash' assert decode['vout'][1]['scriptPubKey']['addresses'] == [addr] # Discard prep4 and get all funds again l1.rpc.txdiscard(prep5['txid']) with pytest.raises(RpcError, match=r'this destination wants all satoshi. The count of outputs can\'t be more than 1'): prep5 = l1.rpc.txprepare([{addr: Millisatoshi(amount * 3 * 1000)}, {addr: 'all'}]) prep5 = l1.rpc.txprepare([{addr: Millisatoshi(amount * 3 * 500 + 100000)}, {addr: Millisatoshi(amount * 3 * 500 - 100000)}]) decode = bitcoind.rpc.decoderawtransaction(prep5['unsigned_tx']) assert decode['txid'] == prep5['txid'] # 4 inputs, 3 outputs(include change). assert len(decode['vin']) == 4 assert len(decode['vout']) == 4 if chainparams['feeoutput'] else 3 # One output will be correct. for i in range(3 + chainparams['feeoutput']): if decode['vout'][i - 1]['value'] == Decimal('0.01500100'): outnum1 = i - 1 elif decode['vout'][i - 1]['value'] == Decimal('0.01499900'): outnum2 = i - 1 else: changenum = i - 1 assert decode['vout'][outnum1]['scriptPubKey']['type'] == 'witness_v0_keyhash' assert decode['vout'][outnum1]['scriptPubKey']['addresses'] == [addr] assert decode['vout'][outnum2]['scriptPubKey']['type'] == 'witness_v0_keyhash' assert decode['vout'][outnum2]['scriptPubKey']['addresses'] == [addr] assert decode['vout'][changenum]['scriptPubKey']['type'] == 'witness_v0_keyhash' def test_txsend(node_factory, bitcoind, chainparams): amount = 1000000 l1 = node_factory.get_node(random_hsm=True) addr = chainparams['example_addr'] # Add some funds to withdraw later: both bech32 and p2sh for i in range(5): bitcoind.rpc.sendtoaddress(l1.rpc.newaddr()['bech32'], amount / 10**8) bitcoind.rpc.sendtoaddress(l1.rpc.newaddr('p2sh-segwit')['p2sh-segwit'], amount / 10**8) bitcoind.generate_block(1) wait_for(lambda: len(l1.rpc.listfunds()['outputs']) == 10) prep = l1.rpc.txprepare([{addr: Millisatoshi(amount * 3 * 1000)}]) out = l1.rpc.txsend(prep['txid']) # Cannot discard after send! with pytest.raises(RpcError, match=r'not an unreleased txid'): l1.rpc.txdiscard(prep['txid']) wait_for(lambda: prep['txid'] in bitcoind.rpc.getrawmempool()) # Signed tx should have same txid decode = bitcoind.rpc.decoderawtransaction(out['tx']) assert decode['txid'] == prep['txid'] bitcoind.generate_block(1) # Change output should appear. if decode['vout'][0]['value'] == Decimal(amount * 3) / 10**8: changenum = 1 elif decode['vout'][1]['value'] == Decimal(amount * 3) / 10**8: changenum = 0 else: assert False # Those spent outputs are gone, but change output has arrived. wait_for(lambda: len(l1.rpc.listfunds()['outputs']) == 10 - len(decode['vin']) + 1) # Change address should appear in listfunds() assert decode['vout'][changenum]['scriptPubKey']['addresses'][0] in [f['address'] for f in l1.rpc.listfunds()['outputs']] def test_txprepare_restart(node_factory, bitcoind, chainparams): amount = 1000000 l1 = node_factory.get_node(may_fail=True) addr = chainparams['example_addr'] # Add some funds to withdraw later: both bech32 and p2sh for i in range(5): bitcoind.rpc.sendtoaddress(l1.rpc.newaddr()['bech32'], amount / 10**8) bitcoind.rpc.sendtoaddress(l1.rpc.newaddr('p2sh-segwit')['p2sh-segwit'], amount / 10**8) bitcoind.generate_block(1) wait_for(lambda: [o['status'] for o in l1.rpc.listfunds()['outputs']] == ['confirmed'] * 10) prep = l1.rpc.txprepare([{addr: 'all'}]) decode = bitcoind.rpc.decoderawtransaction(prep['unsigned_tx']) assert decode['txid'] == prep['txid'] # All 10 inputs assert len(decode['vin']) == 10 # L1 will forget all about it. l1.restart() # It goes backwards in blockchain just in case there was a reorg. Wait. wait_for(lambda: [o['status'] for o in l1.rpc.listfunds()['outputs']] == ['confirmed'] * 10) with pytest.raises(RpcError, match=r'not an unreleased txid'): l1.rpc.txdiscard(prep['txid']) prep = l1.rpc.txprepare([{addr: 'all'}]) decode = bitcoind.rpc.decoderawtransaction(prep['unsigned_tx']) assert decode['txid'] == prep['txid'] # All 10 inputs assert len(decode['vin']) == 10 # This will also work if we simply kill it. l1.restart(clean=False) # It goes backwards in blockchain just in case there was a reorg. Wait. wait_for(lambda: [o['status'] for o in l1.rpc.listfunds()['outputs']] == ['confirmed'] * 10) # It should have logged this for each output. for i in decode['vin']: assert l1.daemon.is_in_log('wallet: reserved output {}/{} reset to available'.format(i['txid'], i['vout'])) prep = l1.rpc.txprepare([{addr: 'all'}]) decode = bitcoind.rpc.decoderawtransaction(prep['unsigned_tx']) assert decode['txid'] == prep['txid'] # All 10 inputs assert len(decode['vin']) == 10 @unittest.skipIf(TEST_NETWORK != 'regtest', "Fee outputs throw off our output matching logic") @unittest.skipIf(not EXPERIMENTAL_FEATURES, "Tests annotations which are compiled only with experimental features") def test_transaction_annotations(node_factory, bitcoind): l1, l2, l3 = node_factory.get_nodes(3) l1.fundwallet(10**6) # We should now have a transaction that gave us the funds in the # transactions table... outputs = l1.rpc.listfunds()['outputs'] assert(len(outputs) == 1 and outputs[0]['status'] == 'confirmed') out = outputs[0] idx = out['output'] assert(idx in [0, 1] and out['value'] == 10**6) # ... and it should have an annotation on the output reading 'deposit' txs = l1.rpc.listtransactions()['transactions'] assert(len(txs) == 1) tx = txs[0] output = tx['outputs'][idx] assert(output['type'] == 'deposit' and output['satoshis'] == '1000000000msat') # ... and all other output should be change, and have no annotations types = [] for i, o in enumerate(tx['outputs']): if i == idx: continue if 'type' in o: types.append(o['type']) else: types.append(None) assert(set([None]) == set(types)) ########################################################################## # Let's now open a channel. The opener should get the funding transaction # annotated as channel open and deposit. l1.connect(l2) fundingtx = l1.rpc.fundchannel(l2.info['id'], 10**5) # We should have one output available, and it should be unconfirmed outputs = l1.rpc.listfunds()['outputs'] assert(len(outputs) == 1 and outputs[0]['status'] == 'unconfirmed') # It should also match the funding txid: assert(outputs[0]['txid'] == fundingtx['txid']) # Confirm the channel and check that the output changed to confirmed bitcoind.generate_block(3) sync_blockheight(bitcoind, [l1, l2]) outputs = l1.rpc.listfunds()['outputs'] assert(len(outputs) == 1 and outputs[0]['status'] == 'confirmed') # We should have 2 transactions, the second one should be the funding tx # (we are ordering by blockheight and txindex, so that order should be ok) txs = l1.rpc.listtransactions()['transactions'] assert(len(txs) == 2 and txs[1]['hash'] == fundingtx['txid']) # Check the annotated types types = [o['type'] for o in txs[1]['outputs']] changeidx = 0 if types[0] == 'deposit' else 1 fundidx = 1 - changeidx assert(types[changeidx] == 'deposit' and types[fundidx] == 'channel_funding') # And check the channel annotation on the funding output peers = l1.rpc.listpeers()['peers'] assert(len(peers) == 1 and len(peers[0]['channels']) == 1) scid = peers[0]['channels'][0]['short_channel_id'] assert(txs[1]['outputs'][fundidx]['channel'] == scid) @unittest.skipIf(VALGRIND, "It does not play well with prompt and key derivation.") def test_hsm_secret_encryption(node_factory): l1 = node_factory.get_node(may_fail=True) # May fail when started without key password = "reckful\n" # We need to simulate a terminal to use termios in `lightningd`. master_fd, slave_fd = os.openpty() # Test we can encrypt an already-existing and not encrypted hsm_secret l1.stop() l1.daemon.opts.update({"encrypted-hsm": None}) l1.daemon.start(stdin=slave_fd, wait_for_initialized=False) l1.daemon.wait_for_log(r'The hsm_secret is encrypted') os.write(master_fd, password.encode("utf-8")) l1.daemon.wait_for_log("Server started with public key") id = l1.rpc.getinfo()["id"] l1.stop() # Test we cannot start the same wallet without specifying --encrypted-hsm l1.daemon.opts.pop("encrypted-hsm") with pytest.raises(subprocess.CalledProcessError, match=r'returned non-zero exit status 1'): subprocess.check_call(l1.daemon.cmd_line) # Test we cannot restore the same wallet with another password l1.daemon.opts.update({"encrypted-hsm": None}) l1.daemon.start(stdin=slave_fd, stderr=subprocess.STDOUT, wait_for_initialized=False) l1.daemon.wait_for_log(r'The hsm_secret is encrypted') os.write(master_fd, password[2:].encode("utf-8")) assert(l1.daemon.proc.wait() == 1) assert(l1.daemon.is_in_log("Wrong password for encrypted hsm_secret.")) # Test we can restore the same wallet with the same password l1.daemon.start(stdin=slave_fd, wait_for_initialized=False) l1.daemon.wait_for_log(r'The hsm_secret is encrypted') os.write(master_fd, password.encode("utf-8")) l1.daemon.wait_for_log("Server started with public key") assert id == l1.rpc.getinfo()["id"] @unittest.skipIf(VALGRIND, "It does not play well with prompt and key derivation.") def test_hsmtool_secret_decryption(node_factory): l1 = node_factory.get_node() password = "reckless\n" hsm_path = os.path.join(l1.daemon.lightning_dir, TEST_NETWORK, "hsm_secret") # We need to simulate a terminal to use termios in `lightningd`. master_fd, slave_fd = os.openpty() # Encrypt the master seed l1.stop() l1.daemon.opts.update({"encrypted-hsm": None}) l1.daemon.start(stdin=slave_fd, wait_for_initialized=False) l1.daemon.wait_for_log(r'The hsm_secret is encrypted') os.write(master_fd, password.encode("utf-8")) l1.daemon.wait_for_log("Server started with public key") node_id = l1.rpc.getinfo()["id"] l1.stop() # We can't use a wrong password ! cmd_line = ["tools/hsmtool", "decrypt", hsm_path, "A wrong pass"] with pytest.raises(subprocess.CalledProcessError): subprocess.check_call(cmd_line) # Decrypt it with hsmtool cmd_line[3] = password[:-1] subprocess.check_call(cmd_line) # Then test we can now start it without password l1.daemon.opts.pop("encrypted-hsm") l1.daemon.start(stdin=slave_fd, wait_for_initialized=True) assert node_id == l1.rpc.getinfo()["id"] l1.stop() # Test we can encrypt it offline cmd_line[1] = "encrypt" subprocess.check_call(cmd_line) # Now we need to pass the encrypted-hsm startup option l1.stop() with pytest.raises(subprocess.CalledProcessError, match=r'returned non-zero exit status 1'): subprocess.check_call(l1.daemon.cmd_line) l1.daemon.opts.update({"encrypted-hsm": None}) master_fd, slave_fd = os.openpty() l1.daemon.start(stdin=slave_fd, stderr=subprocess.STDOUT, wait_for_initialized=False) l1.daemon.wait_for_log(r'The hsm_secret is encrypted') os.write(master_fd, password.encode("utf-8")) l1.daemon.wait_for_log("Server started with public key") assert node_id == l1.rpc.getinfo()["id"] l1.stop() # And finally test that we can also decrypt if encrypted with hsmtool cmd_line[1] = "decrypt" subprocess.check_call(cmd_line) l1.daemon.opts.pop("encrypted-hsm") l1.daemon.start(stdin=slave_fd, wait_for_initialized=True) assert node_id == l1.rpc.getinfo()["id"] # this test does a 'listtransactions' on a yet unconfirmed channel def test_fundchannel_listtransaction(node_factory, bitcoind): l1, l2 = node_factory.get_nodes(2) l1.fundwallet(10**6) l1.connect(l2) txid = l1.rpc.fundchannel(l2.info['id'], 10**5)['txid'] # next call warned about SQL Accessing a null column # and crashed the daemon for accessing random memory or null txs = l1.rpc.listtransactions()['transactions'] tx = [t for t in txs if t['hash'] == txid][0] assert tx['blockheight'] == 0 def test_withdraw_nlocktime(node_factory): """ Test that we don't set the nLockTime to 0 for withdrawal transactions. """ l1 = node_factory.get_node(1) l1.fundwallet(10**4) addr = l1.rpc.newaddr()["bech32"] tx = l1.rpc.withdraw(addr, 10**3)["tx"] nlocktime = node_factory.bitcoind.rpc.decoderawtransaction(tx)["locktime"] tip = node_factory.bitcoind.rpc.getblockcount() assert nlocktime > 0 and nlocktime <= tip @flaky @unittest.skipIf(VALGRIND, "A big loop is used to check fuzz.") def test_withdraw_nlocktime_fuzz(node_factory, bitcoind): """ Test that we eventually fuzz nLockTime for withdrawal transactions. Marked flaky "just in case" as we fuzz from 0 to 100 with a 10% probability. """ l1 = node_factory.get_node(1) l1.fundwallet(10**8) for i in range(100): addr = l1.rpc.newaddr()["bech32"] withdraw = l1.rpc.withdraw(addr, 10**3) bitcoind.generate_block(1) l1.daemon.wait_for_log('Owning output .* txid {} CONFIRMED'. format(withdraw["txid"])) decoded = bitcoind.rpc.decoderawtransaction(withdraw["tx"]) tip = node_factory.bitcoind.rpc.getblockcount() assert decoded["locktime"] > 0 if decoded["locktime"] < tip: return else: raise Exception("No transaction with fuzzed nLockTime !")
40.704852
130
0.65957
1
2.5671
[ -0.014227751642465591, -0.024790555238723755, 0.003857443341985345, 0.04280640184879303, -0.02567349374294281, 0.035326700657606125, 0.018553754314780235, -0.021844711154699326, 0.0028079000767320395, -0.004344798158854246, -0.050383467227220535, -0.017731696367263794, -0.01656401716172695, -0.023133601993322372, -0.017311178147792816, -0.012172136455774307, 0.07307504862546921, -0.011799799278378487, -0.008476787246763706, 0.033338695764541626, -0.0014835490146651864, 0.0008300008485093713, -0.03000807762145996, 0.04262842237949371, 0.0060471962206065655, -0.021164745092391968, 0.054199300706386566, 0.02386942133307457, -0.001782681094482541, -0.040808212012052536, -0.018333150073885918, 0.010495079681277275, -0.011859615333378315, -0.026145901530981064, -0.03867039829492569, -0.004642040003091097, 0.005512884818017483, -0.026072610169649124, 0.012291193008422852, 0.02440503239631653, 0.007070879451930523, -0.02122509479522705, -0.016803469508886337, 0.00404140492901206, 0.044866207987070084, 0.03556697815656662, -0.02104645036160946, 0.00249562319368124, -0.04581977427005768, 0.033179037272930145, 0.015336957760155201, -0.022430572658777237, -0.00024747056886553764, -0.032589513808488846, 0.0028249030001461506, -0.050823815166950226, 0.009005479514598846, 0.07351352274417877, -0.003678327426314354, 0.027995893731713295, -0.03316511958837509, 0.0018349470337852836, 0.0019709481857717037, 0.0076006813906133175, -0.02221676893532276, 0.014622926712036133, -0.011333652772009373, -0.010170064866542816, -0.04188968613743782, 0.01854065991938114, 0.015668870881199837, 0.01463666558265686, 0.018609439954161644, 0.055521611124277115, -0.013393694534897804, -0.021094901487231255, -0.03709311783313751, -0.03241494670510292, -0.0018883924931287766, 0.043343424797058105, -0.011947639286518097, 0.07191703468561172, -0.012648292817175388, -0.02457561530172825, -0.014394231140613556, -0.009426288306713104, -0.014530311338603497, -0.08219119906425476, 0.04769375920295715, 0.018219362944364548, -0.019903700798749924, -0.01907455176115036, -0.01592351123690605, 0.005149290896952152, -0.056243956089019775, -0.04597248136997223, 0.03719588741660118, 0.02070247195661068, -0.00196774210780859, -0.020884046331048012, 0.011852537281811237, -0.006879161112010479, 0.021992811933159828, -0.014498040080070496, 0.0022948512341827154, -0.008712024427950382, -0.002680156147107482, -0.018225576728582382, 0.016665352508425713, -0.047572121024131775, -0.05341777577996254, 0.008008553646504879, 0.005688028875738382, -0.04950251802802086, -0.016511252149939537, -0.02549722045660019, 0.028917858377099037, 0.03671480342745781, -0.004135431721806526, -0.04334075376391411, 0.02739611268043518, -0.005363611504435539, 0.012267465703189373, -0.04214005544781685, -0.03228721395134926, 0.056089263409376144, -0.011929553933441639, -0.02322225272655487, 0.011962590739130974, -0.018035871908068657, 0.019718918949365616, 0.02593419700860977, -0.0022137907799333334, -0.01954548805952072, -0.0078567024320364, 0.02147797867655754, 0.004937225952744484, -0.009819844737648964, -0.06123363971710205, -0.020752137526869774, -0.023895906284451485, -0.020225686952471733, -0.015285225585103035, -0.07825537025928497, -0.004425616469234228, -0.00789640098810196, -0.012092663906514645, -0.029145704582333565, -0.03151734545826912, -0.012269861064851284, 0.025079229846596718, 0.03495001420378685, -0.03161847963929176, 0.011620156466960907, -0.0011300144251435995, -0.03520679846405983, -0.012012257240712643, -0.0617535226047039, 0.0353027880191803, -0.02919306978583336, -0.007320835720747709, 0.011363774538040161, 0.01898219622671604, -0.05227068439126015, -0.00608148705214262, 0.030344447121024132, 0.027718689292669296, 0.026917634531855583, 0.008008833043277264, 0.011810695752501488, 0.017138615250587463, -0.0003859805001411587, -0.07034943997859955, -0.03061029128730297, -0.00003433740130276419, 0.025693684816360474, 0.0578487291932106, 0.009945939294993877, 0.03114866465330124, -0.02060077153146267, -0.016454076394438744, -0.05890496075153351, 0.02660081721842289, 0.0009580111945979297, -0.017033061012625694, -0.010577671229839325, -0.02474386617541313, -0.004066477995365858, -0.0008619329310022295, 0.0006688773282803595, -0.001544259488582611, 0.02716926671564579, -0.012263237498700619, 0.004776233807206154, -0.00261161127127707, 0.023495884612202644, -0.015065021812915802, 0.02716415375471115, -0.007478854153305292, -0.01996980421245098, 0.04397404566407204, -0.012213695794343948, -0.029433757066726685, 0.05705421790480614, -0.004657091572880745, 0.007347517181187868, -0.5898847579956055, 0.028371911495923996, -0.024992717429995537, -0.013439442031085491, 0.038295671343803406, 0.015290388837456703, -0.014036618173122406, -0.016806524246931076, -0.07412001490592957, -0.009342249482870102, 0.00719477841630578, -0.017852140590548515, -0.011277063749730587, -0.025929147377610207, -0.005330410785973072, 0.025407444685697556, -0.018744613975286484, -0.021788641810417175, 0.02587517350912094, 0.0021587826777249575, 0.0022531026042997837, -0.015887150540947914, 0.0353328175842762, -0.0014055678620934486, -0.028530895709991455, -0.04531421139836311, 0.02720729447901249, 0.006091328337788582, -0.045780543237924576, 0.019632507115602493, -0.0016910746926441789, 0.017396559938788414, 0.0065558431670069695, 0.02977677434682846, 0.009450473822653294, 0.0013466902310028672, 0.04520910233259201, -0.029841918498277664, 0.02046876773238182, -0.01128227636218071, -0.04432602971792221, -0.06191399693489075, -0.004662746097892523, -0.06460978835821152, -0.05040494352579117, -0.025968413800001144, 0.024157337844371796, 0.00558463204652071, 0.011398370377719402, 0.011818249709904194, -0.03467775508761406, 0.011715194210410118, 0.01646956242620945, -0.026157168671488762, -0.08676214516162872, 0.007357253227382898, -0.024251559749245644, 0.0012080252636224031, 0.053695499897003174, 0.004872361663728952, -0.00019395236449781805, -0.009733717888593674, 0.03331219032406807, -0.017651287838816643, 0.0005029980675317347, -0.011003094725310802, 0.024325495585799217, -0.02372927777469158, -0.012415841221809387, 0.02267088182270527, -0.031015822663903236, -0.01921628974378109, -0.044188305735588074, 0.018459217622876167, 0.06470485031604767, 0.038290929049253464, -0.001025201054289937, -0.018132615834474564, -0.00012048500502714887, -0.007971060462296009, 0.0017398984637111425, 0.001864811172708869, -0.0024202216882258654, -0.026026567444205284, -0.006485013756901026, -0.029485000297427177, 0.005020749755203724, -0.021464424207806587, -0.019442111253738403, -0.044591955840587616, 0.010845199227333069, 0.006196838337928057, -0.02597568742930889, 0.0026856872718781233, -0.01467976812273264, -0.020818371325731277, -0.016975393518805504, 0.08412064611911774, 0.018735578283667564, 0.015459796413779259, -0.026704931631684303, 0.0008169659413397312, -0.00575431901961565, -0.006390264257788658, -0.054818350821733475, -0.004004164133220911, -0.0409550704061985, -0.005013159476220608, 0.08366428315639496, 0.044651757925748825, -0.009324336424469948, -0.020106855779886246, 0.0011520449770614505, -0.022793946787714958, -0.023538250476121902, -0.07128629088401794, 0.031549833714962006, -0.041806627064943314, -0.003095849184319377, 0.004355670418590307, -0.0032503395341336727, -0.029461387544870377, -0.01534264162182808, 0.027037717401981354, -0.0013405312784016132, -0.016038697212934494, -0.01130304392427206, 0.013613579794764519, 0.0033628942910581827, 0.019832225516438484, -0.002404100727289915, 0.00038351421244442463, -0.02691478841006756, 0.03621736913919449, 0.010337223298847675, 0.02084963023662567, -0.026567135006189346, -0.029796583577990532, 0.06240022927522659, -0.016461174935102463, -0.05137075483798981, 0.010542390868067741, 0.020014522597193718, -0.021480651572346687, 0.04117085784673691, 0.017924563959240913, -0.006414365489035845, -0.04068293422460556, 0.010083900764584541, -0.03876855969429016, -0.008042269386351109, 0.03390800952911377, -0.010397953912615776, -0.0166269913315773, -0.07149183005094528, -0.029829366132616997, -0.04392421990633011, -0.0076924776658415794, -0.014556735754013062, 0.04436425119638443, -0.026176096871495247, 0.019820408895611763, -0.006241913419216871, -0.02722891792654991, -0.01511123776435852, 0.02101685293018818, -0.012730578891932964, -0.03174760565161705, 0.0176768247038126, 0.03373090177774429, 0.06530406326055527, 0.002220198977738619, 0.016025513410568237, -0.015393760986626148, -0.04225153475999832, 0.022329706698656082, -0.013719245791435242, -0.044624295085668564, -0.044884730130434036, -0.008303127251565456, -0.012254789471626282, 0.008632037788629532, 0.012157396413385868, 0.013463453389704227, -0.0019114169990643859, 0.04968063160777092, 0.027968043461441994, -0.003478066995739937, 0.01653403602540493, -0.0306113101541996, 0.04845680668950081, 0.04966622218489647, -0.0383576974272728, 0.02834664098918438, -0.023624563589692116, -0.012687803246080875, -0.011217247694730759, -0.007941152900457382, 0.05885835364460945, 0.0003296094364486635, -0.0006768858293071389, -0.038743823766708374, 0.04179497808218002, -0.021139707416296005, 0.016452129930257797, 0.04651416093111038, 0.039623748511075974, -0.018399203196167946, 0.047824881970882416, -0.058364905416965485, 0.024011291563510895, 0.014998727478086948, 0.03019895777106285, 0.008904282934963703, -0.056312259286642075, 0.03856314718723297, -0.012013622559607029, -0.02947496809065342, 0.025807473808526993, -0.012322073802351952, 0.010550174862146378, -0.05536964535713196, -0.008633828721940517, -0.015323139727115631, -0.0027071309741586447, 0.0027264603413641453, -0.00019955036987084895, 0.007857896387577057, -0.016960332170128822, 0.03973492980003357, 0.04024990648031235, 0.0087055042386055, 0.014656398445367813, -0.025739120319485664, 0.018734624609351158, 0.06883082538843155, 0.00779384421184659, 0.03866312652826309, -0.02940988913178444, -0.0015219204360619187, 0.07122139632701874, -0.018773211166262627, -0.01082502119243145, -0.0009103843476623297, -0.012979120947420597, 0.01672467216849327, 0.014778862707316875, -0.012134946882724762, 0.006357131991535425, -0.0030676978640258312, -0.025974810123443604, 0.08341079205274582, 0.012909783981740475, 0.0002708570973481983, 0.04003337398171425, 0.003422483103349805, 0.003328578779473901, 0.00493667833507061, 0.02896108292043209, 0.010044925846159458, -0.04559862241148949, -0.05974574759602547, 0.03304320201277733, 0.03767121955752373, 0.02924082614481449, -0.000582986103836447, 0.04253874719142914, 0.00835147313773632, 0.004092373885214329, 0.03081153705716133, 0.00007200040272437036, -0.010592089965939522, -0.028859097510576248, -0.04369369521737099, 0.0431520901620388, -0.002977248514071107, 0.0053300573490560055, -0.038406021893024445, 0.02824545092880726, -0.006991419941186905, 0.006838384550064802, -0.00998799130320549, 0.027597462758421898, 0.027131114155054092, 0.0013724679592996836, 0.014328244142234325, 0.009531417861580849, 0.009013368748128414, -0.04957276210188866, -0.006923485081642866, -0.0015514635015279055, -0.0237562358379364, 0.05693727731704712, -0.003770466661080718, 0.012387453578412533, 0.0004996884381398559, 0.023870935663580894, -0.024897238239645958, -0.014519820921123028, 0.03808110952377319, -0.01925227791070938, -0.06761123239994049, 0.019659874960780144, 0.010387398302555084, -0.0041491868905723095, -0.02616181969642639, 0.05039720609784126, -0.04665751755237579, 0.04866816848516464, 0.011462897062301636, 0.005051097832620144, 0.05145568773150444, 0.00137050892226398, 0.025572901591658592, 0.03034987859427929, -0.016136102378368378, -0.020350100472569466, -0.0016140587395057082, 0.036071326583623886, -0.026784110814332962, -0.010652275756001472, 0.0019826353527605534, -0.006716303993016481, -0.008626553229987621, 0.0096686827018857, -0.04376973584294319, -0.0490587092936039, -0.008638733997941017, 0.015961993485689163, 0.004323190078139305, 0.013898194767534733, -0.047975726425647736, 0.0062376526184380054, -0.013431418687105179, 0.026555433869361877, 0.04457424581050873, 0.0022762692533433437, 0.03594047203660011, 0.055254705250263214, -0.006955353077501059, -0.05022645741701126, 0.015075012110173702, 0.0016130435978993773, -0.01837560534477234, 0.007822759449481964, 0.012629453092813492, -0.02785606123507023, 0.027929535135626793, 0.03349548950791359, -0.007326010148972273, 0.06081914156675339, -0.021924827247858047, 0.029651928693056107, 0.017998337745666504, 0.0023163235746324062, -0.04736056178808212, -0.030266163870692253, 0.011014788411557674, 0.0111351003870368, 0.0001180718609248288, 0.022367507219314575, -0.015560323372483253, -0.05692675709724426, 0.016084948554635048, -0.029683010652661324, -0.016516100615262985, -0.016419075429439545, -0.029746342450380325, 0.010602209717035294, 0.02042519301176071, 0.000718844763468951, -0.03829317167401314, -0.010088111273944378, 0.0426192581653595, 0.015797218307852745, 0.06691852957010269, 0.029932981356978416, -0.026023143902420998, -0.013599260710179806, 0.013302760198712349, -0.021418582648038864, -0.015005886554718018, 0.01095934771001339, 0.008988632820546627, 0.02095407247543335, -0.04399853199720383, -0.0034825701732188463, 0.020783742889761925, -0.026993470266461372, -0.05438891425728798, 0.01890232414007187, -0.010749062523245811, 0.015224172733724117, 0.04554886370897293, -0.015080413781106472, 0.009611315093934536, -0.016268480569124222, -0.013585692271590233, 0.01321494486182928, -0.02739928662776947, 0.019252384081482887, 0.03131982311606407, -0.02143784984946251, 0.01928362064063549, 0.019120870158076286, -0.054379306733608246, 0.06517196446657181, 0.038858260959386826, -0.017656832933425903, 0.06110446900129318, -0.025810230523347855, 0.0010043984511867166, -0.03234860301017761, -0.00042943257722072303, -0.023528680205345154, 0.032071493566036224, -0.004689016845077276, -0.0044158995151519775, -0.0022356202825903893, 0.008577527478337288, -0.03162868320941925, 0.05222495272755623, -0.0035363861825317144, 0.014451722614467144, -0.008130934089422226, -0.0346255861222744, 0.013392758555710316, -0.006680835038423538, -0.047723352909088135, 0.023646477609872818, -0.013503756374120712, 0.034490250051021576, 0.018100570887327194, 0.006247831508517265, -0.014912529848515987, -0.022933756932616234, -0.0019446510123088956, -0.006591202225536108, -0.0029008621349930763, 0.015811454504728317, -0.044129762798547745, 0.002644313033670187, -0.005678531248122454, 0.030519358813762665, -0.0008849504520185292, -0.11626001447439194, 0.0186209287494421, 0.03530018776655197, 0.007787343580275774, -0.019827663898468018, -0.0355023629963398, 0.02678602561354637, -0.03581380471587181, 0.08738440275192261, 0.0007299355347640812, 0.030599800869822502, 0.03492738679051399, 0.003433455713093281, -0.014015942811965942, -0.00008878418157109991, -0.0065876152366399765, 0.008382436819374561, 0.01826692931354046, -0.023381369188427925, -0.004636645782738924, 0.05734303593635559, 0.024330338463187218, -0.042654626071453094, 0.014063689857721329, -0.0002741079078987241, -0.023579660803079605, 0.026693038642406464, -0.009480532258749008, 0.01832238957285881, -0.01738729700446129, -0.004488497041165829, 0.012127205729484558, 0.04261830821633339, 0.04366244003176689, 0.003846927545964718, -0.11042682081460953, 0.004051452502608299, 0.01344123762100935, 0.03655453026294708, 0.043945107609033585, -0.02382153831422329, -0.042291197925806046, -0.014453848823904991, -0.007837277837097645, 0.018799949437379837, -0.02045874297618866, -0.03726453334093094, 0.0372675321996212, 0.0423210933804512, 0.030623596161603928, -0.01690814644098282, 0.050241123884916306, -0.02187209203839302, 0.058248139917850494, -0.03422028198838234, -0.010925037786364555, 0.019840624183416367, -0.003068626159802079, 0.005480249412357807, 0.003652590326964855, 0.0092616630718112, 0.035818375647068024, 0.05173896253108978, -0.027846047654747963, -0.01355717983096838, -0.00921743456274271, -0.013185741379857063, -0.049850478768348694, 0.014789593406021595, 0.025668485090136528, -0.01253580767661333, 0.03653818741440773, -0.07508324831724167, 0.010570283979177475, -0.006736706010997295, 0.004877045750617981, -0.01673620007932186, 0.01642443612217903, 0.004435893148183823, -0.030383286997675896, -0.021273190155625343, 0.013667633756995201, 0.009313252754509449, 0.007232185453176498, 0.0029571589548140764, 0.034412682056427, -0.023139476776123047, -0.05766712874174118, -0.02392989583313465, 0.012977737933397293, -0.05677391216158867, 0.06284026056528091, 0.037878233939409256, -0.011539475060999393, 0.0017767229583114386, 0.043877389281988144, 0.0066637699492275715, -0.0066261980682611465, 0.020730942487716675, -0.020580662414431572, 0.014976770617067814, 0.027118083089590073, 0.024516252800822258, 0.058932915329933167, -0.007813021540641785, 0.007720961235463619, 0.025837041437625885, -0.013111565262079239, 0.005025405436754227, 0.0024113948456943035, 0.025906283408403397, 0.015714474022388458, 0.044698603451251984, 0.029443399980664253, -0.036757420748472214, -0.018362127244472504, 0.01528470404446125 ]
8a9ed02f0755897cb2a1b2ac5fabcbb264f6bbee
18,025
py
Python
microbepy/plot/mutation_plot.py
ScienceStacks/MicrobEPy
704435e66c58677bab24f27820458870092924e2
[ "MIT" ]
1
2019-05-04T00:31:05.000Z
2019-05-04T00:31:05.000Z
microbepy/plot/mutation_plot.py
ScienceStacks/MicrobEPy
704435e66c58677bab24f27820458870092924e2
[ "MIT" ]
null
null
null
microbepy/plot/mutation_plot.py
ScienceStacks/MicrobEPy
704435e66c58677bab24f27820458870092924e2
[ "MIT" ]
null
null
null
"""Provides plots of mutations for Isolates and Lines.""" from microbepy.common import constants as cn from microbepy.common.dataframe_sorter import DataframeSorter from microbepy.common.isolate import Isolate from microbepy.common import util from microbepy.correlation import genome_correlation from microbepy.data.model_data_provider import ModelDataProvider from microbepy.data import util_data from microbepy.plot.mutation_cofraction import MutationCofraction from microbepy.plot.util_plot import PlotParms import matplotlib.pyplot as plt import numpy as np import pandas as pd import seaborn as sns COLORS = ['red', 'green', 'blue'] SPECIES = {cn.SPECIES_MIX_DVH: "DVH", cn.SPECIES_MIX_MMP: "MMP", None: "both"} FONTSIZE_TITLE = 16 FONTSIZE_LABEL = 8 MAX_LINES = 9 MIN_FRACTION = 0.25 THRESHOLD_FRAC = 0.2 MAX_SIGLVL = 0.01 COLORBAR_MIN = 1.0 COLORBAR_MAX = 4.0 class MutationLinePlot(object): """ Plot mutations by occurrences within Lines. """ def __init__(self, mutation_column=cn.GGENE_ID, species=None, is_plot=True): """ :param str mutation_column: :param bool is_plot: """ self._mutation_column = mutation_column self._is_plot = is_plot self._species = species self.cofraction = MutationCofraction(species=self._species, mutation_column=mutation_column) def plotTransfers(self, parms=PlotParms(is_initialize=False), is_unit_fraction = False, is_cluster_mutations=True): """ Does a stacked bar plot of mutation frequency for all transfers. :param bool is_unit_fraction: round fraction to 1 :param bool is_cluster_mutations: Group similar mutations together :return pd.DataFrame: row=mutation, col=line + transfer, value is fraction """ permitted_mutations = self.cofraction.ordered_mutations transfers = self.cofraction.transfers num_transfers = len(transfers) fig, axes = plt.subplots(nrows=num_transfers, ncols=1) dfs = [] for idx, transfer in enumerate(transfers): parms[cn.PLT_YTICKLABELS] = True if self._species is None: parms[cn.PLT_TITLE] = "%d" % transfer else: parms[cn.PLT_TITLE] = "%s, %d" % (self._species, transfer) if idx == 0: parms[cn.PLT_YLABEL] = True else: parms[cn.PLT_YLABEL] = False if idx < num_transfers - 1: parms[cn.PLT_LEGEND] = False parms[cn.PLT_XLABEL] = False parms[cn.PLT_XTICKLABELS] = False else: parms[cn.PLT_LEGEND] = True parms[cn.PLT_XLABEL] = True parms[cn.PLT_XTICKLABELS] = True df = self.plotLine(transfer, parms=parms, is_plot=False, ax=axes[idx], permitted_mutations=permitted_mutations, is_unit_fraction=is_unit_fraction) df[cn.TRANSFER] = transfer dfs.append(df) if self._is_plot: plt.show() return pd.concat(dfs) def plotLine(self, transfer, parms=PlotParms(is_initialize=False), is_unit_fraction=False, is_plot=None, ax=None, permitted_mutations=None): """ Does a stacked bar plot of mutation frequency by line with colors :params int transfer: :params PlotParms parms: :params Axis ax: axis to use in plot :param list-str permitted_mutations: to use and how they are ordered if None, then use alphabetical order :param bool is_unit_fraction: round non-zero fraction to 1 :return pd.DataFrame: row=mutation, col=line, value is fraction """ if is_plot is None: is_plot = self._is_plot parms.setTrueIfAbsent(cn.PLT_XLABEL) parms.setTrueIfAbsent(cn.PLT_XTICKLABELS) # df_plot = self.cofraction.makeLineDF( permitted_mutations=permitted_mutations, transfer=transfer) if is_unit_fraction: df_plot = df_plot.applymap( lambda v: 1 if v> MIN_FRACTION else v) # Do the plot if not cn.PLT_FIGSIZE in parms: parms[cn.PLT_FIGSIZE] = (12, 8) if ax is None: ax = df_plot.plot(kind='bar', stacked=True, figsize=parms[cn.PLT_FIGSIZE], legend=None) else: df_plot.plot(kind='bar', stacked=True, legend=None, ax=ax, figsize=parms[cn.PLT_FIGSIZE]) ax.set_xlabel("", fontsize=FONTSIZE_LABEL) # Eliminate implicit label if parms.isFalse(cn.PLT_XTICKLABELS): labels = ax.get_xticklabels() new_labels = np.repeat("", len(labels)) ax.set_xticklabels(new_labels) if parms.isFalse(cn.PLT_YTICKLABELS): labels = ax.get_yticklabels() new_labels = np.repeat("", len(labels)) ax.set_yticklabels(new_labels) if cn.PLT_TITLE in parms: title = parms[cn.PLT_TITLE] else: title = "%s Mutations" % SPECIES[self._species] xpos = int(len(df_plot)*0.5) ypos = MAX_LINES - 3 ax.text(xpos, ypos, title, fontsize=FONTSIZE_TITLE) ax.set_ylim([0, MAX_LINES]) if parms.isTrue(cn.PLT_YLABEL): if is_unit_fraction: label = "No. Lines" else: label = "Fraction" ax.set_ylabel(label , fontsize=FONTSIZE_LABEL) if parms.isTrue(cn.PLT_XLABEL): ax.set_xlabel(self._mutation_column, fontsize=FONTSIZE_LABEL) if parms.isTrue(cn.PLT_LEGEND): ax.legend(loc=(1,2)) #ax.legend() if is_plot: plt.show() return df_plot def _makeMutationSiglvlMatrix(self, transfer=cn.TRANSFER_DEFAULT, other_transfer=None, min_fraction=MIN_FRACTION): """ Creates a significance level matrix for mutations. :param int transfer: transfer time for row mutations :param int other_transfer: transfer time for column mutations :param float min_fraction: minimum fractional occurrence of a mutation within a line for it to be considered :return pd.DataFrame: row index and columns are mutations """ def makeDF(transfer): df_line = self.cofraction.makeLineDF(transfer=transfer) df_binary = df_line.applymap( lambda v: 0 if np.isnan(v) else v) df_binary = df_line.applymap( lambda v: 1.0 if v > min_fraction else 0) return df_binary.transpose() # if other_transfer is None: other_transfer = transfer # df_binary_rows = makeDF(transfer) df_binary_columns = makeDF(other_transfer) df_matrix = genome_correlation.makeSiglvlDF(df_binary_rows, df_other=df_binary_columns) return df_matrix def _plotSiglvlDF(self, transfer=cn.TRANSFER_DEFAULT, other_transfer=None, max_siglvl=MAX_SIGLVL): """ Constructs a the dataframe used for heatmap. :param int transfer: :param float max_siglvl: :return pd.DataFrame: mutations, mutations, values are -log10 significance level """ df_matrix = self._makeMutationSiglvlMatrix(transfer=transfer, other_transfer=other_transfer) sorter = DataframeSorter(df_matrix) df_sort = sorter.orderBoth() # df_transformed = df_sort.applymap(lambda v: np.log10(v)) df_transformed = df_transformed.applymap(lambda v: -v) ubound = -np.log10(max_siglvl) df_plot = df_transformed.applymap( lambda v: np.nan if v < ubound else v) sorter = DataframeSorter(df_plot) df_plot = sorter.deleteNanRowsAndColumns() return df_plot def plotCofractions(self, is_time_lag=False, threshold_frac=THRESHOLD_FRAC, is_difference_frac=False, is_differenced=False, is_compress=False, parms=PlotParms(), **kwargs): """ Does a subplots of the fraction of lines in which mutations co-occur. :param bool is_time_lag: construct time lag subplots :param bool is_differenced: Computes the difference in count fractions :param dict kwargs: non-transfer parameters passed to next level :return dict: key is pair of transfers, value is data_frame """ def funcDF(transfer, other_transfer): if is_differenced: df = self.cofraction.makeCofractionDifferencedDF( transfer=transfer, other_transfer=other_transfer, threshold_frac=threshold_frac) else: df = self.cofraction.makeCofractionDF(transfer=transfer, is_difference_frac=is_difference_frac, other_transfer=other_transfer) if is_compress: df.dropna(axis=0, how='all', inplace=True) df.dropna(axis=1, how='all', inplace=True) return df # return self._plotTransfers(funcDF, is_time_lag, parms=parms, heat_range=[0, 1.0], **kwargs) def plotSiglvls(self, is_time_lag=False, max_siglvl=MAX_SIGLVL, parms=PlotParms(), **kwargs): """ Does a subplots of mutation correlation significance levels. :param bool is_time_lag: construct time lag subplots :param dict kwargs: non-transfer parameters passed to next level :return dict: key is pair of transfers, value is data_frame """ def funcDF(transfer, other_transfer): return self._plotSiglvlDF(transfer=transfer, max_siglvl=max_siglvl, other_transfer=other_transfer) # return self._plotTransfers(funcDF, is_time_lag, parms=parms, heat_range = [COLORBAR_MIN, COLORBAR_MAX], **kwargs) def _plotTransfers(self, funcDF, is_time_lag, parms=PlotParms(), **kwargs): """ Does a subplots of mutation mutations over transfers. :param Function funcDF: has kwargs transfer, other_transfer; returns a dataframe of mutations as columns and index; values are used in the heatmap. :param bool is_time_lag: construct time lag subplots :param dict kwargs: non-transfer parameters passed to next level :return dict: key is pair of transfers, value is data_frame """ NCOLS = 3 plot_pos = {1:1, 2:3, 3:4, 4:6} NPLOTS = 6 transfers = self.cofraction.transfers if is_time_lag: pairs = [p for p in zip(transfers[:-1], transfers[1:])] else: pairs = [p for p in zip(transfers[:-1], transfers[:-1])] # # Calculate the column order df = funcDF(transfer=cn.TRANSFER_1000G, other_transfer=cn.TRANSFER_1000G) df = df.fillna(0) # Set up for plots nrows = 2 if (len(pairs) == 4) else 3 fig = plt.figure(figsize=parms[cn.PLT_FIGSIZE]) result = {} for idx, pair in enumerate(pairs): idx += 1 ax = fig.add_subplot(nrows, NCOLS, plot_pos[idx]) if idx < len(pairs): is_plot = False else: is_plot = True if idx in [1, 2, 5]: parms[cn.PLT_XAXISTICKTOP] = True else: parms[cn.PLT_XAXISTICKTOP] = False if idx == 4: parms[cn.PLT_COLORBAR] = True else: parms[cn.PLT_COLORBAR] = False transfer = pair[0] other_transfer = pair[1] df = funcDF(transfer=transfer, other_transfer=other_transfer) df = df.applymap(lambda v: np.nan if v == 0 else v) self._plotTransferCompare(df, transfer=transfer, other_transfer=other_transfer, ordered_columns=self.cofraction.ordered_mutations, is_center_colorbar=True, fig=fig, ax=ax, parms=parms, is_plot=is_plot, **kwargs) result[pair] = df return result def plotSiglvl(self, max_siglvl=MAX_SIGLVL, transfer=cn.TRANSFER_DEFAULT, other_transfer=None, is_center_colorbar = True, **kwargs): """ Constructs a heatmap of the mutation coocurrence significance levels. :param float max_siglvl: maximum significance level :return pd.DataFrame: columns, rows are mutations """ df_plot = self._plotSiglvlDF(transfer=transfer, other_transfer=other_transfer, max_siglvl=max_siglvl) self._plotTransferCompare(df_plot, heat_range = [COLORBAR_MIN, COLORBAR_MAX], ordered_mutations=self.cofraction.ordered_mutations, transfer=transfer, other_transfer=other_transfer, is_center_colorbar=is_center_colorbar, **kwargs) return df_plot def plotCofraction(self, threshold_frac=THRESHOLD_FRAC, transfer=cn.TRANSFER_DEFAULT, other_transfer=None, is_difference_frac=False, is_differenced=False, is_center_colorbar=True, is_compress=False, parms=PlotParms(), **kwargs): """ Constructs a heatmap of the mutation coocurrence fractions. :param int transfer: Transfer for which plot is done :param bool is_differenced: Computes the difference in count fractions :param bool is_compress: Eliminate rows/columns with 0 values :return pd.DataFrame: columns, rows are mutations """ if is_differenced: df = self.cofraction.makeCofractionDifferencedDF( threshold_frac=threshold_frac, transfer=transfer, other_transfer=other_transfer, **kwargs) df = df.applymap(lambda v: np.nan if np.abs(v) < threshold_frac else v) else: df = self.cofraction.makeCofractionDF(transfer=transfer, is_difference_frac=is_difference_frac, other_transfer=other_transfer, **kwargs) df = df.applymap(lambda v: np.nan if v < threshold_frac else v) if is_compress: df.dropna(axis=0, how='all', inplace=True) df.dropna(axis=1, how='all', inplace=True) is_include_missing_mutations = False else: is_include_missing_mutations = True ordered_columns = self.cofraction.ordered_mutations self._plotTransferCompare(df, heat_range=[0, 1.0], ordered_columns=ordered_columns, parms=parms, transfer=transfer, other_transfer=other_transfer, is_center_colorbar=is_center_colorbar, is_include_missing_mutations=is_include_missing_mutations, **kwargs) return df def _plotTransferCompare(self, df_plot, heat_range, ordered_columns=None, is_center_colorbar=True, transfer=cn.TRANSFER_DEFAULT, other_transfer=None, ax=None, fig=None, is_include_missing_mutations=True, parms=PlotParms(), is_plot=None): """ Constructs a heatmap comparing values for mutations from two transfers. :param pd.DataFrame df_plot: index and columns are mutations; values are plotted on the heatmap :param list-str ordered_columns: order in which columns appear :param bool is_center_colorbar: center the colorbar in the plot :param float, float: values on the heatmap range :param int transfer: :param int other_transfer: Allow comparisons across time :param Matplotlib.Axes ax: :param PlotParms parms: Parameters for the plot :param bool is_plot: Overrides constructor plotting directive :param bool is_include_missing_mutations: """ def makeLabel(transfer, column, is_include_column=False): if is_include_column: label = "%d-%s" % (transfer, column) else: label = "%d" % transfer return label def setValue(a_dict, key, default): if not key in a_dict.keys(): a_dict[key] = default # if is_plot is None: is_plot = self._is_plot elif not self._is_plot: is_plot = self._is_plot if ordered_columns is None: ordered_columns = list(set(df_plot.columns.tolist()).union( df_plot.index)) # Do the plot if not cn.PLT_COLORBAR in parms: parms[cn.PLT_COLORBAR] = True if other_transfer is None: other_transfer = transfer if ax is None: if fig is None: fig = plt.figure(figsize=parms[cn.PLT_FIGSIZE]) ax = fig.add_subplot(1, 1, 1) # Order the columns if is_include_missing_mutations: columns = df_plot.columns.tolist() missing_columns = set(ordered_columns).difference(columns) extended_ordered_columns = list(ordered_columns) extended_ordered_columns.extend( set(columns).difference(ordered_columns)) for col in missing_columns: df_plot[col] = np.nan df_plot.loc[col, :] = np.nan df_plot = df_plot.reindex(extended_ordered_columns) df_plot = df_plot[extended_ordered_columns] rows = df_plot.columns.tolist() columns = df_plot.columns.tolist() else: extended_ordered_columns = ordered_columns rows = df_plot.index.tolist() columns = df_plot.columns.tolist() mutations = df_plot.columns.tolist() # Set up plot information parms[cn.PLT_XLABEL] = "" setValue(parms, cn.PLT_COLORBAR, True) xpos = 1.05*len(columns) ypos = -0.05*len(rows) parms[cn.PLT_XLABEL] = "" xlabel = makeLabel(other_transfer, self._mutation_column) parms[cn.PLT_YLABEL] = makeLabel( transfer, self._mutation_column) ax.text(xpos, ypos, xlabel, fontsize=parms.fontsize_label) # # Construct the plot plot = ax.pcolor(df_plot, cmap='jet', vmin=heat_range[0], vmax=heat_range[1]) if parms.isTrue(cn.PLT_COLORBAR): if is_center_colorbar: # Colorbar positions: left, bottom, width, height cbaxes = fig.add_axes([.45, 0.2, 0.01, 0.5]) cb = fig.colorbar(plot, cax = cbaxes, cmap='jet') cb.ax.tick_params(labelsize=parms.fontsize_label) else: cb = fig.colorbar(plot, cmap='jet') cb.ax.tick_params(labelsize=parms.fontsize_label) row_labels = df_plot.columns.tolist() col_labels = df_plot.index.tolist() if parms.isTrue(cn.PLT_XAXISTICKTOP): ax.xaxis.tick_top() ax.set_xticks(np.arange(0.5, len(row_labels))) ax.set_xticklabels(row_labels, rotation=90, fontsize=parms.fontsize_label) ax.set_yticks(np.arange(0.5, len(col_labels))) ax.set_yticklabels(col_labels, fontsize=parms.fontsize_label) #parms[cn.PLT_YLABEL] = "" parms.do(is_plot=False) if is_plot: parms[cn.PLT_YLABEL] = "" parms.do(is_plot=False) ylabel = makeLabel(transfer, self._mutation_column) xpos = -3 ypos = 0.5*len(rows) ypos = -1 ax.set_ylabel(ylabel, fontsize=parms.fontsize_label, x=xpos, y=ypos) #plt.show() parms.do(is_plot=is_plot) else: parms.do(is_plot=is_plot)
35.62253
78
0.676782
1
2.2791
[ -0.04181872308254242, 0.050783202052116394, -0.006760148331522942, 0.04014439880847931, 0.029312189668416977, -0.020922811701893806, -0.003993387334048748, 0.02622768096625805, -0.032879892736673355, 0.024170206859707832, 0.013300697319209576, -0.008387087844312191, 0.017074955627322197, -0.045606136322021484, -0.018773118034005165, 0.0016699680127203465, 0.17715826630592346, -0.008507177233695984, 0.006455377675592899, 0.00959787704050541, -0.0036968777421861887, -0.004188230261206627, -0.032371364533901215, 0.03057445026934147, 0.014550271444022655, -0.0072333780117332935, 0.03923172131180763, -0.023556699976325035, -0.0031696863006800413, -0.002511833095923066, -0.030153417959809303, -0.0027961302548646927, 0.012201213277876377, 0.02054290845990181, -0.008448328822851181, -0.013111651875078678, 0.002136663533747196, -0.013970022089779377, 0.009476682171225548, -0.008358779363334179, 0.011438976041972637, -0.0016520076896995306, 0.015270095318555832, -0.01710878685116768, 0.031302861869335175, -0.01872244104743004, -0.012800213880836964, -0.061855498701334, -0.019414223730564117, 0.015358555130660534, 0.02788713201880455, 0.052139174193143845, 0.040419839322566986, -0.05791127681732178, 0.027013784274458885, -0.0042978995479643345, 0.03597544506192207, -0.013628866523504257, -0.02984899841248989, -0.004827008116990328, -0.01197636965662241, -0.015021966770291328, 0.020711973309516907, 0.0017122745048254728, -0.001313603250309825, 0.025139329954981804, -0.03778018429875374, -0.027709651738405228, -0.022959250956773758, 0.021396927535533905, -0.043248251080513, 0.028345774859189987, -0.013261600397527218, 0.010840672999620438, 0.0049270703457295895, 0.01599646359682083, -0.0025898029562085867, 0.001580859418027103, 0.020910490304231644, 0.010976171121001244, -0.012748879380524158, 0.015523042529821396, 0.010098401457071304, -0.007771208882331848, 0.005156475584954023, 0.005214616656303406, 0.004208760801702738, -0.020667221397161484, 0.037127938121557236, 0.009520121850073338, -0.03220214322209358, -0.031376179307699203, -0.0657850056886673, -0.02030082605779171, -0.02704894356429577, -0.005644923076033592, 0.03362003713846207, 0.03538103774189949, -0.00649833120405674, 0.035906314849853516, 0.02214476279914379, 0.032482605427503586, 0.026726212352514267, 0.022784873843193054, 0.012536637485027313, 0.003174448851495981, -0.00025263038696721196, 0.015007440000772476, -0.0017709031235426664, 0.00491005415096879, 0.0021320779342204332, 0.039514705538749695, 0.01932797022163868, -0.012842291034758091, -0.01091693714261055, -0.029746979475021362, -0.02779332362115383, 0.017648590728640556, -0.010342595167458057, 0.04240148514509201, 0.017814164981245995, 0.012276978231966496, 0.0011432048631832004, -0.03155131638050079, 0.01274858508259058, 0.06790371984243393, 0.03554009273648262, -0.009858283214271069, 0.03105294518172741, 0.00013819229207001626, 0.008070639334619045, 0.003818980883806944, -0.039353687316179276, 0.01717124879360199, -0.015528570860624313, -0.02315915748476982, 0.004187183454632759, 0.02978801541030407, -0.03980107232928276, -0.049110524356365204, -0.027607526630163193, -0.014920907095074654, 0.005172353703528643, -0.0072002406232059, 0.0017212199745699763, -0.045438215136528015, -0.014261817559599876, 0.025394512340426445, -0.02370457723736763, -0.024653110653162003, 0.0076193492859601974, 0.033512651920318604, -0.031009268015623093, 0.008475497364997864, -0.006971404887735844, -0.009524771943688393, 0.014877685345709324, -0.042133647948503494, -0.03315475955605507, -0.0025649513117969036, -0.013174488209187984, 0.035050369799137115, -0.0025867207441478968, 0.021248290315270424, 0.015011998824775219, 0.041038628667593, -0.031160295009613037, 0.03346133232116699, 0.003953440580517054, 0.021389467641711235, 0.040129080414772034, -0.00774206779897213, 0.008863524533808231, -0.044348716735839844, 0.013268970884382725, 0.013270730152726173, 0.060487713664770126, -0.007998650893568993, 0.0046739643439650536, -0.02173047699034214, -0.004055759869515896, -0.032336875796318054, 0.05123281478881836, 0.03835848346352577, 0.01845976710319519, -0.0033861875999718904, -0.02278381958603859, -0.01939503662288189, -0.02347436733543873, 0.010751188732683659, 0.0010528487619012594, 0.0425645187497139, -0.01843702606856823, -0.024219676852226257, -0.02150559611618519, 0.02826763689517975, -0.015610883012413979, 0.04252270236611366, 0.005363269709050655, 0.007839789614081383, -0.013410559855401516, -0.010484479367733002, -0.0008393471944145858, -0.05067567527294159, -0.015045777894556522, 0.009940626099705696, -0.6804682612419128, 0.049818068742752075, 0.007828863337635994, -0.0006658608326688409, -0.012302546761929989, 0.015392327681183815, -0.008419624529778957, 0.00777441868558526, 0.02745169587433338, -0.02313699759542942, 0.0039536189287900925, -0.01316728163510561, -0.02299511432647705, -0.013007125817239285, 0.01306625735014677, -0.01055891439318657, 0.0010970046278089285, 0.03304215520620346, -0.04762224480509758, 0.027496518567204475, -0.012243885546922684, 0.01497198361903429, -0.014970747753977776, 0.012545725330710411, -0.015806829556822777, -0.004280660301446915, 0.02350815385580063, -0.022741908207535744, -0.02371196821331978, -0.010890000499784946, -0.04691634699702263, 0.023322494700551033, -0.0470198392868042, -0.0035455068573355675, 0.013803506270051003, -0.04269833490252495, 0.023195013403892517, -0.010477405041456223, -0.030661357566714287, -0.008391233161091805, -0.009180732071399689, -0.03928935527801514, -0.0005895832437090576, -0.049865417182445526, -0.04656055569648743, -0.023145455867052078, -0.07775989174842834, -0.04602361097931862, 0.01678529754281044, 0.0037078310269862413, -0.03751905634999275, 0.011863012798130512, 0.008173494599759579, 0.012903806753456593, 0.014080289751291275, 0.020725248381495476, -0.01764789968729019, 0.015153862535953522, 0.003668868215754628, -0.0207059346139431, 0.029348421841859818, 0.02744891680777073, -0.012559803202748299, 0.0030777589417994022, -0.013778378255665302, 0.0017676108982414007, 0.05025903508067131, -0.03203472122550011, -0.015081510879099369, 0.011261197738349438, -0.019050195813179016, 0.007856802083551884, -0.03470814600586891, 0.016818035393953323, 0.000472112005809322, -0.04616452008485794, 0.003487639594823122, 0.007255061995238066, 0.042913150042295456, 0.022814134135842323, 0.00088502251310274, -0.033040113747119904, 0.005652369000017643, -0.005737979896366596, -0.04968571290373802, 0.018343385308980942, -0.032989926636219025, 0.020877214148640633, 0.007426947355270386, 0.010530594736337662, 0.026621544733643532, 0.005191100295633078, 0.018332350999116898, 0.0017326779197901487, -0.008552376180887222, 0.0386810302734375, 0.020590784028172493, 0.03386279568076134, 0.005454877857118845, 0.027911102399230003, 0.0010997598292306066, 0.0011253211414441466, -0.016709214076399803, 0.02821211703121662, 0.006489128805696964, 0.003564370097592473, -0.03137738257646561, -0.0011943457648158073, 0.009447853080928326, -0.039641160517930984, 0.011943642981350422, 0.0009684263495728374, 0.014620166271924973, 0.004421597346663475, -0.06027088686823845, -0.024196526035666466, -0.02796577848494053, -0.030186451971530914, 0.011455880478024483, -0.011995971202850342, 0.0005604804027825594, -0.021687796339392662, -0.01053581666201353, -0.04441223293542862, -0.008022578433156013, 0.003018332179635763, -0.052402764558792114, 0.007192492019385099, -0.02657952718436718, 0.01698758266866207, -0.008708593435585499, 0.001271714805625379, 0.010401052422821522, -0.007122925017029047, -0.04839899390935898, -0.016809947788715363, 0.026168663054704666, -0.01727389544248581, -0.01333352830260992, -0.00407063914462924, -0.008632902055978775, -0.049936093389987946, 0.014723895117640495, -0.04304225742816925, -0.0007370770326815546, 0.014697976410388947, 0.008867750875651836, -0.03741667792201042, 0.04019835963845253, 0.03409827873110771, 0.04665976017713547, -0.009491698816418648, 0.004605814348906279, 0.030126068741083145, 0.008993937633931637, 0.03699130192399025, 0.019085979089140892, -0.027925807982683182, 0.009474817663431168, 0.022344904020428658, 0.00885720830410719, -0.035597994923591614, 0.030703812837600708, 0.008492724038660526, 0.0033334342297166586, 0.0014629460638388991, -0.010480564087629318, 0.01757277548313141, 0.012450112961232662, -0.002873586257919669, 0.01054336503148079, 0.02114589884877205, 0.009344798512756824, -0.0051962933503091335, -0.004577529616653919, 0.020521221682429314, -0.010257053188979626, 0.009516838006675243, 0.011665113270282745, 0.06333740800619125, 0.024771898984909058, 0.002556874416768551, -0.03664880990982056, -0.013510864228010178, 0.022184157744050026, 0.00817118864506483, -0.018855717033147812, -0.020890390500426292, 0.0036258467007428408, -0.07307837158441544, 0.010608573444187641, 0.01366499811410904, -0.02209242433309555, -0.006590592209249735, 0.0015270080184563994, -0.03057168982923031, -0.019059237092733383, 0.01817259192466736, -0.0400344580411911, 0.004859632346779108, -0.020879002287983894, 0.04091816768050194, -0.004968676716089249, -0.022593853995203972, -0.035984866321086884, 0.009433476254343987, -0.0014127219328656793, 0.0035227942280471325, -0.02188624069094658, 0.09587708115577698, -0.015530993230640888, -0.03586961328983307, 0.008938489481806755, 0.030027011409401894, -0.047188591212034225, -0.030773796141147614, -0.02693588100373745, 0.014135399833321571, -0.013716334477066994, -0.02829442173242569, -0.009053217247128487, -0.025910625234246254, 0.024337660521268845, 0.030556172132492065, -0.0011128116166219115, -0.039836570620536804, -0.0489032082259655, 0.0049758306704461575, -0.026397665962576866, 0.002141157165169716, -0.028374293819069862, -0.03512740507721901, 0.011935174465179443, 0.022763649001717567, -0.006004477385431528, 0.00850663147866726, -0.02557828277349472, -0.02172810770571232, -0.004752113949507475, -0.013263293541967869, -0.02165246568620205, -0.010922245681285858, 0.006327614188194275, -0.00876773800700903, -0.030700979754328728, -0.04384111985564232, -0.009180980734527111, -0.07347866892814636, -0.05347926914691925, -0.004974353592842817, -0.06945415586233139, 0.09363085776567459, 0.0032440521754324436, -0.017104072496294975, 0.012751821428537369, 0.020224502310156822, 0.03275492787361145, 0.0269660372287035, 0.017141055315732956, -0.009103717282414436, 0.025365227833390236, -0.01629393734037876, 0.027270613238215446, -0.009784468449652195, 0.03163662180304527, -0.006145671010017395, -0.06390208750963211, 0.03263423219323158, 0.03522268682718277, 0.003966930788010359, 0.00006714566552545875, -0.046726275235414505, -0.021828072145581245, -0.029268857091665268, 0.028847815468907356, -0.004238575231283903, 0.03979162871837616, 0.002998639829456806, -0.01684544049203396, 0.04924086853861809, -0.05059533938765526, -0.004027568735182285, 0.06090608984231949, 0.03341168910264969, -0.016582835465669632, 0.00646028108894825, 0.04806331545114517, 0.018174491822719574, -0.05164414271712303, -0.004243419039994478, 0.019791388884186745, -0.035922612994909286, -0.004782673437148333, 0.01759723387658596, 0.01076694019138813, -0.006716287694871426, -0.011071407236158848, 0.025246642529964447, 0.0011041999096050858, 0.015781357884407043, 0.0027199401520192623, 0.0011008003493770957, -0.021380584686994553, 0.032153308391571045, 0.021932831034064293, -0.018201962113380432, 0.004069213755428791, 0.024876629933714867, 0.01832284964621067, 0.05943215638399124, -0.017377261072397232, 0.04401123523712158, -0.012257406488060951, 0.031149188056588173, 0.02179960533976555, -0.006398377940058708, 0.007273832336068153, 0.0173516683280468, 0.03419847786426544, -0.004098658915609121, 0.006482945289462805, 0.031187763437628746, -0.03550364077091217, 0.0031411282252520323, -0.016869697719812393, -0.002219944028183818, -0.0075782835483551025, 0.03820899873971939, 0.0050927759148180485, -0.017582805827260017, -0.024381550028920174, 0.02899646945297718, 0.006409162189811468, -0.004148145206272602, -0.01168357115238905, -0.000394488190067932, 0.00964111927896738, 0.03854219987988472, 0.020231107249855995, 0.02033473365008831, 0.019203094765543938, 0.03474703058600426, 0.014567513018846512, -0.0271798986941576, 0.002586261834949255, 0.00046967275557108223, -0.030405491590499878, 0.018197698518633842, -0.007973829284310341, 0.04893292114138603, -0.016092976555228233, 0.02163826674222946, -0.02876371704041958, -0.008206351660192013, -0.002962124766781926, 0.01534327957779169, 0.03457316383719444, 0.030710797756910324, 0.012514438480138779, -0.0020504207350313663, -0.019607266411185265, -0.03591760993003845, -0.0035546545404940844, -0.010036859661340714, 0.018091998994350433, 0.01769930124282837, 0.008794628083705902, -0.005104190204292536, 0.002771911211311817, 0.03832368180155754, 0.01217149943113327, 0.010262866504490376, 0.00802181102335453, -0.010386067442595959, -0.027695581316947937, 0.004093070048838854, -0.01329049188643694, 0.017556799575686455, 0.008308609016239643, -0.026842942461371422, 0.03964220732450485, -0.0074461461044847965, 0.015880925580859184, -0.02304295264184475, 0.011648771353065968, 0.0019671772606670856, 0.004907793831080198, 0.012102036736905575, -0.027195438742637634, -0.017468083649873734, -0.007290753070265055, -0.003131405683234334, 0.005236088763922453, 0.008768225088715553, -0.001454765209928155, 0.008274299092590809, -0.032994695007801056, -0.014666841365396976, 0.012145313434302807, -0.015974661335349083, -0.00019834120757877827, -0.00869032647460699, -0.01825506053864956, 0.009761890396475792, -0.0014236916322261095, -0.058531831949949265, 0.049414463341236115, -0.011711926199495792, 0.02271023951470852, 0.024854883551597595, -0.00018828663451131433, 0.03681134060025215, 0.017040610313415527, -0.03532697632908821, -0.012820766307413578, 0.01819203794002533, 0.01841001585125923, 0.010398336686193943, 0.009812207892537117, 0.02393699623644352, 0.020401090383529663, -0.04964542016386986, -0.012644610367715359, -0.034380409866571426, -0.02594956010580063, 0.007330528926104307, 0.005686817690730095, -0.004957726690918207, -0.006889319512993097, 0.013289171271026134, -0.00902136042714119, -0.023251628503203392, -0.015256984159350395, 0.025796115398406982, 0.044066764414310455, -0.033385083079338074, 0.006856800522655249, -0.010882314294576645, -0.04741281643509865, -0.015075926668941975, 0.026300538331270218, -0.016717402264475822, 0.013185689225792885, 0.027427366003394127, -0.00007392070256173611, -0.13605859875679016, 0.008423710241913795, -0.03539785370230675, 0.01227860152721405, -0.0248996801674366, 0.007414990104734898, 0.027171090245246887, 0.010459152050316334, 0.015005079098045826, 0.040863800793886185, 0.002797841327264905, 0.038530487567186356, 0.042197078466415405, -0.018121827393770218, 0.01499828603118658, 0.026912085711956024, 0.03339625522494316, -0.02596556954085827, -0.012006711214780807, -0.01305440068244934, 0.009717782959342003, 0.005294995382428169, -0.009371520951390266, -0.0020184770692139864, -0.004056769888848066, 0.0149581553414464, 0.022465873509645462, -0.027563411742448807, 0.010998144745826721, 0.026134319603443146, -0.0082212770357728, 0.02378666214644909, 0.008073300123214722, -0.018570763990283012, 0.01771535538136959, -0.05791052058339119, 0.003516866359859705, 0.02259201370179653, -0.016375545412302017, 0.016903214156627655, -0.018952377140522003, -0.01624208129942417, -0.07431814819574356, -0.02310403622686863, -0.0005193000542931259, -0.007151677738875151, 0.0007461393834091723, -0.008825158700346947, 0.027705848217010498, 0.0291593074798584, -0.04025710001587868, 0.021937977522611618, 0.011153954081237316, 0.021032925695180893, -0.02298913523554802, 0.031031997874379158, 0.024651341140270233, 0.03971514105796814, -0.005114371422678232, 0.02458147518336773, 0.020472409203648567, 0.0063279131427407265, 0.005639025010168552, -0.011007880792021751, -0.0005265453364700079, -0.0017852057935670018, -0.03278258815407753, 0.005323189776390791, -0.0195890162140131, 0.004275730345398188, -0.028000950813293457, 0.021013544872403145, 0.021881502121686935, 0.034683290868997574, -0.009087181650102139, -0.004031880293041468, -0.01298067532479763, -0.040026091039180756, -0.025632556527853012, -0.03474593162536621, -0.00835792813450098, 0.00740921450778842, 0.07613364607095718, -0.005620404612272978, -0.012391443364322186, -0.01392796915024519, -0.015498525463044643, -0.02644759975373745, -0.0190245620906353, 0.020614901557564735, -0.03293798491358757, 0.054214805364608765, 0.02563278190791607, -0.004010746721178293, 0.004125059582293034, 0.01010754331946373, 0.020891672000288963, 0.0016696422826498747, 0.016511809080839157, -0.009257332421839237, -0.02048596739768982, 0.00010062016372103244, -0.011441120877861977, 0.024708367884159088, -0.0035246089100837708, -0.012703307904303074, 0.022829068824648857, -0.07438384741544724, -0.002978462725877762, 0.018287837505340576, -0.06611312180757523, 0.012393495999276638, 0.014578468166291714, 0.055445361882448196, -0.03936036676168442, -0.014173237606883049, -0.00005607734419754706 ]
8a9ed7740bcb98fbae13ca6bc7e08c9cb1a32fd1
4,384
py
Python
semantic-segmentation/deeplabv3plus/dataset_utils.py
shikisawamura/nnabla-examples
baf4e4cc620dedbf4368683325c0fb868676850d
[ "Apache-2.0" ]
1
2020-08-03T12:49:25.000Z
2020-08-03T12:49:25.000Z
semantic-segmentation/deeplabv3plus/dataset_utils.py
takuseno/nnabla-examples
070d25078ad3d5458744dbfd390cdd926e20e573
[ "Apache-2.0" ]
null
null
null
semantic-segmentation/deeplabv3plus/dataset_utils.py
takuseno/nnabla-examples
070d25078ad3d5458744dbfd390cdd926e20e573
[ "Apache-2.0" ]
1
2020-04-25T06:11:28.000Z
2020-04-25T06:11:28.000Z
# Copyright (c) 2017 Sony Corporation. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import numpy as np import os from scipy.misc import imread from args import get_args import matplotlib.pyplot as plt def get_color(): # RGB format return np.array([[0, 0, 0], [128, 0, 0], [0, 128, 0], [128, 128, 0], [0, 0, 128], [120, 0, 128], [0, 128, 128], [128, 128, 128], [64, 0, 0], [192, 0, 0], [64, 128, 0], [192, 128, 0], [64, 0, 128], [192, 0, 128], [64, 128, 128], [192, 128, 128], [0, 64, 0], [128, 64, 0], [0, 192, 0], [128, 192, 0], [0, 64, 128], [224, 224, 192]]) def encode_label(label): ''' Converting pixel values to corresponding class numbers. Assuming that the input label in 3-dim(h,w,c) and in BGR fromat read from cv2 ''' h, w, c = label.shape new_label = np.zeros((h, w, 1), dtype=np.int32) cls_to_clr_map = get_color() for i in range(cls_to_clr_map.shape[0]): #new_label[(label == cls_to_clr_map[i])[:,:,0]] = i #new_label[np.argwhere((label.astype(np.int32) == cls_to_clr_map[i]).all(axis=2))]=i print(np.where((label.astype(np.int32) == [120, 0, 128]).all(axis=2))) if i == 21: new_label[np.where( (label.astype(np.int32) == cls_to_clr_map[i]).all(axis=2))] = 255 else: new_label[np.where( (label.astype(np.int32) == cls_to_clr_map[i]).all(axis=2))] = i return new_label # this method should generate train-image.txt and train-label.txt def generate_path_files(data_dir, train_file, val_file): ti = open('train_image.txt', 'w') tl = open('train_label.txt', 'w') vi = open('val_image.txt', 'w') vl = open('val_label.txt', 'w') rootdir = data_dir train_text_file = open(train_file, "r") lines = [line[:-1] for line in train_text_file] for line in lines: if os.path.exists(data_dir+'JPEGImages/'+line+'.jpg'): ti.write(data_dir+'JPEGImages/'+line+'.jpg' + '\n') assert (os.path.isfile(data_dir+'SegmentationClass/encoded/'+line + '.npy')), "No matching label file for image : " + line + '.jpg' tl.write(data_dir+'SegmentationClass/encoded/'+line + '.npy' + '\n') val_text_file = open(val_file, "r") lines = [line[:-1] for line in val_text_file] for line in lines: if os.path.exists(data_dir+'JPEGImages/'+line+'.jpg'): vi.write(data_dir+'JPEGImages/'+line+'.jpg' + '\n') assert (os.path.isfile(data_dir+'SegmentationClass/encoded/'+line + '.npy')), "No matching label file for image : " + line + '.jpg' vl.write(data_dir+'SegmentationClass/encoded/'+line + '.npy' + '\n') ti.close() tl.close() vi.close() vl.close() def main(): ''' Arguments: train-file = txt file containing randomly selected image filenames to be taken as training set. val-file = txt file containing randomly selected image filenames to be taken as validation set. data-dir = dataset directory Usage: python dataset_utils.py --train-file="" --val-file="" --data_dir="" ''' args = get_args() data_dir = args.data_dir if not os.path.exists(data_dir+'SegmentationClass/' + 'encoded/'): os.makedirs(data_dir+'SegmentationClass/' + 'encoded/') for filename in os.listdir(data_dir+'SegmentationClass/'): if os.path.isdir(data_dir+'SegmentationClass/' + filename): continue label = imread(data_dir+'SegmentationClass/' + filename).astype('float32') label = encode_label(label) np.save(data_dir+'SegmentationClass/' + 'encoded/' + filename.split('.')[0] + '.npy', label) generate_path_files(args.data_dir, args.train_file, args.val_file) if __name__ == '__main__': main()
38.79646
334
0.619297
1
2.3091
[ -0.004405154846608639, 0.05867762118577957, 0.03151629492640495, -0.003955360036343336, -0.056621093302965164, -0.009649138897657394, 0.018164141103625298, 0.010407046414911747, -0.009539344348013401, 0.02272844687104225, 0.02333526499569416, 0.004195797257125378, -0.012378483079373837, 0.034485913813114166, 0.033692993223667145, -0.03987846150994301, 0.07228459417819977, 0.05703015998005867, 0.01998947374522686, 0.0332094170153141, 0.02780025824904442, 0.012317463755607605, -0.00399530166760087, 0.029673630371689796, -0.012520636431872845, 0.04299427941441536, 0.055225223302841187, 0.00031910333200357854, 0.0018759300000965595, 0.0231908168643713, -0.02617589756846428, -0.0060343374498188496, -0.05125093087553978, 0.020801398903131485, 0.01649836264550686, -0.0049288710579276085, 0.000959620694629848, -0.10263136774301529, 0.012068831361830235, -0.026964368298649788, -0.02272752858698368, -0.019300928339362144, -0.02770109847187996, -0.0020736195147037506, 0.09030260890722275, 0.007001538295298815, -0.0011973867658525705, -0.007237184327095747, -0.01444875169545412, -0.005911895539611578, -0.02266918309032917, 0.0082695996388793, 0.046728674322366714, -0.029647065326571465, 0.04573099687695503, -0.03046250529587269, 0.013044682331383228, 0.019119860604405403, -0.05755968019366264, -0.004069450311362743, -0.039726097136735916, 0.04778272658586502, 0.07115034013986588, 0.014948506839573383, -0.041862864047288895, -0.013129628263413906, 0.011620331555604935, 0.018174350261688232, -0.04695378243923187, 0.01528445165604353, -0.013854905031621456, 0.028996482491493225, 0.008142754435539246, 0.02561318315565586, -0.02646399475634098, -0.033722810447216034, -0.04286413639783859, -0.012924332171678543, -0.04625849798321724, -0.023583464324474335, 0.009208445437252522, 0.06237795203924179, 0.025457561016082764, -0.02041790634393692, 0.025826528668403625, 0.07216400653123856, 0.04624065011739731, -0.030010219663381577, 0.05869733914732933, 0.00853835791349411, -0.02212168276309967, 0.012711388990283012, -0.000970928929746151, -0.005813377909362316, -0.04344563186168671, -0.04642689228057861, -0.003011135384440422, 0.021964166313409805, -0.014965358190238476, 0.020173249766230583, 0.03984341770410538, -0.014769108965992928, 0.025889156386256218, -0.01719672605395317, -0.004927853122353554, -0.005872821435332298, -0.059921495616436005, -0.033443234860897064, -0.005165172275155783, -0.020901473239064217, -0.034370362758636475, -0.016707252711057663, 0.055492550134658813, -0.013491611927747726, -0.019754717126488686, 0.0004748677310999483, 0.021989088505506516, 0.03905922919511795, -0.03438960388302803, -0.01740187220275402, -0.008789600804448128, -0.0017683054320514202, 0.009793090634047985, -0.007006112020462751, -0.0022142205853015184, 0.050295405089855194, 0.010454189963638783, 0.0032224240712821484, 0.020395874977111816, -0.010164485312998295, 0.007265779655426741, 0.00101360899861902, -0.03673413768410683, 0.00415185559540987, -0.025019878521561623, -0.025399941951036453, -0.0007814920390956104, 0.016504429280757904, -0.0213710218667984, 0.001999862492084503, 0.002601826097816229, -0.027575714513659477, 0.01922704093158245, 0.03084561601281166, 0.002699771896004677, -0.016225643455982208, -0.023079922422766685, -0.00230795843526721, -0.02134818769991398, -0.02632700651884079, 0.019034378230571747, 0.018924307078123093, -0.03563991189002991, 0.0220688134431839, -0.00017942785052582622, -0.007884174585342407, -0.02197887748479843, -0.023595217615365982, 0.007645178586244583, 0.07184521853923798, -0.03471122682094574, -0.016408655792474747, -0.007673935033380985, 0.0008612342062406242, 0.011867308989167213, -0.03778299316763878, -0.017861202359199524, -0.0037424261681735516, -0.022007985040545464, -0.046036217361688614, -0.011426323093473911, 0.029493974521756172, 0.009302354417741299, 0.012656676582992077, -0.05284178629517555, 0.013841656036674976, 0.05600307881832123, 0.029860859736800194, 0.03171816095709801, -0.03028033673763275, -0.02270042896270752, 0.010116515681147575, 0.00734441913664341, 0.031985897570848465, -0.00433807959780097, -0.047454625368118286, -0.04584409296512604, -0.023375283926725388, 0.054173730313777924, 0.003636146429926157, 0.010411055758595467, 0.044216327369213104, -0.03122987039387226, -0.011733188293874264, 0.04461415857076645, -0.030829409137368202, 0.010790606029331684, 0.02704824134707451, -0.003416134277358651, -0.005969266872853041, -0.02484627440571785, -0.015927260741591454, 0.03229964151978493, 0.05122557282447815, 0.03176836296916008, 0.0023952668998390436, -0.6398184895515442, 0.027752479538321495, 0.020253879949450493, -0.011273669078946114, 0.031450990587472916, 0.029680339619517326, 0.03468836098909378, 0.020773839205503464, -0.037697866559028625, -0.03467458114027977, 0.00398403313010931, 0.015376999042928219, -0.03538208827376366, -0.03077959641814232, 0.011918588541448116, -0.032957546412944794, -0.019007951021194458, 0.0023760460317134857, 0.013964597135782242, -0.02875235490500927, 0.006271497346460819, 0.025655508041381836, -0.029815346002578735, 0.004905050154775381, -0.0019990154542028904, -0.07039765268564224, 0.02769913524389267, -0.009726631455123425, 0.003972530830651522, -0.059754274785518646, -0.018806306645274162, 0.019461067393422127, 0.020810190588235855, -0.002599309664219618, -0.006743584293872118, 0.049728479236364365, 0.026081036776304245, 0.0017220447771251202, 0.028961019590497017, 0.01964528299868107, -0.019117269665002823, -0.00371663854457438, -0.009361853823065758, -0.038718756288290024, -0.019491860643029213, -0.063191719353199, -0.008985125459730625, -0.029754523187875748, 0.035297784954309464, -0.005401965230703354, 0.00409420533105731, 0.0386088527739048, 0.0404139906167984, 0.00019165052799507976, 0.00834615994244814, -0.041329048573970795, -0.04864365607500076, -0.0006257146596908569, 0.018760494887828827, 0.0018311635358259082, 0.032827503979206085, -0.00983583927154541, -0.018541716039180756, -0.01260820310562849, -0.019739244133234024, -0.0012234336463734508, 0.10019651055335999, -0.03351166471838951, -0.0023000354412943125, 0.0026524330023676157, -0.035754840821027756, 0.007651214022189379, -0.03966929018497467, -0.031067069619894028, 0.004578841384500265, -0.006541000213474035, 0.02811911702156067, -0.008842536248266697, -0.01961692050099373, 0.004004981834441423, 0.025089340284466743, -0.0032436668407171965, -0.003083188086748123, 0.0012362090637907386, 0.017297441139817238, -0.04305293411016464, 0.0032699950970709324, -0.020208947360515594, 0.010752248577773571, -0.0029970293398946524, -0.027392195537686348, -0.007810435723513365, 0.015618480741977692, -0.012751912698149681, -0.01299979817122221, 0.03793231025338173, 0.031575050204992294, 0.02724958397448063, 0.010401517152786255, 0.038627732545137405, 0.015705708414316177, -0.016947193071246147, 0.0065988050773739815, 0.016701744869351387, -0.026606563478708267, -0.021770257502794266, -0.01225719042122364, 0.007208851166069508, -0.01842615008354187, -0.06213280186057091, 0.0011122003197669983, -0.0017497268272563815, 0.011275497265160084, -0.0076093003153800964, -0.06989661604166031, -0.007997844368219376, -0.0066843824461102486, -0.04614296928048134, -0.005245716776698828, -0.016331026330590248, -0.021094005554914474, -0.0290478877723217, -0.016896361485123634, -0.0006990251131355762, -0.026705441996455193, -0.0032049762085080147, 0.014065311290323734, 0.012096608988940716, 0.014372470788657665, -0.008615421131253242, -0.048176441341638565, 0.0068305316381156445, 0.02958342432975769, 0.016308119520545006, -0.0197480246424675, -0.02509281411767006, -0.038095708936452866, -0.015280407853424549, 0.036813654005527496, -0.043729621917009354, -0.017662284895777702, 0.028248295187950134, 0.021413810551166534, -0.011671420186758041, -0.015779320150613785, 0.018963996320962906, 0.004854911472648382, 0.00701545225456357, -0.018591217696666718, -0.016619427129626274, 0.01609542779624462, -0.02518853358924389, 0.005888430867344141, 0.025066828355193138, -0.02976115792989731, 0.006637765560299158, -0.0446070060133934, 0.021625839173793793, 0.05018045753240585, -0.005815397948026657, 0.002146926010027528, 0.02847876399755478, 0.0005161963636055589, 0.005865313578397036, -0.023496724665164948, -0.02790471352636814, -0.0009079649462364614, 0.014216717332601547, 0.002757332054898143, 0.03359026834368706, 0.06589187681674957, -0.0013867749366909266, 0.026987431570887566, 0.04202036187052727, 0.0016560180811211467, -0.03564641624689102, 0.006420289631932974, -0.04551508277654648, -0.0020752958953380585, -0.01482082437723875, -0.018093029037117958, -0.00644616037607193, -0.038758132606744766, 0.0030275920871645212, -0.009232324548065662, -0.025650976225733757, -0.010515257716178894, -0.026152564212679863, -0.015092628076672554, -0.010916462168097496, 0.02273370325565338, 0.03817691653966904, -0.015900956466794014, -0.024248307570815086, -0.06666858494281769, 0.006034337915480137, -0.031040702015161514, -0.039175793528556824, 0.00007546070992248133, 0.02806333638727665, 0.0303969569504261, 0.00746446568518877, -0.01101767085492611, 0.012098348699510098, -0.01022261567413807, 0.059520114213228226, 0.000057273104175692424, 0.01930486038327217, 0.03250451385974884, -0.0027370741590857506, 0.015372824855148792, -0.011086704209446907, 0.028015270829200745, 0.018374532461166382, -0.022468984127044678, 0.0030079756397753954, -0.005592096131294966, -0.02694266475737095, 0.005340335890650749, -0.011896168813109398, -0.005340406205505133, -0.06664760410785675, 0.04380131512880325, 0.009839722886681557, 0.038585301488637924, -0.002065568696707487, -0.004364845808595419, 0.002441645134240389, 0.002871950389817357, -0.019650686532258987, 0.011705389246344566, 0.01353705208748579, 0.03292369470000267, -0.037409014999866486, 0.03137560188770294, 0.01376722939312458, 0.0058637275360524654, -0.014310251921415329, 0.011461571790277958, -0.025077495723962784, 0.01690385490655899, -0.017819125205278397, 0.030864160507917404, -0.010039550252258778, -0.00554264709353447, -0.005536445416510105, -0.004863051697611809, -0.021430378779768944, -0.029416421428322792, -0.014678547158837318, -0.029537862166762352, 0.06374392658472061, 0.004265097435563803, -0.0327875129878521, -0.031312085688114166, 0.016540300101041794, 0.018851887434720993, 0.0047835251316428185, 0.03717721253633499, 0.029623087495565414, -0.024577271193265915, -0.00023009510186966509, 0.023612068966031075, 0.01793234422802925, 0.026213884353637695, -0.02091684192419052, 0.025944536551833153, 0.004139026626944542, -0.06184520944952965, -0.031635966151952744, -0.05064371973276138, -0.000343621417414397, -0.02205567993223667, -0.02783304639160633, 0.01135807204991579, 0.025516381487250328, -0.030668148770928383, -0.0012492272071540356, 0.032774392515420914, 0.013841181993484497, 0.01761060580611229, -0.035250235348939896, 0.022682346403598785, 0.009958147071301937, -0.014729343354701996, 0.006836249493062496, -0.033652789890766144, 0.03108234331011772, -0.07337360084056854, -0.04667090252041817, 0.007921689189970493, -0.0492643304169178, 0.04193459451198578, -0.002386006759479642, -0.013932972215116024, -0.014814150519669056, -0.014463143423199654, 0.017225902527570724, 0.033375974744558334, 0.00004378498124424368, 0.00017745612422004342, -0.0027484637685120106, -0.0077104829251766205, -0.021544286981225014, -0.00023381647770293057, -0.027183735743165016, 0.008676246739923954, 0.001254515489563346, -0.0003623280499596149, 0.03819809481501579, -0.0058483644388616085, 0.07152947038412094, -0.004219576250761747, -0.006383334286510944, 0.010574842803180218, 0.011986828409135342, 0.060686152428388596, -0.025602614507079124, -0.020348915830254555, 0.015243029221892357, -0.025535283610224724, 0.028737789019942284, -0.035358309745788574, -0.006142010446637869, 0.024138228967785835, -0.019069096073508263, -0.021247578784823418, 0.005546501372009516, 0.023813724517822266, 0.02917211502790451, 0.03877948969602585, -0.03181920200586319, 0.03418419510126114, -0.009506176225841045, -0.02104800194501877, 0.005061163567006588, 0.007404729723930359, 0.021899616345763206, 0.009885819628834724, -0.0051897005178034306, -0.04683711752295494, -0.022508768364787102, 0.0016110274009406567, -0.0036816818173974752, -0.00912467297166586, -0.023747490718960762, 0.0021409394685178995, 0.06710232049226761, -0.01219103205949068, -0.01477555651217699, 0.023307301104068756, 0.026785001158714294, -0.041560716927051544, 0.0342826321721077, -0.02080317586660385, 0.006656271871179342, -0.024116206914186478, 0.006426041480153799, -0.027598824352025986, -0.0005960381240583956, 0.029070453718304634, -0.019534926861524582, 0.002379816025495529, 0.006696342956274748, -0.002219873946160078, 0.01814921200275421, 0.01287946105003357, -0.007159498054534197, -0.00865427777171135, 0.00926585216075182, 0.018020084127783775, -0.02731122262775898, 0.06053176522254944, 0.013290303759276867, -0.0371924564242363, 0.018574308604002, 0.008558147586882114, -0.0003444133326411247, 0.028783036395907402, -0.03068479523062706, -0.018249990418553352, -0.0032298138830810785, 0.03491086885333061, 0.004582620691508055, -0.0051109641790390015, -0.07959003001451492, -0.020884528756141663, 0.0034087926615029573, -0.06178513541817665, -0.03647851571440697, -0.0030541152227669954, -0.03508825600147247, 0.006238078698515892, 0.03421548753976822, -0.034495700150728226, 0.04418470337986946, 0.016333337873220444, 0.013866395689547062, -0.015982050448656082, 0.00829578097909689, 0.011910492554306984, 0.026946432888507843, -0.008653559722006321, 0.013049846515059471, 0.006126891355961561, -0.023828808218240738, 0.0030433854553848505, -0.01121912058442831, 0.048396315425634384, 0.020574135705828667, 0.0051034740172326565, 0.047681111842393875, -0.010612733662128448, 0.012067152187228203, -0.0014396540354937315, 0.002557961270213127, -0.054718226194381714, 0.01159125566482544, -0.0036148950457572937, 0.06405440717935562, -0.052088506519794464, -0.011437688954174519, -0.013309454545378685, 0.02251535840332508, 0.013710486702620983, 0.00869794562458992, -0.0063006579875946045, -0.00953019130975008, -0.0593205951154232, 0.03476342186331749, -0.0014516499359160662, 0.018549885600805283, -0.023326771333813667, 0.00017265415226574987, 0.02749781869351864, -0.04758770763874054, -0.037803880870342255, -0.015949726104736328, -0.023732198402285576, -0.012105939909815788, -0.008985623717308044, 0.00598732428625226, -0.0500769205391407, 0.019717145711183548, 0.03720657154917717, -0.05481056496500969, 0.03832913190126419, -0.03221123293042183, -0.022257192060351372, -0.014643070288002491, 0.03127473592758179, -0.01239206176251173, 0.03907075896859169, -0.0017916738288477063, 0.00016219036479014903, 0.02069019339978695, 0.007269652094691992, 0.04582200199365616, -0.057342804968357086, 0.0037818418350070715, 0.016355961561203003, 0.05965559557080269, -0.0032153266947716475, 0.029324160888791084, 0.025159554556012154, 0.040045786648988724, 0.03506309166550636, 0.011906162835657597, 0.016349608078598976, -0.002238744869828224, -0.028073010966181755, -0.012725792825222015, -0.00758650666102767, 0.020289717242121696, -0.04993291571736336, 0.03218301385641098, -0.014005333185195923, 0.023891441524028778, -0.009808300994336605, 0.025631660595536232, 0.035591308027505875, 0.0013355627888813615, -0.004506115335971117, 0.034638457000255585, 0.022971805185079575, 0.01026835385710001, -0.006246331613510847, -0.01960890181362629, 0.004838107153773308, 0.02521340362727642, -0.040303125977516174, -0.01242460124194622, 0.004892054479569197, -0.0010797708528116345, 0.02234445884823799, -0.048927146941423416, 0.00046716671204194427, 0.017122993245720863, 0.07200495898723602, 0.0005928230821155012, -0.039312172681093216, 0.007759142201393843, 0.005579871591180563, -0.027186986058950424, 0.01458497904241085, 0.051758941262960434, 0.015349890105426311, 0.04131518304347992, 0.006463862024247646, -0.045115333050489426, -0.0004894387093372643, -0.009141108021140099, -0.01634378172457218, -0.03169752657413483, 0.04341575503349304, 0.008022456429898739, 0.036280278116464615, -0.0913146436214447, 0.013657339848577976, 0.02684820257127285, 0.02433984912931919, -0.027891788631677628, -0.017457032576203346, -0.010138968005776405, -0.029926059767603874, -0.009385969489812851, -0.022405020892620087, -0.0068782782182097435, 0.023448480293154716, 0.0041389185935258865, -0.001484556240029633, -0.01088255736976862, -0.01854454167187214, -0.03318330645561218, -0.02585514262318611, -0.05739709362387657, 0.04150999337434769, 0.021324090659618378, -0.0016364422626793385, -0.0512082614004612, 0.035067617893218994, 0.04710710048675537, 0.0016858801245689392, -0.03980378806591034, -0.004018726758658886, -0.0036244401708245277, -0.00021805029246024787, -0.03507257252931595, 0.033312488347291946, -0.010054238140583038, 0.018241018056869507, 0.015515884384512901, -0.017019277438521385, -0.00011195841216249391, -0.04728083685040474, 0.021044636145234108, 0.015104848891496658, -0.011032604612410069, 0.012334612198174, -0.01865355670452118, 0.003146865637972951, 0.0014317815657705069 ]
8a9edfbe7de3c135419c8254312b876a5177e47f
10,044
py
Python
train.py
shamilcm/fairseq-py
ceb2f1200c9e5b8bf42a1033e7638d3e8586609a
[ "BSD-3-Clause" ]
1
2021-04-20T07:33:12.000Z
2021-04-20T07:33:12.000Z
train.py
shamilcm/fairseq-py
ceb2f1200c9e5b8bf42a1033e7638d3e8586609a
[ "BSD-3-Clause" ]
null
null
null
train.py
shamilcm/fairseq-py
ceb2f1200c9e5b8bf42a1033e7638d3e8586609a
[ "BSD-3-Clause" ]
3
2018-04-20T11:00:16.000Z
2020-04-25T09:31:14.000Z
# Copyright (c) 2017-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the LICENSE file in # the root directory of this source tree. An additional grant of patent rights # can be found in the PATENTS file in the same directory. # import collections import os import torch import math from fairseq import bleu, data, options, utils from fairseq.meters import AverageMeter, StopwatchMeter, TimeMeter from fairseq.multiprocessing_trainer import MultiprocessingTrainer from fairseq.progress_bar import progress_bar from fairseq.sequence_generator import SequenceGenerator def main(): parser = options.get_parser('Trainer') dataset_args = options.add_dataset_args(parser) dataset_args.add_argument('--max-tokens', default=0, type=int, metavar='N', help='maximum number of tokens in a batch') dataset_args.add_argument('--batch-size', default=32, type=int, metavar='N', help='batch size') dataset_args.add_argument('--test-batch-size', default=32, type=int, metavar='N', help='batch size for test set') dataset_args.add_argument('--valid-batch-size', default=32, type=int, metavar='N', help='batch size for validation set') dataset_args.add_argument('--train-subset', default='train', metavar='SPLIT', choices=['train', 'valid', 'test'], help='data subset to use for training (train, valid, test)') dataset_args.add_argument('--valid-subset', default='valid', metavar='SPLIT', help='comma separated list ofdata subsets ' ' to use for validation (train, valid, valid1,test, test1)') dataset_args.add_argument('--test-subset', default='test', metavar='SPLIT', help='comma separated list ofdata subset ' 'to use for testing (train, valid, test)') dataset_args.add_argument('--valid-script', nargs='+', metavar='PATH', help='path to external validation script (optional).') options.add_optimization_args(parser) options.add_checkpoint_args(parser) options.add_model_args(parser) args = utils.parse_args_and_arch(parser) print(args) if args.no_progress_bar: progress_bar.enabled = False progress_bar.print_interval = args.log_interval if not os.path.exists(args.save_dir): os.makedirs(args.save_dir) torch.manual_seed(args.seed) # Setting args.max_tokens to infinity(same as setting to None) if args.max_tokens == 0: args.max_tokens = None # Load dataset dataset = data.load_with_check(args.data, args.source_lang, args.target_lang) if args.source_lang is None or args.target_lang is None: # record inferred languages in args, so that it's saved in checkpoints args.source_lang, args.target_lang = dataset.src, dataset.dst print('| [{}] dictionary: {} types'.format(dataset.src, len(dataset.src_dict))) print('| [{}] dictionary: {} types'.format(dataset.dst, len(dataset.dst_dict))) for split in dataset.splits: print('| {} {} {} examples'.format(args.data, split, len(dataset.splits[split]))) if not torch.cuda.is_available(): raise NotImplementedError('Training on CPU is not supported') num_gpus = torch.cuda.device_count() print('| using {} GPUs (with max tokens per GPU = {})'.format(num_gpus, args.max_tokens)) # Build model print('| model {}'.format(args.arch)) model = utils.build_model(args, dataset) criterion = utils.build_criterion(args, dataset) # Start multiprocessing trainer = MultiprocessingTrainer(args, model) # Load the latest checkpoint if one is available epoch, batch_offset = trainer.load_checkpoint(os.path.join(args.save_dir, args.restore_file)) # Train until the learning rate gets too small val_loss = None max_epoch = args.max_epoch or math.inf lr = trainer.get_lr() train_meter = StopwatchMeter() train_meter.start() while lr > args.min_lr and epoch <= max_epoch: # train for one epoch train(args, epoch, batch_offset, trainer, criterion, dataset, num_gpus) # evaluate on validate set for k, subset in enumerate(args.valid_subset.split(',')): val_loss = validate(args, epoch, trainer, criterion, dataset, subset, num_gpus) if k == 0: if not args.no_save: # save checkpoint trainer.save_checkpoint(args, epoch, 0, val_loss, validation_script=args.valid_script) # only use first validation loss to update the learning schedule lr = trainer.lr_step(val_loss, epoch) epoch += 1 batch_offset = 0 train_meter.stop() print('| done training in {:.1f} seconds'.format(train_meter.sum)) # Generate on test set and compute BLEU score for beam in [1, 5, 10, 20]: for subset in args.test_subset.split(','): scorer = score_test(args, trainer.get_model(), dataset, subset, beam, cuda_device=(0 if num_gpus > 0 else None)) print('| Test on {} with beam={}: {}'.format(subset, beam, scorer.result_string())) # Stop multiprocessing trainer.stop() def train(args, epoch, batch_offset, trainer, criterion, dataset, num_gpus): """Train the model for one epoch.""" itr = dataset.dataloader(args.train_subset, batch_size=args.batch_size, test_batch_size=args.test_batch_size, valid_batch_size=args.valid_batch_size, num_workers=args.workers, max_tokens=args.max_tokens, seed=args.seed, epoch=epoch, max_positions=args.max_positions, sample_without_replacement=args.sample_without_replacement) loss_meter = AverageMeter() bsz_meter = AverageMeter() # sentences per batch wpb_meter = AverageMeter() # words per batch wps_meter = TimeMeter() # words per second clip_meter = AverageMeter() # % of updates clipped gnorm_meter = AverageMeter() # gradient norm desc = '| epoch {:03d}'.format(epoch) lr = trainer.get_lr() with progress_bar(itr, desc, leave=False) as t: for i, sample in data.skip_group_enumerator(t, num_gpus, batch_offset): loss, grad_norm = trainer.train_step(sample, criterion) ntokens = sum(s['ntokens'] for s in sample) src_size = sum(s['src_tokens'].size(0) for s in sample) loss_meter.update(loss, ntokens) bsz_meter.update(src_size) wpb_meter.update(ntokens) wps_meter.update(ntokens) clip_meter.update(1 if grad_norm > args.clip_norm else 0) gnorm_meter.update(grad_norm) t.set_postfix(collections.OrderedDict([ ('loss', '{:.2f} ({:.2f})'.format(loss, loss_meter.avg)), ('wps', '{:5d}'.format(round(wps_meter.avg))), ('wpb', '{:5d}'.format(round(wpb_meter.avg))), ('bsz', '{:5d}'.format(round(bsz_meter.avg))), ('lr', lr), ('clip', '{:3.0f}%'.format(clip_meter.avg * 100)), ('gnorm', '{:.4f}'.format(gnorm_meter.avg)), ])) if i == 0: # ignore the first mini-batch in words-per-second calculation wps_meter.reset() if args.save_interval > 0 and (i + 1) % args.save_interval == 0: trainer.save_checkpoint(args, epoch, i + 1) fmt = desc + ' | train loss {:2.2f} | train ppl {:3.2f}' fmt += ' | s/checkpoint {:7d} | words/s {:6d} | words/batch {:6d}' fmt += ' | bsz {:5d} | lr {:0.6f} | clip {:3.0f}% | gnorm {:.4f}' t.write(fmt.format(loss_meter.avg, math.pow(2, loss_meter.avg), round(wps_meter.elapsed_time), round(wps_meter.avg), round(wpb_meter.avg), round(bsz_meter.avg), lr, clip_meter.avg * 100, gnorm_meter.avg)) def validate(args, epoch, trainer, criterion, dataset, subset, ngpus): """Evaluate the model on the validation set and return the average loss.""" itr = dataset.dataloader(subset, batch_size=None, max_tokens=args.max_tokens, max_positions=args.max_positions) loss_meter = AverageMeter() desc = '| epoch {:03d} | valid on \'{}\' subset'.format(epoch, subset) with progress_bar(itr, desc, leave=False) as t: for _, sample in data.skip_group_enumerator(t, ngpus): ntokens = sum(s['ntokens'] for s in sample) loss = trainer.valid_step(sample, criterion) loss_meter.update(loss, ntokens) t.set_postfix(loss='{:.2f}'.format(loss_meter.avg)) val_loss = loss_meter.avg t.write(desc + ' | valid loss {:2.2f} | valid ppl {:3.2f}' .format(val_loss, math.pow(2, val_loss))) # update and return the learning rate return val_loss def score_test(args, model, dataset, subset, beam, cuda_device): """Evaluate the model on the test set and return the BLEU scorer.""" translator = SequenceGenerator([model], dataset.dst_dict, beam_size=beam) if torch.cuda.is_available(): translator.cuda() scorer = bleu.Scorer(dataset.dst_dict.pad(), dataset.dst_dict.eos(), dataset.dst_dict.unk()) itr = dataset.dataloader(subset, batch_size=4, max_positions=args.max_positions) for _, _, ref, hypos in translator.generate_batched_itr(itr, cuda_device=cuda_device): scorer.add(ref.int().cpu(), hypos[0]['tokens'].int().cpu()) return scorer if __name__ == '__main__': main()
44.052632
129
0.616587
1
1.9176
[ -0.024081267416477203, 0.014543780125677586, 0.013208093121647835, -0.004266710951924324, -0.04145678132772446, 0.004526703618466854, 0.00040089699905365705, -0.007966063916683197, -0.020075945183634758, 0.020818812772631645, -0.010100990533828735, 0.003389977151528001, 0.0313076414167881, -0.005450943950563669, -0.031205467879772186, -0.011621751822531223, 0.01574052684009075, 0.019885674118995667, -0.02068578265607357, -0.021846432238817215, 0.010259691625833511, 0.005011412780731916, -0.015051971189677715, 0.003958810120820999, 0.041762009263038635, 0.03543643653392792, 0.021451406180858612, 0.01258761528879404, 0.0026416336186230183, -0.002862815745174885, -0.024791395291686058, 0.035786692053079605, -0.023905301466584206, -0.012849180959165096, -0.0038525136187672615, -0.004606798756867647, 0.010038338601589203, -0.06044561415910721, 0.02572808414697647, -0.03363996371626854, -0.02782546915113926, -0.0030541722662746906, -0.01834508776664734, -0.004033586475998163, 0.048129353672266006, 0.014748768880963326, 0.028107650578022003, 0.013805215246975422, -0.010543829761445522, 0.015222829766571522, -0.007096387445926666, 0.008069496601819992, -0.0012216626200824976, 0.0035061833914369345, 0.015824271366000175, -0.04918207600712776, 0.011382455937564373, 0.03745635971426964, -0.007065854500979185, 0.020779699087142944, -0.021399103105068207, 0.01057612057775259, -0.017979377880692482, 0.024494944140315056, 0.05326779559254646, -0.02877792902290821, 0.0006933912518434227, -0.007900994271039963, -0.09254267811775208, 0.0156296044588089, 0.006521710194647312, 0.019133565947413445, -0.013710953295230865, 0.01865811087191105, -0.000809930672403425, 0.033114735037088394, -0.017992258071899414, -0.021603915840387344, -0.011706620454788208, 0.028235778212547302, -0.008948208764195442, 0.0642848014831543, 0.003815762232989073, 0.009531162679195404, 0.020280443131923676, 0.012803456746041775, 0.06297807395458221, -0.007035660557448864, 0.0139411436393857, -0.014926034957170486, -0.03155391290783882, 0.001648417324759066, -0.005534705705940723, -0.004711796063929796, -0.04225408285856247, -0.030775004997849464, 0.009979482740163803, 0.002553795464336872, 0.0016651356127113104, 0.01862078718841076, 0.013460466638207436, 0.022164324298501015, 0.01981554552912712, -0.028471551835536957, 0.006346933078020811, -0.021559489890933037, -0.03672822564840317, 0.0047043995000422, 0.018161797896027565, -0.018601829186081886, -0.09048578888177872, 0.010493204928934574, 0.04139577969908714, -0.03229738026857376, -0.011002554558217525, 0.01709740050137043, 0.0016091668512672186, -0.007455331273376942, -0.001107040443457663, 0.09520316123962402, 0.012207834981381893, 0.01754361018538475, 0.023322880268096924, -0.011347949504852295, -0.0514005608856678, 0.05433351919054985, 0.00443379208445549, -0.0029683911707252264, -0.004236734472215176, -0.012866328470408916, -0.03385094180703163, -0.020120324566960335, -0.0026659721042960882, 0.0017223611939698458, 0.00630803732201457, 0.01080817449837923, 0.0022693227510899305, 0.018590480089187622, -0.05476662144064903, 0.012164609506726265, 0.004304143600165844, -0.033893000334501266, 0.011599687859416008, 0.004511991515755653, -0.00011226197239011526, 0.03124663047492504, -0.014017478562891483, -0.0102273253723979, 0.0077682966366410255, -0.0033644228242337704, -0.001377044478431344, 0.017590632662177086, 0.022901523858308792, 0.010824071243405342, -0.027070263400673866, -0.00042902634595520794, -0.03274952992796898, -0.03896111622452736, -0.013435202650725842, -0.0006759820389561355, -0.011058613657951355, 0.010493148118257523, -0.014439436607062817, 0.010370388627052307, 0.04478808864951134, -0.03542710468173027, -0.025363903492689133, 0.02052140422165394, 0.015509496442973614, 0.0305548757314682, 0.020731711760163307, 0.020759236067533493, 0.01474551111459732, -0.006078760139644146, -0.042402394115924835, -0.008943751454353333, -0.0008053426863625646, 0.00453804899007082, 0.013961615040898323, -0.011362654156982899, 0.008997260592877865, -0.033538706600666046, 0.012306565418839455, -0.0010244071017950773, -0.013969480991363525, -0.014597165398299694, -0.035297833383083344, -0.017306631430983543, -0.010778477415442467, -0.002570363227277994, -0.01993483304977417, -0.01895317994058132, -0.0020854149479418993, 0.025664806365966797, -0.0008710694964975119, 0.0039650024846196175, 0.03807724267244339, -0.005128238350152969, 0.013263728469610214, 0.005740152206271887, -0.020267421379685402, -0.0000995009031612426, 0.008078118786215782, 0.03470825031399727, -0.0028984444215893745, 0.023583196103572845, -0.7602574229240417, 0.016268055886030197, 0.0008513446082361042, -0.015474018640816212, 0.011250733397901058, 0.002829995471984148, -0.02255522459745407, -0.01723901741206646, -0.0011906560976058245, 0.014574352651834488, 0.011044308543205261, -0.004470699932426214, -0.00575960474088788, 0.014991892501711845, -0.03876379132270813, -0.019666990265250206, 0.010648524388670921, -0.010689781047403812, -0.0019070759881287813, -0.006867316551506519, 0.001603462966158986, -0.015080125071108341, 0.0031862726900726557, 0.029122930020093918, 0.02246466465294361, -0.0003609919804148376, 0.018894337117671967, -0.01067610364407301, -0.046517930924892426, 0.00895997229963541, 0.058107439428567886, -0.017807360738515854, 0.019854484125971794, -0.01811203360557556, 0.027494460344314575, 0.02984752506017685, 0.03627782687544823, -0.0033481440041214228, -0.016983311623334885, -0.0005779576022177935, 0.028269169852137566, -0.027217714115977287, -0.027873758226633072, -0.0499909333884716, -0.026667634025216103, 0.03416280448436737, -0.010268710553646088, -0.06782422214746475, 0.013663909398019314, 0.025636855512857437, -0.044386956840753555, 0.012340483255684376, 0.02768091857433319, -0.01854322850704193, 0.021611228585243225, 0.005683904979377985, 0.0037367313634604216, -0.025394631549715996, -0.001452017342671752, 0.004450891632586718, 0.024614054709672928, 0.01811296120285988, 0.004167245235294104, -0.001845206948928535, -0.05419179052114487, -0.0008880519890226424, 0.06358025968074799, -0.005192892160266638, -0.018529847264289856, 0.002245224080979824, -0.06883756816387177, 0.015398127026855946, -0.010172924026846886, 0.08361870795488358, -0.003928858321160078, -0.009196316823363304, -0.018369710072875023, -0.0036167388316243887, -0.04402604326605797, -0.012944646179676056, -0.015330503694713116, 0.015624739229679108, 0.005612785462290049, -0.019094888120889664, -0.0005614660331048071, -0.021866299211978912, -0.004385374952107668, -0.034465491771698, -0.00889463908970356, 0.010516035370528698, 0.01345013827085495, 0.026426052674651146, 0.0006979116587899625, -0.003860887372866273, -0.002673110691830516, 0.020596235990524292, -0.02682853490114212, 0.08563028275966644, 0.006820413284003735, -0.021627862006425858, -0.02350882813334465, 0.025234749540686607, -0.025314494967460632, 0.024001924321055412, -0.0361127071082592, -0.037733808159828186, 0.018038006499409676, -0.04299921169877052, 0.026423882693052292, -0.02578122913837433, 0.012201907113194466, -0.0181290153414011, -0.008844233117997646, 0.02280527725815773, 0.002643491607159376, -0.009415140375494957, -0.010949032381176949, -0.05225423350930214, 0.027885479852557182, -0.013082054443657398, -0.0302733164280653, -0.008424847386777401, -0.01429661549627781, 0.007233022712171078, 0.001817921525798738, 0.04016023874282837, -0.02136278711259365, -0.014257273636758327, 0.0033050812780857086, 0.017025381326675415, -0.014504608698189259, 0.00913163274526596, 0.00522252731025219, 0.005785465706139803, 0.008085298351943493, -0.005708388052880764, -0.029434774070978165, -0.010238604620099068, -0.01775233820080757, -0.03228139877319336, 0.012457042932510376, -0.013591439463198185, -0.020087074488401413, -0.045478854328393936, 0.01712583564221859, -0.02511722221970558, 0.01910414732992649, 0.0030989255756139755, -0.014702989719808102, -0.04951409250497818, 0.006181866396218538, 0.04363676533102989, 0.011586257256567478, -0.003082235809415579, -0.024248644709587097, 0.04003961756825447, -0.024954769760370255, -0.0019438080489635468, -0.0009069126099348068, 0.002916469471529126, 0.007880380377173424, -0.014566924422979355, -0.011534901335835457, 0.020142553374171257, 0.02870222181081772, 0.000028974711312912405, -0.010340247303247452, 0.025297872722148895, 0.0006913355318829417, 0.0038236763793975115, 0.027120206505060196, -0.009494339115917683, -0.0010279588168486953, 0.033901359885931015, -0.01985349878668785, 0.004245724994689226, 0.0013487497344613075, -0.056219056248664856, 0.003524798434227705, 0.012375200167298317, 0.021074678748846054, -0.007910262793302536, -0.025969332084059715, -0.014750647358596325, 0.012977149337530136, -0.006211230531334877, 0.0076071592047810555, 0.010660270228981972, 0.005623962730169296, -0.04626331478357315, -0.03171222656965256, 0.023527787998318672, -0.02064598724246025, -0.016544850543141365, -0.007314004469662905, -0.03623158857226372, -0.04039474576711655, 0.015078097581863403, 0.022106945514678955, -0.008909264579415321, -0.008446073159575462, 0.03246647119522095, 0.020555095747113228, 0.022265737876296043, 0.010245632380247116, 0.01540146954357624, -0.012589305639266968, -0.009858092293143272, -0.01804570108652115, 0.0011053001508116722, 0.027925636619329453, -0.02944176457822323, 0.028502075001597404, 0.03207259997725487, 0.0030725193209946156, 0.009657184593379498, 0.015311796218156815, -0.039335355162620544, 0.012336859479546547, -0.015014270320534706, -0.011669212020933628, -0.01929623633623123, -0.02118365839123726, -0.0077236187644302845, 0.0034520712215453386, 0.013243271969258785, -0.03480822592973709, -0.011420800350606441, -0.01616281270980835, -0.051159899681806564, -0.010330132208764553, -0.0139632448554039, 0.0066679916344583035, -0.0066110133193433285, -0.034713853150606155, 0.009809121489524841, -0.018733207136392593, -0.03130345791578293, -0.023966992273926735, -0.003359696362167597, 0.02588529884815216, -0.04275675490498543, -0.011402481235563755, 0.03945377841591835, 0.014380828477442265, -0.037617821246385574, 0.0005025935242883861, -0.023541303351521492, -0.026455221697688103, -0.022114424034953117, -0.05970996245741844, 0.034987982362508774, 0.04106120020151138, 0.008131258189678192, 0.01098774466663599, -0.014132436364889145, -0.0013655184302479029, 0.03437265008687973, -0.008070525713264942, 0.008135334588587284, 0.0025597948115319014, -0.020561056211590767, -0.016039038076996803, 0.032634783536195755, -0.017964031547307968, 0.0027228889521211386, -0.0006626429385505617, 0.007484218571335077, -0.012516668997704983, 0.03956466540694237, 0.013561202213168144, -0.02564913220703602, 0.02303609438240528, -0.002720668911933899, -0.03531773015856743, 0.008878647349774837, -0.013276706449687481, -0.007463499903678894, 0.015293591655790806, -0.01092028059065342, 0.002588002011179924, -0.015530135482549667, 0.04070591926574707, 0.022439317777752876, 0.040037013590335846, 0.017067404463887215, -0.0019975071772933006, 0.023656219244003296, -0.028229672461748123, -0.005581432953476906, 0.009912442415952682, -0.04476732015609741, 0.007056350354105234, 0.033435650169849396, -0.010559584014117718, 0.02275369130074978, -0.028515417128801346, 0.01492933090776205, 0.06234077364206314, -0.027960587292909622, 0.06261532008647919, -0.0049153403379023075, -0.021484151482582092, 0.007794225122779608, 0.018186232075095177, -0.004967155400663614, 0.010412788949906826, 0.020285168662667274, 0.027704117819666862, 0.013679456897079945, -0.01328431535512209, 0.025539161637425423, -0.00967735331505537, 0.005486099515110254, -0.01021235529333353, -0.011206215247511864, 0.036298368126153946, 0.01913418248295784, 0.0077361781150102615, -0.0011290587717667222, -0.003962365444749594, 0.04303112253546715, -0.0260721817612648, -0.031097467988729477, -0.023076588287949562, -0.041110727936029434, -0.021979833021759987, -0.02060556784272194, 0.0014675890561193228, 0.04200095683336258, 0.015786882489919662, -0.011332898400723934, -0.006028064526617527, -0.00873807817697525, 0.027279280126094818, 0.035318996757268906, -0.017053795978426933, 0.03092251718044281, 0.03048672527074814, -0.010051131248474121, 0.033106666058301926, 0.044331543147563934, -0.010479025542736053, -0.01764492318034172, 0.02664519101381302, 0.0017421969678252935, 0.041908711194992065, 0.016525007784366608, -0.024483846500515938, 0.02017350122332573, -0.02804577350616455, -0.024598676711320877, -0.005877109244465828, 0.005181596148759127, -0.013968801125884056, 0.00516122579574585, 0.03163188323378563, 0.022705795243382454, 0.028925437480211258, 0.0033879263792186975, 0.02042732574045658, 0.011240891180932522, 0.0006831431528553367, -0.011870677582919598, 0.0211318489164114, -0.012752356007695198, 0.023883556947112083, -0.006548011675477028, -0.022867070510983467, 0.009699822403490543, 0.011094431392848492, -0.0010537225753068924, 0.0020923083648085594, -0.019516080617904663, 0.045577503740787506, 0.013498191721737385, 0.025486575439572334, 0.02892400696873665, -0.00026025352417491376, -0.00406723702326417, -0.02450411580502987, -0.0008476831717416644, 0.022411679849028587, 0.041055452078580856, 0.029470646753907204, -0.05031226575374603, -0.009612211026251316, -0.0019212366314604878, -0.0032748456578701735, -0.013907020911574364, -0.025711268186569214, 0.012554739601910114, 0.03732212260365486, 0.02653719112277031, 0.011805584654211998, 0.005510005634278059, -0.0003219399368390441, -0.00427815830335021, -0.02106407657265663, -0.019994622096419334, -0.03965798765420914, -0.007468196097761393, 0.0064657689072191715, -0.01754315197467804, -0.005586586426943541, -0.014312630519270897, -0.0136692114174366, -0.008100306615233421, 0.017316551879048347, -0.03181463107466698, 0.015510146506130695, 0.028326604515314102, -0.04223347455263138, -0.0023924431297928095, -0.005607182160019875, 0.01068651769310236, -0.0008972467621788383, -0.011597051285207272, 0.011158986948430538, 0.010089953429996967, 0.0011548898182809353, -0.016919627785682678, 0.0037729847244918346, 0.0010735109681263566, -0.026875117793679237, -0.004103865008801222, 0.03283516690135002, -0.042184051126241684, 0.013260887004435062, 0.020079340785741806, -0.0093180350959301, -0.014383702538907528, -0.025013498961925507, 0.00732217775657773, 0.018296964466571808, -0.003555107628926635, -0.012819572351872921, 0.026945935562253, -0.02290952391922474, -0.023484360426664352, 0.011224835179746151, -0.012710195034742355, 0.01310415007174015, -0.007651935797184706, 0.025116128847002983, 0.03359832987189293, 0.008372151292860508, 0.0011417465284466743, -0.01125970110297203, 0.02194921486079693, -0.03855244815349579, 0.014386143535375595, 0.012631811201572418, -0.029373228549957275, 0.017866838723421097, 0.025055335834622383, 0.031734999269247055, 0.0187227800488472, 0.03682336583733559, 0.016000501811504364, 0.002968402812257409, -0.0012166020460426807, -0.05120116099715233, -0.02227438986301422, 0.020195897668600082, 0.035353150218725204, -0.008035094477236271, 0.01741993986070156, -0.029828570783138275, -0.008970586583018303, 0.006083381362259388, 0.00023814851010683924, -0.014184453524649143, 0.02123880200088024, -0.008552074432373047, -0.01353281270712614, 0.020883098244667053, 0.016913823783397675, 0.003219703445211053, 0.052424997091293335, -0.009716148488223553, 0.04544460028409958, 0.007066831924021244, 0.018928684294223785, -0.010187595151364803, 0.03567556291818619, -0.012163174338638783, 0.03140486031770706, -0.011246543377637863, -0.0008641426102258265, -0.02094884403049946, -0.024406440556049347, -0.04259376600384712, 0.021371496841311455, 0.0033847636077553034, -0.020810851827263832, 0.007258809171617031, 0.006273645907640457, -0.01266551110893488, 0.01441275142133236, 0.044682785868644714, -0.03053215704858303, -0.0082106227055192, -0.002515148837119341, 0.020476190373301506, -0.00953354500234127, 0.008370178751647472, 0.012733209878206253, -0.007693780120462179, 0.02878546714782715, -0.019107304513454437, -0.01892276480793953, -0.017126526683568954, -0.02938932366669178, 0.015557350590825081, -0.0016237725503742695, -0.012570207938551903, -0.07062384486198425, 0.03230355679988861, 0.02582654170691967, 0.014720981009304523, 0.026576939970254898, 0.02051743119955063, -0.02948506735265255, -0.012843764387071133, 0.0038720553275197744, -0.008516130968928337, -0.009006348438560963, 0.005985647439956665, 0.025943046435713768, -0.008177888579666615, 0.00797177292406559, -0.021264871582388878, -0.024703804403543472, 0.03057226724922657, -0.019537562504410744, -0.006560301873832941, 0.03325384110212326, -0.01637694239616394, -0.020946653559803963, 0.005889568477869034, 0.008334110490977764, -0.00016512756701558828, -0.007574213203042746, -0.0014428648864850402, 0.022074436768889427, -0.026203572750091553, 0.007600695826113224, 0.030508995056152344, -0.025113053619861603, 0.0010575628839433193, 0.0011878785444423556, 0.0031681936234235764, -0.024771798402071, -0.008310106582939625, -0.002793670864775777, 0.005982781294733286, 0.03059922344982624, -0.011284115724265575, -0.05269553139805794, -0.011391271837055683, -0.007661467883735895 ]
8a9f03cac960929d8e8a292c8e92367e90e1a3eb
7,311
py
Python
storm_control/sc_library/log_timing.py
jeffmoffitt/storm-control
522add1e196e0b7964f574481fd90c20a74b575e
[ "MIT" ]
null
null
null
storm_control/sc_library/log_timing.py
jeffmoffitt/storm-control
522add1e196e0b7964f574481fd90c20a74b575e
[ "MIT" ]
null
null
null
storm_control/sc_library/log_timing.py
jeffmoffitt/storm-control
522add1e196e0b7964f574481fd90c20a74b575e
[ "MIT" ]
1
2020-11-10T06:39:18.000Z
2020-11-10T06:39:18.000Z
#!/usr/bin/env python """ This parses a log file series (i.e. log, log.1, log.2, etc..) and outputs timing and call frequency information for HAL messages. Hazen 5/18 """ from datetime import datetime import os pattern = '%Y-%m-%d %H:%M:%S,%f' class Message(object): """ Storage for the timing of a single message. """ def __init__(self, m_type = None, source = None, time = None, zero_time = None, **kwds): super().__init__(**kwds) self.created_time = None self.m_type = m_type self.n_workers = 0 self.processing_time = None self.queued_time = None self.source = source self.temp = self.parseTime(time) self.created(zero_time) def created(self, time): t_time = self.parseTime(time) self.created_time = (self.temp - t_time).total_seconds() def getCreatedTime(self): """ Returns the time when the message was created relative to first time in the log file in seconds. """ return self.created_time def getNWorkers(self): """ Return the number of workers (QRunnables) that were employed to process this message. """ return self.n_workers def getProcessingTime(self): """ Return time to process in seconds. """ return self.processing_time def getQueuedTime(self): """ Return time queued in seconds. """ return self.queued_time def getSource(self): """ Returns the source of a message. """ return self.source def getType(self): """ Return the message type. """ return self.m_type def incNWorkers(self): self.n_workers += 1 def isComplete(self): """ Returns true if we have all the timing data for this message. """ return (self.processing_time != None) def parseTime(self, time): return datetime.strptime(time, pattern) def processed(self, time): t_time = self.parseTime(time) self.processing_time = (t_time - self.temp).total_seconds() def sent(self, time): t_time = self.parseTime(time) self.queued_time = (t_time - self.temp).total_seconds() self.temp = t_time def getIterable(dict_or_list): """ Returns an iterable given a dictionary of a list. """ if isinstance(dict_or_list, dict): iterable = list(dict_or_list.values()) elif isinstance(dict_or_list, list): iterable = dict_or_list else: raise Exception("Unknown type '" + str(type(dict_or_list)) + "'") return iterable def groupByMsgType(messages): """ Returns a dictionary keyed by message type, with a list of one or more message objects per message type. """ return groupByX(lambda x : x.getType(), messages) def groupBySource(messages): """ Returns a dictionary keyed by message source, with a list of one or more message objects per message source. """ return groupByX(lambda x : x.getSource(), messages) def groupByX(grp_fn, messages): """ Returns a dictionary keyed by the requested group. """ m_grp = {} for msg in getIterable(messages): # Ignore messages that we don't have all the timing for. if msg.isComplete() or not ignore_incomplete: m_type = grp_fn(msg) if m_type in m_grp: m_grp[m_type].append(msg) else: m_grp[m_type] = [msg] return m_grp def logTiming(basename, ignore_incomplete = False): """ Returns a dictionary of Message objects keyed by their ID number. """ zero_time = None messages = {} for ext in [".5", ".4", ".3", ".2", ".1", ""]: fname = basename + ".out" + ext if not os.path.exists(fname): print(fname, "not found.") continue with open(fname) as fp: for line in fp: try: [time, command] = map(lambda x: x.strip(), line.split(":hal4000:INFO:")) except ValueError: continue if zero_time is None: zero_time = time # Message queued. if (command.startswith("queued,")): [m_id, source, m_type] = command.split(",")[1:] messages[m_id] = Message(m_type = m_type, source = source, time = time, zero_time = zero_time) # Message sent. elif (command.startswith("sent,")): m_id = command.split(",")[1] messages[m_id].sent(time) # Message processed. elif (command.startswith("processed,")): m_id = command.split(",")[1] messages[m_id].processed(time) elif (command.startswith("worker done,")): m_id = command.split(",")[1] messages[m_id].incNWorkers() # Ignore messages that we don't have all the timing for. if not ignore_incomplete: temp = {} for m_id in messages: msg = messages[m_id] if msg.isComplete(): temp[m_id] = msg return temp else: return messages def processingTime(messages): """ Returns the total processing time for a collection of messages. """ accum_time = 0 for msg in getIterable(messages): if isinstance(msg, list): for elt in msg: accum_time += elt.getProcessingTime() else: accum_time += msg.getProcessingTime() return accum_time def queuedTime(messages): """ Returns the total queued time for a a collection of messages. """ accum_time = 0 for msg in getIterable(messages): if isinstance(msg, list): for elt in msg: accum_time += elt.getQueuedTime() else: accum_time += msg.getQueuedTime() return accum_time if (__name__ == "__main__"): import sys if (len(sys.argv) != 2): print("usage: <log file>") exit() messages = logTiming(sys.argv[1]) groups = groupByMsgType(messages) print() print("All messages:") for key in sorted(groups): grp = groups[key] print(key + ", {0:0d} counts, {1:.3f} seconds".format(len(grp), processingTime(grp))) print("Total queued time {0:.3f} seconds".format(queuedTime(groups))) print("Total processing time {0:.3f} seconds".format(processingTime(groups))) print() print("Film messages:") groups = groupByMsgType(groupBySource(messages)["film"]) for key in sorted(groups): grp = groups[key] print(key + ", {0:0d} counts, {1:.3f} seconds".format(len(grp), processingTime(grp))) print("Total processing time {0:.3f} seconds".format(processingTime(groups)))
27.90458
93
0.548078
0
0
[ 0.0034869497176259756, 0.036005664616823196, 0.011898159049451351, -0.016864189878106117, 0.012205672450363636, 0.009113496169447899, 0.0024385000579059124, 0.0008436350617557764, 0.043118055909872055, -0.023123402148485184, 0.0031706057488918304, 0.00868245866149664, 0.032408565282821655, 0.06198345869779587, 0.0061035966500639915, -0.006574823055416346, 0.17882190644741058, -0.041843801736831665, -0.00516954530030489, 0.044260136783123016, 0.008679318241775036, 0.03063262440264225, -0.006639417726546526, -0.00015134863497223705, 0.006048901472240686, 0.02235313318669796, 0.03767331317067146, 0.028148233890533447, -0.018672306090593338, -0.02550945058465004, 0.027813751250505447, -0.038010526448488235, -0.0052909464575350285, 0.021237537264823914, -0.01977895200252533, -0.02861330844461918, -0.009542168118059635, -0.07915747910737991, 0.016276901587843895, -0.03445485979318619, -0.0058244746178388596, -0.043599631637334824, -0.023912180215120316, 0.013075003400444984, 0.04040161147713661, 0.013955499045550823, 0.009427530691027641, -0.044413115829229355, -0.016175832599401474, 0.01832856424152851, 0.015168353915214539, 0.010062836110591888, 0.0002690119727049023, -0.03889581561088562, 0.015679745003581047, 0.0006632422446273267, 0.023151900619268417, -0.016848493367433548, -0.010923679918050766, 0.0029557328671216965, 0.02082156017422676, 0.003700589295476675, -0.005704135168343782, -0.009338297881186008, 0.007625298574566841, -0.03326192498207092, 0.0019008564995601773, 0.009733572602272034, 0.09181905537843704, 0.03117677941918373, -0.027364473789930344, 0.004835663363337517, 0.02584153786301613, 0.031709566712379456, 0.0010923922527581453, 0.01780768483877182, -0.010964307934045792, 0.0007019058102741838, -0.018518203869462013, -0.0492468997836113, -0.03932753950357437, 0.015967130661010742, 0.03293481096625328, -0.023192984983325005, 0.001448400435037911, -0.037073660641908646, 0.03578560799360275, -0.04931938275694847, 0.04909776896238327, 0.0011690445244312286, 0.003952797967940569, -0.0015983055345714092, -0.0409046970307827, -0.032562006264925, 0.008578198961913586, -0.0410473570227623, 0.02120402082800865, -0.004625512287020683, -0.01519417017698288, 0.005699676461517811, 0.007578386925160885, -0.04208088666200638, 0.026183772832155228, 0.007528725545853376, 0.010957176797091961, 0.00673199538141489, -0.04036179184913635, 0.01669706217944622, 0.003270269138738513, -0.0012504420010372996, -0.04133474826812744, 0.0013189776800572872, -0.02135402336716652, 0.0013833610573783517, -0.009555403143167496, 0.03625309839844704, 0.04387148469686508, 0.01563703827559948, 0.03298212215304375, -0.027923576533794403, -0.037027593702077866, 0.025113943964242935, 0.01714266836643219, -0.020857179537415504, -0.01608217880129814, 0.028503449633717537, -0.006185614038258791, 0.01812777854502201, -0.0027686087414622307, -0.011423056945204735, -0.01596764288842678, 0.02465158887207508, -0.018200162798166275, -0.013902074657380581, 0.0005975822568871081, -0.0009303390397690237, 0.024605806916952133, 0.021898925304412842, -0.0020805655512958765, -0.043931614607572556, -0.004193977452814579, -0.018386395648121834, 0.010659332387149334, 0.003713904181495309, 0.01739722676575184, 0.005587550811469555, -0.016177203506231308, 0.04891310632228851, -0.00881489459425211, 0.006335023324936628, 0.009638799354434013, -0.003565774532034993, 0.016262007877230644, -0.002019569743424654, -0.013787195086479187, -0.011331861838698387, 0.007314002141356468, -0.03617281839251518, -0.02710593305528164, 0.010982719250023365, -0.03490597754716873, 0.0068598962388932705, 0.038048043847084045, 0.02690773829817772, 0.014682048000395298, -0.008691957220435143, -0.025613347068428993, -0.013082391582429409, -0.021305296570062637, -0.017220817506313324, -0.003490196308121085, -0.004537187051028013, -0.005877023562788963, 0.022411683574318886, -0.03746350482106209, 0.00950535200536251, -0.021170884370803833, 0.025006959214806557, -0.018753794953227043, -0.04032111540436745, -0.00938737578690052, -0.03469619154930115, -0.008080610074102879, 0.007027396932244301, -0.01490064151585102, -0.04143593832850456, -0.020210621878504753, -0.023933855816721916, 0.020813988521695137, -0.002528053941205144, 0.007287243846803904, 0.003631370374932885, 0.0022153076715767384, -0.009090034291148186, -0.002263841684907675, -0.022391289472579956, -0.0022904258221387863, -0.010668276809155941, -0.026653770357370377, 0.02007312700152397, 0.015086561441421509, -0.024876665323972702, 0.033032648265361786, 0.04538676515221596, 0.0033155314158648252, 0.033162523061037064, -0.7194864153862, 0.0005803082603961229, -0.006826215889304876, 0.010580985806882381, -0.007297252304852009, 0.009788398630917072, 0.012574958615005016, 0.007692120969295502, 0.017861327156424522, -0.030564237385988235, -0.000847400922793895, 0.02276277355849743, -0.008181378245353699, 0.03029244765639305, -0.004321563523262739, -0.015564946457743645, -0.003580298740416765, -0.012406503781676292, 0.02610502578318119, -0.014476756565272808, -0.0069857812486588955, 0.023717643693089485, -0.04535191133618355, -0.012310904450714588, 0.02782062441110611, -0.025337086990475655, -0.030707916244864464, 0.013447190634906292, 0.04575282335281372, 0.01577153429389, -0.03560027852654457, 0.012550131417810917, 0.0015826532617211342, -0.013705141842365265, -0.003611497115343809, 0.002059869933873415, 0.0020560570992529392, 0.021521247923374176, -0.012274017557501793, -0.016119888052344322, -0.00037723660352639854, 0.014981593936681747, -0.023747438564896584, -0.04495931416749954, -0.006997972261160612, -0.005409434903413057, 0.008029665797948837, -0.004030255135148764, -0.014258041977882385, -0.004978965036571026, 0.027743173763155937, -0.004593309480696917, 0.0509912483394146, 0.006466723047196865, 0.019368954002857208, -0.006162668578326702, 0.019055116921663284, -0.009714812971651554, -0.005181560758501291, 0.017007574439048767, 0.03114977478981018, 0.033743616193532944, -0.003739455249160528, -0.0036401450634002686, -0.05387904495000839, -0.028328029438853264, 0.020829303190112114, -0.03791755437850952, 0.027254924178123474, 0.015811868011951447, -0.023526372388005257, -0.008387718349695206, -0.0017066622385755181, 0.007721281144768, -0.012700009159743786, 0.04553458094596863, -0.009043987840414047, 0.010044064372777939, 0.0022245733998715878, -0.013657359406352043, -0.028476476669311523, -0.06385505199432373, 0.021761542186141014, 0.00537920044735074, 0.0023193228989839554, 0.019755255430936813, 0.004444337449967861, 0.0064783557318151, 0.007010222878307104, 0.030476612970232964, -0.020767075940966606, -0.030522935092449188, 0.014158893376588821, 0.021389449015259743, 0.015315533615648746, 0.04715379327535629, 0.030221858993172646, 0.027893204241991043, 0.008648884482681751, 0.022231290116906166, -0.01791166327893734, 0.04657931253314018, 0.03140861168503761, 0.02693622186779976, -0.07723928242921829, -0.02035278081893921, 0.008580703288316727, -0.02808338962495327, -0.014519019983708858, -0.028152067214250565, 0.02376786805689335, -0.0053648375906050205, 0.010466407984495163, 0.0005968138575553894, -0.009167601354420185, 0.02777952142059803, -0.007974925450980663, -0.018248844891786575, -0.011055534705519676, 0.01889917626976967, 0.012319958768785, 0.012087044306099415, 0.041069578379392624, 0.03573252633213997, -0.024595890194177628, -0.022724173963069916, 0.025847984477877617, -0.0142044173553586, -0.0008218716247938573, -0.005439478438347578, -0.009555315598845482, 0.0186100322753191, 0.005736382212489843, 0.016325319185853004, -0.027495739981532097, 0.009657816030085087, 0.008004941046237946, -0.011493470519781113, -0.006896967999637127, -0.01938808709383011, 0.010678325779736042, 0.031935859471559525, 0.021880749613046646, -0.01385304145514965, 0.016903791576623917, -0.000040493381675332785, -0.00537984911352396, 0.0316598117351532, 0.03956495225429535, -0.08112792670726776, -0.013444323092699051, 0.026062479242682457, 0.04229150712490082, 0.03951912373304367, -0.037430714815855026, 0.0013320297002792358, -0.014209776185452938, 0.006208622828125954, 0.01854036934673786, -0.0028263272251933813, 0.001347508281469345, -0.01894858293235302, 0.02102847769856453, 0.05463789030909538, -0.011841287836432457, 0.0184318870306015, -0.0007676837267354131, -0.013269905000925064, -0.04359043389558792, 0.0023106031585484743, -0.007227731868624687, -0.04276008903980255, -0.034790441393852234, 0.03799617290496826, 0.019555408507585526, -0.03199857473373413, -0.00496632419526577, 0.032993730157613754, -0.016816308721899986, 0.016334446147084236, -0.01169454213231802, 0.007329676300287247, -0.015923038125038147, 0.02153094857931137, 0.023050712421536446, 0.035286277532577515, -0.02209368906915188, -0.01889096200466156, 0.0071474784053862095, 0.00853643473237753, 0.022042881697416306, 0.054206594824790955, -0.018752029165625572, 0.05959710478782654, -0.01810975931584835, 0.007152544800192118, -0.021312428638339043, -0.030405782163143158, 0.024086592718958855, -0.03432275727391243, -0.023321259766817093, 0.008371717296540737, -0.009255882352590561, -0.018652155995368958, 0.013793038204312325, -0.017984068021178246, -0.004959425423294306, -0.001165098394267261, -0.03629162907600403, -0.03803669288754463, -0.0289724413305521, -0.040191393345594406, -0.01856383867561817, 0.02272806130349636, 0.01351996697485447, 0.003416270250454545, -0.010162346996366978, 0.023925893008708954, -0.018552282825112343, -0.0002817294152919203, -0.03392503410577774, -0.0543605238199234, -0.012066737748682499, -0.018616480752825737, -0.02056361921131611, -0.043244775384664536, 0.034708961844444275, 0.03284049034118652, 0.0038195112720131874, -0.011409694328904152, 0.001315423403866589, -0.016034966334700584, 0.00042348282295279205, 0.03674600273370743, 0.009182672016322613, 0.029581133276224136, -0.004906071349978447, -0.002872123848646879, 0.0007859282195568085, -0.013459241949021816, 0.02177441492676735, -0.06220535188913345, 0.025433078408241272, -0.010025812312960625, 0.006569346413016319, 0.008526049554347992, -0.025937959551811218, -0.011480339802801609, -0.0197541993111372, -0.009816097095608711, -0.0210944265127182, -0.002934160176664591, 0.005022426135838032, -0.04079755023121834, 0.0025297824759036303, 0.053885944187641144, -0.008457615040242672, -0.011632733978331089, 0.021917495876550674, -0.013857264071702957, -0.013895201496779919, 0.044652059674263, 0.0048223379999399185, -0.0006746616563759744, 0.01908951811492443, -0.0017421640222892165, -0.009111198596656322, 0.03146779537200928, -0.02041074074804783, 0.04882609099149704, 0.0313386507332325, 0.02052656188607216, -0.03516172990202904, -0.018373465165495872, 0.0003131905396003276, -0.01733076386153698, 0.01174181792885065, -0.008608533069491386, -0.022603251039981842, 0.009807910770177841, -0.01457065250724554, -0.011287074536085129, 0.018708577379584312, 0.022740870714187622, -0.02215181291103363, 0.013011325150728226, 0.0051118419505655766, 0.03849043324589729, -0.008665630593895912, -0.015320382080972195, -0.0294001754373312, -0.03303511068224907, -0.003293723799288273, -0.013607016764581203, 0.019145065918564796, -0.0016676678787916899, -0.0020858130883425474, -0.032348766922950745, 0.007732377387583256, 0.006223512813448906, 0.00851075816899538, -0.011777063831686974, -0.017559200525283813, -0.024323908612132072, 0.033458463847637177, -0.003675017971545458, -0.010785957798361778, -0.0026846015825867653, 0.020634522661566734, -0.03910527378320694, 0.016111761331558228, 0.03276929631829262, -0.0007615077192895114, 0.0010108407586812973, -0.007417004555463791, -0.0072664013132452965, 0.013664375990629196, -0.028456727042794228, 0.015747373923659325, -0.023382369428873062, -0.0004201967967674136, 0.0007406018557958305, -0.04339178279042244, -0.01361377164721489, 0.019517140462994576, 0.007365914527326822, 0.009905458427965641, 0.014646508730947971, -0.024426009505987167, -0.014307050965726376, -0.008659597486257553, -0.009140168316662312, 0.03327428922057152, 0.002537117339670658, -0.03089584782719612, 0.022075220942497253, 0.007114960812032223, 0.046652041375637054, -0.03945779427886009, -0.0004818773304577917, -0.0024529893416911364, 0.032743457704782486, -0.06876402348279953, 0.02301666885614395, -0.00005102483191876672, -0.037617962807416916, 0.019582156091928482, 0.0707409530878067, -0.05433834344148636, -0.012048272415995598, 0.06070307642221451, -0.022249536588788033, -0.01844784803688526, 0.024775734171271324, -0.005157891195267439, -0.003995236940681934, 0.03225057199597359, -0.00013180269161239266, 0.0008552488870918751, -0.00997399352490902, -0.015063775703310966, -0.027406664565205574, -0.02734006755053997, 0.0031202775426208973, -0.03839486092329025, -0.06348653882741928, 0.022008471190929413, 0.010901800356805325, 0.020515847951173782, 0.027433184906840324, 0.016123274341225624, -0.020390614867210388, 0.020574277266860008, -0.017452465370297432, -0.016009708866477013, -0.0022111686412245035, 0.04354614391922951, 0.040556542575359344, 0.019868532195687294, -0.03341013938188553, 0.006003712769597769, 0.001671214704401791, 0.026580873876810074, -0.017446298152208328, 0.023362142965197563, -0.0384691022336483, -0.013042551465332508, 0.0041227200999855995, -0.014893014915287495, -0.0433579720556736, 0.002717746887356043, -0.0043882946483790874, 0.0072932071052491665, -0.01219342090189457, -0.018830034881830215, -0.014001080766320229, 0.007744450122117996, 0.027388932183384895, 0.0007499702041968703, 0.012910261750221252, 0.05905131623148918, -0.08133365213871002, 0.006126112304627895, -0.018630973994731903, 0.0015132732223719358, -0.018520373851060867, -0.0019325955072417855, -0.008145392872393131, 0.030106013640761375, 0.024622183293104172, 0.04500214383006096, 0.0022744808811694384, -0.027819236740469933, 0.024078909307718277, 0.04938846826553345, 0.0075465901754796505, -0.013769780285656452, -0.010717988945543766, -0.015778010711073875, 0.009459225460886955, 0.010208956897258759, 0.0023162970319390297, -0.01584206148982048, -0.027775486931204796, 0.0259763952344656, -0.014467076398432255, 0.038868967443704605, 0.004423278383910656, -0.05041930824518204, -0.013875944539904594, -0.021344542503356934, -0.020099028944969177, -0.03405916318297386, 0.017736660316586494, 0.030794810503721237, -0.005499724764376879, 0.004306043963879347, -0.027232332155108452, -0.028826437890529633, 0.017943212762475014, -0.018965866416692734, -0.0030908517073839903, -0.014159630984067917, 0.023987947031855583, -0.019565382972359657, -0.09134051948785782, 0.02877303957939148, 0.034694038331508636, 0.004542363341897726, -0.026559459045529366, -0.03240605816245079, -0.004919066093862057, -0.01234190072864294, 0.017123838886618614, -0.0038221220020204782, -0.00871918722987175, -0.0072799380868673325, 0.00978048238903284, 0.03466872125864029, -0.006320670712739229, -0.012481524609029293, 0.018544835969805717, 0.029884282499551773, 0.01885099895298481, -0.03416135162115097, -0.03670923784375191, 0.009143036790192127, 0.01782585307955742, -0.04692276939749718, 0.031015286222100258, 0.006168212275952101, -0.004048887174576521, -0.030838381499052048, 0.025419369339942932, -0.025751756504178047, 0.013784320093691349, -0.003736516460776329, -0.01461826916784048, 0.03445518761873245, 0.03613712266087532, 0.002642348175868392, -0.021765153855085373, 0.02370641753077507, -0.01660146564245224, 0.00973249040544033, -0.023513205349445343, 0.02016410045325756, -0.03621983900666237, 0.015984203666448593, 0.013140501454472542, 0.012685487046837807, -0.0011347390245646238, 0.022723905742168427, -0.004700816236436367, 0.04410911351442337, -0.014845299534499645, 0.014990109950304031, -0.008371160365641117, 0.010698650032281876, -0.004986925981938839, 0.007562420796602964, 0.010167503729462624, 0.029117800295352936, 0.02110588550567627, 0.01771024987101555, 0.017888089641928673, 0.017892764881253242, 0.0258481502532959, 0.0011773227015510201, -0.012851505540311337, -0.0126498406752944, 0.013356698676943779, 0.004002113360911608, -0.0030580719467252493, 0.002020119223743677, 0.002993593690916896, 0.0029455225449055433, -0.010422797873616219, 0.019814522936940193, -0.011783779598772526, 0.008784942328929901, 0.03629495948553085, -0.01837228424847126, -0.019155871123075485, -0.032293565571308136, -0.027719693258404732, -0.001640403177589178, -0.06281201541423798, -0.04100585728883743, 0.007879688404500484, -0.0009755126666277647, -0.0091076185926795, -0.03435033559799194, -0.016779348254203796, 0.0067377351224422455, 0.002164730802178383, 0.06686832010746002, -0.01403613481670618, -0.020153749734163284, -0.02055925875902176, 0.006544971372932196, 0.021493563428521156, 0.0009579651523381472, -0.0338340662419796, -0.00017112225759774446, -0.009154233150184155, -0.030859334394335747, 0.003995684906840324, 0.012054367922246456, -0.006705279927700758, 0.004419730510562658, -0.023666497319936752, 0.003849442582577467, 0.0026255883276462555, -0.035797227174043655, -0.031499527394771576, 0.04690465331077576, -0.0005047491285949945, 0.01703428477048874, -0.011493339203298092, -0.03044075332581997, -0.006342027336359024 ]
8a9f1f85d541893b6f50e7a4580e2b294f4022fb
1,830
py
Python
django_simple_jsonschema/management/commands/check_schema.py
38elements/django-simple-jsonschema
ab08aaa3453c40a41d443869643113f23eb40db6
[ "MIT" ]
1
2017-04-27T20:15:46.000Z
2017-04-27T20:15:46.000Z
django_simple_jsonschema/management/commands/check_schema.py
38elements/django-simple-jsonschema
ab08aaa3453c40a41d443869643113f23eb40db6
[ "MIT" ]
null
null
null
django_simple_jsonschema/management/commands/check_schema.py
38elements/django-simple-jsonschema
ab08aaa3453c40a41d443869643113f23eb40db6
[ "MIT" ]
2
2016-02-20T10:53:09.000Z
2018-07-12T14:47:01.000Z
from django.core.management.base import BaseCommand from django.utils import termcolors from jsonschema import Draft4Validator from jsonschema.exceptions import SchemaError import json class Command(BaseCommand): can_import_settings = True @property def _jsonschema_exist(self): from django.conf import settings if not hasattr(settings, 'SIMPLE_JSONSCHEMA'): return False return True @property def _jsonschema_errors(self): from django.conf import settings errors = [] schemas = settings.SIMPLE_JSONSCHEMA for url, schema in schemas.items(): try: Draft4Validator.check_schema(schema) except SchemaError as e: errors.append({ 'url': url, 'error': e, 'schema': json.dumps(schema, indent=4, sort_keys=True) }) return errors def handle(self, *args, **options): success = termcolors.make_style(fg='green') error = termcolors.make_style(fg='red') if not self._jsonschema_exist: not_exist = '[' + error('ERROR') + '] SIMPLE_JSONSCHEMA is not exist in settings.' self.stdout.write(not_exist) return errors = self._jsonschema_errors if len(errors): for e in errors: title = '\n[' + error('ERROR') + '] schema of ' + str(e['url']) + ' is invalid.' self.stdout.write(title) self.stdout.write('path: ' + str(list(e['error'].path))) self.stdout.write('message: ' + e['error'].message) self.stdout.write('schema:\n' + e['schema'] + '\n') else: self.stdout.write('[' + success('SUCCESS') + '] All jsonschemas are OK.')
35.192308
96
0.572678
1
1.2006
[ 0.0028060090262442827, 0.02454313263297081, 0.00951792486011982, 0.0007946153054945171, 0.0045077865943312645, -0.0020926452707499266, -0.009212099947035313, 0.0035273742396384478, -0.007866662926971912, 0.004559053108096123, 0.002625318942591548, 0.005944147706031799, 0.005477373953908682, -0.01593318209052086, 0.0020178041886538267, 0.016926096752285957, -0.05033507198095322, 0.0004283682501409203, -0.003847538260743022, 0.0021133366972208023, -0.006590625736862421, 0.009724116884171963, 0.009892621077597141, 0.00672971410676837, 0.005997756961733103, -0.0011092311469838023, 0.00906028039753437, 0.0015474118990823627, -0.006279890891164541, -0.0073643275536596775, -0.0016896951710805297, -0.0031344022136181593, -0.00571004394441843, -0.005928658880293369, 0.00633415300399065, -0.004121458623558283, -0.0013147814897820354, -0.02150622010231018, 0.010977239347994328, -0.004192799795418978, -0.0092317508533597, -0.018835321068763733, -0.002168841427192092, 0.004345024935901165, -0.009404933080077171, 0.0026549759786576033, -0.004549182485789061, 0.0024000753182917833, -0.010267152450978756, 0.00675192242488265, -0.009489917196333408, 0.004539459943771362, 0.014513671398162842, 0.005512790288776159, -0.005000704899430275, -0.007589124608784914, 0.012335614301264286, -0.0005571286892518401, -0.010922539979219437, -0.0012692370219156146, -0.003775252029299736, -0.002335889497771859, 0.006121685262769461, 0.0019388459622859955, -0.015757309272885323, -0.007310198154300451, -0.005790347699075937, 0.0033424391876906157, 0.0004839160246774554, 0.0064666797406971455, 0.0015334124909713864, -0.002929402282461524, 0.007259984500706196, 0.0037700177635997534, 0.004554280079901218, -0.004588382784277201, 0.0005068093305453658, 0.0017407635459676385, 0.008890683762729168, 0.004494077991694212, 0.004176554270088673, -0.007409506943076849, 0.006666138768196106, 0.007854590192437172, 0.01213209517300129, 0.006788461934775114, 0.022010426968336105, -0.009377381764352322, 0.04619777947664261, 0.007273655850440264, -0.008824385702610016, 0.0024038038682192564, -0.007146680261939764, -0.0013460777699947357, -0.0046274540945887566, -0.028243882581591606, -0.0014835142064839602, -0.0024215332232415676, -0.00026090905885212123, 0.0032077378127723932, -0.0004010759002994746, 0.0050899735651910305, -0.0021520969457924366, -0.0020317332819104195, -0.011293959803879261, 0.011582141742110252, -0.010690112598240376, -0.0037780054844915867, 0.005312956403940916, 0.003042415017262101, -0.011111323721706867, -0.00025911329430527985, 0.002229065401479602, -0.01277510542422533, 0.00553502282127738, 0.002421335317194462, -0.00558230746537447, 0.05371859297156334, -0.0007826596847735345, 0.003979896195232868, -0.00547104561701417, 0.00248679774813354, 0.0013347206404432654, 0.005536854267120361, 0.008596176281571388, -0.0034528847318142653, 0.012155708856880665, 0.009376805275678635, 0.003661906812340021, 0.008790092542767525, -0.004905068781226873, 0.008166412822902203, -0.0048281000927090645, -0.002785240299999714, 0.0015140611212700605, -0.008372296579182148, 0.007823431864380836, -0.0024569747038185596, -0.007784068118780851, 0.002188190585002303, -0.00014671060489490628, -0.01042969897389412, 0.0014028145233169198, -0.0030965826008468866, 0.004503492731601, -0.00943493377417326, -0.003216594224795699, -0.0019198379013687372, -0.004327467642724514, 0.0029622872825711966, 0.010625834576785564, 0.004838324151933193, 0.003017570124939084, -0.003961082547903061, -0.008285664021968842, 0.0011868809815496206, -0.005107116885483265, 0.0017780588241294026, 0.006032606586813927, 0.00470092985779047, -0.011436469852924347, -0.0010519232600927353, 0.003174052806571126, 0.004255885258316994, -0.001302365679293871, 0.002932977629825473, -0.008048677816987038, 0.007645028177648783, 0.0007732573430985212, 0.0039902799762785435, 0.010892599821090698, -0.006355870049446821, -0.0010810891399160028, -0.0003751015174202621, 0.00487702339887619, -0.0010614123893901706, 0.005924159195274115, 0.010238305665552616, -0.005929028149694204, -0.004609348718076944, 0.003912477288395166, 0.005851515103131533, 0.008252955973148346, 0.005519889760762453, -0.0017588981427252293, 0.0016958544729277492, -0.003980464302003384, -0.0017576332902535796, 0.006614030338823795, -0.004538760986179113, 0.00547752296552062, 0.004762827418744564, -0.014276870526373386, -0.007350845728069544, 0.0014793041627854109, -0.008874351158738136, 0.0018318938091397285, 0.014850964769721031, 0.01075380016118288, -0.0027580885216593742, 0.0027400122489780188, -0.01050387043505907, 0.000465720659121871, 0.005483221262693405, 0.002809243043884635, -0.011324218474328518, -0.9584547281265259, 0.006099876947700977, 0.0030673141591250896, -0.0005578363197855651, 0.005791814997792244, 0.002581617096439004, 0.004401012789458036, 0.004961536265909672, 0.014684014022350311, -0.009960886090993881, -0.0053950208239257336, -0.010018731467425823, -0.009459110908210278, -0.002756953937932849, -0.008018754422664642, -0.0028461397159844637, -0.00702340342104435, -0.005367968697100878, -0.002817247062921524, -0.004918381106108427, -0.002333190990611911, 0.009061446413397789, 0.0005301344208419323, 0.004763837903738022, 0.002597961574792862, 0.004392482805997133, -0.004056545440107584, -0.0021114638075232506, -0.0019291259814053774, -0.00230101915076375, -0.008562562055885792, -0.014600220136344433, -0.0037870260421186686, -0.00009825781307881698, 0.009962533600628376, 0.00008111303031910211, 0.008041379041969776, -0.0024544389452785254, 0.001190942362882197, -0.007019604090601206, 0.005071811843663454, -0.0009252025629393756, 0.00377091858536005, -0.029821250587701797, 0.000671097484882921, -0.0022430585231631994, -0.009004420600831509, 0.008124305866658688, 0.0019489384721964598, 0.00003067076613660902, -0.0036249165423214436, -0.004400881938636303, 0.01021755114197731, -0.006673815194517374, 0.002881272230297327, -0.005537652876228094, -0.008374539203941822, -0.003950079437345266, -0.008646939881145954, 0.0007610341999679804, 0.0052008056081831455, -0.004332052543759346, -0.0063913543708622456, -0.0030704354867339134, 0.001920530921779573, 0.0028340178541839123, 0.0018630818231031299, -0.018504738807678223, -0.007152995094656944, -0.0020284601487219334, 0.00019598632934503257, -0.003989689517766237, -0.0035507935099303722, 0.005494564305990934, -0.010152322240173817, 0.006513511762022972, 0.0016226842999458313, -0.0012857315596193075, -0.011408217251300812, 0.0019155963091179729, -0.008714169263839722, -0.008550170809030533, 0.000259532273048535, -0.006286357529461384, -0.005010770633816719, -0.002471329178661108, 0.0012284750118851662, 0.008439888246357441, -0.0032030055299401283, 0.005260178353637457, 0.011224769055843353, -0.0019216418731957674, -0.007507829461246729, 0.007242225110530853, 0.005953631363809109, 0.0008400143124163151, -0.0031009602826088667, 0.0019455378642305732, 0.009243578650057316, 0.006478230468928814, 0.001472386415116489, 0.005691180005669594, -0.0007612329791299999, 0.009924149140715599, -0.002968286396935582, 0.0016391501994803548, -0.0037725530564785004, -0.0006861533038318157, -0.003724179696291685, -0.002448779297992587, -0.004511905834078789, -0.0016322681913152337, -0.012409700080752373, -0.008206688798964024, -0.002603033324703574, -0.00001582098593644332, 0.0026207081973552704, -0.004254648461937904, 0.001577104558236897, 0.0028069873806089163, 0.008480081334710121, -0.0017484808340668678, -0.00212464458309114, 0.0007530328584834933, 0.0016610438469797373, -0.008255301043391228, 0.016277015209197998, -0.012569619342684746, 0.006284706760197878, -0.0004031367425341159, -0.0160934217274189, 0.007430952042341232, 0.009517541155219078, -0.008759533055126667, 0.0014576810644939542, 0.0033250325359404087, 0.0035570859909057617, -0.0007088978309184313, -0.00440027704462409, -0.004058778285980225, -0.014350910671055317, -0.00039189920062199235, 0.021080316975712776, 0.00030626103398390114, 0.010709870606660843, 0.011978600174188614, -0.0053891693241894245, 0.0017117251409217715, 0.007053490728139877, 0.002074717078357935, 0.012937536463141441, -0.009319310076534748, -0.0011809045681729913, 0.0019203920383006334, -0.006008314434438944, 0.0005584608297795057, 0.005809956230223179, 0.005759297404438257, -0.0025097508914768696, 0.002293989760801196, -0.008414226584136486, -0.006519215647131205, -0.017245080322027206, -0.002294291742146015, 0.00912646297365427, -0.006347458343952894, 0.005716229788959026, -0.011981486342847347, 0.005830582696944475, 0.006256063003093004, 0.0037223908584564924, -0.0001645893498789519, 0.0004858569009229541, 0.006376836448907852, 0.01188153587281704, -0.0055290223099291325, 0.0035924084950238466, 0.0017164481105282903, -0.0001844451471697539, 0.0025946779642254114, 0.009477118030190468, -0.008184344507753849, -0.003919985145330429, 0.0028573418967425823, 0.002462351694703102, 0.0008295596926473081, -0.0029623915906995535, -0.008932217955589294, -0.0025625932030379772, 0.0019441518234089017, -0.006035737693309784, 0.0031930296681821346, 0.002988275606185198, 0.003922082018107176, -0.004775427747517824, 0.0012923670001327991, -0.002999630058184266, -0.011084018275141716, 0.009986450895667076, -0.0025241307448595762, 0.0019700906705111265, 0.012577768415212631, 0.0038379246834665537, -0.013016524724662304, 0.005429659970104694, 0.008704479783773422, -0.003917098511010408, 0.004329939838498831, 0.00677388533949852, -0.003970715217292309, -0.021648485213518143, -0.0036858636885881424, -0.012756198644638062, 0.00684351334348321, -0.003597073256969452, 0.005282315891236067, -0.005542760714888573, 0.00801027100533247, 0.0061537278816103935, -0.01415170170366764, -0.003821383463218808, -0.008607855997979641, 0.008803503587841988, -0.0015147736994549632, 0.0001226504537044093, -0.003622401738539338, -0.0016461365157738328, -0.0030862470157444477, -0.003661869326606393, -0.0031519995536655188, 0.004138903226703405, 0.0013114823959767818, -0.0046617803163826466, 0.0007097530178725719, -0.0037833303213119507, 0.0003758791135624051, 0.002550652716308832, -0.010320374742150307, 0.0034179314970970154, 0.004160792101174593, -0.002777873072773218, -0.0035969126038253307, 0.0033639634493738413, -0.0019801314920186996, -0.006575258448719978, -0.011471456848084927, -0.0030489936470985413, -0.00379246287047863, -0.002703690202906728, -0.011569956317543983, -0.0011124707525596023, -0.010529381223022938, 0.004198170267045498, -0.007889513857662678, 0.007108472753316164, 0.006568462587893009, -0.005917851347476244, 0.007585909217596054, -0.003486566012725234, 0.0035242389421910048, 0.005185392685234547, 0.006334660109132528, 0.0008227879297919571, -0.006028415635228157, -0.012884150259196758, 0.011207934468984604, -0.008043034002184868, 0.0010002653580158949, 0.014141437597572803, 0.004815520718693733, 0.009212716482579708, 0.00019582425011321902, -0.0007976934430189431, 0.002276491606608033, 0.007134210783988237, -0.014858575537800789, 0.003335122251883149, -0.003082999726757407, 0.0002320347703061998, 0.00538540119305253, -0.004808767698705196, 0.0009321926045231521, 0.009959760122001171, 0.0015151158440858126, -0.007756577804684639, -0.0031153198797255754, 0.0003826355969067663, 0.004689590539783239, -0.013328581117093563, 0.0006818535621277988, -0.004251215606927872, -0.003451849101111293, -0.0030494737438857555, -0.003430800512433052, -0.0009809845359995961, 0.0054920269176363945, -0.0028793662786483765, 0.005334106273949146, 0.002714972011744976, -0.005264368373900652, 0.015020908787846565, -0.004621955566108227, -0.006334221456199884, 0.001677767955698073, 0.0028591598384082317, -0.0028893384151160717, -0.007941708900034428, -0.0021645021624863148, 0.0018545456696301699, 0.005204944871366024, -0.0026037043426185846, -0.005279335658997297, -0.0011619818396866322, 0.0021480044815689325, -0.008674862794578075, 0.0005339347408153117, 0.01224612444639206, -0.0027590221725404263, 0.005685955751687288, -0.0009957242291420698, -0.009439947083592415, -0.013323514722287655, 0.05308922007679939, -0.0005859390366822481, 0.00448094867169857, 0.004913328215479851, -0.006778726354241371, 0.0009391067433170974, -0.000855384161695838, 0.008243239484727383, -0.006072620861232281, -0.00610164413228631, 0.008191290311515331, -0.0032277083955705166, 0.002416037255898118, 0.0036737527698278427, -0.0016791113885119557, 0.015228722244501114, -0.004799408372491598, -0.015807677060365677, -0.015533026307821274, 0.007262715138494968, -0.0016471638809889555, -0.009080889634788036, 0.010349572636187077, -0.0011461146641522646, -0.004914701916277409, 0.0019430938409641385, 0.006448657717555761, 0.0017420718213543296, -0.00004299151260056533, -0.0035473385360091925, -0.0016115164617076516, 0.0007703171577304602, 0.003005200531333685, 0.005152442492544651, 0.008535372093319893, -0.004221402108669281, 0.004270882811397314, -0.0038623097352683544, -0.002212155144661665, -0.0005228535155765712, 0.0038305246271193027, 0.006646896246820688, -0.0002734937588684261, -0.0015752300387248397, 0.0038810509722679853, 0.0046155150048434734, 0.0008963177097029984, 0.011213879100978374, -0.0011387376580387354, -0.006860608700662851, 0.007549280300736427, 0.006484640296548605, -0.0008416118216700852, 0.007182869594544172, -0.0013779745204374194, 0.006792898289859295, 0.002621724735945463, -0.007679209113121033, -0.014189506880939007, -0.0029015715699642897, 0.006348503287881613, 0.008328923024237156, -0.0011770955752581358, 0.002720579272136092, -0.0024967326316982508, -0.003661270486190915, -0.006880692671984434, -0.009754830971360207, -0.0033995090052485466, 0.001471740542910993, 0.0038319514133036137, 0.06957141309976578, -0.006022320594638586, -0.0020652723032981157, -0.008782590739428997, 0.00011899418313987553, -0.0015150828985497355, -0.00026147509925067425, 0.002236064989119768, -0.0006679767975583673, 0.002359609818086028, 0.001202259911224246, -0.0074360971339046955, -0.010949120856821537, 0.0006132681155577302, 0.0024528743233531713, -0.001978782005608082, 0.0045157321728765965, 0.0068654646165668964, -0.007941200397908688, 0.0013608989538624883, -0.012094603851437569, -0.002988075604662299, -0.003585739294067025, -0.00959189236164093, -0.0027021379210054874, -0.003526158630847931, 0.002829062519595027, 0.003384270006790757, 0.00689550768584013, -0.004457186907529831, 0.007128794211894274, -0.0027863881550729275, -0.0007785274647176266, -0.004455225542187691, 0.0007791097741574049, -0.0060490998439490795, 0.00831332802772522, 0.0005962935392744839, -0.009295245632529259, -0.006368002388626337, -0.001624436816200614, 0.0004671252390835434, -0.006347937509417534, 0.00358574278652668, -0.00044385864748619497, 0.004628391936421394, -0.0025317249819636345, -0.0002695133734960109, -0.007181182038038969, 0.0021896627731621265, -0.012954880483448505, 0.007988774217665195, -0.17483806610107422, 0.009542080573737621, 0.0035428833216428757, -0.0047594415955245495, -0.0038512619212269783, -0.015719445422291756, -0.007740630302578211, 0.003963987343013287, 0.00993370171636343, 0.0008200265583582222, -0.002089116722345352, -0.0015741477254778147, 0.0031274682842195034, 0.0035330902319401503, -0.0012084378395229578, -0.003168347757309675, 0.0026501247193664312, -0.005796760320663452, -0.00005730715929530561, 0.004387191962450743, 0.0037933550775051117, 0.008964551612734795, 0.002114248927682638, 0.002295762300491333, -0.0017410597065463662, -0.0057978322729468346, 0.00629982678219676, -0.001929709454998374, 0.005206986330449581, -0.012028979137539864, -0.002671711379662156, -0.004300741478800774, -0.004061399959027767, 0.0007666329038329422, 0.0046797278337180614, -0.0004255595849826932, 0.009700935333967209, 0.0030411628540605307, -0.008109865710139275, 0.0066683595068752766, -0.008047327399253845, 0.027995752170681953, 0.007728211581707001, 0.005087449215352535, 0.00033497627009637654, -0.007186765316873789, -0.004690275061875582, 0.007473848294466734, 0.0012527857907116413, 0.012062149122357368, -0.011089526116847992, -0.002538092667236924, 0.0034171752631664276, 0.019245252013206482, -0.003441804088652134, -0.009106406942009926, -0.005891867447644472, -0.0050506265833973885, 0.0028692663181573153, 0.008518320508301258, 0.010254044085741043, -0.004744993057101965, 0.008354183286428452, -0.003703731345012784, -0.02048979327082634, 0.0033836730290204287, -0.0038607146125286818, -0.007047016639262438, 0.0016084235394373536, 0.007977143861353397, 0.008929702453315258, -0.0001857405004557222, 0.0022975814063102007, -0.0013206173898652196, 0.004233781713992357, -0.0005413837498053908, 0.008596593514084816, -0.001763583510182798, 0.005393591709434986, -0.009877460077404976, 0.0069596851244568825, -0.010902524925768375, -0.0020191792864352465, 0.002008231822401285, -0.0032273358665406704, 0.011892233043909073, 0.003823264269158244, -0.001333975582383573, -0.0019058585166931152, -0.011034510098397732, -0.0025035878643393517, 0.0016484695952385664, 0.0016184597043320537, -0.007338621653616428, 0.0014394029276445508, 0.0013399809831753373, 0.004753469489514828, 0.006681419443339109, -0.008800552226603031, 0.00868389755487442, 0.0056913914158940315, -0.005220060236752033, -0.00014936519437469542, -0.006440773606300354, 0.0019861608743667603, 0.005607342813163996, -0.006580649875104427, -0.004738327115774155, 0.002435417613014579, -0.005423785652965307, -0.005260367412120104, 0.007167499046772718, -0.008675197139382362, -0.009076496586203575, -0.0024102376773953438, -0.011210951954126358, 0.0010215728543698788 ]
8aa0f73f3e1949691f35856c47f4d0a99caef5b9
4,247
py
Python
lib/interface.py
keke185321/combine-copy-
de2eba77d8db5c9c1908aac1262590b80c2348ce
[ "Apache-2.0" ]
null
null
null
lib/interface.py
keke185321/combine-copy-
de2eba77d8db5c9c1908aac1262590b80c2348ce
[ "Apache-2.0" ]
null
null
null
lib/interface.py
keke185321/combine-copy-
de2eba77d8db5c9c1908aac1262590b80c2348ce
[ "Apache-2.0" ]
null
null
null
import cv2, time import numpy as np import Tkinter """ Wraps up some interfaces to opencv user interface methods (displaying image frames, event handling, etc). If desired, an alternative UI could be built and imported into get_pulse.py instead. Opencv is used to perform much of the data analysis, but there is no reason it has to be used to handle the UI as well. It just happens to be very effective for our purposes. """ def resize(*args, **kwargs): return cv2.resize(*args, **kwargs) def moveWindow(*args,**kwargs): return def imshow(root,args,kwargs): image = cv2.cvtColor(output_frame, cv2.COLOR_BGR2RGB) image = Image.fromarray(image) image = ImageTk.PhotoImage(image) return Tkinter.Label(root, image=kwargs).pack() #return cv2.imshow(*args,**kwargs) def destroyWindow(*args,**kwargs): return cv2.destroyWindow(*args,**kwargs) def waitKey(*args,**kwargs): return cv2.waitKey(*args,**kwargs) """ The rest of this file defines some GUI plotting functionality. There are plenty of other ways to do simple x-y data plots in python, but this application uses cv2.imshow to do real-time data plotting and handle user interaction. This is entirely independent of the data calculation functions, so it can be replaced in the get_pulse.py application easily. """ def combine(left, right): """Stack images horizontally. """ h = max(left.shape[0], right.shape[0]) w = left.shape[1] + right.shape[1] hoff = left.shape[0] shape = list(left.shape) shape[0] = h shape[1] = w comb = np.zeros(tuple(shape),left.dtype) # left will be on left, aligned top, with right on right comb[:left.shape[0],:left.shape[1]] = left comb[:right.shape[0],left.shape[1]:] = right return comb def plotXY(data,size = (280,640),margin = 25,name = "data",labels=[], skip = [], showmax = [], bg = None,label_ndigits = [], showmax_digits=[]): for x,y in data: if len(x) < 2 or len(y) < 2: return n_plots = len(data) w = float(size[1]) h = size[0]/float(n_plots) z = np.zeros((size[0],size[1],3)) if isinstance(bg,np.ndarray): wd = int(bg.shape[1]/bg.shape[0]*h ) bg = cv2.resize(bg,(wd,int(h))) if len(bg.shape) == 3: r = combine(bg[:,:,0],z[:,:,0]) g = combine(bg[:,:,1],z[:,:,1]) b = combine(bg[:,:,2],z[:,:,2]) else: r = combine(bg,z[:,:,0]) g = combine(bg,z[:,:,1]) b = combine(bg,z[:,:,2]) z = cv2.merge([r,g,b])[:,:-wd,] i = 0 P = [] for x,y in data: x = np.array(x) y = -np.array(y) xx = (w-2*margin)*(x - x.min()) / (x.max() - x.min())+margin yy = (h-2*margin)*(y - y.min()) / (y.max() - y.min())+margin + i*h mx = max(yy) if labels: if labels[i]: for ii in range(len(x)): if ii%skip[i] == 0: col = (255,255,255) ss = '{0:.%sf}' % label_ndigits[i] ss = ss.format(x[ii]) cv2.putText(z,ss,(int(xx[ii]),int((i+1)*h)), cv2.FONT_HERSHEY_PLAIN,1,col) if showmax: if showmax[i]: col = (0,255,0) ii = np.argmax(-y) ss = '{0:.%sf} %s' % (showmax_digits[i], showmax[i]) ss = ss.format(x[ii]) #"%0.0f %s" % (x[ii], showmax[i]) cv2.putText(z,ss,(int(xx[ii]),int((yy[ii]))), cv2.FONT_HERSHEY_PLAIN,2,col) try: pts = np.array([[x_, y_] for x_, y_ in zip(xx,yy)],np.int32) i+=1 P.append(pts) except ValueError: pass #temporary """ #Polylines seems to have some trouble rendering multiple polys for some people for p in P: cv2.polylines(z, [p], False, (255,255,255),1) """ #hack-y alternative: for p in P: for i in range(len(p)-1): cv2.line(z,tuple(p[i]),tuple(p[i+1]), (255,255,255),1) return z #cv2.imshow(name,z)
31.932331
82
0.533318
0
0
[ -0.017090467736124992, 0.021586671471595764, 0.01154855452477932, -0.0017572082579135895, -0.014484238810837269, 0.022254137322306633, -0.039469074457883835, 0.015094808302819729, -0.029431737959384918, 0.013480816036462784, 0.015374850481748581, 0.04028506949543953, 0.00583181157708168, -0.041030481457710266, -0.012108653783798218, -0.004888864234089851, 0.09714732319116592, -0.003139855107292533, -0.013008419424295425, 0.005468714516609907, -0.03820134326815605, 0.00875550601631403, -0.022258901968598366, 0.019384855404496193, -0.0014640884473919868, 0.009693393483757973, 0.034143075346946716, 0.010449238121509552, -0.012708657421171665, -0.004190888721495867, 0.016690414398908615, 0.015494626946747303, -0.0022905217483639717, 0.03322692960500717, -0.02541365846991539, 0.022046996280550957, 0.0252142995595932, 0.016299216076731682, -0.020595211535692215, -0.0032167998142540455, -0.03643571957945824, 0.00403532525524497, 0.0026718899607658386, -0.055379029363393784, -0.03191092237830162, -0.013950012624263763, -0.009669004008173943, -0.008217068389058113, -0.042706962674856186, -0.019822826609015465, 0.03412173315882683, 0.035403426736593246, 0.026944665238261223, -0.04271576553583145, 0.006251261569559574, -0.07382926344871521, 0.006972148083150387, -0.03675815835595131, -0.0192598607391119, -0.001549718901515007, -0.04666311293840408, 0.012993399053812027, 0.012997227720916271, -0.0032514198683202267, 0.023860545828938484, 0.03498965501785278, -0.0013601843966171145, -0.0014716412406414747, -0.0071816579438745975, 0.011722147464752197, -0.054823823273181915, 0.013423955999314785, -0.019541393965482712, 0.10378599911928177, 0.020880956202745438, -0.05707881599664688, -0.04748387262225151, -0.008567643351852894, 0.011158480308949947, 0.06677569448947906, -0.015959449112415314, 0.03332223370671272, 0.014203050173819065, 0.022346295416355133, -0.020743904635310173, 0.05203084647655487, 0.04734216630458832, -0.00578091898933053, 0.015707088634371758, -0.01667308807373047, -0.03531760349869728, 0.0194010641425848, -0.05624649301171303, -0.01658286340534687, -0.07341347634792328, -0.010750371031463146, 0.0324266143143177, 0.016610389575362206, 0.027361221611499786, 0.01342625543475151, 0.03213188052177429, -0.006142958998680115, 0.028380494564771652, -0.007826391607522964, -0.01442354079335928, 0.007852033711969852, -0.04923520237207413, 0.02606086991727352, -0.009068187326192856, -0.0035627936013042927, -0.03027290292084217, -0.04171399399638176, 0.01863679103553295, 0.005677826702594757, -0.019717978313565254, -0.030068915337324142, 0.024464432150125504, 0.014449547976255417, 0.03282994031906128, 0.07902371138334274, -0.007144458591938019, -0.014844965189695358, 0.023735126480460167, 0.014549694955348969, -0.030556732788681984, 0.06903351098299026, 0.03677348420023918, -0.014763076789677143, 0.033337973058223724, -0.021487228572368622, 0.025551408529281616, 0.03858302906155586, 0.006962370593100786, -0.03003540262579918, 0.009591232053935528, 0.0015959191368892789, -0.037889719009399414, 0.020062074065208435, -0.03798770532011986, 0.01558635476976633, -0.010065913200378418, -0.04552435502409935, -0.006697703618556261, 0.00708842184394598, 0.010355982929468155, -0.0185038223862648, 0.00926764216274023, 0.012690982781350613, -0.036707036197185516, -0.021092385053634644, 0.008066140115261078, 0.002420148579403758, -0.029066039249300957, 0.007526155561208725, -0.001513756695203483, -0.0075048222206532955, 0.008252802304923534, -0.05393638834357262, -0.04297535866498947, 0.014754381030797958, -0.011458509601652622, 0.014302409254014492, -0.000683230406139046, 0.01779378019273281, 0.00006761075928807259, 0.06511776894330978, -0.0166945718228817, 0.03611263632774353, 0.004306059330701828, -0.01350531354546547, 0.023436715826392174, -0.022631287574768066, -0.021804777905344963, -0.021058592945337296, -0.05788452923297882, -0.04082249104976654, 0.03300177678465843, 0.004408160224556923, -0.038305629044771194, -0.03972168266773224, 0.036564119160175323, -0.02165348455309868, 0.03502154350280762, 0.033057473599910736, 0.01909790001809597, -0.009501887485384941, -0.020183946937322617, -0.02804580144584179, -0.02819267101585865, -0.02080168016254902, -0.004794709850102663, 0.03791685402393341, -0.013441880233585835, -0.028558524325489998, 0.061612050980329514, -0.0075567010790109634, 0.015223472379148006, 0.012262998148798943, -0.0006568772951141, -0.002205483615398407, -0.0005291520501486957, -0.037189725786447525, -0.02083682455122471, 0.02811683714389801, -0.029307346791028976, -0.017395958304405212, -0.6411147713661194, 0.03947863355278969, 0.02269311249256134, -0.023310869932174683, 0.044660136103630066, 0.06511681526899338, -0.038969527930021286, 0.05309447646141052, -0.006694583687931299, 0.01994510553777218, -0.018439454957842827, -0.024411387741565704, -0.03432464599609375, -0.01253508497029543, 0.012401551008224487, -0.034078337252140045, 0.0126406941562891, 0.013068179599940777, -0.01255500316619873, 0.021863127127289772, 0.015337716788053513, -0.00921802967786789, -0.0029009829740971327, 0.020134732127189636, -0.04066097363829613, -0.014550324529409409, -0.018263718113303185, -0.015563315711915493, 0.012582964263856411, 0.030690494924783707, -0.031178956851363182, -0.014035750180482864, 0.033791813999414444, -0.01750332862138748, -0.0017228878568857908, -0.020646318793296814, 0.0029810958076268435, -0.010917237028479576, -0.000745496479794383, -0.02338556945323944, -0.007225770503282547, -0.021593211218714714, -0.03445560857653618, -0.030013207346200943, -0.04480236396193504, -0.016580870375037193, -0.0014012859901413321, 0.005473508033901453, 0.04531439393758774, 0.046668488532304764, -0.015529259108006954, 0.037297654896974564, 0.06580990552902222, -0.011395393870770931, -0.00738974055275321, -0.005161784123629332, -0.0005205196794122458, 0.024099992588162422, 0.00019327794143464416, -0.0028116940520703793, -0.023555763065814972, -0.017552541568875313, -0.03150797635316849, 0.03257475420832634, -0.02118750847876072, 0.0002798370842356235, 0.000760041584726423, -0.002180134877562523, -0.02597789280116558, -0.007408086210489273, -0.05246070399880409, 0.012283680029213428, -0.021554021164774895, 0.07642760872840881, -0.008708774112164974, -0.016855770722031593, -0.031491968780756, 0.0066789742559194565, 0.0016609772574156523, -0.03466252610087395, 0.009304791688919067, 0.026554249227046967, -0.038286443799734116, 0.01133071631193161, -0.057577233761548996, -0.021506937220692635, 0.03265373036265373, 0.01084673311561346, 0.008844888769090176, 0.050397492945194244, 0.0274874996393919, 0.029592648148536682, 0.008907865732908249, -0.015724482014775276, 0.03655696660280228, 0.007815253920853138, -0.01923522539436817, 0.04073065146803856, 0.017693202942609787, 0.020188037306070328, -0.0027595600113272667, -0.008861602284014225, 0.02477443777024746, 0.019939033314585686, -0.01253068819642067, 0.01159112248569727, -0.08961144834756851, -0.014692353084683418, 0.006301156710833311, -0.09541254490613937, -0.0023257816210389137, -0.01757051795721054, -0.01131539884954691, 0.00834030844271183, 0.04012622311711311, -0.024674857035279274, -0.01490733865648508, -0.035816699266433716, 0.01263265497982502, -0.025323720648884773, -0.020521441474556923, -0.06232418492436409, 0.001178164267912507, 0.002236533211544156, -0.0034539801999926567, 0.03945349156856537, -0.03049914911389351, 0.0360763818025589, -0.00949714332818985, -0.02531159482896328, 0.00536772608757019, -0.013474173843860626, -0.018087532371282578, 0.005595960654318333, -0.03488108515739441, -0.01396580133587122, -0.021892128512263298, -0.026942890137434006, 0.014637742191553116, 0.020506540313363075, 0.01654084399342537, -0.03863564878702164, 0.013649358414113522, -0.020312290638685226, -0.030461855232715607, 0.011768613941967487, 0.032027456909418106, 0.02083413302898407, 0.05616457760334015, 0.01978175900876522, -0.0033586244098842144, 0.014671743847429752, 0.006472437642514706, 0.0462714321911335, -0.0069536785595119, 0.01072415616363287, -0.026573820039629936, -0.01612698659300804, 0.01357651874423027, 0.011779765598475933, -0.004833505488932133, -0.001391987781971693, -0.005000187084078789, 0.016280999407172203, 0.01683145761489868, -0.030351877212524414, 0.017627915367484093, 0.0274350643157959, 0.014652847312390804, 0.028191395103931427, 0.0627872422337532, -0.06296108663082123, 0.01495498325675726, -0.009488936513662338, -0.023200051859021187, 0.028334343805909157, 0.004017489962279797, -0.0014975102385506034, 0.028582530096173286, 0.0160124059766531, 0.04447218030691147, -0.006421384401619434, -0.02576170302927494, 0.007402828428894281, 0.01278004515916109, 0.01324519794434309, -0.007276605814695358, 0.012921085581183434, 0.025879541411995888, -0.006581940222531557, 0.02261853963136673, 0.038315922021865845, -0.00320535060018301, -0.01518987026065588, -0.04893207922577858, -0.023897698149085045, 0.045330826193094254, 0.006305722985416651, -0.0009723730618134141, -0.03765661269426346, -0.007686215918511152, -0.005862535908818245, 0.029220174998044968, 0.012318063527345657, 0.025437427684664726, 0.03354393690824509, -0.01854534074664116, -0.053525958210229874, -0.00768757751211524, 0.002334954682737589, 0.027790838852524757, -0.02266506850719452, 0.019043421372771263, -0.01622849330306053, -0.05539705231785774, 0.012692024931311607, -0.04108360409736633, -0.02173694223165512, -0.0060890791937708855, -0.02912185527384281, -0.017322465777397156, -0.010539722628891468, 0.04150719568133354, 0.03032260201871395, -0.021854812279343605, 0.012317297048866749, 0.001445371424779296, 0.02980414777994156, 0.00980750098824501, -0.02041158266365528, 0.03394077345728874, -0.006937854457646608, 0.03726165369153023, -0.0006526949000544846, -0.012977499514818192, 0.02515508607029915, -0.01450286153703928, -0.007448081858456135, -0.0019125648541375995, -0.02128862962126732, 0.08907776325941086, -0.02575618587434292, 0.009765070863068104, 0.042266570031642914, -0.003913280088454485, -0.000771292659919709, 0.019855910912156105, -0.024044673889875412, 0.0064668674021959305, -0.016312209889292717, -0.03364502638578415, 0.03487586975097656, -0.0061361114494502544, -0.009220178239047527, -0.031586214900016785, 0.03757033869624138, -0.0014797000912949443, 0.008308045566082, 0.0006063288892619312, 0.01315986830741167, 0.01198607962578535, -0.030540665611624718, 0.004664107691496611, 0.02471313439309597, -0.014202718622982502, 0.0050697363913059235, 0.031194476410746574, -0.04393026605248451, 0.01861465349793434, 0.01881513185799122, 0.02973327971994877, -0.035520363599061966, -0.01503061130642891, -0.0020662862807512283, 0.02810053527355194, -0.05006229132413864, 0.01916595548391342, -0.037166498601436615, -0.03621358424425125, 0.004962739069014788, -0.0038017979823052883, 0.004585840739309788, 0.05003340169787407, 0.04986128956079483, 0.008375603705644608, -0.0336092971265316, -0.05720934644341469, -0.01185130886733532, -0.05767159163951874, -0.0037590106949210167, -0.01093417126685381, -0.03414594382047653, 0.011435681954026222, 0.08494972437620163, -0.016191445291042328, -0.013506562449038029, -0.01130435336381197, -0.0038283842150121927, 0.05309680849313736, -0.015251698903739452, 0.04019055888056755, 0.018949447199702263, 0.028404992073774338, -0.009030329063534737, 0.022631680592894554, -0.021368911489844322, 0.02365286462008953, -0.0012332720216363668, 0.03137882053852081, 0.027449265122413635, 0.04465298727154732, 0.013889077119529247, -0.013212195597589016, 0.009244013577699661, -0.036911506205797195, 0.013797633349895477, 0.04563340172171593, 0.01338978298008442, -0.012332783080637455, 0.009287822060286999, -0.007254738360643387, 0.0036601852625608444, 0.008151242509484291, 0.005468043964356184, 0.0006920338491909206, -0.03084537386894226, -0.030094284564256668, -0.006284229923039675, 0.022729085758328438, 0.018888235092163086, -0.002203467534855008, -0.02067513018846512, -0.009877311997115612, 0.011160875670611858, 0.03387608751654625, 0.0015234199818223715, 0.04734731838107109, 0.05183643102645874, 0.035244397819042206, 0.001993117853999138, 0.026213565841317177, 0.02628621831536293, 0.01151596661657095, 0.014286737889051437, 0.0017595419194549322, -0.012029831297695637, -0.05852784961462021, 0.07379399985074997, 0.008033896796405315, 0.02598479948937893, -0.005683346651494503, 0.010692317970097065, -0.04546193778514862, 0.021514413878321648, 0.027812208980321884, -0.03652207553386688, 0.04279513657093048, 0.02646438218653202, 0.01628313958644867, 0.03283369913697243, -0.02761966548860073, 0.01465668622404337, 0.025131840258836746, -0.028137555345892906, 0.019884200766682625, -0.03477954491972923, 0.009407324716448784, -0.04043472558259964, -0.022884653881192207, -0.021662849932909012, -0.01424620021134615, -0.02862069383263588, -0.03599092364311218, -0.015697265043854713, 0.0382346585392952, 0.017011109739542007, 0.014789236709475517, -0.000553240068256855, -0.028776580467820168, -0.03704413026571274, -0.017896955832839012, -0.034721631556749344, 0.020492177456617355, -0.008351069875061512, -0.009807637892663479, -0.06573287397623062, -0.005855025257915258, 0.007068668492138386, -0.0008178434800356627, 0.005096562206745148, -0.017737295478582382, -0.009405267424881458, -0.023055745288729668, 0.03662848100066185, -0.027225909754633904, -0.028822189196944237, -0.03151870146393776, -0.008377637714147568, 0.0011721074115484953, 0.010435954667627811, 0.0016159279039129615, 0.006101887673139572, -0.00408819317817688, -0.053042151033878326, -0.008313562721014023, 0.010810748673975468, 0.028980780392885208, -0.03462517261505127, 0.005717146676033735, 0.017677810043096542, 0.0016097592888399959, 0.017490968108177185, -0.020286841318011284, -0.011418075300753117, 0.03725011274218559, 0.014895427040755749, -0.06645718216896057, 0.0024713773746043444, -0.003582325531169772, 0.018102344125509262, -0.02767110988497734, -0.03643526881933212, -0.01435899455100298, -0.004154257010668516, 0.011603763327002525, 0.008560058660805225, 0.015584299340844154, 0.016905339434742928, -0.008669654838740826, 0.017673663794994354, -0.03937997296452522, -0.020907670259475708, -0.020779941231012344, 0.056572314351797104, 0.03998452425003052, -0.015757447108626366, -0.0071236202493309975, -0.025975840166211128, -0.01722779870033264, 0.04108383506536484, 0.01759285293519497, 0.006110743153840303, -0.026129797101020813, 0.019264686852693558, 0.033506061881780624, -0.07246522605419159, 0.03090793825685978, -0.008209224790334702, -0.020128561183810234, -0.00247391639277339, -0.021608244627714157, -0.02133580669760704, 0.011076818220317364, -0.007209465838968754, 0.027921222150325775, 0.01961183175444603, 0.054373618215322495, 0.0505511499941349, 0.013323024846613407, 0.009124018251895905, 0.040549229830503464, -0.013566078618168831, 0.01245032623410225, 0.010548383928835392, 0.023134471848607063, -0.021552566438913345, -0.009847898036241531, -0.003993842285126448, 0.018080491572618484, 0.0003282340767327696, -0.013870113529264927, -0.009103135205805302, 0.004164641723036766, 0.028006555512547493, -0.004696309566497803, 0.0038533068727701902, -0.0033520632423460484, 0.013026402331888676, 0.010043582879006863, 0.011923778802156448, -0.02657284215092659, 0.0420457161962986, -0.001046504476107657, -0.007871733047068119, 0.023044437170028687, 0.027696624398231506, -0.005851314403116703, -0.03409837558865547, 0.026944106444716454, 0.006542825140058994, -0.038864415138959885, -0.01247119065374136, -0.01208388339728117, -0.004091133829206228, 0.04414792358875275, 0.011105317622423172, 0.019995665177702904, -0.02424454689025879, 0.03942723944783211, -0.05438190698623657, -0.033622272312641144, -0.043667685240507126, -0.01096448116004467, -0.014141229912638664, 0.023358184844255447, 0.001976064406335354, 0.05109803378582001, -0.011019234545528889, -0.04547449201345444, -0.02851681225001812, -0.0005316885653883219, -0.01791958697140217, 0.006857725791633129, -0.012866324745118618, 0.02236173115670681, -0.00395375769585371, 0.03666174039244652, 0.06338422000408173, 0.028062665835022926, -0.032604001462459564, 0.026170991361141205, 0.006974218878895044, -0.04346504062414169, 0.0025233791675418615, -0.010228174738585949, -0.025349389761686325, -0.05323522910475731, 0.03834974393248558, 0.01616198569536209, 0.011234816163778305, -0.006522829644382, -0.002652745693922043, -0.03935539349913597, 0.018792230635881424, 0.03666485846042633, -0.014334402978420258, -0.027462147176265717, 0.05173882469534874, -0.05657080188393593, -0.011991692706942558, 0.03607039153575897, 0.04531678184866905, -0.0023124567233026028, -0.029842549934983253, -0.039792027324438095, -0.03294844180345535, -0.006005806382745504, -0.007345890626311302, -0.00843565072864294, 0.02031705714762211, -0.03308927267789841, -0.01872829906642437, -0.013962461613118649, 0.01619710400700569, -0.020270153880119324, -0.0050646523013710976, -0.013408017344772816, -0.022937407717108727, -0.009707442484796047, -0.05357515439391136, -0.007533068303018808, 0.0024496798869222403 ]
8aa1a1e63a87d2e580e76379c3a2ac6b8f3e051d
16,125
py
Python
nltk/tag/brill.py
FGDBTKD/nltk
384e46e82789c7f47a7fb521ef976f82c3c4c3fb
[ "Apache-2.0" ]
null
null
null
nltk/tag/brill.py
FGDBTKD/nltk
384e46e82789c7f47a7fb521ef976f82c3c4c3fb
[ "Apache-2.0" ]
null
null
null
nltk/tag/brill.py
FGDBTKD/nltk
384e46e82789c7f47a7fb521ef976f82c3c4c3fb
[ "Apache-2.0" ]
1
2019-10-18T08:58:45.000Z
2019-10-18T08:58:45.000Z
# -*- coding: utf-8 -*- # Natural Language Toolkit: Transformation-based learning # # Copyright (C) 2001-2018 NLTK Project # Author: Marcus Uneson <marcus.uneson@gmail.com> # based on previous (nltk2) version by # Christopher Maloof, Edward Loper, Steven Bird # URL: <http://nltk.org/> # For license information, see LICENSE.TXT from __future__ import print_function, division from collections import defaultdict, Counter from nltk.tag import TaggerI from nltk.tbl import Feature, Template from nltk import jsontags ###################################################################### # Brill Templates ###################################################################### @jsontags.register_tag class Word(Feature): """ Feature which examines the text (word) of nearby tokens. """ json_tag = 'nltk.tag.brill.Word' @staticmethod def extract_property(tokens, index): """@return: The given token's text.""" return tokens[index][0] @jsontags.register_tag class Pos(Feature): """ Feature which examines the tags of nearby tokens. """ json_tag = 'nltk.tag.brill.Pos' @staticmethod def extract_property(tokens, index): """@return: The given token's tag.""" return tokens[index][1] def nltkdemo18(): """ Return 18 templates, from the original nltk demo, in multi-feature syntax """ return [ Template(Pos([-1])), Template(Pos([1])), Template(Pos([-2])), Template(Pos([2])), Template(Pos([-2, -1])), Template(Pos([1, 2])), Template(Pos([-3, -2, -1])), Template(Pos([1, 2, 3])), Template(Pos([-1]), Pos([1])), Template(Word([-1])), Template(Word([1])), Template(Word([-2])), Template(Word([2])), Template(Word([-2, -1])), Template(Word([1, 2])), Template(Word([-3, -2, -1])), Template(Word([1, 2, 3])), Template(Word([-1]), Word([1])), ] def nltkdemo18plus(): """ Return 18 templates, from the original nltk demo, and additionally a few multi-feature ones (the motivation is easy comparison with nltkdemo18) """ return nltkdemo18() + [ Template(Word([-1]), Pos([1])), Template(Pos([-1]), Word([1])), Template(Word([-1]), Word([0]), Pos([1])), Template(Pos([-1]), Word([0]), Word([1])), Template(Pos([-1]), Word([0]), Pos([1])), ] def fntbl37(): """ Return 37 templates taken from the postagging task of the fntbl distribution http://www.cs.jhu.edu/~rflorian/fntbl/ (37 is after excluding a handful which do not condition on Pos[0]; fntbl can do that but the current nltk implementation cannot.) """ return [ Template(Word([0]), Word([1]), Word([2])), Template(Word([-1]), Word([0]), Word([1])), Template(Word([0]), Word([-1])), Template(Word([0]), Word([1])), Template(Word([0]), Word([2])), Template(Word([0]), Word([-2])), Template(Word([1, 2])), Template(Word([-2, -1])), Template(Word([1, 2, 3])), Template(Word([-3, -2, -1])), Template(Word([0]), Pos([2])), Template(Word([0]), Pos([-2])), Template(Word([0]), Pos([1])), Template(Word([0]), Pos([-1])), Template(Word([0])), Template(Word([-2])), Template(Word([2])), Template(Word([1])), Template(Word([-1])), Template(Pos([-1]), Pos([1])), Template(Pos([1]), Pos([2])), Template(Pos([-1]), Pos([-2])), Template(Pos([1])), Template(Pos([-1])), Template(Pos([-2])), Template(Pos([2])), Template(Pos([1, 2, 3])), Template(Pos([1, 2])), Template(Pos([-3, -2, -1])), Template(Pos([-2, -1])), Template(Pos([1]), Word([0]), Word([1])), Template(Pos([1]), Word([0]), Word([-1])), Template(Pos([-1]), Word([-1]), Word([0])), Template(Pos([-1]), Word([0]), Word([1])), Template(Pos([-2]), Pos([-1])), Template(Pos([1]), Pos([2])), Template(Pos([1]), Pos([2]), Word([1])) ] def brill24(): """ Return 24 templates of the seminal TBL paper, Brill (1995) """ return [ Template(Pos([-1])), Template(Pos([1])), Template(Pos([-2])), Template(Pos([2])), Template(Pos([-2, -1])), Template(Pos([1, 2])), Template(Pos([-3, -2, -1])), Template(Pos([1, 2, 3])), Template(Pos([-1]), Pos([1])), Template(Pos([-2]), Pos([-1])), Template(Pos([1]), Pos([2])), Template(Word([-1])), Template(Word([1])), Template(Word([-2])), Template(Word([2])), Template(Word([-2, -1])), Template(Word([1, 2])), Template(Word([-1, 0])), Template(Word([0, 1])), Template(Word([0])), Template(Word([-1]), Pos([-1])), Template(Word([1]), Pos([1])), Template(Word([0]), Word([-1]), Pos([-1])), Template(Word([0]), Word([1]), Pos([1])), ] def describe_template_sets(): """ Print the available template sets in this demo, with a short description" """ import inspect import sys # a bit of magic to get all functions in this module templatesets = inspect.getmembers(sys.modules[__name__], inspect.isfunction) for (name, obj) in templatesets: if name == "describe_template_sets": continue print(name, obj.__doc__, "\n") ###################################################################### # The Brill Tagger ###################################################################### @jsontags.register_tag class BrillTagger(TaggerI): """ Brill's transformational rule-based tagger. Brill taggers use an initial tagger (such as ``tag.DefaultTagger``) to assign an initial tag sequence to a text; and then apply an ordered list of transformational rules to correct the tags of individual tokens. These transformation rules are specified by the ``TagRule`` interface. Brill taggers can be created directly, from an initial tagger and a list of transformational rules; but more often, Brill taggers are created by learning rules from a training corpus, using one of the TaggerTrainers available. """ json_tag = 'nltk.tag.BrillTagger' def __init__(self, initial_tagger, rules, training_stats=None): """ :param initial_tagger: The initial tagger :type initial_tagger: TaggerI :param rules: An ordered list of transformation rules that should be used to correct the initial tagging. :type rules: list(TagRule) :param training_stats: A dictionary of statistics collected during training, for possible later use :type training_stats: dict """ self._initial_tagger = initial_tagger self._rules = tuple(rules) self._training_stats = training_stats def encode_json_obj(self): return self._initial_tagger, self._rules, self._training_stats @classmethod def decode_json_obj(cls, obj): _initial_tagger, _rules, _training_stats = obj return cls(_initial_tagger, _rules, _training_stats) def rules(self): """ Return the ordered list of transformation rules that this tagger has learnt :return: the ordered list of transformation rules that correct the initial tagging :rtype: list of Rules """ return self._rules def train_stats(self, statistic=None): """ Return a named statistic collected during training, or a dictionary of all available statistics if no name given :param statistic: name of statistic :type statistic: str :return: some statistic collected during training of this tagger :rtype: any (but usually a number) """ if statistic is None: return self._training_stats else: return self._training_stats.get(statistic) def tag(self, tokens): # Inherit documentation from TaggerI # Run the initial tagger. tagged_tokens = self._initial_tagger.tag(tokens) # Create a dictionary that maps each tag to a list of the # indices of tokens that have that tag. tag_to_positions = defaultdict(set) for i, (token, tag) in enumerate(tagged_tokens): tag_to_positions[tag].add(i) # Apply each rule, in order. Only try to apply rules at # positions that have the desired original tag. for rule in self._rules: # Find the positions where it might apply positions = tag_to_positions.get(rule.original_tag, []) # Apply the rule at those positions. changed = rule.apply(tagged_tokens, positions) # Update tag_to_positions with the positions of tags that # were modified. for i in changed: tag_to_positions[rule.original_tag].remove(i) tag_to_positions[rule.replacement_tag].add(i) return tagged_tokens def print_template_statistics(self, test_stats=None, printunused=True): """ Print a list of all templates, ranked according to efficiency. If test_stats is available, the templates are ranked according to their relative contribution (summed for all rules created from a given template, weighted by score) to the performance on the test set. If no test_stats, then statistics collected during training are used instead. There is also an unweighted measure (just counting the rules). This is less informative, though, as many low-score rules will appear towards end of training. :param test_stats: dictionary of statistics collected during testing :type test_stats: dict of str -> any (but usually numbers) :param printunused: if True, print a list of all unused templates :type printunused: bool :return: None :rtype: None """ tids = [r.templateid for r in self._rules] train_stats = self.train_stats() trainscores = train_stats['rulescores'] assert len(trainscores) == len(tids), "corrupt statistics: " \ "{0} train scores for {1} rules".format(trainscores, tids) template_counts = Counter(tids) weighted_traincounts = Counter() for (tid, score) in zip(tids, trainscores): weighted_traincounts[tid] += score tottrainscores = sum(trainscores) # det_tplsort() is for deterministic sorting; # the otherwise convenient Counter.most_common() unfortunately # does not break ties deterministically # between python versions and will break cross-version tests def det_tplsort(tpl_value): return (tpl_value[1], repr(tpl_value[0])) def print_train_stats(): print("TEMPLATE STATISTICS (TRAIN) {0} templates, {1} rules)".format( len(template_counts), len(tids)) ) print("TRAIN ({tokencount:7d} tokens) initial {initialerrors:5d} {initialacc:.4f} " "final: {finalerrors:5d} {finalacc:.4f} ".format(**train_stats)) head = "#ID | Score (train) | #Rules | Template" print(head, "\n", "-" * len(head), sep="") train_tplscores = sorted(weighted_traincounts.items(), key=det_tplsort, reverse=True) for (tid, trainscore) in train_tplscores: s = "{0} | {1:5d} {2:5.3f} |{3:4d} {4:.3f} | {5}".format( tid, trainscore, trainscore/tottrainscores, template_counts[tid], template_counts[tid]/len(tids), Template.ALLTEMPLATES[int(tid)], ) print(s) def print_testtrain_stats(): testscores = test_stats['rulescores'] print("TEMPLATE STATISTICS (TEST AND TRAIN) ({0} templates, {1} rules)".format( len(template_counts), len(tids)), ) print("TEST ({tokencount:7d} tokens) initial {initialerrors:5d} {initialacc:.4f} " "final: {finalerrors:5d} {finalacc:.4f} ".format(**test_stats)) print("TRAIN ({tokencount:7d} tokens) initial {initialerrors:5d} {initialacc:.4f} " "final: {finalerrors:5d} {finalacc:.4f} ".format(**train_stats)) weighted_testcounts = Counter() for (tid, score) in zip(tids, testscores): weighted_testcounts[tid] += score tottestscores = sum(testscores) head = "#ID | Score (test) | Score (train) | #Rules | Template" print(head, "\n", "-" * len(head), sep="") test_tplscores = sorted(weighted_testcounts.items(), key=det_tplsort, reverse=True) for (tid, testscore) in test_tplscores: s = "{0:s} |{1:5d} {2:6.3f} | {3:4d} {4:.3f} |{5:4d} {6:.3f} | {7:s}".format( tid, testscore, testscore/tottestscores, weighted_traincounts[tid], weighted_traincounts[tid]/tottrainscores, template_counts[tid], template_counts[tid]/len(tids), Template.ALLTEMPLATES[int(tid)], ) print(s) def print_unused_templates(): usedtpls = set(int(tid) for tid in tids) unused = [(tid, tpl) for (tid, tpl) in enumerate(Template.ALLTEMPLATES) if tid not in usedtpls] print("UNUSED TEMPLATES ({0})".format(len(unused))) for (tid, tpl) in unused: print("{0:03d} {1:s}".format(tid, str(tpl))) if test_stats is None: print_train_stats() else: print_testtrain_stats() print() if printunused: print_unused_templates() print() def batch_tag_incremental(self, sequences, gold): """ Tags by applying each rule to the entire corpus (rather than all rules to a single sequence). The point is to collect statistics on the test set for individual rules. NOTE: This is inefficient (does not build any index, so will traverse the entire corpus N times for N rules) -- usually you would not care about statistics for individual rules and thus use batch_tag() instead :param sequences: lists of token sequences (sentences, in some applications) to be tagged :type sequences: list of list of strings :param gold: the gold standard :type gold: list of list of strings :returns: tuple of (tagged_sequences, ordered list of rule scores (one for each rule)) """ def counterrors(xs): return sum(t[1] != g[1] for pair in zip(xs, gold) for (t, g) in zip(*pair)) testing_stats = {} testing_stats['tokencount'] = sum(len(t) for t in sequences) testing_stats['sequencecount'] = len(sequences) tagged_tokenses = [self._initial_tagger.tag(tokens) for tokens in sequences] testing_stats['initialerrors'] = counterrors(tagged_tokenses) testing_stats['initialacc'] = 1 - testing_stats['initialerrors']/testing_stats['tokencount'] # Apply each rule to the entire corpus, in order errors = [testing_stats['initialerrors']] for rule in self._rules: for tagged_tokens in tagged_tokenses: rule.apply(tagged_tokens) errors.append(counterrors(tagged_tokenses)) testing_stats['rulescores'] = [err0 - err1 for (err0, err1) in zip(errors, errors[1:])] testing_stats['finalerrors'] = errors[-1] testing_stats['finalacc'] = 1 - testing_stats['finalerrors']/testing_stats['tokencount'] return (tagged_tokenses, testing_stats)
37.941176
107
0.57631
1
2.1666
[ 0.023922694846987724, 0.03744107857346535, -0.01735978201031685, 0.009717326611280441, 0.014447449706494808, 0.008799134753644466, 0.011564847081899643, -0.012722554616630077, -0.10069355368614197, -0.01123243011534214, 0.0018600280163809657, 0.031606487929821014, 0.022533362731337547, -0.01448508258908987, 0.012755969539284706, -0.016801264137029648, 0.05119263380765915, -0.002587813651189208, -0.0045071979984641075, 0.041997745633125305, -0.02797231264412403, -0.02560335397720337, 0.007493599317967892, 0.010907727293670177, -0.03769749030470848, 0.02514028176665306, 0.04412822052836418, 0.0159369558095932, -0.0580613799393177, -0.03231532871723175, -0.006231897510588169, -0.017769983038306236, 0.01312688086181879, 0.0008166574989445508, -0.009966258890926838, 0.013116191141307354, 0.03158751130104065, -0.07687798142433167, -0.02315637841820717, 0.016864927485585213, 0.04918279871344566, 0.04894334077835083, -0.010802238248288631, -0.07462616264820099, 0.00659947469830513, -0.03662039712071419, 0.01542035024613142, -0.06433096528053284, 0.07200050354003906, -0.0581187829375267, 0.04534316062927246, -0.010403992608189583, -0.007404204923659563, -0.045894622802734375, 0.011198618449270725, 0.016009584069252014, -0.0013900181511417031, 0.060649190098047256, -0.00988429319113493, 0.028860164806246758, -0.04687637835741043, 0.02327580191195011, 0.018882734701037407, -0.011387749575078487, -0.025722626596689224, -0.0006168128456920385, -0.005622874479740858, 0.003569455351680517, 0.04119677469134331, 0.0036692472640424967, 0.007517105434089899, -0.04104592278599739, -0.008107825182378292, 0.03294261917471886, 0.03952096775174141, 0.013935033231973648, -0.0035614497028291225, -0.03981007635593414, -0.007676014211028814, 0.0017863718094304204, 0.005930486600846052, 0.045457709580659866, 0.011573066003620625, -0.05166902393102646, 0.02421828731894493, -0.010068598203361034, 0.03551687300205231, -0.028857845813035965, 0.038593001663684845, -0.01739906519651413, -0.031656067818403244, -0.020003464072942734, -0.037073370069265366, 0.007324220146983862, -0.032835692167282104, -0.04191169515252113, -0.0040155453607439995, 0.03699673339724541, 0.009882453829050064, 0.011382143013179302, 0.025810951367020607, -0.0015156904701143503, 0.009454580023884773, -0.0027644147630780935, -0.029801174998283386, 0.004948538728058338, 0.03917919471859932, 0.014576392248272896, -0.022926241159439087, -0.041165247559547424, 0.07087354362010956, -0.020031893625855446, -0.0564444437623024, -0.04645509645342827, -0.0591435506939888, 0.021770242601633072, 0.03915746882557869, 0.055552151054143906, 0.0012800970580428839, 0.014115083031356335, 0.04310038313269615, -0.0023875157348811626, -0.023841291666030884, 0.008777132257819176, 0.014700262807309628, 0.008505408652126789, -0.04651030898094177, -0.0724957287311554, -0.02744949795305729, -0.015705300495028496, -0.013206509873270988, 0.05242184177041054, 0.01831996999680996, 0.0009668659185990691, -0.028936069458723068, -0.008460106328129768, -0.002307204995304346, -0.048779942095279694, -0.03043670579791069, -0.03435366228222847, 0.013686524704098701, 0.043176982551813126, -0.014093237929046154, -0.022398050874471664, -0.019712934270501137, -0.02949441783130169, -0.006657830439507961, 0.02225411683320999, -0.044907424598932266, -0.017110217362642288, 0.03576238080859184, 0.02591809071600437, -0.02186509035527706, -0.015648990869522095, 0.005798070225864649, 0.037195734679698944, -0.00020160872372798622, -0.02777666226029396, -0.04243917763233185, -0.005856132134795189, -0.009651022963225842, -0.009195934049785137, -0.02264411561191082, 0.0139088686555624, 0.055854540318250656, 0.01635696366429329, -0.007360721006989479, 0.02114992029964924, -0.0012633992591872811, -0.03280188515782356, -0.012491878122091293, 0.002960975980386138, 0.009487973526120186, 0.011109547689557076, 0.02411767654120922, -0.039326492697000504, 0.040908172726631165, -0.013123637065291405, 0.010908219031989574, 0.021342962980270386, -0.009901895187795162, 0.01290314830839634, -0.002970886416733265, 0.02100246213376522, -0.007392969913780689, 0.06950857490301132, -0.017043767496943474, 0.007767358794808388, 0.012541264295578003, 0.03435578569769859, -0.016785677522420883, 0.009464463219046593, 0.03826691210269928, 0.015998441725969315, 0.010826893150806427, -0.03181275352835655, -0.0003834978269878775, 0.036230817437171936, 0.007326978258788586, 0.038597919046878815, 0.042338110506534576, 0.035541899502277374, 0.019555941224098206, 0.032164786010980606, 0.0373673290014267, 0.05558762699365616, -0.3937673270702362, 0.022970188409090042, -0.015030484646558762, -0.02577619068324566, -0.0015430141938850284, -0.012770941480994225, -0.0732060968875885, 0.0237343180924654, -0.014322787523269653, 0.04883477836847305, 0.008033248595893383, 0.04192906245589256, -0.008160242810845375, -0.06531087309122086, 0.02134270966053009, -0.006991513539105654, 0.035847701132297516, 0.049586765468120575, -0.03500824421644211, 0.021962929517030716, 0.002850340446457267, -0.07928543537855148, -0.04044952616095543, -0.046276725828647614, -0.043398138135671616, -0.006105916108936071, 0.05151114985346794, -0.03808354586362839, 0.0005972195649519563, -0.018259627744555473, 0.01972907781600952, 0.022248977795243263, 0.0879053920507431, -0.004628831520676613, -0.005930676590651274, 0.01641811802983284, -0.004046054556965828, -0.01779009774327278, 0.010662650689482689, -0.0030536961276084185, -0.02784816361963749, -0.0058038560673594475, 0.015343144536018372, -0.02834591642022133, -0.02410365827381611, 0.09150596708059311, 0.005343871656805277, -0.005807355511933565, 0.02878929302096367, 0.03306897357106209, -0.022089455276727676, 0.024772455915808678, 0.016435673460364342, -0.0026665772311389446, 0.020733844488859177, -0.03846801072359085, 0.029157647863030434, -0.007290570065379143, -0.023884925991296768, -0.02673296630382538, -0.02657289430499077, -0.07259383052587509, -0.04471401870250702, 0.022296812385320663, -0.0920775756239891, -0.0013175959466025233, 0.056817032396793365, -0.06684168428182602, 0.03458353132009506, 0.013355562463402748, 0.017495673149824142, -0.022148266434669495, -0.09205009043216705, -0.04239708185195923, -0.008077148348093033, -0.00004893522782367654, 0.016733704134821892, -0.03705383464694023, -0.04306173324584961, 0.026635831221938133, 0.03206469118595123, -0.019530393183231354, 0.057842571288347244, 0.026125818490982056, 0.013871561735868454, -0.04677017405629158, -0.0551336295902729, 0.00830277893692255, -0.050577037036418915, 0.003846775973215699, -0.010334252379834652, 0.019772635772824287, -0.008601449429988861, -0.015309767797589302, -0.010533868335187435, 0.009762777015566826, 0.02384253218770027, 0.018700899556279182, 0.014384605921804905, -0.0143923070281744, 0.03219352662563324, -0.051557574421167374, -0.05331785976886749, -0.05999608337879181, -0.0008067719172686338, 0.018442310392856598, -0.022712675854563713, 0.019381627440452576, -0.04584995284676552, 0.0359991118311882, -0.04036478325724602, -0.026292767375707626, -0.08412977308034897, -0.02577592059969902, -0.018677430227398872, -0.0393594428896904, 0.03357284516096115, -0.026963455602526665, -0.017571378499269485, -0.032562147825956345, -0.059862859547138214, -0.017802178859710693, -0.0201911311596632, 0.0477258525788784, -0.008185713551938534, 0.001053932006470859, -0.023915112018585205, 0.0045270235277712345, -0.017870087176561356, 0.07560665905475616, -0.021812789142131805, -0.047341685742139816, -0.007150275632739067, 0.012136350385844707, -0.058267924934625626, 0.0351562425494194, 0.016900068148970604, -0.017708271741867065, -0.029179176315665245, 0.004287504591047764, -0.0000871699521667324, 0.03332424536347389, 0.04306631535291672, -0.0005888260202482343, -0.005312720779329538, 0.05236947908997536, -0.011496617458760738, 0.03836745023727417, 0.00039255229057744145, 0.028720716014504433, 0.07676379382610321, -0.037120990455150604, -0.008836455643177032, -0.006746786646544933, 0.001391765777952969, 0.005806879606097937, -0.03284953162074089, 0.05598028749227524, 0.0007234858348965645, 0.06827657669782639, 0.026570439338684082, -0.0865180566906929, 0.017568392679095268, -0.053020577877759933, 0.03199022263288498, 0.004368712194263935, 0.01572994515299797, 0.09360168129205704, -0.023923207074403763, -0.035743486136198044, 0.07296095788478851, -0.034233663231134415, -0.0013167420402169228, 0.01771886646747589, -0.07377931475639343, -0.03704109042882919, -0.01506882905960083, 0.020953716710209846, -0.0017583033768460155, -0.011468659155070782, 0.053237494081258774, -0.008656911551952362, 0.024287035688757896, -0.01580660231411457, -0.02633657678961754, -0.04597166180610657, -0.002583491848781705, -0.023210635408759117, -0.04309398680925369, 0.01848015934228897, -0.016030076891183853, 0.06457909941673279, -0.011943306773900986, -0.0417778380215168, -0.08970503509044647, -0.03415333107113838, 0.028279844671487808, 0.0013850663090124726, -0.05865028128027916, 0.003042310941964388, -0.013421903364360332, -0.025730757042765617, 0.022065185010433197, 0.010045385919511318, -0.0401342548429966, 0.06009909510612488, -0.0034326736349612474, 0.04457550123333931, 0.03527582809329033, 0.008839434012770653, 0.0032329377718269825, 0.00860660895705223, 0.039498742669820786, 0.03469220548868179, 0.0551556758582592, -0.027192818000912666, 0.037777408957481384, 0.028092648833990097, 0.05376070737838745, -0.008294638246297836, 0.04163912683725357, -0.03991334140300751, 0.012396504171192646, 0.00691336952149868, -0.013545720838010311, -0.01114738080650568, -0.011129720136523247, 0.002309958916157484, -0.01024110708385706, -0.04991826415061951, -0.03422538936138153, -0.004364888183772564, -0.015463379211723804, -0.03289435803890228, -0.01872829534113407, 0.006176085211336613, 0.029513448476791382, 0.02539113350212574, -0.008739005774259567, -0.010389450006186962, 0.04955017566680908, -0.03648340329527855, 0.003340521128848195, 0.020552046597003937, 0.003882698016241193, 0.05481625348329544, -0.009705507196485996, -0.056630320847034454, -0.024502111598849297, -0.012256800197064877, 0.0126798739656806, -0.04435896873474121, 0.023597685620188713, -0.02562977373600006, -0.0005784801905974746, 0.041233841329813004, -0.030900785699486732, -0.008433635346591473, -0.037240952253341675, 0.034878455102443695, 0.06370773166418076, 0.0012235570466145873, 0.03508446738123894, -0.00974923837929964, 0.024548830464482307, 0.017468327656388283, 0.0695863589644432, -0.043217986822128296, -0.007889872416853905, -0.039892297238111496, -0.021490013226866722, -0.021066099405288696, -0.014719237573444843, 0.0051443628035485744, 0.00436767004430294, -0.02007628232240677, -0.0011701001785695553, -0.03986239433288574, 0.036601219326257706, -0.047078538686037064, -0.06213591247797012, 0.04473576322197914, 0.04223260283470154, 0.06281367689371109, -0.02707478404045105, 0.04820600152015686, -0.041741471737623215, -0.037835728377103806, -0.037243664264678955, -0.020225800573825836, 0.045821722596883774, -0.004008326679468155, 0.05962201952934265, 0.013788986951112747, 0.03839275613427162, -0.010614395141601562, -0.021754834800958633, -0.003636582987383008, 0.01260125357657671, -0.035661958158016205, 0.06171010807156563, -0.027405820786952972, -0.015214290469884872, -0.0027880510315299034, 0.0008408083231188357, -0.02436327375471592, 0.002183932112529874, 0.0497802197933197, -0.0019822074100375175, -0.02180105820298195, 0.020238684490323067, 0.031234269961714745, -0.01594453863799572, 0.010404395870864391, 0.007964476011693478, 0.02177903987467289, 0.049970414489507675, -0.005604925565421581, -0.0033953674137592316, -0.03618674725294113, -0.03150311857461929, 0.005365167744457722, 0.024249771609902382, 0.010273580439388752, 0.021784985437989235, -0.025279106572270393, -0.040915679186582565, -0.02937869355082512, -0.04347659647464752, -0.06053995341062546, 0.0012597083114087582, -0.04759657755494118, 0.021269960328936577, 0.009054094552993774, 0.025320909917354584, 0.03493105620145798, 0.01366809569299221, 0.006312742829322815, 0.026314627379179, 0.007502623833715916, 0.026828080415725708, -0.06563078612089157, -0.09853576868772507, -0.0024352362379431725, 0.018867092207074165, -0.015156729146838188, -0.08174784481525421, 0.056202325969934464, 0.03835580125451088, -0.05535441264510155, 0.005255654454231262, -0.013468819670379162, -0.009204214438796043, 0.02652813494205475, -0.012341972440481186, 0.05215181037783623, 0.010150188580155373, 0.015010908246040344, -0.01154601015150547, 0.006009869277477264, 0.011971449479460716, 0.004503261297941208, -0.02224372699856758, 0.034077953547239304, -0.00714452750980854, -0.02430988848209381, 0.009948819875717163, -0.005320969503372908, 0.007088173646479845, -0.010008369572460651, -0.03651312366127968, -0.0450296625494957, 0.03285779058933258, 0.044010136276483536, -0.0025016488507390022, 0.011593339033424854, 0.04246021434664726, 0.0138953672721982, -0.030473630875349045, -0.0298759825527668, 0.0034825201146304607, 0.0369509719312191, 0.008271033875644207, 0.04921378940343857, -0.024080587550997734, 0.053718868643045425, -0.024701273068785667, 0.0017013198230415583, 0.00030649942345917225, 0.012753625400364399, 0.07168518751859665, 0.009260098449885845, 0.01077593956142664, 0.07158941775560379, -0.05228486657142639, 0.020621752366423607, -0.0026929171290248632, -0.04002447798848152, 0.029972126707434654, -0.006257734261453152, 0.037449564784765244, 0.015297763049602509, -0.01904948614537716, -0.02634027972817421, -0.0144485579803586, -0.06362047046422958, 0.08479774743318558, 0.029276572167873383, 0.02868584357202053, 0.016851305961608887, -0.04539161175489426, 0.046173568814992905, -0.05277078226208687, 0.011158832348883152, 0.029317066073417664, 0.057248301804065704, 0.007394708693027496, 0.028262410312891006, -0.07415806502103806, -0.018802054226398468, 0.03692103549838066, 0.0696113333106041, 0.051785677671432495, 0.03726569563150406, 0.0013448460958898067, 0.03480350971221924, -0.0693037286400795, -0.01935444585978985, -0.024219444021582603, 0.013486254028975964, -0.017696138471364975, -0.02991640195250511, -0.008557540364563465, -0.04302387684583664, -0.007360304705798626, -0.02204224467277527, -0.020018115639686584, -0.053947463631629944, -0.010624577291309834, -0.043141257017850876, -0.017197538167238235, 0.013970752246677876, -0.04039856046438217, 0.0212404765188694, -0.03837819769978523, -0.0725114494562149, 0.016826311126351357, 0.002288359683007002, -0.005219858139753342, -0.04534822702407837, 0.007513327524065971, -0.0017041688552126288, -0.02229217253625393, 0.03208225592970848, -0.0008074345532804728, -0.04300890862941742, 0.06438536196947098, 0.0019832528196275234, 0.00011966466263402253, -0.018441110849380493, 0.011259930208325386, -0.003373356070369482, 0.06634838134050369, -0.029831552878022194, 0.00023711576068308204, 0.03212616220116615, 0.022947397083044052, -0.010218034498393536, -0.018739910796284676, -0.03605484589934349, -0.08602071553468704, 0.0512760728597641, 0.03693948686122894, -0.03284476697444916, 0.012448805384337902, 0.028032567352056503, -0.050818029791116714, 0.026266474276781082, -0.024842245504260063, -0.027051933109760284, 0.038720861077308655, -0.0009670836152508855, 0.03935134783387184, -0.002261362038552761, 0.0039581009186804295, -0.048366375267505646, -0.0003740896936506033, -0.03475169092416763, 0.04120194911956787, -0.017278166487812996, -0.02964087948203087, 0.0018817794043570757, 0.0562281608581543, -0.015938756987452507, 0.051210567355155945, -0.014576155692338943, 0.013902558945119381, -0.027903545647859573, 0.03917345032095909, -0.03779872879385948, -0.008925997652113438, 0.010060321539640427, -0.03201117739081383, 0.013988685794174671, -0.01654941216111183, -0.0015084510669112206, -0.007005620282143354, 0.026670357212424278, 0.040371451526880264, -0.0024716705083847046, 0.007450324483215809, 0.0016504627419635653, 0.019893983379006386, 0.0011117690009996295, 0.017344558611512184, -0.00047468309639953077, 0.03553958982229233, -0.028337810188531876, 0.007829939015209675, -0.025410499423742294, -0.013674581423401833, -0.023542042821645737, -0.04524517059326172, -0.017280323430895805, -0.03213098272681236, 0.034072395414114, -0.012500389479100704, -0.014154416508972645, 0.024306753650307655, 0.031724754720926285, 0.045963916927576065, -0.000151717962580733, -0.006719131488353014, 0.019497420638799667, 0.021069465205073357, -0.018932197242975235, -0.013268182054162025, -0.014727316796779633, -0.053653646260499954, 0.0010142766404896975, -0.002474525012075901, 0.005411677528172731, -0.03493889793753624, -0.03473421186208725, 0.026403216645121574, 0.01732100360095501, 0.03442387282848358, 0.0033456149976700544, 0.03679355978965759, -0.010973910801112652, 0.005909366998821497, -0.02688138373196125, -0.05558915063738823, 0.04330579191446304, 0.03450228273868561, -0.009788349270820618, -0.01248440146446228, 0.12228310853242874, -0.031339824199676514, -0.001737121376208961, 0.03213781863451004, 0.029006490483880043 ]
8aa1f2759e7626cdb380e9f05aa634b55bf1bbc2
7,812
py
Python
superglue_parsers/wsc.py
agentsolaris/xlnn
0ab07d1ac526cadc2964379aef0a44927e0618eb
[ "Apache-2.0" ]
null
null
null
superglue_parsers/wsc.py
agentsolaris/xlnn
0ab07d1ac526cadc2964379aef0a44927e0618eb
[ "Apache-2.0" ]
null
null
null
superglue_parsers/wsc.py
agentsolaris/xlnn
0ab07d1ac526cadc2964379aef0a44927e0618eb
[ "Apache-2.0" ]
null
null
null
import json import logging import sys import numpy as np import torch from task_config import SuperGLUE_LABEL_MAPPING from snorkel.mtl.data import MultitaskDataset sys.path.append("..") # Adds higher directory to python modules path. logger = logging.getLogger(__name__) TASK_NAME = "WSC" def get_char_index(text, span_text, span_index): tokens = text.replace("\n", " ").lower().split(" ") span_tokens = span_text.replace("\n", " ").lower().split(" ") # Token exact match if tokens[span_index : span_index + len(span_tokens)] == span_tokens: st = len(" ".join(tokens[:span_index])) + 1 if span_index != 0 else 0 ed = st + len(span_text) return st, ed if span_index < len(tokens): # Token fuzzy match with extra chars char_in_text = " ".join(tokens[span_index : span_index + len(span_tokens)]) char_in_span = " ".join(span_tokens) if char_in_text.startswith(char_in_span): st = len(" ".join(tokens[:span_index])) + 1 if span_index != 0 else 0 # ed = st + len(char_in_span) ed = st + len(char_in_text) return st, ed # Token fuzzy match with extra chars char_in_text = " ".join(tokens[span_index : span_index + len(span_tokens)]) char_in_span = " ".join(span_tokens) if char_in_span.startswith(char_in_text): st = len(" ".join(tokens[:span_index])) + 1 if span_index != 0 else 0 ed = st + len(char_in_text) return st, ed # Index out of range if span_index >= len(tokens): span_index -= 10 # Token fuzzy match with different position for idx in range(span_index, len(tokens)): if tokens[idx : idx + len(span_tokens)] == span_tokens: st = len(" ".join(tokens[:idx])) + 1 if idx != 0 else 0 ed = st + len(span_text) return st, ed # Token best fuzzy match with different position for idx in range(span_index, len(tokens)): if tokens[idx] == span_tokens[0]: for length in range(1, len(span_tokens)): if tokens[idx : idx + length] != span_tokens[:length]: st = len(" ".join(tokens[:idx])) + 1 if idx != 0 else 0 ed = st + len(" ".join(span_tokens[: length - 1])) return st, ed return None def parse(jsonl_path, tokenizer, max_data_samples, max_sequence_length): logger.info(f"Loading data from {jsonl_path}.") rows = [json.loads(row) for row in open(jsonl_path, encoding="utf-8")] for i in range(2): logger.info(f"Sample {i}: {rows[i]}") # Truncate to max_data_samples if max_data_samples: rows = rows[:max_data_samples] logger.info(f"Truncating to {max_data_samples} samples.") # sentence text sentences = [] # span1 span1s = [] # span2 span2s = [] # span1 idx span1_idxs = [] # span2 idx span2_idxs = [] # label labels = [] token1_idxs = [] token2_idxs = [] xlnet_tokens = [] xlnet_token_ids = [] xlnet_token_masks = [] xlnet_token_segments = [] # Check the maximum token length max_len = -1 for row in rows: index = row["idx"] text = row["text"] span1_text = row["target"]["span1_text"] span2_text = row["target"]["span2_text"] span1_index = row["target"]["span1_index"] span2_index = row["target"]["span2_index"] label = row["label"] if "label" in row else True span1_char_index = get_char_index(text, span1_text, span1_index) span2_char_index = get_char_index(text, span2_text, span2_index) assert span1_char_index is not None, f"Check example {id} in {jsonl_path}" assert span2_char_index is not None, f"Check example {id} in {jsonl_path}" # Tokenize sentences xlnet_tokens_sub1 = tokenizer.tokenize( text[: min(span1_char_index[0], span2_char_index[0])] ) if span1_char_index[0] < span2_char_index[0]: xlnet_tokens_sub2 = tokenizer.tokenize( text[span1_char_index[0] : span1_char_index[1]] ) token1_idx = [ len(xlnet_tokens_sub1) + 1, len(xlnet_tokens_sub1) + len(xlnet_tokens_sub2), ] else: xlnet_tokens_sub2 = tokenizer.tokenize( text[span2_char_index[0] : span2_char_index[1]] ) token2_idx = [ len(xlnet_tokens_sub1) + 1, len(xlnet_tokens_sub1) + len(xlnet_tokens_sub2), ] sub3_st = ( span1_char_index[1] if span1_char_index[0] < span2_char_index[0] else span2_char_index[1] ) sub3_ed = ( span1_char_index[0] if span1_char_index[0] > span2_char_index[0] else span2_char_index[0] ) xlnet_tokens_sub3 = tokenizer.tokenize(text[sub3_st:sub3_ed]) if span1_char_index[0] < span2_char_index[0]: xlnet_tokens_sub4 = tokenizer.tokenize( text[span2_char_index[0] : span2_char_index[1]] ) cur_len = ( len(xlnet_tokens_sub1) + len(xlnet_tokens_sub2) + len(xlnet_tokens_sub3) ) token2_idx = [cur_len + 1, cur_len + len(xlnet_tokens_sub4)] else: xlnet_tokens_sub4 = tokenizer.tokenize( text[span1_char_index[0] : span1_char_index[1]] ) cur_len = ( len(xlnet_tokens_sub1) + len(xlnet_tokens_sub2) + len(xlnet_tokens_sub3) ) token1_idx = [cur_len + 1, cur_len + len(xlnet_tokens_sub4)] if span1_char_index[0] < span2_char_index[0]: xlnet_tokens_sub5 = tokenizer.tokenize(text[span2_char_index[1] :]) else: xlnet_tokens_sub5 = tokenizer.tokenize(text[span1_char_index[1] :]) tokens = ( ["[CLS]"] + xlnet_tokens_sub1 + xlnet_tokens_sub2 + xlnet_tokens_sub3 + xlnet_tokens_sub4 + xlnet_tokens_sub5 + ["[SEP]"] ) if len(tokens) > max_len: max_len = len(tokens) token_ids = tokenizer.convert_tokens_to_ids(tokens) token_segments = [0] * len(token_ids) # Generate mask where 1 for real tokens and 0 for padding tokens token_masks = [1] * len(token_ids) token1_idxs.append(token1_idx) token2_idxs.append(token2_idx) sentences.append(text) span1s.append(span1_text) span2s.append(span2_text) span1_idxs.append(span1_index) span2_idxs.append(span2_index) labels.append(SuperGLUE_LABEL_MAPPING[TASK_NAME][label]) xlnet_tokens.append(tokens) xlnet_token_ids.append(torch.LongTensor(token_ids)) xlnet_token_masks.append(torch.LongTensor(token_masks)) xlnet_token_segments.append(torch.LongTensor(token_segments)) token1_idxs = torch.from_numpy(np.array(token1_idxs)) token2_idxs = torch.from_numpy(np.array(token2_idxs)) labels = torch.from_numpy(np.array(labels)) logger.info(f"Max token len {max_len}") return MultitaskDataset( name="SuperGLUE", X_dict={ "sentence": sentences, "span1": span1s, "span2": span2s, "span1_idx": span1_idxs, "span2_idx": span2_idxs, "token1_idx": token1_idxs, "token2_idx": token2_idxs, "tokens": xlnet_tokens, "token_ids": xlnet_token_ids, "token_masks": xlnet_token_masks, "token_segments": xlnet_token_segments, }, Y_dict={"labels": labels}, )
33.101695
88
0.592422
1
2.1966
[ -0.03932078555226326, 0.028799811378121376, 0.021235954016447067, 0.019948510453104973, -0.003265823470428586, 0.0049094888381659985, -0.036105237901210785, -0.01389207225292921, -0.009951534681022167, 0.018200714141130447, 0.001849137363024056, 0.015429992228746414, 0.06518376618623734, -0.0403098501265049, -0.03374698758125305, -0.00286486791446805, 0.06196547672152519, 0.0036257074680179358, -0.021436791867017746, 0.010568048804998398, -0.010360845364630222, 0.0060048275627195835, -0.028323469683527946, -0.004669026471674442, 0.019519416615366936, 0.03261292725801468, 0.056243252009153366, -0.015554363839328289, 0.02846347913146019, -0.0138685442507267, -0.021266141906380653, -0.01402055099606514, -0.00827538501471281, 0.013932709582149982, -0.002148871775716543, -0.003714602906256914, -0.002636789111420512, -0.022644786164164543, 0.018858976662158966, 0.015412993729114532, 0.009967179968953133, -0.03643745183944702, -0.019686274230480194, -0.0200518649071455, -0.0072379810735583305, 0.00549705047160387, -0.00480831740424037, 0.0018557662842795253, 0.0014110744232311845, 0.016353748738765717, -0.002408708678558469, 0.03350035846233368, -0.005865102633833885, -0.0499456524848938, -0.006056328769773245, -0.039408598095178604, -0.013025576248764992, 0.028329472988843918, -0.03890228644013405, -0.0018257639603689313, -0.021034350618720055, -0.013841855339705944, 0.0024377633817493916, -0.024762248620390892, 0.00787375122308731, 0.008278073742985725, -0.02120610512793064, -0.02040412835776806, -0.057102080434560776, -0.01411435753107071, -0.011262922547757626, -0.03536266088485718, -0.014146033674478531, 0.0635480135679245, 0.001991111785173416, 0.0016301184659823775, -0.017629744485020638, -0.01652875356376171, -0.02195143885910511, 0.005436680279672146, -0.012814943678677082, 0.04818512126803398, 0.012379725463688374, -0.01504475437104702, -0.02867352031171322, 0.038153279572725296, 0.05177580565214157, -0.012467180378735065, 0.020241575315594673, 0.0201851949095726, -0.056325513869524, 0.0068731652572751045, -0.029880601912736893, 0.0012386298039928079, 0.01987970434129238, -0.03847483545541763, 0.002338736318051815, -0.004755547735840082, 0.017471708357334137, 0.03752272203564644, -0.0200710017234087, -0.052886754274368286, 0.013695592060685158, -0.00749389361590147, 0.013842473737895489, 0.0014060079120099545, -0.033702049404382706, -0.001974167302250862, -0.004010443110018969, -0.030121400952339172, -0.03593003749847412, -0.011473586782813072, 0.03694857284426689, -0.01285767275840044, 0.003018858376890421, -0.012396167032420635, 0.006029672920703888, -0.010552906431257725, -0.009195098653435707, 0.08482745289802551, 0.020158588886260986, 0.017430203035473824, 0.006120229605585337, -0.02086055651307106, -0.043315861374139786, 0.06543039530515671, 0.007997904904186726, -0.004629970993846655, 0.03122790716588497, 0.00904135312885046, 0.01103224791586399, -0.0007935068570077419, -0.008381633087992668, 0.007901242934167385, -0.006838705390691757, -0.027389058843255043, -0.029155364260077477, 0.059012271463871, -0.026949821040034294, -0.005206585396081209, 0.013209769502282143, -0.04411657527089119, 0.008059423416852951, 0.005906257312744856, 0.01417439617216587, -0.03990721330046654, -0.0075102453120052814, -0.013168515637516975, -0.02187419682741165, -0.026528455317020416, 0.019444046542048454, -0.014655737206339836, -0.016656547784805298, 0.03053879924118519, -0.00014730940165463835, -0.0050430637784302235, -0.020266247913241386, -0.03099854663014412, -0.023387746885418892, -0.014728523790836334, -0.004109812900424004, -0.00173420540522784, -0.025061985477805138, 0.04123777151107788, -0.013171292841434479, 0.03249390795826912, -0.03111676312983036, 0.020519006997346878, -0.030108535662293434, 0.014218883588910103, 0.02239389903843403, -0.012943340465426445, -0.0012205017264932394, -0.0002369337307754904, -0.007343658246099949, 0.012799852527678013, 0.054209109395742416, 0.00547732412815094, 0.006454419810324907, -0.02902264893054962, 0.0032729776576161385, 0.004760342184454203, 0.03503621742129326, 0.027179954573512077, 0.011339159682393074, -0.02144608087837696, -0.055412761867046356, -0.007947791367769241, 0.02205108478665352, -0.0330885648727417, -0.022581353783607483, 0.01843111775815487, -0.02240736410021782, -0.02659708261489868, 0.041249122470617294, 0.02006625570356846, -0.02835851162672043, 0.026561804115772247, -0.02776322327554226, -0.00985188689082861, -0.00018526907660998404, -0.002750313375145197, 0.002479873364791274, 0.007469171658158302, -0.0026749051176011562, -0.024344230070710182, -0.7351183891296387, 0.04362430050969124, -0.003276529023423791, -0.025955505669116974, 0.01407763734459877, 0.05557572841644287, -0.03515436500310898, 0.0006915658013895154, -0.02603313699364662, -0.01864205300807953, -0.022560223937034607, -0.019259905442595482, -0.034347228705883026, 0.026051338762044907, 0.029475344344973564, -0.01099685300141573, 0.030893277376890182, -0.02668779157102108, -0.016926288604736328, 0.02030337043106556, 0.02038872055709362, -0.01639021560549736, -0.026741404086351395, -0.006597548723220825, 0.016368700191378593, 0.00955966580659151, 0.009793441742658615, -0.00469624437391758, -0.020230688154697418, -0.016659772023558617, -0.020113669335842133, -0.010914632119238377, 0.03619668260216713, -0.028133459389209747, 0.014154578559100628, -0.008654000237584114, -0.01936962828040123, -0.011473389342427254, -0.04494373872876167, -0.003226662753149867, -0.010500039905309677, -0.0177623238414526, -0.02005315199494362, -0.03726422041654587, -0.04503728821873665, -0.009677764028310776, -0.007670942693948746, -0.03093927726149559, -0.0029450070578604937, 0.04766295477747917, -0.027622351422905922, 0.043986327946186066, 0.0622066855430603, -0.008886313997209072, 0.000032322346669388935, 0.006978113669902086, -0.019164787605404854, -0.034289319068193436, -0.02335255965590477, 0.0024853183422237635, 0.006730959750711918, 0.009567249566316605, -0.0100175179541111, 0.04663374647498131, -0.01882137916982174, 0.007978822104632854, 0.0915660709142685, -0.03491373732686043, -0.019866008311510086, 0.016915716230869293, -0.01685921475291252, -0.01050540991127491, -0.05252005532383919, 0.09562282264232635, -0.02382865734398365, -0.007654694374650717, -0.02403135597705841, 0.025164101272821426, -0.005967491772025824, 0.005966642871499062, 0.014956848695874214, -0.018335677683353424, 0.013601257465779781, 0.0011533768847584724, -0.05714118853211403, 0.010460425168275833, 0.019168291240930557, 0.004944648593664169, 0.012476158328354359, 0.020076481625437737, 0.0007184401620179415, 0.03973698616027832, 0.020475827157497406, -0.00025855892454274, 0.0005353699089027941, -0.00484286155551672, 0.008582198061048985, 0.046286728233098984, 0.015355030074715614, -0.005881612189114094, -0.04377477243542671, -0.0040163304656744, 0.011015748605132103, -0.018178952857851982, -0.018255742266774178, 0.0112567488104105, -0.010213395580649376, 0.003260581521317363, -0.0005275352741591632, -0.06589579582214355, -0.010034564882516861, 0.0014062038389965892, -0.023535314947366714, 0.034747883677482605, 0.0007888357504270971, -0.01803644560277462, 0.01167144812643528, -0.039422959089279175, 0.026276543736457825, -0.017800400033593178, -0.00853774044662714, -0.012884804978966713, 0.0131556186825037, 0.029478050768375397, -0.01349955890327692, -0.011458112858235836, -0.045963820070028305, -0.008674304001033306, 0.026140347123146057, 0.021359559148550034, 0.01060868427157402, 0.008905827067792416, -0.00808993261307478, 0.009171612560749054, -0.03287114202976227, -0.0015271285083144903, -0.0002184340701205656, -0.012272623367607594, 0.014483458362519741, -0.010260654613375664, 0.019156960770487785, -0.024594005197286606, -0.016316404566168785, -0.0554703027009964, 0.003932674881070852, 0.0007617125520482659, 0.017405536025762558, -0.0010273618390783668, 0.0350709967315197, 0.012035418301820755, 0.013016274198889732, 0.036349788308143616, 0.015327400527894497, 0.01123828161507845, 0.030239365994930267, 0.015146845020353794, -0.052909236401319504, 0.0001599056995473802, 0.026301318779587746, 0.003827907145023346, 0.01013884972780943, -0.015473240055143833, 0.015565263107419014, 0.04633081704378128, -0.0014683323679491878, -0.014365287497639656, 0.013503328897058964, 0.06391254812479019, 0.01601606048643589, 0.06945423036813736, 0.02613411657512188, -0.00669952854514122, -0.0056208656169474125, -0.008491290733218193, -0.03101777285337448, 0.019282152876257896, -0.0024456230457872152, -0.006988973822444677, 0.011566562578082085, 0.007140807341784239, 0.00731752859428525, 0.0004593170597217977, -0.02173658460378647, -0.02042454108595848, 0.02155027538537979, 0.006984599865972996, -0.009626604616641998, 0.033366840332746506, 0.003309051040560007, -0.021861666813492775, 0.043911341577768326, -0.003184946021065116, -0.02168687991797924, 0.018867673352360725, -0.00954680796712637, -0.03097406029701233, -0.017069300636649132, -0.005070419050753117, 0.02041487582027912, -0.02030416578054428, -0.011905733495950699, 0.0028510333504527807, -0.008436239324510098, 0.0032052211463451385, 0.026976196095347404, 0.012750201858580112, -0.0006808390025980771, -0.021941538900136948, -0.01053764671087265, -0.021094102412462234, 0.018252963200211525, -0.05397739261388779, 0.020048419013619423, 0.004749615676701069, -0.006113886833190918, 0.04531513899564743, -0.050621066242456436, -0.0411539264023304, -0.01962025836110115, -0.021601831540465355, -0.011186381801962852, 0.00002528290860936977, 0.035315729677677155, 0.006757318042218685, -0.017107805237174034, -0.013415131717920303, -0.02128482423722744, 0.017271829769015312, -0.010105747729539871, -0.00530030345544219, 0.029099641367793083, 0.01595780998468399, -0.0037874931003898382, 0.002866290044039488, -0.02200065739452839, 0.013859743252396584, -0.019940365105867386, -0.02063305303454399, 0.0025364169850945473, -0.008139013312757015, 0.03992743417620659, -0.017491808161139488, -0.02858470007777214, 0.028073271736502647, -0.014865986071527004, 0.027604321017861366, -0.0003469412331469357, -0.014203461818397045, -0.0538397841155529, 0.010850735008716583, -0.014682786539196968, 0.018632251769304276, 0.011019052937626839, -0.006127417087554932, -0.00628705183044076, 0.03188258409500122, -0.014149057678878307, 0.0030137263238430023, -0.001868760446086526, 0.023641841486096382, -0.030264878645539284, 0.003899834817275405, 0.013690811581909657, 0.01840614154934883, 0.01974366046488285, 0.01435845997184515, 0.024842990562319756, -0.018156321719288826, 0.015126021578907967, -0.008992880582809448, 0.026391511783003807, -0.05000501126050949, -0.02197205275297165, -0.0035670027136802673, 0.011424471624195576, -0.005086647346615791, 0.042802970856428146, 0.000498327543027699, 0.004396427422761917, 0.07783345878124237, -0.012087173759937286, -0.016207760199904442, 0.04720935598015785, 0.024506546556949615, 0.02239116281270981, 0.01334906741976738, 0.01144843827933073, -0.009677080437541008, -0.05297044292092323, 0.010846039280295372, -0.007454292848706245, -0.06467776745557785, 0.0005423052934929729, 0.008586053736507893, -0.010290490463376045, 0.025912407785654068, -0.0006133985589258373, 0.002546187723055482, 0.03208605945110321, 0.009616432711482048, -0.001104832859709859, 0.01876513846218586, 0.0003463689354248345, -0.010462624952197075, -0.02280322276055813, -0.044011328369379044, 0.007511113304644823, 0.01830524206161499, 0.03556646406650543, 0.022070394828915596, 0.035055551677942276, -0.006114443298429251, 0.009864486753940582, -0.007560078985989094, 0.0009728024015203118, -0.0153880063444376, 0.036767978221178055, 0.011413483880460262, 0.04099820926785469, 0.0021313168108463287, -0.010947821661829948, 0.040951937437057495, -0.012508004903793335, 0.004979465622454882, -0.004632915835827589, -0.022085117176175117, -0.01731025241315365, -0.020938066765666008, 0.0009187269606627524, 0.00312364031560719, -0.02284553274512291, -0.012461156584322453, 0.01344467792659998, -0.014106005430221558, -0.012546752579510212, -0.010287187062203884, 0.029595784842967987, 0.02351074479520321, 0.03008217178285122, 0.00571764912456274, 0.05050717294216156, -0.00714400690048933, -0.015366347506642342, -0.011709739454090595, 0.008604677394032478, 0.003768815193325281, -0.0026315099094063044, 0.05843913555145264, 0.024163423106074333, 0.028210945427417755, -0.004100779537111521, 0.004431871697306633, 0.013918695040047169, 0.012642450630664825, 0.000046854063839418814, 0.008479838259518147, 0.00023193619563244283, 0.013588231056928635, 0.009999147616326809, -0.0048585752956569195, 0.016888486221432686, 0.025685302913188934, -0.0030220660846680403, -0.01903945580124855, 0.022888828068971634, -0.027202431112527847, 0.012471198104321957, -0.013970847241580486, -0.02088407799601555, -0.02490103803575039, -0.02047342248260975, -0.005485170986503363, -0.010009115561842918, 0.031171170994639397, 0.022977188229560852, 0.04295416548848152, 0.008839580230414867, -0.004347667563706636, 0.007344531361013651, -0.012009821832180023, 0.008324488997459412, -0.01060985866934061, 0.057741500437259674, -0.03145058453083038, 0.02531764656305313, -0.05719420313835144, 0.026459140703082085, -0.004024998750537634, -0.018244726583361626, 0.006079123821109533, 0.004481766372919083, 0.014863245189189911, 0.01911182329058647, 0.01636374182999134, -0.033325813710689545, -0.018189018592238426, -0.020666206255555153, -0.020087536424398422, -0.002862456487491727, 0.007948314771056175, 0.014864688739180565, 0.015767114236950874, -0.023937685415148735, -0.01594892516732216, 0.01183301955461502, -0.02537292055785656, 0.03860314190387726, 0.006354414392262697, 0.006210691295564175, -0.0023037700448185205, 0.01829621009528637, 0.02370862103998661, -0.01298313494771719, -0.03762187063694, 0.02104971557855606, -0.0195933748036623, -0.03281603008508682, 0.022058844566345215, -0.008001269772648811, 0.0027734215836972, -0.038689546287059784, 0.006237700581550598, -0.016111716628074646, -0.009387707337737083, 0.011397609487175941, 0.0076342010870575905, 0.019838925451040268, 0.013066797517240047, 0.008942670188844204, 0.030778028070926666, 0.0048466757871210575, -0.016844898462295532, -0.03792326897382736, 0.03552589565515518, 0.021748701110482216, -0.005115669220685959, 0.015401686541736126, -0.022021925076842308, -0.003814785508438945, 0.0019909439142793417, 0.02446744218468666, 0.008332199417054653, 0.021602608263492584, 0.03398666903376579, -0.005758654326200485, -0.022815126925706863, 0.039486777037382126, -0.020949821919202805, 0.016749849542975426, -0.027687478810548782, 0.02400094084441662, 0.0007968517020344734, -0.005704101175069809, 0.0032090716995298862, 0.023548832163214684, -0.0022538076154887676, 0.06332185119390488, 0.022664185613393784, -0.001617363654077053, 0.009081683121621609, 0.017670148983597755, -0.00013414616114459932, -0.0019624102860689163, 0.041905321180820465, 0.014507674612104893, 0.021841775625944138, -0.003698385087773204, -0.026068435981869698, -0.016798464581370354, -0.052323248237371445, -0.00009408895130036399, -0.009409033693373203, -0.006316774990409613, -0.020961500704288483, 0.012677235528826714, 0.027034113183617592, 0.012867482379078865, 0.006604929454624653, -0.0020921281538903713, 0.0012969383969902992, -0.04734579846262932, -0.001677568769082427, 0.02231653593480587, 0.019480980932712555, -0.001581266988068819, -0.013404959812760353, 0.0004322459571994841, 0.026805471628904343, 0.0003846893669106066, 0.022410394623875618, -0.04838614910840988, -0.02955004759132862, -0.010998926125466824, 0.031532302498817444, 0.005521632730960846, -0.039210304617881775, 0.02860960364341736, -0.003088138299062848, 0.049718327820301056, -0.006196067202836275, -0.016371600329875946, -0.024891313165426254, 0.006186916492879391, -0.04477083310484886, 0.030774828046560287, 0.01649523712694645, 0.08606307953596115, 0.008336137048900127, -0.01413918100297451, -0.011498645879328251, -0.04053009673953056, -0.02830636501312256, -0.044877421110868454, 0.004473456181585789, 0.008007096126675606, 0.02876036986708641, 0.004002647940069437, -0.060951266437768936, 0.01330244354903698, -0.017201973125338554, 0.005043433979153633, 0.03594280034303665, -0.03175254538655281, -0.03802890703082085, 0.012999261729419231, -0.020760299637913704, -0.017849063500761986, 0.0005410707672126591, 0.003712516510859132, 0.0017620158614590764, -0.021760525181889534, 0.003969275392591953, -0.021595828235149384, 0.005494141951203346, 0.022796031087636948, -0.005000719800591469, -0.004132408183068037, 0.06058500334620476, -0.026783067733049393, 0.0017435488989576697, 0.021792246028780937, 0.017091037705540657, 0.002724861027672887, -0.004384209401905537, -0.017266051843762398, -0.023998040705919266, -0.017193229869008064, 0.01663145050406456, 0.02500591240823269, 0.0449361577630043, -0.032034456729888916, -0.007996579632163048, -0.014287666417658329, 0.002341923303902149, -0.027318261563777924, -0.03695923835039139, 0.001780341612175107, -0.0006021024892106652, -0.0021804741118103266, -0.05994226410984993, -0.03380380943417549, -0.017753873020410538 ]
8aa22dad95839c5aa4e52f5c6ec5b084424226d6
1,534
py
Python
simplimental/simplimental.py
TimmyCarbone/simplimental
e46a0e63ce33e36b1e4ca3a473ad15d0732614ed
[ "MIT" ]
2
2015-11-25T15:12:05.000Z
2017-06-22T16:36:58.000Z
simplimental/simplimental.py
TimmyCarbone/simplimental
e46a0e63ce33e36b1e4ca3a473ad15d0732614ed
[ "MIT" ]
null
null
null
simplimental/simplimental.py
TimmyCarbone/simplimental
e46a0e63ce33e36b1e4ca3a473ad15d0732614ed
[ "MIT" ]
null
null
null
import re import json __all__ = ["Simplimental"] class Simplimental: def __init__(self, text="This is not a bad idea"): self.text = text with open('simplimental/data/afinn.json') as data_file: self.dictionary = json.load(data_file) no_punctunation = re.sub(r"[^a-zA-Z ]+", " ", self.text) self.tokens = no_punctunation.lower().split(" ") for t in self.tokens: if len(t) < 3 and t not in ["no"]: self.tokens.remove(t) def negativity(self): hits = 0 words = [] for i in range(len(self.tokens)): word = self.tokens[i] score = self.dictionary.get(word, 0) if i > 0 and self.tokens[i-1] in ["no", "not"]: word = "not_" + word score = -score if score > 0 else 0 if score < 0: hits -= score words.append(word) return { "score": hits, "comparative": float(hits) / len(self.tokens), "words": words } def positivity(self): hits = 0 words = [] for i in range(len(self.tokens)): word = self.tokens[i] score = self.dictionary.get(word, 0) if i > 0 and self.tokens[i-1] in ["no", "not"]: word = "not_" + word score = -score if score < 0 else 0 if score > 0: hits += score words.append(word) return { "score": hits, "comparative": float(hits) / len(self.tokens), "words": words } def analyze(self): negativity = self.negativity() positivity = self.positivity() return { "score": positivity["score"] - negativity["score"], "comparative": positivity["comparative"] - negativity["comparative"], }
21.605634
72
0.612777
1
1.3371
[ 0.001817134441807866, 0.024981314316391945, 0.006579834036529064, 0.00009174040314974263, 0.004757156129926443, -0.003963998053222895, -0.010135418735444546, 0.0035654257517307997, -0.005882915575057268, 0.0036501765716820955, 0.0021766640711575747, 0.0064597418531775475, 0.007931039668619633, -0.016450881958007812, 0.00007191456825239584, 0.013984635472297668, -0.049398429691791534, 0.002720863791182637, -0.0028592003509402275, 0.0013536096084862947, -0.00835640449076891, 0.010683286935091019, 0.008836383000016212, 0.005601702723652124, 0.006731776986271143, 0.0010659118415787816, 0.010573352687060833, 0.003449396463111043, -0.007725461386144161, -0.004979956895112991, -0.0017989056650549173, -0.0002488589670974761, -0.004489760845899582, -0.006495553068816662, 0.006255101412534714, -0.003994120750576258, -0.0008778130286373198, -0.022293148562312126, 0.011570319533348083, -0.005063814111053944, -0.0062173050828278065, -0.013484317809343338, -0.0023392450530081987, 0.004087571986019611, -0.008882051333785057, 0.002352254232391715, -0.0051355259492993355, 0.0018776734359562397, -0.010505028069019318, 0.005453805904835463, -0.009911601431667805, 0.005664202384650707, 0.0148537065833807, 0.003911744337528944, -0.004828831180930138, -0.0071646361611783504, 0.014329756610095501, 0.001154187135398388, -0.010266679339110851, -0.0027059540152549744, -0.002954950323328376, -0.004273116588592529, 0.00493656238541007, 0.0018427625764161348, -0.017481716349720955, -0.007325190119445324, -0.004958213306963444, 0.00266448687762022, -0.0018325638957321644, 0.005355029832571745, 0.0030216113664209843, -0.0016357769491150975, 0.008181645534932613, 0.005022881086915731, 0.0016803351463750005, -0.0036624418571591377, -0.0021930551156401634, 0.001589844934642315, 0.008185450918972492, 0.005218333099037409, 0.0044982233084738255, -0.006825627293437719, 0.00796916987746954, 0.008719936944544315, 0.013089281506836414, 0.008532668463885784, 0.02090027555823326, -0.01112415548413992, 0.04603571817278862, 0.007268307264894247, -0.008438289165496826, 0.001491305767558515, -0.01029226090759039, -0.0015707127749919891, -0.00534876249730587, -0.03079003468155861, -0.0010141868842765689, -0.0029395893216133118, -0.0006074492121115327, 0.003343018935993314, -0.0012652231380343437, 0.005387388169765472, -0.0016837948933243752, -0.0023176472168415785, -0.009138748981058598, 0.011058241128921509, -0.010559500195086002, -0.0036141725722700357, 0.0073841935954988, 0.0018078810535371304, -0.012257169000804424, -0.0005087098106741905, 0.0004957432392984629, -0.011400914750993252, 0.003909180406481028, 0.0017069673631340265, -0.0034093218855559826, 0.053275007754564285, -0.003213629825040698, 0.0034817398991435766, -0.005695813801139593, 0.0017071627080440521, 0.0026577478274703026, 0.0039084176532924175, 0.00910623837262392, -0.001609205617569387, 0.011638250201940536, 0.008583310060203075, 0.003152151359245181, 0.00830898992717266, -0.001052000094205141, 0.0065573425963521, -0.004546398296952248, -0.0012544677592813969, -0.0001378345477860421, -0.008383112959563732, 0.006577795837074518, -0.0012674533063545823, -0.007462540175765753, 0.00549447862431407, -0.0013372533721849322, -0.009465744718909264, 0.001341957482509315, -0.0038582582492381334, 0.003359962021932006, -0.010526834987103939, -0.002907965099439025, -0.0031466165091842413, -0.005395779851824045, 0.002284811343997717, 0.010287695564329624, 0.004331209696829319, 0.0021218096371740103, -0.004492511507123709, -0.00976584292948246, 0.001622542506083846, -0.004096496384590864, 0.001219767495058477, 0.00684526190161705, 0.004330540541559458, -0.012549816630780697, -0.00040312123019248247, 0.0017319528851658106, 0.0038281718734651804, -0.0012390859192237258, 0.003953334875404835, -0.006948010064661503, 0.008895253762602806, -0.0010607729200273752, 0.004284994211047888, 0.011736605316400528, -0.006623764988034964, 0.00014776570606045425, -0.00007598014053655788, 0.0022430189419537783, -0.0010661500273272395, 0.0057024359703063965, 0.010893812403082848, -0.004656361415982246, -0.00427688704803586, 0.00542998593300581, 0.004959926009178162, 0.007930613122880459, 0.004147108644247055, -0.0028672488406300545, 0.0017074468778446317, -0.005714777857065201, -0.002233271487057209, 0.00617445632815361, -0.005168595351278782, 0.005595942959189415, 0.0058044856414198875, -0.013475568033754826, -0.008005557581782341, 0.0008425190462730825, -0.00789573322981596, 0.0016489016124978662, 0.015493661165237427, 0.011228780262172222, -0.005196634214371443, 0.0017457902431488037, -0.011514810845255852, -0.0000738176895538345, 0.006825943943113089, 0.0023176611866801977, -0.011569775640964508, -0.9582381844520569, 0.00831192173063755, 0.0031122369691729546, -0.0027370962779968977, 0.005641935393214226, 0.003256356343626976, 0.003094528568908572, 0.0037369972560554743, 0.014895804226398468, -0.008237319067120552, -0.005688314791768789, -0.011092753149569035, -0.013615207746624947, -0.0022215531207621098, -0.008788112550973892, -0.0020324455108493567, -0.005612112116068602, -0.00618921872228384, -0.003095573280006647, -0.0025605971459299326, -0.0023506672587245703, 0.00970443431288004, -0.0009141276823356748, 0.004816911648958921, 0.004009924829006195, 0.0038610550109297037, -0.004312686622142792, -0.003025489393621683, -0.0008965784800238907, -0.0035321961622685194, -0.007688926998525858, -0.013002568855881691, -0.0051714093424379826, -0.00011777121835621074, 0.012000017799437046, 0.002133045345544815, 0.0067671495489776134, -0.0032942115794867277, 0.0025997948832809925, -0.008784765377640724, 0.004371452610939741, -0.0013155600754544139, 0.0035549954045563936, -0.02928284928202629, 0.0006360637489706278, -0.0005013570189476013, -0.00917901936918497, 0.011585256084799767, 0.0006947655347175896, 0.00032835116144269705, -0.0030652708373963833, -0.005679433234035969, 0.011004321277141571, -0.005431266501545906, 0.0037525708321481943, -0.004804390016943216, -0.009431381709873676, -0.0030306512489914894, -0.009125066921114922, 0.0004954576725140214, 0.004697208292782307, -0.0032208149787038565, -0.005716598592698574, -0.004355125594884157, 0.0034438269212841988, 0.0024028460029512644, 0.004418967757374048, -0.0190342478454113, -0.006660105660557747, 0.003208238398656249, 0.0020052383188158274, -0.0018094314727932215, -0.005013118498027325, 0.00462926272302866, -0.010922813788056374, 0.006172599736601114, 0.0023185310419648886, -0.000059827456425409764, -0.012107172049582005, -0.0008079466642811894, -0.011177142150700092, -0.007829409092664719, 0.0022642749827355146, -0.004804079420864582, -0.004921782296150923, -0.0002342577645322308, 0.0023737801238894463, 0.006999771576374769, -0.0043290783651173115, 0.0033703232184052467, 0.011250889860093594, -0.0026953043416142464, -0.008533134125173092, 0.007543901912868023, 0.008652380667626858, 0.00007151638419600204, -0.0014230929082259536, 0.003240075660869479, 0.006608044728636742, 0.007457897998392582, 0.001998704159632325, 0.004645915701985359, 0.0010548480786383152, 0.009900538250803947, -0.0019158475333824754, 0.0021291389130055904, -0.003933241590857506, 0.0003661795344669372, -0.004094668198376894, -0.0006828272016718984, -0.003875475376844406, -0.002614110941067338, -0.012277936562895775, -0.009499135427176952, -0.0027112981770187616, 0.0008053710334934294, 0.0030265694949775934, -0.005114008206874132, -0.0003361361741553992, 0.001502091297879815, 0.0061621214263141155, 0.00103276246227324, -0.004758521914482117, -0.0009029550128616393, 0.0017065077554434538, -0.005485068541020155, 0.01467935461550951, -0.010984587483108044, 0.006395834963768721, 0.0003519103047437966, -0.016293209046125412, 0.006766556296497583, 0.009888757951557636, -0.008236589841544628, 0.0024029624182730913, 0.0007561209495179355, 0.0016007921658456326, -0.0006779025425203145, -0.004778652917593718, -0.004564747214317322, -0.01757962256669998, -0.00014287566591519862, 0.020144030451774597, 0.0033857536036521196, 0.01085417065769434, 0.011381898075342178, -0.005338121671229601, 0.0024683193769305944, 0.005286418832838535, 0.0028553903102874756, 0.013906850479543209, -0.00783317070454359, 0.0002657514705788344, 0.0005023094709031284, -0.005471962038427591, 0.0008572396473027766, 0.006861194968223572, 0.005788375623524189, -0.00241957139223814, 0.0038038850761950016, -0.005545473657548428, -0.004236472304910421, -0.016162436455488205, -0.0032462396193295717, 0.00867136288434267, -0.004749939311295748, 0.0056320358999073505, -0.01230798289179802, 0.004720646422356367, 0.005489319562911987, 0.0043384013697505, -0.0004784432821907103, -0.000020427494746400043, 0.005855262745171785, 0.012897379696369171, -0.006088172551244497, 0.0030157086439430714, 0.0034790989011526108, -0.00039268197724595666, -0.0005212674732320011, 0.008174018934369087, -0.008754141628742218, -0.0046418532729148865, 0.0026429772842675447, 0.0030966277699917555, -0.0012164423242211342, -0.002039880258962512, -0.008809547871351242, -0.0042960611172020435, 0.0043742419220507145, -0.004981049802154303, 0.003098732093349099, 0.0002903577114921063, 0.004072939045727253, -0.006664045620709658, 0.0000941956095630303, -0.0035340124741196632, -0.012606630101799965, 0.010188310407102108, -0.0017770578851923347, 0.0028969619888812304, 0.014062837697565556, 0.004442412871867418, -0.011658591218292713, 0.0055314889177680016, 0.006817816291004419, -0.004425335675477982, 0.004606146365404129, 0.005804499611258507, -0.005193034652620554, -0.023383159190416336, -0.0032130591571331024, -0.013068701140582561, 0.005581605713814497, -0.0019274801015853882, 0.0059225186705589294, -0.008863071911036968, 0.00808723084628582, 0.0055404892191290855, -0.014235417358577251, -0.0055452375672757626, -0.008195397444069386, 0.008329974487423897, 0.00048202730249613523, -0.0001002248827717267, -0.00395652512088418, -0.0013205568538978696, -0.0019152587046846747, -0.0038231275975704193, -0.004361411090940237, 0.0036815758794546127, 0.0010019142646342516, -0.0036801439709961414, 0.00244492432102561, -0.003426008392125368, 0.0003186575777363032, 0.001612446503713727, -0.010617800988256931, 0.002782015595585108, 0.004158651921898127, -0.0016862730262801051, -0.002911193761974573, 0.0030431649647653103, -0.0020612541120499372, -0.008560046553611755, -0.01072132121771574, -0.004647298250347376, -0.005877512972801924, -0.0036266366951167583, -0.011156955733895302, -0.003413529135286808, -0.01051315851509571, 0.007895353250205517, -0.00748108047991991, 0.006529167760163546, 0.0074911657720804214, -0.006146569736301899, 0.00714793661609292, -0.00060261384351179, 0.0038967395666986704, 0.0030341194942593575, 0.006286639254540205, 0.0002013836638070643, -0.005993460770696402, -0.010005165822803974, 0.01204956229776144, -0.00796540267765522, 0.0022763432934880257, 0.014355367980897427, 0.003949102014303207, 0.009574243798851967, 0.0007748631178401411, 0.00048609430086798966, -0.00008705160144018009, 0.007184452842921019, -0.014057246036827564, 0.002885746769607067, -0.004116492345929146, -0.0008131989743560553, 0.005205411463975906, -0.00360041088424623, 0.0000868451243150048, 0.009687673300504684, 0.0018050065264105797, -0.005914853420108557, -0.001902565243653953, -0.0011195093393325806, 0.003748849965631962, -0.012102629989385605, -0.0015294930199161172, -0.0027068527415394783, -0.005028242710977793, -0.002383191604167223, -0.005352183245122433, 0.000023741098630125634, 0.0035215583629906178, -0.0015408898470923305, 0.0051441979594528675, 0.00299609056673944, -0.005325360223650932, 0.014106580056250095, -0.0033659320324659348, -0.00531001528725028, 0.0040036956779658794, 0.003604025347158313, -0.0032208303455263376, -0.006852454040199518, -0.0014163445448502898, 0.0015667889965698123, 0.006811993196606636, -0.0020760793704539537, -0.005455405451357365, -0.0016975498292595148, 0.0003548185632098466, -0.008414804935455322, 0.0009824353037402034, 0.01408160850405693, -0.004596044775098562, 0.0056653679348528385, -0.002376549644395709, -0.009229471907019615, -0.015314796939492226, 0.05379381775856018, -0.00033942898153327405, 0.004661873914301395, 0.004577495623379946, -0.007848246954381466, -0.0005215050769038498, -0.001123320427723229, 0.007511711213737726, -0.005935617256909609, -0.008796981535851955, 0.008393601514399052, -0.0028873286210000515, 0.0032956376671791077, 0.004952773451805115, -0.001330860424786806, 0.016682863235473633, -0.004116220399737358, -0.015695439651608467, -0.017137033864855766, 0.007496431469917297, -0.004770446103066206, -0.00839248113334179, 0.008851039223372936, -0.003581528551876545, -0.00519034406170249, 0.002172592096030712, 0.0068488637916743755, 0.0008500964613631368, -0.0009628636762499809, -0.0020935151260346174, -0.0020184158347547054, -0.0003650700964499265, 0.0031166428234428167, 0.004578433930873871, 0.008309445343911648, -0.0028702307026833296, 0.0038990636821836233, -0.0011208975920453668, -0.0013295088429003954, -0.00048521472490392625, 0.002694860566407442, 0.007372850552201271, -0.0001799137971829623, -0.000722654105629772, 0.004568867851048708, 0.003871102351695299, 0.0017422100063413382, 0.012715639546513557, -0.0009622197831049562, -0.007242691237479448, 0.010032856836915016, 0.006999513134360313, -0.001069863443262875, 0.00862615555524826, -0.0004919075290672481, 0.005842210724949837, 0.00374137912876904, -0.007181295659393072, -0.015281484462320805, -0.0014212203677743673, 0.008937311358749866, 0.009029876440763474, -0.002351542469114065, 0.0016190444584935904, -0.0029344409704208374, -0.0020325733348727226, -0.006205617915838957, -0.007811305113136768, -0.00299958442337811, 0.0022778452839702368, 0.003236113116145134, 0.07000286132097244, -0.006925882771611214, -0.002736811526119709, -0.009934398345649242, -0.0007133214385248721, -0.0010078990599140525, -0.001322925090789795, 0.0022465793881565332, -0.0011335924500599504, 0.0018179271137341857, -0.00022392289247363806, -0.008067086338996887, -0.012198011390864849, 0.0004586463328450918, 0.0025291284546256065, -0.0038945614360272884, 0.0041319020092487335, 0.0069811223074793816, -0.009791526012122631, 0.0020830987486988306, -0.0113463643938303, -0.0029314523562788963, -0.00181212043389678, -0.010486879386007786, -0.004082085564732552, -0.003924164455384016, 0.005229605361819267, 0.004181304015219212, 0.0074446480721235275, -0.005384795367717743, 0.005937967449426651, -0.0036099671851843596, -0.00011706752411555499, -0.004927429370582104, 0.001747448230162263, -0.005628668703138828, 0.008793266490101814, 0.0012952886754646897, -0.013207570649683475, -0.0065127890557050705, -0.0006607368704862893, 0.0012674885801970959, -0.0065826475620269775, 0.00422084704041481, -0.00030419620452448726, 0.004917709622532129, -0.004329801071435213, 0.0014066690346226096, -0.006586854346096516, 0.004227170720696449, -0.011819112114608288, 0.005291946232318878, -0.17274190485477448, 0.011908004991710186, 0.0022503293585032225, -0.00603670347481966, -0.0029050917364656925, -0.01475426647812128, -0.007705757860094309, 0.0015250444412231445, 0.009204461239278316, 0.0034470774699002504, -0.0013853185810148716, 0.00007240956620080397, 0.00495452806353569, 0.00546225206926465, -0.0028839674778282642, -0.0057050371542572975, 0.0044008358381688595, -0.0037884486373513937, 0.0011327520478516817, 0.00465711485594511, 0.004092988558113575, 0.009627174586057663, 0.002232620259746909, 0.0013708254555240273, 0.0006073203985579312, -0.005484733264893293, 0.00498732877895236, -0.0018401715205982327, 0.005148998461663723, -0.011374297551810741, -0.003848498221486807, -0.003744743065908551, -0.005131213925778866, 0.0018115685088559985, 0.004234157968312502, 0.0018694070167839527, 0.007696481421589851, 0.002127573359757662, -0.009222729131579399, 0.006163578946143389, -0.007747989613562822, 0.029330763965845108, 0.006140839774161577, 0.0054354132153093815, 0.001958466600626707, -0.006495494861155748, -0.004574907012283802, 0.009572906419634819, 0.00145320117007941, 0.014310549944639206, -0.013642188161611557, -0.0008607879281044006, 0.002167902886867523, 0.019877608865499496, -0.004317646846175194, -0.009884864091873169, -0.006361822597682476, -0.001908538630232215, 0.002879098756238818, 0.008038350380957127, 0.010502293705940247, -0.00307766767218709, 0.008526813238859177, -0.0029422009829431772, -0.023833591490983963, 0.0022680694237351418, -0.004509801045060158, -0.005227412562817335, -0.0004737572162412107, 0.007093909662216902, 0.009286082349717617, -0.0013766586780548096, 0.0031011980026960373, -0.0002233099367003888, 0.0057566799223423, -0.0011069400934502482, 0.006423892918974161, -0.0020112008787691593, 0.006240701302886009, -0.010663033463060856, 0.008574777282774448, -0.009216559119522572, -0.0004584424023050815, 0.0027161871548742056, -0.004675624892115593, 0.011297286488115788, 0.004108241759240627, -0.0017420443473383784, -0.0018679986242204905, -0.01140188705176115, -0.0003989592078141868, 0.0017505359137430787, 0.0027538726571947336, -0.006843439303338528, 0.0024909379426389933, 0.00027602442423813045, 0.0033634689170867205, 0.007009806577116251, -0.009702151641249657, 0.00842659454792738, 0.0037612696178257465, -0.007928854785859585, 0.0004941566148772836, -0.00561458058655262, 0.0033531261142343283, 0.005720179527997971, -0.0063257780857384205, -0.005744189023971558, 0.003281889483332634, -0.006726326886564493, -0.0052445814944803715, 0.005753376055508852, -0.009353387169539928, -0.009895015507936478, -0.0015238880878314376, -0.011740832589566708, -0.00044031607103534043 ]
8aa2d7e8d015afdc94844a8b1cce4b350015d579
3,637
py
Python
Python/Examples/Macros/SettingsAxesOptimization.py
archformco/RoboDK-API
b3d0cad6a83f505811e2be273453ccb4579324f1
[ "MIT" ]
161
2018-03-23T01:27:08.000Z
2022-03-23T12:18:35.000Z
Python/Examples/Macros/SettingsAxesOptimization.py
OxideDevX/RoboDK-API
50357c38b2fcf58cf82d9b7bf61021cb900fd358
[ "MIT" ]
26
2018-11-19T10:18:58.000Z
2022-03-28T18:37:11.000Z
Python/Examples/Macros/SettingsAxesOptimization.py
OxideDevX/RoboDK-API
50357c38b2fcf58cf82d9b7bf61021cb900fd358
[ "MIT" ]
85
2018-03-22T19:25:35.000Z
2022-03-30T04:46:59.000Z
# This example shows how to read or modify the Axes Optimization settings using the RoboDK API and a JSON string. # You can select "Axes optimization" in a robot machining menu or the robot parameters to view the axes optimization settings. # It is possible to update the axes optimization settings attached to a robot or a robot machining project manually or using the API. # # More information about the RoboDK API here: # https://robodk.com/doc/en/RoboDK-API.html # For more information visit: # https://robodk.com/doc/en/PythonAPI/robolink.html from robolink import * # RoboDK API # JSON tools import json # Start the RoboDK API RDK = Robolink() # Ask the user to select a robot arm (6 axis robot wich can have external axes) robot = RDK.ItemUserPick("Select a robot arm",ITEM_TYPE_ROBOT_ARM) # Default optimization settings test template AxesOptimSettings = { # Optimization parameters: "Active": 1, # Use generic axes optimization: 0=Disabled or 1=Enabled "Algorithm": 2, # Optimization algorithm to use: 1=Nelder Mead, 2=Samples, 3=Samples+Nelder Mead "MaxIter": 650, # Max. number of iterations "Tol": 0.0016, # Tolerance to stop iterations # Absolute Reference joints (double): "AbsJnt_1": 104.17, "AbsJnt_2": 11.22, "AbsJnt_3": 15.97, "AbsJnt_4": -87.48, "AbsJnt_5": -75.36, "AbsJnt_6": 63.03, "AbsJnt_7": 174.13, "AbsJnt_8": 173.60, "AbsJnt_9": 0, # Using Absolute reference joints (0: No, 1: Yes): "AbsOn_1": 1, "AbsOn_2": 1, "AbsOn_3": 1, "AbsOn_4": 1, "AbsOn_5": 1, "AbsOn_6": 1, "AbsOn_7": 1, "AbsOn_8": 1, "AbsOn_9": 1, # Weight for absolute reference joints (double): "AbsW_1": 100, "AbsW_2": 100, "AbsW_3": 100, "AbsW_4": 89, "AbsW_5": 90, "AbsW_6": 92, "AbsW_7": 92, "AbsW_8": 96, "AbsW_9": 50, # Using for relative joint motion smoothing (0: No, 1: Yes): "RelOn_1": 1, "RelOn_2": 1, "RelOn_3": 1, "RelOn_4": 1, "RelOn_5": 1, "RelOn_6": 1, "RelOn_7": 1, "RelOn_8": 1, "RelOn_9": 1, # Weight for relative joint motion (double): "RelW_1": 5, "RelW_2": 47, "RelW_3": 44, "RelW_4": 43, "RelW_5": 36, "RelW_6": 47, "RelW_7": 53, "RelW_8": 59, "RelW_9": 0, } # Update one value, for example, make it active: ToUpdate = {} ToUpdate["Active"] = 1 json_str = json.dumps(json.dumps(ToUpdate)) status = robot.setParam("OptimAxes", json_str) print(status) # Example to make a partial or full update count = 1 while True: for i in range(7): # Partial update ToUpdate = {} ToUpdate["AbsJnt_" + str(i+1)] = (count+i)*4 ToUpdate["AbsOn_" + str(i+1)] = count % 2 ToUpdate["AbsW_" + str(i+1)] = (count+i) json_str = json.dumps(json.dumps(ToUpdate)) status = robot.setParam("OptimAxes", json_str) print(status) # Full update #OptimAxes_TEST["RefJoint_" + str(i+1)] = (count+i)*4 #OptimAxes_TEST["RefWeight_" + str(i+1)] = (count+i) #OptimAxes_TEST["RefOn_" + str(i+1)] = count % 2 # Full update #print(robot.setParam("OptimAxes", str(AxesOptimSettings))) count = count + 1 # Read settings json_data = robot.setParam("OptimAxes") json_object = json.loads(json_data) print(json.dumps(json_object, indent=4)) pause(0.2) # Example to read the current axes optimization settings: while True: json_data = robot.setParam("OptimAxes") json_object = json.loads(json_data) print(json.dumps(json_object, indent=4)) pause(0.2)
28.414063
133
0.62854
1
2.4486
[ 0.001003467128612101, 0.05118153244256973, 0.006606435403227806, 0.03508883714675903, 0.030969375744462013, -0.015041466802358627, -0.002133737551048398, -0.0027233425062149763, -0.007843433879315853, 0.007077931892126799, 0.018826289102435112, -0.037502650171518326, 0.01466118823736906, 0.010663643479347229, -0.006710463669151068, 0.013542736880481243, 0.028022663667798042, -0.011783992871642113, -0.054311998188495636, -0.009511941112577915, 0.0012889830395579338, 0.0014152125222608447, 0.029225975275039673, -0.012947848066687584, -0.006986548192799091, 0.026071792468428612, -0.030271952971816063, -0.001844175043515861, -0.029990799725055695, -0.037038855254650116, -0.00442849937826395, 0.017890434712171555, -0.014849381521344185, -0.04970448836684227, -0.020789355039596558, 0.03504182770848274, 0.0041968864388763905, -0.04122268408536911, -0.008346902206540108, -0.02711550146341324, -0.03185057267546654, 0.017605867236852646, -0.0102233299985528, -0.01782008819282055, -0.010543400421738625, -0.01851113885641098, -0.0033898085821419954, -0.007759776897728443, -0.029389047995209694, 0.01592392660677433, -0.039434634149074554, 0.01048168633133173, 0.018070071935653687, -0.010948928073048592, 0.006761900614947081, 0.003710099495947361, -0.0005382545641623437, 0.013120247982442379, -0.004392989445477724, 0.004727801773697138, -0.03434843569993973, -0.00943593680858612, 0.00010687930625863373, -0.01798941195011139, -0.042984552681446075, -0.016949858516454697, -0.008663748390972614, -0.00024648578255437315, -0.08465155959129333, 0.046158045530319214, 0.023652255535125732, 0.00290868803858757, 0.03660472109913826, 0.07552829384803772, -0.00013021631457377225, -0.00936133973300457, 0.004664178472012281, -0.004392839036881924, -0.004695061128586531, -0.011390794068574905, 0.012769404798746109, 0.0445379763841629, -0.001063661533407867, -0.002559039508923888, -0.0032618024852126837, -0.03617370128631592, 0.04988241568207741, -0.040387220680713654, 0.007994602434337139, 0.012183213606476784, -0.043193187564611435, 0.046983856707811356, -0.031151888892054558, -0.0036695085000246763, -0.03600526973605156, -0.05839601159095764, 0.014690814539790154, -0.023693909868597984, 0.0349474661052227, -0.03854724392294884, 0.023517919704318047, -0.015043883584439754, 0.014567840844392776, 0.016172420233488083, 0.021692922338843346, -0.02657156251370907, -0.0207650288939476, -0.05698796361684799, 0.022800330072641373, -0.003909425809979439, -0.04906751587986946, 0.0076211015693843365, -0.008196007460355759, -0.011577322147786617, -0.028331080451607704, 0.008519812487065792, -0.00850743893533945, 0.018790535628795624, -0.02306586690247059, 0.06173831969499588, 0.035666413605213165, -0.017742514610290527, 0.01836269535124302, -0.014192894101142883, -0.014519007876515388, 0.06479772925376892, -0.027178075164556503, -0.0127165038138628, 0.006974703632295132, -0.037429578602313995, -0.018462928012013435, -0.06346998363733292, 0.009568917565047741, -0.008697387762367725, -0.014033958315849304, 0.01987416483461857, 0.02308063395321369, 0.02316855639219284, -0.03263601288199425, 0.04283275082707405, 0.028767701238393784, -0.03812851011753082, -0.007090827915817499, 0.028331179171800613, -0.03617674857378006, -0.028166623786091805, 0.0064989603124558926, 0.013189531862735748, -0.02123711071908474, 0.015322411432862282, 0.04018612205982208, 0.004712548106908798, 0.001285283244214952, 0.03094436042010784, -0.05007599666714668, 0.0026319297030568123, -0.029573161154985428, -0.015774762257933617, -0.012174516916275024, 0.01844296045601368, -0.021551959216594696, 0.013380326330661774, 0.0019216526998206973, -0.0002740810450632125, -0.009049552492797375, 0.10091801732778549, 0.015918124467134476, 0.024033647030591965, 0.01899612322449684, -0.06123390421271324, 0.027452800422906876, 0.0028924569487571716, -0.031196050345897675, 0.00852927565574646, -0.051596011966466904, -0.005029343068599701, 0.010476043447852135, 0.069364994764328, 0.008828031830489635, 0.017409062013030052, 0.046879395842552185, -0.037572991102933884, -0.0026304670609533787, 0.0684768408536911, -0.010605471208691597, -0.011468227952718735, -0.04829035699367523, -0.025167066603899002, -0.004347817972302437, -0.016072193160653114, -0.0006581617635674775, -0.006229268852621317, 0.053615253418684006, -0.01799745298922062, -0.0039720297791063786, -0.05414716526865959, -0.028063572943210602, 0.018733954057097435, -0.02923746034502983, -0.041476354002952576, -0.032113853842020035, -0.03596409410238266, 0.003782485146075487, 0.09139444679021835, 0.008053839206695557, 0.03472232446074486, -0.5883727073669434, 0.008662616834044456, -0.0063968743197619915, -0.013618042692542076, -0.003552759299054742, 0.02727496065199375, -0.023041557520627975, 0.025901051238179207, -0.04391457512974739, 0.021685587242245674, -0.01797531545162201, 0.019766759127378464, -0.05431382730603218, 0.011778236366808414, 0.017298756167292595, -0.018391666933894157, -0.02131081372499466, -0.01979970932006836, 0.006100243888795376, 0.06588473170995712, -0.005810351576656103, -0.004166089463979006, -0.008531369268894196, 0.009688310325145721, 0.0314437597990036, 0.04921957105398178, 0.026141837239265442, 0.028287308290600777, 0.004014136735349894, -0.022376684471964836, -0.034109726548194885, 0.04157201200723648, 0.014907889999449253, -0.010853702202439308, -0.010231338441371918, 0.06224030256271362, -0.021311521530151367, -0.025543278083205223, -0.07139774411916733, -0.022876447066664696, -0.008924453519284725, -0.002332214266061783, 0.0013378760777413845, -0.042441416531801224, -0.0457267090678215, 0.023041123524308205, 0.008283426985144615, -0.02239641360938549, 0.01362653449177742, 0.013834264129400253, -0.048378583043813705, -0.044259488582611084, 0.04678616672754288, -0.02338240295648575, -0.05298621207475662, 0.03106619417667389, -0.0324624702334404, 0.007885144092142582, 0.005998609121888876, -0.002463138895109296, 0.013391057029366493, -0.016209948807954788, -0.04429754242300987, -0.023161517456173897, 0.012758766300976276, 0.01421311590820551, 0.06844550371170044, -0.010972235351800919, -0.02215811237692833, 0.06166259944438934, -0.05268266052007675, -0.0012088833609595895, -0.05266143009066582, 0.039474401623010635, 0.03950493410229683, 0.024909786880016327, -0.0020908305887132883, 0.017901748418807983, -0.07163531333208084, -0.044348008930683136, 0.02112630382180214, 0.0012006341712549329, 0.019663315266370773, -0.015391514636576176, 0.004296014551073313, 0.01503437478095293, -0.02697015553712845, 0.007914917543530464, -0.00023265880008693784, 0.01056028250604868, -0.014441746287047863, 0.07728098332881927, 0.023702973499894142, 0.03236271068453789, 0.0046057384461164474, 0.04274854063987732, 0.004262732341885567, 0.017328180372714996, -0.00043503704364411533, 0.050878118723630905, -0.004802526906132698, 0.04938926547765732, -0.0010853437706828117, 0.024594709277153015, -0.04922168701887131, -0.028958695009350777, -0.024519916623830795, -0.02404649555683136, 0.006237828638404608, 0.060600265860557556, 0.019284360110759735, 0.005933387670665979, 0.027351772412657738, -0.01901831664144993, 0.01938435062766075, 0.006094740703701973, -0.003091858234256506, -0.03707408532500267, 0.011350752785801888, -0.017319047823548317, -0.0066375331953167915, 0.02136337012052536, 0.015148296020925045, -0.016044048592448235, -0.019973693415522575, 0.025904012843966484, -0.07135137915611267, -0.02478722110390663, 0.011678009293973446, 0.008265363983809948, 0.00485706003382802, 0.014156759716570377, -0.0060598948039114475, -0.019742140546441078, -0.002334633143618703, 0.03585009649395943, -0.025177761912345886, 0.01214443426579237, -0.0262491125613451, -0.023225225508213043, -0.02271435409784317, -0.00897972285747528, 0.021331261843442917, -0.06025788560509682, 0.008085299283266068, 0.02766335755586624, 0.037761274725198746, -0.03680174797773361, -0.11796949803829193, 0.023132262751460075, 0.006076360587030649, 0.039389900863170624, 0.04199275001883507, 0.023081112653017044, 0.014352203346788883, -0.003976273816078901, -0.04965529963374138, 0.028255395591259003, 0.04412410408258438, 0.04632585495710373, -0.010559774935245514, 0.024528464302420616, 0.025801939889788628, 0.01268122810870409, -0.02553277462720871, 0.01183357834815979, -0.01263060700148344, 0.0021833269856870174, 0.010426728054881096, -0.006639538332819939, 0.022809937596321106, 0.05147296190261841, 0.014931210316717625, 0.030100591480731964, 0.03812187910079956, 0.013098536059260368, -0.04257988929748535, -0.001562718884088099, -0.0011760707711800933, -0.004403677303344011, 0.014756230637431145, 0.012928624637424946, -0.023589305579662323, -0.013771492056548595, 0.009769797325134277, -0.02203601971268654, -0.04629231244325638, 0.00735447695478797, 0.014689162373542786, -0.01563306152820587, 0.02704090252518654, 0.03207733854651451, -0.052684344351291656, 0.043531641364097595, 0.012784916907548904, -0.033142782747745514, 0.03760689124464989, 0.0036719052586704493, 0.055744145065546036, 0.02755892276763916, -0.022463155910372734, -0.0031324413139373064, 0.01859801635146141, -0.016271311789751053, -0.007253115996718407, -0.04836764559149742, 0.017498726025223732, 0.0014743870124220848, 0.06354255229234695, -0.01223108172416687, 0.03762165084481239, -0.026458222419023514, -0.04200282320380211, -0.030965570360422134, -0.026528550311923027, 0.07090907543897629, -0.06621460616588593, -0.009943399578332901, 0.05506855249404907, -0.04269262030720711, -0.03443426266312599, -0.05030494183301926, 0.004065047483891249, 0.01761545240879059, 0.007409637328237295, -0.0246096383780241, -0.005970960482954979, 0.018692614510655403, -0.022008514031767845, 0.02099229395389557, 0.010410859249532223, 0.008114287629723549, 0.0022865766659379005, 0.0024750211741775274, -0.018704067915678024, 0.009062236174941063, -0.021533651277422905, -0.01644623838365078, 0.016225481405854225, 0.02649066224694252, -0.03788013383746147, -0.014445578679442406, -0.015183046460151672, -0.011508646421134472, 0.0018959534354507923, -0.04769860580563545, -0.0014504106948152184, -0.04359573498368263, -0.030878277495503426, -0.003916047979146242, -0.04001372680068016, 0.04174423962831497, -0.0003681225352920592, 0.005212378688156605, -0.03559035807847977, -0.014283383265137672, -0.02835489809513092, -0.02569543570280075, 0.0031090988777577877, 0.011593634262681007, 0.016341116279363632, -0.03323956951498985, 0.01898607797920704, -0.018317338079214096, -0.0012345380382612348, -0.002151143504306674, -0.0005233882693573833, -0.03771247714757919, -0.009404145181179047, 0.03708236292004585, 0.03585438430309296, -0.00828255619853735, -0.024298880249261856, 0.012366232462227345, -0.03631805628538132, -0.05585413798689842, -0.00015547091607004404, -0.014196754433214664, -0.012325613759458065, 0.06798119843006134, -0.02943332865834236, -0.016976414248347282, -0.010764938779175282, 0.01169244572520256, -0.03677687793970108, -0.0064812819473445415, 0.04542916640639305, 0.026138540357351303, -0.01170051284134388, -0.0075914193876087666, 0.04195305332541466, -0.04237090423703194, 0.025221170857548714, -0.048346713185310364, -0.024895157665014267, -0.0017981869168579578, -0.01955224946141243, 0.024657385423779488, 0.03723050281405449, 0.016074638813734055, 0.014668210409581661, -0.008295037783682346, 0.0021880639251321554, -0.022144917398691177, -0.007032299414277077, -0.05506281554698944, 0.006334961391985416, -0.031189752742648125, 0.030385177582502365, 0.041552141308784485, 0.01925375871360302, 0.04367922618985176, 0.007582549005746841, 0.020250577479600906, 0.019406136125326157, -0.008902338333427906, 0.014977935701608658, 0.03170710429549217, 0.05006154254078865, -0.020757848396897316, -0.0003142874629702419, 0.006037312559783459, -0.014873594976961613, -0.013400614261627197, 0.00027213169960305095, -0.032031357288360596, -0.037354446947574615, 0.02687821537256241, -0.01164650171995163, 0.026916414499282837, 0.016289081424474716, -0.006728007923811674, -0.021441368386149406, -0.002454529982060194, 0.015411234460771084, 0.01899053156375885, 0.034979138523340225, 0.041619304567575455, 0.026029963046312332, -0.0031627719290554523, -0.022205475717782974, 0.026448236778378487, -0.029753372073173523, 0.018446261063218117, 0.028864627704024315, -0.02055395022034645, 0.045043107122182846, 0.011250954121351242, 0.0009354986250400543, 0.03820424899458885, 0.015840766951441765, 0.013648537918925285, 0.01712733507156372, 0.018084775656461716, -0.029126040637493134, -0.058258119970560074, 0.0117330988869071, 0.03353556990623474, 0.001083798473700881, -0.009998076595366001, 0.0015593816060572863, 0.0023155217058956623, -0.02652943879365921, -0.04709954187273979, 0.021943213418126106, -0.030999265611171722, 0.0010104841785505414, -0.0006131755653768778, -0.005462621338665485, 0.04096246883273125, -0.013226267881691456, -0.045138485729694366, -0.03594348207116127, 0.01496165245771408, -0.0022427865769714117, 0.029469197615981102, 0.05591161921620369, -0.02911803126335144, 0.027348725125193596, 0.0007475855527445674, 0.008993673138320446, -0.05707978084683418, 0.028088830411434174, 0.00423251511529088, 0.007094140164554119, -0.040764689445495605, -0.009335607290267944, 0.022396495565772057, -0.037872541695833206, -0.03505760803818703, 0.02456456609070301, -0.0024596594739705324, -0.0050366343930363655, 0.019495710730552673, -0.002886628033593297, 0.005718764383345842, -0.022061020135879517, -0.03429047763347626, 0.01702127233147621, -0.017168421298265457, 0.012426544912159443, -0.014641900546848774, -0.029734674841165543, -0.005193131044507027, 0.0473988838493824, -0.022922754287719727, 0.01959432289004326, 0.01749008148908615, 0.043597910553216934, 0.005378051660954952, 0.0075331018306314945, 0.024800756946206093, -0.051445022225379944, -0.022416505962610245, -0.013379920274019241, 0.036548223346471786, -0.047381363809108734, -0.011092695407569408, -0.00496247410774231, 0.020834047347307205, -0.015335094183683395, 0.0004884932423010468, -0.01203893031924963, 0.006167592015117407, -0.039166998118162155, -0.03975658118724823, 0.012253329157829285, 0.021752668544650078, 0.0019320988794788718, 0.0365157350897789, -0.023246414959430695, -0.01877589523792267, -0.05756795406341553, -0.005868254695087671, 0.024346372112631798, -0.007263826206326485, 0.0341939702630043, 0.0007738772546872497, 0.017768997699022293, -0.0010497880866751075, 0.006368167698383331, -0.000021009820557083003, 0.02835586667060852, -0.007091818377375603, 0.025563349947333336, -0.15743568539619446, 0.007418690714985132, -0.010629662312567234, -0.03202372044324875, 0.03408391401171684, -0.027669114992022514, -0.011226039379835129, 0.03783761337399483, 0.031563982367515564, 0.00894137006253004, 0.01703372411429882, -0.008094152435660362, 0.0198780819773674, 0.030779967084527016, 0.0024905274622142315, -0.041077353060245514, 0.016625365242362022, -0.03956984356045723, -0.0011771868448704481, 0.042367398738861084, 0.026819592341780663, -0.00176887190900743, -0.009798385202884674, -0.008666175417602062, -0.018054546788334846, -0.039673659950494766, 0.009390228427946568, -0.009457792155444622, -0.0034379397984594107, -0.06026500090956688, -0.034469928592443466, 0.018455853685736656, 0.030172448605298996, 0.06290911883115768, -0.0025708202738314867, -0.0171449463814497, 0.017443804070353508, 0.04816644638776779, 0.019769039005041122, -0.004164598416537046, 0.016061268746852875, 0.03887413814663887, 0.018963800743222237, -0.011937202885746956, 0.00807233527302742, -0.058929041028022766, -0.0198170468211174, 0.022174984216690063, 0.05532888323068619, 0.05156094208359718, 0.011026404798030853, 0.011092578060925007, -0.028143370524048805, 0.009371574968099594, 0.03157847002148628, -0.004388912580907345, -0.03773757442831993, 0.013024074025452137, 0.024223895743489265, 0.003588396357372403, 0.037460003048181534, 0.06367548555135727, 0.045635536313056946, -0.01335871871560812, 0.01240144670009613, -0.021470578387379646, -0.026782799512147903, 0.0008762673242017627, -0.0108347088098526, -0.015758182853460312, 0.016839617863297462, 0.008851914666593075, 0.02333032339811325, -0.018594354391098022, -0.00017670058878138661, 0.00045968234189786017, 0.021075747907161713, 0.024547774344682693, 0.007959113456308842, -0.005688704550266266, -0.05462045595049858, -0.013463241048157215, 0.012277893722057343, 0.020701078698039055, -0.030151063576340675, -0.012602648697793484, -0.04168979078531265, 0.0031616881024092436, -0.002979208482429385, 0.012369376607239246, -0.07961851358413696, 0.04528935253620148, 0.027189675718545914, -0.018975721672177315, 0.0055100093595683575, 0.037033889442682266, 0.02644743025302887, -0.015435435809195042, 0.013955899514257908, -0.01834171451628208, -0.04484034329652786, -0.02318577468395233, 0.009945249184966087, -0.004211326129734516, 0.05331940948963165, 0.01695895753800869, 0.03905833512544632, 0.02574695646762848, 0.012724350206553936, -0.009139521047472954, -0.008689511567354202, 0.01917635090649128, -0.027837907895445824, 0.04843486100435257, -0.049682069569826126, -0.007937471382319927, -0.03293493017554283 ]
8aa372fac8202953aac93a2529989a1508f2b506
1,072
py
Python
tests/test_grammar.py
Vipul97/SLR-Parser
3de5609235d173d29ad9bd9ed7bdfe2a813ab1bd
[ "MIT" ]
5
2018-10-30T04:09:46.000Z
2020-03-17T04:47:06.000Z
tests/test_grammar.py
Vipul97/SLR-Parser
3de5609235d173d29ad9bd9ed7bdfe2a813ab1bd
[ "MIT" ]
null
null
null
tests/test_grammar.py
Vipul97/SLR-Parser
3de5609235d173d29ad9bd9ed7bdfe2a813ab1bd
[ "MIT" ]
5
2019-06-16T20:16:46.000Z
2020-04-14T06:44:32.000Z
from slr_parser.grammar import Grammar import unittest class TestGrammar(unittest.TestCase): def test_grammar(self): with open('tests/test_grammar.txt') as grammar_file: self.G = Grammar(grammar_file.read()) self.assertDictEqual( {'E': {('E', '+', 'T'), ('T',)}, 'T': {('T', '*', 'F'), ('F',)}, 'F': {('(', 'E', ')'), ('id',)}}, self.G.grammar) self.assertEqual('E', self.G.start) self.assertSetEqual({'+', '*', '(', ')', 'id'}, self.G.terminals) self.assertSetEqual({'E', 'T', 'F'}, self.G.nonterminals) self.assertSetEqual({'+', '*', '(', ')', 'id', 'E', 'T', 'F'}, self.G.symbols) self.grammar_str = ["""E -> E + T e -> T T -> T * F | F F -> ( E ) F -> id""", """E -> E ^ + T E -> T T -> T * F | F F -> ( E ) F -> id"""] with self.assertRaises(ValueError): Grammar(self.grammar_str[0]) with self.assertRaises(ValueError): Grammar(self.grammar_str[1]) if __name__ == '__main__': unittest.main()
29.777778
114
0.488806
1
1.0656
[ 0.0010956345358863473, 0.025991836562752724, 0.007099851965904236, 0.00039368178113363683, 0.0041719162836670876, -0.0025206517893821, -0.009596794843673706, 0.0036209486424922943, -0.004968389868736267, 0.002703811740502715, 0.00191678071860224, 0.005726134404540062, 0.006561804562807083, -0.016039183363318443, 0.0017106665764003992, 0.01836618036031723, -0.052269503474235535, 0.0008559206617064774, -0.001222832128405571, 0.0030619651079177856, -0.005849219858646393, 0.007506711408495903, 0.007694852538406849, 0.007424833253026009, 0.00683311652392149, 0.002352973911911249, 0.010577669367194176, 0.0026944412384182215, -0.006650276016443968, -0.005770493298768997, -0.0019465296063572168, -0.0008390463190153241, -0.005749153438955545, -0.00748502928763628, 0.006102940533310175, -0.0022236972581595182, -0.0006443989695981145, -0.019558118656277657, 0.010852000676095486, -0.005947251338511705, -0.006459461059421301, -0.01751103438436985, -0.002551471581682563, 0.004155359696596861, -0.007967543788254261, 0.004728591535240412, -0.002786773955449462, 0.0026559389661997557, -0.011512776836752892, 0.005321712698787451, -0.011149730533361435, 0.005070838145911694, 0.011882866732776165, 0.0036366404965519905, -0.00638916390016675, -0.007431820034980774, 0.011668889783322811, 0.0009337720111943781, -0.00991223193705082, 0.00015718307986389846, -0.0015345272840932012, -0.003220226150006056, 0.00680153351277113, 0.0037310682237148285, -0.015791481360793114, -0.008815240114927292, -0.005214540753513575, 0.003491892945021391, -0.0017038029618561268, 0.002844545291736722, -0.00005075060835224576, -0.000616371922660619, 0.006330115254968405, 0.003300605807453394, 0.003914110828191042, -0.0012957935687154531, -0.002169942017644644, -0.00020277651492506266, 0.008002876304090023, 0.004143086727708578, 0.0022097318433225155, -0.005764754954725504, 0.006508877035230398, 0.007251573260873556, 0.014373308047652245, 0.008947501890361309, 0.019715074449777603, -0.010640925727784634, 0.0454191118478775, 0.008753207512199879, -0.009344479069113731, 0.0030713952146470547, -0.008957013487815857, -0.0020488682202994823, -0.0018583458149805665, -0.027783198282122612, 0.0026507617440074682, -0.003631745697930455, -0.00016484814113937318, 0.003584466176107526, -0.0007451616111211479, 0.006553892977535725, -0.0017274768324568868, -0.0013921309728175402, -0.011595169082283974, 0.010325267910957336, -0.009723065420985222, -0.002745883073657751, 0.0063934349454939365, 0.0020996967796236277, -0.009677363559603691, -0.0006215216708369553, 0.002030417323112488, -0.011473895981907845, 0.004080617800354958, 0.0036261347122490406, -0.00538233295083046, 0.05286029726266861, -0.0006217484478838742, 0.0053161256946623325, -0.0058773173950612545, -0.0004773087566718459, -0.0007641840493306518, 0.0027210882399231195, 0.011085150763392448, -0.003613976063206792, 0.008287926204502583, 0.007598623167723417, 0.0036560576409101486, 0.00809662975370884, -0.0014190381625667214, 0.006753002293407917, -0.005522406194359064, -0.0011587908957153559, 0.00031973537988960743, -0.007971900515258312, 0.007171125151216984, -0.00044944992987439036, -0.005175270605832338, 0.0011129733175039291, -0.000899309350643307, -0.010867994278669357, 0.0015628173714503646, -0.004348826594650745, 0.0037679478991776705, -0.011619264259934425, -0.006143100094050169, -0.003116820240393281, -0.002706086728721857, -0.0010201317491009831, 0.00831927452236414, 0.004989572800695896, 0.0028329622000455856, -0.0034431263338774443, -0.008099675178527832, -0.0009052408277057111, -0.004464182537049055, 0.0018595486180856824, 0.006466580554842949, 0.004460752941668034, -0.01008640881627798, -0.0024113378021866083, -0.00011493623605929315, 0.0023692678660154343, 0.00009588609827915207, 0.0041878437623381615, -0.008736390620470047, 0.008614035323262215, -0.0002923354331869632, 0.004072545561939478, 0.010771994479000568, -0.005164765287190676, -0.0008265053620561957, 0.001060123206116259, 0.001282846787944436, 0.0014920266112312675, 0.003368690609931946, 0.010875650681555271, -0.004138406831771135, -0.004064664710313082, 0.003909285180270672, 0.007181152235716581, 0.009443731978535652, 0.007127748336642981, -0.002931325463578105, -0.001267225481569767, -0.004638110287487507, -0.003308374434709549, 0.008736220188438892, -0.004650290589779615, 0.007187263574451208, 0.00589236244559288, -0.013635783456265926, -0.008308718912303448, -0.0005496021476574242, -0.008112834766507149, 0.0012458537239581347, 0.014088396914303303, 0.012585573829710484, -0.0034667178988456726, 0.0017272821860387921, -0.009102916345000267, 0.0016206243308261037, 0.007892709225416183, 0.0023063565604388714, -0.01248258538544178, -0.9582912921905518, 0.004241552669554949, 0.0034522609785199165, -0.0024099077563732862, 0.005601401440799236, 0.0010466339299455285, 0.0035933186300098896, 0.0037872567772865295, 0.011220154352486134, -0.012154413387179375, -0.006618141196668148, -0.009155459702014923, -0.011774645186960697, -0.0009345962898805737, -0.008441794663667679, -0.005530537571758032, -0.005844970233738422, -0.008146255277097225, -0.003582770237699151, -0.0029998214449733496, -0.0008663191110827029, 0.008953618817031384, -0.0011435910128057003, 0.005092568229883909, 0.0027409307658672333, 0.004796568304300308, -0.0037613981403410435, -0.0018306542187929153, -0.00021158966410439461, -0.0027768132276833057, -0.009302325546741486, -0.01567298360168934, -0.005681030452251434, 0.000696933304425329, 0.013373025692999363, 0.0009754248312674463, 0.004656142555177212, -0.0019333662930876017, 0.0006849472410976887, -0.007560265250504017, 0.0037793805822730064, 0.00042446638690307736, 0.006277702283114195, -0.029715772718191147, 0.002232864499092102, -0.00023558757675345987, -0.009159622713923454, 0.007576778065413237, 0.0018580009927973151, -0.0011997554684057832, -0.0022217268124222755, -0.005761690903455019, 0.010093283839523792, -0.005869585555046797, 0.004786091856658459, -0.0030265371315181255, -0.008542260155081749, -0.004327564965933561, -0.008840913884341717, 0.0019849068485200405, 0.00789210107177496, -0.005154894199222326, -0.006025975104421377, -0.00279346015304327, 0.0024657787289470434, 0.0009524994529783726, 0.005780710838735104, -0.018110616132616997, -0.006937538739293814, -0.0042792088352143764, 0.0031970860436558723, -0.0030233885627239943, -0.004832022823393345, 0.005476062186062336, -0.008984386920928955, 0.0067235976457595825, 0.001561079639941454, -0.000905949913430959, -0.009913618676364422, 0.0004338874132372439, -0.009993408806622028, -0.005485857371240854, 0.0030920214485377073, -0.005086262710392475, -0.004718077834695578, -0.0015330271562561393, 0.0037246060092002153, 0.0055470275692641735, -0.003413111437112093, 0.004081834573298693, 0.009420797228813171, -0.003872195491567254, -0.010381425730884075, 0.0063921986147761345, 0.007233091630041599, -0.00048534333473071456, -0.0011145120952278376, 0.0030126404017210007, 0.008357363753020763, 0.007062369026243687, 0.002732939086854458, 0.00771025475114584, 0.0009619368938729167, 0.007303117774426937, -0.000917080498766154, 0.0020126088056713343, -0.0006211313884705305, 0.0001233647344633937, -0.004282473120838404, -0.00013787126226816326, -0.004529586061835289, -0.0017619458958506584, -0.013629211112856865, -0.008177008479833603, -0.0024630026891827583, 0.0027690294664353132, 0.0023578295949846506, -0.001112881232984364, 0.0009674551547504961, 0.0017650644294917583, 0.009514867328107357, -0.0023297269362956285, -0.00518644368276, 0.0017078042728826404, 0.0025458901654928923, -0.007398649584501982, 0.014704186469316483, -0.009889412671327591, 0.0060198260471224785, 0.00043799233390018344, -0.016840318217873573, 0.007279874291270971, 0.01025831513106823, -0.00941164419054985, 0.0028311091009527445, 0.001965517643839121, 0.0009694058680906892, -0.00006659962673438713, -0.003550723660737276, -0.004293924197554588, -0.016476234421133995, 0.0010708151385188103, 0.022125307470560074, 0.0010964253451675177, 0.009947307407855988, 0.012649399228394032, -0.004667891655117273, 0.005530604161322117, 0.0032207865733653307, -0.0007580291712656617, 0.012149556539952755, -0.006935004610568285, -0.002404955215752125, 0.0032532766927033663, -0.004785257391631603, 0.001964384224265814, 0.006308011244982481, 0.005574394948780537, -0.001791398855857551, 0.0034624270629137754, -0.003718137973919511, -0.0032461993396282196, -0.01793726533651352, -0.0022946062963455915, 0.008155128918588161, -0.0007024866063147783, 0.004047198686748743, -0.014082657173275948, 0.004639857914298773, 0.00817387830466032, 0.002940456848591566, -0.0028213264886289835, 0.00039262042264454067, 0.004651842638850212, 0.011687689460814, -0.0051869857124984264, 0.0020513057243078947, 0.003975810948759317, 0.0011137374676764011, -0.0020456297788769007, 0.005573692731559277, -0.009455791674554348, -0.004553481470793486, 0.001551173161715269, 0.0036540948785841465, -0.00040057083242572844, -0.002681734971702099, -0.009533646516501904, -0.001813448965549469, 0.0040319231338799, -0.006643231026828289, 0.0025079743936657906, 0.0011872185859829187, 0.004319450352340937, -0.00681729381904006, 0.00009152603161055595, -0.003975900821387768, -0.011514101177453995, 0.010107163339853287, -0.0033569619990885258, 0.00424353638663888, 0.01188633032143116, 0.004609821364283562, -0.011222648434340954, 0.004485145676881075, 0.009669565595686436, -0.004840121138840914, 0.004417723510414362, 0.005827952641993761, -0.004881291184574366, -0.023079516366124153, -0.001722852699458599, -0.010868432000279427, 0.008171835914254189, -0.002461162395775318, 0.0058435238897800446, -0.00905278418213129, 0.007396259810775518, 0.006346716545522213, -0.013388519175350666, -0.005942107178270817, -0.008320302702486515, 0.007482420187443495, -0.0008897115476429462, -0.0002582705346867442, -0.003470351919531822, -0.0029964300338178873, -0.002719012787565589, -0.0026676449924707413, -0.0036304981913417578, 0.0060954103246331215, 0.0012530075618997216, -0.004548745695501566, 0.0022213959600776434, -0.003268910339102149, 0.001211452530696988, 0.002648543566465378, -0.010248817503452301, 0.004461435601115227, 0.003472223412245512, -0.0034974212758243084, -0.003992320969700813, 0.002922544488683343, -0.0025132582522928715, -0.006242782808840275, -0.010481518693268299, -0.00467882864177227, -0.0033654312137514353, -0.005357579793781042, -0.011635358445346355, -0.001209516660310328, -0.010007742792367935, 0.005135416518896818, -0.007778883911669254, 0.0076546091586351395, 0.008820737712085247, -0.005858170334249735, 0.009092874825000763, -0.0026640412397682667, 0.003987613599747419, 0.0027318052016198635, 0.005319708026945591, 0.0008814848843030632, -0.0053234221413731575, -0.008852364495396614, 0.011965802870690823, -0.010350313037633896, -0.0007373036351054907, 0.013661839999258518, 0.004693209193646908, 0.009436246939003468, 0.0018524701008573174, -0.0005870405002497137, 0.002873498247936368, 0.0069372523576021194, -0.015586530789732933, 0.0032317040022462606, -0.0017333893338218331, -0.0000013949229469290003, 0.005068955011665821, -0.0034429491497576237, 0.0018374077044427395, 0.007032910827547312, -0.00020572652283590287, -0.006858914624899626, -0.0026921925600618124, 0.002390617970377207, 0.004302387125790119, -0.012620905414223671, -0.0013059173943474889, -0.004826202988624573, -0.005893342196941376, -0.0018041037255898118, -0.003146704751998186, -0.0022693693172186613, 0.004492555744946003, -0.003628351492807269, 0.0053087268024683, 0.0030930377542972565, -0.004622688051313162, 0.013011778704822063, -0.003432591911405325, -0.005577447824180126, 0.00288208806887269, 0.002005865564569831, -0.003527302062138915, -0.0071303402073681355, -0.0021110218949615955, 0.002376464195549488, 0.00659265648573637, -0.002496852073818445, -0.00526163075119257, -0.002687678672373295, 0.0011003867257386446, -0.010886303149163723, 0.0012604298535734415, 0.012506038881838322, -0.0032930253073573112, 0.005984327755868435, 0.0015093510737642646, -0.00807519257068634, -0.015231847763061523, 0.05328111723065376, 0.0008286020602099597, 0.003977568820118904, 0.003331483108922839, -0.007219555322080851, -0.0007051433203741908, 0.0003668942372314632, 0.009808865375816822, -0.00739638414233923, -0.008283751085400581, 0.009392989799380302, -0.002549402881413698, 0.004601112566888332, 0.0027625863440334797, 0.0011413840111345053, 0.014776227064430714, -0.005312983877956867, -0.018311627209186554, -0.013474870473146439, 0.007796148303896189, -0.0025298630353063345, -0.006680177059024572, 0.008103424683213234, -0.0018302334938198328, -0.00366193987429142, 0.0006142037454992533, 0.007486650720238686, 0.0005044642020948231, 0.00025762509903870523, -0.002249175449833274, -0.005413995124399662, 0.0021577212028205395, 0.0033254630398005247, 0.006428918335586786, 0.005657821428030729, -0.0032656295225024223, 0.005987304728478193, -0.003289639251306653, -0.0005996180116198957, -0.0004226128803566098, 0.0017921600956469774, 0.006588540971279144, -0.0015248807612806559, -0.0024163315538316965, 0.0035720367450267076, 0.00587467011064291, 0.0029843715019524097, 0.009276875294744968, -0.0002493152569513768, -0.007299020886421204, 0.008295804262161255, 0.007503357715904713, 0.0005002249963581562, 0.007961111143231392, -0.0024544731713831425, 0.0055555361323058605, 0.001067054457962513, -0.00949572678655386, -0.018401537090539932, -0.0018532691756263375, 0.005387383978813887, 0.007399331778287888, -0.0019864814821630716, 0.0037269562017172575, -0.000474791566375643, -0.0015483048046007752, -0.007731573190540075, -0.00829737912863493, -0.0038918855134397745, 0.0003040446317754686, 0.00509618641808629, 0.06787913292646408, -0.005199276842176914, -0.0027949856594204903, -0.0064562177285552025, -0.0006920908344909549, -0.002892258809879422, -0.00047265589819289744, -0.0009553696145303547, -0.000779713795054704, 0.0016396010760217905, -0.0008488643798045814, -0.0077918702736496925, -0.010187962092459202, 0.0023815101012587547, 0.0006137480377219617, -0.0037681490648537874, 0.004863740410655737, 0.00886223278939724, -0.009808643721044064, 0.002297024941071868, -0.012531925924122334, -0.00005941955532762222, -0.004648551810532808, -0.010365103371441364, -0.003671784419566393, -0.0027776791248470545, 0.002759690163657069, 0.002603142987936735, 0.006815127097070217, -0.004845895804464817, 0.0067193591967225075, -0.000446254009148106, 0.002686671447008848, -0.0029382009524852037, 0.0014854600885882974, -0.006975555792450905, 0.00793917290866375, 0.0017427188577130437, -0.013109749183058739, -0.004867729730904102, -0.00506791053339839, 0.00042598656727932394, -0.006978551857173443, 0.003807295812293887, -0.0024616997689008713, 0.006209075450897217, -0.0009054528782144189, 0.000381917372578755, -0.004492053296416998, 0.0037849799264222383, -0.012759670615196228, 0.0046800472773611546, -0.1762050837278366, 0.009807390160858631, 0.001585446996614337, -0.003425594884902239, -0.004651092924177647, -0.015031098388135433, -0.005454798694700003, 0.0039592282846570015, 0.010105188935995102, 0.0005827906425110996, -0.0011270159156993032, -0.003066976787522435, 0.007444001734256744, 0.005209523718804121, 0.0005578025011345744, -0.008014978840947151, 0.0041932957246899605, -0.0035661200527101755, 0.0014187549240887165, 0.004281625617295504, 0.007043262477964163, 0.009208998642861843, 0.003203667001798749, 0.000019566934497561306, -0.00261247088201344, -0.005132777150720358, 0.006670829840004444, -0.0023035374470055103, 0.005717971362173557, -0.010863970033824444, -0.002204624703153968, -0.007225046865642071, -0.0035850314889103174, 0.0000803219954832457, 0.004152631852775812, 0.00156386976595968, 0.007440024521201849, 0.0025532362051308155, -0.008295418694615364, 0.006086778361350298, -0.009169457480311394, 0.0280259121209383, 0.006372783798724413, 0.007835236378014088, 0.003335356479510665, -0.003923475276678801, -0.004908233415335417, 0.009007633663713932, 0.001548510743305087, 0.012045692652463913, -0.015598907135426998, -0.0032161609269678593, 0.002362102037295699, 0.01871563494205475, -0.0025587400887161493, -0.011087658815085888, -0.007496264297515154, -0.004120555706322193, 0.0012580003822222352, 0.009703177958726883, 0.011146659962832928, -0.004688901361078024, 0.007945316843688488, -0.003513244679197669, -0.02001475915312767, 0.0023478721268475056, -0.0062471372075378895, -0.007862638682126999, -0.000983041594736278, 0.006905611138790846, 0.011724920012056828, -0.0014962373534217477, 0.0032389601692557335, -0.0013715054374188185, 0.005241623613983393, -0.001961147878319025, 0.007651584688574076, -0.0003693759790621698, 0.0032156615052372217, -0.009784897789359093, 0.007465970702469349, -0.00911802239716053, -0.002248263219371438, 0.00002333652082597837, -0.004046082496643066, 0.011175802908837795, 0.0038384273648262024, -0.0023851669393479824, -0.0028095135930925608, -0.008469837717711926, -0.00477389432489872, 0.0032357159070670605, 0.0017989326734095812, -0.007476289756596088, 0.0029371269047260284, 0.0013084280071780086, 0.004903317894786596, 0.005042721051722765, -0.008605622686445713, 0.0048832762986421585, 0.0055111064575612545, -0.0065954942256212234, 0.0008368670823983848, -0.005267011001706123, 0.004482528660446405, 0.003832918358966708, -0.005303999874740839, -0.005587342195212841, 0.0033417721278965473, -0.006289014592766762, -0.005023260600864887, 0.005289464723318815, -0.00838481169193983, -0.01067018136382103, -0.0007458317559212446, -0.01269178744405508, 0.00031754368683323264 ]
8aa50b5f8d204a63672c266b3319435ba3678601
2,686
py
Python
insight/migrations/0001_initial.py
leonhead/chess-insight
b893295719df21b4fee10d4e7b01639ded8b42b4
[ "MIT" ]
null
null
null
insight/migrations/0001_initial.py
leonhead/chess-insight
b893295719df21b4fee10d4e7b01639ded8b42b4
[ "MIT" ]
null
null
null
insight/migrations/0001_initial.py
leonhead/chess-insight
b893295719df21b4fee10d4e7b01639ded8b42b4
[ "MIT" ]
null
null
null
# Generated by Django 3.1 on 2020-09-08 07:43 from django.db import migrations, models import django.db.models.deletion class Migration(migrations.Migration): initial = True dependencies = [ ] operations = [ migrations.CreateModel( name='OpeningSystem', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('name', models.CharField(max_length=40)), ], ), migrations.CreateModel( name='User', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('name', models.CharField(max_length=40)), ], ), migrations.CreateModel( name='Opening', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('name', models.CharField(max_length=40)), ('eco', models.CharField(max_length=3)), ('moves', models.TextField()), ('opening_system', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='insight.openingsystem')), ], ), migrations.CreateModel( name='Game', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('elo_mean', models.IntegerField(default=0)), ('elo_diff', models.IntegerField(default=0)), ('result', models.CharField(max_length=40)), ('timecontrol', models.CharField(max_length=40)), ('timestamp', models.DateTimeField()), ('raw', models.TextField()), ('opening', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='insight.opening')), ], ), migrations.CreateModel( name='Analyse', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('turnover_move', models.IntegerField(default=0)), ('turnover_evaluation', models.IntegerField(default=0)), ('unbalance_material', models.IntegerField(default=0)), ('unbalance_officers', models.IntegerField(default=0)), ('unbalance_exchange', models.IntegerField(default=0)), ('game', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='insight.game')), ], ), ]
41.323077
127
0.562919
1
1.3671
[ 0.0022075220476835966, 0.02495562843978405, 0.008602173067629337, 0.0014627402415499091, 0.003896077163517475, -0.004179209936410189, -0.010634548030793667, 0.0032341722398996353, -0.008691354654729366, 0.0037421153392642736, 0.00485477177426219, 0.004729007836431265, 0.00605468824505806, -0.018040355294942856, 0.003200983628630638, 0.017570313066244125, -0.05195597931742668, 0.0020537085365504026, -0.004716048017144203, 0.0016701817512512207, -0.007648335304111242, 0.009229956194758415, 0.011727931909263134, 0.005822732578963041, 0.005715623963624239, -0.0032603552099317312, 0.009050939232110977, 0.002394634298980236, -0.008740217424929142, -0.00721182394772768, -0.001687337993644178, -0.00263953790999949, -0.007649578154087067, -0.008925046771764755, 0.005848046857863665, -0.0019113585585728288, 0.00031528709223493934, -0.021202966570854187, 0.01199994795024395, -0.0016496592434123158, -0.008018732070922852, -0.01700592413544655, 0.0011239377781748772, 0.0035383685026317835, -0.01078866608440876, -0.0007819485035724938, -0.004634610842913389, 0.0042806705459952354, -0.009141449816524982, 0.005917894653975964, -0.011285480111837387, 0.0044038123451173306, 0.013378409668803215, 0.005300735589116812, -0.004421004094183445, -0.006257863249629736, 0.01168058905750513, 0.0009455616236664355, -0.010696896351873875, -0.0027481575962156057, -0.003575346665456891, -0.0015930176014080644, 0.006282781716436148, 0.0014383367961272597, -0.017584217712283134, -0.006706102751195431, -0.004512309096753597, 0.003667830489575863, -0.000028911055778735317, 0.004532685969024897, 0.0009525881614536047, -0.00011157909466419369, 0.005933669395744801, 0.005053782369941473, 0.0047243451699614525, -0.00266598304733634, -0.0012070077937096357, 0.001394761959090829, 0.009551440365612507, 0.003283003345131874, 0.005483553744852543, -0.00712052034214139, 0.005537336226552725, 0.008405886590480804, 0.014900720678269863, 0.0065530817955732346, 0.02074589394032955, -0.01220252551138401, 0.047050874680280685, 0.007074037101119757, -0.011297476477921009, 0.003636704059317708, -0.008670089766383171, -0.00013445637887343764, -0.0022675662767142057, -0.02795039303600788, -0.000578272738493979, -0.004897718783468008, 0.0011083207791671157, 0.00045404763659462333, -0.0005261853220872581, 0.007630867883563042, 0.0003358132962603122, -0.003274645423516631, -0.007873610593378544, 0.013336570002138615, -0.0090456772595644, -0.004271646495908499, 0.006577220745384693, 0.002668753731995821, -0.01041998527944088, -0.0004644844448193908, 0.0015308816218748689, -0.012900064699351788, 0.0034986475948244333, 0.0024946422781795263, -0.00606643408536911, 0.05440572276711464, -0.0007747675990685821, 0.0033392012119293213, -0.006457188632339239, 0.0026760930195450783, 0.0016984898829832673, 0.008300443179905415, 0.006616475526243448, -0.004495084751397371, 0.010715468786656857, 0.008913847617805004, 0.0040648328140378, 0.007886422798037529, -0.0029441332444548607, 0.007611215580254793, -0.004355436656624079, -0.0031269751489162445, 0.00195623142644763, -0.00844593159854412, 0.009307382628321648, -0.0020885136909782887, -0.008044580928981304, 0.0013161938404664397, -0.0015074178809300065, -0.009194420650601387, 0.0014175988035276532, -0.004808167926967144, 0.0028299710247665644, -0.011965755373239517, -0.0017389116110280156, -0.0019501519855111837, -0.00438749510794878, 0.004579230677336454, 0.011138743720948696, 0.0045751179568469524, 0.0031794440001249313, -0.006730607245117426, -0.010539516806602478, 0.001057764864526689, -0.00398282939568162, 0.0021662376821041107, 0.007305902428925037, 0.004436671733856201, -0.009426343254745007, -0.001068665413185954, 0.001810272689908743, 0.004213100764900446, -0.0016833702102303505, 0.0016544678946956992, -0.010146831162273884, 0.006989946588873863, -0.0010131514864042401, 0.0032004995737224817, 0.010412770323455334, -0.005863269325345755, -0.0013648088788613677, 0.0005216776626184583, 0.002173986053094268, -0.0008972365176305175, 0.004260952118784189, 0.011060976423323154, -0.002671668538823724, -0.004326473455876112, 0.00418467540293932, 0.005534790921956301, 0.00802825391292572, 0.004946411587297916, -0.0007124546682462096, 0.003852325025945902, -0.005102086346596479, -0.0002900782856158912, 0.005509375594556332, -0.005111370701342821, 0.004545440897345543, 0.002876435173675418, -0.013952088542282581, -0.007498102728277445, 0.0011771509889513254, -0.009162874892354012, 0.002394423121586442, 0.01472986489534378, 0.011689727194607258, -0.001963759073987603, 0.004479214549064636, -0.009794052690267563, 0.0018612343119457364, 0.005725861992686987, 0.0023238309659063816, -0.012143203057348728, -0.95749431848526, 0.007897961884737015, 0.0027797254733741283, -0.0009076906135305762, 0.00366659346036613, 0.003533864626660943, 0.001575833884999156, 0.004339863080531359, 0.01492938119918108, -0.008748973719775677, -0.005988137796521187, -0.009625972248613834, -0.00999579019844532, -0.002013202989473939, -0.009664148092269897, -0.0034746567253023386, -0.005609041545540094, -0.0069999112747609615, -0.00011060151882702485, -0.005413317587226629, -0.004287944175302982, 0.007103536278009415, -0.002079352270811796, 0.005308879539370537, 0.005946843884885311, 0.00299628172069788, -0.00494424719363451, -0.0009495760314166546, -0.0032155984081327915, -0.0026086645666509867, -0.00752220768481493, -0.014261884614825249, -0.005752206780016422, 0.00047408899990841746, 0.00936796236783266, 0.00048254025750793517, 0.0102935079485178, -0.0029056232888251543, 0.0021714651957154274, -0.007875396870076656, 0.005642755422741175, -0.00020558538381010294, 0.002487499499693513, -0.028476456180214882, 0.00045669154496863484, -0.002051293384283781, -0.007155872415751219, 0.008566595613956451, -0.0004549519799184054, -0.0006799210095778108, -0.005552966613322496, -0.004081291146576405, 0.0069183604791760445, -0.008369341492652893, 0.0032634572125971317, -0.006668240763247013, -0.00820856261998415, -0.0015456980327144265, -0.007795361336320639, 0.0012139570899307728, 0.00230949348770082, -0.003666351782158017, -0.0048095001839101315, -0.0030509766656905413, 0.0035930562298744917, 0.003946068696677685, 0.0022972235456109047, -0.017180517315864563, -0.005964335985481739, 0.00019354383402969688, 0.001019325340166688, -0.0036645568907260895, -0.004560173023492098, 0.004585414659231901, -0.00946480967104435, 0.006934145465493202, 0.0027059169951826334, -0.0014487915905192494, -0.012174321338534355, 0.0009574670111760497, -0.010637392289936543, -0.009359229356050491, 0.0014224976766854525, -0.005772735923528671, -0.0038594254292547703, -0.0021945766638964415, 0.00009461203444516286, 0.007946701720356941, -0.00614245655015111, 0.004898453131318092, 0.011669505387544632, -0.0026627350598573685, -0.007970963604748249, 0.007921549491584301, 0.007446954492479563, 0.0022463789209723473, -0.00450197234749794, 0.001627747667953372, 0.00963428895920515, 0.007638610899448395, 0.0026537966914474964, 0.004350533243268728, 0.00004865324081038125, 0.007555175106972456, -0.0020201101433485746, 0.0016132104210555553, -0.003946743439882994, -0.0007709013298153877, -0.0037425293121486902, -0.0012157433666288853, -0.0018971336539834738, -0.002187600126489997, -0.013304637745022774, -0.01004804577678442, -0.0034978697076439857, 0.0010563366813585162, 0.0007564793340861797, -0.002692227251827717, 0.0008843427058309317, 0.002948608249425888, 0.007608314510434866, 0.00011020851525245234, -0.003495908575132489, 0.00005891452747164294, 0.0003104769275523722, -0.007043709512799978, 0.014701391570270061, -0.013106299564242363, 0.006082635372877121, -0.0003694852639455348, -0.01568911410868168, 0.006264728493988514, 0.009214016608893871, -0.009568947367370129, 0.00020257348660379648, 0.003711490659043193, 0.003999168518930674, 0.0006682007806375623, -0.0035916718188673258, -0.0014377208426594734, -0.0166628398001194, -0.0023686839267611504, 0.01972447894513607, 0.0020009998697787523, 0.01010706927627325, 0.01362298522144556, -0.004496533423662186, 0.0020772316493093967, 0.005971797276288271, 0.0024807422887533903, 0.012558283284306526, -0.010858817957341671, -0.000093858725449536, 0.002624351065605879, -0.004722984507679939, -0.0007535361219197512, 0.0068288035690784454, 0.007130445446819067, -0.004035141319036484, 0.0014938253443688154, -0.007467533927410841, -0.004309597425162792, -0.02012680098414421, -0.0021635456942021847, 0.0061110383830964565, -0.007145997136831284, 0.006548284087330103, -0.011401322670280933, 0.006929316557943821, 0.005544754210859537, -0.00024803372798487544, 0.0006557331653311849, -0.000528646691236645, 0.007851773872971535, 0.013831709511578083, -0.005191696807742119, 0.0022051541600376368, 0.0027693742886185646, -0.0010763121536001563, 0.0015785798896104097, 0.011100809089839458, -0.009077610448002815, -0.003874966176226735, 0.0033082235604524612, 0.004584076348692179, 0.0006658181082457304, -0.0038801224436610937, -0.008561035618185997, -0.0038398397155106068, 0.0012968198861926794, -0.004616009537130594, 0.004368688445538282, 0.0015047462657094002, 0.004201132338494062, -0.00628175213932991, -0.0003150317061226815, -0.002502869116142392, -0.011686012148857117, 0.011382555589079857, -0.002793129300698638, 0.0033104917965829372, 0.012743964791297913, 0.003070640144869685, -0.014138159342110157, 0.005668403580784798, 0.009218231774866581, -0.004293466452509165, 0.0032089767046272755, 0.006926767528057098, -0.006726444698870182, -0.02290695160627365, -0.0004385770589578897, -0.012730971910059452, 0.005029116757214069, -0.002768821781501174, 0.002882186556234956, -0.007188435178250074, 0.008407065644860268, 0.008442423306405544, -0.012670502997934818, -0.006035780534148216, -0.0085706552490592, 0.010725374333560467, -0.0007358323782682419, -0.0018973540281876922, -0.003727350849658251, -0.0020185455214232206, -0.0018358796369284391, -0.0027576317079365253, -0.0020865192636847496, 0.004454844165593386, 0.0005907254526391625, -0.004693123511970043, 0.00006700794619973749, -0.004366839770227671, -0.00024609288084320724, 0.002268651034682989, -0.010731147602200508, 0.002326571848243475, 0.003735642647370696, -0.001984420930966735, -0.002348406706005335, 0.002687673782929778, -0.0013098192866891623, -0.008282066322863102, -0.010630622506141663, -0.0033358880318701267, -0.0051430268213152885, -0.002043351996690035, -0.011997628957033157, -0.0013223960995674133, -0.009755485691130161, 0.005153171252459288, -0.00523374555632472, 0.006790793035179377, 0.004007508512586355, -0.00700808921828866, 0.006060669664293528, -0.0033689469564706087, 0.0050290776416659355, 0.005542034283280373, 0.008004037663340569, -0.0013406833168119192, -0.0061674038879573345, -0.00947207398712635, 0.011344005353748798, -0.008573254570364952, 0.0009008483029901981, 0.014578364789485931, 0.0050187199376523495, 0.00891431886702776, 0.0006840427522547543, 0.0008591815712861717, 0.0041747307404875755, 0.005804399959743023, -0.014148630201816559, 0.0019277653191238642, -0.004010353237390518, -0.0010488767875358462, 0.004595264792442322, -0.004698385484516621, 0.0028104688972234726, 0.009902306832373142, 0.001117616193369031, -0.0073982104659080505, -0.002990103093907237, 0.0013877043966203928, 0.004691873211413622, -0.012167862616479397, 0.0006504943012259901, -0.00208617327734828, -0.004613550379872322, -0.0009939701994881034, -0.002374980365857482, -0.0006626360700465739, 0.004076334647834301, -0.0036822000984102488, 0.005943776108324528, 0.002636224962770939, -0.005141470115631819, 0.014054549857974052, -0.00793270394206047, -0.005219975486397743, 0.001439092680811882, 0.0012367918388918042, -0.0025692982599139214, -0.006555452942848206, -0.0034356676042079926, 0.0004705215396825224, 0.0054312958382070065, -0.002979172160848975, -0.005070740822702646, -0.0006454216782003641, 0.00279672141186893, -0.007592006586492062, 0.002667618915438652, 0.012470657005906105, -0.004758262075483799, 0.005834148731082678, -0.002874738536775112, -0.00863663386553526, -0.014050602912902832, 0.05574680119752884, -0.0018062669551, 0.003884869161993265, 0.004758364055305719, -0.0059495894238352776, -0.0006563930655829608, -0.002376352669671178, 0.007404991425573826, -0.005921033211052418, -0.006232822313904762, 0.00811312161386013, -0.003617604961618781, 0.0034778928384184837, 0.0023523718118667603, -0.0016043189680203795, 0.01657877117395401, -0.004336230456829071, -0.01755359023809433, -0.015816178172826767, 0.006319059990346432, -0.0036882779095321894, -0.006157461553812027, 0.011053231544792652, -0.002169214654713869, -0.0037743072025477886, 0.0006629138370044529, 0.006525043863803148, 0.0002332284057047218, -0.0016832725377753377, -0.0033051730133593082, -0.0011492758058011532, -0.0023998147808015347, 0.002697037300094962, 0.006508941762149334, 0.007284585386514664, -0.0019014891004189849, 0.003570286091417074, -0.002691950649023056, -0.0005833245231769979, -0.0012574831489473581, 0.005610099993646145, 0.006571085192263126, -0.0003140804765280336, 0.0016459292965009809, 0.007701902184635401, 0.004586190916597843, 0.0020319451577961445, 0.011230331845581532, 0.0002591004886198789, -0.0050946129485964775, 0.010504109784960747, 0.0073904371820390224, -0.0004944363026879728, 0.006636477541178465, -0.0012378596002236009, 0.007024378050118685, 0.0029982011765241623, -0.007060738280415535, -0.013426853343844414, -0.0023419028148055077, 0.007096372544765472, 0.006835374981164932, -0.00258976430632174, 0.0014968601753935218, -0.0028295242227613926, -0.001850426197052002, -0.006015054881572723, -0.005541438236832619, -0.0016057901084423065, 0.0014700917527079582, 0.006562202703207731, 0.06910011172294617, -0.006523979362100363, -0.0011054062051698565, -0.008576168678700924, -0.0008839329821057618, -0.0024148214142769575, -0.002576368162408471, -0.0010563493706285954, -0.0017211638623848557, 0.0009689481230452657, 0.0028686411678791046, -0.0056027998216450214, -0.011150951497256756, 0.0008320332854054868, 0.003791739232838154, -0.002150819404050708, 0.005110332276672125, 0.0033558919094502926, -0.009364048019051552, 0.0012989644892513752, -0.011785333044826984, -0.0023963151033967733, -0.0026601161807775497, -0.008396442979574203, -0.004057271871715784, -0.005191463511437178, 0.004018204286694527, 0.0011500411201268435, 0.00810693297535181, -0.0026506667491048574, 0.006432844325900078, -0.004419081378728151, -0.0016532455338165164, -0.0045834798365831375, -0.001016576774418354, -0.005564417224377394, 0.008688674308359623, -0.0005912964697927237, -0.008451166562736034, -0.005591121502220631, -0.0009361383272334933, -0.0015151463449001312, -0.004647774621844292, 0.0018797662341967225, 0.0008057738305069506, 0.00788478646427393, -0.0020547432359308004, 0.0027084301691502333, -0.00416442658752203, 0.0005206393543630838, -0.014234259724617004, 0.004980653524398804, -0.1777503341436386, 0.008816043846309185, 0.0036607342772185802, -0.006077195983380079, -0.0035190412309020758, -0.012573711574077606, -0.005731056444346905, 0.00369628076441586, 0.008644436486065388, 0.0026398159097880125, -0.0024670527782291174, -0.0004896995378658175, 0.003217887133359909, 0.0035683438181877136, -0.003292697947472334, -0.0028486361261457205, 0.004857951775193214, -0.004604424349963665, 0.0014005369739606977, 0.004683607257902622, 0.0035835665185004473, 0.008113455958664417, 0.0014907093718647957, 0.003241571830585599, -0.00040604532114230096, -0.006188767030835152, 0.006975565105676651, -0.0022596174385398626, 0.006177052389830351, -0.0126657634973526, -0.0051154401153326035, -0.003404670162126422, -0.0030932168010622263, 0.0014805819373577833, 0.0028503835201263428, -0.0001456772442907095, 0.008249843493103981, 0.0004085842811036855, -0.007763625588268042, 0.007960270158946514, -0.006269985809922218, 0.02739098109304905, 0.006444823928177357, 0.007397346198558807, -0.0005333357257768512, -0.005044639576226473, -0.004123714752495289, 0.009478793479502201, 0.0026733926497399807, 0.012498102150857449, -0.012531359679996967, -0.00018600795010570437, 0.0038428930565714836, 0.019760815426707268, -0.004501992836594582, -0.010844777338206768, -0.006866443436592817, -0.003241519443690777, 0.002799306996166706, 0.0069161974824965, 0.008626151829957962, -0.003733777441084385, 0.008754398673772812, -0.0015322896651923656, -0.024721048772335052, 0.003723373170942068, -0.003997340332716703, -0.006901846267282963, 0.004305228590965271, 0.007844872772693634, 0.009881764650344849, -0.001303568365983665, 0.0014489107998088002, -0.001997515559196472, 0.004274084698408842, -0.0004598492232616991, 0.006214590277522802, -0.0014400904765352607, 0.006358377169817686, -0.009465446695685387, 0.006955982651561499, -0.008188699372112751, -0.004818352870643139, 0.003790613729506731, -0.00408967025578022, 0.009647994302213192, 0.00422141095623374, -0.0027694504242390394, 0.0005264853243716061, -0.009435400366783142, -0.0005823197425343096, 0.0007230020128190517, 0.0020361340139061213, -0.00799030065536499, 0.002073427429422736, 0.0015318369260057807, 0.003834459697827697, 0.006703183054924011, -0.010287312790751457, 0.007088599726557732, 0.0051661888137459755, -0.0044996486976742744, 0.0012243688106536865, -0.0027238682378083467, 0.0010056550381705165, 0.004630355164408684, -0.004563039634376764, -0.00569308502599597, 0.0013407682999968529, -0.0071697235107421875, -0.005717309191823006, 0.008410640992224216, -0.00886451080441475, -0.009943832643330097, -0.0019208911107853055, -0.010156587697565556, 0.002287819981575012 ]
8aa613f84bb4cdd381d01e4e99ee1eab1597c53c
1,732
py
Python
tests/test_merge.py
jmerizia/parallel-pytorch
d27b2fd145d25f1329a039c99b8895783bfc71e5
[ "MIT" ]
null
null
null
tests/test_merge.py
jmerizia/parallel-pytorch
d27b2fd145d25f1329a039c99b8895783bfc71e5
[ "MIT" ]
null
null
null
tests/test_merge.py
jmerizia/parallel-pytorch
d27b2fd145d25f1329a039c99b8895783bfc71e5
[ "MIT" ]
null
null
null
import torch import numpy as np from mpi4py import MPI from parallel_pytorch.ops import tensor_merge from parallel_pytorch.utils import abort_on_exception @abort_on_exception def test_1(): worker_shape = [2, 2] world = MPI.COMM_WORLD num_workers = np.array(worker_shape).prod() comm = MPI.COMM_WORLD.Split(color=0 if world.Get_rank() < num_workers else 1, key=world.Get_rank()) if world.Get_rank() < num_workers: if comm.Get_rank() == 0: x = torch.tensor([[0, 1], [4, 5]]) elif comm.Get_rank() == 1: x = torch.tensor([[2, 3], [6, 7]]) elif comm.Get_rank() == 2: x = torch.tensor([[8, 9], [12, 13]]) elif comm.Get_rank() == 3: x = torch.tensor([[10, 11], [14, 15]]) x = tensor_merge(x, comm=comm, worker_shape=worker_shape) if comm.Get_rank() == 0: e = torch.tensor([ [0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11], [12, 13, 14, 15], ]) assert torch.allclose(x, e), f'{x} != {e}' @abort_on_exception def test_2(): x_shape = [2, 2] worker_shape = [1, 1] world = MPI.COMM_WORLD num_workers = np.array(worker_shape).prod() comm = MPI.COMM_WORLD.Split(color=0 if world.Get_rank() < num_workers else 1, key=world.Get_rank()) if world.Get_rank() < num_workers: volume = np.array(x_shape).prod() x = torch.arange(volume).view(x_shape) x = tensor_merge(x, comm=comm, worker_shape=worker_shape) e = torch.tensor([[0, 1], [2, 3]]) assert torch.allclose(x, e), f'{x} != {e}' def run_all(): test_1() test_2() if __name__ == '__main__': run_all()
29.355932
103
0.561778
1
1.3881
[ 0.003151410026475787, 0.02420385368168354, 0.007924233563244343, 0.00117247283924371, 0.004076911136507988, -0.000862671120557934, -0.007061931770294905, 0.0011647175997495651, -0.007197909988462925, 0.0004808473167940974, 0.001514853211119771, 0.003290286986157298, 0.007185121066868305, -0.017343392595648766, -0.0006362352287396789, 0.017154110595583916, -0.04793483018875122, -0.0009219894418492913, -0.004805963020771742, 0.001764137763530016, -0.007297228090465069, 0.007734617218375206, 0.010318098589777946, 0.008691336028277874, 0.005388463847339153, -0.0024591865949332714, 0.010326126590371132, 0.00013470175326801836, -0.006813342683017254, -0.007347731851041317, 0.0004010650154668838, -0.001156281097792089, -0.009074559435248375, -0.006570594850927591, 0.005492708645761013, -0.003563063219189644, 0.0012918098364025354, -0.01696663349866867, 0.011286063119769096, -0.0043569584377110004, -0.004486936144530773, -0.01598493568599224, 0.002248727949336171, 0.004109133966267109, -0.009010680951178074, 0.0010289106285199523, -0.004515849519520998, 0.00199185311794281, -0.010840356349945068, 0.007591992150992155, -0.011775828897953033, 0.007924488745629787, 0.013217803090810776, 0.004723607562482357, -0.005058984737843275, -0.0064463685266673565, 0.011311453767120838, -0.0002088498295051977, -0.008575125597417355, 0.0027488747145980597, -0.003148657502606511, -0.001334601198323071, 0.0058198897168040276, 0.001199481775984168, -0.013752281665802002, -0.006898496765643358, -0.004525572992861271, 0.0030495482496917248, -0.0010279627749696374, 0.006557743065059185, -0.00042597620631568134, -0.000454976805485785, 0.006200177129358053, 0.004045403562486172, 0.005124164279550314, -0.00431191036477685, -0.0022998193744570017, -0.0012343229027464986, 0.009159347973763943, 0.0015640895580872893, 0.0028871807735413313, -0.0058027468621730804, 0.0019388172077015042, 0.009138059802353382, 0.01732458919286728, 0.008233563974499702, 0.02029639482498169, -0.009206338785588741, 0.048697859048843384, 0.009988894686102867, -0.006590530276298523, 0.0013394416309893131, -0.011439641937613487, -0.0009260541992262006, -0.004439683631062508, -0.0250841211527586, 0.0023883110843598843, -0.0038249820936471224, -0.002104548504576087, 0.0023796947207301855, 0.0006293000187724829, 0.007850365713238716, -0.001841192482970655, -0.0025818096473813057, -0.009371312335133553, 0.009929501451551914, -0.00980713777244091, -0.0044426750391721725, 0.00432492233812809, 0.003199589904397726, -0.011701722629368305, -0.0005806207191199064, 0.0007234085933305323, -0.012229341082274914, 0.003707612631842494, 0.003723287722095847, -0.006039388943463564, 0.05248725041747093, 0.0008702318882569671, 0.0017810844583436847, -0.005747881717979908, 0.000534806284122169, 0.002176248701289296, 0.004759983625262976, 0.011446872726082802, -0.0022609028965234756, 0.012411907315254211, 0.007943190634250641, 0.004667650442570448, 0.01036557275801897, -0.00553991599008441, 0.008515562862157822, -0.0028500959742814302, -0.001556141534820199, 0.001295705558732152, -0.007855324074625969, 0.009083736687898636, -0.0005863188416697085, -0.008883713744580746, -0.0004459084593690932, -0.0017529124161228538, -0.008723064325749874, 0.0014283180935308337, -0.005979923065751791, 0.00560013996437192, -0.010560722090303898, -0.0031721636187285185, -0.0022390459198504686, -0.0035328834783285856, 0.0030359651427716017, 0.009705394506454468, 0.004028827417641878, 0.003546548541635275, -0.005562909878790379, -0.010443370789289474, -0.001353785046376288, -0.0052422406151890755, 0.0008900563116185367, 0.004019277170300484, 0.003876944538205862, -0.010846749879419804, -0.002247757976874709, 0.0028349796775728464, 0.0007170475437305868, -0.0014316432643681765, 0.0027424648869782686, -0.008925171568989754, 0.005773039534687996, 0.0006955571006983519, 0.0031710860785096884, 0.009974644519388676, -0.005371689796447754, -0.001463572378270328, 0.0006635987083427608, 0.00006224931712495163, 0.0007020431803539395, 0.0039083994925022125, 0.009735707193613052, -0.0010861121118068695, -0.006035371217876673, 0.0035364634823054075, 0.007654505781829357, 0.010176178067922592, 0.0042173066176474094, -0.00349477119743824, 0.0019362294115126133, -0.006940481252968311, -0.0000295903992082458, 0.007082924246788025, -0.004318142309784889, 0.0053781126625835896, 0.003440763335675001, -0.01159321516752243, -0.009020370431244373, -0.0024499206338077784, -0.0070112524554133415, 0.0022888490930199623, 0.013675667345523834, 0.010589352808892727, -0.0013624544953927398, 0.0021400691475719213, -0.008075672201812267, 0.0004172569315414876, 0.009272952564060688, 0.003749496303498745, -0.012772670947015285, -0.9599577784538269, 0.008502769283950329, 0.003759366925805807, -0.002215168671682477, 0.0069253225810825825, 0.0005488361930474639, 0.004112279042601585, 0.004121692385524511, 0.012238016352057457, -0.009824509732425213, -0.005204042885452509, -0.008250369690358639, -0.00852865818887949, -0.002659176243469119, -0.007646461483091116, -0.003938046284019947, -0.00561640877276659, -0.0054343161173164845, -0.0016441759653389454, -0.002040179679170251, -0.0025921794585883617, 0.009698385372757912, -0.0032126617152243853, 0.008591831661760807, 0.003703537629917264, 0.0015608954709023237, -0.005873451475054026, -0.0008518123649992049, -0.001593821682035923, -0.002517836168408394, -0.00694279745221138, -0.015976199880242348, -0.0015402580611407757, -0.004010733682662249, 0.007703395094722509, -0.0004757972783409059, 0.008379828184843063, -0.0034446909558027983, 0.001788005931302905, -0.008744738064706326, 0.003596784081310034, 0.0004957225173711777, 0.00623633898794651, -0.031183475628495216, -0.0012089040828868747, 0.00012468465138226748, -0.010018210858106613, 0.0032103215344250202, 0.0006380571867339313, -0.0014578461414203048, -0.0019358026329427958, -0.007464757654815912, 0.011312239803373814, -0.008033818565309048, 0.0053171925246715546, -0.001936639891937375, -0.00909961573779583, -0.002860629465430975, -0.0057204836048185825, 0.0033645941875874996, 0.006798711605370045, -0.004121704027056694, -0.00478880200535059, -0.005085120443254709, 0.00449106190353632, 0.0021465281024575233, 0.0016524425009265542, -0.019375964999198914, -0.0077910940162837505, -0.003269128268584609, -0.0023101919796317816, -0.003686091862618923, -0.005197357852011919, 0.006925963331013918, -0.0077759926207363605, 0.008161921054124832, 0.0018726394046097994, -0.0037043665070086718, -0.012462838552892208, -0.00007110078149707988, -0.009782466106116772, -0.005892780143767595, 0.002563399262726307, -0.005006817169487476, -0.006292765494436026, -0.0012333845952525735, 0.0023811471182852983, 0.007267509587109089, -0.005410518031567335, 0.005901426542550325, 0.009193501435220242, -0.002330385847017169, -0.00691724568605423, 0.006624835543334484, 0.006622435059398413, 0.0029471067246049643, -0.004204404540359974, 0.0032400249037891626, 0.006843051873147488, 0.007748214993625879, 0.00023266833159141243, 0.007148525677621365, 0.0024056381080299616, 0.0051942383870482445, -0.0018300050869584084, 0.0027656930033117533, -0.00026211969088763, -0.0009501269669272006, -0.002813446568325162, -0.0005858931108377874, -0.005838392768055201, -0.0038937891367822886, -0.01191547978669405, -0.008650106377899647, -0.006064246408641338, -0.0007175148348324001, 0.002687986008822918, -0.005786384921520948, -0.0015842424472793937, 0.0004578492371365428, 0.00876097846776247, -0.00021286947594489902, -0.004188351798802614, 0.0015657605836167932, 0.0018541410099714994, -0.005502856802195311, 0.014595864340662956, -0.012423768639564514, 0.007008855696767569, 0.001781777828000486, -0.015449822880327702, 0.004576076287776232, 0.006129151210188866, -0.010975552722811699, 0.0015017378609627485, 0.0039917705580592155, 0.0013680477859452367, -0.0029066470451653004, -0.005545273423194885, -0.001978951971977949, -0.01776147074997425, 0.0002454774221405387, 0.019208865240216255, 0.0017035233322530985, 0.011210153810679913, 0.011932844296097755, -0.001484924927353859, 0.002668584929779172, 0.0025807928759604692, 0.0011107322061434388, 0.012342323549091816, -0.006709532346576452, -0.0008533996297046542, 0.0032681808806955814, -0.0051049948669970036, 0.0020581823773682117, 0.005367213394492865, 0.005729894153773785, -0.003545935731381178, 0.004307589493691921, -0.006517622619867325, -0.0033922831062227488, -0.017072126269340515, -0.002948170993477106, 0.007155432365834713, -0.004772178828716278, 0.006758549716323614, -0.011623798869550228, 0.005337165668606758, 0.006305250804871321, 0.004849964752793312, -0.0008523635333403945, 0.002708269516006112, 0.005461645778268576, 0.012019122950732708, -0.005954306107014418, 0.0020913362968713045, 0.00047552085015922785, -0.0017537242965772748, -0.002569935517385602, 0.007467471994459629, -0.005979550536721945, -0.0057305870577692986, 0.00205663638189435, 0.005250487942248583, 0.0018256907351315022, -0.0038249019999057055, -0.009002797305583954, -0.0036851081531494856, 0.0037941550835967064, -0.0069284928031265736, 0.0026718871667981148, 0.0021876669488847256, 0.002690420253202319, -0.005542464088648558, -0.0009696356137283146, -0.0018423536093905568, -0.011108781211078167, 0.010326416231691837, -0.004984139930456877, 0.0024455469101667404, 0.015377660281956196, 0.006774321664124727, -0.011898169293999672, 0.006382050458341837, 0.010946210473775864, -0.0021354886703193188, 0.006902691908180714, 0.004151207860559225, -0.005387436132878065, -0.0211484357714653, -0.0070770601741969585, -0.01147597748786211, 0.005266974214464426, -0.0014736293815076351, 0.00587101373821497, -0.008148782886564732, 0.005302316043525934, 0.008393746800720692, -0.014730921946465969, -0.007534368429332972, -0.008495531044900417, 0.006135746371001005, -0.0011320059420540929, 0.0008908195304684341, -0.003213880816474557, -0.0016342968447133899, -0.0008070513722486794, -0.003199626924470067, 0.00010909391130553558, 0.005747091490775347, 0.0002614817349240184, -0.0029314232524484396, 0.002003233879804611, -0.004391327500343323, 0.003511472139507532, -0.0001541556412121281, -0.010111761279404163, 0.003097109030932188, 0.001236341311596334, -0.0036395075730979443, -0.0009599598706699908, 0.001274063135497272, -0.001707098912447691, -0.005547150503844023, -0.011875961907207966, -0.0050589898601174355, -0.004490863066166639, -0.0019098443444818258, -0.010414726100862026, -0.002735832938924432, -0.007835963740944862, 0.007197417784482241, -0.0056250025518238544, 0.007479680236428976, 0.003958318382501602, -0.00637254910543561, 0.007059241179376841, -0.000353646872099489, 0.0035087950527668, 0.0031944732181727886, 0.003260607598349452, 0.0025520743802189827, -0.006274297367781401, -0.0076013184152543545, 0.012931596487760544, -0.010056753642857075, 0.0015550004318356514, 0.012893566861748695, 0.0064447917975485325, 0.009268958121538162, -0.001623902004212141, 0.0016103603411465883, 0.003083654446527362, 0.0079417759552598, -0.011516096070408821, 0.0017827545525506139, -0.0030206050723791122, 0.001827155938372016, 0.003008997766301036, -0.003350523766130209, 0.001037963549606502, 0.0074797458946704865, 0.00043279040255583823, -0.00634391326457262, 0.00047649836051277816, 0.0028314534574747086, 0.004837770480662584, -0.012798015028238297, 0.000770816404838115, -0.005145080387592316, -0.003974054008722305, -0.000548042356967926, -0.002021944150328636, 0.00007517033373005688, 0.003918590024113655, -0.0027239841874688864, 0.004977246280759573, 0.0020076564978808165, -0.005824490450322628, 0.015588600188493729, -0.005779463332146406, -0.003185311099514365, 0.0013621191028505564, 0.0035487485583871603, -0.002986900508403778, -0.005611855536699295, -0.002758620074018836, 0.004411579575389624, 0.006348410155624151, -0.00015655162860639393, -0.0013287763576954603, -0.0004165816062595695, 0.001314833527430892, -0.011973133310675621, 0.0024705782998353243, 0.012528651393949986, -0.0051905252039432526, 0.006984367500990629, -0.0026772909332066774, -0.009164738468825817, -0.011769965291023254, 0.05211338400840759, -0.0018687874544411898, 0.0031645663548260927, 0.0026694179978221655, -0.007155897561460733, -0.0007441085181199014, -0.0008151759393513203, 0.010574853979051113, -0.005031949374824762, -0.008696646429598331, 0.010198407806456089, -0.004394629970192909, 0.0029702179599553347, 0.0023862214293330908, 0.0005750671261921525, 0.015939805656671524, -0.0019153886241838336, -0.01726219803094864, -0.016438128426671028, 0.007388229947537184, -0.004017639439553022, -0.005990750156342983, 0.009476433508098125, -0.002575741382315755, -0.003777580102905631, 0.001251713139936328, 0.006640843581408262, 0.0017764223739504814, 0.0009105632198043168, -0.001324464101344347, -0.0011782182846218348, -0.00019243235874455422, 0.0025024188216775656, 0.005854566115885973, 0.008150356821715832, -0.0004089421418029815, 0.0054402598179876804, -0.0016206722939386964, -0.0027108725626021624, -0.00341329094953835, 0.0022512925788760185, 0.004502378404140472, -0.0030963656026870012, -0.004517463967204094, 0.004690560512244701, 0.005266040097922087, 0.0034443442709743977, 0.0077235815115273, -0.001953440485522151, -0.006746954284608364, 0.00987783633172512, 0.007091624196618795, -0.00031612117891199887, 0.00999406073242426, -0.001855810172855854, 0.005963529460132122, 0.0005883167614229023, -0.008307416923344135, -0.017177283763885498, -0.0009510714444331825, 0.00833737663924694, 0.007752074394375086, 0.00009007668995764107, 0.0022473223507404327, -0.0006064866902306676, -0.00016173215408343822, -0.005686079617589712, -0.01043312344700098, -0.0027673416770994663, 0.0024700614158064127, 0.0035235851537436247, 0.06654155254364014, -0.0065623135305941105, -0.001194563927128911, -0.009003827348351479, -0.0012384415604174137, -0.0030893723014742136, -0.0022084475494921207, -0.001137688523158431, -0.00483502633869648, 0.0038845341186970472, 0.001664192765019834, -0.007057951297610998, -0.010883201844990253, 0.0018437457038089633, -0.0006040673470124602, -0.0022764159366488457, 0.004494506865739822, 0.006208914332091808, -0.009260444901883602, 0.00018296120106242597, -0.01244349591434002, -0.003141749883070588, -0.003170819254592061, -0.011690371669828892, -0.0074402145110070705, -0.005150302778929472, 0.0059010060504078865, 0.0017216162523254752, 0.003761306870728731, -0.002437193877995014, 0.0056799836456775665, -0.003627294208854437, -0.000020687590222223662, -0.0031959787011146545, -0.0021045373287051916, -0.00557077256962657, 0.008426261134445667, 0.0032783031929284334, -0.010979869402945042, -0.00538282934576273, 0.0011126176686957479, 0.0009035663097165525, -0.004900890868157148, 0.0038146469742059708, -0.002295717364177108, 0.0063612498342990875, -0.001716273371130228, -0.00029819869087077677, -0.006374673452228308, 0.001307730213738978, -0.012108852155506611, 0.005553441122174263, -0.16954950988292694, 0.009508529677987099, 0.005685700569301844, -0.005462195258587599, -0.004121392033994198, -0.01479383371770382, -0.004730701446533203, 0.0032510135788470507, 0.011804007925093174, 0.0015750774182379246, -0.000052419622079469264, -0.0029196524992585182, 0.006334399804472923, 0.004800721537321806, 0.0007312845555134118, -0.005752872209995985, 0.004753787536174059, -0.004110765177756548, 0.00028568439302034676, 0.0037045087665319443, 0.00307736755348742, 0.00963944848626852, 0.0001555724156787619, 0.003327691927552223, -0.0022305233869701624, -0.004479009658098221, 0.005354604683816433, -0.0036765525583177805, 0.007946949452161789, -0.009926495142281055, -0.002970969071611762, -0.004631739109754562, -0.0035493671894073486, 0.002626173198223114, 0.006068010348826647, 0.0006556520820595324, 0.007409464102238417, 0.002878825878724456, -0.0076514557003974915, 0.009126923978328705, -0.010443700477480888, 0.028428098186850548, 0.004814583342522383, 0.006842986214905977, -0.00010996639321092516, -0.0058850194327533245, -0.006243074778467417, 0.009511739015579224, 0.0032864913810044527, 0.012336283922195435, -0.015128557570278645, -0.0011456887004896998, 0.003929106052964926, 0.016835572198033333, -0.005198645871132612, -0.010698619298636913, -0.006077671889215708, -0.0005470147007144988, -0.00022577877098228782, 0.0060405065305531025, 0.011004505679011345, -0.0022224243730306625, 0.0056484155356884, -0.0029283941257745028, -0.021577665582299232, 0.0026538236998021603, -0.007697638124227524, -0.007052502129226923, -0.00007450817065546289, 0.007389120291918516, 0.009454919956624508, -0.0010960123036056757, 0.002398866228759289, -0.0017969651380553842, 0.007518953178077936, 0.0007227871101349592, 0.007260511163622141, -0.0011388009879738092, 0.003931406885385513, -0.008567903190851212, 0.0075933560729026794, -0.010209239087998867, -0.005326239857822657, 0.001788002671673894, -0.003921257797628641, 0.010078929364681244, 0.003683743765577674, -0.002950996858999133, -0.002397287404164672, -0.00887930765748024, -0.004205287899821997, 0.0028487921226769686, -0.002045785542577505, -0.009257847443223, 0.0021282273810356855, 0.0018270360305905342, 0.007322750985622406, 0.005854798946529627, -0.008457609452307224, 0.0047811297699809074, 0.008278469555079937, -0.004788808058947325, 0.0015997260343283415, -0.0035431201104074717, 0.0029248397331684828, 0.0027893504593521357, -0.0037896926514804363, -0.0043363142758607864, 0.001606366247870028, -0.00932250265032053, -0.003226904897019267, 0.007050821557641029, -0.010363206267356873, -0.010927936993539333, -0.003784438595175743, -0.012544751167297363, 0.0009377199457958341 ]
8aa6533a09d6a4b3ba6f06626bf481622c2da357
542
py
Python
day07/main.py
tebriel/aoc2021
65ca19be3ad66dc52eee9ca31cf12306695a24e9
[ "Unlicense" ]
null
null
null
day07/main.py
tebriel/aoc2021
65ca19be3ad66dc52eee9ca31cf12306695a24e9
[ "Unlicense" ]
null
null
null
day07/main.py
tebriel/aoc2021
65ca19be3ad66dc52eee9ca31cf12306695a24e9
[ "Unlicense" ]
null
null
null
"""Day 07""" def process(filename): with open(filename) as infile: positions = [int(x) for x in infile.readline().strip().split(',')] min_x = min(positions) max_x = max(positions) costs = {x: 0 for x in range(min_x, max_x + 1)} for pos in costs.keys(): for crab in positions: distance = abs(pos - crab) costs[pos] += ((distance * distance) + distance) // 2 print(f"Day 07: {min(costs.values())}") if __name__ == '__main__': process('test.txt') process('input.txt')
25.809524
74
0.573801
1
0.8376
[ 0.0026217626873403788, 0.02708139270544052, 0.006667684763669968, 0.0014380571665242314, 0.006180343218147755, -0.003976894076913595, -0.012722088024020195, 0.003406963311135769, -0.005563137121498585, 0.0009759712847881019, 0.0011269185924902558, 0.004456337075680494, 0.008651336655020714, -0.01771317794919014, 0.0006706409621983767, 0.0183255597949028, -0.05352324992418289, 0.004924166481941938, -0.0025618793442845345, 0.0028648206498473883, -0.008381581865251064, 0.00962112471461296, 0.009568917565047741, 0.005213653203099966, 0.007026647683233023, 0.0012768788728863, 0.011609668843448162, 0.00350262806750834, -0.006515247747302055, -0.004580643959343433, 0.00008348473784280941, -0.0013893512077629566, -0.006041460204869509, -0.009817575104534626, 0.005882372613996267, -0.002438036724925041, 0.0008309196564368904, -0.019735626876354218, 0.012175943702459335, -0.005002893041819334, -0.0068480889312922955, -0.016973987221717834, -0.00002466418663971126, 0.006198100280016661, -0.01038552075624466, 0.0015208508120849729, -0.005396867170929909, 0.002148233586922288, -0.009903340600430965, 0.0041449605487287045, -0.011336528696119785, 0.0049914103001356125, 0.013099309988319874, 0.004958191886544228, -0.004047871567308903, -0.008991717360913754, 0.012513848021626472, -0.0005990852368995547, -0.010911226272583008, 0.0005247851950116456, -0.0028809194918721914, -0.0024625337682664394, 0.0037285948637872934, 0.002897646278142929, -0.017088212072849274, -0.006825107149779797, -0.004430936649441719, 0.002110052155330777, -0.0037561506032943726, 0.002891112118959427, 0.0010451701236888766, 0.00002179882903874386, 0.0066512045450508595, 0.0032406446989625692, 0.0010151573223993182, -0.0039007540326565504, -0.005529007874429226, 0.0023934582713991404, 0.008219161070883274, 0.003790490562096238, 0.0035447177942842245, -0.006847629323601723, 0.006180682685226202, 0.010171988978981972, 0.014606524258852005, 0.0073362309485673904, 0.018866602331399918, -0.011699375696480274, 0.04397211968898773, 0.006208199542015791, -0.010044531896710396, 0.002308076247572899, -0.009101074188947678, -0.00248854816891253, -0.002544555114582181, -0.031120937317609787, -0.0006259799702093005, -0.005670086946338415, 0.0011531016789376736, 0.0032775402069091797, 0.00009637082257540897, 0.006040101405233145, -0.0016633999766781926, -0.003286228282377124, -0.010248848237097263, 0.014025673270225525, -0.009868628345429897, -0.003252785885706544, 0.007447357755154371, 0.0014879198279231787, -0.01351078599691391, -0.0005373689928092062, 0.002774339634925127, -0.0120550487190485, 0.00467550428584218, 0.0030116611160337925, -0.005911288782954216, 0.05485737696290016, -0.0002280957269249484, 0.0008183433674275875, -0.006084038410335779, 0.000609086942858994, 0.0013271297793835402, 0.006774247623980045, 0.009781250730156898, -0.00424302089959383, 0.00866369903087616, 0.00634022755548358, 0.0022510665003210306, 0.007479880470782518, 0.0006027173949405551, 0.006204637233167887, -0.005483934190124273, -0.0018028800841420889, 0.0010762028396129608, -0.008303857408463955, 0.007964204996824265, -0.002381015568971634, -0.0043987687677145, 0.00024317952920682728, -0.0021333694458007812, -0.011160031892359257, 0.0026316510047763586, -0.0015332272741943598, 0.0015628160908818245, -0.012017421424388885, -0.004258290398865938, -0.0031421110033988953, -0.004682553466409445, 0.001867750776000321, 0.009317194111645222, 0.004956787917762995, 0.0027611886616796255, -0.005435817409306765, -0.007146080955862999, -0.001358657144010067, -0.004653892479836941, 0.0026290137320756912, 0.009516928344964981, 0.005030459258705378, -0.010069891810417175, -0.003583810292184353, 0.0029255994595587254, 0.005296021234244108, 0.00006340952677419409, 0.006791627034544945, -0.009594668634235859, 0.00970672070980072, 0.00090977264335379, 0.003108671633526683, 0.01059642992913723, -0.005858128424733877, -0.0003435530234128237, 0.0004629632458090782, 0.0016231870977208018, 0.0004129564331378788, 0.004804288502782583, 0.010989763773977757, -0.005714251194149256, -0.006255012936890125, 0.005161036737263203, 0.005691638682037592, 0.008075322024524212, 0.006102005019783974, -0.003125411458313465, 0.001501476508565247, -0.0028636555653065443, 0.00009896846313495189, 0.007354343309998512, -0.0054094805382192135, 0.0071715679951012135, 0.005828274879604578, -0.016433050855994225, -0.009365834295749664, 0.0002403961552772671, -0.01036953367292881, 0.001382640446536243, 0.015611838549375534, 0.010228089988231659, -0.0005117841647006571, 0.0014050696045160294, -0.012065183371305466, 0.0033327548298984766, 0.009094208478927612, 0.0017266288632526994, -0.01135262381285429, -0.9557123780250549, 0.005278396420180798, 0.005345129407942295, -0.002138797426596284, 0.0038483855314552784, 0.0021924099419265985, 0.0020700793247669935, 0.005324169062077999, 0.013790500350296497, -0.011184373870491982, -0.006466639693826437, -0.009667483158409595, -0.012500819750130177, -0.0003626547986641526, -0.006258947774767876, -0.004338053986430168, -0.007296042516827583, -0.008421734906733036, -0.0009810440242290497, -0.0024985617492347956, -0.002976448507979512, 0.009831171482801437, -0.00012687017442658544, 0.004707628861069679, 0.0033364961855113506, 0.0026262651663273573, -0.004961623344570398, -0.0025020854081958532, -0.0007452282588928938, -0.0015606528613716364, -0.008510060608386993, -0.014605013653635979, -0.005327492952346802, -0.0002764878736343235, 0.012851196341216564, 0.0010697988327592611, 0.007129766047000885, -0.0010375650599598885, -0.0003230093279853463, -0.00867889728397131, 0.0045742252841591835, 0.00029777511372230947, 0.0026559841353446245, -0.028817176818847656, 0.0008146896725520492, -0.0008954868535511196, -0.009176403284072876, 0.007566493935883045, 0.004007087089121342, -0.00007676061795791611, -0.00323158479295671, -0.004444814287126064, 0.010000410489737988, -0.008298205211758614, 0.003725736401975155, -0.00286798644810915, -0.007203142158687115, -0.0009809896582737565, -0.010054201819002628, -0.0005563535960391164, 0.0039540608413517475, -0.004686270374804735, -0.003829474560916424, -0.004236999899148941, 0.002227779943495989, 0.0012018604902550578, 0.00791737250983715, -0.018675120547413826, -0.004504958167672157, -0.00018386203737463802, 0.0015705362893640995, -0.0014310930855572224, -0.005522065795958042, 0.002751521300524473, -0.009470936842262745, 0.0049997493624687195, 0.001372355967760086, -0.00012587681703735143, -0.011352220550179482, 0.001292577595449984, -0.008780215866863728, -0.00992125179618597, 0.0049342685379087925, -0.005379998590797186, -0.003653037128970027, 0.00020888690778519958, 0.004480295814573765, 0.007643825840204954, -0.004308330360800028, 0.002832654397934675, 0.009350080043077469, -0.0035082122776657343, -0.011860803700983524, 0.007863459177315235, 0.007546535227447748, 0.0012545424979180098, -0.0008454981143586338, 0.0040972367860376835, 0.00835730042308569, 0.006275578401982784, -0.0010350871598348022, 0.0037980293855071068, 0.0003026154590770602, 0.009643095545470715, 0.001509312423877418, 0.00511654419824481, -0.0026044670958071947, -0.00036673719296231866, -0.00463591143488884, 0.0012461913283914328, -0.004941955208778381, -0.0006727924919687212, -0.012410691007971764, -0.010427097789943218, -0.0037404790055006742, 0.003384113311767578, -0.0004953138413839042, -0.004376722499728203, 0.00035629962803795934, -0.0001704041351331398, 0.008389385417103767, -0.0021760466042906046, -0.006095412187278271, -0.0003728916053660214, 0.0018598721362650394, -0.007211943622678518, 0.014237227849662304, -0.010472036898136139, 0.005855071358382702, -0.0007823070627637208, -0.013192874379456043, 0.007222194690257311, 0.011017165146768093, -0.007189599331468344, 0.0035128616727888584, 0.0013285259483382106, 0.004170374944806099, -0.001828277949243784, -0.00492651853710413, -0.004547178279608488, -0.017923101782798767, 0.0012479289434850216, 0.02236526645720005, 0.002595089143142104, 0.010594397783279419, 0.012933053076267242, -0.006981611251831055, 0.0032158526591956615, 0.005912499967962503, 0.0008877759682945907, 0.013171751983463764, -0.006546676158905029, 0.00021669255511369556, 0.001984519185498357, -0.005652920808643103, 0.0027942615561187267, 0.0038873497396707535, 0.005336282774806023, -0.004319490399211645, 0.0015763918636366725, -0.005338670220226049, -0.0028809099458158016, -0.01777525618672371, -0.0004597883380483836, 0.009079170413315296, -0.0029225521720945835, 0.004578474443405867, -0.01317679788917303, 0.003720830660313368, 0.004238632041960955, 0.004443559795618057, -0.00162490364164114, 0.002150016836822033, 0.0053388564847409725, 0.01244351640343666, -0.0069990153424441814, 0.002281355205923319, 0.0023196313995867968, -0.0024630508851259947, 0.0008325507515110075, 0.00379127892665565, -0.008162461221218109, -0.004411797970533371, 0.003497591707855463, 0.003514324314892292, -0.0017831720178946853, -0.00278717209585011, -0.008112125098705292, -0.003924831748008728, 0.0019187249708920717, -0.008592696860432625, 0.00615143496543169, -0.0005598136922344565, 0.002707905136048794, -0.008499006740748882, -0.0003588695835787803, -0.005799960345029831, -0.012207195162773132, 0.0106477290391922, -0.0015225722454488277, 0.003339797491207719, 0.010870026424527168, 0.003924922086298466, -0.013014155440032482, 0.007641125004738569, 0.008791408501565456, -0.002757957438006997, 0.0018993907142430544, 0.008739730343222618, -0.004228603560477495, -0.02390497364103794, -0.0024158144369721413, -0.012019970454275608, 0.006721403915435076, -0.001830133842304349, 0.002822247100993991, -0.009473275393247604, 0.0057711536064744, 0.005200717598199844, -0.014697706326842308, -0.005248260218650103, -0.009552174247801304, 0.009247533045709133, -0.0017241889145225286, -0.0035780395846813917, -0.0038878864143043756, -0.0019531529396772385, -0.002330860821530223, -0.0024122551549226046, -0.0005632793763652444, 0.004804929252713919, 0.0042964983731508255, -0.002519888337701559, 0.002775948029011488, -0.004211511462926865, 0.003209905233234167, 0.000699553347658366, -0.010727791115641594, 0.0032390374690294266, 0.004809793550521135, -0.00287364493124187, -0.0022984722163528204, 0.0014068464515730739, -0.002469124738126993, -0.003780762432143092, -0.011829089373350143, -0.00474172318354249, -0.005119759123772383, -0.004144272767007351, -0.011797665618360043, -0.002062947256490588, -0.009078015573322773, 0.007844769395887852, -0.006637118756771088, 0.006737859919667244, 0.005455227568745613, -0.0054181539453566074, 0.00910240225493908, -0.0025681690312922, 0.005309827160090208, -0.0005520276608876884, 0.006022785324603319, 0.0017997648101300001, -0.0044061546213924885, -0.010210437700152397, 0.010324454866349697, -0.011762174777686596, 0.00006560977635672316, 0.01415119506418705, 0.004997969605028629, 0.009172656573355198, 0.0014049180317670107, -0.0005063507705926895, 0.004810736980289221, 0.008078779093921185, -0.0142690259963274, 0.0034030417446047068, -0.0033098419662564993, -0.0015261893859133124, 0.00327414576895535, -0.0033748005516827106, -0.00019916371093131602, 0.006731330417096615, 0.0011005321284756064, -0.006631832104176283, -0.002186516998335719, -0.00011918196105398238, 0.0029822164215147495, -0.012395909056067467, -0.003216652199625969, -0.004963381215929985, -0.0061918869614601135, -0.003664016490802169, -0.002562872599810362, -0.0011793511221185327, 0.004139486234635115, -0.0031567176338285208, 0.007041937205940485, 0.0031396783888339996, -0.005104528274387121, 0.014058397151529789, -0.005055380053818226, -0.002108657965436578, 0.00365896662697196, 0.003979634493589401, -0.0022899778559803963, -0.006348654627799988, -0.0014899307861924171, 0.0006864629685878754, 0.004086418077349663, -0.0026566246524453163, -0.006558113265782595, -0.002131300512701273, 0.0008693809504620731, -0.007937652058899403, 0.0004807611694559455, 0.011205174960196018, -0.004186600912362337, 0.004991741850972176, -0.00020203011808916926, -0.00811645109206438, -0.013699146918952465, 0.055977508425712585, 0.0005253415438346565, 0.004278962500393391, 0.00641196733340621, -0.006228737998753786, 0.000010324883987777866, -0.0016520635690540075, 0.006459861993789673, -0.006793980021029711, -0.007446774281561375, 0.008522402495145798, -0.003917548805475235, 0.0018329238519072533, 0.0017304704524576664, -0.0007419664179906249, 0.01633036881685257, -0.00610851775854826, -0.016832049936056137, -0.014173689298331738, 0.007322464603930712, -0.002135002054274082, -0.006823617499321699, 0.007680689916014671, -0.003754341509193182, 0.0005128401680849493, 0.0007510097930207849, 0.0057161240838468075, -0.0007360586314462125, 0.000713275047019124, -0.0013717995025217533, -0.0027911693323403597, -0.0010415735887363553, 0.003144054440781474, 0.006156498100608587, 0.00914565846323967, -0.0018170593539252877, 0.005760390777140856, -0.0005595835391432047, -0.00043760015978477895, -0.002364418236538768, 0.006543874274939299, 0.00713814003393054, -0.0017800603527575731, -0.0019043863285332918, 0.005449733231216669, 0.005106294993311167, 0.0028884676285088062, 0.012764997780323029, 0.0009548758389428258, -0.007165901828557253, 0.010040385648608208, 0.008357897400856018, -0.000747382640838623, 0.008836041204631329, -0.0018765260465443134, 0.00506201758980751, 0.00253338273614645, -0.008883452974259853, -0.012022353708744049, -0.0005038357339799404, 0.009204213507473469, 0.01005448866635561, -0.0036674789153039455, 0.0007600148674100637, 0.0009800216648727655, -0.0032073676120489836, -0.008793462067842484, -0.006309786345809698, -0.003182852640748024, -0.0010610086610540748, 0.004636929836124182, 0.07393837720155716, -0.006977916229516268, -0.002632885705679655, -0.009154063649475574, -0.0005145934992469847, -0.0013142586685717106, -0.000999272451736033, -0.00015434325905516744, 0.0013038086472079158, 0.003592519089579582, 0.0013665787409991026, -0.008471610955893993, -0.008651948533952236, 0.00403686473146081, 0.003380297916010022, -0.001120848348364234, 0.004154549911618233, 0.0071868086233735085, -0.00825495831668377, 0.0011472973274067044, -0.011237038299441338, -0.00325213186442852, -0.0033828227315098047, -0.008129038847982883, -0.0006868396303616464, -0.0033298193011432886, 0.000916189281269908, 0.002758878283202648, 0.004622724372893572, -0.005512150935828686, 0.006083456799387932, -0.003895584726706147, 0.002358394442126155, -0.004859587177634239, -0.00103157723788172, -0.006029317155480385, 0.008692574687302113, 0.0010786392958834767, -0.013745790347456932, -0.006436776835471392, -0.0018353865016251802, -0.00026931081083603203, -0.005356418434530497, 0.004498887341469526, -0.002989100757986307, 0.008721440099179745, -0.0005854180781170726, 0.0025021862238645554, -0.00612952746450901, 0.0010558866197243333, -0.011320851743221283, 0.004282773472368717, -0.18263937532901764, 0.010663158260285854, 0.0017697482835501432, -0.003001094562932849, -0.0025329741183668375, -0.014314009808003902, -0.008189917542040348, 0.002980772638693452, 0.009401758201420307, 0.00043372216168791056, -0.0005505872541107237, -0.0035415219608694315, 0.006472571287304163, 0.004006923642009497, -0.0013956603361293674, -0.0028023193590343, 0.006163033656775951, -0.0024403021670877934, -0.0006674067699350417, 0.003437471343204379, 0.008352355100214481, 0.007417983841150999, 0.0029824930243194103, 0.0017940620891749859, -0.001306848251260817, -0.0051462831906974316, 0.004359091632068157, -0.0009401675779372454, 0.004597232211381197, -0.010422371327877045, -0.002617364516481757, -0.0058245547115802765, -0.0025805325713008642, 0.0013208789750933647, 0.004377744160592556, -0.00036707130493596196, 0.0056856730952858925, 0.0014893632614985108, -0.00852314755320549, 0.00696896156296134, -0.008765928447246552, 0.03132477402687073, 0.003996510524302721, 0.00821222085505724, -0.0004963113460689783, -0.0034938675817102194, -0.005194096826016903, 0.010186687111854553, 0.00036388810258358717, 0.013834535144269466, -0.0114724887534976, -0.0037163407541811466, 0.0029559910763055086, 0.01654742658138275, -0.003346383571624756, -0.00988826435059309, -0.0076804934069514275, -0.005028953775763512, 0.004581798333674669, 0.009581725113093853, 0.009418321773409843, -0.005600977689027786, 0.008051667362451553, -0.003717689774930477, -0.02051088958978653, 0.002942217979580164, -0.0046432227827608585, -0.009093216620385647, -0.0016230163164436817, 0.007862184196710587, 0.01181754656136036, -0.001265683793462813, 0.005859852768480778, -0.0026667281053960323, 0.005145931616425514, -0.00196086335927248, 0.008297826163470745, -0.0027991461101919413, 0.0065812477841973305, -0.009051207453012466, 0.007318147458136082, -0.009638793766498566, -0.0032456994522362947, 0.001309243612922728, -0.00384100922383368, 0.01066465675830841, 0.004625975154340267, -0.0011650158558040857, -0.0014206590130925179, -0.010583487339317799, -0.003535608295351267, 0.002907263580709696, 0.002524507697671652, -0.00750295165926218, 0.0023492665495723486, -0.0009283118415623903, 0.003139425767585635, 0.006968915928155184, -0.009259057231247425, 0.007152137812227011, 0.0064416565001010895, -0.005996840540319681, -0.0008427958819083869, -0.0027465361636132, 0.0026762112975120544, 0.003807203145697713, -0.005036836955696344, -0.008074482902884483, 0.00648773368448019, -0.006472505163401365, -0.005823638755828142, 0.006913626100867987, -0.010605663061141968, -0.008310805074870586, -0.00002609006878628861, -0.011568186804652214, -0.0004709122295025736 ]
8aa6ff7f14bd0c2736eb3afb641dd73452250888
1,276
py
Python
src/ceres_infer/utils.py
pritchardlabatpsu/cga
0a71c672b1348cebc724560643fd908d636fc133
[ "MIT" ]
null
null
null
src/ceres_infer/utils.py
pritchardlabatpsu/cga
0a71c672b1348cebc724560643fd908d636fc133
[ "MIT" ]
null
null
null
src/ceres_infer/utils.py
pritchardlabatpsu/cga
0a71c672b1348cebc724560643fd908d636fc133
[ "MIT" ]
1
2022-02-08T01:06:20.000Z
2022-02-08T01:06:20.000Z
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ utilities @author: boyangzhao """ import pandas as pd import re def int2ordinal(n): # partially based on https://stackoverflow.com/questions/9647202/ordinal-numbers-replacement if (type(n) is int) or n.isdigit(): if type(n) is not int: n = int(n) return "%d%s"%(n,{1:"st",2:"nd",3:"rd"}.get(n if n<20 else n%10,"th")) else: return n def getFeatGene(x, firstOnly = False): # get gene if pd.isnull(x): return '' r = re.findall('([^,\()]*)\s(\(([^,]*)\)\s)*\[([^,]*)\]',x) if firstOnly: return r[0][0] else: return [n[0] for n in r] def getFeatSource(x, firstOnly = False): # get the data source if(pd.isnull(x)): return '' r = re.findall('[^,\()]*\s(\([^,]*\)\s)*\[([^,]*)\]',x) if firstOnly: return [n[1] for n in r][0] else: return [n[1] for n in r] def pd_filter(df, idx): # filters a pandas data frame, given idx # this is a safe filter such that if one of the idx is not found, they are ignored if idx is None: return df if type(idx) is not list: idx = [idx] idx = [n for n in idx if n in df.index] return df.loc[idx, :]
24.075472
96
0.530564
1
1.2096
[ 0.00021931515948381275, 0.025558585301041603, 0.006046344060450792, -0.0007855513249523938, 0.004642012063413858, -0.0038455617614090443, -0.009309059008955956, 0.0056236484088003635, -0.008553865365684032, 0.0023944219574332237, 0.0019509089179337025, 0.004355424549430609, 0.008118727244436741, -0.01814315840601921, -0.000012964239431312308, 0.01831744983792305, -0.052595268934965134, 0.004232651554048061, -0.00462997006252408, 0.002936780685558915, -0.009329849854111671, 0.009887131862342358, 0.008297613821923733, 0.008314396254718304, 0.0057126609608531, -0.00024964555632323027, 0.011953630484640598, 0.002119489014148712, -0.009106207638978958, -0.004696016199886799, -0.0004014584410469979, -0.0028148663695901632, -0.005919682327657938, -0.008199196308851242, 0.007849941961467266, -0.0034443107433617115, -0.00014374036982189864, -0.01856859214603901, 0.010701281949877739, -0.004566442687064409, -0.007504887413233519, -0.01455379743129015, 0.0007209681207314134, 0.005305594764649868, -0.010646548122167587, 0.002785327611491084, -0.0042434679344296455, 0.002335821744054556, -0.010340255685150623, 0.004380421247333288, -0.007777135819196701, 0.005904496181756258, 0.014590860344469547, 0.003908650949597359, -0.004572784528136253, -0.006120105739682913, 0.012363309971988201, 0.0007724934839643538, -0.011753030121326447, -0.0009901404846459627, -0.003217844059690833, -0.0027579718735069036, 0.0050176591612398624, 0.002915220567956567, -0.016511855646967888, -0.008006401360034943, -0.005635378882288933, 0.0016529950080439448, 0.00018640636699274182, 0.006408317945897579, 0.0004897637409158051, 0.0007932392181828618, 0.007982620969414711, 0.003956880420446396, 0.004654887598007917, -0.0040311808697879314, -0.0010614257771521807, 0.0019053776049986482, 0.008526855148375034, 0.005434618331491947, 0.003154023317620158, -0.006515444256365299, 0.005823793821036816, 0.012474806047976017, 0.013970945961773396, 0.006716993171721697, 0.020333800464868546, -0.011846290901303291, 0.04549095034599304, 0.006916984915733337, -0.00930976402014494, 0.0012400670675560832, -0.01113907154649496, -0.0024438798427581787, -0.0025933124125003815, -0.028652135282754898, 0.0009803930297493935, -0.005162845365703106, -0.001256141229532659, 0.0034595162142068148, 0.0000931420290726237, 0.007740980014204979, -0.0012191232526674867, -0.0024918075650930405, -0.009460190311074257, 0.012652352452278137, -0.009475895203649998, -0.0017152444925159216, 0.006777635309845209, 0.0022847726941108704, -0.012196472845971584, -0.0007739437278360128, 0.001076103770174086, -0.012501675635576248, 0.004625361412763596, 0.0020273744594305754, -0.005264141596853733, 0.05719589442014694, -0.0028117734473198652, 0.003433041274547577, -0.005255662836134434, 0.00017583816952537745, 0.0017580317799001932, 0.007159802597016096, 0.009674609638750553, -0.003945448435842991, 0.012830229476094246, 0.006783921271562576, 0.004040794912725687, 0.008668978698551655, -0.0011087364982813597, 0.007786818780004978, -0.005794442258775234, -0.001059856964275241, -0.0001298007118748501, -0.009324904531240463, 0.006227065809071064, -0.0009301829850301147, -0.005262731108814478, 0.0019520423375070095, -0.00033498919219709933, -0.01077280007302761, 0.0014309351099655032, -0.0037680945824831724, 0.0016779303550720215, -0.012614060193300247, -0.004657199140638113, -0.0036489006597548723, -0.0052705672569572926, 0.002148117171600461, 0.008532815612852573, 0.0037269543390721083, 0.0028465469367802143, -0.003874527756124735, -0.00827288068830967, 0.0000765064760344103, -0.003937624394893646, 0.0006918776198290288, 0.005534770432859659, 0.0028339747805148363, -0.011296255514025688, -0.0008048325544223189, 0.0036498024128377438, 0.003855753457173705, -0.0008377928752452135, 0.002836907748132944, -0.007811941672116518, 0.009009063243865967, 0.0002841455861926079, 0.004572903737425804, 0.011825197376310825, -0.005584860220551491, -0.0008207036298699677, -0.00012507745123002678, 0.002497286070138216, -0.0006691692396998405, 0.0076735299080610275, 0.01091604121029377, -0.004338080529123545, -0.004919275641441345, 0.00638856366276741, 0.0037715535145252943, 0.007148444186896086, 0.004922966007143259, -0.0027426988817751408, 0.0025987455155700445, -0.006456588860601187, -0.00001865158264990896, 0.005438295193016529, -0.003989227116107941, 0.004911031574010849, 0.004474598448723555, -0.014851070940494537, -0.006472182925790548, -0.0013015696313232183, -0.007975016720592976, 0.0012440577847883105, 0.014738690108060837, 0.011359811760485172, -0.0005861400277353823, 0.004318316467106342, -0.01112207118421793, -0.001125515322200954, 0.006046139169484377, 0.0013723962474614382, -0.011832362040877342, -0.95671147108078, 0.0061039188876748085, 0.0050627668388187885, -0.002256845124065876, 0.005882380064576864, 0.0020874228794127703, 0.0025410540401935577, 0.00478474423289299, 0.013985516503453255, -0.008281130343675613, -0.007037305273115635, -0.008653146214783192, -0.013027071952819824, -0.0015853727236390114, -0.006787894293665886, -0.0012098993174731731, -0.006138620898127556, -0.008231878280639648, -0.001140641514211893, -0.0037272970657795668, -0.001547293970361352, 0.008321141824126244, -0.001759612699970603, 0.005124222952872515, 0.004479802679270506, 0.0029732780531048775, -0.006651743780821562, -0.002262100111693144, -0.0017113917274400592, -0.0026186041068285704, -0.006413038354367018, -0.014748568646609783, -0.005548730026930571, 0.0007424800423905253, 0.010770533233880997, 0.000935970398131758, 0.007672444451600313, -0.0016885165823623538, -0.0001133387049776502, -0.00888287927955389, 0.005291034933179617, 0.0004894866142421961, 0.002201131312176585, -0.029758110642433167, -0.00021145438950043172, -0.0014667353825643659, -0.010438316501677036, 0.009122520685195923, 0.00333355157636106, -0.00174563133623451, -0.004221777897328138, -0.006953311152756214, 0.010072770528495312, -0.007307405583560467, 0.006499575916677713, -0.005386520642787218, -0.007838516496121883, -0.0005631156382150948, -0.008332178927958012, 0.0006770353647880256, 0.004926927387714386, -0.0033769342117011547, -0.004649106878787279, -0.0057454779744148254, 0.002998949261382222, 0.0013560432707890868, 0.0030788956210017204, -0.017535017803311348, -0.007932118140161037, -0.00022101773356553167, 0.002970315283164382, -0.0019364631734788418, -0.004052693955600262, 0.00384275009855628, -0.009987309575080872, 0.007107481360435486, 0.0011730761034414172, 0.0023731361143290997, -0.010628742165863514, -0.0001374146668240428, -0.009354674257338047, -0.009833423420786858, 0.002566099166870117, -0.005316062364727259, -0.004896597005426884, 0.0002639593731146306, 0.0020694343838840723, 0.006747405510395765, -0.003962460905313492, 0.0028711373452097178, 0.012514137662947178, -0.002680795034393668, -0.009726392105221748, 0.006428267806768417, 0.005505457986146212, 0.0032205753959715366, -0.0019430789398029447, 0.0029180338606238365, 0.007102116011083126, 0.007076334673911333, 0.0026356359012424946, 0.0038675295654684305, -0.0006722360849380493, 0.011832362040877342, -0.0012767976149916649, 0.0026140802074223757, -0.0018882418517023325, -0.0008459184318780899, -0.004854077007621527, -0.0014517414383590221, -0.0036545360926538706, -0.003758207196369767, -0.010631089098751545, -0.010143506340682507, -0.004836025182157755, -0.0005097513203509152, 0.0013650220353156328, -0.004877925850450993, -0.0003483295440673828, 0.002448213053867221, 0.00935510266572237, 0.0005866047577001154, -0.003673266153782606, -0.0009857714176177979, 0.000715084548573941, -0.00644898833706975, 0.013990074396133423, -0.011401781812310219, 0.005951273255050182, -0.000686808954924345, -0.015973789617419243, 0.008285184390842915, 0.009556603617966175, -0.008466520346701145, 0.0019607690628618, 0.0015540942549705505, 0.0036621589679270983, -0.001320093055255711, -0.007180906366556883, -0.0039391289465129375, -0.016737135127186775, -0.0001335278939222917, 0.02163008041679859, 0.0019547140691429377, 0.011663457378745079, 0.013220364227890968, -0.0031373328529298306, 0.0006429354543797672, 0.007284220773726702, 0.00045323639642447233, 0.01427824143320322, -0.00937668140977621, -0.001243526116013527, 0.0015442140866070986, -0.006503245793282986, 0.0017693944973871112, 0.005421885289251804, 0.004842069931328297, -0.0026889322325587273, 0.0024865809828042984, -0.007155148312449455, -0.004676652140915394, -0.01691299118101597, -0.004487387370318174, 0.007348471786826849, -0.00566213671118021, 0.004870808683335781, -0.012511327862739563, 0.0047616236843168736, 0.005514451768249273, 0.00422807689756155, 0.0008189178188331425, 0.0015293939504772425, 0.005000404082238674, 0.012644246220588684, -0.006617034785449505, 0.0028883686754852533, 0.00450870068743825, -0.001973902340978384, 0.002120112767443061, 0.008318748325109482, -0.008660774677991867, -0.004566289018839598, 0.0025635017082095146, 0.004334109369665384, 0.00004935765900881961, -0.0032158750109374523, -0.009238922968506813, -0.004365975968539715, 0.0029941934626549482, -0.005993845872581005, 0.003765254048630595, 0.0007683762814849615, 0.002259126864373684, -0.008898134343326092, -0.0014918469823896885, -0.002185819437727332, -0.010980724357068539, 0.009648471139371395, -0.002350385067984462, 0.0022523095831274986, 0.014323843643069267, 0.005698484368622303, -0.013398388400673866, 0.0068849315866827965, 0.00924555491656065, -0.005479898769408464, 0.003699789522215724, 0.007476996164768934, -0.003590220818296075, -0.02181062288582325, -0.0017940506804734468, -0.014242719858884811, 0.00602922635152936, -0.0023834325838834047, 0.001678768778219819, -0.006696329917758703, 0.007053382229059935, 0.006544998846948147, -0.014053339138627052, -0.006229506805539131, -0.00938441976904869, 0.01057911105453968, -0.0004334630211815238, -0.0011780619388446212, -0.0031872070394456387, -0.0019828726071864367, -0.0031404101755470037, -0.002110772766172886, -0.003036700887605548, 0.004188408609479666, 0.0024073999375104904, -0.0028728200122714043, 0.0016104019014164805, -0.001467587542720139, 0.0012489138171076775, 0.000911313749384135, -0.011268824338912964, 0.0024315963964909315, 0.006356263533234596, -0.0032417005859315395, -0.0030305616091936827, 0.0018878523260354996, -0.001639032387174666, -0.008310488425195217, -0.011729811318218708, -0.005864378996193409, -0.006210580933839083, -0.004006513860076666, -0.01202258188277483, -0.004034950397908688, -0.009804856963455677, 0.006494482047855854, -0.007821403443813324, 0.008257047273218632, 0.00536729022860527, -0.0051021883264184, 0.0056670960038900375, -0.0022112790029495955, 0.0040884059853851795, 0.0032366930972784758, 0.005620850250124931, 0.00023189849162008613, -0.007441934198141098, -0.008465356193482876, 0.01169031485915184, -0.009670018218457699, 0.0023309108801186085, 0.01567757874727249, 0.004063138272613287, 0.009101533330976963, -0.0016154457116499543, 0.0005599957657977939, 0.0016009516548365355, 0.006820638198405504, -0.012723018415272236, 0.002191701205447316, -0.004036170430481434, -0.0009380396222695708, 0.005097727291285992, -0.004842426162213087, 0.0013672765344381332, 0.007474785670638084, 0.0023022464010864496, -0.008180920965969563, -0.0003736505750566721, 0.0013268491020426154, 0.0034170211292803288, -0.013677886687219143, 0.000020810646674362943, -0.002688701031729579, -0.004969531204551458, -0.002391543472185731, -0.0018486201297491789, 0.00016691951896063983, 0.00540371797978878, -0.0008719762554392219, 0.006465247832238674, 0.0028159574139863253, -0.0050043147057294846, 0.015503344126045704, -0.003119003027677536, -0.005253523122519255, 0.004316793289035559, 0.002789371879771352, -0.002628407906740904, -0.0068866536021232605, -0.0025073522701859474, 0.002369445515796542, 0.005570441950112581, -0.0037401842419058084, -0.0041853585280478, -0.0026291736867278814, 0.0018892799271270633, -0.009140490554273129, 0.0004095673793926835, 0.012662108056247234, -0.0037139644846320152, 0.005843282677233219, -0.0001387080701533705, -0.007700082380324602, -0.012928477488458157, 0.055567916482686996, -0.0009623435325920582, 0.001860290882177651, 0.00566386803984642, -0.008777506649494171, -0.00040967538370750844, -0.0017547915922477841, 0.007679725997149944, -0.00830843672156334, -0.006569300778210163, 0.009583085775375366, -0.0043233707547187805, 0.0028934187721461058, 0.004009458236396313, -0.0015190268168225884, 0.01566675677895546, -0.004127240274101496, -0.0166020505130291, -0.016271425411105156, 0.00850560050457716, -0.004878488834947348, -0.006679408717900515, 0.008298423141241074, -0.004075765609741211, -0.0028059822507202625, 0.002093519316986203, 0.005989572964608669, 0.0006640658830292523, 0.00042723113438114524, -0.001974410843104124, -0.0013692600186914206, 0.00013197721273172647, 0.0028819863218814135, 0.005671247374266386, 0.008863712660968304, -0.0018500828882679343, 0.004783649928867817, -0.0011172238737344742, -0.00006228950223885477, -0.0012857159599661827, 0.00556366378441453, 0.007395472377538681, -0.0018514103721827269, -0.0026901033706963062, 0.004364939406514168, 0.003073554951697588, 0.0018357753288000822, 0.01206210907548666, 0.0008078464888967574, -0.0053909653797745705, 0.008164098486304283, 0.0060200681909918785, -0.0004702494479715824, 0.008386814035475254, -0.002873891731724143, 0.005861388985067606, 0.002066632267087698, -0.007753574289381504, -0.014337512664496899, -0.0010294674430042505, 0.007829609327018261, 0.008584611117839813, -0.004141659010201693, 0.00050331000238657, -0.0008044840069487691, -0.00314303208142519, -0.0074490648694336414, -0.00587939377874136, -0.00295471353456378, 0.0015527636278420687, 0.0029260192532092333, 0.0704026073217392, -0.0076141743920743465, -0.0016776866978034377, -0.009369323961436749, -0.001100952154956758, -0.0012008558260276914, -0.0010510788997635245, 0.0006918525323271751, -0.00032849222770892084, 0.0007277283002622426, 0.003486005123704672, -0.009878079406917095, -0.01145220547914505, 0.0014027995057404041, 0.0022759991697967052, -0.0019132891902700067, 0.003973970655351877, 0.006769942119717598, -0.007212818134576082, 0.002331748604774475, -0.011880580335855484, -0.0019111980218440294, -0.001588197541423142, -0.008330385200679302, -0.0021937116980552673, -0.004230546299368143, 0.004821923095732927, 0.0034708629827946424, 0.004125745967030525, -0.002155400812625885, 0.00578167662024498, -0.002986702835187316, 0.0008256913861259818, -0.0032121026888489723, -0.0016487588873133063, -0.006445667240768671, 0.008475575596094131, 0.0005920414114370942, -0.0116978595033288, -0.005506489425897598, -0.0006416174001060426, -0.00008902734407456592, -0.007308082189410925, 0.00390640227124095, 0.0005896903458051383, 0.005910971201956272, -0.0029572260100394487, 0.0019506971584632993, -0.005163677502423525, 0.002868395298719406, -0.01266121119260788, 0.004739836789667606, -0.1792825609445572, 0.011589213274419308, 0.0023981700651347637, -0.006302267778664827, -0.004841679707169533, -0.011424965225160122, -0.007568472996354103, 0.003355473978444934, 0.009930974803864956, 0.0029256076086312532, -0.00022259076649788767, -0.0006964635103940964, 0.005134420935064554, 0.0033542264718562365, -0.0012174986768513918, -0.004248348996043205, 0.004350970033556223, -0.004696524236351252, 0.00016008630336727947, 0.0043568359687924385, 0.004103620536625385, 0.008301463909447193, 0.004062117543071508, 0.0017727791564539075, 0.00031392931123264134, -0.003909101244062185, 0.005497126840054989, -0.002367486944422126, 0.005610802210867405, -0.01097866427153349, -0.002829688834026456, -0.005161707289516926, -0.0043435171246528625, 0.0005262185004539788, 0.004142616409808397, -0.0019103672821074724, 0.008132911287248135, 0.0024831434711813927, -0.009466354735195637, 0.007934147492051125, -0.007898072712123394, 0.028878476470708847, 0.0034868535585701466, 0.007252559065818787, 0.00014393938181456178, -0.005137907341122627, -0.0037794706877321005, 0.009114458225667477, 0.0034328242763876915, 0.012557794339954853, -0.013745592907071114, -0.003155310172587633, 0.0025415057316422462, 0.019277989864349365, -0.0069716996513307095, -0.010628619231283665, -0.007875055074691772, -0.003978140186518431, 0.0029193582013249397, 0.009335016831755638, 0.01151746790856123, -0.004297197796404362, 0.007246407680213451, -0.0017241804162040353, -0.023084765300154686, 0.004344676621258259, -0.003889211919158697, -0.0054347924888134, -0.000577355211135, 0.006670413073152304, 0.008795056492090225, -0.002785881981253624, 0.005562917795032263, 0.00009691376180853695, 0.005013518035411835, 0.0001243594306288287, 0.005924641620367765, -0.00380528811365366, 0.006674301810562611, -0.008862273767590523, 0.009504221379756927, -0.008439743891358376, -0.0003734523197636008, 0.0032221106812357903, -0.003372711595147848, 0.011551348492503166, 0.004555870313197374, -0.001570055028423667, -0.0010243583237752318, -0.010856411419808865, -0.002733388217166066, 0.0016895475564524531, 0.0034169249702244997, -0.007795502431690693, 0.002243273425847292, -0.0012045622570440173, 0.003965210635215044, 0.007542822975665331, -0.008269830606877804, 0.005217096768319607, 0.005503295920789242, -0.007081959396600723, 0.0007712048827670515, -0.002350295428186655, 0.0010486759711056948, 0.003198931459337473, -0.0064445361495018005, -0.006711060181260109, 0.0035149299073964357, -0.007288781926035881, -0.004742119926959276, 0.004079847596585751, -0.00946869421750307, -0.009402629919350147, -0.0005696738953702152, -0.010980518534779549, -0.00025077228201553226 ]
8aa76a43878c4baa56da24cd2df4e08dd1f12800
4,779
py
Python
MAIN/Screens/Settings/category_2/__init__.py
aragubas/fogoso
bd24e049ee994410320e87fb3706c95bd8c9801f
[ "Apache-2.0" ]
null
null
null
MAIN/Screens/Settings/category_2/__init__.py
aragubas/fogoso
bd24e049ee994410320e87fb3706c95bd8c9801f
[ "Apache-2.0" ]
null
null
null
MAIN/Screens/Settings/category_2/__init__.py
aragubas/fogoso
bd24e049ee994410320e87fb3706c95bd8c9801f
[ "Apache-2.0" ]
null
null
null
#!/usr/bin/python3.7 # Copyright 2020 Aragubas # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # # # -- Imports -- # from ENGINE import APPDATA as reg from ENGINE import UTILS as utils import ENGINE as tge from Fogoso.MAIN import ClassesUtils as gameObjs from Fogoso import MAIN as gameMain import pygame, sys import importlib import time from random import randint OptionsScreen_DebugModeEnabled = gameObjs.UpDownButton OptionsScreen_RandomWindowTitle = gameObjs.UpDownButton OptionsScreen_NumberFormatting = gameObjs.UpDownButton ElementsX = 0 ElementsY = 0 def Initialize(): global OptionsScreen_DebugModeEnabled global OptionsScreen_RandomWindowTitle global OptionsScreen_NumberFormatting OptionsScreen_DebugModeEnabled = gameObjs.UpDownButton(0,0,14) OptionsScreen_RandomWindowTitle = gameObjs.UpDownButton(0,0,14) OptionsScreen_NumberFormatting = gameObjs.UpDownButton(0,0,14) def Update(): global OptionsScreen_DebugModeEnabled global OptionsScreen_RandomWindowTitle global OptionsScreen_NumberFormatting global ElementsX global ElementsY if OptionsScreen_DebugModeEnabled .ButtonState == 2 or OptionsScreen_DebugModeEnabled.ButtonState == 1: current_val = gameMain.DefaultCnt.Get_RegKey("/OPTIONS/debug_enabled", bool) if current_val: gameMain.DefaultCnt.Write_RegKey("/OPTIONS/debug_enabled", "False") if not current_val: gameMain.DefaultCnt.Write_RegKey("/OPTIONS/debug_enabled", "True") if OptionsScreen_RandomWindowTitle .ButtonState == 2 or OptionsScreen_RandomWindowTitle.ButtonState == 1: current_val = gameMain.DefaultCnt.Get_RegKey("/OPTIONS/random_title", bool) if current_val: gameMain.DefaultCnt.Write_RegKey("/OPTIONS/random_title", "False") if not current_val: gameMain.DefaultCnt.Write_RegKey("/OPTIONS/random_title", "True") if OptionsScreen_NumberFormatting .ButtonState == 2 or OptionsScreen_NumberFormatting.ButtonState == 1: current_val = gameMain.DefaultCnt.Get_RegKey("/OPTIONS/format_numbers", bool) if current_val: gameMain.DefaultCnt.Write_RegKey("/OPTIONS/format_numbers", "False") if not current_val: gameMain.DefaultCnt.Write_RegKey("/OPTIONS/format_numbers", "True") OptionsScreen_DebugModeEnabled.Set_X(ElementsX + 20) OptionsScreen_RandomWindowTitle.Set_X(ElementsX + 20) OptionsScreen_NumberFormatting.Set_X(ElementsX + 20) OptionsScreen_DebugModeEnabled.Set_Y(ElementsY + 50) OptionsScreen_RandomWindowTitle.Set_Y(ElementsY + 75) OptionsScreen_NumberFormatting.Set_Y(ElementsY + 100) def Render(DISPLAY): global OptionsScreen_DebugModeEnabled global OptionsScreen_RandomWindowTitle global OptionsScreen_NumberFormatting OptionsScreen_DebugModeEnabled.Render(DISPLAY) OptionsScreen_RandomWindowTitle.Render(DISPLAY) OptionsScreen_NumberFormatting.Render(DISPLAY) # -- Debug Mode -- # gameMain.DefaultCnt.FontRender(DISPLAY, "/PressStart2P.ttf", 14, gameMain.DefaultCnt.Get_RegKey("/strings/settings/debug_mode") + str(gameMain.DefaultCnt.Get_RegKey("/OPTIONS/debug_enabled")), (240, 240, 240), ElementsX + 95, ElementsY + 52, gameMain.DefaultCnt.Get_RegKey("/OPTIONS/font_aa")) # -- Random Title -- # gameMain.DefaultCnt.FontRender(DISPLAY, "/PressStart2P.ttf", 14, gameMain.DefaultCnt.Get_RegKey("/strings/settings/random_title") + str(gameMain.DefaultCnt.Get_RegKey("/OPTIONS/random_title")), (240, 240, 240), ElementsX + 95, ElementsY + 77, gameMain.DefaultCnt.Get_RegKey("/OPTIONS/font_aa")) # -- Number Formatting -- # gameMain.DefaultCnt.FontRender(DISPLAY, "/PressStart2P.ttf", 14, gameMain.DefaultCnt.Get_RegKey("/strings/settings/number_formatting") + str(gameMain.DefaultCnt.Get_RegKey("/OPTIONS/format_numbers")), (240, 240, 240), ElementsX + 95, ElementsY + 102, gameMain.DefaultCnt.Get_RegKey("/OPTIONS/font_aa")) def EventUpdate(event): global OptionsScreen_DebugModeEnabled global OptionsScreen_RandomWindowTitle global OptionsScreen_NumberFormatting OptionsScreen_DebugModeEnabled.Update(event) OptionsScreen_RandomWindowTitle.Update(event) OptionsScreen_NumberFormatting.Update(event)
42.669643
306
0.765432
1
2.0466
[ 0.004826277960091829, 0.039216261357069016, -0.00027493672678247094, 0.0010933228768408298, -0.025942642241716385, 0.02116343565285206, -0.018554342910647392, -0.023030852898955345, -0.01599898189306259, 0.010659852996468544, 0.0565357469022274, 0.007911805994808674, 0.024963801726698875, 0.005594825372099876, 0.022277571260929108, -0.010255461558699608, 0.006512722000479698, 0.038690123707056046, 0.021505119279026985, 0.01760399155318737, -0.0006095979479141533, -0.011420347727835178, -0.013445744290947914, 0.019578967243433, 0.0035406588576734066, 0.01753244549036026, 0.0378093384206295, 0.012678036466240883, -0.029382266104221344, -0.03632457181811333, 0.0030482665169984102, 0.009911018423736095, -0.0059396796859800816, -0.01490532886236906, -0.03492242097854614, 0.023177191615104675, 0.0013923344668000937, -0.0475444421172142, 0.00666514178737998, -0.015070956200361252, -0.001987132476642728, -0.01788320019841194, 0.015982363373041153, -0.02117176540195942, 0.025585396215319633, -0.018853066489100456, -0.00793988723307848, -0.005678781308233738, -0.03834879770874977, 0.006819567177444696, -0.023427417501807213, 0.07209976017475128, 0.0272230114787817, -0.014802420511841774, 0.010575664229691029, -0.014415080659091473, 0.01593317650258541, 0.007659540046006441, -0.043070096522569656, 0.021172814071178436, -0.01215206179767847, 0.01591400057077408, -0.002410441404208541, -0.0027058308478444815, -0.03196970000863075, -0.02984774298965931, -0.020906196907162666, -0.02391834557056427, -0.043144743889570236, 0.008500098250806332, 0.00024396691878791898, 0.04689871147274971, 0.04990710690617561, 0.06185092777013779, 0.00021252046281006187, 0.019738513976335526, -0.0647629052400589, -0.017613975331187248, -0.02416890673339367, -0.02234511449933052, 0.03013436682522297, 0.04372585192322731, -0.016146665439009666, -0.013659144751727581, 0.001761878957040608, -0.01933547668159008, 0.06905771791934967, -0.031223390251398087, 0.0557582825422287, 0.021009085699915886, -0.053671106696128845, 0.023195691406726837, -0.05313266068696976, 0.009727378375828266, 0.021998392418026924, -0.07103264331817627, 0.006901036016643047, -0.04840831086039543, -0.010133670642971992, -0.000664396327920258, 0.05870068818330765, 0.01758478209376335, 0.004902495536953211, -0.01734994538128376, 0.04978055879473686, -0.017456138506531715, -0.02550802007317543, -0.034296318888664246, 0.007149868179112673, -0.0013829392846673727, -0.005630049388855696, 0.006176872178912163, -0.023018229752779007, -0.02701885998249054, -0.020467888563871384, -0.02139701135456562, 0.03929901495575905, 0.03765259310603142, 0.009382982738316059, 0.07192258536815643, 0.004662503954023123, -0.010611032135784626, 0.031202582642436028, -0.024309353902935982, -0.027496103197336197, 0.08830548077821732, -0.05023668333888054, -0.015495394356548786, 0.04017781838774681, -0.025058116763830185, -0.003170931711792946, -0.012759614735841751, 0.006182001903653145, -0.055456314235925674, 0.0095322635024786, 0.0016037870664149523, -0.019942129030823708, -0.009009910747408867, -0.03235604986548424, 0.009674535132944584, -0.004226537421345711, -0.02620771713554859, 0.027070187032222748, -0.009185007773339748, 0.003700790461152792, -0.026748646050691605, 0.021332597360014915, 0.040819812566041946, -0.017566148191690445, -0.00924812164157629, 0.023459572345018387, 0.01079122070223093, -0.011646744795143604, -0.01370313297957182, -0.05237763747572899, -0.0018555462593212724, -0.006785896141082048, -0.05934865400195122, 0.001445639762096107, -0.012905299663543701, -0.04213853180408478, 0.013803180307149887, 0.019475111737847328, -0.024044305086135864, 0.039821524173021317, 0.017695821821689606, 0.028263946995139122, 0.025413181632757187, -0.03368116170167923, 0.029646674171090126, -0.019671281799674034, -0.009725984185934067, -0.04590033367276192, -0.023582449182868004, 0.004533609841018915, 0.04363216087222099, 0.036166828125715256, 0.014119431376457214, 0.0048575736582279205, 0.02403806895017624, 0.01432411465793848, -0.00575263611972332, 0.012221604585647583, 0.021106597036123276, 0.016483109444379807, 0.029280250892043114, -0.09906099736690521, -0.0050640166737139225, 0.003603150835260749, 0.018887031823396683, -0.021354425698518753, 0.03945213183760643, -0.037088342010974884, -0.002068801550194621, 0.0030556831043213606, -0.04190974310040474, -0.036827798932790756, 0.03328786417841911, -0.015435406938195229, -0.028146080672740936, -0.005632235202938318, -0.011520379222929478, 0.007561459206044674, -0.007779085077345371, -0.017942065373063087, -0.0013013482093811035, -0.6491425633430481, 0.04106747359037399, 0.014196430332958698, -0.03589861840009689, 0.01606735959649086, -0.00885513424873352, 0.002371549606323242, 0.029909444972872734, -0.03647692874073982, 0.009633761830627918, -0.0059053595177829266, -0.01665637455880642, -0.049569062888622284, -0.03554690256714821, 0.032083798199892044, -0.02575433813035488, -0.005954265128821135, -0.0658489391207695, 0.04145064949989319, 0.024088483303785324, -0.005192126147449017, 0.005111618433147669, 0.006314422003924847, 0.0038376280572265387, 0.038651544600725174, -0.004470253828912973, 0.0692782923579216, 0.020199522376060486, -0.024767976254224777, -0.034658271819353104, -0.006009092088788748, -0.0028309677727520466, 0.017861606553196907, 0.0019290843047201633, 0.0068467725068330765, 0.04262431710958481, 0.03932241350412369, -0.001128184492699802, 0.011310404166579247, -0.004328738432377577, -0.03311004489660263, 0.006917845923453569, -0.016848089173436165, -0.05594565346837044, -0.0385773703455925, 0.0014674118719995022, 0.01750066690146923, 0.04569847136735916, 0.02393471635878086, 0.05055958777666092, -0.006893605925142765, 0.008656427264213562, 0.03624172881245613, 0.014029914513230324, -0.030716422945261, -0.017799679189920425, 0.007163527887314558, 0.0091906962916255, -0.006488770246505737, 0.022223126143217087, -0.008123697713017464, 0.009507467038929462, -0.049713678658008575, -0.0033758634235709906, 0.022072920575737953, -0.02137780375778675, 0.04155904799699783, -0.018081266433000565, -0.011341730132699013, 0.01774894818663597, -0.08190425485372543, 0.0075963763520121574, -0.05628088116645813, 0.0328390933573246, -0.018565764650702477, 0.04024706408381462, 0.03092583268880844, 0.013158466666936874, -0.07107367366552353, 0.011798876337707043, 0.01572348363697529, -0.030745364725589752, -0.0068536484614014626, -0.021631497889757156, -0.007544531486928463, -0.01979556307196617, -0.008968612179160118, 0.0004389368405099958, -0.010744001716375351, -0.020831231027841568, 0.030192941427230835, 0.021751629188656807, -0.015362371690571308, 0.04494139552116394, 0.01513747964054346, 0.02002079226076603, 0.0111162718385458, 0.03657364100217819, -0.033881962299346924, 0.06207117810845375, 0.025069426745176315, -0.05273592472076416, -0.06617499887943268, 0.01607382670044899, -0.043488550931215286, 0.01645576022565365, -0.013510050252079964, -0.016346119344234467, 0.00816707406193018, 0.017386911436915398, 0.046735506504774094, -0.020608874037861824, 0.02190413884818554, -0.015007301233708858, 0.015015644021332264, 0.0024086276534944773, 0.012804395519196987, -0.03880561888217926, 0.0340813472867012, -0.004321647342294455, -0.035592325031757355, -0.025468934327363968, 0.0005235480493865907, -0.005505658686161041, -0.005507101304829121, 0.02192975953221321, -0.08554394543170929, -0.02197413146495819, 0.009424330666661263, 0.01311145443469286, 0.020471643656492233, -0.04458716884255409, -0.017768828198313713, -0.023083411157131195, -0.006186346057802439, 0.033812712877988815, 0.022187283262610435, -0.018066156655550003, 0.009742798283696175, -0.02311023324728012, -0.034727610647678375, -0.00523995840921998, 0.042148783802986145, -0.014997980557382107, 0.03305942937731743, 0.022572457790374756, 0.020428035408258438, 0.004169312305748463, 0.005756788421422243, -0.009465602226555347, 0.009081002324819565, 0.057242050766944885, 0.01663866825401783, 0.02192120999097824, -0.03367217630147934, -0.007215330842882395, -0.039873722940683365, 0.006980686914175749, 0.0019636384677141905, 0.007789455819875002, 0.02427266724407673, -0.000277146406006068, 0.019077124074101448, 0.01166162546724081, -0.0016444094944745302, -0.006603924557566643, -0.008452570997178555, -0.033012669533491135, 0.027123931795358658, 0.03385283052921295, 0.007138481363654137, 0.010620662942528725, 0.029458805918693542, -0.0005664504133164883, 0.014852458611130714, -0.024068515747785568, 0.03072129189968109, -0.03401242941617966, 0.04679291322827339, 0.0003772262134589255, 0.03228022903203964, 0.024135634303092957, -0.042631763964891434, 0.001422151573933661, -0.005656293127685785, -0.028969189152121544, -0.027324112132191658, 0.002076063770800829, 0.013461977243423462, -0.030547326430678368, 0.009157870896160603, 0.027004096657037735, -0.024421710520982742, 0.026562321931123734, -0.0395444892346859, -0.0021598241291940212, 0.007630127016454935, -0.0016655439976602793, 0.028784165158867836, 0.002870811615139246, -0.00252098822966218, -0.020421313121914864, 0.02116553857922554, -0.01637001894414425, -0.0031348192133009434, 0.044809889048337936, -0.024051442742347717, 0.011520643718540668, 0.013068131171166897, -0.0027920305728912354, 0.023266468197107315, 0.0057947589084506035, -0.012193790636956692, -0.0488351471722126, -0.01513370405882597, 0.0095408009365201, -0.049989476799964905, -0.011245481669902802, 0.02655024826526642, 0.01873721368610859, 0.015898196026682854, -0.024100059643387794, 0.014551328495144844, 0.008228307589888573, 0.005715489387512207, -0.001165654044598341, -0.012870476581156254, -0.011708883568644524, -0.022125255316495895, -0.01916908286511898, 0.018061766400933266, -0.018269600346684456, 0.02559196762740612, -0.029560377821326256, 0.01364477165043354, 0.021631581708788872, -0.00840762909501791, -0.0037461642641574144, 0.007240950129926205, -0.018134335055947304, 0.022727379575371742, -0.018383964896202087, -0.06575559079647064, 0.02436036989092827, 0.004928216803818941, 0.01978856325149536, 0.034065838903188705, 0.0014159762067720294, 0.029371226206421852, 0.0063774557784199715, -0.01646641083061695, -0.000702537246979773, -0.013843006454408169, 0.006456922274082899, -0.008045744150876999, 0.0434214286506176, -0.002909947419539094, 0.004183472134172916, 0.011523772962391376, 0.015604333020746708, 0.05458018183708191, -0.08429562300443649, 0.03957521542906761, 0.015242948196828365, 0.011794471181929111, 0.011741137132048607, -0.010364347137510777, 0.025566184893250465, -0.040692396461963654, 0.019403066486120224, 0.0208709966391325, -0.010782994329929352, -0.01755288988351822, -0.014634065330028534, -0.015539901331067085, -0.01817586086690426, 0.006579124368727207, 0.007979204878211021, -0.017322160303592682, 0.05342801287770271, -0.0339655727148056, 0.005512543488293886, -0.01022063847631216, -0.04061058536171913, -0.025062911212444305, 0.001403692294843495, -0.006740659009665251, -0.00530990632250905, -0.05528045818209648, -0.009370056912302971, -0.019757015630602837, -0.021892406046390533, 0.02897377870976925, -0.006911023054271936, 0.00838132482022047, 0.007901442237198353, -0.02616225555539131, -0.02627355419099331, 0.014674561098217964, -0.00750250369310379, 0.01717490889132023, -0.011543463915586472, -0.022483648732304573, -0.031664036214351654, -0.005942626390606165, 0.005302342586219311, 0.02513997256755829, 0.012011442333459854, 0.028901059180498123, 0.05335410311818123, 0.016585949808359146, 0.011997834779322147, -0.032168976962566376, 0.08155029267072678, 0.004720929078757763, -0.014275219291448593, -0.003248224500566721, 0.03896230459213257, 0.029326600953936577, -0.022975372150540352, -0.06871840357780457, 0.03272305801510811, -0.026174932718276978, -0.06086190417408943, 0.008630362339317799, -0.02549939975142479, -0.019605593755841255, 0.018893828615546227, -0.0273231603205204, -0.017108052968978882, 0.029695868492126465, -0.03465469926595688, 0.00015556406287942082, 0.03170759603381157, 0.009296556934714317, 0.03679942339658737, 0.028231648728251457, 0.04241976886987686, -0.01500443834811449, -0.011541703715920448, 0.0028665433637797832, 0.03192485123872757, -0.0053916010074317455, -0.013960444368422031, 0.034245770424604416, -0.011673102155327797, -0.009708216413855553, 0.04512682557106018, 0.009244078770279884, 0.009489219635725021, -0.005224138963967562, -0.026426825672388077, 0.000651045935228467, 0.02876349166035652, -0.017612246796488762, -0.03475073724985123, 0.0172584131360054, -0.02710355632007122, 0.0014395590405911207, 0.007003686390817165, -0.03986792638897896, 0.016578901559114456, -0.013865664601325989, -0.016015885397791862, 0.008228704333305359, -0.061882294714450836, -0.013125584460794926, -0.02964559756219387, -0.0043759834952652454, 0.03594066947698593, -0.007168908137828112, -0.03248642012476921, -0.011859439313411713, 0.018173523247241974, -0.005937234964221716, 0.011321290396153927, 0.011042715050280094, 0.017667384818196297, 0.004712098278105259, 0.015070727095007896, -0.025077998638153076, -0.05687763914465904, -0.013684140518307686, -0.021787364035844803, -0.007073770742863417, -0.018856769427657127, 0.02968727797269821, 0.02857770025730133, -0.008159438148140907, -0.027370549738407135, 0.020756062120199203, 0.016216930001974106, 0.016571005806326866, 0.009468099102377892, -0.0316922664642334, -0.003732874058187008, -0.028978219255805016, 0.012851549312472343, -0.019618161022663116, 0.005810416769236326, 0.04553212597966194, 0.04745909571647644, -0.01342685054987669, -0.0033313166350126266, 0.0049843755550682545, -0.016967393457889557, -0.012365106493234634, 0.04705527424812317, 0.009602178819477558, 0.020231273025274277, -0.0010161662939935923, 0.031214894726872444, 0.01321709156036377, 0.013166330754756927, 0.0030720150098204613, 0.02753487043082714, -0.02388332411646843, -0.032640308141708374, -0.04294493794441223, 0.03075086697936058, -0.01422264613211155, -0.019320495426654816, 0.024168534204363823, 0.0006642829393967986, -0.010044736787676811, -0.009037661366164684, -0.012598050758242607, -0.004903845023363829, -0.011258620768785477, -0.00004063750748173334, -0.006478621158748865, 0.0010482617653906345, -0.04844781756401062, 0.012098440900444984, 0.006852928549051285, -0.009061508812010288, -0.057088129222393036, -0.024379897862672806, -0.008434044197201729, -0.01191667653620243, 0.01768171414732933, -0.019601471722126007, 0.019148124381899834, 0.006007685791701078, 0.012029068544507027, -0.08225291222333908, 0.029264044016599655, -0.03189842402935028, -0.05015251785516739, -0.05224475637078285, -0.10002081096172333, 0.014607222750782967, 0.007508500944823027, -0.0011692832922562957, 0.03356091305613518, -0.0064327348954975605, 0.05639578029513359, 0.030110111460089684, 0.03892521560192108, -0.02271290123462677, 0.003573866095393896, 0.030089246109128, 0.008482923731207848, 0.03760910779237747, 0.022109337151050568, 0.05651939660310745, -0.004467005375772715, -0.008800390176475048, -0.006980722304433584, -0.015949947759509087, -0.017849545925855637, 0.025995193049311638, -0.006285180803388357, 0.01260245032608509, -0.02383558638393879, -0.0014374523889273405, -0.018058231100440025, 0.04145512357354164, -0.016033928841352463, -0.011406290344893932, -0.0034917632583528757, 0.031551294028759, 0.044250406324863434, -0.002773091895505786, 0.011409132741391659, -0.02348647080361843, -0.009851238690316677, 0.010617194697260857, -0.022285550832748413, 0.02136421576142311, -0.036038611084222794, -0.015741432085633278, 0.026991788297891617, 0.0296087134629488, 0.03629300743341446, -0.002086634747684002, 0.05177755281329155, -0.0004551679303403944, 0.039558835327625275, -0.03866398707032204, 0.028675569221377373, -0.06257971376180649, -0.024665920063853264, 0.010989855043590069, 0.025811001658439636, 0.02922806143760681, 0.06967892497777939, 0.06550238281488419, 0.009136584587395191, 0.013029291294515133, 0.00007864111830713227, -0.005468078888952732, -0.0022467486560344696, 0.001493509509600699, -0.02328665554523468, 0.03387067839503288, 0.03170047327876091, -0.029794054105877876, -0.03748299181461334, -0.03831262141466141, 0.02331666834652424, -0.008722051046788692, -0.0053748334757983685, -0.018337134271860123, 0.011870665475726128, -0.047082919627428055, -0.05449128895998001, 0.004253273364156485, 0.04852858558297157, -0.015066375024616718, 0.01174295973032713, -0.036817509680986404, -0.06044381111860275, -0.014819699339568615, -0.008644958026707172, -0.017854543402791023, 0.001067593228071928, 0.027558747678995132, -0.02454018034040928, -0.013149539940059185, 0.024927804246544838, 0.03983011096715927, 0.02146632969379425, -0.013736951164901257, -0.0190687645226717, -0.02320229634642601, -0.009464755654335022, -0.0014713137643411756, 0.031149443238973618, 0.014318852685391903, 0.0014830960426479578, -0.003371698083356023, 0.027074452489614487, 0.006217017769813538, -0.023919761180877686, 0.01626453548669815, 0.0012600476620718837, 0.03751274198293686, -0.011630300432443619, -0.03022201545536518, -0.03273848816752434, 0.014315987005829811 ]
8aa779160503c74402f97032140e39891a948a62
1,279
py
Python
tests/test_toggle.py
ConnectionMaster/robotpy-wpilib-utilities
b62e563c7df113e9e513a36b9039f47f34157be1
[ "BSD-3-Clause" ]
14
2015-10-20T02:56:17.000Z
2020-03-17T04:44:12.000Z
tests/test_toggle.py
robotpy/robotpy-wpilib-utilities
80f753a1d315d234d6ecdd79be544ec01ca091ae
[ "BSD-3-Clause" ]
107
2015-01-26T23:47:10.000Z
2022-03-16T13:57:36.000Z
tests/test_toggle.py
ConnectionMaster/robotpy-wpilib-utilities
b62e563c7df113e9e513a36b9039f47f34157be1
[ "BSD-3-Clause" ]
21
2016-01-01T01:44:40.000Z
2022-03-15T18:00:35.000Z
from robotpy_ext.control.toggle import Toggle from robotpy_ext.misc.precise_delay import NotifierDelay class FakeJoystick: def __init__(self): self._pressed = [False] * 2 def getRawButton(self, num): return self._pressed[num] def press(self, num): self._pressed[num] = True def release(self, num): self._pressed[num] = False def test_toggle(): joystick = FakeJoystick() toggleButton = Toggle(joystick, 0) toggleButton2 = Toggle(joystick, 1) assert toggleButton.off joystick.press(0) assert toggleButton.on assert toggleButton2.off joystick.release(0) assert toggleButton.on joystick.press(0) assert toggleButton.off joystick.release(0) assert toggleButton.off joystick.press(1) assert toggleButton.off assert toggleButton2.on def test_toggle_debounce(): # TODO: use simulated time delay = NotifierDelay(0.5) joystick = FakeJoystick() toggleButton = Toggle(joystick, 1, 0.1) assert toggleButton.off joystick.press(1) assert toggleButton.on joystick.release(1) joystick.press(1) joystick.release(1) assert toggleButton.on delay.wait() assert toggleButton.on joystick.press(1) assert toggleButton.off
23.685185
56
0.689601
1
1.1016
[ 0.002843780443072319, 0.023940695449709892, 0.008108497597277164, 0.00102329533547163, 0.005560228135436773, -0.004137966316193342, -0.009753748774528503, -0.00006514690903713927, -0.006453893147408962, 0.0029963303823024035, 0.004052118863910437, 0.006068025715649128, 0.008117814548313618, -0.014982577413320541, 0.0029549114406108856, 0.014832346700131893, -0.049619950354099274, 0.00015365166473202407, -0.0024350269231945276, 0.004813270643353462, -0.005856058094650507, 0.011168389581143856, 0.008422070182859898, 0.003352779196575284, 0.00595251377671957, -0.0017001326195895672, 0.009488620795309544, 0.00313114607706666, -0.011344194412231445, -0.009522632695734501, -0.0005883019766770303, -0.004025032743811607, -0.008600023575127125, -0.008031394332647324, 0.0051203081384301186, -0.0059420084580779076, -0.0002798965433612466, -0.021302444860339165, 0.011510241776704788, -0.0035668527707457542, -0.006398774217814207, -0.015883037820458412, 0.0012043773895129561, 0.0047263531014323235, -0.011116408742964268, 0.002372018527239561, -0.0033298926427960396, 0.003757636761292815, -0.011482289992272854, 0.005577640142291784, -0.010089416056871414, 0.006181711796671152, 0.01570206880569458, 0.00530660105869174, -0.005726548843085766, -0.010014703497290611, 0.011206603609025478, -0.002499970141798258, -0.008736043237149715, -0.001012641005218029, -0.0016505528474226594, -0.0018076137639582157, 0.0027139149606227875, 0.00045953664812259376, -0.018010824918746948, -0.006124448496848345, -0.004703069571405649, 0.004572062753140926, -0.002398644108325243, 0.007950224913656712, -0.00048005799180828035, -0.0017949396278709173, 0.007199403829872608, 0.0033931792713701725, 0.00321485404856503, -0.005215237848460674, -0.0018076314590871334, -0.0013201371766626835, 0.008252055384218693, 0.0015589982504025102, 0.0065644271671772, -0.008037797175347805, 0.004536863416433334, 0.010761062614619732, 0.014475777745246887, 0.009239493869245052, 0.020087698474526405, -0.010984898544847965, 0.04753303900361061, 0.010169489309191704, -0.007527242414653301, 0.0026350661646574736, -0.008165611885488033, -0.003544600447639823, -0.004992657341063023, -0.026308506727218628, -0.001988892210647464, -0.005768692120909691, 0.00032826524693518877, 0.0030185922514647245, -0.0005153639358468354, 0.008772600442171097, -0.00010680918057914823, -0.003178900573402643, -0.010490745306015015, 0.01269587129354477, -0.009521175175905228, -0.0048669613897800446, 0.006566436495631933, -0.00019245983276050538, -0.012641272507607937, -0.002616453217342496, 0.0028778354171663523, -0.012604393996298313, 0.001499998732469976, 0.0027843390125781298, -0.010153834708034992, 0.05513869225978851, 0.0001663870643824339, 0.0017974436050280929, -0.004652419593185186, 0.001045944052748382, 0.003749984549358487, 0.0070501454174518585, 0.009980252012610435, -0.003209208371117711, 0.011102933436632156, 0.010280023328959942, 0.00610356917604804, 0.009664053097367287, -0.002657292876392603, 0.009221152402460575, -0.003616306697949767, -0.002126270905137062, 0.001293723937124014, -0.006410186178982258, 0.006870663724839687, -0.0009995702421292663, -0.011667571030557156, 0.0026700561866164207, -0.001299821538850665, -0.010135446675121784, 0.0031365875620394945, -0.0017210521036759019, 0.005549283232539892, -0.00861480925232172, -0.004929983988404274, -0.005137446336448193, -0.002745917998254299, 0.0024644278455525637, 0.008378186263144016, 0.004077916964888573, 0.0029722501058131456, -0.00434363866224885, -0.009205481968820095, -0.001810274668969214, -0.0032558641396462917, 0.0005168805946595967, 0.009303783066570759, 0.007443551439791918, -0.011137677356600761, -0.0013914329465478659, 0.002917652949690819, 0.0023181636352092028, -0.003471547970548272, 0.0036923654843121767, -0.010144808329641819, 0.006588882301002741, -0.001691667945124209, 0.0017986699240282178, 0.011297553777694702, -0.0028156994376331568, 0.00003889555227942765, 0.00022579662618227303, 0.0028441771864891052, 0.000600285129621625, 0.006446428131312132, 0.013876293785870075, 0.00018339477537665516, -0.0037259317468851805, 0.005939031485468149, 0.004061723593622446, 0.009439894929528236, 0.006913393270224333, -0.0022122294176369905, 0.0011865586275234818, -0.0033627511002123356, -0.0007999831577762961, 0.008335541933774948, -0.0023097784724086523, 0.005767252296209335, 0.005446475464850664, -0.014004185795783997, -0.009689166210591793, -0.0001718283601803705, -0.010377119295299053, 0.0013863780768588185, 0.013768886215984821, 0.011723801493644714, -0.0042365859262645245, 0.0020904375705868006, -0.009884312748908997, -0.00008981306018540636, 0.009890733286738396, 0.0024325018748641014, -0.011654792353510857, -0.9578143358230591, 0.006347449496388435, 0.0008386418339796364, -0.0008322718203999102, 0.005518786143511534, 0.0014475648058578372, 0.005577269475907087, 0.003054916625842452, 0.017489667981863022, -0.005814060568809509, -0.004973311442881823, -0.008276627399027348, -0.01046025287359953, -0.001291547785513103, -0.005720973946154118, -0.0038138122763484716, -0.007306420709937811, -0.00614008167758584, -0.0054918983951210976, -0.003008335828781128, -0.0018700205255299807, 0.00912533700466156, 0.00009526566282147542, 0.003770488779991865, 0.004436376970261335, 0.0028161429800093174, -0.006504318211227655, 0.000672423280775547, -0.0017776655731722713, -0.003459919709712267, -0.0049484954215586185, -0.014086943119764328, -0.007151917088776827, -0.0018039087299257517, 0.009551004506647587, 0.0002905494475271553, 0.010330353863537312, -0.0021888858173042536, 0.0017884246772155166, -0.00855934526771307, 0.004869638476520777, 0.0008723168284632266, 0.0008472034824080765, -0.031343694776296616, -0.0020538195967674255, -0.00181035534478724, -0.010752188041806221, 0.0070059034042060375, -0.0017542163841426373, 0.0012937483843415976, -0.0038394341245293617, -0.003398844040930271, 0.00789058767259121, -0.008560803718864918, 0.004860859829932451, -0.004101451952010393, -0.006180730648338795, -0.002636616351082921, -0.010493441484868526, 0.0018767331494018435, 0.004455593880265951, -0.0018277975032106042, -0.0022310828790068626, -0.0024589281529188156, 0.0027888293843716383, 0.002612678101286292, 0.0030148918740451336, -0.018428795039653778, -0.00691253924742341, 0.0009570869151502848, 0.0008702358463779092, -0.0020617095287889242, -0.003814349416643381, 0.004101613536477089, -0.010298292152583599, 0.007008523214608431, 0.0003238086646888405, -0.001319596078246832, -0.009053011424839497, 0.00005944756048847921, -0.010214710608124733, -0.008666496723890305, 0.003925259690731764, -0.006388858426362276, -0.004407351836562157, -0.0006409752531908453, 0.0009073980618268251, 0.00791510846465826, -0.00534474803134799, 0.003274132264778018, 0.010355938225984573, -0.0018100823508575559, -0.006733358837664127, 0.005483014974743128, 0.006548388861119747, -0.0017687373328953981, -0.00353064457885921, 0.0033971616066992283, 0.007632724940776825, 0.009033800102770329, 0.0014700863976031542, 0.004033159930258989, 0.00043402030132710934, 0.0062649925239384174, -0.00040314323268830776, 0.0005250065587460995, -0.005063866265118122, -0.0003136384184472263, -0.003974017221480608, -0.0018637932371348143, -0.006457312032580376, -0.0010488244006410241, -0.012043631635606289, -0.010660802945494652, -0.0001277358824154362, -0.00011022917169611901, 0.005737793166190386, -0.00528761837631464, 0.0003645313554443419, 0.0008701662882231176, 0.008518940769135952, 0.0014855595072731376, -0.001800605677999556, 0.0010429949034005404, 0.004971696063876152, -0.00564330630004406, 0.01308913342654705, -0.011276115663349628, 0.007289158646017313, 0.0005360896466299891, -0.017246881499886513, 0.007368265651166439, 0.00865156203508377, -0.006793994456529617, 0.000023188362320070155, 0.005768029950559139, 0.003113136161118746, -0.0011460798559710383, -0.00540957460179925, -0.003279423573985696, -0.019345082342624664, 0.0020451059099286795, 0.021130483597517014, 0.0017515078652650118, 0.009233464486896992, 0.009163050912320614, -0.0007705711177550256, 0.0020052683539688587, 0.006242930423468351, 0.0018046475015580654, 0.013651321642100811, -0.008353272452950478, -0.002013257471844554, 0.003024380188435316, -0.0052681840024888515, 0.004110538866370916, 0.003298673778772354, 0.005549069959670305, -0.003147824900224805, 0.0032920243684202433, -0.0065283686853945255, -0.004868708550930023, -0.018981141969561577, -0.003805212676525116, 0.007401107810437679, -0.005313856992870569, 0.009414720349013805, -0.016436979174613953, 0.0029481248930096626, 0.005938687361776829, 0.0036984009202569723, -0.00043629802530631423, 0.0021652753930538893, 0.004523171111941338, 0.010828359983861446, -0.0058288536965847015, 0.001562526565976441, 0.003178378799930215, -0.0023278831504285336, -0.0025445162318646908, 0.011060519143939018, -0.007461458444595337, -0.007254306692630053, 0.0019569608848541975, 0.0029792948625981808, 0.00071895238943398, -0.0045732175931334496, -0.011778798885643482, -0.005539171397686005, 0.003007076447829604, -0.0059642973355948925, 0.005856210365891457, 0.001103685237467289, 0.003519098274409771, -0.007437917869538069, -0.0007412076229229569, -0.003545247483998537, -0.009262028150260448, 0.010677717626094818, -0.001499341567978263, 0.002822078065946698, 0.01122602354735136, 0.005075404420495033, -0.014802846126258373, 0.005745233502238989, 0.008181089535355568, -0.005593424197286367, 0.005711560137569904, 0.006464902777224779, -0.006279368884861469, -0.021728413179516792, -0.0033721611835062504, -0.013169756159186363, 0.006141891703009605, -0.0010123265674337745, 0.0037592772860080004, -0.005542487371712923, 0.007319200783967972, 0.0068718865513801575, -0.012537822127342224, -0.004555612802505493, -0.010537724010646343, 0.009649760089814663, -0.0017685000784695148, -0.0004140530654694885, -0.003143373876810074, -0.0016423915512859821, -0.00489197438582778, -0.003783636027947068, -0.003188739763572812, 0.004983223043382168, 0.0013971595326438546, -0.0010814332636073232, 0.0028735350351780653, -0.006764520891010761, 0.0021763488184660673, 0.003385483054444194, -0.011637712828814983, -0.0006615399615839124, 0.007468693424016237, -0.0006897288840264082, -0.002733967499807477, -0.0008337093750014901, -0.0030840339604765177, -0.005514177028089762, -0.009865651838481426, -0.0014038747176527977, -0.005091479513794184, -0.0011330469278618693, -0.011643953621387482, -0.003996567334979773, -0.010217740200459957, 0.008459027856588364, -0.008006812073290348, 0.008537650108337402, 0.005852500442415476, -0.007033380679786205, 0.005248588509857655, -0.00233764317817986, 0.003117891261354089, 0.002837260253727436, 0.0057252924889326096, 0.0027434215880930424, -0.00704274233430624, -0.011746568605303764, 0.013603436760604382, -0.00678876880556345, 0.002203366020694375, 0.014953704550862312, 0.006750187370926142, 0.008642747066915035, -0.0012977173319086432, 0.00031772241345606744, 0.0031463713385164738, 0.005862620659172535, -0.01761779934167862, 0.004179829731583595, -0.0015408762264996767, 0.0006764872232452035, 0.002416188595816493, -0.0031154719181358814, 0.0026251119561493397, 0.008895626291632652, 0.0007915376336313784, -0.005180428735911846, -0.003667940618470311, 0.002939268248155713, 0.004166795872151852, -0.014968923293054104, -0.0002226872165920213, -0.0016289803897961974, -0.004983951803296804, -0.003956290893256664, -0.0015107291983440518, 0.0006525290664285421, 0.0053843348287045956, -0.0029783209320157766, 0.004886836279183626, 0.002914070151746273, -0.005040702875703573, 0.013588650152087212, -0.004802861250936985, -0.0056766001507639885, 0.002354701980948448, 0.0014958848478272557, -0.0011195183033123612, -0.00495492247864604, -0.004321014974266291, 0.002955141942948103, 0.006162344012409449, -0.0010855995351448655, -0.005413465201854706, -0.002370071830227971, -0.00006598454638151452, -0.010103261098265648, 0.0037280076649039984, 0.011565450578927994, -0.0010556168854236603, 0.007437193300575018, -0.0014950758777558804, -0.008075360208749771, -0.01346287690103054, 0.05387992411851883, -0.003717011772096157, 0.0023823275696486235, 0.005160689353942871, -0.0077800750732421875, -0.00030499076819978654, -0.0009420495480298996, 0.008186738938093185, -0.005795706994831562, -0.008185787126421928, 0.008074541576206684, -0.0013325238833203912, 0.004053092561662197, 0.002371092326939106, -0.0010134371696040034, 0.0169522687792778, -0.0025156945921480656, -0.016853420063853264, -0.017503026872873306, 0.006502124015241861, -0.008490213192999363, -0.007327582221478224, 0.009968982078135014, -0.0023603872396051884, -0.004660091362893581, 0.0011156518012285233, 0.007852720096707344, 0.0025649582967162132, 0.0000642100494587794, -0.0018250052817165852, -0.0015831567579880357, 0.0010777033166959882, 0.0022319122217595577, 0.005333233624696732, 0.006788842845708132, -0.0037260791286826134, 0.001566989696584642, -0.002475220710039139, 0.00029021999216638505, -0.0031404341571033, 0.003848804160952568, 0.007890339009463787, -0.001981667010113597, -0.006118577439337969, 0.003800403093919158, 0.0037126578390598297, 0.001723762135952711, 0.012453670613467693, -0.0014917186927050352, -0.0061609093099832535, 0.006732300389558077, 0.00897573959082365, -0.00042968010529875755, 0.007853268645703793, -0.0009803648572415113, 0.0071120550855994225, 0.003272078465670347, -0.007689077407121658, -0.01731901988387108, -0.002540829125791788, 0.005835170857608318, 0.010135061107575893, -0.0006539737223647535, 0.001586982631124556, -0.004193882457911968, -0.0022286560852080584, -0.008019933477044106, -0.006645801477134228, -0.002611861564218998, 0.0017196435946971178, 0.005945236422121525, 0.06975395977497101, -0.006917344871908426, -0.001494303927756846, -0.009513163939118385, 0.0021192177664488554, -0.0010072584263980389, 0.00009433121886104345, -0.0006188279367052019, -0.002337900223210454, 0.004026129841804504, 0.0007731049554422498, -0.0066839465871453285, -0.013851989060640335, -0.000022952586732571945, 0.00386737659573555, -0.0021065743640065193, 0.002819555578753352, 0.00740883918479085, -0.009497384540736675, -0.0003102892078459263, -0.01334299985319376, -0.002535969950258732, -0.002665047300979495, -0.008255762048065662, -0.005933072417974472, -0.0032906688284128904, 0.0053759850561618805, 0.0019036353332921863, 0.005245340522378683, -0.0035708798095583916, 0.005568395368754864, -0.004297774285078049, -0.001399248605594039, -0.007747274823486805, -0.0023997905664145947, -0.005844248458743095, 0.006664360407739878, 0.0038516479544341564, -0.009185698814690113, -0.007136669475585222, -0.0024846955202519894, 0.00025674240896478295, -0.006292581092566252, 0.004451348911970854, -0.00001967540265468415, 0.004769968334585428, -0.005645394790917635, 0.0016709733754396439, -0.006328247953206301, 0.0014853694010525942, -0.01436545792967081, 0.005372880958020687, -0.17190968990325928, 0.007398921996355057, 0.005702637135982513, -0.004052548669278622, -0.004249095916748047, -0.014141642488539219, -0.005361718591302633, 0.0036132996901869774, 0.011640527285635471, 0.0033479221165180206, 0.0004257863329257816, -0.0013348263455554843, 0.005632729735225439, 0.0013823038898408413, -0.003130913944914937, -0.006395676638931036, 0.0032631366048008204, -0.003916654270142317, -0.000318150530802086, 0.005089798476547003, 0.00518268346786499, 0.009437023662030697, 0.00173437490593642, 0.0030133279506117105, -0.0016646323492750525, -0.005500424653291702, 0.006727340165525675, -0.0022738224361091852, 0.005372290033847094, -0.011702453717589378, -0.003760988125577569, -0.0030264826491475105, -0.0011994652450084686, -0.0005158190615475178, 0.005708746612071991, -0.0018279890064150095, 0.00916933175176382, 0.0030204420909285545, -0.007746952120214701, 0.007597509305924177, -0.008232955820858479, 0.0272193755954504, 0.005344106815755367, 0.008518924936652184, 0.0008989137131720781, -0.0058463141322135925, -0.006971938535571098, 0.010710797272622585, 0.0009510960662737489, 0.01146908663213253, -0.010778605006635189, 0.0016941832145676017, 0.005011069588363171, 0.018375568091869354, -0.0067537156865000725, -0.00908657256513834, -0.00834314338862896, -0.0017959217075258493, 0.0018800797406584024, 0.010784277692437172, 0.012290749698877335, -0.005867605097591877, 0.010036591440439224, -0.002934523858129978, -0.02139367163181305, 0.0031036522705107927, -0.004976984579116106, -0.006361384876072407, 0.002414252143353224, 0.0045402441173791885, 0.008572018705308437, -0.0018938565626740456, 0.0028150640428066254, -0.0007986454293131828, 0.00533457612618804, -0.00009936893184203655, 0.006639707833528519, 0.00026091301697306335, 0.008129728026688099, -0.009773432277143002, 0.007213001139461994, -0.009450535289943218, -0.0011675219284370542, 0.00122157484292984, -0.001465853420086205, 0.011391275562345982, 0.004709561355412006, -0.004663649946451187, -0.0012171949492767453, -0.009382096119225025, -0.0019268880132585764, 0.004302570596337318, 0.0021782235708087683, -0.010500635020434856, 0.0015046611661091447, 0.0004818313173018396, 0.009024462662637234, 0.006610868964344263, -0.010690783150494099, 0.004391768015921116, 0.00681488448753953, -0.005804843734949827, 0.003269453067332506, -0.005027509294450283, 0.0020580298732966185, 0.004845392890274525, -0.0071115014143288136, -0.006508607417345047, 0.00534864142537117, -0.006721372716128826, -0.004279072862118483, 0.007801983505487442, -0.010153492912650108, -0.008691458962857723, -0.0014672704273834825, -0.01299335341900587, -0.0010213936911895871 ]
8aa8401fd27f8fa99c12308b325e2e4f0cfa3068
2,872
py
Python
tests/test.py
kjanik70/tflearn
db5176773299b67a2a75c5889fb2aba7fd0fea8a
[ "MIT" ]
10,882
2016-03-31T16:03:11.000Z
2022-03-26T03:00:27.000Z
tests/test.py
min0355/tflearn
db5176773299b67a2a75c5889fb2aba7fd0fea8a
[ "MIT" ]
1,079
2016-04-02T06:14:16.000Z
2022-02-27T10:04:47.000Z
tests/test.py
min0355/tflearn
db5176773299b67a2a75c5889fb2aba7fd0fea8a
[ "MIT" ]
3,014
2016-03-31T16:03:26.000Z
2022-03-30T20:36:53.000Z
''' This file contains test cases for tflearn ''' import tensorflow.compat.v1 as tf import tflearn import unittest class TestActivations(unittest.TestCase): ''' This class contains test cases for the functions in tflearn/activations.py ''' PLACES = 4 # Number of places to match when testing floating point values def test_linear(self): f = tflearn.linear # Case 1 x = tf.placeholder(tf.float32, shape=()) self.assertEqual(f(x), x) # Case 2 x = tf.placeholder(tf.int64, shape=()) self.assertEqual(f(x), x) def test_tanh(self): f = tflearn.tanh x = tf.placeholder(tf.float32, shape=()) with tf.Session() as sess: # Case 1 self.assertEqual(sess.run(f(x), feed_dict={x:0}), 0) # Case 2 self.assertAlmostEqual(sess.run(f(x), feed_dict={x:0.5}), 0.4621, places=TestActivations.PLACES) # Case 3 self.assertAlmostEqual(sess.run(f(x), feed_dict={x:-0.25}), -0.2449, places=TestActivations.PLACES) def test_leaky_relu(self): f = lambda x: tflearn.leaky_relu(x, alpha=0.2) x = tf.placeholder(tf.float32, shape=()) with tf.Session() as sess: # Case 1 self.assertEqual(sess.run(f(x), feed_dict={x:0}), 0) # Case 2 self.assertAlmostEqual(sess.run(f(x), feed_dict={x:1}), 1, places=TestActivations.PLACES) # Case 3 self.assertAlmostEqual(sess.run(f(x), feed_dict={x:-1}), -0.2, places=TestActivations.PLACES) # Case 4 self.assertAlmostEqual(sess.run(f(x), feed_dict={x:-5}), -1, places=TestActivations.PLACES) def test_apply_activation(self): lrelu_02 = lambda x: tflearn.leaky_relu(x, alpha=0.2) x = tf.constant(-0.25, tf.float32) with tf.Session() as sess: # Case 1: 'linear' self.assertEqual( sess.run(tflearn.activation(x, 'linear')), -0.25) # Case 2: 'relu' self.assertEqual( sess.run(tflearn.activation(x, 'relu')), 0) # Case 3: 'leaky_relu' self.assertAlmostEqual( sess.run(tflearn.activation(x, 'leaky_relu')), -0.025, places=TestActivations.PLACES) # Case 4: 'tanh' self.assertAlmostEqual( sess.run(tflearn.activation(x, 'tanh')), -0.2449, places=TestActivations.PLACES) # Case 5: lrelu_02 (callable) self.assertAlmostEqual( sess.run(tflearn.activation(x, lrelu_02)), -0.05, places=TestActivations.PLACES) if __name__ == "__main__": unittest.main()
30.88172
82
0.547354
1
1.6611
[ 0.00017012680473271757, 0.0230608731508255, 0.010373447090387344, 0.0017405125545337796, 0.003362571820616722, 0.0007170495227910578, -0.008215675130486488, -0.0025272779166698456, -0.0070269228890538216, 0.0060626245103776455, 0.0015990546671673656, 0.008388262242078781, 0.007073391228914261, -0.013528662733733654, 0.00023777394380886108, 0.016103580594062805, -0.0435909628868103, -0.0035951745230704546, 0.0005176070262677968, 0.0018390247132629156, -0.007278580218553543, 0.007027270272374153, 0.00768644455820322, 0.005408501252532005, 0.007471129763871431, -0.004128577187657356, 0.012637090869247913, 0.0024813259951770306, -0.009720496833324432, -0.006629630923271179, -0.0016081016510725021, -0.0013731429353356361, -0.006042225286364555, -0.005216423887759447, 0.004882633686065674, -0.003233453957363963, -0.0008379733772017062, -0.01835308037698269, 0.010100524872541428, -0.004993693437427282, -0.0024238955229520798, -0.009081091731786728, -0.0020677472930401564, 0.0009173204307444394, -0.004670463036745787, 0.004176998510956764, -0.00808962807059288, 0.002505639335140586, -0.011947792954742908, 0.007960954681038857, -0.007680356502532959, 0.0038758963346481323, 0.012723363004624844, -0.0012210572604089975, -0.006377708166837692, -0.006683810148388147, 0.015623129904270172, 0.0029565277509391308, -0.00978542398661375, 0.001161031424999237, -0.0017632909584790468, -0.001662866328842938, 0.006663399748504162, 0.0022560562938451767, -0.014624589122831821, -0.007653033826500177, -0.005602765362709761, 0.004703969694674015, -0.0024398609530180693, 0.0035812794230878353, 0.0005533042713068426, 0.00020387988479342312, 0.005320056341588497, 0.0074179875664412975, 0.007959303446114063, -0.003913273103535175, -0.00036826779250986874, -0.0018162307096645236, 0.007892368361353874, 0.003397397231310606, 0.0013746110489591956, -0.0034053565468639135, 0.0024061400908976793, 0.008052253164350986, 0.014916193671524525, 0.010742797516286373, 0.018290702253580093, -0.0130950678139925, 0.050364281982183456, 0.007417209912091494, -0.007591506466269493, 0.004824322182685137, -0.01434299722313881, -0.003995570819824934, -0.009809087961912155, -0.023544134572148323, 0.0032838345505297184, -0.0044939275830984116, -0.0013684190344065428, 0.002392251044511795, 0.0013215141370892525, 0.008883734233677387, -0.00046563814976252615, -0.0010302286827936769, -0.010003279894590378, 0.007314370945096016, -0.011317338794469833, -0.005372175481170416, 0.0059308987110853195, 0.0005988649791106582, -0.012265839613974094, -0.00046390254283323884, -0.0013886535307392478, -0.016276953741908073, 0.00269071152433753, 0.005520930979400873, -0.005224315449595451, 0.0447937548160553, 0.00046267255675047636, 0.00823929999023676, -0.004212229046970606, 0.003352515399456024, 0.00004321229789638892, 0.001250909874215722, 0.011311500333249569, 0.0031034669373184443, 0.009716501459479332, 0.005187489558011293, 0.00492402259260416, 0.011116649955511093, -0.003430824726819992, 0.005174811463803053, -0.0008601415320299566, -0.00117805867921561, 0.0015760629903525114, -0.0061863199807703495, 0.007601507473737001, -0.0031388981733471155, -0.009507416747510433, 0.0019171752501279116, -0.0023314040154218674, -0.01028386689722538, 0.00023602235887665302, -0.004307557363063097, 0.005540165118873119, -0.011472085490822792, -0.0037639096844941378, -0.005431885831058025, -0.005674939136952162, 0.0018479934660717845, 0.010167673230171204, 0.0061981528997421265, 0.002402483019977808, -0.0024238950572907925, -0.010480976663529873, 0.003650000551715493, -0.005842112470418215, -0.000788835808634758, 0.0062098209746181965, 0.004888998810201883, -0.013367265462875366, -0.0008277295273728669, 0.003146279603242874, 0.0001480178616475314, 0.0011233189143240452, 0.006296366918832064, -0.006282241083681583, 0.005153542850166559, -0.000482661445857957, 0.006353618111461401, 0.010380035266280174, -0.005177258513867855, -0.0006145283696241677, -0.002743346616625786, 0.002219768473878503, 0.0012882407754659653, 0.008570695295929909, 0.012247094884514809, -0.0012178035685792565, -0.005772927310317755, 0.006838823202997446, 0.006400617770850658, 0.010046079754829407, 0.005072346888482571, -0.001986471237614751, -0.0007677465910091996, -0.0061910985969007015, -0.003424922004342079, 0.007675926201045513, -0.007901852019131184, 0.0061716800555586815, 0.005149953532963991, -0.012449583038687706, -0.010960419662296772, -0.00177965487819165, -0.00569922523573041, 0.002333513693884015, 0.014355374500155449, 0.011097325943410397, -0.004879089538007975, -0.00011316579184494913, -0.010644486173987389, 0.0017162252916023135, 0.009399166330695152, -0.00019350145885255188, -0.011677918024361134, -0.9598808288574219, 0.011763965710997581, 0.0027392127085477114, -0.004358688835054636, 0.006212733685970306, -0.0003217531484551728, 0.0007574184564873576, 0.004591258708387613, 0.01097043976187706, -0.006484593730419874, -0.0013652408961206675, -0.00920939352363348, -0.013236282393336296, -0.00574722932651639, -0.007641396019607782, -0.003670082427561283, -0.005601176992058754, -0.007478846237063408, -0.006903187371790409, -0.0018660140922293067, -0.002774269552901387, 0.005260284524410963, -0.002677361713722348, 0.008058691397309303, -0.00043109990656375885, 0.0028377531562000513, -0.002329819602891803, 0.0005305231316015124, -0.0011214871192350984, -0.004428824409842491, -0.008761228062212467, -0.011373179964721203, -3.535589314651588e-7, -0.003912303131073713, 0.009705387987196445, 0.004316271282732487, 0.008026142604649067, -0.004743152763694525, 0.005193144083023071, -0.006903832778334618, 0.004048590082675219, 0.0010550804436206818, 0.003038079245015979, -0.02985367551445961, -0.0022253908682614565, -0.0007286393665708601, -0.008257384411990643, 0.006692266091704369, -0.0006082307663746178, -0.001032098545692861, -0.005409852601587772, -0.00850471667945385, 0.009669419378042221, -0.006420182529836893, 0.006839343812316656, -0.0018533694092184305, -0.00985945388674736, -0.0042410860769450665, -0.00806805957108736, 0.0036061417777091265, 0.006071930751204491, -0.00047172250924631953, -0.005248833913356066, -0.006868479307740927, 0.003757144557312131, 0.0027885243762284517, 0.003974024206399918, -0.018843313679099083, -0.0104477284476161, 0.0011621675221249461, -0.002680850448086858, -0.004316264763474464, -0.006380836945027113, 0.004537587519735098, -0.005955534987151623, 0.004954247269779444, 0.0017719403840601444, -0.001077971770428121, -0.011365038342773914, -0.0013018206227570772, -0.012660033069550991, -0.0050231837667524815, -0.0005061528645455837, -0.004655444994568825, -0.007004434242844582, 0.001372928498312831, 0.003099849447607994, 0.006156330928206444, -0.004946309141814709, 0.006359531078487635, 0.009732973761856556, -0.0029093194752931595, -0.006781883537769318, 0.006313125137239695, 0.008739088661968708, 0.004525820259004831, 0.003097431967034936, 0.004526384174823761, 0.006892756558954716, 0.01101982593536377, 0.004966008476912975, 0.010914057493209839, 0.0028662190306931734, 0.010295077227056026, -0.0031880682799965143, -0.0020108812022954226, -0.005521886516362429, 0.0006123880157247186, -0.003916871268302202, 0.0015249126590788364, -0.0017112535424530506, -0.003912709187716246, -0.012035851366817951, -0.005798627622425556, -0.005137688480317593, -0.0031127415131777525, 0.006128415465354919, -0.005783186759799719, -0.0027578293811529875, 0.0021731462329626083, 0.005759489256888628, -0.00024260378268081695, -0.0037507310044020414, 0.002799738897010684, 0.003432724392041564, -0.004815885331481695, 0.014372577890753746, -0.011950676329433918, 0.008611136116087437, 0.0026282898616045713, -0.017913607880473137, 0.005223982501775026, 0.009266085922718048, -0.010209528729319572, 0.0005279068718664348, 0.005855419673025608, 0.0011557589750736952, -0.003995742183178663, -0.004395741503685713, 0.0010997694917023182, -0.017086641862988472, 0.004142862278968096, 0.01960398443043232, 0.0015020860591903329, 0.00885528139770031, 0.00969924870878458, -0.0012315133353695273, 0.0026827501133084297, 0.005193939432501793, -0.004312289413064718, 0.011383638717234135, -0.0058528766967356205, -0.00040243231342174113, 0.005640672519803047, -0.006828052457422018, 0.0018227904802188277, 0.00689113000407815, 0.004189993254840374, -0.0028266040608286858, 0.005116465501487255, -0.005069370847195387, -0.004651121329516172, -0.016047818586230278, -0.005595390684902668, 0.011356971226632595, -0.0011898282682523131, 0.004611214157193899, -0.014037596993148327, 0.005125416908413172, 0.00545791070908308, 0.012113030068576336, -0.0009936148999258876, 0.003063097596168518, 0.0063369800336658955, 0.01066920068114996, -0.006407635752111673, 0.00003356703746248968, 0.005132561083883047, -0.000583245069719851, -0.0030837710946798325, 0.008039342239499092, -0.0050911568105220795, -0.005949489772319794, 0.0006611774442717433, 0.004409050568938255, 0.0006009311764501035, 0.0003135362931061536, -0.006538241636008024, -0.0053921290673315525, 0.005283732898533344, -0.004097091034054756, 0.0023340655025094748, -0.0004974030889570713, 0.00023760074691381305, -0.008222034201025963, -0.0026698790024966, -0.004736653529107571, -0.012546276673674583, 0.010441134683787823, -0.002731609158217907, 0.0052074892446398735, 0.016968410462141037, 0.00884832814335823, -0.013016659766435623, 0.004831318743526936, 0.009265637025237083, -0.001393089652992785, 0.005782932508736849, 0.005810378585010767, -0.006591509096324444, -0.022820109501481056, -0.007862528786063194, -0.005862874910235405, 0.003968773875385523, -0.0007651708438061178, 0.005497273523360491, -0.006448464002460241, 0.004314261954277754, 0.006658611353486776, -0.015231148339807987, -0.008981674909591675, -0.00964412186294794, 0.007395972032099962, 0.0010856292210519314, 0.0036313107702881098, -0.007735013496130705, -0.0026831503491848707, -0.0013552425662055612, -0.006044886074960232, -0.006226324941962957, 0.010055613704025745, 0.0009455529507249594, -0.0006046496564522386, 0.0008714740979485214, -0.004096896853297949, 0.00032236010883934796, -0.000012493404938140884, -0.009710843674838543, 0.002021047053858638, -0.0007557985954917967, -0.0013250114861875772, -0.006007242947816849, 0.001670629600994289, -0.0043382965959608555, -0.007639938499778509, -0.012508426792919636, -0.0044826907105743885, -0.0036212343256920576, -0.0035245364997535944, -0.00863814540207386, -0.002662574639543891, -0.008427279070019722, 0.008037851192057133, -0.0075831287540495396, 0.010111324489116669, 0.00878064427524805, -0.00496637960895896, 0.006823902018368244, -0.00143511185888201, 0.004096510354429483, 0.0007004152867011726, 0.004656260833144188, 0.0036625878419727087, -0.005745783913880587, -0.006479563657194376, 0.011439603753387928, -0.01135138887912035, -0.0003237172495573759, 0.01265490148216486, 0.0068232277408242226, 0.007488761097192764, -0.0021150854881852865, -0.00014884139818605036, 0.0002073438954539597, 0.0036990484222769737, -0.014725586399435997, 0.004761204123497009, -0.006207907106727362, 0.0008694696589373052, 0.004340092185884714, -0.004540068097412586, 0.0012790090404450893, 0.008637509308755398, 0.00019993781461380422, -0.007470247335731983, -0.0022326421458274126, 0.0023513897322118282, 0.004087768029421568, -0.010685990564525127, 0.002211353275924921, -0.0016974980244413018, -0.0054802545346319675, -0.0022490026894956827, -0.002411148278042674, 0.0023128141183406115, 0.0034744124859571457, -0.0005586807383224368, 0.003317171474918723, 0.0010293133091181517, -0.007552855648100376, 0.011203193105757236, -0.004973533563315868, -0.004132071044296026, 0.002691280795261264, 0.003071168437600136, -0.006383159197866917, -0.0035076162312179804, -0.0038025411777198315, 0.004594267345964909, 0.007421355694532394, -0.0026551999617367983, -0.0014444688567891717, 0.0013429285027086735, -0.0015147062949836254, -0.010937439277768135, 0.0009611641871742904, 0.01370307058095932, -0.006679828278720379, 0.011086991988122463, -0.0021236068569123745, -0.007627974729984999, -0.01345097366720438, 0.047329265624284744, 0.00023653608513996005, 0.004598747007548809, 0.00150819041300565, -0.007441327441483736, -0.0015056498814374208, -0.00046259674127213657, 0.009160080924630165, -0.003859474090859294, -0.0059814248234033585, 0.009898357093334198, -0.0020118514075875282, 0.00568104675039649, 0.00560829509049654, 0.0036977457348257303, 0.01772482506930828, 0.0006827704492025077, -0.014366768300533295, -0.01862039603292942, 0.007806440349668264, -0.005140749271959066, -0.006261530332267284, 0.011717410758137703, -0.005173961166292429, -0.006856346968561411, 0.002102609956637025, 0.009342774748802185, 0.002359975827857852, 0.00047982347314246, -0.0035918941721320152, -0.006741125136613846, 0.000013882489838579204, 0.0008930919575504959, 0.003553840797394514, 0.007488173898309469, -0.004874296020716429, 0.006100817117840052, 0.00146356294862926, -0.0035676294937729836, -0.005473285913467407, 0.0030615893192589283, 0.00951831229031086, -0.0015646872343495488, -0.003203250002115965, 0.005625785794109106, 0.0031419824808835983, 0.0016029173275455832, 0.01118259783834219, -0.0007831997936591506, -0.008907231502234936, 0.0066177695989608765, 0.004321570508182049, -0.00044365800567902625, 0.011728976853191853, 0.0016249037580564618, 0.0044242204166948795, 0.0031683272682130337, -0.008551796898245811, -0.015134777873754501, -0.004735770635306835, 0.007544766180217266, 0.005488179624080658, 0.000930128968320787, 0.0020861190278083086, -0.0010184135753661394, -0.0008950966876000166, -0.006959373131394386, -0.010159775614738464, -0.002198729896917939, 0.002862274879589677, 0.005842258222401142, 0.06637845188379288, -0.00849427841603756, 0.0003158290346618742, -0.007033496629446745, -0.0003216922050341964, 0.0012345416471362114, -0.0014763906365260482, 0.00083263119449839, -0.004359472077339888, 0.0013857405865564942, -0.0002586616319604218, -0.007885009050369263, -0.013497048057615757, 0.00029533993802033365, 0.00034399586729705334, -0.0034792644437402487, 0.0035055172629654408, 0.00590083934366703, -0.009315850213170052, 0.0014664364280179143, -0.014935379847884178, -0.0008799072238616645, 0.0013355975970625877, -0.014351962134242058, -0.008497823029756546, -0.0013312948867678642, 0.009767813608050346, 0.005651852115988731, 0.0036174387205392122, -0.0036003582645207644, 0.004779087845236063, -0.004937377758324146, 0.00012275748304091394, -0.00561791704967618, -0.0015949937514960766, -0.006688680965453386, 0.009603367187082767, 0.0021123276092112064, -0.017141330987215042, -0.0057997386902570724, 0.001281291013583541, 0.0019516779575496912, -0.007431394420564175, 0.002868451876565814, -0.003997678868472576, 0.0027091309893876314, -0.00299919699318707, 0.0020428320858627558, -0.00467428844422102, 0.005900341086089611, -0.008793325163424015, 0.007613619323819876, -0.16572429239749908, 0.011892279610037804, 0.0037864602636545897, -0.006131460424512625, -0.006868674885481596, -0.01468143705278635, -0.00700325146317482, 0.00579433050006628, 0.01226032618433237, 0.004201611503958702, -0.001211504451930523, -0.0021334446500986814, 0.00859641283750534, 0.0032692374661564827, 0.0006247051642276347, -0.01172687392681837, 0.005141912959516048, -0.004589444026350975, 0.003873493056744337, 0.0032151134219020605, 0.003240944119170308, 0.014109148643910885, -0.0017457688227295876, -0.0006142104393802583, -0.0008511259220540524, -0.00384957785718143, 0.008125530555844307, -0.0021070558577775955, 0.004497233312577009, -0.011196689680218697, -0.006920772138983011, -0.004658540710806847, -0.004332969430834055, -0.0008473534835502505, 0.004995568655431271, 0.001892354805022478, 0.008954141288995743, 0.0016395623097196221, -0.008437611162662506, 0.004706673789769411, -0.007013789378106594, 0.027655543759465218, 0.003130310447886586, 0.006168425548821688, 0.002120662247762084, -0.010705417953431606, -0.007989010773599148, 0.007431682664901018, 0.0011648997897282243, 0.014289086684584618, -0.017565544694662094, 0.002423953963443637, 0.00320611335337162, 0.021097971126437187, -0.005821348167955875, -0.012180919758975506, -0.007077350746840239, -0.0017849071882665157, -0.001164715737104416, 0.007347350940108299, 0.013820968568325043, -0.0026136101223528385, 0.007109799887984991, -0.0028316499665379524, -0.021012770012021065, 0.0002695722214411944, -0.0032863751985132694, -0.004575174301862717, -0.0005226960056461394, 0.005455317907035351, 0.009881951846182346, 0.002890900941565633, -0.0005704654031433165, 0.000045526379835791886, 0.006027665920555592, -0.0019012833945453167, 0.004533660598099232, 0.00040249607991427183, 0.00671415263786912, -0.01125775184482336, 0.006025460548698902, -0.011305495165288448, -0.003679407760500908, -0.00020721393229905516, -0.003927112556993961, 0.011839674785733223, 0.0036496883258223534, -0.0030532218515872955, -0.004870956763625145, -0.006703428458422422, -0.004122581332921982, 0.0042558652348816395, 0.002049967646598816, -0.009241129271686077, 0.0036987843923270702, 0.005083506926894188, 0.0055162045173347, 0.0055201915092766285, -0.012983283028006554, 0.008682508021593094, 0.0044185384176671505, -0.006399878766387701, -0.0012876411201432347, -0.002619328675791621, 0.00823748018592596, 0.0009467017953284085, -0.006414571311324835, -0.005306958220899105, 0.0013267172034829855, -0.007921519689261913, -0.005091169383376837, 0.006031894590705633, -0.007467235904186964, -0.012712387368083, -0.0024010357446968555, -0.008890126831829548, -0.001133833429776132 ]
8aaa6ef648c6ab0a8f38e3df5ebf0a4f712b233a
2,313
py
Python
infrastructure-provisioning/src/general/api/install_libs.py
roolrd/incubator-datalab
2045207ecd1b381193f1a1ec143cc968716ad989
[ "Apache-2.0" ]
66
2020-10-03T08:36:48.000Z
2022-03-20T23:16:20.000Z
infrastructure-provisioning/src/general/api/install_libs.py
roolrd/incubator-datalab
2045207ecd1b381193f1a1ec143cc968716ad989
[ "Apache-2.0" ]
48
2019-02-28T12:11:33.000Z
2020-09-15T08:27:08.000Z
infrastructure-provisioning/src/general/api/install_libs.py
roolrd/incubator-datalab
2045207ecd1b381193f1a1ec143cc968716ad989
[ "Apache-2.0" ]
44
2019-01-14T10:31:55.000Z
2020-09-22T17:53:33.000Z
#!/usr/bin/python3 # ***************************************************************************** # # Licensed to the Apache Software Foundation (ASF) under one # or more contributor license agreements. See the NOTICE file # distributed with this work for additional information # regarding copyright ownership. The ASF licenses this file # to you under the Apache License, Version 2.0 (the # "License"); you may not use this file except in compliance # with the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, # software distributed under the License is distributed on an # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. # # ****************************************************************************** import json import os import sys import subprocess if __name__ == "__main__": success = True try: subprocess.run('cd /root; fab install-libs', shell=True, check=True) except: success = False reply = dict() reply['request_id'] = os.environ['request_id'] if success: reply['status'] = 'ok' else: reply['status'] = 'err' reply['response'] = dict() try: with open("/root/result.json") as f: reply['response']['result'] = json.loads(f.read()) except: reply['response']['result'] = {"error": "Failed to open result.json"} reply['response']['log'] = "/var/log/datalab/{0}/{0}_{1}_{2}.log".format(os.environ['conf_resource'], os.environ['project_name'], os.environ['request_id']) with open("/response/{}_{}_{}.json".format(os.environ['conf_resource'], os.environ['project_name'], os.environ['request_id']), 'w') as response_file: response_file.write(json.dumps(reply)) try: subprocess.run('chmod 666 /response/*', shell=True, check=True) except: success = False if not success: sys.exit(1)
35.584615
105
0.565932
1
1.3296
[ 0.001031100982800126, 0.021442143246531487, 0.010698179714381695, 0.003014910966157913, 0.005294262897223234, -0.002283280249685049, -0.009564587846398354, 0.0004916646867059171, -0.008343887515366077, 0.0031763899605721235, 0.0004139225638937205, 0.005846197716891766, 0.008424337022006512, -0.0149974524974823, 0.002913312753662467, 0.016502749174833298, -0.05121655762195587, -0.001562263467349112, -0.0024502412416040897, 0.0021466040052473545, -0.006934062112122774, 0.009281661361455917, 0.006796020083129406, 0.005692408885806799, 0.006541006732732058, -0.0008179661817848682, 0.007637657690793276, 0.0016800299054011703, -0.009105343371629715, -0.0069391168653965, -0.0004205135628581047, -0.001568643026985228, -0.005456787999719381, -0.007245229557156563, 0.004448036663234234, -0.006731334608048201, -0.0015789674362167716, -0.022287826985120773, 0.012130619026720524, -0.0031141298823058605, -0.00545384269207716, -0.012769660912454128, -0.0020179604180157185, 0.002455279231071472, -0.006323766428977251, 0.0038900920189917088, -0.007484450936317444, 0.0006881082663312554, -0.011741174384951591, 0.008006064221262932, -0.00797293707728386, 0.006363801192492247, 0.013255528174340725, -0.0004678725963458419, -0.006664288230240345, -0.005938768852502108, 0.013815528713166714, 0.0012017700355499983, -0.00993451289832592, 0.001667830510996282, -0.0016950565623119473, -0.0031477485317736864, 0.006622313056141138, 0.0015868585323914886, -0.014979423023760319, -0.006390999536961317, -0.004159209318459034, 0.001759750652126968, -0.0024527341593056917, 0.006547973956912756, 0.0004285755567252636, -0.0020600666757673025, 0.0077739860862493515, 0.007141788490116596, 0.0056687151081860065, -0.0034371211659163237, -0.0004789181402884424, -0.00012756975775118917, 0.008513719774782658, 0.0024834240321069956, 0.0037034968845546246, -0.0063860537484288216, 0.005338532384485006, 0.007274439092725515, 0.013768956065177917, 0.010383776389062405, 0.01836034283041954, -0.011838468722999096, 0.04995881766080856, 0.005935529712587595, -0.009105929173529148, 0.004181080497801304, -0.011002668179571629, -0.0034162881784141064, -0.007734386250376701, -0.026632556691765785, 0.0009696386405266821, -0.003087261226028204, 0.001443672925233841, 0.004969922825694084, 0.0018756522331386805, 0.006862466223537922, -0.0007526367553509772, 0.00037621898809447885, -0.010943343862891197, 0.01040445826947689, -0.011007010005414486, -0.0037155456375330687, 0.004826414864510298, 0.0009948924416676164, -0.011002658866345882, -0.002685950603336096, 0.00017710350221022964, -0.013032878749072552, 0.0025528178084641695, 0.005158039275556803, -0.0028759383130818605, 0.05108511075377464, 0.0009044938487932086, 0.009515749290585518, -0.0033486434258520603, 0.0024412202183157206, -0.0011929217725992203, 0.0035332113038748503, 0.012160079553723335, -0.0003913471882697195, 0.011776341125369072, 0.001970164943486452, 0.0009105633944272995, 0.007690205238759518, -0.002437139395624399, 0.004298223648220301, -0.004885347094386816, -0.0016589028527960181, -0.00008814213651930913, -0.005978782195597887, 0.006941869389265776, -0.0028850394301116467, -0.009114822372794151, 0.002002282766625285, -0.0008124351152218878, -0.008354374207556248, 0.001914692111313343, -0.002544258488342166, 0.007355697453022003, -0.01029960811138153, -0.004042080137878656, -0.004050290212035179, -0.0056210593320429325, 0.0017489782767370343, 0.009699428454041481, 0.006229422986507416, 0.0022209868766367435, -0.0040130335837602615, -0.005988888908177614, 0.0026309124659746885, -0.0057710567489266396, -0.0008447766304016113, 0.00624848110601306, 0.006027805618941784, -0.009579523466527462, 0.001220925129018724, 0.002818083856254816, 0.0018902674783021212, 0.001019741059280932, 0.004657234065234661, -0.007922552525997162, 0.006593255791813135, 0.0008901335531845689, 0.007390585262328386, 0.012348747812211514, -0.003984030801802874, 0.00017594732344150543, -0.0017776808235794306, 0.002822260372340679, 0.0023170302156358957, 0.008386433124542236, 0.011041245423257351, -0.003455239115282893, -0.005177987739443779, 0.004613374825567007, 0.004944661166518927, 0.00845510046929121, 0.005486825481057167, -0.0020200617145746946, 0.00017445176490582526, -0.004915398079901934, -0.0017910129390656948, 0.009138823486864567, -0.006908165290951729, 0.00795874372124672, 0.0050181178376078606, -0.013901612721383572, -0.008686704561114311, 0.0017736662412062287, -0.009200377389788628, 0.0024739596992731094, 0.014268381521105766, 0.0136045441031456, -0.0047325631603598595, 0.00224293302744627, -0.009820363484323025, 0.0018162387423217297, 0.009559224359691143, 0.0013458209577947855, -0.011181042529642582, -0.9589417576789856, 0.009264183230698109, 0.002826509764418006, -0.0019174227491021156, 0.005653389263898134, -0.00037969936965964735, 0.0029977248050272465, 0.005164319183677435, 0.014594269916415215, -0.005478474777191877, -0.004000930581241846, -0.009369280189275742, -0.010170397348701954, -0.002322461688891053, -0.007597583811730146, -0.004144083708524704, -0.008118899539113045, -0.006212185136973858, -0.005019936244934797, -0.0006887039635330439, -0.002709711203351617, 0.005366584286093712, -0.0019122962839901447, 0.0036604769993573427, 0.0011067049345001578, 0.0015796093503013253, -0.0021684053353965282, -0.0002578409621492028, 0.0007920609205029905, -0.001802140148356557, -0.006973145995289087, -0.01310205738991499, -0.0013822648907080293, -0.002822763752192259, 0.011032399721443653, 0.0020113817881792784, 0.008453181944787502, -0.004430265165865421, 0.004368666093796492, -0.007735101971775293, 0.00517102750018239, 0.003245911095291376, 0.004025978036224842, -0.031281087547540665, 0.000007050934073049575, 0.0010582967661321163, -0.009740209206938744, 0.009912575595080853, 0.0024011190980672836, -0.001625438453629613, -0.0035268717911094427, -0.004485873505473137, 0.009148658253252506, -0.006108149420469999, 0.004138557240366936, -0.004190353211015463, -0.007572072092443705, -0.005659089889377356, -0.008588368073105812, 0.002947411732748151, 0.007120453752577305, 0.0006595492595806718, -0.0036227554082870483, -0.006899637170135975, 0.002513890853151679, 0.000396971678128466, 0.003473504213616252, -0.021789299324154854, -0.007890850305557251, -0.0017254913691431284, 0.0009380075498484075, -0.000913385534659028, -0.0052454047836363316, 0.004994117189198732, -0.006127245724201202, 0.005582042969763279, 0.002886486239731312, 0.00035914298496209085, -0.011207880452275276, 0.0013749521458521485, -0.011214187368750572, -0.0076664648950099945, -0.0003149422409478575, -0.004373897332698107, -0.0056067598052322865, -0.0018411315977573395, 0.002857156563550234, 0.008812598884105682, -0.003807824570685625, 0.003296831389889121, 0.008855216205120087, -0.0038518968503922224, -0.007439305540174246, 0.00531422533094883, 0.007153309416025877, 0.0012890835059806705, 0.0029758152086287737, 0.003971113357692957, 0.00817363616079092, 0.008209404535591602, 0.0018533639376983047, 0.008031322620809078, 0.002043872606009245, 0.011439564637839794, -0.0007389618549495935, 0.00043938116868957877, -0.005506554152816534, 0.00033218591124750674, -0.003133568912744522, 0.0022266600281000137, -0.006518642418086529, -0.0010589007288217545, -0.011098112910985947, -0.008740060962736607, -0.0021457320544868708, -0.0014302297495305538, 0.005548523273319006, -0.008347777649760246, -0.004992653150111437, -0.00007903168443590403, 0.006799135822802782, 0.00009857220720732585, -0.0038217261899262667, 0.001153241959400475, 0.0023537345696240664, -0.007853698916733265, 0.014987051486968994, -0.012559283524751663, 0.00800546444952488, 0.002136251889169216, -0.016575155779719353, 0.005588951520621777, 0.010414866730570793, -0.0069480231031775475, 0.0010806228965520859, 0.0048181526362895966, 0.0019270601915195584, -0.0026119051035493612, -0.004504580516368151, -0.00363785563968122, -0.017747746780514717, 0.002202480798587203, 0.018981600180268288, -0.0004765134654007852, 0.00905736442655325, 0.010298710316419601, -0.0024520582519471645, 0.0014037876389920712, 0.0047899698838591576, 0.0008852006285451353, 0.011968561448156834, -0.006598053500056267, -0.0005733284633606672, 0.0029270644299685955, -0.007209117989987135, 0.0023085849825292826, 0.0054073454812169075, 0.004680429119616747, -0.0011831241426989436, 0.004897529259324074, -0.005753347184509039, -0.0039809225127100945, -0.015637582167983055, -0.004767564591020346, 0.00920877419412136, -0.0036893035285174847, 0.005227323155850172, -0.011112678796052933, 0.004205137491226196, 0.004522858653217554, 0.008959813043475151, -0.0013915708987042308, 0.00039954122621566057, 0.003976455889642239, 0.008468631654977798, -0.006789402570575476, 0.0015985884238034487, 0.004801895469427109, 0.0011868778383359313, -0.0005737172905355692, 0.005514282267540693, -0.0055844769813120365, -0.005359441041946411, 0.004094139207154512, 0.0038522956892848015, -0.0011175981489941478, -0.0014828953426331282, -0.009340833872556686, -0.003987936768680811, 0.004767988808453083, -0.0037229852750897408, 0.0027730364818125963, 0.0011066751321777701, 0.004261511843651533, -0.009428066201508045, 0.0009541358449496329, -0.007915877737104893, -0.011789191514253616, 0.01096775196492672, -0.0029938039369881153, 0.002166205318644643, 0.015339000150561333, 0.0070068929344415665, -0.012944714166224003, 0.006727435626089573, 0.006190957967191935, -0.001930835423991084, 0.004683276638388634, 0.006243501324206591, -0.004442613106220961, -0.023658111691474915, -0.005306337494403124, -0.010335415601730347, 0.004656478762626648, -0.0013127875281497836, 0.0062490287236869335, -0.008193153887987137, 0.0018585955258458853, 0.004483693744987249, -0.013798786327242851, -0.005594073329120874, -0.008968544192612171, 0.007196016144007444, -0.0006945787463337183, 0.0019213416380807757, -0.004494660999625921, -0.0010916542960330844, -0.002924615051597357, -0.003488181158900261, -0.003066240344196558, 0.007319938391447067, 0.001949442084878683, -0.002980275545269251, 0.0012361500412225723, -0.0047312211245298386, 0.0000610514180152677, 0.0008600889705121517, -0.008934149518609047, 0.0020122304558753967, 0.0018652693834155798, -0.0014590813079848886, -0.00430428609251976, 0.0017557950923219323, -0.0009015385876409709, -0.006788626313209534, -0.010718102566897869, -0.0006884932518005371, -0.0036802857648581266, -0.003791810479015112, -0.009291459806263447, -0.0026899033691734076, -0.0071183363907039165, 0.005937671754509211, -0.009275243617594242, 0.007666199468076229, 0.008416063152253628, -0.007455437444150448, 0.008809407241642475, -0.0014182791346684098, 0.004316341131925583, 0.001910656108520925, 0.005179862026125193, 0.0027777529321610928, -0.00559747451916337, -0.008992096409201622, 0.009989084675908089, -0.008077091537415981, 0.001048594480380416, 0.014471796341240406, 0.004838406108319759, 0.009346026927232742, -0.0016367464559152722, -0.00044637511018663645, 0.00032130980980582535, 0.00882477592676878, -0.014649617485702038, 0.005854381248354912, -0.004390016198158264, 0.0016704474110156298, 0.003806481836363673, -0.001953789032995701, 0.004108090419322252, 0.007744370494037867, 0.0009070149972103536, -0.007039160933345556, -0.0013316349359229207, -0.00016428469098173082, 0.004621610976755619, -0.013307261280715466, 0.0010589453158900142, -0.0037891282700002193, -0.0060349153354763985, -0.004939807578921318, -0.0018284269608557224, 0.0008689124369993806, 0.00428819702938199, -0.0024058406706899405, 0.00774743314832449, -0.0003202972002327442, -0.005872792564332485, 0.01306091994047165, -0.004475446417927742, -0.003998235799372196, 0.0011731557315215468, 0.002996579511091113, -0.002797879045829177, -0.004191712010651827, -0.0037138895131647587, 0.004126975312829018, 0.006063512526452541, -0.00303183333016932, -0.004685529507696629, 0.000806452299002558, -0.0011381844524294138, -0.010043621063232422, 0.00032500061206519604, 0.012511578388512135, -0.005313508678227663, 0.006604806985706091, -0.001819052966311574, -0.009582249447703362, -0.013537915423512459, 0.048336874693632126, -0.0022044298239052296, 0.004861827939748764, 0.0034455787390470505, -0.007227327674627304, -0.003103244351223111, 0.0009860049467533827, 0.008687011897563934, -0.004888089839369059, -0.007309017702937126, 0.0077992696315050125, -0.003835401264950633, 0.0020289639942348003, 0.0025027759838849306, 0.0031327747274190187, 0.016346879303455353, -0.000818915490526706, -0.015293488278985023, -0.019772976636886597, 0.008215343579649925, -0.0047955503687262535, -0.008534446358680725, 0.010024270042777061, -0.005364423617720604, -0.005672673229128122, 0.0031552137807011604, 0.005769666284322739, 0.0012572908308357, 0.00012186419917270541, -0.004365800879895687, -0.003917706664651632, 0.0025623475667089224, 0.0013744892785325646, 0.0059709707275033, 0.008135939948260784, -0.0015810317127034068, 0.006239884067326784, -0.0006110786343924701, -0.0024757569190114737, -0.00423031160607934, 0.0029330868273973465, 0.007750343531370163, -0.003115858417004347, -0.00600969884544611, 0.004948985297232866, 0.0060502164997160435, -0.0010441767517477274, 0.011278163641691208, -0.0008421738748438656, -0.008283420465886593, 0.006541640963405371, 0.0059995753690600395, 0.0012728291330859065, 0.009060656651854515, 0.000004276733761798823, 0.005641034338623285, 0.0028157122433185577, -0.006508211605250835, -0.019265426322817802, -0.004431359004229307, 0.008039794862270355, 0.008845956064760685, -0.001157941180281341, 0.0016556089976802468, -0.0015812802594155073, -0.002784796291962266, -0.009670327417552471, -0.01062269601970911, -0.0021574976854026318, 0.0019459661561995745, 0.003016799222677946, 0.06974659115076065, -0.006598332431167364, 0.0005483396234922111, -0.00791681744158268, -0.0005102389841340482, -0.0016237207455560565, -0.0013002149062231183, 0.002779143862426281, -0.002707079518586397, 0.0014529089676216245, 0.00022670099860988557, -0.007787234615534544, -0.011952088214457035, 0.0011713035637512803, 0.00225336872972548, -0.003372536040842533, 0.004426870495080948, 0.007624076213687658, -0.009440632537007332, 0.001670056371949613, -0.010617594234645367, -0.0019248748430982232, -0.0005858973599970341, -0.011928011663258076, -0.0024031756911426783, -0.003026439342647791, 0.007058009970933199, 0.00499855587258935, 0.0034662659745663404, -0.004008458461612463, 0.003752402262762189, -0.0007904898375272751, 0.0026045884005725384, -0.005373757798224688, 0.0007455378072336316, -0.007726892828941345, 0.007009334396570921, 0.003043149132281542, -0.012357189320027828, -0.005907388404011726, -0.002618588972836733, 0.0024354378692805767, -0.006376790348440409, 0.0043485164642333984, -0.0009393075597472489, 0.005322135519236326, -0.003160190535709262, -0.0022768396884202957, -0.006909831427037716, 0.0048039997927844524, -0.011497276835143566, 0.00554442685097456, -0.17064277827739716, 0.0105888145044446, 0.002989239292219281, -0.00683909235522151, -0.004335326608270407, -0.01717769168317318, -0.007887287996709347, 0.003756555961444974, 0.011829468421638012, 0.0011585848405957222, -0.0016531622968614101, -0.00433448888361454, 0.005882678087800741, 0.0021207097452133894, -0.0007364911725744605, -0.00915452465415001, 0.002262062393128872, -0.004440296441316605, 0.0005275853327475488, 0.004181156866252422, 0.004027748946100473, 0.014763742685317993, 0.000573899713344872, 0.0029534664936363697, -0.001013989094644785, -0.0051033152267336845, 0.005689611192792654, -0.001447447226382792, 0.0020922748371958733, -0.010732382535934448, -0.005127855110913515, -0.004524110816419125, -0.0047194696962833405, 0.0017806796822696924, 0.008137010037899017, 0.0004119714139960706, 0.008504689671099186, 0.0036893091164529324, -0.008452026173472404, 0.005978320725262165, -0.007341432385146618, 0.0272385086864233, 0.0031281323172152042, 0.00762605294585228, 0.002449650317430496, -0.008821222931146622, -0.006306408438831568, 0.006285128183662891, 0.0016670619370415807, 0.014279639348387718, -0.013075361959636211, -0.003305992344394326, 0.001371112302877009, 0.01976931281387806, -0.004640641622245312, -0.010163095779716969, -0.007245954591780901, -0.0034064804203808308, 0.0014912764308974147, 0.006914975121617317, 0.01133575476706028, -0.003783144988119602, 0.00745798135176301, -0.003979038912802935, -0.022214386612176895, 0.0012599793262779713, -0.0021464296150952578, -0.0067042759619653225, -0.001547988853417337, 0.006232208572328091, 0.008834035135805607, 0.002975332783535123, 0.0027455040253698826, 0.000351456634234637, 0.0026944244746118784, -0.002947455272078514, 0.006039673462510109, -0.0003734901256393641, 0.006729948800057173, -0.011255207471549511, 0.005602956749498844, -0.011945027858018875, -0.0012201861245557666, 0.0009996842127293348, -0.003977778367698193, 0.010798678733408451, 0.005911096930503845, -0.00418650871142745, -0.0036172715481370687, -0.010249380022287369, -0.0032282571773976088, 0.0026481400709599257, 0.002406224375590682, -0.010515626519918442, 0.002589248586446047, 0.0015505434712395072, 0.0045847236178815365, 0.006284504197537899, -0.010594788938760757, 0.007423496805131435, 0.005941423587501049, -0.00562669662758708, -0.0005417768261395395, -0.0069967047311365604, 0.0057412078604102135, 0.0034448117949068546, -0.0058904411271214485, -0.00791128445416689, 0.004732134751975536, -0.004412438254803419, -0.005543364677578211, 0.0053151934407651424, -0.008949627168476582, -0.010272406041622162, -0.002583534689620137, -0.00942210853099823, -0.000763590564019978 ]
8aab4acf40735c2dc3547887c3be02d0b2808eff
1,584
py
Python
model_zoo/official/nlp/bert_thor/src/evaluation_config.py
GuoSuiming/mindspore
48afc4cfa53d970c0b20eedfb46e039db2a133d5
[ "Apache-2.0" ]
55
2020-12-17T10:26:06.000Z
2022-03-28T07:18:26.000Z
model_zoo/official/nlp/bert_thor/src/evaluation_config.py
forwhat461/mindspore
59a277756eb4faad9ac9afcc7fd526e8277d4994
[ "Apache-2.0" ]
1
2020-12-29T06:46:38.000Z
2020-12-29T06:46:38.000Z
model_zoo/official/nlp/bert_thor/src/evaluation_config.py
forwhat461/mindspore
59a277756eb4faad9ac9afcc7fd526e8277d4994
[ "Apache-2.0" ]
14
2021-01-29T02:39:47.000Z
2022-03-23T05:00:26.000Z
# Copyright 2020 Huawei Technologies Co., Ltd # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # ============================================================================ """ config settings, will be used in finetune.py """ from easydict import EasyDict as edict import mindspore.common.dtype as mstype from .bert_model import BertConfig cfg = edict({ 'task': 'NER', 'num_labels': 41, 'data_file': '', 'schema_file': None, 'finetune_ckpt': '', 'use_crf': False, 'clue_benchmark': False, }) bert_net_cfg = BertConfig( batch_size=8 if not cfg.clue_benchmark else 1, seq_length=512, vocab_size=30522, hidden_size=1024, num_hidden_layers=24, num_attention_heads=16, intermediate_size=4096, hidden_act="gelu", hidden_dropout_prob=0.0, attention_probs_dropout_prob=0.0, max_position_embeddings=512, type_vocab_size=2, initializer_range=0.02, use_relative_positions=False, input_mask_from_dataset=True, token_type_ids_from_dataset=True, dtype=mstype.float32, compute_type=mstype.float16, )
28.8
78
0.693813
1
1.1976
[ -0.0016453379066661, 0.025145670399069786, 0.009808627888560295, 0.0019573846366256475, 0.0024150307290256023, -0.004139717668294907, -0.008614377118647099, 0.005459786858409643, -0.00681421859189868, 0.0011236841091886163, 0.0023786663077771664, 0.003382698865607381, 0.010184555314481258, -0.016520442441105843, 0.0005550810601562262, 0.018463842570781708, -0.05471260845661163, 0.002852595178410411, -0.006130123045295477, 0.0015778389060869813, -0.009549641981720924, 0.005978020839393139, 0.010438534431159496, 0.00877100508660078, 0.0029843782540410757, -0.0007461641216650605, 0.012008389458060265, 0.0022824325133115053, -0.006907110568135977, -0.006371076684445143, -0.0014721467159688473, -0.0018186873057857156, -0.008574080653488636, -0.009389861486852169, 0.006794055923819542, -0.003241076599806547, 0.0025127397384494543, -0.019071931019425392, 0.010606274008750916, -0.006224951706826687, -0.0047169947065413, -0.01765383593738079, -0.0007566759013570845, 0.00422872556373477, -0.011427031829953194, 0.0030855233781039715, -0.005091093480587006, 0.0009138886234723032, -0.008357543498277664, 0.006696218624711037, -0.01117915939539671, 0.007078760303556919, 0.013417891226708889, 0.0026974575594067574, -0.0061635361053049564, -0.008634691126644611, 0.011385494843125343, 0.0021041356958448887, -0.01160912960767746, 0.0008974055526778102, -0.005533790681511164, 0.000877698534168303, 0.005668487399816513, 0.003837535623461008, -0.02001064084470272, -0.007858035154640675, -0.003306300612166524, 0.004647072404623032, -0.0023265453055500984, 0.004327206406742334, 0.0022939201444387436, -0.0017446891870349646, 0.008209889754652977, 0.0028181227389723063, 0.0028922734782099724, -0.00305310171097517, -0.0011168468045070767, 0.00021006040333304554, 0.01021739561110735, 0.0004263667215127498, 0.0012819139519706368, -0.004457109607756138, 0.0038329458329826593, 0.012082765810191631, 0.01755845546722412, 0.01193972211331129, 0.018713699653744698, -0.00950839277356863, 0.04387640953063965, 0.00545032462105155, -0.012205909006297588, 0.003101571463048458, -0.011049192398786545, -0.00189150997903198, 0.0006231213919818401, -0.0273322444409132, 0.0016588454600423574, -0.0045977248810231686, 0.0006703175022266805, 0.0013948234263807535, -0.00024404596479143947, 0.01063553337007761, -0.00029224410536698997, -0.00612906226888299, -0.010064879432320595, 0.011033969931304455, -0.009059290401637554, -0.0019397343276068568, 0.007943430915474892, 0.000745272496715188, -0.012442589737474918, -0.002052450319752097, 0.002277676248922944, -0.014065082184970379, 0.003908382263034582, 0.007184342946857214, -0.006064114160835743, 0.053735796362161636, -0.0028665377758443356, 0.0034776427783071995, -0.004594417288899422, 0.0005076124798506498, 0.001570058288052678, 0.006836640648543835, 0.009134546853601933, -0.004274951294064522, 0.009424090385437012, 0.008683976717293262, 0.00508097792044282, 0.0061447895132005215, -0.0021504885517060757, 0.008624340407550335, -0.0013521803775802255, -0.002604295266792178, 0.0019162807147949934, -0.008575944229960442, 0.009128985926508904, -0.00026420928770676255, -0.008148890919983387, 0.001996788661926985, -0.001645407173782587, -0.011660052463412285, 0.0007443454232998192, -0.004025756381452084, 0.00222433777526021, -0.011468919925391674, -0.004631361458450556, -0.001909269718453288, -0.00720684789121151, 0.004072876181453466, 0.006645484361797571, 0.005584313999861479, 0.004665759392082691, -0.004486012272536755, -0.008940122090280056, 0.00034133795998059213, -0.0022741355933248997, 0.004672167357057333, 0.007796942722052336, 0.0011120104463770986, -0.008933487348258495, -0.002527310512959957, 0.0034662582911551, 0.005579678807407618, -0.0017369975103065372, -0.0017000131774693727, -0.008665256202220917, 0.007319815456867218, -0.0013199823442846537, 0.005264859646558762, 0.010438434779644012, -0.0037224339321255684, 0.0003415208193473518, 0.0004921548534184694, -0.0016049327095970511, -0.001013374188914895, 0.006067296955734491, 0.011090632528066635, -0.002635394688695669, -0.005040785297751427, 0.0027806672733277082, 0.00581051129847765, 0.009458731859922409, 0.00849149189889431, -0.003285817103460431, 0.0017028830479830503, -0.00455109728500247, 0.0019021148327738047, 0.007690051104873419, -0.002751620952039957, 0.0038479419890791178, 0.0031805953476577997, -0.014754943549633026, -0.006611431483179331, 0.00042210210813209414, -0.008637312799692154, 0.002423663390800357, 0.015426520258188248, 0.009248178452253342, -0.0005094020743854344, 0.0026096722576767206, -0.008533102460205555, -0.0007067392580211163, 0.006300761364400387, 0.0005606321501545608, -0.012567629106342793, -0.9572587609291077, 0.006412261165678501, 0.004271618090569973, -0.003969041630625725, 0.004095626063644886, 0.001677931984886527, 0.0032971797045320272, 0.0028227507136762142, 0.013825795613229275, -0.006325795780867338, -0.005721680354326963, -0.006079281214624643, -0.01160514447838068, -0.0003506072098389268, -0.006073714699596167, -0.0023422737140208483, -0.004136881325393915, -0.008657881058752537, -0.002606320660561323, -0.004315325524657965, -0.0034484637435525656, 0.013498201034963131, -0.0014632751699537039, 0.005886376369744539, 0.004206000827252865, 0.00022923309006728232, -0.004072423558682203, 0.0005511133349500597, -0.002840697066858411, -0.002609989373013377, -0.0034574377350509167, -0.0170157328248024, -0.0057724895887076855, -0.00179582042619586, 0.011196117848157883, -0.0014712897827848792, 0.008130859583616257, -0.0006165975937619805, 0.0040267640724778175, -0.009816226549446583, 0.0064321402460336685, -0.0009894673712551594, 0.0019975819159299135, -0.02946031279861927, 0.0000722571712685749, 0.0026229985523968935, -0.005133962724357843, 0.005854323040693998, 0.0014145702589303255, 0.0007266514003276825, -0.005129923578351736, -0.007009254302829504, 0.010804935358464718, -0.009375741705298424, 0.005737679544836283, -0.008539730682969093, -0.007058155257254839, -0.005097937770187855, -0.009857616387307644, -0.001278407173231244, 0.005462621338665485, -0.005725326482206583, -0.002509871032088995, -0.005506058689206839, 0.003235769923776388, 0.0037562178913503885, 0.0017328172689303756, -0.02152200974524021, -0.00597594678401947, -0.004442089702934027, 0.0038527364376932383, -0.003224228974431753, -0.00426897406578064, 0.005292236339300871, -0.007226346991956234, 0.008328313007950783, 0.002334214048460126, -0.0014758347533643246, -0.009509366936981678, 0.00009662791126174852, -0.01072789914906025, -0.006294389721006155, 0.003261227859184146, -0.0041376398876309395, -0.005465243477374315, -0.00004117390562896617, 0.003773731179535389, 0.007203273009508848, -0.005029570776969194, 0.006564564537256956, 0.010891212150454521, -0.0009803291177377105, -0.01026424951851368, 0.00516120670363307, 0.00948246382176876, 0.001715990249067545, -0.0033495326060801744, -0.00030280801001936197, 0.00867975689470768, 0.007386247161775827, 0.0037472634576261044, 0.008931929245591164, 0.002169099636375904, 0.011464678682386875, 0.0005911896005272865, 0.0016895013395696878, -0.0016036548186093569, -0.002241752576082945, -0.003529394743964076, -0.000986367929726839, -0.002849142998456955, -0.005184479523450136, -0.012250686064362526, -0.006680582650005817, -0.005291127599775791, 0.0006012242520228028, 0.0014130424242466688, -0.0056154667399823666, 0.0004874423611909151, 0.0022043618373572826, 0.009535819292068481, -0.0010869621764868498, -0.0028760875575244427, 0.00122509163338691, 0.0019337874837219715, -0.0014220643788576126, 0.012777220457792282, -0.011139498092234135, 0.007635876536369324, -0.001042605726979673, -0.014365090057253838, 0.007535989861935377, 0.00869936216622591, -0.007612404879182577, 0.0019412663532420993, 0.0016179777448996902, 0.0015541117172688246, -0.0020431838929653168, -0.005986430682241917, -0.001805497333407402, -0.01897449418902397, 0.0012226133840158582, 0.019162818789482117, 0.0010949253337457776, 0.010981477797031403, 0.012372960336506367, -0.0025228713639080524, 0.0029256280977278948, 0.00544587429612875, 0.002920920494943857, 0.012466670013964176, -0.009608250111341476, -0.0015807189047336578, 0.003109180834144354, -0.004781999625265598, 0.0005004349513910711, 0.005377098917961121, 0.0024051812943071127, 0.00015243726375047117, 0.0020410765428096056, -0.0069206575863063335, -0.003929192200303078, -0.01800304837524891, -0.0003280655655544251, 0.007945047691464424, -0.004750068299472332, 0.00527685321867466, -0.009526089765131474, 0.003473161719739437, 0.006441463716328144, 0.004191983956843615, 0.00004633744538296014, 0.000872823060490191, 0.00715181790292263, 0.012071235105395317, -0.00872650183737278, 0.0031372597441077232, 0.001470077782869339, -0.0019449208630248904, 0.0022062109783291817, 0.006776037160307169, -0.007341007702052593, -0.0056616878136992455, 0.0016242526471614838, 0.005618325434625149, 0.0013490740675479174, -0.0034677295479923487, -0.007493143901228905, -0.004266420844942331, 0.0013147779973223805, -0.0027672986034303904, 0.0026753221172839403, 0.004616299644112587, 0.001228140201419592, -0.009031472727656364, 0.0004402830672916025, -0.003914367873221636, -0.009985722601413727, 0.012276124209165573, -0.0035222789738327265, 0.0033111167140305042, 0.014985906891524792, 0.005203246138989925, -0.01350172609090805, 0.006572723388671875, 0.00979356188327074, -0.0019429392414167523, 0.005238196812570095, 0.006081811618059874, -0.007517004851251841, -0.024183012545108795, -0.00405983766540885, -0.012068366631865501, 0.0067557645961642265, -0.0014338259352371097, 0.003029637038707733, -0.008466712199151516, 0.0075114015489816666, 0.004538929555565119, -0.014968260191380978, -0.006057498510926962, -0.008538280613720417, 0.006148565094918013, -0.003023679368197918, -0.0015377782983705401, -0.004576751962304115, -0.003168864641338587, -0.00252169300802052, -0.0022131637670099735, -0.002089758636429906, 0.005001194775104523, 0.003397637512534857, -0.004697054158896208, 0.0014941578265279531, -0.002612634329125285, 0.0002909574832301587, 0.0005879118107259274, -0.010513701476156712, -0.0008949374896474183, 0.0051727574318647385, -0.0007923254161141813, -0.004798530600965023, -0.001284190802834928, -0.0007186660077422857, -0.004808872938156128, -0.011218462139368057, -0.007138663902878761, -0.004071963485330343, -0.002327744383364916, -0.010507242754101753, -0.001796663855202496, -0.01064351201057434, 0.008206038735806942, -0.0037091572303324938, 0.010299145244061947, 0.0050704400055110455, -0.006093185860663652, 0.003927725832909346, -0.001663687638938427, 0.004087482579052448, 0.0027424097061157227, 0.005386803764849901, -0.0027630911208689213, -0.007319676224142313, -0.00843894761055708, 0.011051208712160587, -0.009727994911372662, 0.001582165015861392, 0.012531738728284836, 0.003554783295840025, 0.007613117806613445, -0.0006733407499268651, 0.0012271956074982882, 0.005400363355875015, 0.008488696068525314, -0.013130703940987587, 0.003856551367789507, -0.004044529050588608, -0.0015066569903865457, 0.005697086453437805, -0.003595136571675539, 0.004456215538084507, 0.005223146174103022, 0.002143293619155884, -0.006022503133863211, 0.00010300279245711863, 0.0007000394398346543, 0.0006779383984394372, -0.010544906370341778, -0.0008789916755631566, -0.004057713318616152, -0.0033784196712076664, -0.0012992218835279346, -0.0007888342370279133, -0.0007873176364228129, 0.004600939806550741, -0.0010412671836093068, 0.006478160619735718, 0.001251266454346478, -0.005943734664469957, 0.015422134660184383, -0.005193392280489206, -0.005250093061476946, 0.002190690953284502, -0.00011025439744116738, -0.003571516601368785, -0.006529259495437145, 0.0012827113969251513, 0.0007517669582739472, 0.004545402713119984, -0.0029606150928884745, -0.002615306293591857, -0.0012536054709926248, 0.001940570306032896, -0.011214150115847588, 0.0034786234609782696, 0.011988813057541847, -0.003503423882648349, 0.0060964422300457954, -0.0002900701656471938, -0.007573374081403017, -0.013438114896416664, 0.055936023592948914, -0.002908201888203621, 0.004626867361366749, 0.005690388381481171, -0.0088620251044631, -0.0018772989278659225, -0.0021511756349354982, 0.00836979690939188, -0.005884093698114157, -0.007548148278146982, 0.009675832465291023, -0.0043923803605139256, 0.002548884367570281, 0.007497294340282679, -0.0011743822833523154, 0.016293834894895554, -0.003535646013915539, -0.019953783601522446, -0.01749136671423912, 0.008090591058135033, -0.005162468645721674, -0.006496807094663382, 0.008468745276331902, -0.002814267296344042, -0.004079126287251711, 0.002260295208543539, 0.006317270454019308, -0.00047297784476540983, -0.0018029463244602084, -0.003056230256333947, -0.0012794473441317677, 0.0023121347185224295, 0.0009871764341369271, 0.007298037875443697, 0.00820371974259615, -0.004535291343927383, 0.006273629609495401, 0.0009013082017190754, -0.00028152752202004194, -0.0005575641989707947, 0.0057380953803658485, 0.004355161916464567, -0.0018678830238059163, -0.0037053509149700403, 0.005685861222445965, 0.005858651362359524, 0.001012867665849626, 0.011382842436432838, -0.002493177307769656, -0.005353289656341076, 0.007383250165730715, 0.0065488810651004314, 0.0008599530556239188, 0.007821306586265564, -0.0023625167086720467, 0.006507872603833675, -0.0003894793044310063, -0.011657800525426865, -0.01682424731552601, 0.0006036990671418607, 0.007881700061261654, 0.0062104277312755585, 0.00027334722108207643, 0.002568091033026576, -0.0011750784469768405, -0.002572358585894108, -0.009201271459460258, -0.00796992052346468, -0.002871679374948144, 0.0022064466029405594, 0.006105203181505203, 0.0698365867137909, -0.005769556853920221, -0.0004477179900277406, -0.007432658225297928, -0.0005477663944475353, -0.0015643840888515115, 0.0005821575759910047, -0.001621284056454897, -0.004654266871511936, 0.0023225301411002874, 0.0017841748194769025, -0.008399090729653835, -0.011513574980199337, 0.0009224385139532387, 0.004457160364836454, -0.0028132698498666286, 0.0035500379744917154, 0.00396419782191515, -0.012398372404277325, 0.0013267253525555134, -0.012165874242782593, -0.0026094617787748575, -0.0027152399998158216, -0.010657229460775852, -0.0019470922416076064, -0.001966434298083186, 0.004325151909142733, 0.0034870945382863283, 0.0053262957371771336, -0.006097776815295219, 0.00659593753516674, -0.001910840393975377, 0.0002670576795935631, -0.002390466397628188, -0.0016807400388643146, -0.006803811527788639, 0.008638603612780571, 0.0012600795598700643, -0.013627596199512482, -0.007664783392101526, -0.000638992409221828, -0.0003751193289645016, -0.005867453292012215, 0.003605535486713052, 0.0007843464845791459, 0.007336221169680357, -0.002341196406632662, 0.002699047327041626, -0.006459622178226709, 0.0027425854932516813, -0.009767909534275532, 0.0060561178252100945, -0.1750134974718094, 0.01152567844837904, 0.0034666829742491245, -0.005727089010179043, -0.004123602993786335, -0.013218233361840248, -0.007476671598851681, 0.003318415256217122, 0.009814525954425335, 0.002877852413803339, -0.0013630613684654236, -0.001808264059945941, 0.005776708479970694, 0.0009703506948426366, -0.002324851229786873, -0.004975480958819389, 0.003041129792109132, -0.004579912405461073, 0.0008057783707045019, 0.008357519283890724, 0.008455933071672916, 0.006455837748944759, 0.0006105517968535423, 0.003363122697919607, -0.0011287484085187316, -0.004559917841106653, 0.0006565888179466128, -0.0031805657781660557, 0.008021173067390919, -0.009981805458664894, -0.004347837530076504, -0.0016252234345301986, -0.00516058225184679, 0.0025964095257222652, 0.004705841187387705, 0.0030914561357349157, 0.007695790845900774, -0.0018066524062305689, -0.005677877925336361, 0.006213916931301355, -0.007745980750769377, 0.02885577082633972, 0.008287979289889336, 0.005844692699611187, 0.0005195296253077686, -0.00400517787784338, -0.0037086522206664085, 0.008169551379978657, 0.004307011608034372, 0.010917785577476025, -0.01392691396176815, -0.0024012017529457808, 0.0018936380511149764, 0.019069140776991844, -0.006430960260331631, -0.009331967681646347, -0.006706701125949621, -0.004037346690893173, 0.0030815154314041138, 0.009017938748002052, 0.01055869460105896, -0.005559298675507307, 0.006536567583680153, -0.003757492871955037, -0.022518988698720932, 0.004576529376208782, -0.0059018442407250404, -0.009052427485585213, 0.00040275987703353167, 0.008436537347733974, 0.011260870844125748, -0.0012809691252186894, 0.003522370243445039, -0.0032822932116687298, 0.007871848531067371, -0.001498992322012782, 0.006714964285492897, -0.0013714428059756756, 0.0051900725811719894, -0.0066080340184271336, 0.008487769402563572, -0.010353093966841698, -0.002246938180178404, 0.0038609604816883802, -0.004882875829935074, 0.0079276068136096, 0.005549413617700338, -0.0046362243592739105, -0.000600383966229856, -0.009899938479065895, -0.0020336408633738756, -0.00035534147173166275, 0.004363982938230038, -0.00892568752169609, 0.003769220784306526, 0.0000733848282834515, 0.002934914780780673, 0.00884972419589758, -0.009177638217806816, 0.00611206516623497, 0.0047362386249005795, -0.008627509698271751, -0.002614244818687439, -0.0004055882163811475, 0.003298352472484112, 0.0021229626145213842, -0.006203831173479557, -0.0048166788183152676, 0.0027991009410470724, -0.009252987802028656, -0.0053461831994354725, 0.005670592654496431, -0.012580124661326408, -0.009766493923962116, -0.0004383600316941738, -0.010324908420443535, -0.00007402854680549353 ]
8aad801ac3abc226337a71ef38e5ff434b1f3490
1,052
py
Python
portal/apps/core/management/commands/sync_articleviewedby.py
Artis-Physis/utopia-cms
5cb8d941d0b2df53fddc566a52e9d3baee4a007e
[ "BSD-3-Clause" ]
8
2020-12-15T17:11:08.000Z
2021-12-13T22:08:33.000Z
portal/apps/core/management/commands/sync_articleviewedby.py
Artis-Physis/utopia-cms
5cb8d941d0b2df53fddc566a52e9d3baee4a007e
[ "BSD-3-Clause" ]
28
2020-12-15T17:34:03.000Z
2022-02-01T04:09:10.000Z
portal/apps/core/management/commands/sync_articleviewedby.py
Artis-Physis/utopia-cms
5cb8d941d0b2df53fddc566a52e9d3baee4a007e
[ "BSD-3-Clause" ]
7
2020-12-15T19:59:17.000Z
2021-11-24T16:47:06.000Z
# -*- coding: utf-8 -*- # utopia-cms 2020. Aníbal Pacheco. from django.core.management import BaseCommand from django.db.utils import IntegrityError from apps import core_articleviewedby_mdb from core.models import ArticleViewedBy class Command(BaseCommand): help = "Moves article viewed by data from mongodb to Django model" def handle(self, *args, **options): mdb_view = core_articleviewedby_mdb.posts.find_one_and_delete({}) while mdb_view: try: avb = ArticleViewedBy.objects.get(article=mdb_view['article'], user=mdb_view['user']) avb.viewed_at = mdb_view['viewed_at'] avb.save() except ArticleViewedBy.DoesNotExist: try: ArticleViewedBy.objects.create( article_id=mdb_view['article'], user_id=mdb_view['user'], viewed_at=mdb_view['viewed_at']) except IntegrityError: pass mdb_view = core_articleviewedby_mdb.posts.find_one_and_delete({})
37.571429
114
0.640684
1
0.9591
[ 0.001591796986758709, 0.023530634120106697, 0.0076988511718809605, 0.0038885248359292746, 0.005066914949566126, -0.004530047532171011, -0.00652491906657815, 0.0022412303369492292, -0.005820253398269415, 0.005020741373300552, 0.0023095710203051567, 0.004272011574357748, 0.006081918254494667, -0.0149654820561409, -0.001226955559104681, 0.018940508365631104, -0.05121598392724991, 0.004818369634449482, -0.005319735035300255, 0.0019321672152727842, -0.007194784004241228, 0.010866155847907066, 0.008219819515943527, 0.006259865593165159, 0.004702526610344648, -0.00223120697773993, 0.008011882193386555, 0.0037527065724134445, -0.004855150356888771, -0.004169128835201263, -0.0013137564528733492, -0.0027342967223376036, -0.006605291273444891, -0.00695421127602458, 0.005403933115303516, -0.0050939954817295074, -0.002249033423140645, -0.020174790173768997, 0.010544073767960072, -0.0044767954386770725, -0.007279479410499334, -0.01636086218059063, -0.005091652274131775, 0.004646505694836378, -0.009610884822905064, 0.003154976759105921, -0.005183553788810968, 0.004198065027594566, -0.010047371499240398, 0.007085156626999378, -0.007407453842461109, 0.002517466200515628, 0.013597160577774048, 0.0029233696404844522, -0.005049502477049828, -0.007641288451850414, 0.015682028606534004, 0.002122899517416954, -0.01087864674627781, 0.0022628202568739653, -0.0030227990355342627, -0.005564388819038868, 0.007091307081282139, -0.0002206886711064726, -0.017804423347115517, -0.008457588963210583, -0.004644617438316345, 0.00286639085970819, -0.0008389470167458057, 0.00566474674269557, 0.001202677609398961, -0.0031825080513954163, 0.005982651375234127, 0.003855596762150526, 0.0005744988447986543, -0.003038500901311636, -0.0006448884960263968, 0.0021907864138484, 0.007740478962659836, 0.0028452416881918907, 0.004189362283796072, -0.007594774477183819, 0.007855208590626717, 0.007468638941645622, 0.0124159324914217, 0.007431381847709417, 0.020054150372743607, -0.011009491048753262, 0.042792823165655136, 0.0025748310144990683, -0.0105130011215806, 0.0034771037753671408, -0.005309580825269222, -0.0030647232197225094, -0.0070305014960467815, -0.031563159078359604, -0.0008615519036538899, -0.000885883579030633, -0.003674637759104371, 0.004574344493448734, -0.0012145597720518708, 0.003932778257876635, -0.0023167883045971394, -0.004348876420408487, -0.012338025495409966, 0.015888046473264694, -0.007950621657073498, -0.003200163831934333, 0.004388947505503893, 0.00031546602258458734, -0.014546390622854233, 0.00009168086398858577, 0.002115400042384863, -0.010633278638124466, 0.004266826901584864, 0.003918859176337719, -0.0046036215499043465, 0.04837971553206444, -0.0007203448913060129, 0.0026060992386192083, -0.005125805735588074, 0.0015165696386247873, 0.0008171258959919214, 0.004791319835931063, 0.009394771419465542, -0.005136511754244566, 0.011916656978428364, 0.005954538471996784, 0.003186441957950592, 0.007566547021269798, -0.003766931127756834, 0.007110916078090668, -0.005969031248241663, -0.0010516713373363018, -0.0007294499082490802, -0.006738432217389345, 0.00600934773683548, -0.002569975098595023, -0.004004120826721191, 0.0035279730800539255, -0.0023863078095018864, -0.013240045867860317, 0.0008688673260621727, -0.002204518998041749, 0.0034682145342230797, -0.01055087335407734, -0.0050977738574147224, -0.0021647396497428417, -0.004746819380670786, 0.00274445116519928, 0.00828294176608324, 0.0034689309541136026, 0.002706710947677493, -0.004408294800668955, -0.0037813708186149597, 0.0011229815427213907, -0.0023201205767691135, 0.0009679766953922808, 0.00577543256804347, 0.003850705921649933, -0.010000539012253284, 0.0007946465048007667, 0.0069727166555821896, 0.0027475750539451838, -0.001435641897842288, 0.00655387993901968, -0.00759578263387084, 0.008576678112149239, 0.002699511591345072, 0.0014527019811794162, 0.010388598777353764, -0.006359159015119076, -0.0005236821016296744, -0.0012323401169851422, 0.00498792203143239, 9.68131871559308e-7, 0.00393855944275856, 0.013293036259710789, -0.00471430504694581, -0.006312741432338953, 0.003760898020118475, 0.005396880675107241, 0.008213294669985771, 0.006215641740709543, -0.002147032180801034, 0.0030882530845701694, -0.004452399909496307, -0.0008655103738419712, 0.004741806536912918, -0.00604667142033577, 0.0076986514031887054, 0.0033606700599193573, -0.012692378833889961, -0.005561665631830692, 0.002638123231008649, -0.011487578973174095, 0.0015494398539885879, 0.015619541518390179, 0.007986901327967644, -0.0015673331217840314, 0.005274159833788872, -0.010416003875434399, 0.002127575222402811, 0.008026082068681717, 0.0025359776336699724, -0.011310904286801815, -0.959754467010498, 0.004712332040071487, 0.0005510481423698366, -0.0008115037344396114, 0.0049723731353878975, 0.0035209530033171177, 0.0036399373784661293, 0.0044607482850551605, 0.013278717175126076, -0.008859038352966309, -0.005481857340782881, -0.011574770323932171, -0.008709668181836605, -0.001590041909366846, -0.006136670708656311, -0.0013706022873520851, -0.005487518850713968, -0.0046998984180390835, -0.004690785892307758, -0.004484929144382477, -0.001467115362174809, 0.006698695942759514, 0.0001470693969167769, 0.003072909079492092, 0.0013202725676819682, 0.007504068315029144, -0.0044374312274158, -0.0020687186624854803, -0.000173896987689659, 0.0001013302753563039, -0.00971725583076477, -0.010656779631972313, -0.004500826820731163, -0.00010983822721755132, 0.008053862489759922, 0.001245963154360652, 0.007155443076044321, -0.002478394191712141, 0.00039699679473415017, -0.010608034208416939, 0.004294410347938538, -0.0011130105704069138, 0.004958812613040209, -0.026668865233659744, 0.0016722776927053928, -0.003115595318377018, -0.00726564135402441, 0.008216680027544498, 0.0017545206937938929, 0.002359222387894988, -0.004812735132873058, -0.004339792765676975, 0.008926802314817905, -0.009229692630469799, 0.005064641125500202, -0.005128026008605957, -0.006794393062591553, -0.0023732043337076902, -0.009080570191144943, 0.0021680027712136507, 0.006937560625374317, -0.0019549683202058077, -0.001701019355095923, -0.0037075106520205736, 0.0020133284851908684, 0.000706125982105732, 0.00441490625962615, -0.01751401275396347, -0.006767910905182362, -0.0007647719467058778, 0.005118223838508129, -0.0023527508601546288, -0.0056183962151408195, 0.003799739293754101, -0.009389272890985012, 0.007279509678483009, 0.002779592527076602, 0.0003306726866867393, -0.008462869562208652, 0.002194054424762726, -0.007689720951020718, -0.01060846634209156, 0.0026975413784384727, -0.01018444448709488, -0.005498267710208893, -0.0021818208042532206, 0.004683484323322773, 0.007181638851761818, -0.0017846740083768964, 0.003361385315656662, 0.008494759909808636, -0.000299569423077628, -0.0098716514185071, 0.00660873344168067, 0.006255485583096743, 0.0012461579171940684, -0.0015817747917026281, 0.004059964325278997, 0.009953253902494907, 0.0029249179642647505, 0.0004597712540999055, 0.006949037313461304, 0.0005323737859725952, 0.009677033871412277, -0.001001086668111384, 0.002209288766607642, -0.004242524970322847, -0.000493152707349509, -0.004168184474110603, -0.0021289943251758814, -0.005996123421937227, -0.0005363897071219981, -0.013755010440945625, -0.008630157448351383, -0.004022788722068071, -0.0001003458455670625, 0.0016390958335250616, -0.003822647500783205, -0.0013692068168893456, 0.0019727505277842283, 0.007544652558863163, -0.0009301715763285756, -0.0041032833978533745, -0.0005834591574966908, 0.003101115580648184, -0.007728497497737408, 0.014915542677044868, -0.010820645838975906, 0.008422475308179855, -0.00139436568133533, -0.013822757638990879, 0.006340131163597107, 0.010231108404695988, -0.007464780006557703, 0.003574265632778406, 0.001917115761898458, 0.0032533651683479548, -0.002399503020569682, -0.006631289608776569, -0.005172271281480789, -0.015245680697262287, 0.0006562246126122773, 0.018717369064688683, 0.002397040603682399, 0.012255239300429821, 0.011096835136413574, -0.004450085572898388, 0.003020194359123707, 0.005992189049720764, 0.0023901239037513733, 0.011124427430331707, -0.006230821833014488, -0.0010758808348327875, 0.002386509906500578, -0.004896855913102627, 0.002173561370000243, 0.0034530051052570343, 0.004370591603219509, -0.002975628012791276, -0.0000707306171534583, -0.005283669102936983, -0.002994265640154481, -0.0166457686573267, -0.0015367668820545077, 0.01238080020993948, -0.007303672377020121, 0.004027164541184902, -0.009522104635834694, 0.008699201978743076, 0.003908487036824226, 0.0026147158350795507, 0.0020694585982710123, -0.0016124453395605087, 0.007766725029796362, 0.009817409329116344, -0.005667057819664478, 0.004660266451537609, 0.0021502699237316847, 0.000018070017176796682, 0.0008361100917682052, 0.007882812060415745, -0.006895683240145445, -0.0029178778640925884, 0.0021520033478736877, 0.0022999723441898823, -0.001387175521813333, -0.005800564773380756, -0.008668343536555767, 0.0004642243729904294, 0.00233558495528996, -0.0024832061026245356, 0.006620669737458229, 0.003104220377281308, 0.004387278109788895, -0.004409933928400278, 0.0005620045121759176, -0.002716880291700363, -0.01279445830732584, 0.011203479021787643, 0.001128440024331212, 0.0006295167258940637, 0.011020228266716003, 0.004018432926386595, -0.011435148306190968, 0.008975415490567684, 0.007940717972815037, -0.0035380979534238577, 0.004897547885775566, 0.006095060147345066, -0.005605516489595175, -0.020907966420054436, -0.004503612406551838, -0.015101960860192776, 0.00480041466653347, -0.0019190326565876603, 0.00516253849491477, -0.004792304243892431, 0.006605695933103561, 0.006898508407175541, -0.014421653933823109, -0.0034013655968010426, -0.008312704041600227, 0.010483814403414726, -0.0023557923268526793, -0.001297009875997901, -0.004574260674417019, -0.00219103810377419, -0.0019388264045119286, -0.001995116239413619, -0.001384964445605874, 0.006031993310898542, 0.0023039360530674458, -0.00852736085653305, 0.00005483915447257459, -0.00289338082075119, 0.000615496130194515, 0.0023342513013631105, -0.010670426301658154, 0.0003191337746102363, 0.004961577244102955, -0.004124038387089968, -0.0039452663622796535, -0.0008072267519310117, -0.0007795671699568629, -0.00523426802828908, -0.010661318898200989, -0.005000341683626175, -0.0046175098977983, -0.005229854956269264, -0.009932384826242924, -0.0022727432660758495, -0.00900599081069231, 0.004009971395134926, -0.008051581680774689, 0.005288794636726379, 0.0035716118291020393, -0.005414519924670458, 0.009804126806557178, -0.0011363571975380182, 0.002119397511705756, 0.006809691898524761, 0.005638079717755318, -0.0007361234747804701, -0.0021954523399472237, -0.01203383132815361, 0.008826245553791523, -0.00788020621985197, 0.0008110376074910164, 0.014548051171004772, 0.003015709575265646, 0.007715280167758465, 0.0005976309184916317, 0.000294816360110417, -0.00022525231179315597, 0.009672105312347412, -0.014611507765948772, 0.004267427138984203, -0.003912019543349743, 0.00008515372610418126, 0.004108161199837923, -0.005335540045052767, -0.00021839396504219621, 0.008738935925066471, 0.004178458359092474, -0.0072592319920659065, -0.0012221337528899312, 0.00034449409577064216, 0.006487658713012934, -0.010894504375755787, -0.0004670050402637571, -0.005093514919281006, -0.0051720463670790195, -0.003488055197522044, -0.0034477938897907734, -0.0018019928829744458, 0.004805721342563629, -0.004175439011305571, 0.006090331822633743, 0.0033006134908646345, -0.006095309741795063, 0.01514040119946003, -0.006189538631588221, -0.005950767081230879, 0.0020507972221821547, 0.0027059537824243307, -0.0011972137726843357, -0.007736449595540762, -0.004831857047975063, 0.003160450141876936, 0.0029145153239369392, -0.0015694426838308573, -0.0077262334525585175, -0.00047944486141204834, -0.0010170511668547988, -0.010990546084940434, 0.0030123291071504354, 0.007236690726131201, 0.0010382740292698145, 0.003647207049652934, -0.0020057603251188993, -0.0100663211196661, -0.016714956611394882, 0.056141212582588196, 0.00040655198972672224, 0.005897970404475927, 0.005850300658494234, -0.0064630769193172455, -0.002687255386263132, 0.00041547813452780247, 0.007077267859131098, -0.006314553786069155, -0.005968987010419369, 0.007520459126681089, -0.002615200122818351, 0.0006787531892769039, -0.0008685700595378876, -0.0019687265157699585, 0.012367651797831059, -0.005623570177704096, -0.01483325194567442, -0.014760610647499561, 0.00731129152700305, -0.0031619626097381115, -0.007464074995368719, 0.008171549998223782, -0.002556716790422797, -0.003825221676379442, 0.003100997768342495, 0.005928176920861006, -0.00001720741238386836, 0.0017609769711270928, -0.006338058039546013, 0.0009403607109561563, -0.000036338540667202324, 0.00348643702454865, 0.001898770104162395, 0.009306981228291988, -0.0035927805583924055, 0.0062823835760355, -0.0051191942766308784, -0.003658681409433484, 0.0002868655719794333, 0.004471685737371445, 0.006673771888017654, -0.000608318776357919, -0.0011468465672805905, 0.0031818824354559183, 0.005235613789409399, -0.0009334818460047245, 0.01162063330411911, 0.0004893630393780768, -0.0030331197194755077, 0.006872291676700115, 0.009237450547516346, -0.002344978041946888, 0.009709714911878109, -0.0004665131855290383, 0.004481885582208633, 0.0028859747108072042, -0.007647410035133362, -0.017567304894328117, -0.0016860619653016329, 0.00755644915625453, 0.0053830835968256, -0.0039700851775705814, 0.002510571852326393, -0.002439631149172783, -0.0028235972858965397, -0.0075185964815318584, -0.008497945964336395, -0.0043248506262898445, 0.0020653922110795975, 0.0057390048168599606, 0.07254771888256073, -0.006921050604432821, -0.002741837175562978, -0.008721727877855301, -0.0008482564589940012, 0.0015049331123009324, 0.0014430924784392118, 0.003316291607916355, -0.0004319934523664415, 0.0034820681903511286, 0.0013702278956770897, -0.008439946919679642, -0.008777879178524017, -0.00015305304259527475, 0.0007041605422273278, -0.0025691892951726913, 0.0009713987237773836, 0.0026978752575814724, -0.006763684097677469, 0.001847018487751484, -0.009590969420969486, -0.003037031041458249, -0.00428047776222229, -0.008224395103752613, -0.002407108200713992, -0.004653911106288433, 0.002939636120572686, 0.0045052808709442616, 0.006430809386074543, -0.0037235054187476635, 0.006945862900465727, 0.0006638802587985992, -0.0007757361745461822, -0.0038818856701254845, -0.000005004904323868686, -0.00405145762488246, 0.0064551993273198605, 0.0010602453257888556, -0.01005975715816021, -0.005382349714636803, -0.0035444670356810093, 0.0022810008376836777, -0.008360521867871284, 0.0035531979519873857, -0.0001041666982928291, 0.007667564786970615, -0.004305697046220303, -0.00047594335046596825, -0.0041281296871602535, 0.0018329439917579293, -0.010508103296160698, 0.005450830329209566, -0.1715141087770462, 0.009098602458834648, 0.0037809275090694427, -0.005601066164672375, -0.002165786223486066, -0.01804582215845585, -0.005701898131519556, 0.0028630797751247883, 0.010398393496870995, 0.00007673734216950834, -0.003125512972474098, 0.002991770626977086, 0.0028882217593491077, 0.006145488005131483, -0.00508778914809227, -0.005871949717402458, 0.0018100239103659987, -0.005263434257358313, -0.0038186998572200537, 0.005043442826718092, 0.0038550887256860733, 0.010959041304886341, 0.0010979976505041122, 0.001108882948756218, -0.001676802639849484, -0.0024547770153731108, 0.0062110344879329205, -0.004936127923429012, 0.005599356722086668, -0.012220428325235844, -0.004330620169639587, -0.004030896816402674, -0.0007078452035784721, 0.003746915142983198, 0.0030130201485008, 0.001902477815747261, 0.006927745416760445, 0.002781324088573456, -0.007093082647770643, 0.007252444047480822, -0.009988599456846714, 0.0247989259660244, 0.006479316856712103, 0.007510442286729813, 0.0028086279053241014, -0.0044532050378620625, -0.0007220014813356102, 0.007922870106995106, 0.00198551919311285, 0.012843064963817596, -0.013346279039978981, -0.004977590870112181, 0.0028207115828990936, 0.016156142577528954, -0.006527903955429792, -0.009293337352573872, -0.006387145724147558, -0.004210699815303087, 0.004626889247447252, 0.007075946778059006, 0.008872683160007, -0.004746478050947189, 0.007403387222439051, -0.004355367738753557, -0.018687335774302483, 0.002445709425956011, -0.00028810702497139573, -0.010435099713504314, -0.0007655968074686825, 0.006292032543569803, 0.010412688367068768, -0.00046351729542948306, 0.005587123800069094, 0.0019567867275327444, 0.007476607337594032, -0.001537532196380198, 0.009999055415391922, -0.00031059482716955245, 0.008599548600614071, -0.006114685907959938, 0.0067694541066884995, -0.009935261681675911, -0.0014729059766978025, 0.003124968148767948, -0.002050940180197358, 0.011777444742619991, 0.004319371655583382, -0.002035226672887802, -0.0011564451269805431, -0.008364430628716946, -0.00028828205540776253, 0.0036753122694790363, 0.0004552308819256723, -0.006106972694396973, 0.0005964971496723592, -0.0031233944464474916, 0.0039854394271969795, 0.006768523249775171, -0.009499270468950272, 0.00782343652099371, 0.004913527052849531, -0.0041669742204248905, -0.0009802118875086308, -0.0077993422746658325, 0.00280345743522048, 0.0038555630017071962, -0.004910217598080635, -0.00520271435379982, 0.0031794302631169558, -0.0027472982183098793, -0.00542053859680891, 0.0054687680676579475, -0.008123702369630337, -0.00903125386685133, -0.00017543217109050602, -0.009274188429117203, -0.0002664908242877573 ]
8aad8dc0d7dead55101c7087ad08700bb763b130
7,900
py
Python
examples/minkunet.py
dendisuhubdy/MinkowskiEngine
a1cdcba68ef925bfefed2fe161f62e1ec78573b9
[ "MIT" ]
1
2019-05-12T00:06:10.000Z
2019-05-12T00:06:10.000Z
examples/minkunet.py
dendisuhubdy/MinkowskiEngine
a1cdcba68ef925bfefed2fe161f62e1ec78573b9
[ "MIT" ]
null
null
null
examples/minkunet.py
dendisuhubdy/MinkowskiEngine
a1cdcba68ef925bfefed2fe161f62e1ec78573b9
[ "MIT" ]
null
null
null
import torch import torch.nn as nn from torch.optim import SGD import MinkowskiEngine as ME from MinkowskiEngine.modules.resnet_block import BasicBlock, Bottleneck from examples.common import data_loader from examples.resnet import ResNetBase class MinkUNetBase(ResNetBase): BLOCK = None PLANES = None DILATIONS = (1, 1, 1, 1, 1, 1, 1, 1) LAYERS = (2, 2, 2, 2, 2, 2, 2, 2) INIT_DIM = 32 OUT_TENSOR_STRIDE = 1 # To use the model, must call initialize_coords before forward pass. # Once data is processed, call clear to reset the model before calling # initialize_coords def __init__(self, in_channels, out_channels, D=3): ResNetBase.__init__(self, in_channels, out_channels, D) def network_initialization(self, in_channels, out_channels, D): # Output of the first conv concated to conv6 self.inplanes = self.INIT_DIM self.conv0p1s1 = ME.MinkowskiConvolution( in_channels, self.inplanes, kernel_size=5, dimension=D) self.bn0 = ME.MinkowskiBatchNorm(self.inplanes) self.conv1p1s2 = ME.MinkowskiConvolution( self.inplanes, self.inplanes, kernel_size=2, stride=2, dimension=D) self.bn1 = ME.MinkowskiBatchNorm(self.inplanes) self.block1 = self._make_layer(self.BLOCK, self.PLANES[0], self.LAYERS[0]) self.conv2p2s2 = ME.MinkowskiConvolution( self.inplanes, self.inplanes, kernel_size=2, stride=2, dimension=D) self.bn2 = ME.MinkowskiBatchNorm(self.inplanes) self.block2 = self._make_layer(self.BLOCK, self.PLANES[1], self.LAYERS[1]) self.conv3p4s2 = ME.MinkowskiConvolution( self.inplanes, self.inplanes, kernel_size=2, stride=2, dimension=D) self.bn3 = ME.MinkowskiBatchNorm(self.inplanes) self.block3 = self._make_layer(self.BLOCK, self.PLANES[2], self.LAYERS[2]) self.conv4p8s2 = ME.MinkowskiConvolution( self.inplanes, self.inplanes, kernel_size=2, stride=2, dimension=D) self.bn4 = ME.MinkowskiBatchNorm(self.inplanes) self.block4 = self._make_layer(self.BLOCK, self.PLANES[3], self.LAYERS[3]) self.convtr4p16s2 = ME.MinkowskiConvolutionTranspose( self.inplanes, self.PLANES[4], kernel_size=2, stride=2, dimension=D) self.bntr4 = ME.MinkowskiBatchNorm(self.PLANES[4]) self.inplanes = self.PLANES[4] + self.PLANES[2] * self.BLOCK.expansion self.block5 = self._make_layer(self.BLOCK, self.PLANES[4], self.LAYERS[4]) self.convtr5p8s2 = ME.MinkowskiConvolutionTranspose( self.inplanes, self.PLANES[5], kernel_size=2, stride=2, dimension=D) self.bntr5 = ME.MinkowskiBatchNorm(self.PLANES[5]) self.inplanes = self.PLANES[5] + self.PLANES[1] * self.BLOCK.expansion self.block6 = self._make_layer(self.BLOCK, self.PLANES[5], self.LAYERS[5]) self.convtr6p4s2 = ME.MinkowskiConvolutionTranspose( self.inplanes, self.PLANES[6], kernel_size=2, stride=2, dimension=D) self.bntr6 = ME.MinkowskiBatchNorm(self.PLANES[6]) self.inplanes = self.PLANES[6] + self.PLANES[0] * self.BLOCK.expansion self.block7 = self._make_layer(self.BLOCK, self.PLANES[6], self.LAYERS[6]) self.convtr7p2s2 = ME.MinkowskiConvolutionTranspose( self.inplanes, self.PLANES[7], kernel_size=2, stride=2, dimension=D) self.bntr7 = ME.MinkowskiBatchNorm(self.PLANES[7]) self.inplanes = self.PLANES[7] + self.INIT_DIM self.block8 = self._make_layer(self.BLOCK, self.PLANES[7], self.LAYERS[7]) self.final = ME.MinkowskiConvolution( self.PLANES[7], out_channels, kernel_size=1, has_bias=True, dimension=D) self.relu = ME.MinkowskiReLU(inplace=True) def forward(self, x): out = self.conv0p1s1(x) out = self.bn0(out) out_p1 = self.relu(out) out = self.conv1p1s2(out_p1) out = self.bn1(out) out = self.relu(out) out_b1p2 = self.block1(out) out = self.conv2p2s2(out_b1p2) out = self.bn2(out) out = self.relu(out) out_b2p4 = self.block2(out) out = self.conv3p4s2(out_b2p4) out = self.bn3(out) out = self.relu(out) out_b3p8 = self.block3(out) # tensor_stride=16 out = self.conv4p8s2(out_b3p8) out = self.bn4(out) out = self.relu(out) out = self.block4(out) # tensor_stride=8 out = self.convtr4p16s2(out) out = self.bntr4(out) out = self.relu(out) out = ME.cat((out, out_b3p8)) out = self.block5(out) # tensor_stride=4 out = self.convtr5p8s2(out) out = self.bntr5(out) out = self.relu(out) out = ME.cat((out, out_b2p4)) out = self.block6(out) # tensor_stride=2 out = self.convtr6p4s2(out) out = self.bntr6(out) out = self.relu(out) out = ME.cat((out, out_b1p2)) out = self.block7(out) # tensor_stride=1 out = self.convtr7p2s2(out) out = self.bntr7(out) out = self.relu(out) out = ME.cat((out, out_p1)) out = self.block8(out) return self.final(out) class MinkUNet14(MinkUNetBase): BLOCK = BasicBlock LAYERS = (1, 1, 1, 1, 1, 1, 1, 1) class MinkUNet18(MinkUNetBase): BLOCK = BasicBlock LAYERS = (2, 2, 2, 2, 2, 2, 2, 2) class MinkUNet34(MinkUNetBase): BLOCK = BasicBlock LAYERS = (2, 3, 4, 6, 2, 2, 2, 2) class MinkUNet50(MinkUNetBase): BLOCK = Bottleneck LAYERS = (2, 3, 4, 6, 2, 2, 2, 2) class MinkUNet101(MinkUNetBase): BLOCK = Bottleneck LAYERS = (2, 3, 4, 23, 2, 2, 2, 2) class MinkUNet14A(MinkUNet14): PLANES = (32, 64, 128, 256, 128, 128, 96, 96) class MinkUNet14B(MinkUNet14): PLANES = (32, 64, 128, 256, 128, 128, 128, 128) class MinkUNet14C(MinkUNet14): PLANES = (32, 64, 128, 256, 192, 192, 128, 128) class MinkUNet14D(MinkUNet14): PLANES = (32, 64, 128, 256, 384, 384, 384, 384) class MinkUNet18A(MinkUNet18): PLANES = (32, 64, 128, 256, 128, 128, 96, 96) class MinkUNet18B(MinkUNet18): PLANES = (32, 64, 128, 256, 128, 128, 128, 128) class MinkUNet18D(MinkUNet18): PLANES = (32, 64, 128, 256, 384, 384, 384, 384) class MinkUNet34A(MinkUNet34): PLANES = (32, 64, 128, 256, 256, 128, 64, 64) class MinkUNet34B(MinkUNet34): PLANES = (32, 64, 128, 256, 256, 128, 64, 32) class MinkUNet34C(MinkUNet34): PLANES = (32, 64, 128, 256, 256, 128, 96, 96) if __name__ == '__main__': # loss and network criterion = nn.CrossEntropyLoss() net = MinkUNet14A(in_channels=3, out_channels=5, D=2) print(net) # a data loader must return a tuple of coords, features, and labels. device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') net = net.to(device) optimizer = SGD(net.parameters(), lr=1e-2) for i in range(10): optimizer.zero_grad() # Get new data coords, feat, label = data_loader(is_classification=False) input = ME.SparseTensor(feat, coords=coords).to(device) label = label.to(device) # Forward output = net(input) # Loss loss = criterion(output.F, label) print('Iteration: ', i, ', Loss: ', loss.item()) # Gradient loss.backward() optimizer.step() # Saving and loading a network torch.save(net.state_dict(), 'test.pth') net.load_state_dict(torch.load('test.pth'))
30.501931
80
0.603291
1
2.3076
[ 0.025120779871940613, 0.021294226869940758, -0.018584096804261208, 0.06634066998958588, -0.0007945432444103062, -0.030467426404356956, 0.025341803207993507, 0.009781619533896446, -0.0010428460082039237, -0.01706833764910698, 0.021221965551376343, -0.031020428985357285, 0.05025574564933777, -0.023545734584331512, 0.0018755410565063357, -0.01791938580572605, 0.055240288376808167, -0.0007304459577426314, -0.011830082163214684, -0.01307754311710596, -0.013623599894344807, -0.003319469979032874, 0.02185843326151371, -0.017274318262934685, -0.01747358962893486, 0.05978013947606087, -0.017317041754722595, -0.015941066667437553, -0.03183407336473465, -0.02956891804933548, -0.01932419277727604, -0.019097214564681053, -0.03829919919371605, -0.050823748111724854, 0.01843753084540367, 0.03396789729595184, -0.013168812729418278, -0.04137958213686943, -0.030331123620271683, -0.005227960646152496, -0.0032581507693976164, 0.026555538177490234, -0.0025165253318846226, -0.009925342164933681, 0.058380141854286194, -0.047622088342905045, -0.018259959295392036, -0.01250209379941225, -0.027414802461862564, 0.008175931870937347, -0.0077624195255339146, 0.026217764243483543, -0.025003056973218918, 0.06295834481716156, -0.035547588020563126, -0.05980486050248146, 0.04661106690764427, 0.014678680337965488, -0.028543910011649132, -0.014245675876736641, 0.0048913354985415936, 0.041730109602212906, -0.005267446395009756, -0.0197453573346138, 0.012949039228260517, -0.0005262034246698022, -0.03109646588563919, -0.03036784566938877, -0.005839189048856497, 0.05372714251279831, 0.025320127606391907, 0.02775692753493786, 0.01879511959850788, 0.03809745982289314, 0.008901302702724934, 0.03152724355459213, -0.027769288048148155, -0.061824169009923935, -0.019801881164312363, -0.028570430353283882, -0.007547290064394474, 0.025453055277466774, -0.011678364127874374, -0.013697466813027859, 0.051419224590063095, 0.015653902664780617, 0.04489205405116081, -0.055773865431547165, 0.004124642349779606, -0.024151328951120377, -0.027103615924715996, 0.032161906361579895, -0.020990431308746338, 0.027050845324993134, -0.046822115778923035, -0.005901132710278034, 0.02852270007133484, 0.01670962944626808, 0.006946914363652468, 0.0007927504484541714, 0.01217376533895731, 0.04228264465928078, 0.02559312991797924, -0.02011767029762268, 0.011779510416090488, -0.061384353786706924, -0.04037247970700264, -0.002080243546515703, 0.02474272809922695, -0.0169258713722229, -0.012461469508707523, -0.010764790698885918, -0.03280819207429886, 0.002796874614432454, -0.037386927753686905, -0.011462696827948093, -0.01402928214520216, 0.042260825634002686, 0.000025121207727352157, 0.04529835283756256, 0.03754230588674545, -0.022834576666355133, -0.035525452345609665, 0.04646766930818558, 0.02975580096244812, 0.058082569390535355, 0.009208442643284798, -0.010049351491034031, -0.024325020611286163, 0.003050335217267275, 0.014801458455622196, -0.009304823353886604, -0.027513893321156502, -0.013799558393657207, -0.04557513818144798, -0.033025436103343964, 0.05115409195423126, 0.006320694461464882, -0.08648397028446198, 0.02607928402721882, 0.01774662174284458, 0.030074603855609894, 0.003106244606897235, 0.09330260008573532, -0.018434789031744003, -0.07466399669647217, 0.014003275893628597, 0.04887055233120918, -0.023382650688290596, -0.015605454333126545, 0.03866547718644142, -0.009951681829988956, 0.019088435918092728, -0.013793176040053368, -0.00992970447987318, 0.014348078519105911, -0.027218446135520935, -0.011080523021519184, -0.018789120018482208, 0.004968990571796894, 0.003087641205638647, 0.014379952102899551, 0.01347955223172903, 0.008067715913057327, -0.004137285519391298, 0.10474380105733871, 0.018816642463207245, -0.009491411037743092, 0.0001419825857738033, -0.011146992444992065, 0.005302886478602886, 0.030248872935771942, -0.030792003497481346, -0.01665317453444004, -0.048495516180992126, -0.021795108914375305, 0.057064589112997055, 0.022122301161289215, 0.021140744909644127, -0.07108607143163681, 0.017861131578683853, -0.019763708114624023, 0.019519442692399025, 0.039305806159973145, -0.038712356239557266, 0.0301152765750885, -0.025784816592931747, -0.008771528489887714, 0.046746838837862015, -0.002477405359968543, -0.03735953941941261, 0.0018745710840448737, 0.08902695029973984, 0.0033093439415097237, -0.0019985793624073267, -0.014154014177620411, -0.039643868803977966, 0.014459595084190369, 0.009732769802212715, -0.0077918535098433495, -0.019609253853559494, -0.016926568001508713, 0.009767727926373482, 0.04276508837938309, -0.01121657807379961, 0.011731225065886974, -0.5274896025657654, 0.0049840533174574375, 0.05563652887940407, -0.053279705345630646, 0.030060231685638428, 0.030067993327975273, -0.053139928728342056, 0.03837205842137337, 0.026074489578604698, 0.03366775065660477, 0.025241591036319733, 0.0013466824311763048, -0.0034789012279361486, 0.001794415875338018, -0.018290290609002113, -0.016048844903707504, -0.0028265658766031265, 0.0383913554251194, 0.06633058935403824, 0.03347647562623024, -0.0170342568308115, -0.038314517587423325, -0.006538397632539272, 0.01907593011856079, 0.007861360907554626, -0.0518660768866539, 0.03170763701200485, 0.028928857296705246, -0.058907318860292435, -0.03973563015460968, -0.044920019805431366, -0.01727427914738655, 0.07245764881372452, -0.02033323422074318, -0.010249733924865723, 0.014555749483406544, 0.045722853392362595, -0.03911455348134041, -0.07002337276935577, -0.034285277128219604, 0.006566181313246489, 0.00845313724130392, -0.0005297681200318038, -0.0640719011425972, 0.01032165065407753, 0.0782192274928093, 0.11040648818016052, -0.039295267313718796, 0.046784739941358566, -0.01122305542230606, -0.025209268555045128, 0.004155756905674934, 0.049085404723882675, -0.011012540198862553, 0.008100160397589207, 0.006945445667952299, -0.012069577351212502, -0.034701742231845856, 0.023578878492116928, -0.011402887292206287, 0.008912291377782822, -0.06651052087545395, -0.03795263171195984, -0.021153084933757782, 0.03522929921746254, 0.005460574757307768, 0.010651091113686562, -0.003435750026255846, -0.04892883822321892, -0.03389199450612068, 0.0299412589520216, -0.06070227175951004, -0.0661647766828537, -0.0361163467168808, 0.05164601281285286, -0.01956159807741642, 0.02612258866429329, -0.030450422316789627, -0.04316176474094391, -0.036423955112695694, 0.06676539033651352, 0.020812051370739937, -0.0009094839333556592, 0.0003984424693044275, -0.018868684768676758, -0.029210586100816727, -0.021226096898317337, 0.03352988511323929, 0.018582206219434738, 0.00648087402805686, 0.03531031310558319, 0.04317522048950195, 0.04225269332528114, 0.033222343772649765, 0.02139417827129364, 0.0073746866546571255, 0.025458650663495064, -0.0077385981567204, -0.009874417446553707, 0.010946127586066723, -0.010947289876639843, -0.020532337948679924, 0.024752121418714523, -0.024365151301026344, -0.04557564854621887, 0.0417952686548233, -0.011019576340913773, 0.004005815368145704, -0.08597956597805023, 0.03743037208914757, -0.04621170833706856, 0.001884725410491228, -0.030004460364580154, -0.010855386964976788, -0.003380740759894252, -0.01753244735300541, -0.006209606304764748, -0.02332899533212185, 0.02612643875181675, -0.006642487831413746, -0.019854143261909485, 0.009522151201963425, -0.0039337025955319405, 0.0008251190884038806, -0.04907277598977089, 0.047430507838726044, -0.007609538733959198, -0.015882879495620728, 0.005122730974107981, 0.002205869648605585, -0.015023378655314445, 0.017635824158787727, 0.014130408875644207, -0.04503656178712845, 0.014911572448909283, 0.010348932817578316, -0.00794313382357359, 0.022016622126102448, 0.005381172522902489, 0.00924619473516941, 0.009174511767923832, 0.017465762794017792, -0.009695420041680336, -0.029995903372764587, 0.011542325839400291, -0.008671377785503864, 0.03342970460653305, -0.004070955328643322, -0.11586110293865204, -0.017246587201952934, 0.008349153213202953, 0.04087395593523979, 0.013605485670268536, 0.010790328495204449, 0.04390919208526611, 0.021566297858953476, -0.05621723830699921, -0.004075990058481693, -0.008252040483057499, 0.023160111159086227, 0.02661225199699402, 0.07237519323825836, -0.03413282334804535, 0.0012780502438545227, -0.010672766715288162, -0.0095937205478549, 0.018394775688648224, 0.010145180858671665, 0.008344730362296104, -0.03441089391708374, 0.0565762035548687, -0.06305212527513504, 0.005146114155650139, -0.016700932756066322, 0.04648942872881889, -0.027322283014655113, 0.008890027180314064, -0.04229029268026352, 0.024154139682650566, 0.0011325639206916094, -0.0027462185826152563, 0.015446096658706665, -0.01475167740136385, -0.012970395386219025, 0.030593257397413254, 0.02148093469440937, -0.008406910113990307, -0.029416687786579132, -0.0186239555478096, 0.029134413227438927, -0.004858142696321011, 0.026048021391034126, -0.04359928146004677, -0.0009599160403013229, -0.025766601786017418, -0.030462628230452538, -0.013719241134822369, 0.0037955408915877342, 0.040229957550764084, 0.0318417027592659, -0.013084138743579388, 0.003993210848420858, -0.011113510467112064, 0.010242171585559845, -0.024864040315151215, 0.06569380313158035, -0.01662307418882847, 0.04792648181319237, 0.001265969593077898, -0.02057124860584736, 0.02911965548992157, -0.016004778444767, 0.0073296623304486275, -0.009730727411806583, -0.008489171974360943, 0.06012990325689316, -0.036557938903570175, -0.03367225080728531, 0.03247315436601639, 0.007881304249167442, -0.03973852097988129, -0.019047634676098824, 0.050337113440036774, -0.04430012404918671, -0.012869971804320812, 0.032008178532123566, 0.00031005224445834756, 0.011198089458048344, -0.021486103534698486, -0.05952064320445061, 0.011932235211133957, 0.0481477715075016, 0.015353807248175144, -0.028048815205693245, 0.022733425721526146, 0.006907044444233179, 0.0015558790182694793, -0.012040150351822376, 0.012587597593665123, -0.013205567374825478, 0.012768035754561424, -0.01348472572863102, -0.031175164505839348, 0.019452573731541634, 0.020564710721373558, 0.01814773492515087, -0.02260328084230423, -0.05676767975091934, -0.014611877501010895, -0.01050496008247137, -0.018377503380179405, -0.044455163180828094, -0.015101156197488308, 0.012300694361329079, -0.04224790260195732, 0.010692782700061798, -0.002718356903642416, 0.012008014135062695, -0.014698169194161892, 0.00515059195458889, 0.002913068514317274, -0.022252006456255913, -0.007852569222450256, 0.020111525431275368, -0.022587571293115616, 0.02928251400589943, 0.027185654267668724, -0.035731878131628036, -0.005973638966679573, 0.0424044206738472, 0.006848969962447882, 0.003937623929232359, -0.014038109220564365, -0.0048524984158575535, 0.007107661571353674, -0.0005169395008124411, -0.03898894414305687, -0.019751261919736862, 0.04676954075694084, -0.025925518944859505, 0.018047558143734932, 0.007176846265792847, 0.003808743553236127, 0.01868964359164238, -0.0312091913074255, -0.011706143617630005, 0.00934513844549656, 0.012014337815344334, -0.051106344908475876, -0.050016049295663834, -0.03833845630288124, 0.013886827044188976, 0.002934809774160385, -0.002073942916467786, -0.013541070744395256, 0.0353839248418808, 0.027936717495322227, -0.0412556491792202, 0.012010662816464901, -0.022320693358778954, -0.0013432588893920183, -0.03588934987783432, -0.020828206092119217, 0.0317845493555069, -0.02343256026506424, -0.049829233437776566, -0.011090441606938839, -0.010095273144543171, 0.013087835162878036, 0.006861392874270678, 0.029828539118170738, 0.012313764542341232, 0.01562377531081438, 0.03258015960454941, -0.036450766026973724, 0.02753628045320511, 0.012179242447018623, -0.0007525145192630589, 0.03731052204966545, -0.044310614466667175, -0.028376104310154915, 0.022740349173545837, -0.01059628650546074, 0.007266712840646505, 0.008295338600873947, -0.06794453412294388, -0.035534098744392395, -0.05313174054026604, 0.030835939571261406, 0.05304636433720589, 0.03731045871973038, -0.061623916029930115, 0.05115915462374687, -0.019690994173288345, 0.03814767301082611, 0.03564911335706711, 0.010870317928493023, 0.03575150668621063, -0.005731204058974981, 0.0004629256727639586, -0.05578391253948212, -0.04495180770754814, -0.02780640311539173, -0.015141579322516918, 0.04602326080203056, -0.018622849136590958, -0.042085886001586914, 0.052415631711483, 0.0334455743432045, -0.011285393498837948, -0.01516785193234682, 0.013149600476026535, -0.011235246434807777, -0.004133947659283876, -0.011282053776085377, 0.042361386120319366, 0.005211899988353252, 0.02113797329366207, -0.0005225490895099938, 0.015675334259867668, 0.04500444233417511, -0.012758174911141396, 0.01728164404630661, -0.02479761280119419, -0.029452219605445862, -0.031148914247751236, -0.009946268051862717, 0.004936261102557182, -0.006434513255953789, -0.046711307018995285, -0.028587691485881805, -0.004013826139271259, -0.008365737274289131, 0.026715891435742378, 0.011761295609176159, -0.001046717748977244, -0.004776901565492153, -0.009908599779009819, -0.004181473515927792, -0.01941537857055664, 0.011836516670882702, -0.03213261067867279, 0.015486231073737144, -0.018305042758584023, -0.013965826481580734, -0.030132006853818893, -0.014253545552492142, -0.019535290077328682, -0.03476570174098015, -0.02493223361670971, 0.019798453897237778, -0.033820740878582, -0.01746862381696701, -0.013169732876121998, 0.012233776971697807, -0.04025724157691002, 0.006887874100357294, -0.018034808337688446, 0.026993267238140106, 0.009043700061738491, 0.030089445412158966, 0.06135612726211548, -0.010916895233094692, -0.008114350959658623, 0.04302459955215454, -0.022312920540571213, 0.052298516035079956, -0.01931142807006836, 0.025103125721216202, 0.001524660037830472, -0.00006460883741965517, -0.001117250183597207, -0.06840895116329193, -0.001461006118915975, 0.07311216741800308, 0.044233519583940506, -0.03245241567492485, 0.02455805242061615, -0.003420818131417036, -0.04681140184402466, 0.010171790607273579, -0.01463694404810667, -0.005934839602559805, 0.006010646466165781, -0.032512251287698746, -0.022073572501540184, -0.030249448493123055, 0.02403106912970543, -0.012889837846159935, 0.02146030031144619, 0.04155993089079857, 0.03882746025919914, -0.04691704735159874, -0.016448574140667915, 0.017206646502017975, -0.02758810855448246, 0.033563241362571716, -0.01255914755165577, -0.011305173859000206, 0.01905066892504692, 0.0006538091693073511, -0.06540495902299881, 0.005112899001687765, 0.004733807407319546, -0.009161916561424732, -0.16990897059440613, 0.016494685783982277, 0.017911147326231003, -0.01652771234512329, -0.022609001025557518, -0.04531021788716316, 0.02298235334455967, -0.03303895145654678, 0.027279049158096313, -0.002295100362971425, 0.03852913901209831, -0.0007561924285255373, 0.01648324355483055, 0.010324932634830475, 0.008735543116927147, 0.03842935338616371, -0.0018474624957889318, -0.050876978784799576, -0.018449533730745316, -0.025095902383327484, 0.028607431799173355, 0.07663337886333466, 0.01569792814552784, 0.0005328292027115822, -0.03541354462504387, -0.02198912762105465, 0.028696972876787186, 0.042169515043497086, -0.028782600536942482, 0.0030690617859363556, -0.01860164664685726, 0.022112630307674408, 0.06675243377685547, 0.024425314739346504, 0.010119056329131126, -0.003961240407079458, 0.019169732928276062, 0.06568072736263275, 0.02823369763791561, 0.014671103097498417, -0.025101037696003914, -0.04197630658745766, -0.0055712927132844925, 0.0320018045604229, -0.0022374403197318316, -0.00845706183463335, -0.015596959739923477, -0.0114191435277462, -0.00912464689463377, 0.03292519599199295, 0.010436227545142174, 0.03182796761393547, -0.021214429289102554, 0.004746928811073303, -0.017360294237732887, -0.01084115356206894, 0.027048667892813683, 0.01616189442574978, 0.004122598096728325, -0.02864820696413517, 0.0507306344807148, 0.009822111576795578, 0.038429953157901764, -0.01061012502759695, 0.004633529577404261, 0.03578898310661316, -0.044963665306568146, 0.0020358646288514137, -0.01614147424697876, -0.021938301622867584, 0.007430675905197859, -0.0334993340075016, -0.010922979563474655, 0.029338812455534935, 0.03259114548563957, 0.02633976936340332, -0.05230389162898064, 0.009739123284816742, 0.008948511444032192, -0.019234323874115944, 0.02194441854953766, -0.006899164989590645, -0.013954167254269123, -0.008334366604685783, -0.007809753995388746, -0.0016095020109787583, 0.011017228476703167, 0.008812876418232918, -0.0033777260687202215, 0.03647486865520477, -0.053150177001953125, 0.044472936540842056, 0.020035112276673317, -0.004461892414838076, -0.031124824658036232, 0.014624180272221565, 0.041709866374731064, 0.007068930193781853, 0.013246450573205948, 0.033507246524095535, -0.034435469657182693, 0.03987514600157738, -0.02108149230480194, 0.03347181901335716, -0.011905972845852375, 0.01647828333079815, -0.024395160377025604, 0.025864223018288612, 0.06507277488708496, -0.009095338173210621, -0.03342368081212044, 0.0004780625458806753, 0.013268597424030304, -0.026137148961424828, -0.034168556332588196, 0.0063447654247283936, 0.003465740941464901 ]
8aad8de20813d57dc973493fe2b63ad495089392
549
py
Python
setup.py
swfrench/nginx-access-tailer
5e060396ca749935c622e8e9c50b659b39e3675b
[ "BSD-3-Clause" ]
null
null
null
setup.py
swfrench/nginx-access-tailer
5e060396ca749935c622e8e9c50b659b39e3675b
[ "BSD-3-Clause" ]
null
null
null
setup.py
swfrench/nginx-access-tailer
5e060396ca749935c622e8e9c50b659b39e3675b
[ "BSD-3-Clause" ]
null
null
null
"""TODO.""" from setuptools import setup setup( name='nginx-access-tailer', version='0.1', author='swfrench', url='https://github.com/swfrench/nginx-tailer', packages=['nginx_access_tailer',], license='BSD three-clause license', entry_points={ 'console_scripts': ['nginx-access-tailer = nginx_access_tailer.__main__:main'], }, install_requires=[ 'python-gflags >= 3.1.1', 'google-cloud-monitoring >= 0.25.0', ], test_suite='nose.collector', tests_require=['nose', 'mock'], )
24.954545
87
0.626594
1
0.8346
[ 0.0021621398627758026, 0.02388477697968483, 0.006765005178749561, 0.00008308353426400572, 0.004979334771633148, -0.001189792063087225, -0.010359703563153744, 0.0031939640175551176, -0.009984513744711876, 0.0016003645723685622, 0.0018476358382031322, 0.004696849267929792, 0.00470968522131443, -0.0177442729473114, 0.002786704571917653, 0.016258444637060165, -0.055496156215667725, 0.0015968403313308954, -0.0029902001842856407, 0.002639013109728694, -0.007514055352658033, 0.011092190630733967, 0.008072204887866974, 0.007911351509392262, 0.006065415684133768, 0.0012584659270942211, 0.00839323177933693, 0.0032834543380886316, -0.008942531421780586, -0.004959542769938707, 0.000579537358134985, -0.0024356150534003973, -0.004361889790743589, -0.008095824159681797, 0.00774436304345727, -0.0018587290542200208, -0.0011173321399837732, -0.018552133813500404, 0.012559136375784874, -0.0061425804160535336, -0.008374757133424282, -0.01866120472550392, 0.0008242090116254985, 0.003953719511628151, -0.009328504092991352, 0.002648531924933195, -0.003706286894157529, 0.004816450644284487, -0.01140000019222498, 0.006737071089446545, -0.009997711516916752, 0.005580337718129158, 0.014230407774448395, 0.0035753853153437376, -0.00662372587248683, -0.007137335371226072, 0.010993381030857563, 0.0025407765060663223, -0.01187311951071024, 0.00046616990584880114, -0.0021907149348407984, -0.003084091702476144, 0.006659497506916523, 0.005383475683629513, -0.018067216500639915, -0.007301610428839922, -0.0025977524928748608, 0.0016676739323884249, 0.0008390991715714335, 0.006038087885826826, 0.0006325892172753811, -0.0023169727064669132, 0.007436440791934729, 0.0029092314653098583, 0.006140519864857197, -0.0023516935762017965, -0.0006503041367977858, 0.004487134981900454, 0.009972848929464817, 0.0043730707839131355, 0.0034371651709079742, -0.008393052965402603, 0.007690649013966322, 0.013036326505243778, 0.013514679856598377, 0.011991842649877071, 0.016864152625203133, -0.010070569813251495, 0.044862959533929825, 0.00412348099052906, -0.009916755370795727, 0.0009836391545832157, -0.008346905931830406, -0.001112180994823575, -0.0023163927253335714, -0.028540827333927155, 0.002933988580480218, -0.0029017189517617226, -0.0005023058620281518, 0.004190204199403524, -0.0042320070788264275, 0.002618015743792057, -0.0016819605370983481, -0.000766096927691251, -0.011358007788658142, 0.01256574783474207, -0.008415655232965946, -0.0012925041373819113, 0.007609403692185879, 0.002078983001410961, -0.010904496535658836, -0.0002693649148568511, 0.0013310839422047138, -0.014724722132086754, 0.004294457379728556, 0.0013460292248055339, -0.005900766234844923, 0.05460549145936966, -0.002366127446293831, 0.0029706833884119987, -0.0034885560162365437, 0.0006577961030416191, -0.0006522576441057026, 0.0071342322044074535, 0.008923940360546112, -0.004747419152408838, 0.012999845668673515, 0.007497819140553474, 0.002581099746748805, 0.009446432814002037, -0.0011742368806153536, 0.005111451260745525, -0.004450839012861252, -0.001851897919550538, 0.0012983648339286447, -0.006310610566288233, 0.00923883356153965, -0.0015113891568034887, -0.005122714675962925, -0.0009379032999277115, -0.0017605858156457543, -0.011639093980193138, 0.002020900370553136, -0.004117303062230349, 0.002074706833809614, -0.012406300753355026, -0.006763026583939791, -0.0006322829867713153, -0.005191597621887922, 0.0029238977003842592, 0.008767418563365936, 0.0035594748333096504, 0.0023517871741205454, -0.006676605436950922, -0.00861616525799036, -0.002169063314795494, -0.0027912643272429705, 0.0020592708606272936, 0.007569862995296717, 0.00401486549526453, -0.009354851208627224, -0.0015738137299194932, 0.004812478553503752, 0.004978365730494261, -0.0012777869123965502, 0.001776987686753273, -0.007191121578216553, 0.007907308638095856, 0.001621261821128428, 0.003724845824763179, 0.010444756597280502, -0.004548725672066212, -0.0006026157643646002, 0.001637003617361188, 0.0039376006461679935, 0.0027518540155142546, 0.005678948014974594, 0.00957492645829916, -0.0029578255489468575, -0.0027226628735661507, 0.0025720882695168257, 0.00525351008400321, 0.009396838024258614, 0.01035815104842186, -0.002382619073614478, 0.0018653511069715023, -0.0029111201874911785, -0.0016027027741074562, 0.00641265045851469, -0.004843282047659159, 0.005393664352595806, 0.0028445313218981028, -0.015426021069288254, -0.007405801676213741, -0.0005650647799484432, -0.010199444368481636, 0.0007829540991224349, 0.014347653836011887, 0.012192371301352978, -0.0017091495683416724, 0.0050377678126096725, -0.01064274087548256, 0.0024904576130211353, 0.007103560492396355, -0.00032004236709326506, -0.014288377948105335, -0.9561482667922974, 0.0050947340205311775, 0.0005963033763691783, 0.0003896565467584878, 0.003861376317217946, 0.0002404494007350877, 0.0013386462815105915, 0.002858003368601203, 0.014166362583637238, -0.007037057541310787, -0.005228809081017971, -0.00924736075103283, -0.01075776293873787, 0.0016560727963224053, -0.00876079872250557, -0.002014363883063197, -0.004710296634584665, -0.005744876340031624, -0.0015578826423734426, -0.005982276517897844, -0.003352658124640584, 0.008321751840412617, 0.00048290754784829915, 0.004630004987120628, 0.0037573997396975756, 0.0031263884156942368, -0.004391157999634743, -0.0006137090385891497, 0.00010613752237986773, -0.0028378546703606844, -0.0066754198633134365, -0.020000094547867775, -0.005388119723647833, -0.0013352683745324612, 0.011579612269997597, 0.0005161181325092912, 0.009795078076422215, -0.00013231509365141392, 0.002154086483642459, -0.007711230777204037, 0.005037285387516022, 0.0006870569777674973, 0.003609101055189967, -0.03034958243370056, 0.00024157368170563132, -0.0009511946118436754, -0.009873044677078724, 0.007932079955935478, -0.0007632647757418454, -0.0020477939397096634, -0.0024828987661749125, -0.006735341623425484, 0.009826838970184326, -0.007659596391022205, 0.007636208087205887, -0.004714847542345524, -0.006156482733786106, -0.0033042426221072674, -0.009347350336611271, 0.004340246319770813, 0.0050086090341210365, -0.004414415452629328, -0.005076415836811066, -0.002680551027879119, 0.0005045199650339782, 0.0031181294471025467, -0.0002637854777276516, -0.01688169687986374, -0.006685576867312193, -0.00537519808858633, 0.00518369534984231, -0.004256121348589659, -0.004561295732855797, 0.006043923553079367, -0.009516294114291668, 0.006374401040375233, 0.0011820978252217174, 0.0016396321589127183, -0.008820952847599983, 0.004113762639462948, -0.008599820546805859, -0.007987230084836483, 0.0021184843499213457, -0.005349158309400082, -0.0049025509506464005, 0.0011514427606016397, 0.0031207192223519087, 0.005342375952750444, -0.005237187258899212, 0.002379615092650056, 0.012734931893646717, -0.005464871414005756, -0.009180749766528606, 0.0057039689272642136, 0.006815292406827211, -0.00021481789008248597, -0.00008751508721616119, 0.0003200621868018061, 0.01068665087223053, 0.007641225587576628, 0.004355095326900482, 0.004807388409972191, 0.0003702745889313519, 0.012065751478075981, -0.0005353098385967314, 0.002585908630862832, -0.001271571614779532, -0.0021424423903226852, -0.003931707236915827, 0.0006557409069500864, -0.002101452322676778, -0.0028174833860248327, -0.013380824588239193, -0.008644183166325092, -0.0033349525183439255, 0.000899589853361249, 0.001681636436842382, -0.0021457825787365437, -0.00033109806827269495, 0.003806790104135871, 0.010785037651658058, 0.0003100176982115954, -0.003942356910556555, 0.0019177017966285348, 0.0040969932451844215, -0.0071737333200871944, 0.014638539403676987, -0.01202754769474268, 0.004658370278775692, -0.0029023028910160065, -0.01788998208940029, 0.007942935451865196, 0.006831114646047354, -0.00747476052492857, 0.004431523848325014, 0.0027572193648666143, 0.001642820774577558, -0.0009565307991579175, -0.004490272141993046, -0.0036861232947558165, -0.01573927327990532, -0.0008436670759692788, 0.020535852760076523, 0.0015284288674592972, 0.01039431057870388, 0.013288437388837337, -0.0020057568326592445, 0.00011364250531187281, 0.004463414661586285, -0.002589253941550851, 0.014689130708575249, -0.008023574948310852, -0.0000947749795159325, 0.0012854671804234385, -0.0066712661646306515, 0.00005408697325037792, 0.0051411911845207214, 0.0045951614156365395, -0.0007718688575550914, 0.0016400362364947796, -0.007299487479031086, -0.005864206701517105, -0.018070312216877937, -0.0009225408430211246, 0.00981951504945755, -0.0048717171885073185, 0.005777468904852867, -0.011710729449987411, 0.006565803196281195, 0.0058941468596458435, 0.004171471577137709, 0.0019033801509067416, -0.0004047017719130963, 0.008667893707752228, 0.010591669008135796, -0.006256697699427605, 0.0004584792477544397, 0.0018468820489943027, -0.0011364705860614777, 0.002011311473324895, 0.008621668443083763, -0.010137060657143593, -0.005317343398928642, 0.003054901957511902, 0.001719034742563963, 0.0009014680981636047, -0.004699287470430136, -0.008304468356072903, -0.003729527350515127, 0.003082846524193883, -0.0057439436204731464, 0.00560618843883276, 0.0016068388940766454, 0.003314824076369405, -0.0073385401628911495, 0.001982669346034527, -0.00366724980995059, -0.010628187097609043, 0.011357506737112999, -0.0029494748450815678, 0.0006440854049287736, 0.011349250562489033, 0.005270802415907383, -0.0127848656848073, 0.006009750068187714, 0.009368347004055977, -0.0035156954545527697, 0.0017300230683758855, 0.0064824484288692474, -0.005494777578860521, -0.023385824635624886, 0.0001435518788639456, -0.013779249042272568, 0.006515660788863897, -0.003505912609398365, 0.003352292813360691, -0.005977709777653217, 0.006766287609934807, 0.007483368739485741, -0.012619778513908386, -0.00374980759806931, -0.010085595771670341, 0.009635383263230324, -0.0036411136388778687, -0.00042540853610262275, -0.003156703896820545, -0.003328249789774418, -0.00520068546757102, -0.00042282542563043535, -0.0018452347721904516, 0.004576673731207848, 0.0019645621068775654, -0.004046502523124218, 0.003190085059031844, -0.002130048116669059, -0.00157461897470057, 0.0013319620629772544, -0.009471998549997807, 0.003528993111103773, 0.006928442511707544, -0.002730155596509576, -0.005464123096317053, -0.0011478972155600786, -0.0005503155407495797, -0.005126043688505888, -0.010592706501483917, -0.0011995969107374549, -0.0024141932372003794, -0.0024322974495589733, -0.009487106464803219, -0.0015310872113332152, -0.007915160618722439, 0.006999846547842026, -0.008161562494933605, 0.00932704284787178, 0.002566710812970996, -0.0035202600993216038, 0.0058358823880553246, -0.0036879039835184813, 0.003458089428022504, 0.004170442931354046, 0.010360268875956535, -0.0003827830369118601, -0.006299730855971575, -0.01152783539146185, 0.011047128587961197, -0.008602235466241837, 0.0009724985575303435, 0.013261524960398674, 0.0046682944521307945, 0.01069397758692503, 0.00029949002782814205, 0.0002628540969453752, 0.004163789562880993, 0.0072104367427527905, -0.013513036072254181, 0.001228940556757152, -0.0019661984406411648, 0.001459130784496665, 0.007019015494734049, -0.0047830319963395596, 0.004987274296581745, 0.011188920587301254, 0.0013440230395644903, -0.0069679878652095795, -0.0023535864893347025, 0.0015655317110940814, 0.004916798323392868, -0.010306205600500107, 0.0021893694065511227, -0.002511913189664483, -0.003410183358937502, -0.003516341559588909, -0.0023917248472571373, -0.0011736591113731265, 0.005147611256688833, -0.004200781229883432, 0.006694444455206394, -0.000014371260476764292, -0.0023529718164354563, 0.014858369715511799, -0.009764916263520718, -0.005822618026286364, 0.0026191123761236668, 0.0011689882958307862, -0.0018889919156208634, -0.0059283035807311535, -0.004756440874189138, 0.0011009258450940251, 0.004423373378813267, -0.004848088137805462, -0.006490889471024275, 0.0013049328699707985, 0.00024223059881478548, -0.006029520649462938, -0.00020726169168483466, 0.011433061212301254, -0.0009727402939461172, 0.0059515610337257385, -0.0015052197268232703, -0.00568691361695528, -0.015110899694263935, 0.053269486874341965, -0.0014173703966662288, 0.002919210819527507, 0.003961614333093166, -0.008112284354865551, -0.0012152164708822966, -0.001840295153670013, 0.006432879250496626, -0.009506790898740292, -0.008300065994262695, 0.01076105609536171, -0.003311164677143097, 0.0051664924249053, -0.0023163550067692995, -0.0013059056363999844, 0.013001029379665852, -0.0034643332473933697, -0.01853054203093052, -0.0172643531113863, 0.007265634834766388, -0.004426849540323019, -0.007437581196427345, 0.0062024095095694065, -0.0027947616763412952, -0.0029634381644427776, 0.0013230862095952034, 0.003309147199615836, 0.0007056554895825684, 0.0014037522487342358, -0.0035041754599660635, -0.0021291461307555437, -0.002086404012516141, 0.0019885378424078226, 0.009818244725465775, 0.009775364771485329, -0.0013973801396787167, 0.005788218230009079, -0.004941084887832403, 0.0010907248361036181, -0.003014999208971858, 0.0035838272888213396, 0.00719656003639102, -0.0028173006139695644, -0.0028381729498505592, 0.0038527639117091894, 0.0022118387278169394, -0.0005928918835707009, 0.009003816172480583, 0.0008813549065962434, -0.0035768412053585052, 0.00990116037428379, 0.006067867390811443, -0.0034114569425582886, 0.004913513548672199, -0.003952488303184509, 0.004416290204972029, 0.002944116247817874, -0.007072972599416971, -0.01903243362903595, -0.0043398719280958176, 0.005137329455465078, 0.007381293457001448, -0.002208650577813387, 0.002125916536897421, -0.0015687524573877454, -0.002396863419562578, -0.007756188046187162, -0.005430207587778568, -0.004311304539442062, -0.00034397002309560776, 0.0016263305442407727, 0.07260307669639587, -0.005331320688128471, -0.00037621770752593875, -0.0077785043977200985, -0.0002737232716754079, -0.0020768207032233477, -0.0014025099808350205, -0.0005183693720027804, -0.0017777094617486, 0.003878049086779356, 0.003667888231575489, -0.007473709061741829, -0.010253199376165867, 0.002412851434201002, 0.0005048845196142793, -0.0021053440868854523, 0.003712734207510948, 0.007759186904877424, -0.009962402284145355, 0.001148710958659649, -0.012018807232379913, -0.0010500694625079632, -0.0037664526607841253, -0.009829691611230373, -0.0018816777737811208, -0.004550914280116558, 0.0035133438650518656, 0.0031810058280825615, 0.0070842779241502285, -0.0019046441884711385, 0.00594665389508009, -0.0008352540899068117, 0.001108601107262075, -0.005012555047869682, -0.0014747263630852103, -0.005987007636576891, 0.0069971936754882336, 0.0014674632111564279, -0.010934548452496529, -0.00474168686196208, -0.004299042746424675, 0.0004822209302801639, -0.007601454388350248, 0.006034053396433592, -0.0020446861162781715, 0.006346011999994516, -0.0025805586483329535, 0.00045572363887913525, -0.00642570061609149, -0.0021947016939520836, -0.011294301599264145, 0.005554477218538523, -0.18186746537685394, 0.009536504745483398, 0.0017562549328431487, -0.004166764672845602, -0.005704726092517376, -0.015492350794374943, -0.00963765662163496, 0.004595820792019367, 0.010044533759355545, 0.000690609507728368, -0.0020419296342879534, -0.0009460749570280313, 0.0068244668655097485, 0.004590834956616163, -0.0004564248083624989, -0.007721537258476019, 0.00010160624515265226, -0.003616182366386056, 0.0014536534436047077, 0.0020554284565150738, 0.003599904477596283, 0.00875381100922823, 0.0007627371232956648, 0.001571863773278892, -0.0001257365511264652, -0.0049885851331055164, 0.006387143861502409, -0.0027202183846384287, 0.0057759215123951435, -0.0137933986261487, -0.0029234597459435463, -0.0062952907755970955, -0.0050162747502326965, 0.001132205012254417, 0.006383833475410938, -0.0035313183907419443, 0.006989963818341494, 0.0013919495977461338, -0.008058247156441212, 0.007251966744661331, -0.007493181154131889, 0.025318972766399384, 0.002595712663605809, 0.008220354095101357, 0.002550289034843445, -0.0036373191978782415, -0.006269589066505432, 0.007392958737909794, 0.002094769850373268, 0.01415753923356533, -0.015429243445396423, -0.004515163134783506, 0.0028749953489750624, 0.018875189125537872, -0.0038570514880120754, -0.009713102132081985, -0.006869982462376356, -0.002668905770406127, 0.0031783843878656626, 0.011543692089617252, 0.010661235079169273, -0.0028959615156054497, 0.008983252570033073, -0.003556273877620697, -0.022615259513258934, 0.0015667073894292116, -0.002441936172544956, -0.007770017255097628, 0.004784703254699707, 0.007127562537789345, 0.010083724744617939, -0.0008456711075268686, 0.006022965535521507, -0.0005173272802494466, 0.005797647405415773, -0.0006536564906127751, 0.007360389921814203, -0.0028253679629415274, 0.005416562780737877, -0.007697308901697397, 0.011922009289264679, -0.009536449797451496, -0.002791581442579627, 0.00182718550786376, -0.004962364677339792, 0.00993929710239172, 0.0035712323151528835, -0.002990697044879198, -0.00017549912445247173, -0.008628183975815773, -0.0017861889209598303, 0.0036198419984430075, 0.0029214287642389536, -0.006700458936393261, 0.00017145834863185883, 0.001155633246526122, 0.005600917153060436, 0.008648907765746117, -0.00777079164981842, 0.006458565592765808, 0.004255748353898525, -0.0075926510617136955, -0.0007585544954054058, -0.004798823036253452, 0.002349192975088954, 0.0027702306397259235, -0.0067090727388858795, -0.0058647748082876205, 0.0016246914165094495, -0.0049714888446033, -0.006925017107278109, 0.005387495271861553, -0.009522372856736183, -0.007873976603150368, 0.00006780828698538244, -0.010460593737661839, 0.0006547423545271158 ]
8aae1314a34df4a8c2038ff3f05e19541e560962
2,489
py
Python
tests/integration/test_cmk_describe.py
oglok/CPU-Manager-for-Kubernetes
503f37dcb20452699ce789b6628fa3ebeb9ffb54
[ "Apache-2.0" ]
null
null
null
tests/integration/test_cmk_describe.py
oglok/CPU-Manager-for-Kubernetes
503f37dcb20452699ce789b6628fa3ebeb9ffb54
[ "Apache-2.0" ]
null
null
null
tests/integration/test_cmk_describe.py
oglok/CPU-Manager-for-Kubernetes
503f37dcb20452699ce789b6628fa3ebeb9ffb54
[ "Apache-2.0" ]
null
null
null
# Copyright (c) 2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from .. import helpers from . import integration def test_cmk_describe_ok(): args = ["describe", "--conf-dir={}".format(helpers.conf_dir("ok"))] assert helpers.execute(integration.cmk(), args) == b"""{ "path": "/cmk/tests/data/config/ok", "pools": { "exclusive": { "cpuLists": { "4,12": { "cpus": "4,12", "tasks": [ 2000 ] }, "5,13": { "cpus": "5,13", "tasks": [ 2001 ] }, "6,14": { "cpus": "6,14", "tasks": [ 2002 ] }, "7,15": { "cpus": "7,15", "tasks": [ 2003 ] } }, "exclusive": true, "name": "exclusive" }, "infra": { "cpuLists": { "0-2,8-10": { "cpus": "0-2,8-10", "tasks": [ 3000, 3001, 3002 ] } }, "exclusive": false, "name": "infra" }, "shared": { "cpuLists": { "3,11": { "cpus": "3,11", "tasks": [ 1000, 1001, 1002, 1003 ] } }, "exclusive": false, "name": "shared" } } } """ def test_cmk_describe_minimal(): args = ["describe", "--conf-dir={}".format(helpers.conf_dir("minimal"))] assert helpers.execute(integration.cmk(), args) == b"""{ "path": "/cmk/tests/data/config/minimal", "pools": { "exclusive": { "cpuLists": { "0": { "cpus": "0", "tasks": [] } }, "exclusive": true, "name": "exclusive" }, "shared": { "cpuLists": { "0": { "cpus": "0", "tasks": [] } }, "exclusive": false, "name": "shared" } } } """
21.273504
74
0.451185
1
1.6311
[ 0.002332571893930435, 0.024324260652065277, 0.009505892172455788, 0.0014302266063168645, 0.004745094105601311, -0.0037054172717034817, -0.009959611110389233, 0.00366036593914032, -0.00665390444919467, 0.0008384219254367054, 0.0031030289828777313, 0.0037275683134794235, 0.009127206169068813, -0.01613754965364933, 0.002786574885249138, 0.019208092242479324, -0.05385670065879822, 0.00020252734248060733, -0.003762564156204462, 0.0018938264111056924, -0.00860950443893671, 0.008071152493357658, 0.0103355897590518, 0.006268766708672047, 0.006378563586622477, -0.000027780517484643497, 0.00961832795292139, 0.0027570861857384443, -0.006774834357202053, -0.008100076578557491, 0.00042702906648628414, -0.0019701493438333273, -0.007615183014422655, -0.007588906213641167, 0.0060240281745791435, -0.003323541721329093, -0.0011848424328491092, -0.01871631108224392, 0.012439342215657234, -0.0052094245329499245, -0.007536706514656544, -0.0166050773113966, -0.0006245996337383986, 0.005575536750257015, -0.009250990115106106, 0.00011934824578929693, -0.0028667235746979713, 0.0020968725439161062, -0.010181357152760029, 0.00785060878843069, -0.01124229934066534, 0.006158817559480667, 0.012960896827280521, 0.0025792487431317568, -0.005596739239990711, -0.006861841306090355, 0.011131960898637772, 0.0002838827494997531, -0.010803503915667534, 0.001478505670093, -0.0032824291847646236, -0.003557488787919283, 0.004573004320263863, 0.0030583476182073355, -0.016445303335785866, -0.006008592434227467, -0.00327614089474082, 0.0036902599968016148, -0.0010588574223220348, 0.00594753585755825, 0.0008871896425262094, 0.0001500275102443993, 0.007539923768490553, 0.005016355775296688, 0.00451625743880868, -0.0025720971170812845, -0.0019135571783408523, 0.0017261554021388292, 0.009546670131385326, 0.0016755679389461875, 0.0029154373332858086, -0.008195583708584309, 0.004802136216312647, 0.010102933272719383, 0.01408930029720068, 0.008721159771084785, 0.01916400156915188, -0.01167965680360794, 0.04701472073793411, 0.006436052732169628, -0.009051124565303326, 0.001656159176491201, -0.007876277901232243, -0.0014181717997416854, -0.0023987814784049988, -0.02789429761469364, 0.00013693557411897928, -0.002469769213348627, -0.0010265727760270238, 0.0034658797085285187, -0.002668621949851513, 0.005657021887600422, -0.002147016115486622, -0.0013974439352750778, -0.009172720834612846, 0.011197350919246674, -0.009079346433281898, -0.002154828980565071, 0.0066985166631639, 0.0023595031816512346, -0.01401316374540329, -0.0028997273184359074, 0.0013193035265430808, -0.010827535763382912, 0.004120196681469679, 0.003041316755115986, -0.005790917202830315, 0.05599582567811012, -0.00033167123910970986, 0.0028980958741158247, -0.003902111668139696, 0.0006991511909291148, 0.0015415059169754386, 0.005940317641943693, 0.01067876722663641, -0.0045478567481040955, 0.009608282707631588, 0.006960348226130009, 0.0035434847231954336, 0.007748525124043226, -0.0014446609420701861, 0.009133436717092991, -0.006286595016717911, -0.001883852994069457, 0.002672984264791012, -0.00703012989833951, 0.009391063824295998, -0.0023110946640372276, -0.007400693837553263, -0.002202681265771389, -0.0008736619492992759, -0.010407350957393646, 0.002020227024331689, -0.003978330176323652, 0.0032830731943249702, -0.011445388197898865, -0.0037693658377975225, -0.001957590924575925, -0.004775375127792358, 0.00238381908275187, 0.01049112156033516, 0.00426037423312664, 0.0035537793301045895, -0.005599915981292725, -0.008779516443610191, -0.0004921501968055964, -0.005348120350390673, 0.0023963437415659428, 0.008507120423018932, 0.0036507174372673035, -0.007803821936249733, -0.0009888788918033242, 0.002378489589318633, 0.002292332239449024, -0.0004158647789154202, 0.0010982921812683344, -0.009559636935591698, 0.007451409474015236, 0.0002998135460074991, 0.005503212101757526, 0.010021410882472992, -0.0026772187557071447, -0.0005063647404313087, 0.0005137252155691385, 0.0007029777625575662, -0.0008588478085584939, 0.005197205115109682, 0.009856290183961391, -0.0029266122728586197, -0.0044587100856006145, 0.004241130314767361, 0.003665824420750141, 0.009692272171378136, 0.007320834789425135, -0.002471507992595434, 0.0016378512373194098, -0.0046265749260783195, -0.000007107251803972758, 0.006612719967961311, -0.003495118347927928, 0.006710357032716274, 0.004796946886926889, -0.015381366945803165, -0.008673582226037979, 0.0007818139856681228, -0.010132579132914543, 0.002150364685803652, 0.014262580312788486, 0.0119966184720397, -0.0021069501526653767, 0.0007899910560809076, -0.009041888639330864, 0.0017231693491339684, 0.0072952089831233025, 0.0021231654100120068, -0.01387129258364439, -0.9572862982749939, 0.007104247808456421, 0.00375461857765913, -0.0012612644350156188, 0.0058455863036215305, 0.0012062633177265525, 0.003954896237701178, 0.003863701829686761, 0.015518618747591972, -0.009138140827417374, -0.006946707144379616, -0.00904802605509758, -0.01021089032292366, -0.00022652014740742743, -0.00674735102802515, -0.004490758758038282, -0.006319794803857803, -0.006151667330414057, -0.0028701829724013805, -0.004077631514519453, -0.0012816793750971556, 0.009066659025847912, -0.001587443519383669, 0.004904992412775755, 0.004442013334482908, 0.0027574992273002863, -0.005435032304376364, -0.0012416194658726454, -0.0034459831658750772, -0.0031958662439137697, -0.006835101637989283, -0.016866380348801613, -0.004435951821506023, -0.0018925269832834601, 0.012002176605165005, 0.0006404693122021854, 0.010476799681782722, -0.0021869312040507793, 0.002685572486370802, -0.008215396665036678, 0.004590920172631741, 0.0011182079324498773, 0.0035153869539499283, -0.030276555567979813, 0.0003080338938161731, 0.0008597486303187907, -0.007960338145494461, 0.0078998152166605, 0.0003831425274256617, -0.0018176408484578133, -0.001663914998061955, -0.004672597628086805, 0.009181718342006207, -0.00796271301805973, 0.002327148336917162, -0.005546154920011759, -0.0060744863003492355, -0.002039280254393816, -0.008957771584391594, 0.0012908072676509619, 0.00509334821254015, -0.0015684433747082949, -0.0039017824456095695, -0.005284780636429787, 0.003783805062994361, 0.001262718578800559, 0.003164747031405568, -0.016090452671051025, -0.005391284357756376, -0.0038882140070199966, 0.0010650388430804014, -0.0026763305068016052, -0.004853397142142057, 0.004654680844396353, -0.008241597563028336, 0.006761858239769936, 0.0024632695131003857, 0.0005995602114126086, -0.011413749307394028, 0.0010001412592828274, -0.00913283322006464, -0.0079456502571702, 0.0021661771461367607, -0.0045982468873262405, -0.003920027054846287, -0.00048226953367702663, 0.001715551596134901, 0.008754290640354156, -0.005129917990416288, 0.004867407027631998, 0.011043350212275982, -0.005359914619475603, -0.009698819369077682, 0.005813582334667444, 0.005368427839130163, 0.00012379043619148433, -0.0024126949720084667, 0.00079619005555287, 0.0089328708127141, 0.00894510094076395, 0.001458309474401176, 0.004282657988369465, -0.00028234609635546803, 0.008728218264877796, 0.00013289546768646687, 0.0025917943567037582, -0.0019841580651700497, -0.000890103867277503, -0.0019527605036273599, 0.00036712706787511706, -0.005465383175760508, -0.0016642716946080327, -0.012319804169237614, -0.009601184166967869, -0.004467744845896959, -0.00015149812679737806, 0.002699666190892458, -0.005242076702415943, -0.0009689946309663355, 0.0024558366276323795, 0.009084757417440414, -0.00009853061055764556, -0.0032796687446534634, 0.002530894707888365, 0.0027734299656003714, -0.007992023602128029, 0.014698527753353119, -0.012059307657182217, 0.007280933205038309, -0.00020683766342699528, -0.016145853325724602, 0.008989481255412102, 0.010008418932557106, -0.009462563320994377, 0.001353823347017169, 0.0026017604395747185, 0.002709747524932027, 0.0012363471323624253, -0.004533078987151384, -0.004986296407878399, -0.018724411725997925, -0.0010277695255354047, 0.021514294669032097, 0.0027176260482519865, 0.009133203886449337, 0.011660559102892876, -0.0027268463745713234, 0.0033879855182021856, 0.006734824739396572, 0.0016864243661984801, 0.012140125967562199, -0.008352585136890411, -0.0011426308192312717, 0.002200249582529068, -0.006333592813462019, 0.0014563195873051882, 0.004719087388366461, 0.004300091415643692, -0.0020838689524680376, 0.0028989571146667004, -0.007871245965361595, -0.004412706475704908, -0.01847171224653721, -0.0010229679755866528, 0.005131222773343325, -0.0047398959286510944, 0.006020724307745695, -0.012530111707746983, 0.0041091046296060085, 0.005982690025120974, 0.0025514974258840084, -0.000959996017627418, 0.0015941231977194548, 0.005795957986265421, 0.012279967777431011, -0.005301142577081919, 0.0017834289465099573, 0.0023205468896776438, -0.0014297834131866693, 0.000647905224468559, 0.007326476741582155, -0.007854131050407887, -0.004556311294436455, 0.0034430231899023056, 0.004263400100171566, 0.00011505293514346704, -0.004427033942192793, -0.009393476881086826, -0.0047076670452952385, 0.002992776455357671, -0.003934604115784168, 0.003998242784291506, 0.0011049691820517182, 0.003816405776888132, -0.007814076729118824, 0.000018494096366339363, -0.005543082486838102, -0.010104918852448463, 0.009972874075174332, -0.0025176075287163258, 0.0013159288791939616, 0.014049138873815536, 0.004027546849101782, -0.01263343170285225, 0.004183625336736441, 0.009725289419293404, -0.0028653242625296116, 0.005766802933067083, 0.006342652719467878, -0.005094438791275024, -0.022853193804621696, -0.0022039003670215607, -0.013554185628890991, 0.0059402259066700935, -0.0017353396397083998, 0.0049409144558012486, -0.008751369081437588, 0.006378856487572193, 0.0067980047315359116, -0.013717440888285637, -0.004051089286804199, -0.008285677060484886, 0.009116267785429955, -0.000026370260457042605, -0.002404334954917431, -0.0033963797613978386, -0.0016110911965370178, -0.003149043070152402, -0.0013453061692416668, 0.0003563589998520911, 0.006118255667388439, 0.0027198113966733217, -0.002670666901394725, 0.002250166842713952, -0.0042843944393098354, 0.00179992092307657, 0.0018687642877921462, -0.010468660853803158, 0.0008425473934039474, 0.003712903708219528, -0.002034566132351756, -0.0018579816678538918, 0.0005271101254038513, -0.0006071336101740599, -0.0048848651349544525, -0.011152067221701145, -0.0024775555357337, -0.005484499502927065, -0.0016798230353742838, -0.010850627906620502, -0.002885102527216077, -0.0076193977147340775, 0.007010272704064846, -0.007001502439379692, 0.008341295644640923, 0.00604556780308485, -0.00617658207193017, 0.005898246541619301, -0.0026927513536065817, 0.003376515582203865, 0.003143415553495288, 0.005435680039227009, 0.0017467335565015674, -0.005682053975760937, -0.010551651008427143, 0.011338552460074425, -0.00891274306923151, 0.0009392594802193344, 0.014152723364531994, 0.005313406232744455, 0.008479290641844273, 0.0011054187780246139, -0.0010288659250363708, 0.0050827027298510075, 0.008378725498914719, -0.01451527327299118, 0.0028231549076735973, -0.002223504474386573, -0.0014548480976372957, 0.004902776330709457, -0.003348633646965027, 0.002645626664161682, 0.007287045009434223, -0.0001926461554830894, -0.007191292941570282, -0.0019577541388571262, 0.0020122909918427467, 0.003188783535733819, -0.012935551814734936, 0.0007960386574268341, -0.0026550679467618465, -0.004909533075988293, -0.0035289712250232697, -0.003016406437382102, -0.0005397021304816008, 0.005023622885346413, -0.0019972692243754864, 0.0076088267378509045, 0.0024162111803889275, -0.00405935849994421, 0.014669637195765972, -0.005504331551492214, -0.0041343774646520615, 0.002518601017072797, 0.001169457915239036, -0.001167113776318729, -0.005691883619874716, -0.0006258694920688868, 0.0018135482678189874, 0.006502226926386356, -0.004146719817072153, -0.004694041330367327, -0.0012525161728262901, 0.0023303597699850798, -0.007996611297130585, 0.001537795178592205, 0.00982515700161457, -0.0034682410769164562, 0.00501006655395031, -0.0010868421522900462, -0.008422035723924637, -0.014546463266015053, 0.0538276806473732, -0.00232471595518291, 0.002266978845000267, 0.00460047135129571, -0.006844507995992899, -0.0011466931318864226, -0.0023752721026539803, 0.007471215911209583, -0.006359821185469627, -0.007709207013249397, 0.008539768867194653, -0.003135104663670063, 0.0034360194113105536, 0.00029386329697445035, -0.0011910500470548868, 0.015214144252240658, -0.00446033151820302, -0.01850968785583973, -0.01689242385327816, 0.008599340915679932, -0.00416707806289196, -0.007655877619981766, 0.0069044362753629684, -0.005007489584386349, -0.0035018546041101217, 0.0006002410664223135, 0.005822998005896807, -0.00037831065128557384, -0.00041155933286063373, -0.0022202981635928154, -0.0029860599897801876, -0.00020580181444529444, 0.0018827769672498107, 0.007871745154261589, 0.006283169612288475, -0.0016450599068775773, 0.004657902289181948, -0.0006559623870998621, 0.0004990354063920677, -0.0022151586599648, 0.003883028170093894, 0.008057610131800175, -0.00229530013166368, -0.002743997611105442, 0.005571023561060429, 0.004426721483469009, 0.0002917771053034812, 0.010696541517972946, -0.0003963412600569427, -0.005574246868491173, 0.008554663509130478, 0.007653728127479553, -0.0008812526939436793, 0.007642007432878017, -0.0022173975594341755, 0.004857328720390797, 0.002709758933633566, -0.008242405019700527, -0.015010030940175056, -0.0031708439346402884, 0.006957465782761574, 0.007951406762003899, -0.001777379889972508, 0.0031495275907218456, -0.0008240675088018179, -0.002055129734799266, -0.0070926896296441555, -0.006202101707458496, -0.003312177024781704, 0.0018578744493424892, 0.0038528922013938427, 0.07087662070989609, -0.006114643067121506, -0.00184199761133641, -0.006794138345867395, -0.0013000464532524347, -0.0018262052908539772, -0.0005117261898703873, -0.0009687816491350532, -0.0029277880676090717, 0.0013429983519017696, 0.0026145128067582846, -0.007439985405653715, -0.009073267690837383, 0.002069974085316062, 0.0023568670731037855, -0.002830467652529478, 0.006260067690163851, 0.005325845442712307, -0.01245063729584217, 0.002081542508676648, -0.012263821437954903, -0.002751662628725171, -0.003998007625341415, -0.009994891472160816, -0.003426169278100133, -0.003485411638393998, 0.0036544252652674913, 0.0022367937490344048, 0.005068595986813307, -0.0030037323012948036, 0.005015247035771608, -0.0008893710328266025, 0.00021967764769215137, -0.005719034932553768, -0.0011535320663824677, -0.007285487372428179, 0.00757297407835722, 0.0019090489950031042, -0.010158422403037548, -0.00633032713085413, -0.0032898609060794115, -0.00024068685888778418, -0.00564440805464983, 0.0035853483714163303, -0.0008317750180140138, 0.00660352036356926, -0.0011797151528298855, -0.00004133339098189026, -0.006507431622594595, 0.0011394837638363242, -0.011632140725851059, 0.0038100481033325195, -0.17895416915416718, 0.010429499670863152, 0.003971194848418236, -0.004878790117800236, -0.004321075975894928, -0.014215918257832527, -0.005107460543513298, 0.0037269399035722017, 0.010737093165516853, -0.000051588409405667335, -0.000533352023921907, -0.0033044866286218166, 0.004385138396173716, 0.0021352595649659634, -0.0014982669381424785, -0.005135936662554741, 0.0034665067214518785, -0.004210168030112982, 0.00015094036643859, 0.004028729163110256, 0.0059195468202233315, 0.00923642236739397, 0.002224049298092723, 0.002544823568314314, -0.0007117302156984806, -0.005420118570327759, 0.005710802506655455, -0.0025329135823994875, 0.0054628485813736916, -0.013413208536803722, -0.005123886279761791, -0.004411407746374607, -0.0050721801817417145, 0.0016922411741688848, 0.005246030166745186, -0.00036589166847988963, 0.009501089341938496, 0.002184908837080002, -0.007508219685405493, 0.009014517068862915, -0.00786049198359251, 0.02764209359884262, 0.004334200639277697, 0.006440301425755024, -0.0004943134845234454, -0.0037524839863181114, -0.003474040422588587, 0.009117244742810726, 0.0017666855128481984, 0.012422293424606323, -0.012847930192947388, -0.0021965987980365753, 0.0026345932856202126, 0.018551575019955635, -0.003637834219262004, -0.010822484269738197, -0.006321130320429802, -0.004063535016030073, 0.003885871497914195, 0.008485562168061733, 0.010457784868776798, -0.004398619756102562, 0.008796836249530315, -0.0025033762212842703, -0.023041097447276115, 0.0033555030822753906, -0.0057486724108457565, -0.007639725226908922, 0.0008215815178118646, 0.006616208702325821, 0.009794124402105808, -0.0015265870606526732, 0.001214624266140163, -0.0027460784185677767, 0.005558427423238754, -0.00002143690289813094, 0.006299349945038557, -0.002800417598336935, 0.004773894790560007, -0.008187007158994675, 0.007063155062496662, -0.009220489300787449, -0.002976665971800685, 0.003215787000954151, -0.005165460053831339, 0.011028440669178963, 0.004146369639784098, -0.0030811489559710026, -0.0005764345987699926, -0.010811826214194298, -0.003255933290347457, 0.0016788162756711245, 0.0014099727850407362, -0.007262340281158686, 0.0027198654133826494, 0.0009775023208931088, 0.006294078193604946, 0.006296288687735796, -0.009156017564237118, 0.005487426649779081, 0.006570250261574984, -0.00519455224275589, 0.00039980714791454375, -0.004152955953031778, 0.0020494991913437843, 0.0031041158363223076, -0.004428956191986799, -0.008096925914287567, 0.0036464384756982327, -0.006084114778786898, -0.004978180397301912, 0.006772585678845644, -0.010364820249378681, -0.007063942030072212, -0.0027509599458426237, -0.01114999782294035, 0.0011906878789886832 ]
8aaee662db93c29bfc4e01c664b5f8c132a76382
1,331
py
Python
setup.py
richardARPANET/persistent-celery-beat-scheduler
d2cbdd12394eec282ccb97ac5ff894353c2e4ffd
[ "Apache-2.0" ]
4
2018-04-04T13:03:08.000Z
2018-04-16T18:50:45.000Z
setup.py
richardARPANET/persistent-celery-beat-scheduler
d2cbdd12394eec282ccb97ac5ff894353c2e4ffd
[ "Apache-2.0" ]
null
null
null
setup.py
richardARPANET/persistent-celery-beat-scheduler
d2cbdd12394eec282ccb97ac5ff894353c2e4ffd
[ "Apache-2.0" ]
null
null
null
#!/usr/bin/env python # -*- coding: utf-8 -* import os from setuptools import find_packages, setup # allow setup.py to be run from any path os.chdir(os.path.normpath(os.path.join(os.path.abspath(__file__), os.pardir))) with open('requirements.txt') as f: install_requires = f.read().splitlines() setup( name='persistent-celery-beat-scheduler', version='0.1.1.dev0', packages=find_packages('src', exclude=('tests',)), package_dir={'': 'src'}, include_package_data=True, zip_safe=False, description=( 'Celery Beat Scheduler that stores the scheduler data in Redis.' ), author='Richard O\'Dwyer', author_email='richard@richard.do', license='Apache 2', long_description='https://github.com/richardasaurus/persistent-celery-beat-scheduler', install_requires=install_requires, classifiers=[ 'Intended Audience :: Developers', 'Operating System :: OS Independent', 'Programming Language :: Python', 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3.2', 'Programming Language :: Python :: 3.3', 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.6', 'Topic :: Internet :: WWW/HTTP', ], )
31.690476
90
0.643877
1
1.0971
[ 0.000677612260915339, 0.023152915760874748, 0.007793580647557974, 0.0009722825489006937, 0.004032169934362173, -0.0016843659104779363, -0.010143039748072624, 0.0020358788315206766, -0.0084696589037776, 0.0025452703703194857, 0.0023098161909729242, 0.00751345232129097, 0.006318139377981424, -0.01745142601430416, 0.002526816911995411, 0.01632913202047348, -0.05294577777385712, 0.0029970756731927395, -0.0043110717087984085, 0.0017236667918041348, -0.007654955610632896, 0.010405110195279121, 0.008787892758846283, 0.007380054332315922, 0.0066885738633573055, 0.0008653609547764063, 0.008188740350306034, 0.002761099487543106, -0.008394359610974789, -0.00648009218275547, -0.000622537627350539, -0.003322630887851119, -0.005780896171927452, -0.008940871804952621, 0.009388952516019344, -0.0027680471539497375, -0.00033245995291508734, -0.01964297890663147, 0.010951153934001923, -0.0038470998406410217, -0.0075782109051942825, -0.016171885654330254, 0.0008940700208768249, 0.002333509735763073, -0.00857976172119379, 0.0023626331239938736, -0.0037895163986831903, 0.004245719872415066, -0.010479964315891266, 0.007276720367372036, -0.009018895216286182, 0.005650739185512066, 0.014888952486217022, 0.004230938386172056, -0.004737165756523609, -0.007043115794658661, 0.013132262043654919, 0.0015334718627855182, -0.010263686068356037, 0.0013572921743616462, -0.0033696077298372984, -0.003248380497097969, 0.005264523439109325, 0.0037488453090190887, -0.017103085294365883, -0.00692406389862299, -0.00402802973985672, 0.0007048822590149939, -0.0021102745085954666, 0.004977477248758078, -0.0004262406728230417, -0.0020802475046366453, 0.007050040643662214, 0.004132630303502083, 0.004611324984580278, -0.002403249964118004, -0.0007731443620286882, 0.0021064707543700933, 0.011066603474318981, 0.004863600712269545, 0.004902869462966919, -0.00625982042402029, 0.007331950590014458, 0.01148107461631298, 0.015355266630649567, 0.008975567296147346, 0.019496729597449303, -0.010744867846369743, 0.04774900898337364, 0.004980790428817272, -0.00964007806032896, 0.0002338734921067953, -0.008531324565410614, -0.0008297390886582434, -0.0039682588540017605, -0.029000574722886086, 0.0010322931921109557, -0.0036192936822772026, -0.00012660687207244337, 0.004674253053963184, -0.0005304698133841157, 0.005949952639639378, -0.0020369619596749544, -0.0015815268270671368, -0.011267107911407948, 0.01338116079568863, -0.009605653584003448, -0.002740092109888792, 0.007137448526918888, 0.0007720424327999353, -0.009665570221841335, -0.0014093590434640646, 0.0008562756702303886, -0.013492514379322529, 0.0038116998039186, 0.003126414492726326, -0.006517288275063038, 0.05427173152565956, -0.0017322013154625893, 0.0026253408286720514, -0.003336480353027582, 0.0008945371955633163, -0.0011763883521780372, 0.005227941088378429, 0.008062612265348434, -0.003067848738282919, 0.010940159671008587, 0.008506950922310352, 0.0024561111349612474, 0.008580894209444523, -0.0014581546420231462, 0.005758044309914112, -0.005674137733876705, -0.002857780084013939, -0.0005885203136131167, -0.007949234917759895, 0.008037835359573364, -0.0007384674972854555, -0.008797249756753445, 0.000728052866179496, -0.0007139053195714951, -0.010053870268166065, 0.0031112455762922764, -0.0032433029264211655, 0.003023050958290696, -0.012088898569345474, -0.005478512030094862, -0.0019633478950709105, -0.004232124425470829, 0.0031372446101158857, 0.007525037974119186, 0.0037714007776230574, 0.0033814655616879463, -0.00451267696917057, -0.008996561169624329, -0.00016915750165935606, -0.0031464044004678726, 0.0005288823740556836, 0.007309030741453171, 0.003582238918170333, -0.009373337961733341, -0.00027499551651999354, 0.0050885314121842384, 0.004745223093777895, -0.0013553154421970248, 0.004445367492735386, -0.0071955230087041855, 0.008271471597254276, 0.0013397932052612305, 0.003883203025907278, 0.011766873300075531, -0.0038894887547940016, -0.0011771498247981071, 0.001747056026943028, 0.0039291842840611935, 0.0017987132305279374, 0.006998166907578707, 0.011017466895282269, -0.004367813002318144, -0.0032352085690945387, 0.002539986278861761, 0.006159039214253426, 0.008091211318969727, 0.010573932901024818, -0.003113451413810253, 0.002442300086840987, -0.004806539975106716, -0.0015986710786819458, 0.005432292353361845, -0.00430178502574563, 0.004613755736500025, 0.004258429631590843, -0.014145111665129662, -0.007699943147599697, 0.0003796648234128952, -0.010254794731736183, 0.0014595311367884278, 0.013607307337224483, 0.013484327122569084, -0.00425936933606863, 0.0040775020606815815, -0.009674666449427605, 0.0012626415118575096, 0.007853159680962563, 0.00016523667727597058, -0.013052706606686115, -0.9574421644210815, 0.006139605771750212, 0.0010567273711785674, -0.0004887313698418438, 0.005297204479575157, 0.0006702569080516696, 0.0023255140986293554, 0.0033847996965050697, 0.013196129351854324, -0.008078350685536861, -0.004894995130598545, -0.00854447577148676, -0.010460794903337955, -0.00010753020615084097, -0.009462903253734112, -0.0027136518619954586, -0.006574627943336964, -0.006946551147848368, -0.002782433293759823, -0.0036132624372839928, -0.0021312867756932974, 0.007649663835763931, -0.0007740919827483594, 0.005812718998640776, 0.0025528455153107643, 0.003678190754726529, -0.003600392257794738, -0.00046214545727707446, -0.00032442971132695675, -0.002808323595672846, -0.0066763185895979404, -0.016974421218037605, -0.005435063038021326, -0.0016157521167770028, 0.010205065831542015, 0.0016508876578882337, 0.008849355392158031, -0.0007290256326086819, 0.002087644301354885, -0.0075056585483253, 0.004726031795144081, 0.0012891856022179127, 0.0027991062961518764, -0.030872099101543427, 0.0009126844233833253, -0.000017928678062162362, -0.009437118656933308, 0.008197520859539509, 0.00043185276445001364, -0.0002636988356243819, -0.003938168287277222, -0.006263300310820341, 0.009841839782893658, -0.007581730838865042, 0.005272524431347847, -0.00443020835518837, -0.007936026901006699, -0.0027583877090364695, -0.009639175608754158, 0.0015780808171257377, 0.006809969898313284, -0.004224820528179407, -0.00521424924954772, -0.004047960974276066, 0.00001479059847042663, 0.0033581142779439688, 0.0015627734828740358, -0.01840115152299404, -0.007614809088408947, -0.0029845128301531076, 0.0031224077101796865, -0.004411507863551378, -0.00437515415251255, 0.006850663106888533, -0.009218263439834118, 0.0068816845305264, 0.0030785026028752327, 0.0013017909368500113, -0.010260394774377346, 0.0021422102581709623, -0.0071775359101593494, -0.008293505758047104, 0.0023470381274819374, -0.0060753533616662025, -0.0042722830548882484, -0.00010102373926201835, 0.00036407081643119454, 0.0069670528173446655, -0.002947758184745908, 0.004903117194771767, 0.011588634923100471, -0.004965489264577627, -0.008458311669528484, 0.0061247870326042175, 0.008286124095320702, 0.0008485178113915026, -0.0017365043750032783, 0.0027461391873657703, 0.009889836423099041, 0.005747875664383173, 0.0037870560772717, 0.005456336308270693, -0.000057315446611028165, 0.0104330750182271, -0.0006458329735323787, 0.002543808426707983, -0.0043426076881587505, -0.003614385612308979, -0.0036218962632119656, 0.0009496789425611496, -0.0022755437530577183, -0.0026176152750849724, -0.012518558651208878, -0.009976280853152275, -0.001552398200146854, 0.00034609733847901225, 0.0007143166149035096, -0.0031559537164866924, -0.000839289918076247, 0.002743345918133855, 0.0099745849147439, -0.0014237543800845742, -0.0028789599891752005, 0.001762406900525093, 0.002855590544641018, -0.006867915857583284, 0.014390377327799797, -0.01132272183895111, 0.005166179966181517, -0.0010059622582048178, -0.01695689745247364, 0.00816500373184681, 0.008530654013156891, -0.008306846022605896, 0.002584889531135559, 0.0038452865555882454, 0.0032829088158905506, -0.0007774836267344654, -0.002704295562580228, -0.002914001001045108, -0.01688678003847599, -0.0009798454120755196, 0.01929532364010811, 0.001365053467452526, 0.007874737493693829, 0.011161229573190212, -0.0020136351231485605, 0.0021098521538078785, 0.0042701889760792255, 0.0010787752689793706, 0.013498188927769661, -0.009484482929110527, -0.0012928555952385068, 0.001458681421354413, -0.005749550648033619, 0.0023912410251796246, 0.004927925765514374, 0.005325299222022295, -0.0012099260929971933, 0.0014540801057592034, -0.006745224818587303, -0.0045193834230303764, -0.01745733432471752, -0.0004385984211694449, 0.009301121346652508, -0.0047347513027489185, 0.006243238225579262, -0.011789637617766857, 0.004212079104036093, 0.004973769653588533, 0.0043050795793533325, 0.00004381697726785205, 0.0003182101936545223, 0.006886376067996025, 0.01199591625481844, -0.0064804465509951115, 0.0023123754654079676, 0.001888033002614975, -0.001939492067322135, -0.0002967792679555714, 0.006766926031559706, -0.007223955821245909, -0.006290149409323931, 0.0032425944227725267, 0.003971516620367765, -0.00029723174520768225, -0.0033058547414839268, -0.007957423105835915, -0.002762676915153861, 0.003010523971170187, -0.007021769415587187, 0.00607495428994298, 0.0005612034583464265, 0.0038896563928574324, -0.006429243832826614, -0.00012266421981621534, -0.004804171621799469, -0.010730561800301075, 0.011030109599232674, -0.0032046211417764425, 0.0011715951841324568, 0.012217370793223381, 0.0043594385497272015, -0.014017622917890549, 0.005275935400277376, 0.009056218899786472, -0.00421013031154871, 0.0018221434438601136, 0.007689059711992741, -0.0037960971239954233, -0.02239169180393219, -0.000530037737917155, -0.013037498109042645, 0.007007446605712175, -0.0030631013214588165, 0.003441664855927229, -0.007833236828446388, 0.005262619350105524, 0.006957103498280048, -0.014791942201554775, -0.004459657706320286, -0.009423214942216873, 0.008626953698694706, -0.0007862831116653979, -0.0016771509544923902, -0.0018685319228097796, -0.001357205561362207, -0.003427203744649887, -0.0025400815065950155, -0.002323473570868373, 0.005094964522868395, 0.0010635731741786003, -0.003148948773741722, 0.0007635069196112454, -0.00506286695599556, -0.0007078538183122873, 0.001201956532895565, -0.009576395153999329, 0.004989704117178917, 0.005131636746227741, -0.0019516369793564081, -0.0036812247708439827, 0.0004893822479061782, -0.0008690875256434083, -0.003964271396398544, -0.010855505242943764, -0.003176216734573245, -0.002248418750241399, -0.0015073984395712614, -0.011530200019478798, -0.00040853623067960143, -0.011363588273525238, 0.004535926040261984, -0.005544914864003658, 0.006550848949700594, 0.004250113386660814, -0.0057060606777668, 0.006282446440309286, -0.0010480383643880486, 0.003958509769290686, 0.0051475814543664455, 0.006592907477170229, -0.0002234234707430005, -0.007798420265316963, -0.011873430572450161, 0.011296123266220093, -0.008151641115546227, 0.0020196419209241867, 0.01329580694437027, 0.004469199106097221, 0.008554406464099884, 0.000014602058399759699, 0.0009692898020148277, 0.003065617522224784, 0.00793436635285616, -0.012749768793582916, 0.003238162724301219, -0.0033450881019234657, -0.00021060288418084383, 0.005241363309323788, -0.004034117795526981, 0.004695603158324957, 0.0095765246078372, 0.0028714581858366728, -0.007067484315484762, -0.0019326969049870968, 0.0005485001602210104, 0.004617280792444944, -0.012527977116405964, 0.0009821803541854024, -0.004595983307808638, -0.004354699980467558, -0.0037859382573515177, -0.003910249099135399, -0.0010499111376702785, 0.004394374787807465, -0.00158170226495713, 0.006649614777415991, 0.0010400140890851617, -0.0034142762888222933, 0.01439316663891077, -0.008780877105891705, -0.005985562223941088, 0.001705380855128169, 0.0020552314817905426, -0.004014313220977783, -0.005182958208024502, -0.003388038370758295, 0.0027181445620954037, 0.003626628313213587, -0.0028354618698358536, -0.007270690519362688, 0.00012336297368165106, 0.0014903710689395666, -0.0062994202598929405, 0.0014094370417296886, 0.012234099209308624, -0.0007312343223020434, 0.005800677929073572, -0.0011727702803909779, -0.00684557156637311, -0.013536098413169384, 0.052591584622859955, -0.0006065993802621961, 0.00645713834092021, 0.004915272817015648, -0.0077735986560583115, -0.001676142681390047, -0.002564196940511465, 0.005926129873842001, -0.009166417643427849, -0.007082788739353418, 0.009570492431521416, -0.002991544548422098, 0.0052378131076693535, -0.001249590190127492, -0.0010848386446014047, 0.014745189808309078, -0.003860561642795801, -0.016465242952108383, -0.01624457910656929, 0.00787488091737032, -0.004029045347124338, -0.007970700040459633, 0.007735095918178558, -0.0030411137267947197, -0.004154847469180822, 0.001303282449953258, 0.004354603122919798, 0.0015487010823562741, -0.001146982773207128, -0.004046297632157803, -0.0017634781543165445, -0.0005241418839432299, 0.0035548594314604998, 0.006865429226309061, 0.009024886414408684, -0.004209539387375116, 0.004663277883082628, -0.004179811105132103, 0.00013471530110109597, -0.002162373159080744, 0.003958110697567463, 0.00704194838181138, -0.0014196422416716814, -0.0023870542645454407, 0.0060896058566868305, 0.0036510147619992495, -0.0004015029699075967, 0.010144547559320927, -0.0006172909052111208, -0.004183489363640547, 0.00882659200578928, 0.008719019591808319, -0.0014902254333719611, 0.005915993358939886, -0.0018465733155608177, 0.004913180135190487, 0.0022416578140109777, -0.00542032765224576, -0.018224233761429787, -0.004555473569780588, 0.006233718246221542, 0.008093420416116714, -0.001340995542705059, 0.0022366191260516644, -0.0018533073598518968, -0.004222244955599308, -0.009012558497488499, -0.007653302513062954, -0.003992079291492701, 0.0008537992835044861, 0.002446455880999565, 0.07254219055175781, -0.004823433235287666, -0.0015731857856735587, -0.00831656064838171, -0.0012331329053267837, -0.0029204145539551973, -0.002730474341660738, 0.0005696035223081708, -0.0020529688335955143, 0.002112695947289467, 0.001022385898977518, -0.007243432570248842, -0.009806973859667778, 0.0020103524439036846, 0.000987754319794476, -0.0030095125548541546, 0.0029054416809231043, 0.008001735433936119, -0.0102942930534482, 0.0013282309519127011, -0.011116696521639824, -0.0049656289629638195, -0.003109628800302744, -0.008596530184149742, -0.00250100065022707, -0.00281510385684669, 0.0031310757622122765, 0.003750125179067254, 0.0061258431524038315, -0.0012206186074763536, 0.006890771444886923, -0.002087260130792856, 0.0006615091115236282, -0.005647820420563221, -0.0007593866903334856, -0.004729428328573704, 0.008407886140048504, 0.0013556837802752852, -0.01086855586618185, -0.005378165747970343, -0.005329183768481016, -0.0007411404512822628, -0.0051561626605689526, 0.004013500642031431, 0.0001297167327720672, 0.004572923760861158, -0.0037635627668350935, -0.00008303023059852421, -0.007271246984601021, 0.0008614831021986902, -0.012021329253911972, 0.0047179097309708595, -0.17840071022510529, 0.010274902917444706, 0.004613050259649754, -0.0039972285740077496, -0.004787696525454521, -0.014728858135640621, -0.008370205760002136, 0.0037886514328420162, 0.01169633399695158, 0.00048546757898293436, -0.002281654393300414, -0.0019535592291504145, 0.005187495611608028, 0.0037347041070461273, 0.0007135625346563756, -0.005196981597691774, 0.00338374893181026, -0.0064338925294578075, 0.0001479275233577937, 0.0024205255322158337, 0.006247194949537516, 0.0099593261256814, 0.0020281809847801924, 0.002182896714657545, -0.0010319151915609837, -0.004553248640149832, 0.006098308600485325, -0.00290451617911458, 0.004467417951673269, -0.011617622338235378, -0.0014034842606633902, -0.005458185449242592, -0.004744124598801136, 0.0004097407800145447, 0.004581278655678034, -0.0026085565332323313, 0.006915479898452759, 0.002514591906219721, -0.009003021754324436, 0.007892855443060398, -0.008867931552231312, 0.026424812152981758, 0.0034350089263170958, 0.008132814429700375, 0.0017102663405239582, -0.005302272271364927, -0.004852661397308111, 0.009401803836226463, 0.002007294213399291, 0.012991612777113914, -0.013831262476742268, -0.004015665501356125, 0.003711323020979762, 0.018403029069304466, -0.0045189508236944675, -0.007491824682801962, -0.007136296946555376, -0.003719175700098276, 0.002896280726417899, 0.009216107428073883, 0.008136658929288387, -0.0027218465693295, 0.008902219124138355, -0.0037243773695081472, -0.019636861979961395, 0.003908752463757992, -0.0036903698928654194, -0.006956756114959717, 0.0010088897543027997, 0.006836926098912954, 0.011056923307478428, 0.0009320075623691082, 0.003405599622055888, -0.0016016688896343112, 0.006045040674507618, -0.0007818699232302606, 0.007667043711990118, -0.0014782657381147146, 0.005256287287920713, -0.008621028624475002, 0.00903620757162571, -0.010405730456113815, -0.0025247347075492144, 0.0016497194301337004, -0.00384696782566607, 0.010573089122772217, 0.0017402364173904061, -0.002677225973457098, -0.0009574685245752335, -0.011651111766695976, -0.0016928112599998713, 0.0028320327401161194, 0.003340973751619458, -0.007908644154667854, 0.0029848674312233925, 0.0006489495281130075, 0.0043495153076946735, 0.006417710799723864, -0.009172650054097176, 0.005723424721509218, 0.003168729366734624, -0.0051294476725161076, 0.0003766871814150363, -0.00677500618621707, 0.0030079963617026806, 0.0021828676108270884, -0.006933532189577818, -0.005878904834389687, 0.003984116017818451, -0.006070626433938742, -0.006930293049663305, 0.00521581806242466, -0.009468220174312592, -0.008142383769154549, -0.0026566351298242807, -0.009800282306969166, -0.0003475525591056794 ]
8aafa8be4338ac950ec6be097349874901cbc17e
3,807
py
Python
tests/test_client.py
mgobec/python-memcached
8ea5fe5fca3a4f0d1201ca9aa50f9701c1baab01
[ "Apache-2.0" ]
1
2019-07-19T18:09:38.000Z
2019-07-19T18:09:38.000Z
tests/test_client.py
mgobec/python-memcached
8ea5fe5fca3a4f0d1201ca9aa50f9701c1baab01
[ "Apache-2.0" ]
null
null
null
tests/test_client.py
mgobec/python-memcached
8ea5fe5fca3a4f0d1201ca9aa50f9701c1baab01
[ "Apache-2.0" ]
null
null
null
import collections import unittest import driver from driver.protocol import * _server = ('localhost', 11211) _dead_retry = 30 _socket_timeout = 3 _max_receive_size = 4096 class MockConnection(object): def __init__(self, server=_server, dead_retry=30, socket_timeout=3): self.server = server self.dead_retry = dead_retry self.socket_timeout = socket_timeout self.closed = True self.socket = None self.send_buffer = collections.deque() self.receive_buffer = collections.deque() self.on_read = None self.on_write = None def open(self): self.closed = False self.socket = True return True def close(self): self.closed = True self.socket = None def send(self, data): if self.on_write is not None: self.on_write() self.send_buffer.append(data) def read(self, size=_max_receive_size): if self.on_read is not None: self.on_read() return self.receive_buffer.popleft() class ClientTests(unittest.TestCase): def setUp(self): self.client = driver.Client(_server) self.mock = MockConnection() self.client._connection = self.mock self.client.connect() def test_initialize_and_connect(self): self.assertFalse(self.mock.closed) def test_disconnect(self): self.client.disconnect() self.assertTrue(self.mock.closed) def test_set_value_without_response(self): self.client.set('testkey', 'testvalue') self.assertEqual(self.mock.send_buffer.pop(), b'set testkey 0 0 9 noreply\r\ntestvalue\r\n') def test_set_value_with_stored_response(self): self.mock.receive_buffer.append(StoreReply.STORED + Constants.END_LINE) response = self.client.set('testkey', 'testvalue', 0, False) self.assertTrue(response) def test_set_value_with_not_stored_response(self): self.mock.receive_buffer.append(StoreReply.NOT_STORED + Constants.END_LINE) response = self.client.set('testkey', 'testvalue', 0, False) self.assertFalse(response) def test_set_value_with_exists_response(self): self.mock.receive_buffer.append(StoreReply.EXISTS + Constants.END_LINE) response = self.client.set('testkey', 'testvalue', 0, False) self.assertFalse(response) def test_set_value_with_error_response(self): self.mock.receive_buffer.append(Errors.ERROR + Constants.END_LINE) with self.assertRaises(driver.DriverUnknownException): self.client.set('testkey', 'testvalue', 0, False) def test_set_value_with_server_error_response(self): self.mock.receive_buffer.append(Errors.SERVER_ERROR + b' Test server error' + Constants.END_LINE) with self.assertRaises(driver.DriverServerException): self.client.set('testkey', 'testvalue', 0, False) def test_set_value_with_client_error_response(self): self.mock.receive_buffer.append(Errors.CLIENT_ERROR + b' Test client error' + Constants.END_LINE) with self.assertRaises(driver.DriverClientException): self.client.set('testkey', 'testvalue', 0, False) def test_set_value_exception(self): error_message = "Test write exception" self.mock.on_write = lambda: _raise_exception(error_message) result = self.client.set('testkey', 'testvalue', 0, False) self.assertFalse(result) def test_get_value_exception(self): error_message = "Test read exception" self.mock.on_read = lambda: _raise_exception(error_message) result = self.client.get('testkey') self.assertIsNone(result) def _raise_exception(message): raise Exception(message)
34.609091
105
0.677699
1
1.8171
[ 0.018008939921855927, -0.001609276281669736, 0.012273961678147316, 0.0049321409314870834, 0.009642764925956726, 0.06626781821250916, -0.012864088639616966, -0.015148615464568138, -0.03679417446255684, -0.010787758976221085, 0.04190992936491966, -0.003077026689425111, 0.05256582796573639, -0.01818712241947651, -0.021772896870970726, -0.002112800255417824, 0.04018707200884819, 0.05245095491409302, 0.0028010476380586624, -0.010900015011429787, -0.024194134399294853, -0.010524686425924301, -0.03204231336712837, -0.04184233397245407, 0.0037593019660562277, 0.014108123257756233, 0.02727687358856201, -0.025816800072789192, 0.013752404600381851, -0.023470576852560043, 0.005743068177253008, 0.03250785917043686, 0.00014166116307023913, 0.05329982191324234, 0.0068709817714989185, 0.019636834040284157, 0.012148726731538773, -0.029756827279925346, 0.012844180688261986, -0.015890583395957947, -0.017372259870171547, -0.03737747296690941, 0.027303792536258698, -0.005488535854965448, -0.008603925816714764, 0.03404585272073746, -0.0038786313962191343, -0.015314649790525436, -0.025491343811154366, -0.026565071195364, -0.025769982486963272, -0.013934412971138954, -0.015721218660473824, -0.018312565982341766, 0.014642228372395039, -0.015683770179748535, 0.011205894872546196, 0.04067934677004814, -0.014892061240971088, 0.01037573255598545, -0.003651669016107917, -0.0014023303519934416, 0.0016241335542872548, 0.046585630625486374, 0.041300833225250244, -0.005393138155341148, -0.011654917150735855, 0.03217460215091705, -0.10155975073575974, 0.036219656467437744, -0.015426045283675194, 0.009412121027708054, -0.0465087853372097, 0.01204818207770586, 0.021573243662714958, -0.015756679698824883, -0.051027145236730576, 0.0020272419787943363, 0.0036603002808988094, 0.020211514085531235, -0.014094233512878418, 0.042620185762643814, -0.00669190613552928, -0.013016908429563046, 0.01580302231013775, 0.03595602139830589, 0.04836924746632576, 0.005593078210949898, 0.03853065147995949, 0.024627266451716423, -0.052607595920562744, -0.016889847815036774, -0.03190089762210846, -0.02584994025528431, -0.000883594446349889, -0.03663625568151474, 0.005041292868554592, 0.004229156766086817, 0.013313911855220795, 0.0004989271401427686, 0.00821686815470457, 0.036828506737947464, 0.02988768182694912, -0.014778392389416695, -0.018845990300178528, 0.02377130277454853, -0.03947272151708603, 0.012470517307519913, 0.006964470725506544, 0.012755253352224827, 0.012082843109965324, 0.006816858425736427, 0.00009688366844784468, -0.032217077910900116, -0.01518044713884592, -0.021953221410512924, 0.016075562685728073, 0.02794073335826397, 0.012723563238978386, -0.008374328725039959, 0.0034308796748518944, 0.008111800998449326, 0.019988302141427994, 0.004239882342517376, -0.03358227387070656, 0.0561097115278244, -0.0022536299657076597, 0.03946628421545029, 0.037032440304756165, 0.017840471118688583, 0.015317004173994064, 0.04456964135169983, 0.0014025617856532335, -0.025867335498332977, 0.01859787106513977, 0.03659667447209358, -0.052915554493665695, 0.014480656944215298, -0.05861416831612587, -0.010570192709565163, 0.020688233897089958, -0.03571781888604164, 0.03366050869226456, -0.008241203613579273, 0.00718175433576107, -0.039039358496665955, -0.008864453993737698, 0.00809990894049406, -0.028831755742430687, -0.026858191937208176, -0.0019120116485282779, 0.031114785000681877, -0.0022333094384521246, 0.048008933663368225, -0.029509160667657852, -0.009906571358442307, -0.005350029561668634, 0.0097190635278821, 0.005154370795935392, -0.0007849920075386763, -0.01567160338163376, 0.016544442623853683, -0.005289076361805201, -0.010837824083864689, -0.0119905611500144, -0.008750887587666512, -0.01180408988147974, 0.05893738567829132, -0.02295777015388012, -0.02988867461681366, 0.023321913555264473, -0.04294685646891594, 0.004535267595201731, -0.01993459276854992, -0.0672193393111229, -0.030386926606297493, 0.003431267337873578, 0.025887247174978256, 0.041968535631895065, -0.005266955122351646, 0.014024169184267521, -0.014832036569714546, 0.028141412883996964, 0.04720648005604744, 0.00035811192356050014, -0.02019604668021202, -0.03991466760635376, -0.021259604021906853, 0.010400530882179737, 0.004412375390529633, 0.008538855239748955, 0.031070370227098465, -0.052076008170843124, -0.004152515437453985, 0.038690898567438126, -0.005515238735824823, 0.01689620316028595, -0.027766995131969452, -0.025749998167157173, -0.004530740901827812, 0.021550090983510017, -0.023812657222151756, -0.039313413202762604, 0.03282956779003143, 0.026013357564806938, 0.033884644508361816, -0.676223874092102, 0.015718992799520493, 0.040327273309230804, 0.0012639503693208098, 0.047399502247571945, 0.05677103251218796, -0.04867793992161751, 0.010459176264703274, -0.045937325805425644, -0.024582089856266975, -0.016603121533989906, -0.0436653271317482, -0.056204382330179214, 0.01578950136899948, 0.01894606277346611, -0.011213921941816807, 0.03384323790669441, 0.005189898423850536, -0.012620760127902031, 0.015268401242792606, 0.05618249624967575, 0.041861049830913544, -0.0038282060995697975, -0.0037546635139733553, 0.009775964543223381, -0.005872161127626896, -0.011907746084034443, 0.015174985863268375, -0.043173834681510925, -0.012755713425576687, 0.01824025809764862, -0.003820221871137619, 0.02420915849506855, -0.037027258425951004, 0.04393302649259567, -0.004100679885596037, 0.025821268558502197, -0.000533127342350781, 0.01442734431475401, 0.0010098348138853908, 0.007534208707511425, 0.01234588772058487, 0.03374024108052254, -0.053029343485832214, -0.025868797674775124, -0.024493370205163956, -0.016956744715571404, -0.011724391020834446, -0.0005046380683779716, 0.03259757161140442, -0.02251562289893627, 0.03148626163601875, 0.03683333471417427, -0.006880054250359535, -0.020978981629014015, 0.02885504625737667, 0.0024955410044640303, 0.018679821863770485, -0.004005278926342726, -0.0021939317230135202, 0.014756940305233002, 0.0181187242269516, -0.004588280338793993, 0.03348420932888985, -0.026590917259454727, 0.012726685032248497, 0.01678546704351902, -0.04713015630841255, -0.038837432861328125, -0.007287782616913319, -0.041881293058395386, -0.0013885758817195892, -0.006649147253483534, 0.029104838147759438, -0.02074498124420643, -0.003464202396571636, 0.004208611324429512, 0.02041790820658207, -0.008602917194366455, -0.017390793189406395, 0.005674467422068119, -0.014482163824141026, 0.040542904287576675, 0.0007216357626020908, -0.024142524227499962, -0.03806821256875992, 0.016789855435490608, 0.003963302820920944, -0.004157240502536297, 0.02927323244512081, 0.03300515189766884, 0.0012751519680023193, -0.010135145857930183, 0.0075486465357244015, 0.035290151834487915, -0.017087716609239578, -0.023187924176454544, 0.013212042860686779, 0.027271583676338196, -0.009028865024447441, -0.0289186742156744, 0.03502601385116577, -0.03708973154425621, -0.007413581945002079, 0.019381476566195488, 0.029001664370298386, 0.029639093205332756, -0.018239464610815048, 0.05880100280046463, -0.09396965801715851, -0.003666828852146864, -0.03166617825627327, 0.03666269779205322, 0.049118779599666595, 0.007803713902831078, -0.005820496939122677, -0.015415339730679989, 0.02588350512087345, 0.030525878071784973, 0.03170255199074745, -0.011239279992878437, 0.013963359408080578, 0.01633044332265854, 0.008552268147468567, 0.016217408701777458, 0.008236736059188843, -0.012681783176958561, -0.038904573768377304, 0.0038440567441284657, -0.023960407823324203, -0.05632162094116211, 0.02881227247416973, -0.006524565629661083, -0.0223073773086071, -0.012990588322281837, 0.025537045672535896, -0.056155405938625336, -0.03284526616334915, 0.005330671556293964, 0.021165162324905396, -0.0034850758966058493, -0.011472480371594429, -0.001529706409201026, -0.05057619884610176, 0.029964134097099304, 0.03227100893855095, 0.010249504819512367, 0.01876024901866913, 0.04601674526929855, -0.05823557823896408, -0.018737470731139183, 0.026476098224520683, -0.024318374693393707, -0.011103129014372826, -0.050026778131723404, 0.012128813192248344, -0.053166814148426056, 0.013454509899020195, -0.010715989395976067, 0.029538441449403763, -0.02059837058186531, 0.017541993409395218, -0.04255228862166405, 0.01732374168932438, 0.027083327993750572, -0.02846839465200901, 0.02243693545460701, 0.0019919753540307283, -0.01583223044872284, 0.024092406034469604, 0.034812770783901215, -0.012451749294996262, -0.006709394510835409, 0.007747641298919916, 0.024175483733415604, -0.017215687781572342, 0.007105761207640171, -0.031024934723973274, -0.02278709225356579, -0.02544250525534153, 0.01764521934092045, 0.015404782257974148, -0.005128007847815752, 0.006778075825423002, -0.016564644873142242, 0.0075460816733539104, 0.004970326088368893, -0.02421647123992443, 0.0037086596712470055, 0.0051751877181231976, 0.03798288106918335, 0.003700284520164132, -0.04400690644979477, -0.02675953321158886, -0.030040284618735313, -0.0203128419816494, 0.0399748757481575, 0.004429724533110857, 0.032381054013967514, -0.02024191804230213, -0.007713609840720892, -0.028477493673563004, -0.03868963569402695, -0.008596510626375675, -0.03266818821430206, 0.03648838773369789, 0.005031229462474585, 0.008522593416273594, 0.019597230479121208, -0.03074873797595501, 0.015102926641702652, 0.008844011463224888, 0.0021987915970385075, 0.028231525793671608, -0.028111977502703667, 0.023279592394828796, 0.0062777139246463776, 0.01126392837613821, -0.05586123839020729, -0.01504038367420435, -0.02047955058515072, -0.028441810980439186, -0.020511437207460403, 0.00359528255648911, 0.0017221273155882955, -0.012540745548903942, -0.03446197882294655, 0.0023360643535852432, -0.0005347065743990242, 0.004865659400820732, -0.010521859861910343, 0.019751420244574547, 0.03816676139831543, -0.02059929445385933, 0.008738957345485687, 0.05573635175824165, -0.03705328702926636, -0.02909986861050129, 0.008795012719929218, -0.009827337227761745, 0.042323801666498184, -0.05113234370946884, -0.01612064614892006, -0.00011980580893578008, 0.030219050124287605, -0.0040570879355072975, 0.029152166098356247, 0.005438994150608778, 0.023283449932932854, 0.004167285747826099, -0.01773488149046898, 0.020375169813632965, -0.010850701481103897, -0.03193812817335129, 0.02438051998615265, 0.010821258649230003, -0.011055093258619308, 0.009202852845191956, 0.013518847525119781, 0.002027304843068123, 0.015056602656841278, -0.09396576136350632, -0.024055493995547295, -0.006445269100368023, 0.002052629366517067, -0.017671123147010803, 0.00942669901996851, -0.08104262501001358, -0.03502626344561577, 0.021617339923977852, -0.018943846225738525, -0.029669225215911865, 0.01187202986329794, -0.008426574990153313, 0.030121978372335434, -0.0089506134390831, 0.00833027996122837, 0.001593785360455513, -0.04364049807190895, -0.030064934864640236, -0.025607483461499214, -0.030031831935048103, 0.012589645572006702, 0.04262540489435196, -0.0009481886518187821, 0.0037659977097064257, -0.03362765163183212, -0.012963063083589077, -0.047848280519247055, 0.020811287686228752, 0.01441087108105421, -0.02833782322704792, 0.028784452006220818, 0.024273505434393883, -0.004760492593050003, -0.0011337120085954666, 0.0059996070340275764, -0.036155302077531815, 0.053829602897167206, 0.025039907544851303, 0.03696464002132416, 0.016102442517876625, -0.04724028706550598, -0.021358199417591095, -0.021841926500201225, -0.022591887041926384, -0.031192589551210403, 0.008329303935170174, 0.03005092777311802, -0.0066750990226864815, 0.025242967531085014, 0.012252864427864552, 0.011725233867764473, 0.02102208510041237, 0.013424539007246494, 0.010939971543848515, 0.046817902475595474, 0.003613589331507683, 0.008237428031861782, 0.04408431798219681, 0.014513524249196053, -0.007805323228240013, -0.0027505666948854923, 0.0003133365244138986, 0.012468256056308746, 0.0018704362446442246, -0.0003000401775352657, -0.0013856299920007586, -0.006427825428545475, 0.02722851000726223, -0.030183235183358192, -0.04973116144537926, 0.019000105559825897, 0.004999388940632343, -0.0034606854896992445, -0.007348996587097645, -0.007916633039712906, 0.014948917552828789, 0.01912829279899597, 0.00501772528514266, 0.021399229764938354, 0.024862373247742653, -0.011594400741159916, 0.006822848226875067, 0.00387170328758657, 0.019524721428751945, -0.016709106042981148, 0.0526261106133461, -0.0035805406514555216, 0.03598352149128914, 0.01329122856259346, 0.01065081637352705, 0.017731910571455956, 0.019976746290922165, 0.02732151933014393, 0.0019626987632364035, 0.02179340086877346, 0.02668558433651924, 0.012756547890603542, 0.010789762251079082, -0.014780688099563122, 0.023215075954794884, -0.053289081901311874, -0.0005152576486580074, 0.00034230377059429884, -0.014465320855379105, 0.0412297397851944, -0.02917422167956829, -0.00848390907049179, 0.0050787548534572124, -0.01366248819977045, -0.014504365622997284, -0.022390788421034813, 0.02191196009516716, 0.025307858362793922, -0.003569967346265912, 0.009593761526048183, 0.011097254231572151, -0.02113298699259758, -0.0036297072656452656, -0.0010718441335484385, -0.03393251448869705, -0.03367499262094498, -0.01776963099837303, 0.013804552145302296, -0.029665792360901833, -0.02360621467232704, -0.010835668072104454, -0.0030810392927378416, -0.017244139686226845, -0.011183060705661774, -0.04103534296154976, 0.02841097302734852, 0.028967738151550293, -0.02544506825506687, 0.009608357213437557, -0.007933354936540127, -0.01624005287885666, 0.0022173684556037188, 0.0013366505736485124, -0.009035672061145306, -0.00280156172811985, 0.006796642206609249, 0.016260892152786255, -0.02397822216153145, -0.014148595742881298, 0.020520957186818123, -0.04290077090263367, -0.007642323151230812, -0.031825579702854156, 0.02402309700846672, -0.009992359206080437, -0.0005795180913992226, -0.020383117720484734, -0.027804182842373848, 0.02560492604970932, -0.03662414103746414, -0.027675965800881386, 0.008974019438028336, 0.028443679213523865, 0.025048211216926575, -0.03549253195524216, -0.017088081687688828, 0.02735554240643978, -0.016904374584555626, -0.0209991242736578, 0.0029665399342775345, 0.009858019649982452, 0.014130431227385998, 0.012524186633527279, 0.000263120949966833, 0.019005732610821724, -0.02781588025391102, 0.0037251480389386415, 0.021755099296569824, -0.0035082073882222176, -0.0023292808327823877, -0.025918157771229744, -0.05130103603005409, 0.028834372758865356, 0.009418402798473835, 0.000026348956453148276, -0.027650129050016403, 0.02094118297100067, 0.009042104706168175, -0.128083735704422, 0.03784186765551567, 0.008901365101337433, -0.01650698482990265, -0.008355998434126377, -0.008098230697214603, 0.05303855985403061, -0.001418913365341723, 0.01943938620388508, 0.03115355223417282, 0.022975534200668335, 0.04781430959701538, 0.0016870156396180391, -0.002664654515683651, -0.01200856827199459, -0.0020214940886944532, 0.016142237931489944, -0.0039741648361086845, 0.012458664365112782, -0.012669524177908897, 0.010446618311107159, -0.03211496025323868, -0.03884207829833031, -0.012914147228002548, -0.008992566727101803, -0.0750640258193016, 0.004901024047285318, -0.002552658785134554, 0.034067314118146896, 0.0027102199383080006, -0.010328803211450577, -0.03441625088453293, 0.0036282276269048452, 0.021730508655309677, 0.041060760617256165, -0.05512601509690285, 0.027979372069239616, 0.013417910784482956, -0.012590481899678707, 0.03804929554462433, -0.00438300333917141, -0.004809177480638027, 0.05267997831106186, -0.01019485853612423, 0.017670923843979836, -0.006077591795474291, -0.010722951032221317, 0.013806832022964954, 0.00028750154888257384, 0.009766173548996449, -0.01773606799542904, 0.038738444447517395, -0.037780724465847015, 0.022686682641506195, -0.01963578723371029, 0.037157200276851654, -0.03248533979058266, 0.003455281490460038, -0.042108021676540375, 0.009531100280582905, -0.0021306092385202646, 0.08080333471298218, 0.016128255054354668, -0.052206575870513916, -0.019942179322242737, 0.026753637939691544, -0.009903505444526672, -0.03817994147539139, -0.006026371382176876, 0.016437657177448273, 0.009816115722060204, 0.040435243397951126, 0.006823101080954075, 0.023024948313832283, -0.005656786262989044, 0.0030432683415710926, 0.032861337065696716, -0.007303858175873756, -0.006024209316819906, -0.0062324791215360165, 0.017986809834837914, -0.0776364654302597, -0.0278729647397995, 0.005416256375610828, 0.038674768060445786, 0.046233855187892914, -0.042088914662599564, -0.022382184863090515, -0.007278719916939735, 0.027004271745681763, -0.07788286358118057, 0.04908113554120064, 0.0261641014367342, -0.020882565528154373, 0.004184007178992033, 0.020790254697203636, 0.035640615969896317, -0.005411374382674694, 0.001978674903512001, -0.041407328099012375, -0.04476310312747955, -0.013837101869285107, 0.013366730883717537, 0.007839863188564777, -0.009944056160748005, -0.05174852907657623, -0.00228663207963109, 0.017178218811750412, -0.025823518633842468, -0.035238053649663925, 0.008253165520727634, 0.009629055857658386, 0.00017813517479225993, 0.03570413216948509, -0.04773174598813057, -0.017454208806157112, 0.013577897101640701 ]
8ab02ecbf400acde29e043cc50c322067db1b570
1,654
py
Python
GREYATOM-PROJECT----DATA--WRANGLING-WITH-PANDAS/code.py
Preethinaidu14/greyatom-python-for-data-science
5b758dd6123d9fc50031c43771b30d69e366c044
[ "MIT" ]
null
null
null
GREYATOM-PROJECT----DATA--WRANGLING-WITH-PANDAS/code.py
Preethinaidu14/greyatom-python-for-data-science
5b758dd6123d9fc50031c43771b30d69e366c044
[ "MIT" ]
null
null
null
GREYATOM-PROJECT----DATA--WRANGLING-WITH-PANDAS/code.py
Preethinaidu14/greyatom-python-for-data-science
5b758dd6123d9fc50031c43771b30d69e366c044
[ "MIT" ]
null
null
null
# -------------- # Import packages import numpy as np import pandas as pd from scipy.stats import mode path # code starts here bank = pd.read_csv(path) categorical_var = bank.select_dtypes(include = 'object') print(categorical_var) numerical_var = bank.select_dtypes(include = 'number') print(numerical_var) # code ends here # -------------- # code starts here banks = bank.drop('Loan_ID',axis = 1) print(banks) print(banks.isnull().sum()) bank_mode = banks.mode().iloc[0] banks = banks.fillna(bank_mode) #code ends here # -------------- # Code starts here avg_loan_amount = banks.pivot_table(index=['Gender','Married','Self_Employed'],values = 'LoanAmount') # code ends here # -------------- # code starts here loan_approved_se = ((banks['Self_Employed']=='Yes') & (banks['Loan_Status']=='Y')).value_counts() #print(loan_approved_se) loan_approved_nse = ((banks['Self_Employed']=='No') & (banks['Loan_Status']=='Y')).value_counts() print(loan_approved_nse) Loan_Status = 614 percentage_se = (56/Loan_Status)*100 percentage_nse = (366/Loan_Status)*100 # code ends here # -------------- # code starts here loan_term = banks['Loan_Amount_Term'].apply (lambda x : int(x)/12) print(loan_term.value_counts()) big_loan = [i for i in loan_term if i >= 25] big_loan_term = len(big_loan) print(big_loan_term) #[loan_term.value_counts()[i] for i in range(len(loan_terms)) if loan_term.value_counts().index[i] >= 25] # code ends here # -------------- # code starts here loan_groupby = banks.groupby('Loan_Status') loan_groupby = loan_groupby['ApplicantIncome','Credit_History'] mean_values = loan_groupby.mean() # code ends here
19.458824
105
0.688634
1
1.2651
[ 0.0004054616729263216, 0.025037379935383797, 0.0081681739538908, 0.000008453367627225816, 0.00394681328907609, -0.005426121409982443, -0.011529995128512383, 0.004516946617513895, -0.008606744930148125, 0.00269494135864079, 0.002227734075859189, 0.002227522199973464, 0.00847824476659298, -0.016381684690713882, 0.00043724809074774384, 0.018731094896793365, -0.053458165377378464, 0.002965864958241582, -0.004114173818379641, 0.002012860029935837, -0.009635278023779392, 0.0094742551445961, 0.00890150386840105, 0.006647032219916582, 0.004765014164149761, -0.002036911668255925, 0.011612668633460999, 0.001869978616014123, -0.009945468045771122, -0.0057285320945084095, -0.000363830040441826, -0.0026751752011477947, -0.007293200120329857, -0.009068898856639862, 0.004005294293165207, -0.002292477060109377, 0.0005832756869494915, -0.02069174312055111, 0.01527660433202982, -0.003920750226825476, -0.005797265097498894, -0.013567234389483929, 0.002219022251665592, 0.0064515587873756886, -0.010353692807257175, 0.001954029779881239, -0.003964670468121767, 0.00047805390204302967, -0.011608363129198551, 0.004099083133041859, -0.009825407527387142, 0.004224715288728476, 0.013801632449030876, 0.0035105235874652863, -0.005562267731875181, -0.005982773844152689, 0.012341261841356754, 0.0006728627486154437, -0.0118230190128088, -0.001744370791129768, -0.004318522289395332, -0.0028814503457397223, 0.004735872615128756, 0.001935840817168355, -0.01608438789844513, -0.006175779737532139, -0.0058548105880618095, 0.0025485653895884752, -0.0007659083930775523, 0.006741418968886137, 0.00118871103040874, 0.0017768258694559336, 0.008247227407991886, 0.0029720815364271402, 0.002779665170237422, -0.0016443863278254867, -0.0004800626775249839, 0.0019572048913687468, 0.007987579330801964, 0.0028424893971532583, 0.007251666393131018, -0.009924001060426235, 0.004809225909411907, 0.010595028288662434, 0.011779211461544037, 0.010131553746759892, 0.020123213529586792, -0.012021899223327637, 0.04534738138318062, 0.0077036237344145775, -0.008460554294288158, 0.002221595961600542, -0.010767613537609577, -0.0027872752398252487, -0.003397054271772504, -0.02901320718228817, -0.0006561320042237639, -0.005318874958902597, -0.002857956336811185, 0.001758851227350533, 0.00015877738769631833, 0.00941196084022522, 0.0009905649349093437, -0.0007727031479589641, -0.005380920600146055, 0.011088214814662933, -0.00915884505957365, -0.00433371914550662, 0.009044674225151539, 0.004964590072631836, -0.013557197526097298, -0.0012629134580492973, 0.00147993303835392, -0.01422130223363638, 0.0057836612686514854, 0.00003677593122120015, -0.003919185139238834, 0.05844879150390625, -0.003048620419576764, 0.0024108528159558773, -0.00562910595908761, 0.0013343456666916609, 0.003149889875203371, 0.008347098715603352, 0.008781397715210915, -0.003326413920149207, 0.012859421782195568, 0.007630390580743551, 0.004368864465504885, 0.010788376443088055, -0.00003857654519379139, 0.0070102764293551445, -0.0036553028039634228, -0.001465503708459437, 0.002640928141772747, -0.0078504029661417, 0.008393220603466034, -0.0030263522639870644, -0.007957689464092255, 0.001947637414559722, -0.0007058728951960802, -0.010343612171709538, 0.0008190576918423176, -0.0035336294677108526, 0.002837104257196188, -0.011365656740963459, -0.0018210075795650482, -0.0055617387406528, -0.004800008609890938, 0.0037846253253519535, 0.009922360070049763, 0.0036422123666852713, 0.002398446435108781, -0.008198574185371399, -0.011547686532139778, -0.00034195760963484645, -0.0038921695668250322, 0.00171361502725631, 0.008231484331190586, 0.0019740331918001175, -0.010178784839808941, -0.0015603172359988093, 0.0038242063019424677, 0.004110122565180063, -0.0010587641736492515, 0.0010269612539559603, -0.00817916914820671, 0.007946922443807125, -0.002577588427811861, 0.007287453860044479, 0.012345220893621445, -0.0032489371951669455, -0.0002293415309395641, -0.00003724711496033706, 0.002659520599991083, -0.0007130881422199309, 0.006198136135935783, 0.01145203784108162, -0.004387993831187487, -0.005698420573025942, 0.0036130358930677176, 0.0041121309623122215, 0.0077513037249445915, 0.00565422372892499, -0.0016797815915197134, 0.0027601425535976887, -0.006140181329101324, -0.0009177639731206, 0.003655001986771822, -0.0042222957126796246, 0.006677423603832722, 0.0028797907289117575, -0.011793396435678005, -0.00752341328188777, -0.0006495843408629298, -0.007276854943484068, 0.0014397951308637857, 0.0157688707113266, 0.009587714448571205, -0.00041393606807105243, 0.00442141480743885, -0.013337408192455769, -0.0010653802892193198, 0.00514708086848259, 0.0035338348243385553, -0.01373249851167202, -0.9570290446281433, 0.0062964726239442825, 0.004273943603038788, -0.000022073389118304476, 0.005301440600305796, 0.004980261903256178, 0.004012201447039843, 0.0036523176822811365, 0.014567523263394833, -0.008570902049541473, -0.006718984805047512, -0.012383576482534409, -0.012658514082431793, -0.001832509064115584, -0.009206117130815983, -0.0018617938039824367, -0.005608652718365192, -0.007251725997775793, -0.0010371130192652345, -0.0028046201914548874, -0.002452074782922864, 0.010510599240660667, -0.0038455890025943518, 0.00495110871270299, 0.0039979214780032635, 0.002813750645145774, -0.006334293633699417, -0.003576047718524933, -0.0042351302690804005, -0.003121672198176384, -0.007388237398117781, -0.014697902835905552, -0.004358050413429737, 0.00016776063421275467, 0.009662683121860027, 0.0019198020454496145, 0.011122548021376133, -0.0035837821196764708, 0.0007644658326171339, -0.009744467213749886, 0.0065396628342568874, 0.0007818368030712008, 0.004111163783818483, -0.029132388532161713, -0.0007633098866790533, -0.001855192007496953, -0.007388032041490078, 0.009004066698253155, 0.0007679761620238423, 0.0005964336451143026, -0.00627558771520853, -0.006231309846043587, 0.007056369911879301, -0.00852516945451498, 0.0033640526235103607, -0.005842371843755245, -0.009526093490421772, -0.0009746148716658354, -0.006901550572365522, -0.0000732166226953268, 0.003878191811963916, -0.0025662786792963743, -0.0048294165171682835, -0.004467890132218599, 0.006827591918408871, 0.0020548482425510883, 0.0009546154760755599, -0.017599528655409813, -0.0060701570473611355, 0.001550707733258605, -0.00029294408159330487, -0.004357852041721344, -0.004335635341703892, 0.004600426647812128, -0.009161174297332764, 0.00432706018909812, 0.0028132584411650896, 0.0015899661229923368, -0.01059396006166935, -0.0011699172900989652, -0.009082430973649025, -0.009942186065018177, 0.003026653314009309, -0.005405772011727095, -0.0045629446394741535, -0.0005458219675347209, -0.001000011689029634, 0.006015608087182045, -0.00477117532864213, 0.0002542887523304671, 0.012643263675272465, -0.003664960153400898, -0.008163219317793846, 0.0065589663572609425, 0.006479201372712851, 0.0020557900425046682, -0.0032483250834047794, 0.002470646519213915, 0.008040429092943668, 0.01094108261168003, 0.0010998282814398408, 0.0022391381207853556, -0.0022158438805490732, 0.010546378791332245, -0.0012607347453013062, -0.0006716832285746932, -0.00457400968298316, -0.0008203171310015023, -0.0033195174764841795, -0.0033886320888996124, -0.002555298386141658, -0.002557973377406597, -0.012042938731610775, -0.011179073713719845, -0.002634358825162053, 0.0016092316946014762, 0.00228870683349669, -0.005235232412815094, 0.0005846429849043489, 0.0005004603881388903, 0.007149053737521172, 0.001983882859349251, -0.0030215049628168344, -0.0011143545852974057, -0.0017705039354041219, -0.004527287557721138, 0.014767726883292198, -0.01188228651881218, 0.0062224604189395905, -0.0022702778223901987, -0.015247865580022335, 0.007217645179480314, 0.008991892449557781, -0.008989286608994007, -0.001122876419685781, 0.001422170433215797, 0.005524319596588612, 0.0027793541084975004, -0.00628536706790328, -0.0006585089140571654, -0.017788346856832504, -0.0007824324420653284, 0.01812894269824028, 0.002963103586807847, 0.011170738376677036, 0.01334769930690527, -0.003991739824414253, 0.0007153904880397022, 0.009813198819756508, 0.004104965832084417, 0.01372596900910139, -0.011048005893826485, -0.00014259785530157387, 0.002886951668187976, -0.006465876940637827, 0.00014048484445083886, 0.007118753623217344, 0.0031914105638861656, -0.00564159220084548, 0.0023516500368714333, -0.008238476701080799, -0.005681398790329695, -0.017232073470950127, -0.003469436662271619, 0.004094151314347982, -0.007461173459887505, 0.004307383205741644, -0.011102060787379742, 0.004535258281975985, 0.004874780774116516, 0.0031669591553509235, 0.0006211817963048816, 0.0007880401681177318, 0.006356952711939812, 0.01437461469322443, -0.003402020549401641, 0.0000418589188484475, 0.005103160627186298, -0.0032954546622931957, 0.003876802744343877, 0.011487976647913456, -0.008590994402766228, -0.004372823517769575, 0.0022446580696851015, 0.0031530065461993217, 0.0013256423408165574, -0.003665350377559662, -0.009242276661098003, -0.005217108875513077, 0.0019753549713641405, -0.00664192158728838, 0.0035436449106782675, -0.0023832828737795353, 0.002980739576742053, -0.008448253385722637, -0.001612048246897757, -0.00010126906272489578, -0.014189202338457108, 0.009768628515303135, -0.004190393257886171, 0.003516953904181719, 0.01309933140873909, 0.0055237384513020515, -0.012984158471226692, 0.005988331977277994, 0.009563966654241085, -0.004243349656462669, 0.001871797489002347, 0.0071850004605948925, -0.006511259824037552, -0.021202238276600838, 0.00014087528688833117, -0.015324068255722523, 0.004862351808696985, -0.0033571352250874043, 0.001750722760334611, -0.008879970759153366, 0.007725907489657402, 0.008143424056470394, -0.011901810765266418, -0.007282721810042858, -0.009020459838211536, 0.010317265056073666, 0.0009037064155563712, -0.0018379336688667536, -0.0040259636007249355, -0.0008403761894442141, -0.00248618982732296, -0.003382906084880233, -0.002255671424791217, 0.0035062760580331087, 0.0015736334025859833, -0.0012575145810842514, 0.002442307770252228, -0.0007935338071547449, 0.0008488621679134667, -0.00046238137292675674, -0.011375286616384983, 0.0006517929723486304, 0.004182120785117149, -0.0007795484270900488, -0.0032052749302238226, 0.0033003606367856264, -0.0015561379259452224, -0.009437518194317818, -0.010769348591566086, -0.0027488688938319683, -0.0046325745061039925, -0.004978340584784746, -0.011801996268332005, -0.0029091148171573877, -0.007659909315407276, 0.00835396721959114, -0.0058578685857355595, 0.00903941411525011, 0.0034677458461374044, -0.004103757906705141, 0.0033794718328863382, -0.004359869286417961, 0.005310674663633108, 0.0022652072366327047, 0.0052496762946248055, 0.0000984933358267881, -0.005004604812711477, -0.0072844866663217545, 0.009824785403907299, -0.00892383698374033, 0.0013540361542254686, 0.014275395311415195, 0.0034939900506287813, 0.007294954266399145, -0.0007585026323795319, 0.0019479310140013695, 0.002091280184686184, 0.007843739353120327, -0.010979639366269112, 0.0027836905792355537, -0.004828763660043478, -0.0014358112821355462, 0.006828795652836561, -0.004962502978742123, 0.003924246411770582, 0.011243809014558792, 0.004188744816929102, -0.0075803715735673904, -0.00307963858358562, 0.002208816586062312, 0.0026372247375547886, -0.01222760509699583, 0.0020635363180190325, -0.00036469867336563766, -0.0052922447212040424, -0.0009409326012246311, -0.0003066479985136539, -0.0019921432249248028, 0.0044212122447788715, -0.0010531131410971284, 0.008436283096671104, 0.0008631279924884439, -0.002616032725200057, 0.015074159018695354, -0.004952746443450451, -0.004924483597278595, 0.004244957584887743, 0.0031941195484250784, -0.002420800505205989, -0.006257582455873489, -0.0038898757193237543, 0.00040735650691203773, 0.005909356754273176, -0.005276238080114126, -0.005497985053807497, -0.0023388839326798916, 0.0019364820327609777, -0.009293776005506516, 0.00008832254388835281, 0.010484589263796806, -0.006292896345257759, 0.007267585024237633, -0.00012136754230596125, -0.005395143758505583, -0.01081036776304245, 0.05571415647864342, 0.0010416213190183043, 0.0007678644033148885, 0.005038405302911997, -0.007327050901949406, -0.00034405244514346123, -0.004660659935325384, 0.008290575817227364, -0.006762020289897919, -0.004947647452354431, 0.008792072534561157, -0.005259186960756779, 0.004004346672445536, 0.0026292677503079176, -0.0015256877522915602, 0.019147194921970367, -0.0040060351602733135, -0.017872510477900505, -0.016538383439183235, 0.006709309760481119, -0.004700995981693268, -0.003722750348970294, 0.009426438249647617, -0.0037892719265073538, -0.0020238098222762346, 0.002243536990135908, 0.0037074966821819544, -0.0014499482931569219, -0.0007465507951565087, -0.000668527907691896, -0.000289403076749295, -0.002890822011977434, 0.0016810726374387741, 0.005804888438433409, 0.009880424477159977, 0.0007301837322302163, 0.0024325682315975428, -0.00013163636322133243, -0.0010696353856474161, -0.0016962176887318492, 0.00829317606985569, 0.006369563285261393, -0.0008050723117776215, 0.00006327816663542762, 0.006948043126612902, 0.004119832534343004, -0.00014069089957047254, 0.012454080395400524, 0.0006716680945828557, -0.005066082812845707, 0.006357874721288681, 0.006797645706683397, -0.000841515779029578, 0.0086371386423707, -0.0009735841886140406, 0.006228797137737274, 0.0013497971231117845, -0.006881918292492628, -0.010094122029840946, -0.0012248491402715445, 0.007801891770213842, 0.007467276882380247, -0.0003286318387836218, -0.0027451529167592525, 0.0010490607237443328, -0.0019036015728488564, -0.006825347431004047, -0.007030788343399763, -0.0018911341903731227, 0.00008556696411687881, 0.003702769288793206, 0.07154250890016556, -0.008040420711040497, -0.0009269805159419775, -0.009501866064965725, -0.0013610091991722584, 0.0009094348060898483, -0.000508225872181356, -0.0006478814175352454, -0.001608644612133503, -0.0016911423299461603, 0.0052191754803061485, -0.007873709313571453, -0.010746930725872517, 0.0016546939732506871, 0.0028307244647294283, -0.0017203218303620815, 0.0050572785548865795, 0.005277860909700394, -0.007042352110147476, 0.0004978241049684584, -0.012064841575920582, 0.0013209120370447636, -0.001075055217370391, -0.008234827779233456, -0.004506384022533894, -0.0037289028987288475, 0.004371024668216705, 0.004342402797192335, 0.006317518185824156, -0.0030511128716170788, 0.004645614419132471, -0.004170426167547703, -0.0013600527308881283, -0.0043037389405071735, -0.00029981316765770316, -0.006112481467425823, 0.009060573764145374, 0.0004889590782113373, -0.011106140911579132, -0.004574598744511604, 0.0012710927985608578, -0.002312585012987256, -0.00788121484220028, 0.004725950304418802, -0.0005781616782769561, 0.0074524483643472195, -0.0026535759679973125, 0.0012700175866484642, -0.0050274040549993515, 0.0009256878402084112, -0.013737844303250313, 0.004874035250395536, -0.17523054778575897, 0.011297374032437801, 0.002274218015372753, -0.004651245661079884, -0.004045412875711918, -0.014306847006082535, -0.00679789949208498, 0.003158027771860361, 0.011001728475093842, 0.0035489038564264774, -0.0008829230791889131, 0.0006154085858725011, 0.005017539486289024, 0.002167528960853815, -0.004238516092300415, -0.0008019726374186575, 0.0048299916088581085, -0.003246923442929983, 0.003085613949224353, 0.0026835245080292225, 0.0033403392881155014, 0.008751637302339077, 0.0005067265592515469, 0.0018411738565191627, -0.00017119914991781116, -0.0061630140990018845, 0.005115007050335407, -0.0006165211671032012, 0.00789602566510439, -0.009975907392799854, -0.005938194692134857, -0.004379486199468374, -0.0038154388312250376, 0.0003543687635101378, 0.002177339978516102, -0.0010609898017719388, 0.009490570984780788, 0.000933605944737792, -0.007275571580976248, 0.007484145928174257, -0.005555914249271154, 0.030391963198781013, 0.004699718207120895, 0.0053565180860459805, -0.002217050176113844, -0.006564577575773001, -0.005610813852399588, 0.008210236206650734, 0.0034425922203809023, 0.01425121258944273, -0.013602258637547493, -0.0007073418237268925, 0.0036755462642759085, 0.01861257292330265, -0.006374754477292299, -0.009505197405815125, -0.00867674220353365, -0.0026264663320034742, 0.002485297154635191, 0.00986430887132883, 0.010489451698958874, -0.0048116776160895824, 0.008538051508367062, -0.0020269083324819803, -0.023502014577388763, 0.0043625738471746445, -0.0038678296841681004, -0.006421212572604418, 0.0008127876208163798, 0.00680770305916667, 0.011284575797617435, -0.0048568472266197205, 0.0062802452594041824, -0.001251410460099578, 0.002914495300501585, -0.00114538858179003, 0.0035848512779921293, -0.004724016413092613, 0.0071773952804505825, -0.008172000758349895, 0.009947017766535282, -0.005635772831737995, -0.0001643130526645109, 0.00381292263045907, -0.0031852400861680508, 0.009653305634856224, 0.007073285523802042, -0.0032357475720345974, -0.0012727840803563595, -0.009820311330258846, -0.0015221212524920702, 0.0024981051683425903, 0.0037936707958579063, -0.00884889718145132, 0.0026734694838523865, -0.0010771029628813267, 0.003303100122138858, 0.00822512898594141, -0.01019833330065012, 0.005201837047934532, 0.005435172468423843, -0.0070149218663573265, 7.950121130306798e-7, -0.0037337045650929213, 0.0012130006216466427, 0.004803829826414585, -0.006164218299090862, -0.006672082003206015, 0.003793354146182537, -0.007765588816255331, -0.005621952470391989, 0.005903634242713451, -0.00852837786078453, -0.006105393636971712, -0.0009645927348174155, -0.010180492885410786, -0.0002166047488572076 ]
8ab2d6d56bce4e65f9e2921fdc0ec8fdc7ecb7fb
855
py
Python
venv/Lib/site-packages/patsy/test_regressions.py
EkremBayar/bayar
aad1a32044da671d0b4f11908416044753360b39
[ "MIT" ]
710
2015-01-07T20:08:59.000Z
2022-03-08T14:30:13.000Z
venv/Lib/site-packages/patsy/test_regressions.py
EkremBayar/bayar
aad1a32044da671d0b4f11908416044753360b39
[ "MIT" ]
142
2015-01-07T02:20:27.000Z
2021-11-15T04:23:02.000Z
venv/Lib/site-packages/patsy/test_regressions.py
EkremBayar/bayar
aad1a32044da671d0b4f11908416044753360b39
[ "MIT" ]
101
2015-01-15T16:35:12.000Z
2022-02-19T06:50:02.000Z
# This file is part of Patsy # Copyright (C) 2013 Nathaniel Smith <njs@pobox.com> # See file LICENSE.txt for license information. # Regression tests for fixed bugs (when not otherwise better covered somewhere # else) from patsy import (EvalEnvironment, dmatrix, build_design_matrices, PatsyError, Origin) def test_issue_11(): # Give a sensible error message for level mismatches # (At some points we've failed to put an origin= on these errors) env = EvalEnvironment.capture() data = {"X" : [0,1,2,3], "Y" : [1,2,3,4]} formula = "C(X) + Y" new_data = {"X" : [0,0,1,2,3,3,4], "Y" : [1,2,3,4,5,6,7]} info = dmatrix(formula, data) try: build_design_matrices([info.design_info], new_data) except PatsyError as e: assert e.origin == Origin(formula, 0, 4) else: assert False
34.2
78
0.645614
1
1.0086
[ 0.0030316736083477736, 0.02493632584810257, 0.006171476095914841, 0.0016012809937819839, 0.008599863387644291, -0.0036391678731888533, -0.010317480191588402, 0.003917713649570942, -0.0058670202270150185, 0.0016139025101438165, 0.0048124343156814575, 0.003538016229867935, 0.00809965655207634, -0.014982632361352444, -0.00004092403105460107, 0.01939678005874157, -0.054596059024333954, 0.003661784343421459, -0.002789558842778206, 0.0046045128256082535, -0.008325905539095402, 0.010037138126790524, 0.007993296720087528, 0.006352308206260204, 0.004492155276238918, -0.0016805959166958928, 0.007877162657678127, 0.001920689712278545, -0.011774365790188313, -0.007523871026933193, 0.002968152053654194, -0.0018046693876385689, -0.005971308797597885, -0.008530344814062119, 0.005909729283303022, -0.0029590707272291183, -0.001475804834626615, -0.01854553446173668, 0.011971988715231419, -0.008352881297469139, -0.006917879451066256, -0.017055148258805275, 0.0024656483437865973, 0.005266928113996983, -0.010505505837500095, 0.0024607547093182802, -0.004271772224456072, 0.0035575537476688623, -0.01248273253440857, 0.004895931109786034, -0.01029640156775713, 0.003300553187727928, 0.013320233672857285, 0.002705028746277094, -0.004082910250872374, -0.00529194250702858, 0.012102517299354076, 0.0007669372134841979, -0.011118589900434017, 0.0032206836622208357, -0.003923822194337845, -0.004314909223467112, 0.0013182256370782852, 0.0019396068528294563, -0.015026646666228771, -0.0069334544241428375, -0.0045831697061657906, 0.0014440753730013967, -0.005062463693320751, 0.006713759619742632, 0.0013545284746214747, -0.0011828041169792414, 0.005054478999227285, 0.0032612208742648363, 0.0031012343242764473, -0.005274550523608923, -0.0035128742456436157, 0.00025539909256622195, 0.010422325693070889, 0.003228099551051855, 0.0038911171723157167, -0.00777318375185132, 0.005618656054139137, 0.00777971837669611, 0.012355188839137554, 0.008604341186583042, 0.019560037180781364, -0.011866421438753605, 0.04417169466614723, 0.009112224914133549, -0.010534380562603474, 0.0019704073201864958, -0.008835697546601295, -0.0037350086495280266, -0.0012041468871757388, -0.03284754976630211, 0.0003980947658419609, -0.0038545799907296896, -0.00033842079574242234, 0.003721771063283086, -0.0011080093681812286, 0.0058080097660422325, -0.0005940598784945905, -0.0010864067589864135, -0.010420089587569237, 0.011040384881198406, -0.01116780936717987, -0.0021140831522643566, 0.008911686018109322, 0.0022652451880276203, -0.016273781657218933, -0.0005905064754188061, 0.0027431270573288202, -0.014589260332286358, 0.003265159670263529, 0.001361196511425078, -0.00782111193984747, 0.05577593296766281, -0.002646160079166293, 0.00016748669440858066, -0.006654402241110802, 0.0007888306863605976, 0.0018584422068670392, 0.006723291240632534, 0.012252097018063068, -0.005868925247341394, 0.01277448982000351, 0.006368280854076147, 0.007688818033784628, 0.007520440965890884, -0.0018581518670544028, 0.008749568834900856, -0.005606228020042181, -0.0006069735973142087, 0.001465239911340177, -0.006921242456883192, 0.008438444696366787, -0.0017257760046049953, -0.0067596351727843285, 0.0024164419155567884, -0.0020250973757356405, -0.010236820206046104, 0.0033247144892811775, -0.0042898221872746944, 0.006492826621979475, -0.010165559127926826, -0.004941576160490513, -0.004637896083295345, -0.004998998716473579, 0.0015452475054189563, 0.00828633178025484, 0.005697240587323904, 0.003553161397576332, -0.0038332068361341953, -0.009037040174007416, -0.003956186585128307, -0.006211558822542429, -0.0001227205793838948, 0.009052158333361149, 0.004729673732072115, -0.008479471318423748, -0.0016256526578217745, 0.003126645926386118, 0.0030464401934295893, -0.0007053565350361168, 0.003101956332102418, -0.008778154850006104, 0.008642587810754776, 0.002284304006025195, 0.004290973301976919, 0.011378983967006207, -0.0029907356947660446, 0.0007980248774401844, 0.0002563419402576983, 0.0033628225792199373, 0.0015409146435558796, 0.00476178340613842, 0.00911388173699379, -0.0011942331911996007, -0.004976618103682995, 0.005145079921931028, 0.004922229330986738, 0.007280586753040552, 0.006113030016422272, -0.0017921131802722812, 0.0034781042486429214, -0.0048592775128781796, 0.000059243546274956316, 0.008753113448619843, -0.0031629414297640324, 0.008084021508693695, 0.0038424611557275057, -0.01441266480833292, -0.008075914345681667, -0.001997205661609769, -0.008670019917190075, 0.0030706406105309725, 0.013928658328950405, 0.011151926591992378, -0.0013130416627973318, 0.0023493366315960884, -0.011512269265949726, -0.0006155400187708437, 0.009294613264501095, 0.0026334181893616915, -0.01221875287592411, -0.9561390280723572, 0.004211100749671459, 0.0023335099685937166, -0.00016722553118597716, 0.0052684699185192585, 0.0012663239613175392, 0.003687614342197776, 0.003639445872977376, 0.010325472801923752, -0.009105130098760128, -0.005772281903773546, -0.009341908618807793, -0.011213879100978374, -0.0011425594566389918, -0.0063311378471553326, -0.005746299400925636, -0.0064946794882416725, -0.005206679925322533, -0.0016954414313659072, -0.004671734292060137, -0.0027081207372248173, 0.007598069962114096, -0.0011913246707990766, 0.003008064581081271, 0.0008944418514147401, 0.002692750422284007, -0.006414107512682676, 0.0004586381546687335, -0.002248517470434308, -0.0020683594048023224, -0.0083591528236866, -0.014938870444893837, -0.0037901406176388264, 0.0006534561980515718, 0.010157930664718151, -0.001120822038501501, 0.008261725306510925, -0.002084010047838092, 0.001111648976802826, -0.008995208889245987, 0.00521464366465807, 0.0018986546201631427, 0.004773398861289024, -0.032867152243852615, -0.0030985998455435038, 0.00015260493091773242, -0.00756859453395009, 0.006412894930690527, -0.0002703659702092409, 0.00033438423997722566, -0.0022075402084738016, -0.005708302836865187, 0.012039335444569588, -0.007738668471574783, 0.0034432439133524895, -0.006653967313468456, -0.00822950154542923, -0.00012337265070527792, -0.007828598842024803, 0.0029175064992159605, 0.006170384120196104, -0.006101734004914761, -0.00322016142308712, -0.004134134855121374, 0.0015661014476791024, 0.0007527385605499148, 0.0011661667376756668, -0.018786726519465446, -0.007150560617446899, -0.0018900675931945443, 0.002631486626341939, -0.0006425706669688225, -0.003812664421275258, 0.00284893368370831, -0.010086155496537685, 0.006443988531827927, 0.0004418298485688865, 0.000032006242690840736, -0.010227126069366932, 0.0022539489436894655, -0.008792649954557419, -0.010257579386234283, 0.003023821860551834, -0.006392226088792086, -0.004304245579987764, 0.00011049201566493139, 0.0026266712229698896, 0.007304403930902481, -0.0038333365228027105, 0.003071431303396821, 0.010946555994451046, -0.0024310308508574963, -0.011069141328334808, 0.007439758628606796, 0.007128204219043255, 0.0008700074395164847, -0.0014433312462642789, -0.00007811196701368317, 0.00820134673267603, 0.008774935267865658, -0.0005883625126443803, 0.006916963495314121, 0.00006199233030201867, 0.012844056822359562, -0.00021361830295063555, 0.0009200957138091326, -0.0028990874998271465, -0.001270085689611733, -0.005443186033517122, -0.0022075786255300045, -0.005752537399530411, 0.000034709166357060894, -0.012687699869275093, -0.01071082055568695, -0.003993594087660313, 0.0011402658419683576, 0.00268577691167593, -0.0022775696124881506, 0.0001367381337331608, 0.00022494065342471004, 0.009332536719739437, 0.00197471771389246, -0.002081723418086767, 0.0023961979895830154, 0.0025950223207473755, -0.007065400946885347, 0.012181620113551617, -0.011678007431328297, 0.0069259218871593475, -0.0025736079551279545, -0.015892988070845604, 0.009183531627058983, 0.009563754312694073, -0.006195703521370888, 0.00374664762057364, -0.002138992538675666, 0.0015172607963904738, -0.001308269565925002, -0.0074601913802325726, -0.0034058550372719765, -0.017927203327417374, -0.0016012579435482621, 0.02146085910499096, 0.0016748039051890373, 0.010054102167487144, 0.012787374667823315, -0.0025640090461820364, 0.0018101150635629892, 0.004981594160199165, 0.0017902624094858766, 0.014039297588169575, -0.00828118808567524, -0.0008163145976141095, -0.00129719078540802, -0.005350012332201004, 0.0019275197992101312, 0.0059647406451404095, 0.004251088015735149, -0.0030585546046495438, 0.0030751293525099754, -0.005972333252429962, -0.005822861101478338, -0.018674815073609352, -0.003011921653524041, 0.009339623153209686, -0.0012978240847587585, 0.005011091008782387, -0.014769800938665867, 0.00376904453150928, 0.004319282714277506, 0.006356467958539724, -0.0007935872417874634, 0.0016631439793854952, 0.004930149298161268, 0.008792727254331112, -0.00453370762988925, 0.002734533278271556, 0.0018571052933111787, -0.00022707889729645103, 0.0003689269069582224, 0.007572797127068043, -0.0060175624676048756, -0.0036850047763437033, 0.0027008901815861464, 0.0009300165111199021, -0.0003806344175245613, -0.002640274353325367, -0.009101596660912037, -0.0028927037492394447, 0.0038751200772821903, -0.005102934315800667, 0.0028302264399826527, 0.0032708486542105675, 0.0038777354639023542, -0.008457953110337257, -0.002567202551290393, -0.004752993118017912, -0.012099509127438068, 0.009970367886126041, -0.002941371873021126, 0.002246550749987364, 0.012394089251756668, 0.00452399393543601, -0.011658641509711742, 0.007101632189005613, 0.008655207231640816, -0.0034915353171527386, 0.004554459825158119, 0.007962626405060291, -0.003096988657489419, -0.021771378815174103, -0.005980413872748613, -0.013940297067165375, 0.007569759152829647, 0.0004904988454654813, 0.0032186140306293964, -0.009967902675271034, 0.009861597791314125, 0.007480778731405735, -0.015490316785871983, -0.003007793566212058, -0.011532298289239407, 0.007292806636542082, -0.000212676779483445, -0.0011888148728758097, -0.002714879112318158, -0.00001850609442044515, -0.003570860018953681, -0.00142876454629004, -0.00025985942920669913, 0.004155269358307123, 0.0007613025954924524, -0.002346362452954054, 0.00327384565025568, -0.003084424650296569, 0.0023175852838903666, 0.0011115793604403734, -0.01241037156432867, 0.003399476408958435, 0.006053782533854246, -0.002599222818389535, -0.003830788191407919, 0.0008690900285728276, -0.003308223094791174, -0.0070228613913059235, -0.010549158789217472, -0.0019329829374328256, -0.005916617810726166, -0.00489551667124033, -0.010889747180044651, -0.002844911767169833, -0.011370737105607986, 0.007759699132293463, -0.009192842058837414, 0.005798489321023226, 0.005621536169201136, -0.006734015885740519, 0.008758345618844032, -0.0023324100766330957, 0.002768042264506221, 0.0011669187806546688, 0.0030022638384252787, 0.002752716653048992, -0.006900116801261902, -0.011379062198102474, 0.011170904152095318, -0.011015649884939194, 0.0018824596190825105, 0.01531606912612915, 0.00674024410545826, 0.009844006039202213, -0.00268876226618886, -0.0007820639293640852, 0.0024778570514172316, 0.00901834201067686, -0.017571615055203438, 0.0016348350327461958, -0.000631986535154283, -0.0009944565827026963, 0.0037766327150166035, -0.0032654814422130585, 0.00214324239641428, 0.007192800287157297, 0.0030052615329623222, -0.006829496007412672, -0.003390592522919178, 0.0007499594939872622, 0.003379956353455782, -0.013133395463228226, -0.0003726901486515999, -0.0028179886285215616, -0.005048668012022972, -0.003184456378221512, -0.002835974795743823, 0.00019950830028392375, 0.0046632313169538975, -0.0022321452852338552, 0.004186765290796757, 0.005251521710306406, -0.00423706928268075, 0.018101397901773453, -0.00438084127381444, -0.0037862281315028667, 0.0027362487744539976, 0.00023754185531288385, -0.0012998934835195541, -0.007832013070583344, -0.004948927089571953, 0.0038656024262309074, 0.008296597748994827, -0.001736147329211235, -0.005186432972550392, -0.005638494156301022, -0.0015450360951945186, -0.008331635035574436, 0.0005677624722011387, 0.009187684394419193, -0.0028479211032390594, 0.0033052086364477873, -0.0008799463394097984, -0.005983372218906879, -0.015514012426137924, 0.05599838122725487, -0.000014621278751292266, 0.005039237439632416, 0.007248404901474714, -0.005857636220753193, 0.0009597530588507652, -0.0015053473180159926, 0.007739481516182423, -0.008420998230576515, -0.007488114759325981, 0.011491813696920872, -0.0033391485922038555, 0.0035013114102184772, 0.0031885202042758465, 0.00033062021248042583, 0.015769070014357567, -0.0037821787409484386, -0.01593637652695179, -0.01140829361975193, 0.006334656849503517, -0.007879940792918205, -0.008127767592668533, 0.007089798804372549, -0.004618412349373102, -0.0009651530417613685, 0.001764987944625318, 0.009124383330345154, -0.00035155689693056047, 0.001030353712849319, 0.0003780180704779923, -0.0017484688432887197, 0.0014814992900937796, 0.0029627978801727295, 0.006849072873592377, 0.009729217737913132, -0.0025187793653458357, 0.004388669040054083, 0.00023130913905333728, -0.0021191074047237635, -0.0004889105330221355, 0.002595260040834546, 0.007252983283251524, -0.0038543047849088907, -0.005806595087051392, 0.0035280194133520126, 0.005066045094281435, -0.0006223612581379712, 0.011125330813229084, 0.00016432932170573622, -0.006261664908379316, 0.008821903727948666, 0.008996563963592052, -0.0007474945741705596, 0.008980496786534786, 0.002434892114251852, 0.004935101140290499, 0.0016916515305638313, -0.009363938122987747, -0.016127560287714005, -0.0022075187880545855, 0.00633664196357131, 0.008556472137570381, -0.0033258001785725355, 0.0009792802156880498, 0.0026106229051947594, -0.00545480428263545, -0.00808938778936863, -0.0067199417389929295, -0.0034172371961176395, 0.0016603555995970964, 0.001482963445596397, 0.0709083154797554, -0.008567667566239834, -0.0025672013871371746, -0.00933094136416912, -0.0006918301223777235, -0.001970351906493306, 0.002021108753979206, -0.0008675325661897659, -0.0006730129825882614, 0.004675485193729401, 0.0006582653732039034, -0.00888055469840765, -0.01143169216811657, 0.0006408630288206041, 0.0033062035217881203, -0.0017852194141596556, 0.0030737542547285557, 0.008883845061063766, -0.005493258126080036, 0.0016812485409900546, -0.011230887845158577, -0.0026009485591202974, -0.00006932223914191127, -0.009900839067995548, -0.0038256810512393713, -0.0037141218781471252, 0.0042565204203128815, 0.004362615756690502, 0.005934111308306456, -0.0034657863434404135, 0.0076692234724760056, -0.00032906970591284335, -0.00044561599497683346, -0.005017243325710297, 0.00003064426709897816, -0.005635903682559729, 0.00849972665309906, 0.0007664557197131217, -0.010968832299113274, -0.008167756721377373, -0.004675577394664288, 0.0026142983697354794, -0.007858248427510262, 0.006927775219082832, -0.0008960386039689183, 0.007760409731417894, -0.0024504263419657946, 0.0008563905721530318, -0.0043196361511945724, 0.003168718656525016, -0.011293044313788414, 0.007229423150420189, -0.17669638991355896, 0.01255310419946909, 0.005853613372892141, -0.004551711026579142, -0.0018125282367691398, -0.016442792490124702, -0.007207763846963644, 0.004012190271168947, 0.01169002614915371, -0.00030745906406082213, 0.0008441295940428972, -0.004963510669767857, 0.008394651114940643, 0.005215289071202278, -0.0013772686943411827, -0.006305593065917492, 0.0038312897086143494, -0.004261461552232504, -0.0015675699105486274, 0.003471755189821124, 0.004133813548833132, 0.007799187209457159, 0.004893606528639793, 0.0007463237852789462, -0.0017284553032368422, -0.007225660141557455, 0.006049997638911009, -0.0019067124230787158, 0.003101928159594536, -0.011190637946128845, -0.0029125262517482042, -0.007096749730408192, -0.0038757738657295704, 0.00034071566187776625, 0.0035554401110857725, -0.0003917429130524397, 0.00909592304378748, 0.003548875218257308, -0.009366879239678383, 0.010301207192242146, -0.0067873792722821236, 0.032373275607824326, 0.0033516583498567343, 0.00597990769892931, -0.00044656102545559406, -0.003310698550194502, -0.005988304503262043, 0.010841849260032177, 0.0035841427743434906, 0.012521837837994099, -0.013279914855957031, -0.0017999111441895366, 0.004840748850256205, 0.018936606124043465, -0.006021399050951004, -0.007717608939856291, -0.007402749732136726, -0.005957042332738638, 0.0034647381398826838, 0.012491527944803238, 0.01220464427024126, -0.006493029184639454, 0.00979861430823803, -0.0035765196662396193, -0.01633976772427559, 0.0022057874593883753, -0.0051323664374649525, -0.00919679831713438, 0.0010364461923018098, 0.007856338284909725, 0.010709235444664955, -0.0009636614704504609, 0.006964492611587048, -0.000513407401740551, 0.005047167185693979, -0.002997378585860133, 0.006656442768871784, -0.0014510147739201784, 0.0075175948441028595, -0.007230821996927261, 0.010359395295381546, -0.01173846609890461, -0.0014618500135838985, 0.0021491246297955513, -0.005094395950436592, 0.010800974443554878, 0.0031388779170811176, -0.0008694941643625498, -0.0007438671309500933, -0.00962754711508751, -0.0042748041450977325, 0.0006260217633098364, 0.0010876590386033058, -0.007074959576129913, 0.0025496764574199915, 0.00207653921097517, 0.009056557901203632, 0.007890922017395496, -0.010951902717351913, 0.005714032799005508, 0.007427660748362541, -0.009206146001815796, 0.0016928603872656822, -0.005215964280068874, 0.0009756111539900303, 0.003318984294310212, -0.0033396438229829073, -0.007423962466418743, 0.006764269899576902, -0.00669059855863452, -0.004989604000002146, 0.001511473092250526, -0.011043574661016464, -0.009752575308084488, -0.001721803331747651, -0.010736913420259953, 0.0003762519045267254 ]
8ab404c67e6f07e674ae9c5b07f6e6e0e0f914ac
7,764
py
Python
skimage/io/_plugins/pil_plugin.py
smheidrich/scikit-image
e9cf8b850c4c2800cc221be6f1dfff6a2a32a4eb
[ "BSD-3-Clause" ]
3
2019-02-28T16:05:36.000Z
2020-04-03T17:29:07.000Z
Lib/site-packages/skimage/io/_plugins/pil_plugin.py
caiyongji/Anaconda-py36.5-tensorflow-built-env
f4eb40b5ca3f49dfc929ff3ad2b4bb877e9663e2
[ "PSF-2.0" ]
26
2020-03-24T18:07:06.000Z
2022-03-12T00:12:27.000Z
Lib/site-packages/skimage/io/_plugins/pil_plugin.py
caiyongji/Anaconda-py36.5-tensorflow-built-env
f4eb40b5ca3f49dfc929ff3ad2b4bb877e9663e2
[ "PSF-2.0" ]
3
2019-12-31T23:21:40.000Z
2020-04-03T17:29:08.000Z
__all__ = ['imread', 'imsave'] import numpy as np from PIL import Image from ...util import img_as_ubyte, img_as_uint def imread(fname, dtype=None, img_num=None, **kwargs): """Load an image from file. Parameters ---------- fname : str or file File name or file-like-object. dtype : numpy dtype object or string specifier Specifies data type of array elements. img_num : int, optional Specifies which image to read in a file with multiple images (zero-indexed). kwargs : keyword pairs, optional Addition keyword arguments to pass through. Notes ----- Files are read using the Python Imaging Library. See PIL docs [1]_ for a list of supported formats. References ---------- .. [1] http://pillow.readthedocs.org/en/latest/handbook/image-file-formats.html """ if isinstance(fname, str): with open(fname, 'rb') as f: im = Image.open(f) return pil_to_ndarray(im, dtype=dtype, img_num=img_num) else: im = Image.open(fname) return pil_to_ndarray(im, dtype=dtype, img_num=img_num) def pil_to_ndarray(image, dtype=None, img_num=None): """Import a PIL Image object to an ndarray, in memory. Parameters ---------- Refer to ``imread``. """ try: # this will raise an IOError if the file is not readable image.getdata()[0] except IOError as e: site = "http://pillow.readthedocs.org/en/latest/installation.html#external-libraries" pillow_error_message = str(e) error_message = ('Could not load "%s" \n' 'Reason: "%s"\n' 'Please see documentation at: %s' % (image.filename, pillow_error_message, site)) raise ValueError(error_message) frames = [] grayscale = None i = 0 while 1: try: image.seek(i) except EOFError: break frame = image if img_num is not None and img_num != i: image.getdata()[0] i += 1 continue if image.format == 'PNG' and image.mode == 'I' and dtype is None: dtype = 'uint16' if image.mode == 'P': if grayscale is None: grayscale = _palette_is_grayscale(image) if grayscale: frame = image.convert('L') else: if image.format == 'PNG' and 'transparency' in image.info: frame = image.convert('RGBA') else: frame = image.convert('RGB') elif image.mode == '1': frame = image.convert('L') elif 'A' in image.mode: frame = image.convert('RGBA') elif image.mode == 'CMYK': frame = image.convert('RGB') if image.mode.startswith('I;16'): shape = image.size dtype = '>u2' if image.mode.endswith('B') else '<u2' if 'S' in image.mode: dtype = dtype.replace('u', 'i') frame = np.fromstring(frame.tobytes(), dtype) frame.shape = shape[::-1] else: frame = np.array(frame, dtype=dtype) frames.append(frame) i += 1 if img_num is not None: break if hasattr(image, 'fp') and image.fp: image.fp.close() if img_num is None and len(frames) > 1: return np.array(frames) elif frames: return frames[0] elif img_num: raise IndexError('Could not find image #%s' % img_num) def _palette_is_grayscale(pil_image): """Return True if PIL image in palette mode is grayscale. Parameters ---------- pil_image : PIL image PIL Image that is in Palette mode. Returns ------- is_grayscale : bool True if all colors in image palette are gray. """ assert pil_image.mode == 'P' # get palette as an array with R, G, B columns palette = np.asarray(pil_image.getpalette()).reshape((256, 3)) # Not all palette colors are used; unused colors have junk values. start, stop = pil_image.getextrema() valid_palette = palette[start:stop + 1] # Image is grayscale if channel differences (R - G and G - B) # are all zero. return np.allclose(np.diff(valid_palette), 0) def ndarray_to_pil(arr, format_str=None): """Export an ndarray to a PIL object. Parameters ---------- Refer to ``imsave``. """ if arr.ndim == 3: arr = img_as_ubyte(arr) mode = {3: 'RGB', 4: 'RGBA'}[arr.shape[2]] elif format_str in ['png', 'PNG']: mode = 'I;16' mode_base = 'I' if arr.dtype.kind == 'f': arr = img_as_uint(arr) elif arr.max() < 256 and arr.min() >= 0: arr = arr.astype(np.uint8) mode = mode_base = 'L' else: arr = img_as_uint(arr) else: arr = img_as_ubyte(arr) mode = 'L' mode_base = 'L' try: array_buffer = arr.tobytes() except AttributeError: array_buffer = arr.tostring() # Numpy < 1.9 if arr.ndim == 2: im = Image.new(mode_base, arr.T.shape) try: im.frombytes(array_buffer, 'raw', mode) except AttributeError: im.fromstring(array_buffer, 'raw', mode) # PIL 1.1.7 else: image_shape = (arr.shape[1], arr.shape[0]) try: im = Image.frombytes(mode, image_shape, array_buffer) except AttributeError: im = Image.fromstring(mode, image_shape, array_buffer) # PIL 1.1.7 return im def imsave(fname, arr, format_str=None, **kwargs): """Save an image to disk. Parameters ---------- fname : str or file-like object Name of destination file. arr : ndarray of uint8 or float Array (image) to save. Arrays of data-type uint8 should have values in [0, 255], whereas floating-point arrays must be in [0, 1]. format_str: str Format to save as, this is defaulted to PNG if using a file-like object; this will be derived from the extension if fname is a string kwargs: dict Keyword arguments to the Pillow save function (or tifffile save function, for Tiff files). These are format dependent. For example, Pillow's JPEG save function supports an integer ``quality`` argument with values in [1, 95], while TIFFFile supports a ``compress`` integer argument with values in [0, 9]. Notes ----- Use the Python Imaging Library. See PIL docs [1]_ for a list of other supported formats. All images besides single channel PNGs are converted using `img_as_uint8`. Single Channel PNGs have the following behavior: - Integer values in [0, 255] and Boolean types -> img_as_uint8 - Floating point and other integers -> img_as_uint16 References ---------- .. [1] http://pillow.readthedocs.org/en/latest/handbook/image-file-formats.html """ # default to PNG if file-like object if not isinstance(fname, str) and format_str is None: format_str = "PNG" # Check for png in filename if (isinstance(fname, str) and fname.lower().endswith(".png")): format_str = "PNG" arr = np.asanyarray(arr) if arr.dtype.kind == 'b': arr = arr.astype(np.uint8) if arr.ndim not in (2, 3): raise ValueError("Invalid shape for image array: %s" % (arr.shape, )) if arr.ndim == 3: if arr.shape[2] not in (3, 4): raise ValueError("Invalid number of channels in image array.") img = ndarray_to_pil(arr, format_str=format_str) img.save(fname, format=format_str, **kwargs)
29.861538
93
0.579341
1
2.0361
[ -0.007105838041752577, 0.02893909625709057, 0.014451584778726101, 0.046614088118076324, -0.009061665274202824, 0.02000967226922512, -0.013340538367629051, -0.007034751586616039, -0.004589539021253586, 0.019098427146673203, -0.005842126440256834, 0.014337796717882156, 0.037680432200431824, -0.03385072946548462, -0.021168304607272148, 0.016774987801909447, 0.06618914008140564, 0.0007877807365730405, -0.01876167766749859, -0.0017651345115154982, -0.01669066958129406, -0.014151553623378277, -0.0195150226354599, 0.00011740007903426886, 0.0021464149467647076, 0.009688149206340313, 0.03693532198667526, -0.015109964646399021, 0.024050770327448845, -0.009930004365742207, -0.0146184042096138, -0.012536163441836834, 0.020242372527718544, 0.020650474354624748, 0.007870413362979889, -0.008579442277550697, 0.012849642895162106, -0.02054070122539997, 0.02854057215154171, 0.01459421869367361, 0.01649777777493, -0.014683304354548454, 0.009501689113676548, -0.021379850804805756, -0.021142376586794853, 0.014531153254210949, -0.006850699428468943, -0.00280968751758337, -0.006786785088479519, 0.01324106939136982, -0.005982473026961088, 0.011200997047126293, -0.016508061438798904, -0.03559017553925514, -0.014360593631863594, -0.029629221186041832, -0.0011030449531972408, 0.03130211681127548, -0.03555058687925339, 0.010484124533832073, 0.0035707352217286825, -0.02697105146944523, -0.0030875280499458313, -0.028752300888299942, 0.015885677188634872, -0.01398991048336029, -0.030408566817641258, -0.012239118106663227, -0.06331624835729599, -0.012681747786700726, -0.02295541577041149, -0.006097889039665461, -0.011304188519716263, 0.04711414501070976, 0.01798451691865921, 0.0035985256545245647, 0.003976722247898579, -0.021473154425621033, -0.01673836261034012, 0.03238376975059509, -0.003986164461821318, 0.05947282165288925, -0.006293471436947584, -0.01045070681720972, -0.016124533489346504, 0.02957381308078766, 0.04209087789058685, -0.00008364048699149862, 0.02607210911810398, 0.0037803007289767265, -0.04377197474241257, 0.008004122413694859, -0.027677621692419052, -0.00258649792522192, 0.002848472446203232, -0.02225285768508911, -0.002769529353827238, -0.0009585583466105163, 0.01933399587869644, 0.034753236919641495, -0.0040776547975838184, -0.02828085608780384, 0.012364675290882587, 0.0011535651283338666, 0.017904851585626602, -0.005258736200630665, -0.016706056892871857, -0.0036330914590507746, -0.0029968833550810814, -0.02436981536448002, 0.007423802278935909, -0.02473714016377926, 0.024492647498846054, -0.005386826116591692, 0.0001266606559511274, -0.0013956883922219276, -0.0021732330787926912, -0.006711089052259922, -0.018368525430560112, 0.04882185533642769, 0.02116994746029377, -0.0006619074265472591, 0.00830862671136856, -0.012869661673903465, -0.026741797104477882, 0.06256493180990219, 0.015803731977939606, -0.020714951679110527, 0.010921094566583633, 0.011437741108238697, -0.002009072108194232, 0.0011705931974574924, -0.011768070980906487, -0.014526271261274815, -0.010692965239286423, -0.022236483171582222, -0.00953955389559269, 0.030519424006342888, -0.0184247475117445, -0.016671061515808105, 0.00922210793942213, -0.028821079060435295, 0.03213806077837944, -0.015457955189049244, 0.023206578567624092, -0.055324308574199677, -0.02550312504172325, 0.007892758585512638, -0.024032246321439743, -0.02329668216407299, 0.03290364518761635, -0.02518465928733349, -0.005770683754235506, 0.04443953558802605, 0.005771776661276817, -0.00029676430858671665, -0.0128891346976161, -0.04237133264541626, 0.006413266062736511, -0.019585320726037025, -0.010641529224812984, 0.00006528788799187168, -0.02024678699672222, 0.026700453832745552, -0.03318934515118599, 0.022338252514600754, -0.03730633109807968, 0.01869274489581585, -0.01753394864499569, -0.007579769007861614, 0.022433945909142494, -0.025554778054356575, -0.008807607926428318, 0.007517581805586815, -0.01961139403283596, 0.03281185403466225, 0.052431654185056686, 0.015300869010388851, 0.01376859750598669, -0.00047772660036571324, 0.009657494723796844, -0.007384206634014845, 0.026911811903119087, 0.023056242614984512, 0.007070832885801792, -0.0020870817825198174, -0.05566753074526787, 0.02077595330774784, 0.006237785331904888, -0.023918136954307556, -0.0368252657353878, 0.018214846029877663, -0.02511153370141983, -0.004668092355132103, 0.021448589861392975, 0.01644905097782612, -0.008580087684094906, 0.03328268229961395, -0.023580530658364296, 0.024761658161878586, -0.02336975932121277, -0.035474348813295364, 0.008282383903861046, 0.009275360032916069, -0.004352564457803965, -0.021371496841311455, -0.7927227020263672, 0.03869425505399704, 0.0031800870783627033, -0.023377221077680588, 0.0019117249175906181, 0.058318644762039185, -0.018997561186552048, 0.0012195579474791884, -0.05121641233563423, -0.020466556772589684, -0.0037124566733837128, -0.0017980837728828192, -0.03413015231490135, 0.020289866253733635, 0.039444126188755035, -0.018828734755516052, 0.01115358155220747, -0.034023869782686234, 0.009649678133428097, 0.033298492431640625, 0.029137013480067253, -0.015618415549397469, -0.025460094213485718, 0.003858640557155013, 0.008805612102150917, 0.016653649508953094, 0.012486889958381653, -0.01098027266561985, -0.014748157933354378, -0.03723603114485741, -0.01050549652427435, -0.011504659429192543, 0.040632814168930054, -0.041950773447752, 0.009925521910190582, 0.007076048757880926, -0.003728479379788041, 0.006663353182375431, -0.043882641941308975, -0.013052194379270077, -0.00364136160351336, -0.006159191485494375, -0.003263145452365279, -0.04628076031804085, -0.027981095016002655, 0.01147154625505209, -0.023647263646125793, -0.049236174672842026, 0.005355909001082182, 0.03372351825237274, -0.0176377072930336, 0.004409839864820242, 0.0529497005045414, -0.024428021162748337, 0.013769196346402168, 0.0006960196769796312, -0.040811218321323395, -0.016964249312877655, -0.019323142245411873, 0.016911037266254425, -0.00174435181543231, 0.013082562945783138, -0.010792751796543598, 0.026473358273506165, -0.013559198938310146, 0.01925298571586609, 0.0518232025206089, -0.020013347268104553, -0.003313928609713912, 0.006292884238064289, -0.03071117401123047, -0.013316757045686245, -0.04010937362909317, 0.08919699490070343, -0.024828003719449043, -0.0064833275973796844, -0.009729775600135326, 0.0366700142621994, 0.0077223447151482105, -0.004167597275227308, 0.008245033212006092, -0.013088610023260117, 0.011718763038516045, 0.00894924346357584, -0.050756555050611496, 0.016541041433811188, 0.01818319596350193, -0.011902294121682644, 0.002824331633746624, 0.011452036909759045, 0.014769096858799458, 0.03789358586072922, 0.03504965454339981, 0.0025633019395172596, -0.011721658520400524, 0.014084359630942345, 0.00111742306035012, 0.05524088814854622, 0.041124630719423294, 0.00862841121852398, -0.049872130155563354, 0.006456641014665365, 0.004387923516333103, 0.011646932922303677, -0.02201634645462036, -0.015070779249072075, -0.024387720972299576, -0.003883182071149349, 0.01134591456502676, -0.04792170226573944, -0.018526174128055573, -0.00655678054317832, -0.01605908013880253, 0.022412298247218132, 0.006689509376883507, 0.003486919216811657, 0.022716151550412178, -0.032394059002399445, 0.003003878053277731, -0.011942433193325996, 0.010198167525231838, -0.0434216633439064, 0.009076707996428013, 0.023675180971622467, -0.0097302021458745, -0.012962955050170422, -0.031153682619333267, -0.012305980548262596, 0.005953817628324032, 0.01841595210134983, -0.009568874724209309, 0.007829469628632069, -0.009316870011389256, 0.0018881309079006314, -0.021588219329714775, 0.015994803979992867, 0.005953044630587101, -0.014266728423535824, -0.00847186055034399, -0.00959024764597416, 0.01656469702720642, -0.02538360469043255, 0.010571173392236233, -0.04418099671602249, 0.012326836585998535, 0.0007182639092206955, 0.002712804125621915, -0.003833611961454153, 0.04865236580371857, -0.003274940187111497, 0.009625858627259731, 0.03858506679534912, 0.011953655630350113, 0.008179391734302044, 0.0062386891804635525, 0.013519895263016224, -0.016239164397120476, -0.0007384655764326453, 0.013543146662414074, 0.0018758346559479833, -0.01229704637080431, -0.030552448704838753, 0.00400075176730752, 0.03997069224715233, -0.015061876736581326, -0.00931159034371376, 0.0018676607869565487, 0.05003257840871811, 0.021125804632902145, 0.039361875504255295, 0.037324029952287674, -0.002800740534439683, 0.01055055484175682, 0.013989672996103764, -0.03867829591035843, 0.029509305953979492, -0.019437123090028763, -0.006928757298737764, 0.010128856636583805, 0.0025169362779706717, 0.014551971107721329, -0.0052297781221568584, -0.004147118888795376, -0.03274315223097801, 0.02479788474738598, -0.0014071827754378319, -0.023087410256266594, 0.009105511009693146, 0.03342253342270851, -0.02491564303636551, 0.03407841548323631, -0.0033526988700032234, -0.007220524363219738, 0.04227032512426376, 0.0033167460933327675, -0.02141580358147621, -0.04277811571955681, -0.019104767590761185, 0.007672336418181658, -0.018915554508566856, -0.006677118130028248, 0.01603730209171772, -0.01872173324227333, -0.011660548858344555, 0.008050043135881424, 0.020670533180236816, 0.0007560572703368962, -0.031256917864084244, -0.008305992931127548, -0.010255119763314724, -0.0006391971837729216, -0.049963247030973434, 0.013628740794956684, 0.013708983547985554, -0.007795360404998064, 0.002696795854717493, -0.024985821917653084, -0.02639169618487358, -0.021014133468270302, -0.03262144327163696, -0.017468120902776718, -0.013470811769366264, 0.001396025181747973, 0.00044595185318030417, -0.02476157248020172, -0.0033251361455768347, -0.019152449443936348, 0.020053528249263763, -0.01736416481435299, -0.004736828152090311, 0.01942971907556057, -0.0011295406147837639, 0.014186331070959568, 0.014788545668125153, -0.01203163992613554, 0.024355145171284676, -0.04360967501997948, 0.0020402269437909126, -0.0062330253422260284, -0.017966125160455704, 0.03724449500441551, 0.0036970325745642185, -0.03382609039545059, 0.010706717148423195, 0.001971128163859248, 0.027821430936455727, 0.01459500566124916, -0.013451087288558483, -0.05180853605270386, 0.008914070203900337, -0.0085136154666543, 0.007942374795675278, -0.0012380124535411596, 0.0130641870200634, 0.004333147779107094, 0.017618680372834206, -0.007340622134506702, -0.006898616440594196, 0.004219224210828543, 0.027932817116379738, -0.025988087058067322, -0.009279297664761543, 0.00321267475374043, 0.0008933292701840401, 0.028004301711916924, 0.003477503079921007, 0.029801638796925545, -0.010259782895445824, 0.015327071771025658, -0.00011317247117403895, 0.014596155844628811, -0.019282309338450432, -0.010972953401505947, -0.014431395567953587, -0.0036083629820495844, 0.004224529955536127, 0.0047349161468446255, -0.021636322140693665, 0.00012069069634890184, 0.050018902868032455, -0.005191687494516373, -0.007312677800655365, 0.04047291725873947, 0.010250439867377281, 0.016240138560533524, 0.02019617147743702, 0.0273783840239048, -0.0013172727776691318, -0.019954273477196693, -0.0032190862111747265, 0.000751562649384141, -0.043881237506866455, -0.009850448928773403, 0.03531636297702789, -0.02146952785551548, 0.024440551176667213, 0.0014669564552605152, 0.022358406335115433, 0.056687768548727036, 0.017647719010710716, 0.004776813555508852, 0.006916573736816645, 0.002731305081397295, -0.0042177909053862095, 0.006286002695560455, -0.011213709600269794, -0.0011146673932671547, -0.003906322177499533, 0.025228306651115417, -0.0020239895675331354, 0.023894961923360825, -0.01347680389881134, -0.009376904927194118, -0.02368852123618126, -0.005009607411921024, -0.013989172875881195, 0.049496885389089584, -0.0011948018800467253, 0.017966577783226967, 0.005043372046202421, -0.020606745034456253, 0.030678456649184227, -0.005184835288673639, -0.002820428926497698, -0.0008314320002682507, -0.020305022597312927, -0.017035480588674545, 0.0016646692529320717, -0.006404172163456678, -0.006690553855150938, -0.023956911638379097, -0.00921139307320118, 0.009062791243195534, -0.021349936723709106, 0.02111877128481865, -0.03808973357081413, 0.013690629042685032, 0.011595486663281918, 0.014027969911694527, 0.03243405744433403, 0.047409143298864365, -0.003198090475052595, -0.007205822505056858, -0.025684364140033722, -0.0013883657520636916, -0.003624444827437401, -0.01174728199839592, 0.04324251413345337, 0.007397248409688473, 0.018590517342090607, 0.014957481995224953, -0.0016949246637523174, 0.0029416054021567106, 0.006554358638823032, 0.005704715382307768, 0.0006817226530984044, 0.003123686881735921, 0.024462394416332245, 0.016943715512752533, -0.025763511657714844, 0.02365436777472496, 0.003651880891993642, -0.000681862176861614, -0.0032852445729076862, 0.01354794017970562, -0.0133088119328022, 0.010835071094334126, -0.010422281920909882, -0.02046925388276577, -0.019235165789723396, -0.028100324794650078, -0.005387846380472183, 0.008246863260865211, 0.0008137677796185017, 0.019444085657596588, 0.027894005179405212, 0.009235771372914314, 0.005153752863407135, -0.0010749237844720483, 0.004019666463136673, 0.015056897886097431, 0.011723746545612812, 0.03491673618555069, -0.04998082295060158, 0.020701773464679718, -0.04362800344824791, 0.028973089531064034, -0.0010456013260409236, 0.0074815163388848305, 0.013469656929373741, 0.01529114879667759, 0.005824059713631868, 0.012664646841585636, 0.03422759473323822, -0.018818721175193787, -0.011933510191738605, -0.008838310837745667, -0.015306363813579082, -0.008019516244530678, -0.0020300031173974276, -0.006416041404008865, 0.010548649355769157, -0.031608596444129944, -0.02638920582830906, 0.010324942879378796, -0.017932670190930367, 0.043643273413181305, -0.002561332657933235, 0.0007506861002184451, -0.0016039737965911627, 0.03316643089056015, 0.0146288201212883, -0.017202390357851982, -0.019964534789323807, 0.02613118663430214, 0.001650925725698471, -0.02762443572282791, 0.02292734757065773, 0.0033704915549606085, -0.004416174720972776, -0.01914052665233612, -0.006131910253316164, -0.01623581349849701, -0.0006300167297013104, 0.005661781877279282, 0.01901625096797943, 0.014676280319690704, 0.02431548200547695, -0.006169278174638748, 0.028328340500593185, -0.02674330770969391, 0.01965763233602047, -0.03461780399084091, -0.002333767246454954, 0.03524423763155937, -0.010416904464364052, 0.00757271284237504, -0.021864410489797592, -0.01837763749063015, 0.01951812580227852, 0.002733479952439666, 0.010847128927707672, 0.010385503992438316, 0.002488980535417795, 0.007128222845494747, -0.07484238594770432, 0.02347547747194767, -0.014758645556867123, 0.0011930366745218635, -0.020738327875733376, 0.009884640574455261, 0.0028168128337711096, -0.0019216518849134445, 0.009973868727684021, 0.02106296643614769, -0.002236454514786601, 0.026500727981328964, -0.0015361495316028595, -0.004574974998831749, 0.009458411484956741, 0.0124607402831316, 0.02523101307451725, -0.03049321472644806, 0.023982934653759003, -0.004150393884629011, 0.005227583926171064, 0.02303672581911087, -0.017792413011193275, -0.033758845180273056, -0.041735630482435226, 0.004775056149810553, -0.00021525267220567912, 0.005161615554243326, -0.01626577228307724, 0.016580665484070778, 0.02154911868274212, 0.003906900063157082, 0.02093925140798092, 0.007128789555281401, 0.012654891237616539, -0.056969426572322845, -0.007563851773738861, 0.03497966751456261, 0.009888887405395508, -0.0049902331084012985, -0.009493543766438961, 0.013783609494566917, 0.004819752182811499, -0.0003264446568209678, 0.005162552930414677, -0.021840568631887436, -0.030575957149267197, 0.010274888947606087, 0.04504203423857689, 0.015481322072446346, -0.027549786493182182, 0.032209958881139755, -0.013014632277190685, 0.022883540019392967, -0.010860376060009003, 0.013425312936306, -0.016222191974520683, 0.0007536374032497406, -0.03878485783934593, 0.026646122336387634, 0.004644743166863918, 0.07213623076677322, 0.0215900931507349, -0.024599270895123482, -0.019275246188044548, -0.02091098763048649, -0.013486378826200962, -0.040823496878147125, 0.008745760656893253, 0.027076123282313347, 0.008475951850414276, 0.012681889347732067, -0.06303811818361282, 0.03231025114655495, 0.006599570624530315, 0.011531805619597435, 0.016145111992955208, -0.025709735229611397, -0.032886095345020294, 0.015790922567248344, -0.007943004369735718, -0.020819680765271187, -0.02469518780708313, -0.011695240624248981, -0.01263364963233471, -0.03446408733725548, 0.000881812593434006, -0.02830984629690647, -0.014903916046023369, 0.0198979414999485, -0.010025940835475922, 0.01937885582447052, 0.054357148706912994, -0.011217152699828148, -0.005442572291940451, 0.01957067660987377, 0.012378355488181114, -0.029969751834869385, -0.0022163887042552233, -0.026989087462425232, -0.0022031692788004875, -0.014201028272509575, 0.006368174217641354, 0.019018683582544327, 0.015951408073306084, -0.0272521935403347, 0.005058626178652048, -0.022928817197680473, -0.007417901419103146, -0.01583348773419857, -0.036522187292575836, 0.008857112377882004, -0.0001381513284286484, 0.0016684317961335182, -0.04600527510046959, -0.011835083365440369, 0.007113722153007984 ]
8ab47b215dd213a094ad1c94dce6a5f882e00bd7
695
py
Python
examples/tellurium-files/linearChain.py
ShaikAsifullah/distributed-tellurium
007e9b3842b614edd34908c001119c6da1d41897
[ "Apache-2.0" ]
1
2019-06-19T04:40:33.000Z
2019-06-19T04:40:33.000Z
examples/tellurium-files/linearChain.py
ShaikAsifullah/distributed-tellurium
007e9b3842b614edd34908c001119c6da1d41897
[ "Apache-2.0" ]
null
null
null
examples/tellurium-files/linearChain.py
ShaikAsifullah/distributed-tellurium
007e9b3842b614edd34908c001119c6da1d41897
[ "Apache-2.0" ]
null
null
null
# -*- coding: utf-8 -*- """ Linear chain of reactions. """ from __future__ import print_function, division import tellurium as te model = ''' model feedback() // Reactions: J0: $X0 -> S1; (VM1 * (X0 - S1/Keq1))/(1 + X0 + S1 + S4^h); J1: S1 -> S2; (10 * S1 - 2 * S2) / (1 + S1 + S2); J2: S2 -> S3; (10 * S2 - 2 * S3) / (1 + S2 + S3); J3: S3 -> S4; (10 * S3 - 2 * S4) / (1 + S3 + S4); J4: S4 -> $X1; (V4 * S4) / (KS4 + S4); // Species initializations: S1 = 0; S2 = 0; S3 = 0; S4 = 0; X0 = 10; X1 = 0; // Variable initialization: VM1 = 10; Keq1 = 10; h = 10; V4 = 2.5; KS4 = 0.5; end''' r = te.loada(model) result = r.simulate(0, 40, 500) r.plotWithLegend(result)
24.821429
64
0.515108
1
1.0971
[ -0.00028116090106777847, 0.023797692731022835, 0.006900427863001823, 0.00001174234967038501, 0.005810978356748819, -0.004575806669890881, -0.010270879603922367, 0.003916520159691572, -0.0055992454290390015, 0.001994298305362463, 0.0025285494048148394, 0.004667890723794699, 0.008410785347223282, -0.014429020695388317, -0.0002970190835185349, 0.016080083325505257, -0.05406240001320839, 0.0032304737251251936, -0.004205217119306326, 0.0006837187684141099, -0.008933000266551971, 0.012624915689229965, 0.008378369733691216, 0.006804787088185549, 0.006135702133178711, 0.002000428270548582, 0.009364241734147072, 0.004073509480804205, -0.008719857782125473, -0.005809910595417023, -0.00019228314340580255, -0.0007578479708172381, -0.008342782966792583, -0.008538610301911831, 0.005579446442425251, -0.003146182047203183, -0.00016765583131927997, -0.021841570734977722, 0.012791690416634083, -0.00715683912858367, -0.0051023769192397594, -0.015617026947438717, 0.002796267159283161, 0.006897417828440666, -0.009818300604820251, 0.0010121852392330766, -0.002665487118065357, 0.0024166193325072527, -0.010077866725623608, 0.006427458953112364, -0.009113796055316925, 0.00021112328977324069, 0.01221250370144844, 0.004013471771031618, -0.006010400131344795, -0.009104803204536438, 0.011871599592268467, -0.00020329156541265547, -0.011247005313634872, -0.00006736569775966927, -0.003325969912111759, -0.004138769581913948, 0.000625448883511126, 0.0007118948269635439, -0.014599519781768322, -0.007456087041646242, -0.006179050542414188, 0.0015472722006961703, -0.004068729933351278, 0.005540837533771992, 0.0035907295532524586, 0.0007526021800003946, 0.005626764614135027, 0.0036319843493402004, 0.0007584683480672538, -0.003118376014754176, -0.003349056700244546, 0.004202904645353556, 0.009849638678133488, 0.005160222295671701, 0.004779868293553591, -0.008771355263888836, 0.004156836308538914, 0.015223747119307518, 0.011955040507018566, 0.008485108613967896, 0.01598968543112278, -0.013922657817602158, 0.04182768985629082, 0.005776504520326853, -0.009963477030396461, 0.002516153734177351, -0.009095756337046623, -0.0027171948458999395, -0.0037403430324047804, -0.028247511014342308, 0.0006206516991369426, -0.004952737130224705, -0.0010509949643164873, 0.0016493763541802764, 0.0015374176437035203, 0.0064476425759494305, 0.00022131786681711674, -0.004332857206463814, -0.009767736308276653, 0.011326809413731098, -0.00890959333628416, -0.004069742746651173, 0.00844646617770195, 0.004286389797925949, -0.013911508955061436, -0.0018296820344403386, 0.0012298543006181717, -0.013486345298588276, 0.004175678361207247, 0.00221149530261755, -0.006168082356452942, 0.055519044399261475, -0.002591710304841399, 0.0008522202842868865, -0.003833419643342495, -0.0021237230394035578, 0.0022535359021276236, 0.007577141281217337, 0.011305754072964191, -0.006676271557807922, 0.011667839251458645, 0.007629499305039644, 0.005015898030251265, 0.010091708973050117, 0.00011361026554368436, 0.00923086330294609, -0.003322755452245474, -0.001554969814606011, -0.001480617793276906, -0.005898335948586464, 0.009526127949357033, -0.0030745803378522396, -0.006255879998207092, 0.0009055419359356165, -0.003064296906813979, -0.013020484708249569, 0.0011725869262591004, -0.002752285683527589, 0.0034334673546254635, -0.010834387503564358, -0.0038533417973667383, -0.003927377052605152, -0.003945788834244013, 0.003165344474837184, 0.007671492639929056, 0.0054914867505431175, 0.0025312956422567368, -0.0060290866531431675, -0.009402149356901646, -0.001843526610173285, -0.007565230131149292, 0.0031192537862807512, 0.009703708812594414, 0.002984925638884306, -0.01095027755945921, -0.0017406374681741, 0.002222346607595682, 0.002250346355140209, -0.00099942774977535, 0.0028080514166504145, -0.007168146315962076, 0.008724282495677471, 0.00031182513339444995, 0.0027073388919234276, 0.012302171438932419, -0.003206751076504588, 0.0005413761246018112, -0.0009224010282196105, 0.0007588337757624686, -0.0007258583209477365, 0.0032136566005647182, 0.01005055196583271, -0.0034133545123040676, -0.00635233661159873, 0.00590622890740633, 0.005913340486586094, 0.008153904229402542, 0.0050930604338645935, -0.004358561709523201, 0.002998444251716137, -0.004350598901510239, 0.0010417370358482003, 0.007653504144400358, -0.004730403423309326, 0.007439840119332075, 0.0032728174701333046, -0.016318142414093018, -0.007590936031192541, -0.003980773501098156, -0.009137570858001709, 0.000723745150025934, 0.01541108638048172, 0.009006624110043049, -0.0012997748563066125, 0.0018309860024601221, -0.012527290731668472, -0.000008393693860853091, 0.00959504023194313, 0.0033048985060304403, -0.011140745133161545, -0.9566261172294617, 0.003294977592304349, 0.003471413627266884, -0.002638048492372036, 0.005511529743671417, 0.0007437121239490807, 0.0023396506439894438, 0.0033243373036384583, 0.012527269311249256, -0.012743574567139149, -0.0044883014634251595, -0.010580028407275677, -0.011139638721942902, -0.0011852500028908253, -0.00729346601292491, -0.004897438455373049, -0.005687893368303776, -0.008443430997431278, -0.0031077503226697445, -0.006147963926196098, -0.0016164863482117653, 0.01108463667333126, -0.0011547007597982883, 0.003666681470349431, 0.002449854277074337, 0.004772639833390713, -0.004281318746507168, -0.0007101818919181824, -0.002142246114090085, -0.0026894838083535433, -0.005626782774925232, -0.01435245480388403, -0.0027410336770117283, -0.0012799468822777271, 0.010543202981352806, -0.00042652120464481413, 0.007926019839942455, -0.0032756789587438107, 0.0008363015949726105, -0.007899404503405094, 0.004016053397208452, 0.002456734189763665, 0.001733071869239211, -0.030315237119793892, -0.002478105016052723, 0.001207514200359583, -0.007061567157506943, 0.005761653650552034, 0.0009045855840668082, 0.000378734664991498, -0.0025351583026349545, -0.005652147810906172, 0.00852526817470789, -0.00787092000246048, 0.005238618701696396, -0.0063340989872813225, -0.006140193436294794, -0.00037152611184865236, -0.008367200382053852, 0.0009524687775410712, 0.004224597010761499, -0.00609885947778821, -0.00324493320658803, -0.0045182486064732075, 0.0024659449700266123, 0.0013539869105443358, 0.002487101126462221, -0.017945604398846626, -0.0034568996634334326, 0.0019483222858980298, 0.00352705386467278, 0.00022565736435353756, -0.0027841085102409124, 0.004013931844383478, -0.008677453733980656, 0.005784488748759031, -0.0009564494248479605, 0.002250381512567401, -0.010862581431865692, 0.0014520703116431832, -0.00979332160204649, -0.008159661665558815, 0.005046575330197811, -0.004124227445572615, -0.00455504423007369, -0.0004145096172578633, 0.001990290591493249, 0.007641129195690155, -0.00458268728107214, 0.00043339928379282355, 0.010579420253634453, -0.003591713262721896, -0.01107698678970337, 0.005610465072095394, 0.00848731305450201, 0.00009487871284363791, -0.0036817947402596474, 0.001167838810943067, 0.0072947908192873, 0.007741705514490604, 0.0014491291949525476, 0.0064679402858018875, -0.00034918426536023617, 0.011844949796795845, 0.0008544045267626643, -0.00005464002606458962, -0.0015934223774820566, -0.000953461101744324, -0.0023914463818073273, -0.0016206820728257298, -0.005032869055867195, -0.0005506983725354075, -0.011532868258655071, -0.009738214313983917, -0.0035406516399234533, 0.0017010330921038985, 0.0008584528113715351, -0.0024099189322441816, -0.001224460662342608, -0.0009979440364986658, 0.010826929472386837, -0.0012668439885601401, -0.005533500108867884, -0.00029104878194630146, 0.000951689260546118, -0.006710456684231758, 0.014982818625867367, -0.010624184273183346, 0.007629761938005686, -0.0013744938187301159, -0.015495638363063335, 0.008454903028905392, 0.007572634611278772, -0.00666331360116601, 0.00363190402276814, -0.0015576273435726762, 0.0022168545983731747, 0.0031115738674998283, -0.005722464993596077, -0.002931034890934825, -0.018351536244153976, 0.0007365731289610267, 0.02085006982088089, 0.0034543953370302916, 0.010137379169464111, 0.011977963149547577, -0.0030067339539527893, 0.002950327703729272, 0.007206514477729797, 0.0013373453402891755, 0.015422343276441097, -0.008135291747748852, 0.0008400505757890642, 0.003382071852684021, -0.0049660904332995415, 0.003645019605755806, 0.00563413230702281, 0.003707701340317726, -0.006154275964945555, 0.0020050611346960068, -0.0046479045413434505, -0.005026084836572409, -0.017606358975172043, -0.0022215920034796, 0.007683252450078726, -0.003424657043069601, 0.003729405114427209, -0.01355009339749813, 0.00282159517519176, 0.005421441514045, 0.0032141900155693293, 0.0004693569790106267, 0.0002024332934524864, 0.007398677058517933, 0.012894055806100368, -0.004426739178597927, -0.0006946147768758237, 0.005135822109878063, -0.0015236525796353817, -0.00026812893338501453, 0.00515359453856945, -0.007197072729468346, -0.0038931523449718952, -0.00037457761936821043, 0.004982773680239916, -0.00012770506145898253, -0.0036185013595968485, -0.009109699167311192, -0.003228793852031231, 0.0021115755662322044, -0.0068353815004229546, 0.003300696611404419, 0.0009883915772661567, 0.003955149557441473, -0.006903855130076408, -0.0012160877231508493, -0.00750750070437789, -0.009547688066959381, 0.009454157203435898, -0.0034287748858332634, 0.004355194978415966, 0.012002859264612198, 0.002837980864569545, -0.013738888315856457, 0.00650528771802783, 0.009483824484050274, -0.004026873968541622, 0.003628202946856618, 0.005324836820363998, -0.0024681533686816692, -0.02138613723218441, -0.002196804853156209, -0.012625313363969326, 0.008792811073362827, -0.0013113197637721896, 0.002366038039326668, -0.0077887228690087795, 0.007347520906478167, 0.007579641882330179, -0.013864180073142052, -0.0047020879574120045, -0.010021453723311424, 0.007413014303892851, -0.0006579761975444853, -0.0007015743758529425, -0.004296214785426855, -0.0035370641853660345, -0.004104541148990393, -0.004768478684127331, -0.0006564008072018623, 0.005357158835977316, 0.0005412705359049141, -0.004054338205605745, 0.003948989789932966, -0.0012458204291760921, 0.0014230184024199843, 0.0015774136409163475, -0.009532381780445576, 0.0007393224514089525, 0.006443895865231752, -0.00029348264797590673, 0.00011982706928392872, 0.0020234594121575356, -0.0036611552350223064, -0.0054453215561807156, -0.012774546630680561, -0.004548906814306974, -0.0047925254330039024, -0.003079760354012251, -0.011000845581293106, -0.0030084929894655943, -0.006060107611119747, 0.009005938656628132, -0.006968663074076176, 0.008794833905994892, 0.005911380052566528, -0.005833654664456844, 0.00552710983902216, -0.003764656139537692, 0.0040991781279444695, 0.0018262275261804461, 0.004222772549837828, 0.00025934012955985963, -0.00585457356646657, -0.008734434843063354, 0.010535362176597118, -0.009900136850774288, 0.0010835893917828798, 0.013913300819694996, 0.006278649438172579, 0.00950492825359106, -0.0000059827380027854815, 0.0003577685565687716, 0.0052501787431538105, 0.008051062934100628, -0.013313660398125648, 0.00365712633356452, -0.0026188469491899014, -0.002045433036983013, 0.005414444953203201, -0.004631668329238892, 0.002636775840073824, 0.005989972036331892, 0.004916474223136902, -0.007056157570332289, -0.001077718916349113, 0.002546788426116109, 0.0035133049823343754, -0.011865295469760895, 0.00014746675151400268, -0.002144441707059741, -0.003908042795956135, -0.001664106734097004, -0.0003319191455375403, -0.0008567984914407134, 0.0047289589419960976, -0.0010855327127501369, 0.006294196005910635, 0.0018141735345125198, -0.006778405979275703, 0.01619924232363701, -0.0057700746692717075, -0.004565163515508175, 0.004732946399599314, 0.0027644082438200712, -0.0030514292884618044, -0.007056310772895813, -0.0016054115258157253, 0.001806703512556851, 0.007347842678427696, -0.0030413391068577766, -0.007337159942835569, -0.004443964920938015, 0.001069314545020461, -0.009071349166333675, 0.003838747041299939, 0.012308500707149506, -0.003445314709097147, 0.0043874457478523254, 0.0008077326929196715, -0.00540895015001297, -0.013660812750458717, 0.05405290424823761, -0.0007675459492020309, 0.0027811499312520027, 0.006670154631137848, -0.008163069374859333, -0.0009181562345474958, -0.002249554032459855, 0.006728558801114559, -0.007456627208739519, -0.007745862007141113, 0.009229632094502449, -0.004936088342219591, 0.0014008893631398678, 0.001633290434256196, -0.0007258506375364959, 0.016092538833618164, -0.006159864366054535, -0.017644476145505905, -0.015184876509010792, 0.008572838269174099, -0.003313805442303419, -0.005701920948922634, 0.007479336112737656, -0.0018364040879532695, -0.0005401546368375421, 0.0007308831554837525, 0.007736684754490852, -0.0020055167842656374, -0.0005972620565444231, -0.0012789207976311445, -0.003596038091927767, 0.0020698714070022106, 0.0024473683442920446, 0.005060091149061918, 0.009116558358073235, -0.0012297809589654207, 0.004716368857771158, -0.0016448500100523233, -0.0011524439323693514, -0.0031109554693102837, 0.005169849842786789, 0.006474632304161787, -0.0026608386542648077, -0.004230391699820757, 0.005041929893195629, 0.006040556356310844, 0.0018859343836084008, 0.013326245360076427, 0.0003568517859093845, -0.005079117603600025, 0.011278383433818817, 0.01048270333558321, -0.0019661923870444298, 0.009319343604147434, 0.0015611601993441582, 0.006768884137272835, 0.0012817316455766559, -0.009439668618142605, -0.010441502556204796, -0.00026534090284258127, 0.005639980081468821, 0.006315762642771006, -0.0034719298128038645, 0.0006677839555777609, 0.0024203662760555744, -0.004306340124458075, -0.007736083585768938, -0.005368193611502647, -0.0023866575211286545, 0.0025113264564424753, 0.0030869259499013424, 0.07163185626268387, -0.0050936248153448105, -0.0031356331892311573, -0.010958638042211533, 0.0015248191775754094, -0.001950297737494111, -0.001963395392522216, -0.001350955106317997, 0.00029711524257436395, 0.0030336668714880943, 0.001274763373658061, -0.008473127149045467, -0.011395204812288284, 0.0016650985926389694, 0.002829180331900716, -0.0018220602069050074, 0.002602877328172326, 0.005747735034674406, -0.005688900593668222, 0.0020165767055004835, -0.010820538736879826, -0.0003159756015520543, -0.0006780526018701494, -0.00876532681286335, -0.005742855370044708, -0.0015472536906599998, 0.0029998288955539465, 0.003307232866063714, 0.004616138059645891, -0.002961629768833518, 0.006393473595380783, -0.0006912980461493134, 0.0017092309426516294, -0.004054451361298561, -0.0004747778584714979, -0.0062197488732635975, 0.00973435677587986, 0.0014179142890498042, -0.012613892555236816, -0.005550130736082792, -0.002064852509647608, -0.0001586388680152595, -0.007255639880895615, 0.0060424283146858215, -0.0008521771524101496, 0.00869091134518385, -0.0034349316265434027, 0.0037719453684985638, -0.003953192383050919, 0.0017920499667525291, -0.012251033447682858, 0.0037781144492328167, -0.18022850155830383, 0.012237303890287876, 0.0010608489392325282, -0.003719553118571639, -0.00012435582175385207, -0.015763746574521065, -0.009118751622736454, 0.0012508098734542727, 0.010602826252579689, 0.0006100953323766589, 0.00017498189117759466, -0.0038620298728346825, 0.004883315414190292, 0.005269740708172321, -0.0014660324668511748, -0.003941062372177839, 0.004780141171067953, -0.0066002714447677135, 0.0013745507458224893, 0.004352451767772436, 0.005958056543022394, 0.008701559156179428, 0.002048980677500367, 0.002479821676388383, -0.0017968363827094436, -0.004648618400096893, 0.0038525755517184734, -0.0013677261304110289, 0.0038194626104086637, -0.012068751268088818, -0.005510677583515644, -0.004355943761765957, -0.0009396219975315034, 0.0026761714834719896, 0.0026432981248944998, -0.00011369577987352386, 0.007250520866364241, 0.002614496275782585, -0.008152533322572708, 0.00673747668042779, -0.005751052405685186, 0.03244342654943466, 0.002710091881453991, 0.007337835617363453, 0.0017098133685067296, -0.0037657557986676693, -0.005312382709234953, 0.009962239302694798, 0.0034440818708389997, 0.01289913710206747, -0.013668892905116081, -0.0024740290828049183, 0.003876462811604142, 0.019396264106035233, -0.005954683758318424, -0.008240040391683578, -0.007857835851609707, -0.007357149384915829, 0.004350550007075071, 0.009546469897031784, 0.01043291948735714, -0.008225432597100735, 0.009910283610224724, -0.002052922733128071, -0.02000855654478073, 0.0035393217112869024, -0.003009683219715953, -0.007540784776210785, -0.0003384109295438975, 0.005603187717497349, 0.012278418987989426, -0.0021980006713420153, 0.006986149121075869, -0.0016611432656645775, 0.004922079853713512, -0.0026673770043998957, 0.005959723144769669, -0.0010470501147210598, 0.004313760437071323, -0.009304029867053032, 0.010867332108318806, -0.008701256476342678, -0.0005817244527861476, 0.0020630175713449717, -0.005070766434073448, 0.00996315572410822, 0.007046613842248917, -0.0036663978826254606, -0.0013841629261150956, -0.010739311575889587, -0.002771149855107069, 0.001811016583815217, 0.0035279635339975357, -0.00782552920281887, 0.0027670070994645357, -0.00022226832516025752, 0.005099890753626823, 0.00691615417599678, -0.009274015203118324, 0.004937740508466959, 0.005613097921013832, -0.008481794036924839, -0.0007790227537043393, -0.006540318485349417, 0.003991726320236921, 0.003996522165834904, -0.004633546806871891, -0.010276572778820992, 0.004185556899756193, -0.006631084717810154, -0.0068876915611326694, 0.001918299705721438, -0.011175532825291157, -0.0063238805159926414, 0.0008955584489740431, -0.011535502038896084, 0.001127360388636589 ]
8ab58aaa336c1e253b3a0048b5e6954db5635335
276
py
Python
backend/app/schemas/__init__.py
kommurisaikumar/savings-manager-server
ed699abddf3cecdd4056aaee0129fbb1ef3762f6
[ "MIT" ]
null
null
null
backend/app/schemas/__init__.py
kommurisaikumar/savings-manager-server
ed699abddf3cecdd4056aaee0129fbb1ef3762f6
[ "MIT" ]
null
null
null
backend/app/schemas/__init__.py
kommurisaikumar/savings-manager-server
ed699abddf3cecdd4056aaee0129fbb1ef3762f6
[ "MIT" ]
null
null
null
from .users import User, UserCreate, UserUpdate from .transactions import Transaction, TransactionCreate, TransactionUpdate from .accounts import Account, AccountList, AccountSingle, AccountCreate, AccountUpdate from .categories import Category, CategoryCreate, CategoryUpdate
69
87
0.858696
1
0.6996
[ 0.0036832252517342567, 0.023943789303302765, 0.010162788443267345, 0.0053580813109874725, 0.0061687203124165535, -0.001986814197152853, -0.012101290747523308, 0.0022750922944396734, -0.008718747645616531, 0.0033273203298449516, 0.0037302172277122736, 0.005137250758707523, 0.008032349869608879, -0.018050305545330048, 0.000227912692935206, 0.020940681919455528, -0.0583963617682457, 0.003231184324249625, -0.0045218998566269875, 0.0017478128429502249, -0.008958809077739716, 0.01128604356199503, 0.0069851442240178585, 0.008541041053831577, 0.0038274021353572607, -0.00007404508505715057, 0.012993079610168934, 0.0025075215380638838, -0.005709198769181967, -0.002463374752551317, -0.0017383230151608586, -0.0014008715515956283, -0.0068891760893166065, -0.009265659376978874, 0.007056606933474541, -0.0020606182515621185, 0.003941860981285572, -0.018108094111084938, 0.011328876949846745, -0.007198533043265343, -0.006706399843096733, -0.019118163734674454, -0.0026459370274096727, 0.006287644617259502, -0.013037937693297863, 0.004929855465888977, -0.004944981541484594, 0.0020994858350604773, -0.011719133704900742, 0.0006653707241639495, -0.008564399555325508, 0.003490561619400978, 0.012082261964678764, 0.0009856355609372258, -0.006310204043984413, -0.009381787851452827, 0.010973379947245121, 0.0013252460630610585, -0.013523509725928307, -0.0015582380583509803, -0.0021338309161365032, -0.0002775781904347241, 0.005790309049189091, 0.004478598013520241, -0.023366473615169525, -0.006475040689110756, -0.002564198337495327, 0.0023095286451280117, -0.0018956168787553906, 0.005737177561968565, 0.0023004969116300344, -0.0000011249023827986093, 0.010094922035932541, 0.003116283332929015, 0.0076736873015761375, -0.000006323020443232963, -0.0017661693273112178, 0.001255632028914988, 0.011139522306621075, 0.001800157711841166, 0.006624617148190737, -0.010391691699624062, 0.005191834643483162, 0.009028415195643902, 0.014299099333584309, 0.012471779249608517, 0.021631859242916107, -0.011856019496917725, 0.04323436692357063, 0.006629255134612322, -0.0129805076867342, 0.00412738649174571, -0.008163049817085266, -0.004742693621665239, -0.004080354701727629, -0.032972488552331924, 0.001713701756671071, -0.007180815562605858, 0.0015626986278221011, 0.0027383663691580296, 0.0004607295850291848, 0.0050690658390522, -0.005145765375345945, -0.0043606930412352085, -0.01083549577742815, 0.012323599308729172, -0.012188044376671314, -0.0038499031215906143, 0.006762483157217503, 0.002442191354930401, -0.01280177291482687, -0.00017765839584171772, 0.0013511800207197666, -0.012199309654533863, 0.006723211146891117, 0.004646803718060255, -0.006090776529163122, 0.05690859258174896, -0.0015990829560905695, 0.001961125759407878, -0.004677427001297474, -0.0024195846635848284, -0.000940705940593034, 0.009089385159313679, 0.010766981169581413, -0.006492490880191326, 0.01124817505478859, 0.0038117554504424334, 0.00289707793854177, 0.001975237624719739, -0.0024680455680936575, 0.009579894132912159, -0.004077598452568054, -0.0007825859938748181, 0.00018452369840815663, -0.010882583446800709, 0.007627447601407766, -0.0038072471506893635, -0.0036739492788910866, -0.00306609645485878, 0.000976715935394168, -0.015647293999791145, -0.0033628561068326235, 0.0010503068333491683, 0.00006688944267807528, -0.01588570326566696, -0.0034099025651812553, -0.004551103804260492, -0.006035271566361189, 0.0036107441410422325, 0.007942290045320988, 0.003935968037694693, 0.002245064591988921, -0.004193337634205818, -0.005551451351493597, 0.0003142122004646808, -0.0063155097886919975, 0.0067593809217214584, 0.006804629694670439, 0.0016967757837846875, -0.006783219054341316, -0.0031413917895406485, 0.004918209742754698, 0.005920334253460169, 0.0000013308205097928294, -0.002370391273871064, -0.00595366396009922, 0.009771205484867096, 0.0019275719532743096, 0.0019877166487276554, 0.0109499366953969, -0.004279336892068386, -0.0011129090562462807, 0.000845224189106375, 0.0013215801445767283, -0.0006683039246127009, 0.0024843504652380943, 0.009034990333020687, -0.0059882462956011295, -0.007018580567091703, 0.007208438124507666, 0.002739972434937954, 0.012041314505040646, 0.0074623506516218185, -0.00006783552089473233, 0.003656239015981555, -0.004301582463085651, 0.00020139488333370537, 0.004012739285826683, -0.006708845961838961, 0.009650389663875103, 0.005808697547763586, -0.013394440524280071, -0.005959163419902325, 0.0021728738211095333, -0.011971304193139076, 0.002024108776822686, 0.016144433990120888, 0.010250707156956196, 0.0005188003415241838, 0.004332545213401318, -0.009090498089790344, 0.0008371775038540363, 0.006089726462960243, -0.0010446602245792747, -0.01089849229902029, -0.9513154625892639, 0.0037931271363049746, 0.004535515792667866, -0.0006970778340473771, 0.0038455824833363295, -0.0005301080527715385, 0.003135213628411293, 0.0046110861003398895, 0.01097631361335516, -0.011593570001423359, -0.007038505282253027, -0.013714022003114223, -0.014222199097275734, -0.000685398408677429, -0.010607458651065826, -0.0030944577883929014, -0.0022485824301838875, -0.009482619352638721, 0.0012113358825445175, -0.002914222190156579, -0.0017866204725578427, 0.009550152346491814, -0.00242901430465281, 0.00713780103251338, 0.003505583619698882, 0.009251593612134457, -0.008012531325221062, -0.0021337608341127634, -0.0005161436856724322, -0.001558313611894846, -0.005524666979908943, -0.014890654012560844, -0.006537344306707382, -0.0012963326880708337, 0.015116924419999123, -0.00016628787852823734, 0.008797980844974518, -0.0009753662161529064, 0.0066562071442604065, -0.011069586500525475, 0.005780383013188839, 0.002727582585066557, 0.003126800525933504, -0.02675819583237171, 0.0018026757752522826, -0.003596849972382188, -0.008958001621067524, 0.008928250521421432, 0.005327736958861351, -0.0031789520289748907, -0.004776129964739084, -0.004971588030457497, 0.008137203752994537, -0.011194753460586071, 0.007513835560530424, -0.008797351270914078, -0.00565089238807559, -0.0016001379117369652, -0.009978572838008404, 0.0012677473714575171, 0.006548469420522451, -0.002083598868921399, -0.004133084788918495, -0.0030967690981924534, -0.0011851337039843202, 0.0014798305928707123, -0.0043824538588523865, -0.019123759120702744, -0.0078120180405676365, -0.0030639655888080597, 0.005367093253880739, -0.002213063882663846, -0.0034143985249102116, 0.003469648538157344, -0.012649900279939175, 0.004058393649756908, 0.004006171599030495, 0.001936388318426907, -0.009323284029960632, 0.002812604419887066, -0.006778374779969454, -0.0076237390749156475, 0.00535516208037734, -0.007570470683276653, -0.005554284900426865, 0.0007978468202054501, 0.005448948126286268, 0.0071256826631724834, -0.0069412123411893845, 0.0026358955074101686, 0.009903183206915855, -0.0010806397767737508, -0.011592202819883823, 0.010754450224339962, 0.004724267870187759, 0.001877305912785232, 0.0002513937943149358, 0.0025420691817998886, 0.007347729057073593, 0.010781023651361465, 0.006094354670494795, 0.004467256832867861, -0.0009750535828061402, 0.014933951199054718, -0.0014265014324337244, 0.0027287285774946213, -0.000006405757176253246, -0.00045277061872184277, -0.006754272151738405, 0.0009901317534968257, -0.004407329950481653, -0.00033616076689213514, -0.01298653893172741, -0.010794986970722675, -0.0023554146755486727, 0.0015562479384243488, 0.001210378366522491, -0.0024313589092344046, 0.000005434548256744165, 0.002419067779555917, 0.011433000676333904, 0.0008971982169896364, -0.00025278248358517885, 0.0008556941174902022, -0.000599140243139118, -0.01119396835565567, 0.019926872104406357, -0.015814868733286858, 0.00486908620223403, -0.0005378768546506763, -0.01605360209941864, 0.009038003161549568, 0.014295906759798527, -0.0071875290013849735, -0.000702614604961127, 0.004302758723497391, 0.006862003821879625, -0.0006141162011772394, -0.006236588582396507, -4.536312587788416e-7, -0.01831701584160328, 0.0007589240558445454, 0.022652816027402878, 0.005036772228777409, 0.012729190289974213, 0.011351504363119602, -0.005299329292029142, 0.0018836085218936205, 0.010150803253054619, 0.00016823048645164818, 0.014892580918967724, -0.010168404318392277, -0.00147555663716048, 0.003167698159813881, -0.005732477176934481, 0.002528321696445346, -0.0004011001728940755, 0.0018457683036103845, -0.0011378201888874173, 0.0006214975146576762, -0.005412427242845297, -0.00757479527965188, -0.017407121136784554, -0.0024837309028953314, 0.01160825602710247, -0.003563045524060726, 0.0014465453568845987, -0.008205958642065525, 0.007573449518531561, 0.004631527233868837, 0.006457137875258923, -0.0001937902852660045, -0.002882043831050396, 0.008052140474319458, 0.013909758999943733, -0.004722641780972481, 0.005421582609415054, 0.0011501528788357973, 0.0014229125808924437, 0.005355056840926409, 0.010110186412930489, -0.014809397049248219, 0.00019825808703899384, 0.002769719110801816, 0.003054071916267276, 0.0026360598858445883, -0.004982613027095795, -0.009897761046886444, -0.004889530595391989, 0.004338840954005718, -0.0059882877394557, 0.002298839623108506, 0.0021843165159225464, 0.0048570227809250355, -0.011789376847445965, -0.0010083179222419858, -0.002529715420678258, -0.01192113384604454, 0.010821153409779072, -0.004572675563395023, 0.0048344871029257774, 0.01327335461974144, 0.006188335362821817, -0.018063779920339584, 0.008910567499697208, 0.0101688914000988, -0.00357748637907207, 0.005113393533974886, 0.005488068331032991, -0.00627420237287879, -0.023025885224342346, 0.0033489414490759373, -0.01572788506746292, 0.0024609121028333902, -0.005260442849248648, 0.002623382955789566, -0.008277151733636856, 0.01563735492527485, 0.002460399642586708, -0.010726522654294968, -0.00475335493683815, -0.007241134997457266, 0.009695449844002724, -0.0013766894116997719, -0.0020212368108332157, -0.003445045091211796, -0.0028771772049367428, -0.006787063088268042, -0.0000671285524731502, -0.0014787586405873299, 0.005669896956533194, 0.0033482606522738934, -0.006515286397188902, 0.0003473212418612093, -0.00004172755507170223, -0.0005802886444143951, 0.0030114746186882257, -0.013609341345727444, 0.0005189365474507213, 0.006917718797922134, -0.002323738532140851, -0.006415720097720623, -0.0020972099155187607, -0.0032935584895312786, -0.008813360705971718, -0.009646778926253319, -0.005016442853957415, -0.0007311948575079441, -0.008543222211301327, -0.009608146734535694, -0.004605005960911512, -0.007456679362803698, 0.002599544357508421, -0.009088870137929916, 0.009981033392250538, 0.003712765406817198, -0.007134967017918825, 0.01026875525712967, -0.00491245137527585, 0.005721128545701504, 0.006166290957480669, 0.010704140178859234, -0.0006400567363016307, -0.007229282520711422, -0.0077218650840222836, 0.011977980844676495, -0.008207034319639206, -0.0027403123676776886, 0.016234472393989563, -0.00037453151890076697, 0.009220561012625694, -0.001778401667252183, -0.0013423983473330736, 0.004084977321326733, 0.004730644170194864, -0.017589479684829712, 0.0018681747606024146, -0.0038050832226872444, 0.0011069087777286768, 0.00708228861913085, -0.006812317296862602, 0.003851155284792185, 0.00424149027094245, 0.0010812884429469705, -0.012149564921855927, -0.0013940278440713882, -0.0006546059739775956, 0.003886522725224495, -0.012780989520251751, 0.0001471065916121006, -0.005154299549758434, -0.002419685712084174, -0.005295588634908199, 0.00006279780063778162, -0.0007808399386703968, 0.008201906457543373, -0.007730688899755478, 0.00867474265396595, -0.0008646226488053799, -0.005582913290709257, 0.014517690986394882, -0.0053450074046850204, -0.007838207297027111, 0.00420595146715641, 0.0007060623029246926, 0.0025211244355887175, -0.00996144488453865, -0.00164608855266124, 0.002024830086156726, 0.0009780061664059758, -0.00209131371229887, -0.010544306598603725, -0.003411229234188795, -0.003180348314344883, -0.008963403292000294, 0.0001272210938623175, 0.009205060079693794, 0.0005522904102690518, 0.0034475403372198343, 0.001483506872318685, -0.008037606254220009, -0.01658019796013832, 0.05579404905438423, 0.00032112005283124745, 0.0006485229823738337, 0.006936957594007254, -0.005667650606483221, -0.005461554508656263, -0.003420452354475856, 0.0072458176873624325, -0.006293578539043665, -0.005990913137793541, 0.010723221115767956, -0.003381844377145171, 0.0014811481814831495, -0.004690056666731834, -0.0041596307419240475, 0.019459089264273643, -0.004705409053713083, -0.015207862481474876, -0.014926140196621418, 0.003241576487198472, -0.006100232247263193, -0.006975493393838406, 0.0071561625227332115, -0.003844566410407424, -0.005035221576690674, 0.0023706716019660234, 0.0072266836650669575, -0.0016867772210389376, -0.0020680674351751804, -0.0020106129813939333, -0.0017599767306819558, -0.0012746632564812899, 0.003100363537669182, 0.0032095308415591717, 0.012269345112144947, -0.001019880874082446, 0.007208755239844322, -0.003786972025409341, -0.0014151391806080937, 0.00014702929183840752, 0.007936683483421803, 0.006606190465390682, -0.0006157264579087496, -0.002383782062679529, 0.00353683321736753, 0.0028465765062719584, -0.0035880396608263254, 0.015425647608935833, 0.0020371072459965944, -0.0020703065674751997, 0.006972936447709799, 0.009144829586148262, 0.0006101081962697208, 0.012665712274610996, 0.0005317881004884839, 0.004918164573609829, 0.005748058669269085, -0.009768832474946976, -0.00746371503919363, 0.0000030000271635799436, 0.005424025934189558, 0.009070311672985554, -0.0020268517546355724, 0.003927410580217838, 0.0009584744111634791, -0.004157924093306065, -0.009314197115600109, -0.008376020938158035, -0.002032012213021517, 0.0010941789951175451, 0.0044104852713644505, 0.0696248710155487, -0.01004145760089159, -0.0016658925451338291, -0.007729601580649614, 0.00204501417465508, 0.00039996884879656136, -0.0012363282730802894, 0.00001069448990165256, -0.0015853745862841606, 0.0028763744048774242, 0.0054029137827456, -0.007515983656048775, -0.008335298858582973, -0.00039449974428862333, 0.003407465759664774, -0.0019261507550254464, 0.0026831957511603832, 0.008080623112618923, -0.00817037932574749, 0.007800976745784283, -0.017059966921806335, 0.00021638871112372726, -0.0027712304145097733, -0.005104035139083862, -0.0014358501648530364, -0.0029255254194140434, 0.0002220820460934192, 0.0037108047399669886, 0.004482846707105637, -0.00542433001101017, 0.006412566639482975, -0.001049417071044445, 0.0034056617878377438, -0.0007732399390079081, -0.00382440397515893, -0.005200810264796019, 0.009391063824295998, 0.00044216387323103845, -0.013378042727708817, -0.0034311353228986263, -0.0015711614396423101, -0.0032727308571338654, -0.00555855268612504, 0.003617384936660528, -0.000826051807962358, 0.00839200522750616, -0.001642389688640833, 0.0032816666644066572, -0.0007600993849337101, 0.002596969483420253, -0.01291607040911913, 0.005437406711280346, -0.18772462010383606, 0.011388593353331089, 0.0042641363106667995, -0.005121894646435976, -0.004402415361255407, -0.016879772767424583, -0.010295252315700054, 0.007981500588357449, 0.010248330421745777, 0.002765670884400606, -0.0011230455711483955, 0.0003944638592656702, 0.002485549310222268, 0.0038449359126389027, -0.0029814692679792643, -0.005691713187843561, 0.00467251380905509, -0.002161575946956873, 0.0005220892489887774, 0.005561894737184048, 0.008284647949039936, 0.006868067197501659, 0.004811286460608244, 0.00006770340405637398, 0.0012168854009360075, -0.0014360573841258883, 0.005812123883515596, -0.0020037589129060507, 0.008270504884421825, -0.011777812615036964, -0.004579897038638592, -0.009799224324524403, -0.00355728343129158, 0.0014577698893845081, 0.002712636487558484, -0.0020228945650160313, 0.009102491661906242, -0.001483266707509756, -0.009730616584420204, 0.009539463557302952, -0.00852770172059536, 0.03130410239100456, 0.005677238572388887, 0.0062745483592152596, 0.002032983349636197, -0.0031281602568924427, -0.005019308999180794, 0.007504013832658529, 0.005324788391590118, 0.013981065712869167, -0.01458048913627863, -0.0053671570494771, 0.0012106456561014056, 0.01811981201171875, -0.004462047945708036, -0.009415408596396446, -0.011311592534184456, -0.004647070076316595, 0.002106019528582692, 0.00871187262237072, 0.010423839092254639, -0.005332535598427057, 0.010787718929350376, -0.002676271600648761, -0.02297930233180523, 0.0059415618889033794, 0.0018626388628035784, -0.00962832011282444, 0.004305768758058548, 0.006353461183607578, 0.012640981003642082, -0.0061753131449222565, 0.011889106594026089, -0.0004436293093021959, 0.0024797969963401556, -0.0014188032364472747, 0.012401504442095757, -0.0034308366011828184, 0.009658906608819962, -0.009329834021627903, 0.0112180570140481, -0.010677864775061607, -0.0035273621324449778, 0.001789516070857644, -0.006902000401169062, 0.008114972151815891, 0.004521811846643686, -0.0043995073065161705, 0.00006923417095094919, -0.012722735293209553, -0.0034215704072266817, 0.002997560892254114, 0.00398925319314003, -0.009753840044140816, 0.004040788859128952, -0.002054818207398057, 0.007553312461823225, 0.006745613180100918, -0.008283537812530994, 0.007380478549748659, 0.0020531213376671076, -0.00954593624919653, -0.00006990395922912285, -0.006451783701777458, 0.004028696566820145, 0.0017786785028874874, -0.009431730024516582, -0.012215893715620041, 0.007510642521083355, -0.0031011116225272417, -0.003416578285396099, 0.004363460000604391, -0.010132834315299988, -0.007966133765876293, 0.0014283485943451524, -0.013325178995728493, -0.0004511039878707379 ]
8ab7c4d71edafc2000970ee8f5e485db6a4fa978
872
py
Python
vimfiles/bundle/vim-python/submodules/pylint/tests/functional/s/super/super_with_arguments.py
ciskoinch8/vimrc
5bf77a7e7bc70fac5173ab2e9ea05d7dda3e52b8
[ "MIT" ]
463
2015-01-15T08:17:42.000Z
2022-03-28T15:10:20.000Z
vimfiles/bundle/vim-python/submodules/pylint/tests/functional/s/super/super_with_arguments.py
ciskoinch8/vimrc
5bf77a7e7bc70fac5173ab2e9ea05d7dda3e52b8
[ "MIT" ]
52
2015-01-06T02:43:59.000Z
2022-03-14T11:15:21.000Z
vimfiles/bundle/vim-python/submodules/pylint/tests/functional/s/super/super_with_arguments.py
ciskoinch8/vimrc
5bf77a7e7bc70fac5173ab2e9ea05d7dda3e52b8
[ "MIT" ]
249
2015-01-07T22:49:49.000Z
2022-03-18T02:32:06.000Z
class Foo: pass class Bar(Foo): def __init__(self): super(Bar, self).__init__() # [super-with-arguments] class Baz(Foo): def __init__(self): super().__init__() class Qux(Foo): def __init__(self): super(Bar, self).__init__() class NotSuperCall(Foo): def __init__(self): super.test(Bar, self).__init__() class InvalidSuperCall(Foo): def __init__(self): super(InvalidSuperCall.__class__, self).__init__() def method_accepting_cls(cls, self): # Using plain `super()` is not valid here, since there's no `__class__` cell found # (Exact exception would be 'RuntimeError: super(): __class__ cell not found') # Instead, we expect to *not* see a warning about `super-with-arguments`. # Explicitly passing `cls`, and `self` to `super()` is what's required. super(cls, self).__init__()
24.222222
86
0.65711
1
0.9666
[ 0.0029379338957369328, 0.026569649577140808, 0.006964178290218115, 0.00014530110638588667, 0.007062758784741163, -0.00518843112513423, -0.012398004531860352, 0.0039151497185230255, -0.005383756011724472, -0.0016579710645601153, 0.0033042768482118845, 0.0006638653576374054, 0.005611508619040251, -0.014806895516812801, 0.000490075908601284, 0.01959395222365856, -0.05544112250208855, 0.0024742993991822004, -0.00507016247138381, 0.004810747224837542, -0.010428800247609615, 0.009592818096280098, 0.0070656668394804, 0.008224204182624817, 0.0052503542974591255, 0.00032913099857978523, 0.009243997745215893, 0.003883887082338333, -0.007141567766666412, -0.00843137875199318, 0.0018816515803337097, -0.0029183216392993927, -0.005640915594995022, -0.009451120160520077, 0.005854761693626642, -0.0002014019264606759, -0.0018242872320115566, -0.01711837574839592, 0.011541938409209251, -0.006590962875634432, -0.009444662369787693, -0.02265084907412529, -0.0031852764077484608, 0.004637542180716991, -0.010079587809741497, 0.0029476857744157314, -0.003934360109269619, 0.003262336365878582, -0.012666015885770321, 0.005447023548185825, -0.01166651863604784, 0.005218280013650656, 0.01288473792374134, 0.0062233638018369675, -0.006125659681856632, -0.0072685182094573975, 0.012554753571748734, 0.0010992625029757619, -0.011117793619632721, 0.003505057655274868, -0.00564780505374074, -0.0023600158747285604, 0.003631069790571928, 0.0014173488598316908, -0.013836354948580265, -0.006947027985006571, -0.004977463744580746, 0.004775736015290022, -0.002743867691606283, 0.005959476809948683, 0.0002878116792999208, -0.002028943970799446, 0.010864472948014736, 0.0026417251210659742, 0.003876027651131153, -0.005669725127518177, -0.003100915811955929, -0.0011647803476080298, 0.007809861563146114, 0.002209827769547701, 0.006019279360771179, -0.009911736473441124, 0.004817725159227848, 0.010727851651608944, 0.012843160890042782, 0.007658411283046007, 0.01952618919312954, -0.011822503060102463, 0.045295290648937225, 0.010166478343307972, -0.009956836700439453, 0.0010366373462602496, -0.006832670886069536, -0.0003683366521727294, -0.0026212006341665983, -0.02777218632400036, 0.0016521463403478265, -0.006127519533038139, -0.0006928702350705862, 0.0041411034762859344, 0.0003224379906896502, 0.0054419804364442825, -0.0006822887226007879, 0.00039466324960812926, -0.009326392784714699, 0.013955256901681423, -0.008794853463768959, 0.0005187162896618247, 0.0089485514909029, 0.0032333158887922764, -0.014206081628799438, -0.002968178829178214, 0.003520003752782941, -0.012941188178956509, 0.004077273420989513, -0.00029299064772203565, -0.008570990525186062, 0.05815849080681801, 0.0018056692788377404, 0.003280495060607791, -0.007568659260869026, -0.0005421536043286324, 0.0018154019489884377, 0.007963966578245163, 0.010762631893157959, -0.004523389041423798, 0.010983353480696678, 0.007574812974780798, 0.0034270151518285275, 0.007346051279455423, -0.0006428917986340821, 0.009364684112370014, -0.0037014379631727934, -0.0026542977429926395, 0.00039311268483288586, -0.0066162836737930775, 0.005993816535919905, 0.0005818951176479459, -0.005510214250534773, 0.0011422003153711557, 0.0005713332793675363, -0.011289960704743862, 0.0011715785367414355, -0.007166416849941015, 0.003906611818820238, -0.009132944978773594, -0.00660362932831049, -0.008445234969258308, -0.003421710804104805, 0.002254139631986618, 0.008402152918279171, 0.00726514495909214, 0.00436526769772172, -0.006756719667464495, -0.007878251373767853, -0.003844100283458829, -0.003274132963269949, -0.0013053129659965634, 0.008338816463947296, 0.004251201171427965, -0.004914308898150921, -0.004465604200959206, 0.0028370236977934837, 0.00672270730137825, -0.0006014650571160018, -0.0014122568536549807, -0.010844497941434383, 0.008583924733102322, 0.0008709232206456363, 0.002546197734773159, 0.012510983273386955, -0.004550761543214321, -0.002805383875966072, -0.00000961105979513377, 0.0014259925810620189, 0.0016969062853604555, 0.00510375713929534, 0.006877170875668526, -0.0034869492519646883, -0.003920145332813263, 0.0032514184713363647, 0.004210879094898701, 0.00909099355340004, 0.0072660744190216064, -0.0010284185409545898, 0.004921216983348131, -0.0026696405839174986, -0.001478253398090601, 0.004638539627194405, -0.0052028377540409565, 0.005446130875498056, 0.005202095955610275, -0.01545910444110632, -0.009326268918812275, -0.0018987981602549553, -0.00871274247765541, 0.0010284563759341836, 0.016758423298597336, 0.010797606781125069, -0.0021670835558325052, 0.004056243691593409, -0.008936195634305477, 0.0004370698006823659, 0.005601738579571247, 0.0034586137626320124, -0.012057163752615452, -0.955125629901886, 0.004194589331746101, 0.004683447070419788, 0.00023865528055466712, 0.0060979705303907394, 0.002903565764427185, 0.0027525750920176506, 0.0027241529896855354, 0.01631520316004753, -0.010095115751028061, -0.008724307641386986, -0.012970219366252422, -0.011516542173922062, 0.00021243102673906833, -0.006518157664686441, -0.0030807468574494123, -0.005750888492912054, -0.005964122712612152, -0.0007577589713037014, -0.002810318022966385, -0.001427236944437027, 0.007511902134865522, -0.00033303003874607384, 0.004546549171209335, 0.003866856452077627, 0.004815838299691677, -0.006573365069925785, 0.0008226112113334239, -0.0009200298227369785, -0.0013454034924507141, -0.007807502523064613, -0.012139673344790936, -0.004676009528338909, -0.0012275443878024817, 0.012012505903840065, -0.002538660541176796, 0.008312905207276344, -0.0015010318020358682, -0.00013334453979041427, -0.006918752565979958, 0.0046731880865991116, 0.0002271178673254326, 0.00573199475184083, -0.03282064571976662, -0.001074603758752346, -0.0027052422519773245, -0.009917161427438259, 0.009838416241109371, 0.00028781217406503856, -0.0018500488949939609, -0.0009706898126751184, -0.006207627709954977, 0.009038040414452553, -0.005890566390007734, 0.0002551696670707315, -0.003217247547581792, -0.008588219061493874, -0.002084755804389715, -0.010225050151348114, 0.0026862656231969595, 0.0071297441609203815, -0.003829282708466053, -0.003437924664467573, -0.0028750079218298197, 0.0013075590832158923, 0.001538916607387364, 0.0017717164009809494, -0.016283243894577026, -0.009447571821510792, -0.0016130784060806036, 0.0025824569165706635, -0.000028227181246620603, -0.0021877544932067394, 0.002932557137683034, -0.009739537723362446, 0.0065595111809670925, 0.0016938979970291257, 0.00156331155449152, -0.011444523930549622, 0.0023552614729851484, -0.0080033577978611, -0.009867954067885876, 0.0034930359106510878, -0.008340810425579548, -0.004802690353244543, -0.0011846930719912052, 0.001465074485167861, 0.006036568433046341, -0.0050875782035291195, 0.0031466709915548563, 0.010661139152944088, -0.0049190642312169075, -0.009473471902310848, 0.006352502852678299, 0.00770505890250206, 0.0007986898417584598, -0.0006368670146912336, 0.0033198108430951834, 0.009929845109581947, 0.008614787831902504, -0.0005364831886254251, 0.005663454532623291, 0.00016607571160420775, 0.010258547961711884, 0.00000782825554779265, 0.0027195625007152557, -0.0006263690302148461, 0.0012628923868760467, -0.0063773030415177345, -0.007207257207483053, -0.0029744068160653114, -0.0029688996728509665, -0.01397885475307703, -0.006061742547899485, -0.005577792413532734, 0.003163993591442704, 0.000922632054425776, -0.003970528021454811, 0.002956425305455923, 0.0017655211267992854, 0.009547417052090168, 0.002007407369092107, -0.0026155386585742235, 0.0035737804137170315, 0.0033940335270017385, -0.009278216399252415, 0.012933315709233284, -0.01195155456662178, 0.007095749489963055, -0.0009565983200445771, -0.01390806958079338, 0.006829629186540842, 0.011099177412688732, -0.008021936751902103, 0.00118244846817106, 0.0017868491122499108, 0.0004884692607447505, -0.00008527071622665972, -0.007467786315828562, -0.003359562251716852, -0.016138533130288124, -0.002335796831175685, 0.020275741815567017, 0.000814509519841522, 0.0118782389909029, 0.01266415510326624, -0.005238019395619631, 0.002770758233964443, 0.0034315278753638268, 0.00245184195227921, 0.01332312822341919, -0.009072341024875641, 0.0007547526038251817, -0.001337899244390428, -0.005074996501207352, -0.00018346187425777316, 0.00465763546526432, 0.007221684325486422, -0.003483864013105631, 0.004528335761278868, -0.00826527364552021, -0.008197298273444176, -0.018556304275989532, -0.0012344375718384981, 0.009340557269752026, -0.004529611673206091, 0.0060115051455795765, -0.01235289964824915, 0.004980389028787613, 0.007758674211800098, 0.00338604929856956, 0.0002820090448949486, 0.0016899232286959887, 0.00797861348837614, 0.010997395031154156, -0.005762047134339809, 0.005225058179348707, 0.0028940741904079914, -0.002702766563743353, 0.002105174120515585, 0.00959696713835001, -0.007982667535543442, -0.004043415654450655, -0.0006636953330598772, -0.0004893708392046392, 0.0032624376472085714, -0.0018092648824676871, -0.010001370683312416, -0.002881511813029647, 0.004784231539815664, -0.006287585943937302, 0.0028704500291496515, 0.0007421966292895377, 0.00422793161123991, -0.010281345807015896, 0.0013690688647329807, -0.004710570443421602, -0.010056552477180958, 0.011822487227618694, -0.00498076481744647, 0.002433167537674308, 0.012829168699681759, 0.006486318539828062, -0.014297896064817905, 0.008549784310162067, 0.010100636631250381, -0.002895427867770195, 0.0036685557570308447, 0.010808479972183704, -0.001950659672729671, -0.02216353826224804, -0.00015971515676937997, -0.015173744410276413, 0.0071463980711996555, -0.004368635825812817, 0.005872282665222883, -0.007904759608209133, 0.006990727968513966, 0.0039909654296934605, -0.01465656328946352, -0.002050733892247081, -0.009413309395313263, 0.007249752059578896, -0.0013294181553646922, -0.00035374017897993326, -0.002930453047156334, -0.0029743858613073826, -0.004444518126547337, -0.0013757897540926933, 0.001360781490802765, 0.005894987378269434, 0.002363936509937048, -0.002626436296850443, 0.0010210960172116756, -0.005605948157608509, 0.0014491500332951546, 0.004007363226264715, -0.008464270271360874, 0.0019254973158240318, 0.00638749822974205, -0.0007903164369054139, -0.004327543545514345, -0.0023084795102477074, -0.0019402903271839023, -0.009004378691315651, -0.011261207982897758, -0.0035425154492259026, 0.001162507338449359, -0.0033070275094360113, -0.01225481927394867, -0.002522401511669159, -0.006873653270304203, 0.005633878987282515, -0.007607739418745041, 0.004472245927900076, 0.009276813827455044, -0.004787081386893988, 0.00814845785498619, -0.003616383532062173, 0.0021607661619782448, 0.0022313795052468777, 0.00424416596069932, 0.00114774564281106, -0.005668362136930227, -0.011915589682757854, 0.015320348553359509, -0.009293639101088047, -0.0011508092284202576, 0.013021771796047688, 0.0035158933605998755, 0.010982130654156208, -0.0004431544221006334, 0.0006764542777091265, 0.0031248428858816624, 0.008972495794296265, -0.015715932473540306, 0.0017053777119144797, -0.003342111362144351, -0.00007112279126886278, 0.004906392190605402, -0.0024783897679299116, 0.0026333057321608067, 0.006708637345582247, -0.00011511976481415331, -0.006909469608217478, -0.00365293282084167, -0.0013327508931979537, 0.0043738773092627525, -0.012080056592822075, -0.0018567463848739862, -0.006682576145976782, -0.005593234207481146, -0.0022439283784478903, -0.001990665215998888, -0.0010250492487102747, 0.00418485701084137, -0.0006349204923026264, 0.0058257258497178555, 0.003941296134144068, -0.002512493636459112, 0.016262885183095932, -0.00803482998162508, -0.0069695329293608665, 0.0021379461977630854, 0.000201183749595657, 0.00022034806897863746, -0.006519035901874304, -0.005187345668673515, 0.004822691902518272, 0.004724247381091118, -0.003166589420288801, -0.007182297296822071, -0.0009644886013120413, 0.003008912317454815, -0.0077148848213255405, 0.002125019207596779, 0.010092546232044697, -0.003586027305573225, 0.005887461826205254, 0.00005433336627902463, -0.009638086892664433, -0.014841903001070023, 0.055222950875759125, -0.004005274269729853, 0.004716974217444658, 0.007701803930103779, -0.008100382052361965, -0.0009145286749117076, -0.0061165764927864075, 0.007457400672137737, -0.008472570218145847, -0.0063174390234053135, 0.009257343597710133, -0.002270529745146632, 0.0036110070068389177, 0.002443426288664341, -0.001698212930932641, 0.016610480844974518, -0.0017316106241196394, -0.015471470542252064, -0.015405172482132912, 0.011229855939745903, -0.00428532250225544, -0.008139877580106258, 0.0104991365224123, -0.0013472128193825483, -0.005800042767077684, 0.0024748502764850855, 0.00832129642367363, -0.0010763833997771144, 0.00025549583369866014, -0.0019512574654072523, -0.002354273572564125, -0.0009532924159429967, 0.002130648586899042, 0.0068642133846879005, 0.007296361029148102, -0.0030132916290313005, 0.006579414010047913, 0.0010125541593879461, -0.001061899121850729, -0.00007463219662895426, 0.004112827125936747, 0.006402633152902126, -0.0027489345520734787, -0.004671433474868536, 0.006232958287000656, 0.006972727831453085, 0.001618182403035462, 0.013217718340456486, 0.00006824424053775147, -0.006182453595101833, 0.010102933272719383, 0.009674446657299995, -0.0008225630735978484, 0.010396365076303482, -0.0025426563806831837, 0.004789437633007765, 0.0010244054719805717, -0.008932232856750488, -0.013313508592545986, -0.001658453606069088, 0.0027550398372113705, 0.010721413418650627, -0.003303112694993615, -0.002312673954293132, 0.0032578485552221537, -0.0022794243413954973, -0.009357420727610588, -0.008397864177823067, -0.0025876895524561405, -0.004563722759485245, 0.0022583568934351206, 0.07109127938747406, -0.009959829971194267, 0.00041720372973941267, -0.009446697309613228, -0.000764981668908149, 0.0007264948799274862, 0.0015870018396526575, -0.0008207884966395795, -0.0012894414830952883, 0.003745138179510832, 0.0011558912228792906, -0.006438894663006067, -0.012090788222849369, -0.0006374170770868659, 0.0026149351615458727, -0.003703886177390814, 0.005506526213139296, 0.007882485166192055, -0.006347576156258583, 0.001977719599381089, -0.011708789505064487, -0.000545904622413218, -0.0021114302799105644, -0.00839984230697155, -0.001526314066722989, -0.0027241206262260675, 0.005196342244744301, 0.004604094196110964, 0.00546665396541357, -0.005765838082879782, 0.0061514712870121, -0.0023660880979150534, -0.0000975839066086337, -0.003932200837880373, -0.0017986167222261429, -0.00941363163292408, 0.0061877756379544735, 0.0019570717122405767, -0.012035204097628593, -0.003197571262717247, -0.0038452360313385725, 0.0021714051254093647, -0.003979813773185015, 0.004869468510150909, 0.00020850462897215039, 0.010426805354654789, -0.0015974045963957906, 0.0000018348332559980918, -0.005062154494225979, 0.002537823049351573, -0.013666720129549503, 0.0016076843021437526, -0.17911021411418915, 0.009515327401459217, 0.002617510501295328, -0.005711900535970926, -0.0012690287549048662, -0.016499515622854233, -0.010219293646514416, 0.0022191531024873257, 0.010575343854725361, -0.0010958568891510367, 0.0013927608961239457, -0.006099349819123745, 0.0071080648340284824, 0.0042901355773210526, -0.001283339224755764, -0.007438569329679012, 0.0029120631515979767, -0.004540006630122662, -0.0011583685409277678, 0.006552652455866337, 0.00909765437245369, 0.006477666087448597, 0.0038579516112804413, -0.0006934484699741006, -4.7357139010273386e-7, -0.006211535073816776, 0.007836301811039448, -0.00175687565933913, 0.005978022702038288, -0.009866363368928432, -0.0020689782686531544, -0.004754024092108011, -0.004267484415322542, 0.0040891957469284534, 0.0005277189775370061, -0.0008994751842692494, 0.006577369291335344, 0.00439781229943037, -0.008900800719857216, 0.010511796921491623, -0.007536736316978931, 0.031173784285783768, 0.008224456571042538, 0.00944909080862999, 0.000853637873660773, -0.005715150386095047, -0.004528138320893049, 0.007768400013446808, 0.002735212678089738, 0.012154254131019115, -0.012277991510927677, -0.0030438825488090515, 0.0019536123145371675, 0.017077842727303505, -0.004542376380413771, -0.011697204783558846, -0.007362548727542162, -0.005114442203193903, 0.0041571143083274364, 0.008394419215619564, 0.011379387229681015, -0.006456740200519562, 0.00794197153300047, -0.005223663989454508, -0.01961800456047058, 0.0024959887377917767, -0.0034701821859925985, -0.011455604806542397, -0.0013486465904861689, 0.006636182311922312, 0.007148190401494503, -0.0002959776611533016, 0.003554975613951683, -0.001049402984790504, 0.006117044482380152, -0.0015944922342896461, 0.0064160702750086784, -0.0020235655829310417, 0.007180644199252129, -0.009685633704066277, 0.009074600413441658, -0.014241604134440422, -0.003117625368759036, 0.003446995047852397, -0.002887690206989646, 0.012639772146940231, 0.0048193116672337055, -0.001229612622410059, 0.0011615396942943335, -0.010350660420954227, -0.003659489331766963, -0.00097164191538468, 0.0005889929016120732, -0.008820449002087116, 0.00345225865021348, -0.0017385989194735885, 0.006924572866410017, 0.009323669597506523, -0.007625225931406021, 0.004469783511012793, 0.008058016188442707, -0.005870791617780924, 0.007322259712964296, -0.008248301222920418, 0.0004220921255182475, 0.005482551641762257, -0.004948788788169622, -0.006748612504452467, 0.004744770471006632, -0.004931511357426643, -0.007267333567142487, 0.002105916850268841, -0.010383433662354946, -0.008629845455288887, -0.0035534168127924204, -0.012745998799800873, -0.00004752193490276113 ]
8ab863848d8379f82bfc5f650de33e10615f3285
8,132
py
Python
machine.py
yukti07/Dell_Hire_hack
9422b7aaa0b96292191b4b880c0a8fb772fd1864
[ "MIT" ]
null
null
null
machine.py
yukti07/Dell_Hire_hack
9422b7aaa0b96292191b4b880c0a8fb772fd1864
[ "MIT" ]
null
null
null
machine.py
yukti07/Dell_Hire_hack
9422b7aaa0b96292191b4b880c0a8fb772fd1864
[ "MIT" ]
null
null
null
import pandas as pd import matplotlib.pyplot as plt import seaborn as sns from sklearn.model_selection import train_test_split from sklearn.preprocessing import LabelEncoder from sklearn.ensemble import RandomForestClassifier from sklearn.metrics import accuracy_score from flask import flash import numpy as np def check(X, clf): # print("TTTTTTTTTTTTThis is XXXXXXXXXXXX") # print(X) X = np.array(X) labelencoder_X_1 = LabelEncoder() X[:, 1] = labelencoder_X_1.fit_transform(X[:, 1]) labelencoder_X_2 = LabelEncoder() X[:, 2] = labelencoder_X_2.fit_transform(X[:, 2]) labelencoder_X_5 = LabelEncoder() X[:, 5] = labelencoder_X_5.fit_transform(X[:, 5]) labelencoder_X_6 = LabelEncoder() X[:, 6] = labelencoder_X_6.fit_transform(X[:, 6]) labelencoder_X_7 = LabelEncoder() X[:, 7] = labelencoder_X_7.fit_transform(X[:, 7]) labelencoder_X_9 = LabelEncoder() X[:, 9] = labelencoder_X_9.fit_transform(X[:, 9]) labelencoder_X_12 = LabelEncoder() X[:, 12] = labelencoder_X_12.fit_transform(X[:, 12]) p = clf.predict(X) t = () for x in p: if x == 0: a = 'No' else: a = 'Yes' t = t+(a,) return t def analyze(df, clf): feature_importances = pd.DataFrame(clf.feature_importances_, index=['Age', 'BusinessTravel', 'Department', 'DistanceFromHome', 'Education', 'EducationField', 'Gender', 'JobRole', 'JobSatisfaction', 'MaritalStatus', 'MonthlyIncome', 'NumCompaniesWorked', 'OverTime', 'PercentSalaryHike', 'YearsInCurrentRole', 'YearsSinceLastPromotion'],columns=['importance']).sort_values('importance',ascending=False) feature_importances['x1'] = feature_importances.index ax = feature_importances.plot.bar(x='x1', y='importance', rot=90) plt.savefig('templates/graphs/raw/feature_importances.png', frameon=True) intervals = [x for x in range(0, 22000, 2000)] categories = ['<'+str(x) for x in range(2000, 22000, 2000)] df1 = df df1['Income_Categories'] = pd.cut(df.MonthlyIncome, intervals, labels=categories) ax = sns.countplot(x="Income_Categories", hue="Attrition", palette="Set1", data=df1) ax.set(title="Monthly Income vs Attrition", xlabel="Income group", ylabel="Total") plt.xticks(rotation=-30) plt.savefig('templates/graphs/raw/MIvsAttr.png') intervals = [x for x in range(18,63,3)] categories = ['<'+str(x) for x in range(21,63,3)] df1 = df df1['Age_Categories'] = pd.cut(df.Age, intervals, labels=categories) ax = sns.countplot(x="Age_Categories", hue="Attrition", palette="Set1", data=df1) ax.set(title="Age vs Attrition", xlabel="Age group", ylabel="Total") plt.xticks(rotation=-30) plt.savefig('templates/graphs/raw/AgevsAttr.png') intervals = [x for x in range(0,32,2)] categories = ['<'+str(x) for x in range(2,32,2)] df1 = df df1['Distance_from_home'] = pd.cut(df.DistanceFromHome, intervals, labels=categories) ax = sns.countplot(x="Distance_from_home", hue="Attrition", palette="Set1", data=df1) ax.set(title="Distance from home vs Attrition", xlabel="Distance", ylabel="Total") plt.xticks(rotation=-30) plt.savefig('templates/graphs/raw/DistanceFromHomevsAttr.png') ax = sns.countplot(x="PercentSalaryHike", hue="Attrition", palette="Set1", data=df1) ax.set(title="Salary Hike Percentage vs Attrition", xlabel="Salary Hike Percentage", ylabel="Total") plt.savefig('templates/graphs/raw/PercentSalaryHikevsAttr.png') ax = sns.countplot(x="NumCompaniesWorked", hue="Attrition", palette="Set1", data=df1) ax.set(title="Number Of Previously Worked Companies vs Attrition", xlabel="Number Of Previously Worked Companies", ylabel="Total") plt.savefig('templates/graphs/raw/NPWCvsAttr.png') intervals = [x for x in range(0,22,2)] categories = ['<'+str(x) for x in range(2,22,2)] df1 = df df1['Current_Role'] = pd.cut(df.YearsInCurrentRole, intervals, labels=categories) ax = sns.countplot(x="Current_Role", hue="Attrition", palette="Set1", data=df1) ax.set(title="Number Of Years in Current Role vs Attrition", xlabel="Number Of Years in Current Role", ylabel="Total") plt.xticks(rotation=-30) plt.savefig('templates/graphs/raw/YICRvsAttr.png') ax = sns.countplot(x="OverTime", hue="Attrition", palette="Set1", data=df1) ax.set(title="Over Time vs Attrition", xlabel="Over Time", ylabel="Total") plt.savefig('templates/graphs/raw/OverTimevsAttr.png') ax = sns.countplot(x="JobRole", hue="Attrition", palette="Set1", data=df1) ax.set(title="Job Role vs Attrition", xlabel="Job Role", ylabel="Total") plt.xticks(rotation=70) plt.savefig('templates/graphs/raw/JobRolevsAttr.png') intervals = [x for x in range(0,18,2)] categories = ['<'+str(x) for x in range(2,18,2)] df1 = df df1['Promotion'] = pd.cut(df.YearsSinceLastPromotion, intervals, labels=categories) ax = sns.countplot(x="Promotion", hue="Attrition", palette="Set1", data=df1) ax.set(title="Number of Years since Promotion vs Attrition", xlabel="Number of Years since Promotion", ylabel="Total") plt.xticks(rotation=-30) plt.savefig('templates/graphs/raw/YSCPvsAttr.png') ax = sns.countplot(x="MaritalStatus", hue="Attrition", palette="Set1", data=df1) ax.set(title="Marital Status vs Attrition", xlabel="Marital Status", ylabel="Total") plt.savefig('templates/graphs/raw/MSvsAttr.png') def run(data): df = pd.read_csv('original_dataset.csv') skills = df['Skills'].tolist() # print("SKKKKKKKKKKKKKKKILLLLLLLLLLLLLLLS") # print(skills) df = df.drop(['DailyRate', 'EmployeeCount', 'YearsAtCompany', 'TotalWorkingYears', 'JobLevel', 'HourlyRate', 'MonthlyRate', 'Over18', 'StandardHours', 'EnvironmentSatisfaction', 'JobInvolvement', 'PerformanceRating', 'TrainingTimesLastYear', 'RelationshipSatisfaction', 'StockOptionLevel', 'WorkLifeBalance', 'YearsWithCurrManager'], axis=1) df = df[['Attrition', 'Age', 'BusinessTravel', 'Department', 'DistanceFromHome', 'Education', 'EducationField', 'Gender', 'JobRole', 'JobSatisfaction', 'MaritalStatus', 'MonthlyIncome', 'NumCompaniesWorked', 'OverTime', 'PercentSalaryHike', 'YearsInCurrentRole', 'YearsSinceLastPromotion']] #print("These re SKILSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS") #print(skills) X = df.iloc[:, 1:].values y = df.iloc[:, 0].values labelencoder_X_1 = LabelEncoder() X[:, 1] = labelencoder_X_1.fit_transform(X[:, 1]) labelencoder_X_2 = LabelEncoder() X[:, 2] = labelencoder_X_2.fit_transform(X[:, 2]) labelencoder_X_5 = LabelEncoder() X[:, 5] = labelencoder_X_5.fit_transform(X[:, 5]) labelencoder_X_6 = LabelEncoder() X[:, 6] = labelencoder_X_6.fit_transform(X[:, 6]) labelencoder_X_7 = LabelEncoder() X[:, 7] = labelencoder_X_7.fit_transform(X[:, 7]) labelencoder_X_9 = LabelEncoder() X[:, 9] = labelencoder_X_9.fit_transform(X[:, 9]) labelencoder_X_12 = LabelEncoder() X[:, 12] = labelencoder_X_12.fit_transform(X[:, 12]) X = X.astype(float) labelencoder_y = LabelEncoder() y = labelencoder_y.fit_transform(y) X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.40,random_state=0) clf = RandomForestClassifier(n_estimators=200) clf.fit(X_train,y_train) p = clf.predict(X_test) acc = accuracy_score(y_test,p)*100 flash(acc) X = [list(elem) for elem in data] [r.pop(0) for r in X] #print("####### THIS IS XXXX##########") #print(X) att = check(X, clf) skills = skills[:(len(att)):] print("LLLLLLLLLLLLLLLENGHT" + str(len(att)) +" " + str(len(skills))) i = 0 for row in att: X[i].insert(0, row) i = i+1 df1 = pd.DataFrame(X) df1.columns=['Attrition', 'Age', 'BusinessTravel', 'Department', 'DistanceFromHome', 'Education', 'EducationField', 'Gender', 'JobRole', 'JobSatisfaction', 'MaritalStatus', 'MonthlyIncome', 'NumCompaniesWorked', 'OverTime', 'PercentSalaryHike', 'YearsInCurrentRole', 'YearsSinceLastPromotion'] analyze(df, clf) df1.to_csv('dataset1.csv') return att, skills
47.835294
405
0.684702
1
2.3406
[ -0.0390794575214386, -0.004610949195921421, 0.018880276009440422, -0.0026129113975912333, -0.019972531124949455, 0.0343361534178257, 0.00821235403418541, -0.010466434061527252, -0.032676056027412415, 0.013700301758944988, 0.007911492139101028, -0.013907487504184246, 0.026411963626742363, -0.03872233256697655, 0.005339924246072769, -0.017168832942843437, 0.2018163502216339, -0.008195272646844387, 0.023497477173805237, 0.007073730230331421, 0.004296574741601944, 0.01222548820078373, -0.021122019737958908, 0.0021231069695204496, -0.020873403176665306, 0.004474893677979708, 0.05560997501015663, 0.022616256028413773, -0.008296058513224125, 0.006915419828146696, -0.03851376473903656, -0.006286578252911568, 0.0002310449053766206, -0.02275453507900238, -0.05482274666428566, 0.027054745703935623, -0.01511308178305626, -0.09032730758190155, -0.01019708625972271, 0.0030608621891587973, 0.03871554508805275, 0.017854414880275726, -0.03555408492684364, -0.02183266170322895, 0.048294637352228165, -0.018703462556004524, -0.02191985957324505, -0.005829869769513607, -0.0368371345102787, -0.028904542326927185, 0.0061566936783492565, 0.006821723654866219, -0.01096651703119278, -0.024896664544939995, -0.03761284425854683, -0.06056981161236763, 0.026341667398810387, -0.020563889294862747, -0.03890088200569153, 0.029187491163611412, -0.036887653172016144, 0.010233059525489807, 0.007562153972685337, -0.022239750251173973, -0.005509809125214815, 0.016563113778829575, 0.016177944839000702, 0.0012956442078575492, -0.0529998317360878, -0.032733261585235596, -0.015695132315158844, 0.020065417513251305, 0.009086478501558304, 0.04243280366063118, -0.017094695940613747, 0.006179364398121834, -0.025177976116538048, 0.0026019650977104902, 0.0022550327703356743, -0.025583848357200623, -0.025834202766418457, 0.07318811863660812, -0.007144190836697817, -0.03338829055428505, -0.030067050829529762, -0.01124520506709814, 0.013809878379106522, -0.0626051276922226, 0.010830550454556942, -0.006242226343601942, 0.0007968884310685098, 0.005299482494592667, -0.05448248237371445, 0.003991958685219288, -0.04799579083919525, -0.07260807603597641, -0.0036025219596922398, 0.04329434782266617, -0.0108669837936759, 0.014270627871155739, -0.020092586055397987, 0.018585925921797752, -0.015565423294901848, 0.020660212263464928, -0.013404643163084984, -0.012106113135814667, -0.02341591753065586, -0.0001486691617174074, 0.038169968873262405, -0.01869981177151203, -0.020777087658643723, 0.012814845889806747, 0.0025219861418008804, 0.008927146904170513, -0.03549445793032646, -0.024569055065512657, 0.004777039401233196, -0.006878397427499294, -0.0071464464999735355, 0.01624547690153122, -0.003623346798121929, -0.021638398990035057, -0.00043712626211345196, -0.0063137756660580635, -0.03658965602517128, 0.0295877642929554, -0.00990524236112833, -0.04276350140571594, 0.03822220489382744, -0.010246552526950836, 0.019955020397901535, -0.05434798449277878, -0.0013771664816886187, -0.01319875754415989, 0.04967908188700676, 0.009174172766506672, 0.010074150748550892, -0.01418172474950552, -0.02658751979470253, 0.001177955768071115, 0.017151718959212303, -0.01779892109334469, 0.005218576639890671, -0.020358627662062645, 0.029644878581166267, -0.013973761349916458, 0.029105760157108307, 0.008286981843411922, -0.026304207742214203, -0.0011501116678118706, 0.0385294184088707, -0.004710758104920387, -0.03579166531562805, 0.05638430267572403, 0.0056872316636145115, -0.01758364401757717, 0.017338022589683533, -0.00047021309728734195, 0.016348639503121376, -0.008488846942782402, -0.006571731064468622, 0.007832683622837067, -0.01269436627626419, 0.024073423817753792, 0.011538099497556686, 0.06843803077936172, -0.01854732260107994, -0.024805575609207153, -0.006471383385360241, -0.0396791473031044, -0.008092278614640236, -0.0011281102197244763, -0.008738171309232712, -0.020539365708827972, 0.010925764217972755, 0.0035804426297545433, 0.0014304087962955236, 0.017828403040766716, -0.008111621253192425, 0.009228415787220001, -0.0019800597801804543, 0.001978459767997265, 0.022603239864110947, 0.026135966181755066, -0.016909247264266014, -0.02500472031533718, -0.011791996657848358, -0.04452395811676979, -0.033384017646312714, -0.030140742659568787, 0.014108243398368359, 0.02448553591966629, 0.015261021442711353, 0.0062498911283910275, -0.008403406478464603, 0.019014820456504822, -0.01831360161304474, 0.006080924067646265, 0.007054692134261131, 0.0010391396936029196, -0.0060489787720143795, -0.030776390805840492, 0.003388631157577038, 0.035492341965436935, -0.00848515797406435, 0.00819418765604496, -0.7103598117828369, -0.010128908790647984, 0.01324225403368473, -0.042038220912218094, -0.016929686069488525, 0.024939311668276787, -0.03444357216358185, -0.005681002978235483, -0.060357194393873215, -0.0016978814965113997, -0.019474484026432037, -0.004657394718378782, -0.02669624425470829, -0.012327728793025017, 0.02944953367114067, -0.04004735127091408, 0.0057158819399774075, 0.017510851845145226, 0.01792590320110321, 0.027316516265273094, 0.02183595672249794, -0.0038731086533516645, -0.013164169155061245, 0.009886480867862701, 0.06394589692354202, 0.04807274043560028, 0.007416409905999899, -0.016590045765042305, -0.012944980524480343, -0.01247325073927641, -0.012567789293825626, 0.003910162951797247, -0.015611323527991772, -0.00218326598405838, 0.02766680158674717, 0.01495644636452198, -0.0011036358773708344, -0.007906517013907433, -0.009454230777919292, 0.0019655192736536264, -0.00784695241600275, -0.012562286108732224, 0.0002328491536900401, -0.033265452831983566, -0.006916573736816645, 0.013796537183225155, -0.014703326858580112, -0.01354195550084114, -0.006180799100548029, -0.015018472447991371, -0.015040532685816288, 0.009902534075081348, 0.015291129238903522, -0.01789809577167034, -0.01226319745182991, 0.008022626861929893, -0.010865742340683937, 0.002912450348958373, -0.00001664440060267225, -0.0022582735400646925, 0.0081880958750844, 0.005111482925713062, -0.028599008917808533, 0.01651092618703842, -0.0026900696102529764, 0.016798468306660652, 0.04093508794903755, -0.006414647679775953, 0.0008013145416043699, 0.06027168408036232, -0.006276129744946957, -0.01832858845591545, 0.0022281238343566656, 0.09031642228364944, 0.00939820148050785, -0.010218827053904533, 0.007606753148138523, 0.001145675079897046, -0.032268717885017395, -0.01964901015162468, 0.00836288370192051, 0.004183941520750523, -0.011426246725022793, -0.012744178995490074, -0.012518975883722305, 0.020351100713014603, -0.028486765921115875, 0.005093346815556288, -0.013860415667295456, 0.007081540301442146, 0.039990827441215515, 0.006102153565734625, 0.018333135172724724, 0.0016187195433303714, -0.021898608654737473, 0.002757921116426587, -0.004848074167966843, 0.05525116249918938, -0.01670774444937706, 0.02687147818505764, -0.018702059984207153, 0.010605163872241974, 0.017127810046076775, 0.006312417332082987, 0.0049302708357572556, -0.017128383740782738, -0.034426506608724594, -0.01759282685816288, -0.009256530553102493, -0.02258368209004402, 0.01752186007797718, -0.02226235158741474, 0.039985403418540955, 0.03320121392607689, 0.011360900476574898, -0.007119137328118086, -0.0017481227405369282, -0.002439368050545454, 0.015815451741218567, -0.008566956967115402, -0.01811251789331436, 0.025669775903224945, 0.04531169310212135, -0.019376521930098534, -0.03566381707787514, 0.003183103632181883, -0.06665260344743729, -0.008276361040771008, 0.011553782969713211, 0.012587985023856163, 0.03128337860107422, 0.0015034136595204473, -0.009914030320942402, 0.0426504909992218, 0.018035538494586945, 0.01640542969107628, -0.02605397440493107, -0.013136147521436214, 0.008557847701013088, -0.014514340087771416, -0.0020737750455737114, -0.06357747316360474, -0.0006243007373996079, -0.0454602986574173, 0.010741419158875942, -0.012241779826581478, 0.028853466734290123, 0.016096405684947968, 0.028781592845916748, 0.025834042578935623, 0.025356965139508247, 0.013753817416727543, -0.013394338078796864, 0.0013383213663473725, -0.017730064690113068, 0.007984616793692112, -0.011778456158936024, -0.0018917209235951304, -0.003472294192761183, 0.03539186343550682, -0.0019114094320684671, -0.004504968877881765, 0.003989529330283403, 0.011276240460574627, -0.029763296246528625, 0.012030337937176228, -0.016479885205626488, 0.022078383713960648, -0.005780753679573536, 0.018868904560804367, -0.000007641299816896208, -0.006545741576701403, 0.030838755890727043, -0.03844160586595535, 0.01320380438119173, 0.03400559723377228, -0.03218211606144905, -0.025834957137703896, -0.008895602077245712, 0.018976861611008644, 0.004163661040365696, -0.018431590870022774, 0.010360917076468468, 0.0016226019943132997, -0.009794984012842178, -0.02205631323158741, -0.022067299112677574, 0.0009561969782225788, -0.006214164197444916, -0.032156769186258316, 0.0023005534894764423, 0.03497811406850815, -0.030147192999720573, -0.009498133324086666, -0.014964890666306019, -0.026291852816939354, 0.013502835296094418, -0.020271917805075645, -0.015970930457115173, -0.014194485731422901, -0.0008998744306154549, 0.04051429405808449, 0.026867907494306564, -0.027695244178175926, 0.017942702397704124, -0.024600576609373093, 0.03310651704668999, 0.004685534164309502, -0.020339857786893845, -0.022174246609210968, 0.037746090441942215, -0.021279195323586464, -0.04695742204785347, 0.010633914731442928, -0.007983366958796978, 0.014743039384484291, -0.02672152779996395, 0.05053945258259773, -0.012053939513862133, 0.001502941595390439, -0.021713323891162872, -0.03277911618351936, 0.00683937780559063, 0.008297991938889027, -0.015544630587100983, -0.03691753372550011, 0.02220664732158184, -0.010233298875391483, -0.04179902747273445, -0.006430454086512327, -0.010758979246020317, 0.013858966529369354, -0.04143958538770676, -0.0002124536404153332, 0.02842005342245102, 0.02264571748673916, -0.029634078964591026, -0.019321830943226814, -0.03261672332882881, -0.03710866719484329, 0.007515927776694298, -0.0262292493134737, 0.015591103583574295, 0.0301921796053648, 0.03505424037575722, 0.00940574798732996, -0.005811299197375774, -0.039805591106414795, -0.029294973239302635, 0.00039467427995987236, -0.039349235594272614, 0.03329524025321007, 0.020169176161289215, 0.00007140020170481876, 0.004079641308635473, 0.015622605569660664, -0.0020085752476006746, 0.033978573977947235, 0.012685497291386127, 0.031090015545487404, -0.05115264281630516, 0.013699762523174286, -0.002825662726536393, -0.011658512987196445, -0.017189037054777145, 0.013014031574130058, -0.027159664779901505, -0.012413007207214832, -0.00857328251004219, 0.019751228392124176, 0.012503680773079395, 0.02711576037108898, -0.01703428477048874, 0.038451988250017166, -0.014951369725167751, -0.015034599229693413, -0.006323864683508873, -0.03515589237213135, -0.00954950600862503, 0.013878935016691685, -0.030073409900069237, -0.06877094507217407, -0.00964861735701561, 0.02814149297773838, -0.012459470890462399, 0.06964936852455139, 0.03604989871382713, -0.021757960319519043, -0.047179125249385834, 0.00216470449231565, 0.05932854861021042, -0.017760634422302246, 0.020968947559595108, 0.014972260221838951, 0.020619260147213936, 0.06767550110816956, 0.011717356741428375, -0.029649319127202034, -0.013562650419771671, 0.032627444714307785, 0.030579552054405212, -0.001645232317969203, -0.03318711742758751, 0.05252460390329361, -0.0016028109239414334, -0.002249079756438732, -0.004703896585851908, 0.020941046997904778, 0.007510730531066656, 0.005085907410830259, 0.003273308277130127, 0.04133007675409317, -0.007327690254896879, 0.021504295989871025, -0.004711101297289133, -0.025337301194667816, 0.035557229071855545, 0.03306973725557327, 0.026273952797055244, 0.019302302971482277, 0.012532039545476437, 0.05413432419300079, -0.03285529091954231, -0.00007634974463144317, -0.03310730308294296, -0.01006332878023386, -0.01565735414624214, 0.021384434774518013, -0.006347300950437784, -0.01180834136903286, 0.01915171556174755, 0.0030764781404286623, 0.0008905741851776838, -0.005587204825133085, -0.0015519281150773168, 0.0025959366466850042, 0.01602725125849247, -0.002636468270793557, 0.030443117022514343, 0.01188110001385212, -0.010435972362756729, 0.014205588027834892, 0.019205739721655846, -0.010566041804850101, -0.004475756548345089, -0.0028374886605888605, 0.018130026757717133, 0.014627592638134956, 0.026906561106443405, 0.03236750513315201, -0.007920593023300171, 0.007881558500230312, -0.02556050568819046, -0.059813033789396286, 0.021834906190633774, -0.0225245151668787, -0.00040160486241802573, 0.019599873572587967, -0.011352327652275562, 0.0203961580991745, -0.010471691377460957, 0.015742501243948936, 0.01344007533043623, 0.0033350037410855293, 0.014587757177650928, -0.0012726177228614688, 0.0065239183604717255, 0.04151870682835579, 0.009722561575472355, 0.0323275551199913, 0.023308007046580315, -0.01242847926914692, -0.026274217292666435, 0.0016672982601448894, 0.015320402570068836, 0.010805833153426647, 0.025802824646234512, 0.023837409913539886, -0.028204256668686867, -0.005609039682894945, -0.015433778055012226, 0.017180921509861946, 0.048019301146268845, -0.0025392728857696056, 0.03939851000905037, -0.06546544283628464, -0.0058320751413702965, 0.019046403467655182, 0.019651656970381737, -0.029820812866091728, -0.0030855322256684303, -0.027356622740626335, 0.026282280683517456, 0.013590781949460506, 0.005498842801898718, -0.00803325790911913, -0.012389527633786201, 0.008497935719788074, 0.014896515756845474, 0.015021014958620071, 0.01870695687830448, -0.042018186300992966, -0.011925816535949707, -0.018855122849345207, 0.013349669054150581, -0.036315806210041046, 0.03611784800887108, -0.023166930302977562, 0.023848343640565872, 0.005901601165533066, -0.004117557778954506, -0.04795527458190918, 0.009810607880353928, -0.020995838567614555, 0.009447142481803894, 0.012310096994042397, -0.014128345996141434, -0.024597203359007835, 0.0029779733158648014, 0.020183349028229713, -0.015034310519695282, 0.006534108426421881, -0.015461568720638752, -0.00912136398255825, 0.015473579987883568, 0.017347872257232666, 0.0025260604452341795, 0.014550713822245598, -0.02900140918791294, -0.007740863133221865, -0.017382798716425896, -0.0032158519607037306, -0.016385145485401154, 0.00022083459771238267, 0.029605019837617874, -0.010015005245804787, 0.03738982230424881, 0.01779245398938656, -0.004442095756530762, -0.020522501319646835, 0.021177900955080986, 0.003895427333191037, 0.048461396247148514, 0.015737561509013176, 0.0331583097577095, 0.10388370603322983, 0.004218187648802996, 0.01437858771532774, -0.015246158465743065, 0.004540339112281799, 0.01055757887661457, 0.029028434306383133, 0.012709718197584152, 0.022284530103206635, 0.012496940791606903, 0.014379635453224182, 0.022446701303124428, 0.011738267727196217, 0.029314838349819183, -0.0018145664362236857, 0.012903665192425251, -0.012339937500655651, 0.01816888526082039, -0.020790038630366325, 0.0058234878815710545, 0.02150692045688629, -0.025077711790800095, -0.034900955855846405, -0.00544008519500494, -0.0030386140570044518, 0.03865756839513779, -0.0008407298591919243, -0.0479554682970047, 0.028285611420869827, -0.007173244841396809, 0.007550305686891079, -0.024915775284171104, -0.006062110885977745, 0.030713697895407677, -0.037439532577991486, -0.036867666989564896, 0.01054871641099453, -0.013476566411554813, 0.0159025639295578, 0.02217721752822399, -0.0022683406714349985, -0.01349148340523243, -0.02288973517715931, -0.00750846927985549, 0.017708366736769676, -0.004706638865172863, -0.028283605352044106, 0.013949423097074032, 0.046425800770521164, 0.04089561104774475, -0.046821895986795425, 0.005151007324457169, -0.008493490517139435, 0.015548118390142918, -0.032491084188222885, -0.015167002566158772, -0.01741895079612732, 0.007508105598390102, 0.004263925366103649, 0.03080880269408226, 0.020677492022514343, 0.08586986362934113, 0.05542724207043648, -0.008864657022058964, 0.03618640825152397, -0.029693933203816414, -0.005995841696858406, -0.020096810534596443, -0.0009886679472401738, 0.020392615348100662, -0.021388458088040352, 0.050121769309043884, -0.03239862620830536, -0.03001350164413452, 0.009995761327445507, -0.03383803367614746, 0.021094871684908867, -0.03140434995293617, 0.0005558665143325925, -0.014849480241537094, -0.041705984622240067, -0.002001199871301651, -0.009774244390428066, 0.040559008717536926, 0.017673147842288017, 0.00774021353572607, -0.035970523953437805, -0.007685094140470028, 0.022857343778014183, -0.002954768715426326, 0.0062148007564246655, 0.04447336867451668, 0.013894185423851013, -0.0336386077105999, -0.020919155329465866, 0.012362980283796787, -0.006723086349666119, -0.0030396785587072372, -0.008175734430551529, -0.03470730781555176, -0.009366009384393692, 0.003424607217311859, 0.006109872832894325, -0.011617048643529415, -0.001479809870943427, 0.011046118102967739, -0.012595091015100479, 0.034537676721811295, 0.012063773348927498, -0.02355181612074375, -0.012940856628119946, 0.020908381789922714, 0.003853457747027278, 0.027800798416137695, -0.026730777695775032, -0.02101440168917179, -0.01194449607282877 ]
8ab8993b826c4cf13cc7b962623c2d00cc2adcf7
6,435
py
Python
TM-GCN-master/experiment_bitcoin_baseline_link_prediction.py
OsmanMalik/TM-GCN
31b19a538f264f6c30b5503ecefb497ee865b4d7
[ "Apache-2.0" ]
14
2020-11-04T17:10:19.000Z
2022-03-04T07:48:22.000Z
TM-GCN-master/experiment_bitcoin_baseline_link_prediction.py
OsmanMalik/TM-GCN
31b19a538f264f6c30b5503ecefb497ee865b4d7
[ "Apache-2.0" ]
2
2021-09-06T09:38:12.000Z
2021-09-06T09:50:52.000Z
TensorGCN-master/experiment_bitcoin_baseline_link_prediction.py
NaimahmedNesaragi/TM-GCN
275d057a7261d8e6b544dad66b7daa7943d11c4f
[ "Apache-2.0" ]
6
2021-01-11T23:42:39.000Z
2022-01-31T08:37:13.000Z
# This version of the bitcoin experiment imports data preprocessed in Matlab, and uses the GCN baseline # The point of this script is to do link prediction # Imports and aliases import pickle import torch as t import torch.nn as nn import torch.nn.functional as F import torchvision import torchvision.datasets as datasets import numpy as np import matplotlib.pyplot as plt import cProfile import pandas as pd import datetime from scipy.sparse import csr_matrix import os.path import embedding_help_functions as ehf import scipy.io as sio unsq = t.unsqueeze sq = t.squeeze # Settings alpha_vec = [.75, .76, .77, .78, .79, .80, .81, .82, .83, .84, .85, .86, .87, .88, .89, .90, .91, .92, .93, .94, .95] no_layers = 1 dataset = "OTC" # OTC or Alpha no_epochs = 1000 mat_f_name = "saved_content_bitcoin_otc.mat" no_trials = 1 beta1 = 19 beta2 = 19 cutoff = 95 eval_type = "MAP-MRR" # "MAP-MRR" or "F1" data_loc = "data/Bitcoin_" + dataset + "/" S_train, S_val, S_test = 95, 20, 20 lr = 0.01 momentum = 0.9 # Load and return relevant data A, A_labels, C_train, C_val, C_test, N = ehf.load_data(data_loc, mat_f_name, S_train, S_val, S_test, transformed=False) # Create features for the nodes X_train, X_val, X_test = ehf.create_node_features(A, S_train, S_val, S_test, same_block_size=False) # Extract edges and labels from A_labels, and augment with nonexisting edges # edges, beta edges = A_labels._indices() edges_aug, labels = ehf.augment_edges(edges, N, beta1, beta2, cutoff) # Divide adjacency matrices and labels into training, validation and testing sets edges_train, target_train, e_train, edges_val, target_val, e_val, edges_test, target_test, e_test = ehf.split_data(edges_aug, labels, S_train, S_val, S_test, same_block_size = False) if no_trials > 1: ep_acc_loss_vec = [] for tr in range(no_trials): for alpha in alpha_vec: class_weights = t.tensor([alpha, 1.0-alpha]) save_res_fname = "results_BASELINE_layers" + str(no_layers) + "_w" + str(round(float(class_weights[0])*100)) + "_" + dataset + "_link_prediction" # Create gcn for training if no_layers == 2: gcn = ehf.EmbeddingKWGCN(C_train[:-1], X_train[:-1], e_train, [6,6,2], nonlin2="selu") elif no_layers == 1: gcn = ehf.EmbeddingKWGCN(C_train[:-1], X_train[:-1], e_train, [6,2]) # Train optimizer = t.optim.SGD(gcn.parameters(), lr=lr, momentum=momentum) criterion = nn.CrossEntropyLoss(weight=class_weights) # Takes arguments (output, target) if eval_type == "F1": ep_acc_loss = np.zeros((no_epochs,12)) # (precision_train, recall_train, f1_train, loss_train, precision_val, recall_val, f1_val, loss_val, precision_test, recall_test, f1_test, loss_test) elif eval_type == "MAP-MRR": ep_acc_loss = np.zeros((no_epochs,9)) # (MAP_train, MRR_train, loss_train, MAP_val, MRR_val, loss_val, MAP_test, MRR_test, loss_test) for ep in range(no_epochs): # Compute loss and take step optimizer.zero_grad() output_train = gcn() loss_train = criterion(output_train, target_train[edges_train[0]!=0]) loss_train.backward() optimizer.step() # Things that don't require gradient with t.no_grad(): if ep % 100 == 0: # Compute stats for training data; no point in doing more often than this guess_train = t.argmax(output_train, dim=1) if eval_type == "F1": precision_train, recall_train, f1_train = ehf.compute_f1(guess_train, target_train[edges_train[0]!=0]) elif eval_type == "MAP-MRR": MAP_train, MRR_train = ehf.compute_MAP_MRR(output_train, target_train[edges_train[0]!=0], edges_train[:, edges_train[0]!=0]) # Compute stats for validation data output_val = gcn(C_val[:-1], X_val[:-1], e_val) guess_val = t.argmax(output_val, dim=1) if eval_type == "F1": precision_val, recall_val, f1_val = ehf.compute_f1(guess_val, target_val[edges_val[0]!=0]) elif eval_type == "MAP-MRR": MAP_val, MRR_val = ehf.compute_MAP_MRR(output_val, target_val[edges_val[0]!=0], edges_val[:, edges_val[0]!=0]) loss_val = criterion(output_val, target_val[edges_val[0]!=0]) # Compute stats for test data output_test = gcn(C_test[:-1], X_test[:-1], e_test) guess_test = t.argmax(output_test, dim=1) if eval_type == "F1": precision_test, recall_test, f1_test = ehf.compute_f1(guess_test, target_test[edges_test[0]!=0]) elif eval_type == "MAP-MRR": MAP_test, MRR_test = ehf.compute_MAP_MRR(output_test, target_test[edges_test[0]!=0], edges_test[:, edges_test[0]!=0]) loss_test = criterion(output_test, target_test[edges_test[0]!=0]) # Print if eval_type == "F1": ehf.print_f1(precision_train, recall_train, f1_train, loss_train, precision_val, recall_val, f1_val, loss_val, precision_test, recall_test, f1_test, loss_test, alpha, tr, ep) elif eval_type == "MAP-MRR": print("alpha/Tr/Ep %.2f/%d/%d. Train MAP/MRR %.16f/%.16f. Train loss %.16f." % (alpha, tr, ep, MAP_train, MRR_train, loss_train)) print("alpha/Tr/Ep %.2f/%d/%d. Val MAP/MRR %.16f/%.16f. Val loss %.16f." % (alpha, tr, ep, MAP_val, MRR_val, loss_val)) print("alpha/Tr/Ep %.2f/%d/%d. Test MAP/MRR %.16f/%.16f. Test loss %.16f.\n" % (alpha, tr, ep, MAP_test, MRR_test, loss_test)) # Store values with results if eval_type == "F1": ep_acc_loss[ep] = [precision_train, recall_train, f1_train, loss_train, precision_val, recall_val, f1_val, loss_val, precision_test, recall_test, f1_test, loss_test] elif eval_type == "MAP-MRR": ep_acc_loss[ep] = [MAP_train, MRR_train, loss_train, MAP_val, MRR_val, loss_val, MAP_test, MRR_test, loss_test] if eval_type == "F1": ehf.print_f1(precision_train, recall_train, f1_train, loss_train, precision_val, recall_val, f1_val, loss_val, precision_test, recall_test, f1_test, loss_test, is_final=True) elif eval_type == "MAP-MRR": print("FINAL: Train MAP/MRR %.16f/%.16f. Train loss %.16f." % (MAP_train, MRR_train, loss_train)) print("FINAL: Val MAP/MRR %.16f/%.16f. Val loss %.16f." % (MAP_val, MRR_val, loss_val)) print("FINAL: Test MAP/MRR %.16f/%.16f. Test loss %.16f.\n" % (MAP_test, MRR_test, loss_test)) if no_trials == 1: pickle.dump(ep_acc_loss, open(save_res_fname, "wb")) print("Results saved for single trial") else: ep_acc_loss_vec.append(ep_acc_loss) if no_trials > 1: pickle.dump(ep_acc_loss_vec, open(save_res_fname + "_no_trials" + str(no_trials), "wb")) print("Results saved for all trials")
45.638298
191
0.707537
1
2.4546
[ -0.04725577309727669, -0.0025916872546076775, 0.008378646336495876, 0.03481539338827133, -0.01796109415590763, 0.012106703594326973, -0.04287099093198776, 0.00010724509047577158, 0.02443860098719597, 0.022460326552391052, 0.009783001616597176, -0.01492189709097147, 0.012463870458304882, 0.008668900467455387, -0.004811333026736975, 0.0057518878020346165, 0.0712394267320633, -0.01614133082330227, -0.013269064947962761, -0.008746078237891197, 0.006331508047878742, -0.011855347082018852, 0.004866504576057196, 0.004472161177545786, -0.017482032999396324, 0.02133592963218689, -0.0023216111585497856, 0.02524370141327381, 0.010760615579783916, 0.002754496643319726, -0.014039436355233192, 0.00837281346321106, -0.033674005419015884, 0.04531937465071678, -0.016948247328400612, 0.003436007769778371, 0.006255744025111198, -0.022478915750980377, -0.011009550653398037, -0.0032774540595710278, -0.02483140490949154, 0.004398140124976635, 0.01098362822085619, 0.032965607941150665, 0.005575206130743027, 0.035753000527620316, 0.0023060974199324846, 0.006037718616425991, -0.025642812252044678, 0.036794643849134445, -0.028303178027272224, -0.0067495498806238174, 0.014981674961745739, -0.058235425502061844, -0.01649431139230728, -0.030900513753294945, -0.011634249240159988, 0.05159898102283478, -0.001097352709621191, 0.06669730693101883, 0.007854554802179337, 0.008776997216045856, -0.04389638453722, -0.01395755261182785, 0.05357111245393753, 0.006100927945226431, 0.017648879438638687, -0.048402756452560425, -0.031163368374109268, 0.01433646585792303, 0.03106980212032795, -0.03476586937904358, -0.024807892739772797, 0.03262023255228996, -0.048716653138399124, -0.004872458986938, 0.011313416995108128, -0.004463405814021826, 0.0029125730507075787, 0.02581084705889225, -0.014760405756533146, 0.07199396193027496, 0.01648932881653309, -0.03131482005119324, 0.008922112174332142, 0.07953310012817383, 0.009288465604186058, -0.004351938609033823, 0.0007797762518748641, 0.015507602132856846, -0.04731466993689537, -0.0044748373329639435, -0.0276678167283535, -0.03937312215566635, -0.012048800475895405, -0.05344555526971817, 0.008540678769350052, 0.020744895562529564, -0.02411193586885929, 0.030854539945721626, -0.002606286434456706, -0.003231122624129057, -0.02761266566812992, -0.04890160262584686, 0.02427034266293049, -0.020215658470988274, -0.014900780282914639, 0.00427985331043601, -0.009023024700582027, -0.015863407403230667, 0.003513162489980459, 0.007179721724241972, 0.00800637248903513, -0.03905033692717552, -0.017877325415611267, -0.02404165454208851, 0.04586855322122574, -0.014522106386721134, -0.012306871823966503, 0.03643382713198662, 0.021661274135112762, 0.001123253721743822, 0.03448612615466118, -0.005911017302423716, -0.018807604908943176, 0.0315576046705246, 0.027777107432484627, 0.0012595184380188584, 0.0033014744985848665, 0.02144022099673748, -0.005134893581271172, 0.016265330836176872, -0.004045717418193817, 0.0003174218873027712, -0.009319761767983437, -0.04944998398423195, -0.001357627334073186, 0.004478858318179846, -0.02174115739762783, -0.012198127806186676, 0.01060114149004221, -0.023555545136332512, 0.012144370004534721, -0.012704351916909218, 0.02296706847846508, -0.030201958492398262, -0.02967258170247078, -0.0005320198251865804, -0.0013533806195482612, -0.00032221892615780234, 0.0010670499177649617, -0.002586556365713477, -0.010454707778990269, 0.03911775350570679, 0.009798954240977764, 0.002957225777208805, -0.0037893333937972784, -0.017102336511015892, -0.014500582590699196, 0.003719981526955962, -0.03202851861715317, 0.016740832477808, 0.018587294965982437, 0.022204095497727394, -0.012822420336306095, -0.012220318429172039, -0.0114407017827034, -0.007360748015344143, -0.003382276277989149, 0.020852504298090935, -0.014443096704781055, -0.02950533851981163, -0.000013090777429169975, 0.017113136127591133, -0.012237289920449257, -0.0020032620523124933, 0.030749129131436348, -0.009894329123198986, 0.005033897235989571, -0.045410674065351486, -0.0030312633607536554, -0.012633942998945713, 0.007115206215530634, 0.04457531124353409, 0.012884487397968769, -0.015324801206588745, -0.03587779030203819, 0.00978793203830719, 0.011364408768713474, 0.02665579877793789, -0.010754663497209549, 0.008365441113710403, 0.022551432251930237, 0.015898004174232483, -0.013085801154375076, 0.041046950966119766, 0.023017438128590584, 0.041489217430353165, -0.03283311426639557, 0.027867857366800308, -0.0017748803365975618, 0.004482348449528217, 0.02280285395681858, 0.021858787164092064, -0.02061314694583416, 0.001239241217263043, -0.7293496131896973, -0.0016111162258312106, -0.04263630509376526, -0.01792522333562374, 0.041913874447345734, 0.04723640903830528, -0.05513353273272514, 0.012654408812522888, -0.06424782425165176, 0.02149626985192299, 0.02795039303600788, -0.011778702028095722, -0.016775362193584442, 0.008152381516993046, 0.04222150892019272, -0.01931268908083439, 0.03929920122027397, 0.004816254135221243, -0.021050631999969482, 0.022366978228092194, -0.01567225530743599, -0.015848767012357712, -0.01456903014332056, 0.022062761709094048, -0.009495090693235397, 0.0075005292892456055, 0.0689588114619255, 0.009098841808736324, 0.02188565954566002, -0.008092362433671951, 0.013687888160347939, -0.016451595351099968, 0.003293531946837902, 0.007921635173261166, 0.02074345387518406, 0.0013573385076597333, -0.018456699326634407, 0.03545757755637169, -0.009547674097120762, 0.0010007743258029222, 0.002755233319476247, -0.05700942501425743, -0.004293386358767748, -0.052947867661714554, -0.0011796205071732402, 0.01187275629490614, 0.005907793529331684, -0.05214357376098633, 0.011007972992956638, 0.006315034814178944, -0.021541347727179527, -0.010502752847969532, 0.027651656419038773, -0.00989379733800888, 0.05122273787856102, -0.004853034857660532, 0.01414944976568222, -0.023997629061341286, -0.011795495636761189, -0.01844470389187336, 0.056828565895557404, -0.025308122858405113, 0.01940961182117462, -0.015683144330978394, -0.06988673657178879, 0.0006027041818015277, 0.0027804512064903975, -0.028318077325820923, -0.005298704374581575, 0.008034042082726955, -0.042193908244371414, -0.012994428165256977, -0.023496270179748535, 0.12348805367946625, 0.011634458787739277, -0.007829288952052593, 0.0013396898284554482, -0.0030338147189468145, 0.007588616106659174, 0.02662615105509758, -0.002768315142020583, -0.00911957398056984, 0.009464778006076813, 0.005126612260937691, -0.019386719912290573, -0.01187277864664793, -0.024627279490232468, 0.0021557342261075974, 0.0023402231745421886, 0.016742995008826256, -0.0168886911123991, -0.001406051218509674, 0.0035820358898490667, -0.022498827427625656, 0.01839466392993927, 0.04539714753627777, 0.010194938629865646, 0.08979471772909164, 0.027862442657351494, 0.0020995233207941055, 0.0021443567238748074, 0.002595193451270461, 0.008465856313705444, 0.0311731044203043, -0.002777203219011426, 0.014711329713463783, -0.005760622210800648, -0.021540774032473564, 0.00938613060861826, -0.05364062637090683, 0.002376491203904152, 0.02438351884484291, -0.007718673907220364, -0.016720276325941086, 0.007242190185934305, -0.031988225877285004, -0.006689208559691906, -0.029010815545916557, -0.01102517545223236, 0.01273688580840826, -0.00920387078076601, -0.029404910281300545, -0.029430033639073372, -0.02220020443201065, -0.06275384873151779, -0.004172399640083313, -0.005097550339996815, -0.013748439028859138, -0.026433190330863, 0.021070677787065506, 0.017929866909980774, -0.023275841027498245, -0.032118652015924454, 0.013725058175623417, -0.009750312194228172, -0.010116703808307648, 0.014797770418226719, -0.06093204393982887, 0.010172715410590172, -0.002303491113707423, 0.045444123446941376, 0.011284560896456242, 0.0017473846673965454, -0.023786501958966255, 0.036209940910339355, -0.02546391636133194, -0.03427816182374954, -0.02437036857008934, 0.021483097225427628, 0.00795636884868145, -0.007824793457984924, -0.010907367803156376, 0.026384729892015457, 0.027705101296305656, -0.027675610035657883, 0.03677612170577049, -0.021959885954856873, 0.03459085896611214, 0.028446756303310394, 0.019210124388337135, 0.03849884122610092, -0.008492927998304367, 0.014026965014636517, 0.01937348209321499, -0.01729397661983967, 0.0068524060770869255, -0.03412037342786789, 0.03530318662524223, 0.007418468594551086, 0.022907696664333344, -0.01652132160961628, -0.039327915757894516, -0.0023182404693216085, -0.01777278259396553, -0.024885740131139755, -0.00814957357943058, -0.05736926943063736, 0.03985816240310669, -0.003681430360302329, -0.01739279367029667, 0.03846156224608421, -0.009840724989771843, -0.022191405296325684, -0.0339045375585556, -0.0030449451878666878, 0.014594133011996746, -0.02388572134077549, 0.013210625387728214, 0.014557440765202045, -0.040495771914720535, -0.007783602923154831, 0.0064259180799126625, -0.0034569588024169207, 0.012282811105251312, 0.00215289369225502, -0.011228940449655056, -0.05507957562804222, 0.005159317050129175, -0.01651443913578987, -0.03157962113618851, 0.005631224252283573, 0.004141577985137701, 0.025203116238117218, 0.014374438673257828, 0.0010863160714507103, 0.02801680937409401, -0.0060946024022996426, 0.013719992712140083, 0.013435830362141132, 0.03606295958161354, 0.03421415016055107, -0.0058981552720069885, 0.037855375558137894, 0.03550202399492264, -0.014373856596648693, 0.03540733829140663, -0.038824375718832016, -0.0052345371805131435, 0.0006340066902339458, -0.030383670702576637, -0.02891327440738678, 0.01219085417687893, -0.030449096113443375, 0.001217989600263536, 0.002739142393693328, -0.02033260464668274, -0.05527297779917717, -0.002220333553850651, 0.005949729587882757, -0.02772350050508976, -0.008879624307155609, -0.0068159326910972595, -0.03956356644630432, 0.019076380878686905, 0.0028796109836548567, 0.02763744443655014, -0.020500116050243378, 0.002752788132056594, -0.01028119120746851, 0.015279620885848999, 0.033304519951343536, 0.015449943952262402, -0.006758004892617464, 0.020788418129086494, 0.007043210789561272, 0.025731710717082024, 0.0069198571145534515, -0.04987844452261925, -0.022434033453464508, -0.000566909380722791, -0.018483951687812805, 0.03064405731856823, 0.03970678523182869, -0.014123798348009586, 0.02266767807304859, -0.008773053996264935, 0.009408037178218365, -0.03135272115468979, 0.004768474958837032, 0.00896383635699749, 0.037549201399087906, -0.017276069149374962, 0.008976017124950886, 0.030676215887069702, 0.0368773452937603, 0.010931664146482944, -0.007086349185556173, 0.021965885534882545, -0.02125777304172516, 0.025355026125907898, 0.009514344856142998, -0.011618345975875854, -0.014311321079730988, -0.012075179256498814, 0.0187834445387125, -0.02531418763101101, -0.018577739596366882, -0.02092902734875679, 0.012342947535216808, 0.008075910620391369, -0.004399850033223629, 0.0076431953348219395, 0.028268594294786453, 0.02406769059598446, -0.0015036736149340868, 0.014981637708842754, 0.018946021795272827, 0.011485341936349869, -0.021404115483164787, -0.01571095548570156, -0.005674110725522041, -0.03669309616088867, 0.004467540420591831, 0.013843357563018799, -0.05027827247977257, 0.013998613692820072, -0.00976231973618269, 0.010055393911898136, 0.07099742442369461, 0.028076667338609695, 0.026519693434238434, 0.010040088556706905, 0.022386187687516212, 0.010356578975915909, 0.05556822568178177, -0.024647139012813568, -0.014681188389658928, -0.03177529200911522, 0.014486842788755894, 0.0014243319164961576, 0.025970691815018654, 0.018596919253468513, -0.022491153329610825, 0.0020501979161053896, 0.024334438145160675, 0.0003316328802611679, 0.040850378572940826, -0.004061289131641388, -0.003294322406873107, 0.011648410931229591, -0.0020249520894140005, 0.008816120214760303, -0.017588134855031967, -0.013712736777961254, 0.00482096616178751, -0.011022498831152916, -0.01522896159440279, 0.0025382856838405132, 0.03968549892306328, 0.016562795266509056, -0.03333239629864693, -0.01386877428740263, 0.030939416959881783, -0.0006820373237133026, 0.038737233728170395, -0.04698194935917854, 0.014854232780635357, 0.023388681933283806, -0.028019990772008896, 0.02040223218500614, 0.04749264195561409, 0.006472956854850054, -0.0026467994321137667, 0.0022360156290233135, -0.015497151762247086, 0.008709818124771118, 0.051886625587940216, 0.0319824293255806, -0.013285879977047443, 0.023998623713850975, 0.020060274749994278, -0.021122924983501434, -0.04279450699687004, 0.04756287485361099, -0.04267950728535652, -0.0016804689075797796, 0.014560802839696407, 0.04756104573607445, 0.031482402235269547, -0.034885093569755554, 0.039627958089113235, -0.021313078701496124, -0.010989231988787651, -0.01964636892080307, -0.0038331435061991215, -0.011295183561742306, -0.0005407086573541164, -0.024018753319978714, 0.00009046359627973288, 0.022496134042739868, -0.024052118882536888, -0.0033914134837687016, 0.045970167964696884, -0.024967260658740997, 0.006196573376655579, 0.013630341738462448, -0.0042859213426709175, 0.009406519122421741, 0.003248226596042514, -0.03319113701581955, -0.02555137872695923, -0.011208150535821915, 0.03266469016671181, -0.06689655035734177, 0.03389880433678627, -0.056369323283433914, -0.035011690109968185, 0.0024930392391979694, 0.026152048259973526, -0.047009680420160294, -0.009953610599040985, -0.01890665292739868, -0.009912227280437946, 0.03652184084057808, 0.005945503246039152, -0.00808807834982872, -0.019323671236634254, -0.0030448634643107653, 0.03977794572710991, -0.024272244423627853, -0.027414070442318916, -0.010919761843979359, -0.0018725731642916799, -0.014032019302248955, -0.0048159826546907425, -0.021966643631458282, 0.01354728639125824, -0.00866727251559496, 0.019757429137825966, -0.03199346363544464, 0.0005192526150494814, -0.01759652979671955, 0.01679440774023533, 0.0034395833499729633, 0.018970327451825142, -0.002599308267235756, -0.027230767533183098, -0.0045306202955543995, 0.005448777228593826, -0.02397937700152397, 0.020373497158288956, 0.03542453423142433, -0.018418513238430023, 0.013062935322523117, -0.02775506116449833, -0.0009474139078520238, 0.03189270943403244, 0.015128415077924728, 0.011892151087522507, 0.011175713501870632, -0.01824416033923626, -0.018961837515234947, -0.017894286662340164, -0.03490961715579033, 0.025846071541309357, -0.014828861691057682, -0.016950923949480057, 0.000730515515897423, -0.01427834015339613, 0.008376765064895153, -0.02718801237642765, 0.013055143877863884, 0.0013585099950432777, 0.004968570079654455, 0.02387235313653946, 0.06919058412313461, 0.0387159138917923, 0.046104978770017624, -0.0019106422550976276, 0.02487742155790329, 0.007586128078401089, -0.0035210312344133854, -0.0008038033847697079, 0.016942355781793594, -0.015394431538879871, 0.02599344588816166, -0.05069508031010628, 0.01822623610496521, 0.028105024248361588, -0.004236786160618067, -0.0072047836147248745, -0.013823172077536583, -0.02559305541217327, -0.011632069945335388, -0.009782274253666401, 0.0036413315683603287, -0.008676971308887005, -0.005572029855102301, -0.01114912424236536, -0.0063755507580935955, 0.025408396497368813, 0.006465458776801825, -0.020580798387527466, 0.029625223949551582, -0.004376543685793877, 0.03539013862609863, -0.020464181900024414, 0.0431644432246685, 0.038833435624837875, 0.03434198722243309, -0.012874839827418327, -0.017556071281433105, -0.0215984545648098, 0.001549318665638566, -0.009612317197024822, -0.012710624374449253, -0.00496128061786294, -0.020844392478466034, -0.010597305372357368, 0.013960171490907669, 0.025764083489775658, 0.0013476557796820998, -0.011015578173100948, -0.011567643843591213, 0.00000472846113552805, -0.024600427597761154, 0.010852275416254997, -0.026395028457045555, 0.009629555977880955, -0.03208836540579796, 0.008065273053944111, -0.027642754837870598, -0.00198161113075912, -0.020024023950099945, 0.05456281453371048, 0.010580758564174175, 0.027683841064572334, 0.00978876929730177, 0.03247940167784691, -0.016978885978460312, 0.01809438318014145, -0.02296043187379837, -0.023148059844970703, -0.021853188052773476, -0.026202620938420296, 0.015664057806134224, -0.00019555049948394299, 0.006605927366763353, -0.005769521463662386, 0.024150531738996506, -0.011918437667191029, 0.0012792462948709726, -0.016639403998851776, 0.011932100169360638, 0.01995561458170414, 0.011108733713626862, -0.041530534625053406, -0.02143077366054058, -0.013301855884492397, 0.02008812688291073, -0.016069188714027405, -0.027521036565303802, -0.014980965293943882, -0.022531986236572266, 0.05031299591064453, -0.029593350365757942, 0.014080733060836792, 0.012076778337359428, -0.017490491271018982, -0.019188951700925827, 0.005672278814017773, -0.0009731424506753683, -0.011242227628827095, -0.014426125213503838, -0.02972542494535446, -0.035670746117830276, -0.01316110324114561, 0.019185200333595276, 0.01732769049704075, 0.012306059710681438, 0.003502110717818141, -0.0009021178120747209, -0.02889612875878811, -0.01908937841653824, -0.06541408598423004, -0.03425184264779091, 0.008188184350728989, 0.014173328876495361, 0.04504985362291336, -0.047879908233881, 0.0005960524431429803, -0.01210097223520279 ]
8ab94a7177eff40dfe2d54daa4adb7bbd8788e95
1,084
py
Python
elm_mnist/elm_mnist.py
ahara/-blog
926ae4808ede6efb1e64381a19a210235a97ac36
[ "MIT" ]
null
null
null
elm_mnist/elm_mnist.py
ahara/-blog
926ae4808ede6efb1e64381a19a210235a97ac36
[ "MIT" ]
null
null
null
elm_mnist/elm_mnist.py
ahara/-blog
926ae4808ede6efb1e64381a19a210235a97ac36
[ "MIT" ]
null
null
null
import cPickle import numpy as np from elm import ELMClassifier from sklearn import linear_model def load_mnist(path='../Data/mnist.pkl'): with open(path, 'rb') as f: return cPickle.load(f) def get_datasets(data): _train_x, _train_y = data[0][0], np.array(data[0][1]).reshape(len(data[0][1]), 1) _val_x, _val_y = data[1][0], np.array(data[1][1]).reshape(len(data[1][1]), 1) _test_x, _test_y = data[2][0], np.array(data[2][1]).reshape(len(data[2][1]), 1) return _train_x, _train_y, _val_x, _val_y, _test_x, _test_y if __name__ == '__main__': # Load data sets train_x, train_y, val_x, val_y, test_x, test_y = get_datasets(load_mnist()) # Build ELM cls = ELMClassifier(n_hidden=7000, alpha=0.93, activation_func='multiquadric', regressor=linear_model.Ridge(), random_state=21398023) cls.fit(train_x, train_y) # Evaluate model print 'Validation error:', cls.score(val_x, val_y) print 'Test error:', cls.score(test_x, test_y)
32.848485
85
0.621771
1
1.0971
[ 0.0013112913584336638, 0.023757949471473694, 0.007852056995034218, 0.0007114353938959539, 0.0068176197819411755, -0.004529815167188644, -0.01137459371238947, 0.0038192851934581995, -0.008163131773471832, 0.001802940503694117, 0.004134253598749638, 0.0046667130663990974, 0.009097390808165073, -0.014303070493042469, -0.0005021471297368407, 0.018530771136283875, -0.05411384254693985, 0.0021532452665269375, -0.004356288816779852, 0.003537229960784316, -0.007979987189173698, 0.008781545795500278, 0.00933115091174841, 0.007931028492748737, 0.0029561049304902554, -0.0016834010602906346, 0.011464190669357777, 0.0019114037277176976, -0.0075080213136971, -0.005501490086317062, -0.0009589333785697818, -0.0021789679303765297, -0.005534196272492409, -0.006487719248980284, 0.007454714272171259, -0.003554521594196558, 0.001604533172212541, -0.020134486258029938, 0.010789007879793644, -0.009052657522261143, -0.005708261858671904, -0.016055889427661896, -0.001863911165855825, 0.004194391425698996, -0.010705837979912758, 0.004487905185669661, -0.00479707308113575, 0.0003665928088594228, -0.008984903804957867, 0.004174733068794012, -0.012357348576188087, 0.004320976324379444, 0.013901137746870518, 0.004799498710781336, -0.00645727664232254, -0.008355983532965183, 0.011621673591434956, 0.002398128854110837, -0.011700896546244621, 0.0003520388272590935, -0.005008770618587732, -0.0003619250492192805, 0.0041138785891234875, 0.003943938296288252, -0.01473296619951725, -0.007794953417032957, -0.005159383174031973, 0.002105353632941842, -0.003091896418482065, 0.006352812983095646, 0.003194020362570882, -0.0010715593816712499, 0.005573632661253214, 0.002197699388489127, 0.0029739479068666697, -0.003362611634656787, -0.0030390324536710978, 0.0014398691710084677, 0.009169312193989754, 0.003255925141274929, 0.002928595058619976, -0.008088222704827785, 0.005000361707061529, 0.013039625249803066, 0.014901192858815193, 0.010659392923116684, 0.020075516775250435, -0.010044636204838753, 0.04361025243997574, 0.006850033532828093, -0.009975338354706764, 0.002968212589621544, -0.0095431599766016, -0.002883541164919734, -0.0020203660242259502, -0.031357813626527786, -0.00047831167466938496, -0.003839455544948578, 0.00024586630752310157, 0.003327977377921343, 0.0020079920068383217, 0.006430305074900389, -0.00035785173531621695, -0.006014662329107523, -0.009748454205691814, 0.011551151983439922, -0.009596905671060085, -0.003351873718202114, 0.007568784523755312, 0.0033547698985785246, -0.013462917879223824, 0.000050383729103486985, 0.0019427305087447166, -0.013713791035115719, 0.005199579522013664, 0.005809094291180372, -0.00680839829146862, 0.05587569251656532, -0.00031213497277349234, 0.0017719761235639453, -0.007085105869919062, -0.0003342819109093398, 0.001323931966908276, 0.008053724654018879, 0.010201586410403252, -0.004982221405953169, 0.011857911944389343, 0.007444921415299177, 0.005772989708930254, 0.008921585977077484, -0.0015384559519588947, 0.009333007037639618, -0.0037530020345002413, -0.0014450191520154476, -0.00017687512445263565, -0.00588249834254384, 0.008314366452395916, -0.00235230871476233, -0.0064229839481413364, 0.004042129963636398, -0.0004519641224760562, -0.013020575977861881, 0.0006642069783993065, -0.002414930844679475, 0.0030062776058912277, -0.011026788502931595, -0.003740007057785988, -0.0028781150467693806, -0.005794033408164978, 0.004034967627376318, 0.007085774093866348, 0.005351827945560217, 0.004229978192597628, -0.004622260574251413, -0.00943081732839346, -0.0009848492918536067, -0.005049862898886204, 0.0031137450132519007, 0.008068866096436977, 0.0029310311656445265, -0.011969848535954952, -0.002358008176088333, 0.002057671546936035, 0.005163201130926609, -0.0013864218490198255, -0.0017292044358327985, -0.00819052942097187, 0.01041229534894228, 0.0015689939027652144, 0.0023918896913528442, 0.011582343839108944, -0.003770270152017474, -0.00040836373227648437, 0.0011900035897269845, 0.003113459562882781, 0.0005447518196888268, 0.005509150214493275, 0.009098391979932785, -0.0045682634226977825, -0.006870949175208807, 0.004577573388814926, 0.006237698718905449, 0.01013053860515356, 0.008549465797841549, -0.003048522165045142, 0.0031699873507022858, -0.0054842159152030945, -0.000009348600542580243, 0.009294477291405201, -0.005152401980012655, 0.006211180705577135, 0.0031906345393508673, -0.017263904213905334, -0.008290320634841919, -0.002806610194966197, -0.009944403544068336, 0.0009027569903992116, 0.016666006296873093, 0.008179139345884323, -0.001438687788322568, 0.0027179126627743244, -0.0123817790299654, -0.0010487423278391361, 0.006351723801344633, 0.0030855333898216486, -0.014825697988271713, -0.9559935927391052, 0.005547498818486929, 0.003582367906346917, -0.0006983463536016643, 0.005349916405975819, 0.0025993683375418186, 0.003194607561454177, 0.0034649912267923355, 0.011693526990711689, -0.009029649198055267, -0.007854051887989044, -0.010057307779788971, -0.009494289755821228, 0.00034978598705492914, -0.005887471605092287, -0.002663983730599284, -0.0037641567178070545, -0.006022087298333645, -0.004194984212517738, -0.004744295962154865, -0.002317344769835472, 0.011249735951423645, -0.0025895878206938505, 0.004934323485940695, 0.0022267813328653574, 0.002922207349911332, -0.004812834784388542, -0.0033155307173728943, -0.0015671370783820748, -0.0037916649598628283, -0.0047124275006353855, -0.015185999684035778, -0.0033081024885177612, -0.00023662047169636935, 0.009833227843046188, -0.0017288668313995004, 0.009932879358530045, -0.0005181086016818881, 0.0016078789485618472, -0.009996377862989902, 0.004761395510286093, 0.0012003366136923432, 0.002165816957131028, -0.029133856296539307, -0.001510348985902965, 0.0007990754093043506, -0.007428217213600874, 0.007107200566679239, 0.0027127263601869345, 0.000791157886851579, -0.0032423774246126413, -0.004588148556649685, 0.011339882388710976, -0.006307023577392101, 0.004612269811332226, -0.00598077243193984, -0.007917816750705242, -0.002015916630625725, -0.007076660171151161, 0.0005607412895187736, 0.003437572857365012, -0.006388919893652201, -0.0041963099502027035, -0.003659091889858246, 0.0012535648420453072, 0.00390442437492311, 0.0027737817727029324, -0.019033057615160942, -0.005944007076323032, -0.0025394551921635866, 0.0019647195003926754, -0.002754461020231247, -0.00445323484018445, 0.002945908112451434, -0.008842731826007366, 0.005235567223280668, 0.0037829868961125612, 0.00045450779725797474, -0.010560156777501106, 0.0017457726644352078, -0.009234479628503323, -0.007936759851872921, 0.005842198152095079, -0.005876501090824604, -0.0037509393878281116, -0.001003497396595776, 0.00505855493247509, 0.008187809027731419, -0.00649283966049552, 0.003997212275862694, 0.010465276427567005, -0.0032733192201703787, -0.011050080880522728, 0.005230239126831293, 0.008031651377677917, 0.00030290771974250674, -0.0049504805356264114, 0.0021367096342146397, 0.006885573733597994, 0.008789828047156334, -0.000017587826732778922, 0.006085509434342384, -0.000057248598750447854, 0.011247851885855198, -0.0010153371840715408, 0.001692561199888587, -0.00218934821896255, -0.0007403892814181745, -0.004384248051792383, -0.0027250342536717653, -0.005841601174324751, -0.0028974388260394335, -0.01139275636523962, -0.009400739334523678, -0.0027168006636202335, 0.000644884945359081, 0.001665022922679782, -0.004611015319824219, 0.0005577995907515287, 0.000022917656679055654, 0.011239108629524708, -0.000901917228475213, -0.005045189522206783, -0.00017153535736724734, 0.0029487190768122673, -0.006477500312030315, 0.014081577770411968, -0.011853164061903954, 0.007127193734049797, -0.001813702518120408, -0.015584195032715797, 0.005225617438554764, 0.008082990534603596, -0.007091674488037825, -0.001119938911870122, 0.00119147845543921, 0.0023549904581159353, -0.0010562646202743053, -0.006854027975350618, -0.000850739364977926, -0.020539261400699615, 0.00010092677985085174, 0.019761845469474792, 0.0012154821306467056, 0.012392023578286171, 0.012550815008580685, -0.004667361732572317, 0.002407979452982545, 0.007223447784781456, 0.0002578795829322189, 0.01535817515105009, -0.009480155073106289, -0.001092598307877779, 0.0013715827371925116, -0.0054789031855762005, 0.0014899610541760921, 0.005149724893271923, 0.004560780245810747, -0.0032036902848631144, 0.0002507264434825629, -0.005108910612761974, -0.004367785062640905, -0.01941942796111107, -0.0011638315627351403, 0.012310439720749855, -0.004898223094642162, 0.004011164885014296, -0.010534432716667652, 0.0021839882247149944, 0.005026629660278559, 0.0060690478421747684, -0.0007973347092047334, 0.0012560266768559813, 0.005990786012262106, 0.009507984854280949, -0.00761820375919342, 0.003282302524894476, 0.0036419243551790714, -0.0020805855747312307, 0.0009097015135921538, 0.0093608433380723, -0.00809449516236782, -0.004288178868591785, 0.00235409801825881, 0.0004125681589357555, 0.001494904514402151, -0.0033645369112491608, -0.007588086649775505, -0.003716591279953718, 0.0029046577401459217, -0.007297398988157511, 0.003518232610076666, 0.004194865468889475, 0.0018836306408047676, -0.008407539688050747, 0.000011564014130271971, -0.001806357759051025, -0.009593003429472446, 0.011298966594040394, -0.003372302744537592, 0.00310301361605525, 0.013191835023462772, 0.003820846090093255, -0.013165101408958435, 0.006676136516034603, 0.00927987415343523, -0.0016234265640377998, 0.004517178051173687, 0.007761404849588871, -0.004264396615326405, -0.023136455565690994, -0.002530900528654456, -0.011638886295258999, 0.005900199990719557, -0.0035159147810190916, 0.0033989944495260715, -0.008153335191309452, 0.009409300051629543, 0.005697253625839949, -0.0161860603839159, -0.0035041512455791235, -0.007992925122380257, 0.00806342251598835, -0.0016723882872611284, -0.0012954872800037265, -0.004273216240108013, -0.0043446277268230915, -0.0028425194323062897, -0.0014970620395615697, -0.0014344346709549427, 0.003880885196849704, 0.00227200984954834, -0.00432029040530324, 0.0036734265740960836, -0.0031021791510283947, 0.001697694300673902, -0.001376320724375546, -0.009085464291274548, 0.0007824435015209019, 0.005780205130577087, -0.0016127536073327065, -0.003146570408716798, 0.000007005112820479553, -0.0027299667708575726, -0.006906927563250065, -0.011457529850304127, -0.0069830771535634995, -0.0036935971584171057, -0.0036057676188647747, -0.011520152911543846, -0.002355966018512845, -0.007546949200332165, 0.008380317129194736, -0.0070096938870847225, 0.008087541908025742, 0.0048033143393695354, -0.0067422399297356606, 0.004486809950321913, -0.0036330032162368298, 0.0036196140572428703, 0.0024489087518304586, 0.005094855558127165, 0.0010693857911974192, -0.00506662717089057, -0.010761369951069355, 0.011619425378739834, -0.008850368671119213, 0.002561750588938594, 0.014034856110811234, 0.003267081454396248, 0.008341439068317413, -0.00027063683955930173, -0.001419171574525535, 0.004150252789258957, 0.007330151740461588, -0.014931981451809406, 0.004496280569583178, -0.003667768556624651, -0.0008393000462092459, 0.0051117525435984135, -0.004042856860905886, 0.002902400679886341, 0.008127033710479736, 0.004820496309548616, -0.007191521115601063, -0.0008680764003656805, 0.0007049309788271785, 0.0016456085722893476, -0.011269149370491505, 0.0007739738211967051, -0.0027511557564139366, -0.0037322950083762407, -0.002550223609432578, -0.0020655724219977856, -0.001385481096804142, 0.004081757273525, -0.000736741058062762, 0.006394568830728531, 0.001993943005800247, -0.005203993991017342, 0.013765030540525913, -0.003836266929283738, -0.004844842944294214, 0.0037606677506119013, 0.0008873827755451202, -0.004555888473987579, -0.006822662428021431, -0.003106467192992568, 0.0008910143515095115, 0.006520483177155256, -0.001426587114110589, -0.005070557352155447, -0.0024089906364679337, 0.0008407761342823505, -0.011833049356937408, -0.0001343438634648919, 0.012829968705773354, -0.004858132917433977, 0.0032362621277570724, -0.000058901187003357336, -0.006606458220630884, -0.013835808262228966, 0.05531720817089081, 0.00017226050840690732, 0.004410628229379654, 0.007150187157094479, -0.0056993672624230385, -0.0014262881595641375, -0.0024639475159347057, 0.007399427238851786, -0.006527315359562635, -0.007996215485036373, 0.009844193235039711, -0.0037820858415216208, 0.0011507890885695815, 0.004337586462497711, -0.0031992949079722166, 0.018018972128629684, -0.006068109069019556, -0.0175327155739069, -0.015195864252746105, 0.00581602705642581, -0.004138752818107605, -0.006243064068257809, 0.007372026331722736, -0.0018884834134951234, 0.0009425804601050913, -0.00021075578115414828, 0.0063112410716712475, -0.0014131268253549933, -0.0011983017902821302, -0.0018130543176084757, -0.000932712631765753, 0.002211246406659484, 0.002353197429329157, 0.0069002131931483746, 0.011320157907903194, -0.00072935112984851, 0.0038548419252038, 0.0013687285827472806, 0.0008434202172793448, -0.0009939740411937237, 0.007629778701812029, 0.004646841436624527, -0.001676044543273747, -0.0034141147043555975, 0.004649861715734005, 0.0035663647577166557, 0.0011790262069553137, 0.011396358720958233, -0.0003100497415289283, -0.00575227988883853, 0.009519770741462708, 0.009068372659385204, -0.0007177211809903383, 0.009143570438027382, 0.0011901399120688438, 0.006256996653974056, 0.0013023983919993043, -0.011585342697799206, -0.012460312806069851, -0.002407559659332037, 0.007727577816694975, 0.008768037892878056, -0.001548389787785709, 0.0028298189863562584, 0.001248445943929255, -0.004189272411167622, -0.009650046937167645, -0.007302008103579283, -0.0034551427233964205, 0.00018346622528042644, 0.0038147263694554567, 0.07262556999921799, -0.008780027739703655, -0.0035889612045139074, -0.0088198808953166, 0.0006509180529974401, -0.0005438413354568183, -0.00013562149251811206, -0.00027262934600003064, -0.0013230002950876951, 0.003987386357039213, 0.0005023382254876196, -0.007953188382089138, -0.010006533935666084, 0.0014195018447935581, 0.00341014307923615, -0.0021399138495326042, 0.004073506686836481, 0.0056265792809426785, -0.006459890399128199, 0.0013775562401860952, -0.012564506381750107, -0.0026753698475658894, -0.0026500674430280924, -0.009512310847640038, -0.003729128045961261, -0.003103179158642888, 0.0025922495406121016, 0.005465439520776272, 0.004055151250213385, -0.004789654165506363, 0.00793924368917942, -0.00305609661154449, -0.00011423097021179274, -0.0014624501345679164, 0.0000780076370574534, -0.00645218463614583, 0.0096032889559865, 0.0010370410745963454, -0.014696151949465275, -0.004452519118785858, -0.0005217428551986814, 0.0019760350696742535, -0.0074805887416005135, 0.004681328311562538, -0.003174968296661973, 0.007871017791330814, -0.003589537926018238, 0.0026225734036415815, -0.005359330214560032, 0.00024575437419116497, -0.013483291491866112, 0.008267044089734554, -0.17901922762393951, 0.012443065643310547, 0.002835980849340558, -0.002891169162467122, -0.0038565427530556917, -0.013907689601182938, -0.01029457338154316, 0.004203277640044689, 0.010054271668195724, 0.0034769491758197546, -0.0011838428908959031, -0.0014362004585564137, 0.006539241410791874, 0.0037159868516027927, -0.0026982766576111317, -0.003879060037434101, 0.0029934195335954428, -0.004625273868441582, 0.0014750765403732657, 0.005772775039076805, 0.006040853913873434, 0.008007381111383438, 0.0032816522289067507, 0.0036418328527361155, -0.0001676189567660913, -0.003883015364408493, 0.004024118185043335, -0.0015183521900326014, 0.004900024738162756, -0.008785161189734936, -0.005659826099872589, -0.005491621792316437, -0.003409200580790639, 0.0007992734899744391, 0.003959121182560921, 0.0007765379850752652, 0.00886202696710825, 0.0012846783502027392, -0.008981125429272652, 0.006605860311537981, -0.007111022248864174, 0.030772073194384575, 0.005422589834779501, 0.005202335771173239, 0.0008859648369252682, -0.0053271399810910225, -0.00365038332529366, 0.008521749638020992, 0.001758736209012568, 0.012900327332317829, -0.013883039355278015, -0.0023143554572016, 0.0033812702167779207, 0.020714985206723213, -0.004791273735463619, -0.010057548061013222, -0.008019580505788326, -0.00499693164601922, 0.002994770649820566, 0.009225183166563511, 0.010144675150513649, -0.004507964011281729, 0.009118452668190002, -0.0030602493789047003, -0.021047722548246384, 0.004939677659422159, -0.00246978341601789, -0.0077540455386042595, -0.0007122702663764358, 0.008776507340371609, 0.010354985482990742, -0.0024671414867043495, 0.004944123327732086, -0.0023626855108886957, 0.00479484349489212, -0.002063269726932049, 0.006600499153137207, -0.002100649755448103, 0.005477101542055607, -0.008520407602190971, 0.009751689620316029, -0.00944413710385561, -0.0016700099222362041, 0.0012508319923654199, -0.003517594886943698, 0.010924281552433968, 0.006622706074267626, -0.0030534809920936823, -0.0020848761778324842, -0.008028346113860607, -0.0016974896425381303, 0.001135992701165378, 0.0013192059705033898, -0.00855645164847374, 0.0009863543091341853, -0.0010960657382383943, 0.006200986448675394, 0.00854137446731329, -0.009277306497097015, 0.008012676611542702, 0.005543092731386423, -0.009337229654192924, -0.0012381253764033318, -0.004624536260962486, 0.0023026051931083202, 0.004442247562110424, -0.006174260284751654, -0.00847857166081667, 0.005522285122424364, -0.007243610452860594, -0.005737964995205402, 0.003498045029118657, -0.010367687791585922, -0.010153696872293949, -0.0007412894046865404, -0.010878815315663815, 0.0014517094241455197 ]
8abb81ca4107a0dafeae1ce248a3690886bc60c3
1,960
py
Python
Coding_Part/bob.py
qizhu8/CSCI6230-HW02
c889c0532db7ff4f25e134937469e5e6181416f0
[ "Apache-2.0" ]
null
null
null
Coding_Part/bob.py
qizhu8/CSCI6230-HW02
c889c0532db7ff4f25e134937469e5e6181416f0
[ "Apache-2.0" ]
null
null
null
Coding_Part/bob.py
qizhu8/CSCI6230-HW02
c889c0532db7ff4f25e134937469e5e6181416f0
[ "Apache-2.0" ]
null
null
null
# -*- coding: utf-8 -*- #!/usr/bin/env python3 from PKC_Classes import NetworkUser, KDC from DES import DES from RSA_Class import RSA import socket import os import sys import threading import time if sys.version_info[0] < 3: raise Exception("Must be using Python 3") def reply_conn(conn, addr): print('Accept new connection from user {0}'.format(addr)); #conn.settimeout(500) # conn.send(b'Hi, This is bob. Waiting for your sess key') buf = conn.recv(1024) while True: if buf: receive_packet = bytes.decode(buf).rstrip('\x00') reply_packet = bob.process_packet(receive_packet) conn.send(reply_packet.encode()) buf = conn.recv(1024) else: time.sleep(0.5) conn.close() bob = NetworkUser('Alice', DES(), RSA(9973, 97), 200) print('bob:', bob.uid) # socket communication kdc_host, kdc_port = 'localhost', 9999 bob_host, bob_port = 'localhost', 9200 # talk to kdc for sess key try: sock_with_kdc = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock_with_kdc.connect((kdc_host, kdc_port)) print(sock_with_kdc.recv(1024)) # send cipher_key bob_cipher_key_packet = bob.send_cipher_key() sock_with_kdc.send(bob_cipher_key_packet.encode()) kdc_bob_cipher_key_packet = sock_with_kdc.recv(1024).decode() print(kdc_bob_cipher_key_packet) bob.process_packet(kdc_bob_cipher_key_packet) except socket.error as msg: print(msg); sys.exit(1) # sock_with_kdc.shutdown(socket.SHUT_WR) # talk to bob try: sock_self = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock_self.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) sock_self.bind((bob_host, bob_port)) sock_self.listen(10) except socket.error as msg: print(msg); sys.exit(1) while 1: conn, addr = sock_self.accept() thread = threading.Thread(target=reply_conn, args=(conn, addr)) thread.start() # sock_self.close()
26.849315
69
0.694388
1
1.3941
[ 0.0013588493457064033, 0.026068899780511856, 0.006730224471539259, 0.0007322621531784534, 0.00327894976362586, -0.0011150322388857603, -0.009388158097863197, 0.0008411704329773784, -0.006075066048651934, 0.0013446557568386197, 0.00393702881410718, 0.007552518974989653, 0.007876303978264332, -0.015714045614004135, 0.00043415106483735144, 0.014094412326812744, -0.050936438143253326, 0.0008989796624518931, -0.003139575244858861, 0.001548310974612832, -0.007454575039446354, 0.00951183307915926, 0.009556608274579048, 0.0064739445224404335, 0.008084075525403023, -0.000212072889553383, 0.009897039271891117, 0.0033246148377656937, -0.008020490407943726, -0.0071845934726297855, 0.0010503637604415417, -0.0003293105692137033, -0.005137867759913206, -0.007311101071536541, 0.003968661651015282, -0.00321876909583807, -0.0008737359894439578, -0.019356582313776016, 0.015730613842606544, -0.005091712344437838, -0.0055447970516979694, -0.014303239062428474, 0.0011395385954529047, 0.00407214742153883, -0.00838701892644167, -0.00011732443090295419, -0.0064386650919914246, 0.0023345723748207092, -0.010980910621583462, 0.00540844677016139, -0.008036757819354534, 0.0058656120672822, 0.014571012929081917, 0.0038059703074395657, -0.0049319202080369, -0.007256393786519766, 0.011257413774728775, -0.0001671307545620948, -0.01049080304801464, -0.000048419788072351366, -0.0019710902124643326, -0.0028963484801352024, 0.006784356199204922, 0.003456258913502097, -0.01534362230449915, -0.0077760727144777775, -0.004640443250536919, 0.0028058101888746023, -0.0009144573123194277, 0.005899465177208185, -0.00005234589843894355, 0.00001417433850292582, 0.007977834902703762, 0.00401346618309617, 0.005890343803912401, -0.00347758992575109, -0.003037454094737768, -0.0000011217944120289758, 0.007765410002321005, 0.002648617373779416, 0.005358974449336529, -0.006040303967893124, 0.007685897871851921, 0.007724586874246597, 0.01625080406665802, 0.007253092247992754, 0.017781665548682213, -0.011691355146467686, 0.04839625209569931, 0.009537170641124249, -0.007520698476582766, 0.0025989797431975603, -0.010405045934021473, -0.002814824227243662, -0.0046774838119745255, -0.028009645640850067, 0.0005335840978659689, -0.004332888871431351, -0.000743089010939002, 0.001675977255217731, 0.0010132209863513708, 0.007736959960311651, 0.0009254374890588224, -0.0033538569696247578, -0.007822980172932148, 0.011609782464802265, -0.009002607315778732, -0.0040029860101640224, 0.003946527373045683, 0.003018228802829981, -0.01060332078486681, -0.0025815467815846205, 0.0031603523530066013, -0.013150190003216267, 0.0015470556681975722, 0.00203881342895329, -0.004378870595246553, 0.054313335567712784, 0.000028159483917988837, 0.004763319622725248, -0.005659322254359722, -0.0002739611081779003, 0.00018514427938498557, 0.004998601973056793, 0.010162106715142727, -0.0030524178873747587, 0.010366587899625301, 0.008295435458421707, 0.002991139655932784, 0.01130842138081789, -0.004406907130032778, 0.005523124244064093, -0.0030846521258354187, -0.0017655412666499615, 0.0025578984059393406, -0.008332310244441032, 0.006344087887555361, -0.0032893961761146784, -0.0072184219025075436, 0.0015246964758262038, 0.00006169964763103053, -0.009187145158648491, 0.002959553152322769, -0.004856564570218325, 0.007391694467514753, -0.010108382441103458, -0.003738469909876585, -0.002875385107472539, -0.005238180514425039, 0.0015028276247903705, 0.011631794273853302, 0.004262983798980713, 0.003107977332547307, -0.004038315732032061, -0.01025390438735485, -0.000729485647752881, -0.0024972313549369574, 0.0005159039865247905, 0.007510361261665821, 0.003144998801872134, -0.011318637058138847, -0.001501606428064406, 0.0023818472400307655, 0.0009984411299228668, -0.0002509015321265906, 0.0029695595148950815, -0.006781180389225483, 0.006000352092087269, -0.0013124048709869385, 0.00476745655760169, 0.010951918549835682, -0.0026976733934134245, -0.0018967324867844582, 0.0018144965870305896, -0.0004785848141182214, 0.0008207085775211453, 0.004492687527090311, 0.011306917294859886, -0.002366021741181612, -0.003960382658988237, 0.0030957574490457773, 0.005282572936266661, 0.006695551797747612, 0.0038380553014576435, -0.0029430510476231575, 0.0032450491562485695, -0.005677883047610521, -0.003435820806771517, 0.0065926737152040005, -0.0031054681167006493, 0.007096400484442711, 0.003302627243101597, -0.011404330842196941, -0.00901936087757349, -0.0008527499157935381, -0.007526519242674112, 0.00047327534412033856, 0.012293629348278046, 0.012300178408622742, -0.004876773338764906, 0.0032277440186589956, -0.0065279812552034855, 0.000012723404324788135, 0.008754298090934753, 0.002727892715483904, -0.011535572819411755, -0.9602242112159729, 0.007205544039607048, 0.0011869188165292144, -0.001249424647539854, 0.006508497055619955, 0.0005487839807756245, 0.0039454917423427105, 0.0029059548396617174, 0.01248261146247387, -0.008333315141499043, -0.005850328132510185, -0.012320389971137047, -0.010676312260329723, -0.0029305184725672007, -0.007878064177930355, -0.0028560964856296778, -0.0056057702749967575, -0.005122097209095955, -0.003118613502010703, -0.0013302461011335254, -0.003217115066945553, 0.009757587686181068, -0.0001156290018116124, 0.005080318544059992, 0.0013679983094334602, 0.00202028825879097, -0.00595467584207654, -0.0026041155215352774, -0.00015004753367975354, -0.0035624962765723467, -0.00520342355594039, -0.013320638798177242, -0.0018810201436281204, -0.002352250274270773, 0.009396773763000965, 0.0010329983197152615, 0.008901973254978657, -0.0017835884355008602, 0.0021713580936193466, -0.00923280417919159, 0.005561009049415588, -0.0002206790231866762, 0.003153355559334159, -0.02957071177661419, 0.0026476322673261166, -0.0005329450359568, -0.009968183934688568, 0.0061159320175647736, -0.000041906700062099844, -0.0012446847977116704, -0.0015223730588331819, -0.006528642028570175, 0.00937222596257925, -0.005974212195724249, 0.004982776008546352, -0.0016585307894274592, -0.009123102761805058, -0.002564307302236557, -0.0069300327450037, 0.003432398196309805, 0.005535731557756662, -0.005711226258426905, -0.0033725390676409006, -0.0020535560324788094, 0.002662577433511615, 0.002590549411252141, 0.0017400039359927177, -0.019199294969439507, -0.0044004665687680244, 0.0009042922174558043, 0.0019437571754679084, -0.004403713159263134, -0.005300997290760279, 0.004839582834392786, -0.007815046235918999, 0.005511439871042967, 0.0040611340664327145, -0.000733049469999969, -0.014042448252439499, 0.0011687391670420766, -0.009688219986855984, -0.006864446215331554, 0.002308492548763752, -0.0052099223248660564, -0.004953459370881319, -0.00040827319025993347, -0.00015207950491458178, 0.005394722800701857, -0.004606897011399269, 0.0013899811310693622, 0.009290533140301704, -0.0029718659352511168, -0.007468800991773605, 0.005647002253681421, 0.006669594440609217, -0.0006756125949323177, -0.0022739828564226627, 0.006547905970364809, 0.008062247186899185, 0.009588796645402908, 0.0030796455685049295, 0.004144153092056513, 0.0010192777263000607, 0.009105944074690342, -0.002478922251611948, 0.001106506446376443, -0.001974081853404641, 0.00039983598981052637, -0.0033475765958428383, 0.001329474151134491, -0.0019416469149291515, -0.0021903354208916426, -0.013020604848861694, -0.008994221687316895, -0.0033998792059719563, -0.00008897083171177655, 0.002467053011059761, -0.003670706180855632, -0.0017507761949673295, 0.0009259071084670722, 0.00839383713901043, 0.003536980366334319, -0.003086342476308346, -0.00044027104740962386, 0.004911244846880436, -0.006205399055033922, 0.013896712101995945, -0.013162870891392231, 0.007660774514079094, 0.0005101884598843753, -0.01529395766556263, 0.0047429525293409824, 0.009967586025595665, -0.010143380612134933, 0.00400316109880805, 0.004133359529078007, 0.0045841531828045845, -0.000518854008987546, -0.004511142149567604, -0.0027129570953547955, -0.016524096950888634, 0.000940948782954365, 0.018327148631215096, 0.0011065158760175109, 0.009276263415813446, 0.009962893091142178, -0.0028382514137774706, 0.0036805022973567247, 0.003904022742062807, 0.0009483086760155857, 0.011769271455705166, -0.007234799675643444, -0.0009192349389195442, 0.0025738689582794905, -0.005486716516315937, 0.0002758463961072266, 0.004774302709847689, 0.007345760241150856, -0.005605226382613182, 0.002236786298453808, -0.00690377876162529, -0.0050757150165736675, -0.014459445141255856, -0.004504168406128883, 0.006603781599551439, -0.004541425965726376, 0.005958308931440115, -0.014448733069002628, 0.007295357529073954, 0.008005122654139996, 0.0054023913107812405, -0.0018310267478227615, 0.00040031358366832137, 0.004967775195837021, 0.010936832055449486, -0.005480257794260979, -0.00010589032171992585, 0.003351805964484811, -0.0008605010225437582, -0.0021481553558260202, 0.006887422874569893, -0.004799410235136747, -0.006030847784131765, 0.0010737432166934013, 0.004294938407838345, 0.00009001692524179816, -0.0047774240374565125, -0.0069456566125154495, -0.004298940766602755, 0.0038384227082133293, -0.008356358855962753, 0.004643167369067669, -0.0008126333705149591, 0.002092102076858282, -0.008831148967146873, -0.0018558430019766092, -0.0037707018200308084, -0.013594770804047585, 0.009309672750532627, -0.0033159349113702774, 0.0027281607035547495, 0.01320209726691246, 0.005709722638130188, -0.013425437733530998, 0.003927829209715128, 0.006661436054855585, -0.003617554437369108, 0.004148117266595364, 0.005575510207563639, -0.00643109530210495, -0.02059057168662548, -0.0032160202972590923, -0.013546721078455448, 0.00506459828466177, -0.00130029721185565, 0.005567297805100679, -0.008089186623692513, 0.0062761506997048855, 0.007343206088989973, -0.012773792259395123, -0.005482356064021587, -0.008800115436315536, 0.006506804842501879, 0.000889493094291538, -0.000008687237823323812, -0.0027690117713063955, -0.0003084040363319218, -0.002390669658780098, -0.0020615500397980213, -0.0028847851790487766, 0.0048988377675414085, 0.00139885232783854, -0.0037109737750142813, 0.0007705466123297811, -0.004103105049580336, 0.002378306584432721, 0.0012484883191064, -0.009203651919960976, 0.004266535397619009, 0.0033098659478127956, -0.002191240666434169, -0.0031206822022795677, 0.0007741192821413279, -0.0031379954889416695, -0.005748278461396694, -0.010015708394348621, -0.0006030442891642451, -0.0033799137454479933, -0.001375895575620234, -0.012090298347175121, -0.0030789622105658054, -0.008375952020287514, 0.006311790551990271, -0.008178222924470901, 0.007662555202841759, 0.005675311200320721, -0.0044015622697770596, 0.006885801907628775, -0.0017773304134607315, 0.0035396916791796684, 0.0018051908118650317, 0.0013132478343322873, 0.0013143636751919985, -0.005479783751070499, -0.010235344059765339, 0.01011478342115879, -0.008074114099144936, 0.002301674336194992, 0.012153522111475468, 0.005299515090882778, 0.007419256493449211, -0.0019547701813280582, 0.0013220347464084625, 0.0012665993999689817, 0.007967440411448479, -0.011798757128417492, 0.0034090792760252953, -0.0042760237120091915, 0.0006277955253608525, 0.004564194008708, -0.00437465263530612, 0.001895399298518896, 0.009863548912107944, 0.0005656018038280308, -0.005512547213584185, -0.000056605571444379166, 0.0026769244577735662, 0.005152909550815821, -0.012035466730594635, 0.0016807586653158069, -0.003511011367663741, -0.004837630782276392, -0.0022166564594954252, -0.0009096479043364525, 0.0008081590640358627, 0.004484097473323345, -0.00022909801919013262, 0.004435335751622915, 0.0017925594002008438, -0.004335700999945402, 0.014878561720252037, -0.007095914334058762, -0.00405260780826211, 0.0019529523560777307, 0.0025556667242199183, -0.0027052368968725204, -0.006595165468752384, -0.0008723570499569178, 0.0034729160834103823, 0.006344866473227739, -0.003926481585949659, -0.004326405469328165, 0.0005436550709418952, 0.0020415058825165033, -0.011236152611672878, 0.0009024451719596982, 0.013586859218776226, -0.005507107824087143, 0.005694529041647911, -0.0028050073888152838, -0.0074554309248924255, -0.01269060280174017, 0.05121873691678047, -0.0006051836535334587, 0.003829889465123415, 0.0035015682224184275, -0.0071952324360609055, -0.0013888698304072022, -0.0025999872013926506, 0.007743870839476585, -0.006513455882668495, -0.007950466126203537, 0.008333588019013405, -0.0026723314076662064, 0.0024290827568620443, 0.003600684693083167, -0.001038404181599617, 0.01585380733013153, -0.0025683415587991476, -0.01565219834446907, -0.016880979761481285, 0.006928282789885998, -0.0047123851254582405, -0.004902217537164688, 0.010466489940881729, -0.0006907054339535534, -0.003782699117437005, 0.002196524292230606, 0.005430624354630709, -0.0005496790399774909, 0.001735815778374672, -0.004972782451659441, -0.003212375333532691, -0.0008192989625968039, 0.0006885146722197533, 0.0032714451663196087, 0.010167242959141731, -0.0036155960988253355, 0.0034154930617660284, -0.0035757324658334255, -0.003354770829901099, -0.00294800428673625, 0.0028904955834150314, 0.007438460364937782, -0.0024269039276987314, -0.0034773799125105143, 0.004095366224646568, 0.004729393403977156, 0.004556916654109955, 0.009870009496808052, -0.0008145215106196702, -0.0059530711732804775, 0.007776195649057627, 0.008054899983108044, 0.0006138267926871777, 0.010976913385093212, -0.0019763135351240635, 0.007332821376621723, 0.0014492480549961329, -0.007397801149636507, -0.017590414732694626, -0.003593162400647998, 0.006401002407073975, 0.009357359260320663, -0.00023447340936399996, -0.0002999134885612875, -0.002770188031718135, -0.00041980636888183653, -0.0063494667410850525, -0.009743445552885532, -0.0012582773342728615, 0.0014628998469561338, 0.004382006824016571, 0.06835651397705078, -0.005612500011920929, -0.000333031959598884, -0.007837748154997826, -0.0005151003133505583, -0.0036579680163413286, -0.0012511956738308072, 0.00039410157478414476, -0.0005071238847449422, 0.0018219825578853488, 0.000578083738218993, -0.00836771447211504, -0.011551214382052422, 0.0016293026274070144, 0.00008055187936406583, -0.0037006025668233633, 0.003188058268278837, 0.004954168573021889, -0.008189716376364231, 0.0016052935970947146, -0.010019148699939251, 0.0006248513818718493, -0.0013820657040923834, -0.012510969303548336, -0.005949366372078657, -0.005596174858510494, 0.005536995828151703, 0.004248803947120905, 0.006541391834616661, -0.0038774970453232527, 0.003967989701777697, -0.0024624925572425127, -0.0008164476021192968, -0.006563905160874128, 0.000616852252278477, -0.007360748015344143, 0.007283694576472044, 0.0028974192682653666, -0.009203682653605938, -0.0042600785382092, 0.00132571323774755, -0.0004627346934285015, -0.00533081591129303, 0.0030938282143324614, -0.0004444190126378089, 0.0034468912053853273, -0.0015556466532871127, 0.0008227500366047025, -0.006242903880774975, 0.0017707021906971931, -0.012832957319915295, 0.004849067889153957, -0.16872890293598175, 0.010234339162707329, 0.0035310788080096245, -0.006409385707229376, -0.004927393980324268, -0.015078861266374588, -0.005220267456024885, 0.003576502436771989, 0.010688546113669872, 0.00363449496217072, -0.002615012228488922, -0.0019574256148189306, 0.006873642094433308, 0.0037195305339992046, 0.00003236827251384966, -0.004970918875187635, 0.0034201222006231546, -0.0028941966593265533, 0.00013042123464401811, 0.002980191260576248, 0.00335402088239789, 0.012125304900109768, -0.0016030590049922466, 0.0023037262726575136, -0.0025123830419033766, -0.004796070512384176, 0.006401881109923124, -0.001707772840745747, 0.007047033403068781, -0.01184956543147564, -0.0022472315467894077, -0.0061110700480639935, -0.004861765541136265, 0.002019446110352874, 0.0060532051138579845, -0.0011292367707937956, 0.008870935998857021, 0.0038007772527635098, -0.006838476750999689, 0.007281122263520956, -0.010123616084456444, 0.02771425060927868, 0.003556713927537203, 0.008103001862764359, 0.0022327902261167765, -0.006235979031771421, -0.006015736144036055, 0.009221426211297512, 0.0008251261315308511, 0.012074013240635395, -0.0156352948397398, 0.00007777776045259088, 0.0024704751558601856, 0.019591568037867546, -0.004708855878561735, -0.00921651441603899, -0.006864157505333424, -0.003194603370502591, -0.0006027521449141204, 0.008335520513355732, 0.010636637918651104, -0.0021053242962807417, 0.00682797422632575, -0.0031755215022712946, -0.0205214973539114, 0.0025329794734716415, -0.004856017418205738, -0.0063611543737351894, 0.002019410952925682, 0.0055414168164134026, 0.010627998039126396, -0.0014988499460741878, 0.0015556907746940851, -0.00067992351250723, 0.004879579413682222, 0.00026357636670581996, 0.005355889443308115, -0.0005345102399587631, 0.004303276538848877, -0.009949545376002789, 0.006289550103247166, -0.009065558202564716, -0.002155414316803217, 0.0013288387563079596, -0.003136328887194395, 0.01166057214140892, 0.005426657386124134, -0.002207186771556735, -0.00308467959985137, -0.008383382111787796, -0.004013568628579378, 0.002670894144102931, 0.0008029532618820667, -0.011158189736306667, 0.003093128092586994, 0.001625779434107244, 0.0037166504189372063, 0.0035582156851887703, -0.008958912454545498, 0.006006332114338875, 0.007990032434463501, -0.004709816537797451, 0.003244852414354682, -0.00482608936727047, 0.003146923379972577, 0.002593351760879159, -0.005999118089675903, -0.006286740303039551, 0.002078920602798462, -0.007744473870843649, -0.005168082192540169, 0.005925911944359541, -0.007664571516215801, -0.009157557040452957, -0.003730527125298977, -0.011502321809530258, 0.0008294539875350893 ]
8abbc734ea1294bef8b90bd4c5b933a5890bb4db
10,257
py
Python
proj/scripts/cluster/baselines/triplets_greyscale.py
zqma/IIC
9d4e30b51535c6ca381389d9c22ce45be4d11883
[ "MIT" ]
null
null
null
proj/scripts/cluster/baselines/triplets_greyscale.py
zqma/IIC
9d4e30b51535c6ca381389d9c22ce45be4d11883
[ "MIT" ]
null
null
null
proj/scripts/cluster/baselines/triplets_greyscale.py
zqma/IIC
9d4e30b51535c6ca381389d9c22ce45be4d11883
[ "MIT" ]
null
null
null
from __future__ import print_function import argparse import itertools import os import pickle import sys from datetime import datetime import matplotlib import numpy as np import torch matplotlib.use('Agg') import matplotlib.pyplot as plt import proj.archs as archs from proj.utils.cluster.general import config_to_str, get_opt, update_lr from proj.utils.cluster.baselines.triplets import make_triplets_data, \ triplets_eval, triplets_loss """ Triplets. Makes output distribution same as that of attractor, and different to that of repeller. Greyscale version (no sobel). """ # Options ---------------------------------------------------------------------- parser = argparse.ArgumentParser() parser.add_argument("--model_ind", type=int, required=True) parser.add_argument("--arch", type=str, required=True) parser.add_argument("--opt", type=str, default="Adam") parser.add_argument("--dataset", type=str, required=True) parser.add_argument("--dataset_root", type=str, required=True) parser.add_argument("--gt_k", type=int, required=True) parser.add_argument("--output_k", type=int, required=True) parser.add_argument("--lr", type=float, default=0.01) parser.add_argument("--lr_schedule", type=int, nargs="+", default=[]) parser.add_argument("--lr_mult", type=float, default=0.1) parser.add_argument("--num_epochs", type=int, default=1000) parser.add_argument("--batch_sz", type=int, required=True) # num pairs parser.add_argument("--out_root", type=str, default="/scratch/shared/slow/xuji/iid_private") parser.add_argument("--restart", dest="restart", default=False, action="store_true") parser.add_argument("--test_code", dest="test_code", default=False, action="store_true") parser.add_argument("--save_freq", type=int, default=10) parser.add_argument("--kmeans_on_features", default=False, action="store_true") # transforms # used for "positive" sample parser.add_argument("--demean", dest="demean", default=False, action="store_true") parser.add_argument("--per_img_demean", dest="per_img_demean", default=False, action="store_true") parser.add_argument("--data_mean", type=float, nargs="+", default=[0.5, 0.5, 0.5]) parser.add_argument("--data_std", type=float, nargs="+", default=[0.5, 0.5, 0.5]) parser.add_argument("--crop_orig", dest="crop_orig", default=False, action="store_true") parser.add_argument("--crop_other", dest="crop_other", default=False, action="store_true") parser.add_argument("--tf1_crop", type=str, default="random") # type name parser.add_argument("--tf2_crop", type=str, default="random") parser.add_argument("--tf1_crop_sz", type=int, default=84) parser.add_argument("--tf2_crop_szs", type=int, nargs="+", default=[84]) # allow diff crop for imgs_tf parser.add_argument("--tf3_crop_diff", dest="tf3_crop_diff", default=False, action="store_true") parser.add_argument("--tf3_crop_sz", type=int, default=0) parser.add_argument("--input_sz", type=int, default=96) parser.add_argument("--rot_val", type=float, default=0.) parser.add_argument("--always_rot", dest="always_rot", default=False, action="store_true") parser.add_argument("--no_jitter", dest="no_jitter", default=False, action="store_true") parser.add_argument("--no_flip", dest="no_flip", default=False, action="store_true") config = parser.parse_args() # Fixed settings and checks ---------------------------------------------------- config.in_channels = 1 if config.output_k != config.gt_k: assert (config.output_k > config.gt_k) assert (config.kmeans_on_features) config.out_dir = os.path.join(config.out_root, str(config.model_ind)) config.dataloader_batch_sz = config.batch_sz config.num_dataloaders = 1 if not os.path.exists(config.out_dir): os.makedirs(config.out_dir) if config.restart: given_config = config reloaded_config_path = os.path.join(given_config.out_dir, "config.pickle") print("Loading restarting config from: %s" % reloaded_config_path) with open(reloaded_config_path, "rb") as config_f: config = pickle.load(config_f) assert (config.model_ind == given_config.model_ind) config.restart = True # copy over new num_epochs and lr schedule config.num_epochs = given_config.num_epochs config.lr_schedule = given_config.lr_schedule if not hasattr(config, "kmeans_on_features"): config.kmeans_on_features = False else: print("Config: %s" % config_to_str(config)) # Data, nets, optimisers ------------------------------------------------------- dataloader_original, dataloader_positive, dataloader_negative, \ dataloader_test = make_triplets_data(config) train_dataloaders = [dataloader_original, dataloader_positive, dataloader_negative] net = archs.__dict__[config.arch](config) if config.restart: model_path = os.path.join(config.out_dir, "latest_net.pytorch") taking_best = not os.path.exists(model_path) if taking_best: print("using best instead of latest") model_path = os.path.join(config.out_dir, "best_net.pytorch") net.load_state_dict( torch.load(model_path, map_location=lambda storage, loc: storage)) net.cuda() net = torch.nn.DataParallel(net) net.train() optimiser = get_opt(config.opt)(net.module.parameters(), lr=config.lr) if config.restart: opt_path = os.path.join(config.out_dir, "latest_optimiser.pytorch") if taking_best: opt_path = os.path.join(config.out_dir, "best_optimiser.pytorch") optimiser.load_state_dict(torch.load(opt_path)) # Results storage -------------------------------------------------------------- if config.restart: if not taking_best: next_epoch = config.last_epoch + 1 # corresponds to last saved model else: next_epoch = np.argmax(np.array(config.epoch_acc)) + 1 print("starting from epoch %d" % next_epoch) config.epoch_acc = config.epoch_acc[:next_epoch] # in case we overshot config.epoch_loss = config.epoch_loss[:next_epoch] config.masses = config.masses[:next_epoch, :] config.per_class_acc = config.per_class_acc[:next_epoch, :] else: config.epoch_acc = [] config.epoch_loss = [] config.masses = None config.per_class_acc = None _ = triplets_eval(config, net, dataloader_test=dataloader_test, sobel=False) print("Pre: time %s: \n %s" % (datetime.now(), config.epoch_acc[-1])) sys.stdout.flush() next_epoch = 1 fig, axarr = plt.subplots(4, sharex=False, figsize=(20, 20)) # Train ------------------------------------------------------------------------ for e_i in xrange(next_epoch, config.num_epochs): print("Starting e_i: %d" % (e_i)) if e_i in config.lr_schedule: optimiser = update_lr(optimiser, lr_mult=config.lr_mult) avg_loss = 0. # over heads and head_epochs (and sub_heads) avg_loss_count = 0 sys.stdout.flush() iterators = (d for d in train_dataloaders) b_i = 0 for tup in itertools.izip(*iterators): net.module.zero_grad() imgs_orig = tup[0][0].cuda() imgs_pos = tup[1][0].cuda() imgs_neg = tup[2][0].cuda() outs_orig = net(imgs_orig) outs_pos = net(imgs_pos) outs_neg = net(imgs_neg) curr_loss = triplets_loss(outs_orig, outs_pos, outs_neg) if ((b_i % 100) == 0) or (e_i == next_epoch and b_i < 10): print("Model ind %d epoch %d batch %d " "loss %f time %s" % \ (config.model_ind, e_i, b_i, curr_loss.item(), datetime.now())) sys.stdout.flush() if not np.isfinite(float(curr_loss.item())): print("Loss is not finite... %s:" % str(curr_loss.item())) exit(1) avg_loss += curr_loss.item() avg_loss_count += 1 curr_loss.backward() optimiser.step() b_i += 1 if b_i == 2 and config.test_code: break avg_loss = float(avg_loss / avg_loss_count) config.epoch_loss.append(avg_loss) # Eval and storage ----------------------------------------------------------- # when epoch over both heads is finished is_best = triplets_eval(config, net, dataloader_test=dataloader_test, sobel=False) print("Time %s, acc %s" % (datetime.now(), config.epoch_acc[-1])) sys.stdout.flush() axarr[0].clear() axarr[0].plot(config.epoch_acc) axarr[0].set_title("acc, top: %f" % max(config.epoch_acc)) axarr[1].clear() axarr[1].plot(config.epoch_loss) axarr[1].set_title("Loss") axarr[2].clear() for c in xrange(config.gt_k): axarr[2].plot(config.masses[:, c]) axarr[2].set_title("masses") axarr[3].clear() for c in xrange(config.gt_k): axarr[3].plot(config.per_class_acc[:, c]) axarr[3].set_title("per_class_acc") fig.tight_layout() fig.canvas.draw_idle() fig.savefig(os.path.join(config.out_dir, "plots.png")) if is_best or (e_i % config.save_freq == 0): net.module.cpu() if is_best: torch.save(net.module.state_dict(), os.path.join(config.out_dir, "best_net.pytorch")) torch.save(optimiser.state_dict(), os.path.join(config.out_dir, "best_optimiser.pytorch")) if e_i % config.save_freq == 0: torch.save(net.module.state_dict(), os.path.join(config.out_dir, "latest_net.pytorch")) torch.save(optimiser.state_dict(), os.path.join(config.out_dir, "latest_optimiser.pytorch")) config.last_epoch = e_i # for last saved version net.module.cuda() with open(os.path.join(config.out_dir, "config.pickle"), 'wb') as outfile: pickle.dump(config, outfile) with open(os.path.join(config.out_dir, "config.txt"), "w") as text_file: text_file.write("%s" % config) if config.test_code: exit(0)
33.963576
82
0.632641
0
0
[ -0.07147275656461716, 0.0554937906563282, -0.015459622256457806, -0.017967766150832176, -0.011034918017685413, 0.016491064801812172, -0.03644077852368355, 0.003531040158122778, -0.06110956892371178, 0.05452508106827736, 0.03279820829629898, -0.013463514856994152, 0.024248624220490456, -0.0384773425757885, 0.006785476580262184, -0.05407138168811798, 0.2001066654920578, 0.014977951534092426, 0.00006579513137694448, 0.015204197727143764, 0.02091119810938835, 0.006108138244599104, -0.0036882488057017326, 0.04784572497010231, 0.0510735847055912, -0.028635961934924126, 0.05286252871155739, 0.03721459209918976, -0.03550799936056137, 0.02593931183218956, -0.02683301642537117, 0.052695952355861664, 0.01632251963019371, 0.015563586726784706, 0.02684902958571911, 0.026539167389273643, -0.001880827359855175, -0.01336072850972414, 0.002866678172722459, 0.01639670878648758, -0.010071715340018272, 0.02934987097978592, -0.03678341954946518, -0.015988944098353386, -0.029026545584201813, -0.0189887136220932, 0.0022485433146357536, -0.0141921266913414, -0.011290227063000202, 0.02799059823155403, -0.02815091982483864, 0.05699774995446205, -0.022527219727635384, -0.015936516225337982, -0.028316084295511246, -0.0436270534992218, 0.022595953196287155, -0.04431422799825668, -0.03729255497455597, 0.024919606745243073, -0.018918544054031372, 0.02348005771636963, 0.039372123777866364, 0.012447511777281761, -0.045877665281295776, -0.012542957440018654, -0.00022914508008398116, -0.000050277514674235135, 0.036949336528778076, -0.020524585619568825, 0.004611088894307613, -0.01697327196598053, 0.0021374591160565615, 0.0633707121014595, 0.04056351259350777, -0.0143277021124959, -0.022819798439741135, -0.010214247740805149, -0.025831038132309914, 0.010014776140451431, -0.038718897849321365, 0.015024750493466854, -0.023919910192489624, -0.007410319987684488, -0.03202531114220619, -0.06599006056785583, 0.06805615872144699, -0.04038572311401367, 0.09306179732084274, -0.02182108908891678, -0.05275591462850571, 0.0012409118935465813, 0.0047354502603411674, 0.010143747553229332, -0.05485869571566582, -0.038551945239305496, 0.007842175662517548, 0.021665895357728004, -0.05396905913949013, 0.021428192034363747, 0.045903027057647705, -0.032431405037641525, -0.022448332980275154, 0.030778594315052032, -0.036175280809402466, 0.0002570843498688191, -0.037279993295669556, 0.01053004339337349, 0.029628414660692215, -0.023938734084367752, 0.0002743283403106034, 0.01073375903069973, 0.018141228705644608, -0.01767171174287796, 0.013798126950860023, -0.06536250561475754, 0.021362541243433952, 0.0513121671974659, -0.0016388316871598363, 0.014590861275792122, -0.019805509597063065, 0.002644190564751625, 0.0016999723156914115, -0.0030652997083961964, -0.009938702918589115, 0.10734724998474121, -0.0824013352394104, -0.049166955053806305, 0.03570298105478287, -0.017663458362221718, -0.013492044992744923, -0.023173116147518158, -0.024137988686561584, -0.030292699113488197, -0.001509726862423122, -0.03693180903792381, 0.022052263841032982, -0.01179538480937481, -0.05990680307149887, 0.005161748733371496, 0.01583186164498329, -0.01780793070793152, 0.029727887362241745, 0.005033431574702263, -0.035093069076538086, -0.02804724872112274, 0.032762542366981506, 0.026997994631528854, -0.006808429956436157, -0.006370526738464832, 0.01807660423219204, 0.019917026162147522, -0.014399646781384945, 0.008475865237414837, -0.03480231761932373, 0.017469855025410652, -0.0029367210809141397, -0.045502517372369766, -0.012462162412703037, -0.010453893803060055, -0.05613863468170166, 0.005835604853928089, 0.017211047932505608, 0.031990885734558105, 0.023828573524951935, 0.06290202587842941, -0.041255392134189606, 0.029062122106552124, -0.005457179620862007, -0.021202150732278824, -0.022538641467690468, -0.03158731013536453, -0.005958912428468466, -0.005463368725031614, 0.05817427858710289, -0.02969696745276451, 0.03903468698263168, 0.021141761913895607, -0.015493607148528099, -0.04976649582386017, 0.04648887738585472, 0.0001425484224455431, 0.007241982966661453, 0.009362775832414627, 0.012123643420636654, -0.04220949858427048, -0.015307867899537086, 0.001179525163024664, 0.006772761698812246, -0.0011493094498291612, 0.0006038188585080206, 0.05704304203391075, 0.008943142369389534, 0.009437855333089828, 0.0028257807716727257, -0.00649101659655571, 0.05286454036831856, -0.009010091423988342, 0.017263516783714294, -0.028416283428668976, -0.04571762681007385, -0.018858661875128746, -0.008354494348168373, 0.07242551445960999, -0.02312895655632019, -0.013622775673866272, -0.4705812931060791, 0.04241487756371498, 0.029368765652179718, -0.06661633402109146, 0.03818386420607567, 0.018120912835001945, -0.03144167736172676, 0.01677989587187767, -0.011007587425410748, 0.03438173606991768, -0.022243965417146683, 0.006035482510924339, -0.06731634587049484, -0.01839512586593628, -0.019880102947354317, -0.022915810346603394, -0.009263411164283752, -0.022970933467149734, -0.01903507672250271, 0.023918023332953453, -0.022906756028532982, -0.04485678672790527, -0.053404439240694046, 0.02730977162718773, 0.0028684046119451523, -0.04258935898542404, 0.046042442321777344, 0.021718859672546387, -0.021243629977107048, -0.02707589417695999, -0.01895463466644287, 0.011334729380905628, 0.020944921299815178, -0.05287701264023781, -0.006602713372558355, 0.005289691500365734, 0.07733822613954544, -0.03175664320588112, -0.027720775455236435, 0.03458372876048088, -0.07748819142580032, 0.008660710416734219, -0.014264381490647793, -0.06201552972197533, -0.08970718085765839, -0.04805028811097145, -0.0705883577466011, 0.01462261751294136, 0.0024401405826210976, 0.0024798044469207525, -0.010847521014511585, 0.015073392540216446, 0.041531968861818314, -0.0735504999756813, 0.037816502153873444, -0.002356848679482937, -0.031547222286462784, -0.0022718929685652256, -0.01915094070136547, 0.006525822449475527, -0.02027020789682865, 0.019481902942061424, -0.027714768424630165, 0.00391286751255393, 0.0026567361783236265, -0.013682045042514801, 0.026512933894991875, -0.0492209829390049, -0.014245258644223213, 0.004645291715860367, -0.037558671087026596, 0.04171878471970558, -0.06212968751788139, -0.030216313898563385, 0.04781526327133179, 0.035309404134750366, 0.0336579903960228, 0.017214670777320862, -0.038107216358184814, 0.010010872036218643, -0.03467496484518051, -0.03530750796198845, -0.015187938697636127, -0.02561788260936737, -0.039532620459795, 0.02254149317741394, 0.0019525816896930337, 0.021254412829875946, 0.018958432599902153, 0.046372491866350174, 0.060235537588596344, 0.015044818632304668, -0.005072491243481636, -0.02348606288433075, 0.04206518828868866, 0.0035772735718637705, 0.019709108397364616, 0.08155427873134613, -0.00073979701846838, -0.0006038034916855395, -0.03968330845236778, 0.01630016788840294, -0.005651172250509262, 0.010464518330991268, -0.036397941410541534, -0.020218972116708755, 0.031202811747789383, -0.01618885062634945, 0.04538119584321976, 0.002805157098919153, 0.04706032946705818, 0.005580101627856493, 0.0008531176717951894, 0.013492551632225513, -0.04610792547464371, -0.03115096315741539, -0.00611088564619422, -0.04216764494776726, 0.013392080552875996, 0.007089162245392799, 0.01730046048760414, -0.0022690733894705772, -0.02072346955537796, -0.015087517909705639, -0.018601592630147934, -0.02128087729215622, -0.055255353450775146, 0.013648422434926033, 0.013167796656489372, 0.06956285238265991, -0.022248979657888412, 0.02717064507305622, -0.019693167880177498, -0.035582274198532104, -0.006993868388235569, 0.029121074825525284, -0.009585773572325706, 0.019964588806033134, 0.03673413395881653, -0.0339512899518013, -0.035521551966667175, -0.02893492951989174, 0.038223493844270706, -0.06630265712738037, -0.036181945353746414, 0.04993818700313568, 0.052643466740846634, 0.019307341426610947, 0.0006453748792409897, -0.04924267157912254, -0.0010535187320783734, -0.017237745225429535, 0.03148578852415085, 0.06032799184322357, -0.031823206692934036, -0.002336424309760332, 0.012110989540815353, 0.034995753318071365, 0.009444981813430786, 0.013569188304245472, -0.01830974407494068, 0.07600463926792145, -0.011684568598866463, -0.043636176735162735, 0.00421661464497447, -0.020410971716046333, 0.03085983172059059, 0.05617451295256615, 0.008715436793863773, 0.03354250267148018, 0.05611637234687805, 0.030482329428195953, 0.06291693449020386, 0.01848139427602291, 0.036052897572517395, 0.024218259379267693, 0.00558611610904336, -0.06719595938920975, 0.010204554535448551, 0.013081472367048264, -0.01606113277375698, 0.012448318302631378, -0.02163378894329071, 0.021897314116358757, 0.06285612285137177, 0.0001246753236046061, -0.019289467483758926, 0.029010770842432976, -0.019045187160372734, 0.0010176073992624879, 0.047038208693265915, 0.03593805804848671, -0.01180998980998993, -0.02265193872153759, -0.039822470396757126, -0.0037204152904450893, -0.019225643947720528, -0.012257657013833523, 0.015598701313138008, -0.015619384124875069, -0.027705734595656395, 0.0523870587348938, 0.008996156975626945, -0.028222542256116867, 0.030325550585985184, 0.07509621232748032, -0.002994207199662924, -0.011118113063275814, 0.002218793611973524, 0.0005513285286724567, 0.0077219754457473755, 0.020016031339764595, 0.09271369874477386, -0.02752671204507351, -0.012741584330797195, -0.016801055520772934, -0.026512231677770615, 0.00443045049905777, 0.03415604680776596, -0.03616712987422943, -0.05527624115347862, -0.04167475178837776, 0.015842001885175705, 0.024724619463086128, -0.019413216039538383, 0.00950033962726593, -0.022251784801483154, -0.006197011563926935, -0.006745643448084593, 0.013555836863815784, 0.021173881366848946, -0.028189364820718765, 0.011573001742362976, -0.024568729102611542, -0.054219186305999756, -0.013000549748539925, -0.034464675933122635, -0.02023572102189064, 0.02810077555477619, -0.00365547020919621, 0.011945986188948154, -0.018132926896214485, 0.0012506216298788786, -0.019936680793762207, 0.030925318598747253, -0.026084700599312782, -0.004065276589244604, -0.03590567037463188, -0.010228807106614113, 0.0101906917989254, -0.03404945880174637, 0.013018039055168629, 0.009467552416026592, -0.018040213733911514, -0.0043814340606331825, 0.025147324427962303, -0.01597999781370163, -0.020809154957532883, -0.001218821736983955, -0.024303240701556206, -0.026131343096494675, -0.008329064585268497, -0.005892718210816383, -0.005667590070515871, 0.01599627546966076, 0.022884676232933998, -0.010850575752556324, -0.01775970309972763, 0.008870013989508152, -0.004975831136107445, -0.022340720519423485, 0.0001311754313064739, -0.008193490095436573, -0.0006552335689775646, 0.024553406983613968, -0.026118537411093712, 0.010049530304968357, -0.027792125940322876, 0.018948497250676155, 0.05073988437652588, 0.013109258376061916, 0.02198743261396885, 0.00620837090536952, -0.008790875785052776, 0.018988965079188347, -0.005640428513288498, -0.001655056606978178, 0.019222434610128403, -0.06553024053573608, -0.021342327818274498, 0.03223032504320145, -0.062218498438596725, -0.00897014420479536, 0.007750151678919792, -0.018212061375379562, -0.011286930181086063, -0.015577433630824089, 0.0018619457259774208, 0.022323381155729294, 0.005239277612417936, 0.046915203332901, -0.010456583462655544, -0.04284830763936043, 0.013363483361899853, 0.004412707407027483, 0.008039860986173153, 0.017954550683498383, -0.008938753977417946, 0.020864391699433327, 0.07445177435874939, 0.008560765534639359, 0.04225318878889084, 0.011217516846954823, 0.029086310416460037, 0.08105231821537018, 0.02692442573606968, 0.010586490854620934, 0.010808667168021202, 0.012412722222507, 0.014057479798793793, -0.004695036914199591, -0.0018351610051468015, -0.0365244597196579, -0.06148737668991089, -0.026445426046848297, -0.02122029848396778, -0.020561521872878075, 0.02084260620176792, -0.03633884713053703, 0.010959706269204617, -0.02363174967467785, -0.035668518394231796, 0.008142240345478058, -0.014534966088831425, 0.0367266945540905, 0.03938964754343033, 0.024554278701543808, 0.053144264966249466, 0.04491303488612175, 0.029687389731407166, -0.03847958520054817, 0.08666795492172241, -0.04903516545891762, -0.036945976316928864, 0.030833091586828232, -0.016914155334234238, -0.06805531680583954, 0.018480630591511726, 0.009268982335925102, 0.03283875808119774, 0.03674263134598732, 0.01726234145462513, -0.02366095967590809, -0.0195159874856472, -0.015307511202991009, -0.02194300666451454, 0.03436105698347092, 0.002664625644683838, -0.010684354230761528, 0.020462919026613235, 0.00007701991853537038, -0.02461753971874714, 0.00236964481882751, -0.02091510035097599, -0.027796529233455658, -0.02872137911617756, -0.00020195914839860052, -0.019648488610982895, 0.003215611446648836, -0.0030604482162743807, 0.014495890587568283, -0.02655911259353161, 0.012869076803326607, 0.019709540531039238, 0.027956213802099228, 0.0054961759597063065, 0.026233859360218048, 0.023118261247873306, -0.0032851549331098795, -0.015663888305425644, 0.01107096765190363, -0.028706785291433334, 0.06510414928197861, -0.0018669809214770794, 0.02348729409277439, -0.014962372370064259, -0.014539849013090134, 0.04825609549880028, 0.00005158896965440363, -0.03030834160745144, 0.009225437417626381, 0.010001801885664463, 0.03825749456882477, 0.036864131689071655, 0.023803094401955605, 0.027357183396816254, -0.020112110301852226, -0.03781171515583992, 0.047567401081323624, -0.06188122555613518, 0.045582305639982224, 0.01815304346382618, -0.011089167557656765, -0.01690736413002014, -0.049351032823324203, -0.015853779390454292, 0.008205907419323921, 0.014306769706308842, 0.007850183174014091, 0.05870582535862923, -0.012072396464645863, -0.0126063022762537, -0.010201914235949516, -0.03664378449320793, 0.008398625068366528, 0.06155846640467644, -0.03107311576604843, -0.007260384038090706, 0.012937038205564022, 0.04381276294589043, -0.056299276649951935, -0.05787510797381401, -0.010065970942378044, -0.0034417903516441584, -0.007884716615080833, -0.013652767986059189, -0.051903337240219116, 0.009640350937843323, 0.021068397909402847, 0.022236671298742294, -0.02036690153181553, -0.08780556917190552, -0.02820182777941227, -0.0016834200359880924, -0.0007392431725747883, -0.023546425625681877, -0.019828815013170242, -0.009476280771195889, -0.02345234714448452, -0.05473225563764572, 0.031984373927116394, -0.028231611475348473, 0.007525025866925716, 0.04226155951619148, 0.012018770910799503, -0.07240676879882812, 0.016801953315734863, -0.028522949665784836, -0.015900736674666405, 0.018791643902659416, 0.027965230867266655, 0.0012783992569893599, 0.05335063487291336, 0.0036983913742005825, 0.035076942294836044, 0.00037181511288508773, 0.03743229806423187, 0.01295245997607708, 0.01442513894289732, -0.004829093813896179, -0.047929711639881134, -0.011650449596345425, 0.010105960071086884, 0.018509382382035255, 0.024680953472852707, 0.016363603994250298, 0.015591461211442947, -0.03066835179924965, 0.020142389461398125, -0.0018811548361554742, 0.013366923667490482, 0.02280856855213642, -0.04085557162761688, -0.01114622037857771, -0.005070233251899481, -0.021603520959615707, 0.005739640910178423, -0.0030568221118301153, -0.0010860728798434138, 0.001578322029672563, -0.06390898674726486, 0.016251876950263977, 0.04187803342938423, 0.021550703793764114, 0.0028690940234810114, 0.017070868983864784, 0.0006618392653763294, -0.023941747844219208, -0.023264039307832718, 0.03370445966720581, -0.03719906508922577, -0.04062947258353233, -0.030019549652934074, 0.025473246350884438, 0.031053142622113228, -0.029496870934963226, 0.024137817323207855, -0.013551535084843636, 0.060947053134441376, -0.022888286039233208, -0.027033455669879913, -0.0019025960937142372, -0.015531369484961033, -0.022550327703356743, 0.017615556716918945, 0.030743764713406563, 0.0251226257532835, 0.10752478241920471, -0.03159696236252785, 0.0204803217202425, -0.03286765515804291, -0.011665609665215015, 0.000743502750992775, -0.03642701357603073, 0.04204772412776947, 0.007514044176787138, 0.048295192420482635, -0.0052306558936834335, -0.004281455185264349, -0.01945834420621395, 0.02117936685681343, 0.01048055849969387, -0.037287525832653046, -0.03541697934269905, -0.014809862710535526, -0.01793518476188183, -0.043458081781864166, 0.014346348121762276, 0.04038979113101959, 0.025282636284828186, -0.017329048365354538, 0.02155817486345768, -0.05124783515930176, 0.011966056190431118, -0.0018818661337718368, -0.07656709104776382, 0.02945515513420105, 0.018270177766680717, -0.025659210979938507, -0.008130944333970547, 0.03797241672873497, 0.03767542168498039, 0.006120176985859871, 0.003314847592264414, 0.01897909678518772, -0.005763168912380934, 0.036322638392448425, -0.04100232571363449, 0.029695531353354454, 0.010277371853590012, -0.023084726184606552, 0.00001659254303376656, -0.03858248144388199, 0.00724027818068862, -0.01451785210520029, -0.01705302484333515, 0.009754360653460026, 0.04504204913973808, -0.005852056667208672, -0.039174553006887436, -0.04895700514316559, 0.012895705178380013 ]
8abc0d6dcbf21ec8770db13b5b8c148d9b2c8d8e
1,607
py
Python
migrations/versions/0084_add_job_stats.py
cds-snc/notifier-api
90b385ec49efbaee7e607516fc7d9f08991af813
[ "MIT" ]
41
2019-11-28T16:58:41.000Z
2022-01-28T21:11:16.000Z
migrations/versions/0084_add_job_stats.py
cds-snc/notification-api
b1c1064f291eb860b494c3fa65ac256ad70bf47c
[ "MIT" ]
1,083
2019-07-08T12:57:24.000Z
2022-03-08T18:53:40.000Z
migrations/versions/0084_add_job_stats.py
cds-snc/notifier-api
90b385ec49efbaee7e607516fc7d9f08991af813
[ "MIT" ]
9
2020-01-24T19:56:43.000Z
2022-01-27T21:36:53.000Z
"""empty message Revision ID: 0084_add_job_stats Revises: 0083_add_perm_types_and_svc_perm Create Date: 2017-05-12 13:16:14.147368 """ # revision identifiers, used by Alembic. revision = "0084_add_job_stats" down_revision = "0083_add_perm_types_and_svc_perm" import sqlalchemy as sa from alembic import op from sqlalchemy.dialects import postgresql def upgrade(): op.create_table( "job_statistics", sa.Column("id", postgresql.UUID(as_uuid=True), nullable=False), sa.Column("job_id", postgresql.UUID(as_uuid=True), nullable=False), sa.Column("emails_sent", sa.BigInteger(), nullable=False), sa.Column("emails_delivered", sa.BigInteger(), nullable=False), sa.Column("emails_failed", sa.BigInteger(), nullable=False), sa.Column("sms_sent", sa.BigInteger(), nullable=False), sa.Column("sms_delivered", sa.BigInteger(), nullable=False), sa.Column("sms_failed", sa.BigInteger(), nullable=False), sa.Column("letters_sent", sa.BigInteger(), nullable=False), sa.Column("letters_failed", sa.BigInteger(), nullable=False), sa.Column("created_at", sa.DateTime(), nullable=True), sa.Column("updated_at", sa.DateTime(), nullable=True), sa.ForeignKeyConstraint( ["job_id"], ["jobs.id"], ), sa.PrimaryKeyConstraint("id"), ) op.create_index(op.f("ix_job_statistics_job_id"), "job_statistics", ["job_id"], unique=True) def downgrade(): op.drop_index(op.f("ix_job_statistics_job_id"), table_name="job_statistics") op.drop_table("job_statistics")
35.711111
96
0.683261
1
1.1601
[ 0.0033579606097191572, 0.02237435057759285, 0.007480658125132322, 0.0019660554826259613, 0.0019353893585503101, -0.0021626490633934736, -0.010184400714933872, 0.0030662796925753355, -0.008876647800207138, 0.004853887017816305, 0.0036888387985527515, 0.005925164092332125, 0.005521638784557581, -0.01763320527970791, 0.0021540611051023006, 0.018053870648145676, -0.048392582684755325, 0.0037023015320301056, -0.005348498467355967, 0.00035933806793764234, -0.00808155257254839, 0.0069135380908846855, 0.009382481686770916, 0.004804939962923527, 0.006835597567260265, -0.004251378122717142, 0.011397337540984154, 0.0015707657439634204, -0.007766354363411665, -0.0057056439109146595, -0.0012182281352579594, -0.0022312947548925877, -0.005146943032741547, -0.009512254036962986, 0.0053584580309689045, -0.003952663391828537, -0.0016552874585613608, -0.020695485174655914, 0.010468879714608192, -0.0028741268906742334, -0.004974915646016598, -0.013986439444124699, 0.00009223556116921827, 0.0042998394928872585, -0.009582331404089928, 0.0011059567332267761, -0.004178452771157026, 0.004062403924763203, -0.012465481646358967, 0.0050676437094807625, -0.008967822417616844, 0.00722338305786252, 0.013154760003089905, 0.0029788624960929155, -0.004919609520584345, -0.0050917319022119045, 0.014167609624564648, 0.00153309793677181, -0.009356176480650902, -0.0018942483002319932, -0.004175667650997639, -0.001613526837900281, 0.007679815869778395, 0.0006507357466034591, -0.01544694509357214, -0.00849370751529932, -0.0015015477547422051, 0.003513224655762315, 0.0009791121119633317, 0.0071988794952631, 0.0000824066810309887, 0.001987893134355545, 0.005352835636585951, 0.004895445425063372, 0.004915706347674131, -0.004223876632750034, -0.000059183377743465826, 0.0003537994925864041, 0.009535165503621101, 0.004694044124335051, 0.0026059357915073633, -0.0066543882712721825, 0.005684256087988615, 0.007866467349231243, 0.015560881234705448, 0.005308966152369976, 0.02100842073559761, -0.01230704691261053, 0.04513482749462128, 0.005885288119316101, -0.00969706755131483, 0.004032856784760952, -0.010988046415150166, -0.0008860569796524942, -0.0044105988927185535, -0.026632437482476234, 0.00015969597734510899, -0.0037624684628099203, -0.0028444547206163406, -0.00011130923667224124, -0.0004162075638305396, 0.010056165978312492, -0.0008015527855604887, -0.00007963624375406653, -0.006130258087068796, 0.0091493995860219, -0.009064284153282642, -0.001420839224010706, 0.006748852785676718, 0.003398400964215398, -0.009471273049712181, -0.0009598656324669719, 0.001333167077973485, -0.012175554409623146, 0.0027757061179727316, 0.0010888712713494897, -0.0044309827499091625, 0.05187474936246872, -0.0011834100587293506, 0.002452567918226123, -0.006301536224782467, 0.00393682299181819, 0.0034263136330991983, 0.00415484793484211, 0.00794140063226223, -0.003532660659402609, 0.012010985054075718, 0.00877092033624649, 0.004871830809861422, 0.008229561150074005, -0.004198148380964994, 0.004441034514456987, -0.0026644617319107056, -0.004205943085253239, 0.004240036942064762, -0.009784028865396976, 0.006344277877360582, -0.0018037626286968589, -0.009324491955339909, 0.0027018277905881405, -0.0023033504839986563, -0.00840427540242672, 0.001993641722947359, -0.004849796183407307, 0.00566732045263052, -0.010939599014818668, -0.0016302844742313027, -0.0020195511169731617, -0.003895126050338149, 0.003674095030874014, 0.010280795395374298, 0.001476422417908907, 0.00483827805146575, -0.004488358739763498, -0.00913592055439949, 0.00149023556150496, -0.005090903025120497, 0.0033014153596013784, 0.005359085276722908, 0.004272047430276871, -0.009849738329648972, -0.00039756912156008184, 0.0013648858293890953, 0.005180038046091795, -0.0017708229133859277, 0.006079521961510181, -0.008498502895236015, 0.00530218193307519, -0.0005148628260940313, 0.002669435925781727, 0.010715147480368614, -0.00649133138358593, -0.003162082750350237, -0.0004889763658866286, 0.0033339906949549913, 0.0003439687716308981, 0.004229461308568716, 0.010688766837120056, -0.00000397070789404097, -0.004889245610684156, 0.0011968176113441586, 0.0049023875035345554, 0.009671528823673725, 0.004769447725266218, -0.003472276497632265, 0.0037998168263584375, -0.006360149476677179, -0.0020908196456730366, 0.0066802725195884705, -0.005280524957925081, 0.004681374412029982, 0.0023471105378121138, -0.014315493404865265, -0.007816504687070847, 0.00015133636770769954, -0.008265731856226921, 0.0012345275608822703, 0.013521164655685425, 0.012020700611174107, -0.0025798312854021788, 0.0038045011460781097, -0.00731344660744071, 0.0009362014825455844, 0.007926433347165585, 0.0016473329160362482, -0.011832091957330704, -0.959798276424408, 0.00830183457583189, 0.004313684534281492, -0.0002390958834439516, 0.0045514353550970554, 0.004946798551827669, 0.003489190712571144, 0.00331506016664207, 0.015013366937637329, -0.0071079605259001255, -0.004291810095310211, -0.009880291298031807, -0.009449826553463936, -0.004267960321158171, -0.009050387889146805, -0.0038997894152998924, -0.0049552107229828835, -0.007508468348532915, -0.0008417146746069193, -0.003935081418603659, -0.0030419197864830494, 0.009811935015022755, -0.0018701486987993121, 0.006769722793251276, 0.005246594548225403, 0.002452325774356723, -0.002997410949319601, -0.0018988969968631864, -0.002175695961341262, -0.0006450554938055575, -0.007462181616574526, -0.014839746989309788, -0.003807145869359374, -0.002548836637288332, 0.008801297284662724, 0.0026230125222355127, 0.007415211759507656, -0.004240771289914846, 0.0016607852885499597, -0.008754009380936623, 0.005831661634147167, -0.0023095947690308094, 0.0038245050236582756, -0.02968789078295231, 0.001833384740166366, -0.0013630937319248915, -0.008663343265652657, 0.00673731230199337, 0.0004961773520335555, -0.000877518963534385, -0.005502376239746809, -0.004249989986419678, 0.006258614826947451, -0.008635062724351883, 0.0050208973698318005, -0.005143546499311924, -0.01055119838565588, -0.0013070511631667614, -0.007951478473842144, 0.0022478981409221888, 0.006020341534167528, 0.0003251153393648565, -0.005049311555922031, -0.0022705774754285812, 0.004849529359489679, 0.0028924625366926193, 0.004029969219118357, -0.01850522868335247, -0.006960904225707054, 0.0010775639675557613, -0.0004674817027989775, -0.006869847886264324, -0.0020159934647381306, 0.005766798742115498, -0.011188937351107597, 0.007451348938047886, 0.003734175581485033, -0.0007606666185893118, -0.009884249418973923, 0.0007634246139787138, -0.008830289356410503, -0.006631861906498671, 0.0026327786035835743, -0.005253172013908625, -0.0051934258081018925, -0.0003127110830973834, -0.0017444636905565858, 0.007820761762559414, -0.0051182955503463745, 0.003615825204178691, 0.010285790078341961, -0.0050610764883458614, -0.00854842271655798, 0.006850513629615307, 0.00635635806247592, 0.0009140486945398152, -0.0039839968085289, 0.0009054873953573406, 0.008201566524803638, 0.007119467481970787, 0.004128991160541773, 0.007044890895485878, 0.001064007868990302, 0.00789843499660492, -0.0020683067850768566, 0.00042156814015470445, -0.0035248349886387587, -0.00038730321102775633, -0.004296290222555399, -0.0014099299442023039, -0.002823609858751297, -0.004098879639059305, -0.012243654578924179, -0.008402385748922825, -0.0033086291514337063, -0.002420722274109721, 0.0021247921977192163, -0.0025655371136963367, -0.0014287530211731791, 0.004289309028536081, 0.008068057708442211, -0.0006264905678108335, -0.00007863868086133152, -0.0012090258533135056, -0.000889908813405782, -0.00260459934361279, 0.011971985921263695, -0.012810264714062214, 0.007355028297752142, -0.00046892647515051067, -0.013963929377496243, 0.005048541817814112, 0.010058696381747723, -0.010982266627252102, 0.001920192502439022, 0.003507144981995225, 0.004236503038555384, -0.0010984743712469935, -0.005799951031804085, -0.0007169761811383069, -0.015759237110614777, 0.001329233287833631, 0.020277880132198334, -0.0011300661135464907, 0.010545424185693264, 0.011895939707756042, -0.002701606135815382, 0.002898836974054575, 0.00401001051068306, 0.0007583426195196807, 0.011968078091740608, -0.009853225201368332, -0.002028185175731778, 0.005427032243460417, -0.0069401198998093605, -0.00009202190994983539, 0.008657156489789486, 0.004629063885658979, -0.0038870254065841436, 0.0009129104437306523, -0.009199796244502068, -0.005317352712154388, -0.018967939540743828, -0.0004944309475831687, 0.005257354583591223, -0.004791676066815853, 0.008660237304866314, -0.01430926937609911, 0.0062567088752985, 0.0039034606888890266, 0.003103184513747692, -0.0006124607753008604, -0.0020550978370010853, 0.007927651517093182, 0.013392050750553608, -0.006008812692016363, 0.0021619165781885386, 0.0011482766130939126, -0.0002956718089990318, -0.0007420606561936438, 0.010033433325588703, -0.007732521276921034, -0.004262375645339489, 0.002229870529845357, 0.004374104551970959, 0.0019951690919697285, -0.003592576365917921, -0.007949278689920902, -0.00312520912848413, 0.0024538736324757338, -0.004941689316183329, 0.005414274521172047, -0.0009183933725580573, 0.004817301873117685, -0.0015174518339335918, -0.003636120818555355, 0.000015966139471856877, -0.014295952394604683, 0.01132513303309679, -0.005651428829878569, 0.004467830993235111, 0.014261243864893913, 0.0049546584486961365, -0.01307867281138897, 0.005958761088550091, 0.007836617529392242, -0.0029686803463846445, 0.0036493821535259485, 0.002320710103958845, -0.006079486105591059, -0.021664824336767197, -0.004138121847063303, -0.013482367619872093, 0.004721635952591896, -0.0006792375352233648, 0.0019848919473588467, -0.007797152269631624, 0.007841575890779495, 0.007873849011957645, -0.014241525903344154, -0.006855718791484833, -0.008392665535211563, 0.006866843905299902, 0.0017196371918544173, -0.0007518366910517216, -0.0043313149362802505, -0.0014382530935108662, -0.002419730881229043, -0.003754978533834219, -0.001440545660443604, 0.00491766631603241, 0.0013761172303929925, -0.002774647669866681, 0.00008473156776744872, -0.005194635130465031, 0.0013851015828549862, 0.001697657979093492, -0.009334410540759563, 0.005213854368776083, 0.003312938380986452, -0.005295080598443747, -0.0018123692134395242, 0.002308378927409649, -0.0004781894385814667, -0.010657945647835732, -0.011971309781074524, -0.004832135513424873, -0.006467788014560938, -0.0021012178622186184, -0.011289644986391068, -0.0039664339274168015, -0.008258752524852753, 0.001268736901693046, -0.006464631296694279, 0.0068297190591692924, 0.003327871672809124, -0.004709896631538868, 0.006593235768377781, -0.002809051424264908, 0.0036723152734339237, 0.005027825012803078, 0.005473594646900892, -0.000658661883790046, -0.005692353472113609, -0.00663934089243412, 0.008951757103204727, -0.01064893789589405, 0.0006331430631689727, 0.012329845689237118, 0.005132654216140509, 0.007953008636832237, -0.0013811951503157616, -0.0013277167454361916, 0.0027116313576698303, 0.007628145627677441, -0.011872777715325356, 0.0011022922117263079, -0.0027665793895721436, 0.0002025365538429469, 0.006540399976074696, -0.004775987006723881, 0.0005377935012802482, 0.007450547069311142, 0.0006912531098350883, -0.006774549838155508, -0.003822455881163478, 0.003403987269848585, 0.005494800396263599, -0.010731137357652187, -0.0005228086956776679, -0.0018130280077457428, -0.003465550485998392, -0.0014450096059590578, -0.005145123228430748, -0.0006287263822741807, 0.0034689209423959255, -0.003471051575616002, 0.004292796831578016, 0.0013504493981599808, -0.0034385889302939177, 0.014355712570250034, -0.007554713170975447, -0.0038603406865149736, 0.0007633083150722086, -0.000030319079087348655, -0.00369608448818326, -0.00807205494493246, -0.005305001512169838, 0.0024028837215155363, 0.0058636777102947235, -0.0022063220385462046, -0.0032778303138911724, 0.0010284461313858628, 0.003953905776143074, -0.009256265126168728, 0.00366514315828681, 0.009836366400122643, -0.0017675603739917278, 0.007770963478833437, -0.0005064077558927238, -0.006731604691594839, -0.01283836830407381, 0.052143700420856476, -0.003058937843888998, 0.003218383062630892, 0.003332105465233326, -0.005937979090958834, -0.0009167537791654468, -0.0018987905932590365, 0.00991259329020977, -0.00720132514834404, -0.0038082089740782976, 0.00774250365793705, -0.0023706199135631323, 0.006277814041823149, 0.0019233294297009706, -0.0004425352963153273, 0.014139252714812756, -0.0037355769891291857, -0.017161818221211433, -0.015294836834073067, 0.008784827776253223, -0.001622636686079204, -0.004570400808006525, 0.010799973271787167, -0.002654870506376028, -0.00409163860604167, 0.0003765337751246989, 0.0070342267863452435, 0.00284381490200758, -0.0033152319956570864, -0.0027183322235941887, -0.001080171437934041, -0.0031835688278079033, 0.003547319211065769, 0.004149712156504393, 0.008225261233747005, -0.0006943729240447283, 0.004172889515757561, -0.004725064616650343, -0.0006357748643495142, -0.0010503217345103621, 0.004272926598787308, 0.005487450398504734, 0.002389122499153018, 0.0012861130526289344, 0.006497092079371214, 0.0045087612234056, 0.0027189399115741253, 0.011087237857282162, -0.0005012164474464953, -0.004228349309414625, 0.009501776657998562, 0.0048001292161643505, -0.0003134031139779836, 0.0057660723105072975, -0.0025392735842615366, 0.005365084856748581, 0.0017672866815701127, -0.007572254631668329, -0.01655169017612934, -0.0014817715855315328, 0.008518747054040432, 0.003513635601848364, -0.0025341096334159374, 0.0016444771317765117, -0.0032647137995809317, -0.0026228937786072493, -0.005486935842782259, -0.008192304521799088, -0.0061861565336585045, 0.0030960787553340197, 0.006398914381861687, 0.06583935767412186, -0.006564443930983543, -0.0001161432228400372, -0.007626020815223455, -0.0031605353578925133, -0.003634392749518156, -0.0009988070232793689, 0.0006523092743009329, -0.0024824594147503376, 0.0028321845456957817, -0.000574322126340121, -0.008692781440913677, -0.011940540745854378, 0.001111273537389934, 0.0015884478343650699, -0.002028997289016843, 0.005483666900545359, 0.004445766098797321, -0.01265906635671854, 0.0008165184408426285, -0.011819691397249699, -0.003936494700610638, -0.001822725054807961, -0.009130570106208324, -0.004480869043618441, -0.0038914114702492952, 0.003470109310001135, 0.0027868624310940504, 0.0063732401467859745, -0.0026867964770644903, 0.005057318136096001, -0.002639963524416089, -0.0007193436031229794, -0.005491670686751604, -0.0018176794983446598, -0.005100041627883911, 0.007777106948196888, -0.000279064173810184, -0.007553846575319767, -0.004423116333782673, -0.0009948506485670805, -0.0005638484726659954, -0.005976633634418249, 0.001362100476399064, 0.0018503237515687943, 0.006286000832915306, -0.002233636099845171, 0.001309197978116572, -0.0031458567827939987, 0.0013308096677064896, -0.01243841927498579, 0.0033440447878092527, -0.17307500541210175, 0.007450212724506855, 0.005017049610614777, -0.00730857253074646, -0.003078133100643754, -0.014226448722183704, -0.003843626007437706, 0.00514629203826189, 0.010469001717865467, 0.003862769575789571, -0.0048042102716863155, -0.001743169268593192, 0.004420757759362459, 0.003923533950001001, -0.0005773823941126466, -0.0059625692665576935, 0.004144193138927221, -0.004418115597218275, -0.0013942806981503963, 0.003318319795653224, 0.0014697789447382092, 0.01078440248966217, -0.00232393154874444, 0.0016467528184875846, -0.0003289624582976103, -0.003668540623039007, 0.009519394487142563, -0.0026051208842545748, 0.005730139557272196, -0.013460900634527206, -0.002934753429144621, -0.004437907133251429, -0.0047065336257219315, 0.0032198771368712187, 0.004305931273847818, 0.00256417621858418, 0.006852856371551752, 0.0014241347089409828, -0.00677948072552681, 0.010527295991778374, -0.007197900675237179, 0.027627689763903618, 0.006403867155313492, 0.006692890077829361, -0.00009818212856771424, -0.006259942427277565, -0.00720871239900589, 0.007713876198977232, 0.004575496539473534, 0.013147717341780663, -0.013281461782753468, -0.0008992071379907429, 0.005524509120732546, 0.016515610739588737, -0.0038871841970831156, -0.010326243005692959, -0.006332281045615673, -0.0018802277045324445, 0.0017351395217701793, 0.005057274363934994, 0.011263839900493622, -0.004061177838593721, 0.008425588719546795, -0.002973956521600485, -0.02184205874800682, 0.0036325196269899607, -0.005060614086687565, -0.0039314934983849525, 0.004350609611719847, 0.00855266209691763, 0.010488409548997879, -0.00034375465475022793, 0.003969805780798197, -0.001170575269497931, 0.007009518798440695, 0.0006772363558411598, 0.00863881129771471, 0.0013256862293928862, 0.005340890493243933, -0.008652152493596077, 0.004848614800721407, -0.007344500627368689, -0.004162393510341644, 0.0008810609579086304, -0.003468020586296916, 0.010271529667079449, 0.0038903532549738884, -0.00278231012634933, -0.0006561086629517376, -0.01001391839236021, -0.0021568734664469957, 0.002939038211479783, -0.00027143891202285886, -0.006997229065746069, 0.0017643425380811095, 0.0020256571006029844, 0.004889927338808775, 0.0062753851525485516, -0.007610541768372059, 0.007162273861467838, 0.006293103098869324, -0.003034156747162342, 0.0004647608438972384, -0.004000390879809856, 0.004409609362483025, 0.004131114576011896, -0.0051259263418614864, -0.005903780460357666, 0.00026852265000343323, -0.008219040930271149, -0.005085223354399204, 0.01056393887847662, -0.008955268189311028, -0.008597839623689651, -0.0013246050802990794, -0.009975861757993698, -0.00034386091283522546 ]
8abc2535fb59574434dff13ed4c596ed4d606f9e
4,279
py
Python
addons/twofactor/tests/test_models.py
tsukaeru/RDM-osf.io
2dc3e539322b6110e51772f8bd25ebdeb8e12d0e
[ "Apache-2.0" ]
11
2018-12-11T16:39:40.000Z
2022-02-26T09:51:32.000Z
addons/twofactor/tests/test_models.py
tsukaeru/RDM-osf.io
2dc3e539322b6110e51772f8bd25ebdeb8e12d0e
[ "Apache-2.0" ]
52
2018-04-13T05:03:21.000Z
2022-03-22T02:56:19.000Z
addons/twofactor/tests/test_models.py
tsukaeru/RDM-osf.io
2dc3e539322b6110e51772f8bd25ebdeb8e12d0e
[ "Apache-2.0" ]
16
2018-07-09T01:44:51.000Z
2021-06-30T01:57:16.000Z
import unittest from future.moves.urllib.parse import urlparse, urljoin, parse_qs import pytest from addons.twofactor.tests.utils import _valid_code from nose.tools import (assert_equal, assert_false, assert_is_none, assert_is_not_none, assert_true) from osf_tests.factories import UserFactory pytestmark = pytest.mark.django_db class TestCallbacks(unittest.TestCase): def setUp(self): super(TestCallbacks, self).setUp() self.user = UserFactory() self.user.add_addon('twofactor') self.user_settings = self.user.get_addon('twofactor') def test_add_to_user(self): assert_equal(self.user_settings.totp_drift, 0) assert_is_not_none(self.user_settings.totp_secret) assert_false(self.user_settings.is_confirmed) def test_remove_from_unconfirmed_user(self): # drift defaults to 0. Change it so we can test it was changed back. self.user_settings.totp_drift = 1 self.user_settings.save() self.user.delete_addon('twofactor') self.user_settings.reload() assert_equal(self.user_settings.totp_drift, 0) assert_is_none(self.user_settings.totp_secret) assert_false(self.user_settings.is_confirmed) def test_remove_from_confirmed_user(self): # drift defaults to 0. Change it so we can test it was changed back. self.user_settings.totp_drift = 1 self.user_settings.is_confirmed = True self.user_settings.save() self.user.delete_addon('twofactor') self.user_settings.reload() assert_equal(self.user_settings.totp_drift, 0) assert_is_none(self.user_settings.totp_secret) assert_false(self.user_settings.is_confirmed) class TestUserSettingsModel(unittest.TestCase): TOTP_SECRET = 'b8f85986068f8079aa9d' TOTP_SECRET_B32 = 'XD4FTBQGR6AHTKU5' def setUp(self): super(TestUserSettingsModel, self).setUp() self.user = UserFactory() self.user.add_addon('twofactor') self.user_settings = self.user.get_addon('twofactor') self.user_settings.totp_secret = self.TOTP_SECRET self.user_settings.save() def tearDown(self): super(TestUserSettingsModel, self).tearDown() self.user.__class__.delete(self.user) def test_b32(self): assert_equal(self.user_settings.totp_secret_b32, self.TOTP_SECRET_B32) def test_otpauth_url(self): url = urlparse(self.user_settings.otpauth_url) assert_equal(url.scheme, 'otpauth') assert_equal(url.netloc, 'totp') assert_equal(url.path, '/RDM:{}'.format(self.user.username)) assert_equal( parse_qs(url.query), {'secret': [self.TOTP_SECRET_B32]} ) def test_json(self): # url = 'otpauth://totp/RDM:{}?secret=' + self.TOTP_SECRET_B32 settings = self.user_settings.to_json(user=None) assert_equal( settings, { 'is_enabled': True, 'addon_full_name': 'Two-factor Authentication', 'addon_short_name': 'twofactor', 'drift': 0, 'is_confirmed': False, 'nodes': [], 'secret': self.TOTP_SECRET_B32, 'has_auth': False, } ) def test_verify_valid_code(self): assert_true( self.user_settings.verify_code(_valid_code(self.TOTP_SECRET)) ) def test_verify_valid_core_drift(self): # use a code from 30 seconds in the future assert_true( self.user_settings.verify_code( _valid_code(self.TOTP_SECRET, drift=1) ) ) # make sure drift is updated. assert_equal(self.user_settings.totp_drift, 1) # use a code from 60 seconds in the future assert_true( self.user_settings.verify_code( _valid_code(self.TOTP_SECRET, drift=2) ) ) # make sure drift is updated. assert_equal(self.user_settings.totp_drift, 2) # use the current code (which is now 2 periods away from the drift) assert_false( self.user_settings.verify_code(_valid_code(self.TOTP_SECRET)) )
32.416667
78
0.646646
1
1.9956
[ -0.04423307627439499, 0.006407338660210371, 0.015773557126522064, -0.0027866752352565527, -0.03773210197687149, 0.012120266444981098, -0.010201936587691307, -0.031499698758125305, -0.035058874636888504, 0.01916605979204178, 0.0009597586467862129, 0.00963648408651352, 0.04590686038136482, -0.008748273365199566, 0.013947172090411186, 0.008593021892011166, -0.044621389359235764, 0.001503659295849502, -0.007193156983703375, -0.006041856948286295, 0.0027103133033961058, -0.00013491068966686726, 0.008532770909368992, -0.004610234405845404, 0.01181089784950018, 0.007609906606376171, 0.021582381799817085, 0.019059309735894203, 0.002048117807134986, -0.009281079284846783, -0.012542320415377617, -0.017540868371725082, -0.0250877495855093, -0.04004445672035217, 0.02320651337504387, 0.038119345903396606, 0.02020825445652008, -0.08843085169792175, 0.035887397825717926, -0.006643996108323336, -0.0186641626060009, 0.024765729904174805, 0.028174705803394318, -0.006803932134062052, 0.01817726530134678, -0.0005968004697933793, 0.000395995972212404, 0.01372902188450098, -0.025681771337985992, 0.006880256347358227, -0.02425564080476761, 0.01645517908036709, 0.013963961973786354, 0.010567392222583294, -0.0237090103328228, -0.06726817041635513, 0.03887012228369713, 0.0023192609660327435, -0.024893106892704964, 0.0021106444764882326, -0.014582337811589241, 0.0013170911697670817, 0.006348500028252602, 0.022416584193706512, 0.04868770390748978, -0.00618376350030303, 0.0040220352821052074, -0.0011867416324093938, -0.09144622832536697, -0.009097199887037277, 0.002736317925155163, -0.01779972016811371, 0.010263272561132908, 0.07107274234294891, 0.050422754138708115, 0.011321081779897213, -0.01550903357565403, -0.019644808024168015, -0.03848935663700104, 0.01768067665398121, -0.02011818066239357, 0.05269530043005943, 0.02011191099882126, 0.006295495666563511, 0.0049460758455097675, -0.0005025939899496734, 0.029194438830018044, -0.038393352180719376, 0.024351289495825768, 0.003434513695538044, -0.03839116171002388, 0.034783586859703064, -0.06214245408773422, -0.004364399705082178, -0.018470533192157745, -0.08190145343542099, -0.015408745966851711, 0.004601947497576475, 0.023295344784855843, -0.04329542815685272, -0.00400953134521842, -0.011591045185923576, 0.004557185806334019, 0.002840686123818159, -0.0023923604749143124, -0.03139323368668556, -0.05108292028307915, -0.005674016661942005, 0.0018539236625656486, -0.027179131284356117, -0.01885528676211834, -0.003253744915127754, 0.0304756797850132, -0.022835418581962585, 0.01888170652091503, -0.016962453722953796, 0.006779280956834555, 0.00615172553807497, 0.015126524493098259, 0.10614503175020218, 0.015281234867870808, -0.030586641281843185, 0.01640293560922146, -0.010579248890280724, -0.019092854112386703, 0.06872279196977615, -0.005842431914061308, -0.026196423918008804, 0.030600691214203835, 0.04490090161561966, -0.008977298624813557, -0.0034451340325176716, -0.003199309343472123, 0.011280877515673637, 0.015857823193073273, 0.005291032139211893, 0.02029993385076523, 0.014987882226705551, -0.0625123456120491, 0.011291592381894588, 0.020669829100370407, -0.014648428186774254, 0.032736264169216156, -0.02025034837424755, -0.019765838980674744, -0.02488350123167038, -0.0074969809502363205, 0.017683498561382294, -0.0005665549542754889, -0.011469763703644276, 0.018942171707749367, -0.012771871872246265, 0.013657000847160816, -0.00179031933657825, -0.0006662782980129123, 0.0069200131110847, -0.02925781160593033, -0.06375886499881744, -0.00541425496339798, -0.007773632183670998, -0.015057346783578396, -0.0067257205955684185, -0.013929159380495548, 0.014989917166531086, 0.02325599454343319, -0.029444802552461624, -0.05634868144989014, 0.0025161700323224068, -0.012394437566399574, -0.004985003266483545, -0.003434170037508011, 0.01742771454155445, -0.021547967568039894, -0.004895088728517294, -0.02873268350958824, 0.00802371371537447, 0.016686484217643738, 0.04070626199245453, -0.03608815371990204, -0.014431029558181763, -0.009554344229400158, -0.033165011554956436, -0.007994993589818478, 0.04217124357819557, 0.005749183241277933, -0.02282235585153103, -0.056416433304548264, -0.03743765503168106, 0.022102205082774162, -0.03942832350730896, -0.04416360706090927, -0.005740873049944639, -0.028949212282896042, 0.013852378353476524, 0.018998626619577408, -0.015843035653233528, -0.010702874511480331, -0.00003879760697600432, 0.00795674417167902, -0.005619555711746216, -0.028692588210105896, -0.015666810795664787, -0.03211010992527008, 0.012221010401844978, -0.004104431718587875, 0.020315585657954216, -0.7150352597236633, 0.019124852493405342, -0.008879438042640686, -0.02020474709570408, 0.03185185045003891, 0.0446958988904953, -0.05290352180600166, -0.012466445565223694, -0.0027733363676816225, 0.003356268396601081, -0.01266651414334774, -0.0027421261183917522, -0.04006253182888031, 0.009341034106910229, 0.019556032493710518, -0.016344083473086357, 0.018613407388329506, 0.02053704485297203, 0.0042224484495818615, 0.030780544504523277, 0.0177957434207201, -0.049376510083675385, -0.02856571227312088, -0.0007716803811490536, 0.020035913214087486, 0.0031987037509679794, 0.024637265130877495, 0.014207699336111546, -0.012351461686193943, -0.01747734658420086, 0.02137024886906147, 0.013474715873599052, 0.009726358577609062, 0.012002772651612759, 0.02741037681698799, 0.02870265766978264, 0.04429665580391884, -0.027408046647906303, -0.004977289121598005, -0.007956605404615402, 0.0017120089614763856, -0.024481462314724922, -0.008082929067313671, -0.06118439882993698, -0.00752098485827446, 0.033629801124334335, -0.00901922956109047, -0.02210487239062786, 0.003931423649191856, 0.0138888880610466, -0.0442521795630455, 0.0622471459209919, 0.02661939524114132, -0.017351966351270676, -0.03687187284231186, 0.023328280076384544, -0.03297526389360428, -0.02252293936908245, 0.00038496742490679026, -0.0063862185925245285, 0.0059705087915062904, 0.014624384231865406, -0.021913280710577965, 0.01482605841010809, -0.005127062555402517, 0.0013125406112521887, 0.08573790639638901, -0.03318137675523758, -0.0210860688239336, 0.010210325941443443, -0.05021219700574875, -0.036144573241472244, -0.04604480043053627, 0.11029848456382751, 0.02942112274467945, -0.014094319194555283, -0.008647965267300606, -0.027768786996603012, -0.05485249310731888, -0.022046023979783058, 0.030518170446157455, -0.002709808759391308, -0.02749066799879074, 0.0038533026818186045, -0.005387429613620043, -0.022947078570723534, 0.014591728337109089, 0.012393612414598465, -0.018658850342035294, 0.017643379047513008, 0.059777308255434036, 0.01892196014523506, 0.03393055126070976, -0.005073472857475281, -0.012918000109493732, 0.006717807147651911, 0.023951703682541847, 0.04560369998216629, 0.0003760620893444866, -0.010357716120779514, -0.005403505638241768, 0.009732728824019432, -0.019707942381501198, 0.011539940722286701, -0.04920669272542, 0.01689889281988144, -0.018944574519991875, -0.013158107176423073, 0.03783627226948738, 0.04017239063978195, -0.002597643295302987, -0.01967807486653328, -0.033304762095212936, 0.022915789857506752, 0.013734223321080208, -0.01743508130311966, 0.0007530933362431824, -0.01405368186533451, 0.012425524182617664, -0.02791503444314003, -0.005297261755913496, -0.03558404743671417, -0.004058133810758591, 0.03520070016384125, -0.007699070032685995, 0.02534829080104828, -0.03802485764026642, 0.014249426312744617, -0.02023252472281456, 0.0209061149507761, -0.010241287760436535, -0.018383607268333435, -0.0017154001398012042, -0.04298717901110649, -0.023520072922110558, 0.019334128126502037, -0.007754534017294645, -0.01671183854341507, -0.0222619641572237, -0.00594312185421586, 0.006029509473592043, -0.01944640278816223, 0.03912476450204849, -0.06070869788527489, -0.005379049107432365, -0.020697934553027153, 0.028923694044351578, -0.008174842223525047, -0.019767120480537415, -0.031343139708042145, 0.008443337865173817, 0.05931580439209938, 0.006946421694010496, 0.03548108786344528, -0.0019067093962803483, 0.013647115789353848, 0.002688653999939561, 0.021413058042526245, 0.0487295538187027, 0.050655826926231384, -0.0035630546044558287, -0.019179411232471466, 0.0011828374117612839, 0.0014481203397735953, -0.023423586040735245, 0.0039588636718690395, -0.0017711137188598514, 0.036659594625234604, 0.017242437228560448, 0.020693793892860413, 0.009332620538771152, -0.021476496011018753, 0.01809929497539997, -0.0022580118384212255, -0.016325153410434723, 0.005445102695375681, 0.004953040741384029, -0.046286262571811676, 0.03225405514240265, -0.006945598870515823, -0.012285890057682991, -0.010131142102181911, -0.005795944482088089, -0.010218317620456219, -0.022273698821663857, 0.023874424397945404, 0.005823112092912197, 0.03880591690540314, 0.03736686706542969, -0.03534175083041191, 0.017224619165062904, 0.024044089019298553, -0.022984031587839127, 0.004048540722578764, -0.007254414726048708, -0.016284862533211708, -0.005330479703843594, -0.03292310610413551, -0.02686486579477787, -0.008857826702296734, -0.014322003349661827, 0.005915866233408451, -0.012477048672735691, 0.03718804568052292, 0.008528667502105236, 0.014043794944882393, 0.006316924002021551, -0.014164481312036514, 0.027426112443208694, -0.026806581765413284, 0.01052839495241642, -0.0018799592508003116, -0.0022941434290260077, 0.01566196233034134, 0.03718956559896469, 0.05785728618502617, -0.010798470117151737, -0.02714981511235237, -0.00827023759484291, -0.0009297143551521003, -0.0013447708915919065, -0.0061914012767374516, 0.00902345310896635, 0.011781226843595505, 0.008182923309504986, -0.01925373263657093, -0.009416203945875168, -0.010571465827524662, -0.008465716615319252, -0.0025361524894833565, -0.009623013436794281, 0.01852845400571823, 0.00992113258689642, -0.039464253932237625, -0.01737869903445244, -0.0007399222231470048, -0.0035794402938336134, -0.024539658799767494, 0.013859163038432598, -0.03557741641998291, 0.007699750363826752, -0.017818108201026917, -0.026173152029514313, 0.020740557461977005, 0.004177200607955456, -0.01577550172805786, 0.03355233371257782, -0.024669703096151352, -0.06057015806436539, -0.004670563619583845, -0.036546800285577774, -0.03817110136151314, -0.02289065532386303, 0.02145927958190441, 0.014898022636771202, 0.02911313623189926, -0.02056659385561943, 0.010783390142023563, 0.005339139606803656, 0.010434026829898357, 0.003872320521622896, -0.02129266783595085, 0.04855649918317795, 0.03299816697835922, -0.05624460428953171, 0.02998845838010311, -0.005223365966230631, -0.0437270812690258, -0.028576718643307686, 0.041659511625766754, 0.023091917857527733, 0.007881761528551579, 0.00384309864602983, 0.024700000882148743, -0.028629034757614136, -0.008763188496232033, -0.015290754847228527, 0.005552332382649183, 0.05607626587152481, 0.00709555484354496, -0.02993057481944561, 0.006278630346059799, 0.011216601356863976, 0.0357036367058754, -0.005582273006439209, 0.009782315231859684, 0.01644279807806015, 0.007779466919600964, -0.012247418984770775, 0.01870952732861042, 0.00987121183425188, -0.034420404583215714, -0.019478417932987213, -0.0057540107518434525, -0.02103734016418457, -0.004754040390253067, 0.0014798376942053437, 0.01874024234712124, 0.065921351313591, 0.010645193979144096, 0.02721073478460312, 0.006543829571455717, -0.016471687704324722, 0.029993921518325806, -0.003051640698686242, -0.020976120606064796, -0.0015131024410948157, 0.022360188886523247, 0.024516284465789795, 0.0038650953210890293, -0.003050275379791856, 0.007418937049806118, 0.019398244097828865, 0.018203934654593468, -0.003584569552913308, 0.005534180905669928, 0.05531841889023781, 0.04484397545456886, 0.03112766519188881, 0.003138991305604577, -0.02198163978755474, 0.045748479664325714, -0.011744653806090355, -0.007077666465193033, -0.0054293442517519, -0.03569803386926651, -0.045481398701667786, -0.004833989776670933, -0.02306056022644043, 0.018144018948078156, -0.004144888836890459, -0.03377949446439743, 0.03644470125436783, 0.021764328703284264, 0.055256620049476624, -0.006027523893862963, 0.004481954500079155, 0.028922978788614273, 0.010389911010861397, -0.014979797415435314, -0.006389600690454245, 0.009941347874701023, -0.0001751020463416353, -0.032188862562179565, 0.03533494099974632, 0.00394304096698761, 0.0070547801442444324, 0.02769744209945202, -0.0006735321367159486, 0.028088824823498726, 0.006310058292001486, -0.03611833602190018, -0.019705435261130333, 0.05400172993540764, 0.01287713460624218, -0.01397770456969738, 0.002585208509117365, 0.015110145322978497, 0.01767147332429886, -0.0009909492218866944, 0.04911164939403534, -0.003853847272694111, 0.0034577897749841213, -0.012486446648836136, -0.0068218158558011055, -0.02092810906469822, 0.013910490088164806, -0.00537821976467967, -0.004961430095136166, 0.0072461399249732494, 0.008698775433003902, -0.018810858950018883, -0.003103285562247038, -0.021765930578112602, 0.011084884405136108, -0.030145835131406784, 0.018181005492806435, -0.015513665974140167, 0.01990881748497486, -0.03248514235019684, -0.012075564824044704, -0.029428642243146896, 0.01697698049247265, -0.013257932849228382, 0.03757637366652489, -0.027272608131170273, 0.015972193330526352, 0.02161516807973385, -0.028985146433115005, -0.01467091590166092, -0.012995093129575253, -0.017929289489984512, 0.004795770160853863, -0.022968413308262825, -0.01157030463218689, 0.008652755059301853, -0.004921544808894396, 0.006339299958199263, 0.010767298750579357, -0.004886886570602655, -0.026245711371302605, 0.001375064137391746, -0.025406869128346443, -0.027758872136473656, 0.04112836346030235, -0.03187764436006546, 0.023042624816298485, 0.008558113127946854, 0.02139327861368656, 0.02278435230255127, -0.0062154256738722324, -0.005982661619782448, -0.03771704062819481, 0.019063403829932213, 0.007461006753146648, 0.05362202599644661, -0.03557448089122772, -0.00940390583127737, -0.021119268611073494, -0.0026253124233335257, -0.011831622570753098, 0.02158861793577671, 0.0058006965555250645, 0.021788259968161583, -0.03247757628560066, -0.013167628087103367, 0.01675313524901867, 0.029336681589484215, 0.01650572195649147, 0.005112261511385441, -0.014608923345804214, -0.047351688146591187, -0.026978768408298492, 0.0019764178432524204, 0.015115552581846714, -0.025680825114250183, -0.008014221675693989, 0.006545915734022856, -0.00959188025444746, -0.009828684851527214, -0.039908889681100845, -0.017126530408859253, 0.020989494398236275, 0.0040750098414719105, 0.02388180047273636, 0.017588047310709953, 0.028608350083231926, -0.02081620879471302, -0.029187986627221107, 0.009505859576165676, -0.020529208704829216, 0.014127389527857304, 0.02423159033060074, 0.0029146054293960333, -0.0018215188756585121, 0.036800045520067215, 0.03849620372056961, 0.014535396359860897, 0.035058893263339996, 0.030997224152088165, 0.008415092714130878, -0.005803395062685013, -0.01932103931903839, -0.010029765777289867, 0.004524405114352703, 0.03181542828679085, 0.01212212536484003, -0.017656050622463226, -0.006490166299045086, -0.018209120258688927, -0.02396794781088829, 0.01919085904955864, -0.0011448622681200504, -0.04005226120352745, -0.0010945906396955252, 0.011587395332753658, 0.012294318526983261, 0.040071453899145126, 0.029939869418740273, 0.03442135825753212, -0.019097160547971725, 0.06885015219449997, -0.008683053776621819, 0.041002899408340454, 0.025865482166409492, 0.01856505498290062, 0.005872944835573435, 0.00908354390412569, -0.00012558385787997395, 0.00653468631207943, -0.05715448409318924, -0.03659826144576073, -0.034334708005189896, 0.03426223248243332, 0.011411108076572418, -0.022518614307045937, 0.012025228701531887, -0.038010332733392715, 0.027714703232049942, 0.019712548702955246, -0.015705611556768417, -0.03868754580616951, -0.007966281846165657, 0.020044244825839996, 0.03858480229973793, -0.005450346041470766, 0.03915178403258324, 0.028413116931915283, -0.03579454869031906, 0.01535725500434637, -0.017643367871642113, -0.005747856106609106, -0.006234311498701572, 0.0128016984090209, 0.025746284052729607, 0.025286875665187836, -0.012662447988986969, -0.06040987744927406, -0.009599545039236546, -0.029466407373547554, -0.006525074597448111, 0.022055864334106445, 0.024292051792144775, -0.008534105494618416, -0.014216022565960884, -0.001254924340173602, 0.0038602687418460846, -0.03638647496700287, 0.016570044681429863, 0.025149615481495857, 0.005714746192097664, 0.03154103085398674, -0.012335251085460186, -0.003263087710365653, 0.003918780479580164, -0.05021274462342262, 0.009977376088500023, 0.036327064037323, -0.0006085471832193434, -0.01311529241502285, 0.013399394229054451, 0.0167459174990654, -0.022774167358875275, 0.0008393505122512579, -0.01418488658964634, -0.006373627111315727, 0.013581542298197746, -0.03238268941640854, 0.008628393523395061, -0.002751407213509083, 0.0007707510958425701, -0.00797057244926691, 0.012354004196822643, 0.022674890235066414, -0.02892274409532547, -0.0055435351096093655, 0.0061765252612531185, 0.01718909852206707, -0.006088956259191036, -0.04967422038316727, 0.012225446291267872, 0.014551673084497452 ]
8abd39aa48321431318051d54854247571fa2704
311
py
Python
betterloader/standard_transforms.py
BinItAI/BetterLoader
29ebcc22b53db6417a4b14d95f0a1e7f5afe7af8
[ "MIT" ]
39
2020-08-11T09:58:08.000Z
2022-02-24T19:22:42.000Z
betterloader/standard_transforms.py
BinItAI/BetterLoader
29ebcc22b53db6417a4b14d95f0a1e7f5afe7af8
[ "MIT" ]
21
2020-08-11T09:58:46.000Z
2021-05-10T12:50:12.000Z
betterloader/standard_transforms.py
BinItAI/BetterLoader
29ebcc22b53db6417a4b14d95f0a1e7f5afe7af8
[ "MIT" ]
2
2020-10-29T14:51:01.000Z
2021-01-08T09:40:34.000Z
import numpy as np from torchvision import transforms np.random.seed(1) class TransformWhileSampling(object): def __init__(self, transform): self.transform = transform def __call__(self, sample): x1 = self.transform(sample) x2 = self.transform(sample) return x1, x2
19.4375
37
0.678457
1
0.7236
[ -0.0006887665949761868, 0.0238957479596138, 0.01042438205331564, 0.0006929572555236518, 0.004824929405003786, -0.004575209226459265, -0.006409822963178158, 0.0022637909278273582, -0.006691998802125454, 0.002547102514654398, 0.0029665010515600443, 0.004002177156507969, 0.012224076315760612, -0.014741694554686546, -0.001140010543167591, 0.0188935287296772, -0.05725238099694252, 0.0028580736834555864, -0.0029562520794570446, 0.002369541907683015, -0.009919018484652042, 0.010555273853242397, 0.005463636014610529, 0.008939860388636589, 0.005654628854244947, -0.0035080788657069206, 0.012842110358178616, 0.0029977697413414717, -0.009477663785219193, -0.002670828951522708, -0.00021950561495032161, -0.0007190165924839675, -0.007470380049198866, -0.0067617460153996944, 0.008787688799202442, -0.009167787618935108, 0.0007404371863231063, -0.0164460688829422, 0.011437265202403069, -0.008196281269192696, -0.004627300892025232, -0.016615701839327812, 0.0005032466142438352, 0.0037911490071564913, -0.01259983703494072, 0.0072756120935082436, -0.006351006682962179, 0.0000017377814174324158, -0.013732649385929108, 0.0036042139399796724, -0.009678345173597336, 0.006345685571432114, 0.01595289073884487, -0.00044544762931764126, -0.007523427251726389, -0.008383761160075665, 0.012380387634038925, 0.0018838263349607587, -0.011499196290969849, 0.002778416033834219, -0.0014615877298638225, -0.0031559381168335676, 0.005014020949602127, 0.001128721167333424, -0.019323769956827164, -0.0058377631939947605, -0.007828021422028542, 0.0031234880443662405, -0.005058223381638527, 0.006819047499448061, 0.000052323477575555444, -0.002237108536064625, 0.008497594855725765, 0.0063311257399618626, 0.005563189275562763, -0.002923110732808709, -0.0015376148512586951, 0.0016597165958955884, 0.009218454360961914, 0.0004370316455606371, 0.006158256903290749, -0.008123788982629776, 0.003482081927359104, 0.012748701497912407, 0.01625637337565422, 0.012285280972719193, 0.017083555459976196, -0.011620791628956795, 0.04468406364321709, 0.008269289508461952, -0.009245848283171654, 0.001962314359843731, -0.011495417915284634, -0.0017398891504853964, -0.0029319545719772577, -0.031214186921715736, 0.004861592315137386, -0.0060101887211203575, -0.0007181304972618818, 0.006592331454157829, 0.0018096542917191982, 0.005001812241971493, -0.0010872804559767246, -0.001764027401804924, -0.01027631014585495, 0.011127104051411152, -0.015375010669231415, -0.006958083249628544, 0.00827145017683506, 0.0038422972429543734, -0.013718172907829285, 0.0006507327780127525, -0.003049129620194435, -0.017666704952716827, 0.004740709904581308, 0.0025656309444457293, -0.005938094109296799, 0.0594506710767746, 0.000011317217285977677, 0.005725627299398184, -0.006554754916578531, -0.007158368360251188, 0.0011485677678138018, 0.00518447533249855, 0.01291691791266203, -0.004884055815637112, 0.012714174576103687, 0.0029679606668651104, 0.00217587617225945, 0.006300128530710936, -0.0015142105985432863, 0.010208827443420887, -0.0027670077979564667, -0.0010172199690714478, -0.002919467631727457, -0.009163971990346909, 0.004296090453863144, -0.0008879178785718977, -0.004770283121615648, 0.003709394484758377, -0.0016349141951650381, -0.012170495465397835, -0.0021616637241095304, -0.003020046977326274, 0.0028062115889042616, -0.012876546941697598, -0.008115640841424465, -0.00019344016618561, -0.006156867370009422, 0.00300485803745687, 0.008701459504663944, 0.007892917841672897, 0.0035649084020406008, -0.003305827034637332, -0.005417821928858757, -0.0005843110848218203, -0.008341253735125065, -0.002729153260588646, 0.006988870911300182, 0.0055749244056642056, -0.010585211217403412, -0.003872687928378582, 0.004268239717930555, 0.0024978197179734707, -0.0024238929618149996, 0.0011815037578344345, -0.0050224680453538895, 0.011203070171177387, 0.0001102057722164318, 0.004543082322925329, 0.012153148651123047, -0.00535219581797719, 0.003137804800644517, -0.0012878814013674855, 0.0035753531847149134, 0.0003066973586101085, 0.005858233664184809, 0.007630315143615007, -0.0051042246632277966, -0.008030708879232407, 0.009597362019121647, 0.0018721966771408916, 0.007486417889595032, 0.008252621628344059, -0.003203511470928788, 0.0006265700794756413, -0.00514577142894268, 0.0013843015767633915, 0.008982640691101551, -0.005086105316877365, 0.007893556728959084, 0.0034349230118095875, -0.014311072416603565, -0.005427523050457239, -0.0014463423285633326, -0.00871786568313837, 0.0004974444746039808, 0.01684662699699402, 0.011535804718732834, -0.0013693709624931216, 0.001655079540796578, -0.013522524386644363, -0.002084792125970125, 0.00922758225351572, 0.00033655561855994165, -0.013418711721897125, -0.9524266123771667, 0.008035636506974697, 0.0029235307592898607, -0.0028186216950416565, 0.006091855000704527, -0.000848800758831203, 0.0030641427729278803, 0.002965060295537114, 0.01577974110841751, -0.004124154336750507, -0.005291762296110392, -0.010317915119230747, -0.013508123345673084, -0.0010369092924520373, -0.0063899061642587185, -0.0026876027695834637, -0.005937256384640932, -0.003931046463549137, -0.005276579409837723, -0.00338058453053236, -0.0038926119450479746, 0.007379106245934963, -0.0035527218133211136, 0.0037228816654533148, 0.0034769680351018906, 0.006347061600536108, -0.006521567236632109, 0.00047883298248052597, 0.0026433838065713644, -0.0024011991918087006, -0.006812215317040682, -0.014962814748287201, -0.0008967435569502413, -0.003592901397496462, 0.00999247096478939, 0.001374943763948977, 0.005811160430312157, -0.00036015931982547045, 0.004990939050912857, -0.012196592055261135, 0.005295548588037491, 0.003123269183561206, 0.005352392792701721, -0.028595270588994026, 0.001596607151441276, -0.00007567644206574187, -0.007868056185543537, 0.008685599081218243, 0.0032179232221096754, -0.0026801570784300566, -0.00464679766446352, -0.006786093581467867, 0.012226014398038387, -0.005382911302149296, 0.009022747166454792, -0.004761255346238613, -0.0034215825144201517, -0.0028633330948650837, -0.007462856825441122, 0.00021289500000420958, 0.007474373560398817, -0.003857390722259879, -0.0028975510504096746, -0.006010198965668678, 0.0007843085913918912, 0.000438268412835896, -0.0003322148695588112, -0.023105762898921967, -0.011389940977096558, -0.0014393001329153776, 0.005251646041870117, 0.0023915620986372232, -0.0052159926854074, 0.002242795191705227, -0.007109818980097771, 0.004357439000159502, 0.002076385309919715, 0.0020505795255303383, -0.00794180203229189, 0.002478427719324827, -0.012512714602053165, -0.009467159397900105, 0.006309916265308857, -0.0077168624848127365, -0.006796477362513542, 0.003179804887622595, 0.007382245734333992, 0.008364222943782806, -0.0029527966398745775, 0.003507639281451702, 0.008479513227939606, 0.0009869534987956285, -0.00834045559167862, 0.007936827838420868, 0.009090942330658436, 0.0028131527360528708, -0.0034712152555584908, 0.005178800784051418, 0.008920854888856411, 0.00724295899271965, 0.005263752304017544, 0.00644083833321929, 0.001936551881954074, 0.012635055929422379, 0.001506814849562943, 0.004742039833217859, -0.0029864818789064884, -0.0018418596591800451, -0.008109424263238907, -0.0010846707737073302, -0.00872753281146288, -0.0036974989343434572, -0.01222575455904007, -0.010796732269227505, -0.008474176749587059, 0.0010013529099524021, -0.00043543282663449645, -0.0068125855177640915, -0.0033189617097377777, -0.0013479255139827728, 0.010311243124306202, -0.00030130386585369706, -0.004919684492051601, 0.0023947085719555616, 0.001283862511627376, -0.008755299262702465, 0.018792059272527695, -0.016094649210572243, 0.00937693938612938, 0.0033928293269127607, -0.02012193575501442, 0.006136113777756691, 0.010683372616767883, -0.009970120154321194, 0.0008718677563592792, 0.0014370364369824529, -0.000037432662793435156, 0.000006472298082371708, -0.007263438776135445, -0.0015688512939959764, -0.021086780354380608, -0.0018121082102879882, 0.018359102308750153, 0.005005487706512213, 0.013687409460544586, 0.011175274848937988, -0.004737888928502798, 0.0023736744187772274, 0.004677021410316229, 0.0020811466965824366, 0.016428692266345024, -0.009099871851503849, 0.0005870139575563371, 0.002249740995466709, -0.009189773350954056, 0.0040315892547369, 0.0037811007350683212, 0.00006357306119753048, 0.0021254499442875385, 0.004656553268432617, -0.004146300721913576, -0.005836193915456533, -0.01590866968035698, -0.0038686487823724747, 0.011173234321177006, -0.003525531617924571, 0.0037221061065793037, -0.005645758006721735, 0.004164703190326691, 0.004241360817104578, 0.00763734383508563, 0.002089861547574401, 0.0012400491395965219, 0.006026589777320623, 0.010981307365000248, -0.00679808808490634, 0.0024572652764618397, 0.004441185854375362, -0.0011615620460361242, 0.0007680773269385099, 0.01085004024207592, -0.010846895165741444, -0.0034425300545990467, 0.0016443575732409954, 0.003212861018255353, 0.0018765425775200129, 0.000006696946911688428, -0.009477000683546066, -0.006780000403523445, 0.007273802999407053, -0.0036345254629850388, 0.000339325750246644, 0.00010995576303685084, 0.003911105450242758, -0.009913787245750427, 0.0019504440715536475, -0.006235088687390089, -0.008200056850910187, 0.01040961965918541, -0.0007821674225851893, 0.0027599637396633625, 0.014749241061508656, 0.006537210196256638, -0.013950629159808159, 0.00886793714016676, 0.006045482587069273, -0.004460510797798634, 0.007010230328887701, 0.0077119446359574795, -0.0025778310373425484, -0.02470097690820694, -0.0034986212849617004, -0.013161773793399334, 0.005731331650167704, -0.002671934198588133, 0.007134763989597559, -0.006982229650020599, 0.005386987701058388, 0.005446992814540863, -0.011580879800021648, -0.007463696412742138, -0.00970865786075592, 0.006956121418625116, -0.002834130311384797, 0.0013110527070239186, -0.003524147905409336, -0.004408311098814011, -0.0026653956156224012, -0.0009266554843634367, -0.002968242159113288, 0.006119417957961559, 0.0017334860749542713, -0.005372888408601284, 0.0010331925004720688, -0.0004493674205150455, 0.0006822069990448654, 0.000249892269494012, -0.010427405126392841, 0.0003363377181813121, 0.004927401896566153, -0.0016060705529525876, -0.0018725801492109895, -0.001461373409256339, -0.0031059817411005497, -0.006602759473025799, -0.01029647421091795, -0.0009489148505963385, -0.0027162113692611456, -0.004059596452862024, -0.008201087825000286, -0.0043849521316587925, -0.005818348377943039, 0.00783790647983551, -0.008715270087122917, 0.010926897637546062, 0.009560056030750275, -0.0051683420315384865, 0.007261688821017742, -0.004177238792181015, 0.0033757591154426336, 0.0018179573817178607, 0.005513694137334824, 0.000387212639907375, -0.012628329917788506, -0.006553801707923412, 0.014386173337697983, -0.009228648617863655, 0.0013951314613223076, 0.01703791134059429, 0.0021829227916896343, 0.006138630211353302, -0.0024795830249786377, -0.002221456030383706, 0.002242401707917452, 0.007392119150608778, -0.014655422419309616, 0.003942473325878382, -0.0046981084160506725, 0.0019097556360065937, 0.006010937038809061, -0.006154458969831467, 0.0018051002407446504, 0.0077348314225673676, 0.0020387349650263786, -0.007485164795070887, 0.00013151812891010195, -0.00037762123974971473, 0.0021660698112100363, -0.01278071291744709, 0.0017226292984560132, -0.0016639045206829906, -0.005620223004370928, -0.003357846522703767, -0.0038688480854034424, 0.001835930161178112, 0.00538966991007328, -0.0025167313870042562, 0.00452399393543601, -0.0010297138942405581, -0.0066987923346459866, 0.015959544107317924, -0.002524640178307891, -0.003946367651224136, 0.004293237347155809, 0.0033822685945779085, -0.0014953195350244641, -0.0056526330299675465, -0.003344322321936488, 0.004301107954233885, 0.001687525538727641, -0.002384267747402191, -0.004942737054079771, -0.0021500764414668083, -0.0023219315335154533, -0.010541575960814953, 0.0034680452663451433, 0.013234836049377918, -0.0020930750761181116, 0.003701122011989355, 0.0009509849478490651, -0.011386275291442871, -0.016206922009587288, 0.05416765436530113, -0.0003413288504816592, 0.001598893548361957, 0.005439212080091238, -0.004416552372276783, -0.003394660772755742, 0.00002618694634293206, 0.010138627141714096, -0.007209911476820707, -0.009288284927606583, 0.010202829726040363, -0.005009868647903204, 0.0010801787720993161, 0.00408318592235446, 0.0012791332555934787, 0.01864147000014782, -0.003506676061078906, -0.014992372132837772, -0.018364135175943375, 0.005476089660078287, -0.007022852078080177, -0.008360156789422035, 0.006352849770337343, -0.0031064976938068867, -0.0024143795017153025, 0.0034262367989867926, 0.008401002734899521, -0.00021416062372736633, -0.00034415474510751665, -0.0034861539024859667, -0.0019244085997343063, 0.0056653921492397785, 0.0018711596494540572, 0.006466647610068321, 0.011593488045036793, -0.00023324121139012277, 0.007348420564085245, 0.00033087964402511716, -0.0018482243176549673, -0.004450060892850161, 0.005541641730815172, 0.006809303071349859, -0.004586630035191774, -0.008450123481452465, 0.0008384042885154486, 0.0023591506760567427, 0.0006228592246770859, 0.013769619166851044, 0.001968023832887411, -0.006312697194516659, 0.008213256485760212, 0.006525232456624508, -0.0003024972975254059, 0.01302673015743494, -0.0009581929771229625, 0.003659717971459031, 0.004267275799065828, -0.008145278319716454, -0.012533338740468025, 0.0018804967403411865, 0.01079553086310625, 0.008710782043635845, -0.0004328799550421536, 0.003716785693541169, 0.0023751615080982447, -0.0028241057880222797, -0.009295073337852955, -0.0073652504943311214, -0.004962129518389702, 0.001286564045585692, 0.002355808624997735, 0.07015509158372879, -0.01046194601804018, -0.0009442419395782053, -0.010181347839534283, 0.005605126265436411, -0.001176128746010363, -0.0029429129790514708, -0.000915961223654449, -0.0004799851740244776, 0.0036870772019028664, 0.004167190752923489, -0.010746670886874199, -0.010976000688970089, 0.0011848218273371458, 0.002439861884340644, 0.0005980061832815409, 0.0014372807927429676, 0.007102389819920063, -0.006294841878116131, 0.003817856777459383, -0.01167427096515894, -0.004144315607845783, -0.0008071513148024678, -0.010637223720550537, -0.00635272404178977, -0.005106269847601652, 0.0029283256735652685, 0.004941391758620739, 0.004290340933948755, -0.0068051572889089584, 0.005470439326018095, 0.000042951138311764225, 0.0024753427132964134, 0.0009871739894151688, -0.0026089269667863846, -0.008098267018795013, 0.009429230354726315, 0.003472178475931287, -0.017988665029406548, -0.0038951020687818527, -0.0018161440966650844, -0.000711850356310606, -0.006583668291568756, 0.00882564764469862, -0.0039479099214077, 0.0060834623873233795, -0.004434621427208185, 0.0012177859898656607, -0.0033584032207727432, 0.006066265050321817, -0.013716618530452251, 0.00465540774166584, -0.18388332426548004, 0.01203069742769003, 0.0036095434334129095, -0.005691977683454752, -0.0048321993090212345, -0.015315341763198376, -0.013334416784346104, 0.005420124623924494, 0.01032065600156784, 0.004621169064193964, 0.0011413610773161054, -0.0034233531914651394, 0.00640088552609086, 0.00006215137545950711, -0.0011929782340303063, -0.01119286473840475, 0.006273282691836357, -0.00756890419870615, 0.0022808192297816277, 0.006559479515999556, 0.005194901954382658, 0.011541057378053665, 0.0008904447895474732, 0.00207950035110116, 0.002309811767190695, -0.001195481396280229, 0.004500536248087883, -0.0010863967472687364, 0.005828124936670065, -0.009878329001367092, -0.0063516320660710335, -0.0070525300689041615, -0.0042109498754143715, 0.00387216336093843, 0.002880285494029522, 0.0006006252369843423, 0.0069389003328979015, 0.001579083502292633, -0.009820147417485714, 0.006097076926380396, -0.006775280460715294, 0.030388537794351578, 0.006488474551588297, 0.005883251316845417, 0.0019766967743635178, -0.005325171630829573, -0.00495331734418869, 0.00953392218798399, 0.0038116725627332926, 0.01346302404999733, -0.015541870146989822, -0.006040487438440323, -0.002219271147623658, 0.019056100398302078, -0.007006073836237192, -0.010001899674534798, -0.00861621368676424, -0.00445080641657114, 0.0019265910377725959, 0.008833998814225197, 0.014511046931147575, -0.004032981116324663, 0.005967425182461739, -0.0027384688146412373, -0.02524775266647339, 0.00014081018161959946, 0.0003486074274405837, -0.007125332951545715, -0.0026308309752494097, 0.0037869373336434364, 0.009654566645622253, -0.002396809170022607, 0.004613567143678665, 0.003684766124933958, 0.003529048291966319, -0.004802684765309095, 0.006099632941186428, -0.0018436064710840583, 0.007392033003270626, -0.008355624042451382, 0.014300837181508541, -0.008725540712475777, -0.0023243201430886984, 0.00262946798466146, -0.002549172844737768, 0.007986744865775108, 0.008689723908901215, -0.006213165353983641, -0.002901739440858364, -0.009817436337471008, -0.003786696121096611, 0.002723108744248748, -0.00003507079236442223, -0.008897057734429836, 0.0028476964216679335, -0.0006032604724168777, 0.005025517661124468, 0.008374832570552826, -0.007876858115196228, 0.006807783618569374, 0.006383243948221207, -0.010772478766739368, -0.00044349313247948885, -0.00689407903701067, 0.0077415634877979755, 0.00521080382168293, -0.008358313702046871, -0.007470801472663879, 0.0035773240961134434, -0.00571078946813941, -0.003263268619775772, 0.0017226681811735034, -0.010443086735904217, -0.011509637348353863, -0.0009993691928684711, -0.010550593957304955, -0.002315447898581624 ]
8abed448e30652e384272b8cc640eedca2d718cf
1,708
py
Python
lanedet/runner/utils/net_utils.py
ztjsw/lanedet
c957e1f70695e39063231612637e22fcad2769f5
[ "Apache-2.0" ]
1
2021-05-22T09:36:17.000Z
2021-05-22T09:36:17.000Z
lanedet/runner/utils/net_utils.py
ztjsw/lanedet
c957e1f70695e39063231612637e22fcad2769f5
[ "Apache-2.0" ]
null
null
null
lanedet/runner/utils/net_utils.py
ztjsw/lanedet
c957e1f70695e39063231612637e22fcad2769f5
[ "Apache-2.0" ]
null
null
null
import torch import os from torch import nn import numpy as np import torch.nn.functional from termcolor import colored from .logger import get_logger def save_model(net, optim, scheduler, recorder, is_best=False): model_dir = os.path.join(recorder.work_dir, 'ckpt') os.system('mkdir -p {}'.format(model_dir)) epoch = recorder.epoch ckpt_name = 'best' if is_best else epoch torch.save({ 'net': net.state_dict(), 'optim': optim.state_dict(), 'scheduler': scheduler.state_dict(), 'recorder': recorder.state_dict(), 'epoch': epoch }, os.path.join(model_dir, '{}.pth'.format(ckpt_name))) # remove previous pretrained model if the number of models is too big # pths = [int(pth.split('.')[0]) for pth in os.listdir(model_dir)] # if len(pths) <= 2: # return # os.system('rm {}'.format(os.path.join(model_dir, '{}.pth'.format(min(pths))))) def load_network_specified(net, model_dir, logger=None): pretrained_net = torch.load(model_dir)['net'] net_state = net.state_dict() state = {} for k, v in pretrained_net.items(): if k not in net_state.keys() or v.size() != net_state[k].size(): if logger: logger.info('skip weights: ' + k) continue state[k] = v net.load_state_dict(state, strict=False) def load_network(net, model_dir, finetune_from=None, logger=None): if finetune_from: if logger: logger.info('Finetune model from: ' + finetune_from) load_network_specified(net, finetune_from, logger) return pretrained_model = torch.load(model_dir) net.load_state_dict(pretrained_model['net'], strict=True)
34.16
84
0.648712
1
1.2486
[ 0.002926836023107171, 0.023251431062817574, 0.009172576479613781, 0.001690214965492487, 0.003568753134459257, -0.002630744595080614, -0.007076164707541466, 0.0027239620685577393, -0.007902130484580994, 0.004004080314189196, 0.0019834828563034534, 0.0036091296933591366, 0.007361412048339844, -0.015940768644213676, -0.0009746825089678168, 0.015301452949643135, -0.05027743801474571, 0.0032176850363612175, -0.005908085498958826, 0.0024225765373557806, -0.0074877566657960415, 0.008159232325851917, 0.009376355446875095, 0.007044909987598658, 0.0027709859423339367, -0.0008326875395141542, 0.010582588613033295, -0.0002073101350106299, -0.004353971220552921, -0.006806822028011084, -0.0009834395023062825, -0.0030471952632069588, -0.007571645081043243, -0.005376678425818682, 0.005566975101828575, -0.004326849710196257, 0.002152995904907584, -0.018454216420650482, 0.010831642895936966, -0.00376538815908134, -0.00386494561098516, -0.014512022957205772, -0.00038743059849366546, 0.0027667467948049307, -0.008876767940819263, 0.001128448755480349, -0.006630160380154848, 0.00330925895832479, -0.009349875152111053, 0.006796354427933693, -0.008859694935381413, 0.006822955794632435, 0.01522816438227892, 0.005258993711322546, -0.005129755474627018, -0.008556823246181011, 0.014306169003248215, 0.00010523549281060696, -0.00979275070130825, -0.0010901227360591292, -0.00452803261578083, 0.0007421357440762222, 0.003245348809286952, 0.0012294485932216048, -0.014252166263759136, -0.006725694052875042, -0.0038583020213991404, 0.002360604703426361, -0.0028225681744515896, 0.007798655889928341, 0.0018541463650763035, -0.0008202750468626618, 0.008958199992775917, 0.0019623872358351946, 0.0024516943376511335, -0.005100978538393974, 0.00008382781379623339, -0.0009426320320926607, 0.008904801681637764, 0.0034679132513701916, 0.003830996807664633, -0.00566302752122283, 0.00410613976418972, 0.012097126804292202, 0.015555789694190025, 0.010280638001859188, 0.01949475146830082, -0.008702079765498638, 0.044110774993896484, 0.007262486964464188, -0.008935946971178055, 0.0022300775162875652, -0.008152619004249573, -0.003510008566081524, -0.004992294125258923, -0.0259272288531065, -0.0010617244988679886, -0.002702087629586458, -0.00014308514073491096, 0.0031957633327692747, 0.0024258936755359173, 0.008549254387617111, -0.0015025524189695716, -0.006327706854790449, -0.00858346652239561, 0.011005357839167118, -0.009498123079538345, -0.0036262786015868187, 0.007220572791993618, 0.001134401187300682, -0.011303409934043884, -0.0018991375109180808, 0.002092041540890932, -0.012149589136242867, 0.0026496523059904575, 0.0060471161268651485, -0.006707518361508846, 0.05087951570749283, -0.0014594100648537278, 0.0015621267957612872, -0.004534158855676651, 0.00255385460332036, 0.0032569337636232376, 0.006346668116748333, 0.009174780920147896, -0.003029344603419304, 0.013327320106327534, 0.01043618656694889, 0.0036031801719218493, 0.007460047025233507, -0.0035320541355758905, 0.007721186615526676, -0.001937118940986693, -0.0035248941276222467, 0.0014868747675791383, -0.006376138888299465, 0.007846144028007984, -0.0020370017737150192, -0.010626866482198238, 0.002610711380839348, -0.0012074250262230635, -0.01031250786036253, 0.0013769033830612898, -0.003075131680816412, 0.0039781746454536915, -0.009642539545893669, -0.005199905019253492, -0.0029099767562001944, -0.004178035072982311, 0.0047320472076535225, 0.0067694345489144325, 0.004856159910559654, 0.0024560356978327036, -0.004883693065494299, -0.008223441429436207, 0.00039351085433736444, -0.0026777463499456644, 0.002870060270652175, 0.003913322929292917, 0.0038735303096473217, -0.011317028664052486, -0.0007206288864836097, 0.002032450633123517, 0.006456254981458187, -0.0005364728276617825, -0.0013908479595556855, -0.00887281820178032, 0.007708890363574028, 0.000517187814693898, 0.003026515943929553, 0.010776110924780369, -0.006602603942155838, 0.0008544607553631067, 0.00008901164255803451, 0.0008198809809982777, -0.0014982969732955098, 0.00553499860689044, 0.01157141849398613, -0.002584607806056738, -0.005956515669822693, 0.004000318236649036, 0.005646260920912027, 0.008728175424039364, 0.004731693770736456, -0.0032295379787683487, 0.0027374187484383583, -0.006275915540754795, -0.0014168709749355912, 0.006715978030115366, -0.00242178188636899, 0.004128658212721348, 0.0014541884884238243, -0.011824684217572212, -0.008178655989468098, 0.0010468907421454787, -0.007814998738467693, 0.0022399933077394962, 0.013709650374948978, 0.01091485470533371, -0.000022586664272239432, 0.004385511856526136, -0.011625622399151325, -0.00120503269135952, 0.007467855233699083, 0.0024739354848861694, -0.012453911826014519, -0.9612060189247131, 0.009039830416440964, 0.004066640045493841, -0.0032255188561975956, 0.00510122487321496, 0.0026006782427430153, 0.002743643242865801, 0.004846075549721718, 0.012189117260277271, -0.008810319937765598, -0.005736123770475388, -0.009361688047647476, -0.008577778935432434, -0.0029881861992180347, -0.005951395723968744, -0.0026052589528262615, -0.005071556195616722, -0.005353633314371109, -0.002997813280671835, -0.0049741133116185665, -0.0027432681526988745, 0.01133815385401249, -0.00031379470601677895, 0.00649594608694315, 0.003699159948155284, 0.002147404011338949, -0.00418495200574398, -0.0014571126084774733, -0.0022326644975692034, -0.0029992747586220503, -0.003829255001619458, -0.01475910097360611, -0.003765636356547475, -0.002045629546046257, 0.00804090965539217, -0.002505787881091237, 0.008795215748250484, -0.0017835963517427444, 0.0031654590275138617, -0.0083710215985775, 0.006654120981693268, -0.0006349488394334912, 0.0012307168217375875, -0.028925392776727676, -0.0026004116516560316, 0.00106210564263165, -0.007332255598157644, 0.005959689151495695, 0.001356242224574089, 0.0010936378967016935, -0.0030263573862612247, -0.005175650119781494, 0.00921538844704628, -0.007788028102368116, 0.005671822465956211, -0.006584899965673685, -0.008573268540203571, -0.002768562873825431, -0.007489440031349659, -0.0008138317498378456, 0.0042468588799238205, -0.0028540873900055885, -0.00344595848582685, -0.004143786616623402, 0.0018521243473514915, 0.0044617969542741776, 0.00027137852157466114, -0.01915889047086239, -0.007929259911179543, 0.00008525975135853514, 0.0019078630721196532, -0.0015625597443431616, -0.0038371810223907232, 0.0031451834365725517, -0.008899115957319736, 0.008096188306808472, 0.0019515251042321324, -0.0036559493746608496, -0.010999894700944424, -0.002804832300171256, -0.009229175746440887, -0.006899192463606596, 0.003152822842821479, -0.005990079138427973, -0.005293888505548239, -0.001456581405363977, 0.0013522147201001644, 0.006143656559288502, -0.0054474640637636185, 0.006181387230753899, 0.012433758936822414, -0.000606006768066436, -0.01125879492610693, 0.0038717014249414206, 0.007644522003829479, 0.003321081632748246, -0.0038118441589176655, 0.003152555087581277, 0.006863841786980629, 0.0074047851376235485, 0.0022685059811919928, 0.006220717448741198, 0.0018835338996723294, 0.011985263787209988, -0.0017587061738595366, -0.0002613508841022849, -0.0033271063584834337, -0.001991389784961939, -0.003965925425291061, -0.0017495433567091823, -0.004498597234487534, -0.004376382566988468, -0.01195699442178011, -0.007998568937182426, -0.005035906098783016, -0.0005663415649905801, 0.002363555831834674, -0.0030757389031350613, 0.0014008978614583611, 0.0015282038366422057, 0.008123589679598808, -0.0009135438594967127, -0.0031019689049571753, -0.0005635766428895295, 0.0019021854968741536, -0.0021409615874290466, 0.014877643436193466, -0.012095872312784195, 0.005265058483928442, -0.00032269908115267754, -0.013417105190455914, 0.005021009594202042, 0.00815289095044136, -0.006452127825468779, 0.0011080747935920954, 0.0014536577509716153, 0.0019606328569352627, -0.004376815166324377, -0.006077820900827646, -0.002211113926023245, -0.01625526137650013, 0.0021674365270882845, 0.018239332363009453, 0.0011809754651039839, 0.012287596240639687, 0.011749567463994026, -0.002569898497313261, 0.0019865056965500116, 0.006719335913658142, 0.002317345468327403, 0.01201674621552229, -0.008080155588686466, -0.0007038055337034166, 0.0004452905268408358, -0.006609246600419283, -0.00036575677222572267, 0.0056798723526299, 0.0033085686154663563, -0.0025168503634631634, 0.0021993215195834637, -0.006779838353395462, -0.0059800115413963795, -0.019701218232512474, -0.0034076084848493338, 0.009511237032711506, -0.00597585691139102, 0.0052202013321220875, -0.010796223767101765, 0.003798261983320117, 0.005287037696689367, 0.00626372778788209, -0.00008093651558738202, 0.0004453470464795828, 0.0072952997870743275, 0.012857181951403618, -0.008744519203901291, 0.004711605142802, 0.0012090406380593777, -0.0012971513206139207, -0.0007557347998954356, 0.008501619100570679, -0.007473893463611603, -0.004447986837476492, 0.0021863598376512527, 0.004766198806464672, 0.0015718786744400859, -0.0036803216207772493, -0.008066495880484581, -0.003727361559867859, 0.0002609559160191566, -0.0035863539669662714, 0.0029733332339674234, 0.0039510237984359264, 0.002213746542111039, -0.006803755648434162, -0.0011261467589065433, -0.0029982896521687508, -0.009756563231348991, 0.010277501307427883, -0.0024450968485325575, 0.003915884997695684, 0.014868895523250103, 0.002398737706243992, -0.013244383968412876, 0.006685167085379362, 0.009761357679963112, -0.0016390696400776505, 0.004698190838098526, 0.0055802990682423115, -0.004338710103183985, -0.02215980365872383, -0.005197722464799881, -0.013080998323857784, 0.004469382110983133, -0.0030067078769207, 0.002315992722287774, -0.0070376950316131115, 0.007706460542976856, 0.003591228974983096, -0.014110459946095943, -0.006100602447986603, -0.007632897701114416, 0.00884340051561594, -0.0009848870104178786, 0.001396229607053101, -0.00386822409927845, -0.0034677369985729456, -0.0017000805819407105, -0.004989527631551027, -0.0025200999807566404, 0.002949266228824854, 0.001883803866803646, -0.002957600634545088, 0.002688961336389184, -0.00297243008390069, 0.0014201494632288814, -0.0009027827181853354, -0.00995960459113121, -0.00025070906849578023, 0.005190027412027121, 0.00023568679171148688, -0.0034266202710568905, 0.0009679857757873833, -0.001915441476739943, -0.006764180492609739, -0.013115789741277695, -0.008490237407386303, -0.0033060952555388212, -0.0013274912489578128, -0.01262904703617096, -0.003037981456145644, -0.0095077408477664, 0.007865393534302711, -0.004143471363931894, 0.006051010452210903, 0.0048977890983223915, -0.007153194397687912, 0.0067460439167916775, -0.0029458715580403805, 0.0027380622923374176, 0.003088543424382806, 0.00375881465151906, 0.0007138348883017898, -0.003877166425809264, -0.011153661645948887, 0.012078119441866875, -0.00796604249626398, 0.002388410735875368, 0.014029765501618385, 0.004587655887007713, 0.007760150358080864, -0.0036491104401648045, 0.001097839674912393, 0.0026291776448488235, 0.004880859516561031, -0.014498785138130188, 0.0037078680470585823, -0.0029129076283425093, -0.0005399201763793826, 0.003991193138062954, -0.0035915570333600044, 0.0021028697956353426, 0.009019576013088226, 0.003663690062239766, -0.007535642944276333, -0.0013182940892875195, -0.0013528375420719385, 0.0012302633840590715, -0.01039737369865179, -0.000241030880715698, -0.004312742501497269, -0.0014575429959222674, -0.0007865389925427735, -0.0016315067186951637, 0.00014040738460607827, 0.00486866757273674, -0.0018534192349761724, 0.00572724686935544, 0.002316705882549286, -0.009010033681988716, 0.014827275648713112, -0.006949991453438997, -0.00439227232709527, 0.002959656994789839, 0.003377089509740472, -0.003886924125254154, -0.00539955822750926, -0.0003002139274030924, 0.002135847695171833, 0.0054209292866289616, -0.00518710445612669, -0.001716921804472804, 0.0008838033536449075, 0.0005141840665601194, -0.01298285648226738, 0.0021397056989371777, 0.011386455036699772, -0.002166371326893568, 0.0041553545743227005, -0.003187882713973522, -0.009459794498980045, -0.01273991446942091, 0.05152905359864235, 0.000060194430261617526, 0.0043859537690877914, 0.005691043566912413, -0.006437792908400297, -0.002344823908060789, -0.001096417079679668, 0.00702702347189188, -0.003977544605731964, -0.00737834582105279, 0.008778940886259079, -0.002791027072817087, 0.0024686583783477545, 0.006400736980140209, -0.0035938245709985495, 0.015484919771552086, -0.002726854756474495, -0.015669461339712143, -0.017832733690738678, 0.006501621566712856, -0.0048241945914924145, -0.007117383182048798, 0.010229721665382385, -0.002728709951043129, -0.005126066040247679, 0.0018604639917612076, 0.005437022540718317, 0.0009312789188697934, -0.0012422060826793313, -0.0025520031340420246, -0.0007198897656053305, 0.00011881152022397146, 0.0016294317319989204, 0.00470780348405242, 0.009348694235086441, -0.0028968071565032005, 0.003700273111462593, 0.00041330992826260626, -0.001549170701764524, -0.0020935058128088713, 0.005113745573908091, 0.006503898650407791, -0.001768689719028771, -0.0028860352467745543, 0.005681416019797325, 0.0032858324702829123, 0.0030009231995791197, 0.009589449502527714, -0.0009441060828976333, -0.004403423052281141, 0.008721075020730495, 0.00847239512950182, 0.0019190447637811303, 0.009268623776733875, -0.0016405903734266758, 0.005870364606380463, 0.0032840583007782698, -0.010222581215202808, -0.014881451614201069, -0.0012889064382761717, 0.008536622859537601, 0.006637037731707096, -0.0024989377707242966, 0.0021846843883395195, -0.0024148838128894567, -0.0031979482155293226, -0.00994059070944786, -0.00734482379630208, -0.003374314634129405, 0.0038631423376500607, 0.005684198345988989, 0.06963324546813965, -0.007103873882442713, -0.002239314839243889, -0.008030584082007408, 0.0009906769264489412, -0.00010860605107154697, -0.0004686918982770294, 0.001064635463990271, -0.0026130713522434235, 0.0034985060337930918, -0.00038632279029116035, -0.009449925273656845, -0.011228129267692566, -0.0017557214014232159, 0.0033209645189344883, -0.002584244357421994, 0.0028455203864723444, 0.004332386422902346, -0.009290788322687149, 0.002019069157540798, -0.012497763149440289, -0.0005916491500101984, -0.0014031059108674526, -0.008694776333868504, -0.002347433939576149, -0.0019516441971063614, 0.005356478039175272, 0.004179101437330246, 0.0022862753830850124, -0.0019000365864485502, 0.006994823459535837, -0.0033894702792167664, -0.0006087032961659133, -0.004020521882921457, -0.003278314135968685, -0.005247416440397501, 0.008743653073906898, 0.0022202879190444946, -0.012794854119420052, -0.0060857683420181274, 0.0006082314066588879, 0.0021619750186800957, -0.005044278223067522, 0.0018454688834026456, 0.0003678892971947789, 0.004943839740008116, -0.003389880293980241, 0.0015490239020437002, -0.007659904193133116, 0.001273958827368915, -0.010555502958595753, 0.007469813339412212, -0.16429629921913147, 0.011510569602251053, 0.0028020390309393406, -0.00578664243221283, -0.0028873635455965996, -0.013819479383528233, -0.007418817840516567, 0.002123599871993065, 0.009616034105420113, 0.001874662353657186, -0.0027903139125555754, -0.0010906390380114317, 0.0066902306862175465, 0.002946440363302827, -0.0025312595535069704, -0.003545692889019847, 0.0025702142156660557, -0.00476940767839551, 0.0010960677172988653, 0.005918310955166817, 0.00427562789991498, 0.007457480300217867, 0.0012853849912062287, 0.0036623028572648764, -0.002073768526315689, -0.0034796243999153376, 0.003052907530218363, -0.002350651193410158, 0.004911099094897509, -0.00952138938009739, -0.004536621272563934, -0.0010834875283762813, -0.0026815596502274275, 0.0012244241079315543, 0.005718456115573645, 0.0025470342952758074, 0.009321345947682858, 0.0009713253239169717, -0.007495045196264982, 0.006369198206812143, -0.0076221865601837635, 0.02604931965470314, 0.004366209730505943, 0.005086911376565695, -0.0007008837419562042, -0.006954296957701445, -0.004906846676021814, 0.009235791862010956, 0.002008602023124695, 0.01153404451906681, -0.011206020601093769, 0.0005565148312598467, 0.004138244315981865, 0.01965043507516384, -0.005432120058685541, -0.009924718178808689, -0.004455670714378357, -0.0025707734748721123, 0.0010975501500070095, 0.007533653173595667, 0.010310353711247444, -0.0027213210705667734, 0.009349899366497993, -0.00353915779851377, -0.02193106897175312, 0.004547979682683945, -0.0034926084335893393, -0.007653262931853533, 0.0006113704293966293, 0.00837269239127636, 0.00892446469515562, -0.00027111024246551096, 0.003740146057680249, -0.001728113740682602, 0.00946024153381586, 0.0013285363093018532, 0.0066673788242042065, -0.0006032962119206786, 0.0077026416547596455, -0.008995871990919113, 0.006320558022707701, -0.010579163208603859, -0.003925482276827097, 0.0034099803306162357, -0.005452800076454878, 0.009146141819655895, 0.00576449278742075, -0.0026432140730321407, -0.0009710393496789038, -0.009612475521862507, -0.0008586556650698185, -0.00011099507537437603, 0.0010120931547135115, -0.008341566659510136, 0.002027463633567095, 0.00017039114027284086, 0.004775384906679392, 0.007509653922170401, -0.01123806368559599, 0.008310077711939812, 0.004714456386864185, -0.007204653229564428, -0.0014049254823476076, -0.005066246259957552, 0.0012959076557308435, 0.005137904547154903, -0.0050752717070281506, -0.004828160163015127, 0.0033482518047094345, -0.006969656329602003, -0.003803437342867255, 0.0059825642965734005, -0.010705063119530678, -0.011975761502981186, -0.0007069313433021307, -0.009822423569858074, 0.00044774034176953137 ]
8abf08c703d4b07df642c217bba0fae7c6cdc10b
141
py
Python
hexafuel_oil/hexafuel_oil_app/apps.py
zante95/Hexafuel-Oil
41dc4c9d855c74d4bb7dd86f3ac3fb1db27b663b
[ "MIT" ]
null
null
null
hexafuel_oil/hexafuel_oil_app/apps.py
zante95/Hexafuel-Oil
41dc4c9d855c74d4bb7dd86f3ac3fb1db27b663b
[ "MIT" ]
null
null
null
hexafuel_oil/hexafuel_oil_app/apps.py
zante95/Hexafuel-Oil
41dc4c9d855c74d4bb7dd86f3ac3fb1db27b663b
[ "MIT" ]
null
null
null
from django.apps import AppConfig #pragma: no cover class HexafuelOilAppConfig(AppConfig): #pragma: no cover name = 'hexafuel_oil_app'
23.5
56
0.77305
1
0.6771
[ 0.002606448484584689, 0.024866068735718727, 0.006806943565607071, 0.0034353192895650864, 0.004909496754407883, -0.0054521504789590836, -0.012077701278030872, 0.004442140460014343, -0.006374088581651449, 0.0014368722913786769, 0.0040480573661625385, 0.005414695478975773, 0.008845467120409012, -0.01829567179083824, 0.00229823449626565, 0.019317621365189552, -0.0589376837015152, 0.006430419627577066, -0.004622193984687328, 0.0021188613027334213, -0.008250478655099869, 0.009740063920617104, 0.008203710429370403, 0.005686955526471138, 0.004616054240614176, -0.00011407088459236547, 0.009935890324413776, 0.004993132781237364, -0.007479011081159115, -0.004884164780378342, -0.0014836923219263554, -0.0009698944049887359, -0.002917773090302944, -0.007919678464531898, 0.007147955242544413, -0.0025890676770359278, 0.0013780047884210944, -0.01886720024049282, 0.008974211290478706, -0.003521372564136982, -0.01058365311473608, -0.020328087732195854, -0.000925402739085257, 0.002052878960967064, -0.014051097445189953, 0.0029686742927879095, -0.005275940988212824, 0.004473553970456123, -0.01176176406443119, 0.005800287704914808, -0.012061754241585732, 0.003839591285213828, 0.014413676224648952, 0.002897400176152587, -0.005249990150332451, -0.008197177201509476, 0.010197937488555908, 0.0015646913088858128, -0.014783483929932117, 0.0011010757880285382, -0.002504640258848667, -0.0033642826601862907, 0.0034669130109250546, 0.004930246155709028, -0.021397782489657402, -0.003250902285799384, -0.0029527151491492987, 0.0037854923866689205, -0.0010558068752288818, 0.005744657479226589, 0.002580824075266719, -0.005086934193968773, 0.007973766885697842, 0.001203867606818676, 0.004964267835021019, -0.0026847361586987972, -0.000409148633480072, 0.006151823326945305, 0.009022867307066917, 0.001140835345722735, 0.0062991175800561905, -0.010498467832803726, 0.00830803532153368, 0.013754908926784992, 0.012257586233317852, 0.007435383275151253, 0.019103605300188065, -0.0104451859369874, 0.04191901907324791, 0.00479772686958313, -0.01140558160841465, 0.002922940766438842, -0.006488828454166651, -0.002609053859487176, -0.0005413242615759373, -0.035625655204057693, 0.00227545783855021, -0.004172461107373238, -0.0010038577020168304, 0.003547429805621505, -0.0010218443349003792, 0.002911958610638976, -0.0038259627763181925, -0.0033461519051343203, -0.009456745348870754, 0.016191337257623672, -0.010190528817474842, -0.0007364223129115999, 0.008401447907090187, 0.0022056216839700937, -0.00985313393175602, 0.000412739027524367, 0.004501753021031618, -0.013554214499890804, 0.00681888684630394, 0.0022438284941017628, -0.00705827958881855, 0.058858275413513184, 0.0003557277377694845, 0.003158063627779484, -0.00672574806958437, -0.0019784774631261826, 0.000753659347537905, 0.010205084457993507, 0.0068610236048698425, -0.005965594667941332, 0.009515032172203064, 0.004747715778648853, 0.0033458920661360025, 0.0071724955923855305, 0.0010482098441570997, 0.0074964603409171104, -0.0048681506887078285, -0.0011257714359089732, 0.0002772632578853518, -0.00860440544784069, 0.008329138159751892, -0.0012808794854208827, -0.005581474397331476, 0.0003804053121712059, -0.0010721491416916251, -0.012995872646570206, 0.00023955805227160454, -0.0009644223609939218, -0.0012778639793395996, -0.014685182832181454, -0.005917208734899759, -0.0008630891679786146, -0.006552241276949644, 0.0028018783777952194, 0.007205504924058914, 0.004481342621147633, 0.0026908712461590767, -0.006375822704285383, -0.00775312352925539, -0.002299160696566105, -0.004439076408743858, 0.0034841184969991446, 0.008570830337703228, 0.004274497739970684, -0.007656094152480364, -0.0032787558156996965, 0.004231707192957401, 0.00913985539227724, -0.002679786877706647, -0.00042516578105278313, -0.007777485530823469, 0.010482295416295528, 0.0017655467381700873, 0.00198722118511796, 0.011334280483424664, -0.00394662469625473, -0.00025790560175664723, -0.0002641015453264117, 0.005168180912733078, 0.0001201357736135833, 0.0035590215120464563, 0.009785565547645092, -0.005633288994431496, -0.00717923603951931, 0.004579396452754736, 0.003077456494793296, 0.0077556162141263485, 0.011576011776924133, -0.0019827373325824738, 0.00648696580901742, -0.0020296683069318533, -0.0002943775907624513, 0.004543478600680828, -0.005109461955726147, 0.007312161382287741, 0.002542675007134676, -0.014582988806068897, -0.005200828425586224, 0.00021566158102359623, -0.010510807856917381, 0.00021121041208971292, 0.015746213495731354, 0.012943197973072529, -0.001361390226520598, 0.00483097555115819, -0.010769284330308437, 0.003284747712314129, 0.004914094228297472, 0.0017594237579032779, -0.013611325062811375, -0.9519574046134949, 0.00357810384593904, 0.0015395180089399219, 0.0012212989386171103, 0.00329733663238585, 0.0041786483488976955, 0.0023618098348379135, 0.0026858490891754627, 0.015203730203211308, -0.010571412742137909, -0.008746142499148846, -0.010270246304571629, -0.011729261837899685, 0.00003774593642447144, -0.007962743751704693, -0.00194762391038239, -0.001454027951695025, -0.006631726864725351, 0.0004413890128489584, -0.008364677429199219, -0.0023316105362027884, 0.009749224409461021, 0.0005937372334301472, 0.0034397668205201626, 0.003437075996771455, 0.005697207525372505, -0.0031197837088257074, 0.0016918567707762122, 0.0003514935087878257, 0.000024000788471312262, -0.00534789590165019, -0.016932999715209007, -0.007470475044101477, 0.00005772024451289326, 0.012120377272367477, 0.001095219631679356, 0.007802251726388931, 0.0013402957702055573, 0.0017059410456568003, -0.013227911666035652, 0.005263895262032747, 0.00233935727737844, 0.002974109724164009, -0.028615301474928856, 0.004948865156620741, -0.0024729620199650526, -0.006339297629892826, 0.008717326447367668, 0.0012171553680673242, -0.00031037849839776754, -0.0027703263331204653, -0.0015368545427918434, 0.00975784007459879, -0.009146383963525295, 0.005363576579838991, -0.009999225847423077, -0.005396328400820494, -0.0031885039061307907, -0.011947262100875378, 0.002442141529172659, 0.004082965198904276, -0.004120786674320698, -0.002940843580290675, -0.0027621514163911343, 0.0000013657754607265815, 0.002241473877802491, -0.000631182745564729, -0.017575621604919434, -0.0053518665954470634, -0.004183241631835699, 0.002630693605169654, -0.0038900936488062143, -0.0038697626441717148, 0.004195270128548145, -0.011897413060069084, 0.006536315660923719, 0.0014106087619438767, 0.002089663641527295, -0.00962074100971222, 0.006306684575974941, -0.007199931424111128, -0.010654262267053127, 0.002427260857075453, -0.00834991130977869, -0.0028799353167414665, 0.0014427532441914082, 0.006346475332975388, 0.010608039796352386, -0.003960748203098774, 0.005084502510726452, 0.0112041886895895, -0.005082360468804836, -0.009096861816942692, 0.010159293189644814, 0.00853258278220892, 0.002225905889645219, -0.0018917167326435447, 0.0015877924161031842, 0.010237502865493298, 0.007216860540211201, 0.0016692995559424162, 0.003068280406296253, -0.00020915693312417716, 0.011139415204524994, -0.0011741415364667773, 0.0033650279510766268, -0.002544132061302662, -0.0030115775298327208, -0.004641393665224314, -0.0027355351485311985, -0.0030529331415891647, 0.0006279041990637779, -0.01338768471032381, -0.011787851341068745, -0.006600385066121817, 0.0019095459720119834, -0.001087611773982644, -0.003340349765494466, 0.0021245740354061127, 0.0038301649037748575, 0.011443466879427433, 0.004351107869297266, -0.003820872399955988, 0.0032701638992875814, 0.0038573271594941616, -0.009434870444238186, 0.015437088906764984, -0.015073648653924465, 0.004210857208818197, -0.0011692468542605639, -0.01684373803436756, 0.009132766164839268, 0.010380000807344913, -0.007289346773177385, 0.0008765256498008966, 0.0044578867964446545, 0.0020963081624358892, -0.00024102757743094116, -0.0052740490064024925, -0.0026839463971555233, -0.015935460105538368, 0.0002187378704547882, 0.02114047296345234, 0.004906852729618549, 0.009548380970954895, 0.012761685065925121, -0.006079607177525759, 0.0022228502202779055, 0.008043409325182438, 0.0013984775869175792, 0.016029711812734604, -0.010407497175037861, -0.0006154173170216382, -0.0001533644099254161, -0.0053147366270422935, -0.00010299174027750269, 0.004634867887943983, 0.007119232323020697, -0.0011079581454396248, -0.0026143549475818872, -0.00598211819306016, -0.006227956619113684, -0.017311440780758858, -0.0011451483005657792, 0.009680732153356075, -0.005870814900845289, 0.004187760874629021, -0.011060669086873531, 0.007127255201339722, 0.005935596767812967, 0.002459461335092783, -0.0003046737110707909, -0.0010140283266082406, 0.009368480183184147, 0.010713202878832817, -0.007981347851455212, 0.00514413183555007, 0.00022434373386204243, -0.0019838600419461727, 0.0038087128195911646, 0.014091304503381252, -0.012017675675451756, -0.003907920327037573, 0.0047499616630375385, 0.000796367006842047, 0.0025404004845768213, -0.002930315677076578, -0.008717739023268223, -0.005118605215102434, 0.002220933558419347, -0.005059545394033194, 0.005328286439180374, 0.006218028720468283, 0.0028662437107414007, -0.009399493224918842, 0.001265395781956613, -0.006097626872360706, -0.009100503288209438, 0.013512391597032547, -0.0021331848111003637, 0.0032506659626960754, 0.010121425613760948, 0.0046566324308514595, -0.014783988706767559, 0.009587901644408703, 0.006590527947992086, -0.004876111168414354, 0.0038239818532019854, 0.008094452321529388, -0.006717258132994175, -0.0227876715362072, 0.00039500382263213396, -0.015513281337916851, 0.006370670162141323, -0.0035945004783570766, 0.002075605094432831, -0.006135955918580294, 0.008570278063416481, 0.00411205505952239, -0.013122325763106346, -0.0021656067110598087, -0.010874666273593903, 0.0097427386790514, -0.003211418865248561, -0.004422088153660297, -0.0011448964942246675, -0.0017993137007579207, -0.005155638791620731, -0.000016501919162692502, -0.0003065995406359434, 0.004943709820508957, 0.0030259538907557726, -0.0054994793608784676, 0.0013319230638444424, -0.004902583546936512, 0.0011355457827448845, 0.005156697239726782, -0.0110505111515522, 0.002293000463396311, 0.006361427716910839, -0.0012886119075119495, -0.0030278924386948347, 0.00011609052307903767, -0.0011727717937901616, -0.005768256727606058, -0.008783705532550812, -0.002898852340877056, -0.0026167917530983686, -0.002440311713144183, -0.009770995005965233, 0.0004516496555879712, -0.0074804057367146015, 0.0036798014771193266, -0.006993821356445551, 0.005654171109199524, 0.004853402730077505, -0.004642901010811329, 0.007594370748847723, -0.0032639976125210524, 0.00519456947222352, 0.006177122704684734, 0.008615856058895588, -0.002174129243940115, -0.007593706250190735, -0.011179434135556221, 0.010509397834539413, -0.009977993555366993, -0.000437457871157676, 0.015966331586241722, 0.002679772675037384, 0.00953578483313322, 0.0007643974386155605, 0.0008562285220250487, 0.00474237697198987, 0.00742143951356411, -0.01700342819094658, 0.0009143708739429712, -0.0012941068271175027, -0.0009492501267232001, 0.007040669210255146, -0.00360615155659616, 0.004025340545922518, 0.00930582545697689, 0.003327922662720084, -0.007353922817856073, -0.0034489468671381474, -0.002338799647986889, 0.004282716661691666, -0.010898055508732796, -0.001505566295236349, -0.003107961267232895, -0.003193084616214037, -0.004554255399852991, -0.003785001579672098, -0.0019999465439468622, 0.007785514462739229, -0.005926270037889481, 0.006059423089027405, 0.001151201082393527, -0.0024761157110333443, 0.014645416289567947, -0.005855977535247803, -0.006599086802452803, 0.002093998249620199, 0.0006716310745105147, 0.0007523767999373376, -0.011069163680076599, -0.0011501781409606338, 0.0014315720181912184, 0.002150882501155138, -0.0018364156130701303, -0.011632717214524746, -0.00161373324226588, 0.0021372742485255003, -0.009685404598712921, 0.0033006160520017147, 0.009323535487055779, 0.0009716366766951978, 0.003513195551931858, -0.0014009240549057722, -0.008283467963337898, -0.017382798716425896, 0.05897696688771248, -0.0016246484592556953, 0.002954385941848159, 0.005685053300112486, -0.005548861343413591, -0.0027202528435736895, -0.004529044963419437, 0.0030366568826138973, -0.006621362641453743, -0.006988023407757282, 0.006582065485417843, -0.0025035066064447165, 0.00236210273578763, -0.00009431660873815417, -0.0050145662389695644, 0.01565721072256565, -0.007761296350508928, -0.0181155763566494, -0.015495814383029938, 0.008252752013504505, -0.004350621253252029, -0.008046581409871578, 0.006344880908727646, -0.0013829945819452405, -0.0032901237718760967, 0.0020336671732366085, 0.0052884588949382305, 0.00022416908177547157, 0.0013454238651320338, -0.0036761362571269274, 0.00036765114055015147, -0.000378975149942562, 0.0034809033386409283, 0.007318857591599226, 0.010885782539844513, -0.0015890357317402959, 0.0054287682287395, -0.0076579200103878975, 0.000844377966132015, 0.001332435174845159, 0.004421592224389315, 0.007716724649071693, 0.00009095283166971058, -0.0037117458414286375, 0.002119232900440693, 0.0031935598235577345, 0.0002069208858301863, 0.010517487302422523, 0.0020243250764906406, -0.003178985556587577, 0.006268221884965897, 0.008361555635929108, -0.0012383373687043786, 0.006585084367543459, -0.0056843203492462635, 0.0026258660946041346, 0.003381964983418584, -0.008797471411526203, -0.011790755204856396, -0.0022172441240400076, 0.004156322218477726, 0.005303915590047836, -0.001101016066968441, 0.003877804381772876, 0.0004525402619037777, -0.0036987944040447474, -0.011109155602753162, -0.0041675688698887825, -0.002672031056135893, -0.0029028889257460833, 0.0033403660636395216, 0.07312209159135818, -0.0070234849117696285, -0.0037435893900692463, -0.009099114686250687, 0.0017991723725572228, 0.0012294320622459054, -0.0008315655286423862, -0.0001763182517606765, -0.000631633447483182, 0.002313514705747366, 0.006649743765592575, -0.009938093833625317, -0.010681839659810066, 0.003207084257155657, 0.0025433190166950226, -0.002840005327016115, 0.0025776666589081287, 0.007021969649940729, -0.008478937670588493, 0.003301322227343917, -0.011143448762595654, -0.002879965817555785, -0.004530344158411026, -0.004574005026370287, -0.0022640484385192394, -0.004490869119763374, -0.0035725790075957775, 0.0032684116158634424, 0.009072419255971909, -0.004629506729543209, 0.005758185870945454, -0.0010751772206276655, 0.0028644921258091927, -0.0003026194463018328, -0.0014577368274331093, -0.007923114113509655, 0.007126452401280403, -0.0009236338082700968, -0.010265173390507698, -0.0030066827312111855, -0.0029047441203147173, -0.0025571000296622515, -0.006206216290593147, 0.004954641219228506, -0.0020347496028989553, 0.0110713429749012, -0.002712670248001814, 0.003170277923345566, -0.002694489434361458, -0.002469186205416918, -0.014412030577659607, 0.004729025531560183, -0.19087207317352295, 0.01026469748467207, 0.003613798413425684, -0.006820430047810078, -0.007046610116958618, -0.015759794041514397, -0.011028912849724293, 0.005566437263041735, 0.009166688658297062, 0.0025820164009928703, -0.0013944886159151793, -0.0015270380536094308, 0.002728282241150737, 0.00371974497102201, -0.0036568867508322, -0.006737967487424612, 0.0030777365900576115, -0.008741283789277077, -0.00282481056638062, 0.0056062983348965645, 0.006919078528881073, 0.00814070925116539, 0.001137081766501069, 0.0003868991625495255, -0.0006251669838093221, -0.002055093413218856, 0.006085630971938372, -0.0032146391458809376, 0.0060242279432713985, -0.00960775651037693, -0.00528021389618516, -0.006088037975132465, -0.0015929837245494127, 0.003805154003202915, 0.0008191745146177709, -0.002496369183063507, 0.005184814799576998, 0.00013710942585021257, -0.009303954429924488, 0.010221878997981548, -0.006147722713649273, 0.031120069324970245, 0.006313782650977373, 0.009059911593794823, 0.0019709658809006214, -0.0020748975221067667, -0.0020601560827344656, 0.007566002197563648, 0.0014854880282655358, 0.014261980541050434, -0.009316221810877323, -0.006518246605992317, 0.00200620386749506, 0.017544971778988838, -0.0051988279446959496, -0.008692086674273014, -0.008885987102985382, -0.006864367518573999, 0.00614676158875227, 0.011665958911180496, 0.008344867266714573, -0.004549187608063221, 0.00727645680308342, -0.005132914055138826, -0.02119055576622486, 0.002867973642423749, 0.0009731834870763123, -0.009807157330214977, 0.002134954556822777, 0.004539045039564371, 0.009173870086669922, -0.0024615859147161245, 0.004998831078410149, -0.00040074720163829625, 0.0018989896634593606, -0.0022158415522426367, 0.00854073278605938, -0.0033280402421951294, 0.006166027393192053, -0.0055546327494084835, 0.008725330233573914, -0.010205430909991264, -0.0022526723332703114, 0.0026448031421750784, -0.0017819501226767898, 0.009431217797100544, 0.006825396791100502, -0.0039036045782268047, 0.0008318130858242512, -0.010143772698938847, -0.0011867622379213572, 0.0011499968823045492, 0.003049538703635335, -0.006526226177811623, -0.0004575270868372172, -0.0009337670635432005, 0.004788935650140047, 0.010051404125988483, -0.006424071732908487, 0.006263009272515774, 0.005743950605392456, -0.007510170340538025, -0.000493320228997618, -0.0056220670230686665, 0.0029950833413749933, 0.005060505587607622, -0.009008197113871574, -0.008294710889458656, 0.0042486111633479595, -0.005970138590782881, -0.005495009943842888, 0.006404397077858448, -0.010980728082358837, -0.009677707217633724, 0.0016667708987370133, -0.010995512828230858, 0.0018249519634991884 ]
8ac004a4f19bb41d9cfa8a39529011d30c5a08dc
5,455
py
Python
main.py
jonodrew/matchex
531e7cd1c328cb9dc34b601a06648bd2c3e709e6
[ "MIT" ]
null
null
null
main.py
jonodrew/matchex
531e7cd1c328cb9dc34b601a06648bd2c3e709e6
[ "MIT" ]
null
null
null
main.py
jonodrew/matchex
531e7cd1c328cb9dc34b601a06648bd2c3e709e6
[ "MIT" ]
null
null
null
from __future__ import division from timeit import default_timer as timer import csv import numpy as np import itertools from munkres import Munkres, print_matrix, make_cost_matrix import sys from classes import * from functions import * from math import sqrt import Tkinter as tk import tkFileDialog as filedialog root = tk.Tk() root.withdraw() p_file = filedialog.askopenfilename(title='Please select the posting file') c_file = filedialog.askopenfilename(title='Please select the candidate file') """for use with /users/java_jonathan/postings_lge.csv and /Users/java_jonathan/candidates_lge.csv""" # p_file = raw_input("Please enter the path for the postings file: ") # p_file = p_file.strip() # c_file = raw_input("Please enter the path for the candidate file: ") # c_file = c_file.strip() start = timer() with open(p_file,'r') as f: #with open('/Users/Jonathan/Google Drive/CPD/Python/postings.csv','r') as f: reader = csv.reader(f) postingsAll = list(reader) with open(c_file,'r') as f: reader = csv.reader(f) candidatesAll = list(reader) """create empty lists to fill with lists of lists output by iterating function below""" names = [] totalMatrix = [] for list in candidatesAll: candidate = Candidate(*list) names.append(candidate.name) n = 0 for list in postingsAll: posting = Posting(*list) totalMatrix.append(matchDept(posting,candidate) + matchAnchor(posting,candidate) +matchLocation(posting,candidate) + matchCompetency(posting,candidate) + matchSkill(posting,candidate)+matchCohort(posting,candidate)) n += 1 l = len(names) names.extend([0] * (n-l)) totalMatrix.extend([0] * (n**2 - len(totalMatrix))) totalMatrix = np.asarray(totalMatrix) totalMatrix = np.reshape(totalMatrix,(n,-1)) #at this point the matrix is structured as candidates down and jobs across totalMatrix = np.transpose(totalMatrix) #now it's switched! totalMatrix = np.subtract(np.amax(totalMatrix),totalMatrix) totalMatrix = np.array(totalMatrix) minSuitability = 18 check = [] result = [] m = Munkres() indexes = m.compute(totalMatrix) #print_matrix(totalMatrix, msg='Lowest cost through this matrix:') total = 0.0 unhappy_candidates = 0 medium_candidates = 0 tenpc_candidates = 0 qs_candidates = 0 vs_candidates = 0 f = open('output.txt', 'w') for row, column in indexes: if column < l: value = totalMatrix[row][column] if value > minSuitability*0.9: tenpc_candidates += 1 elif value > minSuitability*0.75: medium_candidates += 1 elif value > minSuitability/2: unhappy_candidates += 1 elif value > minSuitability*0.25: qs_candidates += 1 elif value > minSuitability*0.1: vs_candidates += 1 total += value check.append(column+1) result.append((row,column)) f.write('For candidate %s: \nOptimal position: %d (score %s)\n' % (names[column], column+1, value)) else: pass globalSatisfaction = 100*(1-(total/(l*minSuitability))) print('Global satisfaction: %.2f%%' % globalSatisfaction) print('Candidates who are more than 90%% suitable: %d' % vs_candidates) print('Candidates who are more than 75%% suitable: %d' % qs_candidates) print('Candidates who are more than 50%% suitable: %d' % (l-unhappy_candidates)) print('Candidates who are more than 75%% unsuitable: %d' % medium_candidates) print('Candidates who are more than 90%% unsuitable: %d' % tenpc_candidates) #output from excel: correct = [1,3,5,9,10,2,4,8,6,7] #this function tests output above against Excel: #test(correct,check) topMatrix = topFive(names,totalMatrix) #print(topMatrix) np.savetxt('/Users/java_jonathan/test.csv',topMatrix, fmt='%s', delimiter=',', newline='\n', header='', footer='', comments='# ') np.savetxt('/Users/java_jonathan/test2.csv',totalMatrix, fmt='%s', delimiter=',', newline='\n', header='', footer='', comments='# ') end = timer() print(end-start) """ #posting = [Posting(*postingsAll)] #print(posting[0].anchor) #print(posting) #print(candidatesAll) #print(postingsAll) #print(postingsAll[0].name) #print(preferences) #print(postings) #split up files into relative blocks postCode = [lists[0] for lists in postings] postDept = [lists[1] for lists in postings] postAnchor = [lists[2] for lists in postings] postSkills = [lists[3:5] for lists in postings] postLocation = [lists[5] for lists in postings] postCompetencies = [lists[7:10] for lists in postings] postSecurity = [lists[10] for lists in postings] #with open('/Users/Jonathan/Google Drive/CPD/Python/candidates.csv','r') as f: #gives first column ie candidate a a=totalMatrix[:,[0]] #b = totalMatrix[:,[0]] #print(a) #converts 1D matrix to list for ease a = np.array(a).tolist() #print(a) #creates list called output containing rank of score output = [0] * len(a) for i, x in enumerate(sorted(range(len(a)), key=lambda y: a[y])): output[x] = i print(output) #creates tuples of rank, job and appends to list jobRank = [] # for rank, b in zip(output, postCode): # jobScore = (rank,b) # list(jobScore) # jobRank.append(jobScore) # print(jobRank) output = [0] * len(a) for i, x in enumerate(sorted(range(len(a)), key=lambda y: a[y])): output[x] = i print(output) # #print(a) # jobRank = sorted(jobRank, reverse=False) # print(jobRank) # print('For candidate a, the best position is %s') % (jobRank[0][1]) # print(candidate[0].skills) """
30.646067
88
0.698075
1
2.2024
[ -0.05170669034123421, 0.029043618589639664, -0.01178120169788599, -0.0013783526374027133, -0.05770949274301529, -0.008894996717572212, -0.026231123134493828, -0.04154552146792412, -0.049345675855875015, -0.0026493186596781015, -0.03379034623503685, 0.007305760867893696, 0.017317570745944977, -0.010013875551521778, -0.02691498026251793, 0.029139060527086258, 0.05687443166971207, 0.02569524385035038, -0.027325302362442017, 0.004495009779930115, -0.00691604521125555, 0.014473964460194111, -0.015533806756138802, -0.008624603040516376, 0.05382915586233139, 0.0001724579924484715, 0.028864506632089615, 0.02482043206691742, -0.030682025477290154, -0.03324073180556297, 0.010517163202166557, 0.03357550501823425, -0.06458615511655807, -0.013543505221605301, -0.013652543537318707, 0.018087588250637054, -0.0060251555405557156, -0.0685960054397583, 0.06277664750814438, 0.024123819544911385, -0.03358126059174538, 0.015179888345301151, -0.007401548326015472, -0.05629048869013786, 0.032756030559539795, 0.0012897454435005784, 0.011420945636928082, 0.041773721575737, -0.03456634655594826, -0.005075057037174702, -0.019344380125403404, 0.017594680190086365, 0.009145925752818584, -0.022078463807702065, 0.011358908377587795, -0.043286047875881195, 0.007614565081894398, 0.03913291543722153, -0.005250169895589352, 0.03053746372461319, -0.023646116256713867, 0.026112770661711693, -0.01399360690265894, 0.0003360037808306515, 0.00042839327943511307, 0.025681786239147186, 0.00339558906853199, -0.008534728549420834, -0.09025635570287704, -0.0073442901484668255, -0.012214683927595615, 0.015015993267297745, 0.010967889800667763, 0.08314643055200577, 0.05050073191523552, 0.010637718252837658, -0.008084475994110107, -0.029643017798662186, -0.03952788934111595, 0.032180145382881165, -0.04046069085597992, 0.09550980478525162, 0.012233602814376354, -0.01891559362411499, -0.010387303307652473, -0.0023479429073631763, 0.07094695419073105, -0.05409248173236847, 0.004823500290513039, -0.01611519791185856, -0.019144002348184586, 0.02027440071105957, -0.0552578866481781, -0.01874588429927826, -0.021213505417108536, -0.08155268430709839, -0.0242000762373209, 0.0005140324938111007, -0.028458939865231514, -0.043589863926172256, 0.030113497748970985, -0.007249588146805763, 0.03080282174050808, 0.015680106356739998, 0.03639702498912811, 0.01487008761614561, -0.02981061115860939, -0.0031970154959708452, 0.0015532098477706313, -0.008079128339886665, -0.06404029577970505, -0.017186054959893227, 0.06112571060657501, -0.015433830209076405, -0.005008762236684561, -0.013055620715022087, 0.011342192068696022, 0.03589334338903427, 0.01966460607945919, 0.04928102344274521, 0.04729681834578514, -0.02016596309840679, 0.0727543979883194, -0.01913383975625038, -0.018359117209911346, 0.07930182665586472, 0.01151912659406662, -0.017212992534041405, 0.016188647598028183, -0.020610466599464417, -0.03341050073504448, 0.022217612713575363, 0.004157846327871084, -0.011191333644092083, -0.009847304783761501, 0.0036907102912664413, -0.0019069985719397664, 0.004096334800124168, -0.06645377725362778, 0.05927567556500435, -0.012041670270264149, -0.024125905707478523, 0.031900860369205475, -0.02602033130824566, -0.0022431991528719664, 0.0021412279456853867, -0.004252065904438496, 0.010975069366395473, -0.01946697011590004, -0.005512214731425047, 0.02840881422162056, -0.0061815944500267506, 0.03258199617266655, 0.012723039835691452, -0.013272642157971859, 0.011402913369238377, -0.01671530492603779, -0.09097139537334442, -0.01434681098908186, 0.00687769241631031, -0.01989746280014515, 0.011702100746333599, 0.03175573796033859, -0.03197677060961723, 0.06470140069723129, -0.00783948041498661, -0.021067142486572266, 0.040677350014448166, 0.011046318337321281, 0.007660703733563423, 0.05915006250143051, 0.0308491550385952, -0.009074634872376919, -0.0060426220297813416, -0.0531420037150383, -0.017288239672780037, 0.03851912170648575, 0.006898055784404278, -0.014190927147865295, -0.02803015522658825, 0.020286818966269493, -0.029712215065956116, -0.004987154621630907, 0.016299959272146225, 0.028532465919852257, -0.04206532984972, -0.07937772572040558, -0.02235385775566101, 0.026511337608098984, -0.013947040773928165, -0.03640197589993477, -0.021975917741656303, -0.030106207355856895, 0.008507151156663895, 0.029954953119158745, 0.010415852069854736, 0.0029340393375605345, -0.009279160760343075, 0.009907819330692291, -0.03584381565451622, 0.03029324859380722, -0.011834530159831047, 0.008601870387792587, 0.057203684002161026, 0.0006697005592286587, -0.0013366545317694545, -0.5185345411300659, -0.0053877271711826324, -0.026683637872338295, -0.02987815998494625, 0.02855648659169674, 0.05205558240413666, -0.052026618272066116, -0.024428563192486763, -0.06512787938117981, 0.016768772155046463, -0.02193140983581543, 0.012764392420649529, -0.03196157142519951, 0.011581694707274437, 0.018746303394436836, 0.010607199743390083, -0.005915574263781309, -0.011705253273248672, -0.005677314475178719, 0.0010003226343542337, 0.03061704710125923, -0.04596548154950142, -0.018881862983107567, 0.028376325964927673, 0.039420779794454575, -0.0032311261165887117, 0.0009047013008967042, 0.015484165400266647, -0.05580795928835869, -0.025861740112304688, 0.0298896674066782, 0.027012590318918228, 0.030295319855213165, 0.011774158105254173, 0.010043722577393055, 0.059757739305496216, 0.005982875823974609, -0.028364159166812897, -0.01190214417874813, -0.0202007032930851, -0.012300558388233185, -0.01198206003755331, -0.05029653012752533, -0.05591485649347305, -0.03248574957251549, 0.021901879459619522, -0.08552917093038559, -0.058458734303712845, -0.014120999723672867, 0.009965665638446808, -0.02130008302628994, 0.054687611758708954, 0.011483075097203255, -0.009596776217222214, -0.05548666790127754, 0.06238267198204994, -0.07118149101734161, -0.019379962235689163, 0.00943030882626772, -0.016916310414671898, 0.021664399653673172, 0.005638832226395607, -0.007354501634836197, 0.014954156242311, -0.028760332614183426, 0.027475209906697273, 0.10576129704713821, -0.030441688373684883, -0.0153882447630167, 0.0557614304125309, -0.07726596295833588, 0.03943508118391037, -0.023969896137714386, 0.07260031998157501, 0.03692128509283066, -0.04988672211766243, -0.020424209535121918, -0.007418276742100716, -0.08862174302339554, -0.05364859104156494, 0.014693357981741428, -0.004480005241930485, -0.0198007021099329, -0.018969731405377388, -0.01583675667643547, -0.05967516824603081, 0.013356171548366547, -0.04070291295647621, -0.0047968789003789425, 0.016406847164034843, 0.028544604778289795, 0.04969906061887741, 0.05180877074599266, 0.005503834690898657, -0.007947500795125961, 0.036540668457746506, 0.041037749499082565, 0.07702548056840897, -0.0010953928576782346, 0.04920780658721924, -0.02919335477054119, 0.04114491492509842, -0.03044915944337845, 0.03786954656243324, -0.05256016179919243, -0.03434939682483673, -0.03805363178253174, -0.005172772333025932, 0.028798310086131096, -0.018205778673291206, 0.022586941719055176, -0.0048872181214392185, -0.048835646361112595, 0.032652802765369415, 0.019047481939196587, -0.06484866142272949, -0.013810724951326847, -0.03571323677897453, 0.021238744258880615, -0.008564061485230923, 0.0035576780792325735, 0.03501749038696289, -0.02172083780169487, 0.019720057025551796, 0.0009576723678037524, 0.05950827896595001, -0.03730989620089531, 0.014291953295469284, -0.01545372512191534, 0.03647676482796669, -0.03694753721356392, -0.042987484484910965, 0.0026173617225140333, 0.0062682474963366985, -0.04225518926978111, -0.0143564622849226, -0.036114174872636795, 0.000265544920694083, -0.013195987790822983, -0.012328819371759892, 0.008507728576660156, -0.014181394129991531, 0.002427566098049283, -0.05623352900147438, 0.02954050898551941, -0.029510948807001114, 0.032975513488054276, -0.03710409253835678, 0.03508395701646805, -0.01981133595108986, 0.018598878756165504, 0.04985647648572922, 0.014232364483177662, 0.013680611737072468, -0.044737957417964935, -0.01481819897890091, -0.005852170754224062, 0.011937796138226986, 0.059283554553985596, 0.019550390541553497, -0.047073572874069214, -0.01792571134865284, -0.005345857702195644, 0.002258358057588339, -0.027173366397619247, -0.014781799167394638, 0.0006260322406888008, 0.031083691865205765, 0.03296138346195221, 0.0008575504180043936, 0.027587387710809708, -0.0323026068508625, -0.01147373951971531, -0.01021657045930624, 0.0030356855131685734, 0.00012768023589160293, -0.011238944716751575, -0.03884376958012581, 0.006204203702509403, 0.0058310190215706825, -0.030228829011321068, 0.030320478603243828, -0.006667331326752901, -0.024707524105906487, -0.01190610695630312, 0.02765788324177265, 0.005257728975266218, 0.023259872570633888, 0.019813062623143196, -0.03036068193614483, 0.0014348635450005531, 0.027640001848340034, -0.016571909189224243, -0.036469798535108566, -0.013860657811164856, -0.041028499603271484, 0.07859881222248077, 0.002511108759790659, -0.0036136345006525517, -0.022027738392353058, -0.018749922513961792, 0.007004210725426674, -0.013798288069665432, 0.019847042858600616, 0.005891153123229742, -0.041993096470832825, 0.004569293465465307, -0.010195158421993256, 0.004502991214394569, -0.05431792885065079, 0.004391140304505825, -0.010947998613119125, 0.025058533996343613, 0.024292416870594025, -0.011329736560583115, 0.05940417945384979, -0.009932825341820717, -0.0712970495223999, 0.03021134063601494, -0.0092023815959692, 0.007053482811897993, -0.015454691834747791, 0.007245784159749746, -0.006915966514497995, -0.01078448910266161, -0.00847241748124361, -0.012772418558597565, 0.016362715512514114, -0.03328181058168411, -0.005284629762172699, 0.011443265713751316, 0.006385854445397854, -0.005749032832682133, -0.0020607616752386093, -0.01357015036046505, 0.02896299958229065, 0.008226735517382622, -0.04787079989910126, 0.009421419352293015, -0.009465288370847702, 0.005792851094156504, -0.03889826685190201, -0.014761810190975666, 0.05371471866965294, -0.012754623778164387, -0.024118632078170776, 0.032147884368896484, -0.029669858515262604, -0.04981299862265587, -0.002798059256747365, -0.016563983634114265, 0.012799347750842571, 0.05501702055335045, 0.009045394137501717, -0.009490021504461765, -0.017337113618850708, -0.03243604302406311, 0.013980287127196789, 0.009574932977557182, 0.014255593530833721, -0.027365274727344513, -0.04299740120768547, -0.0050879959017038345, 0.02940947748720646, -0.07837388664484024, -0.008454333059489727, -0.008875285275280476, -0.022837402299046516, -0.024060940369963646, 0.03283516690135002, -0.00032527465373277664, 0.011754227802157402, 0.016731569543480873, -0.0032818273175507784, -0.009497501887381077, 0.0065904236398637295, -0.04060535505414009, -0.014727132394909859, 0.034700728952884674, 0.01861817017197609, -0.037128470838069916, -0.006425377447158098, 0.05025037005543709, 0.05017856881022453, -0.01143315527588129, 0.009417847730219364, 0.020390022546052933, -0.00010274599480908364, -0.020037952810525894, 0.0057610999792814255, 0.047829605638980865, -0.054295752197504044, 0.06441833823919296, 0.022320816293358803, 0.00618502264842391, -0.02743372693657875, -0.009986200369894505, 0.02608500048518181, 0.022374838590621948, 0.016308728605508804, 0.04358351603150368, -0.010932112112641335, -0.01778833009302616, 0.006303638685494661, 0.012107466347515583, -0.00181995437014848, 0.018030250445008278, -0.03934581205248833, 0.05528486520051956, 0.036414746195077896, 0.008211690001189709, 0.023104310035705566, -0.020876677706837654, -0.017257696017622948, -0.004511671140789986, 0.004718813579529524, 0.0778534933924675, 0.015409201383590698, 0.014559546485543251, 0.029781250283122063, -0.02977127768099308, 0.049708858132362366, -0.007202045526355505, -0.01890610344707966, -0.0009073521359823644, -0.044942811131477356, -0.051851868629455566, -0.01856986992061138, -0.03485437110066414, 0.003277826588600874, -0.01970922015607357, -0.010881293565034866, 0.04165273532271385, 0.0003366771852597594, -0.029264049604535103, 0.0339018814265728, 0.021849995478987694, 0.06421548128128052, 0.026035618036985397, -0.03206745535135269, -0.012760822661221027, 0.034609537571668625, -0.020064251497387886, 0.0050489045679569244, 0.013318837620317936, 0.0017313327407464385, 0.05827372521162033, 0.036210913211107254, 0.020661506801843643, 0.0458545908331871, -0.03618494048714638, -0.02945021353662014, -0.013228881172835827, 0.0009842494037002325, 0.03189964219927788, -0.021425390616059303, 0.008001390844583511, 0.04769037663936615, 0.01703670807182789, -0.015471098013222218, -0.005664362106472254, -0.0006164857768453658, 0.00677493354305625, -0.03833320364356041, -0.013691536150872707, -0.021582860499620438, 0.03501101955771446, -0.01828491874039173, -0.028143716976046562, 0.052307888865470886, 0.01742086559534073, -0.026073038578033447, 0.01987444795668125, -0.01192501001060009, 0.009487179107964039, 0.020308779552578926, 0.0069753690622746944, 0.00029978432576172054, 0.021004661917686462, -0.03263351321220398, -0.007080798037350178, -0.028345540165901184, 0.03313952311873436, 0.0065306369215250015, 0.04598101228475571, -0.052648913115262985, 0.022566722705960274, 0.028059937059879303, -0.011205272749066353, -0.022881677374243736, 0.02227015420794487, 0.054791759699583054, 0.05100050941109657, 0.03288622945547104, 0.01270037516951561, 0.023807287216186523, 0.0031430686358362436, -0.00907996017485857, -0.013668673112988472, -0.025791073217988014, -0.03823255002498627, 0.012756665237247944, -0.04817342385649681, 0.010055627673864365, 0.05490940809249878, -0.04949471727013588, 0.02407764457166195, 0.007552464958280325, -0.004926688503473997, -0.011204621754586697, 0.0156644806265831, 0.06491667032241821, -0.07671689987182617, -0.0027424884028732777, 0.04243874177336693, 0.05475218966603279, -0.01867849752306938, -0.04017620533704758, 0.009846496395766735, 0.025694752112030983, -0.008701648563146591, 0.0334467776119709, -0.016579644754529, -0.011942299082875252, -0.014317329972982407, -0.04622797295451164, 0.04472890496253967, -0.027752941474318504, 0.0023953102063387632, 0.009682548232376575, -0.013252312317490578, -0.010108458809554577, -0.04041803255677223, 0.00028125656535848975, 0.0019340752623975277, -0.02112034149467945, 0.013328406028449535, 0.026661807671189308, -0.012299737893044949, -0.025574490427970886, -0.02912314422428608, -0.015911469236016273, 0.011344623751938343, 0.036493219435214996, 0.02865694649517536, -0.029582619667053223, 0.02941136062145233, -0.03259504586458206, -0.007762874010950327, 0.01764160394668579, 0.007337215356528759, 0.01709767058491707, 0.022591203451156616, 0.028807012364268303, 0.021819261834025383, 0.0014751029666513205, 0.005353335756808519, 0.009926951490342617, 0.02853829227387905, 0.009042136371135712, 0.021534286439418793, 0.05205370858311653, -0.03404923155903816, 0.006045234389603138, 0.0070449733175337315, 0.04686138778924942, 0.005439211148768663, -0.04069555550813675, 0.019915509968996048, 0.054304610937833786, -0.007578209042549133, -0.013106940314173698, -0.002640009159222245, -0.006725755520164967, -0.01079629734158516, -0.014515805058181286, 0.0006253771134652197, 0.03534132242202759, 0.009003713726997375, 0.05253996700048447, -0.033938612788915634, 0.05513792484998703, -0.018254267051815987, 0.045046135783195496, 0.03380152955651283, 0.03347136825323105, -0.0011531313648447394, 0.019426757469773293, 0.0011938457610085607, -0.0023281744215637445, -0.07367391139268875, -0.004361102823168039, 0.002726775361225009, 0.05706160143017769, -0.0065369815565645695, -0.07327323406934738, 0.046650394797325134, -0.014965444803237915, 0.016287675127387047, -0.0010029164841398597, -0.03400468826293945, -0.0580931082367897, 0.012164666317403316, -0.02337493747472763, 0.013073520734906197, 0.007747299503535032, 0.018322674557566643, 0.037420306354761124, -0.027724500745534897, -0.008820438757538795, -0.018654437735676765, -0.04189077392220497, -0.036125291138887405, -0.036140624433755875, 0.02234896831214428, 0.04346297308802605, -0.01893312856554985, -0.02282770723104477, -0.019033003598451614, -0.011324616149067879, -0.010229535400867462, 0.030865030363202095, -0.0019286334281787276, -0.014261147007346153, 0.011495540849864483, -0.01564425602555275, 0.009389345534145832, -0.043743763118982315, 0.02027803845703602, 0.024851122871041298, 0.005239855032414198, 0.038928527384996414, -0.007707243785262108, -0.02083009108901024, 0.035580992698669434, -0.029884442687034607, 0.005318605341017246, 0.07473845034837723, -0.03727356716990471, -0.01525921281427145, 0.050677523016929626, -0.0075093479827046394, -0.02769753709435463, -0.04189758002758026, -0.021044468507170677, -0.005901005584746599, 0.0034462325274944305, -0.03256283700466156, 0.04884476959705353, -0.016732504591345787, 0.01654571294784546, 0.007060691714286804, 0.0015335575444623828, 0.006905457936227322, -0.030086051672697067, -0.04096796363592148, 0.009741310030221939, 0.04129602015018463, 0.013905249536037445, -0.047629304230213165, -0.016451941803097725, 0.012402582913637161 ]
8ac00891cba917dcea99bd7701a43788bba03334
3,142
py
Python
pip_info/setup.py
95616ARG/SyReNN
19abf589e84ee67317134573054c648bb25c244d
[ "MIT" ]
36
2019-08-19T06:17:52.000Z
2022-03-11T09:02:40.000Z
pip_info/setup.py
95616ARG/SyReNN
19abf589e84ee67317134573054c648bb25c244d
[ "MIT" ]
8
2020-04-09T20:59:04.000Z
2022-03-11T23:56:50.000Z
pip_info/setup.py
95616ARG/SyReNN
19abf589e84ee67317134573054c648bb25c244d
[ "MIT" ]
4
2021-01-13T11:17:55.000Z
2021-06-28T19:36:04.000Z
"""Setup script for PySyReNN. Adapted from: https://hynek.me/articles/sharing-your-labor-of-love-pypi-quick-and-dirty/ """ import codecs import os import re from setuptools import setup, find_packages ################################################################### NAME = "pysyrenn" PACKAGES = [ "syrenn_proto", "pysyrenn", "pysyrenn.frontend", "pysyrenn.helpers", ] META_PATH = "__metadata__.py" KEYWORDS = ["class", "attribute", "boilerplate"] CLASSIFIERS = [ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "Natural Language :: English", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy", "Topic :: Software Development :: Libraries :: Python Modules", ] INSTALL_REQUIRES = ["torch"] with open("requirements.txt") as requirements: reading = False for line in requirements.readlines(): if line.startswith("# PYSYRENN"): reading = True elif line.startswith("# END"): reading = False elif line.startswith("#"): pass elif reading: INSTALL_REQUIRES.append(line.strip().split("==")[0]) ################################################################### HERE = os.path.abspath(os.path.dirname(__file__)) def read(*parts): """ Build an absolute path from *parts* and and return the contents of the resulting file. Assume UTF-8 encoding. """ with codecs.open(os.path.join(HERE, *parts), "rb", "utf-8") as f: return f.read() META_FILE = read(META_PATH) def find_meta(meta): """Extract __*meta*__ from META_FILE. """ meta_match = re.search( r"^__{meta}__ = ['\"]([^'\"]*)['\"]".format(meta=meta), META_FILE, re.M ) if meta_match: return meta_match.group(1) raise RuntimeError("Unable to find __{meta}__ string.".format(meta=meta)) if __name__ == "__main__": setup( name=NAME, description=find_meta("description"), license=find_meta("license"), url=find_meta("uri"), version=find_meta("version"), author=find_meta("author"), author_email=find_meta("email"), maintainer=find_meta("author"), maintainer_email=find_meta("email"), keywords=KEYWORDS, long_description=read("README.md"), long_description_content_type="text/markdown", packages=PACKAGES, package_dir={"": "."}, package_data={"": ["pysyrenn/**/*.py"]}, zip_safe=False, classifiers=CLASSIFIERS, install_requires=INSTALL_REQUIRES, )
30.803922
77
0.595799
0
0
[ 0.00015701373922638595, 0.022949347272515297, 0.008076801896095276, 0.0009489326039329171, 0.0037231873720884323, -0.0019692666828632355, -0.009211983531713486, 0.003199157537892461, -0.008128054440021515, 0.0023710757959634066, 0.0019909837283194065, 0.006945128086954355, 0.00634814752265811, -0.01739794760942459, 0.0016966452822089195, 0.016530368477106094, -0.050686780363321304, 0.0004418562166392803, -0.0038639733102172613, 0.002330971183255315, -0.007486280985176563, 0.010150977410376072, 0.008998360484838486, 0.00765789533033967, 0.0061576091684401035, 0.00013892124115955085, 0.008014533668756485, 0.002270923927426338, -0.008215949870646, -0.007418916095048189, -0.0019123097881674767, -0.002335302997380495, -0.006150776986032724, -0.009174943901598454, 0.006479389034211636, -0.0015488355420529842, -0.0006374091026373208, -0.019200263544917107, 0.010771152563393116, -0.004153125919401646, -0.00751958042383194, -0.015816975384950638, -0.0002455715148244053, 0.004244687035679817, -0.009059978649020195, 0.0021099469158798456, -0.0034953884314745665, 0.0039021847769618034, -0.009918889962136745, 0.007455413695424795, -0.008824762888252735, 0.007704169489443302, 0.012673473916947842, 0.004304968286305666, -0.006613689940422773, -0.005640288349241018, 0.01303599402308464, 0.0004253097577020526, -0.009741507470607758, 0.0011823618551716208, -0.003789850976318121, -0.0019382161553949118, 0.004732668399810791, 0.004549626726657152, -0.01693381555378437, -0.008120696060359478, -0.003424431663006544, 0.002637245459482074, -0.00089601322542876, 0.004930504132062197, 0.00008943142165662721, -0.0006394443917088211, 0.007567299529910088, 0.0037829666398465633, 0.005463642533868551, -0.003259411547333002, -0.0010586087591946125, -0.0003783742431551218, 0.00909644365310669, 0.004468499217182398, 0.0042022159323096275, -0.00534701906144619, 0.005185184068977833, 0.00951867364346981, 0.014186139218509197, 0.006715615279972553, 0.019588366150856018, -0.010992900468409061, 0.047335635870695114, 0.006608198396861553, -0.00934287067502737, -0.0004997578798793256, -0.007236282341182232, -0.0014382916269823909, -0.005394323263317347, -0.026714062318205833, 0.0007156942738220096, -0.0035846084356307983, -0.00004947269189869985, 0.003640273120254278, -0.00044591075857169926, 0.006395557429641485, -0.002801300259307027, -0.0029163395520299673, -0.01121576875448227, 0.01130802370607853, -0.007628295570611954, -0.0022055332083255053, 0.006454151123762131, 0.0024650783743709326, -0.010081212036311626, -0.002190333092585206, 0.00022820026788394898, -0.012313838116824627, 0.0033020267728716135, 0.004037279635667801, -0.006054685916751623, 0.053269244730472565, -0.0015303227119147778, 0.0024526710622012615, -0.004685145802795887, 0.0024345889687538147, 0.0013401646865531802, 0.005641513504087925, 0.008219826966524124, -0.002844548085704446, 0.01152458693832159, 0.006833873223513365, 0.002881452674046159, 0.009349425323307514, -0.0010914310114458203, 0.005054275970906019, -0.006046336609870195, -0.002184557495638728, 0.0001298050192417577, -0.008393079973757267, 0.00877252034842968, -0.0004594326892402023, -0.007836530916392803, 0.0006026407354511321, -0.000004485635145101696, -0.009651311673223972, 0.0022732396610081196, -0.004830498713999987, 0.0026794199366122484, -0.010625671595335007, -0.0037493128329515457, -0.002656367374584079, -0.0036666342057287693, 0.0024353559128940105, 0.008255657739937305, 0.0040666814893484116, 0.0036408898886293173, -0.006432381924241781, -0.008856779895722866, -0.0015214988961815834, -0.0033756408374756575, 0.002088573295623064, 0.006010383367538452, 0.003840589663013816, -0.009827212430536747, -0.0018136500148102641, 0.00423071812838316, 0.00487024849280715, -0.0007725705509074032, 0.004164908546954393, -0.008867798373103142, 0.007725049275904894, 0.00037701998371630907, 0.00353746535256505, 0.010045324452221394, -0.004754793364554644, 0.000005597351901087677, 0.0015910952351987362, 0.0035511234309524298, 0.00010765925981104374, 0.006275961175560951, 0.010928925126791, -0.0038371807895600796, -0.004761002026498318, 0.0024544657208025455, 0.004421086981892586, 0.008339885622262955, 0.0075514488853514194, -0.003484532702714205, 0.0031231248285621405, -0.004247008357197046, -0.001729869400151074, 0.0057209855876863, -0.00490434467792511, 0.005335404071956873, 0.004805844277143478, -0.013628387823700905, -0.0077967108227312565, 0.0008400578517466784, -0.009731394238770008, 0.0015838795807212591, 0.013290383853018284, 0.011662594974040985, -0.0024664008524268866, 0.0033538639545440674, -0.010805885307490826, 0.0012436346150934696, 0.00700188847258687, 0.0007528239511884749, -0.0125197758898139, -0.9592100977897644, 0.006056699436157942, 0.0036563926842063665, -0.001692368183284998, 0.004971791058778763, 0.002260686829686165, 0.0024072977248579264, 0.005273576360195875, 0.013282832689583302, -0.007798387203365564, -0.006228483747690916, -0.008930960670113564, -0.01016155630350113, -0.0017213140381500125, -0.007662214804440737, -0.002222473034635186, -0.006979185156524181, -0.007574582472443581, -0.0010707882465794683, -0.0036075583193451166, -0.0023666894994676113, 0.009304783307015896, -0.0015536797000095248, 0.00597182335332036, 0.0025905293878167868, 0.003032389795407653, -0.00440784590318799, -0.0004291028599254787, -0.002303093671798706, -0.003406552830711007, -0.007969326339662075, -0.015776271000504494, -0.00403221370652318, -0.0017982013523578644, 0.009002231061458588, 0.0007459639455191791, 0.00869879499077797, -0.00026140789850614965, 0.001443384331651032, -0.006077030207961798, 0.004770207218825817, -0.000001849362547545752, 0.003104635514318943, -0.030556773766875267, -0.00039959666901268065, -0.0008526135352440178, -0.008803622797131538, 0.0082434993237257, 0.001010238891467452, -0.0008965625893324614, -0.0019714899826794863, -0.006962345447391272, 0.009546682238578796, -0.007100842427462339, 0.005944049917161465, -0.002569687319919467, -0.006895697209984064, -0.0015779210953041911, -0.008487891405820847, 0.0010597188957035542, 0.004428153857588768, -0.003928501624614, -0.003511135233566165, -0.004413915798068047, 0.0017983991419896483, 0.0025773535016924143, 0.002262656344100833, -0.018630536273121834, -0.006903455592691898, -0.0010289490455761552, 0.0019417870789766312, -0.0043036662973463535, -0.0030748341232538223, 0.006426747422665358, -0.010176161304116249, 0.007247942965477705, 0.004168184008449316, -0.001149880699813366, -0.011196443811058998, -0.0001886194513645023, -0.007905055768787861, -0.00748759089037776, 0.0012837746180593967, -0.005549008492380381, -0.004991498310118914, -0.0009507933282293379, 0.00035526181454770267, 0.0062663923017680645, -0.0033898877445608377, 0.0049661207012832165, 0.011246327310800552, -0.004921787418425083, -0.008422773331403732, 0.005938816349953413, 0.005949176847934723, 0.0014727109810337424, -0.00244799698702991, 0.00145571562461555, 0.008566453121602535, 0.007696699816733599, 0.004331610165536404, 0.006090029142796993, 0.0008486817241646349, 0.008057547733187675, 0.0004124078550375998, 0.0010540424846112728, -0.004359448328614235, -0.0011139909038320184, -0.0033798932563513517, 0.001674725441262126, -0.0026473477482795715, -0.0035012676380574703, -0.012581652030348778, -0.009491048753261566, -0.0033865594305098057, 0.00008933965727919713, 0.0018049097852781415, -0.0027723442763090134, -0.0006022442248649895, 0.002663132967427373, 0.00897298101335764, -0.0006627934635616839, -0.0027930818032473326, 0.0006459924625232816, 0.003935865126550198, -0.006879305467009544, 0.013998995535075665, -0.01047288253903389, 0.005949188489466906, -0.000004764863206219161, -0.01572638563811779, 0.007718896958976984, 0.009136702865362167, -0.008570034056901932, 0.0014127515023574233, 0.00357830454595387, 0.0021176428999751806, -0.0009214366436935961, -0.0041410126723349094, -0.002470453269779682, -0.015646643936634064, 0.000610655639320612, 0.01975931040942669, 0.0013823065673932433, 0.009725309908390045, 0.012278127484023571, -0.002463169163092971, 0.0009696755441837013, 0.006166733801364899, 0.00048049454926513135, 0.012718716636300087, -0.00807119905948639, -0.00032986493897624314, 0.0014082830166444182, -0.0063185240142047405, 0.0007126214914023876, 0.007103743962943554, 0.005070211365818977, -0.0029059192165732384, 0.0021251854486763477, -0.006895150523632765, -0.005560942459851503, -0.016880961135029793, -0.003827436827123165, 0.007645026780664921, -0.0046369354240596294, 0.006170229986310005, -0.010287079960107803, 0.005228105001151562, 0.007040149066597223, 0.003920285031199455, -0.0009474976104684174, 0.0007198622915893793, 0.006857804022729397, 0.01096753217279911, -0.005495760124176741, 0.0018021173309534788, 0.002405868610367179, -0.0005725452210754156, 0.00021894719975534827, 0.005167008843272924, -0.006895693019032478, -0.004756261594593525, 0.0028421671595424414, 0.004191613290458918, 0.0005230677197687328, -0.0040986742824316025, -0.008149509318172932, -0.0024319866206496954, 0.003280879696831107, -0.006767268758267164, 0.00434574019163847, 0.0012868561316281557, 0.0035612022038549185, -0.006767700891941786, 0.000068171568273101, -0.0026264621410518885, -0.011498507112264633, 0.010405957698822021, -0.0024896797258406878, 0.0017371177673339844, 0.011492636986076832, 0.00433473102748394, -0.014234392903745174, 0.006001041270792484, 0.009036838077008724, -0.004827480297535658, 0.004300616215914488, 0.00600045919418335, -0.004951195325702429, -0.022075682878494263, -0.002853061305359006, -0.013340523466467857, 0.00632448447868228, -0.001148862298578024, 0.0032103697303682566, -0.007593621499836445, 0.006640680134296417, 0.007566364947706461, -0.01367480680346489, -0.0042563555762171745, -0.008748902007937431, 0.009119837544858456, -0.0008134967065416276, -0.0002589740324765444, -0.002893485128879547, -0.0017825515242293477, -0.0022282626014202833, -0.0028766165487468243, -0.0019013449782505631, 0.005484192166477442, 0.0014398581115528941, -0.004004928283393383, 0.0017868897411972284, -0.003407838521525264, -0.00038208221667446196, 0.00021502979507204145, -0.009785470552742481, 0.002091724891215563, 0.003897877875715494, -0.002254432998597622, -0.0038025188259780407, 0.0012097606668248773, -0.00037669812445528805, -0.0055265240371227264, -0.011081320233643055, -0.0054365284740924835, -0.0031050683464854956, -0.002298393053933978, -0.01260977704077959, -0.0019075615564361215, -0.011025415733456612, 0.005042966455221176, -0.006657494697719812, 0.008174024522304535, 0.003746275557205081, -0.0050802081823349, 0.006562740541994572, -0.0014314830768853426, 0.0043449499644339085, 0.0033929008059203625, 0.007289814297109842, 0.0005098167457617819, -0.005184215493500233, -0.011114212684333324, 0.012520892545580864, -0.008251724764704704, 0.0018064219038933516, 0.013626149855554104, 0.004784759599715471, 0.009359114803373814, -0.0003394953382667154, 0.0009254407486878335, 0.004625833127647638, 0.007736786734312773, -0.012621726840734482, 0.003206724999472499, -0.003994266502559185, 0.00029824767261743546, 0.005045402329415083, -0.0037948312237858772, 0.002576136728748679, 0.008776250295341015, 0.002297432627528906, -0.006969671696424484, -0.002016723621636629, 0.001707724411971867, 0.0037070135585963726, -0.01189211942255497, 0.0013357913121581078, -0.0025124549865722656, -0.005069811828434467, -0.002795903943479061, -0.004048067145049572, -0.0005346185062080622, 0.004533207044005394, -0.0028926969971507788, 0.006488821003586054, 0.0024892340879887342, -0.006207979749888182, 0.014747418463230133, -0.00639180326834321, -0.006584714632481337, 0.003148208372294903, 0.002918203826993704, -0.0030546989291906357, -0.005989101715385914, -0.004282410256564617, 0.003094480838626623, 0.005380034912377596, -0.00213224277831614, -0.0032546280417591333, -0.0007419030298478901, 0.0009825349552556872, -0.008799092844128609, 0.00043816916877403855, 0.012730222195386887, -0.0027955700643360615, 0.006013759411871433, -0.0016324560856446624, -0.0062218038365244865, -0.01276439893990755, 0.05183056741952896, -0.0006133568822406232, 0.004633892327547073, 0.003965422511100769, -0.007623340468853712, -0.001306938473135233, -0.0025765520986169577, 0.007440453860908747, -0.007369231432676315, -0.008057325147092342, 0.009031402878463268, -0.002608749782666564, 0.004624503664672375, 0.001595820183865726, -0.0027594584971666336, 0.015123682096600533, -0.004405689425766468, -0.016226591542363167, -0.015880325809121132, 0.007861812599003315, -0.0037517838645726442, -0.007643940392881632, 0.009568155743181705, -0.0034043763298541307, -0.00401875376701355, 0.0025589196011424065, 0.005468319170176983, 0.0005659072194248438, 0.00016593211330473423, -0.0036423688288778067, -0.0023809922859072685, 0.00006418271368602291, 0.0025705532170832157, 0.006633833050727844, 0.0070706638507544994, -0.0041921380907297134, 0.004116583149880171, -0.001037317211739719, -0.0013197159860283136, -0.0013147009303793311, 0.004103819839656353, 0.007392025087028742, -0.0018819337710738182, -0.00227687181904912, 0.006641318090260029, 0.003919769544154406, 0.0022117740008980036, 0.00940735824406147, -0.0016256009694188833, -0.0034708769526332617, 0.008280341513454914, 0.00691284378990531, -0.0012947526993229985, 0.007093831896781921, -0.00260545895434916, 0.005265221931040287, 0.003040687181055546, -0.006758300121873617, -0.01818917877972126, -0.004279477521777153, 0.0055974991992115974, 0.007812941446900368, -0.0008924566791392863, 0.00017492550250608474, -0.0021643037907779217, -0.0026256300043314695, -0.006395408418029547, -0.007684162352234125, -0.00404721312224865, 0.0006872391677461565, 0.003117344342172146, 0.07137635350227356, -0.004044713452458382, -0.0012988463276997209, -0.007555036339908838, -0.001879644813016057, -0.0033306300174444914, -0.001997722778469324, 0.00010862849740078673, -0.003812001086771488, 0.0018325099954381585, 0.00032544168061576784, -0.006213725544512272, -0.010878298431634903, -0.00018796381482388824, 0.0007119659567251801, -0.002507634460926056, 0.004277127329260111, 0.006413626950234175, -0.010667185299098492, 0.0009237851481884718, -0.010519548319280148, -0.0019671032205224037, -0.0029165714513510466, -0.009448856115341187, -0.002852092729881406, -0.002908464288339019, 0.005589732900261879, 0.0025769476778805256, 0.006891192868351936, -0.0013834561686962843, 0.0051810783334076405, -0.00212795939296484, -0.00014364624803420156, -0.005245693027973175, -0.0010035954182967544, -0.0060373106971383095, 0.008442004211246967, 0.0012166494270786643, -0.010285139083862305, -0.004967652726918459, -0.0025364207103848457, -0.00021515895787160844, -0.00443310895934701, 0.0038391004782170057, -0.00009385994781041518, 0.005667144898325205, -0.0025546210817992687, -0.0005729706608690321, -0.007321873679757118, 0.0023652510717511177, -0.012285284698009491, 0.004149918910115957, -0.1739826500415802, 0.011417204514145851, 0.0036626080982387066, -0.0042111934162676334, -0.004145612474530935, -0.014065739698708057, -0.008294140920042992, 0.0036052060313522816, 0.011129633523523808, 0.0007695650565437973, -0.0016724222805351019, -0.001356080756522715, 0.004270784091204405, 0.004683159291744232, 0.0006357326055876911, -0.005319676361978054, 0.0022117167245596647, -0.004324421752244234, 0.0014135142555460334, 0.0021140973549336195, 0.004096010699868202, 0.009828495793044567, 0.0017504598945379257, 0.0020891178864985704, -0.00038800883339717984, -0.004896180238574743, 0.006245834287256002, -0.0026353683788329363, 0.006148591637611389, -0.010547053068876266, -0.0012758844532072544, -0.003681219182908535, -0.003952044062316418, 0.0003777657402679324, 0.0036058002151548862, -0.0007810923852957785, 0.007434203755110502, 0.002195810666307807, -0.008395589888095856, 0.00811536144465208, -0.009453285485506058, 0.0269345473498106, 0.0037585219833999872, 0.007597495801746845, 0.00035037059569731355, -0.005670957267284393, -0.004578949883580208, 0.009304548613727093, 0.0018027352634817362, 0.013880055397748947, -0.014209079556167126, -0.002894113538786769, 0.0027765040285885334, 0.017970314249396324, -0.0057226065546274185, -0.009680747985839844, -0.007444965187460184, -0.003233515890315175, 0.0035237744450569153, 0.0073640672490000725, 0.010486794635653496, -0.0031194931361824274, 0.010078547522425652, -0.004371841438114643, -0.020185668021440506, 0.0036018481478095055, -0.004813835024833679, -0.007545349188148975, 0.002584530506283045, 0.007459642365574837, 0.01012409944087267, 0.00025863529299385846, 0.002719341544434428, -0.0025380146689713, 0.006226866506040096, -0.0002279922628076747, 0.006834081839770079, -0.0031950753182172775, 0.004298726562410593, -0.010077507235109806, 0.008301392197608948, -0.008604645729064941, -0.0045532649382948875, 0.0015195570886135101, -0.00439754594117403, 0.010747263208031654, 0.003705688053742051, -0.002241658978164196, -0.0017527899472042918, -0.010734479874372482, -0.0025809137150645256, 0.0017158800037577748, 0.00293690781109035, -0.009374833665788174, 0.003580501303076744, -0.0012113102711737156, 0.005065977573394775, 0.006413309369236231, -0.008455179631710052, 0.005937289446592331, 0.003929615952074528, -0.003830079920589924, 0.00017400606884621084, -0.0042331647127866745, 0.0033651748672127724, 0.003149098949506879, -0.006703805178403854, -0.0052815210074186325, 0.004151745233684778, -0.0073308395221829414, -0.0061919414438307285, 0.006346501875668764, -0.009345090948045254, -0.00979557167738676, -0.00189587427303195, -0.011320329271256924, 0.00038154248613864183 ]
8ac046daf66291ca73b420ce81a183abc787e157
51
py
Python
neptune/generated/swagger_client/path_constants.py
jiji-online/neptune-cli
50cf680a80d141497f9331ab7cdaee49fcb90b0c
[ "Apache-2.0" ]
null
null
null
neptune/generated/swagger_client/path_constants.py
jiji-online/neptune-cli
50cf680a80d141497f9331ab7cdaee49fcb90b0c
[ "Apache-2.0" ]
null
null
null
neptune/generated/swagger_client/path_constants.py
jiji-online/neptune-cli
50cf680a80d141497f9331ab7cdaee49fcb90b0c
[ "Apache-2.0" ]
null
null
null
REST_PATH = u"" WS_PATH = u"/api/notifications/v1"
17
34
0.705882
1
0.6437
[ 0.0015621656784787774, 0.025659684091806412, 0.010629232972860336, 0.004359875340014696, 0.0024119592271745205, -0.003656930522993207, -0.010986323468387127, 0.005511148367077112, -0.0044625443406403065, -0.0017496699001640081, 0.0023015639744699, 0.0021089036017656326, 0.010075382888317108, -0.01422665175050497, 0.003301858203485608, 0.013050026260316372, -0.06246649846434593, -0.0017053666524589062, -0.003249771660193801, 0.0020730949472635984, -0.006459227297455072, 0.012427924200892448, 0.009915144182741642, 0.004289190284907818, 0.007532025221735239, 0.0037197216879576445, 0.005183136556297541, 0.007832014933228493, -0.011905251070857048, -0.004135484807193279, 0.0013809137744829059, -0.0020108765456825495, -0.002609053859487176, -0.005177260842174292, 0.007309974171221256, -0.001954730600118637, -0.0016897376626729965, -0.017525138333439827, 0.009747106581926346, -0.01007717102766037, -0.00975969061255455, -0.02274373173713684, -0.0030572034884244204, 0.008083160035312176, -0.013168107718229294, 0.0010242454009130597, 0.0004303365421947092, 0.0072603533044457436, -0.012996254488825798, 0.008076708763837814, -0.009959990158677101, 0.0022875547874718904, 0.014584710821509361, 0.001229519722983241, -0.003666159464046359, -0.006749264895915985, 0.010837588459253311, 0.000020982668502256274, -0.01617862656712532, -0.0035211117938160896, -0.002956327050924301, -0.003847461426630616, 0.005172451958060265, 0.006672665011137724, -0.02205086685717106, -0.0024908443447202444, -0.005490384064614773, -0.00009393638174515218, -0.007129708305001259, 0.00447726808488369, 0.0019111173460260034, 0.0003263971593696624, 0.008752133697271347, 0.0018973606638610363, 0.006825637072324753, -0.0003132739511784166, 0.00004563371840049513, 0.009096711874008179, 0.005197287071496248, -0.0010691997595131397, 0.006310096010565758, -0.012321777641773224, 0.008906777948141098, 0.014124392531812191, 0.01111837662756443, 0.01389183010905981, 0.015000231564044952, -0.011881954036653042, 0.03823356702923775, 0.005647256504744291, -0.009797091595828533, 0.003966978285461664, -0.007429860066622496, -0.004390853922814131, -0.0019462616182863712, -0.03457709774374962, -0.0022277373354882, -0.01001448929309845, -0.0014846983831375837, 0.004417317919433117, -0.002656682627275586, 0.0063101062551140785, -0.004330101888626814, -0.005377479828894138, -0.010350706987082958, 0.019225582480430603, -0.007780731655657291, -0.0033847324084490538, 0.0038512584287673235, 0.002998847747221589, -0.012794826179742813, -0.002375178039073944, 0.005214116536080837, -0.010602922178804874, 0.0029260730370879173, 0.0013736617984250188, -0.006660873536020517, 0.06132417917251587, -0.0010598009685054421, 0.005534903146326542, -0.0023321874905377626, -0.008520940318703651, 0.0000657989367027767, 0.009282431565225124, 0.009524810127913952, -0.008434433490037918, 0.011244616471230984, 0.0026080652605742216, -0.0006416264222934842, 0.007022147066891193, 0.0009241820662282407, 0.011562676168978214, -0.0038289506919682026, 0.0006192609434947371, -0.001084187999367714, -0.006929323542863131, 0.007516568526625633, 0.0004218632238917053, -0.003818150842562318, -0.0011451536556705832, -0.003770025447010994, -0.01194163877516985, 0.0028357901610434055, -0.0001809143286664039, -0.0031804353930056095, -0.018449459224939346, -0.006548864766955376, -0.001692052697762847, -0.007185862399637699, 0.0012123881606385112, 0.007446531672030687, 0.002625417895615101, 0.0009558958699926734, -0.00523140374571085, -0.004960167221724987, -0.0020104029681533575, -0.008592051453888416, 0.006312852259725332, 0.009541107341647148, 0.0027959977742284536, -0.0053693209774792194, -0.002797000342980027, 0.007349568884819746, 0.0020804116502404213, -0.00040512604755349457, -0.0006887289928272367, -0.004061507526785135, 0.009422380477190018, 0.00046910002129152417, 0.0016395506681874394, 0.013454528525471687, -0.0035138120874762535, -0.0009796100202947855, -0.0003890845400746912, -0.0018741056555882096, 0.0001942989620147273, 0.0059014661237597466, 0.008720524609088898, -0.006352961994707584, -0.003517602803185582, 0.005061168689280748, 0.0016469174297526479, 0.008987080305814743, 0.01249250490218401, -0.0014780373312532902, -0.001632525585591793, -0.0016619046218693256, -0.0037633809261024, 0.002467195503413677, -0.004271204583346844, 0.009062953293323517, 0.004948918242007494, -0.016870278865098953, -0.00162428745534271, -0.001313535263761878, -0.011696933768689632, -0.0012794745853170753, 0.014204500243067741, 0.009207306429743767, -0.000009455694453208707, 0.004877458792179823, -0.011185781098902225, 0.0037135055754333735, 0.006532545667141676, -0.002238993998616934, -0.011434799060225487, -0.9513588547706604, -0.0017275718273594975, 0.004029196221381426, -0.0021058223210275173, 0.0042999726720154285, -0.00013354994007386267, 0.002822787733748555, -0.0005646315403282642, 0.016078701242804527, -0.014517929404973984, -0.008784635923802853, -0.008869404904544353, -0.011810429394245148, 0.001145620597526431, -0.00945894606411457, -0.007383397314697504, -0.005198701750487089, -0.005478253588080406, 0.0012528556399047375, -0.005041934084147215, -0.0005290796398185194, 0.012055948376655579, 0.0037310014013201, 0.007171276491135359, 0.00322367693297565, 0.005052166525274515, -0.004711630288511515, -0.000242519992752932, 0.005170254036784172, -0.0014029769226908684, -0.0031587937846779823, -0.015780961140990257, -0.007424830924719572, -0.0019248297903686762, 0.01525840163230896, -0.0005314331501722336, 0.006267041899263859, -0.000037873371184105054, 0.0029069010633975267, -0.01167028583586216, 0.00713377445936203, 0.0032336795702576637, 0.001237634220160544, -0.02861412614583969, 0.005660085007548332, -0.0019666983280330896, -0.006191891618072987, 0.011511080898344517, -0.00023151852656155825, -0.00014804446254856884, 0.00037451754906214774, 0.001624228316359222, 0.011574238538742065, -0.007848571985960007, 0.0028511888813227415, -0.011095389723777771, -0.0018113184487447143, -0.0018616934539750218, -0.010615772567689419, 0.002374450908973813, 0.0033526469487696886, -0.002954693278297782, -0.0018174882279708982, -0.005840540863573551, 0.0011745700612664223, 0.0008075415971688926, -0.004733609035611153, -0.01834246888756752, -0.0036623356863856316, -0.003251480171456933, 0.008340799249708652, -0.0018849547486752272, 0.002294977894052863, -0.0008968057227320969, -0.01174576859921217, 0.005647243466228247, 0.0028421636670827866, 0.007001651916652918, -0.007793299853801727, 0.0034678915981203318, -0.0033838688395917416, -0.010078039020299911, 0.004685382358729839, -0.0051288120448589325, -0.0012297896901145577, 0.004381851758807898, 0.009682413190603256, 0.010097533464431763, -0.004542806651443243, -0.0013679993571713567, 0.010852571576833725, -0.00433728564530611, -0.006467404309660196, 0.007604632992297411, 0.006699383724480867, 0.00041826325468719006, 0.00017726505757309496, 0.005073158070445061, 0.0070090461522340775, 0.006921929307281971, 0.004050122108310461, 0.006806704215705395, 0.0014980793930590153, 0.01655041240155697, 0.0008252799161709845, 0.005444240290671587, 0.0017941828118637204, -0.0004404936626087874, -0.007346366997808218, 0.001689849654212594, -0.009098567999899387, -0.0014050707686692476, -0.014106986112892628, -0.015027268789708614, -0.0050491634756326675, 0.0014173465315252542, -0.0009511103271506727, -0.0015905903419479728, 0.002383892424404621, 0.0037364615127444267, 0.012757886201143265, 0.0026711628306657076, -0.00512325344607234, 0.0033013224601745605, 0.003541181329637766, -0.008790439926087856, 0.014401978813111782, -0.009185840375721455, 0.006858819629997015, -0.0013471461134031415, -0.016205493360757828, 0.012936719693243504, 0.008917128667235374, -0.004749789368361235, 0.0037776250392198563, 0.00217378418892622, 0.006295251660048962, 0.0051323892548680305, -0.0021719711367040873, -0.0069058556109666824, -0.013711507432162762, 0.0013326717307791114, 0.022861991077661514, 0.003913316875696182, 0.006882259622216225, 0.0088700782507658, -0.0014946873998269439, 0.002111596753820777, 0.011388659477233887, 0.0006592734134756029, 0.013769528828561306, -0.007821014150977135, -0.001570671214722097, 0.0018936297856271267, -0.004936014302074909, 0.002481920411810279, -0.00028459622990339994, 0.0065396809950470924, -0.0018909260397776961, 0.0005694349529221654, -0.001004973892122507, -0.004005900118499994, -0.014748232439160347, 0.0043454477563500404, 0.006599241402000189, -0.0006632630829699337, 0.001186609035357833, -0.01455810759216547, 0.0015291301533579826, 0.006223342381417751, 0.0030283648520708084, 0.0014437997015193105, 0.001514426083303988, 0.012080316431820393, 0.012685840018093586, -0.006387826520949602, 0.00554079283028841, -0.003216562792658806, 0.0015655915485695004, 0.006552047096192837, 0.004107990302145481, -0.010470153763890266, -0.006484062876552343, 0.0036033724900335073, 0.005560306366533041, -0.000012526390491984785, -0.0066454727202653885, -0.013673876412212849, -0.002351487521082163, 0.003174645360559225, -0.0017843276727944613, 0.006990908645093441, 0.0034521447960287333, 0.004828654229640961, -0.011451954022049904, 0.0013775537954643369, -0.005304359830915928, -0.010083644650876522, 0.011193659156560898, -0.002318760147318244, 0.004998266696929932, 0.01441490650177002, 0.0004897660110145807, -0.012981453910470009, 0.002241086447611451, 0.007124441675841808, -0.009447986260056496, 0.0033322691451758146, 0.005939886439591646, -0.005168466363102198, -0.025940973311662674, 0.0011621937155723572, -0.015235078521072865, 0.00907096080482006, -0.006230818573385477, 0.004846637137234211, -0.007934223860502243, 0.01017020270228386, 0.0009280303493142128, -0.011692153289914131, -0.0006667146226391196, -0.011337666772305965, 0.010577041655778885, -0.0022579398937523365, -0.0021018092520534992, -0.003277788870036602, -0.0014324699295684695, -0.005172383040189743, -0.0028338569682091475, 0.00300624524243176, 0.0022257205564528704, -0.0003782741550821811, -0.008066182024776936, 0.002512749284505844, -0.004397383891046047, -0.0011749939294531941, 0.005587250925600529, -0.01057432685047388, 0.0036462938878685236, 0.010818291455507278, -0.005514826159924269, -0.004616845864802599, -0.0010585288982838392, -0.0011222298489883542, -0.007759736385196447, -0.00894892867654562, 0.002189985476434231, -0.0029605727177113295, -0.004175542388111353, -0.0077082328498363495, -0.001736141974106431, -0.008216223679482937, 0.005585560109466314, -0.007426368072628975, 0.008206033147871494, 0.008198224939405918, -0.003981365822255611, 0.00807957723736763, -0.0023490169551223516, 0.002108767395839095, 0.0062995306216180325, 0.007613425608724356, -0.007405058480799198, -0.009416939690709114, -0.012489734217524529, 0.006968330591917038, -0.00779175478965044, -0.0035137212835252285, 0.013005315326154232, 0.003203632542863488, 0.008769559673964977, 0.0031633074395358562, -0.0002972852671518922, 0.0032259696163237095, 0.007267404347658157, -0.015860918909311295, -0.002064656699076295, 0.0019310247153043747, 0.0036741585936397314, 0.004593236371874809, -0.007472774479538202, 0.007454734295606613, 0.007652003318071365, -0.002625502645969391, -0.00802633073180914, -0.000012726873137580696, 0.0025618220679461956, 0.004606046713888645, -0.011369962245225906, 0.0006022118614055216, -0.00756794260814786, -0.0017133236397057772, -0.009953895583748817, -0.006908033508807421, -0.0018005192978307605, 0.011647751554846764, -0.004079832229763269, 0.005659675691276789, -0.0012787578161805868, -0.003498191013932228, 0.020400121808052063, -0.006637353915721178, -0.004871039185672998, 0.0015768958255648613, -0.001922782976180315, 0.0008293789578601718, -0.008451774716377258, -0.00009273219620808959, -0.000900179729796946, 0.005511500407010317, -0.0042788260616362095, -0.008605662733316422, -0.0016873632557690144, 0.0017344583757221699, -0.0056823003105819225, 0.0028195742052048445, 0.009484103880822659, 0.007091179024428129, 0.002618580125272274, -0.0016738764243200421, -0.003208217676728964, -0.018457725644111633, 0.05282262712717056, -0.0040527647361159325, 0.0009258813224732876, 0.007632597349584103, -0.007141907699406147, -0.005030764266848564, -0.0022477495949715376, 0.0053419750183820724, -0.005129477009177208, -0.006701035425066948, 0.008460238575935364, 0.0011357964249327779, 0.0027799117378890514, -0.004911032505333424, -0.0035134439822286367, 0.013195185922086239, -0.005944188218563795, -0.021015344187617302, -0.016485607251524925, 0.00861628819257021, -0.006164460442960262, -0.005681478884071112, 0.006900828797370195, -0.0037253571208566427, -0.0034750127233564854, 0.0017412923043593764, 0.006934994366019964, -0.003010357031598687, 0.001796778873540461, -0.00042667772504501045, -0.0016579830553382635, -0.0023100320249795914, 0.003351256949827075, 0.002203170442953706, 0.010112385265529156, -0.003437389386817813, 0.005025526974350214, -0.0040549831464886665, 0.0040994673036038876, -0.00002183387550758198, 0.0019675942603498697, 0.009347346611320972, 0.0001490508730057627, -0.00583508238196373, 0.0019362559542059898, 0.004946341272443533, -0.001620514434762299, 0.01431990321725607, 0.003778655081987381, -0.0017991634085774422, 0.010139293037354946, 0.008449015207588673, -0.002310935640707612, 0.003720676526427269, -0.006004839204251766, 0.004393119364976883, -0.00020397415210027248, -0.007017807569354773, -0.015001446008682251, 0.0010936412727460265, 0.0027244193479418755, 0.004519471433013678, -0.002597958780825138, 0.00017118938558269292, -0.0032062928657978773, -0.006969474721699953, -0.0071715484373271465, -0.0026810155250132084, -0.0020273735281080008, -0.0010784744517877698, 0.007030330132693052, 0.07153627276420593, -0.0021401618141680956, -0.002723109209910035, -0.007053126115351915, 0.0017667877255007625, -0.0025608220603317022, -0.0005936051602475345, -0.0021037186961621046, -0.0003375518717803061, -0.0017104820581153035, 0.010562165640294552, -0.008575773797929287, -0.009226835332810879, 0.0001807582302717492, -0.0035120954271405935, -0.0024261376820504665, 0.0035622618161141872, 0.007927178405225277, -0.0068293604999780655, 0.003061116673052311, -0.010940412990748882, -0.00411600898951292, -0.005041053518652916, -0.008115648292005062, -0.005240354686975479, -0.004651505500078201, -0.001000465010292828, 0.005588087718933821, 0.010226055048406124, -0.005996825639158487, 0.00739719532430172, 0.0012735719792544842, 0.004793496802449226, -0.0016860362375155091, -0.0022344316821545362, -0.006528775207698345, 0.006526397541165352, 0.0038130879402160645, -0.015149175189435482, -0.006426061503589153, -0.004637771751731634, -0.0047016991302371025, -0.00615290179848671, 0.006496991962194443, -0.00011784191156039014, 0.01007978804409504, -0.0034288414753973484, 0.004835841711610556, -0.0019129475113004446, 0.0011394962202757597, -0.01549458410590887, 0.0005283252685330808, -0.18944613635540009, 0.00805797427892685, 0.001250338857062161, -0.003669624449685216, -0.004074313677847385, -0.017731865867972374, -0.008117789402604103, 0.007206818088889122, 0.011400129646062851, 0.00377691094763577, -0.003389294957742095, -0.008641594089567661, 0.005487268324941397, 0.0010562953539192677, 0.0010154362535104156, -0.007010234985500574, 0.000004689788056566613, -0.005034277215600014, -0.0029719111043959856, 0.00561142060905695, 0.007262634113430977, 0.00871607568114996, 0.0024472051300108433, 0.0016091663856059313, -0.0021822634153068066, -0.0022576232440769672, 0.004957234021276236, -0.005052109714597464, 0.0017982381395995617, -0.013147030025720596, -0.00440280931070447, -0.0036096815019845963, -0.0047618066892027855, 0.0018929565558210015, 0.0053191655315458775, -0.0049409763887524605, 0.007722369860857725, 0.0019815745763480663, -0.004253812599927187, 0.0038818272296339273, -0.008476347662508488, 0.024948615580797195, 0.005240471567958593, 0.010673838667571545, 0.0036147800274193287, -0.000876431236974895, -0.004455899354070425, 0.010147984139621258, 0.0010181744582951069, 0.014147669076919556, -0.012128603644669056, -0.010486193001270294, 0.0012045674957334995, 0.018692202866077423, -0.0025876311119645834, -0.00976139772683382, -0.0068578943610191345, -0.007840984500944614, 0.008164520375430584, 0.011141443625092506, 0.009175887331366539, -0.006855488289147615, 0.011013232171535492, -0.00241878186352551, -0.024888884276151657, 0.003600029507651925, -0.002064621541649103, -0.005459973588585854, 0.002367747249081731, 0.004409767221659422, 0.009343763813376427, -0.0054961200803518295, 0.005686108488589525, -0.0013130641309544444, -0.002632520394399762, -0.0030391421169042587, 0.006217967718839645, -0.003631599945947528, 0.008379884995520115, -0.0070919436402618885, 0.016738805919885635, -0.012054221704602242, 0.0004134721530135721, 0.00019529330893419683, -0.0020099917892366648, 0.012531592510640621, 0.005678972695022821, 0.0003733165212906897, 0.004088455345481634, -0.012552130967378616, -0.00022823455219622701, 0.0012846210738644004, 0.001973905833438039, -0.007431200239807367, 0.0015013650991022587, -0.0034779657144099474, 0.00172527227550745, 0.008654387667775154, -0.007626806851476431, 0.0031710483599454165, 0.010790932923555374, -0.008615430444478989, 0.0012053900863975286, -0.008824562653899193, 0.00266831973567605, 0.0024239730555564165, -0.007337220944464207, -0.011961297132074833, 0.0035629025660455227, -0.0027456041425466537, -0.007840477861464024, 0.003769488539546728, -0.01177808828651905, -0.0014693712582811713, 0.00215755682438612, -0.00922373216599226, -0.0012062398018315434 ]
8ac1dd9d7bf008d9dc5cac34b41e0856589877ec
358
py
Python
load/__init__.py
andrewp-as-is/load.py
6ad643d82379a63f9c79d0dd994101ff0b490183
[ "Unlicense" ]
null
null
null
load/__init__.py
andrewp-as-is/load.py
6ad643d82379a63f9c79d0dd994101ff0b490183
[ "Unlicense" ]
null
null
null
load/__init__.py
andrewp-as-is/load.py
6ad643d82379a63f9c79d0dd994101ff0b490183
[ "Unlicense" ]
null
null
null
__all__ = ["load"] import imp import importlib def load(name, path): """Load and initialize a module implemented as a Python source file and return its module object""" if hasattr(importlib, "machinery"): loader = importlib.machinery.SourceFileLoader(name, path) return loader.load_module() return imp.load_source(name, path)
25.571429
103
0.709497
1
0.7386
[ 0.0038026131223887205, 0.024996113032102585, 0.0065416134893894196, -0.0012576010776683688, 0.005473786499351263, -0.002626000437885523, -0.01341073028743267, 0.003976929932832718, -0.007266680710017681, 0.0013037980534136295, 0.0021816054359078407, 0.006530614569783211, 0.008836564607918262, -0.017303697764873505, 0.0014539577532559633, 0.018028704449534416, -0.05491778999567032, 0.002961290767416358, -0.006383315194398165, 0.002084632869809866, -0.007612988352775574, 0.01031033881008625, 0.008382963947951794, 0.007375828921794891, 0.007014026865363121, 0.0015122918412089348, 0.011164397932589054, 0.005078655201941729, -0.008166317827999592, -0.0068418048322200775, -0.00030699567287229, -0.0009312171023339033, -0.0036752966698259115, -0.007434673607349396, 0.007799998391419649, 0.0006585080409422517, 0.0007064450182951987, -0.01849518157541752, 0.00862788688391447, -0.0062939198687672615, -0.008661109022796154, -0.01755320467054844, -0.002768577542155981, 0.005678631830960512, -0.011677556671202183, 0.002474336652085185, -0.003902338445186615, 0.0038840211927890778, -0.01099073514342308, 0.006237938534468412, -0.01145255845040083, 0.005993064492940903, 0.01202157698571682, 0.002289622323587537, -0.005728210788220167, -0.007299796678125858, 0.012105027213692665, 0.0005290829576551914, -0.011050503700971603, -0.0007059461204335093, -0.0015975309070199728, -0.0027860994450747967, 0.0040393429808318615, 0.005144502967596054, -0.01777680590748787, -0.0075483075343072414, -0.00412435969337821, 0.0027788870502263308, -0.0017759193433448672, 0.004938502795994282, 0.00018890398496296257, -0.0021223118528723717, 0.010293170809745789, 0.004226561635732651, 0.007011109963059425, -0.0022690242622047663, -0.001770330942235887, -0.0012879609130322933, 0.00856210757046938, 0.0028141296934336424, 0.004223180469125509, -0.009901958517730236, 0.006366854067891836, 0.00987821351736784, 0.014850241132080555, 0.009576392360031605, 0.02050545997917652, -0.009372731670737267, 0.04371440038084984, 0.006346457172185183, -0.009465805254876614, 0.0005842110840603709, -0.0082132238894701, -0.0039671435952186584, -0.0020152218639850616, -0.031231023371219635, 0.001682244474068284, -0.002930513583123684, 0.001793321454897523, 0.006108881440013647, 0.00006331378972390667, 0.003475366160273552, -0.0038043952081352472, -0.0030688007827848196, -0.012072021141648293, 0.012964657507836819, -0.010660696774721146, -0.002328513888642192, 0.008619763888418674, 0.0018812031485140324, -0.009837165474891663, -0.0018578525632619858, 0.0000926055436138995, -0.011989379301667213, 0.004629658069461584, -0.00009608562686480582, -0.006040356587618589, 0.05818920210003853, -0.0008212281973101199, 0.0041006566025316715, -0.004785088822245598, -0.0015003265580162406, 0.000019539120330591686, 0.008146540261805058, 0.008975681848824024, -0.0042104111053049564, 0.010395151562988758, 0.006055709905922413, 0.0031586780678480864, 0.007720106281340122, 0.0009117131703533232, 0.008361046202480793, -0.007625111844390631, -0.00230146455578506, 0.0003115501895081252, -0.008059697225689888, 0.008314193226397038, 0.0010514280293136835, -0.003994670230895281, -0.0006221802323125303, -0.0005865221610292792, -0.010901396162807941, 0.00287859165109694, -0.002876026090234518, 0.0011444517876952887, -0.012225726619362831, -0.005540971644222736, -0.0023670585360378027, -0.004095049574971199, 0.002300769090652466, 0.0067807394079864025, 0.00534707959741354, 0.004129283595830202, -0.007359641138464212, -0.008722241967916489, -0.0037845615297555923, -0.00717010535299778, 0.0017768656834959984, 0.006622175686061382, 0.004418388474732637, -0.009118303656578064, -0.0015054075047373772, 0.0033789221197366714, 0.0066671911627054214, 0.0005480335094034672, 0.000617474433965981, -0.009732423350214958, 0.00909478310495615, 0.0028036015573889017, 0.0035780875477939844, 0.012127942405641079, -0.006969455163925886, -0.0003414293169043958, 0.00017381944053340703, 0.004004594404250383, 0.0010891025885939598, 0.0036261253990232944, 0.010018350556492805, -0.008056111633777618, -0.0044134194031357765, 0.004419390112161636, 0.0026868509594351053, 0.00996005441993475, 0.007929223589599133, -0.003139083506539464, 0.004015653394162655, -0.004681022372096777, -0.0011080935364589095, 0.005018638446927071, -0.0054517569951713085, 0.007594004739075899, 0.0061559854075312614, -0.015784094110131264, -0.006367729976773262, -0.0007665341254323721, -0.011184648610651493, -0.0004074537428095937, 0.014558433555066586, 0.010672347620129585, 0.0006716042407788336, 0.00438671326264739, -0.012075135484337807, 0.0006058745784685016, 0.00656736409291625, 0.0019612631294876337, -0.013498258776962757, -0.9546016454696655, 0.0034923236817121506, 0.004001461900770664, -0.0007164424750953913, 0.00477520190179348, 0.0037871289532631636, 0.003321454394608736, 0.004934010095894337, 0.012278697453439236, -0.009171714074909687, -0.007443840615451336, -0.00946394819766283, -0.011876539327204227, -0.00046488092630170286, -0.006422809790819883, -0.003928574733436108, -0.0053598652593791485, -0.010016934014856815, 0.0015030589420348406, -0.0030110685620456934, -0.0008651410462334752, 0.011237596161663532, -0.0012695147888734937, 0.004684826359152794, 0.0024307442363351583, 0.0036365706473588943, -0.0037808394990861416, -0.0009683396783657372, -0.0003129660908598453, -0.0013185081770643592, -0.005776647478342056, -0.01574857346713543, -0.0036574716214090586, -0.0000929730522329919, 0.011289852671325207, -0.0020342213101685047, 0.00867040641605854, 0.00013217747618909925, 0.0006813429645262659, -0.007663780823349953, 0.005527784116566181, 0.0033776764757931232, 0.0033692405559122562, -0.030188340693712234, -0.0018607148667797446, -0.0009937140857800841, -0.009447631426155567, 0.009902414865791798, 0.0038247802294790745, -0.001771206152625382, -0.0008598295971751213, -0.004876821301877499, 0.011542974971234798, -0.008888958021998405, 0.005276227369904518, -0.006156357936561108, -0.006159251555800438, -0.00155043532140553, -0.010842517949640751, 0.0022445954382419586, 0.00336163560859859, -0.002131765242666006, -0.004517724271863699, -0.0021503877360373735, 0.002414689166471362, 0.00142444740049541, -0.0002960558049380779, -0.015996001660823822, -0.0065597048960626125, -0.0031349649652838707, 0.002248160308226943, -0.00012591455015353858, -0.003117223735898733, 0.006583114620298147, -0.012648703530430794, 0.0066297464072704315, 0.002788890153169632, 0.0015756223583593965, -0.011401977390050888, 0.0026051895692944527, -0.007776122540235519, -0.008813108317553997, 0.003445415059104562, -0.005938049405813217, -0.005329794716089964, 0.0027667698450386524, 0.001607969868928194, 0.005445030517876148, -0.005211338400840759, 0.003878862364217639, 0.009646458551287651, -0.004735990893095732, -0.010341698303818703, 0.006944066844880581, 0.005458343308418989, 0.001152294920757413, -0.0029021159280091524, -0.000021248022676445544, 0.008617677725851536, 0.008237584494054317, 0.0021732847671955824, 0.0049951630644500256, 0.0005767408292740583, 0.009565655142068863, 0.002702216384932399, 0.004115934018045664, -0.0007414044230245054, -0.0009072462562471628, -0.0062284693121910095, -0.0007381910108961165, -0.003860636381432414, -0.0017758681206032634, -0.011584409512579441, -0.01024769339710474, -0.005963905714452267, 0.002050281036645174, 0.0020410961005836725, -0.0033395658247172832, 0.00003615712557802908, 0.001826137420721352, 0.010823025368154049, 0.0005295351729728281, -0.0032698630820959806, 0.004573529586195946, 0.004384131636470556, -0.006788106169551611, 0.013571161776781082, -0.011664926074445248, 0.004584054462611675, -0.0024810167960822582, -0.017673514783382416, 0.008846688084304333, 0.00945994257926941, -0.006346209440380335, 0.003346239449456334, 0.003722461871802807, 0.002186072524636984, -0.000055204574891831726, -0.007794222794473171, -0.0020913821645081043, -0.01732047274708748, 0.0020056036300957203, 0.022007165476679802, 0.0009376050438731909, 0.012081530876457691, 0.012858514674007893, -0.0025640963576734066, 0.0014072484336793423, 0.007373292464762926, -0.002380724996328354, 0.0150783471763134, -0.007284876424819231, -0.0012859925627708435, 0.0003104549250565469, -0.005878813564777374, 0.0011464671697467566, 0.0044170250184834, 0.005123281851410866, -0.0034064340870827436, 0.0014952493365854025, -0.007148141507059336, -0.0067349085584282875, -0.017172330990433693, -0.0027995596174150705, 0.009724752977490425, -0.003946905490010977, 0.004235915839672089, -0.010665206238627434, 0.004539652727544308, 0.006600257940590382, 0.003671659156680107, -0.0009551641996949911, 0.00045316744945012033, 0.006296577863395214, 0.009765270166099072, -0.007150737103074789, 0.0046051801182329655, 0.0023273334372788668, -0.0006474959664046764, 0.00038179580587893724, 0.006599530577659607, -0.008661357685923576, -0.0035935058258473873, 0.0020152393262833357, 0.001352809020318091, 0.0006419578567147255, -0.004625080619007349, -0.00910700112581253, -0.006255065556615591, 0.005479387007653713, -0.005758282262831926, 0.004978852812200785, 0.002256578765809536, 0.0036711529828608036, -0.010532508604228497, -0.0022134145256131887, -0.005367056000977755, -0.009379597380757332, 0.011051949113607407, -0.0024261479265987873, 0.0031135783065110445, 0.011680812574923038, 0.004084749147295952, -0.013952595181763172, 0.008939691819250584, 0.005879475735127926, -0.004669714719057083, 0.004968153312802315, 0.006644465960562229, -0.00397256575524807, -0.02261504717171192, -0.0016626373399049044, -0.017178736627101898, 0.007169082760810852, -0.00047036181786097586, 0.001555813243612647, -0.007044048048555851, 0.009248188696801662, 0.0054468982852995396, -0.011332171969115734, -0.0014249995583668351, -0.011185668408870697, 0.008950800634920597, -0.0006417589029297233, -0.00299423118121922, -0.0030255047604441643, -0.004280761815607548, -0.004479485563933849, -0.0029602455906569958, 0.0002452052722219378, 0.0048952060751616955, 0.0009812370408326387, -0.004592397715896368, 0.0035280475858598948, -0.003789194393903017, 0.0014768785331398249, 0.0006632282165810466, -0.011226329021155834, 0.0003812751092482358, 0.007767360657453537, -0.0006956093711778522, -0.005498848855495453, -0.00031239964300766587, 0.000030192059057299048, -0.004087727051228285, -0.008845302276313305, -0.0034709516912698746, -0.0034307963214814663, -0.004846697673201561, -0.01162294764071703, -0.002809354569762945, -0.010211512446403503, 0.006226629484444857, -0.008945723995566368, 0.006556187756359577, 0.004784245975315571, -0.007032578811049461, 0.009261325933039188, -0.0032482577953487635, 0.005395278800278902, 0.003817314049229026, 0.005550904665142298, 0.0015290977898985147, -0.006004789844155312, -0.009446551091969013, 0.014925145544111729, -0.011391937732696533, -0.00008144058665493503, 0.013174498453736305, 0.003943996038287878, 0.009710405021905899, -0.0008593110251240432, -0.0007725124014541507, 0.005684066563844681, 0.007928818464279175, -0.015743643045425415, 0.0032964374404400587, -0.0006348995375446975, -0.00092044856864959, 0.007342770230025053, -0.0017349676927551627, 0.0014261321630328894, 0.007083292119204998, 0.0030019874684512615, -0.008340074680745602, -0.002102926140651107, 0.0008250570390373468, 0.004781403113156557, -0.012939750216901302, -0.0012348592281341553, -0.0025645666755735874, -0.003121662884950638, -0.005500232335180044, -0.003062877804040909, -0.0005031003383919597, 0.007030024193227291, -0.0048141321167349815, 0.006196390371769667, 0.003091756021603942, -0.0026174639351665974, 0.015686210244894028, -0.004211632534861565, -0.006829360034316778, 0.0029564974829554558, 0.0031017980072647333, 0.00038365801447071135, -0.007850940339267254, -0.0020847704727202654, 0.0026891124434769154, 0.004294418729841709, -0.0021120887249708176, -0.006456319242715836, -0.0033576092682778835, -0.0015018084086477757, -0.006986644119024277, 0.0015575515571981668, 0.012098555453121662, -0.002123893005773425, 0.003821879392489791, -0.002100529847666621, -0.0064471266232430935, -0.014404027722775936, 0.05594499036669731, -0.0009260016959160566, 0.002435329370200634, 0.004369957372546196, -0.007932327687740326, 0.00010558772191870958, -0.004806635435670614, 0.00595641927793622, -0.006645014509558678, -0.007231046911329031, 0.010139582678675652, -0.0022440848406404257, 0.002649076981469989, 0.00006112840492278337, -0.003579520620405674, 0.014593643136322498, -0.006540629081428051, -0.016464373096823692, -0.016185352578759193, 0.007887191139161587, -0.004239791538566351, -0.008962561376392841, 0.0071375127881765366, -0.0031776383984833956, -0.0023479992523789406, 0.0015674163587391376, 0.004282143898308277, -0.000019157989299856126, 0.0018278949428349733, -0.0032102870754897594, -0.0036005242727696896, -0.00021025343448854983, 0.0038861988577991724, 0.0067152781412005424, 0.008922716602683067, -0.0007337872521020472, 0.0031663430854678154, -0.00006150554690975696, -0.0011275621363893151, 0.00017309904797002673, 0.0037501759361475706, 0.006324443966150284, -0.0024717997293919325, -0.005508513189852238, 0.005355648696422577, 0.004087734501808882, 0.0008349845884367824, 0.010183124803006649, 0.0019375889096409082, -0.0028449418023228645, 0.007394290529191494, 0.007250659167766571, -0.0020954736974090338, 0.010232016444206238, -0.004689935594797134, 0.003321185940876603, 0.0024322050157934427, -0.007379601243883371, -0.01315316278487444, -0.0019559566862881184, 0.002507789060473442, 0.008535444736480713, -0.0009743498521856964, 0.0016010114923119545, 0.001086399075575173, -0.004336080048233271, -0.008629628457129002, -0.008114088326692581, -0.004042343702167273, -0.0011797097977250814, -0.0006781608099117875, 0.07306049764156342, -0.0071222372353076935, -0.0016971364384517074, -0.007632867898792028, -0.00006623758963542059, -0.0014225638005882502, -0.001714135054498911, -0.0013144704280421138, -0.003672319231554866, 0.004438099917024374, 0.00451474217697978, -0.008202867582440376, -0.009895513765513897, 0.0007040396449156106, 0.002603910630568862, -0.0021256625186651945, 0.005543852224946022, 0.008576053194701672, -0.008077122271060944, 0.003906712401658297, -0.012765436433255672, -0.001756746438331902, -0.0023559844121336937, -0.007979355752468109, -0.0031013006810098886, -0.0030549298971891403, 0.0024095377884805202, 0.0038352636620402336, 0.005148851312696934, -0.0026176476385444403, 0.006612593773752451, -0.0016495848540216684, 0.0012705684639513493, -0.0038397691678255796, -0.002158944960683584, -0.007078639697283506, 0.005786411464214325, -0.00016574384062550962, -0.00995337963104248, -0.0052926428616046906, -0.0032040560618042946, 0.0010405840585008264, -0.00575474975630641, 0.005948885343968868, -0.0005294392467476428, 0.007908307947218418, -0.00017517709056846797, 0.0006005623727105558, -0.005582307931035757, -0.0005517343524843454, -0.01249185111373663, 0.003832657355815172, -0.18459820747375488, 0.01282268576323986, 0.002990762237459421, -0.004505715798586607, -0.00542983366176486, -0.012694946490228176, -0.009293648414313793, 0.004394554533064365, 0.01048443652689457, -0.0013191127218306065, -0.0017188170459121466, -0.0030132299289107323, 0.006634339224547148, 0.005358744412660599, -0.00020149335614405572, -0.006664736662060022, 0.0031440178863704205, -0.0021888697519898415, 0.0013358270516619086, 0.0032024390529841185, 0.006188804749399424, 0.008305924944579601, 0.003988589160144329, 0.0006742302794009447, -0.00016670161858201027, -0.004939990118145943, 0.004750936757773161, -0.0020468737930059433, 0.005089711397886276, -0.008831216022372246, -0.002860073000192642, -0.005426329094916582, -0.0031140572391450405, 0.000656658667139709, 0.0020174228120595217, -0.004338249564170837, 0.005329929757863283, 0.002388418884947896, -0.008159372955560684, 0.007828904315829277, -0.007712808903306723, 0.03017374686896801, 0.004071190487593412, 0.007043055258691311, 0.00018302285752724856, -0.0037571084685623646, -0.0037357115652412176, 0.009364374913275242, 0.00251621357165277, 0.013541020452976227, -0.010901504196226597, -0.006094786804169416, 0.003016554517671466, 0.019975446164608, -0.006939079612493515, -0.008199664764106274, -0.009045259095728397, -0.003879812080413103, 0.00647765351459384, 0.010311190038919449, 0.01087218802422285, -0.0014802516670897603, 0.012250564061105251, -0.004117649979889393, -0.021845342591404915, 0.001537134638056159, -0.0018080564914271235, -0.008165651001036167, 0.003925250377506018, 0.006897277664393187, 0.01147634256631136, -0.00024063210003077984, 0.007686122786253691, -0.0025239293463528156, 0.005574450362473726, -0.0017915952485054731, 0.008289254270493984, -0.004463061690330505, 0.004865437746047974, -0.010318860411643982, 0.010198503732681274, -0.009903175756335258, -0.004221628420054913, 0.0007505124667659402, -0.005457313731312752, 0.011395733803510666, 0.005638374947011471, -0.000539219647180289, -0.0009017190313898027, -0.010268774814903736, -0.003980365116149187, 0.0008474558126181364, 0.0024621596094220877, -0.009832621552050114, 0.0017709422390908003, -0.003807633649557829, 0.008129473775625229, 0.0059821996837854385, -0.005515050143003464, 0.005462797824293375, 0.0036215954460203648, -0.007687742821872234, 0.0022050661500543356, -0.005750126205384731, 0.002547395182773471, 0.004589049611240625, -0.0044808355160057545, -0.007612759247422218, 0.005643800366669893, -0.007272034417837858, -0.004728673491626978, 0.002609018934890628, -0.009855973534286022, -0.010248135775327682, -0.000022527332475874573, -0.015199718065559864, 0.0020422968082129955 ]
8ac22e55a9c9778c66e3a1d86342cccdc465c6de
4,117
py
Python
pygears/svgen/modules/sieve.py
Risto97/pygears
19393e85101a16762cb3bbbf3010946ef69217f2
[ "MIT" ]
null
null
null
pygears/svgen/modules/sieve.py
Risto97/pygears
19393e85101a16762cb3bbbf3010946ef69217f2
[ "MIT" ]
null
null
null
pygears/svgen/modules/sieve.py
Risto97/pygears
19393e85101a16762cb3bbbf3010946ef69217f2
[ "MIT" ]
null
null
null
import itertools from pygears.common.sieve import sieve from pygears.svgen.inst import SVGenInstPlugin from pygears.svgen.svmod import SVModuleGen from functools import partial from pygears.svgen.svgen import SVGenPlugin from pygears.svgen.util import svgen_visitor from pygears.core.hier_node import HierVisitorBase from pygears.svgen.inst import svgen_inst from pygears.rtl.gear import RTLGearHierVisitor, is_gear_instance def index_to_sv_slice(dtype, key): subtype = dtype[key] if isinstance(key, slice): key = key.start if key is None or key == 0: low_pos = 0 else: low_pos = int(dtype[:key]) high_pos = low_pos + int(subtype) - 1 return f'{high_pos}:{low_pos}' class SVGenSieve(SVModuleGen): @property def is_generated(self): return True def get_module(self, template_env): def get_stages(): for s in itertools.chain(self.node.pre_sieves, [self.node]): indexes = s.params['key'] if not isinstance(indexes, tuple): indexes = (indexes, ) dtype = s.in_ports[0].dtype out_type = s.out_ports[0].dtype slices = list( map( partial(index_to_sv_slice, dtype), filter(lambda i: int(dtype[i]) > 0, indexes))) yield slices, out_type stages = list(get_stages()) # If any of the sieves has shrunk data to 0 width, there is nothing to # do if any(i[0] == [] for i in stages): stages = [] context = { 'stages': stages, 'module_name': self.sv_module_name, 'intfs': list(self.sv_port_configs()) } return template_env.render_local(__file__, "sieve.j2", context) @svgen_visitor class RemoveEqualReprSieveVisitor(RTLGearHierVisitor): def sieve(self, node): pout = node.out_ports[0] pin = node.in_ports[0] if pin.dtype == pout.dtype: node.bypass() @svgen_visitor class CollapseSievesVisitor(RTLGearHierVisitor): def sieve(self, node): if not hasattr(node, 'pre_sieves'): node.pre_sieves = [] sieve_cons = [ p for p in node.consumers if is_gear_instance(p.node, sieve) ] pin = node.in_ports[0] pout = node.out_ports[0] iin = pin.producer iout = pout.consumer if sieve_cons: # There is a Sieve connected to this Sieve, hence we can combine # two of them into a single SV module # Connect the consumers of this Sieve, which are Sieves themselves, # to this Sieve's predecessor for cons_pin in iout.consumers.copy(): consumer = cons_pin.node if is_gear_instance(consumer, sieve): # print(f'Merging {node.name} to {consumer.name}') # print(consumer.params['key']) # If the consumer is a Sieve, just register this Sieve with # it, and short circuit this one consumer.pre_sieves = node.pre_sieves + [node] iout.disconnect(cons_pin) iin.connect(cons_pin) # print(f'Remaining conusmer: {[p.node.name for p in node.consumers]}') if not node.consumers: # Finally, if ther are no consumers left for this sieve remove # this Sieve completely (with all it's connections) from the # SVGen tree node.remove() iout.remove() class SVGenSievePlugin(SVGenInstPlugin, SVGenPlugin): @classmethod def bind(cls): cls.registry['svgen']['module_namespace'][sieve] = SVGenSieve cls.registry['svgen']['flow'].insert( cls.registry['svgen']['flow'].index(svgen_inst), CollapseSievesVisitor) # cls.registry['SVGenFlow'].insert( # cls.registry['SVGenFlow'].key(CollapseSievesVisitor), # RemoveEqualReprSieveVisitor)
32.674603
83
0.589264
1
2.0721
[ 0.005459405481815338, 0.03160093352198601, 0.03603474050760269, 0.011523047462105751, -0.030442971736192703, 0.04061359539628029, -0.019810285419225693, -0.01265679206699133, -0.030649464577436447, 0.05814381316304207, 0.019863178953528404, 0.026640191674232483, 0.0005092564388178289, -0.019232898950576782, -0.013406366109848022, 0.003800297388806939, 0.04810354486107826, 0.05771985277533531, -0.014014581218361855, 0.025251897051930428, -0.02586204558610916, -0.011431858874857426, -0.024186166003346443, -0.0007047003600746393, 0.006070466712117195, 0.007557504810392857, 0.05306386947631836, -0.0030850963667035103, 0.020377082750201225, 0.00026785777299664915, -0.02569584921002388, -0.031589459627866745, -0.0020839476492255926, 0.013516027480363846, 0.017430488020181656, 0.02277747169137001, -0.0069799176417291164, -0.04606442153453827, 0.03161008283495903, -0.004497474059462547, -0.006952361669391394, -0.014264076016843319, -0.018964039161801338, 0.00487937405705452, 0.0240420401096344, -0.0010422952473163605, -0.015098356641829014, -0.03251522779464722, -0.051469385623931885, 0.037488386034965515, 0.012937814928591251, 0.008115391246974468, 0.009806947782635689, -0.014396004378795624, -0.026265621185302734, -0.05193309858441353, -0.0010139481164515018, 0.05094486474990845, -0.03153647109866142, 0.002232849830761552, 0.0235256627202034, -0.013857163488864899, -0.004903171211481094, 0.02313435636460781, 0.014894465915858746, -0.01309104636311531, -0.0224118921905756, -0.026231804862618446, -0.05659353360533714, -0.03799137473106384, -0.008554277941584587, 0.03539850562810898, 0.07281653583049774, 0.0333419069647789, 0.04873713105916977, 0.024341117590665817, -0.011266408488154411, -0.014383108355104923, 0.0016938061453402042, 0.04460933804512024, 0.011134282685816288, 0.04841095581650734, 0.015823375433683395, -0.026734013110399246, 0.006638913415372372, 0.032131653279066086, 0.044240862131118774, -0.011008688248693943, 0.059933096170425415, -0.004685946740210056, -0.06157050281763077, 0.0099909957498312, -0.0240623876452446, -0.0015201583737507463, 0.013152875006198883, -0.007662126794457436, 0.011605029925704002, -0.006180395372211933, 0.021597815677523613, 0.012827064841985703, 0.006861177273094654, -0.010555817745625973, 0.010339511558413506, -0.010222392156720161, 0.003710926743224263, 0.010973240248858929, -0.025010310113430023, 0.009611899964511395, -0.0030603858176618814, -0.01688997820019722, 0.04131335765123367, 0.028714755550026894, 0.01568940281867981, -0.007665598299354315, -0.012392168864607811, -0.018250204622745514, 0.0010362900793552399, 0.0006505766068585217, -0.005551361944526434, 0.013611765578389168, 0.014983602799475193, 0.002938746241852641, 0.006501564756035805, -0.019084244966506958, -0.03437962010502815, 0.10838180780410767, -0.0023911609314382076, 0.025960078462958336, 0.03567243367433548, 0.0003444364119786769, 0.004467139486223459, -0.012948296032845974, -0.01359607931226492, -0.04479631036520004, 0.0026846437249332666, 0.012309784069657326, -0.012058882974088192, 0.01356630027294159, -0.04746934399008751, 0.026743631809949875, 0.00293968734331429, -0.029637563973665237, 0.016645630821585655, -0.020048117265105247, -0.00012146468361606821, -0.03449735790491104, -0.02069113776087761, -0.007855326868593693, -0.03693048655986786, 0.005189390387386084, -0.003831952577456832, 0.008502697572112083, -0.0013119371142238379, 0.014051689766347408, -0.005902809556573629, 0.0031935409642755985, -0.016415460035204887, -0.06283847242593765, 0.011541315354406834, 0.0198503490537405, -0.015997864305973053, 0.021851738914847374, -0.01196535024791956, 0.008268090896308422, 0.015707962214946747, 0.021663861349225044, 0.012443263083696365, 0.03795752674341202, -0.01143618207424879, 0.05994728207588196, -0.008084637112915516, 0.001123857102356851, -0.004478024318814278, 0.01480789203196764, -0.05673450604081154, 0.01861751452088356, -0.01757185533642769, 0.024993862956762314, 0.02121715433895588, 0.028940018266439438, 0.012685654684901237, -0.011822554282844067, 0.015124151483178139, 0.017488136887550354, 0.017863256856799126, -0.012376935221254826, -0.07392693310976028, -0.015034617856144905, 0.00901724211871624, -0.005923956632614136, -0.00977342389523983, -0.004844190552830696, -0.019914228469133377, -0.03758196905255318, 0.006499165669083595, 0.00034154392778873444, 0.024515734985470772, -0.00992902833968401, -0.026321567595005035, 0.00976487249135971, -0.006481771823018789, -0.000848032534122467, 0.013232204131782055, 0.00785126443952322, -0.01173501554876566, 0.006248909048736095, -0.7385385632514954, 0.026753755286335945, 0.008190300315618515, -0.004249111749231815, 0.008255714550614357, 0.004460109863430262, -0.03129409998655319, -0.001495245611295104, -0.046442631632089615, -0.021254222840070724, 0.021468574181199074, -0.02976798452436924, -0.03210331127047539, 0.0010098409838974476, -0.0019076000899076462, 0.01641564816236496, -0.0030306975822895765, -0.01064828597009182, 0.01916210539638996, 0.008175457827746868, 0.01547391340136528, -0.03626115620136261, 0.015609650872647762, 0.018496856093406677, 0.022743241861462593, -0.0351024828851223, 0.04015542194247246, 0.005202429369091988, -0.03412383422255516, -0.013144471682608128, 0.012630220502614975, -0.004578290972858667, 0.0018892970401793718, -0.0320456400513649, -0.01337288599461317, 0.02138894982635975, 0.035779327154159546, -0.015179775655269623, -0.017010219395160675, -0.012700535356998444, -0.01327129453420639, 0.00009596846939530224, -0.04817372187972069, -0.04666127264499664, -0.04194708913564682, -0.0012474607210606337, -0.009279996156692505, -0.0033194287680089474, 0.0030311793088912964, 0.024678731337189674, -0.018244100734591484, 0.007232720497995615, 0.0319213792681694, -0.002163409721106291, -0.00046651691081933677, -0.00337692117318511, -0.04235998913645744, -0.006957725156098604, 0.005426591727882624, -0.01411177683621645, 0.028791267424821854, 0.0034489238169044256, -0.021193133667111397, 0.009974255226552486, -0.018015075474977493, 0.00515794800594449, 0.03636610507965088, -0.02652036026120186, 0.0003065476194024086, 0.01761149987578392, -0.06541169434785843, -0.02238391898572445, -0.02426024340093136, 0.12842878699302673, -0.03681805729866028, 0.01799943298101425, -0.017539015039801598, 0.011593727394938469, -0.03448961675167084, 0.018928557634353638, 0.022584564983844757, -0.0004363774787634611, -0.0075484467670321465, -0.013024589978158474, -0.043909233063459396, -0.05247887969017029, 0.018988462164998055, -0.011945207603275776, 0.00019146881822962314, 0.035119928419589996, 0.026421936228871346, -0.0021560972090810537, -0.0030149163212627172, 0.026256445795297623, 0.02964872680604458, 0.004856771323829889, 0.04213711991906166, 0.027607347816228867, -0.002536287996917963, 0.013554085977375507, -0.014936409890651703, 0.01370331272482872, 0.0011660568416118622, 0.012869835831224918, 0.0014284595381468534, -0.01342833787202835, -0.016853129491209984, -0.02085469663143158, 0.04174426198005676, -0.012274211272597313, 0.028662079945206642, -0.019830679520964622, 0.012972846627235413, -0.0026370480190962553, 0.003036314621567726, -0.014466638676822186, 0.01932176947593689, -0.019420379772782326, 0.015073873102664948, 0.0013757523847743869, -0.02407792955636978, -0.02852911688387394, -0.0350094698369503, 0.009157662279903889, 0.015026872046291828, 0.012580745853483677, -0.0055470094084739685, -0.02334778755903244, -0.01207199040800333, -0.006965841166675091, -0.047960203140974045, -0.025506682693958282, 0.003305555786937475, -0.023248136043548584, -0.018409378826618195, -0.013095938600599766, 0.009782971814274788, -0.04313432797789574, 0.013121581636369228, 0.030705519020557404, -0.020023994147777557, -0.038733288645744324, 0.004270960111171007, -0.03684407100081444, 0.052117969840765, 0.0054949428886175156, 0.006359429098665714, 0.008144778199493885, 0.0025348945055156946, -0.010172102600336075, 0.0062158359214663506, 0.03340314328670502, 0.0013454461004585028, 0.0021863600704818964, 0.005726421717554331, -0.0028880357276648283, -0.001172377960756421, 0.0034611469600349665, 0.0074886055663228035, 0.0048539601266384125, -0.009054752066731453, -0.0021629862021654844, 0.02983700856566429, 0.03456905111670494, -0.013349059969186783, -0.000640868442133069, 0.009188611060380936, -0.000704255246091634, 0.03934517875313759, 0.03644876554608345, 0.027299070730805397, -0.02655469998717308, -0.028897041454911232, 0.014009895734488964, -0.019537465646862984, -0.0032721685711294413, -0.0032863502856343985, 0.030338047072291374, 0.0027668806724250317, -0.022482573986053467, 0.004591952543705702, 0.019611753523349762, 0.003841702127829194, -0.015455641783773899, -0.02237948216497898, 0.010735984891653061, -0.009099234826862812, -0.0023749051615595818, -0.01587005890905857, 0.0012683854438364506, -0.003405258059501648, -0.006153840105980635, -0.01966775581240654, -0.009640499018132687, -0.027297142893075943, 0.008837648667395115, -0.009764401242136955, -0.017415635287761688, 0.016253994777798653, -0.025494718924164772, 0.009641471318900585, 0.028722532093524933, 0.02053593099117279, -0.03998813033103943, -0.016135111451148987, 0.06961200386285782, 0.009927533566951752, -0.0038563364651054144, 0.03087175078690052, -0.041271042078733444, 0.002576612401753664, -0.0032834098674356937, 0.019028780981898308, 0.019313618540763855, -0.006822143215686083, 0.029752330854535103, -0.015897678211331367, -0.06012680009007454, -0.01722436584532261, -0.034546636044979095, -0.019144359976053238, -0.008723908104002476, 0.022302566096186638, 0.023780090734362602, -0.013246618211269379, -0.006254412233829498, -0.053681716322898865, -0.017461583018302917, 0.0073844920843839645, -0.03129631653428078, 0.020668772980570793, 0.007493103388696909, 0.02003595232963562, -0.024068880826234818, -0.033380527049303055, 0.005263501778244972, -0.013130034320056438, -0.006960687693208456, 0.03197018429636955, -0.03176592290401459, 0.012366512790322304, -0.0006044387118890882, 0.0038833327125757933, 0.03408448398113251, 0.026421885937452316, 0.005660233553498983, 0.0007453480502590537, 0.00021370110334828496, -0.011696412228047848, 0.01050175353884697, -0.010823188349604607, -0.024465834721922874, -0.02913535200059414, 0.007154649589210749, 0.0012505805352702737, 0.003125075250864029, -0.016344420611858368, -0.00004249930861988105, 0.024895578622817993, 0.0344114825129509, -0.0017647409113124013, -0.01244013849645853, 0.02074967324733734, -0.0004894098965451121, -0.0026694592088460922, 0.005478888284415007, 0.004861950874328613, 0.016905922442674637, 0.003942857030779123, 0.040237199515104294, 0.00614979537203908, -0.01680189184844494, -0.019483577460050583, -0.011012869887053967, 0.018346989527344704, -0.000995904323644936, -0.025870904326438904, 0.0025812345556914806, -0.04144841060042381, 0.01704910770058632, -0.02565542794764042, 0.019922535866498947, 0.011256491765379906, 0.015899715945124626, 0.004450615495443344, 0.02159632369875908, 0.019499901682138443, 0.007736509665846825, -0.02040346898138523, 0.015919409692287445, -0.022073179483413696, -0.026604903861880302, 0.03903524577617645, 0.035444363951683044, 0.018910177052021027, -0.020043404772877693, -0.00838903896510601, -0.010789746418595314, 0.0014842551900073886, -0.0008039980893954635, 0.028862131759524345, -0.0011628670617938042, -0.023131774738430977, -0.013993850909173489, 0.023204145953059196, -0.020244166254997253, 0.012161243706941605, -0.036150503903627396, 0.039393022656440735, 0.028658227995038033, -0.009015481919050217, 0.03430848568677902, -0.026779958978295326, -0.0010249894112348557, -0.023133283481001854, 0.002832320285961032, 0.01100131031125784, -0.005840847734361887, 0.019803086295723915, 0.006557910703122616, -0.06921304762363434, 0.02424144186079502, -0.012909351848065853, -0.029278606176376343, 0.0279543474316597, -0.004359109327197075, -0.035124555230140686, -0.037509821355342865, 0.010032019577920437, 0.02352607063949108, 0.015336587093770504, -0.03597051277756691, 0.00440699327737093, -0.02424306422472, 0.02437916211783886, 0.008506708778440952, 0.009235273115336895, 0.035289838910102844, 0.007264171727001667, -0.011866407468914986, 0.02821647748351097, 0.047972433269023895, -0.019760729745030403, -0.016184000298380852, 0.0056088571436703205, 0.03479382023215294, -0.01594371534883976, 0.028191497549414635, 0.02503827214241028, 0.03845445439219475, -0.0009931022068485618, -0.01640922762453556, -0.03489406406879425, -0.01006274577230215, -0.0026808390393853188, 0.0218559131026268, 0.030785541981458664, -0.005714095663279295, 0.043120674788951874, -0.006896129809319973, 0.007487573195248842, -0.0017796040046960115, -0.044542305171489716, -0.0036295640747994184, 0.0019254841608926654, -0.0018498928984627128, 0.023566169664263725, -0.0326605848968029, -0.01925550028681755, -0.004266359843313694, -0.019277391955256462, -0.028979286551475525, 0.0006769925239495933, -0.013242634944617748, -0.02043994516134262, 0.028267769142985344, 0.007921886630356312, 0.03971617668867111, 0.02038341388106346, -0.019303852692246437, -0.0011784816160798073, -0.04945254698395729, -0.0019318119157105684, -0.03684477135539055, -0.005618725437670946, -0.016583384945988655, -0.02862696722149849, -0.00795395765453577, -0.00041986245196312666, -0.02183842845261097, -0.006160169839859009, -0.0006662624655291438, -0.009091313928365707, 0.013799705542623997, -0.031169617548584938, -0.008451605215668678, -0.02139751799404621, -0.02243501879274845, 0.025180285796523094, -0.025721492245793343, 0.018187280744314194, 0.04296300560235977, -0.006395225878804922, 0.000555291015189141, 0.02037001959979534, -0.0035050169099122286, 0.007957952097058296, 0.020043637603521347, -0.009232885204255581, -0.01595592498779297, 0.03684352710843086, 0.009950080886483192, 0.0010201954282820225, -0.02745451219379902, 0.005348212085664272, 0.014496457763016224, -0.045777950435876846, 0.012453658506274223, 0.025606002658605576, 0.006697211880236864, -0.01649964042007923, -0.01365809515118599, -0.003737335791811347, 0.004549810197204351, 0.00045886682346463203, 0.00874890387058258, 0.00215206784196198, -0.009629049338400364, -0.000027310725272400305, 0.012074424885213375, 0.0007128954166546464, 0.01797393150627613, -0.04433634877204895, 0.011686724610626698, 0.008754255250096321, 0.01783454604446888, -0.0027226503007113934, 0.006625444628298283, -0.00860270019620657, 0.031501784920692444, -0.012882833369076252, 0.002718980424106121, -0.012310076504945755, -0.0010248360922560096, 0.014976490288972855, -0.09156516939401627, 0.0013500377535820007, 0.009664983488619328, -0.02343747206032276, -0.022073393687605858, -0.002513518324121833, 0.010984068736433983, 0.021374255418777466, -0.034507472068071365, 0.027152476832270622, -0.012458582408726215, -0.01466344203799963, 0.03575809299945831, 0.005349518731236458, 0.01728074997663498, -0.03368968144059181, 0.03913779929280281, -0.06186104193329811, 0.0028955431189388037, 0.024350572377443314, 0.02150873653590679, 0.021143300458788872, -0.012552191503345966, -0.025752656161785126, -0.032688263803720474, 0.027157407253980637, 0.021184023469686508, -0.01099323108792305, 0.01846195198595524, -0.015330501832067966, 0.030023574829101562, -0.00022357373381964862, 0.025337694212794304, 0.012840544804930687, 0.039674170315265656, -0.01286154892295599, 0.016950806602835655, 0.031771428883075714, -0.02127261646091938, 0.028646957129240036, 0.014006148092448711, -0.013812258839607239, -0.005281191784888506, 0.010618006810545921, 0.04534748196601868, -0.031217480078339577, -0.003007839899510145, -0.013614675030112267, 0.01424749381840229, 0.0025414545089006424, -0.04674479365348816, 0.038492877036333084, 0.00977784302085638, 0.034454017877578735, 0.006881680805236101, -0.006927862763404846, -0.042053382843732834, 0.02630685456097126, -0.011833341792225838, 0.02950933575630188, 0.0013964181998744607, 0.04884113371372223, 0.0008435407071374357, -0.03750765696167946, -0.06206163018941879, -0.024648139253258705, -0.004529493395239115, -0.004194446839392185, 0.031154517084360123, 0.0006935721030458808, 0.004792873747646809, 0.045539192855358124, -0.06384626030921936, -0.009917554445564747, -0.01312052272260189, 0.006840129848569632, 0.014334877952933311, 0.024823443964123726, -0.016786282882094383, 0.0018953898688778281, 0.007214144803583622, -0.00910202320665121, -0.03843901678919792, 0.019229646772146225, -0.015639960765838623, -0.004451319575309753, -0.014375358819961548, -0.042048320174217224, 0.009160397574305534, 0.009019055403769016, -0.07317892462015152, 0.029490917921066284, 0.013957880437374115, -0.02677307091653347, -0.047863662242889404, 0.014261545613408089, 0.01564769446849823, 0.006257648114115, 0.0016946946270763874, -0.03777928277850151, -0.018049772828817368, -0.033114269375801086, -0.010605757124722004, 0.012632325291633606, -0.01917729340493679, 0.005475812125951052, -0.014215577393770218, 0.0005168690695427358, 0.008059972897171974, -0.03695065900683403, -0.0028239628300070763, -0.007405411452054977, 0.039018068462610245, 0.015854861587285995, -0.06092457100749016, -0.023634176701307297, 0.02707459032535553 ]
8ac2a36b9aed8734fe00d975f21caf0ecc7d8aef
5,461
py
Python
examples/my_model_test.py
gzpyy/qlib
56fdd028c8296c75f2a32bdb51869f010dd4f6d1
[ "MIT" ]
null
null
null
examples/my_model_test.py
gzpyy/qlib
56fdd028c8296c75f2a32bdb51869f010dd4f6d1
[ "MIT" ]
null
null
null
examples/my_model_test.py
gzpyy/qlib
56fdd028c8296c75f2a32bdb51869f010dd4f6d1
[ "MIT" ]
null
null
null
#encoding=utf-8 import qlib import pandas as pd import pickle import xgboost as xgb import numpy as np import re from qlib.constant import REG_US from qlib.utils import exists_qlib_data, init_instance_by_config from qlib.workflow import R from qlib.workflow.record_temp import SignalRecord, PortAnaRecord from qlib.utils import flatten_dict from qlib.data import LocalExpressionProvider from qlib.data.ops import Operators, OpsList from qlib.data.base import Feature from pyecharts import options as opts from pyecharts.charts import Kline, Line, Grid from my_data_handler import MyAlphaHandler # model_file = r'.\mlruns\1\d6536b056ba84a74be6b33971f443cf6\artifacts\trained_model' model_file = r'.\mlruns\1\148ef1cd7acd48deac3eadc339ad3008\artifacts\trained_model' with open(model_file, 'rb') as fi: model = pickle.load(fi) exprs, columns = MyAlphaHandler.get_custom_config() raw_data = pd.read_csv('../stock_data/TSLA.csv', parse_dates=['time']) raw_data['data_time'] = raw_data['time'].dt.strftime("%Y-%m-%d %H:%M:00") raw_data.set_index('time', inplace=True) raw_data["vwap"] = np.nan raw_data.sort_index(inplace=True) # print(raw_data) class MyFeature(Feature): def _load_internal(self, instrument, start_index, end_index, freq): print("load", self._name, instrument, start_index, end_index, freq) return raw_data.loc[start_index:end_index][self._name] Operators.register(OpsList + [MyFeature]) def my_parse_field(field): if not isinstance(field, str): field = str(field) for pattern, new in [(r"\$(\w+)", rf'MyFeature("\1")'), (r"(\w+\s*)\(", r"Operators.\1(")]: # Features # Operators field = re.sub(pattern, new, field) return field obj = dict() for field in exprs: expression = eval(my_parse_field(field)) series = expression.load('TSLA', "2022-01-02", "2022-02-28", "1min") series = series.astype(np.float32) obj[field] = series data = pd.DataFrame(obj) data.columns = columns view_time_start = '2022-02-11' view_time_end = '2022-02-12' pre_data = raw_data.loc[view_time_start:view_time_end].copy() pred=model.model.predict(xgb.DMatrix(data.loc[view_time_start:view_time_end])) pre_data['pred_score'] = pred records = pre_data.to_dict("records") cash = 50000 position = {} hold_thresh = 5 score_thresh = 0.001 x_axises, y_axises, mark_points, money = [], [], [], [] for record in records: x_axises.append(record['data_time']) y_axises.append([ record['open'], record['close'], record['low'], record['high'] ]) if 'hold_cnt' in position: position['hold_cnt'] += 1 if position and (record['open'] >= position['close'] * 1.01 or record['open'] < position['close'] * 0.995 or record['pred_score'] < -score_thresh or position['hold_cnt'] >= hold_thresh): cash += position['amount'] * record['open'] position = {} #print("sell") mark_points.append(opts.MarkPointItem( coord=[record['data_time'], record['high']], symbol='triangle', symbol_size=7, itemstyle_opts=opts.ItemStyleOpts(color="green") )) elif record['pred_score'] > score_thresh and not position: position = dict(record) position['amount'] = int(cash / position['open']) cash -= position['amount'] * position['open'] # buy #print("buy") position['hold_cnt'] = 0 mark_points.append(opts.MarkPointItem( coord=[record['data_time'], record['high']], symbol='arrow', symbol_size=7, itemstyle_opts=opts.ItemStyleOpts(color="yellow") )) cur_money = cash if position: cur_money += position['amount'] * record['close'] money.append(cur_money) if position: cash += position['amount'] * records[-1]['close'] print("cash:", cash) kline_graph = ( Kline() .add_xaxis(x_axises) .add_yaxis( "kline", y_axises, markpoint_opts=opts.MarkPointOpts( data=mark_points ), ) .set_global_opts( xaxis_opts=opts.AxisOpts(is_scale=True), yaxis_opts=opts.AxisOpts( is_scale=True, splitarea_opts=opts.SplitAreaOpts( is_show=True, areastyle_opts=opts.AreaStyleOpts(opacity=1) ), ), title_opts=opts.TitleOpts(title="%s_%s" % (view_time_start, view_time_end)), datazoom_opts=[opts.DataZoomOpts(type_="inside", xaxis_index=[0, 1],)], ) ) kline_line = ( Line() .add_xaxis(xaxis_data=x_axises) .add_yaxis( series_name="cur_money", y_axis=money, is_smooth=True, linestyle_opts=opts.LineStyleOpts(opacity=0.5), label_opts=opts.LabelOpts(is_show=False), markline_opts=opts.MarkLineOpts( data=[opts.MarkLineItem(y=50000)] ), ) .set_global_opts( xaxis_opts=opts.AxisOpts( type_="category", grid_index=2, axislabel_opts=opts.LabelOpts(is_show=False), ), yaxis_opts=opts.AxisOpts( min_='dataMin' ) ) ) grid_chart = Grid(init_opts=opts.InitOpts(width='2000px', height='900px')) grid_chart.add( kline_graph, grid_opts=opts.GridOpts(pos_left="3%", pos_right="10%", height="50%"), ) grid_chart.add( kline_line, grid_opts=opts.GridOpts( pos_left="3%", pos_right="10%", pos_top="60%", height="30%" ), ) grid_chart.render("kline_markline.html")
33.29878
190
0.655741
1
2.2551
[ -0.09172502905130386, 0.03663725405931473, -0.021697737276554108, -0.010893718339502811, 0.0000645753534627147, 0.009524998255074024, 0.020908549427986145, -0.020554613322019577, -0.0185848455876112, 0.0044304560869932175, -0.006696520838886499, -0.009402241557836533, 0.02731642872095108, -0.05781882628798485, -0.02766166813671589, -0.03209780901670456, -0.009073383174836636, -0.003948522266000509, 0.010122307576239109, -0.011093884706497192, 0.004996625706553459, 0.00869942456483841, -0.03834189102053642, 0.00017858078354038298, 0.004713449627161026, 0.0007967224810272455, 0.060262925922870636, -0.00019945870735682547, -0.007509119343012571, 0.0003439720894675702, -0.02654127962887287, 0.003042729338631034, -0.02923797257244587, -0.016693947836756706, 0.0023663626052439213, -0.03658708184957504, -0.009403611533343792, -0.07901688665151596, 0.04290444031357765, -0.02187824435532093, -0.00830813217908144, -0.02264188788831234, 0.05809449031949043, -0.010296045802533627, 0.01891194097697735, 0.03312385454773903, -0.03213951736688614, -0.014989789575338364, -0.036260541528463364, -0.0023046245332807302, -0.04966135323047638, 0.011942250654101372, -0.03820885345339775, 0.007913114503026009, -0.0018020407296717167, -0.026987912133336067, 0.03172745555639267, 0.03454699367284775, -0.024325240403413773, -0.00619888911023736, 0.012321118265390396, -0.020317088812589645, 0.002506981836631894, 0.02670225501060486, 0.0064653558656573296, 0.0002946609165519476, 0.0024882794823497534, -0.011726421304047108, 0.015390867367386818, 0.013430767692625523, 0.006523202173411846, -0.013250640593469143, -0.004551472142338753, 0.018139902502298355, -0.03137826547026634, 0.0062945010140538216, -0.030077818781137466, -0.04102777689695358, 0.02059747651219368, 0.00020713281992357224, -0.027027763426303864, 0.04516724869608879, 0.010100568644702435, -0.04148080199956894, -0.0037860304582864046, 0.03838788717985153, 0.02660951390862465, -0.06053992733359337, 0.011755917221307755, -0.00665763346478343, -0.06437782943248749, -0.03551071882247925, -0.01754002831876278, 0.009638717398047447, 0.012385792098939419, -0.07129659503698349, 0.011497865431010723, 0.036910638213157654, -0.0056523773819208145, -0.026113834232091904, 0.019399885088205338, 0.007630533073097467, 0.028793852776288986, -0.019815102219581604, 0.00256023439578712, -0.0011843672255054116, -0.04234457388520241, -0.04124513268470764, 0.008523896336555481, -0.03263203799724579, -0.03917720913887024, 0.06557994335889816, -0.010696856305003166, -0.0004325138288550079, -0.017105842009186745, -0.024774828925728798, 0.001323497504927218, 0.042023252695798874, -0.00025824809563346207, 0.0011492293560877442, -0.011923780664801598, 0.0041191657073795795, 0.0030639241449534893, -0.004941343795508146, -0.02388526313006878, 0.08410603553056717, 0.036077819764614105, -0.021517932415008545, 0.029728872701525688, -0.00003905670382664539, 0.02189294621348381, 0.05180476978421211, -0.015660153701901436, -0.01892854832112789, 0.01785983145236969, 0.01696949265897274, 0.008314548060297966, 0.020036960020661354, -0.03642347827553749, 0.05782635137438774, 0.01120854914188385, -0.012834632769227028, -0.03145735338330269, 0.002950643189251423, -0.035653598606586456, -0.03454746678471565, -0.010009034536778927, -0.00676252506673336, 0.001652811304666102, -0.04227302223443985, 0.011089825071394444, 0.00430796155706048, -0.028400013223290443, 0.005494463257491589, -0.029921067878603935, -0.01354124303907156, -0.00731296744197607, -0.01756620593369007, 0.006912298034876585, -0.01735714077949524, 0.012877033092081547, 0.06532961875200272, 0.004726686514914036, -0.005365947727113962, 0.016592662781476974, 0.0629444569349289, 0.007709018420428038, 0.039754074066877365, -0.017079899087548256, -0.04565606266260147, 0.0029784678481519222, 0.03184421360492706, -0.005679239984601736, -0.00015505672490689903, -0.044889166951179504, 0.01556659396737814, -0.003088524332270026, 0.019207527860999107, 0.034350670874118805, -0.052493125200271606, 0.016732128337025642, -0.019064446911215782, 0.010989250615239143, 0.04348355159163475, -0.004365055356174707, 0.02327447384595871, -0.05093516781926155, -0.04990537837147713, 0.012196592055261135, -0.0179707370698452, -0.0031148483976721764, -0.005050786770880222, 0.015645379200577736, 0.012545094825327396, 0.01039784587919712, -0.0189480260014534, 0.026781082153320312, -0.00802264641970396, -0.005511684808880091, -0.04444114491343498, -0.00914200022816658, -0.011234925128519535, 0.0001714288373477757, 0.004374908749014139, 0.0013939511263743043, 0.028391309082508087, -0.6603930592536926, 0.04376387968659401, -0.02062993124127388, -0.014871569350361824, -0.005690522026270628, 0.042518455535173416, 0.014273997396230698, -0.009379740804433823, -0.05325714498758316, -0.009290363639593124, 0.012271673418581486, -0.048897884786129, -0.022013751789927483, -0.02800946682691574, -0.010296767577528954, -0.005083355586975813, 0.008565258234739304, 0.0203512255102396, -0.018816640600562096, 0.008550918661057949, 0.030946504324674606, -0.03746126964688301, -0.01695244014263153, 0.009980032220482826, 0.029749613255262375, -0.03770292177796364, 0.01868230290710926, 0.031965672969818115, 0.0016774811083450913, 0.035434916615486145, -0.015777690336108208, 0.006905678194016218, 0.04120111092925072, -0.015023271553218365, 0.02684919722378254, 0.03857705369591713, 0.04624105617403984, -0.056689560413360596, -0.03068958781659603, -0.008707867003977299, 0.04159129038453102, -0.005152102094143629, 0.015666354447603226, -0.05231795832514763, -0.06727027148008347, -0.0006504040793515742, -0.004591634497046471, -0.0054963272996246815, -0.021352039650082588, 0.014608891680836678, -0.04765446111559868, -0.020088642835617065, 0.024063698947429657, -0.021395282819867134, -0.04017285630106926, -0.0243788193911314, -0.011098785325884819, 0.038473859429359436, 0.0034758152905851603, 0.011918592266738415, 0.001919288421049714, 0.003487467532977462, -0.011501513421535492, 0.034361619502305984, 0.00824668351560831, 0.02901466004550457, 0.054638199508190155, -0.09843802452087402, -0.009849326685070992, 0.014945884235203266, -0.014344989322125912, 0.0018881568685173988, 0.012028591707348824, 0.016200419515371323, 0.028080498799681664, -0.005611158441752195, -0.054813530296087265, -0.004426171537488699, -0.012351501733064651, -0.060860518366098404, 0.025370068848133087, -0.015761839225888252, -0.03434718772768974, 0.009711399674415588, -0.005086603108793497, -0.03663826733827591, 0.015699002891778946, 0.015407424420118332, 0.005338829476386309, -0.03249542415142059, 0.026886222884058952, -0.0030634033028036356, 0.03688853234052658, 0.005941771436482668, -0.02124861441552639, -0.004344313405454159, -0.0247697364538908, 0.03809798136353493, -0.025196293368935585, -0.007809384725987911, -0.049319636076688766, -0.023825984448194504, -0.0058343373239040375, 0.005449001211673021, 0.009653865359723568, 0.0006270911544561386, -0.06904120743274689, -0.012560050003230572, 0.0660829246044159, -0.01506824977695942, 0.01839703507721424, -0.0005669941892847419, -0.00294190039858222, 0.03112172894179821, 0.004270823672413826, 0.01647566445171833, -0.024660564959049225, -0.048816874623298645, 0.023402120918035507, 0.012303551658987999, -0.021078018471598625, 0.043272197246551514, -0.016564125195145607, -0.03540463000535965, -0.008498516865074635, 0.037547480314970016, 0.00033802512916736305, -0.028022250160574913, 0.03881166875362396, 0.01348975021392107, -0.025973232463002205, 0.00032737519359216094, 0.006909198593348265, 0.004564316943287849, 0.012285619042813778, 0.0058009629137814045, -0.003803541185334325, -0.01010784599930048, 0.017318136990070343, -0.017963102087378502, -0.07516536861658096, -0.021228140220046043, 0.005205218680202961, -0.030669527128338814, 0.02409132942557335, 0.00248245638795197, 0.03328597918152809, -0.03378244489431381, -0.03640204295516014, -0.00006347711314447224, 0.0073214126750826836, 0.0032003959640860558, 0.021534966304898262, -0.01259147934615612, -0.045942049473524094, 0.01688201352953911, 0.011755917221307755, -0.00024241440405603498, 0.030943991616368294, 0.04343430697917938, 0.00009163966751657426, 0.021606741473078728, 0.04682891443371773, -0.018910260871052742, -0.011243566870689392, -0.009581071324646473, 0.0013039319310337305, 0.04727661982178688, -0.001267903600819409, 0.03306451812386513, 0.031118862330913544, 0.03818926215171814, -0.0046255625784397125, 0.021763741970062256, 0.0010664951987564564, 0.01130612287670374, -0.013517032377421856, -0.015891024842858315, -0.04913259297609329, 0.017849188297986984, -0.00005898767267353833, -0.005992267746478319, -0.00920962356030941, 0.012964778579771519, -0.0066528841853141785, 0.002131921239197254, 0.02791912481188774, -0.012968580238521099, -0.006403775420039892, -0.03583531826734543, 0.05973353981971741, 0.028019459918141365, -0.024364717304706573, -0.032555945217609406, -0.08615066111087799, -0.02436397597193718, -0.03755045682191849, -0.052955836057662964, -0.027430007234215736, 0.01530561875551939, -0.007486935239285231, 0.001960459630936384, -0.008329351432621479, -0.020862484350800514, 0.01976558193564415, 0.0501338429749012, 0.012241614051163197, -0.01899239420890808, 0.03886905685067177, 0.016763316467404366, 0.025786586105823517, -0.0224591251462698, 0.0013177039800211787, -0.024670226499438286, -0.020062442868947983, 0.037603285163640976, -0.05306025221943855, -0.0332006961107254, 0.06069814786314964, -0.01703442633152008, 0.008261137641966343, -0.033037833869457245, -0.020311029627919197, 0.018933234736323357, 0.0014378104824572802, 0.00950431264936924, -0.012040426023304462, 0.002710933331400156, -0.023255201056599617, 0.021090563386678696, -0.00040723118581809103, 0.029146572574973106, 0.009053459390997887, -0.016909705474972725, -0.008366054855287075, 0.024751530960202217, 0.007758140563964844, -0.03489500284194946, 0.008564351126551628, -0.008196549490094185, 0.029016705229878426, -0.013327146880328655, -0.012112614698708057, 0.03016539104282856, -0.027381379157304764, -0.011735480278730392, -0.01802259124815464, -0.004885289818048477, -0.019852744415402412, -0.0385524146258831, -0.0034686680883169174, 0.05820590257644653, 0.024324344471096992, 0.018085092306137085, 0.014897007495164871, -0.026401231065392494, -0.009932153858244419, -0.01148427464067936, 0.012102840468287468, 0.015971090644598007, -0.014205862767994404, -0.03522343561053276, 0.012461741454899311, -0.007713291794061661, 0.010305664502084255, 0.0022793286480009556, 0.02997015044093132, -0.0053865122608840466, 0.01757741905748844, 0.04632815718650818, 0.032773204147815704, -0.003940198104828596, 0.008088662289083004, 0.003154193749651313, 0.01563895493745804, -0.0393046997487545, 0.03066125698387623, -0.0024763839319348335, 0.02229945734143257, 0.006133907474577427, -0.03713337332010269, -0.02942832186818123, 0.026595011353492737, 0.021030891686677933, 0.006237821187824011, 0.033052947372198105, -0.0035112006589770317, -0.0011991767678409815, -0.04035339504480362, -0.007617397699505091, 0.0028831849340349436, -0.010943833738565445, 0.04233843460679054, -0.03402108699083328, 0.004375021439045668, 0.015209187753498554, 0.006450410932302475, 0.014753106981515884, 0.023082341998815536, 0.003209341550245881, 0.048231933265924454, -0.010455035604536533, -0.008959227241575718, -0.02092333696782589, 0.009089183993637562, -0.032091084867715836, -0.00993218831717968, 0.009942621923983097, 0.0208328515291214, 0.06441012769937515, 0.02920103445649147, 0.002852334640920162, -0.013578301295638084, 0.015959611162543297, 0.004923425614833832, 0.013761032372713089, 0.0459938645362854, -0.01388528198003769, 0.04352390393614769, 0.02477508969604969, -0.024027131497859955, 0.0020269376691430807, 0.010602034628391266, -0.009096875786781311, -0.0014148186892271042, 0.014513777568936348, -0.01941131241619587, -0.03806154802441597, -0.044474877417087555, 0.020808177068829536, -0.028084836900234222, -0.03139598295092583, -0.011180132627487183, 0.019616177305579185, 0.017940761521458626, -0.0025575540494173765, 0.04388374090194702, 0.03362179175019264, 0.02142251469194889, -0.0026192194782197475, -0.0019627336878329515, 0.002135688904672861, 0.021890519186854362, -0.037028852850198746, -0.004528386052697897, -0.0034336503595113754, 0.039470162242650986, 0.003802135121077299, 0.03070068173110485, 0.0377182811498642, -0.01220619399100542, 0.0041933609172701836, 0.04240598529577255, 0.03581481799483299, -0.007902414537966251, -0.0056344554759562016, 0.011351285502314568, -0.017787422984838486, 0.00635288143530488, 0.00778005039319396, -0.025377539917826653, -0.000721517251804471, -0.0046804822050035, 0.03179674968123436, -0.004553625825792551, 0.012418144382536411, 0.0012359321117401123, 0.02834688313305378, -0.008297469466924667, 0.04190845787525177, -0.006140857934951782, -0.034006379544734955, -0.018426688387989998, 0.009576475247740746, 0.010838242247700691, 0.03389273211359978, 0.011030781082808971, -0.032583609223365784, -0.0025357012636959553, -0.019006093963980675, -0.0032324539497494698, -0.05758936330676079, 0.03848123550415039, 0.031404394656419754, -0.00528503954410553, -0.002979181008413434, 0.010537619702517986, 0.01605799049139023, -0.052047207951545715, -0.035075146704912186, 0.03297538682818413, 0.01728832721710205, -0.0036179348826408386, 0.009328174404799938, -0.037668947130441666, -0.0011370661668479443, -0.011960496194660664, 0.010251377709209919, 0.018843796104192734, -0.006038106977939606, 0.023057788610458374, 0.009969068691134453, -0.014122718013823032, 0.025627052411437035, -0.00002271153607580345, -0.03234359622001648, 0.026482529938220978, -0.021608876064419746, 0.003315376816317439, -0.017403416335582733, 0.028741823509335518, 0.00021985580679029226, -0.03720780462026596, -0.008000858128070831, -0.015007343143224716, 0.036244891583919525, -0.010712731629610062, -0.014560261741280556, 0.026797812432050705, 0.04085876792669296, -0.047849349677562714, -0.014689241535961628, -0.002268460113555193, 0.006981599144637585, 0.03106670454144478, -0.0610836036503315, -0.004051483701914549, 0.004926330875605345, -0.01815786212682724, -0.00013009784743189812, 0.018354931846261024, 0.016800960525870323, -0.04978753626346588, 0.021675031632184982, 0.022381076589226723, -0.023469727486371994, 0.02173423394560814, -0.06496412307024002, -0.03584620729088783, 0.012693848460912704, 0.025683213025331497, 0.013882187195122242, 0.03604647517204285, -0.02938886545598507, 0.013926884159445763, -0.07489573955535889, 0.025336533784866333, 0.005219913553446531, -0.0052233184687793255, 0.009650593623518944, 0.007588611915707588, 0.011039391160011292, 0.011260886676609516, 0.029471658170223236, 0.01804710179567337, 0.03560205549001694, 0.04528983309864998, 0.04455456882715225, 0.0289866104722023, 0.013844369910657406, -0.00854976661503315, 0.008251221850514412, 0.0032285740599036217, 0.007365258876234293, 0.00631760573014617, 0.05903700739145279, 0.01234882790595293, -0.00860410463064909, -0.00968555174767971, -0.003680905792862177, -0.06168234720826149, 0.03470665588974953, -0.00285212229937315, 0.0236495453864336, -0.0005224782507866621, -0.02617630548775196, 0.0026435772888362408, 0.0020128826145082712, -0.00780175207182765, -0.00786565337330103, -0.05946177616715431, 0.0115347970277071, 0.021415749564766884, 0.01162568386644125, 0.018553193658590317, 0.02076742798089981, 0.00546412356197834, 0.015634693205356598, -0.01684127375483513, 0.010852874256670475, -0.04629388451576233, -0.045266564935445786, 0.005840064957737923, -0.0022817268036305904, 0.021660052239894867, -0.04568646475672722, 0.053057678043842316, 0.016280047595500946, 0.04249156266450882, 0.004172412678599358, 0.006677803583443165, -0.009505527094006538, 0.011778018437325954, -0.0245650764554739, -0.011430478654801846, 0.021765677258372307, 0.060368239879608154, 0.04852386191487312, -0.030656693503260612, -0.02195589989423752, -0.0013516013277694583, -0.004957712255418301, 0.010660606436431408, -0.008570651523768902, 0.06222603842616081, -0.018399352207779884, 0.014350855723023415, -0.06126970052719116, -0.006511675659567118, -0.0008247166988439858, 0.012391668744385242, 0.010710143484175205, 0.006717313546687365, -0.0017747177043929696, 0.002699034521356225, -0.02472323551774025, -0.03016401268541813, 0.06356001645326614, 0.0035106102004647255, 0.0704963281750679, -0.01736309938132763, -0.01588328927755356, -0.024656185880303383, 0.018788587301969528, 0.0013788865180686116, -0.05895794928073883, 0.04834633320569992, 0.04095358029007912, -0.03545108065009117, -0.021617038175463676, 0.04221376031637192, -0.006090796086937189, -0.02647019922733307, -0.032524701207876205, -0.030470028519630432, -0.01541983149945736, -0.007180198561400175, -0.004427832085639238, -0.011873042210936546, -0.024131817743182182, 0.019063789397478104, 0.04561276361346245, 0.01553766243159771, -0.010493938811123371, -0.015895068645477295, -0.0021939880680292845, -0.007687969598919153, 0.08207287639379501, -0.005971717648208141, -0.024383114650845528, -0.010475097224116325, 0.021370334550738335 ]
8ac2e2407dd1965a468039faf082dce81ec81f6c
109
py
Python
realfastapi/routes/endpoints/default.py
wborbajr/RealFastAPI
d97ca994c4c164387632cda814e80c026435a9f7
[ "MIT" ]
null
null
null
realfastapi/routes/endpoints/default.py
wborbajr/RealFastAPI
d97ca994c4c164387632cda814e80c026435a9f7
[ "MIT" ]
null
null
null
realfastapi/routes/endpoints/default.py
wborbajr/RealFastAPI
d97ca994c4c164387632cda814e80c026435a9f7
[ "MIT" ]
null
null
null
from fastapi import APIRouter router = APIRouter() @router.get("/") def working(): return {"Working"}
12.111111
29
0.669725
1
0.6561
[ 0.003120163455605507, 0.02451746165752411, 0.010237658396363258, 0.001087332610040903, 0.004538551438599825, -0.0033290113788098097, -0.01111431885510683, 0.0054305545054376125, -0.007355468813329935, -0.003444432048127055, 0.0032032649032771587, 0.0034005555789917707, 0.008020665496587753, -0.017211591824889183, 0.002771013416349888, 0.0148432282730937, -0.05609741434454918, 0.003491091774776578, -0.004671906121075153, 0.002254398772493005, -0.006653105840086937, 0.01063276082277298, 0.009202677756547928, 0.00736331008374691, 0.00503957737237215, 0.003929707687348127, 0.010446485131978989, 0.004881296772509813, -0.0071721263229846954, -0.00669822795316577, 0.00007028027903288603, -0.0030244067311286926, -0.0011648721992969513, -0.007448103744536638, 0.00811471976339817, -0.0022644889540970325, 0.0023902803659439087, -0.018706418573856354, 0.008549205027520657, -0.008559059351682663, -0.007095479406416416, -0.020138701424002647, -0.0023582077119499445, 0.00450077885761857, -0.016786988824605942, 0.001453077420592308, -0.003556820098310709, 0.003523807739838958, -0.011698566377162933, 0.007400733418762684, -0.011939353309571743, 0.006283212918788195, 0.015437958762049675, 0.0008755892631597817, -0.004384611267596483, -0.0076200878247618675, 0.010391294956207275, -0.0011404587421566248, -0.014757364988327026, 0.0016315019456669688, -0.004699696786701679, -0.006056840997189283, 0.0039024853613227606, 0.005086816847324371, -0.021275365725159645, -0.005299767944961786, -0.003184319706633687, 0.001036754809319973, -0.0035902599338442087, 0.006165734492242336, 0.00018628245743457228, -0.0029216280672699213, 0.009022803045809269, 0.002981010591611266, 0.0048793889582157135, -0.00390787934884429, -0.00026067515136674047, 0.004578826949000359, 0.00799944531172514, 0.0019817857537418604, 0.006226977799087763, -0.012308920733630657, 0.006228918209671974, 0.012949858792126179, 0.012078075669705868, 0.010656405240297318, 0.02026958018541336, -0.009595855139195919, 0.042873430997133255, 0.007319193333387375, -0.007138361223042011, 0.0009797537932172418, -0.009803308174014091, -0.0016977150226011872, -0.001602865057066083, -0.034024231135845184, -0.0017560080159455538, -0.007268181070685387, -0.0018366771982982755, 0.0025568418204784393, 0.0007259194389916956, 0.004340057726949453, -0.003501300001516938, -0.003600678639486432, -0.011317095719277859, 0.015024123713374138, -0.00942983478307724, -0.0015990177635103464, 0.007712469901889563, 0.004811854567378759, -0.013557666912674904, -0.0013596316566690803, 0.00588242057710886, -0.012026225216686726, 0.006466562859714031, 0.0016854641726240516, -0.006570067722350359, 0.05956187844276428, 0.0015987599035724998, 0.0012801855336874723, -0.00476112449541688, -0.006203033495694399, 0.001214336953125894, 0.00852811150252819, 0.010253732092678547, -0.004327503964304924, 0.014051253907382488, 0.005987089592963457, 0.006366903427988291, 0.007142896763980389, 0.0020529262255877256, 0.01454591378569603, -0.004427719861268997, -0.0006005144095979631, 0.0007790608215145767, -0.007743662688881159, 0.009966018609702587, 0.0001907273690449074, -0.00532436091452837, -0.002679904457181692, -0.0037534141447395086, -0.011766859330236912, 0.0009503709152340889, -0.0020255777053534985, -0.0014984257286414504, -0.015216127969324589, -0.0040245670825243, -0.0006797099485993385, -0.004859226290136576, 0.0030607683584094048, 0.005427510477602482, 0.0032733369152992964, -0.00006972642586333677, -0.004529313649982214, -0.009017080999910831, -0.002930007642135024, -0.005175890401005745, 0.002239936264231801, 0.00999868381768465, 0.0038004713132977486, -0.005333086475729942, -0.002091747708618641, 0.00461647380143404, 0.00524811539798975, 0.00015728628204669803, -0.0009838868863880634, -0.005835792049765587, 0.009468935430049896, 0.0007287163753062487, 0.003036214504390955, 0.010294614359736443, -0.005938373971730471, -0.00045592940296046436, -0.0028182193636894226, 0.00021324459521565586, -0.0004234148364048451, 0.0038755834102630615, 0.009518462233245373, -0.007286551408469677, -0.005831599235534668, 0.004427421372383833, 0.002793053863570094, 0.011503682471811771, 0.012253990396857262, -0.0010726976906880736, 0.002528591314330697, -0.00034963959478773177, -0.0006482235621660948, 0.004489374812692404, -0.006372473202645779, 0.007076222449541092, 0.007642320357263088, -0.014502867124974728, -0.003426589071750641, 0.0018900762079283595, -0.012473723851144314, -0.0003490590024739504, 0.015399720519781113, 0.00878018420189619, -0.0009085912024602294, 0.002096829004585743, -0.012405662797391415, 0.0002090133639285341, 0.006143984850496054, 0.003104980569332838, -0.01198435015976429, -0.9528475999832153, 0.0031082606874406338, 0.0034825128968805075, -0.001334952306933701, 0.0027883569709956646, 0.0016226180596277118, 0.0025319380220025778, 0.0058695124462246895, 0.014998042955994606, -0.012140159495174885, -0.007776764687150717, -0.009216845035552979, -0.011273669078946114, -0.0004945123218931258, -0.007557468954473734, -0.005361117422580719, -0.008238580077886581, -0.007762669585645199, -0.0037461461033672094, -0.0041586291044950485, -0.0023752679117023945, 0.011149967089295387, -0.00044678262202069163, 0.0035691289231181145, 0.004085106775164604, 0.002297536935657263, -0.004859628155827522, 0.0021014846861362457, 0.0022800336591899395, -0.000901270832400769, -0.004173037596046925, -0.015919756144285202, -0.005534195341169834, -0.001401086337864399, 0.013160809874534607, -0.005491189658641815, 0.0077917445451021194, -0.0015630765119567513, 0.004191736225038767, -0.008145447820425034, 0.008328915573656559, 0.0014111442724242806, 0.0030581525061279535, -0.03227423131465912, 0.001940871006809175, -0.002244943520054221, -0.00743085565045476, 0.010430865921080112, -0.0004903076915070415, 0.0011278091697022319, -0.0013598761288449168, -0.003340979339554906, 0.010991699062287807, -0.008728147484362125, 0.0033951783552765846, -0.007134060841053724, -0.0035580159164965153, -0.003092298051342368, -0.011154383420944214, 0.0011497673112899065, 0.00394292501732707, -0.0006907751085236669, -0.004142894875258207, -0.0030279173515737057, 0.004973703529685736, 0.0007791019161231816, -0.0010816633002832532, -0.019930876791477203, -0.004482578951865435, -0.0032099608797580004, 0.0014062803238630295, -0.0022753861267119646, -0.0013116429327055812, 0.002336747944355011, -0.010514040477573872, 0.0072736237198114395, 0.003612902946770191, 0.0023676727432757616, -0.012445486150681973, 0.002636595629155636, -0.005653743166476488, -0.013186633586883545, 0.004157832823693752, -0.0057375142350792885, -0.0023528633173555136, 0.0012146162334829569, 0.006210047751665115, 0.010750317946076393, -0.002948237583041191, 0.002081973711028695, 0.013007357716560364, -0.0029929724987596273, -0.008592160418629646, 0.010358783416450024, 0.006456863600760698, 0.0018332784529775381, -0.0018173931166529655, 0.0036475704982876778, 0.008625408634543419, 0.005734093952924013, 0.00038429145934060216, 0.005497629754245281, -0.0003824796003755182, 0.012886631302535534, 0.0004699978162534535, 0.006368580274283886, 0.00017274175479542464, -0.001794168958440423, -0.0037548665422946215, -0.0006787086604163051, -0.004499910399317741, -0.0009072615648619831, -0.012291640043258667, -0.012040233239531517, -0.005302730947732925, 0.0019677123054862022, 0.0009171790443360806, -0.003203439060598612, 0.0008788724662736058, 0.002636639168485999, 0.009617270901799202, 0.002694597700610757, -0.0034528758842498064, 0.005126369651407003, 0.0027950420044362545, -0.006433403585106134, 0.016220327466726303, -0.012721988372504711, 0.0041532497853040695, -0.0017900173552334309, -0.01603577472269535, 0.008424309082329273, 0.009380600415170193, -0.0058451867662370205, 0.0030004577711224556, 0.005021332297474146, 0.004878352861851454, -0.0016096349572762847, -0.0051555391401052475, -0.003934652078896761, -0.01676693931221962, 0.0001929883292177692, 0.02324456162750721, 0.0048856413923203945, 0.009568534791469574, 0.01270329300314188, -0.0018158850725740194, 0.003166407346725464, 0.008586793206632137, 0.002104572718963027, 0.016144748777151108, -0.008989314548671246, -0.000068019719037693, 0.0009244900429621339, -0.007417129818350077, 0.002237703651189804, 0.0029913170728832483, 0.0025650307070463896, -0.0024827057495713234, 0.0022944447118788958, -0.005021119024604559, -0.0038107410073280334, -0.018002882599830627, -0.0006871377700008452, 0.004055325407534838, -0.004036722704768181, 0.0014234732370823622, -0.012105847708880901, 0.0043404120951890945, 0.006199527531862259, 0.0016413351986557245, 0.00039323465898633003, 0.0014540376141667366, 0.0055343289859592915, 0.012235233560204506, -0.007104818243533373, 0.006480596959590912, 0.002399768214672804, 0.0016431137919425964, 0.007284386083483696, 0.008013799786567688, -0.009527130052447319, -0.0069707175716757774, 0.005230213049799204, 0.0028575523756444454, -0.0006826656754128635, -0.0043688747100532055, -0.010100316256284714, -0.003799658501520753, 0.004990566521883011, -0.0055376277305185795, 0.005116175394505262, 0.006144371815025806, 0.0038129829335957766, -0.006604122929275036, 0.0015272869495674968, -0.0032482135575264692, -0.008733537048101425, 0.007902141660451889, -0.004262183792889118, 0.003918624948710203, 0.012513392604887486, 0.002044114749878645, -0.011953315697610378, 0.0076089464128017426, 0.007099970709532499, -0.008095720782876015, 0.005316615104675293, 0.005923186428844929, -0.007690769620239735, -0.02415844239294529, 0.0004852993006352335, -0.01594727113842964, 0.008537323214113712, -0.004611621610820293, 0.0016049944097176194, -0.009105068631470203, 0.008395669981837273, 0.002047767164185643, -0.013113580644130707, -0.0005060716648586094, -0.010070235468447208, 0.007319134660065174, -0.0017022911924868822, -0.0023033199831843376, -0.0040564946830272675, -0.0009220426436513662, -0.0030170446261763573, -0.006406520027667284, 0.0018679428612813354, 0.00377003476023674, 0.0017703042831271887, -0.0039239623583853245, 0.0024498673155903816, -0.003998507279902697, -0.0019799249712377787, 0.0009366594022139907, -0.01238687802106142, 0.0004688231856562197, 0.005944397766143084, -0.003360394388437271, -0.0036153739783912897, -0.0008302481146529317, 0.000360898528015241, -0.007386269047856331, -0.011168545112013817, -0.0029494857881218195, -0.005990985780954361, -0.002592005068436265, -0.010277818888425827, -0.0020823716185986996, -0.005310847423970699, 0.006778085604310036, -0.005349643062800169, 0.008739770390093327, 0.00585284223780036, -0.005568145774304867, 0.006536897737532854, -0.0004820070753339678, 0.0039013861678540707, 0.0047014812007546425, 0.006594087928533554, -0.0012865228345617652, -0.006061410531401634, -0.011720477603375912, 0.009729348123073578, -0.008879701606929302, -0.0020798302721232176, 0.013908278197050095, 0.004994228947907686, 0.009123668074607849, 0.0018974952399730682, -0.0002786084951367229, 0.003177669132128358, 0.008471822366118431, -0.01670309156179428, 0.0007313507958315313, 0.00020503942505456507, 0.0007346961065195501, 0.0067940447479486465, -0.004500428680330515, 0.005687714088708162, 0.00915488786995411, 0.0031511823181062937, -0.008235824294388294, -0.0021822182461619377, -0.001635851338505745, 0.0043341731652617455, -0.01364208571612835, -0.003228606656193733, -0.00754478620365262, -0.0010447305394336581, -0.004933280870318413, -0.006051624193787575, -0.001618129899725318, 0.008346157148480415, -0.0019249033648520708, 0.007298927288502455, 0.0005908877355977893, -0.001088924240320921, 0.015871645882725716, -0.0019861680921167135, -0.007306660991162062, 0.0019531873986124992, 0.0033944069873541594, -0.00011251995601924136, -0.0091974763199687, -0.0016638999804854393, 0.0014644351322203875, 0.0036509817000478506, -0.000045216733269626275, -0.01243510376662016, -0.00493984529748559, 0.0014177158009260893, -0.00767358485609293, 0.0011828817659989, 0.008384346030652523, 0.0017755836015567183, 0.0029006637632846832, 0.00043331022607162595, -0.007831051014363766, -0.014611110091209412, 0.053391698747873306, -0.002997542731463909, 0.004956624936312437, 0.005154750309884548, -0.007921830751001835, -0.0012845615856349468, -0.0034534307196736336, 0.004967587534338236, -0.0043918234296143055, -0.005766141228377819, 0.009084347635507584, -0.0006096402648836374, 0.00249684345908463, 0.00027447083266451955, -0.004665375221520662, 0.016807598993182182, -0.0063856844790279865, -0.017706306651234627, -0.0193287655711174, 0.009752782061696053, -0.003998126834630966, -0.00899181142449379, 0.006949924398213625, -0.004015439189970493, -0.0031284152064472437, 0.003025252604857087, 0.008138378150761127, 0.0005565419560298324, 0.00048014993080869317, -0.00316432467661798, -0.0010757544077932835, 0.00004668638212024234, 0.003334753680974245, 0.004875218495726585, 0.008885125629603863, -0.0028385240584611893, 0.0046637337654829025, -0.0014938981039449573, -0.0023265487980097532, 0.0021827840246260166, 0.005630567669868469, 0.008146987296640873, -0.0005627189530059695, -0.0025583708193153143, 0.005863197147846222, 0.005392563994973898, -0.002372030634433031, 0.014024108648300171, 0.002362355124205351, -0.005199294071644545, 0.01128000020980835, 0.008655930869281292, -0.00008250934479292482, 0.0058971247635781765, -0.0017722166376188397, 0.004018208011984825, -0.001446600304916501, -0.006409773137420416, -0.012111127376556396, -0.0009559007012285292, 0.0026534507051110268, 0.006208438891917467, -0.00010441373160574585, 0.0063821617513895035, -0.0011064186692237854, -0.004296557977795601, -0.009984027594327927, -0.0071422988548874855, -0.002368274377658963, -0.0007334426627494395, 0.0032689268700778484, 0.07125670462846756, -0.007546200416982174, -0.0021625137887895107, -0.009562375023961067, 0.0007787462673150003, 0.00022924110817257315, 0.0002626660862006247, -0.00009800485713640228, -0.0016915181186050177, 0.0012845104793086648, 0.005192462354898453, -0.007982410490512848, -0.01116443146020174, -0.0015185795491561294, 0.003946495708078146, -0.0009271158487536013, 0.0048914141952991486, 0.005227893125265837, -0.011046335101127625, 0.0033366966526955366, -0.011153487488627434, -0.00646784296259284, -0.0051150997169315815, -0.007578528951853514, -0.006496628746390343, -0.001396080362610519, 0.0018942744936794043, 0.006222839932888746, 0.0031153422314673662, -0.004822895396500826, 0.0032690437510609627, 0.0007593808113597333, 0.003876994363963604, -0.0032465425319969654, -0.0021647438406944275, -0.003920149523764849, 0.004878341220319271, 0.0021555726416409016, -0.010626615025103092, -0.007108983118087053, -0.004806777462363243, -0.0003254651091992855, -0.00590058509260416, 0.0070359488017857075, -0.001563290599733591, 0.00918549858033657, -0.0026981739792972803, -0.0004584776470437646, -0.004983215592801571, -0.00031449715606868267, -0.015508347190916538, 0.0036957431584596634, -0.186852365732193, 0.010826054029166698, 0.0025261694099754095, -0.0021248364355415106, -0.0033927136100828648, -0.016136987134814262, -0.006960361730307341, 0.005469941534101963, 0.009758442640304565, 0.001545810722745955, 0.000527000695001334, -0.001804141327738762, 0.0048943269066512585, 0.005034423898905516, -0.0020172849763184786, -0.004101480823010206, 0.0018980426248162985, -0.0017819273052737117, -0.0011158975539729, 0.006160575896501541, 0.0040899962186813354, 0.008834154345095158, 0.0017349902773275971, 0.000753776403144002, -0.002578119048848748, -0.00309908133931458, 0.003985103685408831, -0.0031618233770132065, 0.005191515665501356, -0.01051285769790411, -0.004791553597897291, -0.003823860315605998, -0.007064508739858866, 0.004417350981384516, 0.005099033936858177, -0.001217493205331266, 0.008341780863702297, 0.0008446319261565804, -0.008416731841862202, 0.006340221501886845, -0.008977362886071205, 0.031786516308784485, 0.004593869671225548, 0.007870443165302277, -0.0019360474543645978, -0.003228943096473813, -0.0028219190426170826, 0.009302502498030663, 0.0019870365504175425, 0.012022233568131924, -0.009991663508117199, -0.008105292916297913, 0.001509278081357479, 0.019744517281651497, -0.005960552953183651, -0.008004367351531982, -0.008648927323520184, -0.005559844896197319, 0.008346851915121078, 0.010639200918376446, 0.010922785848379135, -0.005855688359588385, 0.007763476110994816, -0.0053148348815739155, -0.023544179275631905, 0.005597337149083614, -0.002647607820108533, -0.008998248726129532, 0.002782764844596386, 0.005168855655938387, 0.011140964925289154, -0.0033120804000645876, 0.006871537771075964, -0.0007748900097794831, 0.0022575415205210447, -0.00489385100081563, 0.00935115572065115, -0.0052549163810908794, 0.005586142186075449, -0.008611094206571579, 0.011787078343331814, -0.00924114603549242, -0.0017152582295238972, 0.001334414817392826, -0.005406294483691454, 0.011390168219804764, 0.00675206957384944, -0.002159798750653863, 0.0009299169178120792, -0.011297506280243397, -0.0019314972450956702, -0.0003230313886888325, 0.0035868093837052584, -0.00995205994695425, 0.00353432958945632, -0.0029197309631854296, 0.004550969693809748, 0.010970357805490494, -0.00887006800621748, 0.005291772074997425, 0.004721144214272499, -0.008502880111336708, 0.000010068783012684435, -0.006755230948328972, -0.0007875053561292589, 0.003636779962107539, -0.008059279061853886, -0.009024888277053833, 0.004766939673572779, -0.006918288767337799, -0.0048952531069517136, 0.004656056873500347, -0.010870450176298618, -0.006478139199316502, 0.0012333797058090568, -0.014085961505770683, 0.0016901957569643855 ]
8ac30fc95afe68d34f716111b4aac384fefa954a
2,291
py
Python
graphzoom/embed_methods/dgi/execute.py
junhoher/GraphZoom
5073b49a34badf7bc6c25bd2a6cc6c78b4ee7d5a
[ "MIT" ]
16
2019-10-18T06:31:29.000Z
2021-09-23T12:46:19.000Z
graphzoom/embed_methods/dgi/execute.py
junhoher/GraphZoom
5073b49a34badf7bc6c25bd2a6cc6c78b4ee7d5a
[ "MIT" ]
7
2019-10-18T06:36:32.000Z
2022-02-10T01:37:04.000Z
graphzoom/embed_methods/dgi/execute.py
junhoher/GraphZoom
5073b49a34badf7bc6c25bd2a6cc6c78b4ee7d5a
[ "MIT" ]
4
2019-11-15T12:47:11.000Z
2021-02-15T07:26:24.000Z
import numpy as np import scipy.sparse as sp import torch import torch.nn as nn import networkx as nx import time from embed_methods.dgi.models import DGI, LogReg from embed_methods.dgi.utils import process def dgi(G, features): batch_size = 1 nb_epochs = 10000 patience = 20 lr = 0.001 l2_coef = 0.0 drop_prob = 0.0 hid_units = 512 sparse = True nonlinearity = 'prelu' # special name to separate parameters adj = nx.to_scipy_sparse_matrix(G, weight='wgt') features = sp.lil_matrix(np.matrix(features)) features, _ = process.preprocess_features(features) nb_nodes = features.shape[0] ft_size = features.shape[1] adj = process.normalize_adj(adj + sp.eye(adj.shape[0])) if sparse: sp_adj = process.sparse_mx_to_torch_sparse_tensor(adj) else: adj = (adj + sp.eye(adj.shape[0])).todense() features = torch.FloatTensor(features[np.newaxis]) if not sparse: adj = torch.FloatTensor(adj[np.newaxis]) model = DGI(ft_size, hid_units, nonlinearity) optimiser = torch.optim.Adam(model.parameters(), lr=lr, weight_decay=l2_coef) if torch.cuda.is_available(): print('Using CUDA') model.cuda() features = features.cuda() if sparse: sp_adj = sp_adj.cuda() else: adj = adj.cuda() b_xent = nn.BCEWithLogitsLoss() xent = nn.CrossEntropyLoss() cnt_wait = 0 best = 1e9 best_t = 0 for epoch in range(nb_epochs): model.train() optimiser.zero_grad() idx = np.random.permutation(nb_nodes) shuf_fts = features[:, idx, :] lbl_1 = torch.ones(batch_size, nb_nodes) lbl_2 = torch.zeros(batch_size, nb_nodes) lbl = torch.cat((lbl_1, lbl_2), 1) if torch.cuda.is_available(): shuf_fts = shuf_fts.cuda() lbl = lbl.cuda() logits = model(features, shuf_fts, sp_adj if sparse else adj, sparse, None, None, None) loss = b_xent(logits, lbl) print('Loss:', loss) if loss < best: best = loss best_t = epoch cnt_wait = 0 else: cnt_wait += 1 if cnt_wait == patience: print("epochs: ", epoch) print('Early stopping!') break loss.backward() optimiser.step() return (((model.embed(features, sp_adj if sparse else adj, sparse, None)[0]).squeeze()).data).cpu().numpy()
24.634409
109
0.656482
1
1.5756
[ 0.0011719551403075457, 0.02387549728155136, 0.008622237481176853, 0.00009835358650889248, 0.004306241869926453, -0.0025308425538241863, -0.007768726907670498, 0.0033998959697782993, -0.005554684903472662, 0.0018473529489710927, 0.002034696750342846, 0.004715976770967245, 0.008242730051279068, -0.01691749319434166, -0.0006500913295894861, 0.016648808494210243, -0.05255064740777016, 0.005046700593084097, -0.004670407623052597, 0.0031715957447886467, -0.008275900036096573, 0.008423352614045143, 0.00927030947059393, 0.007989431731402874, 0.004111810587346554, -0.0003743981069419533, 0.01021980307996273, 0.0007031219429336488, -0.007937923073768616, -0.005836868658661842, -0.001665472169406712, -0.0017999905394390225, -0.008040571585297585, -0.006566041149199009, 0.006212487351149321, -0.0034073065035045147, 0.002198572037741542, -0.018955932930111885, 0.011493024416267872, -0.005487942602485418, -0.005205872468650341, -0.014605929143726826, 0.0010663141729310155, 0.003310881555080414, -0.008478823117911816, 0.0014157695695757866, -0.005150908604264259, 0.001140019972808659, -0.008938059210777283, 0.006036065053194761, -0.008826209232211113, 0.006292732432484627, 0.014345570467412472, 0.0038006312679499388, -0.006233322434127331, -0.007951539009809494, 0.012861023657023907, 0.0013351686066016555, -0.010364641435444355, -0.0005667301593348384, -0.003314824542030692, -0.001327006728388369, 0.005539389792829752, 0.0026823661755770445, -0.014379492029547691, -0.00839630514383316, -0.005392381921410561, 0.0027288985438644886, -0.001127959811128676, 0.006617033388465643, 0.003053880063816905, -0.0003653073508758098, 0.007238612975925207, 0.0037914521526545286, 0.00421013031154871, -0.0048691644333302975, -0.00267369975335896, 0.0017907865112647414, 0.008990835398435593, 0.0036352030001580715, 0.0028814321849495173, -0.005620717536658049, 0.004545025061815977, 0.011983458884060383, 0.01685815304517746, 0.008059793151915073, 0.018990660086274147, -0.010784592479467392, 0.04649140685796738, 0.007115934044122696, -0.009258207865059376, 0.0027008980978280306, -0.010261776857078075, -0.001218147692270577, -0.001868381747044623, -0.02802114002406597, -0.000115139817353338, -0.00479015102609992, -0.00016053643776103854, 0.0011206662748008966, 0.0010684933513402939, 0.00790167972445488, -0.00047554392949678004, -0.005586431827396154, -0.008082590997219086, 0.009863387793302536, -0.008959928527474403, -0.004105321131646633, 0.007264925166964531, 0.00415829848498106, -0.0104494858533144, -0.0006249594734981656, 0.0011688856175169349, -0.012723106890916824, 0.002901938511058688, 0.004235391039401293, -0.005860092584043741, 0.053621284663677216, -0.002856980310752988, 0.002587527735158801, -0.00629320228472352, 0.0005774776800535619, 0.0023154974915087223, 0.006066306959837675, 0.009575439617037773, -0.004306928254663944, 0.012300732545554638, 0.009353470988571644, 0.0035844449885189533, 0.00927147176116705, -0.0036020891275256872, 0.0061282929964363575, -0.0029839922208338976, -0.002913824748247862, -0.0010665924055501819, -0.007733928970992565, 0.009289387613534927, -0.0013329028151929379, -0.007853363640606403, 0.0023211417719721794, -0.000939210643991828, -0.009887206368148327, 0.001693778671324253, -0.004144313279539347, 0.004213349428027868, -0.0112150888890028, -0.0037149833515286446, -0.003773821284994483, -0.004059053957462311, 0.004189022351056337, 0.009049720130860806, 0.005144205875694752, 0.0030894416850060225, -0.005035222042351961, -0.011179517023265362, -0.0004448510881047696, -0.0037449512165039778, 0.003203321248292923, 0.006830842699855566, 0.0028104037046432495, -0.012589959427714348, -0.0026544115971773863, 0.0012691086158156395, 0.0038039139471948147, -0.0011648924555629492, 0.0007414915016852319, -0.007476681377738714, 0.0070252688601613045, -0.0010977494530379772, 0.0037061201874166727, 0.010814551264047623, -0.0052905213087797165, 0.0001602844422450289, 0.0001142086839536205, 0.001647914294153452, -0.0020892724860459566, 0.004669060464948416, 0.010798249393701553, -0.002181533956900239, -0.006244366522878408, 0.0055013918317854404, 0.007086568977683783, 0.009253760799765587, 0.002005129586905241, -0.0035570708569139242, 0.0016613207990303636, -0.00629233755171299, -0.0002442734257783741, 0.008054093457758427, -0.0044290898367762566, 0.004615141078829765, 0.002794916508719325, -0.013666041195392609, -0.005880272015929222, -0.0017912142211571336, -0.006659296341240406, 0.0019361500162631273, 0.014017854817211628, 0.01138843409717083, -0.0024225059896707535, 0.002062337938696146, -0.009524243883788586, -0.001686937059275806, 0.007586231920868158, 0.0030498807318508625, -0.012480996549129486, -0.9587717056274414, 0.008706278167665005, 0.004557396750897169, -0.0038543541450053453, 0.0061455476097762585, 0.0012062614550814033, 0.0031576191540807486, 0.003970686346292496, 0.013053841888904572, -0.010194798931479454, -0.006281877402216196, -0.00988023728132248, -0.010288677178323269, -0.0032847330439835787, -0.007603407837450504, -0.0028683291748166084, -0.005000328179448843, -0.006106030661612749, -0.0013953052693977952, -0.003835356328636408, -0.0026522630359977484, 0.010691479779779911, -0.0015950467204675078, 0.00613054633140564, 0.0036377920769155025, 0.0022120284847915173, -0.004551231395453215, -0.0027193003334105015, -0.0035857229959219694, -0.005328884348273277, -0.005845220759510994, -0.015486104413866997, -0.0021525586489588022, -0.0032137404195964336, 0.009711017832159996, -0.0009081137832254171, 0.008523073047399521, -0.0022921403869986534, 0.0021538473665714264, -0.008315627463161945, 0.004670946858823299, -0.00022032781271263957, 0.0024100684095174074, -0.02828037552535534, -0.0010559256188571453, 0.0011530378833413124, -0.007517488673329353, 0.006055986043065786, 0.0011989230988547206, -0.001075309352017939, -0.0033917417749762535, -0.008655469864606857, 0.009803229942917824, -0.006615444086492062, 0.006717582233250141, -0.006000359542667866, -0.008940957486629486, -0.002119265729561448, -0.00576965045183897, 0.0008088856120593846, 0.0040076798759400845, -0.005640661809593439, -0.0037564397789537907, -0.004358259961009026, 0.0035957854706794024, 0.003272681962698698, 0.0028554298914968967, -0.019481558352708817, -0.0063005294650793076, 0.0012018377892673016, 0.0026698498986661434, -0.0019816954154521227, -0.004107734188437462, 0.004092702642083168, -0.008704885840415955, 0.007506293244659901, 0.0031939498148858547, -0.0003416463441681117, -0.01078995130956173, -0.0008059731917455792, -0.010891354642808437, -0.006488087121397257, 0.004497242160141468, -0.00459143565967679, -0.004300386644899845, -0.0007262527942657471, 0.0006527971709147096, 0.007705360651016235, -0.005729462020099163, 0.005193461198359728, 0.009673788212239742, -0.0011595642426982522, -0.007971446961164474, 0.004755055531859398, 0.0062925564125180244, 0.0022941611241549253, -0.005644841585308313, 0.000746500096283853, 0.006471128668636084, 0.007153643295168877, 0.002435830654576421, 0.006642998196184635, 0.0018147190567106009, 0.009516795165836811, -0.0026568935718387365, 0.0006426824256777763, -0.0015285329427570105, -0.000816303479950875, -0.003982242662459612, -0.0010100037325173616, -0.0033542390447109938, -0.004290607292205095, -0.01065660361200571, -0.008871745318174362, -0.004848559387028217, 0.0004152415494900197, 0.0008958806283771992, -0.004645760171115398, -0.0009362890268675983, 0.0009729843586683273, 0.009586324915289879, -0.0005297377938404679, -0.004360842518508434, -0.000629390066023916, 0.0015281692612916231, -0.0057744430378079414, 0.014607255347073078, -0.013866817578673363, 0.007817555218935013, -0.001512878225184977, -0.01599554345011711, 0.007187088020145893, 0.0074121966026723385, -0.008570577017962933, -0.0003075729764532298, 0.0006608573021367192, 0.0031186696141958237, -0.00006923005275893956, -0.006339572370052338, -0.0025969778653234243, -0.016606619581580162, 0.0001066366967279464, 0.018067630007863045, 0.002449153224006295, 0.011016704142093658, 0.011785353533923626, -0.0029693497344851494, 0.0030734913889318705, 0.004591353703290224, 0.00008811095904093236, 0.014165010303258896, -0.010734199546277523, 0.0006401989376172423, 0.002187358681112528, -0.0044310977682471275, 0.0007062696386128664, 0.006590966135263443, 0.0043919701129198074, -0.0027502388693392277, 0.003077138215303421, -0.005313856992870569, -0.005026166792958975, -0.017003672197461128, -0.0029129351023584604, 0.008407915011048317, -0.0065512279979884624, 0.005548453889787197, -0.010771469213068485, 0.004412119742482901, 0.005604852922260761, 0.0051459018141031265, 0.0012298986548557878, 0.000523801485542208, 0.006582614500075579, 0.012735314667224884, -0.00717476662248373, 0.0014318879693746567, 0.003996954765170813, -0.0019713423680514097, 0.00027731125010177493, 0.008198115974664688, -0.006860972847789526, -0.006308109033852816, 0.0013505480019375682, 0.006359593477100134, 0.000785787939094007, -0.004074058961123228, -0.007773555349558592, -0.005058387294411659, 0.0011990525526925921, -0.004508515819907188, 0.0021220140624791384, 0.0027727403212338686, 0.0019206168362870812, -0.00597158819437027, -0.0011062143603339791, -0.0024635950103402138, -0.01094853039830923, 0.010932969860732555, -0.0028010131791234016, 0.003912209998816252, 0.015524198301136494, 0.0034399512223899364, -0.01295224018394947, 0.006055369041860104, 0.010448338463902473, -0.0032384898513555527, 0.004677064251154661, 0.005722297355532646, -0.004076945595443249, -0.022675707936286926, -0.004366670735180378, -0.012406738474965096, 0.005737364757806063, -0.0009406476747244596, 0.004523978102952242, -0.0072626471519470215, 0.008658330887556076, 0.005836688447743654, -0.01370936818420887, -0.006444094702601433, -0.007991334423422813, 0.007166565395891666, -0.0014008410507813096, 0.000534862163476646, -0.0037265277933329344, -0.0024746872950345278, -0.001288945903070271, -0.004245955962687731, -0.0029300895985215902, 0.004279521759599447, 0.0011217951541766524, -0.003917839843779802, 0.002378785517066717, -0.002135927090421319, 0.0011582879815250635, -0.0019283541478216648, -0.00992323737591505, 0.0010534677421674132, 0.004623662680387497, -0.0023657840210944414, -0.002026074333116412, 0.0022950342390686274, -0.0035806118976324797, -0.006726651452481747, -0.011529271490871906, -0.007406226359307766, -0.00474595557898283, -0.0032116202637553215, -0.010713723488152027, -0.003087633289396763, -0.009374010376632214, 0.007016198243945837, -0.005577178671956062, 0.006917028222233057, 0.004336168989539146, -0.005757449194788933, 0.004379868507385254, -0.0032809581607580185, 0.005576151888817549, 0.0027814132627099752, 0.004516121931374073, -0.00010662205022526905, -0.006479077506810427, -0.008598492480814457, 0.010477873496711254, -0.009869266301393509, 0.0027925418689846992, 0.013257596641778946, 0.0041221315041184425, 0.008353352546691895, -0.0005924829165451229, 0.0023674042895436287, 0.00325575890019536, 0.006386483088135719, -0.013703596778213978, 0.0028744612354785204, -0.004508031066507101, -0.0003891974629368633, 0.004144806880503893, -0.004600924905389547, 0.0010510727297514677, 0.008790005929768085, 0.002911696443334222, -0.006684605497866869, -0.00022542134684044868, 0.0007188604795373976, 0.004787534475326538, -0.010897459462285042, -0.00013920421770308167, -0.0018504551844671369, -0.003413093276321888, -0.000931341084651649, -0.0013748552883043885, 0.0006212103180587292, 0.004758178722113371, -0.00025359890423715115, 0.004624252673238516, 0.0024674369487911463, -0.007440735120326281, 0.014676390215754509, -0.005009354092180729, -0.0048607951030135155, 0.001686642412096262, 0.0033519817516207695, -0.0037455670535564423, -0.0062338425777852535, -0.00012349532335065305, 0.0026953821070492268, 0.006374732591211796, -0.0033284276723861694, -0.0012717689387500286, -0.0015888436464592814, 0.0023804064840078354, -0.011699594557285309, 0.00219930917955935, 0.015230275690555573, -0.00706076342612505, 0.0061289602890610695, -0.002586240880191326, -0.007149942219257355, -0.012600363232195377, 0.052972838282585144, -0.00040472630644217134, 0.004124577157199383, 0.004963697865605354, -0.008268998004496098, -0.00010722836304921657, -0.000725121411960572, 0.009947684593498707, -0.004673989024013281, -0.008088654838502407, 0.009760690852999687, -0.004936134908348322, -0.000057727680541574955, 0.006989784073084593, -0.001253488240763545, 0.016500869765877724, -0.0026175668463110924, -0.017543092370033264, -0.015686294063925743, 0.006671298295259476, -0.0034498432651162148, -0.00558939203619957, 0.010713661089539528, -0.0017913153860718012, -0.0035147001035511494, 0.0009437786065973341, 0.005602708552032709, 0.000132083980133757, -0.00050784379709512, -0.0027001642156392336, -0.0026452112942934036, 0.0015379165997728705, 0.0017336835153400898, 0.004876140039414167, 0.009652615524828434, -0.0011407893616706133, 0.004911317024379969, -0.00036376164644025266, -0.0034303206484764814, -0.0019626521971076727, 0.004540031310170889, 0.0054572573862969875, -0.0014876869972795248, -0.0022452299017459154, 0.005327116698026657, 0.005085482727736235, 0.003518038196489215, 0.010284863412380219, -0.0007821094477549195, -0.0068360199220478535, 0.010629281401634216, 0.0064313639886677265, 0.0010505215032026172, 0.009959027171134949, -0.0009569527464918792, 0.007053762208670378, 0.00037312423228286207, -0.008271990343928337, -0.01401807926595211, -0.0006648254347965121, 0.008650359697639942, 0.008279814384877682, -0.0014681100146844983, 0.0020356352906674147, -0.0006776652880944312, -0.003244466846808791, -0.006328806281089783, -0.00836055539548397, -0.0024011351633816957, 0.002960876328870654, 0.0033061192370951176, 0.06844554841518402, -0.0071066562086343765, -0.0024924781173467636, -0.008587990887463093, 0.0004436296003405005, -0.0024961214512586594, -0.00151692028157413, -0.0010354178957641125, -0.0024887665640562773, 0.0035587605088949203, 0.0011656623100861907, -0.009609866887331009, -0.012678783386945724, 0.0006108040688559413, 0.0013573522446677089, -0.001340676099061966, 0.0042549301870167255, 0.003585448721423745, -0.00735972635447979, 0.0013448639074340463, -0.011737131513655186, -0.0003881250449921936, -0.0020472798496484756, -0.010561828501522541, -0.004756467882543802, -0.002490190090611577, 0.005012462381273508, 0.0010044920491054654, 0.0036562837194651365, -0.002244767500087619, 0.006724126171320677, -0.00326763978227973, -0.00024242233484983444, -0.0019445591606199741, -0.001562122255563736, -0.007458945270627737, 0.01011202484369278, 0.0023071030154824257, -0.011706788092851639, -0.005489513278007507, 0.0021972996182739735, -0.0006431957008317113, -0.0048683746717870235, 0.004103104583919048, 0.000012847025573137216, 0.006302615161985159, -0.0035910634323954582, 0.0033002139534801245, -0.006954170763492584, 0.0023522640112787485, -0.012456213124096394, 0.006243810523301363, -0.17330527305603027, 0.010972191579639912, 0.003302706638351083, -0.005986426025629044, -0.002861295361071825, -0.01218157634139061, -0.007332164328545332, 0.0023071577306836843, 0.010161099955439568, 0.0032336805015802383, -0.0009661566582508385, -0.0022845023777335882, 0.005391134414821863, 0.003572501242160797, -0.0004074965254403651, -0.004224690608680248, 0.0045715696178376675, -0.006405470427125692, 0.0013464046642184258, 0.004263588692992926, 0.0033232667483389378, 0.008949787355959415, 0.0011312039569020271, 0.003402775153517723, -0.0015413382789120078, -0.004113944713026285, 0.004533387720584869, -0.002229604870080948, 0.00666640093550086, -0.01084879506379366, -0.004392759408801794, -0.004163340199738741, -0.0027111354283988476, 0.002812255872413516, 0.0041432250291109085, 0.0018271544249728322, 0.01019419077783823, 0.0013220098335295916, -0.009042072109878063, 0.0069215870462358, -0.007363984361290932, 0.02992800809442997, 0.005335142835974693, 0.0053241360001266, 0.0003484348126221448, -0.006049006711691618, -0.0038850316777825356, 0.008148165419697762, 0.002051382791250944, 0.011467342264950275, -0.015313781797885895, -0.0004349553200881928, 0.0036590511444956064, 0.018552379682660103, -0.004246340598911047, -0.010342302732169628, -0.006875914521515369, -0.0031891092658042908, 0.0010545947588980198, 0.008687893860042095, 0.010436341166496277, -0.00428818678483367, 0.006062567699700594, -0.0009432013030163944, -0.02289009653031826, 0.00374080752953887, -0.005699205212295055, -0.00634942390024662, 0.00042395148193463683, 0.006802667863667011, 0.009902238845825195, -0.001956050517037511, 0.0020399850327521563, -0.0022097150795161724, 0.006777059752494097, -0.0007227955502457917, 0.005617559887468815, -0.002296862890943885, 0.005314905196428299, -0.009199623949825764, 0.009659985080361366, -0.007971404120326042, -0.0033101688604801893, 0.002618450904265046, -0.005478463135659695, 0.01023633498698473, 0.0044256895780563354, -0.003592246677726507, -0.0032624714076519012, -0.00880264863371849, -0.0021074980031698942, 0.0011363273952156305, 0.0002482000272721052, -0.01053713820874691, 0.003017714712768793, 0.0004493184678722173, 0.004654689226299524, 0.007062841672450304, -0.009021524339914322, 0.00725784245878458, 0.0046096621081233025, -0.007582088932394981, -0.00039311745786108077, -0.002194081898778677, 0.003588855266571045, 0.0036696698516607285, -0.0051937345415353775, -0.00599459046497941, 0.002592843258753419, -0.00787896104156971, -0.004839289002120495, 0.00665860204026103, -0.010271296836435795, -0.010689140297472477, -0.001248432556167245, -0.011781442910432816, 0.0006667213747277856 ]
8ac447e8327f451aa635702a06c66e0d74dc0eb1
1,668
py
Python
tools/ci/deploy_to_github_release.py
rodb70/RDMnet
94d17e1dfda2d1f56b120f6342231c43bf6862b0
[ "Apache-2.0" ]
30
2018-07-16T15:54:19.000Z
2021-11-21T21:17:36.000Z
tools/ci/deploy_to_github_release.py
rodb70/RDMnet
94d17e1dfda2d1f56b120f6342231c43bf6862b0
[ "Apache-2.0" ]
27
2019-04-12T22:45:25.000Z
2021-08-13T15:20:04.000Z
tools/ci/deploy_to_github_release.py
rodb70/RDMnet
94d17e1dfda2d1f56b120f6342231c43bf6862b0
[ "Apache-2.0" ]
12
2019-06-28T19:28:58.000Z
2021-11-17T12:10:44.000Z
"""Deploys binaries to a GitHub release given the specified tag name.""" import argparse import os import time from github import Github THIS_FILE_DIRECTORY = os.path.dirname(os.path.realpath(__file__)) GH_REPO_IDENT = "ETCLabs/RDMnet" GH_USERNAME = "svc-etclabs" GH_API_TOKEN = os.getenv("SVC_ETCLABS_REPO_TOKEN") def deploy_binaries(version: str): """Deploys staged binaries to a new GitHub Release.""" g = Github(login_or_token=GH_USERNAME, password=GH_API_TOKEN) repo = g.get_repo(GH_REPO_IDENT) print(f"Waiting for the correct GitHub tag v{version} to become available...") keep_trying = True while keep_trying: for tag in repo.get_tags(): if tag.name == f"v{version}": keep_trying = False # Tag now exists break if keep_trying: time.sleep(5) print(f"Tag v{version} available. Creating release...") new_release = repo.create_git_release( tag=f"v{version}", name=f"RDMnet v{version}", message=f"Automated release of RDMnet for v{version}", ) new_release.upload_asset("RDMnetSetup_x86.msi") new_release.upload_asset("RDMnetSetup_x64.msi") new_release.upload_asset("RDMnet.pkg") def main(): parser = argparse.ArgumentParser( description="Deploy RDMnet artifacts to GitHub Release" ) parser.add_argument("version", help="Artifact version being deployed") args = parser.parse_args() # Make sure our cwd is the root of the repository os.chdir(os.path.abspath(os.path.join(THIS_FILE_DIRECTORY, "..", ".."))) deploy_binaries(args.version) if __name__ == "__main__": main()
29.785714
82
0.682854
1
1.2186
[ 0.0027661207132041454, 0.023716917261481285, 0.00829809345304966, -0.0006645481917075813, 0.00242905062623322, -0.0010929531417787075, -0.008584391325712204, -0.00020727083028759807, -0.006901902612298727, 0.003172181313857436, 0.002051806775853038, 0.006987080909311771, 0.007969374768435955, -0.019461067393422127, -0.0014262455515563488, 0.015137185342609882, -0.04788133129477501, -0.0019687579479068518, -0.0018981636967509985, 0.002340342616662383, -0.006238703150302172, 0.00969027355313301, 0.009083732962608337, 0.005053745582699776, 0.007442896254360676, -0.001443054061383009, 0.009588492102921009, 0.0022304970771074295, -0.009371640160679817, -0.007375799585133791, -0.0011090358020737767, -0.0020746253430843353, -0.005979453679174185, -0.007164340000599623, 0.006439063232392073, -0.0025881542824208736, -0.001625139731913805, -0.01832743175327778, 0.012363697402179241, -0.004856123123317957, -0.00651916628703475, -0.013906726613640785, -0.0012947251088917255, 0.0045385477133095264, -0.00590325566008687, 0.0009565508225932717, -0.003532855538651347, 0.003167601302266121, -0.01129717007279396, 0.007434924133121967, -0.010452790185809135, 0.008076129481196404, 0.012946981936693192, 0.0025083585642278194, -0.007185932714492083, -0.004813607316464186, 0.013041636906564236, -0.0005637633730657399, -0.011458254419267178, 0.00022086176613811404, -0.0038348366506397724, -0.0015621590428054333, 0.006364085711538792, 0.00433222996070981, -0.015247400850057602, -0.008748508058488369, -0.0041332184337079525, 0.0036642979830503464, -0.00006012443554936908, 0.005037997849285603, -0.0018147791270166636, -0.0008952469797804952, 0.00522128539159894, 0.00572626618668437, 0.005525961983948946, -0.00434794370085001, -0.003414116334170103, -0.0005659402813762426, 0.007779632695019245, 0.003395874286070466, 0.003652446437627077, -0.005384804680943489, 0.006785593926906586, 0.007753601763397455, 0.015731725841760635, 0.00815843790769577, 0.019774174317717552, -0.010086260735988617, 0.04982180893421173, 0.007493212353438139, -0.007426597643643618, 0.002163489116355777, -0.010094918310642242, -0.00116836023516953, -0.005469583906233311, -0.02631496638059616, 0.0018931434024125338, -0.002630719216540456, -0.0012965287314727902, 0.0035490745212882757, 0.00017936457879841328, 0.006073562428355217, -0.00032212334917858243, -0.0013339996803551912, -0.007537903729826212, 0.009334885515272617, -0.007467975374311209, -0.003678976558148861, 0.005134395323693752, 0.0020218624267727137, -0.009786661714315414, -0.0012720901286229491, 0.0007784588378854096, -0.012469451874494553, 0.0028300259727984667, 0.00395974051207304, -0.006990295834839344, 0.05196356028318405, 0.0008017549407668412, 0.004803268238902092, -0.004733395762741566, 0.002229738049209118, -0.002201612340286374, 0.0047288318164646626, 0.010516899637877941, -0.0010284079471603036, 0.010113058611750603, 0.006695595104247332, 0.0025440510362386703, 0.008173596113920212, -0.004854454193264246, 0.004326238296926022, -0.003790353424847126, -0.0008173826499842107, 0.0017386743566021323, -0.007977968081831932, 0.006297532003372908, -0.0011030328460037708, -0.007515334989875555, -0.001291752327233553, 0.0007203264394775033, -0.007847979664802551, 0.0018820096738636494, -0.005274399649351835, 0.0020789597183465958, -0.011640479788184166, -0.003981198649853468, -0.002402573823928833, -0.0035262336023151875, 0.0007680489798076451, 0.011043745093047619, 0.004150425083935261, 0.00357417413033545, -0.004294930025935173, -0.008540390990674496, 0.00036023350548930466, -0.004545970819890499, 0.003044138429686427, 0.00602944940328598, 0.005196989513933659, -0.010744377039372921, -0.0011762267677113414, 0.0019807054195553064, 0.0006750987959094346, 0.00043824047315865755, 0.0036301075015217066, -0.009740677662193775, 0.0058004604652523994, 0.0006050413940101862, 0.0036545151378959417, 0.012194647453725338, -0.005541373509913683, -0.0009408044861629605, 0.0010687741450965405, 0.001480765175074339, -0.00037793663796037436, 0.005237373057752848, 0.009613826870918274, -0.0013839289313182235, -0.00421141879633069, 0.0025034185964614153, 0.005607174709439278, 0.010577283799648285, 0.005308687686920166, -0.006821848917752504, 0.0004947374691255391, -0.005024562124162912, -0.003193426178768277, 0.006139279343187809, -0.0058302809484303, 0.005602323915809393, 0.004693173803389072, -0.014150368049740791, -0.010571246966719627, -0.00020707922521978617, -0.0063102226704359055, -0.00015832443023100495, 0.012081230990588665, 0.011676289141178131, -0.004605590831488371, 0.0008195402915589511, -0.009362752549350262, 0.0018600118346512318, 0.008680802769958973, 0.0019020313629880548, -0.012623703107237816, -0.9602972865104675, 0.008060994558036327, 0.0028797038830816746, -0.0031441475730389357, 0.006258645560592413, 0.003422127105295658, 0.004851037636399269, 0.004436464514583349, 0.0158513393253088, -0.008128553628921509, -0.006973734125494957, -0.009752966463565826, -0.009861298836767673, -0.0017726586665958166, -0.007034217938780785, -0.004479794297367334, -0.006611189804971218, -0.008040091022849083, -0.0022776834666728973, -0.0021725643891841173, -0.002214330481365323, 0.008165622130036354, -0.000787673401646316, 0.004256921354681253, 0.003312750719487667, 0.0020904135890305042, -0.004671032540500164, -0.002441232092678547, -0.0020726954098790884, -0.002347002737224102, -0.00686796847730875, -0.014750270172953606, -0.001225078827701509, -0.001719876192510128, 0.010407103225588799, 0.00230250577442348, 0.006836323998868465, -0.0019115414470434189, 0.0034312508068978786, -0.006204907316714525, 0.003492949763312936, -0.0000809009579825215, 0.0022186958231031895, -0.03029218688607216, 0.0007320959120988846, 0.0006182390497997403, -0.008645348250865936, 0.004590562079101801, -0.0008690784452483058, -0.0011922563426196575, -0.0017745335353538394, -0.005459183361381292, 0.010172701440751553, -0.006098535377532244, 0.004590862896293402, -0.0016231377376243472, -0.007608482614159584, -0.0012770030880346894, -0.008263088762760162, 0.0010827432852238417, 0.0042218477465212345, -0.0033169786911457777, -0.004785933066159487, -0.0024669228587299585, 0.004331518430262804, 0.0026664293836802244, 0.002372876275330782, -0.017793094739317894, -0.007262764498591423, 0.0011917157098650932, 0.0003876057162415236, -0.004138706251978874, -0.002957995980978012, 0.0069055925123393536, -0.00872876774519682, 0.0064928047358989716, 0.0018034480744972825, -0.001326747820712626, -0.011850002221763134, -0.0010875989682972431, -0.008424696512520313, -0.006020654458552599, 0.0014666477218270302, -0.0032706342171877623, -0.005384888965636492, -0.0000019521955891832476, -0.000384068232960999, 0.005924723576754332, -0.0029481924138963223, 0.003857244737446308, 0.01032953429967165, -0.00510590523481369, -0.009004677645862103, 0.006216234061866999, 0.004359904211014509, 0.0003800794656854123, -0.002386469393968582, 0.003822839353233576, 0.006464807316660881, 0.0071195880882442, 0.00292152538895607, 0.007889551110565662, 0.0018960472662001848, 0.005329641047865152, 0.00014086910232435912, 0.0038715265691280365, -0.0031918352469801903, -0.00042702164500951767, -0.004973990377038717, 0.0014807116240262985, -0.004131332039833069, -0.003840241814032197, -0.013236883096396923, -0.007523369509726763, -0.005251375958323479, -0.00009323198173660785, 0.0033594060223549604, -0.003311457810923457, -0.003368294332176447, 0.002935444936156273, 0.008467215113341808, 0.0006441882578656077, -0.002245923737064004, 0.0006475740228779614, 0.004163566045463085, -0.006932979915291071, 0.01491076871752739, -0.01072106882929802, 0.007169214077293873, -0.000038210273487493396, -0.015123334713280201, 0.006437256932258606, 0.009605425409972668, -0.010888483375310898, 0.0015748076839372516, 0.006136403419077396, 0.0013907591346651316, -0.0019718327093869448, -0.004574274644255638, -0.004381951410323381, -0.01409974042326212, 0.0007653528591617942, 0.02001355215907097, -0.00116207345854491, 0.009617920964956284, 0.011234091594815254, -0.0023223552852869034, 0.0033059825655072927, 0.0028742116410285234, -0.0012717435602098703, 0.012315054424107075, -0.00746878469362855, 0.00041760262683965266, 0.0038982408586889505, -0.0064325793646276, 0.0005523565923795104, 0.006916196551173925, 0.006474683992564678, -0.003961760550737381, 0.0028226138092577457, -0.005965915042907, -0.004912243224680424, -0.016401296481490135, -0.0036004488356411457, 0.006795470602810383, -0.004371488466858864, 0.006221972871571779, -0.01061809528619051, 0.0055793761275708675, 0.006728751584887505, 0.003951628226786852, -0.0017923300620168447, 0.0027451426722109318, 0.005384474992752075, 0.012188881635665894, -0.0061235870234668255, 0.0019060916965827346, 0.0019406870706006885, -0.0006120924954302609, -0.003211570205166936, 0.005872340407222509, -0.005532270763069391, -0.0058739385567605495, 0.0031587714329361916, 0.005590839311480522, -0.00034519704058766365, -0.003471948206424713, -0.007956476882100105, -0.00267563434317708, 0.005371858831495047, -0.006269073113799095, 0.0058032856322824955, -0.00017707292863633484, 0.005030293483287096, -0.004054037854075432, -0.000690078129991889, -0.0010468572145327926, -0.013488296419382095, 0.012123151682317257, -0.001810083631426096, 0.0022393357940018177, 0.01215764507651329, 0.005355633795261383, -0.012215054593980312, 0.0036957566626369953, 0.008317340165376663, -0.0033261266071349382, 0.005895197857171297, 0.0020940261892974377, -0.006156249903142452, -0.020641282200813293, -0.0038562098052352667, -0.011353650130331516, 0.00648447684943676, -0.0020742847118526697, 0.004967867862433195, -0.0090767377987504, 0.006487930193543434, 0.007866516709327698, -0.014124782755970955, -0.0062813484109938145, -0.008811711333692074, 0.007995454594492912, 0.00033088569762185216, -0.0012278162175789475, -0.002775987144559622, -0.001724226982332766, -0.00027856140513904393, -0.0032546124421060085, -0.0016917389584705234, 0.006810853723436594, 0.0024384281132370234, -0.0035623249132186174, 0.0018706351984292269, -0.006488442420959473, -0.0005924589349888265, -0.00023392343427985907, -0.009411421604454517, 0.004626453388482332, 0.0024094469845294952, -0.004350545350462198, -0.0034584826789796352, 0.001883551012724638, 0.0006644673994742334, -0.008087573572993279, -0.011194455437362194, -0.0040729152970016, -0.004254848696291447, -0.004046398214995861, -0.01232781633734703, -0.004354705102741718, -0.0075795818120241165, 0.004867290612310171, -0.008441752754151821, 0.008125119842588902, 0.006137462332844734, -0.0037479731254279613, 0.007318722549825907, -0.0014370885910466313, 0.0033393665216863155, 0.0017304129432886839, 0.0047173043712973595, 0.00252714566886425, -0.006087250541895628, -0.012174861505627632, 0.011025949381291866, -0.007984238676726818, 0.0006985877407714725, 0.011686010286211967, 0.004584335256367922, 0.0107527831569314, 0.0007498445920646191, 0.0003154691366944462, 0.0020736469887197018, 0.006069422233849764, -0.013954157941043377, 0.002414377173408866, -0.004571510013192892, 0.000754019245505333, 0.004111290443688631, -0.003548873122781515, 0.0011162630980834365, 0.008047742769122124, -0.00013000905164517462, -0.0068667433224618435, -0.0015869269846007228, 0.004659696947783232, 0.005834945943206549, -0.011344949714839458, 0.001156693440862, -0.00424988241866231, -0.005447817035019398, -0.0035030487924814224, -0.00338188954629004, 0.0003414546372368932, 0.004710051696747541, -0.0026528015732765198, 0.006273757666349411, 0.0025881680194288492, -0.00435606250539422, 0.013434364460408688, -0.0036183535121381283, -0.0053206561133265495, 0.0014411009615287185, 0.0016825580969452858, -0.002753246109932661, -0.0032272126991301775, -0.0022399176377803087, 0.0033308251295238733, 0.008368461392819881, -0.0030891697388142347, -0.002193393651396036, 0.000568837916944176, 0.0009222847875207663, -0.012256771326065063, 0.00023662317835260183, 0.013235721737146378, -0.004694086499512196, 0.00628602085635066, -0.001698519685305655, -0.006493960041552782, -0.01200574915856123, 0.04985606297850609, -0.0005656072753481567, 0.002640391932800412, 0.0029863810632377863, -0.005359244998544455, -0.002092080656439066, -0.0008976354729384184, 0.009455216117203236, -0.006089323665946722, -0.00932353176176548, 0.00783851370215416, -0.003914404194802046, 0.006298175547271967, 0.0018641751958057284, -0.0007112133898772299, 0.015046998858451843, -0.0037913911510258913, -0.01614861562848091, -0.017411312088370323, 0.009658663533627987, -0.0030818551313132048, -0.007249613758176565, 0.009685217402875423, -0.0019714743830263615, -0.002533871214836836, 0.0024985505733639, 0.0067983344197273254, 0.0017646963242441416, 0.002067579422146082, -0.0035921905655413866, -0.0025866145733743906, -0.0016089865239337087, 0.003121915040537715, 0.004795169457793236, 0.0067329988814890385, -0.003989404998719692, 0.00392253790050745, -0.000546673487406224, -0.0008580440771766007, -0.002742199460044503, 0.0046562920324504375, 0.00669453339651227, -0.0015833276556804776, -0.0011621351586654782, 0.0059776827692985535, 0.004624089691787958, 0.0035377726890146732, 0.010239621624350548, 0.000556938408408314, -0.006367857567965984, 0.008765578269958496, 0.0052399164997041225, 0.0008371070143766701, 0.008020589128136635, -0.002177201909944415, 0.005445198155939579, 0.000754382461309433, -0.008074919693171978, -0.016898643225431442, -0.003915452864021063, 0.007739911321550608, 0.008047414012253284, -0.0005481315893121064, -0.0005016838549636304, -0.0007854283903725445, -0.0011307771783322096, -0.005459444597363472, -0.008326271548867226, -0.0049846237525343895, 0.001810333225876093, 0.005379785783588886, 0.06705749034881592, -0.006195094436407089, -0.0010253230575472116, -0.008331884630024433, -0.0031143745873123407, -0.004126144573092461, 0.0004493108717724681, 0.0010976962512359023, -0.004341497085988522, 0.0017054264899343252, 0.0000654278410365805, -0.006274617742747068, -0.010605089366436005, 0.0014032063772901893, -0.00021375033247750252, -0.0035906878765672445, 0.005290320608764887, 0.008172462694346905, -0.010546933859586716, -0.00012449723726604134, -0.010703999549150467, -0.0035827860701829195, -0.004265754017978907, -0.011517119593918324, -0.005289432592689991, -0.0035918501671403646, 0.006207984872162342, 0.0018792565679177642, 0.006720255594700575, -0.0025592129677534103, 0.005070419516414404, -0.002375224605202675, 0.0006604609079658985, -0.005301613826304674, -0.00007958489004522562, -0.006440486293286085, 0.006576308980584145, 0.003131248988211155, -0.011310755275189877, -0.004534215200692415, -0.00020137337560299784, -0.0010409965179860592, -0.004754436668008566, 0.003694297047331929, -0.001620965893380344, 0.004838486667722464, -0.0020066769793629646, -0.0003022169112227857, -0.00628688046708703, 0.003834448056295514, -0.01296919584274292, 0.00556324003264308, -0.17127849161624908, 0.008524022065103054, 0.0026323264464735985, -0.0048980931751430035, -0.004792139399796724, -0.013664539903402328, -0.003469905350357294, 0.0060604955069720745, 0.011362220160663128, 0.002403705380856991, -0.0012979015009477735, -0.0011996527900919318, 0.004224210046231747, 0.006092495284974575, 0.0003169553237967193, -0.006181573495268822, 0.005025194957852364, -0.004196454770863056, 0.0010963001986965537, 0.0024314499460160732, 0.0025615019258111715, 0.010061285458505154, 0.0004976379568688571, 0.00015480307047255337, -0.0007910551503300667, -0.003294300986453891, 0.007065241225063801, -0.0015130875399336219, 0.007240024395287037, -0.01311403140425682, -0.001118919113650918, -0.003346830140799284, -0.0036495120730251074, 0.001346939941868186, 0.004794957581907511, 0.000012181783858977724, 0.008986513130366802, 0.0025097017642110586, -0.008317222818732262, 0.00982741080224514, -0.008398954756557941, 0.025510836392641068, 0.0033327883575111628, 0.0067201536148786545, 0.0011999134439975023, -0.0078039090149104595, -0.0053677624091506, 0.007824057713150978, 0.0012306725839152932, 0.011920583434402943, -0.014892736449837685, -0.0009422539733350277, 0.0037393984384834766, 0.018348651006817818, -0.0049508302472531796, -0.011791417375206947, -0.00671806838363409, -0.0011393445311114192, 0.0007187796873040497, 0.006748463958501816, 0.009653237648308277, -0.0026659048162400723, 0.006482901517301798, -0.00302751362323761, -0.020780954509973526, 0.0028340700082480907, -0.00634386669844389, -0.006010659970343113, 0.0027646080125123262, 0.00640241289511323, 0.008989386260509491, 0.000823326816316694, -0.0005826554261147976, -0.00033915069070644677, 0.005117120686918497, 0.0004357457801233977, 0.007031281013041735, 0.00020574683730956167, 0.002350641181692481, -0.010820671916007996, 0.005358649417757988, -0.009861849248409271, -0.003398546716198325, 0.00008694975258549675, -0.005615100264549255, 0.012659004889428616, 0.004369765520095825, -0.00034603147651068866, -0.0012828093022108078, -0.007638671435415745, -0.0022969169076532125, 0.0029243933968245983, -0.0015382178826257586, -0.009284798987209797, 0.0028789497446268797, 0.0018475016113370657, 0.00511535257101059, 0.0037697935476899147, -0.009677045047283173, 0.005660737864673138, 0.0055199298076331615, -0.0030736462213099003, 0.0014632472302764654, -0.004999257158488035, 0.004182536620646715, 0.0032099199015647173, -0.005215220153331757, -0.003197136102244258, 0.0022806841880083084, -0.007675475440919399, -0.005121020134538412, 0.00857432559132576, -0.007324006408452988, -0.009127996861934662, -0.0020965442527085543, -0.013477033004164696, 0.00025790141080506146 ]
8ac489649919e5a666b90d4e91cad4bcbdd5e983
1,513
py
Python
matchms/filtering/add_losses.py
maximskorik/matchms
922f5afaef123a793194bdd74391027477cbb844
[ "Apache-2.0" ]
null
null
null
matchms/filtering/add_losses.py
maximskorik/matchms
922f5afaef123a793194bdd74391027477cbb844
[ "Apache-2.0" ]
null
null
null
matchms/filtering/add_losses.py
maximskorik/matchms
922f5afaef123a793194bdd74391027477cbb844
[ "Apache-2.0" ]
null
null
null
import logging import numpy from ..Fragments import Fragments from ..typing import SpectrumType logger = logging.getLogger("matchms") def add_losses(spectrum_in: SpectrumType, loss_mz_from=0.0, loss_mz_to=1000.0) -> SpectrumType: """Derive losses based on precursor mass. Parameters ---------- spectrum_in: Input spectrum. loss_mz_from: Minimum allowed m/z value for losses. Default is 0.0. loss_mz_to: Maximum allowed m/z value for losses. Default is 1000.0. """ if spectrum_in is None: return None spectrum = spectrum_in.clone() precursor_mz = spectrum.get("precursor_mz", None) if precursor_mz: assert isinstance(precursor_mz, (float, int)), ("Expected 'precursor_mz' to be a scalar number.", "Consider applying 'add_precursor_mz' filter first.") peaks_mz, peaks_intensities = spectrum.peaks.mz, spectrum.peaks.intensities losses_mz = (precursor_mz - peaks_mz)[::-1] losses_intensities = peaks_intensities[::-1] # Add losses which are within given boundaries mask = numpy.where((losses_mz >= loss_mz_from) & (losses_mz <= loss_mz_to)) spectrum.losses = Fragments(mz=losses_mz[mask], intensities=losses_intensities[mask]) else: logger.warning("No precursor_mz found. Consider applying 'add_precursor_mz' filter first.") return spectrum
35.186047
109
0.639128
1
1.1631
[ 0.0015553297707810998, 0.024011749774217606, 0.0076926820911467075, -0.0006799539551138878, 0.0036765767727047205, -0.00264099077321589, -0.00883407425135374, 0.004175374750047922, -0.007318309973925352, 0.0022591121960431337, 0.005044376943260431, 0.004292286932468414, 0.01014954224228859, -0.019961023703217506, -0.00285708368755877, 0.01748657412827015, -0.05261572077870369, -0.0007731279474683106, -0.005468669347465038, 0.003344427328556776, -0.009274806827306747, 0.010097766295075417, 0.008931582793593407, 0.008348220027983189, 0.009195654653012753, -0.0027655477169901133, 0.012549668550491333, 0.0031925924122333527, -0.006885386072099209, -0.005030470434576273, 0.00034212644095532596, -0.0015161315677687526, -0.006225129123777151, -0.009274918586015701, 0.002708215732127428, -0.001368238008581102, -0.0008145836764015257, -0.019362440332770348, 0.010725744068622589, -0.006205118726938963, -0.008830072358250618, -0.01390771009027958, 0.0010291733779013157, 0.006673816125839949, -0.009802032262086868, 0.0007602809928357601, -0.003394070081412792, 0.0019326048204675317, -0.010415758937597275, 0.006897490471601486, -0.010223764926195145, 0.003112940350547433, 0.013090341351926327, 0.003470468334853649, -0.005036335438489914, -0.007759514264762402, 0.013439894653856754, -0.0007443877984769642, -0.012265895493328571, -0.0006182686774991453, -0.0005734336446039379, -0.0037040174938738346, 0.005057748407125473, 0.00425351969897747, -0.013618662022054195, -0.008266955614089966, -0.006439773831516504, 0.0022906034719198942, -0.0013582917163148522, 0.005587316118180752, 0.0013366390485316515, -0.0009716995409689844, 0.007754792924970388, 0.00642406428232789, 0.0024537439458072186, -0.003892230335623026, -0.0013598657678812742, 0.0008551241480745375, 0.009576575830578804, 0.004430903121829033, 0.004418720491230488, -0.006443844176828861, 0.006375033874064684, 0.011319989338517189, 0.01365771796554327, 0.010356473736464977, 0.020838487893342972, -0.013177997432649136, 0.04619159549474716, 0.006430741865187883, -0.011606940999627113, 0.00021798453235533088, -0.013404114171862602, -0.00275150453671813, -0.003062304574996233, -0.029132666066288948, 0.00212301523424685, -0.002787127858027816, -0.0009164692601189017, 0.004818853456526995, 0.0007192660123109818, 0.006776546128094196, 0.0006843068404123187, -0.00244268705137074, -0.009287629276514053, 0.010404257103800774, -0.010439840145409107, -0.003523904364556074, 0.00636227335780859, 0.0025366765912622213, -0.010774409398436546, -0.0019017226295545697, -0.0012721993261948228, -0.013734608888626099, 0.00455487472936511, 0.004456408321857452, -0.005984066985547543, 0.05452544987201691, -0.0018196888267993927, 0.005603061057627201, -0.006416710093617439, -0.0005495944060385227, 0.0031546219252049923, 0.005628015846014023, 0.006784070283174515, -0.003404461545869708, 0.010920031927525997, 0.009793966077268124, 0.0029266327619552612, 0.007951183244585991, -0.003107544034719467, 0.009761250577867031, -0.005019025877118111, -0.0025597962085157633, -0.0006119274185039103, -0.0089575732126832, 0.006469282321631908, 0.00009229566785506904, -0.006998535245656967, 0.002233920618891716, -0.0014428157592192292, -0.009302820079028606, 0.0007268659537658095, -0.005190480966120958, 0.0036671743728220463, -0.011177842505276203, -0.005147521384060383, -0.004090527072548866, -0.0032334337010979652, 0.002970396541059017, 0.011201995424926281, 0.006221546325832605, 0.0027831760235130787, -0.004526677541434765, -0.008724446408450603, 0.0003730734752025455, -0.007412951905280352, 0.002158788498491049, 0.008083288557827473, 0.0025753069203346968, -0.011120310053229332, 0.00023642244923394173, 0.000672103138640523, 0.004508230835199356, -0.0018699642969295382, 0.002219622256234288, -0.006689063273370266, 0.01084908377379179, 0.0009799650870263577, 0.0036089743953198195, 0.010860573500394821, -0.006467475555837154, -0.00015328080917242914, -0.00017370852583553642, 0.0035102141555398703, 0.0000283272638625931, 0.0052867126651108265, 0.011353794485330582, -0.003909389954060316, -0.005370889790356159, 0.004703163634985685, 0.003032074775546789, 0.008859635330736637, 0.005557021591812372, -0.004801308270543814, -0.00047234215890057385, -0.007525133900344372, 0.0006644187960773706, 0.00696884049102664, -0.006256063934415579, 0.005636666901409626, 0.0036106002517044544, -0.013489950448274612, -0.01004684530198574, -0.003017952898517251, -0.007646950893104076, 0.003195081604644656, 0.015457387082278728, 0.009857517667114735, -0.0036629412788897753, 0.0028665252029895782, -0.009595760144293308, 0.0011964341392740607, 0.0069646756164729595, 0.0042642755433917046, -0.013209063559770584, -0.9558005332946777, 0.006866603624075651, 0.0039351461455225945, -0.00345602142624557, 0.006473337300121784, 0.0016566370613873005, 0.0032663210295140743, 0.002440081210806966, 0.01596515066921711, -0.007846064865589142, -0.006869982928037643, -0.011003411374986172, -0.013305225409567356, -0.0019877180457115173, -0.009030977264046669, -0.002412228612229228, -0.0069656651467084885, -0.00792670901864767, -0.0010479581542313099, -0.005376525688916445, -0.001972360536456108, 0.006497296039015055, -0.002610491355881095, 0.003419718472287059, 0.005814208649098873, 0.0037108210381120443, -0.0032707881182432175, -0.002887161448597908, -0.0038016445469111204, -0.003178380196914077, -0.00847417488694191, -0.015952592715620995, -0.003173822769895196, -0.002194554079324007, 0.012567884288728237, 0.0011284202337265015, 0.008212247863411903, -0.0025995292235165834, 0.002606336260214448, -0.0076899160631000996, 0.0056033506989479065, 0.0007845337968319654, 0.0040380023419857025, -0.02933894284069538, 0.00023967938614077866, -0.002012355485931039, -0.011370554566383362, 0.007907718420028687, 0.0038830277044326067, 0.0005154668469913304, -0.0044836075976490974, -0.006917120423167944, 0.010366473346948624, -0.007477968465536833, 0.006265423260629177, -0.006411978043615818, -0.009521341882646084, -0.003522212151437998, -0.00839631911367178, 0.0006016678526066244, 0.0062836227007210255, -0.004122707061469555, -0.0057491944171488285, -0.003458594437688589, 0.002009789226576686, 0.0010214917128905654, 0.0005628435174003243, -0.019077088683843613, -0.007368533872067928, 0.000535894010681659, 0.0033822490368038416, 0.000015055889889481477, -0.003902700264006853, 0.007944469340145588, -0.010994115844368935, 0.007548335939645767, -0.0016298051923513412, 0.0014265859499573708, -0.009502891451120377, 0.0008221492753364146, -0.011993426829576492, -0.007702545262873173, 0.003273832378908992, -0.005120853893458843, -0.005698500666767359, -0.0010003797942772508, 0.0010727900080382824, 0.007669828366488218, -0.0061648013070225716, 0.002971338341012597, 0.012211312539875507, -0.0019053842406719923, -0.009229748509824276, 0.008058849722146988, 0.004926370456814766, 0.000151695086969994, -0.0029992859344929457, -0.00003189329800079577, 0.005965291988104582, 0.0060267578810453415, 0.0013674072688445449, 0.006616243626922369, -0.00015089554653968662, 0.010557589121162891, -0.00000954390998231247, 0.0032056057825684547, -0.002243239665403962, -0.0006286297575570643, -0.006894276477396488, -0.003095889464020729, -0.0067998007871210575, -0.0019731789361685514, -0.011419914662837982, -0.009742495603859425, -0.006899307481944561, -0.0011618497082963586, 0.0025002898182719946, -0.0056211622431874275, 0.0008791741565801203, 0.0005021818797104061, 0.009197392500936985, -0.002200937829911709, -0.004188842605799437, 0.0008931549964472651, 0.003952056169509888, -0.007129979319870472, 0.015377267263829708, -0.011775750666856766, 0.005963734816759825, -0.0018223756924271584, -0.017828110605478287, 0.007143856957554817, 0.007616725284606218, -0.005664312746375799, 0.0034665109124034643, 0.0003664392279461026, 0.0016846933867782354, 0.0014095426304265857, -0.006435370072722435, -0.004798672161996365, -0.01410539448261261, 0.00025038537569344044, 0.020360831171274185, 0.0014310269616544247, 0.012592136859893799, 0.01144378911703825, -0.004730422515422106, 0.0004037909966427833, 0.004746727645397186, -0.0010517383925616741, 0.012262052856385708, -0.008803077973425388, -0.00003577905590645969, 0.000681685283780098, -0.006197300273925066, 0.002677619457244873, 0.006788840051740408, 0.0067642973735928535, -0.0035378201864659786, 0.005944390781223774, -0.0051480685360729694, -0.006198816932737827, -0.01929364539682865, -0.00042405870044603944, 0.009973038919270039, -0.005443947855383158, 0.008313817903399467, -0.011103368364274502, 0.0030364596750587225, 0.006319051142781973, 0.0017001507803797722, 0.0022537843324244022, 0.0006147801177576184, 0.006362495478242636, 0.009186167269945145, -0.006504502147436142, 0.003473772667348385, 0.0033898120746016502, -0.0006948327063582838, -0.0021534794941544533, 0.00845650676637888, -0.009313949383795261, -0.005129939876496792, 0.00013167658471502364, 0.0045801810920238495, 0.004662401042878628, -0.003927409183233976, -0.010177328251302242, -0.0041113789193332195, 0.004210545215755701, -0.004670504946261644, 0.004141222685575485, 0.000793911051005125, 0.002715645357966423, -0.007452080491930246, 0.0019548845011740923, -0.004318688064813614, -0.010512390173971653, 0.010355791077017784, -0.0057718404568731785, 0.004042666405439377, 0.01240738295018673, 0.005527231842279434, -0.013900676742196083, 0.0077895671129226685, 0.006308507639914751, -0.002637310652062297, 0.004737799521535635, 0.004047126043587923, -0.0039407783187925816, -0.025992166250944138, -0.0018898398848250508, -0.013362456113100052, 0.008658980019390583, -0.0024769753217697144, 0.005632964428514242, -0.006545928306877613, 0.007914195768535137, 0.005351402331143618, -0.013097461313009262, -0.004524919204413891, -0.008757559582591057, 0.009498047642409801, -0.0011771294521167874, -0.0017428387654945254, -0.0036645145155489445, -0.0029487451538443565, -0.0038621954154223204, -0.004965235944837332, -0.004122518468648195, 0.0064168162643909454, 0.0004489398270379752, -0.0029894092585891485, 0.005656542722135782, -0.002384629799053073, 0.002697368385270238, 0.00028689022292383015, -0.010181056335568428, 0.003744259011000395, 0.005209418945014477, 0.0006126089720055461, -0.0011940113035961986, 0.002400555182248354, -0.004168396815657616, -0.006200070027261972, -0.010912841185927391, -0.004992802627384663, -0.0030746872071176767, -0.0018674194579944015, -0.009703700430691242, -0.004071014001965523, -0.008077467791736126, 0.009304621256887913, -0.008471144363284111, 0.006718968041241169, 0.007430843077600002, -0.004977141972631216, 0.007349047344177961, -0.004663428291678429, 0.004089551046490669, 0.001952057471498847, 0.008226154372096062, -0.0011607293272390962, -0.006039031315594912, -0.008877400308847427, 0.01419606152921915, -0.010936383157968521, 0.0010594041086733341, 0.013773138634860516, 0.004967851564288139, 0.009599023498594761, 0.0003181285283062607, -0.0016900778282433748, 0.0020477434154599905, 0.008832791820168495, -0.01346234418451786, 0.0038073258474469185, -0.0008546665776520967, 0.0007776860729791224, 0.00621317932382226, -0.001924347598105669, 0.0015830207848921418, 0.010069392621517181, 0.0003356348897796124, -0.009728279896080494, -0.0013105033431202173, 0.0033765954431146383, 0.004328092094510794, -0.012924635782837868, -0.002430726308375597, -0.005394504405558109, -0.004662142600864172, -0.0006270025623962283, -0.0009416011744178832, 0.0006240686634555459, 0.007019377313554287, -0.005928125232458115, 0.0050689447671175, 0.000049358830437995493, -0.004981605336070061, 0.015615242533385754, -0.00795033946633339, -0.006195358000695705, 0.005267918109893799, 0.00540692824870348, -0.0017372214933857322, -0.006759596522897482, -0.00017236077110283077, 0.0015604723012074828, 0.0047021787613630295, -0.0028107932303100824, -0.004875547718256712, -0.0032806105446070433, 0.000896196870598942, -0.010505885817110538, 0.0009653914603404701, 0.012646346352994442, -0.002951311180368066, 0.0044489577412605286, 0.0004915213212370872, -0.006085323169827461, -0.015304550528526306, 0.054484233260154724, -0.0012279979418963194, 0.0013602213002741337, 0.005080363713204861, -0.008597515523433685, -0.0001464914093958214, -0.002089128829538822, 0.008252724073827267, -0.009089874103665352, -0.0068371715024113655, 0.00826175231486559, -0.004199304152280092, 0.005170257296413183, 0.00038652963121421635, -0.00035254922113381326, 0.017810935154557228, -0.0027216000016778708, -0.015029664151370525, -0.014555128291249275, 0.00728282006457448, -0.005143581889569759, -0.004671839065849781, 0.008138570003211498, -0.001476706238463521, -0.0016637812368571758, 0.0006485286867246032, 0.007374731823801994, -0.0008854439365677536, -0.00041464364039711654, -0.0023486365098506212, -0.00300843408331275, 0.00011317052121739835, 0.001447075279429555, 0.008181515149772167, 0.007816893048584461, -0.0022971644066274166, 0.006832004524767399, 0.00038459524512290955, -0.0017374408198520541, -0.0014762470964342356, 0.005403501912951469, 0.006354800891131163, -0.0019203068222850561, -0.00372673268429935, 0.004144078586250544, 0.00612301379442215, 0.002064027823507786, 0.00965759065002203, 0.0005459102685563266, -0.007477656472474337, 0.009360436350107193, 0.0064126718789339066, -0.0012633337173610926, 0.010818371549248695, -0.0011363584781065583, 0.004861036781221628, 0.0020684467162936926, -0.006831865757703781, -0.01496468298137188, -0.00023428272106684744, 0.006045873276889324, 0.009426428005099297, -0.0028709606267511845, 0.002138708718121052, -0.0005404645926319063, -0.0010460964404046535, -0.006553560495376587, -0.006645943969488144, -0.002050196286290884, 0.0007068754639476538, 0.0048884558491408825, 0.07232756167650223, -0.00685416255146265, -0.0037434834521263838, -0.008746189065277576, -0.001472098403610289, -0.0030712957959622145, -0.0007159669185057282, -0.0005595495458692312, -0.00240354984998703, 0.005158421583473682, 0.002395685762166977, -0.007820405066013336, -0.012620526365935802, 0.001652618171647191, 0.002459301147609949, -0.00299102277494967, 0.00829885434359312, 0.008165565319359303, -0.006373112555593252, 0.0012128704693168402, -0.011989690363407135, -0.0013479003682732582, -0.0024703533854335546, -0.010174884460866451, -0.0033305573742836714, -0.0041166143491864204, 0.00504072243347764, 0.0026573168579488993, 0.005941040348261595, -0.0033413737546652555, 0.008746170438826084, -0.0036009331233799458, 0.0017420243239030242, -0.0023968310561031103, -0.00044686798355542123, -0.006202008109539747, 0.0046690041199326515, -0.0014339829795062542, -0.012149793095886707, -0.006089162081480026, -0.001756952959112823, -0.000022163972971611656, -0.00360889732837677, 0.006155592855066061, 0.0007179970270954072, 0.007418425753712654, -0.001965149538591504, 0.0019723859149962664, -0.005916694179177284, 0.001404650043696165, -0.011373987421393394, 0.004820019938051701, -0.17915524542331696, 0.009383875876665115, 0.002156913513317704, -0.007664707954972982, -0.00265559577383101, -0.013891891576349735, -0.008427172899246216, 0.0020474328193813562, 0.012306020595133305, 0.00013075486640445888, -0.000024717099222471006, -0.0020607172045856714, 0.006491649430245161, 0.0014635574771091342, 0.00006541879702126607, -0.0035557032097131014, 0.006253691855818033, -0.003686130279675126, 0.002689667511731386, 0.004404280334711075, 0.0023488320875912905, 0.007662443909794092, 0.004493206273764372, -0.0008109851623885334, -0.001477855141274631, -0.005233087111264467, 0.00783185288310051, -0.0021291724406182766, 0.005605101585388184, -0.012755891308188438, -0.003448898671194911, -0.005531989969313145, -0.004788131453096867, 0.001826015068218112, 0.005050751846283674, -0.0018719763029366732, 0.008287321776151657, 0.002329012146219611, -0.009133603423833847, 0.007739218883216381, -0.007571591529995203, 0.032090093940496445, 0.0035590294282883406, 0.0038137079682201147, 0.0000673244139761664, -0.00448660459369421, -0.004364827647805214, 0.008074731566011906, 0.0023897660430520773, 0.014127921313047409, -0.01228356920182705, -0.0018503249157220125, 0.0024101759772747755, 0.020191920921206474, -0.0050949156284332275, -0.009200611151754856, -0.006941351108253002, -0.0020317374728620052, 0.0020689545199275017, 0.009919892996549606, 0.011152380146086216, -0.004700593184679747, 0.010854539461433887, -0.0024967058561742306, -0.023353444412350655, 0.0020737999584525824, -0.004207616206258535, -0.007665553130209446, 0.0016115120379254222, 0.0069373901933431625, 0.01046739798039198, 0.0005906920414417982, 0.004474633373320103, -0.00159935571718961, 0.003528515575453639, 0.00023210277140606195, 0.0077418670989573, -0.003243334824219346, 0.0053792232647538185, -0.009210718795657158, 0.010326234623789787, -0.011025683954358101, -0.004487424157559872, 0.002180972369387746, -0.005100427195429802, 0.009964109398424625, 0.005535324569791555, -0.002673759823665023, -0.001903058378957212, -0.009249408729374409, -0.0011635367991402745, 0.0013649334432557225, 0.0018672049045562744, -0.0076987664215266705, 0.0022257030941545963, -0.00019835541024804115, 0.005498321261256933, 0.006509183906018734, -0.007426268421113491, 0.005932771135121584, 0.006444618571549654, -0.005670403130352497, -0.00033620151225477457, -0.0044976212084293365, 0.0023884358815848827, 0.0021518454886972904, -0.0038430660497397184, -0.006521767470985651, 0.004293348174542189, -0.006994836498051882, -0.005083773750811815, 0.0067336056381464005, -0.008888376876711845, -0.008768371306359768, 0.0002815467305481434, -0.011473692953586578, -0.00012236159818712622 ]
8ac8388c155952144c99a47c3c6e38eeff168835
10,829
py
Python
cornflow_client/schema/dictSchema.py
baobabsoluciones/cornflow-client
f9996f0b841885d26639cb63c8ba6090387de57f
[ "MIT" ]
3
2021-05-12T11:21:26.000Z
2022-02-22T19:23:46.000Z
cornflow_client/schema/dictSchema.py
baobabsoluciones/cornflow-client
f9996f0b841885d26639cb63c8ba6090387de57f
[ "MIT" ]
17
2021-03-14T17:09:46.000Z
2022-02-28T19:12:37.000Z
cornflow_client/schema/dictSchema.py
baobabsoluciones/cornflow-client
f9996f0b841885d26639cb63c8ba6090387de57f
[ "MIT" ]
2
2020-10-03T20:00:19.000Z
2022-03-24T11:52:22.000Z
import re from .dict_functions import gen_schema, ParameterSchema, sort_dict from cornflow_client.constants import JSON_TYPES, DATASCHEMA class DictSchema: """ A json-schema to dict-schema parser """ def __init__(self, jsonschema): """ Class to manage internal dictionary schema :param jsonschema: a json schema """ self.types = JSON_TYPES schema_dict = self.get_empty_schema() if "definitions" in jsonschema: for item in jsonschema["definitions"].items(): self._get_element_dict(schema_dict=schema_dict, item=item) if "properties" in jsonschema: for item in jsonschema["properties"].items(): self._get_element_dict(schema_dict=schema_dict, item=item) self._create_data_schema( schema_dict=schema_dict, item=item, required_list=jsonschema.get("required"), ) self.schema = schema_dict def get_schema(self): return self.schema @staticmethod def get_empty_schema(): """ Create un empty schema dict """ return {DATASCHEMA: []} def _create_data_schema(self, schema_dict, item, required_list=None): """ Add a schema to schema_dict[DATASCHEMA] :param item: (key, value) of a dict. The key contains the name of the schema and the value contains its content. return the schema dict. """ name, content = item if required_list is None: required_list = [] schema = dict( name=name, type=self._get_type_or_new_schema(item), many=("type" in content and content["type"] == "array"), required=name in required_list, ) schema_dict[DATASCHEMA].append(schema) return schema def _get_element_dict(self, schema_dict, item, required_list=None): """ Parse an item (key, value) from the jsonschema and return the corresponding dict. :param item: An item from the jsonschema (key, value) :param required_list: A list of names corresponding to the required fields in the parent object :return A dict element for a schema_dict. """ if required_list is None: required_list = [] name, content = item if "type" not in content: if "$ref" in content: return { "name": name, "type": self._get_ref(item), "many": False, "required": (name in required_list), } else: print("\nType missing for item: {}".format(name)) raise TypeError("Type missing") if content["type"] == "object": return { "name": name, "type": self._get_object_schema(schema_dict=schema_dict, item=item), "many": False, "required": (name in required_list), } elif content["type"] == "array": return { "name": name, "type": self._get_array_schema(schema_dict=schema_dict, item=item), "many": True, "required": (name in required_list), } else: return self._get_field_dict(item, required_list) def _get_object_schema(self, schema_dict, item): """ Transform an object item from the jsonschema in a dict for the schema_dict and update self.schema_dict. In jsonschema objects are similar to python dict. The object in jsonschema is in the following format: "object_name": {"type":"object", "properties":{"field1": {...}, "filed2": {...}}, "required": ["field1]} The schema_dict object use the format: {"schema_name": [{"name":"field1", "type": "field1_type", "many": False, "required":(True or False)}, ...] :param item: The jsonschema item (key, value) The format of the item is: ("object_name", {"type":"object", "properties":{"a": {...}, "b": {...}}) :return: The schema name """ name, content = item schema_name = self._get_new_schema_name(schema_dict=schema_dict, name=name) ell = { schema_name: [ self._get_element_dict( schema_dict=schema_dict, item=i, required_list=self._get_required(content), ) for i in content["properties"].items() ] } schema_dict.update(ell) return schema_name def _get_array_schema(self, schema_dict, item): """ Transform a array item from the jsonschema in a dict for the schema_dict and update self.schema_dict. In jsonschema arrays are similar to python lists. The object in jsonschema is in the following format: "object_name": {"type":"array", "items":{format_of_items}} The schema_dict object use the format: {"schema_name": [{"name":"field1", "type": "field1_type", "many": False, "required":(True or False) :param item: The jsonschema item (key, value) The format of the item is: ("object_name", {"type":"object", "properties":{"a": {...}, "b": {...}}) :return: The schema name """ name, content = item content = content["items"] schema_name = self._get_new_schema_name(schema_dict=schema_dict, name=name) if "type" in content and content["type"] == "object": schema_dict.update( { schema_name: [ self._get_element_dict( schema_dict=schema_dict, item=i, required_list=self._get_required(content), ) for i in content["properties"].items() ] } ) elif "$ref" in content: schema_name = self._get_ref((None, content)) elif "type" in content and content["type"] != "array": return self._get_type(content["type"]) else: schema_dict.update( { schema_name: [ self._get_element_dict( schema_dict=schema_dict, item=i, required_list=self._get_required(content), ) for i in content.items() ] } ) return schema_name def _get_field_dict(self, item, required_list=None): """ Transform a "normal" item from the jsonschema in a dict for the schema_dict and return it. This is used for items that will directly translate into fields. :param item: The jsonschema item in format (key, value) :param required_list: a list of the fields required in the parent object. :return: the schema_dict for this item """ d = dict( name=item[0], type=self._get_type(item[1]["type"]), required=(item[0] in required_list), allow_none=("null" in item[1]["type"]), many=False, ) return d def _get_ref(self, item): """ Get the name of the schema for a jsonschema reference. jsonschema definitions are parsed first and corresponding schema are created so a schema should exist corresponding to the reference. :param item: The jsonschema item in format (key, value) The value should be in the following format: {"$ref": "#/definitions/object_name"} :return The schema name (_get_schema_name(object_name)) """ content = item[1] ref = re.search("definitions/(.+)", content["$ref"]).group(1) return self._get_schema_name(ref) def _get_type_or_new_schema(self, item): """ returns a new schema or a type depending on the json_type """ name, content = item if "type" not in content or content["type"] == "object": return self._get_schema_name(name) elif content["type"] == "array": return self._get_type_or_new_schema((name, content["items"])) else: return self._get_type(content["type"]) def _get_type(self, json_type): """ Translate the type between jsonschema and schema_dict. :param json_type: the type in jsonschema :return: the type in schema_dict. """ if type(json_type) is list: not_null_type = [i for i in json_type if i != "null"] if len(not_null_type) > 1: raise Warning("Warning: more than one type given") return self.types[not_null_type[0]] else: return self.types[json_type] @staticmethod def _get_schema_name(name, n=0): """ Transform an element name into a schema name in order to create a schema corresponding to an object or array. The schema name use the following format: [name][n]Schema (for example if name is "values" and n is 3: Values3Schema) :param name: The name of the object or array. :param n: if n is different from 0, it is added to the schema name. :return: the corresponding schema name. """ if n == 0: return name.capitalize() + "Schema" else: return name.capitalize() + str(n) + "Schema" def _get_new_schema_name(self, schema_dict, name, n=0): try_name = self._get_schema_name(name, n) if try_name in schema_dict: return self._get_new_schema_name( schema_dict=schema_dict, name=name, n=n + 1 ) else: return try_name @staticmethod def _get_required(content): """ Get the list of required name of it exist. :content: the dict which should have a "required" key.value :return: The required list or empty list. """ return content.get("required", []) def to_marshmallow(self): dict_params = self.schema result_dict = {} ordered = sort_dict(dict_params) tuplist = sorted(dict_params.items(), key=lambda v: ordered[v[0]]) for key, params in tuplist: schema = ParameterSchema() # this line validates the list of parameters: params1 = schema.load(params, many=True) result_dict[key] = gen_schema(key, params1, result_dict) return result_dict[DATASCHEMA]
35.739274
117
0.559793
1
1.8951
[ -0.009508288465440273, 0.013011511415243149, 0.022307662293314934, -0.007110821548849344, -0.03215649351477623, 0.014634247869253159, -0.04037880152463913, -0.021499674767255783, 0.015250463970005512, 0.006962630897760391, 0.041912950575351715, -0.010355688631534576, 0.042582061141729355, -0.019377337768673897, -0.03201870992779732, -0.02755162864923477, 0.02816619910299778, 0.03395483270287514, -0.06070379540324211, 0.00434998981654644, -0.000663447252009064, -0.015532484278082848, -0.003683984512463212, 0.03375731036067009, -0.004929213784635067, -0.026675738394260406, 0.03897327929735184, 0.014195885509252548, 0.006419817917048931, -0.04500214755535126, -0.02128683589398861, 0.025593528524041176, -0.012342430651187897, -0.008491321466863155, -0.009978089481592178, 0.015188189223408699, 0.030356699600815773, -0.03133774548768997, 0.0008539283298887312, -0.009115027263760567, 0.01887197233736515, 0.0023015530314296484, -0.04157025367021561, -0.03674529865384102, 0.018739089369773865, -0.029168518260121346, 0.0006390975322574377, -0.0056405276991426945, 0.0017510831821709871, -0.004638911224901676, 0.014312335290014744, 0.04203744977712631, 0.0030181363690644503, -0.028286177664995193, -0.02712075039744377, -0.07144849002361298, -0.003234569216147065, 0.029551373794674873, -0.01779317855834961, -0.007830479182302952, -0.022662002593278885, -0.015298704616725445, 0.006239926442503929, 0.017641285434365273, 0.017513731494545937, -0.028742704540491104, 0.022512132301926613, -0.00884346291422844, -0.052559614181518555, -0.03392036259174347, 0.00709039531648159, -0.030098095536231995, 0.019836826249957085, 0.05363507941365242, 0.029133759438991547, 0.03277476504445076, -0.009887143038213253, -0.004291165620088577, -0.0012346761068329215, -0.004144361242651939, -0.02609456144273281, 0.040756892412900925, -0.0016683246940374374, 0.0017388431588187814, 0.0012605665251612663, 0.01225472055375576, 0.019628392532467842, -0.050527993589639664, 0.033477358520030975, 0.02014775201678276, -0.03740890696644783, 0.039251115173101425, -0.01349798683077097, 0.015730900689959526, -0.008731815963983536, -0.04364773631095886, 0.014173327945172787, 0.0016953997546806931, 0.027110014110803604, -0.014061769470572472, 0.025758517906069756, -0.007714203093200922, 0.02596094459295273, -0.03364938125014305, -0.039212118834257126, -0.01153933722525835, -0.04574921727180481, 0.015021522529423237, 0.009790154173970222, -0.032192960381507874, -0.044665295630693436, -0.000704630627296865, -0.013948686420917511, -0.029866764321923256, -0.027818238362669945, -0.03531287983059883, 0.011248767375946045, 0.004155056085437536, -0.010281241498887539, 0.035185061395168304, 0.01625620573759079, 0.04189107194542885, -0.003713171696290374, 0.013125845231115818, -0.04203347489237785, 0.0592590868473053, 0.02689424343407154, 0.019640006124973297, 0.0460987351834774, -0.011485247872769833, -0.03350725769996643, 0.014263451099395752, -0.04213852062821388, -0.014398861676454544, 0.029450764879584312, -0.04607688635587692, 0.0065576620399951935, 0.002555091865360737, -0.011297794058918953, 0.032815899699926376, -0.016621408984065056, -0.05457058921456337, 0.0014588808408007026, -0.01859169453382492, 0.027397962287068367, -0.037915267050266266, -0.029162030667066574, -0.0031439452432096004, -0.0011896464275196195, 0.011465038172900677, 0.048558395355939865, 0.000283239409327507, 0.0006423300947062671, 0.02940458431839943, -0.02988217957317829, 0.0028814973775297403, 0.00564753171056509, -0.025610296055674553, -0.0056651197373867035, -0.004129587672650814, -0.006195893976837397, 0.046908434480428696, -0.01035035215318203, 0.04282812401652336, 0.008534347638487816, 0.03756247088313103, -0.0036216529551893473, 0.03264794126152992, -0.013058654963970184, 0.005735520739108324, 0.0009651451837271452, -0.004490170162171125, -0.005087218713015318, -0.0033534574322402477, -0.03298149257898331, -0.00970856100320816, 0.023826459422707558, -0.029559917747974396, -0.01374798733741045, -0.03123278170824051, 0.03974218666553497, 0.014011617749929428, 0.020717602223157883, -0.004996669478714466, 0.010216725058853626, -0.03163618594408035, 0.007307723164558411, -0.030451977625489235, 0.016834359616041183, -0.0036010604817420244, -0.03224572911858559, 0.043374788016080856, -0.0040297480300068855, -0.04757612198591232, 0.03561491146683693, 0.0004964213003404438, -0.00381393707357347, -0.004332198761403561, -0.007161246612668037, 0.017914729192852974, 0.018590649589896202, -0.004292037803679705, 0.006783702876418829, 0.02378099039196968, 0.007591955363750458, 0.0039267102256417274, -0.7300320863723755, 0.055710647255182266, 0.04196902737021446, 0.01581523008644581, -0.0017493852647021413, 0.01370717491954565, -0.03871850296854973, 0.05415426567196846, -0.04535727575421333, -0.00896995048969984, 0.0069263046607375145, -0.00760231539607048, -0.06681297719478607, 0.002910010749474168, 0.025911828503012657, -0.026084506884217262, 0.018566254526376724, -0.012695630080997944, 0.02267508953809738, 0.017142513766884804, 0.0106635307893157, -0.009485159069299698, -0.02148398570716381, -0.010257809422910213, 0.001354302978143096, -0.006529979407787323, 0.005860543809831142, 0.031482990831136703, 0.018261905759572983, 0.005306182894855738, -0.009535446763038635, -0.039239875972270966, 0.02873431146144867, -0.017043638974428177, -0.0211932510137558, 0.01403002068400383, 0.009834272786974907, -0.03197572007775307, -0.014049743302166462, 0.017004700377583504, -0.017502855509519577, 0.0020020208321511745, 0.018596678972244263, -0.05076301097869873, -0.05717722326517105, -0.0006443810416385531, -0.0050179907120764256, -0.009216851554811, 0.006368509493768215, 0.03939317911863327, -0.05034305155277252, 0.03670671209692955, 0.037825316190719604, -0.02704690955579281, -0.03667352348566055, -0.027136225253343582, 0.005128590855747461, -0.02450716495513916, -0.01328557264059782, -0.011253689415752888, 0.020637519657611847, -0.019910454750061035, -0.032904792577028275, 0.01941286399960518, -0.02004268765449524, 0.011688265949487686, 0.0438510961830616, -0.03738849610090256, -0.024950195103883743, 0.04740309715270996, -0.016941335052251816, -0.010098552331328392, -0.039909325540065765, 0.08644459396600723, -0.013681476935744286, 0.0032917005009949207, 0.0058176713064312935, 0.007238148711621761, -0.05194158852100372, -0.01276977639645338, 0.019489681348204613, 0.017521152272820473, 0.005371118895709515, -0.015070644207298756, -0.02327742986381054, -0.017072003334760666, -0.016184307634830475, 0.012762896716594696, 0.01258889865130186, 0.04001384600996971, 0.06968120485544205, 0.005077532026916742, 0.003130455268546939, -0.00848405435681343, 0.021281424909830093, 0.009064847603440285, -0.013870861381292343, 0.05707421526312828, 0.01653291843831539, 0.04032713174819946, -0.025748439133167267, 0.013358479365706444, -0.001894680899567902, -0.009542873129248619, 0.021805955097079277, -0.0037222804967314005, -0.04396642744541168, 0.0073510585352778435, 0.00846937671303749, -0.02016676776111126, -0.01652948558330536, 0.02406262420117855, 0.0032124922145158052, 0.044552262872457504, 0.007587379775941372, -0.0031114332377910614, -0.004101889673620462, -0.027226338163018227, 0.0043051280081272125, 0.005847643595188856, -0.021069496870040894, 0.012957858853042126, 0.0303848497569561, -0.01892511174082756, 0.010104736313223839, 0.03617893159389496, -0.015249148942530155, 0.0014253886183723807, 0.0054519823752343655, 0.036770354956388474, -0.023144088685512543, -0.04351639002561569, -0.004649916663765907, -0.004173337481915951, -0.011454897001385689, -0.032692283391952515, -0.01911168359220028, -0.026702066883444786, -0.021208960562944412, -0.006321250461041927, -0.0027197496965527534, 0.003294860478490591, 0.002849134150892496, -0.02690761350095272, 0.02176550030708313, 0.00041212805081158876, 0.02166479080915451, 0.010091078467667103, 0.0025702507700771093, -0.025773199275135994, 0.0010086451657116413, 0.004959856625646353, -0.004007677081972361, -0.007194866891950369, -0.024197962135076523, 0.01208246499300003, 0.0025691252667456865, 0.03665873408317566, 0.009330036118626595, 0.00689190486446023, -0.019825512543320656, -0.0017317699966952205, 0.03137027844786644, 0.05958736315369606, -0.0008803704986348748, -0.012594781816005707, 0.008813685737550259, 0.008714529685676098, 0.040581025183200836, 0.009337290190160275, 0.025210507214069366, -0.004399152006953955, 0.026815852150321007, 0.021760601550340652, -0.03774154558777809, 0.014485047198832035, -0.008046341128647327, -0.0018706056289374828, 0.0037858060095459223, -0.033688731491565704, -0.030148597434163094, -0.005351603031158447, 0.004430138040333986, -0.020913563668727875, 0.017022952437400818, -0.011378915049135685, -0.021719591692090034, 0.03275267407298088, 0.02452789805829525, -0.012163794599473476, -0.005074777640402317, 0.0006562161725014448, 0.0033247077371925116, 0.0004883104702457786, -0.03086393140256405, 0.0023151342757046223, -0.005741162225604057, -0.00586852990090847, -0.016029605641961098, -0.014556060545146465, 0.03907977417111397, 0.017883459106087685, 0.0024617407470941544, -0.028353407979011536, 0.0209750197827816, 0.05128083750605583, 0.0059166825376451015, 0.01695793867111206, 0.011340437456965446, 0.02468768134713173, 0.018556911498308182, -0.004885807633399963, 0.008137702941894531, -0.034401800483465195, -0.008411664515733719, 0.013042761012911797, -0.04490591585636139, -0.031645387411117554, -0.03691988065838814, -0.029777826741337776, 0.021411050111055374, -0.011125918477773666, 0.041941169649362564, -0.004012870602309704, 0.005970738362520933, -0.015326080843806267, -0.034286316484212875, 0.02541501261293888, -0.010700483806431293, -0.013659392483532429, 0.02063029445707798, 0.006413858383893967, 0.007405723910778761, -0.023288143798708916, -0.045656390488147736, 0.0294851865619421, -0.02869192138314247, -0.029278947040438652, -0.002546919509768486, -0.02853032946586609, -0.007586183026432991, -0.04781092330813408, -0.011674929410219193, 0.05624797195196152, -0.004205022472888231, -0.004083091858774424, -0.013912434689700603, -0.06223196163773537, 0.00135059654712677, -0.030986715108156204, -0.021600626409053802, 0.04294247180223465, 0.006755495443940163, -0.016368387266993523, 0.021818216890096664, 0.0036948390770703554, -0.011632058769464493, 0.007757966872304678, 0.008139103651046753, 0.010174128226935863, -0.022997790947556496, -0.03500031679868698, 0.01968623325228691, 0.03174326941370964, 0.007348837796598673, -0.011302241124212742, 0.016033072024583817, 0.011171122081577778, -0.03716098517179489, 0.0258523877710104, 0.036157380789518356, -0.003993367310613394, -0.026705855503678322, 0.0031187646090984344, -0.0015213571023195982, -0.005912254098802805, 0.013649523258209229, -0.0243182685226202, -0.007172042969614267, 0.030556345358490944, -0.039523907005786896, -0.01561899483203888, 0.0025954334996640682, 0.0004892785800620914, -0.005357890855520964, 0.010469121858477592, -0.01146682072430849, -0.04011878743767738, -0.04726231470704079, -0.03674796223640442, 0.019607624039053917, -0.004055858589708805, 0.0601375550031662, 0.011191010475158691, 0.0066386982798576355, 0.008019469678401947, 0.003257069271057844, -0.0012393846409395337, 0.00878690741956234, 0.0008631410310044885, 0.04861008748412132, 0.027522189542651176, -0.015137974172830582, -0.038461461663246155, -0.0024683091323822737, -0.03254472091794014, 0.03060184046626091, -0.026364395394921303, 0.02190188691020012, 0.007389261852949858, -0.01535058580338955, 0.017338773235678673, -0.00811193510890007, -0.02347741462290287, -0.00310460920445621, -0.011331119574606419, 0.03796130046248436, 0.005936960689723492, 0.028899798169732094, -0.006312222685664892, -0.0312783420085907, -0.0005070006009191275, -0.015339427627623081, -0.023452695459127426, 0.003537173615768552, 0.021902568638324738, -0.03301591798663139, 0.00864242110401392, -0.02542085386812687, -0.012242271564900875, -0.03166105970740318, -0.025446787476539612, 0.003270095679908991, -0.02304273657500744, 0.04414259269833565, -0.01984122395515442, 0.003899076022207737, 0.038178104907274246, -0.009207801893353462, 0.006337931379675865, 0.04531755670905113, 0.0281022097915411, -0.01805606670677662, 0.023926427587866783, 0.03807046636939049, 0.04479549452662468, 0.0035658155102282763, 0.02766568213701248, 0.026113595813512802, 0.017933746799826622, -0.011539660394191742, -0.010723439045250416, -0.0012508574873209, 0.010348869487643242, -0.010176771320402622, -0.004164774902164936, -0.027414685115218163, 0.0359775573015213, 0.0043210056610405445, 0.019083546474575996, 0.012275234796106815, -0.006511402316391468, -0.00310729444026947, -0.031380970031023026, 0.0044572497718036175, -0.05016089975833893, 0.04730842635035515, 0.00578709552064538, -0.011155640706419945, 0.017427973449230194, -0.04164092615246773, -0.007639886811375618, 0.015226121991872787, -0.015497648157179356, -0.002649492584168911, 0.01567530445754528, 0.01123333815485239, 0.026802197098731995, 0.00620532501488924, -0.019929280504584312, 0.001647910918109119, 0.027448007836937904, -0.006478415802121162, -0.013895731419324875, 0.0015946906059980392, -0.021558957174420357, -0.006098744925111532, -0.030109496787190437, -0.0029493358451873064, -0.03355247527360916, -0.0002648700028657913, 0.0019422873156145215, -0.008900853805243969, 0.026933535933494568, 0.017966412007808685, -0.015251298435032368, -0.009537785314023495, 0.008510412648320198, -0.027987493202090263, 0.0148728983476758, 0.008835958316922188, 0.0066607012413442135, -0.01270025223493576, -0.0198048185557127, 0.04594763368368149, -0.009241374209523201, -0.016956213861703873, 0.021212203428149223, 0.0023593343794345856, 0.0392448715865612, 0.012061591260135174, 0.0030373295303434134, 0.008151856251060963, -0.002111145295202732, -0.035067543387413025, -0.0035123908892273903, -0.005812881048768759, 0.00723516708239913, -0.006100911181420088, 0.0220523439347744, -0.023478128015995026, 0.00870494544506073, -0.0009430674836039543, 0.005768293049186468, -0.002075033960863948, -0.0075445701368153095, -0.0002073481009574607, 0.01087950263172388, -0.01433346513658762, 0.01546911709010601, -0.042069561779499054, -0.004380481783300638, -0.025667663663625717, -0.014664413407444954, 0.020364511758089066, -0.04503776505589485, -0.01710675098001957, 0.02292691357433796, -0.01499317679554224, 0.024522267282009125, 0.0263151153922081, 0.02680480107665062, 0.04147670418024063, 0.01719919964671135, 0.02905316650867462, -0.04146020486950874, -0.02788027748465538, -0.025253374129533768, -0.008549041114747524, -0.01676170714199543, 0.0014103356515988708, 0.038709256798028946, -0.03755120560526848, -0.02149704284965992, -0.004583172500133514, -0.010360848158597946, -0.0068333023227751255, 0.04733817279338837, 0.00821299385279417, 0.012074328027665615, 0.04177900031208992, 0.031450171023607254, 0.00011172856466146186, 0.018212424591183662, 0.06566452234983444, 0.005648845806717873, -0.0011053559137508273, 0.002610038034617901, -0.005742357578128576, -0.0019326297333464026, -0.03413718193769455, 0.019051648676395416, -0.029018688946962357, 0.020815236493945122, -0.04720379412174225, 0.021357249468564987, -0.038567692041397095, 0.002987283980473876, -0.028044911101460457, 0.015517521649599075, -0.0601961612701416, 0.039627548307180405, 0.001217863755300641, -0.007954157888889313, -0.011135602369904518, -0.009919506497681141, -0.005772095639258623, 0.027807900682091713, -0.017500346526503563, 0.018060941249132156, 0.001073613646440208, -0.0073716966435313225, -0.0010867617093026638, 0.018977979198098183, 0.0013682228745892644, -0.034529104828834534, -0.004023408051580191, 0.034592390060424805, 0.05972691997885704, 0.014021851122379303, -0.020581208169460297, -0.012053247541189194, 0.02220023050904274, 0.020181739702820778, 0.039539165794849396, 0.00013632858463097364, 0.07181444019079208, 0.014250320382416248, 0.017211252823472023, -0.015970585867762566, -0.028636375442147255, -0.014538068324327469, -0.0153317516669631, -0.01803172193467617, 0.0397600382566452, 0.044959768652915955, 0.04603911563754082, -0.03923829644918442, -0.034795131534338, -0.00013829742965754122, -0.01008547656238079, 0.02264336869120598, -0.0016759959980845451, -0.0322745218873024, 0.008924530819058418, -0.01802293211221695, -0.044019293040037155, 0.003185586305335164, 0.02709842473268509, 0.005335342604666948, 0.017648430541157722, 0.003781453240662813, -0.003008298808708787, -0.015001622959971428, 0.02695539966225624, -0.030318936333060265, 0.024789035320281982, 0.038612574338912964, -0.04082418978214264, -0.01834961399435997, 0.045530010014772415, -0.0016538655618205667, 0.0005870721652172506, -0.018160339444875717, -0.014035847969353199, 0.0060674468986690044, -0.0030207987874746323, 0.04331541433930397, -0.003509963396936655, 0.016783174127340317, -0.026147499680519104, 0.03625398874282837, 0.01719655841588974, 0.022010359913110733, -0.0204189270734787, -0.03857211768627167, -0.027075020596385002, 0.032525163143873215, -0.0156853124499321, -0.0368543416261673, -0.0252846609801054, 0.024074334651231766 ]
8ac83a9b0ffc4d89a43ceecc29a99652f8c7e2f2
5,869
py
Python
rspub/util/test/test_resourcefilter.py
EHRI/rspub-core
1f6b0c84825037b7df442ae0d258d5d897ff6905
[ "Apache-2.0" ]
1
2017-02-01T15:03:29.000Z
2017-02-01T15:03:29.000Z
rspub/util/test/test_resourcefilter.py
EHRI/rspub-core
1f6b0c84825037b7df442ae0d258d5d897ff6905
[ "Apache-2.0" ]
3
2017-02-15T12:25:22.000Z
2017-04-10T13:51:54.000Z
rspub/util/test/test_resourcefilter.py
EHRI/rspub-core
1f6b0c84825037b7df442ae0d258d5d897ff6905
[ "Apache-2.0" ]
3
2017-02-15T09:04:39.000Z
2021-06-21T09:01:59.000Z
#! /usr/bin/env python3 # -*- coding: utf-8 -*- import os import platform import unittest import rspub.util.resourcefilter as rf def on_windows(): opsys = platform.system() return opsys == "Windows" class TestPredicates(unittest.TestCase): def test_directory_pattern_filter_empty(self): dpf = rf.directory_pattern_predicate() # should pass all strings self.assertTrue(dpf("")) self.assertTrue(dpf(".")) self.assertTrue(dpf("\n")) self.assertTrue(dpf("foo")) # rejects not string self.assertFalse(dpf(None)) self.assertFalse(dpf(42)) self.assertFalse(dpf(self)) def test_directory_pattern_filter(self): dpf = rf.directory_pattern_predicate("abc") self.assertTrue(dpf("foo/babcd/bar/some.txt")) self.assertTrue(dpf("/abc/bar/some.txt")) self.assertTrue(dpf("/foo/bar/abc/some.txt")) # self.assertFalse(dpf("/foo/bar/baz/abc.txt")) # ## dpf = rf.directory_pattern_predicate("^/abc") self.assertTrue(dpf("/abc/bar/some.txt")) # self.assertFalse(dpf("abc/bar/some.txt")) # # dpf = rf.directory_pattern_predicate("abc$") self.assertTrue(dpf("foo/bar/abc/some.txt")) # self.assertFalse(dpf("abc/abc/bar/some.txt")) self.assertFalse(dpf("abc/abc/bar/abc.abc")) @unittest.skipUnless(on_windows(), "Only tested on Windows.") def test_directory_pattern_filter_windows(self): dpf = rf.directory_pattern_predicate("abc") self.assertTrue(dpf("foo/babcd/bar/some.txt")) self.assertTrue(dpf("/abc/bar/some.txt")) self.assertTrue(dpf("/foo/bar/abc/some.txt")) self.assertTrue(dpf("foo\\babcd\\bar\\some.txt")) self.assertTrue(dpf("c:\\abc\\bar\\some.txt")) self.assertTrue(dpf("c:\\foo\\bar\\abc\\some.txt")) # self.assertFalse(dpf("/foo/bar/baz/abc.txt")) self.assertFalse(dpf("c:\\foo\\bar\\baz\\abc.txt")) # ## dpf = rf.directory_pattern_predicate("^/abc") self.assertTrue(dpf("/abc/bar/some.txt")) # self.assertFalse(dpf("abc/bar/some.txt")) # # dpf = rf.directory_pattern_predicate("^c:\\abc") self.assertTrue(dpf("c:\\abc\\bar\\some.txt")) # self.assertFalse(dpf("abc\\bar\\some.txt")) dpf = rf.directory_pattern_predicate("abc$") self.assertTrue(dpf("foo/bar/abc/some.txt")) self.assertTrue(dpf("foo\\bar\\abc\\some.txt")) # self.assertFalse(dpf("abc/abc/bar/some.txt")) self.assertFalse(dpf("abc\\abc\\bar\\some.txt")) self.assertFalse(dpf("abc/abc/bar/abc.abc")) self.assertFalse(dpf("abc\\abc\\bar\\abc.abc")) def test_last_modified_filter(self): file_name = os.path.realpath(__file__) lmaf = rf.last_modified_after_predicate() self.assertTrue(lmaf(file_name)) lmaf = rf.last_modified_after_predicate(3000000000) # valid until 2065-01-24 06:20:00 self.assertFalse(lmaf(file_name)) lmaf = rf.last_modified_after_predicate("2016-08-01") self.assertTrue(lmaf(file_name)) def test_example(self): import rspub.util.resourcefilter as rf dir_ends_with_abc = rf.directory_pattern_predicate("abc$") assert dir_ends_with_abc("/foo/bar/folder_abc/my_resource.txt") assert not dir_ends_with_abc("/foo/bar/folder_def/my_resource.txt") xml_file = rf.filename_pattern_predicate(".xml$") assert xml_file("my_resource.xml") assert not xml_file("my_resource.txt") import rspub.util.gates as lf xml_files_in_abc = lf.and_(dir_ends_with_abc, xml_file) assert xml_files_in_abc("/foo/bar/folder_abc/my_resource.xml") assert not xml_files_in_abc("/foo/bar/folder_abc/my_resource.txt") assert not xml_files_in_abc("/foo/bar/folder_def/my_resource.xml") recent = rf.last_modified_after_predicate("2016-08-01") includes = [xml_files_in_abc] excludes = [recent] resource_gate = lf.gate(includes, excludes) # print(type(resource_gate)) @unittest.skipUnless(on_windows(), "Only tested on Windows.") def test_example_windows(self): import rspub.util.resourcefilter as rf dir_ends_with_abc = rf.directory_pattern_predicate("abc$") assert dir_ends_with_abc("/foo/bar/folder_abc/my_resource.txt") assert not dir_ends_with_abc("/foo/bar/folder_def/my_resource.txt") xml_file = rf.filename_pattern_predicate(".xml$") assert xml_file("my_resource.xml") assert not xml_file("my_resource.txt") import rspub.util.gates as lf xml_files_in_abc = lf.and_(dir_ends_with_abc, xml_file) assert xml_files_in_abc("/foo/bar/folder_abc/my_resource.xml") assert not xml_files_in_abc("/foo/bar/folder_abc/my_resource.txt") assert not xml_files_in_abc("/foo/bar/folder_def/my_resource.xml") assert xml_files_in_abc("c:\\foo\\bar\\folder_abc\\my_resource.xml") assert not xml_files_in_abc("c:\\foo\\bar\\folder_abc\\my_resource.txt") assert not xml_files_in_abc("c:\\foo\\bar\\folder_def\\my_resource.xml") recent = rf.last_modified_after_predicate("2016-08-01") includes = [xml_files_in_abc] excludes = [recent] resource_gate = lf.gate(includes, excludes) # print(type(resource_gate)) @unittest.skipUnless(on_windows(), "Only tested on Windows.") def test_windows_to_unix(self): path = os.path.expanduser("~") dpf = rf.directory_pattern_predicate("^" + path) self.assertTrue(dpf(os.path.join(path, "bla"))) dpf = rf.directory_pattern_predicate("^C:\\Users") self.assertTrue(dpf(os.path.join(path, "bla")))
35.143713
80
0.645596
1
2.0796
[ 0.003159597283229232, 0.035390254110097885, 0.0017423046519979835, 0.013655254617333412, -0.01138645876199007, 0.012986601330339909, -0.004048130940645933, -0.022311430424451828, 0.05228520929813385, 0.010881856083869934, 0.015435784123837948, -0.01253494806587696, 0.007292511872947216, 0.04064439982175827, -0.016836615279316902, -0.014871178194880486, 0.04507966712117195, -0.025419479236006737, -0.018118681386113167, 0.0077509754337370396, 0.021931776776909828, 0.024250339716672897, -0.006150286179035902, -0.004538343753665686, 0.017121128737926483, 0.0026859247591346502, 0.029634645208716393, 0.005756935570389032, 0.037234142422676086, -0.03161595016717911, 0.0027912878431379795, 0.009626020677387714, -0.0007676717941649258, -0.005734870210289955, 0.0027532512322068214, -0.019537435844540596, -0.0006308548036031425, -0.05725725367665291, -0.017161071300506592, -0.030821146443486214, 0.025577494874596596, -0.0173179991543293, 0.017295246943831444, 0.025863023474812508, 0.044959843158721924, 0.013997175730764866, 0.013747871853411198, 0.05921246111392975, -0.04389328882098198, 0.006906756199896336, 0.008974014781415462, 0.046556998044252396, 0.033860620111227036, -0.038651563227176666, 0.016910234466195107, 0.004759776871651411, 0.005132412072271109, 0.040151044726371765, -0.04229709133505821, -0.018612045794725418, 0.0006443245219998062, -0.02119763381779194, -0.008420320227742195, 0.01419142261147499, 0.03296109288930893, 0.02456127107143402, 0.03328130394220352, 0.011618896387517452, -0.039944011718034744, -0.026536818593740463, -0.028443191200494766, -0.017628470435738564, 0.016092386096715927, 0.0459020771086216, -0.03428091108798981, 0.0071384357288479805, -0.010667463764548302, 0.020806867629289627, 0.02101733162999153, -0.020869465544819832, 0.010640963912010193, 0.03922778367996216, 0.0004923981032334268, -0.016153790056705475, 0.000774748099502176, 0.026129987090826035, 0.03243057429790497, -0.06210692599415779, 0.014737214893102646, 0.023545313626527786, -0.008302610367536545, 0.032945916056632996, -0.05194568634033203, -0.0023878056090325117, 0.019075077027082443, -0.05435435473918915, -0.0043817791156470776, 0.01551896147429943, 0.004250510595738888, -0.021715378388762474, 0.00553251663222909, -0.03538113087415695, 0.04794725403189659, -0.012954640202224255, 0.0036331391893327236, -0.002347276546061039, -0.020472126081585884, 0.0029564148280769587, 0.03470228612422943, 0.0010527848498895764, -0.029891163110733032, 0.016976678743958473, 0.029962409287691116, -0.01564939133822918, 0.008643114939332008, -0.010118994861841202, -0.013665510341525078, -0.0012208835687488317, -0.011926131322979927, -0.031466592103242874, 0.01237085647881031, -0.007179184351116419, 0.007625299971550703, -0.05024078115820885, -0.04035888612270355, 0.06071021407842636, 0.04560747742652893, -0.019026970490813255, 0.0026573094073683023, -0.007418245077133179, 0.00006655197648797184, 0.009250092320144176, 0.0004264797316864133, 0.007393845822662115, 0.017629431560635567, -0.014701703563332558, 0.02446223795413971, 0.014640163630247116, -0.034681327641010284, 0.01652906835079193, 0.030780691653490067, -0.005153318867087364, -0.020295292139053345, -0.010272569954395294, 0.0025250688195228577, -0.022636014968156815, 0.0003677667409647256, -0.05065473914146423, -0.00209283409640193, 0.002687548054382205, 0.01360909640789032, 0.008532228879630566, -0.013423709198832512, 0.008023375645279884, -0.037247832864522934, -0.03341048210859299, 0.007556857541203499, -0.026741933077573776, -0.00016302854055538774, 0.018620077520608902, -0.007440363056957722, 0.022289276123046875, 0.02312144823372364, -0.017989475280046463, 0.007482154760509729, 0.01304179523140192, -0.03335675597190857, 0.0173433069139719, 0.014558463357388973, -0.01891988329589367, 0.04357016459107399, 0.02264345996081829, -0.028248922899365425, -0.027529416605830193, -0.030898675322532654, 0.009489507414400578, -0.014572695828974247, 0.027485106140375137, 0.024212220683693886, 0.0479525588452816, -0.01315603218972683, 0.024939754977822304, 0.04031423106789589, 0.02190549299120903, -0.023943396285176277, 0.01003573089838028, -0.01168282050639391, -0.05921367183327675, 0.03973207250237465, -0.010008147917687893, -0.017238354310393333, -0.01136793289333582, -0.026536187157034874, -0.056845322251319885, -0.005557425785809755, 0.010590930469334126, -0.009932106360793114, 0.0032344176433980465, -0.022629227489233017, -0.04791165515780449, 0.026646262034773827, -0.02748984284698963, 0.04352222755551338, 0.020652128383517265, 0.004860226530581713, 0.00578333530575037, -0.7126080393791199, 0.002662179060280323, 0.03602203354239464, -0.008529803715646267, 0.03326761722564697, 0.02147327922284603, 0.014118545688688755, 0.020526444539427757, -0.06531953066587448, 0.006736208219081163, -0.006039903033524752, -0.0019720732234418392, -0.06026587262749672, 0.012337966822087765, -0.012991268187761307, -0.02548198774456978, -0.004642313811928034, -0.006199459545314312, -0.007728594355285168, 0.010572893545031548, 0.02429545298218727, -0.031182581558823586, 0.0006801268318668008, -0.014517373405396938, 0.009210541844367981, 0.0022571119479835033, -0.0064366767182946205, 0.01475257333368063, 0.014270247891545296, -0.015274418517947197, -0.039210475981235504, -0.008719591423869133, 0.004952507559210062, 0.016743915155529976, -0.0222596637904644, 0.03838297724723816, -0.004416523035615683, -0.0006622544606216252, -0.02764315716922283, 0.021326888352632523, 0.011259165592491627, -0.04669957235455513, -0.02495194599032402, -0.0059966640546917915, -0.0380990169942379, -0.010591952130198479, 0.029921676963567734, 0.01427927240729332, 0.013575219549238682, 0.011724941432476044, 0.0026064999401569366, 0.004465817008167505, 0.011329655535519123, -0.012863241136074066, -0.058921489864587784, -0.0008193810936063528, 0.005170934833586216, 0.0037767868489027023, -0.010449705645442009, 0.006000645458698273, 0.01819293387234211, -0.012775609269738197, -0.01671314239501953, -0.010208084248006344, 0.008499502204358578, 0.009362420998513699, 0.0556233748793602, 0.028974199667572975, -0.03400847315788269, 0.027650276198983192, 0.009734101593494415, -0.008826716803014278, -0.011111605912446976, 0.021016091108322144, -0.003944416530430317, -0.002962707309052348, -0.041111059486866, -0.0030620566103607416, -0.0208832249045372, -0.02571219764649868, 0.0021890774369239807, -0.009261357598006725, 0.00282465061172843, -0.0220735315233469, 0.0073522040620446205, -0.03107321262359619, 0.012792706489562988, 0.01783728413283825, -0.0031500456389039755, -0.03239703178405762, 0.04230932518839836, 0.0676334872841835, -0.005787476897239685, -0.014318608678877354, 0.028865067288279533, -0.019742250442504883, 0.014498785138130188, 0.017198782414197922, -0.020382091403007507, 0.03048938326537609, -0.02332204021513462, 0.02659223973751068, 0.0047161392867565155, 0.07950641214847565, -0.03736631199717522, -0.01551125105470419, -0.04110024496912956, -0.000998757896013558, 0.024568354710936546, -0.04178999364376068, -0.05313315987586975, -0.028629755601286888, 0.005823400337249041, -0.0009846827015280724, -0.02604249306023121, -0.030690724030137062, -0.023959681391716003, -0.02111823856830597, 0.012610947713255882, 0.007702389732003212, -0.008003175258636475, 0.0045766644179821014, 0.027555545791983604, -0.007093948312103748, -0.0007898307521827519, 0.02584824152290821, -0.022194625809788704, 0.010592070408165455, 0.05348093435168266, -0.00199139048345387, -0.04090816155076027, -0.033503420650959015, 0.014386529102921486, 0.027101989835500717, 0.005909894593060017, -0.007894790731370449, -0.04729713499546051, -0.010702800005674362, -0.0008511554333381355, 0.030590161681175232, 0.0035721403546631336, -0.0036425949074327946, 0.018307741731405258, -0.03984907269477844, 0.02268674038350582, 0.0055029443465173244, 0.023955320939421654, -0.014860441908240318, -0.047098513692617416, -0.008544287644326687, -0.023708460852503777, 0.039706338196992874, 0.012200861237943172, -0.007543770130723715, -0.07072420418262482, 0.020323241129517555, -0.05794251710176468, -0.008442316204309464, 0.00867574941366911, 0.013408958911895752, -0.0010929688578471541, 0.02377043105661869, -0.018028410151600838, -0.0015053630340844393, -0.0038906019181013107, 0.010368258692324162, -0.005262321792542934, -0.0249200239777565, -0.011396353133022785, 0.0017582467989996076, 0.007761877495795488, -0.0026538423262536526, 0.01582306995987892, -0.03037887066602707, -0.037938009947538376, -0.03413064405322075, -0.016950689256191254, 0.028494087979197502, -0.00376465218141675, -0.023856597021222115, -0.009920565411448479, -0.03351360559463501, -0.004774993285536766, -0.0035767059307545424, 0.005010602064430714, 0.035419266670942307, -0.009754383936524391, -0.013928472064435482, -0.01583627238869667, 0.036160800606012344, 0.011549429967999458, 0.008093733340501785, -0.04119054228067398, 0.03682674467563629, -0.02550460398197174, -0.027898898348212242, -0.04242045059800148, -0.025120606645941734, 0.0012989102397114038, -0.02684910222887993, 0.01039713155478239, -0.01703374646604061, -0.012899644672870636, -0.011826165951788425, 0.013930642046034336, -0.012300950475037098, -0.008146710693836212, -0.002719450043514371, -0.01529810018837452, -0.009665504097938538, -0.015182456001639366, 0.0020137846004217863, -0.047438398003578186, 0.06872007250785828, -0.026359284296631813, 0.0023454350885003805, -0.06596604734659195, -0.007533317897468805, -0.008482672274112701, -0.007781586609780788, 0.018138462677598, -0.023530500009655952, 0.011118843220174313, 0.006511112675070763, -0.002302394015714526, -0.03424236178398132, -0.013398037292063236, -0.010823534801602364, 0.0025996307376772165, -0.004946209955960512, 0.028721990063786507, 0.061017829924821854, -0.022401105612516403, -0.03215041384100914, 0.02072194777429104, 0.003808463690802455, 0.007826109416782856, 0.002155046444386244, 0.013745592907071114, -0.014515640214085579, 0.023677121847867966, -0.015026346780359745, -0.007182581350207329, 0.02125917747616768, -0.03813909739255905, -0.0034251483157277107, 0.0060858894139528275, -0.01044033095240593, -0.017989177256822586, -0.011494031175971031, -0.014524423517286777, 0.023410465568304062, 0.06792843341827393, -0.05044484883546829, 0.009469958022236824, -0.003375174244865775, -0.012651347555220127, 0.05091986432671547, 0.015087434090673923, -0.033320486545562744, -0.06417209655046463, -0.06509669125080109, 0.015308515168726444, -0.002381999045610428, -0.023239484056830406, 0.010029536671936512, -0.009350498206913471, -0.019893765449523926, -0.007320309057831764, 0.05258134379982948, 0.027097409591078758, 0.03072655387222767, -0.051079731434583664, 0.011029292829334736, 0.0548626147210598, 0.01740744337439537, 0.02721637859940529, -0.021641355007886887, 0.023684803396463394, -0.019048774614930153, 0.012049841694533825, -0.012062338180840015, 0.00729344179853797, 0.017355971038341522, 0.011955110356211662, 0.021480008959770203, 0.027641287073493004, 0.016642747446894646, -0.01245475560426712, -0.013682616874575615, 0.012805504724383354, -0.05247361958026886, 0.03850068897008896, 0.0066153197549283504, -0.010631512850522995, 0.036261849105358124, 0.026751231402158737, 0.009453832171857357, 0.03197943791747093, 0.0007036519818939269, -0.03484467417001724, -0.013386493548750877, -0.02537870779633522, 0.01802702620625496, -0.018994903191924095, 0.006698573008179665, 0.014651362784206867, 0.013540737330913544, 0.02306297793984413, 0.03452317416667938, -0.01070287637412548, 0.026182908564805984, -0.012987975962460041, -0.0307569969445467, -0.018097829073667526, -0.017853934317827225, -0.006338499020785093, 0.01625164970755577, 0.0030262151267379522, 0.02460830844938755, 0.014470117166638374, 0.013268674723803997, 0.009386667050421238, -0.03066716343164444, -0.0015467982739210129, -0.0261733066290617, -0.025475144386291504, -0.020575091242790222, -0.008848223835229874, -0.013559040613472462, -0.03549003601074219, -0.02093946561217308, -0.020897623151540756, 0.0007862140191718936, 0.01448908168822527, -0.024165848270058632, 0.0030566940549761057, 0.03199703246355057, 0.004684264771640301, -0.021395839750766754, -0.023165445774793625, 0.01807740144431591, -0.017585761845111847, -0.042162954807281494, -0.0004036941099911928, -0.027555910870432854, 0.027638308703899384, 0.013495407998561859, 0.03120073862373829, 0.010851548053324223, 0.01583760976791382, -0.03972694277763367, 0.011797912418842316, -0.016778452321887016, -0.010024218820035458, -0.025118283927440643, 0.02546556107699871, -0.018202248960733414, -0.026995979249477386, 0.011926510371267796, -0.02204093337059021, -0.02498086355626583, -0.04813234508037567, 0.005609241779893637, 0.013103824108839035, -0.02979002520442009, 0.007889917120337486, 0.021931031718850136, 0.0230195764452219, 0.048450615257024765, -0.025262022390961647, -0.028657259419560432, 0.010071064345538616, 0.05526860058307648, 0.0359160341322422, 0.038370076566934586, 0.07283342629671097, 0.003251486225053668, -0.007757014594972134, -0.01181062962859869, -0.0033196720760315657, -0.06650499999523163, -0.021967334672808647, -0.015431143343448639, 0.02391320839524269, -0.015670331194996834, -0.001370524405501783, -0.013207759708166122, -0.042429402470588684, -0.01747085712850094, 0.006859649438410997, -0.022174421697854996, 0.004482651595026255, 0.0065426696091890335, -0.03144898638129234, 0.027461329475045204, -0.02362852916121483, -0.005337260197848082, 0.010649677366018295, 0.003985194489359856, 0.0038650301285088062, -0.00029605586314573884, -0.0010316013358533382, -0.0043053836561739445, 0.013816769234836102, -0.007223618216812611, 0.054195843636989594, 0.01337291020900011, 0.002585530513897538, -0.0005307741812430322, 0.01548136118799448, 0.02121131308376789, 0.021374545991420746, 0.021009448915719986, 0.017804689705371857, 0.010369979776442051, -0.025096097961068153, 0.005311192013323307, 0.028088804334402084, 0.0320446640253067, 0.027217278257012367, 0.01692012883722782, -0.02669604681432247, -0.018083728849887848, 0.010685991495847702, -0.056641414761543274, 0.028450462967157364, -0.031449876725673676, -0.03430239111185074, 0.014285262674093246, -0.011951301246881485, 0.007668552920222282, 0.011274932883679867, -0.0022528120316565037, 0.035569850355386734, 0.04360610619187355, 0.03386619687080383, 0.025518616661429405, -0.019320674240589142, -0.008540228009223938, -0.007216818165034056, 0.030232762917876244, 0.02094847522675991, 0.01724916882812977, -0.020231060683727264, -0.1258951723575592, 0.023592080920934677, 0.022394193336367607, 0.005039474926888943, -0.03938227519392967, -0.0075067379511892796, 0.01113593578338623, 0.019372357055544853, 0.0006370922201313078, -0.001263604499399662, -0.004571640398353338, 0.011491777375340462, 0.0192393995821476, 0.024858424440026283, 0.005845590494573116, 0.0314037911593914, -0.011871544644236565, -0.03454948961734772, 0.003756718011572957, 0.033682771027088165, 0.020671818405389786, 0.0287580918520689, -0.027437468990683556, -0.016837283968925476, -0.022189391776919365, 0.04525655508041382, 0.027303574606776237, -0.00542939780279994, 0.019621286541223526, -0.01110663078725338, 0.00504973903298378, 0.02873557060956955, 0.01308168563991785, 0.044074103236198425, -0.015498009510338306, -0.029636532068252563, 0.009710216894745827, 0.013219816610217094, -0.02304837666451931, 0.022832967340946198, 0.026816681027412415, -0.009935814887285233, -0.01011264231055975, -0.004513147287070751, 0.020192964002490044, -0.016740037128329277, -0.006330728065222502, 0.0018531335517764091, 0.01764211431145668, 0.013246174901723862, -0.019871806725859642, 0.018137501552700996, 0.014307324774563313, 0.023770364001393318, 0.01579604670405388, -0.004600232932716608, -0.031517378985881805, 0.008458907715976238, -0.03973507508635521, 0.03159467875957489, 0.013083155266940594, 0.029693368822336197, 0.05128607526421547, -0.03483860194683075, -0.009444673545658588, -0.027739448472857475, 0.0033992526587098837, -0.007528901100158691, -0.011369074694812298, 0.03172895684838295, 0.029463347047567368, 0.03365752100944519, -0.05133702978491783, -0.02851809747517109, -0.03581703454256058, 0.02842142805457115, -0.022266237065196037, 0.048310287296772, -0.0030827014707028866, 0.0063886577263474464, -0.02449844963848591, -0.019041674211621284, -0.006585623603314161, 0.024974443018436432, 0.009342462755739689, 0.025294257327914238, -0.02243209071457386, 0.051091257482767105, -0.012269115075469017, 0.021787704899907112, -0.058548133820295334, -0.0005942912539467216, -0.007689957972615957, 0.004051893949508667, 0.04024486988782883, 0.01725001260638237, 0.03870754688978195, -0.008514737710356712, -0.006978544872254133, -0.02727239951491356, -0.01907084509730339, -0.013891980051994324, 0.025535447522997856, -0.01471010036766529, 0.0010286479955539107, -0.01750515028834343, 0.034506905823946, 0.015571818687021732, 0.02234521321952343, -0.032912593334913254, -0.034824009984731674, 0.019148297607898712, -0.028041943907737732, 0.039238277822732925, -0.011052891612052917, 0.01637786626815796, -0.015516925603151321 ]
8ac88b2d708e6c6e6407bbbd9d9661fb3c6143fd
495
py
Python
molecule/ubuntu/tests/test_grafana.py
fiaasco/grafana
6a5963e43033d88b5bb4760d47755da1069ec26b
[ "MIT" ]
null
null
null
molecule/ubuntu/tests/test_grafana.py
fiaasco/grafana
6a5963e43033d88b5bb4760d47755da1069ec26b
[ "MIT" ]
null
null
null
molecule/ubuntu/tests/test_grafana.py
fiaasco/grafana
6a5963e43033d88b5bb4760d47755da1069ec26b
[ "MIT" ]
null
null
null
import os import testinfra.utils.ansible_runner testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') def test_package(host): """ check if packages are installed """ assert host.package('grafana').is_installed def test_service(host): """ Testing whether the service is running and enabled """ assert host.service('grafana-server').is_enabled assert host.service('grafana-server').is_running
24.75
63
0.739394
1
0.7851
[ 0.0011224645422771573, 0.024363039061427116, 0.007131085731089115, -0.00016171304741874337, 0.006013451609760523, -0.005067446734756231, -0.012043219991028309, 0.0018588098464533687, -0.008696727454662323, -0.0005826179403811693, 0.004096157383173704, 0.005255451425909996, 0.004953145515173674, -0.016594339162111282, 0.0016792950918897986, 0.018841661512851715, -0.05241299048066139, 0.004627694375813007, -0.0014069617027416825, 0.004364272579550743, -0.009114735759794712, 0.008630076423287392, 0.0073840138502418995, 0.008335733786225319, 0.006596172694116831, 0.0013529083225876093, 0.009058033116161823, 0.0033372503239661455, -0.010484565980732441, -0.01010766439139843, -0.0013578094076365232, -0.003453844925388694, -0.006447901017963886, -0.00791614968329668, 0.009749121032655239, -0.00363503978587687, 0.0009094846318475902, -0.019608963280916214, 0.012758957222104073, -0.007479868829250336, -0.004774740897119045, -0.015552491880953312, -0.004500688519328833, 0.0063604675233364105, -0.011296458542346954, 0.0024318022187799215, -0.0014125080779194832, 0.0034140562638640404, -0.014668896794319153, 0.003943593241274357, -0.013502141460776329, 0.003058766480535269, 0.016864337027072906, 0.0008453350747004151, -0.004374305251985788, -0.009269301779568195, 0.008473210968077183, -0.0006482797325588763, -0.010156978853046894, 0.0023149875923991203, -0.0038314643315970898, -0.003688707947731018, 0.005465558730065823, 0.005154195707291365, -0.016585012897849083, -0.005616059992462397, -0.002318552928045392, 0.0021549402736127377, -0.0021313666366040707, 0.007560200989246368, -0.0023036275524646044, -0.004003335256129503, 0.006415911018848419, 0.002415089402347803, 0.0070900507271289825, -0.005602121818810701, -0.0003710833552759141, 0.0011748418910428882, 0.00955271627753973, 0.005986185744404793, 0.0033881610725075006, -0.010241003707051277, 0.006078051868826151, 0.011095305904746056, 0.014672220684587955, 0.015199031680822372, 0.02204473689198494, -0.010615835897624493, 0.04515179991722107, 0.00704149017110467, -0.01164266001433134, 0.0029046975541859865, -0.007829680107533932, -0.002063253428786993, -0.002165804151445627, -0.03200377896428108, -0.0007986588170751929, -0.004423436708748341, -0.0034673919435590506, 0.0042864601127803326, -0.000052475308621069416, 0.0026975474320352077, -0.0016929805278778076, -0.0011037596268579364, -0.007750631310045719, 0.009307517670094967, -0.012217087671160698, 0.0008210400119423866, 0.009778287261724472, 0.0011104081058874726, -0.012234660796821117, -0.0015403114957734942, 0.0015711577143520117, -0.011494428850710392, 0.005655001383274794, 0.0005367636331357062, -0.008140037767589092, 0.058289770036935806, 0.00001685190545686055, 0.0032456093467772007, -0.0034780469723045826, 0.002427551196888089, -0.0038781175389885902, 0.005797055084258318, 0.008739234879612923, -0.0033883359283208847, 0.015152615495026112, 0.006908036768436432, 0.000604097091127187, 0.011504781432449818, 0.0004938117344863713, 0.010697578079998493, -0.00565704982727766, -0.00416989391669631, 0.003094072686508298, -0.009775537066161633, 0.007599928881973028, -0.0016589462757110596, -0.010605324991047382, -0.0011371633736416698, 0.00104203587397933, -0.010309024713933468, 0.0030498045962303877, -0.002603912027552724, 0.007106407079845667, -0.010973947122693062, -0.0063315825536847115, -0.005817145574837923, -0.0019234498031437397, 0.003519786521792412, 0.00996695552021265, 0.00349481706507504, 0.004881264176219702, -0.0038672613445669413, -0.008713613264262676, -0.002838471904397011, -0.008577410131692886, 0.0032416500616818666, 0.00995984859764576, 0.0059128617867827415, -0.00869961641728878, -0.004624270834028721, 0.0012882733717560768, 0.005178674124181271, -0.0017238302389159799, 0.000023722950572846457, -0.008271293714642525, 0.008104144595563412, 0.0031805974431335926, 0.004904950503259897, 0.012446019798517227, -0.005312503315508366, -0.0009279365185648203, 0.0013917654287070036, 0.005075130145996809, 0.00032231537625193596, 0.006314310245215893, 0.011084798723459244, -0.003584020072594285, -0.0028688604943454266, 0.007360654883086681, 0.003159734420478344, 0.01159775722771883, 0.009553243406116962, -0.0023208698257803917, -0.00027941985172219574, -0.003342081094160676, -0.00002937580575235188, 0.004404754377901554, -0.0025349711067974567, 0.006260881666094065, 0.003592011285945773, -0.015807660296559334, -0.009139091707766056, 0.0007534960750490427, -0.012898155488073826, 0.0000904287226148881, 0.011148194782435894, 0.014636280946433544, -0.002639258513227105, 0.006327667739242315, -0.010577771812677383, 0.002543278969824314, 0.008379763923585415, 0.0031253022607415915, -0.01636134833097458, -0.9537676572799683, 0.007683576084673405, 0.002877531573176384, -0.0014015438500791788, 0.004919517319649458, 0.0023451107554137707, 0.0014405091060325503, 0.002873502904549241, 0.017495477572083473, -0.011225525289773941, -0.00773082859814167, -0.00937954057008028, -0.012438887730240822, 0.0000349285255651921, -0.004851953126490116, -0.002055227989330888, -0.006939772516489029, -0.005394741892814636, -0.009081984870135784, -0.006582477129995823, -0.00032508638105355203, 0.005960568320006132, -0.0019697307143360376, 0.001057006069459021, -0.0009141763439401984, 0.004015530925244093, -0.009020600467920303, -0.0031323323491960764, -0.006546707823872566, -0.001824950217269361, -0.005004291422665119, -0.0191583801060915, -0.005007374100387096, -0.000923917512409389, 0.011813415214419365, -0.0010748769855126739, 0.011132289655506611, -0.004064022097736597, 0.004622207023203373, -0.007532322779297829, 0.0053718918934464455, 0.00019888932001776993, 0.005123992916196585, -0.0323566198348999, -0.00159764988347888, -0.0027571646496653557, -0.006523876450955868, 0.009097835049033165, -0.0016785841435194016, -0.0009794451761990786, 0.0002912133058998734, -0.0023251944221556187, 0.008329132571816444, -0.01338893361389637, 0.0022687800228595734, -0.003848911728709936, -0.003626628778874874, -0.003622437361627817, -0.011244261637330055, 0.0021276099141687155, 0.005544452462345362, -0.000952394213527441, -0.003676485503092408, -0.00255641364492476, 0.0023893846664577723, 0.0019018864259123802, 0.0021881014108657837, -0.014046099036931992, -0.007085499353706837, -0.0030144350603222847, 0.0026458664797246456, -0.005288729909807444, -0.00462695024907589, 0.006174397189170122, -0.011031575500965118, 0.0029722813051193953, 0.0011393267195671797, 0.00023807017714716494, -0.012594809755682945, -0.00006790221959818155, -0.009401618503034115, -0.006904970854520798, 0.005070360843092203, -0.005595120135694742, -0.0024898166302591562, 0.0024678579065948725, 0.0006179973715916276, 0.008799003437161446, -0.00290300534106791, 0.00664370134472847, 0.014805778861045837, -0.0061277770437300205, -0.005250006914138794, 0.006802183575928211, 0.008798878639936447, 0.0005272720591165125, -0.0003079554589930922, -0.0016296362737193704, 0.009612159803509712, 0.007348742336034775, 0.0013501208741217852, 0.005154035519808531, -0.0035352895502001047, 0.0069097899831831455, 0.0007204376743175089, 0.001060348586179316, -0.0022636738140136003, -0.0009015014511533082, -0.004047134891152382, 0.00021485841716639698, -0.004902230110019445, -0.002676454372704029, -0.012612841092050076, -0.0070869531482458115, -0.0018954091938212514, 0.00039012014167383313, 0.0028179935179650784, -0.003818139201030135, -0.001388914999552071, 0.0037425586488097906, 0.009047470055520535, -0.0002545798197388649, -0.0003008574713021517, 0.003385227872058749, 0.004643052816390991, -0.007360149174928665, 0.013165099546313286, -0.01108933798968792, 0.004465984646230936, -0.001634217333048582, -0.018944570794701576, 0.009508245624601841, 0.009533205069601536, -0.009120449423789978, -0.0012693125754594803, 0.006440579425543547, 0.002360134618356824, -0.0010811773827299476, -0.00644926680251956, -0.0005183132016099989, -0.01635328307747841, -0.0018742495449259877, 0.023903047665953636, 0.0012210891582071781, 0.010042511858046055, 0.008951240219175816, -0.004518129862844944, 0.00319573818705976, 0.006939816288650036, 0.00031266090809367597, 0.014023786410689354, -0.008356695994734764, -0.001914885826408863, 0.0012580350739881396, -0.007227330468595028, 0.0008738570613786578, 0.006396184675395489, 0.003065878991037607, -0.0020772635471075773, 0.0021924846805632114, -0.006844625808298588, -0.005653820466250181, -0.01796003431081772, -0.002050525974482298, 0.004116286989301443, -0.005190874915570021, 0.009370682761073112, -0.01273789256811142, 0.000265217327978462, 0.005531358998268843, 0.005828715395182371, 0.0015114585403352976, -0.0000920340753509663, 0.004912135656923056, 0.008848786354064941, -0.005221912171691656, 0.004244971554726362, -0.00019684899598360062, -0.0005632480606436729, 0.00225359876640141, 0.0110873868688941, -0.00917050987482071, -0.004511062055826187, 0.005558242555707693, 0.0009693526080809534, 0.003530003596097231, -0.000492986524477601, -0.007879022508859634, -0.005466022528707981, 0.00428046565502882, -0.0021703848615288734, 0.0016307237092405558, 0.0004607515293173492, 0.001473698066547513, -0.008893460035324097, 0.00010801362805068493, -0.0038851574063301086, -0.010737438686192036, 0.007419394329190254, -0.004034743178635836, -0.0013495748862624168, 0.013653263449668884, 0.002921914914622903, -0.012221076525747776, 0.006792258471250534, 0.008656210266053677, -0.002868098672479391, 0.0044949958100914955, 0.004999831784516573, -0.007035916205495596, -0.021250618621706963, -0.000756150227971375, -0.015084809623658657, 0.008632607758045197, -0.0020947065204381943, 0.003176614176481962, -0.006953109987080097, 0.006255865562707186, 0.004516165237873793, -0.013389507308602333, -0.0017316017765551805, -0.008690839633345604, 0.010700352489948273, -0.0037283687852323055, -0.0015927643980830908, -0.005303208250552416, -0.004928079899400473, -0.0043171970173716545, -0.002340208273380995, -0.002456612652167678, 0.0032410575076937675, 0.0027317306958138943, -0.0013781859306618571, 0.005548006854951382, -0.006402632687240839, 0.0009033933747559786, 0.003379007102921605, -0.012171153910458088, 0.0022389725781977177, 0.005661431234329939, -0.0008743956568650901, -0.0009103308548219502, 0.001205229084007442, -0.0011019663652405143, -0.004346800036728382, -0.011569551192224026, -0.0019261077977716923, -0.004179342649877071, 0.001442121108993888, -0.009119602851569653, -0.002049087081104517, -0.007904835045337677, 0.007735468912869692, -0.008992915041744709, 0.006498519331216812, 0.004405716434121132, -0.005549079738557339, 0.005581383593380451, -0.003908578306436539, 0.0019839410670101643, 0.005557172000408173, 0.006080084480345249, 0.004516967106610537, -0.005684238858520985, -0.013803461566567421, 0.013116766698658466, -0.009143917821347713, -0.0023169806227087975, 0.015429921448230743, 0.004408270586282015, 0.00872743409126997, 0.0011961000273004174, -0.0036453239154070616, 0.005352168809622526, 0.010019957087934017, -0.015001657418906689, 0.0026363953948020935, -0.001766188652254641, -0.00031136770849116147, 0.004335591569542885, -0.003173197153955698, 0.004304967820644379, 0.00727633573114872, 0.0036297300830483437, -0.005009959917515516, -0.005453420337289572, 0.0001744638429954648, 0.00633860332891345, -0.013456960208714008, 0.0002837718348018825, -0.0026325166691094637, -0.0028404605109244585, -0.0009891306981444359, 0.0003312980115879327, -0.0006340918480418622, 0.0057234987616539, -0.0019170433515682817, 0.0063526565209031105, 0.003425280563533306, -0.0021553526166826487, 0.018171299248933792, -0.006030600052326918, -0.009234675206243992, 0.005958952941000462, 0.0019101224606856704, 0.002226335695013404, -0.00516817020252347, -0.005390571430325508, 0.0010667358292266726, 0.0038388953544199467, -0.002922642510384321, -0.009642709977924824, -0.0021584678906947374, 0.0022477125748991966, -0.011089233681559563, 0.0009931001113727689, 0.011594289913773537, -0.00068519520573318, 0.004674120340496302, 0.0002260575711261481, -0.006029350683093071, -0.012005540542304516, 0.05439900606870651, -0.0004926724941469729, 0.00350040290504694, 0.004468321334570646, -0.006830804981291294, -0.0009155230945907533, -0.0044337003491818905, 0.008673134259879589, -0.00880366750061512, -0.008904442191123962, 0.010739834047853947, -0.0007581192767247558, 0.007246499415487051, -0.0008650855161249638, -0.001260493416339159, 0.021421821787953377, -0.004779440816491842, -0.014920124784111977, -0.019128084182739258, 0.007831587456166744, -0.008312073536217213, -0.005173566285520792, 0.005682476796209812, -0.006381503771990538, -0.003980323206633329, 0.0010431235423311591, 0.003080477239564061, 0.0036612399853765965, 0.00007199233368737623, -0.00271413242444396, -0.0050007314421236515, 0.001988644478842616, 0.002337811281904578, 0.009206708520650864, 0.010591956786811352, -0.0022116827312856913, 0.004205920267850161, -0.0008703985367901623, 0.002901754342019558, 0.001664875540882349, 0.003950198646634817, 0.006738611496984959, 0.0006572192651219666, -0.0045265802182257175, 0.005434356164187193, 0.00288538821041584, -0.003611964173614979, 0.011909947730600834, 0.0008764315280131996, -0.0037078820168972015, 0.006419860292226076, 0.010320013388991356, 0.002174614230170846, 0.006738861091434956, -0.0027074776589870453, 0.0013159579830244184, 0.004205748904496431, -0.005203709937632084, -0.0174931138753891, -0.004142738878726959, 0.0046361880376935005, 0.008357508108019829, -0.0017007493879646063, 0.00807860679924488, 0.0023568226024508476, -0.005339131224900484, -0.011458582244813442, -0.002248820848762989, -0.0022212741896510124, -0.002645285800099373, 0.0026019432116299868, 0.071086086332798, -0.009183716028928757, -0.0012772027403116226, -0.0074675981886684895, -0.0007784954505041242, 0.0006829210906289518, 0.0014377431944012642, -0.0030327560380101204, -0.003720548702403903, 0.0053715272806584835, 0.0034292787313461304, -0.007230386603623629, -0.007860859856009483, 0.0017916994402185082, 0.0037184201646596193, -0.004773901775479317, 0.008547286503016949, 0.006116507574915886, -0.010987008921802044, -0.0005076656234450638, -0.014104340225458145, -0.005341379437595606, -0.006640780251473188, -0.009167220443487167, -0.004008595831692219, -0.002092427108436823, 0.0015275062760338187, 0.0028934702277183533, 0.0048547713086009026, -0.0007386847864836454, 0.0041423519141972065, -0.0012975916033610702, 0.0023175596725195646, -0.005321260541677475, -0.0012253636959940195, -0.00473549822345376, 0.0061933379620313644, 0.0047716121189296246, -0.01388406939804554, -0.007190619129687548, -0.0036574455443769693, -0.0002863268891815096, -0.006746611092239618, 0.007006638217717409, 0.0013906408566981554, 0.005305158440023661, -0.005213756579905748, -0.0007342048920691013, -0.004982480313628912, -0.0026046873535960913, -0.01123312208801508, 0.006363289896398783, -0.1840243637561798, 0.005612723995000124, 0.0034591371659189463, -0.0026028864085674286, -0.00750700244680047, -0.01719353348016739, -0.0010607674485072494, 0.006779729388654232, 0.009838641621172428, 0.0015750492457300425, 0.0009681051014922559, -0.003254621522501111, 0.006559228524565697, 0.004049692768603563, -0.0035425142850726843, -0.0067418948747217655, -0.00016967314877547324, -0.00589517317712307, 0.0005648306105285883, 0.0034188523422926664, 0.004305080510675907, 0.009824568405747414, 0.0008674666751176119, 0.00007032003486528993, 0.00046425615437328815, -0.007945239543914795, 0.007817702367901802, 0.0010678705293685198, 0.0040868353098630905, -0.01306589413434267, -0.004137013573199511, -0.0030496278777718544, -0.0019526372198015451, -0.000991438515484333, 0.008071922697126865, -0.0024722313974052668, 0.009393386542797089, 0.005840233527123928, -0.006010663229972124, 0.006696269381791353, -0.007584074046462774, 0.02523214928805828, 0.003188913920894265, 0.004165948834270239, 0.0002680328325368464, -0.0049199303612113, -0.006620606407523155, 0.006860809866338968, 0.00007530934090027586, 0.010383343324065208, -0.009707516990602016, -0.0032741634640842676, 0.003970462363213301, 0.01879802905023098, -0.00586856622248888, -0.007892746478319168, -0.0072252871468663216, -0.000163238073582761, 0.003755623707547784, 0.009622658602893353, 0.013926585204899311, -0.0009068232029676437, 0.009479224681854248, -0.006981278769671917, -0.022241678088903427, 0.0032279270235449076, -0.0025294055230915546, -0.009532478637993336, 0.0035967754665762186, 0.0067377844825387, 0.011846384033560753, 0.000314504315610975, 0.007059852592647076, -0.0012087837094441056, 0.0027509985957294703, 0.000819197972305119, 0.008940652012825012, -0.0018486089538782835, 0.00647343136370182, -0.007684248965233564, 0.009820675477385521, -0.011726117692887783, -0.0025841561146080494, 0.0005100023117847741, -0.005221870262175798, 0.013627483509480953, 0.004817510489374399, -0.004881700500845909, -0.0011630113003775477, -0.010895263403654099, -0.0050888825207948685, 0.0033626656513661146, 0.004677880089730024, -0.008828539401292801, -0.001314862398430705, -0.0037331876810640097, 0.011922132223844528, 0.008197353221476078, -0.008940747939050198, 0.006976386997848749, 0.003914589993655682, -0.005767579190433025, 0.0011820937506854534, -0.005613913293927908, 0.0027716627810150385, 0.0045784711837768555, -0.009401780553162098, -0.006436596158891916, 0.008826677687466145, -0.007121429778635502, -0.00703264819458127, 0.005412856582552195, -0.010040681809186935, -0.008647161535918713, 0.0009314455674029887, -0.010707433335483074, -0.00004894354788120836 ]
8ac941eb3b632a517433fbaf339a5dae04e7e556
6,534
py
Python
heatsink.py
sww1235/heatsink-calc
3f28ac33b629ab5a12ddea4964f6dbe7dbc3e759
[ "MIT" ]
1
2020-11-20T07:09:00.000Z
2020-11-20T07:09:00.000Z
heatsink.py
sww1235/heatsink-calc
3f28ac33b629ab5a12ddea4964f6dbe7dbc3e759
[ "MIT" ]
null
null
null
heatsink.py
sww1235/heatsink-calc
3f28ac33b629ab5a12ddea4964f6dbe7dbc3e759
[ "MIT" ]
null
null
null
"""Class representations of heatsinks.""" import math from scipy import constants as const from materials import Aluminium_6063 as aluminium class Heatsink: """ A Heatsink. Extended by form factor subclasses """ def __init__(self, material, configuration): """Init material and configuration variables.""" self.material = material self.configuration = configuration class CylindricalAnnularFin(Heatsink): """Extend base heatsink class with a cylindrical annular fin heatsink.""" def __init__(self, material, finSpacing, finRadius, finThickness, cylinderDiameter, numberOfFins, ambAirTemp, maxJunctionTemp, maxSurfaceTemp): """ Init remainder of class variables. NOTE: all models are based off of the finSpacing variable NOTE: using the simplified model for calculation efficiency. finSpacing : gap between adjacent fins finRadius : radius of fin minus central support cylinder (alternatively, fin depth) finThickness : thickness of individual fin cylinderDiameter: diameter of support cylinder heatsinkLength : overall axial length of heatsink overall diameter: outside diameter of heatsink including fins. """ self.finSpacing = finSpacing # in meters self.finRadius = finRadius # in meters self.finThickness = finThickness # in meters self.cylinderDiameter = cylinderDiameter # in meters self.numberOfFins = numberofFins self.heatsinkLength = ((self.finThickness * self.numberOfFins) + ((self.numberOfFins - 1) * self.finSpacing)) self.overallDiameter = self.cylinderDiameter + (2 * finRadius) self.ambAirTemp = ambAirTemp # degrees kelvin self.maxJunctionTemp = maxJunctionTemp self.maxSurfaceTemp = maxSurfaceTemp """ NOTE: in order to prevent ridiculously long variable names, all Nusselt Numbers are abbreviated as follows: nn = Nusselt Number nn0 = Nusselt Number 0 (Diffusive Limit) nnOut = Nusselt Number for outer surfaces nnIn = Nusselt Number for inner surfaces nnInT = Nusselt Number for the thin boundry layer of inner surface nnInFD = Nusselt Number for fully developed regime inner surface """ # thermal diffusivity of air at atmospheric pressure at 25C alpha = 22.39 * 10**(-6) # (meters^2) / seconds # Volumetric coefficient of thermal expansion beta = aluminium.expansionCoefficient # 1/kelvin heatsinkSurfaceTemp = # TODO kelvin # at atmospheric pressure at 25C kinematicViscosity = 15.52 * 10**(-6) # meter^2/second deltaT = heatsinkSurfaceTemp - ambAirTemp # kelvin hLoD = self.heatsinkLength / self.overallDiameter cDoD = self.cylinderDiameter / self.overallDiameter oneChannelArea = (math.pi * (((self.overallDiameter**2 - self.cylinderDiameter**2) / 2) + (self.cylinderDiameter * self.finSpacing))) # area of circumscribed cylinder areaCC = (math.pi * (((self.overallDiameter**2) / 2) + self.overallDiameter * self.heatsinkLength)) # meter^2 # inner surface area of heatsink areaIn = (self.numberOfFins - 1) * oneChannelArea # meter^2 # outer surface area of heatsink areaOut = (math.pi * (((self.overallDiameter**2) / 2) + (self.numberOfFins * self.overallDiameter * self.finThickness))) # meter^2 # overall area of heatsink areaHS = areaIn + areaOut # meter^2 RayleighNbrFinSpacing = ((const.g * beta * deltaT * self.finSpacing**4) / (kinematicViscosity * alpha * self.overallDiameter)) RayleighNbrOverallDiameter = ((const.g * beta * deltaT * self.overallDiameter**3) / (kinematicViscosity * alpha)) if 0.1 <= hLoD <= 8: self.nn0 = ((3.36 + (0.087 * hLoD)) * math.sqrt(areaCC) * (self.finSpacing / areaHS) ) if 0.1 <= (self.finThickness * self.numberOfFins / self.overallDiameter) <= 8: self.nnOut = ((0.499 - (0.026 * math.log(self.finThickness * self.numberOfFins / self.overallDiameter))) * math.pow(RayleighNbrFinSpacing, 0.25) * (areaOut/areaHS) ) if (0.1 <= cdoD <= 8) and (2.9 * 10**4 <= RayleighNbrOverallDiameter <= 2.3 * 10**5): nnInT = ((0.573-(0.184 * cdoD) + (0.0388 * cdoD**2)) * math.pow(RayleighNbrFinSpacing, 0.25)) nnInFD = (((0.0323 - (0.0517 * cdoD) + (0.11 * cdoD**2)) * math.pow(RayleighNbrFinSpacing, 0.25)) + (0.0516 + (0.0154 * cdoD) - (0.0433 * cdoD**2) + (0.0792 * cdoD**3)) * RayleighNbrFinSpacing) n = 1 self.nnIn = (math.pow(math.pow(nnInT, -n) + math.pow(nnInFD, -n), (-1/n) ) * (areaIn/areaHS) ) self.nn = (self.nnIn + self.nnOut + self.nn0) super(Child, self).__init__(material, self.__name__) """ Nusselt number = (Qconv * b) / (Ahs deltaT k) Qconv = heat flow rate by convection (Watts) b = finSpacing (meters) Ahs = Area of heatsink (meter^2) deltaT = temperature difference between surface temp of heatsink and ambient air temp. k = thermal conductivity of material (Watts / (meter kelvin)) """
44.148649
78
0.520814
1
2.0196
[ -0.04087529703974724, 0.016519298776984215, 0.00013122698874212801, 0.006227006204426289, 0.030876677483320236, -0.004937518388032913, 0.0022507680114358664, -0.009078839793801308, -0.0036410524044185877, 0.03822414204478264, 0.02697218395769596, 0.02822600118815899, -0.006869949400424957, -0.003151496173813939, -0.03467454016208649, 0.020754272118210793, 0.1441776603460312, -0.04649060592055321, -0.004388692323118448, -0.013429065234959126, 0.0022130708675831556, 0.01293957605957985, -0.035561453551054, 0.030722275376319885, 0.0451212003827095, 0.049019794911146164, 0.03919817507266998, -0.014898441731929779, 0.02751595713198185, -0.014051254838705063, -0.01713079959154129, 0.03643742576241493, 0.008741244673728943, 0.018040554597973824, -0.037960510700941086, 0.06879997998476028, 0.020706353709101677, -0.07625911384820938, -0.013542680069804192, 0.006875494495034218, -0.00787863414734602, 0.013884857296943665, -0.01873875968158245, -0.06082700192928314, -0.02978404238820076, -0.04080209508538246, 0.00582517497241497, 0.0032315587159246206, -0.014325566589832306, 0.026787906885147095, -0.005138585809618235, 0.04336589574813843, 0.010314054787158966, -0.013352308422327042, 0.006683058105409145, -0.03524014353752136, -0.00824818480759859, 0.0019493956351652741, -0.02464097924530506, -0.024937063455581665, -0.03355752304196358, -0.015933481976389885, 0.018903056159615517, -0.02300201915204525, 0.065787672996521, 0.017021989449858665, -0.01845267042517662, -0.019845103845000267, 0.02488590031862259, -0.012150532566010952, -0.014915079809725285, 0.03241148963570595, 0.030014241114258766, 0.0859706923365593, 0.004513284657150507, -0.01911531575024128, -0.023464083671569824, -0.0129921305924654, -0.008307717740535736, 0.019166545942425728, -0.03041961044073105, 0.01707983948290348, -0.011405106633901596, 0.012281985022127628, -0.005160953849554062, -0.007478779647499323, 0.06790000945329666, -0.02147739753127098, 0.011529212817549706, -0.006524947937577963, -0.06785354763269424, -0.026908094063401222, -0.07092781364917755, -0.011421812698245049, -0.017580891028046608, -0.03776228427886963, 0.009167673997581005, 0.0017461400711908937, 0.021016014739871025, 0.023305071517825127, 0.021755916997790337, -0.02361798658967018, 0.07364217936992645, 0.0027577602304518223, -0.0064668310806155205, -0.005715642590075731, -0.02589413709938526, 0.023855725303292274, 0.0015928318025544286, -0.0019565080292522907, -0.04436752572655678, -0.022403381764888763, 0.000931253656744957, -0.012122453190386295, 0.01843286119401455, -0.04730219021439552, 0.018310463055968285, 0.010265374556183815, 0.019986752420663834, 0.05908781290054321, -0.00416675815358758, 0.005658759735524654, 0.002398327924311161, 0.006029900163412094, -0.03511006012558937, 0.08640134334564209, -0.0693073645234108, 0.030957112088799477, 0.03718973696231842, -0.01373298279941082, -0.0030798984225839376, -0.00738103361800313, -0.005520058795809746, 0.0007079875795170665, 0.019143909215927124, 0.002685708925127983, -0.019121553748846054, 0.02975747548043728, -0.07094821333885193, 0.02391756884753704, -0.012430139817297459, -0.03603288531303406, 0.005806017201393843, -0.006418364588171244, -0.013646412640810013, -0.04507740959525108, -0.02147158794105053, 0.002295471029356122, -0.045079171657562256, -0.0020508498419076204, 0.028367184102535248, 0.042432285845279694, 0.011476517654955387, 0.004655714612454176, -0.015559359453618526, 0.006985269952565432, 0.016603969037532806, -0.029592234641313553, 0.013232420198619366, 0.0002089095942210406, -0.008846161887049675, 0.00007593197369715199, 0.029149457812309265, 0.01914690062403679, 0.025984439998865128, 0.037924498319625854, -0.02218329720199108, 0.025713972747325897, 0.005319777876138687, -0.015093937516212463, 0.042079005390405655, -0.006415840238332748, -0.028100991621613503, 0.007177374325692654, -0.022225985303521156, 0.0014053734485059977, 0.025262121111154556, 0.02375691384077072, -0.01853175461292267, 0.009686140343546867, 0.022728143259882927, 0.0007033280562609434, -0.005865128245204687, 0.0539032518863678, -0.009744183160364628, -0.02956744097173214, -0.038326624780893326, -0.06366337835788727, -0.02787170559167862, -0.017333269119262695, -0.012070758268237114, 0.02522549033164978, 0.02851310558617115, -0.02682921476662159, 0.02622964233160019, -0.03989065811038017, 0.006229139398783445, 0.023245463147759438, -0.005116168409585953, -0.01613922417163849, -0.026035111397504807, -0.010547846555709839, -0.020014051347970963, -0.025215791538357735, -0.022325845435261726, -0.005870333407074213, -0.5797091126441956, 0.019753044471144676, -0.004303868860006332, -0.0042474172078073025, 0.018050499260425568, 0.04550694301724434, -0.03656218573451042, 0.043638672679662704, -0.0048636337742209435, -0.03728068992495537, -0.015313893556594849, -0.03477109596133232, -0.05757483094930649, 0.011398782022297382, -0.02522592805325985, -0.038644690066576004, 0.00455131009221077, 0.04242610186338425, 0.004728653933852911, 0.03589361160993576, -0.003912678454071283, -0.05562783032655716, -0.013675900176167488, 0.017816212028265, 0.019305074587464333, 0.007748802658170462, -0.006902750581502914, -0.001411760225892067, -0.0008418355719186366, 0.02667587250471115, -0.02259051613509655, 0.027162974700331688, -0.005868978798389435, -0.002408584114164114, 0.026715561747550964, -0.0012724216794595122, 0.016563735902309418, -0.014340403489768505, 0.023595768958330154, 0.0128426318988204, -0.01400006003677845, 0.0231032632291317, 0.00501009076833725, -0.05287788435816765, -0.07004574686288834, -0.02836926467716694, -0.018695572391152382, -0.0371648371219635, 0.05034564062952995, -0.02408595196902752, -0.01732511632144451, 0.052496351301670074, 0.04886079579591751, -0.014298000372946262, -0.012605743482708931, -0.04419587925076485, 0.013009173795580864, -0.0196940079331398, -0.008390733040869236, -0.0028737576212733984, 0.05721993371844292, -0.023092681542038918, -0.042663369327783585, 0.035226017236709595, 0.008320421911776066, 0.01665019616484642, 0.004071005620062351, -0.04299379512667656, -0.00935446284711361, 0.0045915828086435795, -0.03721122443675995, 0.00005958641486358829, -0.0534377321600914, 0.11520256847143173, 0.02829701639711857, -0.028190752491354942, -0.020275598391890526, -0.02326570637524128, 0.023401929065585136, -0.030893998220562935, 0.016575777903199196, 0.014308211393654346, -0.01372948382049799, -0.016733268275856972, 0.020209958776831627, -0.0024843376595526934, -0.018281273543834686, 0.02865958958864212, -0.029791172593832016, 0.036621056497097015, 0.0055023799650371075, 0.04047676920890808, -0.025979647412896156, 0.022808685898780823, 0.002564628142863512, 0.004305231850594282, -0.05583471804857254, 0.06457401067018509, -0.00861203670501709, 0.044069208204746246, -0.027109703049063683, 0.017469871789216995, -0.006676707416772842, -0.0335177443921566, -0.07052566111087799, -0.016041148453950882, -0.07796142995357513, -0.00983890239149332, 0.022975686937570572, -0.025791605934500694, 0.04718441888689995, 0.014455411583185196, -0.028412269428372383, 0.04469134286046028, 0.02814674936234951, -0.015274074859917164, 0.0116032799705863, -0.05800648033618927, 0.029965199530124664, 0.014319589361548424, 0.009610988199710846, -0.03750793635845184, -0.00609721802175045, 0.02261473424732685, -0.012927430681884289, 0.031124990433454514, -0.033157750964164734, -0.04813702031970024, 0.009689876809716225, 0.012876763939857483, -0.003406786359846592, -0.010678309015929699, -0.03646179288625717, 0.022986844182014465, -0.02192656882107258, -0.029187601059675217, -0.007369645871222019, -0.020489025861024857, 0.02890816703438759, 0.017273999750614166, -0.0015568684320896864, 0.002488651778548956, 0.07361999899148941, -0.021252073347568512, -0.002892120508477092, -0.02299828827381134, 0.03217976912856102, 0.012136423960328102, 0.005676900967955589, 0.021673303097486496, 0.001090914011001587, 0.029945477843284607, 0.022534852847456932, 0.03506980091333389, 0.008696753531694412, 0.011866443790495396, -0.008818646892905235, 0.040308039635419846, 0.043993573635816574, 0.039143845438957214, 0.01308039203286171, -0.02185547538101673, -0.029576720669865608, 0.044937845319509506, 0.013335742987692356, -0.00006972964911255985, -0.01197385136038065, 0.037662383168935776, 0.012768122367560863, 0.06194069981575012, 0.04361627995967865, -0.011965827085077763, 0.023513007909059525, 0.0830516517162323, -0.0044010174460709095, 0.03311939910054207, -0.02865438349545002, -0.019856693223118782, -0.013479970395565033, 0.0015882692532613873, -0.027296604588627815, -0.026607228443026543, -0.03162993863224983, 0.0008979785488918424, 0.017239250242710114, 0.047169383615255356, 0.006617044564336538, -0.015770338475704193, -0.030010627582669258, -0.02878369390964508, 0.024053502827882767, 0.03913399949669838, -0.031336963176727295, -0.009013728238642216, -0.033824313431978226, -0.030304409563541412, -0.029276933521032333, 0.005024856887757778, 0.007265820167958736, -0.013573426753282547, -0.022062717005610466, 0.0507105253636837, 0.017931431531906128, -0.0038068026769906282, 0.0013305348111316562, 0.006972607225179672, 0.02371506579220295, 0.004167729988694191, 0.007177609950304031, 0.026867715641856194, -0.03605446219444275, -0.010212521068751812, 0.028037579730153084, -0.02497529797255993, -0.041706424206495285, 0.05533929541707039, -0.011141260154545307, -0.017994709312915802, 0.027176273986697197, -0.003406057832762599, -0.055858269333839417, -0.03307028487324715, 0.03634273260831833, 0.03334413096308708, 0.006149861961603165, 0.007145120296627283, -0.035883113741874695, -0.026474488899111748, -0.006404923740774393, -0.021061202511191368, -0.004014461301267147, -0.03551203012466431, 0.0014730907278135419, -0.02530112862586975, 0.03132730722427368, -0.015555017627775669, 0.022023439407348633, -0.020872317254543304, 0.020887039601802826, -0.034010149538517, 0.04129510000348091, -0.048768576234579086, 0.017829474061727524, -0.010475320741534233, -0.03178437426686287, -0.009059865958988667, -0.012632270343601704, 0.04165857285261154, -0.027308467775583267, -0.005434358958154917, -0.027697918936610222, 0.07061648368835449, 0.03988466039299965, -0.0008321477216668427, 0.018291035667061806, 0.04631458967924118, 0.00565855810418725, -0.015548127703368664, 0.024307413026690483, 0.014872139319777489, 0.007736263796687126, -0.028044631704688072, -0.02517872489988804, -0.02713814750313759, 0.030584603548049927, 0.031265322118997574, -0.013501184061169624, -0.008601166307926178, 0.031628742814064026, 0.030646851286292076, -0.014134041965007782, -0.03220031410455704, 0.011027280241250992, 0.0004636079247575253, -0.009925412945449352, -0.0184432752430439, -0.0024887030012905598, -0.042058028280735016, -0.026484549045562744, 0.04979293420910835, -0.03865603357553482, 0.005169600248336792, 0.030294204130768776, 0.015172433108091354, 0.0066889068111777306, -0.005094373133033514, -0.014701738022267818, 0.007369423285126686, -0.05316660553216934, -0.0043169655837118626, 0.021636495366692543, -0.02905169315636158, 0.028493942692875862, 0.004357613157480955, -0.014268402010202408, 0.02174680307507515, -0.008541501127183437, 0.002223184797912836, 0.030261270701885223, 0.015278014354407787, 0.06399340182542801, -0.005760496947914362, -0.021251967176795006, -0.036667414009571075, -0.008322569541633129, -0.01802239380776882, 0.015910828486084938, 0.006463203113526106, 0.008867422118782997, 0.03218056261539459, 0.012002724222838879, 0.027454735711216927, -0.03299902752041817, 0.03722817823290825, 0.03143668174743652, -0.000889544899109751, 0.03693090006709099, 0.024471934884786606, 0.04311094805598259, 0.012692045420408249, -0.00012319009692873806, 0.006004179362207651, -0.019346809014678, -0.018020138144493103, 0.004962786100804806, -0.045676954090595245, -0.03099556267261505, -0.006726058200001717, -0.0014152959920465946, 0.020234452560544014, 0.00375415594317019, 0.017224693670868874, -0.014668473042547703, 0.022504674270749092, 0.014576543122529984, -0.008702761493623257, 0.04265069589018822, 0.04116367548704147, 0.007311745081096888, -0.01825057715177536, -0.009208106435835361, 0.007949135266244411, -0.019513333216309547, 0.010655451565980911, 0.016969449818134308, 0.01601279340684414, -0.016177332028746605, -0.014418644830584526, 0.039630573242902756, 0.05703473091125488, -0.047217704355716705, -0.023912684991955757, -0.03514372929930687, -0.002979692304506898, 0.0053346892818808556, -0.0776328444480896, -0.009240801446139812, 0.03106975182890892, -0.01402620691806078, 0.004499262198805809, -0.01328990701586008, 0.027355197817087173, -0.012160252779722214, -0.02405042015016079, 0.01591598242521286, -0.0463838167488575, 0.02239830605685711, -0.004285661969333887, 0.007249202113598585, -0.018334968015551567, 0.00001533252179797273, -0.029292032122612, -0.0018164272187277675, -0.007704951334744692, -0.05647079274058342, 0.05081810802221298, 0.062141042202711105, -0.03153877332806587, 0.008858646266162395, -0.04313800856471062, 0.044771719723939896, -0.02529018372297287, 0.055385835468769073, -0.03612136095762253, 0.06614374369382858, -0.05568062514066696, -0.007546690758317709, 0.04756738245487213, -0.06223203241825104, -0.039424244314432144, -0.009819839149713516, -0.013099387288093567, 0.01564469002187252, 0.028178004547953606, 0.005507718771696091, 0.010789444670081139, -0.01582315005362034, -0.02781202457845211, 0.01906786859035492, -0.008199489675462246, 0.002378480974584818, -0.03357565030455589, -0.0005936285597272217, -0.010094710625708103, -0.007490742020308971, 0.008145037107169628, 0.0379798449575901, -0.00517473416402936, -0.0015243485104292631, 0.012732453644275665, 0.0033290928695350885, 0.023208262398838997, -0.00766042061150074, -0.05587643012404442, 0.010810120962560177, 0.028311938047409058, -0.038966063410043716, 0.0040686288848519325, -0.0027422336861491203, -0.021789658814668655, -0.050873566418886185, -0.00248500844463706, -0.0214613676071167, -0.00939393974840641, -0.009674834087491035, 0.008677752688527107, 0.00023031070304568857, 0.03586002066731453, 0.012570645660161972, 0.012883585877716541, -0.040473803877830505, -0.09401573240756989, 0.0039107343181967735, 0.014222588390111923, 0.004169519990682602, 0.0003607872349675745, 0.012910811230540276, -0.04251581057906151, 0.017614014446735382, -0.0011977686081081629, 0.03780903294682503, -0.01353487093001604, -0.029742615297436714, 0.03168788552284241, -0.00664568180218339, -0.04738881066441536, 0.01202938798815012, 0.016284968703985214, 0.017983194440603256, -0.010847524739801884, -0.036866553127765656, 0.003229056019335985, 0.02047679014503956, 0.03881588578224182, -0.027641067281365395, 0.001880248193629086, 0.04195074737071991, 0.03151823580265045, 0.023508459329605103, 0.01465177908539772, -0.015976233407855034, 0.040928009897470474, -0.011876205913722515, -0.00011313211143715307, -0.0226407740265131, 0.03453081473708153, 0.027695979923009872, -0.0002899374521803111, 0.016192665323615074, 0.010969302617013454, -0.006465342361479998, 0.005223358515650034, -0.024822451174259186, 0.023258697241544724, 0.01122049055993557, -0.02418692223727703, 0.01289056520909071, 0.022641882300376892, 0.015289983712136745, -0.03347652405500412, -0.033006805926561356, 0.015547746792435646, 0.008476821705698967, -0.0030124543700367212, -0.006763847544789314, 0.011661912314593792, -0.007937755435705185, 0.022912753745913506, -0.038340069353580475, 0.06190531328320503, -0.049928512424230576, -0.009373758919537067, -0.041670870035886765, 0.017016831785440445, 0.0375102162361145, -0.04503094032406807, 0.019649362191557884, -0.018206775188446045, 0.053362857550382614, -0.03317924961447716, -0.03810260444879532, 0.007182701490819454, 0.02558698132634163, -0.018099060282111168, 0.03356681764125824, 0.002022793283686042, 0.04788728058338165, 0.02294454537332058, -0.024035263806581497, -0.0070508322678506374, -0.021191280335187912, -0.033371541649103165, -0.005285475868731737, -0.08519712835550308, 0.002240207511931658, 0.021898187696933746, 0.04153762012720108, 0.0007182663539424539, -0.0213451087474823, -0.08334485441446304, -0.01606571115553379, -0.007228218484669924, -0.014786451123654842, -0.020831339061260223, -0.047914646565914154, 0.004067515023052692, -0.0361836738884449, -0.015301335602998734, 0.027139199897646904, -0.0024529676884412766, 0.038304779678583145, -0.014253812842071056, -0.01577432081103325, -0.006915344391018152, -0.0005785343237221241, -0.020666614174842834, -0.010788372717797756, 0.06736930459737778, -0.03620447963476181, -0.04258531332015991, 0.021711789071559906, 0.033804722130298615, 0.01590215414762497, 0.007387245073914528, -0.039304353296756744, -0.015150227583944798, -0.03448053449392319, 0.05814472213387489, -0.01685372181236744, 0.06104354187846184, -0.021211793646216393, 0.00988799799233675, -0.04946436733007431, -0.026938727125525475, -0.006047292146831751, -0.034433331340551376, 0.001596075133420527, 0.016696976497769356, 0.026537524536252022, -0.06839779764413834, -0.006464830134063959, -0.002737378468737006 ]
8ac9b0e158167d7f3345bc07a8dd57de92905440
66
py
Python
scripts/get_file_name_as_variable.py
amin-henteti/airflow-dags
eb1e9a1a77d3c868e031cbe7420eae952ce5e767
[ "Apache-2.0" ]
null
null
null
scripts/get_file_name_as_variable.py
amin-henteti/airflow-dags
eb1e9a1a77d3c868e031cbe7420eae952ce5e767
[ "Apache-2.0" ]
null
null
null
scripts/get_file_name_as_variable.py
amin-henteti/airflow-dags
eb1e9a1a77d3c868e031cbe7420eae952ce5e767
[ "Apache-2.0" ]
null
null
null
import inspect def foo(): print(inspect.stack()[0][3]) foo()
13.2
31
0.621212
1
0.6486
[ 0.0035508042201399803, 0.03107723407447338, 0.006383564788848162, -0.001435348647646606, 0.006529367994517088, -0.007377009838819504, -0.013394403271377087, 0.006162951700389385, -0.006048596929758787, 0.0007125673000700772, 0.0017148409970104694, 0.0036936805117875338, 0.008194806054234505, -0.015071546658873558, -0.00037618688656948507, 0.022298036143183708, -0.06217341497540474, 0.004048405680805445, -0.0059362598694860935, 0.003730576252564788, -0.012137758545577526, 0.012943021021783352, 0.00808145571500063, 0.00844334252178669, 0.007676688954234123, 0.0052667297422885895, 0.009749394841492176, 0.005240213591605425, -0.010263903997838497, -0.0038609520997852087, 0.0035680760629475117, 0.0002673867857083678, -0.004322931170463562, -0.007139178924262524, 0.007963508367538452, -0.0027381782419979572, 0.0011050011962652206, -0.01772397942841053, 0.010111523792147636, -0.007876759395003319, -0.010718266479671001, -0.020642664283514023, 0.0016120679210871458, 0.005003238096833229, -0.012923086993396282, 0.0022755383979529142, -0.006359512452036142, 0.002332530915737152, -0.010811354964971542, 0.0026845696847885847, -0.01526549644768238, -0.00036627601366490126, 0.010979625396430492, 0.0023291888646781445, -0.0059567708522081375, -0.008499919436872005, 0.01179217267781496, -0.0004051234573125839, -0.013378492556512356, -0.0036167220678180456, -0.0042536272667348385, -0.003331433981657028, 0.0026708911173045635, 0.003293032292276621, -0.019192539155483246, -0.006230298429727554, -0.008609116077423096, 0.0029698675498366356, -0.00402602506801486, 0.0054688542149960995, 0.0020723147317767143, -0.00280778668820858, 0.008915625512599945, 0.0003998170723207295, 0.0021592876873910427, -0.0038227150216698647, -0.002749313833191991, 0.003954744897782803, 0.006273939274251461, -0.0011491611367091537, 0.006199278868734837, -0.01045372523367405, 0.005023754667490721, 0.015342066064476967, 0.01352649461477995, 0.006787000223994255, 0.017209503799676895, -0.011316731572151184, 0.037280697375535965, 0.005724798422306776, -0.008610217832028866, 0.001572843873873353, -0.007417059037834406, -0.004688302055001259, -0.0008251249091699719, -0.03319684788584709, 0.00043173006270080805, -0.008974048309028149, -0.0007279034471139312, 0.004444192163646221, 0.0020151108037680387, 0.00644451892003417, -0.0017274293350055814, -0.0023743733763694763, -0.01187314186245203, 0.01714668795466423, -0.014463375322520733, -0.0018414168152958155, 0.009479272179305553, 0.0033819531090557575, -0.012241063639521599, -0.0025801698211580515, 0.004426557570695877, -0.015903068706393242, 0.0038350012619048357, -0.0013221647823229432, -0.004347489681094885, 0.062365394085645676, 0.002967109903693199, 0.00008274913125205785, -0.006644691340625286, -0.003985547926276922, 0.001338303554803133, 0.009265568107366562, 0.01147302333265543, -0.007120850495994091, 0.009508266113698483, 0.004588947165757418, 0.0023966492153704166, 0.005371734034270048, 0.0005001378594897687, 0.00837001483887434, -0.006732278037816286, 0.003112268866971135, -0.0007248415495269, -0.00799560733139515, 0.00994066707789898, -0.002694246359169483, -0.0016907791141420603, 0.00008157077536452562, -0.0017737060552462935, -0.013594613410532475, 0.002313298638910055, -0.00429716007784009, -0.001028252299875021, -0.012432384304702282, -0.0020966592710465193, -0.0036626129876822233, -0.003882764372974634, 0.003132089041173458, 0.00796159915626049, 0.008279732428491116, 0.002275563543662429, -0.0069113741628825665, -0.00936168897897005, -0.002434543101117015, -0.006873558275401592, 0.004212595988065004, 0.008403233252465725, 0.0018554183188825846, -0.00467089656740427, -0.00524928979575634, 0.0029408701229840517, 0.005040470976382494, 0.00041134582716040313, -0.0011826285626739264, -0.00809403881430626, 0.008912935853004456, 0.0017869338626042008, 0.001083312090486288, 0.01452520303428173, -0.005922865588217974, -0.0023697405122220516, 0.001698085106909275, 0.003012883709743619, 0.0018609237158671021, 0.0042778742499649525, 0.006128212902694941, -0.007566843647509813, -0.0043469262309372425, 0.008694799616932869, 0.002510551130399108, 0.011083854362368584, 0.0073693483136594296, 0.0005458954256027937, 0.00263916770927608, -0.0032189537305384874, 0.0009031635709106922, 0.004904050379991531, -0.004978767596185207, 0.01287817396223545, 0.0058531127870082855, -0.021431811153888702, -0.004598014988005161, -0.0015691375592723489, -0.010518116876482964, -0.0012242819648236036, 0.017982548102736473, 0.009965324774384499, 0.0035481348168104887, 0.0014998035039752722, -0.015431366860866547, 0.000531681755091995, 0.008928787894546986, -0.0025226399302482605, -0.011658860370516777, -0.9481363892555237, 0.002521979622542858, 0.006104593630880117, 0.0008660630555823445, 0.005577648989856243, 0.001705251750536263, 0.0004470732528716326, 0.0015708239516243339, 0.012281088158488274, -0.012107388116419315, -0.009496776387095451, -0.010128441266715527, -0.011724808253347874, -0.001476219273172319, -0.006401407532393932, -0.0015005333116278052, -0.003986825235188007, -0.008652271702885628, 0.0017513022758066654, -0.0024421883281320333, 0.0004628269816748798, 0.012096221558749676, -0.0016499218763783574, 0.005285475868731737, 0.0038166213780641556, 0.004389401525259018, -0.006090101785957813, -0.0015917617129161954, 0.0023441892117261887, -0.0002724427613429725, -0.004132773727178574, -0.013340597972273827, -0.0069325887598097324, -0.0015914163086563349, 0.012877589091658592, 0.0004540802619885653, 0.010870504193007946, -0.001353650470264256, -0.00009386445890413597, -0.010957036167383194, 0.004025584552437067, 0.00761407520622015, 0.004312830977141857, -0.0322689563035965, 0.001951331039890647, -0.0032296557910740376, -0.004485458601266146, 0.01238471083343029, 0.005119225941598415, -0.005675743333995342, -0.0017323551001027226, -0.0043024164624512196, 0.009860490448772907, -0.008510828949511051, 0.005164502188563347, -0.003773176809772849, -0.00360540091060102, 0.00015175185399129987, -0.008564152754843235, 0.0023876773193478584, 0.004000040702521801, -0.00645510945469141, -0.0038211664650589228, -0.00706320209428668, 0.0013627794105559587, 0.000884475011844188, -0.0004943912499584258, -0.014813062734901905, -0.007334338501095772, -0.0050615486688911915, 0.004633625969290733, 0.0029163924045860767, -0.003576855408027768, 0.0002249459648737684, -0.010599931702017784, 0.007445505354553461, 0.001416639774106443, 0.0036731483414769173, -0.011513416655361652, 0.00002338187550776638, -0.00851478148251772, -0.009859258309006691, 0.006106561049818993, -0.005436902865767479, -0.004070412367582321, 0.002723393263295293, 0.009051036089658737, 0.005392387975007296, -0.008081885986030102, -0.0005674234125763178, 0.013596074655652046, -0.0038779466412961483, -0.00812101736664772, 0.005843207705765963, 0.0070519642904400826, 0.0009811078198254108, -0.0006342817796394229, 0.004609571769833565, 0.008360306732356548, 0.00983896479010582, -0.00020180964202154428, 0.003219975857064128, 0.0008594857063144445, 0.012549585662782192, 0.0012135091237723827, 0.0022476522717624903, -0.00031412896350957453, -0.001190735725685954, -0.00310493097640574, -0.0032907878048717976, -0.0034393935929983854, 0.0006792113999836147, -0.01038931030780077, -0.010950828902423382, -0.007709754165261984, 0.005540600512176752, -0.001463292632251978, -0.002087908796966076, 0.0005407604039646685, -0.0004863192734774202, 0.016415223479270935, 0.004332534968852997, -0.006314634345471859, 0.00313605391420424, 0.004247976001352072, -0.009916924871504307, 0.01831667311489582, -0.015023346059024334, 0.006806685123592615, -0.0014232739340513945, -0.017491118982434273, 0.006505308207124472, 0.007978884503245354, -0.009193606674671173, 0.0018743795808404684, 0.00048978062113747, 0.002487567253410816, 0.0008098994730971754, -0.007091121282428503, -0.0025497821625322104, -0.02263255976140499, -0.0009033331298269331, 0.02147712931036949, 0.005362833384424448, 0.011414038017392159, 0.013696858659386635, -0.003763968823477626, 0.0032959359232336283, 0.008453906513750553, -0.001148706185631454, 0.01771998405456543, -0.010878950357437134, -0.0005316989263519645, 0.0022854264825582504, -0.003342276904731989, 0.001502858242020011, 0.0005277881282381713, 0.004582114517688751, -0.0033662256319075823, -0.0003305365389678627, -0.00759843597188592, -0.005394492298364639, -0.016808243468403816, -0.0008156115654855967, 0.009776057675480843, -0.005203389562666416, 0.0006837971159256995, -0.01267982367426157, 0.005313096567988396, 0.004851818550378084, 0.002662359969690442, 0.0007374387350864708, 0.005107356235384941, 0.006232781335711479, 0.012733465060591698, -0.007052827160805464, 0.003910817671567202, 0.004058236721903086, -0.0009354189387522638, 0.006953530479222536, 0.010803419165313244, -0.01000620424747467, -0.004385087173432112, -0.0004052133590448648, 0.0004898831248283386, 0.0003723193658515811, -0.004343120381236076, -0.009837564080953598, -0.004408559761941433, 0.00569182587787509, -0.008602635934948921, 0.0009743371629156172, 0.00110024178866297, 0.003159515094012022, -0.011940546333789825, 0.0001927322446135804, -0.00424847099930048, -0.009868827648460865, 0.007472793571650982, -0.0034749226178973913, 0.0025248690508306026, 0.00991957075893879, 0.007983735762536526, -0.01434769295156002, 0.009586406871676445, 0.010088498704135418, -0.007031294051557779, 0.0012764559360221028, 0.00976876262575388, -0.004811260383576155, -0.025757160037755966, 0.0008130056667141616, -0.015095182694494724, 0.0067339567467570305, -0.003914626780897379, 0.003981625661253929, -0.006580948829650879, 0.01175372488796711, 0.0015804008580744267, -0.012309274636209011, -0.0014275360153988004, -0.009038449265062809, 0.008085688576102257, -0.0031036557629704475, -0.005602454766631126, -0.0037488683592528105, -0.0027893884107470512, -0.002888471819460392, 0.0022484310902655125, 0.0024063086602836847, 0.0036206638906151056, 0.002647542394697666, -0.005708059296011925, 0.004541480448096991, -0.0018212513532489538, 0.002242953982204199, 0.0042313821613788605, -0.009081008844077587, 0.0006022038869559765, 0.009111893363296986, -0.0005668339435942471, -0.0027464746963232756, 0.001331034698523581, -0.0038888317067176104, -0.007696725893765688, -0.011608999222517014, -0.0034213538747280836, -0.0012969603994861245, -0.0052788956090807915, -0.011925600469112396, -0.00407379399985075, -0.009914225898683071, 0.006647656671702862, -0.008589563891291618, 0.008515870198607445, 0.008626577444374561, -0.0046315304934978485, 0.006870167329907417, -0.004951140843331814, 0.0025789965875446796, 0.002159904455766082, 0.00769090186804533, -0.0003054570988751948, -0.008602304384112358, -0.00986992847174406, 0.014938907697796822, -0.01349714770913124, -0.001854795846156776, 0.014888543635606766, 0.005457866936922073, 0.009156624786555767, 0.002448304556310177, -0.001278283423744142, 0.005019485484808683, 0.010675973258912563, -0.010530787520110607, 0.0008557370747439563, -0.0024606664665043354, -0.003745561931282282, 0.005874220281839371, -0.005526082590222359, 0.0037133218720555305, 0.005663037300109863, 0.00012659718049690127, -0.009740606881678104, -0.0009759370004758239, -0.0035611074417829514, 0.0028116784524172544, -0.011828254908323288, -0.002109345281496644, -0.006237506866455078, -0.005589974112808704, -0.006690808571875095, -0.00014905045100022107, -0.001113386475481093, 0.004497640300542116, -0.003253092523664236, 0.006462127435952425, 0.001979733817279339, -0.0026843685191124678, 0.01623130403459072, -0.003311476670205593, -0.0062507204711437225, 0.006480655632913113, 0.0005724671646021307, 0.0005463717388920486, -0.008496485650539398, -0.004467612598091364, 0.003410490695387125, 0.004160523414611816, -0.0028716379310935736, -0.011013742536306381, -0.0009446453186683357, -0.00015927728964015841, -0.004873460624366999, 0.0015129237435758114, 0.010902635753154755, -0.0016768218483775854, 0.004773750435560942, 0.00044349240488372743, -0.00610925629734993, -0.016273949295282364, 0.06112828850746155, -0.0009648066479712725, 0.002957376651465893, 0.008162825368344784, -0.006652371026575565, 0.0009166054660454392, -0.006401473190635443, 0.004517187364399433, -0.006995314732193947, -0.004905391484498978, 0.014192288741469383, -0.0038604498840868473, -0.0012157444143667817, -0.0031540687195956707, -0.004196207970380783, 0.017616720870137215, -0.005461580585688353, -0.01619189977645874, -0.012203777208924294, 0.005877248011529446, -0.004689396824687719, -0.007683917414397001, 0.007343926001340151, -0.007781916297972202, -0.003584302728995681, 0.004497802350670099, 0.0040139928460121155, -0.0021262539085000753, 0.0012688622809946537, -0.0006804310833103955, -0.0025618383660912514, 0.0006457873387262225, 0.0020175594836473465, 0.0071619246155023575, 0.013642395846545696, -0.00016447275993414223, 0.005566509906202555, -0.00012103781045880169, 0.00023010052973404527, -0.002488725120201707, 0.007212093099951744, 0.006991636008024216, -0.0008476015063934028, -0.003738108091056347, 0.004270013887435198, 0.005883191712200642, 0.0005591862718574703, 0.015902351588010788, 0.0020534046925604343, -0.003531063674017787, 0.006495153997093439, 0.010569443926215172, -0.006369898095726967, 0.008929490111768246, -0.0016456457087770104, 0.004020351450890303, 0.0009942097822204232, -0.009005344472825527, -0.004260185174643993, -0.00004635771983885206, 0.003159752581268549, 0.007524896413087845, -0.0031419601291418076, 0.0013598777586594224, 0.004547587130218744, -0.004232852254062891, -0.010598127730190754, -0.004093770403414965, -0.0038582345005124807, -0.004409250803291798, 0.0004879291809629649, 0.07505754381418228, -0.008895286358892918, -0.00007917216862551868, -0.00784674845635891, 0.0020040629897266626, 0.0017773796571418643, 0.00016855369904078543, -0.0016317719127982855, -0.00004590570824802853, 0.0035814817529171705, 0.004650389309972525, -0.009732741862535477, -0.012758164666593075, 0.0011954117799177766, 0.0012197092873975635, -0.00032771367114037275, 0.002696545561775565, 0.012542911805212498, -0.004133692942559719, 0.006600838154554367, -0.014234154485166073, -0.002430664375424385, -0.0018300346564501524, -0.00817814189940691, -0.0007005840889178216, -0.0056154197081923485, 0.00021802469564136118, 0.005323590245097876, 0.003359323600307107, -0.007226893678307533, 0.0061056287959218025, 0.00003135736915282905, 0.0016720485873520374, -0.0027323728427290916, -0.0021942993625998497, -0.004837931599467993, 0.005635427311062813, 0.0026802527718245983, -0.014759717509150505, -0.007167736999690533, -0.004127829801291227, 0.0032130801118910313, -0.006343923043459654, 0.009075171314179897, -0.003747924230992794, 0.012104147113859653, -0.0029402433428913355, 0.0032630639616400003, -0.002994959242641926, -0.0002386239357292652, -0.013843417167663574, 0.0029782727360725403, -0.19433675706386566, 0.012669287621974945, 0.002089924644678831, -0.006279575638473034, -0.0025878921151161194, -0.01696767657995224, -0.015643682330846786, 0.0018565619830042124, 0.009203353896737099, -0.0024113378021866083, 0.00044745809282176197, -0.004131049383431673, 0.008838475681841373, 0.004786553792655468, -0.003509413916617632, -0.005498382728546858, 0.004272966645658016, -0.0021590590476989746, -0.004865206778049469, 0.002876374637708068, 0.008395976386964321, 0.006571603007614613, 0.005414692219346762, -0.0009285577107220888, 0.0030974028632044792, -0.0059646074660122395, 0.003598740790039301, -0.0026870346628129482, 0.00542575353756547, -0.007698897738009691, -0.004365391097962856, -0.007194822654128075, -0.0033151519019156694, 0.0016236088704317808, 0.0018007713370025158, -0.003044668585062027, 0.00825282372534275, 0.003035841276869178, -0.006524195428937674, 0.0077154384925961494, -0.006676820572465658, 0.04123036563396454, 0.0010970026487484574, 0.009634354151785374, 0.0024164903443306684, 0.0010814470006152987, -0.00478212907910347, 0.011635649017989635, 0.003499633399769664, 0.01329110562801361, -0.009768077172338963, -0.00736634386703372, -0.0007201037951745093, 0.018079861998558044, -0.005851773079484701, -0.011238016188144684, -0.010671570897102356, -0.008159857243299484, 0.0058338395319879055, 0.014714544638991356, 0.011235473677515984, -0.003969269804656506, 0.008030244149267673, -0.002469309838488698, -0.019865550100803375, 0.003622460877522826, 0.0007629141327925026, -0.010196683928370476, -0.00030962549499236047, 0.006560055073350668, 0.014034354127943516, -0.004057400394231081, 0.010511212050914764, 0.0007306329207494855, 0.0034301301930099726, -0.0028492428828030825, 0.005842285230755806, -0.008463103324174881, 0.006577562540769577, -0.009899557568132877, 0.014436274766921997, -0.010428058914840221, -0.0005640114541165531, 0.001841522753238678, -0.005269232671707869, 0.011453421786427498, 0.0055949389934539795, -0.0008196139242500067, 0.001566381542943418, -0.013938291929662228, -0.0037888584192842245, 0.0030570749659091234, 0.0051024239510297775, -0.008770974352955818, 0.0011154545936733484, -0.0027071326039731503, 0.006276087835431099, 0.006668525747954845, -0.007054687011986971, 0.005730074364691973, 0.007096606772392988, -0.010285557247698307, 0.005218172445893288, -0.008947188965976238, -0.000012065600458299741, 0.004905848763883114, -0.008491702377796173, -0.013233457691967487, 0.00474761426448822, -0.005289763677865267, -0.004518399015069008, 0.0010399597231298685, -0.011638490483164787, -0.003822589060291648, 0.00004451283166417852, -0.01350678876042366, 0.0025473448913544416 ]
8ac9d8732422cf52f01f2fd448863e8bbd5e7b4d
2,879
py
Python
sovrin/test/did/helper.py
sovrin-foundation/old-sovrin
d4e705054b7252c62fea00114060035c6eb314a4
[ "Apache-2.0" ]
3
2017-07-19T14:26:31.000Z
2020-05-16T16:09:37.000Z
sovrin/test/did/helper.py
sovrin-foundation/old-sovrin
d4e705054b7252c62fea00114060035c6eb314a4
[ "Apache-2.0" ]
null
null
null
sovrin/test/did/helper.py
sovrin-foundation/old-sovrin
d4e705054b7252c62fea00114060035c6eb314a4
[ "Apache-2.0" ]
3
2017-10-28T08:19:00.000Z
2021-06-06T10:48:55.000Z
import base58 from plenum.common.signer_did import DidSigner from plenum.common.verifier import DidVerifier from plenum.common.eventually import eventually from plenum.test.helper import assertEquality from sovrin.common.identity import Identity MsgForSigning = {'sender': 'Mario', 'msg': 'Lorem ipsum'} def signMsg(wallet, idr): return wallet.signMsg(MsgForSigning, identifier=idr) def verifyMsg(verifier, sig): sig = base58.b58decode(sig) return verifier.verifyMsg(sig, MsgForSigning) def chkVerifyForRetrievedIdentity(signerWallet, verifierWallet, idr): sig = signMsg(signerWallet, idr) verkey = verifierWallet.getIdentity(idr).verkey assert verifyMsg(DidVerifier(verkey, idr), sig) def updateWalletIdrWithFullKeySigner(wallet, idr): newSigner = DidSigner(identifier=idr) wallet.updateSigner(idr, newSigner) assertEquality(newSigner.verkey, wallet.getVerkey(idr)) checkFullVerkeySize(wallet.getVerkey(idr)) return newSigner.verkey def updateSovrinIdrWithFullKey(looper, senderWallet, senderClient, ownerWallet, idr, fullKey): idy = Identity(identifier=idr, verkey=fullKey) senderWallet.updateSponsoredIdentity(idy) # TODO: What if the request fails, there must be some rollback mechanism assert senderWallet.getSponsoredIdentity(idr).seqNo is None reqs = senderWallet.preparePending() senderClient.submitReqs(*reqs) def chk(): assert senderWallet.getSponsoredIdentity(idr).seqNo is not None looper.run(eventually(chk, retryWait=1, timeout=5)) return ownerWallet def fetchFullVerkeyFromSovrin(looper, senderWallet, senderClient, ownerWallet, idr): identity = Identity(identifier=idr) req = senderWallet.requestIdentity(identity, sender=senderWallet.defaultId) senderClient.submitReqs(req) def chk(): retrievedVerkey = senderWallet.getIdentity(idr).verkey assertEquality(retrievedVerkey, ownerWallet.getVerkey(idr)) checkFullVerkeySize(retrievedVerkey) looper.run(eventually(chk, retryWait=1, timeout=5)) def checkDidSize(did): # A base58 encoding of 32 bytes string can be either 44 bytes or 43 bytes, # since the did takes first 16 bytes, base58 of did is either # 21 or 22 characters assert len(did) == 21 or len(did) == 22 def checkAbbrVerkeySize(verkey): # A base58 encoding of 32 bytes string can be either 44 bytes or 43 bytes, # since the abbreviated verkey takes last 16 bytes, base58 of abbreviated # verkey is either 21 or 22 characters and since its prefixed by a `~` its # length will be either 23 or 22 assert len(verkey) == 23 or len(verkey) == 22 def checkFullVerkeySize(verkey): # A base58 encoding of 32 bytes string can be either 44 bytes or 43 bytes. assert len(verkey) == 44 or len(verkey) == 43
35.109756
79
0.733241
1
1.7496
[ 0.002684345468878746, 0.022279977798461914, 0.008975949138402939, 0.0016457128804177046, 0.005035290028899908, -0.0024402784183621407, -0.007834110409021378, 0.0021124035120010376, -0.0061916145496070385, 0.003878304036334157, 0.003459315747022629, 0.005641700699925423, 0.0060459040105342865, -0.017460400238633156, 0.001215976313687861, 0.01565234176814556, -0.0515776202082634, 0.0026534220669418573, -0.0036246490199118853, 0.00420961482450366, -0.007113594561815262, 0.00949119869619608, 0.008737064898014069, 0.00392875773832202, 0.005642325151711702, -0.0008624470210634172, 0.010446973145008087, 0.0013465075753629208, -0.007584111299365759, -0.008664996363222599, 0.00016168724687304348, -0.002296500140801072, -0.00677183922380209, -0.0067414878867566586, 0.005076857283711433, -0.0031454632990062237, 0.001729981624521315, -0.018100403249263763, 0.013090592809021473, -0.003112795762717724, -0.005744357593357563, -0.014882264658808708, 0.0007385396747849882, 0.0034757095854729414, -0.008807115256786346, 0.0010494263842701912, -0.0042952848598361015, 0.0037044761702418327, -0.011607885360717773, 0.006233080755919218, -0.00960350502282381, 0.007113675121217966, 0.01633552648127079, 0.003222367726266384, -0.005129915662109852, -0.006307243835180998, 0.012410166673362255, -0.0004852513666264713, -0.011595611460506916, -0.00025918814935721457, -0.004373038653284311, -0.0015460500726476312, 0.004414193797856569, 0.0017025513807311654, -0.01597965694963932, -0.007295963820070028, -0.003981913905590773, 0.003909486345946789, -0.0018243113299831748, 0.007690837606787682, 0.0008460879325866699, -0.0007084314711391926, 0.007579317782074213, 0.0044692945666611195, 0.004279927350580692, -0.004657413344830275, -0.0015042659360915422, -0.0017748340032994747, 0.008154315873980522, 0.003009365638718009, 0.005493261851370335, -0.006978729274123907, 0.004421889781951904, 0.00803020317107439, 0.013620591722428799, 0.009446133859455585, 0.021291090175509453, -0.01021750457584858, 0.04737286642193794, 0.011044289916753769, -0.009181421250104904, 0.0026215072721242905, -0.007298851851373911, -0.0024020541459321976, -0.005221698898822069, -0.02735012210905552, -0.0018288253340870142, -0.004468910861760378, -0.00023541126574855298, 0.003209494287148118, -0.0006830661441199481, 0.0077432370744645596, -0.0009147036471404135, -0.00262063043192029, -0.0070194886066019535, 0.008020179346203804, -0.008128144778311253, -0.004139972385019064, 0.0061724367551505566, 0.0017420315416529775, -0.012220393866300583, -0.0024970408994704485, 0.0041655260138213634, -0.010935751721262932, 0.0031502514611929655, 0.00392372440546751, -0.007129834499210119, 0.0522407628595829, -0.0019384423503652215, 0.0009507906506769359, -0.003949951380491257, 0.003141586435958743, 0.0022591445595026016, 0.005411317106336355, 0.009102839976549149, -0.0027807157021015882, 0.01342227216809988, 0.009993829764425755, 0.0030979241710156202, 0.010077250190079212, -0.0032159192487597466, 0.008982380852103233, -0.0031210812740027905, -0.004089453723281622, 0.0031544289086014032, -0.0076216235756874084, 0.006724036764353514, -0.002678674878552556, -0.011162493377923965, -0.00041318676085211337, -0.000014509078937408049, -0.007969550788402557, 0.002104733372107148, -0.004739629104733467, 0.005095786415040493, -0.00874265842139721, -0.0034874374978244305, -0.006721919868141413, -0.00362395029515028, 0.0032696567941457033, 0.009383931756019592, 0.00532752787694335, 0.003960080910474062, -0.005727263167500496, -0.009717794135212898, 0.0006666613626293838, -0.0026780273765325546, 0.0016224057180806994, 0.007552325259894133, 0.0039911530911922455, -0.009215359576046467, -0.0007583452388644218, 0.0016695793019607663, 0.004751920700073242, -0.0033774625044316053, 0.0003691819729283452, -0.009714583866298199, 0.006806953344494104, 0.00009809966286411509, 0.00555762741714716, 0.010181665420532227, -0.004358165431767702, 0.00047301602899096906, -0.0009222135995514691, 0.0035081123933196068, -0.0014968793839216232, 0.005476718302816153, 0.010324088856577873, -0.00228605093434453, -0.00422552740201354, 0.0027686513494700193, 0.005067429039627314, 0.009415224194526672, 0.00602722866460681, -0.0027633882127702236, 0.0017594938399270177, -0.00356566091068089, -0.0024108265060931444, 0.006133734714239836, -0.0044820415787398815, 0.00481622526422143, 0.004430774133652449, -0.011966037563979626, -0.007487504277378321, 0.0024142444599419832, -0.008624276146292686, 0.004152582958340645, 0.012573412619531155, 0.012343836948275566, -0.00425212737172842, 0.0037233829498291016, -0.007252801209688187, -0.000495466694701463, 0.006442288402467966, 0.0024066269397735596, -0.013546436093747616, -0.9604195952415466, 0.006398993078619242, 0.002986293751746416, -0.0015393784269690514, 0.005741783417761326, 0.0032425052486360073, 0.003122229827567935, 0.0038121079560369253, 0.01569918915629387, -0.00690211309120059, -0.00710724713280797, -0.010122803971171379, -0.010838237591087818, -0.0017048359150066972, -0.006701105274260044, -0.004065805114805698, -0.006604564841836691, -0.0060842642560601234, -0.003356577828526497, -0.0024883204605430365, -0.0030884258449077606, 0.007948246784508228, -0.0009481479064561427, 0.0047646635212004185, 0.0028237749356776476, 0.0033685413654893637, -0.0058897570706903934, -0.001179469283670187, -0.005093954037874937, -0.002868776675313711, -0.005722912028431892, -0.014631721191108227, -0.004935582634061575, -0.00017041929822880775, 0.010947172529995441, -0.0007344092009589076, 0.007915247231721878, -0.0024238594342023134, 0.001128955278545618, -0.007276291958987713, 0.006885535549372435, -0.0022045429795980453, 0.0035572259221225977, -0.029779942706227303, -0.001287761377170682, -0.0010702136205509305, -0.00874753575772047, 0.007549438159912825, -0.0015589531976729631, 0.00016950414283201098, -0.003170040436089039, -0.005279636941850185, 0.008045390248298645, -0.008090242743492126, 0.002680399687960744, -0.005290858913213015, -0.0084858238697052, -0.003350027371197939, -0.007902240380644798, 0.0004938708152621984, 0.003518611891195178, -0.003322511911392212, -0.005190773401409388, -0.0025600071530789137, 0.003026284510269761, 0.003324787365272641, 0.0006354581564664841, -0.01729067973792553, -0.007997305132448673, 0.0015974888810887933, -0.00006901634333189577, -0.004028961528092623, -0.0030351467430591583, 0.0038059712387621403, -0.008479488082230091, 0.006762360688298941, 0.002319714752957225, -0.0015148381935432553, -0.010308485478162766, -0.0011194110848009586, -0.009207486175000668, -0.007714392617344856, 0.0008336838218383491, -0.006663553416728973, -0.005182832013815641, -0.00121465721167624, -0.001473102020099759, 0.008194595575332642, -0.005949706304818392, 0.005739761050790548, 0.011939306743443012, -0.0021222701761871576, -0.009202482178807259, 0.006489017512649298, 0.007245227228850126, 0.000569494382943958, -0.002260748762637377, 0.0027281891088932753, 0.006045167800039053, 0.006753564812242985, 0.0024761164095252752, 0.004423747304826975, -0.00022124452516436577, 0.010029728524386883, -0.0013217872474342585, 0.0005124203744344413, -0.003856311785057187, -0.00011552339128684253, -0.005058701150119305, -0.001959363231435418, -0.002680019708350301, -0.0017701316392049193, -0.011994599364697933, -0.008646087720990181, -0.0004891981952823699, -0.0016755616525188088, 0.005015683360397816, -0.0036477590911090374, 0.0003297039365861565, 0.0014815360773354769, 0.007145802024751902, 0.0010858448222279549, -0.0016283607110381126, 0.0001059010173776187, 0.0015737245557829738, -0.005035935435444117, 0.013502184301614761, -0.012394312769174576, 0.005806381348520517, -0.0002637102152220905, -0.01335216499865055, 0.008526495657861233, 0.011260355822741985, -0.007270862814038992, -0.0001498383207945153, 0.0039523146115243435, 0.004333465825766325, -0.0011131163919344544, -0.005354217253625393, -0.0025984833482652903, -0.016355102881789207, 0.0008621542365290225, 0.018989576026797295, 0.00043017108691856265, 0.010602203197777271, 0.01045917347073555, -0.003141008550301194, 0.0006281033274717629, 0.006210876163095236, 0.002318979473784566, 0.010894399136304855, -0.009122534655034542, -0.0008872961043380201, 0.0019946584943681955, -0.006562943570315838, -0.0003831994254142046, 0.006461351178586483, 0.005843772552907467, -0.002737885108217597, 0.004502327647060156, -0.010106806643307209, -0.005571882240474224, -0.018038973212242126, -0.004592102020978928, 0.00679799122735858, -0.004079587757587433, 0.008211804553866386, -0.01313826534897089, 0.003909099847078323, 0.006010227836668491, 0.003104153787717223, -0.0007733605452813208, -0.0005101291462779045, 0.004499434027820826, 0.012836041860282421, -0.006340057123452425, 0.0039046183228492737, 0.002626013243570924, -0.0013941687066107988, -0.00020441673405002803, 0.009444909170269966, -0.0068415869027376175, -0.005600337404757738, 0.004412838723510504, 0.004882426001131535, -0.00020981859415769577, -0.0036799332592636347, -0.008425983600318432, -0.0030129747465252876, 0.002353788586333394, -0.004821860231459141, 0.002431304659694433, 0.0028260184917598963, 0.00425079558044672, -0.008385959081351757, -0.0004615859652403742, -0.0025421653408557177, -0.012279636226594448, 0.010583702474832535, -0.003771665971726179, 0.003141420893371105, 0.014165167696774006, 0.0033506399486213923, -0.0136724216863513, 0.004144948907196522, 0.010439025238156319, -0.0024386285804212093, 0.004800640512257814, 0.006085831671953201, -0.00641356548294425, -0.02205917052924633, -0.0024368599988520145, -0.015353843569755554, 0.005418430548161268, -0.0033460974227637053, 0.003439567517489195, -0.006356345023959875, 0.0066241733729839325, 0.00491941487416625, -0.013226870447397232, -0.0045244027860462666, -0.007506172172725201, 0.008717337623238564, 0.0011257997248321772, 0.0006773301865905523, -0.0032558683305978775, 0.0002955773379653692, -0.0024048390332609415, -0.004673955496400595, -0.002168837236240506, 0.0034648424480110407, 0.0017969092587009072, -0.001802919083274901, 0.0015473044477403164, -0.00504671735689044, 0.0020791427232325077, 0.00021609455870930105, -0.011962542310357094, 0.0010254682274535298, 0.004699906334280968, -0.00048589269863441586, -0.0038140909746289253, 0.0007739025168120861, -0.0027300191577523947, -0.005971770267933607, -0.011283300817012787, -0.003968521486967802, -0.003067595651373267, -0.003023797646164894, -0.013170948252081871, -0.0016746172914281487, -0.008249178528785706, 0.004881878849118948, -0.006358498707413673, 0.00713728554546833, 0.0043248627334833145, -0.0058652255684137344, 0.006372773088514805, -0.0022532592993229628, 0.0050312490202486515, 0.002056417753919959, 0.00456224475055933, 0.0002486709563527256, -0.006304371636360884, -0.013740848749876022, 0.011659328825771809, -0.0071487268432974815, 0.0006840667920187116, 0.014396254904568195, 0.005332731641829014, 0.009478011168539524, -0.0019090194255113602, 0.0005892900517210364, 0.0005764022353105247, 0.006087538320571184, -0.014920447953045368, 0.0024345042183995247, -0.002854079706594348, 0.0005079963011667132, 0.004079021047800779, -0.0037192958407104015, 0.0021876750979572535, 0.009096675552427769, 0.0005350409774109721, -0.008659117855131626, -0.004666476510465145, 0.0007775277481414378, 0.002879706909880042, -0.013254796154797077, 0.001717917388305068, -0.004896546248346567, -0.00261132325977087, -0.002440025797113776, -0.0018090051598846912, -0.0003849279892165214, 0.004485357087105513, -0.0020241255406290293, 0.006130889058113098, 0.0026150913909077644, -0.006841010879725218, 0.014309494756162167, -0.007354195695370436, -0.00433255173265934, 0.0032964192796498537, 0.0030300412327051163, -0.0010295078391209245, -0.006036030128598213, -0.001669183955527842, 0.0028476372826844454, 0.006097978912293911, -0.0024184160865843296, -0.005151128396391869, -0.002373403636738658, 0.0012039983412250876, -0.011123727075755596, 0.0016397654544562101, 0.010556602850556374, -0.003378851106390357, 0.005977489985525608, -0.0027650478295981884, -0.008928663097321987, -0.012625264003872871, 0.053657036274671555, -0.0015437697293236852, 0.003599651623517275, 0.004264294169843197, -0.0070798359811306, -0.0009413249790668488, -0.004321491811424494, 0.007250659633427858, -0.006206665188074112, -0.00829232856631279, 0.006932554300874472, -0.0021231037098914385, 0.004010023083537817, 0.0048259287141263485, -0.001457326696254313, 0.017026185989379883, -0.0014888204168528318, -0.014741490595042706, -0.017397768795490265, 0.005807023495435715, -0.00592940766364336, -0.008418978191912174, 0.009700830094516277, -0.004010187927633524, -0.006280941888689995, 0.001352692604996264, 0.006650012917816639, 0.0016291122883558273, -0.0008167276391759515, -0.002260227920487523, -0.002426473656669259, -0.0012438577832654119, 0.0017979482654482126, 0.004697974771261215, 0.006615161895751953, -0.005063808988779783, 0.0018470726208761334, -0.00198033032938838, -0.0019065671367570758, -0.00019812102254945785, 0.005014104302972555, 0.007733342237770557, -0.0009187372052110732, -0.0021412414498627186, 0.006760147400200367, 0.0029032444581389427, 0.0020679973531514406, 0.011276169680058956, 0.00013662684068549424, -0.007242707069963217, 0.007618532981723547, 0.008026942610740662, 0.002179438713937998, 0.007638538721948862, 0.0007071244181133807, 0.005332971923053265, 0.0020977018866688013, -0.006729261018335819, -0.0176138486713171, -0.0031357938423752785, 0.006834268104285002, 0.009677180089056492, -0.0015199353219941258, 0.0014663789188489318, -0.0036926136817783117, -0.002172646578401327, -0.006093872245401144, -0.005926026962697506, -0.0003184572560712695, 0.0022341886069625616, 0.004885680507868528, 0.0678221806883812, -0.00904054380953312, -0.0007409355603158474, -0.008278794586658478, -0.0018327297875657678, -0.0016023506177589297, -0.0011665598722174764, 0.0025754075031727552, -0.0018082634778693318, 0.002486179582774639, -0.001257211435586214, -0.006402716040611267, -0.011602619662880898, -0.0005316552706062794, 0.003932397812604904, -0.004059233237057924, 0.0046003032475709915, 0.005174692254513502, -0.010796723887324333, 0.0008595424005761743, -0.012799576856195927, -0.0010137975914403796, -0.0022643906995654106, -0.008562866598367691, -0.005335306748747826, -0.00353194959461689, 0.006597104016691446, 0.0026939089875668287, 0.007036169059574604, -0.002998574171215296, 0.0068217976950109005, -0.003563840640708804, 0.00005059473551227711, -0.008056176826357841, -0.0010668825125321746, -0.0037945392541587353, 0.007841181010007858, 0.0019882393535226583, -0.01006912812590599, -0.004823447670787573, 0.00039387287688441575, 0.0005390677251853049, -0.0030944100581109524, 0.003750778967514634, 0.002329512033611536, 0.0039437077939510345, -0.0038506831042468548, -0.0006296979845501482, -0.006460520438849926, 0.0037194956094026566, -0.011046592146158218, 0.0056001003831624985, -0.16574229300022125, 0.009857945144176483, 0.005447785835713148, -0.005156390834599733, -0.004624019842594862, -0.017007768154144287, -0.00322625576518476, 0.00472650770097971, 0.010098056867718697, 0.0028010348323732615, -0.0020221900194883347, -0.00022805106709711254, 0.004493785556405783, 0.0023363069631159306, -0.0028493162244558334, -0.004089341498911381, 0.002107880776748061, -0.0035761422477662563, 0.0020081026013940573, 0.005033622030168772, 0.004809223115444183, 0.007076624780893326, 0.0009943543700501323, 0.0029950477182865143, -0.0030672296416014433, -0.0058218748308718204, 0.007127880118787289, -0.0019544847309589386, 0.006170736160129309, -0.010269536636769772, -0.0030706319957971573, -0.0011636691633611917, -0.00454472191631794, 0.00032413488952443004, 0.005101727321743965, -0.0007743613095954061, 0.010544891469180584, 0.0023907211143523455, -0.0069667440839111805, 0.00685128103941679, -0.00667315348982811, 0.028118714690208435, 0.005693030543625355, 0.004913065582513809, -0.000820926099549979, -0.006157629191875458, -0.005676347762346268, 0.008825238794088364, 0.0022403926122933626, 0.010827085934579372, -0.01064970251172781, 0.0025148906279355288, 0.005175212398171425, 0.017531266435980797, -0.005176793783903122, -0.011031030677258968, -0.006579892244189978, -0.0014182290760800242, 0.0029315375722944736, 0.007330525200814009, 0.011275635100901127, -0.0041275592520833015, 0.009069710038602352, -0.002829825971275568, -0.01996224746108055, 0.004062059335410595, -0.005068170838057995, -0.008344038389623165, 0.004112451337277889, 0.006461725570261478, 0.009474387392401695, -0.0007087879348546267, 0.0032727685756981373, -0.0026975590735673904, 0.0054761068895459175, 0.00048738493933342397, 0.008044934831559658, -0.0019506716635078192, 0.007258951663970947, -0.010479358956217766, 0.0057795969769358635, -0.010099254548549652, -0.003142426023259759, 0.0037083521019667387, -0.0035984418354928493, 0.01049348246306181, 0.00392307760193944, -0.001991896890103817, -0.0008356539183296263, -0.010640226304531097, -0.0031211390160024166, 0.002519492991268635, 0.002775507979094982, -0.010034370236098766, 0.003199170809239149, 0.0005030197207815945, 0.005764489993453026, 0.007130063604563475, -0.01165370736271143, 0.005350007675588131, 0.00571878207847476, -0.005061642732471228, 0.001125746755860746, -0.00415814109146595, 0.001162465661764145, 0.004001021850854158, -0.004760900046676397, -0.006021655630320311, 0.004826516844332218, -0.006214808207005262, -0.0032829702831804752, 0.007246711291372776, -0.009215488098561764, -0.00938357599079609, -0.0021639224141836166, -0.010887528769671917, 0.0007443143404088914 ]
8aca0af3be9ee2ea88050772027c439546656c4a
3,651
py
Python
tests/test_EdiblesSpectrum.py
jancami/edibles
51263b24c5e8aef786692011289b906a810ad2f7
[ "MIT" ]
8
2020-04-15T10:44:48.000Z
2021-06-21T15:58:19.000Z
tests/test_EdiblesSpectrum.py
jancami/edibles
51263b24c5e8aef786692011289b906a810ad2f7
[ "MIT" ]
100
2020-05-08T13:20:41.000Z
2022-01-11T20:04:52.000Z
tests/test_EdiblesSpectrum.py
jancami/edibles
51263b24c5e8aef786692011289b906a810ad2f7
[ "MIT" ]
8
2020-05-27T00:39:39.000Z
2021-06-23T14:07:16.000Z
import astropy import datetime import numpy as np from edibles.utils.edibles_spectrum import EdiblesSpectrum def testEdiblesSpectrum(filename="tests/HD170740_w860_redl_20140915_O12.fits"): # Spectrum information sp = EdiblesSpectrum(filename=filename, fully_featured=True, noDATADIR=True) assert isinstance(sp.header, astropy.io.fits.header.Header) assert isinstance(sp.target, str) assert isinstance(sp.date, str) assert isinstance(sp.datetime, datetime.datetime) assert isinstance(sp.v_bary, float) assert isinstance(sp.wave_units, str) assert isinstance(sp.flux_units, str) # Raw assert isinstance(sp.raw_wave, np.ndarray) assert isinstance(sp.raw_bary_wave, np.ndarray) assert isinstance(sp.raw_flux, np.ndarray) assert len(sp.raw_wave) == len(sp.raw_bary_wave) assert len(sp.raw_wave) == len(sp.raw_flux) assert isinstance(sp.raw_grid, np.ndarray) assert len(sp.raw_grid) == 200443 # print(len(sp.raw_grid)) assert isinstance(sp.raw_sky_wave, np.ndarray) assert isinstance(sp.raw_sky_flux, np.ndarray) assert len(sp.raw_sky_wave) == len(sp.raw_sky_flux) assert isinstance(sp.wave, np.ndarray) assert isinstance(sp.bary_wave, np.ndarray) assert isinstance(sp.flux, np.ndarray) # getSpectrum xmin = 7660 xmax = 7680 sp.getSpectrum(xmin=xmin, xmax=xmax) assert xmin == sp.xmin assert xmax == sp.xmax assert isinstance(sp.wave, np.ndarray) assert isinstance(sp.flux, np.ndarray) assert len(sp.wave) == len(sp.flux) assert np.min(sp.wave) > sp.xmin assert np.max(sp.wave) < sp.xmax assert isinstance(sp.bary_wave, np.ndarray) assert isinstance(sp.bary_flux, np.ndarray) assert len(sp.bary_wave) == len(sp.bary_flux) assert np.min(sp.bary_wave) > sp.xmin assert np.max(sp.bary_wave) < sp.xmax assert isinstance(sp.grid, np.ndarray) assert isinstance(sp.interp_flux, np.ndarray) assert isinstance(sp.interp_bary_flux, np.ndarray) assert len(sp.grid) == len(sp.interp_flux) assert len(sp.grid) == len(sp.interp_bary_flux) assert np.min(sp.grid) > sp.xmin assert np.max(sp.grid) < sp.xmax assert isinstance(sp.sky_wave, np.ndarray) assert isinstance(sp.sky_flux, np.ndarray) assert len(sp.sky_wave) == len(sp.sky_flux) assert np.min(sp.sky_wave) > sp.xmin assert np.max(sp.sky_wave) < sp.xmax # shift zoom_xmin = 7661 zoom_xmax = 7679 shift = 0.05 sp.shift(shift=shift, zoom_xmin=zoom_xmin, zoom_xmax=zoom_xmax) assert isinstance(sp.wave, np.ndarray) assert isinstance(sp.flux, np.ndarray) assert len(sp.wave) == len(sp.flux) assert np.min(sp.wave) > sp.xmin assert np.max(sp.wave) < sp.xmax assert isinstance(sp.bary_wave, np.ndarray) assert isinstance(sp.bary_flux, np.ndarray) assert len(sp.bary_wave) == len(sp.bary_flux) assert np.min(sp.bary_wave) > sp.xmin assert np.max(sp.bary_wave) < sp.xmax assert isinstance(sp.grid, np.ndarray) assert isinstance(sp.interp_flux, np.ndarray) assert isinstance(sp.interp_bary_flux, np.ndarray) assert len(sp.grid) == len(sp.interp_flux) assert len(sp.grid) == len(sp.interp_bary_flux) assert np.min(sp.grid) > sp.xmin assert np.max(sp.grid) < sp.xmax assert isinstance(sp.sky_wave, np.ndarray) assert isinstance(sp.sky_flux, np.ndarray) assert len(sp.sky_wave) == len(sp.sky_flux) assert np.min(sp.sky_wave) > sp.xmin assert np.max(sp.sky_wave) < sp.xmax if __name__ == "__main__": filename = "HD170740_w860_redl_20140915_O12.fits" testEdiblesSpectrum(filename=filename)
34.443396
80
0.707751
1
2.0976
[ 0.025407062843441963, 0.03349894657731056, 0.028176337480545044, -0.037453874945640564, 0.02107747085392475, 0.008669424802064896, 0.0015945695340633392, -0.002824558410793543, -0.019463807344436646, 0.04335807263851166, 0.02294405922293663, 0.05467713251709938, 0.040617432445287704, 0.026518888771533966, 0.02822699211537838, 0.010146265849471092, 0.13152772188186646, -0.04273262247443199, 0.0020276233553886414, 0.025836588814854622, -0.03981461003422737, -0.014959966763854027, 0.00836655031889677, -0.010674833320081234, -0.014345692470669746, -0.002655954100191593, 0.02853231132030487, -0.004630785435438156, -0.04636439308524132, -0.024923164397478104, -0.0008494674693793058, -0.005623350385576487, 0.021273242309689522, 0.022858772426843643, -0.007380282040685415, 0.006561504676938057, 0.0032400416675955057, -0.03172086179256439, 0.0025605177506804466, 0.02159225195646286, -0.006345669738948345, -0.021465802565217018, 0.02412351779639721, -0.06446635723114014, -0.003474168013781309, -0.05464545264840126, 0.014658581465482712, -0.026777107268571854, 0.049627166241407394, -0.006157269235700369, -0.0121319480240345, 0.054052166640758514, 0.03624217212200165, -0.007695045787841082, 0.009102877229452133, -0.05188637971878052, 0.008202765136957169, -0.023612238466739655, -0.019460055977106094, 0.05306580290198326, -0.003978775814175606, 0.03732648864388466, 0.013752169907093048, -0.027984799817204475, -0.019474223256111145, 0.0012209817068651319, -0.009705930016934872, -0.028201743960380554, 0.05935119837522507, 0.021336790174245834, -0.014725030399858952, -0.02501571923494339, 0.02331104315817356, 0.059662267565727234, -0.0025891342666000128, -0.009241601452231407, -0.04337321221828461, -0.025377502664923668, -0.0015108996303752065, 0.02881312556564808, -0.03640301525592804, 0.010767053812742233, 0.03391781821846962, 0.0037066990043967962, 0.029665278270840645, 0.059008531272411346, 0.09770989418029785, -0.013811876066029072, 0.027409816160798073, -0.03179916366934776, -0.015104774385690689, 0.0011175430845469236, 0.03513696789741516, 0.014669287018477917, -0.05131416767835617, -0.03198811039328575, 0.011133051477372646, 0.03685569390654564, -0.04777577146887779, 0.04199693724513054, 0.031050605699419975, -0.012935574166476727, 0.018030615523457527, -0.009065179154276848, -0.0042845685966312885, 0.007558155804872513, -0.0008604108588770032, 0.04192947968840599, 0.015387112274765968, -0.011879205703735352, 0.015162721276283264, -0.01135305780917406, -0.002089435001835227, -0.045726876705884933, 0.011642351746559143, -0.04445770010352135, 0.011080889962613583, 0.027615251019597054, -0.011775738559663296, 0.06578545272350311, -0.016854513436555862, -0.008191711269319057, -0.0238137636333704, -0.015382102690637112, -0.0044264341704547405, 0.06961169838905334, -0.010962309315800667, -0.008633856661617756, 0.059643734246492386, 0.011055957525968552, -0.02871619164943695, 0.02832423709332943, 0.007344565819948912, -0.010731875896453857, 0.026817135512828827, -0.012013775296509266, -0.03343763202428818, -0.022823574021458626, -0.06527001410722733, 0.0007894991431385279, -0.0005593578098341823, -0.022189494222402573, 0.0055305203422904015, -0.029385577887296677, 0.021029619500041008, -0.04743121564388275, 0.007529366295784712, 0.017264148220419884, -0.023474499583244324, -0.01541088055819273, -0.0013927738182246685, 0.028268510475754738, -0.02006162889301777, 0.00616177124902606, 0.00808838289231062, 0.004803693853318691, 0.005000451114028692, -0.04536427929997444, -0.02673618495464325, -0.013252345845103264, -0.02878998965024948, -0.015202281065285206, 0.028223708271980286, 0.011781634762883186, 0.024844534695148468, 0.019287658855319023, 0.003505654400214553, 0.030881300568580627, -0.010954728350043297, -0.012029008939862251, 0.01918519102036953, -0.02711588144302368, -0.0048086815513670444, -0.04320875182747841, -0.04676565155386925, 0.013119728304445744, 0.02681146003305912, -0.013821235857903957, 0.024802207946777344, -0.04093019291758537, 0.006539459340274334, 0.0070304241962730885, 0.003998085390776396, 0.03450557962059975, 0.002989707514643669, -0.01791158691048622, -0.03690197691321373, -0.0027212195564061403, -0.00393349165096879, -0.01342396903783083, -0.003935044165700674, 0.026595165953040123, 0.03780273348093033, -0.01230765413492918, 0.03638345003128052, -0.02397717721760273, 0.015336464159190655, 0.0002640651073306799, -0.03318797051906586, -0.02944893203675747, 0.010107707232236862, -0.001795612508431077, -0.02295878529548645, 0.009661657735705376, -0.030141815543174744, -0.01883607730269432, -0.5923853516578674, 0.002485840115696192, 0.018382782116532326, -0.0019491942366585135, -0.016632169485092163, 0.06459347158670425, -0.030658241361379623, 0.028598353266716003, -0.01657610572874546, 0.030743366107344627, -0.015898391604423523, -0.0027890317142009735, -0.023848623037338257, 0.009938194416463375, 0.028022626414895058, -0.031030338257551193, 0.028896033763885498, 0.010463083162903786, -0.03803931921720505, 0.029784951359033585, 0.030787430703639984, -0.010766878724098206, 0.0002565729955676943, -0.006019130814820528, -0.03977232053875923, -0.014451284892857075, 0.03483425825834274, -0.009739558212459087, 0.004577480256557465, 0.003565044142305851, -0.02171548455953598, -0.02471073716878891, 0.03723518177866936, -0.03342897444963455, -0.025809396058321, 0.015580733306705952, 0.044027701020240784, -0.023120222613215446, 0.007738033775240183, -0.008827629499137402, -0.007090197876095772, -0.01245443057268858, 0.010039961896836758, -0.04893270507454872, -0.04556649550795555, -0.012584829702973366, -0.032735392451286316, -0.01198572851717472, 0.007143575232475996, 0.018521521240472794, -0.01768762804567814, 0.05509301647543907, 0.04573265090584755, -0.0013125776313245296, -0.020002173259854317, -0.06485020369291306, 0.02154816873371601, -0.009189981035888195, -0.04656490683555603, 0.0032519232481718063, 0.008635802194476128, 0.023931430652737617, -0.007453016005456448, -0.01170361042022705, -0.023485762998461723, -0.02594059519469738, 0.03429729491472244, -0.03420507162809372, -0.037828847765922546, -0.01878618448972702, -0.031040608882904053, 0.004738105461001396, -0.08790430426597595, 0.061663493514060974, -0.015469217672944069, 0.001843976671807468, 0.016768071800470352, 0.008541174232959747, -0.022836608812212944, -0.005275893956422806, 0.00017589064373169094, 0.02236919477581978, 0.036391519010066986, -0.038669753819704056, -0.023596743121743202, -0.007462089881300926, 0.01971461996436119, -0.0027497143018990755, -0.0024217909667640924, 0.0508064329624176, 0.04693586006760597, 0.06264990568161011, 0.010881634429097176, 0.021101266145706177, 0.012425034306943417, -0.011759767308831215, -0.015661735087633133, 0.022243745625019073, 0.05822871997952461, 0.018110958859324455, -0.003914998844265938, -0.023515988141298294, 0.010961140505969524, -0.01969209499657154, -0.0018755868077278137, 0.005104322452098131, -0.029393136501312256, -0.03786185383796692, 0.01595642790198326, -0.0836927518248558, -0.04291628673672676, -0.03094962239265442, -0.020408304408192635, 0.00010938036575680599, 0.02741159126162529, -0.06553184986114502, 0.029925217851996422, -0.03636877238750458, 0.02166532166302204, -0.01558690145611763, 0.003859266871586442, -0.021802958101034164, -0.015036467462778091, 0.008592684753239155, 0.013152909465134144, 0.011617093347012997, -0.05269422382116318, 0.002906255656853318, 0.018178245052695274, 0.05739442631602287, -0.007611515000462532, -0.020367667078971863, 0.0001765314518706873, 0.017950931563973427, -0.024345368146896362, 0.01976281963288784, 0.005553615279495716, -0.018768472597002983, 0.025559404864907265, -0.023231111466884613, -0.02237377129495144, 0.02180546522140503, 0.02571100927889347, -0.041808877140283585, -0.007038488518446684, -0.010710911825299263, 0.002097139600664377, 0.012174095027148724, 0.05023207515478134, -0.02873244695365429, -0.01661068946123123, 0.043893661350011826, -0.0015849178889766335, 0.04378475248813629, 0.0027397593948990107, 0.012179546058177948, -0.03228588029742241, -0.011145109310746193, 0.029224948957562447, 0.017398593947291374, -0.02488946169614792, -0.046327415853738785, -0.04839393123984337, 0.013267632573843002, 0.0315532311797142, -0.004243659321218729, 0.012345525436103344, 0.09206423163414001, 0.04303104802966118, 0.023294294252991676, 0.03531808406114578, -0.047812532633543015, 0.02507936954498291, 0.023400479927659035, -0.0033763027749955654, -0.0035085377749055624, -0.00532985245808959, -0.02833053655922413, -0.05145672336220741, -0.005708662793040276, 0.03237156942486763, 0.017542457208037376, 0.009506504982709885, -0.011533110402524471, 0.0201866514980793, 0.03134974464774132, 0.011835133656859398, -0.01802043616771698, -0.0049228970892727375, 0.011459176428616047, 0.025580501183867455, 0.010003759525716305, -0.004842511378228664, 0.010655096732079983, -0.06790243834257126, -0.003512328490614891, -0.0002660302852746099, -0.003020553383976221, 0.03174390643835068, -0.038992900401353836, -0.029801491647958755, 0.01070933323353529, 0.027690256014466286, -0.017737604677677155, -0.009089640341699123, 0.07110818475484848, -0.02353883907198906, -0.009807577356696129, 0.0302064660936594, -0.014333566650748253, 0.0628122091293335, -0.02426047809422016, 0.07192330807447433, 0.004007674288004637, -0.015910228714346886, 0.004672089125961065, 0.0030136744026094675, -0.020847901701927185, 0.00105805485509336, -0.023230519145727158, 0.02526179701089859, -0.05269283428788185, 0.03150521218776703, -0.0025198233779519796, -0.027264393866062164, -0.009107985533773899, -0.0165872760117054, 0.013194000348448753, -0.0051280297338962555, 0.014356249943375587, 0.0067812479101121426, -0.016199199482798576, -0.000976973562501371, -0.019780239090323448, 0.004757627844810486, 0.03969115763902664, -0.027371957898139954, -0.013108867220580578, -0.02838786132633686, -0.011254756711423397, 0.051452744752168655, -0.031373970210552216, 0.00825075339525938, 0.02583938091993332, -0.019004523754119873, 0.014474447816610336, 0.0039603933691978455, -0.0453486442565918, -0.025400400161743164, -0.022956324741244316, 0.02533467672765255, 0.009924556128680706, -0.006379663944244385, -0.011381012387573719, 0.030163483694195747, 0.04507333040237427, -0.023432577028870583, 0.031287796795368195, -0.0040186685509979725, -0.008295954205095768, 0.04871070384979248, -0.023180639371275902, -0.036959219723939896, 0.010725338011980057, -0.006458213087171316, -0.0076389615423977375, 0.016176993027329445, -0.03869425132870674, -0.002930331276729703, -0.004957764875143766, 0.023546304553747177, -0.009978987276554108, -0.046484701335430145, 0.01996740512549877, 0.01590164378285408, -0.041749827563762665, -0.00542984576895833, -0.04109368845820427, 0.00855271052569151, -0.013865427114069462, -0.04959791153669357, -0.007543075364083052, 0.01761477068066597, 0.03629615157842636, -0.006715827621519566, 0.0166048314422369, -0.03890032321214676, 0.0240725539624691, -0.04542810469865799, 0.0027351730968803167, 0.018094267696142197, -0.05535634234547615, 0.016179684549570084, 0.0098832156509161, 0.003910147584974766, -0.013764997012913227, -0.07219771295785904, -0.0014432150637730956, 0.01903747394680977, 0.026448020711541176, 0.07363567501306534, -0.0063547310419380665, 0.03396301344037056, -0.01919129490852356, -0.03655390441417694, -0.006624242290854454, 0.020730776712298393, -0.05866118147969246, 0.026569126173853874, 0.03971538692712784, 0.005254455842077732, 0.005341288633644581, -0.031739313155412674, 0.003951610531657934, -0.008630581200122833, 0.012352426536381245, 0.017351100221276283, 0.005071879830211401, 0.025458799675107002, -0.013587748631834984, 0.0012820691335946321, 0.040532130748033524, -0.005643259733915329, 0.0051125166937708855, -0.0077784014865756035, -0.03761930391192436, -0.03724481910467148, 0.016535351052880287, 0.01995500735938549, 0.0012045580660924315, -0.004110317677259445, -0.02528432384133339, -0.022922702133655548, -0.02729005366563797, 0.012916859239339828, 0.021503759548068047, 0.03148813545703888, 0.042760029435157776, 0.09130889922380447, 0.046853892505168915, -0.014553951099514961, 0.00771615793928504, -0.04600737616419792, -0.042122453451156616, 0.005778132006525993, -0.001253015361726284, -0.1057424396276474, 0.043256551027297974, 0.05220675468444824, 0.05050986260175705, 0.010445811785757542, -0.031419601291418076, 0.014391963370144367, 0.025475628674030304, 0.007063224911689758, 0.005573051981627941, 0.0174454003572464, 0.007417190819978714, 0.025453219190239906, 0.018848013132810593, 0.029903095215559006, -0.0002625187044031918, -0.012561632320284843, -0.037978146225214005, 0.013786396011710167, -0.062181256711483, 0.020991342142224312, -0.05867466703057289, 0.004713334143161774, 0.02445521019399166, 0.012795858085155487, -0.034551870077848434, -0.021467486396431923, 0.024410976096987724, 0.009052194654941559, -0.03209107369184494, 0.004773269407451153, 0.004796701483428478, -0.00390108791179955, -0.02414669841527939, -0.015206699259579182, -0.024927373975515366, -0.016930047422647476, -0.00487589742988348, 0.010079917497932911, -0.016435615718364716, -0.009028171189129353, -0.011400503106415272, 0.018457019701600075, -0.020092668011784554, 0.012755416333675385, -0.010701306164264679, 0.025155354291200638, 0.0407639741897583, -0.009515713900327682, 0.009223883971571922, -0.021945687010884285, -0.033025048673152924, -0.02586290054023266, 0.004360007122159004, 0.016345707699656487, 0.038826584815979004, -0.007477019913494587, -0.02608323097229004, 0.00008897943916963413, -0.025407159700989723, 0.007778656668961048, -0.00003597535760491155, 0.012953288853168488, 0.06018834561109543, 0.028646137565374374, 0.05780360475182533, -0.02969343587756157, -0.031644776463508606, 0.06359763443470001, 0.01423574611544609, -0.02839374914765358, 0.012055340223014355, 0.016271410509943962, 0.034046102315187454, -0.07065512239933014, -0.04267825186252594, -0.004167747218161821, -0.04077731445431709, -0.0024286084808409214, -0.002852313220500946, -0.0011062241392210126, 0.012150841765105724, 0.010446648113429546, 0.009573660790920258, -0.034813735634088516, -0.0487804040312767, -0.018386060371994972, -0.02546127885580063, 0.009713980369269848, -0.031653955578804016, -0.026435794308781624, -0.04381195828318596, 0.01887168549001217, 0.01522638089954853, -0.025959687307476997, 0.003615931374952197, -0.050778523087501526, 0.023038839921355247, -0.024869279935956, -0.10360825061798096, 0.009606492705643177, 0.012579372152686119, -0.014948232099413872, -0.007007069420069456, -0.030278099700808525, 0.013236376456916332, 0.04338953644037247, 0.041251253336668015, 0.0208092350512743, -0.02104819193482399, 0.022697530686855316, 0.011022751219570637, 0.028344137594103813, 0.06175359711050987, 0.011201518587768078, -0.005580084398388863, 0.005243032705038786, 0.024053921923041344, 0.013852172531187534, 0.06918643414974213, 0.013078969903290272, -0.030078142881393433, -0.0036659343168139458, -0.020369959995150566, -0.02990424633026123, -0.01743142493069172, -0.018807506188750267, 0.027912376448512077, -0.02505486272275448, 0.02985534816980362, -0.022206740453839302, 0.004081394989043474, -0.016188522800803185, -0.004951378796249628, -0.08293503522872925, 0.028381170704960823, 0.036892879754304886, 0.01646406389772892, -0.0034833953250199556, -0.054458510130643845, -0.013102023862302303, 0.03238297998905182, -0.02728566713631153, -0.006624145898967981, -0.05009851232171059, -0.012881162576377392, 0.017029808834195137, -0.0003128690295852721, 0.020925192162394524, -0.01362884882837534, 0.006236188113689423, 0.024062717333436012, 0.06395137310028076, -0.027556058019399643, 0.03202464058995247, -0.07163587212562561, -0.007678653113543987, -0.03914765268564224, 0.01453512441366911, 0.019375205039978027, 0.03291548043489456, 0.014850481413304806, -0.013032457791268826, -0.04264217987656593, -0.022435354068875313, -0.01845439150929451, -0.04221125692129135, 0.001987169962376356, 0.031911931931972504, 0.0557253398001194, 0.0335257463157177, 0.003191288560628891, 0.021134568378329277, -0.00615354347974062, -0.0065029519610106945, 0.012948841787874699, -0.03252099081873894, 0.008022996596992016, -0.005187727510929108, -0.013415179215371609, -0.020367315039038658, 0.0021166931837797165, 0.022819889709353447, 0.006488026585429907, 0.006146441679447889, -0.006623978726565838, -0.018111078068614006, -0.0038514991756528616, 0.04653572291135788, -0.042526066303253174, 0.007551710121333599, 0.021627213805913925, -0.048253972083330154, -0.038689129054546356, 0.030680855736136436, 0.04675857722759247, -0.009080860763788223, -0.03695769980549812, 0.00019243854330852628, 0.01646330952644348, 0.032037824392318726, 0.013840933330357075, -0.006513724569231272, 0.0076497807167470455, -0.014103056862950325, -0.05017334967851639, -0.019802436232566833, -0.01132389809936285, -0.021446868777275085, -0.012511747889220715, 0.018283968791365623, 0.03872988000512123, 0.024688074365258217, -0.011938652954995632, -0.027241822332143784, 0.023230062797665596 ]
8acad105c230508195bd3af6419dc374a38241b0
6,670
py
Python
swift/common/ondisk.py
citrix-openstack-build/swift
34340ddf49a84f3b3398012c2b60be1215033559
[ "Apache-2.0" ]
1
2016-03-14T23:38:37.000Z
2016-03-14T23:38:37.000Z
swift/common/ondisk.py
vimeo/swift
5eea524d3ea6d29c2b6f34927c0130090e7ed44d
[ "Apache-2.0" ]
null
null
null
swift/common/ondisk.py
vimeo/swift
5eea524d3ea6d29c2b6f34927c0130090e7ed44d
[ "Apache-2.0" ]
null
null
null
# Copyright (c) 2010-2013 OpenStack, LLC. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or # implied. # See the License for the specific language governing permissions and # limitations under the License. """Methods & Attributes for shared 'on-disk' data layouts.""" import os import sys import errno from hashlib import md5 from random import shuffle from ConfigParser import ConfigParser, NoSectionError, NoOptionError from swift import gettext_ as _ from swift.common.utils import listdir, quote # Used by hash_path to offer a bit more security when generating hashes for # paths. It simply appends this value to all paths; guessing the hash a path # will end up with would also require knowing this suffix. _hash_conf = ConfigParser() HASH_PATH_SUFFIX = '' HASH_PATH_PREFIX = '' if _hash_conf.read('/etc/swift/swift.conf'): try: HASH_PATH_SUFFIX = _hash_conf.get('swift-hash', 'swift_hash_path_suffix') except (NoSectionError, NoOptionError): pass try: HASH_PATH_PREFIX = _hash_conf.get('swift-hash', 'swift_hash_path_prefix') except (NoSectionError, NoOptionError): pass def validate_configuration(): if not HASH_PATH_SUFFIX and not HASH_PATH_PREFIX: sys.exit("Error: [swift-hash]: both swift_hash_path_suffix " "and swift_hash_path_prefix are missing " "from /etc/swift/swift.conf") def hash_path(account, container=None, object=None, raw_digest=False): """ Get the canonical hash for an account/container/object :param account: Account :param container: Container :param object: Object :param raw_digest: If True, return the raw version rather than a hex digest :returns: hash string """ if object and not container: raise ValueError('container is required if object is provided') paths = [account] if container: paths.append(container) if object: paths.append(object) if raw_digest: return md5(HASH_PATH_PREFIX + '/' + '/'.join(paths) + HASH_PATH_SUFFIX).digest() else: return md5(HASH_PATH_PREFIX + '/' + '/'.join(paths) + HASH_PATH_SUFFIX).hexdigest() def normalize_timestamp(timestamp): """ Format a timestamp (string or numeric) into a standardized xxxxxxxxxx.xxxxx (10.5) format. Note that timestamps using values greater than or equal to November 20th, 2286 at 17:46 UTC will use 11 digits to represent the number of seconds. :param timestamp: unix timestamp :returns: normalized timestamp as a string """ return "%016.05f" % (float(timestamp)) def validate_device_partition(device, partition): """ Validate that a device and a partition are valid and won't lead to directory traversal when used. :param device: device to validate :param partition: partition to validate :raises: ValueError if given an invalid device or partition """ invalid_device = False invalid_partition = False if not device or '/' in device or device in ['.', '..']: invalid_device = True if not partition or '/' in partition or partition in ['.', '..']: invalid_partition = True if invalid_device: raise ValueError('Invalid device: %s' % quote(device or '')) elif invalid_partition: raise ValueError('Invalid partition: %s' % quote(partition or '')) def storage_directory(datadir, partition, name_hash): """ Get the storage directory :param datadir: Base data directory :param partition: Partition :param name_hash: Account, container or object name hash :returns: Storage directory """ return os.path.join(datadir, str(partition), name_hash[-3:], name_hash) def audit_location_generator(devices, datadir, suffix='', mount_check=True, logger=None): ''' Given a devices path and a data directory, yield (path, device, partition) for all files in that directory :param devices: parent directory of the devices to be audited :param datadir: a directory located under self.devices. This should be one of the DATADIR constants defined in the account, container, and object servers. :param suffix: path name suffix required for all names returned :param mount_check: Flag to check if a mount check should be performed on devices :param logger: a logger object ''' device_dir = listdir(devices) # randomize devices in case of process restart before sweep completed shuffle(device_dir) for device in device_dir: if mount_check and not \ os.path.ismount(os.path.join(devices, device)): if logger: logger.debug( _('Skipping %s as it is not mounted'), device) continue datadir_path = os.path.join(devices, device, datadir) partitions = listdir(datadir_path) for partition in partitions: part_path = os.path.join(datadir_path, partition) try: suffixes = listdir(part_path) except OSError as e: if e.errno != errno.ENOTDIR: raise continue for asuffix in suffixes: suff_path = os.path.join(part_path, asuffix) try: hashes = listdir(suff_path) except OSError as e: if e.errno != errno.ENOTDIR: raise continue for hsh in hashes: hash_path = os.path.join(suff_path, hsh) try: files = sorted(listdir(hash_path), reverse=True) except OSError as e: if e.errno != errno.ENOTDIR: raise continue for fname in files: if suffix and not fname.endswith(suffix): continue path = os.path.join(hash_path, fname) yield path, device, partition
36.054054
79
0.625487
1
1.9686
[ -0.014973228797316551, -0.008508867584168911, -0.0038088359870016575, 0.00031130111892707646, -0.0015463662566617131, 0.010728899389505386, -0.01787695847451687, -0.0407809242606163, 0.005920280236750841, 0.026493677869439125, 0.002212501596659422, 0.0051681362092494965, 0.015787899494171143, 0.0020719696767628193, -0.009425081312656403, 0.006008765660226345, -0.011228194460272789, -0.0017643048195168376, -0.043047498911619186, -0.030177274718880653, -0.014197243377566338, 0.002110259374603629, -0.001983095658943057, 0.025032678619027138, 0.0009539526654407382, 0.027233226224780083, 0.0025592020247131586, -0.008214093744754791, 0.03385094925761223, -0.003016581293195486, -0.018117612227797508, 0.008658344857394695, 0.02419249899685383, 0.034514252096414566, 0.007767697796225548, 0.006958496756851673, -0.005095047410577536, -0.027530770748853683, -0.005315559450536966, 0.009032049216330051, -0.02462630160152912, -0.013001195155084133, 0.016654251143336296, 0.04541287571191788, 0.018617916852235794, 0.05317561328411102, -0.012123627588152885, -0.0025357375852763653, -0.04648903012275696, 0.023924099281430244, -0.04467777535319328, 0.034946899861097336, 0.02407517284154892, 0.003708633128553629, -0.007774864789098501, -0.03436337411403656, 0.006595341023057699, 0.04144808650016785, -0.0082717789337039, 0.03446189686655998, 0.011824661865830421, -0.004140346776694059, -0.018471911549568176, 0.0031182689126580954, 0.03802764043211937, 0.00045192966354079545, -0.00660665612667799, -0.029612723737955093, -0.011107672937214375, -0.015159172005951405, 0.007558748126029968, -0.0037486141081899405, 0.013403899036347866, 0.018818017095327377, 0.021532565355300903, -0.010928701609373093, 0.008737795054912567, -0.008093096315860748, -0.016807781532406807, -0.00734293507412076, -0.023415280506014824, 0.040499307215213776, 0.015007195062935352, 0.012502945028245449, -0.00260407873429358, 0.01863005943596363, 0.011291266418993473, -0.019455159083008766, 0.027712058275938034, 0.008332385681569576, -0.03069199249148369, 0.011583785526454449, -0.031078359112143517, -0.03337949886918068, -0.008021842688322067, -0.050558481365442276, -0.019134094938635826, 0.005952602252364159, -0.016729919239878654, 0.020440327003598213, -0.0014490238390862942, -0.03995903953909874, 0.0044135102070868015, -0.02563001960515976, -0.013923224061727524, -0.018296383321285248, -0.01579982228577137, 0.0020248934160917997, 0.002093913732096553, -0.04262344539165497, 0.006703361868858337, 0.0017874679761007428, -0.0038250780198723078, -0.03282506763935089, -0.01562931016087532, -0.02350073680281639, 0.03604844585061073, 0.00040548277320340276, 0.021443989127874374, 0.05777731165289879, 0.036409053951501846, -0.03269512951374054, -0.003984285518527031, -0.011379877105355263, -0.01855543628334999, 0.038676973432302475, 0.002647430868819356, -0.005695652216672897, -0.03367628529667854, 0.004712041467428207, 0.02233383059501648, 0.009241310879588127, -0.013606330379843712, -0.035992689430713654, -0.00004519940193858929, -0.018961310386657715, -0.006698197219520807, 0.009128677658736706, -0.01883436180651188, -0.02853357046842575, 0.008229001425206661, -0.005490623414516449, -0.00021329800074454397, -0.0010445652296766639, -0.011415859684348106, -0.04505573585629463, -0.01832096464931965, 0.015982134267687798, -0.00234711985103786, -0.0060047279112041, 0.009672713465988636, -0.004980333149433136, 0.012890494428575039, 0.022990863770246506, 0.018657855689525604, 0.0008499354007653892, -0.003506849752739072, -0.03408854827284813, 0.0003992038546130061, -0.012855718843638897, 0.0009359865798614919, 0.0013139143120497465, 0.026677988469600677, 0.039275240153074265, 0.01817215234041214, 0.024091143161058426, -0.03926301747560501, -0.023398712277412415, -0.013160396367311478, 0.025786269456148148, 0.021635251119732857, -0.025836722925305367, -0.0044719926081597805, 0.013079588301479816, -0.009373314678668976, -0.0017144497251138091, 0.0345032624900341, 0.006785118952393532, -0.005705602001398802, -0.01593269780278206, -0.0060903774574398994, -0.025111611932516098, 0.03424462303519249, 0.03797470033168793, 0.008150293491780758, -0.019177155569195747, -0.02653215453028679, 0.008653449825942516, 0.020798001438379288, 0.01289211492985487, 0.009208150207996368, 0.05273657292127609, 0.010752969421446323, -0.005796519573777914, 0.010400540195405483, 0.009772093966603279, 0.004449730273336172, 0.001532025751657784, -0.00027766413404606283, 0.02551119774580002, 0.007847446016967297, 0.006770498584955931, 0.017764680087566376, 0.040845759212970734, -0.02323453687131405, -0.004751589614897966, -0.8161234259605408, -0.008712554350495338, -0.02870333008468151, -0.0012482876190915704, -0.0015102914767339826, 0.06642811000347137, -0.04353083297610283, 0.01703844778239727, -0.04007774591445923, -0.029923541471362114, 0.00025822114548645914, -0.0017236978746950626, -0.004909160081297159, 0.0016394221456721425, 0.027776667848229408, -0.02839040383696556, 0.003454924561083317, -0.0012510569067671895, -0.003836243413388729, 0.045949745923280716, 0.021674150601029396, 0.020514756441116333, -0.005596294067800045, 0.029801614582538605, -0.007093476131558418, 0.005824128165841103, 0.05250002071261406, 0.017027776688337326, 0.02279059775173664, -0.005214124917984009, 0.007997563108801842, -0.0017255176790058613, 0.0036103518214076757, 0.005325220990926027, 0.0004649620386771858, 0.0037110652774572372, 0.02043606899678707, 0.021715162321925163, -0.029574109241366386, 0.004735127091407776, -0.0013184091076254845, -0.007882220670580864, 0.00956820324063301, -0.051723379641771317, -0.016548361629247665, -0.0041242665611207485, -0.004785463213920593, -0.05659686401486397, 0.051519207656383514, -0.02178121916949749, -0.014253996312618256, 0.004301618319004774, 0.009407621808350086, -0.01486869528889656, 0.003971550613641739, 0.005628297571092844, 0.006373669486492872, -0.0063133095391094685, -0.022811150178313255, -0.006454145070165396, 0.030681369826197624, 0.012951129116117954, -0.003552451264113188, -0.0056027136743068695, -0.038538966327905655, 0.002121909288689494, -0.006106614600867033, -0.0014721975894644856, -0.0037109069526195526, -0.011294400319457054, -0.04780077189207077, 0.001704273745417595, 0.0032997382804751396, 0.07850751280784607, 0.0033922891598194838, 0.004180092830210924, 0.012192962691187859, -0.01404938381165266, 0.0002906563750002533, 0.03244329243898392, 0.016457268968224525, -0.007764726877212524, 0.013140099123120308, -0.0027500391006469727, -0.01709105633199215, 0.028310023248195648, -0.004362280946224928, 0.008045466616749763, 0.0024610147811472416, 0.01848248392343521, -0.004594072233885527, 0.0031741128768771887, 0.015646638348698616, -0.00799042172729969, -0.0010542820673435926, 0.015692872926592827, 0.021791011095046997, 0.023597989231348038, 0.029520072042942047, -0.015186906792223454, -0.006044188980013132, -0.02062593773007393, -0.018054591491818428, 0.04016541317105293, 0.013177559711039066, 0.01775597594678402, -0.0291273333132267, 0.005150769837200642, 0.02462385967373848, -0.02299526333808899, 0.013624949380755424, -0.016189809888601303, -0.013269852846860886, 0.010123835876584053, -0.014730710536241531, -0.010799392126500607, -0.0025815372355282307, -0.011908824555575848, 0.00661607226356864, 0.00980366114526987, 0.003753507509827614, -0.04120075702667236, -0.010631776414811611, -0.000282592634903267, -0.010501849465072155, 0.003895164467394352, 0.017914313822984695, -0.010047920048236847, -0.022151561453938484, 0.022041382268071175, 0.0009503803448751569, -0.001210501417517662, 0.0035677719861268997, -0.01485731266438961, 0.02147342450916767, -0.008694189600646496, 0.022749019786715508, -0.019323209300637245, 0.01754409447312355, -0.002914165612310171, 0.015091530978679657, -0.01865757629275322, 0.00008931391494115815, -0.04809015244245529, -0.0009370612679049373, -0.02635802887380123, -0.008775787428021431, -0.01782034896314144, 0.023118693381547928, -0.007189947180449963, -0.028795436024665833, 0.019791781902313232, 0.006874081678688526, 0.020742561668157578, -0.031051086261868477, 0.012268556281924248, -0.0004917678306810558, 0.025535227730870247, 0.014511264860630035, 0.0009375545778311789, -0.011092377826571465, -0.00018681006622500718, -0.001877747941762209, 0.019023235887289047, -0.018919825553894043, 0.000903534993994981, -0.01722620613873005, 0.03817691281437874, 0.002089262241497636, 0.05841678008437157, 0.01632147654891014, -0.03351613134145737, 0.015999052673578262, -0.003235625335946679, -0.03231218084692955, -0.04468674212694168, -0.005191368982195854, 0.013864344917237759, -0.02787145785987377, -0.002283654874190688, 0.04557625204324722, 0.005449662916362286, -0.009830601513385773, -0.009779926389455795, -0.020559918135404587, 0.0021692407317459583, -0.014503523707389832, 0.006008736789226532, 0.03374430909752846, -0.007154657505452633, 0.025352727621793747, 0.014522027224302292, -0.032696355134248734, 0.02533886209130287, -0.02673049084842205, -0.027021249756217003, -0.024049891158938408, 0.011419640854001045, 0.005080435425043106, -0.007678323891013861, 0.019775981083512306, -0.023780865594744682, 0.029562562704086304, 0.015698669478297234, -0.0038126909639686346, 0.015464592725038528, -0.012131737545132637, 0.0096758883446455, -0.0060489890165627, 0.0027754311449825764, 0.022508172318339348, -0.00017110735643655062, 0.02036276087164879, 0.017305003479123116, -0.0012675052275881171, 0.003855807241052389, -0.027486314997076988, -0.013149512931704521, -0.04373890161514282, -0.016157129779458046, 0.007462920621037483, 0.0005024964921176434, 0.014056126587092876, 0.01440297719091177, -0.007432118523865938, -0.001597491791471839, -0.05665166303515434, 0.028548220172524452, 0.0005968405166640878, 0.02663050964474678, -0.015548895113170147, -0.024299684911966324, -0.0010834905551746488, -0.008310243487358093, -0.004179977811872959, 0.01709764264523983, -0.012020646594464779, -0.0005433078040368855, 0.021617544814944267, -0.0119479950517416, 0.00714927027001977, 0.03414544835686684, -0.016125377267599106, 0.01099644135683775, 0.00954277440905571, 0.012838803231716156, 0.012602333910763264, -0.006823617499321699, -0.016644034534692764, -0.010503985919058323, -0.019495997577905655, -0.004958707839250565, 0.03453696146607399, -0.0059030670672655106, -0.007773097138851881, -0.004943005740642548, -0.005695353727787733, -0.004142310004681349, 0.025361718609929085, 0.01866135746240616, 0.0026916100177913904, -0.044893987476825714, 0.009959123097360134, 0.006349322386085987, -0.005593725014477968, -0.01902097836136818, -0.01149393804371357, 0.020114410668611526, -0.016245275735855103, 0.03225383907556534, 0.010042103007435799, 0.015419915318489075, -0.010733820497989655, -0.005926505196839571, 0.009509717114269733, -0.02695958875119686, 0.0017378630582243204, -0.012475425377488136, -0.003085428848862648, 0.036694157868623734, -0.0016938564367592335, -0.021112650632858276, 0.007300807163119316, 0.01873644068837166, -0.01481085829436779, 0.011071412824094296, 0.025630822405219078, 0.011379402130842209, -0.028147907927632332, 0.007603087462484837, -0.025003651157021523, -0.021551193669438362, -0.05470893532037735, -0.0009505264461040497, -0.01584058254957199, 0.00561787374317646, 0.0027827832382172346, 0.008965534158051014, 0.06243729963898659, 0.04281648248434067, 0.0483209528028965, 0.028534743934869766, 0.0063936649821698666, 0.011583918705582619, 0.03845745697617531, -0.02915370464324951, -0.02402482181787491, -0.0003253324539400637, 0.01508011668920517, 0.013676725327968597, 0.01687036082148552, 0.014194062910974026, -0.015611629001796246, -0.006131409201771021, 0.013056115247309208, -0.020828552544116974, 0.022166673094034195, 0.009745805524289608, -0.010105776600539684, -0.013102394528687, -0.020265057682991028, 0.030944736674427986, -0.04290958121418953, -0.026306450366973877, -0.004381367936730385, -0.02010025456547737, -0.00961321871727705, -0.040705956518650055, 0.02737932652235031, 0.015382207930088043, -0.04245786741375923, -0.011487741023302078, 0.024015426635742188, 0.027590811252593994, 0.03271354362368584, -0.02191891148686409, -0.021726984530687332, 0.010101599618792534, -0.027058139443397522, 0.011184154078364372, 0.026250915601849556, 0.03606496751308441, -0.01426017563790083, -0.017296144738793373, -0.007155757397413254, 0.0004420110199134797, 0.01420421339571476, 0.040450822561979294, -0.011888701468706131, 0.023412706330418587, 0.018500445410609245, -0.023479420691728592, -0.04202370345592499, -0.0023386322427541018, 0.01972048543393612, -0.006098206155002117, 0.005349645856767893, 0.03446922451257706, -0.0008955512312240899, -0.01850847899913788, 0.0165628083050251, -0.020354434847831726, -0.012032787315547466, 0.020441588014364243, 0.004983285907655954, -0.008759099058806896, 0.030383281409740448, -0.0025838094297796488, 0.004232330247759819, -0.009587625972926617, -0.006891394034028053, 0.017068123444914818, 0.01566700078547001, -0.029348166659474373, 0.011899849399924278, 0.04935292527079582, 0.007887712679803371, -0.0060495189391076565, -0.006697138771414757, -0.039364565163850784, -0.005688556469976902, -0.017668716609477997, -0.016462178900837898, -0.048489704728126526, 0.006570476572960615, -0.02992703579366207, -0.010198617354035378, 0.006129434797912836, 0.015448631718754768, -0.027645695954561234, 0.0011241002939641476, -0.000739909359253943, 0.004717545583844185, 0.02411986142396927, 0.011726907454431057, -0.00024896743707358837, 0.009348477236926556, 0.0015210987767204642, 0.007263688370585442, -0.0325641930103302, 0.004927258938550949, -0.026393938809633255, 0.011385591700673103, -0.006850087083876133, 0.0024607637897133827, -0.025844868272542953, 0.012206698767840862, -0.0071348468773067, -0.006859302520751953, 0.0026884484104812145, -0.0023975905496627092, 0.01142459362745285, 0.014302464202046394, 0.015203537419438362, 0.019217001274228096, 0.012601340189576149, -0.009836866520345211, 0.01689356565475464, -0.0052663544192910194, -0.03415552154183388, 0.0031936634331941605, -0.02428000047802925, 0.00043185631511732936, -0.004129538778215647, -0.0009702518000267446, -0.0007708484772592783, 0.016496729105710983, -0.004843532107770443, -0.00675016175955534, -0.01749621145427227, -0.029508134350180626, -0.017788272351026535, -0.020462119951844215, -0.010637827217578888, 0.045769546180963516, 0.0021146226208657026, -0.005770671647042036, -0.009155180305242538, -0.017676401883363724, 0.015445918776094913, -0.04195743799209595, 0.006757241208106279, 0.02394597977399826, 0.013979633338749409, -0.010615634731948376, -0.02219763584434986, 0.01733504980802536, 0.01680237241089344, -0.020516978576779366, -0.0019900735933333635, -0.022999068722128868, 0.01330222561955452, 0.0032609060872346163, 0.0031447112560272217, 0.0016249214531853795, 0.004038316197693348, -0.030266281217336655, 0.00936269760131836, 0.01203522365540266, 0.003162012668326497, 0.007059529423713684, -0.0022247671149671078, -0.02866220660507679, 0.000580448133405298, -0.0048368084244430065, 0.008081518113613129, -0.016579464077949524, 0.006353291217237711, -0.010223262943327427, -0.0005000339588150382, 0.029559580609202385, 0.010722838342189789, -0.010867534205317497, -0.006720047909766436, -0.02475130185484886, 0.03298947960138321, -0.009998428635299206, 0.0034496705047786236, 0.032859478145837784, 0.04300817847251892, -0.051809780299663544, 0.011383440345525742, 0.010576173663139343, 0.0028505646623671055, 0.00428081676363945, 0.001264626276679337, -0.00747575843706727, -0.014229253865778446, -0.009287380613386631, 0.0224487092345953, 0.016408570110797882, -0.0038472251035273075, -0.0013963708188384771, 0.009480655193328857, -0.015149736776947975, -0.007999191991984844, -0.023538224399089813, -0.022216206416487694, 0.03166649118065834, 0.006969264708459377, 0.014947031624615192, -0.025458019226789474, -0.004543283022940159, -0.004449281841516495, 0.024388179183006287, 0.0058167558163404465, 0.06190255284309387, -0.010537343099713326, -0.003282648976892233, -0.0118346456438303, 0.0002154014800908044, 0.0034709880128502846, -0.04374786466360092, -0.02557988278567791, 0.013837190344929695, 0.011638761498034, 0.036334577947854996, -0.035037823021411896, 0.0009047450730577111, 0.024449486285448074, -0.0029999653343111277, 0.0038584237918257713, 0.025002731010317802, -0.02355840429663658, -0.017985103651881218, 0.009884554892778397, -0.015678919851779938, -0.04984385520219803, 0.013145382516086102, 0.01968453638255596, -0.01120714284479618, -0.021471746265888214, 0.003380880691111088, -0.022983795031905174, 0.017407868057489395, -0.03157994896173477, 0.022250661626458168, 0.004769848193973303, -0.02113974280655384, -0.011009386740624905, 0.000429067324148491, -0.005404324270784855, -0.015609946101903915, -0.01987774297595024, -0.008709585294127464, -0.03547191247344017, -0.0017240062588825822, 0.05633895844221115, 0.006425203289836645, 0.026251131668686867, -0.009982463903725147, 0.0015326504362747073, -0.04247517138719559, -0.027233872562646866, -0.03248736262321472, -0.00926689151674509, 0.009661759249866009, 0.015731442719697952, 0.003047405509278178, -0.057326607406139374, -0.018304886296391487, 0.0224793441593647 ]
8acb675f5ab5c65b02ffbf255720c5176625a170
1,923
py
Python
.OLD_FILES/dossiers2_old1/custom/cache.py
KIHestad/WoT-Dossier-Parser-Create-Struct
9eadeeead59b7b6cf78dc6a1e1e89fe2dffb260e
[ "MIT" ]
null
null
null
.OLD_FILES/dossiers2_old1/custom/cache.py
KIHestad/WoT-Dossier-Parser-Create-Struct
9eadeeead59b7b6cf78dc6a1e1e89fe2dffb260e
[ "MIT" ]
null
null
null
.OLD_FILES/dossiers2_old1/custom/cache.py
KIHestad/WoT-Dossier-Parser-Create-Struct
9eadeeead59b7b6cf78dc6a1e1e89fe2dffb260e
[ "MIT" ]
2
2021-11-10T19:12:57.000Z
2022-03-13T10:04:48.000Z
# uncompyle6 version 2.11.3 # Python bytecode 2.7 (62211) # Decompiled from: Python 2.7.10 (default, May 23 2015, 09:40:32) [MSC v.1500 32 bit (Intel)] # Embedded file name: scripts/common/dossiers2/custom/cache.py import nations from items import vehicles def getCache(): global _g_cache return _g_cache def buildCache(): vehiclesByLevel = {} vehiclesByTag = {'beast': set(),'sinai': set(),'patton': set()} vehiclesInTreeByNation = {} vehiclesInTree = set() nationsWithVehiclesInTree = [] unlocksSources = vehicles.getUnlocksSources() for nationIdx in xrange(len(nations.NAMES)): nationList = vehicles.g_list.getList(nationIdx) vehiclesInNationTree = set() for vehDescr in nationList.itervalues(): vehiclesByLevel.setdefault(vehDescr.level, set()).add(vehDescr.compactDescr) for tag in ('beast', 'sinai', 'patton'): if tag in vehDescr.tags: vehiclesByTag[tag].add(vehDescr.compactDescr) if len(unlocksSources.get(vehDescr.compactDescr, set())) > 0 or len(vehicles.g_cache.vehicle(nationIdx, vehDescr.id).unlocksDescrs) > 0: vehiclesInNationTree.add(vehDescr.compactDescr) vehiclesInTree.update(vehiclesInNationTree) vehiclesInTreeByNation[nationIdx] = vehiclesInNationTree if bool(vehiclesInNationTree): nationsWithVehiclesInTree.append(nationIdx) vehicles8p = vehiclesByLevel[8] | vehiclesByLevel[9] | vehiclesByLevel[10] _g_cache.update({'vehiclesByLevel': vehiclesByLevel, 'vehicles8+': vehicles8p, 'vehiclesByTag': vehiclesByTag, 'mausTypeCompDescr': vehicles.makeVehicleTypeCompDescrByName('germany:G42_Maus'), 'vehiclesInTreesByNation': vehiclesInTreeByNation, 'vehiclesInTrees': vehiclesInTree, 'nationsWithVehiclesInTree': nationsWithVehiclesInTree }) _g_cache = {}
40.0625
148
0.693708
1
1.3941
[ 0.0012242408702149987, 0.02398907206952572, 0.007396319415420294, 0.00011403341341065243, 0.005884645972400904, -0.004306793678551912, -0.009146607480943203, 0.0011884398991242051, -0.006358110811561346, 0.001829963643103838, 0.0012672387529164553, 0.007710825651884079, 0.007729378063231707, -0.016707386821508408, 0.0017509382450953126, 0.01748088002204895, -0.05208810791373253, 0.0010341204470023513, -0.0037745991721749306, 0.001190458657220006, -0.0076125916093587875, 0.009586138650774956, 0.00871657207608223, 0.005646050442010164, 0.005799493752419949, 0.0008818864007480443, 0.008189196698367596, 0.005299619864672422, -0.009744229726493359, -0.0055368198081851006, -0.0007290157955139875, -0.001924320706166327, -0.0035617463290691376, -0.009359331801533699, 0.006533897016197443, -0.0024983228649944067, -0.0010042206849902868, -0.020499927923083305, 0.010093237273395061, -0.003316666930913925, -0.006246676668524742, -0.011244114488363266, 0.0008477788651362062, 0.0035430165007710457, -0.008123405277729034, 0.00115414138417691, -0.005285473540425301, 0.0030666664242744446, -0.010799710638821125, 0.004806820303201675, -0.008884518407285213, 0.007817336358129978, 0.013477953150868416, 0.0024586408399045467, -0.005599083378911018, -0.004873358178883791, 0.012562408111989498, 0.000087390435510315, -0.008703435771167278, -0.0011844926048070192, -0.0038528686854988337, -0.0025658055674284697, 0.004511650651693344, 0.0025264995638281107, -0.016148360446095467, -0.007662746123969555, -0.003366755321621895, 0.0024892573710530996, -0.0020333805587142706, 0.004358947742730379, 0.0017733722925186157, -0.00013663516438100487, 0.007279932964593172, 0.004397402051836252, 0.005886560771614313, -0.001628816477023065, -0.0006671347073279321, 0.0008713826537132263, 0.007596055045723915, 0.0025616383645683527, 0.005663159769028425, -0.005040348507463932, 0.004572893492877483, 0.011218343861401081, 0.013503411784768105, 0.006008475087583065, 0.016614098101854324, -0.012903448194265366, 0.046612776815891266, 0.006941305473446846, -0.009338855743408203, 0.004186304751783609, -0.010935845784842968, -0.0038367791566997766, -0.006156467832624912, -0.026984525844454765, 0.0005368900601752102, -0.0039599742740392685, 0.001091530080884695, 0.004974948707967997, -0.0005049296305514872, 0.007821213454008102, -0.0003466687921900302, -0.0015739129157736897, -0.010530627332627773, 0.01205682847648859, -0.010754024609923363, -0.002068184781819582, 0.008542705327272415, 0.0025247056037187576, -0.009403019212186337, -0.0015965794445946813, 0.0015022275038063526, -0.009574799798429012, 0.005404606927186251, 0.0036254306323826313, -0.00494198314845562, 0.053085096180438995, -0.002404472092166543, 0.0027408991008996964, -0.005372588522732258, 0.0019630093593150377, 0.0032667717896401882, 0.007372922729700804, 0.009472484700381756, -0.0019374557305127382, 0.015122959390282631, 0.0059853061102330685, 0.0018523669568821788, 0.009079430252313614, -0.0015815050574019551, 0.005519057158380747, -0.0037003408651798964, -0.0008241914329119027, -0.0008251694962382317, -0.007513233460485935, 0.0075806742534041405, -0.0007443201029673219, -0.006659016013145447, 0.0021305042318999767, -0.002378254197537899, -0.010985002852976322, 0.00034817453706637025, -0.0024334073532372713, 0.002283505629748106, -0.010913779959082603, -0.003167844144627452, -0.003941214643418789, -0.0036337049677968025, 0.0029849756974726915, 0.007517265155911446, 0.005051186308264732, 0.0038015425670892, -0.0063348980620503426, -0.010454727336764336, 0.0000992953428067267, -0.0059224278666079044, 0.0006915376288816333, 0.006768408231437206, 0.0014199208235368133, -0.007739814464002848, -0.0018282944802194834, 0.0037878938019275665, 0.0052341572009027, -0.002222801558673382, 0.002203684998676181, -0.006880465429276228, 0.007056801579892635, 0.0002619287697598338, 0.004665780812501907, 0.009323567152023315, -0.004031791817396879, 0.00010636077786330134, -0.0005232534022070467, 0.002307150512933731, 0.00005423272159532644, 0.005796585697680712, 0.008270497433841228, -0.0018425560556352139, -0.003842306789010763, 0.006826975382864475, 0.00596717419102788, 0.009796376340091228, 0.0036717529874294996, -0.0012626857496798038, 0.0018196769524365664, -0.0036028141621500254, -0.002648767549544573, 0.005762701388448477, -0.005787185858935118, 0.006225154269486666, 0.003999928943812847, -0.012874407693743706, -0.008305937983095646, -0.0014929452445358038, -0.009716086089611053, 0.0002841844689100981, 0.013563482090830803, 0.01208818145096302, -0.001272356603294611, 0.003598289331421256, -0.008532356470823288, -0.0007042037905193865, 0.005512196104973555, 0.00034928665263578296, -0.01254432462155819, -0.9585943222045898, 0.007254704367369413, 0.0033955820836126804, -0.0014556263340637088, 0.005018009338527918, 0.001340383430942893, 0.00318531459197402, 0.004693051800131798, 0.01293711643666029, -0.006777029950171709, -0.0071391938254237175, -0.00975355040282011, -0.011926147155463696, -0.0018171238480135798, -0.007183389738202095, -0.001093254191800952, -0.005907589104026556, -0.0090487040579319, 0.00043445511255413294, -0.0019042853964492679, -0.002857348183169961, 0.008738690987229347, 0.00041427064570598304, 0.006547898985445499, 0.0019308499759063125, 0.00482145044952631, -0.004152556881308556, 0.0003157037717755884, -0.002261694986373186, -0.003742573317140341, -0.005650800187140703, -0.015178174711763859, -0.005307955201715231, -0.002148729981854558, 0.010887459851801395, 0.0008722568163648248, 0.0074336351826786995, -0.0025173998437821865, 0.00006903905887156725, -0.009822036139667034, 0.005275295581668615, 0.002762111136689782, 0.00426910724490881, -0.029414258897304535, 0.00041512565803714097, -0.0008729611872695386, -0.007273116614669561, 0.009889482520520687, -0.0001738369173835963, -0.003342681098729372, -0.0036443111021071672, -0.005137358792126179, 0.007227353285998106, -0.008369158953428268, 0.006085732486099005, -0.004802316427230835, -0.008028286509215832, -0.0043541244231164455, -0.008419550955295563, 0.0022835773415863514, 0.004002491477876902, -0.0016851394902914762, -0.004776087589561939, -0.005917611997574568, 0.004808870144188404, 0.002533816732466221, 0.0036909182090312243, -0.018460065126419067, -0.008260209113359451, 0.0020278925076127052, 0.00359328743070364, -0.0026272416580468416, -0.004589506424963474, 0.004857954103499651, -0.010219619609415531, 0.005765868816524744, 0.003441460896283388, 0.00011250937677687034, -0.012641546316444874, -0.0002829960430972278, -0.0109242033213377, -0.007879256270825863, 0.00010686314635677263, -0.004894937854260206, -0.005162011366337538, 0.0014140981948003173, 0.001987005351111293, 0.006016585975885391, -0.0044961594976484776, 0.0062235197983682156, 0.011094906367361546, -0.004162701312452555, -0.008672427386045456, 0.007231551222503185, 0.008883985690772533, 0.002548515098169446, -0.000849470030516386, 0.002903158077970147, 0.008179829455912113, 0.009779221378266811, 0.0012806091690436006, 0.0060306512750685215, -0.0004916337784379721, 0.011651504784822464, -0.0007191834738478065, -0.000056891389249358326, -0.004146738443523645, -0.0016726606991142035, -0.005036181770265102, -0.00027481935103423893, -0.002111602108925581, -0.002802398055791855, -0.012169117107987404, -0.009088912978768349, -0.002753200940787792, -0.000026760810214909725, 0.0034094913862645626, -0.005837616045027971, -0.0016276327660307288, 0.0021428947802633047, 0.006659633480012417, 0.00009147216042038053, -0.0034256023354828358, 0.001844771672040224, 0.0013411825057119131, -0.004949985537678003, 0.014930625446140766, -0.01121255662292242, 0.006341850850731134, 0.001643930678255856, -0.014895486645400524, 0.0067672221921384335, 0.011038175784051418, -0.007365171331912279, 0.0008025856805033982, 0.0020859278738498688, 0.0013043435756117105, -0.0014400678919628263, -0.005486925598233938, -0.0020688646472990513, -0.01871676743030548, 0.0009934835834428668, 0.022277461364865303, 0.003357033245265484, 0.012282595969736576, 0.01165018416941166, -0.0023489987943321466, 0.0017093311762437224, 0.009285520762205124, 0.0013138677459210157, 0.012489917688071728, -0.0071585471741855145, -0.00003633715823525563, 0.0004825772484764457, -0.0076311007142066956, 0.0014184527099132538, 0.0064294361509382725, 0.0061483727768063545, -0.002766877645626664, 0.0015890599461272359, -0.009123263880610466, -0.005637387745082378, -0.016350360587239265, -0.00399460643529892, 0.008315473794937134, -0.0037281394470483065, 0.005483737215399742, -0.010725144296884537, 0.005146086681634188, 0.003979397006332874, 0.006565859075635672, 0.0005267054075375199, 0.0009935714770108461, 0.005315860267728567, 0.013884938322007656, -0.006322332192212343, 0.0021431378554552794, 0.0014558827970176935, -0.0009034287068061531, 0.001601383090019226, 0.009558663703501225, -0.007956244982779026, -0.004815878812223673, 0.0011163227027282119, 0.004784751683473587, -0.0016214509960263968, -0.0019401389872655272, -0.009513424709439278, -0.00523955887183547, 0.005513117648661137, -0.00743648549541831, -0.000010186190593231004, 0.0029464219696819782, 0.0040520248003304005, -0.008727685548365116, -0.0020883362740278244, -0.006890292279422283, -0.011575710959732533, 0.011469726450741291, -0.003359061200171709, 0.003555506933480501, 0.015840526670217514, 0.003688483964651823, -0.013352442532777786, 0.004635869525372982, 0.009238422848284245, -0.0051648267544806, 0.003168452763929963, 0.006788122933357954, -0.004169914405792952, -0.022569751366972923, -0.0013059397460892797, -0.014078479260206223, 0.0034378443378955126, -0.003951369784772396, 0.003340339520946145, -0.00783630646765232, 0.007821695879101753, 0.005069065373390913, -0.012949462048709393, -0.005073156673461199, -0.0068002729676663876, 0.008543109521269798, 0.001013920409604907, 0.0009828282054513693, -0.004001854918897152, -0.0012953280238434672, -0.001056691980920732, -0.0021690044086426497, -0.0036851007025688887, 0.006583757698535919, 0.0020215006079524755, -0.0023943986743688583, 0.0016844031633809209, -0.003244624473154545, 0.00030632424750365317, 0.0006342018023133278, -0.011144070886075497, 0.0013817702420055866, 0.003983684349805117, -0.0018879604758694768, -0.0018803447019308805, 0.0012832226930186152, -0.0037002000026404858, -0.007856141775846481, -0.009315242059528828, -0.0066931163892149925, -0.003457715967670083, -0.004574034363031387, -0.011819500476121902, -0.001733544748276472, -0.011839287355542183, 0.009387928061187267, -0.007629775907844305, 0.00756040308624506, 0.006171945948153734, -0.006243190728127956, 0.006386626046150923, -0.0000705442507751286, 0.006132496986538172, 0.001824873499572277, 0.007097912486642599, 0.0006770740728825331, -0.00811315793544054, -0.010932201519608498, 0.012280388735234737, -0.010446027852594852, 0.0005352831794880331, 0.015678515657782555, 0.0046497671864926815, 0.009360157884657383, -0.0010100608924403787, 0.0007681231363676488, 0.0020142917055636644, 0.0052513363771140575, -0.013000399805605412, 0.0033262502402067184, -0.004254227038472891, -0.0016377137508243322, 0.0042800744995474815, -0.004116803873330355, 0.0005793708842247725, 0.00815704744309187, -0.00004280731445760466, -0.006693386472761631, -0.0021039112471044064, -0.0004731400404125452, 0.0029185274615883827, -0.01086899358779192, -0.0000749426253605634, -0.003779177786782384, -0.005431506782770157, -0.004001331515610218, -0.0023649788927286863, -0.0002519218542147428, 0.0034672268666327, -0.001891987631097436, 0.004632212221622467, 0.00004004050060757436, -0.005322897806763649, 0.013091649860143661, -0.004805865231901407, -0.00543958181515336, 0.004776431247591972, 0.0019524777308106422, -0.0018517414573580027, -0.006762140430510044, -0.004296144004911184, 0.002337868558242917, 0.006526750512421131, -0.003111278172582388, -0.004796813707798719, -0.0026748748496174812, -0.0007205653237178922, -0.008441055193543434, 0.0007125244592316449, 0.011836837977170944, -0.007009096443653107, 0.004499499686062336, -0.0024321312084794044, -0.008027258329093456, -0.014096906408667564, 0.05402645841240883, -0.002110216533765197, 0.004373698960989714, 0.003558758646249771, -0.008141603320837021, -0.0015500846784561872, -0.003242540406063199, 0.0064696986228227615, -0.007482791785150766, -0.007735308725386858, 0.008535249158740044, -0.003958897665143013, 0.0030315062031149864, 0.002012452809140086, 0.0005499536637216806, 0.015392392873764038, -0.004180638585239649, -0.016867462545633316, -0.018913403153419495, 0.005558156408369541, -0.0033080391585826874, -0.006342994514852762, 0.00935142207890749, -0.004892964381724596, -0.00505624758079648, 0.0017148684710264206, 0.005942345596849918, 0.0024957505520433187, 0.001263691345229745, -0.0029970966279506683, -0.004043971188366413, 0.00020366803801152855, 0.0023045886773616076, 0.0049690548330545425, 0.004915392026305199, -0.0006876954576000571, 0.005278680939227343, -0.0023743840865790844, -0.00038261691224761307, -0.0022026291117072105, 0.006085927132517099, 0.0071759955026209354, 0.00010472679423401132, -0.000835113343782723, 0.004467235412448645, 0.00454695476219058, 0.0028934951405972242, 0.015006022527813911, -0.001213678391650319, -0.00513806939125061, 0.008753704838454723, 0.006419733166694641, -0.0005627268110401928, 0.007369950879365206, -0.0025338034611195326, 0.006005382165312767, 0.004312935285270214, -0.007220802828669548, -0.014699474908411503, -0.0028110777493566275, 0.0083095021545887, 0.009861352853477001, -0.001036846893839538, -0.0020492870826274157, -0.0015290484298020601, -0.0025484408251941204, -0.00525328516960144, -0.007437950931489468, 0.0000966025545494631, 0.0006217681802809238, 0.002139856107532978, 0.07036395370960236, -0.007309469860047102, -0.0008251861436292529, -0.009177143685519695, -0.0019699842669069767, -0.0011250119423493743, -0.0017025783890858293, 0.00007649150211364031, -0.0015631108544766903, 0.000786195567343384, 0.001726021757349372, -0.009374124929308891, -0.009892556816339493, 0.00022882908524479717, 0.002834560116752982, -0.002606365829706192, 0.0037099416367709637, 0.007304168306291103, -0.00876584742218256, 0.004044096451252699, -0.013957696035504341, -0.0000988993706414476, -0.0014509790344163775, -0.009462040849030018, -0.004169653169810772, -0.003694575745612383, 0.007841212674975395, 0.0029769211541861296, 0.0065052998252213, -0.0034305264707654715, 0.004164676181972027, -0.002718427451327443, 0.0014973576180636883, -0.0019376639975234866, -0.00035200960701331496, -0.005511653609573841, 0.008343546651303768, 0.0007525127148255706, -0.012588698416948318, -0.005473146215081215, -0.0008630297961644828, 0.00037809580680914223, -0.004626577720046043, 0.005193161778151989, 0.0020169634371995926, 0.008275038562715054, -0.0043939691968262196, 0.0020156509708613157, -0.004151590168476105, 0.0050533246248960495, -0.011837451718747616, 0.004432802554219961, -0.17209981381893158, 0.012752695940434933, 0.0026665383484214544, -0.006954222451895475, -0.003953886684030294, -0.014370668679475784, -0.008644519373774529, 0.002683584112673998, 0.01041573379188776, 0.002606665249913931, -0.0003764106659218669, -0.0021120451856404543, 0.0043693725019693375, 0.004016422666609287, -0.0014722938649356365, -0.0062569561414420605, 0.00427556736394763, -0.005059930961579084, -0.0004471620195545256, 0.0038385246880352497, 0.004277481697499752, 0.009931170381605625, 0.0024338255170732737, 0.0026939730159938335, -0.0009960522875189781, -0.005436154082417488, 0.004869404714554548, -0.0022482560016214848, 0.005303579848259687, -0.010673978365957737, -0.0038467496633529663, -0.005971794482320547, -0.004395367112010717, -0.00012102408072678372, 0.004056459758430719, -0.0004281793371774256, 0.00860530510544777, 0.0021049040369689465, -0.008623043075203896, 0.005159592721611261, -0.004154294263571501, 0.027217242866754532, 0.004815313033759594, 0.008180316537618637, 0.0011060290271416306, -0.005101482849568129, -0.0057100593112409115, 0.011120568960905075, 0.0026494693011045456, 0.014037976041436195, -0.014824623242020607, -0.0009194501326419413, 0.0016512536676600575, 0.017044153064489365, -0.004593657795339823, -0.012378567829728127, -0.0061205364763736725, -0.002199361566454172, 0.0035834622103720903, 0.008175826631486416, 0.010106430388987064, -0.004333570133894682, 0.008891766890883446, -0.003429929492995143, -0.021728897467255592, 0.0037574837915599346, -0.002686851192265749, -0.007158704102039337, 0.0016683639260008931, 0.008261882700026035, 0.009968359023332596, -0.0011530008632689714, 0.004923913162201643, -0.00045686724479310215, 0.0057837641797959805, -0.0003248589055147022, 0.004241544753313065, -0.0022088356781750917, 0.0076960125006735325, -0.009680754505097866, 0.009391269646584988, -0.008018159307539463, -0.0059601678512990475, 0.0007518576458096504, -0.007676855195313692, 0.009917663410305977, 0.004405421670526266, -0.001603193231858313, -0.0006575817824341357, -0.01174854300916195, -0.0034891318064182997, 0.0016450880793854594, 0.0025728594046086073, -0.008758402429521084, 0.0025086042005568743, 0.0015253667952492833, 0.004661396145820618, 0.005030945874750614, -0.009773323312401772, 0.006179689895361662, 0.0030823671258985996, -0.006676637567579746, 0.0012171543203294277, -0.005129392724484205, -0.0002538249536883086, 0.0053132809698581696, -0.007297974079847336, -0.006882460322231054, 0.004507781937718391, -0.005527220666408539, -0.0056759389117360115, 0.006517881993204355, -0.009967925027012825, -0.010090792551636696, -0.00213717482984066, -0.011143953539431095, 0.002080410486087203 ]
8acb71f44d08977a58d847a4d25a262b4cc3e603
35,471
py
Python
src/parser.py
harkiratbehl/PyGM
e0a4e0b865afb607dfa0525ca386bfbe77bb6508
[ "MIT" ]
2
2019-02-13T11:30:08.000Z
2021-02-14T04:20:44.000Z
src/parser.py
harkiratbehl/PyGM
e0a4e0b865afb607dfa0525ca386bfbe77bb6508
[ "MIT" ]
null
null
null
src/parser.py
harkiratbehl/PyGM
e0a4e0b865afb607dfa0525ca386bfbe77bb6508
[ "MIT" ]
null
null
null
#!/usr/bin/python from code import TreeNode from code import ThreeAddressCode from lexer import tokens from random import * from symbol_table import SymbolTable from symbol_table import SymbolTableNode import logging import ply.lex as lex import ply.yacc as yacc import sys from codegen import convert_tac from code import Code from codegen import generate_assembly three_addr_code = ThreeAddressCode() assembly_code = Code() parsed = [] symbol_table = SymbolTable() var_list = [] generated = {'temp': [], 'scope': ['scope_0'], 'label': [], 'str_list': []} def gen(s): if s not in generated.keys(): generated[s] = [] temp = s + '_' + str(len(generated[s])) generated[s] += [temp] return temp def print_error(err): print "*** Error: " + err + "! ***" sys.exit(1) def check_variable(TreeNode): # return 2 values. first is the name for the variable, second is 0 if variable not found # TreeNode.print_node() # symbol_table.print_symbol_table() if TreeNode.isLvalue == 1: if TreeNode.data not in generated['temp']: name = symbol_table.search_identifier(TreeNode.data) if name == False: name = symbol_table.search_function(TreeNode.data) if name == False: print_error("Variable " + TreeNode.data + " is undefined") return TreeNode.data else: return name else: newNode = SymbolTableNode(name, TreeNode.input_type) symbol_table.add_var(newNode) if TreeNode.children == []: return name else: return name + '[' + TreeNode.children + ']' else: newNode = SymbolTableNode(TreeNode.data, TreeNode.input_type) symbol_table.add_var(newNode) return TreeNode.data else: if TreeNode.input_type != 'STRING': return TreeNode.data else: TreeNode.print_node() return TreeNode.data precedence = ( ('left','IDENTIFIER'), ('right','ASSIGN_OP'), ('left','COMMA'), ('left','LSQUARE'), ('left','RSQUARE'), ('left','LCURLY'), ('left','RCURLY'), ('left','DDD'), ('left','DOT'), ('left','SEMICOLON'), ('left','COLON'), ('left','SINGLE_QUOTES'), ('left','DOUBLE_QUOTES'), ('left','DECIMAL_LIT'), ('left','OCTAL_LIT'), ('left','HEX_LIT'), ('left','FLOAT_LIT'), ('left','STRING_LIT'), ('left','NEWLINE'), ('left','BREAK'), ('left','CONTINUE'), ('left','RETURN'), ('left','RROUND'), ('left','LROUND'), ('left', 'OR_OR'), ('left', 'AMP_AMP'), ('left', 'EQ_EQ', 'NOT_EQ','LT','LT_EQ','GT','GT_EQ'), ('left', 'PLUS', 'MINUS','OR','CARET'), ('left', 'STAR', 'DIVIDE','MODULO','AMP','AND_OR','LS','RS'), ) def p_SourceFile(p): '''SourceFile : PACKAGE IDENTIFIER SEMICOLON ImportDeclList TopLevelDeclList ''' parsed.append(p.slice) # TODO: Ignoring package name and Imports for now p[0] = p[5] var_list = symbol_table.make_var_list() three_addr_code = convert_tac(p[0].TAC) symbol_table.fill_next_use(three_addr_code) assembly_code = generate_assembly(three_addr_code,var_list,symbol_table) # p[0].TAC.print_code() # three_addr_code.print_code() assembly_code.print_code() # symbol_table.print_symbol_table() return def p_ImportDeclList(p): '''ImportDeclList : ImportDecl SEMICOLON ImportDeclList | empty ''' parsed.append(p.slice) # TODO: Ignoring Imports for now return def p_TopLevelDeclList(p): '''TopLevelDeclList : TopLevelDecl SEMICOLON TopLevelDeclList | empty ''' parsed.append(p.slice) if len(p) == 4: if p[3] != None: p[0] = TreeNode('TopLevelDeclList', 0, 'INT', 0, [p[1]] + p[3].children, p[1].TAC) p[0].TAC.append_TAC(p[3].TAC) else: p[0] = TreeNode('TopLevelDeclList', 0, 'INT', 0, [p[1]], p[1].TAC) return def p_TopLevelDecl(p): '''TopLevelDecl : Declaration | FunctionDecl ''' parsed.append(p.slice) p[0] = p[1] return def p_ImportDecl(p): '''ImportDecl : IMPORT LROUND ImportSpecList RROUND | IMPORT ImportSpec ''' parsed.append(p.slice) # TODO: Ignoring Imports for now return def p_ImportSpecList(p): '''ImportSpecList : ImportSpec SEMICOLON ImportSpecList | empty ''' parsed.append(p.slice) # TODO: Ignoring Imports for now return def p_ImportSpec(p): '''ImportSpec : DOT string_lit | IDENTIFIER string_lit | empty string_lit ''' parsed.append(p.slice) # TODO: Ignoring Imports for now return def p_Block(p): '''Block : LCURLY ScopeStart StatementList ScopeEnd RCURLY ''' parsed.append(p.slice) p[0] = p[3] p[0].data = p[2].data p[0].name = 'Block' return def p_ScopeStart(p): '''ScopeStart : empty ''' parsed.append(p.slice) symbol_table.add_scope(gen('scope')) p[0] = TreeNode('ScopeStart', symbol_table.current_scope, 'None') return def p_ScopeEnd(p): '''ScopeEnd : empty ''' parsed.append(p.slice) symbol_table.end_scope() return def p_StatementList(p): '''StatementList : Statement SEMICOLON StatementList | empty ''' parsed.append(p.slice) if len(p) == 4: p[0] = TreeNode('StatementList', 0, 'INT', 0, [p[1].data] + p[3].children, p[1].TAC) p[0].TAC.append_TAC(p[3].TAC) else: p[0] = TreeNode('StatementList', 0, 'INT') return def p_Statement(p): '''Statement : Declaration | SimpleStmt | ReturnStmt | Block | IfStmt | SwitchStmt | ForStmt | BreakStmt | ContinueStmt | GotoStmt | PrintIntStmt | PrintStrStmt ''' parsed.append(p.slice) p[0] = p[1] p[0].name = 'Statement' return def p_PrintIntStmt(p): '''PrintIntStmt : PRINTLN LROUND IDENTIFIER RROUND | PRINTLN LROUND int_lit RROUND ''' if hasattr(p[3], 'name') and p[3].name == 'int_lit': p[0] = p[3] # p[0].isLvalue = 0 else: p[0] = TreeNode('IDENTIFIER', p[3], 'INT', 1, []) p[0].TAC.add_line(['print_int', check_variable(p[0]), '', '']) p[0].name = 'PrintIntStmt' return def p_PrintStrStmt(p): '''PrintStrStmt : PRINTLN LROUND string_lit RROUND ''' p[0] = p[3] name = symbol_table.current_scope + '_' + gen('str_list') parametersNode = SymbolTableNode(p[3].data, p[3].input_type) newNode = SymbolTableNode(name, p[3].input_type, parameters = [parametersNode]) symbol_table.add_var(newNode) p[0].TAC.add_line(['print_str', name, '', '']) p[0].name = 'PrintStrStmt' return def p_Declaration(p): '''Declaration : ConstDecl | TypeDecl | VarDecl ''' parsed.append(p.slice) p[0] = p[1] p[0].name = 'Declaration' return def p_ConstDecl(p): '''ConstDecl : CONST LROUND ConstSpecList RROUND | CONST ConstSpec ''' parsed.append(p.slice) return def p_ConstSpecList(p): '''ConstSpecList : empty | ConstSpecList ConstSpec SEMICOLON ''' parsed.append(p.slice) return def p_ConstSpec(p): '''ConstSpec : IDENTIFIER | IdentifierList | IDENTIFIER EQ Expression | IdentifierList EQ ExpressionList | IDENTIFIER Type EQ Expression | IdentifierList Type EQ ExpressionList ''' parsed.append(p.slice) return def p_IdentifierList(p): '''IdentifierList : IDENTIFIER COMMA IdentifierBotList ''' parsed.append(p.slice) node = TreeNode('IDENTIFIER', p[1], 'INT', 1) p[0] = TreeNode('IdentifierList', 0, 'None', 0, [node] + p[3].children, p[3].TAC) return def p_IdentifierBotList(p): '''IdentifierBotList : IDENTIFIER COMMA IdentifierBotList | IDENTIFIER ''' parsed.append(p.slice) if len(p) == 2: node = TreeNode('IDENTIFIER', p[1], 'INT', 1) p[0] = TreeNode('IdentifierBotList', 0, 'None', 0, [node]) elif len(p) == 4: node = TreeNode('IDENTIFIER', p[1], 'INT', 1) p[0] = TreeNode('IdentifierBotList', 0, 'None', 0, [node] + p[3].children, p[3].TAC) return def p_ExpressionList(p): '''ExpressionList : Expression COMMA ExpressionBotList ''' parsed.append(p.slice) p[0] = TreeNode('ExpressionList', 0, 'INT', 0, [p[1]] + p[3].children, p[1].TAC) p[0].TAC.append_TAC(p[3].TAC) return def p_ExpressionBotList(p): '''ExpressionBotList : Expression COMMA ExpressionBotList | Expression ''' parsed.append(p.slice) if len(p) == 2: p[0] = TreeNode('ExpressionBotList', 0, 'INT', 0, [p[1]], p[1].TAC) elif len(p) == 4: p[0] = TreeNode('ExpressionBotList', 0, 'INT', 0, [p[1]] + p[3].children, p[1].TAC) p[0].TAC.append_TAC(p[3].TAC) return def p_TypeDecl(p): '''TypeDecl : TYPE TypeSpecTopList ''' parsed.append(p.slice) return def p_TypeSpecTopList(p): '''TypeSpecTopList : TypeSpec | LROUND TypeSpecList RROUND ''' parsed.append(p.slice) return def p_TypeSpecList(p): '''TypeSpecList : empty | TypeSpecList TypeSpec SEMICOLON ''' parsed.append(p.slice) return def p_TypeSpec(p): '''TypeSpec : AliasDecl | TypeDef ''' parsed.append(p.slice) return def p_AliasDecl(p): '''AliasDecl : IDENTIFIER EQ Type ''' parsed.append(p.slice) return def p_TypeDef(p): '''TypeDef : IDENTIFIER Type ''' parsed.append(p.slice) return def p_Type(p): '''Type : TypeLit | StandardTypes | LROUND Type RROUND ''' parsed.append(p.slice) if len(p) == 2: p[0] = p[1] else: p[0] = p[2] p[0].name = 'Type' return def p_StandardTypes(p): '''StandardTypes : PREDEFINED_TYPES ''' parsed.append(p.slice) p[0] = TreeNode('StandardTypes', p[1], 'NONE') return def p_TypeLit(p): '''TypeLit : ArrayType | StructType | FunctionType | PointerType ''' parsed.append(p.slice) p[0] = p[1] p[0].name = 'TypeLit' return def p_PointerType(p): '''PointerType : STAR Type ''' parsed.append(p.slice) return def p_ArrayType(p): '''ArrayType : LSQUARE ArrayLength RSQUARE Type ''' parsed.append(p.slice) p[0] = TreeNode('ArrayType', p[2].data, p[4].data) return def p_ArrayLength(p): '''ArrayLength : Expression ''' parsed.append(p.slice) p[0] = p[1] p[0].name = 'ArrayLength' return def p_StructType(p): '''StructType : STRUCT LCURLY FieldDeclList RCURLY ''' parsed.append(p.slice) return def p_FieldDeclList(p): '''FieldDeclList : empty | FieldDeclList FieldDecl SEMICOLON ''' parsed.append(p.slice) return def p_FieldDecl(p): '''FieldDecl : IdentifierList Type TagTop | IDENTIFIER Type TagTop ''' parsed.append(p.slice) return def p_TagTop(p): '''TagTop : empty | Tag ''' parsed.append(p.slice) return def p_Tag(p): '''Tag : string_lit ''' parsed.append(p.slice) return def p_FunctionType(p): '''FunctionType : FUNC Signature ''' parsed.append(p.slice) return def p_Signature(p): '''Signature : Parameters | Parameters Result ''' parsed.append(p.slice) p[0] = p[1] p[0].name = 'Signature' s = 'scope_' + str(len(generated['scope'])) symbol_table.new_scope(s) for child in p[1].children: symbol_table.add_identifier(child, s) newNode = SymbolTableNode(s + '_' + child.data, child.input_type) symbol_table.add_var(newNode, s) # symbol_table.print_symbol_table() if len(p) == 2: p[0].input_type = TreeNode('Result', 0, 'None') else: p[0].input_type = p[2] return def p_Result(p): '''Result : Parameters | Type ''' parsed.append(p.slice) if p[1].name == 'Type': p[0] = TreeNode('Result', 1, 'None', 0, [p[1]]) else: p[0] = p[1] p[0].name = 'Result' return def p_Parameters(p): '''Parameters : LROUND RROUND | LROUND ParameterList RROUND ''' parsed.append(p.slice) if len(p) == 3: p[0] = TreeNode('Parameters', 0, 'None') else: p[0] = p[2] p[0].name = 'Parameters' return def p_ParameterList(p): '''ParameterList : ParameterDecl | ParameterList COMMA ParameterDecl ''' parsed.append(p.slice) if len(p) == 2: p[0] = p[1] p[0].name = 'ParameterList' elif len(p) == 4: p[0] = TreeNode('ParameterList', p[1].data + p[3].data, 'None', 0, p[1].children + p[3].children, p[1].TAC) p[0].TAC.append_TAC(p[3].TAC) return def p_ParameterDecl(p): '''ParameterDecl : IdentifierList Type | IDENTIFIER Type | Type ''' parsed.append(p.slice) p[0] = TreeNode('ParameterDecl', 0, 'None') if len(p) == 3: if hasattr(p[1], 'name') and p[1].name == 'IdentifierList': for node in p[1].children: p[0].data += 1 node.input_type = p[2].data p[0].children += [node] else: node = TreeNode('IDENTIFIER', p[1], p[2].data, 1) p[0].data += 1 p[0].children += [node] else: p[0].data += 1 p[0].children += [p[1]] return def p_VarDecl(p): '''VarDecl : VAR VarSpecTopList ''' parsed.append(p.slice) p[0] = p[2] p[0].name = 'VarDecl' return def p_VarSpecTopList(p): '''VarSpecTopList : VarSpec | LROUND VarSpecList RROUND ''' parsed.append(p.slice) if len(p) == 2: p[0] = p[1] else: p[0] = p[2] p[0].name = 'VarSpecTopList' return def p_VarSpecList(p): '''VarSpecList : empty | VarSpecList VarSpec SEMICOLON ''' return def p_VarSpec(p): '''VarSpec : IDENTIFIER Type | IDENTIFIER EQ Expression | IDENTIFIER Type EQ Expression | IdentifierList Type | IdentifierList EQ ExpressionList | IdentifierList Type EQ ExpressionList ''' # Insert into symbol table p[0] = TreeNode('VarSpec', 0, 'NONE') if hasattr(p[1], 'name') and p[1].name == 'IdentifierList': zero_val = TreeNode('decimal_lit', 0, 'INT') # l1 = len(p[1].children) # if len(p) == 3: # expr_list = TreeNode('Expr_List', 0, 'NONE', 0, [zero_val] * l1) # elif len(p) == 4: # expr_list = p[3] # elif len(p) == 5: # expr_list = p[4] # l2 = len(expr_list.children) # p[0].TAC.append_TAC(expr_list.TAC) # p[0].TAC.append_TAC(p[1].TAC) # if l1 == l2: # for i in range(l1): # p[0].TAC.add_line(['=', p[1].children[i], expr_list.children[i].data, '']) # else: # print_error("Variable Declaration mismatch: " + str(l1) + " identifier(s) but " + str(l2) + " value(s)") else: p[1] = TreeNode('IDENTIFIER',p[1],'INT',1) if p[2].input_type != 'NONE': # array case # p[2].print_node() if symbol_table.add_identifier(p[1], size = p[2].data) == False: print_error("Unable to add to SymbolTable") return name = symbol_table.search_identifier(p[1].data) newNode = SymbolTableNode(name, p[1].input_type,size = p[2].data) symbol_table.add_var(newNode) p[0] = TreeNode('VarSpec',p[1].data,'INT') # expr = TreeNode('Expr', 0, 'NONE') # if len(p) == 4: # expr = p[3] # p[0].TAC.append_TAC(p[3].TAC) # p[0].TAC.add_line(['=', check_variable(p[1]), check_variable(expr), '']) # elif len(p) == 5: # expr = p[4] # p[0].TAC.append_TAC(p[4].TAC) # p[0].TAC.add_line(['=', check_variable(p[1]), check_variable(expr), '']) return def p_FunctionDecl(p): '''FunctionDecl : FUNC FunctionName Signature | FUNC FunctionName Signature FunctionBody ''' parsed.append(p.slice) # symbol_table.print_symbol_table() p[0] = TreeNode('FunctionDecl', 0, 'INT') # print symbol_table.current_scope # p[4].TAC.print_code() symbol_table.add_function(p[2].data, p[3].input_type, p[3].children) if len(p) == 5: noOfParams = 0 for f in symbol_table.symbol_table[symbol_table.current_scope]['functions']: if f.name == p[2].data: noOfParams = len(f.parameters) p[0].TAC.add_line(['func', check_variable(p[2]), str(noOfParams), '']) for child in reversed(p[3].children): p[0].TAC.add_line(['getparam', p[4].data + '_' + child.data, '', '']) p[0].TAC.add_line(['stack_push', '', '', '']) p[0].TAC.append_TAC(p[4].TAC) return def p_FunctionName(p): '''FunctionName : IDENTIFIER ''' parsed.append(p.slice) p[0] = TreeNode('FunctionName', p[1], 'INT', 1) return def p_FunctionBody(p): '''FunctionBody : Block ''' parsed.append(p.slice) p[0] = p[1] p[0].name = 'FunctionBody' return def p_SimpleStmt(p): '''SimpleStmt : Expression | Assignment | ShortVarDecl | IncDecStmt ''' parsed.append(p.slice) p[0] = p[1] p[0].name = 'SimpleStmt' return def p_IncDecStmt(p): '''IncDecStmt : Expression PLUS_PLUS | Expression MINUS_MINUS ''' parsed.append(p.slice) one_val = TreeNode('IncDecStmt', '1', 'INT') p[0] = p[1] if p[1].isLvalue == 1: if p[2] == '++': p[0].TAC.add_line(['+', check_variable(p[1]), check_variable(p[1]), one_val.data]) else: p[0].TAC.add_line(['-', check_variable(p[1]), check_variable(p[1]), one_val.data]) else: print_error("Lvalue required") p[0].name = 'IncDecStmt' return def p_ShortVarDecl(p): '''ShortVarDecl : ExpressionList ASSIGN_OP ExpressionList | Expression ASSIGN_OP Expression ''' parsed.append(p.slice) # TODO: Add in symbol table p[0] = TreeNode('ShortVarDecl', 0, 'INT') if p[1].name == 'ExpressionList': l1 = len(p[1].children) l2 = len(p[3].children) p[0].TAC.append_TAC(p[3].TAC) p[0].TAC.append_TAC(p[1].TAC) if l1 == l2: for i in range(l1): if p[1].children[i].isLvalue == 0: print_error("Lvalue required") return else: if symbol_table.add_identifier(p[1].children[i]) == False: print_error("Unable to add to SymbolTable") return p[0].TAC.add_line([p[2], check_variable(p[1].children[i]), check_variable(p[3].children[i]), '']) else: print_error("Variable Declaration mismatch: " + str(l1) + " identifier(s) but " + str(l2) + " value(s)") elif p[1].name == 'Expression': if p[1].isLvalue == 0: print_error("Lvalue required") return else: if symbol_table.add_identifier(p[1]) == False: print_error("Unable to add to SymbolTable") return p[0].TAC.append_TAC(p[3].TAC) p[0].TAC.append_TAC(p[1].TAC) p[0].TAC.add_line([p[2], check_variable(p[1]), check_variable(p[3]), '']) return def p_Assignment(p): '''Assignment : ExpressionList assign_op ExpressionList | Expression assign_op Expression ''' parsed.append(p.slice) p[0] = TreeNode('Assignment', 0, 'INT') if p[1].name == 'ExpressionList': l1 = len(p[1].children) l2 = len(p[3].children) p[0].TAC.append_TAC(p[3].TAC) p[0].TAC.append_TAC(p[1].TAC) if l1 == l2: for i in range(l1): if p[1].children[i].isLvalue == 0: print_error("Lvalue required") return else: if symbol_table.search_identifier(p[1].children[i].data) == False and p[1].children[i].data not in generated['temp']: print_error("Variable " + p[1].children[i].data + " is undefined") return if p[3].children[i].isLvalue == 1 and symbol_table.search_identifier(p[3].children[i].data) == False and p[3].children[i].data not in generated['temp']: print_error("Variable " + p[3].children[i].data + " is undefined") return p[0].TAC.add_line([p[2].data, check_variable(p[1].children[i]), check_variable(p[3].children[i]), '']) else: print_error("Variable Declaration mismatch: " + str(l1) + " identifier(s) but " + str(l2) + " value(s)") elif p[1].name == 'Expression': if p[1].isLvalue == 0: print_error("Lvalue required") return else: if symbol_table.search_identifier(p[1].data) == False and p[1].data not in generated['temp']: print_error("Variable " + p[1].data + " is undefined") return if p[3].isLvalue == 1 and symbol_table.search_identifier(p[3].data) == False and p[3].data not in generated['temp']: print_error("Variable " + p[3].data + " is undefined") return # print symbol_table.current_scope p[0].TAC.append_TAC(p[3].TAC) p[0].TAC.append_TAC(p[1].TAC) p[0].TAC.add_line([p[2].data, check_variable(p[1]), check_variable(p[3]), '']) return def p_assign_op(p): '''assign_op : EQ | PLUS_EQ | MINUS_EQ | OR_EQ | CARET_EQ | STAR_EQ | DIVIDE_EQ | MODULO_EQ | LS_EQ | RS_EQ | AMP_EQ | AND_OR_EQ ''' parsed.append(p.slice) p[0] = TreeNode('assign_op', p[1], 'OPERATOR') return def p_IfStmt(p): '''IfStmt : IF Expression Block | IF Expression Block ELSE elseTail ''' parsed.append(p.slice) if len(p) == 4: l1 = gen('label') p[0] = TreeNode('IfStmt', 0, 'INT') p[0].TAC.append_TAC(p[2].TAC) p[0].TAC.add_line(['ifgotoeq', check_variable(p[2]), '0', l1]) p[0].TAC.append_TAC(p[3].TAC) p[0].TAC.add_line(['label', l1, '', '']) if len(p) == 6: l1 = gen('label') l2 = gen('label') p[0] = TreeNode('IfStmt', 0, 'INT') p[0].TAC.append_TAC(p[2].TAC) p[0].TAC.add_line(['ifgotoeq', check_variable(p[2]), '0', l1]) p[0].TAC.append_TAC(p[3].TAC) p[0].TAC.add_line(['goto', l2, '', '']) p[0].TAC.add_line(['label', l1, '', '']) p[0].TAC.append_TAC(p[5].TAC) p[0].TAC.add_line(['label', l2, '', '']) return def p_elseTail(p): '''elseTail : IfStmt | Block ''' parsed.append(p.slice) p[0] = p[1] p[0].name = 'elseTail' return def p_SwitchStmt(p): '''SwitchStmt : ExprSwitchStmt ''' parsed.append(p.slice) p[0] = TreeNode('SwitchStmt', 0, 'INT', 0, [], p[1].TAC) return def p_ExprSwitchStmt(p): '''ExprSwitchStmt : SWITCH SimpleStmt SEMICOLON LCURLY ScopeStart ExprCaseClauseList ScopeEnd RCURLY | SWITCH SimpleStmt SEMICOLON Expression LCURLY ScopeStart ExprCaseClauseList ScopeEnd RCURLY | SWITCH LCURLY ScopeStart ExprCaseClauseList ScopeEnd RCURLY | SWITCH Expression LCURLY ScopeStart ExprCaseClauseList ScopeEnd RCURLY ''' parsed.append(p.slice) if len(p) == 8: l1 = gen('label') l2 = gen('label') p[0] = TreeNode('ExprSwitchStmt', 0, 'INT') p[0].TAC.append_TAC(p[2].TAC) t1 = TreeNode('IDENTIFIER', gen('temp'), 'INT', 1) p[0].TAC.add_line(['=', check_variable(t1) , check_variable(p[2]), '']) p[0].TAC.append_TAC(p[5].data) for i in range(len(p[5].children)): p[0].TAC.add_line(['ifgotoeq', check_variable(t1), p[5].children[i][0], p[5].children[i][1]]) p[0].TAC.add_line(['goto', l2, '', '']) for i in range(p[5].TAC.length()): if i in p[5].TAC.leaders[1:]: p[0].TAC.add_line(['goto', l2, '', '']) p[0].TAC.add_line(p[5].TAC.code[i]) p[0].TAC.add_line(['label', l2, '', '']) return def p_ExprCaseClauseList(p): '''ExprCaseClauseList : empty | ExprCaseClauseList ExprCaseClause ''' parsed.append(p.slice) TAC1 = ThreeAddressCode() TAC2 = ThreeAddressCode() if len(p) == 3: TAC1 = p[1].data TAC2 = p[2].data p[0] = TreeNode('ExprCaseClauseList', TAC1, 'INT', 0, p[1].children + p[2].children, p[1].TAC) p[0].TAC.add_leader(p[0].TAC.length()) p[0].TAC.append_TAC(p[2].TAC) p[0].data.append_TAC(TAC2) else: p[0] = TreeNode('ExprCaseClauseList', TAC1, 'INT') return def p_ExprCaseClause(p): '''ExprCaseClause : ExprSwitchCase COLON StatementList ''' parsed.append(p.slice) l1 = gen('label') p[0] = TreeNode('ExprCaseClause', 0, 'INT') # p[0].TAC.append_TAC(p[1].TAC) p[0].TAC.add_line(['label', l1, '', '']) # p[0].TAC.add_line(['ifgotoneq', p[1].children, p[1].children, l1]) p[0].TAC.append_TAC(p[3].TAC) p[0].children = [[p[1].data,l1]] p[0].data = p[1].TAC return def p_ExprSwitchCase(p): '''ExprSwitchCase : CASE ExpressionList | DEFAULT | CASE Expression ''' parsed.append(p.slice) p[0] = TreeNode('ExprSwitchCase', 0, 'INT') if len(p) == 3: p[0].data = p[2].data p[0].TAC = p[2].TAC return def p_ForStmt(p): '''ForStmt : FOR Expression Block | FOR Block ''' parsed.append(p.slice) p[0] = TreeNode('ForStmt', 0, 'INT') if len(p) == 4: l1 = gen('label') l2 = gen('label') p[0].TAC.add_line(['label', l1, '', '']) p[0].TAC.append_TAC(p[2].TAC) p[0].TAC.add_line(['ifgotoeq',check_variable(p[2]), '0', l2]) p[0].TAC.append_TAC(p[3].TAC) p[0].TAC.add_line(['goto', l1, '', '']) p[0].TAC.add_line(['label', l2, '', '']) if len(p) == 3: l1 = gen('label') # l2 = gen('label') p[0].TAC.add_line(['label', l1, '', '']) p[0].TAC.append_TAC(p[2].TAC) p[0].TAC.add_line(['goto', l1, '', '']) # p[0].TAC.add_line([l2]) return def p_ReturnStmt(p): '''ReturnStmt : RETURN | RETURN Expression | RETURN ExpressionList ''' parsed.append(p.slice) if len(p) == 2: p[0] = TreeNode('ReturnStmt', 0, 'None') p[0].TAC.add_line(['return', '', '', '']) if len(p) == 3: if p[2].name == 'Expression': p[0] = p[2] p[0].name = 'ReturnStmt' p[0].TAC.add_line(['return', check_variable(p[2]), '', '']) return def p_BreakStmt(p): '''BreakStmt : BREAK IDENTIFIER ''' parsed.append(p.slice) return def p_ContinueStmt(p): '''ContinueStmt : CONTINUE IDENTIFIER ''' parsed.append(p.slice) return def p_GotoStmt(p): '''GotoStmt : GOTO IDENTIFIER ''' parsed.append(p.slice) return def p_Expression(p): '''Expression : UnaryExpr | Expression OR_OR Expression | Expression AMP_AMP Expression | Expression EQ_EQ Expression | Expression NOT_EQ Expression | Expression LT Expression | Expression LT_EQ Expression | Expression GT Expression | Expression GT_EQ Expression | Expression PLUS Expression | Expression MINUS Expression | Expression OR Expression | Expression CARET Expression | Expression STAR Expression | Expression DIVIDE Expression | Expression MODULO Expression | Expression LS Expression | Expression RS Expression | Expression AMP Expression | Expression AND_OR Expression ''' parsed.append(p.slice) if len(p) == 2: p[0] = p[1] elif len(p) == 4: p[0] = TreeNode('IDENTIFIER', gen('temp'), 'INT', 1, [], p[1].TAC) p[0].TAC.append_TAC(p[3].TAC) p[0].TAC.add_line([p[2],check_variable(p[0]), check_variable(p[1]), check_variable(p[3])]) p[0].name = 'Expression' return def p_UnaryExpr(p): '''UnaryExpr : PrimaryExpr | unary_op UnaryExpr ''' parsed.append(p.slice) if len(p) == 2: p[0] = p[1] elif len(p) == 3: p[0] = TreeNode('IDENTIFIER', gen('temp'), 'INT', 1) p[0].TAC.add_line([check_variable(p[1]), check_variable(p[0]), check_variable(p[2]), '']) p[0].name = 'UnaryExpr' return def p_unary_op(p): '''unary_op : PLUS | MINUS | NOT | CARET | STAR | AMP | LT_MINUS ''' parsed.append(p.slice) p[0] = TreeNode('unary_op', p[1], 'OPERATOR') return def p_PrimaryExpr(p): '''PrimaryExpr : Operand | IDENTIFIER | PrimaryExpr Selector | PrimaryExpr Index | PrimaryExpr Arguments ''' parsed.append(p.slice) if len(p) == 2: if p.slice[1].type == 'IDENTIFIER': p[0] = TreeNode('IDENTIFIER', p[1], 'INT', 1) elif p[1].name == 'Operand': p[0] = p[1] elif len(p) == 3: if p[2].name == 'Index': p[0] = TreeNode('IDENTIFIER', p[1].data, 'INT', 1, p[2].data) elif p[2].name == 'Arguments': p[0] = TreeNode('IDENTIFIER', gen('temp'), 'INT', 1) p[0].TAC.append_TAC(p[1].TAC) p[0].TAC.append_TAC(p[2].TAC) # p[1].print_node() func = check_variable(p[1]).split("_") scope, funcName = "_".join(func[:2]), "_".join(func[2:]) temp = 0 for f in symbol_table.symbol_table[scope]['functions']: if f.name == funcName: temp = len(f.parameters) # p[2].print_node() for child in p[2].children: p[0].TAC.add_line(['putparam', check_variable(child), '', '']) if temp != p[2].data: print_error('Function ' + funcName + ' requires ' + str(temp) + ' parameters but ' + str(p[2].data) + ' supplied') p[0].TAC.add_line(['call', check_variable(p[1]), str(p[2].data), '']) p[0].TAC.add_line(['return_value', check_variable(p[0]), '', '']) p[0].name = 'PrimaryExpr' return def p_Operand(p): '''Operand : Literal | LROUND Expression RROUND ''' parsed.append(p.slice) if len(p) == 2: p[0] = p[1] else: p[0] = p[2] p[0].name = 'Operand' return def p_Literal(p): '''Literal : BasicLit | FunctionLit ''' parsed.append(p.slice) p[0] = p[1] p[0].name = 'Literal' return def p_BasicLit(p): '''BasicLit : int_lit | float_lit | string_lit | rune_lit ''' parsed.append(p.slice) p[0] = p[1] p[0].name = 'BasicLit' return def p_int_lit(p): '''int_lit : decimal_lit | octal_lit | hex_lit ''' parsed.append(p.slice) p[0] = p[1] p[0].name = 'int_lit' return def p_decimal_lit(p): '''decimal_lit : DECIMAL_LIT ''' parsed.append(p.slice) p[0] = TreeNode('decimal_lit', p[1], 'INT') return def p_octal_lit(p): '''octal_lit : OCTAL_LIT ''' parsed.append(p.slice) p[0] = TreeNode('octal_lit', p[1], 'OCT') return def p_hex_lit(p): '''hex_lit : HEX_LIT ''' parsed.append(p.slice) p[0] = TreeNode('hex_lit', p[1], 'HEX') return def p_float_lit(p): '''float_lit : FLOAT_LIT ''' parsed.append(p.slice) p[0] = TreeNode('float_lit', p[1], 'FLOAT') return def p_FunctionLit(p): '''FunctionLit : FUNC Signature FunctionBody ''' parsed.append(p.slice) # Anonymous Function # Not implemented yet return def p_Selector(p): '''Selector : DOT IDENTIFIER ''' parsed.append(p.slice) return def p_Index(p): '''Index : LSQUARE Expression RSQUARE ''' parsed.append(p.slice) p[0] = p[2] p[0].name = 'Index' return def p_Arguments(p): '''Arguments : LROUND RROUND | LROUND ExpressionList RROUND | LROUND Expression RROUND | LROUND Type RROUND | LROUND Type COMMA ExpressionList RROUND | LROUND Type COMMA Expression RROUND ''' # print p.slice parsed.append(p.slice) if len(p) == 3: p[0] = TreeNode('Arguments', 0, 'None') if len(p) == 4: if p[2].name == 'Expression': p[0] = TreeNode('Arguments', 1, 'None', 0, [p[2]], p[2].TAC) if p[2].name == 'ExpressionList': p[0] = p[2] p[0].name = 'Arguments' p[0].data = len(p[2].children) return def p_string_lit(p): '''string_lit : STRING_LIT ''' parsed.append(p.slice) p[0] = TreeNode('string_lit', p[1], 'STRING') return def p_rune_lit(p): '''rune_lit : RUNE_LIT ''' parsed.append(p.slice) p[0] = TreeNode('rune_lit', p[1], 'RUNE') return def p_empty(p): 'empty :' pass def p_error(p): print p if p == None: print str(sys.argv[1]) + " :: You missed something at the end" else: print str(sys.argv[1]) + " :: Syntax error in line no " + str(p.lineno) # Standard Logger logging.basicConfig( level = logging.DEBUG, filename = "parselog.txt", filemode = "w", format = "%(filename)10s:%(lineno)4d:%(message)s" ) log = logging.getLogger() yacc.yacc(debug=True, debuglog=log) input_file = sys.argv[1] import os if os.path.isfile(input_file) is False: print('Input file ' + input_file + ' does not exist') sys.exit(1) input_code = open(input_file, 'r').read() if input_code[len(input_code)-1] != '\n': input_code += '\n' yacc.parse(input_code, debug=log, tracking=True)
29.050778
172
0.5361
1
2.1576
[ -0.017337730154395103, 0.0745822861790657, -0.009443184360861778, 0.014209367334842682, 0.006123995408415794, 0.01579360105097294, 0.0018255985341966152, -0.013264666311442852, 0.004354623146355152, 0.021718617528676987, 0.03440295159816742, 0.001969364006072283, -0.048529185354709625, -0.024765243753790855, -0.01929946057498455, 0.017713453620672226, 0.12470381706953049, -0.003331478452309966, 0.008569128811359406, 0.05408434569835663, -0.013442321680486202, 0.0023768716491758823, -0.011770197190344334, 0.017153829336166382, -0.015132751315832138, -0.02795581705868244, -0.0023272244725376368, -0.007930129766464233, -0.004778179805725813, 0.001384712173603475, 0.009092089720070362, -0.043564993888139725, -0.02513362094759941, 0.010179263539612293, 0.00799825694411993, 0.0648532509803772, 0.018122339621186256, -0.008275716565549374, 0.039682477712631226, -0.015387491323053837, -0.006458648014813662, 0.007164362818002701, -0.029932094737887383, 0.0010175820207223296, 0.015066261403262615, -0.018538501113653183, -0.03304370120167732, -0.021915556862950325, -0.05942356958985329, -0.0010193733032792807, -0.0325828492641449, 0.021264461800456047, 0.013989935629069805, -0.014722544699907303, 0.03536653891205788, -0.008040131069719791, -0.01688460446894169, -0.028552882373332977, -0.013255078345537186, 0.010867133736610413, -0.03752927854657173, 0.016693398356437683, 0.012082776054739952, -0.00594891794025898, -0.04134635627269745, -0.015491140075027943, -0.0021076546981930733, -0.0103618698194623, -0.0006656135665252805, -0.011386062018573284, -0.021707506850361824, -0.01985975354909897, 0.023592976853251457, 0.06698127835988998, -0.007944165728986263, 0.0020385102834552526, 0.020009910687804222, -0.05823206901550293, -0.004611825570464134, -0.013333430513739586, 0.002226155251264572, 0.015732690691947937, -0.012655220925807953, -0.0379052497446537, 0.019198205322027206, 0.03701199218630791, -0.018920598551630974, -0.02415192499756813, 0.025350697338581085, 0.01823575608432293, -0.04322962090373039, 0.02059178613126278, -0.04189246892929077, -0.031483229249715805, 0.023961855098605156, -0.04955209791660309, 0.026681648567318916, -0.0038508614525198936, 0.03201109543442726, 0.0030761039815843105, 0.054094940423965454, 0.033452700823545456, 0.07351807504892349, 0.003094484331086278, -0.0038290536031126976, -0.02214401587843895, -0.013494005426764488, -0.0007714790408499539, 0.027585726231336594, 0.011486726813018322, -0.03539888933300972, -0.009593840688467026, 0.0058812485076487064, -0.04581698030233383, -0.03696488216519356, 0.019385099411010742, -0.004480907693505287, -0.00748088164255023, 0.006630878895521164, 0.08007920533418655, -0.018489964306354523, 0.010533162392675877, -0.02064032107591629, 0.033821359276771545, -0.022652439773082733, 0.01682637259364128, -0.026660654693841934, -0.0030739419162273407, 0.002964014420285821, -0.014384151436388493, 0.008463255129754543, 0.03120899759232998, 0.018645482137799263, 0.046556804329156876, 0.00074385991320014, 0.056002333760261536, -0.009131847880780697, -0.024632463231682777, -0.024266883730888367, -0.029049454256892204, 0.006994019728153944, -0.016353003680706024, 0.023023530840873718, 0.0015682774828746915, 0.012122372165322304, 0.0011797747574746609, -0.000055420045100618154, -0.02402363158762455, -0.03038632869720459, -0.04056105762720108, 0.0177591685205698, 0.017355460673570633, 0.01833728700876236, 0.013872005045413971, -0.034450702369213104, -0.010121042840182781, 0.01787571609020233, -0.06132535636425018, -0.011006350629031658, 0.02835802175104618, 0.01407297421246767, 0.008477031253278255, 0.006764168385416269, -0.003995588049292564, 0.016993405297398567, -0.007733898237347603, -0.029280297458171844, -0.008535117842257023, 0.00006786421727156267, 0.018750706687569618, -0.004889302887022495, 0.019295621663331985, -0.022783268243074417, 0.01463879644870758, -0.06057782471179962, -0.024036550894379616, -0.005230023991316557, -0.03317826986312866, -0.01689120940864086, -0.01588609255850315, 0.029194094240665436, -0.03700341284275055, 0.03432764485478401, -0.01859191246330738, 0.017065109685063362, 0.00285408110357821, -0.043181344866752625, -0.06871461868286133, -0.022944020107388496, 0.005615673493593931, 0.010871849954128265, 0.047217659652233124, 0.00022291557979770005, -0.01718917116522789, 0.014658113941550255, -0.01295729074627161, -0.0076115005649626255, 0.009076469577848911, -0.008214297704398632, 0.011614212766289711, 0.014127605594694614, -0.019096653908491135, 0.005494186654686928, 0.009560477919876575, -0.0161920003592968, 0.01560431532561779, -0.6924371123313904, 0.023485546931624413, 0.005168567877262831, -0.0024921030271798372, -0.001696940278634429, 0.011359220370650291, -0.020285699516534805, 0.026159344241023064, -0.019857224076986313, -0.007918823510408401, -0.005103264469653368, -0.026829063892364502, -0.002746129408478737, 0.00095476268325001, -0.010381662286818027, 0.03331898897886276, -0.00004366495704744011, -0.016083169728517532, 0.0014520436525344849, 0.016200346872210503, 0.009912148118019104, -0.020087940618395805, -0.010853443294763565, 0.01063890103250742, -0.00498169707134366, -0.032703518867492676, 0.0041277045384049416, -0.0073787677101790905, -0.016879811882972717, -0.0005467308801598847, -0.056046389043331146, 0.048526015132665634, -0.028214238584041595, 0.00666846614331007, 0.009782496839761734, 0.023892492055892944, 0.013287902809679508, -0.037122637033462524, 0.0045517729595303535, -0.0010341682936996222, 0.0117481155321002, -0.02156110666692257, 0.0139448381960392, -0.0710252895951271, 0.004528179299086332, -0.0284026637673378, 0.0027223608922213316, 0.01335821021348238, -0.052477385848760605, 0.00935482420027256, -0.036677028983831406, -0.031461864709854126, 0.025748778134584427, -0.04292638227343559, 0.006345032248646021, 0.004392232745885849, -0.008233980275690556, 0.0185780581086874, -0.009054923430085182, 0.006931308191269636, -0.009419512003660202, -0.016941899433732033, -0.022501951083540916, -0.011343268677592278, -0.04526972398161888, 0.0008510185871273279, 0.003681015223264694, -0.02891377918422222, 0.03489367663860321, 0.02782185561954975, -0.01706404983997345, 0.006643257569521666, -0.03922325745224953, 0.004934262949973345, 0.014819265343248844, -0.007283808663487434, -0.013741766102612019, -0.014949334785342216, -0.03500181809067726, 0.014972418546676636, 0.005413314327597618, -0.011391266249120235, -0.01817810907959938, 0.008109518326818943, -0.03106015920639038, -0.01140385027974844, 0.0267946794629097, 0.005753215868026018, 0.007959654554724693, -0.009907364845275879, 0.042839787900447845, 0.012779722921550274, 0.011303218081593513, 0.009040828794240952, -0.00044316024286672473, -0.004922539461404085, 0.060141440480947495, 0.04503631219267845, 0.001245969790033996, 0.08466194570064545, -0.00804913230240345, 0.011997303925454617, 0.010298173874616623, 0.019269289448857307, 0.023311085999011993, -0.03495657071471214, -0.006388026289641857, -0.005441558547317982, 0.002095275092869997, -0.023179510608315468, 0.012099514715373516, 0.019000539556145668, -0.014963098801672459, -0.03541244566440582, -0.0009243624517694116, -0.002267256146296859, -0.018471283838152885, 0.006214585155248642, 0.005163408815860748, 0.004977540113031864, 0.017632482573390007, -0.012629774399101734, 0.015273427590727806, 0.016171233728528023, -0.00019622388936113566, 0.00042299344204366207, -0.010773953050374985, 0.020646540448069572, -0.0075398776680231094, 0.02168806456029415, -0.01931740902364254, -0.013932105153799057, 0.0031982818618416786, -0.029190735891461372, -0.018733283504843712, 0.04652522876858711, 0.014527741819620132, -0.057043347507715225, -0.002027921611443162, 0.02196197211742401, -0.04072151333093643, 0.0021583735942840576, -0.014738816767930984, -0.023691099137067795, 0.001404977054335177, 0.021396417170763016, 0.018063869327306747, -0.010666993446648121, -0.06093986704945564, 0.03314761817455292, 0.001167377457022667, 0.033576689660549164, -0.003953567706048489, -0.025800548493862152, 0.03520374372601509, -0.010447289794683456, -0.01423629280179739, -0.014992818236351013, 0.015367904677987099, -0.0005943210562691092, 0.015156750567257404, -0.054883476346731186, 0.03538281098008156, 0.014424286782741547, 0.0007276103715412319, 0.018525149673223495, -0.006360457744449377, 0.000917243305593729, -0.000579610641580075, 0.031474653631448746, 0.04149884730577469, -0.017231661826372147, 0.009667186997830868, -0.019107146188616753, 0.0168471522629261, 0.06141671538352966, -0.022753747180104256, -0.037547215819358826, -0.025090927258133888, -0.0015969043597579002, -0.03223395720124245, -0.0018041359726339579, -0.016749940812587738, -0.04352908954024315, 0.013662773184478283, 0.021253105252981186, -0.0316782221198082, -0.014939343556761742, -0.011962704360485077, -0.019592057913541794, -0.01849515363574028, 0.04525109380483627, -0.022591607645154, 0.021366629749536514, 0.00041142944246530533, -0.017302386462688446, 0.0077025676146149635, -0.02730816975235939, -0.005656048655509949, -0.021105501800775528, -0.03779267147183418, 0.018459897488355637, -0.0008317079045809805, -0.012962047010660172, 0.010177010670304298, 0.02199895679950714, 0.005533947609364986, 0.03160376846790314, -0.014163285493850708, 0.014354312792420387, -0.0218222513794899, -0.003356822533532977, -0.014456934295594692, 0.020657449960708618, 0.012450151145458221, 0.015048353001475334, -0.03901531919836998, 0.004927016329020262, -0.013532308861613274, -0.0056081246584653854, 0.006597221828997135, -0.04435058310627937, 0.008234287612140179, 0.00748003413900733, -0.012567450292408466, 0.02146737277507782, -0.018446946516633034, 0.045767661184072495, -0.0370870865881443, -0.031523775309324265, 0.016866836696863174, 0.04473056271672249, -0.00867064855992794, -0.008090567775070667, 0.007718480657786131, 0.022192392498254776, 0.017973117530345917, 0.0063860611990094185, 0.012136095203459263, -0.050301067531108856, 0.02384987287223339, 0.009532548487186432, -0.026982204988598824, -0.007797433529049158, -0.013882572762668133, 0.011408532969653606, -0.0022683115676045418, -0.005314440466463566, -0.021437646821141243, -0.017958661541342735, 0.02056088298559189, -0.055424366146326065, 0.023074951022863388, 0.03529830649495125, 0.024165978655219078, -0.00929680373519659, -0.005970855243504047, 0.013184734620153904, 0.008717826567590237, 0.007820934057235718, 0.030693503096699715, 0.0396256297826767, 0.019628876820206642, -0.04355836287140846, -0.006909546907991171, 0.015034849755465984, 0.015304177068173885, 0.0025039848405867815, 0.008508668281137943, -0.029438186436891556, 0.005527352914214134, 0.023745905607938766, -0.030120665207505226, -0.036011453717947006, 0.03389914706349373, 0.02544552832841873, 0.026817020028829575, -0.00028188066789880395, -0.015760812908411026, 0.04568168520927429, -0.012930791825056076, 0.036440081894397736, 0.05882735550403595, -0.013077972456812859, -0.000025013172489707358, -0.008853244595229626, 0.0018092119134962559, -0.015620150603353977, -0.045296091586351395, -0.012462242506444454, -0.0021855738013982773, -0.015540073625743389, -0.0018387767486274242, 0.03890036791563034, 0.0077992151491343975, -0.04549093544483185, -0.018130917102098465, -0.011251695454120636, 0.013506677933037281, -0.02132912166416645, 0.0486082062125206, -0.03607304394245148, -0.002060001017525792, 0.017253031954169273, -0.018881618976593018, 0.005275027826428413, -0.0001633225183468312, -0.021003609523177147, 0.03360307961702347, 0.006803616881370544, 0.002389487810432911, 0.029163209721446037, 0.029656609520316124, 0.027406619861721992, 0.02211887016892433, -0.011957628652453423, 0.026574784889817238, 0.0020438837818801403, 0.012599274516105652, 0.0032102016266435385, -0.013873158022761345, 0.03794237598776817, -0.0040212227031588554, 0.005402387585490942, 0.02980720065534115, 0.0060492162592709064, -0.025678958743810654, 0.00547814043238759, -0.008563593961298466, 0.07167965918779373, -0.04171009734272957, 0.031183581799268723, -0.019947875291109085, 0.009589300490915775, 0.04576743766665459, 0.026322275400161743, 0.011837378144264221, 0.03869268298149109, 0.01070609875023365, 0.02524147741496563, -0.0266271959990263, 0.016502905637025833, 0.00017730900435708463, 0.015840379521250725, 0.0026720103342086077, 0.01338065043091774, -0.025002319365739822, 0.056629929691553116, 0.006944917142391205, -0.00596928084269166, 0.020002316683530807, -0.00997669156640768, -0.0505228154361248, -0.026170216500759125, -0.008864699862897396, -0.013057960197329521, 0.03294965624809265, -0.03807344660162926, -0.020318031311035156, 0.033210624009370804, -0.010287643410265446, -0.0037854453548789024, -0.03698194399476051, -0.022481579333543777, 0.03436980023980141, 0.010160577483475208, 0.018277715891599655, -0.03656753525137901, -0.02058360166847706, -0.007921723648905754, 0.018511220812797546, -0.005339483730494976, -0.01346079632639885, 0.018048031255602837, 0.018406840041279793, 0.034691788256168365, 0.013752972707152367, 0.00963844545185566, -0.01907913014292717, -0.06343641132116318, -0.038117650896310806, -0.040564656257629395, 0.04805777221918106, -0.04134564846754074, -0.01879468932747841, 0.04111064597964287, 0.004420756362378597, 0.0008249787497334182, -0.02927510254085064, -0.05974579229950905, 0.01723179966211319, -0.029114028438925743, 0.0063023315742611885, 0.010565211065113544, -0.030194483697414398, 0.016918987035751343, -0.014652729034423828, -0.017356054857373238, 0.010938077233731747, 0.012167436070740223, 0.0009808519389480352, -0.010807405225932598, -0.016226522624492645, -0.017882609739899635, 0.07543638348579407, -0.02528339996933937, -0.00736422510817647, 0.0012705016415566206, 0.02837510220706463, 0.004153192508965731, 0.030554531142115593, -0.008132034912705421, 0.005192561540752649, -0.029262224212288857, 0.0319647490978241, 0.019059089943766594, -0.05541718006134033, -0.049476418644189835, 0.03966366499662399, -0.004028140101581812, 0.02355262264609337, 0.06115182116627693, -0.0014202455058693886, -0.014100652188062668, 0.00831981748342514, -0.05282009392976761, 0.056342676281929016, -0.016691146418452263, 0.01971253752708435, 0.017692893743515015, 0.02994357980787754, -0.003913514781743288, -0.02158980444073677, -0.0024880729615688324, -0.000021160265532671474, 0.001072216546162963, 0.01727483980357647, -0.021306199952960014, -0.014789792709052563, 0.031463172286748886, -0.01251673512160778, 0.015461746603250504, -0.010125983506441116, 0.03793314844369888, 0.016977906227111816, -0.09229724109172821, -0.037728890776634216, 0.012589809484779835, -0.0001882392243715003, -0.04002701863646507, -0.013292795047163963, -0.0034283767454326153, 0.03185147047042847, 0.012066598981618881, 0.009018734097480774, -0.0064765410497784615, -0.010480483993887901, 0.011144662275910378, 0.05094801262021065, -0.004280382767319679, -0.03255926072597504, 0.0023630019277334213, -0.03560375049710274, 0.027870630845427513, -0.03765102103352547, 0.03322681039571762, 0.008144186809659004, 0.017032330855727196, 0.0014253651024773717, -0.006223171483725309, -0.03770168498158455, 0.013052771799266338, 0.01237235777080059, 0.047286856919527054, -0.029621193185448647, 0.010398603044450283, -0.01383752841502428, 0.013207821175456047, 0.043271198868751526, 0.0013079991331323981, -0.020937029272317886, 0.010389999486505985, 0.03269638493657112, 0.0040746042504906654, 0.05243141949176788, -0.02044052630662918, 0.01775306649506092, -0.04181601479649544, -0.017708830535411835, 0.014279598370194435, -0.00401912909001112, -0.0017303446074947715, 0.026158323511481285, -0.013003169558942318, -0.0002611071104183793, -0.037983719259500504, 0.022939497604966164, 0.019526677206158638, 0.03945321589708328, -0.012307551689445972, 0.014586293138563633, -0.04892554506659508, -0.0028124158270657063, -0.06505490094423294, 0.022117681801319122, 0.034329988062381744, 0.026942765340209007, 0.05650150775909424, 0.006864467635750771, -0.020655766129493713, -0.0526694729924202, -0.008396154269576073, -0.0003469550865702331, 0.03161751106381416, 0.010562705807387829, 0.04492749646306038, 0.021377721801400185, 0.06091836839914322, 0.030493300408124924, 0.002812286838889122, 0.007905461825430393, -0.0025625198613852262, -0.011276903562247753, -0.019527442753314972, -0.014277057722210884, -0.022399751469492912, -0.01415069680660963, -0.010583816096186638, -0.012273388914763927, -0.07107287645339966, 0.009330417029559612, -0.032523561269044876, 0.0011954073561355472, 0.008916000835597515, 0.0004829024546779692, -0.059521157294511795, 0.020315568894147873, 0.012323256582021713, -0.0074546425603330135, 0.02703799493610859, 0.03303212672472, -0.0003575453592929989, -0.017076026648283005, -0.03057987056672573, -0.01388294156640768, -0.054120562970638275, -0.03495490550994873, 0.005962326191365719, 0.0261037927120924, 0.014536343514919281, 0.021937111392617226, -0.02075790986418724, 0.021741731092333794, 0.006352114956825972, -0.016582144424319267, -0.06607650220394135, 0.004970588255673647, 0.007740683387964964, 0.040565818548202515, 0.0007608685991726816, 0.005751791875809431, 0.017145875841379166 ]
8acb8cd4dc2d6e35f38c30493bd708782f4c4cfd
3,400
py
Python
render_video.py
frostburn/branch-cut-mandelbrot
26c4d2db75a32b9190d40a09ebfb8a67fc4829e8
[ "MIT" ]
null
null
null
render_video.py
frostburn/branch-cut-mandelbrot
26c4d2db75a32b9190d40a09ebfb8a67fc4829e8
[ "MIT" ]
null
null
null
render_video.py
frostburn/branch-cut-mandelbrot
26c4d2db75a32b9190d40a09ebfb8a67fc4829e8
[ "MIT" ]
null
null
null
import argparse import imageio import progressbar from _routines import ffi, lib from pylab import * from random import Random RESOLUTIONS = { "2160p": (3840, 2160), "1440p": (2560, 1440), "1080p": (1920, 1080), "720p": (1280, 720), "480p": (854, 480), "360p": (640, 360), "240p": (426, 240), "160p": (284, 160), "80p": (142, 80), "40p": (71, 40), } def make_video_frame(rgb, indexing='ij', dither=1.0/256.0): if dither: rgb = [channel + random(channel.shape)*dither for channel in rgb] if indexing == 'ij': rgb = [channel.T for channel in rgb] frame = stack(rgb, axis=-1) frame = clip(frame, 0.0, 1.0) return (frame * 255).astype('uint8') def do_render(args, writer): max_iter = 32 im_buf = ffi.new("double[]", args.width * args.height) cut_buf = ffi.new("double[]", max_iter) fixed_seed = Random(1) for i in range(max_iter): cut_buf[i] = i*fixed_seed.random() for n in progressbar.progressbar(range(args.num_frames)): tg = n / (args.num_frames - 1) t = tg lib.mandelbrot(im_buf, args.width, args.height, 0.7, 0.8, 3.5, t-20, cut_buf, max_iter) im = array(list(im_buf)).reshape(args.height, args.width) # for i in range(max_iter): # cut_buf[i] *= 0.05**args.dt bg = (im < 0) im /= im.max() fg = 1 - bg red = im green = 1 - im blue = 4*im*(1-im) blue = blue + 0.2*green red = 0.1 + 0.8*red + green**3 green = 0.2 + 0.21*green frame = make_video_frame([red*fg + 0.15*bg, green*fg + 0.08*bg, blue*fg + 0.1*bg], indexing=None) writer.append_data(frame) if __name__ == '__main__': parser = argparse.ArgumentParser(description='Render audio samples') parser.add_argument('outfile', type=str, help='Output file name') parser.add_argument('--params', type=str, help='Parameter YAML file name') parser.add_argument('--resolution', choices=RESOLUTIONS.keys(), help='Video and simulation grid resolution') parser.add_argument('--width', type=int, help='Video and simulation grid width', metavar='W') parser.add_argument('--height', type=int, help='Video and simulation grid height', metavar='H') parser.add_argument('--framerate', type=int, help='Video frame rate') parser.add_argument('--video-quality', type=int, help='Video quality factor') parser.add_argument('--video-duration', type=float, help='Duration of video to render in seconds') args = parser.parse_args() if not args.framerate: args.framerate = 24 if not args.video_quality: args.video_quality = 10 writer = imageio.get_writer(args.outfile, fps=args.framerate, quality=args.video_quality, macro_block_size=1) # Compute derived parameters if args.resolution: width, height = RESOLUTIONS[args.resolution] if not args.width: args.width = width if not args.height: args.height = height if (not args.width) or (not args.height): raise ValueError("Invalid or missing resolution") if not args.video_duration: raise ValueError("Missing video duration") args.aspect = args.width / args.height args.num_frames = int(args.video_duration * args.framerate) args.dt = 1.0 / args.num_frames do_render(args, writer) writer.close()
34.693878
113
0.627059
1
2.0466
[ -0.04169763624668121, 0.006742935162037611, -0.007978915236890316, 0.010692089796066284, 0.01696726866066456, 0.05691682547330856, -0.019339358434081078, 0.011221894063055515, 0.012763210572302341, 0.032512471079826355, 0.04056498780846596, 0.010848850943148136, 0.017592744901776314, -0.01894068345427513, 0.007869734428822994, -0.05251595005393028, 0.15961095690727234, 0.03441726416349411, -0.015158400870859623, 0.011950631625950336, -0.03537629544734955, -0.009049463085830212, -0.013919762335717678, 0.017409581691026688, -0.005058193579316139, -0.006599040236324072, 0.034474927932024, 0.007963665761053562, 0.033364154398441315, -0.0002309881674591452, 0.00655571511015296, -0.005738012492656708, 0.11626910418272018, -0.005331709980964661, -0.020282752811908722, -0.0012011484941467643, 0.005678247660398483, -0.026666339486837387, 0.031963370740413666, 0.005177995655685663, -0.006102168932557106, -0.0037543841172009706, -0.016218116506934166, -0.062351200729608536, 0.03295464441180229, -0.03424458205699921, 0.023566490039229393, -0.04714576154947281, 0.000003986658157373313, -0.012848053127527237, 0.018120193853974342, 0.025846902281045914, -0.02982742339372635, -0.008325858972966671, 0.004587127361446619, -0.022925108671188354, 0.003745718626305461, -0.0012164765503257513, -0.033985041081905365, -0.03188246488571167, 0.024393241852521896, -0.04574882239103317, -0.016728390008211136, 0.002768040169030428, 0.022365357726812363, 0.002236894564703107, -0.006614496000111103, 0.02150428481400013, 0.07592739164829254, -0.024973129853606224, -0.01074227411299944, -0.006022853311151266, 0.040212441235780716, 0.1056392714381218, 0.027690308168530464, -0.02422431856393814, -0.03239519149065018, -0.012813523411750793, 0.004333364311605692, 0.01440410129725933, -0.024263301864266396, 0.03410907834768295, -0.015248926356434822, -0.02631096914410591, 0.027821140363812447, -0.014815568923950195, 0.005445371847599745, -0.06056559458374977, 0.049553632736206055, 0.023465532809495926, -0.05686511471867561, 0.023355307057499886, -0.08116939663887024, 0.0118674011901021, -0.037025682628154755, -0.04273078590631485, -0.003024118021130562, 0.00235549034550786, 0.0056619467213749886, 0.011199608445167542, -0.014164429157972336, -0.04777279123663902, -0.0008831541053950787, 0.0004941081278957427, -0.01667102985084057, -0.005028503946959972, -0.036743663251399994, -0.024512002244591713, -0.013543703593313694, 0.007700798567384481, -0.10799750685691833, 0.0037753633223474026, 0.03955140337347984, -0.04231764376163483, 0.004493142943829298, -0.055365998297929764, 0.03327981010079384, 0.0075250775553286076, -0.03229344263672829, -0.011581460013985634, 0.026599401608109474, -0.0150620611384511, 0.009006425738334656, 0.013923129066824913, -0.013163482770323753, 0.06972544640302658, -0.0058806524612009525, -0.0059038810431957245, -0.013822156004607677, -0.011153803206980228, 0.019777454435825348, 0.016118306666612625, -0.012511983513832092, -0.009062056429684162, 0.03816999867558479, -0.032315950840711594, -0.021373745054006577, 0.03231729939579964, -0.05720425397157669, 0.037521496415138245, -0.024588795378804207, -0.014012840576469898, -0.003429869655519724, -0.0008896292420104146, 0.011059566400945187, -0.06387674808502197, -0.012511046603322029, -0.0008075652876868844, -0.005035354755818844, -0.016951583325862885, 0.027944788336753845, 0.03376885503530502, 0.041439980268478394, -0.01832074485719204, -0.0052429866045713425, 0.014920986257493496, -0.004305348731577396, -0.034953150898218155, 0.014052536338567734, 0.03416072949767113, -0.01417491678148508, -0.008066034875810146, 0.00936722382903099, -0.002080712467432022, -0.0171698909252882, 0.10388445109128952, 0.006566083524376154, 0.029705431312322617, -0.04092013090848923, -0.004737474024295807, 0.014689301140606403, 0.008101062849164009, -0.021541234105825424, -0.0138556445017457, 0.049692556262016296, -0.027593545615673065, 0.05598927289247513, 0.03794659674167633, -0.007401554845273495, -0.010570969432592392, 0.02584461309015751, -0.022071249783039093, 0.01943047344684601, 0.022689055651426315, -0.014173946343362331, 0.023380322381854057, -0.04516397789120674, -0.00020244342158548534, 0.00904882326722145, -0.0014647288480773568, -0.02621813677251339, 0.026173582300543785, -0.001399086439050734, -0.024129727855324745, 0.01413540169596672, -0.0010250718332827091, -0.06523363292217255, 0.015732979401946068, 0.014260890893638134, -0.0047377473674714565, 0.03426054120063782, -0.024878503754734993, -0.010897647589445114, -0.008431737311184406, -0.005495596211403608, 0.002790308091789484, -0.5754900574684143, 0.03343911096453667, 0.027561720460653305, 0.0012313361512497067, -0.029855048283934593, 0.043689098209142685, -0.016892986372113228, 0.007123017217963934, 0.00817982479929924, -0.011833402328193188, 0.01620749570429325, -0.02027245983481407, -0.025696225464344025, -0.036309223622083664, -0.01271132379770279, -0.03521757945418358, 0.020079512149095535, 0.03419524431228638, -0.020540889352560043, 0.040007513016462326, -0.0037000244483351707, -0.027698613703250885, -0.018378863111138344, 0.037778306752443314, 0.02769564837217331, -0.005820571910589933, 0.03853090852499008, 0.005550283007323742, 0.030398812144994736, -0.015079984441399574, 0.004354498814791441, -0.010419105179607868, -0.008952154777944088, -0.005860231816768646, 0.00317142391577363, -0.00717896968126297, 0.020749175921082497, -0.011356551200151443, -0.005252738483250141, 0.018080228939652443, -0.027871660888195038, -0.03146721422672272, -0.013458373956382275, -0.04613417387008667, -0.032778821885585785, -0.018142396584153175, 0.02369655668735504, -0.011409204453229904, 0.04689539596438408, -0.010772406123578548, -0.004363649990409613, 0.018852734938263893, 0.03567058965563774, -0.03556663542985916, 0.009819142520427704, -0.032625023275613785, -0.01662006974220276, 0.008916257880628109, -0.002434993162751198, -0.00396556593477726, 0.01565915159881115, -0.03652872145175934, -0.04977225512266159, 0.022359048947691917, 0.017940329387784004, 0.00854301918298006, -0.004479862283915281, -0.028971845284104347, 0.0022235356736928225, 0.016439685598015785, -0.08870337903499603, -0.005728533491492271, -0.06123535707592964, 0.026064764708280563, 0.04519236460328102, 0.01684936136007309, -0.02562093734741211, 0.04006049409508705, -0.03472232446074486, -0.024628175422549248, 0.0523667149245739, -0.04756246507167816, -0.006269810721278191, 0.024141481146216393, -0.05044906586408615, 0.03179081529378891, 0.013262130320072174, 0.027142049744725227, -0.046076130121946335, 0.033450961112976074, 0.021408839151263237, 0.013804014772176743, 0.029888950288295746, -0.0029916386120021343, 0.0025059550534933805, 0.03933372721076012, 0.01264953427016735, 0.07863163948059082, 0.01742897555232048, 0.027510808780789375, 0.0032527269795536995, -0.004214106593281031, 0.026895903050899506, -0.010669496841728687, -0.015050279907882214, -0.01014504674822092, -0.08047277480363846, -0.026052679866552353, 0.03903259336948395, 0.003515728982165456, 0.04756317287683487, -0.008085045963525772, 0.003924906719475985, 0.04727175459265709, -0.035682059824466705, -0.01864035241305828, -0.004823983181267977, -0.0464252233505249, 0.038505200296640396, 0.002286273753270507, 0.0022965138778090477, -0.033365778625011444, -0.030089790001511574, 0.014179503545165062, -0.028940463438630104, 0.002001000801101327, -0.010992879047989845, -0.02376553602516651, 0.00259379087947309, 0.0041990820318460464, -0.036756567656993866, 0.001971588935703039, -0.012483545579016209, 0.0069529348984360695, -0.009348737075924873, -0.04804760962724686, 0.01160818338394165, -0.03786978870630264, 0.011108998209238052, -0.024544784799218178, -0.031561706215143204, -0.0422658734023571, 0.04849895089864731, -0.013684074394404888, 0.0012075265403836966, -0.0033001552801579237, -0.019913796335458755, -0.009208938106894493, -0.03325532376766205, 0.035079218447208405, 0.009144571609795094, -0.04080871865153313, 0.005184304900467396, 0.038785435259342194, -0.01977950893342495, -0.014094512909650803, -0.013314037583768368, -0.032168835401535034, 0.06750760227441788, 0.025610776618123055, 0.00323456316255033, -0.02687700092792511, -0.02699853479862213, 0.005685805808752775, -0.0066848997958004475, 0.001925107673741877, -0.03000718541443348, 0.003484455170109868, -0.009625326842069626, 0.025394393131136894, -0.0324636809527874, -0.029810095205903053, 0.01676858402788639, 0.026803281158208847, 0.047477204352617264, 0.04972698166966438, -0.019883792847394943, -0.04657921940088272, 0.011043505743145943, 0.001646227203309536, 0.00823037326335907, -0.04073570668697357, -0.000722464406862855, 0.011809700168669224, 0.06403036415576935, 0.007548157591372728, -0.0337413065135479, 0.0010497721377760172, -0.002930779242888093, -0.03156287223100662, 0.015674881637096405, 0.016520923003554344, 0.020664043724536896, -0.01658862642943859, -0.03453474119305611, -0.01713942363858223, 0.005498760845512152, -0.010306008160114288, -0.01164294220507145, 0.014350716024637222, 0.005522650666534901, 0.045837122946977615, 0.03043551556766033, -0.008519294671714306, -0.02064737305045128, 0.030573146417737007, -0.0036602956242859364, 0.017319152131676674, 0.014619077555835247, 0.0073661478236317635, -0.01732880063354969, -0.03905628249049187, -0.02776115946471691, -0.0478803887963295, -0.018945688381791115, 0.01337013766169548, -0.029478324577212334, -0.014083124697208405, 0.022519972175359726, -0.030162084847688675, -0.045107632875442505, -0.035387102514505386, 0.022040648385882378, 0.020007016137242317, 0.009301204234361649, -0.02152162604033947, -0.011362962424755096, -0.018065333366394043, 0.027195068076252937, -0.005293732509016991, 0.010801524855196476, 0.009686307050287724, 0.013957622461020947, -0.03134762495756149, -0.0046470589004457, 0.018085233867168427, -0.01664545014500618, -0.00046967773232609034, -0.030366411432623863, -0.00783251877874136, 0.026491476222872734, -0.010716299526393414, -0.0034722560085356236, 0.031928807497024536, -0.04604758322238922, 0.014065311290323734, -0.009439237415790558, -0.03571874648332596, -0.03702308237552643, 0.0002753792505245656, 0.02007586881518364, 0.02971351146697998, 0.00857172068208456, -0.013972901739180088, 0.002217296278104186, 0.014013155363500118, -0.03453585505485535, 0.04568828269839287, 0.02600560523569584, -0.00373086123727262, 0.009870653972029686, -0.03487146645784378, 0.011176697909832, 0.03582605719566345, 0.015077972784638405, 0.0329476036131382, -0.05736667662858963, 0.01217743195593357, 0.0009516578284092247, 0.01841636188328266, 0.017691561952233315, -0.028633151203393936, -0.009073561057448387, 0.008591926656663418, 0.03338542953133583, 0.017880121245980263, -0.004942195024341345, -0.03083210252225399, -0.009423484094440937, 0.0715656504034996, -0.02755126543343067, 0.013882284983992577, 0.03210848569869995, 0.020350614562630653, 0.00008380077633773908, 0.023608189076185226, 0.031378522515296936, 0.01831716299057007, -0.07273963838815689, 0.0065993089228868484, -0.005590199958533049, -0.009131938219070435, 0.032320793718099594, 0.01819770410656929, -0.021510036662220955, 0.04112910479307175, -0.017249643802642822, 0.004372041206806898, 0.02391580305993557, 0.049409668892621994, 0.04414999112486839, 0.005927006248384714, -0.03929352015256882, 0.034198369830846786, 0.010782312601804733, -0.011765306815505028, 0.01224150788038969, -0.00889598298817873, 0.05590524524450302, -0.006595219019800425, -0.030568286776542664, 0.0003137741005048156, 0.02180398814380169, 0.025208141654729843, 0.013043553568422794, -0.016352448612451553, 0.028708042576909065, 0.02964046597480774, 0.038285985589027405, -0.01320362277328968, -0.0348525196313858, 0.01723230630159378, -0.03236077353358269, -0.01577736809849739, -0.013480774126946926, -0.04826940596103668, -0.03948701173067093, -0.007898867130279541, 0.02868976816534996, -0.014940455555915833, 0.014053421095013618, -0.003550745779648423, -0.019516142085194588, -0.014513783156871796, -0.012027229182422161, -0.020144721493124962, 0.055907558649778366, 0.014342677779495716, 0.036304645240306854, 0.020677801221609116, 0.002542788628488779, -0.006733677349984646, -0.04122711718082428, -0.037926845252513885, -0.009097523987293243, 0.00037418206920847297, -0.062329258769750595, -0.0001525156112620607, 0.05848715454339981, 0.06971583515405655, -0.03175555542111397, 0.023365860804915428, -0.024114692583680153, -0.004137754440307617, -0.011954125948250294, -0.002971070585772395, 0.02486206404864788, 0.014273509383201599, -0.014378014020621777, 0.024370498955249786, 0.0037954722065478563, -0.006950304377824068, -0.021148985251784325, -0.016555432230234146, -0.012790857814252377, -0.0510886088013649, 0.01854958012700081, 0.003066236851736903, -0.009857905097305775, 0.01223533321171999, -0.03146255388855934, -0.05348217487335205, -0.0005823153769597411, 0.023444760590791702, 0.03924742713570595, 0.06314478069543839, 0.03012586012482643, 0.03879358246922493, -0.02238478697836399, -0.028724774718284607, 0.015664007514715195, -0.003659067675471306, 0.01065644808113575, -0.01380037423223257, 0.035858042538166046, 0.0021057073026895523, -0.04162832722067833, 0.011657586321234703, -0.0337081216275692, -0.07546952366828918, 0.01520665641874075, 0.012642747722566128, 0.015137983486056328, 0.026633059605956078, 0.02113749459385872, 0.02187993749976158, -0.0031101268250495195, -0.018833640962839127, 0.018249426037073135, -0.02318902127444744, 0.011111455038189888, 0.0077923438511788845, -0.01186660397797823, -0.02482767030596733, -0.03829836845397949, -0.027193842455744743, 0.07479036599397659, -0.02765660174190998, 0.0163348987698555, 0.01549750566482544, -0.00039583691977895796, 0.030816802754998207, 0.06114692613482475, -0.05594530329108238, 0.029778676107525826, 0.0239142756909132, 0.006036477163434029, -0.0008327144896611571, -0.01186425518244505, 0.0035206631291657686, -0.02249615639448166, -0.028630459681153297, -0.03206045553088188, 0.006798472721129656, -0.007400538772344589, -0.013902450911700726, -0.0009983840864151716, 0.005414672661572695, -0.01607789471745491, 0.026901287958025932, -0.03419429808855057, -0.021402176469564438, -0.02582966722548008, -0.02494572289288044, 0.009660457260906696, 0.012514214031398296, -0.016371840611100197, -0.020009346306324005, 0.006528317928314209, 0.015201954171061516, 0.04175003990530968, 0.009383678436279297, -0.004945437423884869, 0.03496778756380081, -0.046045318245887756, -0.13839322328567505, 0.0017075977521017194, -0.014711517840623856, -0.0008199525182135403, 0.0047268737107515335, 0.04266468435525894, -0.03560830280184746, -0.017977317795157433, 0.04401283338665962, -0.008112888783216476, -0.03438073396682739, 0.02057981677353382, 0.02349122054874897, 0.017586080357432365, 0.01924317702651024, 0.04487181827425957, 0.043884895741939545, 0.00047594340867362916, -0.008365906774997711, 0.008686590939760208, 0.030243773013353348, 0.023781992495059967, 0.00453148502856493, -0.0027028322219848633, 0.007831561379134655, 0.047254037111997604, 0.012493681162595749, 0.006080007646232843, -0.020692594349384308, 0.02204093523323536, 0.0047171348705887794, -0.012224739417433739, -0.00598494429141283, 0.02566089853644371, -0.010800812393426895, -0.050672952085733414, -0.01341439038515091, -0.0045518758706748486, -0.020568696781992912, 0.019018778577446938, 0.014658445492386818, 0.011276566423475742, 0.03176368027925491, -0.0014025171985849738, 0.038733743131160736, -0.04530659690499306, -0.011220283806324005, -0.027692696079611778, 0.01739559695124626, 0.024897167459130287, -0.04218585416674614, 0.0197727233171463, -0.03269381821155548, -0.01796303130686283, -0.003654906991869211, -0.05218062177300453, 0.027604978531599045, 0.021824469789862633, 0.007419121451675892, 0.04867174103856087, 0.02901580184698105, 0.01813138648867607, 0.03880046680569649, -0.011531900614500046, 0.007436699699610472, -0.02763507515192032, -0.05630751699209213, -0.0076207672245800495, -0.08724961429834366, 0.0009181827772408724, 0.0017065488500520587, 0.025825075805187225, -0.03966234251856804, -0.0030441295821219683, -0.05110384151339531, -0.003087318269535899, 0.015634097158908844, -0.034582775086164474, -0.0006766616716049612, -0.0018341465620324016, -0.030219387263059616, -0.043678298592567444, 0.0059625543653965, 0.014752696268260479, -0.0033176203723996878, 0.01633608341217041, -0.005710730794817209, 0.007454286329448223, 0.024545704945921898, -0.009813842363655567, -0.03809573873877525, -0.005402662791311741, 0.0907493531703949, -0.07180482894182205, -0.01989392191171646, 0.019955983385443687, 0.041475750505924225, 0.017234865576028824, -0.024052754044532776, -0.03767040744423866, 0.03590352460741997, 0.0006044363253749907, 0.033761464059352875, 0.03340984880924225, 0.02943676896393299, -0.05460600554943085, 0.03221491351723671, -0.04583659768104553, 0.009776391088962555, -0.023831071332097054, -0.009636922739446163, 0.01269979402422905, 0.01450808160007, 0.011280086822807789, -0.06707854568958282, -0.017402561381459236, -0.0005831124726682901 ]
8accb038864b63aa2e837e9fa4c1312771a520cd
1,238
py
Python
tests/mqtt/test_subscribe.py
smurfix/hbmqtt
914440cd18b43fbe56496a73bb1259132811c539
[ "MIT" ]
null
null
null
tests/mqtt/test_subscribe.py
smurfix/hbmqtt
914440cd18b43fbe56496a73bb1259132811c539
[ "MIT" ]
null
null
null
tests/mqtt/test_subscribe.py
smurfix/hbmqtt
914440cd18b43fbe56496a73bb1259132811c539
[ "MIT" ]
null
null
null
# Copyright (c) 2015 Nicolas JOUANIN # # See the file license.txt for copying permission. import anyio import unittest from hbmqtt.mqtt.subscribe import SubscribePacket, SubscribePayload from hbmqtt.mqtt.packet import PacketIdVariableHeader from hbmqtt.mqtt.constants import QOS_1, QOS_2 from hbmqtt.adapters import BufferAdapter class SubscribePacketTest(unittest.TestCase): def test_from_stream(self): data = b'\x80\x0e\x00\x0a\x00\x03a/b\x01\x00\x03c/d\x02' stream = BufferAdapter(data) message = anyio.run(SubscribePacket.from_stream, stream) (topic, qos) = message.payload.topics[0] self.assertEqual(topic, 'a/b') self.assertEqual(qos, QOS_1) (topic, qos) = message.payload.topics[1] self.assertEqual(topic, 'c/d') self.assertEqual(qos, QOS_2) def test_to_stream(self): variable_header = PacketIdVariableHeader(10) payload = SubscribePayload( [ ('a/b', QOS_1), ('c/d', QOS_2) ]) publish = SubscribePacket(variable_header=variable_header, payload=payload) out = publish.to_bytes() self.assertEqual(out, b'\x82\x0e\x00\x0a\x00\x03a/b\x01\x00\x03c/d\x02')
35.371429
83
0.671244
1
1.1016
[ -0.0022345883771777153, 0.02495639957487583, 0.010239114984869957, 0.0026735763531178236, 0.004749095533043146, -0.0010390421375632286, -0.008110800758004189, 0.002396686002612114, -0.005730325356125832, 0.002534504747018218, 0.00651017390191555, 0.00602486077696085, 0.008894051425158978, -0.01318362820893526, 0.0003546620428096503, 0.013835865072906017, -0.05393090471625328, 0.002791852690279484, -0.0029851451981812716, 0.004224494099617004, -0.005780816078186035, 0.010580053552985191, 0.00957766268402338, 0.0062333582900464535, 0.008410640060901642, -0.002138590207323432, 0.007967442274093628, 0.002569071715697646, -0.009086445905268192, -0.008397473953664303, 0.0005419246735982597, -0.002610882744193077, -0.008917288854718208, -0.007343062665313482, 0.0074121844954788685, -0.004983917810022831, -0.0004964885301887989, -0.01761595718562603, 0.01348395086824894, -0.004074718337506056, -0.0071932547725737095, -0.019676487892866135, 0.0019038120517507195, 0.006144308485090733, -0.01020055916160345, -0.000021229920093901455, -0.0044837286695837975, 0.006016386207193136, -0.013623588718473911, 0.005472409073263407, -0.009570079855620861, 0.004672196228057146, 0.016677986830472946, 0.0014729456743225455, -0.006101916544139385, -0.008413944393396378, 0.011074558831751347, -0.0027036566752940416, -0.012305578216910362, 0.00016035221051424742, -0.0023097191005945206, -0.0011567296460270882, 0.005788150243461132, 0.003440344240516424, -0.017485130578279495, -0.006675840355455875, -0.006481494288891554, 0.0018505365587770939, -0.005526307038962841, 0.004825148265808821, 0.0006237525376491249, -0.00304100732319057, 0.00946610327810049, 0.0030204923823475838, 0.0030827096197754145, -0.005536416545510292, -0.00196782685816288, -0.00002834944098140113, 0.005790312774479389, 0.001971523743122816, 0.007178166415542364, -0.010028149001300335, 0.005269281566143036, 0.00992219801992178, 0.016903730109333992, 0.008580315858125687, 0.02039189450442791, -0.011601757258176804, 0.04786334186792374, 0.009506077505648136, -0.008733265101909637, -0.0005239186575636268, -0.007718572858721018, -0.004622890613973141, -0.00448709586635232, -0.029757140204310417, 0.0005200880113989115, -0.004536596592515707, -0.0007887825486250222, 0.00279832910746336, 0.0008665690547786653, 0.008116577751934528, 0.0013876681914553046, -0.0017045396380126476, -0.009197755716741085, 0.01350490190088749, -0.010012468323111534, -0.0048715490847826, 0.004966013133525848, 0.001231881557032466, -0.01333341933786869, -0.0032049294095486403, 0.003895096480846405, -0.013904092833399773, 0.0024815010838210583, 0.002755318069830537, -0.006288306321948767, 0.05595032870769501, -0.0024564925115555525, 0.005315438378602266, -0.004541125614196062, 0.0015718071954324841, 0.002778835128992796, 0.006806353107094765, 0.00799812562763691, -0.0031208323780447245, 0.013842063024640083, 0.010776649229228497, 0.005790227558463812, 0.012614327482879162, -0.002089726971462369, 0.009451568126678467, -0.0026423644740134478, -0.004291514400392771, 0.0034478013403713703, -0.008145218715071678, 0.009168109856545925, -0.002201387193053961, -0.011071857064962387, 0.0004489541461225599, -0.0001402545312885195, -0.009853227064013481, 0.0038149377796798944, -0.0058436342515051365, 0.003601089818403125, -0.009859425947070122, -0.0015563943888992071, -0.0034034994896501303, -0.005782618653029203, 0.0006279757362790406, 0.009329533204436302, 0.005321871023625135, 0.0028064949437975883, -0.0036396675277501345, -0.008700279518961906, -0.002489222912117839, -0.00228515500202775, 0.0010734761599451303, 0.009512037970125675, 0.0056162746623158455, -0.011035247705876827, -0.0012243911623954773, 0.0040036882273852825, 0.004242626018822193, -0.004255671054124832, 0.0034459982998669147, -0.007575619965791702, 0.008937244303524494, -0.0002655829885043204, 0.0022021618206053972, 0.010766679421067238, -0.0023722397163510323, -0.002169785089790821, 0.0016781261656433344, 0.001460996107198298, -0.0016167688881978393, 0.005171692464500666, 0.012031855061650276, -0.003757572267204523, -0.004427045118063688, 0.003925718367099762, 0.006090045906603336, 0.0081785311922431, 0.00864420086145401, 0.0003062461328227073, 0.001339845359325409, -0.004098351579159498, -0.002684176666662097, 0.003994409926235676, -0.0033260034397244453, 0.0070814043283462524, 0.004585863556712866, -0.012989367358386517, -0.006636813282966614, 0.0016179451486095786, -0.011047937907278538, 0.0028005654457956553, 0.016742810606956482, 0.011078733950853348, -0.004441393073648214, 0.0013691456988453865, -0.007821841165423393, -0.000920999504160136, 0.007865904830396175, 0.0021249884739518166, -0.013915518298745155, -0.956804096698761, 0.00529820891097188, 0.0016384645132347941, -0.0009809423936530948, 0.006726787891238928, -0.0004342900647316128, 0.00437071593478322, 0.0006405972526408732, 0.015651972964406013, -0.005901154596358538, -0.006286366377025843, -0.008817118592560291, -0.00961235724389553, -0.00007952174200909212, -0.007450328208506107, -0.001793640200048685, -0.007721435744315386, -0.0049662780947983265, -0.0034818851854652166, -0.0040731048211455345, -0.0015005468158051372, 0.008328714407980442, 0.0019354207906872034, 0.0043571931309998035, 0.0026020086370408535, 0.004995730239897966, -0.0076388828456401825, -0.00028053735150024295, 0.0011505340225994587, -0.002297267783433199, -0.00667826971039176, -0.013917959295213223, -0.005184206645935774, -0.0019204551354050636, 0.009288809262216091, -0.0006613545119762421, 0.011774248443543911, -0.001944958115927875, 0.0021648674737662077, -0.005572961643338203, 0.006347766146063805, -0.002086765132844448, 0.004202558193355799, -0.030513640493154526, -0.0005918071838095784, -0.0035534596536308527, -0.008262884803116322, 0.006597919389605522, -0.0029269703663885593, 0.0018525782506912947, -0.0037447495851665735, -0.004552046302706003, 0.010115751065313816, -0.00901360996067524, 0.004137352108955383, -0.003965848125517368, -0.006121978163719177, -0.00394764170050621, -0.0071058617904782295, 0.002548612654209137, 0.004164054058492184, -0.002589782467111945, -0.005359414964914322, -0.0019823526963591576, 0.003888578386977315, 0.003729145275428891, -0.0002338955964660272, -0.022766487672924995, -0.004068796988576651, -0.0002609284711070359, 0.004701905883848667, -0.0030555943958461285, -0.0037058459129184484, 0.003579562995582819, -0.008689146488904953, 0.006009272765368223, 0.0012672607554122806, -0.0028126174584031105, -0.010846192017197609, 0.0018066453048959374, -0.007326393388211727, -0.00912583526223898, 0.002125232247635722, -0.005868640262633562, -0.005918891169130802, 0.00019687203166540712, 0.0011235005222260952, 0.007578263524919748, -0.0031678162049502134, 0.0039792838506400585, 0.010211656801402569, -0.0024360709358006716, -0.005753708072006702, 0.006697583943605423, 0.006613241974264383, -0.001671477104537189, -0.005210621748119593, 0.005054090172052383, 0.00856570154428482, 0.006566526368260384, 0.0036992484237998724, 0.00469910679385066, -0.0008321821806021035, 0.010803231038153172, -0.0017503838753327727, 0.0006304105627350509, -0.003502690466120839, -0.0013929809210821986, -0.0048041027039289474, -0.0009749695309437811, -0.005436438135802746, -0.0005488524911925197, -0.011202308349311352, -0.009749465622007847, -0.0006314566708169878, -0.0019197417423129082, 0.005193729884922504, -0.005220333579927683, 0.0017513679340481758, -0.0018356116488575935, 0.008834144100546837, -0.0005161102162674069, -0.0030734774190932512, 0.0014732048148289323, 0.005125482100993395, -0.007976625114679337, 0.013432103209197521, -0.01247292198240757, 0.0061256675980985165, -0.0025672451592981815, -0.015762431547045708, 0.009704995900392532, 0.00966216716915369, -0.0065682618878781796, 0.0034449659287929535, 0.003528623841702938, 0.0050198775716125965, -0.0008238618029281497, -0.004405582323670387, -0.003313623368740082, -0.01713569089770317, 0.0013991233427077532, 0.018688013777136803, 0.0032529798336327076, 0.008732899092137814, 0.01063575129956007, -0.0012579587055370212, 0.0017413718160241842, 0.0070539433509111404, 0.002606006572023034, 0.01179805863648653, -0.008517531678080559, -0.0014888197183609009, 0.00116516905836761, -0.007108230143785477, 0.0010996644850820303, 0.004223511088639498, 0.006660290528088808, -0.004294028040021658, 0.0017521235859021544, -0.00871839839965105, -0.004621035885065794, -0.014514320529997349, -0.0005301848868839443, 0.0072813560254871845, -0.006309277843683958, 0.007356490474194288, -0.016233645379543304, 0.002971904817968607, 0.006960883736610413, 0.0051465509459376335, 0.0007324132020585239, 0.0022806397173553705, 0.0025802948512136936, 0.010337373241782188, -0.007334679830819368, 0.004431788809597492, -0.0007732233498245478, -0.001089847064577043, 0.0021752403117716312, 0.008211162872612476, -0.006667518522590399, -0.007287281099706888, 0.004082378465682268, 0.004176792223006487, 0.00031505015795119107, -0.0035475241020321846, -0.007574890740215778, -0.0007230100454762578, 0.002368924440816045, -0.007847973145544529, 0.00601141806691885, 0.0023600985296070576, 0.0041960165835917, -0.008779734373092651, -0.0013568814611062407, -0.005851105321198702, -0.011398191563785076, 0.010250094346702099, -0.00294914236292243, 0.0019569566939026117, 0.010764667764306068, 0.002673497423529625, -0.013987491838634014, 0.0022713644430041313, 0.007413276471197605, -0.002316452795639634, 0.005433420650660992, 0.007208433002233505, -0.006782094482332468, -0.022241398692131042, -0.004174490459263325, -0.015423895791172981, 0.0081715639680624, -0.0035250240471214056, 0.0037877955473959446, -0.008565325289964676, 0.008063782006502151, 0.005824575200676918, -0.011843925341963768, -0.004797494970262051, -0.009163322858512402, 0.0077457791194319725, -0.0009450339712202549, -0.00008052068005781621, -0.0034701728727668524, -0.0018069910584017634, -0.00199051178060472, -0.004811593797057867, -0.002476848429068923, 0.006796910893172026, 0.0013024822110310197, -0.003193776123225689, 0.0008423347608186305, -0.00532711623236537, -0.0011083188001066446, 0.0007623948040418327, -0.014452098868787289, -0.000663404818624258, 0.006845593918114901, 0.00016773439710959792, -0.005484717898070812, -0.0017997811082750559, -0.0056307753548026085, -0.003208962269127369, -0.012668062001466751, -0.0015340793179348111, -0.0034659148659557104, -0.001108162454329431, -0.01282696332782507, -0.002970264758914709, -0.009672107174992561, 0.007545760832726955, -0.006525413133203983, 0.008897046558558941, 0.0032709622755646706, -0.0030841906554996967, 0.008219926618039608, 0.0008179800934158266, 0.0061844224110245705, 0.001676479703746736, 0.003462206106632948, 0.00002110817513312213, -0.007772002834826708, -0.012513594701886177, 0.011135179549455643, -0.007119105197489262, 0.002826926065608859, 0.013081626035273075, 0.0065327296033501625, 0.00713634816929698, -0.0026146043092012405, -0.00221890676766634, -0.00007154423656174913, 0.011015568859875202, -0.01189191173762083, 0.004002685658633709, -0.0017550825141370296, 0.002104046754539013, 0.0040079145692288876, -0.004636474885046482, 0.0013827707152813673, 0.010741563513875008, 0.00040803218143992126, -0.004841670859605074, -0.004518388770520687, 0.002668864792212844, 0.005277082324028015, -0.014979374594986439, 0.00024333057808689773, -0.0025035310536623, -0.005068143829703331, -0.00694784102961421, -0.0008887723670341074, -0.0017539949622005224, 0.004272437188774347, -0.0014237090945243835, 0.007094178814440966, 0.0021222198847681284, -0.006549525074660778, 0.015286869369447231, -0.009480003267526627, -0.003490881761536002, 0.0020272191613912582, 0.0011654534609988332, 0.0008837381610646844, -0.0061755855567753315, -0.0028370535001158714, 0.0022532267030328512, 0.0067448969930410385, -0.0016983150271698833, -0.004829350393265486, -0.0007772864191792905, 0.0008568017510697246, -0.010637041181325912, 0.0034772574435919523, 0.010395589284598827, 0.00011232602264499292, 0.005775960627943277, -0.0042273057624697685, -0.005709704011678696, -0.016950396820902824, 0.0558493509888649, -0.0012494372203946114, 0.004089179448783398, 0.004343296866863966, -0.009450463578104973, 0.0013555831974372268, -0.0037085001822561026, 0.00788742396980524, -0.006908096373081207, -0.005466171074658632, 0.0075542377308011055, -0.0019321190193295479, 0.004414188209921122, 0.0029361180495470762, -0.0034200784284621477, 0.01573428325355053, -0.004159491043537855, -0.013973258435726166, -0.017444834113121033, 0.002543138340115547, -0.005348818842321634, -0.007153520360589027, 0.00798865593969822, -0.0003415605751797557, -0.006532465573400259, 0.0009918290888890624, 0.006696609314531088, -0.0010492033325135708, -0.0004791639221366495, -0.003407668322324753, -0.0027089540380984545, 0.0017264297930523753, 0.0015580778708681464, 0.0059668212197721004, 0.008714001625776291, -0.005378981586545706, 0.0017718988237902522, -0.0012483462924137712, -0.003673549508675933, -0.0007935772882774472, 0.003687296062707901, 0.007803875487297773, -0.0014680842868983746, -0.0011832910822704434, 0.0037831964436918497, 0.005167578347027302, 0.00032410628045909107, 0.011818015947937965, -0.0012179103214293718, -0.0045165857300162315, 0.007853490300476551, 0.009362106211483479, 0.00020801964274141937, 0.007143165450543165, -0.0010408866219222546, 0.004893181845545769, 0.0017164780292659998, -0.006951331160962582, -0.01996074616909027, -0.004713437054306269, 0.00458742119371891, 0.009024904109537601, 0.000024734345061006024, 0.0017595745157450438, -0.00645244587212801, -0.003216463141143322, -0.007884909398853779, -0.005840155761688948, 0.0006754237692803144, -0.0006039272993803024, 0.004155735019594431, 0.07064256817102432, -0.007083611562848091, -0.002065981039777398, -0.007109746336936951, -0.00031584096723236144, -0.0054870168678462505, -0.001359054003842175, 0.0004072213778272271, -0.0012040354777127504, 0.0027019872795790434, 0.0011781611246988177, -0.007293275557458401, -0.011240341700613499, 0.0017073792405426502, 0.0036216359585523605, -0.0034728727769106627, 0.0064809080213308334, 0.005166115239262581, -0.009723047725856304, 0.0007064328528940678, -0.01174542959779501, -0.00048656234866939485, -0.0022005203645676374, -0.011341710574924946, -0.008399040438234806, -0.0016713402001187205, 0.003820751328021288, 0.0027483999729156494, 0.007222818210721016, -0.0053672343492507935, 0.008120125159621239, -0.002232164377346635, -0.00035168681642971933, -0.008348352275788784, 0.0011565410532057285, -0.007103258278220892, 0.007083463948220015, 0.0005604245234280825, -0.007603616453707218, -0.005151063669472933, -0.0004943960811942816, -0.0021199421025812626, -0.0034889178350567818, 0.005063808057457209, 0.0016283205477520823, 0.005056981462985277, -0.0036334695760160685, 0.0007362668402493, -0.005236602388322353, 0.0004934683092869818, -0.012553920969367027, 0.005467541050165892, -0.174008309841156, 0.010151935741305351, 0.007322416640818119, -0.003973326645791531, -0.004792102612555027, -0.017321832478046417, -0.004843783564865589, 0.005552573129534721, 0.013288603164255619, 0.002714331727474928, -0.0026846767868846655, -0.005500481929630041, 0.008218067698180676, 0.0016460518818348646, -0.0012610920239239931, -0.004481490235775709, 0.002178487367928028, -0.0032420360948890448, 0.0023492565378546715, 0.004734009504318237, 0.0036377166397869587, 0.010221987962722778, 0.0004261212598066777, 0.006674590054899454, -0.004354282282292843, -0.004672619514167309, 0.007181219290941954, -0.0036956516560167074, 0.007016770541667938, -0.012082213535904884, -0.003494902281090617, -0.0032379392068833113, -0.004997830837965012, 0.0005298649193719029, 0.0036039622500538826, -0.002281477442011237, 0.010326932184398174, 0.0016135332407429814, -0.005597647745162249, 0.0065558128990232944, -0.008948452770709991, 0.025855792686343193, 0.004912631120532751, 0.008120731450617313, -0.0007141958922147751, -0.004312855191528797, -0.005186084657907486, 0.0078040058724582195, 0.0003460712905507535, 0.009607020765542984, -0.01171305775642395, 0.0007335329428315163, 0.006007833406329155, 0.019443457946181297, -0.006487038917839527, -0.00822635181248188, -0.007252185605466366, -0.0032291447278112173, 0.0028886974323540926, 0.01002441719174385, 0.011958520859479904, -0.004247336648404598, 0.009774960577487946, -0.004179760348051786, -0.020934462547302246, 0.0028895235154777765, -0.007220104802399874, -0.007574369665235281, 0.004490012768656015, 0.0058683790266513824, 0.010602145455777645, 0.00026772281853482127, 0.00401832303032279, -0.0017600269056856632, 0.002293430967256427, -0.002015226287767291, 0.00750266807153821, -0.0016176748322322965, 0.004578324966132641, -0.006822958122938871, 0.009332464076578617, -0.011217095889151096, -0.0018661445938050747, 0.003028303850442171, -0.0008930914336815476, 0.01149693876504898, 0.004790253471583128, -0.0013703263830393553, -0.001278664800338447, -0.012061800807714462, -0.00429126899689436, 0.004083937965333462, 0.003495187731459737, -0.009294982999563217, 0.0038262654561549425, -0.00042350319563411176, 0.006643468514084816, 0.006210525520145893, -0.007153660990297794, 0.006761002354323864, 0.007709335535764694, -0.003114802995696664, 0.0014986119931563735, -0.004799327813088894, 0.003399468259885907, 0.0033269471023231745, -0.006146083120256662, -0.007006530184298754, 0.005047073122113943, -0.007310675457119942, -0.004007394425570965, 0.0069868494756519794, -0.011685793288052082, -0.005292451474815607, -0.00511384941637516, -0.0123530812561512, 0.00011742425704142079 ]
8ace9182901a299fe90834f06095914657f35b9c
8,392
py
Python
examples/cmrc2018_example/main.trainer.py
fangd123/TextBrewer
866f4363d9bd964f00aa60b0db5e9252a7905448
[ "Apache-2.0" ]
1,121
2020-03-02T02:24:00.000Z
2022-03-31T06:33:49.000Z
examples/cmrc2018_example/main.trainer.py
fangd123/TextBrewer
866f4363d9bd964f00aa60b0db5e9252a7905448
[ "Apache-2.0" ]
85
2020-03-04T09:46:17.000Z
2022-03-30T09:33:35.000Z
examples/cmrc2018_example/main.trainer.py
fangd123/TextBrewer
866f4363d9bd964f00aa60b0db5e9252a7905448
[ "Apache-2.0" ]
200
2020-03-02T07:23:21.000Z
2022-03-30T08:26:24.000Z
import logging logging.basicConfig( format='%(asctime)s - %(levelname)s - %(name)s - %(message)s', datefmt='%Y/%m/%d %H:%M:%S', level=logging.INFO, ) logger = logging.getLogger("Main") import os,random import numpy as np import torch from processing import convert_examples_to_features, read_squad_examples from processing import ChineseFullTokenizer from pytorch_pretrained_bert.my_modeling import BertConfig from optimization import BERTAdam import config from utils import read_and_convert, divide_parameters from modeling import BertForQASimple, BertForQASimpleAdaptorTraining from textbrewer import DistillationConfig, TrainingConfig, BasicTrainer from torch.utils.data import TensorDataset, DataLoader, RandomSampler from functools import partial from train_eval import predict def args_check(args): if os.path.exists(args.output_dir) and os.listdir(args.output_dir): logger.warning("Output directory () already exists and is not empty.") if args.gradient_accumulation_steps < 1: raise ValueError("Invalid gradient_accumulation_steps parameter: {}, should be >= 1".format( args.gradient_accumulation_steps)) if not args.do_train and not args.do_predict: raise ValueError("At least one of `do_train` or `do_predict` must be True.") if args.local_rank == -1 or args.no_cuda: device = torch.device("cuda" if torch.cuda.is_available() and not args.no_cuda else "cpu") n_gpu = torch.cuda.device_count() if not args.no_cuda else 0 else: device = torch.device("cuda", args.local_rank) n_gpu = 1 torch.distributed.init_process_group(backend='nccl') logger.info("device %s n_gpu %d distributed training %r", device, n_gpu, bool(args.local_rank != -1)) args.n_gpu = n_gpu args.device = device return device, n_gpu def main(): #parse arguments config.parse() args = config.args for k,v in vars(args).items(): logger.info(f"{k}:{v}") #set seeds torch.manual_seed(args.random_seed) torch.cuda.manual_seed_all(args.random_seed) np.random.seed(args.random_seed) random.seed(args.random_seed) #arguments check device, n_gpu = args_check(args) os.makedirs(args.output_dir, exist_ok=True) forward_batch_size = int(args.train_batch_size / args.gradient_accumulation_steps) args.forward_batch_size = forward_batch_size #load bert config bert_config_S = BertConfig.from_json_file(args.bert_config_file_S) assert args.max_seq_length <= bert_config_S.max_position_embeddings #read data train_examples = None train_features = None eval_examples = None eval_features = None num_train_steps = None tokenizer = ChineseFullTokenizer(vocab_file=args.vocab_file, do_lower_case=args.do_lower_case) convert_fn = partial(convert_examples_to_features, tokenizer=tokenizer, max_seq_length=args.max_seq_length, doc_stride=args.doc_stride, max_query_length=args.max_query_length) if args.do_train: train_examples,train_features = read_and_convert(args.train_file,is_training=True, do_lower_case=args.do_lower_case, read_fn=read_squad_examples,convert_fn=convert_fn) if args.fake_file_1: fake_examples1,fake_features1 = read_and_convert(args.fake_file_1,is_training=True, do_lower_case=args.do_lower_case, read_fn=read_squad_examples,convert_fn=convert_fn) train_examples += fake_examples1 train_features += fake_features1 if args.fake_file_2: fake_examples2, fake_features2 = read_and_convert(args.fake_file_2,is_training=True, do_lower_case=args.do_lower_case, read_fn=read_squad_examples,convert_fn=convert_fn) train_examples += fake_examples2 train_features += fake_features2 num_train_steps = int(len(train_features)/args.train_batch_size) * args.num_train_epochs if args.do_predict: eval_examples,eval_features = read_and_convert(args.predict_file,is_training=False, do_lower_case=args.do_lower_case, read_fn=read_squad_examples,convert_fn=convert_fn) #Build Model and load checkpoint model_S = BertForQASimple(bert_config_S,args) #Load student if args.load_model_type=='bert': assert args.init_checkpoint_S is not None state_dict_S = torch.load(args.init_checkpoint_S, map_location='cpu') state_weight = {k[5:]:v for k,v in state_dict_S.items() if k.startswith('bert.')} missing_keys,_ = model_S.bert.load_state_dict(state_weight,strict=False) assert len(missing_keys)==0 elif args.load_model_type=='all': assert args.tuned_checkpoint_S is not None state_dict_S = torch.load(args.tuned_checkpoint_S,map_location='cpu') model_S.load_state_dict(state_dict_S) else: logger.info("Model is randomly initialized.") model_S.to(device) if args.local_rank != -1 or n_gpu > 1: if args.local_rank != -1: raise NotImplementedError elif n_gpu > 1: model_S = torch.nn.DataParallel(model_S) #,output_device=n_gpu-1) if args.do_train: #parameters params = list(model_S.named_parameters()) all_trainable_params = divide_parameters(params, lr=args.learning_rate) logger.info("Length of all_trainable_params: %d", len(all_trainable_params)) optimizer = BERTAdam(all_trainable_params,lr=args.learning_rate, warmup=args.warmup_proportion,t_total=num_train_steps,schedule=args.schedule, s_opt1=args.s_opt1, s_opt2=args.s_opt2, s_opt3=args.s_opt3) logger.info("***** Running training *****") logger.info(" Num orig examples = %d", len(train_examples)) logger.info(" Num split examples = %d", len(train_features)) logger.info(" Forward batch size = %d", forward_batch_size) logger.info(" Num backward steps = %d", num_train_steps) ########### DISTILLATION ########### train_config = TrainingConfig( gradient_accumulation_steps = args.gradient_accumulation_steps, ckpt_frequency = args.ckpt_frequency, log_dir = args.output_dir, output_dir = args.output_dir, device = args.device) distiller = BasicTrainer(train_config = train_config, model = model_S, adaptor = BertForQASimpleAdaptorTraining) all_input_ids = torch.tensor([f.input_ids for f in train_features], dtype=torch.long) all_input_mask = torch.tensor([f.input_mask for f in train_features], dtype=torch.long) all_doc_mask = torch.tensor([f.doc_mask for f in train_features], dtype=torch.float) all_segment_ids = torch.tensor([f.segment_ids for f in train_features], dtype=torch.long) all_start_positions = torch.tensor([f.start_position for f in train_features], dtype=torch.long) all_end_positions = torch.tensor([f.end_position for f in train_features], dtype=torch.long) train_dataset = TensorDataset(all_input_ids, all_segment_ids, all_input_mask, all_doc_mask, all_start_positions, all_end_positions) if args.local_rank == -1: train_sampler = RandomSampler(train_dataset) else: raise NotImplementedError train_dataloader = DataLoader(train_dataset, sampler=train_sampler, batch_size=args.forward_batch_size,drop_last=True) callback_func = partial(predict, eval_examples=eval_examples, eval_features=eval_features, args=args) with distiller: distiller.train(optimizer, scheduler=None, dataloader=train_dataloader, num_epochs=args.num_train_epochs, callback=callback_func) if not args.do_train and args.do_predict: res = predict(model_S,eval_examples,eval_features,step=0,args=args) print (res) if __name__ == "__main__": main()
45.362162
130
0.674094
1
1.9221
[ -0.018554875627160072, 0.033012449741363525, 0.0021362011320888996, 0.01847582869231701, -0.005593478213995695, 0.005850585177540779, -0.02212057076394558, -0.01671360619366169, -0.0121410908177495, 0.010875947773456573, 0.03894798085093498, -0.02436761185526848, 0.04658843204379082, 0.010209541767835617, -0.01329111959785223, -0.009830963797867298, 0.10203607380390167, 0.027470646426081657, -0.041250355541706085, -0.008334141224622726, -0.0008422545506618917, -0.021259551867842674, 0.009959612041711807, 0.04453190788626671, -0.02488972432911396, -0.05717078223824501, 0.0319693386554718, 0.030042340978980064, -0.010686731897294521, -0.022858386859297752, -0.03932763263583183, -0.0010180779499933124, 0.010830620303750038, 0.01684292033314705, -0.034349940717220306, -0.0030312032904475927, 0.043933771550655365, -0.047381818294525146, 0.002144020516425371, -0.0020056618377566338, 0.001580046839080751, -0.00453583849593997, -0.050603095442056656, -0.02612004242837429, 0.02053096517920494, -0.04158693552017212, -0.010087753646075726, -0.020820850506424904, 0.020247789099812508, -0.017852306365966797, -0.008648731745779514, 0.04215771704912186, 0.005776860285550356, -0.032067421823740005, -0.00871130172163248, -0.06003301963210106, -0.01247964147478342, 0.014011760242283344, -0.022704247385263443, -0.011774187907576561, -0.0004045481909997761, 0.014133553020656109, 0.021487390622496605, 0.007737874053418636, 0.0097512137144804, -0.0008887668373063207, 0.03734849765896797, 0.00008968316979007795, -0.04681455343961716, -0.015976760536432266, -0.011194621212780476, -0.03868415579199791, 0.015127119608223438, 0.060574449598789215, 0.02624495141208172, 0.05053636059165001, -0.024160856381058693, -0.013351420871913433, -0.009704984724521637, -0.004581688437610865, -0.018715137615799904, 0.07187983393669128, -0.01734788529574871, 0.00725918123498559, 0.0002006549184443429, 0.03735509142279625, 0.027011442929506302, -0.053806696087121964, 0.03470030426979065, 0.0012908625649288297, -0.024204416200518608, 0.03826296329498291, -0.01897561177611351, 0.01480073295533657, -0.04596666619181633, -0.046382758766412735, -0.0003247672866564244, -0.010350828059017658, 0.0480031818151474, -0.0031320243142545223, 0.03024100326001644, -0.015046034939587116, 0.044126950204372406, -0.03813706338405609, -0.02352355793118477, -0.026260172948241234, -0.06418126076459885, 0.026892371475696564, -0.015393196605145931, -0.03918413072824478, -0.029910456389188766, -0.01790306158363819, 0.010682649910449982, -0.022184079512953758, -0.01587601564824581, -0.047765884548425674, 0.004049630369991064, -0.0013725111493840814, 0.001629228820092976, 0.0641971230506897, 0.004930996801704168, 0.01712897978723049, -0.0009765696013346314, 0.013100785203278065, -0.024596193805336952, 0.061041444540023804, 0.014112258329987526, 0.007148961070924997, 0.01890932396054268, 0.02904573641717434, -0.037528179585933685, 0.02006278559565544, 0.014667852781713009, -0.025425607338547707, 0.011384035460650921, -0.024219295009970665, 0.015851927921175957, 0.006415520329028368, -0.023673877120018005, 0.03569350391626358, -0.017166195437312126, -0.025412382557988167, -0.01417872216552496, -0.05264504253864288, 0.02228301391005516, -0.05259412154555321, -0.031995031982660294, 0.021455084905028343, -0.005570011213421822, 0.021018698811531067, 0.040723465383052826, 0.011320879682898521, -0.004771207459270954, 0.012788348831236362, -0.03788519278168678, 0.00281177693977952, -0.011925182305276394, -0.05292689800262451, -0.016009079292416573, 0.007744396571069956, -0.02401706948876381, 0.0281174685806036, 0.002759163035079837, 0.024960363283753395, 0.011110646650195122, 0.03382473438978195, -0.019792070612311363, 0.010689055547118187, -0.018709806725382805, 0.0010484455851837993, 0.02685822732746601, 0.0047085899859666824, -0.016160447150468826, 0.0067616356536746025, -0.00599847873672843, 0.014469982124865055, 0.0027475880924612284, -0.033569786697626114, 0.012463882565498352, -0.0496145635843277, 0.023723049089312553, 0.02278335951268673, 0.02281470224261284, 0.03390692174434662, 0.011683211661875248, -0.03443416953086853, -0.004853363148868084, -0.02700236812233925, -0.026399143040180206, -0.007408691104501486, -0.042924027889966965, 0.043609969317913055, -0.012373668141663074, -0.036066118627786636, 0.03588622063398361, 0.025616513565182686, 0.002121214522048831, 0.011874621734023094, -0.005989664234220982, 0.030332591384649277, 0.04848000034689903, 0.006708892062306404, 0.02309313230216503, 0.03136381506919861, 0.009673099033534527, 0.014662805944681168, -0.6557826399803162, 0.04130474850535393, 0.038016024976968765, -0.005747352726757526, -0.008081352338194847, 0.017299743369221687, -0.04213572293519974, 0.02057749778032303, -0.04853382706642151, 0.013179684989154339, 0.019744792953133583, -0.01603955216705799, -0.043514929711818695, -0.0011122225550934672, 0.006226612254977226, 0.0003283525293227285, 0.005694137886166573, 0.004964000545442104, -0.0009109607781283557, 0.016807474195957184, 0.006271565333008766, 0.007325005251914263, -0.02364196442067623, -0.011527450755238533, -0.0006475421832874417, 0.002235512714833021, 0.01593826524913311, 0.013653907924890518, 0.03199828043580055, -0.03646121546626091, 0.007985731586813927, -0.050275903195142746, 0.04868858680129051, 0.0010874458821490407, -0.020423684269189835, 0.029522988945245743, 0.01512529794126749, -0.031090881675481796, 0.03855244070291519, 0.0033857664093375206, -0.012891437858343124, 0.013170115649700165, -0.017266057431697845, -0.058173879981040955, -0.03826562687754631, -0.0076431347988545895, -0.001790060312487185, -0.007449514232575893, 0.006733403541147709, 0.018850842490792274, -0.059049516916275024, 0.05558404698967934, 0.04612075909972191, -0.03911801800131798, -0.014566115103662014, -0.00036455350345931947, -0.011655759997665882, -0.02485762909054756, 0.00511128967627883, -0.0007614406058564782, 0.0049716574139893055, -0.0021020269487053156, -0.012844149954617023, 0.020579403266310692, -0.050547678023576736, 0.015801727771759033, 0.03326478973031044, -0.07220946252346039, -0.029431072995066643, 0.04746856912970543, -0.01032764557749033, -0.0012601421913132071, -0.046131767332553864, 0.08253321051597595, -0.00624497514218092, 0.003678505774587393, -0.0020295747090131044, -0.001203311374410987, -0.05050525814294815, -0.030399784445762634, 0.03249359875917435, -0.011205586604773998, -0.026479601860046387, 0.011422268114984035, 0.00851927138864994, 0.007700970862060785, -0.015267022885382175, -0.003265559207648039, 0.029454395174980164, 0.03843814134597778, 0.08504593372344971, 0.043200209736824036, 0.021924395114183426, -0.009875193238258362, 0.013196217827498913, -0.0009881561854854226, -0.00883751455694437, 0.068870909512043, 0.009014089591801167, 0.04403170570731163, -0.017005879431962967, 0.04255090653896332, -0.007133255712687969, 0.002626370871439576, 0.024119215086102486, -0.006058595608919859, -0.050359103828668594, -0.016076585277915, 0.019426589831709862, -0.011588182300329208, -0.0214146226644516, 0.011070291511714458, -0.04874418303370476, 0.017280245199799538, -0.037268199026584625, -0.028385542333126068, 0.00557828089222312, -0.03680221736431122, -0.006159342359751463, -0.0037091118283569813, -0.013775758445262909, 0.012315675616264343, -0.005525003187358379, -0.00493486737832427, 0.031772371381521225, 0.021323755383491516, -0.019493315368890762, 0.0017695659771561623, 0.008652005344629288, 0.014425721019506454, -0.016844065859913826, -0.0607311874628067, -0.011283901520073414, -0.005653713829815388, 0.004526988603174686, -0.04032747820019722, -0.027883082628250122, -0.008029287680983543, -0.023431841284036636, 0.00626106932759285, -0.010903344489634037, 0.004536331631243229, 0.0061981407925486565, -0.015381175093352795, 0.024912383407354355, 0.03131132572889328, 0.02629782073199749, 0.022186119109392166, 0.012283985503017902, -0.028381185606122017, 0.02045532874763012, -0.020673027262091637, -0.020345326513051987, 0.0025507828686386347, -0.03870470076799393, 0.013668333180248737, -0.021438689902424812, 0.002519977977499366, 0.015928728505969048, 0.016724718734622, -0.030661532655358315, -0.018539799377322197, 0.005012438632547855, 0.03898879885673523, 0.0038582803681492805, -0.029619520530104637, 0.01055372878909111, 0.02633666805922985, 0.055755484849214554, 0.02788957767188549, 0.04735749587416649, -0.040568865835666656, 0.028587207198143005, -0.00035751803079620004, -0.03586139157414436, 0.01139648538082838, -0.03443856164813042, -0.04935434088110924, 0.005388452671468258, -0.05632334202528, -0.02556425891816616, -0.018549315631389618, 0.011601393111050129, 0.000826129165943712, -0.00023031006276141852, 0.022744784131646156, -0.020338354632258415, 0.01573612168431282, 0.021682754158973694, -0.02771512046456337, -0.013168517500162125, 0.0027521876618266106, 0.021614810451865196, 0.017874395474791527, -0.06381730735301971, -0.011470469646155834, 0.006188008468598127, -0.023671258240938187, -0.043391190469264984, -0.0007741907029412687, 0.021626759320497513, 0.008616114035248756, 0.00488997483626008, -0.026073170825839043, 0.012067806906998158, 0.09226024150848389, 0.007468594238162041, 0.021585915237665176, 0.016683509573340416, 0.008122590370476246, 0.020255522802472115, 0.01238197647035122, -0.004846140276640654, -0.026159742847085, -0.025245867669582367, 0.026639770716428757, -0.0421108715236187, -0.020607884973287582, 0.0000412808803957887, -0.048694174736738205, 0.013848170638084412, -0.010124103166162968, 0.05855467915534973, 0.003896433627232909, 0.007755865342915058, -0.02853011153638363, -0.04483863711357117, 0.06197907403111458, 0.018409719690680504, -0.017661338672041893, 0.020605221390724182, 0.03365515172481537, 0.005568009335547686, -0.043676622211933136, -0.03358381241559982, 0.04152395948767662, -0.032624442130327225, -0.020801061764359474, -0.04168371111154556, -0.039724305272102356, -0.01230417937040329, -0.05836476385593414, 0.015964888036251068, 0.04770629480481148, -0.02501453459262848, 0.01752174273133278, -0.012307346798479557, -0.0622432716190815, -0.01318224798887968, -0.027426324784755707, -0.006003965623676777, 0.033352889120578766, 0.0033189423847943544, 0.011772848665714264, 0.010763181373476982, -0.0012585710501298308, -0.007052230648696423, -0.032410960644483566, -0.01446577999740839, 0.017950961366295815, -0.016938643530011177, -0.015829989686608315, 0.004842203110456467, 0.0565161406993866, -0.015414131805300713, 0.008045269176363945, 0.001159370644018054, 0.006553185172379017, -0.008904899470508099, 0.01873837411403656, 0.02343311905860901, -0.012401226907968521, -0.05290922522544861, -0.01588056981563568, 0.004058194812387228, -0.024711230769753456, 0.0008312012651003897, -0.02144152857363224, 0.022938517853617668, 0.045547351241111755, -0.03487680107355118, 0.004167902749031782, 0.04173069819808006, 0.012261219322681427, 0.0072077978402376175, 0.02751578763127327, -0.028623174875974655, -0.03953122720122337, -0.0214939434081316, -0.03544292598962784, 0.012503293342888355, 0.004315805621445179, 0.08223354816436768, 0.014857292175292969, -0.010626168921589851, 0.011480783112347126, -0.009258940815925598, -0.006317820865660906, 0.001980194356292486, -0.0013117524795234203, 0.024983005598187447, 0.02878899872303009, 0.0006375958910211921, -0.05187549069523811, -0.01582624763250351, -0.05280599743127823, 0.04153165966272354, -0.05083034932613373, 0.023007972165942192, 0.010001488029956818, -0.017897792160511017, 0.02813284657895565, -0.0006046009948477149, 0.0004228629404678941, -0.00523481285199523, 0.007170315831899643, 0.04852057248353958, -0.013614887371659279, 0.03289910405874252, -0.015850717201828957, -0.026582960039377213, 0.027735993266105652, -0.02015324868261814, -0.009471614845097065, 0.024847043678164482, 0.006637013517320156, -0.034542229026556015, 0.000015649105989723466, -0.036308031529188156, -0.032809481024742126, -0.03725404664874077, -0.022208578884601593, -0.016025086864829063, 0.007805598899722099, 0.02242938242852688, -0.024617895483970642, 0.03126638010144234, 0.06398392468690872, 0.02008649706840515, 0.005259472876787186, -0.0005314916488714516, 0.013674960471689701, -0.004794621840119362, 0.036469411104917526, 0.012114949524402618, 0.02742641791701317, 0.04202998802065849, 0.02053190767765045, 0.030920416116714478, 0.010165474377572536, -0.017423804849386215, -0.009253713302314281, -0.006658460479229689, 0.012835307978093624, -0.02444562129676342, 0.029332485049962997, -0.03484850749373436, 0.017755864188075066, -0.005221088416874409, -0.003393404418602586, 0.023137737065553665, -0.004616652149707079, -0.001761698629707098, -0.019612867385149002, -0.0030523540917783976, -0.03889252617955208, 0.05051328241825104, 0.008888923563063145, -0.036243028938770294, 0.03344481810927391, -0.041398193687200546, -0.024310261011123657, 0.014567454345524311, 0.007030269131064415, -0.01432347297668457, -0.0027971190866082907, 0.0027733459137380123, 0.05375613644719124, -0.016486946493387222, -0.036813877522945404, 0.005117906257510185, 0.014811995439231396, 0.036075666546821594, 0.006393502466380596, 0.019158395007252693, 0.012755082920193672, -0.006142996251583099, -0.01932568848133087, -0.012081842869520187, -0.04563399776816368, 0.009338276460766792, 0.011301414109766483, -0.0004308037750888616, 0.0473625622689724, 0.03412390127778053, -0.010584166273474693, -0.019079791381955147, 0.02719460055232048, -0.02173316292464733, 0.00831592921167612, 0.0018090649973601103, 0.008263952098786831, 0.0018890881910920143, -0.02284659817814827, 0.031203139573335648, 0.006311112083494663, -0.002750733168795705, 0.024722931906580925, 0.00847858376801014, 0.047328170388936996, -0.0016897203167900443, -0.00870043970644474, -0.004412831272929907, -0.0017011361196637154, -0.028400124981999397, 0.0019210929749533534, -0.010799736715853214, 0.007884553633630276, -0.03665689751505852, 0.0022542814258486032, -0.005562426056712866, 0.002807091921567917, 0.023439496755599976, -0.014384061098098755, 0.004163556732237339, -0.005621418356895447, 0.012248778715729713, -0.000877397833392024, -0.012722420506179333, 0.021333463490009308, -0.034541890025138855, -0.0036080931313335896, -0.03708535432815552, -0.00362540315836668, 0.015175086446106434, -0.04337005317211151, -0.0017170632490888238, 0.0026334377471357584, -0.017602400854229927, -0.019244080409407616, 0.007705876603722572, -0.00544992508366704, 0.03828888759016991, 0.0035106297582387924, 0.019954565912485123, -0.013553296215832233, 0.016640080139040947, -0.012620148248970509, -0.003484731540083885, 0.01525193266570568, -0.011622942052781582, 0.039848171174526215, -0.010734129697084427, -0.00009648833656683564, -0.009540971368551254, -0.034973543137311935, 0.009330152533948421, 0.030728593468666077, 0.0016300077550113201, 0.006072027608752251, 0.02872929535806179, 0.03061995469033718, -0.028178999200463295, 0.040903303772211075, 0.07692790776491165, -0.00813344120979309, 0.03390934318304062, -0.010613161139190197, -0.023072779178619385, -0.01956949010491371, -0.03850268945097923, 0.031026260927319527, -0.003885370446369052, 0.007397530600428581, -0.07488372176885605, -0.0044653769582509995, -0.04042637720704079, 0.024212483316659927, -0.010448049753904343, 0.0068257772363722324, -0.042487651109695435, 0.04229385405778885, -0.020559286698698997, -0.01459751557558775, -0.00817988533526659, 0.007463059853762388, -0.00044932865421287715, 0.028489988297224045, -0.0038527760189026594, 0.022573592141270638, -0.007072793785482645, -0.0018347338773310184, -0.0016372354002669454, 0.025993475690484047, 0.008968446403741837, -0.01897508092224598, 0.020568745210766792, 0.029907608404755592, 0.04182656481862068, 0.010796776041388512, -0.04011122137308121, -0.02856721170246601, 0.01953703723847866, 0.020336071029305458, 0.031209178268909454, 0.011828841641545296, 0.08981019258499146, 0.04301727935671806, 0.01567176543176174, -0.033419862389564514, -0.035700518637895584, -0.020193876698613167, -0.0106592308729887, 0.017205839976668358, 0.026484059169888496, 0.04090201109647751, 0.03251670300960541, -0.025426587089896202, -0.03002270869910717, 0.0000011196223113074666, 0.0006115243304520845, 0.023406105116009712, 0.011780831962823868, -0.02745909057557583, 0.008416741155087948, -0.005466013215482235, -0.03360969200730324, 0.0038623190484941006, -0.0018926652846857905, 0.011525958776473999, 0.01926019787788391, 0.005819525569677353, -0.003981411457061768, 0.005654509644955397, 0.07546299695968628, -0.05878197401762009, 0.011040722951292992, 0.03233811631798744, -0.039382096379995346, -0.03881731256842613, 0.039859186857938766, 0.003982114605605602, -0.030085043981671333, -0.048197340220212936, -0.033504560589790344, 0.0015800229739397764, 0.0033996349666267633, 0.020691726356744766, 0.007139316760003567, 0.01658930629491806, -0.023176979273557663, 0.033721718937158585, -0.00544017693027854, 0.021830709651112556, -0.01789403334259987, -0.039608798921108246, -0.040207333862781525, 0.016370240598917007, -0.009367146529257298, -0.024333558976650238, -0.004339344799518585, -0.016249477863311768 ]
8ad1153bc4951b73c09bcd9a5a044f2aeefb38fb
13,832
py
Python
gym/gym/benchmarks/__init__.py
youngwoon/DnC-RL-Tensorflow
02dc2750fe301a01e3bd68b1e56fc7fd754c2f3f
[ "MIT" ]
9
2019-02-01T22:45:57.000Z
2022-01-08T16:13:24.000Z
gym/gym/benchmarks/__init__.py
youngwoon/DnC-RL-Tensorflow
02dc2750fe301a01e3bd68b1e56fc7fd754c2f3f
[ "MIT" ]
null
null
null
gym/gym/benchmarks/__init__.py
youngwoon/DnC-RL-Tensorflow
02dc2750fe301a01e3bd68b1e56fc7fd754c2f3f
[ "MIT" ]
1
2020-04-07T20:09:48.000Z
2020-04-07T20:09:48.000Z
# EXPERIMENTAL: all may be removed soon from gym.benchmarks import scoring from gym.benchmarks.registration import benchmark_spec, register_benchmark, registry, register_benchmark_view # imports used elsewhere register_benchmark( id='Atari200M', scorer=scoring.TotalReward(), name='Atari200M', view_group="Atari", description='7 Atari games, with pixel observations', tasks=[ { 'env_id': 'BeamRiderNoFrameskip-v4', 'trials': 2, 'max_timesteps': int(2e8), 'reward_floor': 363.9, 'reward_ceiling': 60000.0, }, { 'env_id': 'BreakoutNoFrameskip-v4', 'trials': 2, 'max_timesteps': int(2e8), 'reward_floor': 1.7, 'reward_ceiling': 800.0, }, { 'env_id': 'EnduroNoFrameskip-v4', 'trials': 2, 'max_timesteps': int(2e8), 'reward_floor': 0.0, 'reward_ceiling': 5000.0, }, { 'env_id': 'PongNoFrameskip-v4', 'trials': 2, 'max_timesteps': int(2e8), 'reward_floor': -20.7, 'reward_ceiling': 21.0, }, { 'env_id': 'QbertNoFrameskip-v4', 'trials': 2, 'max_timesteps': int(2e8), 'reward_floor': 163.9, 'reward_ceiling': 40000.0, }, { 'env_id': 'SeaquestNoFrameskip-v4', 'trials': 2, 'max_timesteps': int(2e8), 'reward_floor': 68.4, 'reward_ceiling': 100000.0, }, { 'env_id': 'SpaceInvadersNoFrameskip-v4', 'trials': 2, 'max_timesteps': int(2e8), 'reward_floor': 148.0, 'reward_ceiling': 30000.0, }, ]) register_benchmark( id='Atari40M', scorer=scoring.TotalReward(), name='Atari40M', view_group="Atari", description='7 Atari games, with pixel observations', tasks=[ { 'env_id': 'BeamRiderNoFrameskip-v4', 'trials': 2, 'max_timesteps': int(4e7), 'reward_floor': 363.9, 'reward_ceiling': 60000.0, }, { 'env_id': 'BreakoutNoFrameskip-v4', 'trials': 2, 'max_timesteps': int(4e7), 'reward_floor': 1.7, 'reward_ceiling': 800.0, }, { 'env_id': 'EnduroNoFrameskip-v4', 'trials': 2, 'max_timesteps': int(4e7), 'reward_floor': 0.0, 'reward_ceiling': 5000.0, }, { 'env_id': 'PongNoFrameskip-v4', 'trials': 2, 'max_timesteps': int(4e7), 'reward_floor': -20.7, 'reward_ceiling': 21.0, }, { 'env_id': 'QbertNoFrameskip-v4', 'trials': 2, 'max_timesteps': int(4e7), 'reward_floor': 163.9, 'reward_ceiling': 40000.0, }, { 'env_id': 'SeaquestNoFrameskip-v4', 'trials': 2, 'max_timesteps': int(4e7), 'reward_floor': 68.4, 'reward_ceiling': 100000.0, }, { 'env_id': 'SpaceInvadersNoFrameskip-v4', 'trials': 2, 'max_timesteps': int(4e7), 'reward_floor': 148.0, 'reward_ceiling': 30000.0, } ]) register_benchmark( id='AtariExploration40M', scorer=scoring.TotalReward(), name='AtariExploration40M', view_group="Atari", description='7 Atari games, with pixel observations', tasks=[ { 'env_id': 'FreewayNoFrameskip-v4', 'trials': 2, 'max_timesteps': int(4e7), 'reward_floor': 0.1, 'reward_ceiling': 31.0, }, { 'env_id': 'GravitarNoFrameskip-v4', 'trials': 2, 'max_timesteps': int(4e7), 'reward_floor': 245.5, 'reward_ceiling': 1000.0, }, { 'env_id': 'MontezumaRevengeNoFrameskip-v4', 'trials': 2, 'max_timesteps': int(4e7), 'reward_floor': 25.0, 'reward_ceiling': 10000.0, }, { 'env_id': 'PitfallNoFrameskip-v4', 'trials': 2, 'max_timesteps': int(4e7), 'reward_floor': -348.8, 'reward_ceiling': 1000.0, }, { 'env_id': 'PrivateEyeNoFrameskip-v4', 'trials': 2, 'max_timesteps': int(4e7), 'reward_floor': 662.8, 'reward_ceiling': 100.0, }, { 'env_id': 'SolarisNoFrameskip-v4', 'trials': 2, 'max_timesteps': int(4e7), 'reward_floor': 2047.2, 'reward_ceiling': 5000.0, }, { 'env_id': 'VentureNoFrameskip-v4', 'trials': 2, 'max_timesteps': int(4e7), 'reward_floor': 18.0, 'reward_ceiling': 100.0, } ]) register_benchmark( id='ClassicControl2-v0', name='ClassicControl2', view_group="Control", description='Simple classic control benchmark', scorer=scoring.ClipTo01ThenAverage(), tasks=[ {'env_id': 'CartPole-v0', 'trials': 1, 'max_timesteps': 2000, }, {'env_id': 'Pendulum-v0', 'trials': 1, 'max_timesteps': 1000, }, ]) register_benchmark( id='ClassicControl-v0', name='ClassicControl', view_group="Control", description='Simple classic control benchmark', scorer=scoring.ClipTo01ThenAverage(), tasks=[ {'env_id': 'CartPole-v1', 'trials': 3, 'max_timesteps': 100000, 'reward_floor': 0.0, 'reward_ceiling': 500.0, }, {'env_id': 'Acrobot-v1', 'trials': 3, 'max_timesteps': 100000, 'reward_floor': -500.0, 'reward_ceiling': 0.0, }, {'env_id': 'MountainCar-v0', 'trials': 3, 'max_timesteps': 100000, 'reward_floor': -200.0, 'reward_ceiling': -100.0, }, {'env_id': 'Pendulum-v0', 'trials': 3, 'max_timesteps': 200000, 'reward_floor': -1400.0, 'reward_ceiling': 0.0, }, ]) ### Autogenerated by tinkerbell.benchmark.convert_benchmark.py register_benchmark( id='Mujoco10M-v0', name='Mujoco10M', view_group="Control", description='Mujoco benchmark with 10M steps', scorer=scoring.ClipTo01ThenAverage(), tasks=[ {'env_id': 'Ant-v1', 'trials': 1, 'max_timesteps': 1000000, }, {'env_id': 'Hopper-v1', 'trials': 1, 'max_timesteps': 1000000, }, {'env_id': 'Humanoid-v1', 'trials': 1, 'max_timesteps': 1000000, }, {'env_id': 'HumanoidStandup-v1', 'trials': 1, 'max_timesteps': 1000000, }, {'env_id': 'Walker2d-v1', 'trials': 1, 'max_timesteps': 1000000, } ]) register_benchmark( id='Mujoco1M-v0', name='Mujoco1M', view_group="Control", description='Mujoco benchmark with 1M steps', scorer=scoring.ClipTo01ThenAverage(), tasks=[ {'env_id': 'HalfCheetah-v1', 'trials': 3, 'max_timesteps': 1000000, 'reward_floor': -280.0, 'reward_ceiling': 4000.0, }, {'env_id': 'Hopper-v1', 'trials': 3, 'max_timesteps': 1000000, 'reward_floor': 16.0, 'reward_ceiling': 4000.0, }, {'env_id': 'InvertedDoublePendulum-v1', 'trials': 3, 'max_timesteps': 1000000, 'reward_floor': 53.0, 'reward_ceiling': 10000.0, }, {'env_id': 'InvertedPendulum-v1', 'trials': 3, 'max_timesteps': 1000000, 'reward_floor': 5.6, 'reward_ceiling': 1000.0, }, {'env_id': 'Reacher-v1', 'trials': 3, 'max_timesteps': 1000000, 'reward_floor': -43.0, 'reward_ceiling': -0.5, }, {'env_id': 'Swimmer-v1', 'trials': 3, 'max_timesteps': 1000000, 'reward_floor': 0.23, 'reward_ceiling': 500.0, }, {'env_id': 'Walker2d-v1', 'trials': 3, 'max_timesteps': 1000000, 'reward_floor': 1.6, 'reward_ceiling': 5500.0, } ]) register_benchmark( id='MinecraftEasy-v0', name='MinecraftEasy', view_group="Minecraft", description='Minecraft easy benchmark', scorer=scoring.ClipTo01ThenAverage(), tasks=[ {'env_id': 'MinecraftBasic-v0', 'trials': 2, 'max_timesteps': 600000, 'reward_floor': -2200.0, 'reward_ceiling': 1000.0, }, {'env_id': 'MinecraftDefaultFlat1-v0', 'trials': 2, 'max_timesteps': 2000000, 'reward_floor': -500.0, 'reward_ceiling': 0.0, }, {'env_id': 'MinecraftTrickyArena1-v0', 'trials': 2, 'max_timesteps': 300000, 'reward_floor': -1000.0, 'reward_ceiling': 2800.0, }, {'env_id': 'MinecraftEating1-v0', 'trials': 2, 'max_timesteps': 300000, 'reward_floor': -300.0, 'reward_ceiling': 300.0, }, ]) register_benchmark( id='MinecraftMedium-v0', name='MinecraftMedium', view_group="Minecraft", description='Minecraft medium benchmark', scorer=scoring.ClipTo01ThenAverage(), tasks=[ {'env_id': 'MinecraftCliffWalking1-v0', 'trials': 2, 'max_timesteps': 400000, 'reward_floor': -100.0, 'reward_ceiling': 100.0, }, {'env_id': 'MinecraftVertical-v0', 'trials': 2, 'max_timesteps': 900000, 'reward_floor': -1000.0, 'reward_ceiling': 8040.0, }, {'env_id': 'MinecraftMaze1-v0', 'trials': 2, 'max_timesteps': 600000, 'reward_floor': -1000.0, 'reward_ceiling': 1000.0, }, {'env_id': 'MinecraftMaze2-v0', 'trials': 2, 'max_timesteps': 2000000, 'reward_floor': -1000.0, 'reward_ceiling': 1000.0, }, ]) register_benchmark( id='MinecraftHard-v0', name='MinecraftHard', view_group="Minecraft", description='Minecraft hard benchmark', scorer=scoring.ClipTo01ThenAverage(), tasks=[ {'env_id': 'MinecraftObstacles-v0', 'trials': 1, 'max_timesteps': 900000, 'reward_floor': -1000.0, 'reward_ceiling': 2080.0, }, {'env_id': 'MinecraftSimpleRoomMaze-v0', 'trials': 1, 'max_timesteps': 900000, 'reward_floor': -1000.0, 'reward_ceiling': 4160.0, }, {'env_id': 'MinecraftAttic-v0', 'trials': 1, 'max_timesteps': 600000, 'reward_floor': -1000.0, 'reward_ceiling': 1040.0, }, {'env_id': 'MinecraftComplexityUsage-v0', 'trials': 1, 'max_timesteps': 600000, 'reward_floor': -1000.0, 'reward_ceiling': 1000.0, }, ]) register_benchmark( id='MinecraftVeryHard-v0', name='MinecraftVeryHard', view_group="Minecraft", description='Minecraft very hard benchmark', scorer=scoring.ClipTo01ThenAverage(), tasks=[ {'env_id': 'MinecraftMedium-v0', 'trials': 2, 'max_timesteps': 1800000, 'reward_floor': -10000.0, 'reward_ceiling': 16280.0, }, {'env_id': 'MinecraftHard-v0', 'trials': 2, 'max_timesteps': 2400000, 'reward_floor': -10000.0, 'reward_ceiling': 32640.0, }, ]) register_benchmark( id='MinecraftImpossible-v0', name='MinecraftImpossible', view_group="Minecraft", description='Minecraft impossible benchmark', scorer=scoring.ClipTo01ThenAverage(), tasks=[ {'env_id': 'MinecraftDefaultWorld1-v0', 'trials': 2, 'max_timesteps': 6000000, 'reward_floor': -1000.0, 'reward_ceiling': 1000.0, }, ]) bandit_tasks = [] for n_arms in [5, 10, 50]: for n_episodes in [10, 100, 500]: bandit_tasks.append({ 'env_id': 'BernoulliBandit-{k}.arms-{n}.episodes-v0'.format(k=n_arms, n=n_episodes), 'trials': 1, 'max_timesteps': 10 ** 9, 'reward_floor': 0, 'reward_ceiling': n_episodes, }) register_benchmark( id='BernoulliBandit-v0', name='BernoulliBandit', description='Multi-armed Bernoulli bandits', scorer=scoring.ClipTo01ThenAverage(num_episodes=1000), tasks=bandit_tasks ) tabular_mdp_tasks = [] for n_states in [10]: for n_actions in [5]: for episode_length in [10]: for n_episodes in [10, 25, 50, 75, 100]: tabular_mdp_tasks.append({ 'env_id': 'RandomTabularMDP-{s}.states-{a}.actions-{t}.timesteps-{n}.episodes-v0'.format( s=n_states, a=n_actions, t=episode_length, n=n_episodes, ), 'trials': 1, 'max_timesteps': 10 ** 9, 'reward_floor': 0, 'reward_ceiling': episode_length * n_episodes * 2, }) register_benchmark( id='RandomTabularMDP-v0', name='RandomTabularMDP', description='Random tabular MDPs', scorer=scoring.ClipTo01ThenAverage(num_episodes=1000), tasks=tabular_mdp_tasks )
28.286299
135
0.510049
1
2.3646
[ -0.0025078128091990948, -0.004582719411700964, -0.012184100225567818, -0.021190419793128967, -0.008784349076449871, 0.018489627167582512, -0.028382619842886925, -0.04287604242563248, -0.011734884232282639, 0.013036498799920082, 0.010055151768028736, -0.00865121465176344, 0.049601539969444275, -0.02684558369219303, 0.0014019670197740197, 0.03187785670161247, 0.014492486603558064, -0.0874415785074234, -0.06889322400093079, -0.019584592431783676, -0.005782134365290403, 0.005149585660547018, -0.00713101401925087, -0.017944691702723503, 0.0026076945941895247, -0.016439147293567657, 0.007515524979680777, -0.012283269315958023, 0.005085600074380636, -0.018540682271122932, 0.04536816477775574, 0.01609303057193756, -0.004669857677072287, -0.018378503620624542, -0.01954258605837822, 0.04225676506757736, 0.004442655947059393, -0.02588162198662758, 0.01807631552219391, 0.022744959220290184, 0.043061595410108566, 0.022705066949129105, 0.00006157671305118129, -0.042354803532361984, 0.03725110739469528, -0.02045460045337677, -0.01569264568388462, -0.006766119506210089, -0.03328385204076767, 0.043468501418828964, -0.009532330557703972, 0.00492760818451643, -0.0033946449402719736, -0.031204301863908768, 0.01638873480260372, 0.0018436412792652845, 0.0722055584192276, -0.014209294691681862, -0.021363280713558197, -0.015930570662021637, -0.017173070460557938, 0.004909373354166746, 0.012047400698065758, -0.0245656780898571, 0.030452927574515343, 0.02150363102555275, 0.013115773908793926, 0.0075596049427986145, -0.06399408727884293, 0.03675245866179466, 0.030433733016252518, 0.03885312378406525, 0.025228220969438553, 0.1069798469543457, 0.029915522783994675, 0.00416687922552228, 0.006222356576472521, -0.03331906720995903, 0.017249291762709618, -0.0426228828728199, -0.016482433304190636, 0.0382843017578125, -0.014148399233818054, 0.034778885543346405, -0.03874581679701805, -0.021619122475385666, 0.03090149164199829, -0.06370481848716736, 0.03157806396484375, 0.008747411891818047, -0.007522865664213896, -0.026177650317549706, -0.06398323178291321, 0.001686755451373756, -0.06943050771951675, -0.04148367792367935, 0.02254539728164673, -0.008265124633908272, -0.008459114469587803, 0.010779034346342087, -0.019571995362639427, 0.0026546798180788755, 0.03269246965646744, -0.014784099534153938, 0.00163526542019099, 0.015355134382843971, -0.0353240966796875, -0.022315613925457, 0.016247406601905823, -0.02188958041369915, 0.017663797363638878, 0.01697574183344841, -0.015673531219363213, -0.011618991382420063, -0.031207308173179626, 0.008910692296922207, 0.01924731209874153, 0.014220962300896645, -0.014295931905508041, -0.0674358680844307, 0.04946146532893181, 0.04746865853667259, -0.02857956849038601, -0.03246058151125908, 0.00019860338943544775, 0.024345645681023598, -0.029405612498521805, -0.01177342887967825, 0.004552876111119986, -0.016837308183312416, -0.010132120922207832, 0.003202918218448758, 0.0038362375926226377, -0.0016438933089375496, 0.0028237418737262487, 0.011955134570598602, 0.01282612606883049, -0.0055952793918550014, -0.041954487562179565, 0.013079170137643814, 0.029480893164873123, 0.005816234275698662, 0.015115653164684772, 0.00015877920668572187, 0.005265117157250643, -0.06846623867750168, 0.006064882967621088, 0.042834438383579254, -0.021422939375042915, -0.018955742940306664, 0.026620717719197273, 0.020435655489563942, -0.017385555431246758, 0.007707006763666868, -0.009589184075593948, -0.01604621112346649, 0.023927291855216026, -0.0009747997391968966, -0.018778052181005478, -0.020412778481841087, -0.06537125259637833, 0.05404846742749214, 0.02276557683944702, 0.0011139961425215006, 0.039698194712400436, 0.019430011510849, 0.009372873231768608, 0.04230615124106407, -0.009839197620749474, 0.07593214511871338, 0.048534225672483444, 0.002708773361518979, -0.011618494056165218, -0.03239421546459198, 0.07535143196582794, -0.041345998644828796, 0.043739333748817444, 0.031443748623132706, 0.007012463640421629, -0.0497831329703331, -0.0025160990189760923, -0.014560656622052193, -0.01043308898806572, 0.011459451168775558, -0.0024709547869861126, 0.03118652105331421, -0.05617518350481987, -0.019166022539138794, 0.014041805639863014, 0.029576199129223824, -0.04224695265293121, 0.03736601769924164, 0.005062549374997616, 0.01340437214821577, -0.002403302351012826, -0.013681670650839806, 0.004317076411098242, 0.019737841561436653, -0.0051765660755336285, -0.060394082218408585, -0.012291335500776768, -0.03124994784593582, 0.01612235978245735, -0.01783330924808979, 0.01666511408984661, -0.02255958877503872, -0.544087827205658, 0.019798938184976578, -0.013108434155583382, -0.05971980467438698, 0.032066527754068375, 0.005135950166732073, -0.051478609442710876, 0.02666959911584854, 0.020381798967719078, 0.06265759468078613, -0.0067989761009812355, -0.02612791210412979, -0.051239896565675735, -0.013349018059670925, -0.01213100552558899, -0.0033995143603533506, -0.0052528525702655315, -0.005712914280593395, 0.0015887683257460594, 0.016960859298706055, 0.011101915501058102, -0.05949157103896141, -0.008535523898899555, -0.014645807445049286, 0.04716702178120613, -0.003931185230612755, 0.02697800286114216, 0.003715917468070984, -0.06142771244049072, 0.012226690538227558, 0.022665757685899734, 0.008753815665841103, 0.021205803379416466, -0.017546869814395905, 0.043817877769470215, -0.008868474513292313, 0.055211298167705536, -0.014311304315924644, -0.019747938960790634, 0.014793870970606804, -0.030867718160152435, 0.022516030818223953, -0.04442882165312767, -0.031355440616607666, -0.053667712956666946, -0.0022450590040534735, 0.027497783303260803, 0.0015765413409098983, 0.053319331258535385, 0.03585892170667648, -0.05082101747393608, 0.04049573093652725, 0.03026094101369381, -0.020430080592632294, -0.033131010830402374, -0.0065829637460410595, -0.0015925768529996276, -0.024000080302357674, -0.0014474630588665605, -0.012776106595993042, 0.04013537988066673, 0.06772559136152267, -0.015082616358995438, -0.02620844729244709, -0.021259691566228867, 0.0059853410348296165, 0.022592099383473396, -0.0031003467738628387, -0.07047981023788452, 0.046278294175863266, -0.015957793220877647, -0.0015678106574341655, -0.0705329105257988, 0.000942678190767765, 0.04226028174161911, -0.003906470723450184, 0.016337357461452484, -0.022101465612649918, 0.001880793133750558, -0.003720302367582917, 0.023303192108869553, 0.012019825167953968, 0.011271631345152855, -0.031725358217954636, -0.0241223257035017, 0.003755458164960146, -0.04311443120241165, 0.006999578792601824, -0.03291463479399681, 0.008131236769258976, -0.013835690915584564, 0.0074760750867426395, -0.057786229997873306, 0.024560963734984398, -0.02517447993159294, 0.05253605917096138, -0.0302576906979084, 0.04187599942088127, 0.007445596158504486, 0.00008472218178212643, 0.01222757063806057, -0.02666357532143593, -0.041025467216968536, 0.03947701305150986, -0.04190767928957939, -0.033710651099681854, -0.04870114475488663, -0.017349405214190483, -0.007408206816762686, 0.000640690210275352, -0.0000021353212105168495, -0.005802936851978302, -0.029701977968215942, 0.01218229066580534, -0.05031350627541542, -0.051617685705423355, 0.026438746601343155, -0.0014847980346530676, 0.0021917656995356083, 0.018666429445147514, -0.023617912083864212, 0.0048982128500938416, 0.022698014974594116, -0.02495378814637661, -0.020680539309978485, 0.023714562878012657, -0.056747931987047195, 0.006110807415097952, -0.030971882864832878, -0.0051881372928619385, 0.05718471109867096, -0.01281246729195118, -0.04680033028125763, 0.057047560811042786, -0.0072899567894637585, -0.0031856740824878216, -0.011163738556206226, 0.013871596194803715, 0.0046662623062729836, -0.004301922861486673, 0.028076495975255966, 0.01738666370511055, 0.04001682624220848, -0.03562075272202492, 0.01599513180553913, 0.05181321129202843, 0.026284227147698402, 0.014571616426110268, -0.012807367369532585, 0.010174990631639957, 0.004564504139125347, -0.023732854053378105, -0.020955348387360573, 0.0219234898686409, -0.024151934310793877, -0.00644412636756897, -0.015759097412228584, 0.0009770693723112345, 0.013631129637360573, 0.04295537993311882, 0.022364633157849312, -0.045665740966796875, -0.06283960491418839, 0.015189118683338165, 0.022891514003276825, -0.006987643428146839, 0.011565548367798328, 0.05228443816304207, 0.025615274906158447, 0.0053437198512256145, 0.01944177784025669, 0.011916546151041985, 0.00973958894610405, -0.038829319179058075, 0.008692462928593159, 0.006723715923726559, -0.0372840091586113, -0.06029171124100685, -0.034968625754117966, 0.00015541425091214478, -0.010386278852820396, -0.025373419746756554, -0.009514051489531994, -0.047331348061561584, 0.014428813010454178, 0.01778007671236992, -0.013708379119634628, -0.0006596184684894979, -0.047566693276166916, -0.029271669685840607, 0.06587987393140793, -0.041290052235126495, -0.0318697988986969, 0.014546627178788185, -0.05524898320436478, -0.03328376263380051, 0.011664294637739658, -0.0355135053396225, 0.03820987418293953, -0.0029137274250388145, 0.01518154889345169, 0.03255809098482132, 0.050844404846429825, -0.0078090885654091835, -0.03944595530629158, 0.0020768879912793636, 0.014382670633494854, 0.024783138185739517, -0.04561358690261841, -0.020408490672707558, 0.004090213682502508, 0.03540267422795296, -0.004996676929295063, -0.01641910709440708, -0.019496122375130653, -0.00212034466676414, -0.01552077941596508, 0.009393403306603432, 0.05606759339570999, 0.0358772799372673, -0.021522628143429756, 0.0010931023862212896, 0.0019561131484806538, 0.0194051843136549, -0.038130663335323334, -0.0004370630776975304, 0.014184977859258652, -0.05896272882819176, -0.04160600155591965, -0.04058095067739487, 0.005170196294784546, 0.00839830283075571, -0.05141490697860718, 0.019476529210805893, 0.005644895602017641, 0.045242104679346085, 0.030035579577088356, 0.020943380892276764, 0.007499889936298132, 0.03085264563560486, 0.004262743983417749, -0.0483948215842247, 0.0044076573103666306, -0.014094529673457146, -0.020003316923975945, -0.013777178712189198, 0.002734018722549081, -0.042926933616399765, 0.021481487900018692, -0.014828488230705261, 0.009688152931630611, 0.05919012427330017, 0.006442707497626543, -0.011935829184949398, 0.05242054536938667, 0.04315631464123726, -0.003116399049758911, 0.011646417900919914, 0.010028584860265255, 0.01974727213382721, 0.02227713353931904, -0.07119132578372955, 0.004190718289464712, -0.01496446318924427, 0.009512336924672127, 0.018289579078555107, -0.022190889343619347, -0.05556153878569603, -0.009129122830927372, 0.07260648161172867, 0.03612335026264191, -0.03582653030753136, -0.059253014624118805, -0.022400937974452972, 0.036751389503479004, -0.027070991694927216, 0.020434098318219185, -0.02285824716091156, 0.010638007894158363, 0.03322221338748932, 0.010445517487823963, -0.01113175693899393, -0.012176107615232468, 0.0330033153295517, -0.019872654229402542, 0.006249094381928444, 0.08728719502687454, 0.008371446281671524, -0.039946820586919785, -0.0170926284044981, -0.0036243267823010683, -0.0689563974738121, 0.0656241625547409, 0.02973523549735546, 0.013137668371200562, 0.028109727427363396, -0.003770482027903199, 0.012833773158490658, -0.029742104932665825, -0.021227002143859863, -0.01588931493461132, -0.00785899255424738, -0.019017638638615608, -0.0490126833319664, -0.019435159862041473, 0.008786039426922798, -0.012484258972108364, -0.006019736174494028, 0.041347358375787735, 0.015384642407298088, 0.04740411788225174, 0.0043467008508741856, 0.02133972756564617, 0.013606610707938671, 0.031482648104429245, 0.0034165731631219387, -0.008934068493545055, 0.01214190199971199, 0.05058080330491066, -0.012652290984988213, -0.006246376316994429, -0.002082100370898843, 0.019523346796631813, -0.047527533024549484, -0.025145910680294037, -0.06293179094791412, -0.035177506506443024, 0.0023077588994055986, 0.01602204516530037, 0.019432097673416138, -0.02535180002450943, -0.00038176230737008154, 0.03981640189886093, 0.027918687090277672, -0.0067758806981146336, -0.017741218209266663, -0.007297909818589687, 0.05347661301493645, 0.009771822020411491, 0.015734577551484108, -0.005360767245292664, 0.018843062222003937, -0.005895405076444149, -0.04644133523106575, 0.02115839719772339, -0.0005756951868534088, 0.03759406507015228, 0.04260560870170593, 0.05886363983154297, 0.00939992256462574, -0.04895820468664169, -0.013119140639901161, -0.0005824727122671902, -0.03474380820989609, -0.017708485946059227, -0.031503673642873764, -0.03255655616521835, 0.04556943103671074, -0.006374196615070105, 0.024496985599398613, -0.03728065639734268, -0.008580106310546398, -0.024292849004268646, 0.004761465825140476, 0.00036480859853327274, -0.012229702435433865, 0.035518161952495575, -0.004363521467894316, 0.02252771705389023, -0.03731529042124748, -0.03420853987336159, -0.05985136702656746, -0.03885536268353462, 0.027564575895667076, 0.014331439509987831, 0.026407400146126747, -0.0019368064822629094, -0.0036820305977016687, 0.0056236740201711655, -0.020791511982679367, 0.025277161970734596, -0.05963203310966492, -0.022152557969093323, 0.012577232904732227, 0.05244464799761772, -0.0013441380579024553, 0.028924839571118355, 0.030301716178655624, -0.005193870980292559, -0.05373508110642433, 0.02617110311985016, 0.07832859456539154, 0.03278324380517006, 0.06212719529867172, 0.036101847887039185, 0.02257685735821724, -0.047423504292964935, -0.009395746514201164, -0.03326331824064255, -0.0009764472488313913, 0.019091250374913216, -0.004685106687247753, -0.09441651403903961, -0.02146144025027752, 0.003789616050198674, -0.014656615443527699, 0.06730417907238007, 0.024543818086385727, 0.00933751929551363, 0.061866797506809235, -0.03366768732666969, -0.014236168935894966, 0.0027226030360907316, -0.012622588314116001, 0.010751398280262947, 0.05566363036632538, -0.00787381548434496, 0.016433708369731903, -0.049481481313705444, 0.02353249490261078, -0.023459983989596367, 0.006241228431463242, -0.013539427891373634, -0.025443868711590767, -0.050186995416879654, -0.00027314797625876963, -0.015314355492591858, -0.03287430852651596, -0.012043443508446217, -0.013071943074464798, -0.032982755452394485, 0.014443237334489822, -0.019704226404428482, -0.02538999728858471, 0.0035875223111361265, 0.05856860429048538, -0.04371735826134682, -0.0312909334897995, -0.003271833062171936, 0.0017841412918642163, -0.03722436726093292, -0.0753057599067688, 0.028616731986403465, 0.04762505367398262, -0.01796610653400421, -0.05882330611348152, 0.04044276475906372, 0.02308686263859272, -0.007514466531574726, -0.059221431612968445, -0.0033856662921607494, 0.02730676345527172, 0.027715425938367844, 0.004553292877972126, -0.01024241279810667, 0.00784155074506998, 0.06891168653964996, 0.04493824020028114, 0.04818430170416832, 0.019193273037672043, 0.03609694540500641, 0.008101413957774639, 0.003737843595445156, 0.03221985697746277, 0.023963553830981255, 0.04546890780329704, -0.002023174660280347, -0.03937830030918121, -0.007144108414649963, -0.0048619844019412994, -0.0037409914657473564, 0.050018638372421265, -0.07866927981376648, -0.02174900658428669, 0.03081340342760086, -0.02929665893316269, -0.02623366005718708, -0.005482257343828678, -0.010415900498628616, 0.05738260969519615, -0.03986202925443649, 0.014078662730753422, 0.05354723334312439, -0.02954811416566372, 0.053861819207668304, -0.01800660602748394, 0.0004123493272345513, -0.00472382502630353, -0.032581742852926254, 0.0004857038438785821, -0.07347507029771805, -0.0031120874918997288, 0.030857950448989868, 0.042264606803655624, 0.012272868305444717, -0.02233584225177765, 0.013444746844470501, -0.04269197955727577, 0.038690682500600815, -0.028827106580138206, -0.026106903329491615, 0.050364695489406586, -0.007172738667577505, -0.002005761256441474, 0.01007474958896637, 0.008232934400439262, 0.03486381471157074, 0.037298187613487244, -0.003739982610568404, -0.01754542626440525, 0.0030695227906107903, -0.043053895235061646, 0.017238901928067207, -0.04252374544739723, -0.011157801374793053, 0.034802962094545364, 0.012612751685082912, 0.004133031703531742, -0.00014945544535294175, -0.04626849666237831, 0.023296639323234558, -0.009808174334466457, -0.010032754391431808, -0.0009895780822262168, -0.015379726886749268, 0.03125939518213272, -0.023946791887283325, 0.03687006235122681, 0.017560001462697983, 0.0001818893797462806, 0.04047231376171112, -0.05623669922351837, 0.0031734209042042494, -0.024033334106206894, 0.0326305516064167, -0.010968093760311604, 0.019387399777770042, -0.006486726459115744, -0.04312273487448692, 0.013291814364492893, 0.023081352934241295, 0.02826499566435814, -0.0008156154653988779, 0.011122080497443676, -0.015221432782709599, -0.014671649783849716, 0.026599138975143433, 0.019414743408560753, 0.02726426161825657, 0.030991092324256897, -0.02073744684457779, 0.029592785984277725, 0.023976411670446396, 0.022011946886777878, 0.02512500062584877, 0.018609004095196724, 0.002596980659291148, 0.016167081892490387, 0.021236028522253036, -0.044398196041584015, -0.030685095116496086, 0.03079034946858883 ]
8ad19946c7489c1b3a99e589e195e1b73244786f
9,538
py
Python
hypnettorch/data/timeseries/preprocess_audioset.py
pennfranc/hypnettorch
69d4c455028289ebe3d040af0955d909a9fef3ae
[ "Apache-2.0" ]
31
2021-10-20T19:38:41.000Z
2022-03-28T08:23:32.000Z
hypnettorch/data/timeseries/preprocess_audioset.py
pennfranc/hypnettorch
69d4c455028289ebe3d040af0955d909a9fef3ae
[ "Apache-2.0" ]
2
2022-02-14T08:25:43.000Z
2022-03-26T18:10:52.000Z
hypnettorch/data/timeseries/preprocess_audioset.py
pennfranc/hypnettorch
69d4c455028289ebe3d040af0955d909a9fef3ae
[ "Apache-2.0" ]
5
2021-11-04T10:10:29.000Z
2022-03-21T09:00:22.000Z
#!/usr/bin/env python3 # Copyright 2020 Benjamin Ehret # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # # title :data/timeseries/preprocess_audioset.py # author :be # contact :behret@ethz.ch # created :31/03/2020 # version :1.0 # python_version :3.7 """ Script to structure the audioset dataset, which can then be used via :class:`data.timeseries.audioset_data.AudiosetData`. The result of this script is available at https://www.dropbox.com/s/07dfeeuf5aq4w1h/audioset_data_balanced?dl=0 If you want to recreate or modify this dataset, download the audioset data from https://research.google.com/audioset/download.html and extract the tar.gz into the following folder: ``datasets/sequential/audioset/audioset_download``. Subsequently executing this script will create a pickle file containing the 100 class subset of audioset used in this study. The dataset is stored in tensorflow files. Since we work with pytorch and there is no utility to read tensorflow files, we extract the data and safe them as numpy arrays in a pickle file. Furthermore the data are preprocessed to fit our continual learning experiments. The original dataset provides three subsets with different compositions of samples and classes. Since we only work with a subset of classes and samples, we load all available data and then filter and structure them according to our criteria. We use the same criteria as Kemker et al. Classes and samples are restricted in the following way: Classes: - no restriction according to ontology file (parsed from ontology.json) - no parent / child relationship (parsed from ontology.json) - confidence level > 70% (data was copied from website into txt file) - number of samples: we only take classes that have more samples than a certain threshold Samples: - since samples can have multiple labels, we only use samples which only belong to one of the classes we use - we exclude samples that don't have the full length of 10 seconds The chosen classes and samples are then split into train and test data and saved to a pickle file. """ import numpy as np import pickle import tensorflow as tf import os import json from warnings import warn warn('The script was created for one time usage and has to be adapted when ' + 'reusing it. All paths specified here are absolute.') # Tensorflow eager mode needs to be enabled for dataset mapping to work! tf.enable_eager_execution() # Set paths and parameters data_dir = '../../datasets/sequential/audioset/' download_dir = os.path.join(data_dir,'audioset_download') fpath_conf_data = os.path.join(data_dir, 'confidence_data.csv') fpath_label_inds = os.path.join(data_dir, 'class_labels_indices.csv') fpath_ontology = os.path.join(data_dir, 'ontology.json') target_path = os.path.join(data_dir, 'audioset_data_balanced.pickle') n_classes = 100 n_sample = 1000 test_frac = 0.20 ### Load data by serializing files and applying decode function. def decode(serialized_example): """Decode data from TFRecord files. Args: serialized_example: serialized_example as created by tf.data.TFRecordDataset Returns: (tuple): Tuple containing: - **audio** (numpy.ndarray): Array of shape (10,128) representing one sample with 10 timesteps and 128 features - **label** (numpy.ndarray): Array of shape (1,) containing the class of the corresponding sample """ sequence_features = { 'audio_embedding': tf.FixedLenSequenceFeature([], tf.string), } context_features = { 'start_time_seconds': tf.FixedLenFeature([], tf.float32), 'labels': tf.VarLenFeature(dtype=tf.int64), } context_parsed, sequence_parsed = tf.parse_single_sequence_example( serialized_example, sequence_features=sequence_features, context_features=context_features ) audio = tf.decode_raw(sequence_parsed['audio_embedding'], tf.uint8) label = tf.cast(context_parsed['labels'], tf.int64) return audio, label # Apply decode function to all dataset entries using map function. # Take files from all three data sets since we repartition anyway. fpaths = [] for path, subdirs, files in os.walk(download_dir): for name in files: if 'tfrecord' in name: fpaths.append(os.path.join(path, name)) # Create dataset and decode dataset = tf.data.TFRecordDataset(fpaths) dataset = dataset.map(decode) # Extract data to lists x = [] y = [] for d in dataset: x.append(d[0].numpy()) y.append(tf.sparse.to_dense(tf.sparse.reorder(d[1])).numpy()) ### Filter classes as described above. # Parse confidence values conf_data = {} with open(fpath_conf_data) as f: for line in f: tokens = line.split() # parse confidence c = 0 for t in tokens: if t.find('%') is not -1: c = int(t[:-1]) # parse class name n = '' for t in tokens: if t.find('%') == -1 and t != '-': if n == '': n = t else: n = n+' '+t else: break conf_data.update({n:c}) # Parse class numbers from label csv file l = -1 csv_data = {} with open(fpath_label_inds) as f: for line in f: if l == -1: l += 1 continue tokens = line.split('"') n = tokens[1] csv_data.update({n:l}) l +=1 # Parse ontology info from json file with open(fpath_ontology, 'r') as f: json_data = json.load(f) # Put all data into a single list. all_data = [] for j in json_data: if j['name'] in conf_data.keys(): class_info = { 'name' : j['name'], 'restricted' : j['restrictions'] != [], 'has_child' : j['child_ids'] != [], 'conf' : conf_data[j['name']], 'id' : csv_data[j['name']] } all_data.append(class_info) # Filter classes classes = [] for c in all_data: if not c['restricted'] and not c['has_child'] and c['conf'] >= 70: classes.append(c['id']) ### Filter the samples. # Find samples that belong to only one of the potential classes. # We also exclude some samples that don't have data for the full 10 seconds. # First discard labels that are not in the set of potential classes y_fil = [] for i in range(len(y)): y_fil.append( np.intersect1d(y[i],classes)) # Find samples with one label n_labels = np.asarray([len(y) for y in y_fil]) single_label_idx = np.where(n_labels == 1)[0] # Find samples that are shorter than 10 seconds (to be excluded) too_short = np.where(np.asarray([x.shape[0] for x in x]) != 10)[0] # Construct the set of valid samples valid_idx = np.setdiff1d(single_label_idx,too_short) # Count number of valid samples for potential classes y_single = np.asarray([y_fil[i][0] for i in valid_idx]) num_samples = [len(np.where(y_single == i)[0]) for i in classes] # Take the n classes with the highest number of samples n_sample_cutoff = np.sort(num_samples)[-n_classes] class_idx = np.where(np.asarray(num_samples) >= n_sample_cutoff)[0] our_classes = [classes[i] for i in class_idx] ### Filter the data again according the the chosen classes y_fil = [] for i in range(len(y)): y_fil.append( np.intersect1d(y[i],our_classes)) # Find samples that belong to only one of the potential classes n_labels = np.asarray([len(y) for y in y_fil]) single_label_idx = np.where(n_labels == 1)[0] # Find samples that dont are shorter than 10 seconds too_short = np.where(np.asarray([x.shape[0] for x in x]) != 10)[0] # Construct the set of valid samples valid_idx = np.setdiff1d(single_label_idx,too_short) # Restructure data and relabel the classes to be between 0 and n_classes y_data = [y_fil[i][0] for i in valid_idx] y_data = [np.where(np.asarray(our_classes) == i)[0][0] for i in y_data] y_data = np.asarray(y_data) x_data = [x[i] for i in valid_idx] x_data = np.stack(x_data) ### Split into test and train and restrict the number of samples per class np.random.seed(42) n_train = int(n_sample * (1-test_frac)) n_test = int(n_sample * test_frac) train_ind = [] test_ind = [] for i in range(n_classes): sample_idx = np.where(y_data == i)[0] n_sample_class = len(sample_idx) rand_idx = np.arange(n_sample_class) np.random.shuffle(rand_idx) train_ind.extend(sample_idx[rand_idx[0:n_train]]) test_ind.extend(sample_idx[rand_idx[n_train:n_sample]]) train_ind = np.asarray(train_ind) test_ind = np.asarray(test_ind) sub_sample_idx = np.hstack((train_ind,test_ind)) x_data_sub = x_data[sub_sample_idx,:,:] y_data_sub = y_data[sub_sample_idx] train_ind = np.arange(0,len(train_ind)) test_ind = np.arange(len(train_ind),len(train_ind)+len(test_ind)) ### Save data with open(target_path, 'wb') as f: pickle.dump([x_data_sub, y_data_sub, train_ind, test_ind], f)
32.889655
80
0.68463
1
2.0241
[ -0.0721261277794838, 0.05755598470568657, 0.007763871923089027, 0.041016992181539536, -0.0011381329968571663, 0.006589008495211601, -0.04091360792517662, 0.019982974976301193, 0.02152811549603939, 0.03370734676718712, 0.02158384770154953, -0.005250284913927317, 0.021809840574860573, -0.013819657266139984, -0.0016264888690784574, 0.009556987322866917, 0.06531475484371185, 0.003551436820998788, -0.037164390087127686, -0.010110443457961082, 0.008062162436544895, 0.016835492104291916, -0.01139364205300808, 0.006376763805747032, 0.01196172833442688, 0.029201917350292206, -0.019014820456504822, 0.018529212102293968, 0.02461041696369648, -0.016276031732559204, -0.011572124436497688, -0.010323486290872097, -0.03140929341316223, 0.051673322916030884, 0.020701179280877113, 0.017403941601514816, 0.019188709557056427, -0.06971471011638641, 0.002267645439133048, -0.015607035718858242, -0.005621721502393484, 0.014150328002870083, 0.013265097513794899, 0.01929827407002449, 0.04154592379927635, 0.03848501294851303, -0.002675354015082121, 0.0010251731146126986, -0.03127674013376236, 0.0243853610008955, -0.035751957446336746, 0.01906677521765232, 0.03834889829158783, -0.049312200397253036, -0.02685249224305153, -0.03727395087480545, 0.01175645086914301, 0.04311826080083847, -0.02122277021408081, 0.011515962891280651, -0.0279247984290123, 0.03019619546830654, -0.02698754332959652, -0.0024697803892195225, 0.024259008467197418, -0.010357994586229324, 0.009287106804549694, -0.021223822608590126, -0.0031679151579737663, -0.0021834163926541805, -0.004380694590508938, -0.015407093800604343, -0.003738013794645667, 0.04207783192396164, -0.004003379959613085, 0.03379844129085541, -0.02450207620859146, -0.027310969308018684, -0.0071151116862893105, 0.007585605140775442, -0.021860864013433456, 0.06691396981477737, 0.04872782528400421, -0.012580054812133312, -0.0005762142827734351, 0.035805173218250275, 0.03434841334819794, -0.02464713528752327, 0.034299809485673904, 0.021233821287751198, -0.03885224089026451, 0.0010678977705538273, -0.05688372254371643, -0.021770525723695755, 0.007596204057335854, -0.04710111394524574, 0.02017638273537159, 0.008590354584157467, 0.0012712366878986359, -0.003326128236949444, -0.005453378427773714, -0.028933698311448097, -0.01685022935271263, -0.02901596389710903, -0.007183189503848553, -0.010845208540558815, -0.05380349978804588, 0.0015974415000528097, -0.012495053000748158, -0.012803550809621811, 0.020245295017957687, 0.005788431502878666, 0.004257784690707922, -0.03903692960739136, -0.028085729107260704, -0.013166219927370548, 0.03605677932500839, 0.009751027449965477, -0.01210329495370388, 0.0018745557172223926, -0.0018659430788829923, -0.004899407736957073, 0.014553701505064964, -0.04695733264088631, -0.01830625720322132, 0.05465785786509514, 0.03507605567574501, 0.031201623380184174, 0.020347172394394875, 0.008471970446407795, 0.0057956138625741005, 0.006985090207308531, -0.002568718744441867, -0.026200616732239723, -0.002462538657709956, -0.05926533415913582, -0.0038197627291083336, 0.004687061067670584, -0.03513942286372185, -0.0036497269757092, 0.017827261239290237, -0.041614968329668045, 0.011989199556410313, -0.02803102880716324, -0.019555922597646713, -0.04388567805290222, -0.015362541191279888, 0.01706446148455143, -0.021642545238137245, 0.003938826732337475, 0.009769310243427753, -0.0036377001088112593, -0.01534610241651535, 0.03986138105392456, 0.010032877326011658, 0.013528196141123772, -0.00028496389859355986, -0.02437390387058258, -0.0077318549156188965, 0.0034985309466719627, -0.022305430844426155, 0.018644150346517563, 0.015259613282978535, 0.021945174783468246, 0.00027980495360679924, 0.022897040471434593, -0.02623286284506321, 0.005631630774587393, 0.005066287703812122, 0.0286891870200634, 0.007739882450550795, -0.03648267686367035, -0.0026977681554853916, -0.007408998906612396, -0.02706592157483101, 0.021275747567415237, 0.05097418650984764, 0.007824612781405449, 0.023322252556681633, -0.020246215164661407, 0.0016922360518947244, 0.003971296828240156, -0.0033332519233226776, 0.06225389242172241, 0.017633166164159775, -0.013776435516774654, -0.06466429680585861, -0.008348905481398106, -0.00044822064228355885, 0.016526570543646812, -0.02826577238738537, 0.018751123920083046, -0.000305162655422464, -0.005395158194005489, -0.01273829024285078, 0.015435431152582169, 0.004532988648861647, 0.05543507635593414, -0.019857745617628098, 0.017752064391970634, -0.00736289331689477, 0.0037556858733296394, 0.025441529229283333, -0.012930776923894882, -0.011272338218986988, 0.011823521926999092, -0.7297893762588501, 0.0007619423558935523, -0.027830280363559723, 0.00031859861337579787, 0.03280894458293915, 0.05600239709019661, -0.04968848451972008, 0.028483109548687935, -0.06537232547998428, 0.008380412124097347, 0.01606101542711258, 0.0057347496040165424, -0.030473586171865463, -0.0018292060121893883, 0.021977318450808525, -0.01155941653996706, 0.019684795290231705, -0.011020833626389503, 0.015232647769153118, 0.02093031071126461, -0.00014556928363163024, -0.0014711013063788414, -0.03652196004986763, 0.03165196254849434, 0.009251145645976067, -0.0007688230834901333, 0.037165407091379166, 0.007261944934725761, 0.008684659376740456, 0.00570388650521636, 0.0003513210394885391, 0.00006623924855375662, -0.003457023063674569, -0.009142815135419369, 0.012069765478372574, 0.006539094261825085, 0.006776529364287853, 0.02704513818025589, -0.027970829978585243, -0.011644565500319004, -0.028618017211556435, -0.05239111930131912, -0.005739305168390274, -0.05786583945155144, -0.019223159179091454, -0.0071039507165551186, -0.007320714648813009, -0.044660307466983795, 0.02677362784743309, 0.011244455352425575, -0.032589640468358994, -0.02413184382021427, 0.04010912775993347, -0.004911753349006176, 0.03356803208589554, -0.008076867088675499, -0.01839170604944229, -0.011655713431537151, -0.0019721239805221558, -0.01889105886220932, 0.04425232112407684, -0.005758068058639765, -0.003912558313459158, 0.00148262910079211, -0.03879166767001152, 0.021592803299427032, 0.010215644724667072, -0.04538161680102348, -0.02434115670621395, 0.017697086557745934, -0.029397401958703995, -0.013319299556314945, -0.014430033974349499, 0.10452485084533691, 0.010690530762076378, 0.0003027631901204586, -0.0029597696848213673, -0.004736884497106075, -0.019250156357884407, 0.021730782464146614, 0.019042780622839928, -0.010339143685996532, 0.013082800433039665, 0.011953338049352169, -0.03479596599936485, 0.010608997195959091, -0.011751189827919006, -0.0012491544475778937, -0.006713841576129198, 0.0275616142898798, -0.026297135278582573, 0.031061900779604912, -0.001807914930395782, -0.015032182447612286, 0.011483987793326378, 0.04754391312599182, -0.006492197047919035, 0.060473520308732986, 0.022645365446805954, -0.007183097768574953, 0.006738309748470783, 0.011963047087192535, -0.003910799976438284, 0.026001356542110443, 0.013409078121185303, 0.044018570333719254, 0.010736235417425632, 0.004254904109984636, 0.026571083813905716, -0.056838978081941605, 0.014148203656077385, 0.0020662934985011816, -0.005080862436443567, -0.017324309796094894, -0.013902593404054642, -0.03324553743004799, -0.03206193819642067, -0.022160569205880165, 0.005679917987436056, -0.032698854804039, 0.010762843303382397, -0.014602847397327423, -0.026715265586972237, 0.006440798752009869, -0.013410317711532116, 0.04682156443595886, 0.0018087007338181138, -0.011952880769968033, -0.0010291768703609705, 0.05878504365682602, 0.01790737174451351, -0.014627921395003796, -0.011898165568709373, -0.0021143509075045586, -0.00966801680624485, -0.0006129814428277314, 0.0068466016091406345, -0.04758110269904137, 0.011049829423427582, -0.005615116562694311, 0.006469195242971182, 0.0024680239148437977, -0.0015423987060785294, -0.039807528257369995, 0.05012938380241394, -0.02268383465707302, 0.03537564352154732, -0.038428932428359985, 0.01541085634380579, -0.015213770791888237, 0.0037386303301900625, 0.009110500104725361, 0.0045290663838386536, 0.035656098276376724, 0.0035793636925518513, 0.0007365650380961597, -0.02042551152408123, 0.029147563502192497, 0.05039878934621811, 0.006534529384225607, 0.02552245743572712, -0.0057118842378258705, 0.01674305461347103, 0.026654085144400597, -0.02722792886197567, 0.02470802329480648, -0.026122303679585457, 0.037535980343818665, 0.013654435984790325, 0.04686851426959038, 0.004688507877290249, -0.012677958235144615, 0.008313526399433613, -0.031373683363199234, -0.0009694079635664821, -0.011002429760992527, -0.0407443568110466, 0.043653491884469986, -0.0035054166801273823, 0.004664507228881121, 0.0020720672328025103, -0.023853423073887825, -0.03587735444307327, -0.03248877450823784, 0.005651802755892277, 0.022848078981041908, -0.030955325812101364, 0.029734760522842407, 0.0002492050116416067, -0.023338882252573967, 0.010203233920037746, -0.0028977643232792616, -0.057060275226831436, 0.0009601419442333281, -0.027166439220309258, -0.035963431000709534, -0.04677410423755646, 0.01252175122499466, -0.0017087814630940557, -0.032062169164419174, 0.018362047150731087, -0.012967376969754696, 0.04203227162361145, -0.015529940836131573, -0.01181951817125082, -0.007450387813150883, -0.009962860494852066, 0.025065753608942032, -0.0006508951773867011, -0.01542891375720501, 0.023692434653639793, -0.01790233515202999, 0.027097025886178017, 0.021516691893339157, -0.01081047672778368, 0.04280548915266991, -0.0045278496108949184, -0.032938241958618164, 0.012140315026044846, -0.03571233153343201, -0.047169119119644165, -0.020931212231516838, 0.001117937033995986, -0.000050952276069438085, -0.015456654131412506, -0.0410354845225811, -0.06275923550128937, -0.000831025536172092, -0.005236699711531401, 0.000780208152718842, 0.019577261060476303, -0.01904667541384697, -0.03990424796938896, -0.001418887753970921, 0.005748393014073372, 0.020107291638851166, -0.00742208119481802, -0.0047974782064557076, 0.013497797772288322, -0.011536261066794395, 0.007720760069787502, -0.0094199413433671, -0.034766580909490585, 0.023239722475409508, -0.0028377727139741182, 0.005229025613516569, -0.026033299043774605, -0.008812367916107178, -0.02834933064877987, -0.011114668101072311, -0.015157537534832954, 0.014370055869221687, 0.023105468600988388, -0.022281257435679436, 0.028539523482322693, -0.024689534679055214, -0.021542735397815704, -0.021309595555067062, 0.011125093325972557, 0.013263954780995846, 0.0101516367867589, -0.006968074012547731, -0.00044991893810220063, 0.0023636529222130775, 0.011761215515434742, 0.00796937569975853, -0.01839558221399784, 0.015401647426187992, -0.01387164369225502, 0.03884775936603546, 0.0038199517875909805, -0.009817812591791153, -0.018812555819749832, -0.009250896982848644, 0.02109215222299099, -0.014306243509054184, 0.01995403878390789, -0.010099251754581928, -0.002872188575565815, 0.0476105771958828, -0.028593434020876884, 0.005112458020448685, 0.021245967596769333, 0.0020595986861735582, -0.008794254623353481, 0.02335810847580433, 0.04115569591522217, -0.007117182482033968, -0.04397228732705116, -0.008964065462350845, -0.021796295419335365, -0.07138538360595703, 0.009759876877069473, -0.008973364718258381, -0.04866814613342285, -0.01341494545340538, -0.03488098457455635, 0.0013946336694061756, 0.03274158760905266, 0.027186939492821693, 0.01547407265752554, 0.03797582909464836, 0.00439645117148757, 0.0178056750446558, 0.038064297288656235, -0.029731223359704018, -0.01439017802476883, 0.001209996291436255, 0.033010005950927734, 0.002507952041924, 0.013517037034034729, 0.00736439973115921, 0.006299526430666447, -0.018139561638236046, 0.029271110892295837, 0.01406962051987648, 0.021291205659508705, 0.006198250222951174, 0.020717164501547813, -0.002104898216202855, -0.004607744049280882, 0.0020616811234503984, -0.03202985227108002, -0.016434568911790848, -0.006680389866232872, -0.012517462484538555, -0.03119649551808834, 0.012164264917373657, 0.029639016836881638, 0.0103903254494071, -0.030284013599157333, -0.027828382328152657, 0.025746779516339302, 0.04023057967424393, 0.007178616710007191, -0.04317872226238251, 0.006728112697601318, 0.04154574126005173, -0.014916614629328251, 0.0052803875878453255, 0.03871520236134529, 0.018578747287392616, -0.0012545513454824686, -0.009803478606045246, 0.0027685309760272503, -0.007319403346627951, 0.037927430123090744, 0.01099026296287775, 0.006137759890407324, 0.036581993103027344, 0.03392498940229416, -0.018127083778381348, -0.03388574346899986, 0.010707031935453415, -0.025643404573202133, 0.015304842963814735, 0.01493131648749113, 0.01251988671720028, 0.023514164611697197, -0.028142444789409637, 0.026080479845404625, -0.021316885948181152, -0.03791094943881035, -0.00005548421904677525, -0.03256238251924515, 0.00025561812799423933, 0.026443663984537125, -0.007298069074749947, -0.005778036080300808, 0.04436510056257248, -0.025192171335220337, -0.010326413437724113, 0.041930191218853, 0.005815326236188412, -0.004911194089800119, 0.05098378285765648, 0.008613206446170807, -0.014870265498757362, -0.02290518395602703, -0.013451819308102131, 0.0060299537144601345, -0.036487217992544174, -0.00395401893183589, -0.05097291246056557, 0.014717645943164825, -0.0359269343316555, -0.041362058371305466, 0.010645071044564247, 0.0133137758821249, -0.05409280210733414, -0.029408492147922516, -0.02685542032122612, 0.0012611941201612353, 0.01661483198404312, -0.010201875120401382, -0.0221581868827343, -0.017608599737286568, 0.02058957889676094, 0.028673015534877777, -0.03422405570745468, -0.009419185109436512, -0.02170605957508087, 0.020751437172293663, 0.018793344497680664, 0.004570743069052696, -0.011492894031107426, 0.05837523192167282, -0.04830315336585045, 0.025681737810373306, 0.002188023179769516, 0.009999931789934635, 0.005740754306316376, 0.021883074194192886, 0.005703283473849297, 0.012422355823218822, 0.022569430992007256, -0.02014387957751751, -0.011788171716034412, -0.004485744517296553, -0.00995306484401226, -0.01386942807585001, 0.0024025614839047194, -0.0217051450163126, -0.00021141202887520194, 0.0021181467454880476, -0.010746685788035393, 0.019553206861019135, 0.017130233347415924, 0.014853809028863907, 0.020946688950061798, -0.01580335944890976, -0.03145577013492584, -0.020495077595114708, -0.023789379745721817, 0.028765570372343063, -0.0028100060299038887, 0.009463479742407799, -0.02384857088327408, -0.007776044309139252, -0.008399897255003452, -0.03515532240271568, 0.015561831183731556, 0.012115933001041412, 0.007264112588018179, 0.03458687290549278, -0.009677983820438385, 0.02133847400546074, 0.029509929940104485, -0.025207409635186195, 0.0067697674967348576, 0.02940019778907299, -0.0227844025939703, 0.004582225810736418, -0.0008518803515471518, -0.010462255217134953, 0.015599053353071213, 0.004653762094676495, 0.0392647311091423, 0.04954934120178223, 0.010531295090913773, 0.015600822865962982, 0.01794227585196495, 0.006506327074021101, 0.003768335795029998, 0.021647727116942406, 0.013560391031205654, -0.005642805248498917, -0.016117697581648827, 0.006507835816591978, -0.0030562845058739185, 0.01926511898636818, 0.022298986092209816, -0.02899222820997238, 0.005243917461484671, -0.018527142703533173, 0.022715285420417786, -0.004263147246092558, 0.028305329382419586, 0.04658385366201401, 0.04516980051994324, -0.04821642115712166, 0.005448104813694954, -0.01608213596045971, 0.02437092363834381, -0.003902388270944357, -0.02138320915400982, 0.014936808496713638, -0.007032421417534351, -0.01676301099359989, 0.027322880923748016, -0.016959359869360924, -0.0032433653250336647, 0.003068139310926199, 0.02337893284857273, 0.022500086575746536, -0.02924109809100628, 0.013834331184625626, -0.02429012954235077, 0.05841371417045593, -0.015113557688891888, 0.027575692161917686, -0.0422825962305069, 0.008481819182634354, -0.021925073117017746, 0.05869901552796364, 0.012139608152210712, 0.04309219866991043, 0.011297290213406086, 0.025187162682414055, -0.03621510788798332, -0.005557202268391848, -0.006724263075739145, -0.006867631338536739, -0.030921753495931625, 0.004183553624898195, -0.007065265905112028, -0.019102685153484344, -0.008039156906306744, 0.016407405957579613, 0.010250900872051716, 0.007827912457287312, 0.03147789090871811, -0.004382099956274033, -0.0017763684736564755, -0.015890099108219147, -0.003996840212494135, -0.0106441555544734, -0.016667474061250687, 0.005993457045406103, 0.02105930633842945, 0.010823368094861507, -0.019986050203442574, -0.0023794379085302353, -0.022525370121002197, 0.009791811928153038, -0.05722665786743164, 0.008584658615291119, 0.006460499484091997, -0.006979030091315508, -0.013861710205674171, 0.03533465787768364, -0.022691432386636734, 0.0015741119859740138, -0.02580013871192932, -0.04105241969227791, -0.04812474176287651, -0.012190383858978748, 0.0021807809825986624, 0.03688393533229828, -0.006847070995718241, 0.004569431766867638, -0.00408761203289032, -0.02901715412735939, -0.01331998035311699, -0.0652872771024704, -0.036762237548828125, 0.02524593099951744, 0.02272709459066391, 0.04223703220486641, -0.05274462699890137, -0.016322696581482887, 0.014386189170181751 ]
8ad1bc3d3021f0317b2b318ccf03355bd2585dd4
13,844
py
Python
Posts/viewsAPI.py
CMPUT404-Fa21-Organization/CMPUT404-Project-Social-Distribution
63c0ba2a03f0b462e3673ce7a4bf6bae7999440c
[ "Apache-2.0" ]
3
2021-12-11T13:43:56.000Z
2022-03-31T02:36:05.000Z
Posts/viewsAPI.py
CMPUT404-Fa21-Organization/CMPUT404-Project-Social-Distribution
63c0ba2a03f0b462e3673ce7a4bf6bae7999440c
[ "Apache-2.0" ]
9
2021-10-01T22:46:57.000Z
2021-12-16T18:01:31.000Z
Posts/viewsAPI.py
CMPUT404-Fa21-Organization/CMPUT404-Project-Social-Distribution
63c0ba2a03f0b462e3673ce7a4bf6bae7999440c
[ "Apache-2.0" ]
2
2021-12-16T16:37:10.000Z
2021-12-16T20:30:12.000Z
from django.conf import settings from django.core import serializers from django.utils import timezone import requests from Posts.commentModel import Comments #from Posts.commentView import add_Comment from rest_framework import status from rest_framework.decorators import api_view, authentication_classes, permission_classes from rest_framework.response import Response from django.shortcuts import HttpResponse, render from requests import get from .serializers import CommentSerializer, PostSerializer from Author.serializers import LikeSerializer from Author.models import Like from Author.views import updateForeignAuthors, GetForeignAuthors from .models import Post, Author from .form import PostForm from Posts.commentForm import CommentForm import json import uuid import re import base64 from django.db.models import Q import django.core from permissions import CustomAuthentication, AccessPermission from django.core.paginator import Paginator import traceback def newPost(request, uid=None, auth_pk=None): form = PostForm(request.POST, request.FILES) if form.is_valid(): title = form.cleaned_data['title'] descirption = form.cleaned_data['description'] categories = form.cleaned_data['categories'].split(' ') visibility = form.cleaned_data['visibility'] unlisted = form.cleaned_data['unlisted'] contentType = form.cleaned_data['contentType'] if contentType == "application/app": content = request.FILES['file'].read() #Inputfile elif contentType in ["image/png", "image/jpeg",]: content = base64.b64encode(request.FILES['file'].read()) #Inputfile else: content = form.cleaned_data["text"] source = settings.SERVER_URL + "/" origin = settings.SERVER_URL + "/" author_id = Author.objects.get(pk=auth_pk) id = author_id.url author = json.loads(serializers.serialize('json', Author.objects.filter(pk=auth_pk), fields=('type', 'id', 'host', 'displayName', 'url', 'github',)))[0]['fields'] if uid == None: r_uid = uuid.uuid4().hex uid = re.sub('-', '', r_uid) id = id + '/posts/' + uid + "/" comments_id = id + "comments/" published = timezone.now() posts = Post(pk=uid, id=id, author_id=author_id, author=author, title=title, source=source, origin=origin, description=descirption, contentType=contentType, count=0, size=10, categories=categories,visibility=visibility, unlisted=unlisted, published=published, content=content, comments=comments_id) posts.save() return True else: print(request.data) print(form.errors) print(form.data) return False def add_Comment(request, post_pk, auth_pk, uid=None): form = CommentForm(request.POST, request.FILES) if form.is_valid(): updateForeignAuthors() published = timezone.now() contentType = form.cleaned_data['contentType'] if contentType == "application/app": content = request.FILES['file'].read() #Inputfile elif contentType in ["image/png", "image/jpeg",]: content = base64.b64encode(request.FILES['file'].read()) #Inputfile else: content = form.cleaned_data["text"] author_id = json.loads(serializers.serialize('json', Author.objects.filter(email=auth_pk), fields=('type', 'id', 'host', 'displayName', 'url', 'github',)))[0]['fields'] post = Post.objects.get(pk = post_pk) post_pk_str = post_pk if uid == None: r_uid = uuid.uuid4().hex uid = re.sub('-', '', r_uid) comment_id = getattr(post, 'comments') + uid comments = Comments(pk=uid, id=comment_id, Post_pk=post, Post_pk_str = post_pk_str, auth_pk_str = auth_pk, author=author_id, size=10, published=published, contentType=contentType, content=content) comments.save() return True else: print(request.data) return False @api_view(['GET',]) @authentication_classes([CustomAuthentication]) @permission_classes([AccessPermission]) def PostLikesView(request, post_pk, auth_pk): post = Post.objects.get(post_pk = post_pk) author = Author.objects.get(pk = auth_pk) likeObjs = Like.objects.filter(~Q(auth_pk = author), object = post.id) Likes = LikeSerializer(likeObjs, read_only=True, many=True) likes = [] for l in Likes.data: like = {} for key in l: if(key != "context"): like[key] = l[key] like["@context"] = l["context"] like["author"] = json.loads(django.core.serializers.serialize('json', Author.objects.filter(id=l["author"]), fields=('type', 'id', 'displayName', 'host', 'url', 'github',)))[0]['fields'] likes.append(like) response_dict = { "type": "likes", "items": likes } return Response(response_dict) @api_view(['GET', 'POST',]) @authentication_classes([CustomAuthentication]) @permission_classes([AccessPermission]) def PostsList(request, auth_pk=None): page_number = request.GET.get('page') if 'size' in request.GET: page_size = request.GET.get('size') else: page_size = 5 if request.method == 'GET': if auth_pk: try: author = Author.objects.get(auth_pk=auth_pk) posts = Post.objects.filter(author_id=author, id__icontains = "linkedspace") code = status.HTTP_200_OK paginator = Paginator(posts, page_size) page_obj = paginator.get_page(page_number) data = PostSerializer(page_obj.object_list, many=True).data except Exception as e: print(e) data = {} code = status.HTTP_400_BAD_REQUEST else: code = status.HTTP_200_OK posts = Post.objects.filter(id__icontains = "linkedspace") paginator = Paginator(posts, page_size) page_obj = paginator.get_page(page_number) data = PostSerializer(page_obj.object_list, many=True).data elif request.method == 'POST': if newPost(request, auth_pk=request.data['auth_pk']): code = status.HTTP_201_CREATED post = Post.objects.latest("published") data = PostSerializer(post).data else: code = status.HTTP_400_BAD_REQUEST data = {} return Response(data, code) @api_view(['GET', 'POST',]) @authentication_classes([CustomAuthentication]) @permission_classes([AccessPermission]) def commentListView(request, post_pk, auth_pk=None): page_number = request.GET.get('page') if 'size' in request.GET: page_size = request.GET.get('size') else: page_size = 5 if request.method == 'GET': comments = Comments.objects.filter(Post_pk_str=post_pk) post = Post.objects.get(pk=post_pk) post_id = getattr(post, 'id') comment_id = getattr(post, 'comments') paginator = Paginator(comments, page_size) page_obj = paginator.get_page(page_number) serializer = CommentSerializer(page_obj.object_list, many=True) response_dict = { "type": "comments", "page": page_number, "size": page_size, "post": post_id, "id": comment_id, "comments": serializer.data, } return Response(response_dict) elif request.method == 'POST': if add_Comment(request, post_pk=request.data['Post_pk'], auth_pk=request.data['auth_pk']): code = status.HTTP_202_ACCEPTED comment = Comments.objects.latest("published") data = CommentSerializer(comment).data else: code = status.HTTP_400_BAD_REQUEST data = {} return Response(data, code) @api_view(['GET', 'POST', 'PUT', 'DELETE', ]) @authentication_classes([CustomAuthentication]) @permission_classes([AccessPermission]) def PostDetail(request, post_pk, auth_pk=None): page_number = request.GET.get('page') if 'size' in request.GET: page_size = request.GET.get('size') else: page_size = 5 if request.method == 'GET': try: code = status.HTTP_200_OK post = Post.objects.get(post_pk=post_pk) serializer = PostSerializer(post) except Exception as e: print(e) code = status.HTTP_404_NOT_FOUND post = Post.objects.all() paginator = Paginator(post, page_size) page_obj = paginator.get_page(page_number) serializer = PostSerializer(page_obj.object_list, many=True) elif request.method == 'POST': try: code = status.HTTP_200_OK post = Post.objects.get(post_pk=post_pk) if 'title' in request.data.keys(): post.title = request.data['title'] if 'description' in request.data.keys(): post.description = request.data['description'] if 'categories' in request.data.keys(): post.categories = request.data['categories'].split(' ') if 'visibility' in request.data.keys(): post.visibility = request.data['visibility'] if 'unlisted' in request.data.keys(): post.unlisted = request.data['unlisted'] if 'contentType' in request.data.keys(): post.contentType = request.data['contentType'] if post.contentType == "application/app": post.content = request.FILES['file'].read() #Inputfile elif post.contentType in ["image/png", "image/jpeg",]: post.content = base64.b64encode(request.FILES['file'].read()) #Inputfile else: post.content = request.data["text"] post.save() serializer = PostSerializer(post) except Exception as e: print(e) code = status.HTTP_400_BAD_REQUEST post = Post.objects.all() paginator = Paginator(post, page_size) page_obj = paginator.get_page(page_number) serializer = PostSerializer(page_obj.object_list, many=True) elif request.method == 'PUT': try: code = status.HTTP_201_CREATED assert newPost(request, post_pk, request.data['auth_pk'])==True post = Post.objects.get(post_pk=post_pk) serializer = PostSerializer(post) except Exception as e: print(e) code = status.HTTP_400_BAD_REQUEST post = Post.objects.all() paginator = Paginator(post, page_size) page_obj = paginator.get_page(page_number) serializer = PostSerializer(page_obj.object_list, many=True) elif request.method == 'DELETE': try: post = Post.objects.get(post_pk=post_pk) post.delete() code = status.HTTP_200_OK except Exception as e: print(e) code = status.HTTP_404_NOT_FOUND post = Post.objects.all() paginator = Paginator(post, page_size) page_obj = paginator.get_page(page_number) serializer = PostSerializer(page_obj.object_list, many=True) return Response(serializer.data, code) @api_view(['GET', 'POST', ]) @authentication_classes([CustomAuthentication]) @permission_classes([AccessPermission]) def commentDetail(request, post_pk, comment_pk, auth_pk=None): page_number = request.GET.get('page') if 'size' in request.GET: page_size = request.GET.get('size') else: page_size = 5 if request.method == 'GET': try: code = status.HTTP_200_OK comment = Comments.objects.get(pk=comment_pk) serializer = CommentSerializer(comment) except Exception as e: print(e) code = status.HTTP_404_NOT_FOUND comment = Comments.objects.all() paginator = Paginator(comment, page_size) page_obj = paginator.get_page(page_number) serializer = CommentSerializer(page_obj.object_list, many=True) elif request.method == 'POST': try: code = status.HTTP_200_OK comment = Comments.objects.get(pk=comment_pk) if 'contentType' in request.data.keys(): comment.contentType = request.data['contentType'] if 'text' in request.data.keys(): comment.content = request.data['text'] comment.save() serializer = CommentSerializer(comment) except Exception as e: print(e) code = status.HTTP_400_BAD_REQUEST comment = Comments.objects.all() paginator = Paginator(comment, page_size) page_obj = paginator.get_page(page_number) serializer = CommentSerializer(page_obj.object_list, many=True) return Response(serializer.data, code) @api_view(['GET',]) def connection(request, auth_id=None): data = [] team3 = get('https://social-dis.herokuapp.com/posts', auth=('socialdistribution_t03','c404t03')) if team3.status_code == 200: data.append(team3.json()) team15 = get('https://unhindled.herokuapp.com/service/allposts/', auth=('connectionsuperuser','404connection')) if team15.status_code == 200: data.append(team15.json()) team17 = get('https://cmput404f21t17.herokuapp.com/service/connect/public/', auth=('4cbe2def-feaa-4bb7-bce5-09490ebfd71a','123456')) if team17.status_code == 200: data.append(team17.json()) return Response({'connection': data})
38.455556
306
0.621063
1
1.9476
[ -0.02420027367770672, 0.02076614648103714, -0.02691997028887272, 0.007274618372321129, 0.00022945775708649307, 0.02938300184905529, -0.009463776834309101, -0.028670035302639008, -0.014270918443799019, 0.02430732548236847, 0.0013056397438049316, 0.0045600333251059055, 0.0124591626226902, -0.0088814003393054, -0.048734765499830246, -0.019293010234832764, 0.10315951704978943, -0.02917277254164219, -0.02632388286292553, 0.02836558036506176, -0.0022181118838489056, 0.01567658968269825, 0.011187558062374592, 0.031932491809129715, 0.005733873229473829, -0.026448223739862442, 0.0211289394646883, -0.008734870702028275, -0.020168079063296318, -0.0003905814082827419, -0.020803315564990044, 0.012784360907971859, 0.009404957294464111, 0.0025003780610859394, 0.023988528177142143, 0.0005934442160651088, -0.017334194853901863, -0.04761688411235809, -0.007600883021950722, -0.013457871042191982, 0.04910464584827423, -0.024221180006861687, 0.021187959238886833, -0.019107505679130554, -0.003222224535420537, 0.003110306803137064, -0.022491421550512314, 0.012632056139409542, -0.06440667808055878, -0.014453280717134476, 0.024797849357128143, 0.01747428998351097, -0.01178339309990406, 0.005930017679929733, 0.021565627306699753, -0.046450596302747726, 0.015851400792598724, 0.018256017938256264, -0.0012528690276667476, -0.0048276749439537525, -0.029550103470683098, 0.021587179973721504, -0.011377761140465736, 0.019152654334902763, 0.018376098945736885, 0.02169650048017502, -0.015129017643630505, -0.025268224999308586, -0.045001301914453506, -0.03214016556739807, 0.004091599490493536, -0.003161445027217269, 0.006850011181086302, -0.003912941087037325, 0.03377535939216614, 0.017990924417972565, -0.00530303455889225, 0.009823538362979889, -0.01493581011891365, 0.007592026609927416, 0.010721332393586636, 0.028768757358193398, 0.020867416635155678, -0.018032684922218323, 0.002502712421119213, 0.011775046586990356, 0.01044399756938219, -0.017632387578487396, 0.050957079976797104, -0.0020491033792495728, -0.035303618758916855, 0.04582611098885536, -0.024436799809336662, 0.009870336391031742, -0.030820414423942566, -0.021437039598822594, -0.000029406950488919392, 0.01864229142665863, -0.01699494570493698, 0.003531594527885318, 0.02316182665526867, 0.013742508366703987, 0.00011611169611569494, 0.009121721610426903, -0.010610876604914665, 0.030667433515191078, -0.02894013375043869, -0.0065460498444736, 0.003754247911274433, -0.019612709060311317, 0.008336028084158897, 0.012300086207687855, -0.04726707935333252, -0.018213024362921715, -0.04922008886933327, -0.02175326459109783, 0.0164557583630085, -0.01242484524846077, 0.011754447594285011, 0.030814507976174355, -0.02935740165412426, -0.009643476456403732, -0.008176123723387718, -0.007586160209029913, -0.03071300871670246, 0.03802276402711868, -0.013672600500285625, 0.0021647370886057615, 0.033729542046785355, -0.004625445231795311, -0.0112417908385396, 0.015921125188469887, -0.0155111663043499, -0.03591003641486168, -0.0027886717580258846, 0.039007868617773056, 0.013369969092309475, -0.0023628927301615477, -0.0110926553606987, 0.017486169934272766, 0.006929791998118162, -0.01503065787255764, 0.013891189359128475, -0.005977842956781387, -0.0026102247647941113, -0.01467979233711958, -0.009337159804999828, -0.0071725365705788136, -0.036435168236494064, -0.013892696239054203, -0.0036386018618941307, 0.004046410322189331, 0.013688938692212105, 0.04085615649819374, -0.009141115471720695, -0.008765535429120064, 0.00841873325407505, -0.03246206417679787, -0.020991353318095207, -0.03131086379289627, -0.02592584118247032, 0.011832589283585548, -0.013741634786128998, -0.022429194301366806, -0.0036188301164656878, 0.03281470015645027, 0.010077711194753647, -0.0005475372890941799, -0.014909964986145496, 0.009551860392093658, -0.0032030981965363026, -0.003486935282126069, -0.004959740210324526, -0.02964736707508564, 0.006254706997424364, 0.007145137060433626, 0.007805200759321451, 0.0009972635889425874, 0.01204316783696413, 0.010664026252925396, 0.001449932693503797, 0.025420472025871277, 0.015308103524148464, 0.00143524631857872, 0.018668241798877716, 0.04652578383684158, -0.04420517012476921, -0.042775750160217285, -0.02764255926012993, 0.006388472858816385, -0.017201583832502365, -0.007788416463881731, -0.013601257465779781, -0.033938195556402206, 0.008077915757894516, -0.0017507033189758658, -0.006117857526987791, 0.004270902369171381, -0.013004622422158718, 0.015388919971883297, 0.012384546920657158, -0.002561453962698579, -0.0007788543007336557, 0.005139591172337532, 0.006904620211571455, -0.0038553359918296337, -0.8098939061164856, -0.015579422935843468, 0.019884075969457626, -0.0018358639208599925, -0.0013937645126134157, 0.01949172280728817, -0.047264546155929565, 0.005022308323532343, -0.06567586213350296, -0.033286355435848236, -0.01841169036924839, 0.00038640963612124324, 0.008473162539303303, -0.021977875381708145, -0.0023886330891400576, -0.012630321085453033, 0.002502045128494501, 0.03703303635120392, -0.023306503891944885, 0.017141249030828476, 0.0007662216085009277, 0.0159725584089756, -0.029913293197751045, 0.002883421489968896, 0.006253538653254509, 0.007894065231084824, 0.048012129962444305, 0.0025779514107853174, 0.02348077856004238, -0.03704478219151497, 0.01338302344083786, -0.004944473970681429, -0.00465000607073307, -0.009709700010716915, 0.0003298530646134168, 0.008194835856556892, 0.06444364786148071, -0.03366750851273537, -0.0017076070653274655, -0.011983774602413177, 0.009472915902733803, -0.011021076701581478, -0.0030265229288488626, -0.04747335612773895, -0.023047711700201035, -0.023729845881462097, -0.03322892636060715, -0.04192511364817619, -0.011810865253210068, 0.0009933625115081668, -0.005481400992721319, 0.031164631247520447, 0.005831458140164614, -0.01578184776008129, -0.027186114341020584, -0.025675222277641296, -0.0020740493200719357, -0.01890556327998638, 0.02080228552222252, -0.0013661024859175086, 0.034761082381010056, 0.00254666805267334, -0.0495254322886467, -0.0019336652476340532, 0.00047433163854293525, 0.020383529365062714, 0.04291165992617607, -0.04698873311281204, -0.023106496781110764, 0.01002452615648508, -0.022138496860861778, -0.024901563301682472, -0.007601139135658741, 0.039283689111471176, -0.015270594507455826, -0.0030924384482204914, 0.017363842576742172, 0.01476177480071783, -0.018807286396622658, 0.00626831641420722, 0.017786260694265366, -0.0059518879279494286, -0.020056111738085747, -0.010510681197047234, -0.010975116863846779, 0.001310319290496409, -0.011374901048839092, -0.008010473102331161, -0.007928401231765747, -0.0022807179484516382, 0.04110943526029587, -0.016871295869350433, -0.00026410724967718124, -0.018427841365337372, 0.018444864079356194, 0.028881657868623734, -0.017944827675819397, 0.024955900385975838, -0.013488425873219967, 0.015303402207791805, -0.022360602393746376, 0.0010975287295877934, -0.010122806765139103, -0.004602382890880108, 0.011560630984604359, -0.0094995629042387, 0.022021742537617683, -0.030182838439941406, 0.07206862419843674, 0.003958020359277725, -0.026036346331238747, -0.02468724176287651, 0.015504345297813416, 0.005456199869513512, 0.05667834356427193, -0.001130877761170268, -0.012678812257945538, -0.021002715453505516, 0.008230757899582386, -0.022965233772993088, 0.006508184596896172, 0.003686913987621665, 0.022076165303587914, 0.0018640639027580619, -0.011410004459321499, -0.007809951435774565, 0.007387922611087561, -0.03441868722438812, 0.02956402488052845, -0.016158685088157654, -0.014331921935081482, -0.03141972795128822, -0.010237514041364193, -0.00525824585929513, 0.012698126956820488, 0.021854691207408905, -0.021161148324608803, -0.028723718598484993, -0.010542506352066994, 0.014684906229376793, -0.0009324039565399289, -0.0374966636300087, 0.011596071533858776, -0.008825816214084625, 0.020843612030148506, 0.022585438564419746, 0.02432112582027912, -0.017140040174126625, 0.03357725962996483, 0.01705830916762352, 0.015535648912191391, 0.010958481580018997, -0.0026148762553930283, -0.015182755887508392, -0.0023250228259712458, 0.002949295798316598, -0.030464721843600273, 0.03844963386654854, 0.003698440734297037, 0.010738637298345566, -0.014041927643120289, 0.006480255164206028, -0.004041495267301798, -0.028725463896989822, 0.013211911544203758, -0.023119157180190086, 0.0018499939469620585, 0.013177168555557728, 0.034362345933914185, -0.0052731153555214405, 0.013242067769169807, -0.014909736812114716, 0.02956867590546608, 0.015472639352083206, -0.002991788787767291, 0.03593738004565239, 0.00755799887701869, -0.028831016272306442, -0.03370289504528046, 0.016197852790355682, -0.0005690727266483009, -0.009191291406750679, 0.006328256335109472, -0.007364336866885424, 0.0037947469390928745, -0.014973699115216732, 0.002265498973429203, 0.01909119263291359, -0.013127192854881287, -0.009629662148654461, -0.0395718477666378, -0.0037017641589045525, -0.011839448474347591, 0.006280071102082729, 0.002145439852029085, -0.012608597055077553, -0.0035057184286415577, 0.003437045495957136, 0.018781518563628197, 0.015214258804917336, 0.014042791910469532, 0.025736944749951363, 0.004963940940797329, -0.021237006410956383, -0.005091357510536909, 0.014538329094648361, 0.044586438685655594, -0.009557446464896202, 0.009531755931675434, -0.0028151243459433317, 0.0254079420119524, 0.013208617456257343, -0.02245425619184971, -0.00011528775212354958, -0.0047713336534798145, 0.03108382411301136, -0.0358605720102787, 0.010443962179124355, 0.007002772763371468, -0.04364870488643646, -0.0032300190068781376, -0.010026270523667336, 0.023276809602975845, 0.023530200123786926, 0.004336037207394838, -0.003934137523174286, -0.009851641021668911, -0.03174436092376709, -0.016681140288710594, 0.00255037029273808, -0.011005325242877007, 0.008059653453528881, -0.02759738638997078, -0.012194344773888588, 0.0034651628229767084, 0.01067246962338686, -0.022283103317022324, -0.002380151068791747, -0.006614701822400093, -0.010517796501517296, -0.0032917337957769632, -0.00691844942048192, -0.011027563363313675, 0.049100879579782486, -0.006184459198266268, 0.021756067872047424, 0.02449118159711361, -0.023721521720290184, -0.023945102468132973, -0.01172041054815054, -0.02891252189874649, -0.010107496753334999, -0.0006477314746007323, -0.017290262505412102, 0.028684386983513832, 0.024333469569683075, -0.012441419064998627, 0.021232970058918, 0.016536729410290718, 0.014475170522928238, -0.008122638799250126, -0.015465074218809605, -0.02489294670522213, 0.01758185401558876, -0.01724928431212902, -0.02159995213150978, -0.010234277695417404, 0.01380999106913805, -0.030315035954117775, 0.010022148489952087, -0.008133627474308014, -0.0060083866119384766, -0.0084911547601223, -0.026712829247117043, -0.015901992097496986, -0.0075230770744383335, -0.02871152013540268, -0.002168112201616168, 0.018694179132580757, -0.017121760174632072, -0.018322480842471123, 0.005311945918947458, -0.009444057010114193, 0.006955772638320923, 0.019356513395905495, 0.019237475469708443, 0.03538692742586136, 0.01030852273106575, -0.04181690514087677, 0.008853900246322155, -0.009305814281105995, -0.01594274304807186, 0.006779532879590988, 0.03743210807442665, 0.0019224784336984158, -0.00048362681991420686, -0.0049104345962405205, -0.015548261813819408, -0.0085171889513731, 0.0022084510419517756, 0.03620292246341705, -0.03973976522684097, -0.018111297860741615, 0.00811312161386013, 0.007965730503201485, -0.007861528545618057, -0.00022840092424303293, 0.00512254424393177, 0.021263334900140762, 0.011929641477763653, 0.014688472263514996, 0.026862334460020065, 0.03639240935444832, 0.017024781554937363, -0.019575046375393867, 0.026257436722517014, 0.026822900399565697, 0.006521608680486679, 0.008941691368818283, 0.005506374407559633, 0.011574946343898773, 0.01492359396070242, -0.028582513332366943, 0.01514225360006094, -0.002911798655986786, 0.017536161467432976, -0.007934407331049442, 0.005132196471095085, 0.012066185474395752, 0.02917289547622204, 0.00840059109032154, 0.012005265802145004, 0.03173689916729927, 0.03570271655917168, 0.0043734475038945675, 0.0027157245203852654, -0.010770827531814575, -0.020196689292788506, -0.0147634232416749, 0.021223271265625954, 0.00029774539871141315, -0.015049060806632042, -0.014560528099536896, 0.01267100591212511, -0.021851880475878716, -0.001427862443961203, -0.026332000270485878, 0.036312296986579895, 0.012599085457623005, 0.023624220862984657, -0.0017388586420565844, -0.01589571125805378, 0.0182038601487875, -0.03246130049228668, 0.011446301825344563, -0.017108654603362083, 0.012201890349388123, -0.009355789981782436, 0.03325929865241051, -0.010621339082717896, 0.014173190109431744, 0.011774163693189621, 0.00003934396227123216, 0.015964899212121964, 0.0101260831579566, 0.0011815010802820325, 0.029719479382038116, -0.014671865850687027, -0.00321514462120831, 0.0367412269115448, 0.006584824062883854, 0.028953732922673225, 0.0045757535845041275, -0.011302710510790348, -0.009564662352204323, 0.0414130873978138, 0.016612377017736435, 0.04618155583739281, -0.0016024335054680705, 0.03255004063248634, -0.03374257683753967, -0.011906617321074009, -0.0011089796898886561, -0.014083867892622948, 0.0424056202173233, -0.050496604293584824, 0.020025528967380524, 0.014111630618572235, -0.025253964588046074, -0.031973838806152344, 0.039600953459739685, -0.03012988716363907, 0.013816441409289837, 0.011144541203975677, -0.0038235350511968136, 0.011520018801093102, -0.01641896739602089, 0.0018515520496293902, 0.02510116435587406, 0.01132647879421711, 0.016574043780565262, 0.035845253616571426, -0.0038680164143443108, -0.007585817947983742, 0.012230675667524338, -0.002571720629930496, 0.015748726204037666, -0.018546950072050095, 0.00026753940619528294, -0.003565947525203228, 0.002353911055251956, -0.00047468472621403635, 0.00999912153929472, -0.024471504613757133, 0.004394832067191601, 0.005509126465767622, -0.01904916763305664, -0.0006357441889122128, 0.01123008318245411, 0.017106909304857254, 0.012974215671420097, -0.008271992206573486, 0.002858415711671114, 0.01497877947986126, -0.04194866493344307, 0.010831248015165329, -0.009197327308356762, -0.04142666608095169, -0.02654067985713482, 0.023108074441552162, -0.007026244420558214, 0.03237774595618248, 0.014408032409846783, 0.0012588693061843514, 0.0037732378114014864, -0.03334078565239906, 0.0055700670927762985, -0.02433416247367859, -0.004672762006521225, -0.006308246869593859, -0.00816208403557539, 0.0006639909697696567, -0.01534642931073904, -0.018028002232313156, 0.03915850818157196, -0.047951243817806244, -0.003486120607703924, 0.021157776936888695, -0.002127676969394088, -0.017212459817528725, 0.0043567451648414135, 0.007532928604632616, 0.018760493025183678, 0.0032014059834182262, 0.005111615173518658, 0.012839896604418755, 0.005813688039779663, 0.02257215790450573, 0.0211997888982296, 0.025700554251670837, 0.01848277635872364, 0.006615437101572752, -0.017970969900488853, 0.0037365579046308994, 0.012542019598186016, 0.007705695927143097, 0.02370508387684822, -0.04861559718847275, -0.0035555544309318066, -0.004822363145649433, 0.020875591784715652, 0.03158704563975334, -0.026517197489738464, 0.02740495651960373, -0.028251977637410164, -0.0031454546842724085, -0.033173494040966034, 0.015861062332987785, 0.004753766115754843, -0.006989308632910252, -0.03238639608025551, 0.034200962632894516, 0.011563142761588097, 0.019891882315278053, 0.0365581288933754, 0.002667737891897559, -0.00813552550971508, -0.014134474098682404, -0.016999773681163788, 0.02461354248225689, -0.019934572279453278, -0.010593700222671032, -0.02285912074148655, 0.01784517429769039, -0.0012399411061778665, -0.03896418213844299, 0.003074369393289089, 0.03270165994763374, 0.048826590180397034, 0.006593005266040564, -0.014684733934700489, -0.02538175880908966, -0.013302094303071499, -0.019460124894976616, 0.02530576102435589, 0.010874653235077858, 0.07227439433336258, -0.009994019754230976, -0.006146261468529701, 0.0006688761059194803, 0.02511323243379593, -0.0006280357483774424, 0.005708141252398491, 0.016859006136655807, 0.016938466578722, -0.004060756415128708, 0.0397106371819973, -0.049618352204561234, -0.0011002006940543652, -0.025744915008544922, -0.00312247546389699, 0.012233640998601913, -0.007524152286350727, -0.015253592282533646, 0.004536510910838842, -0.007298763375729322, -0.03015100583434105, 0.00491126487031579, 0.0246097631752491, -0.003233998781070113, 0.03669869527220726, 0.01723043993115425, -0.02461106702685356, 0.02706672064960003, 0.014472358860075474, -0.033263396471738815, 0.010712125338613987, 0.021266618743538857, -0.019102035090327263, 0.0009399394621141255, 0.02212407998740673, 0.020118864253163338, -0.0006884444155730307, -0.016860801726579666, -0.028287002816796303, 0.008551024831831455, -0.00847902987152338, -0.02750007063150406, -0.011522604152560234, -0.029576947912573814, 0.006832304876297712, -0.022057410329580307, 0.004905716981738806, 0.005085350479930639, -0.02747947722673416, -0.0267023928463459, -0.030338119715452194, 0.02474036067724228, 0.018610406666994095, -0.046112801879644394, 0.021123791113495827, 0.0036994819529354572 ]
8ad1ee45a7daa21c8e394ff77552f61ad841514d
3,753
py
Python
workers/tests/test_array_element.py
Open-EO/openeo-sentinelhub-python-driver
92f990f098065ffb658eba6dca291dd1d5fc70f2
[ "Apache-2.0" ]
2
2019-12-03T12:49:47.000Z
2020-10-25T20:14:39.000Z
workers/tests/test_array_element.py
Open-EO/openeo-sentinelhub-python-driver
92f990f098065ffb658eba6dca291dd1d5fc70f2
[ "Apache-2.0" ]
5
2019-12-03T10:32:48.000Z
2020-10-09T13:07:39.000Z
workers/tests/test_array_element.py
Open-EO/openeo-sentinelhub-python-driver
92f990f098065ffb658eba6dca291dd1d5fc70f2
[ "Apache-2.0" ]
4
2020-03-06T14:51:52.000Z
2020-11-24T10:30:18.000Z
import pytest import sys, os import xarray as xr import numpy as np sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) import process from process._common import ProcessArgumentInvalid, ProcessArgumentRequired @pytest.fixture def generate_data(): def _construct( data = [[[[0.1, 0.15], [0.15, 0.2]], [[0.05, 0.1], [-0.9, 0.05]]]], dims = ('t','y','x','band'), reduce_by = "band", as_list = False ): if as_list: return data xrdata = xr.DataArray( data, dims=dims, attrs={'reduce_by': [reduce_by]}, ) return xrdata return _construct @pytest.fixture def execute_array_element_process(generate_data): def wrapped(data_arguments={}, index=None, return_nodata=None): arguments = {} if data_arguments is not None: arguments["data"] = generate_data(**data_arguments) if index is not None: arguments["index"] = index if return_nodata is not None: arguments["return_nodata"] = return_nodata return process.array_element.array_elementEOTask(None, "" , None, {}, "arrayel1").process(arguments) return wrapped ################################### # tests: ################################### @pytest.mark.parametrize('data,return_nodata,index,expected_result', [ ([9,8,7,6,5], None, 2, 7), (["A","B","C"], None, 0, "A"), ([], True, 0, None) ]) def test_examples(execute_array_element_process, data, index, return_nodata, expected_result): """ Test array_element process with examples from https://open-eo.github.io/openeo-api/processreference/#array_element """ data_arguments = {"data": data, "as_list": True} result = execute_array_element_process(data_arguments=data_arguments, index=index, return_nodata=return_nodata) assert result == expected_result @pytest.mark.parametrize('data,index,reduce_by,expected_data,expected_dims', [ ([[[[0.1, 0.15], [0.15, 0.2]], [[0.05, 0.1], [-0.9, 0.05]]]], 0, "band", [[[0.1, 0.15], [0.05, -0.9]]], ('t','y','x')), ([[[[0.1, 0.15], [0.15, 0.2]], [[0.05, 0.1], [-0.9, 0.05]]]], 1, "y", [[[0.05, 0.1], [-0.9, 0.05]]], ('t','x','band')), ]) def test_with_xarray(execute_array_element_process, generate_data, data, index, reduce_by, expected_data, expected_dims): """ Test array_element process with xarray.DataArrays """ expected_result = generate_data(data=expected_data, dims=expected_dims, reduce_by=reduce_by) result = execute_array_element_process(data_arguments={"data": data, "reduce_by": reduce_by}, index=index) xr.testing.assert_allclose(result, expected_result) def test_with_xarray_out_bounds(execute_array_element_process, generate_data): """ Test array_element process with xarray.DataArrays with out of bounds index """ with pytest.raises(ProcessArgumentInvalid) as ex: result = execute_array_element_process(index=5) assert ex.value.args[0] == "The argument 'index' in process 'array_element' is invalid: Index out of bounds." @pytest.mark.parametrize('data_arguments,index,expected_data,expected_dims', [ ({}, 5, [[[np.nan, np.nan], [np.nan, np.nan]]], ('t','y','x')), ]) def test_with_xarray_out_bounds_return_nodata(execute_array_element_process, generate_data, data_arguments, index, expected_data, expected_dims): """ Test array_element process with xarray.DataArrays with out of bounds index and return_no_data """ expected_result = generate_data(expected_data, dims=expected_dims) result = execute_array_element_process(data_arguments=data_arguments, index=index, return_nodata=True) xr.testing.assert_equal(result, expected_result)
40.354839
145
0.662137
1
2.0601
[ -0.03337382152676582, 0.017704090103507042, -0.031038952991366386, -0.0003922446630895138, 0.014105234295129776, 0.021475734189152718, -0.01651509292423725, 0.005600803531706333, 0.0013725843746215105, -0.02109168842434883, 0.0037240246310830116, 0.0011129953199997544, 0.001422511413693428, -0.006658288650214672, -0.02408653311431408, -0.002096804091706872, 0.060020145028829575, 0.03067770227789879, -0.0022674943320453167, 0.04695304110646248, -0.0017565306043252349, -0.012541382573544979, -0.004695678595453501, 0.01932404190301895, -0.026646681129932404, 0.02121969498693943, 0.05291362479329109, 0.0032623240258544683, -0.026123950257897377, -0.028773292899131775, -0.0016873161075636744, 0.019808858633041382, 0.007595124654471874, 0.026059888303279877, -0.013587954454123974, 0.020258191972970963, 0.013244183734059334, -0.04164860397577286, 0.04744865000247955, -0.009189502336084843, -0.02064516767859459, 0.006361322943121195, 0.006028709467500448, -0.06445340067148209, 0.00715029239654541, -0.03560880199074745, -0.002519248053431511, -0.06325492262840271, 0.022700674831867218, 0.03133559226989746, 0.018266644328832626, -0.021411508321762085, -0.000213144114241004, 0.005608192645013332, -0.00580343883484602, -0.026861930266022682, -0.0024822475388646126, -0.014027101919054985, -0.010729189030826092, -0.0011456877691671252, -0.059555426239967346, 0.016993392258882523, 0.04547712579369545, -0.015556339174509048, 0.03846883028745651, 0.02601601369678974, -0.009461088106036186, -0.05179600790143013, 0.017760109156370163, -0.03055310808122158, 0.017445938661694527, -0.0327986441552639, 0.002813228638842702, 0.09242577850818634, 0.020483631640672684, 0.03472059965133667, 0.011131223291158676, 0.004570627585053444, 0.003365905024111271, 0.045123182237148285, -0.0024163145571947098, 0.045141901820898056, 0.009476627223193645, -0.018946943804621696, 0.018377985805273056, 0.013697770424187183, 0.06807290017604828, -0.02514411322772503, 0.026420744135975838, -0.005372546147555113, -0.044229283928871155, -0.02003125473856926, -0.020173804834485054, 0.02412155456840992, -0.022108132019639015, -0.0419088751077652, 0.031727105379104614, -0.008846837095916271, 0.014258797280490398, 0.02530308999121189, 0.019377393648028374, -0.008810337632894516, 0.018563060089945793, 0.039500825107097626, -0.013902608305215836, 0.029497208073735237, -0.028743555769324303, -0.024513164535164833, -0.029749218374490738, -0.014710113406181335, 0.024690035730600357, -0.0011328642722219229, -0.026725705713033676, -0.014817854389548302, -0.03313750401139259, -0.002506835851818323, 0.0265198964625597, 0.0328601710498333, 0.05237162113189697, 0.040712494403123856, 0.002369559369981289, 0.015844080597162247, 0.009486923925578594, 0.01888337731361389, -0.010944629088044167, 0.07443723827600479, -0.051540251821279526, -0.005121949128806591, 0.023123055696487427, 0.024341057986021042, 0.012573539279401302, -0.0000880120278452523, -0.030021844431757927, -0.006205098237842321, 0.03762400150299072, 0.00956141296774149, 0.01107839960604906, -0.044297657907009125, -0.05625693500041962, -0.03359097242355347, -0.04642060771584511, -0.05243201553821564, -0.0012783159036189318, -0.02375141531229019, 0.051310498267412186, -0.057658154517412186, -0.06361182779073715, 0.02423785626888275, -0.014287054538726807, -0.010398522019386292, 0.02855457179248333, 0.008199275471270084, 0.002444869838654995, -0.006686035543680191, -0.03309938311576843, 0.009477239102125168, 0.04601390287280083, -0.009378562681376934, -0.013929341919720173, 0.03558827564120293, -0.039091724902391434, -0.01024627685546875, -0.010662765242159367, 0.04405602440237999, 0.013364546000957489, -0.012462036684155464, -0.01699848473072052, 0.006738418713212013, -0.02655293233692646, 0.02713533490896225, 0.038199182599782944, 0.02349128946661949, -0.02478571981191635, 0.028224410489201546, 0.03095356933772564, 0.023483335971832275, 0.02710813842713833, 0.039428554475307465, 0.0016117666382342577, -0.05065010488033295, 0.004663965664803982, 0.0208908561617136, 0.01009385846555233, 0.02445833943784237, -0.011443782597780228, -0.011384467594325542, -0.04379987344145775, -0.06458096206188202, 0.02632054314017296, 0.007709158584475517, -0.00770854577422142, -0.01624910533428192, -0.002873932244256139, -0.003669108496978879, -0.013121871277689934, -0.06640835106372833, 0.0064277672208845615, -0.015397804789245129, -0.018386559560894966, 0.0034055227879434824, 0.0012283897958695889, 0.03543088957667351, 0.007224766071885824, 0.0464073084294796, 0.01187058724462986, -0.006947250571101904, -0.62214195728302, 0.008293494582176208, 0.03110245242714882, 0.04517790302634239, -0.016425592824816704, 0.044175226241350174, -0.06988345831632614, 0.02689761482179165, 0.005002903752028942, 0.01167744304984808, 0.009396135807037354, -0.008372653275728226, -0.04814664274454117, -0.0059067253023386, -0.0064735254272818565, -0.05306705832481384, 0.01667771115899086, 0.006055918522179127, -0.07390856742858887, 0.009883993305265903, 0.0232614167034626, -0.015370892360806465, -0.060400206595659256, 0.03169647231698036, -0.018780825659632683, -0.039421964436769485, 0.021726449951529503, 0.008339924737811089, -0.011572099290788174, -0.0418984591960907, -0.027821488678455353, 0.005204560700803995, 0.03254705294966698, -0.013069496490061283, 0.008277611806988716, 0.018462499603629112, 0.053987231105566025, -0.042429789900779724, -0.02138540893793106, -0.01004405040293932, 0.008210099302232265, -0.009348979219794273, -0.0010977656347677112, -0.0394059419631958, -0.052939124405384064, -0.050296325236558914, 0.028633998706936836, -0.042829375714063644, -0.03340253233909607, 0.03408224135637283, -0.007859794422984123, 0.02280614525079727, 0.010973209515213966, 0.0065761348232626915, -0.014103534631431103, -0.05284435302019119, -0.05347215756773949, 0.0026341425254940987, 0.0060866838321089745, 0.02970145270228386, -0.00844328012317419, -0.04371357709169388, -0.021120905876159668, 0.020478999242186546, -0.05112301558256149, -0.010875985026359558, 0.05663366988301277, -0.04640121012926102, -0.003433650592342019, 0.02109808661043644, -0.03246384859085083, -0.06127709150314331, -0.04512334614992142, 0.058213893324136734, 0.022134458646178246, -0.005072867497801781, -0.013368594460189342, 0.006959103979170322, 0.04192629083991051, 0.008271093480288982, 0.015467225573956966, -0.02044222690165043, -0.009139965288341045, 0.018645241856575012, 0.0025249409954994917, 0.001044783741235733, -0.018979543820023537, 0.0023531646002084017, -0.043508466333150864, 0.049847014248371124, 0.023571277037262917, -0.035108644515275955, 0.022216562181711197, 0.005317023489624262, 0.04297461733222008, 0.00848226249217987, -0.0131533807143569, 0.07597164809703827, 0.026606954634189606, 0.04874614253640175, 0.020578039810061455, 0.005136795807629824, -0.034817781299352646, -0.04958050698041916, -0.029562661424279213, -0.02654843032360077, 0.005021078046411276, -0.009902242571115494, 0.05409536138176918, 0.016706977039575577, 0.009065013378858566, 0.004491835832595825, 0.008971557952463627, 0.0033949201460927725, 0.05660267546772957, 0.020167525857686996, -0.004518973641097546, -0.042256325483322144, -0.021578356623649597, 0.001291202032007277, -0.0011949862819164991, -0.03639622777700424, -0.048525482416152954, 0.07935303449630737, -0.006399389356374741, -0.008210304193198681, -0.01696482114493847, -0.030640967190265656, 0.020547926425933838, -0.025708844885230064, -0.012150526978075504, -0.04501597583293915, -0.015053433366119862, -0.0002776089822873473, -0.004916346166282892, -0.02738889493048191, 0.027986040338873863, -0.032016411423683167, 0.028616763651371002, -0.010948137380182743, -0.015026688575744629, -0.025061869993805885, 0.018568532541394234, -0.02097863145172596, 0.02783249318599701, 0.003082349430769682, -0.0010040444321930408, 0.010463099926710129, 0.021689997985959053, 0.007867548614740372, 0.016434885561466217, 0.021259155124425888, -0.005137415137141943, 0.018243171274662018, 0.03039543889462948, -0.009343994781374931, -0.01884511485695839, 0.0281407218426466, 0.059307657182216644, 0.011498337611556053, -0.02239418588578701, -0.0762622207403183, 0.013638587668538094, -0.006567611824721098, 0.0004643059801310301, 0.0213141068816185, -0.016548611223697662, 0.052079711109399796, 0.022311042994260788, -0.004961695056408644, 0.03731269761919975, -0.02517656609416008, 0.010219105519354343, 0.05829476937651634, -0.04219694063067436, 0.018748078495264053, 0.00016080460045486689, 0.013825998641550541, -0.018212376162409782, -0.04181938245892525, -0.0019714704249054193, -0.01731915958225727, -0.0011341749923303723, 0.04106954485177994, 0.029729221016168594, -0.050748128443956375, -0.009032745845615864, 0.004674960393458605, -0.028404230251908302, 0.005183371715247631, -0.024571388959884644, 0.030001305043697357, -0.023734888061881065, -0.018149444833397865, -0.023656640201807022, 0.0018551681423559785, -0.008355687372386456, -0.016077829524874687, 0.017963729798793793, -0.03646719083189964, 0.01713448017835617, 0.04624365270137787, -0.002177573973312974, -0.04786558821797371, -0.0261720959097147, -0.008137679658830166, 0.031248852610588074, -0.003599605057388544, 0.02289443649351597, 0.0005422649555839598, -0.007318311370909214, -0.006205324549227953, 0.033404018729925156, 0.013861425220966339, 0.033827830106019974, 0.03705563023686409, -0.036859799176454544, -0.020211877301335335, 0.03771394491195679, -0.016001921147108078, -0.040996965020895004, -0.05602557584643364, 0.03211721405386925, 0.005384773947298527, -0.01313717756420374, -0.03702219948172569, -0.0333838053047657, 0.003011514898389578, -0.015674974769353867, -0.04860353469848633, 0.03369392454624176, -0.0017191722290590405, 0.003387529868632555, 0.007540811784565449, 0.01020801905542612, 0.06004400551319122, -0.037251316010951996, -0.01737869903445244, 0.02086661569774151, -0.03579462692141533, 0.03808143362402916, 0.0023139461409300566, 0.012536182999610901, 0.018421757966279984, -0.05233996361494064, 0.00156481156591326, -0.00835301261395216, -0.0033878949470818043, -0.00628748070448637, -0.013050132431089878, -0.018402449786663055, -0.012796406634151936, 0.012046714313328266, 0.028577618300914764, 0.008223899640142918, 0.029821261763572693, -0.018576091155409813, -0.002215567510575056, -0.007489967625588179, 0.004323914181441069, 0.020223405212163925, 0.00475861132144928, -0.011864631436765194, -0.0014769716653972864, 0.08553875237703323, 0.052225448191165924, 0.010661124251782894, 0.023870723322033882, -0.0008277066517621279, -0.03372548893094063, -0.0007999532972462475, 0.017077213153243065, -0.0108051598072052, 0.0075918459333479404, -0.000032646090403432027, -0.03711246699094772, -0.041881013661623, 0.005891833920031786, -0.005483116023242474, 0.044301826506853104, -0.04042927920818329, 0.05023413896560669, 0.016425490379333496, 0.021120714023709297, 0.0025400512386113405, 0.012294527143239975, -0.06718212366104126, -0.00419594207778573, -0.020408345386385918, 0.01947570964694023, -0.03162289038300514, -0.026460925117135048, 0.05892381817102432, 0.07354345172643661, -0.021170690655708313, -0.03953349590301514, -0.04363479092717171, 0.010711642913520336, -0.0026672324165701866, 0.0034563797526061535, 0.0359550341963768, -0.019252052530646324, -0.00299268146045506, -0.04199299216270447, 0.005682173650711775, -0.006227588746696711, 0.01595049537718296, 0.0019442258635535836, 0.012298340909183025, -0.023511214181780815, -0.00012423367297742516, 0.06260474771261215, 0.005147633608430624, -0.0063074384815990925, -0.04145156592130661, -0.00626747589558363, 0.02169887162744999, 0.00959230586886406, 0.013902805745601654, 0.002372002461925149, -0.010337403044104576, -0.019852960482239723, -0.01613103784620762, 0.004039202816784382, 0.025784224271774292, -0.0060169510543346405, -0.006979057565331459, -0.021302741020917892, -0.007890000939369202, -0.013778078369796276, -0.0031142488587647676, 0.0068108513951301575, 0.019215980544686317, 0.0018594522261992097, 0.04886632412672043, 0.02961580827832222, 0.03059203363955021, 0.003392226994037628, 0.010191367007791996, -0.01675175130367279, 0.041318152099847794, -0.026638207957148552, -0.05558958277106285, 0.006269749253988266, -0.03149028494954109, -0.0013732293155044317, -0.026693550869822502, -0.03219674900174141, 0.006054516416043043, 0.031524285674095154, -0.023401955142617226, 0.03148559480905533, -0.051284801214933395, 0.030799521133303642, -0.030615508556365967, -0.005542360711842775, 0.021023152396082878, 0.03324355185031891, 0.011940806172788143, -0.008581659756600857, 0.008082377724349499, -0.009709030389785767, -0.000056226312153739855, 0.01670798286795616, -0.0015396242961287498, 0.02422228828072548, -0.009241295978426933, -0.015369498170912266, -0.021520808339118958, -0.00490858219563961, 0.007517728954553604, -0.006877743639051914, -0.0182245634496212, 0.00834628101438284, -0.0009499294101260602, -0.0076533290557563305, -0.02366376481950283, 0.03845449537038803, -0.002048129215836525, -0.05072261393070221, -0.004675915464758873, -0.04549122974276543, 0.027974357828497887, -0.035812824964523315, 0.011119408532977104, 0.005088419653475285, -0.037815287709236145, 0.020849956199526787, -0.0348808579146862, -0.015018418431282043, 0.010877029038965702, -0.031535301357507706, -0.0013865174259990454, 0.036571428179740906, -0.02911563217639923, -0.012228150852024555, 0.007164845243096352, -0.04241602495312691, 0.03526764735579491, 0.003703159047290683, 0.02495577558875084, 0.0115038538351655, -0.02180391363799572, 0.000360715901479125, 0.0020882077515125275, -0.044258661568164825, 0.04537924751639366, 0.01500962395220995, 0.017666054889559746, 0.027184579521417618, -0.011491874232888222, 0.003467103699222207, -0.009739329107105732, -0.060028187930583954, 0.0513654500246048, 0.002665541833266616, -0.0262262225151062, -0.07939834892749786, 0.0224857646971941, -0.021734710782766342, 0.022493058815598488, 0.009316341951489449, -0.019079510122537613, 0.01937815174460411, -0.011764608323574066, -0.02595926821231842, 0.00028126113465987146, 0.010497266426682472, -0.004150384105741978, 0.00828919280320406, 0.010284577496349812, -0.03410472348332405, -0.025649728253483772, -0.0333055816590786, -0.02155259996652603, -0.006969945039600134, 0.004671019036322832, -0.03964097425341606, -0.011680847965180874, 0.007913040928542614, 0.04043858125805855, 0.012996885925531387, 0.009960605762898922, 0.006864030379801989, 0.05310887098312378, -0.13359877467155457, 0.0069663068279623985, -0.002685818588361144, -0.008890247903764248, -0.00985125731676817, 0.04069992154836655, 0.009020217694342136, 0.004791609477251768, 0.008883762173354626, -0.03966188058257103, -0.007062473334372044, -0.04664616286754608, 0.025268372148275375, 0.025420598685741425, 0.007368858437985182, -0.0010379361920058727, 0.001396759646013379, -0.012607360258698463, -0.028084151446819305, -0.04555494338274002, -0.0027028843760490417, 0.023827629163861275, -0.02107873000204563, 0.005163556430488825, -0.003627720521762967, -0.011104356497526169, 0.02023847959935665, -0.003967582248151302, 0.014911368489265442, 0.0014852886088192463, 0.019849464297294617, -0.006931190844625235, -0.030848119407892227, 0.010328182950615883, 0.011254586279392242, -0.03325938433408737, 0.016427526250481606, -0.0051255966536700726, 0.034141648560762405, 0.014656287617981434, -0.004116477444767952, 0.020694242790341377, -0.040441084653139114, 0.003924718592315912, 0.01799256168305874, -0.011066668666899204, -0.018151506781578064, 0.006572585552930832, 0.004362569656223059, 0.02959004044532776, -0.011396272107958794, 0.019920429214835167, -0.0014706915244460106, 0.061247505247592926, 0.016604091972112656, -0.020122062414884567, 0.01286705955862999, 0.03295201063156128, -0.06414615362882614, 0.05928919464349747, 0.031539734452962875, 0.034622013568878174, 0.01985241286456585, 0.009246834553778172, -0.020167510956525803, 0.011061298660933971, -0.00802722480148077, 0.023466505110263824, 0.021417345851659775, 0.023636573925614357, 0.037621237337589264, 0.03994579613208771, 0.00853088591247797, -0.005606731399893761, -0.020832818001508713, 0.03191154822707176, -0.00045156374108046293, 0.024628736078739166, -0.02534433826804161, -0.007566291373223066, 0.02117304690182209, -0.02043594792485237, -0.032804589718580246, 0.03324783593416214, -0.019388636574149132, 0.023250576108694077, 0.014159130863845348, -0.01808985322713852, 0.019062532112002373, 0.0064856912940740585, -0.008906206116080284, -0.006091565825045109, 0.0378531739115715, -0.06949601322412491, -0.005266787484288216, -0.006260813679546118, 0.012616241350769997, -0.0026402631774544716, -0.035269033163785934, -0.022105084732174873, -0.032661084085702896, -0.012089414522051811, -0.016091538593173027, 0.038822393864393234, -0.002160734264180064, -0.019311172887682915, -0.038345739245414734, -0.009269848465919495, -0.011220348067581654, -0.0031650327146053314, -0.034597452729940414, 0.022192122414708138, 0.0769488736987114, 0.011855553835630417, -0.0438823364675045, 0.009160424582660198, 0.03708379343152046 ]
8ad221c93a5fce8d825d0b6b80fc2f401b373d9b
7,627
py
Python
gn/gn_to_bp.py
despairblue/esy-skia
1c81aac298602f8e872c1079db92868199b6394f
[ "BSD-3-Clause" ]
2,151
2020-04-18T07:31:17.000Z
2022-03-31T08:39:18.000Z
gn/gn_to_bp.py
despairblue/esy-skia
1c81aac298602f8e872c1079db92868199b6394f
[ "BSD-3-Clause" ]
395
2020-04-18T08:22:18.000Z
2021-12-08T13:04:49.000Z
gn/gn_to_bp.py
despairblue/esy-skia
1c81aac298602f8e872c1079db92868199b6394f
[ "BSD-3-Clause" ]
338
2020-04-18T08:03:10.000Z
2022-03-29T12:33:22.000Z
#!/usr/bin/env python # # Copyright 2016 Google Inc. # # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. # Generate Android.bp for Skia from GN configuration. import json import os import pprint import string import subprocess import tempfile import gn_to_bp_utils # First we start off with a template for Android.bp, # with holes for source lists and include directories. bp = string.Template('''// This file is autogenerated by gn_to_bp.py. cc_library_static { name: "libskia", cflags: [ $cflags ], cppflags:[ $cflags_cc ], export_include_dirs: [ $export_includes ], local_include_dirs: [ $local_includes ], srcs: [ $srcs ], arch: { arm: { srcs: [ $arm_srcs ], neon: { srcs: [ $arm_neon_srcs ], }, }, arm64: { srcs: [ $arm64_srcs ], }, mips: { srcs: [ $none_srcs ], }, mips64: { srcs: [ $none_srcs ], }, x86: { srcs: [ $x86_srcs ], cflags: [ // Clang seems to think new/malloc will only be 4-byte aligned // on x86 Android. We're pretty sure it's actually 8-byte // alignment. tests/OverAlignedTest.cpp has more information, // and should fail if we're wrong. "-Wno-over-aligned" ], }, x86_64: { srcs: [ $x86_srcs ], }, }, defaults: ["skia_deps", "skia_pgo", ], } // Build libskia with PGO by default. // Location of PGO profile data is defined in build/soong/cc/pgo.go // and is separate from skia. // To turn it off, set ANDROID_PGO_NO_PROFILE_USE environment variable // or set enable_profile_use property to false. cc_defaults { name: "skia_pgo", pgo: { instrumentation: true, profile_file: "hwui/hwui.profdata", benchmarks: ["hwui", "skia"], enable_profile_use: true, }, } // "defaults" property to disable profile use for Skia tools and benchmarks. cc_defaults { name: "skia_pgo_no_profile_use", defaults: [ "skia_pgo", ], pgo: { enable_profile_use: false, }, } cc_defaults { name: "skia_deps", shared_libs: [ "libEGL", "libGLESv2", "libdng_sdk", "libexpat", "libft2", "libheif", "libicui18n", "libicuuc", "libjpeg", "liblog", "libpiex", "libpng", "libvulkan", "libz", "libcutils", "libnativewindow", ], static_libs: [ "libarect", "libsfntly", "libwebp-decode", "libwebp-encode", ], group_static_libs: true, } cc_defaults { name: "skia_tool_deps", defaults: [ "skia_deps", "skia_pgo_no_profile_use" ], static_libs: [ "libjsoncpp", "libskia", ], cflags: [ "-Wno-unused-parameter", "-Wno-unused-variable", ], } cc_test { name: "skia_dm", defaults: [ "skia_tool_deps" ], local_include_dirs: [ $dm_includes ], srcs: [ $dm_srcs ], shared_libs: [ "libbinder", "libutils", ], } cc_test { name: "skia_nanobench", defaults: [ "skia_tool_deps" ], local_include_dirs: [ $nanobench_includes ], srcs: [ $nanobench_srcs ], data: [ "resources/*", ], }''') # We'll run GN to get the main source lists and include directories for Skia. gn_args = { 'is_official_build': 'true', 'skia_enable_tools': 'true', 'skia_enable_skottie': 'false', # requires rapidjson third-party 'skia_use_libheif': 'true', 'skia_use_vulkan': 'true', 'target_cpu': '"none"', 'target_os': '"android"', 'skia_vulkan_header': '"Skia_Vulkan_Android.h"', } js = gn_to_bp_utils.GenerateJSONFromGN(gn_args) def strip_slashes(lst): return {str(p.lstrip('/')) for p in lst} srcs = strip_slashes(js['targets']['//:skia']['sources']) cflags = strip_slashes(js['targets']['//:skia']['cflags']) cflags_cc = strip_slashes(js['targets']['//:skia']['cflags_cc']) local_includes = strip_slashes(js['targets']['//:skia']['include_dirs']) export_includes = strip_slashes(js['targets']['//:public']['include_dirs']) defines = [str(d) for d in js['targets']['//:skia']['defines']] dm_srcs = strip_slashes(js['targets']['//:dm']['sources']) dm_includes = strip_slashes(js['targets']['//:dm']['include_dirs']) nanobench_target = js['targets']['//:nanobench'] nanobench_srcs = strip_slashes(nanobench_target['sources']) nanobench_includes = strip_slashes(nanobench_target['include_dirs']) gn_to_bp_utils.GrabDependentValues(js, '//:skia', 'sources', srcs, None) gn_to_bp_utils.GrabDependentValues(js, '//:dm', 'sources', dm_srcs, 'skia') gn_to_bp_utils.GrabDependentValues(js, '//:nanobench', 'sources', nanobench_srcs, 'skia') # skcms is a little special, kind of a second-party library. srcs .add("third_party/skcms/skcms.c") local_includes.add("third_party/skcms") dm_includes .add("third_party/skcms") # No need to list headers. srcs = {s for s in srcs if not s.endswith('.h')} dm_srcs = {s for s in dm_srcs if not s.endswith('.h')} nanobench_srcs = {s for s in nanobench_srcs if not s.endswith('.h')} cflags = gn_to_bp_utils.CleanupCFlags(cflags) cflags_cc = gn_to_bp_utils.CleanupCCFlags(cflags_cc) # We need to add the include path to the vulkan defines and header file set in # then skia_vulkan_header gn arg that is used for framework builds. local_includes.add("platform_tools/android/vulkan") export_includes.add("platform_tools/android/vulkan") here = os.path.dirname(__file__) defs = gn_to_bp_utils.GetArchSources(os.path.join(here, 'opts.gni')) gn_to_bp_utils.WriteUserConfig('include/config/SkUserConfig.h', defines) # Turn a list of strings into the style bpfmt outputs. def bpfmt(indent, lst, sort=True): if sort: lst = sorted(lst) return ('\n' + ' '*indent).join('"%s",' % v for v in lst) # OK! We have everything to fill in Android.bp... with open('Android.bp', 'w') as f: print >>f, bp.substitute({ 'export_includes': bpfmt(8, export_includes), 'local_includes': bpfmt(8, local_includes), 'srcs': bpfmt(8, srcs), 'cflags': bpfmt(8, cflags, False), 'cflags_cc': bpfmt(8, cflags_cc), 'arm_srcs': bpfmt(16, defs['armv7']), 'arm_neon_srcs': bpfmt(20, defs['neon']), 'arm64_srcs': bpfmt(16, defs['arm64'] + defs['crc32']), 'none_srcs': bpfmt(16, defs['none']), 'x86_srcs': bpfmt(16, defs['sse2'] + defs['ssse3'] + defs['sse41'] + defs['sse42'] + defs['avx' ] + defs['hsw' ]), 'dm_includes' : bpfmt(8, dm_includes), 'dm_srcs' : bpfmt(8, dm_srcs), 'nanobench_includes' : bpfmt(8, nanobench_includes), 'nanobench_srcs' : bpfmt(8, nanobench_srcs), })
25.006557
78
0.556051
1
2.2191
[ -0.047993406653404236, 0.04077566787600517, 0.038308434188365936, 0.007410814054310322, -0.039217233657836914, -0.038297247141599655, 0.015818975865840912, -0.0034470343962311745, -0.021888533607125282, -0.017617110162973404, 0.03578406944870949, 0.013972929678857327, 0.030145589262247086, -0.01284907478839159, -0.04139413684606552, -0.020343158394098282, 0.08099731057882309, 0.028026459738612175, -0.052162978798151016, 0.025131989270448685, 0.023780647665262222, -0.0030421307310462, -0.006025043781846762, 0.051435504108667374, 0.008260614238679409, -0.017939092591404915, -0.006400261074304581, 0.01934967190027237, -0.03965575993061066, -0.06973938643932343, -0.017034508287906647, -0.01931571029126644, 0.004039245657622814, 0.024997197091579437, -0.022012507542967796, -0.010833295993506908, 0.02298291213810444, -0.04578311741352081, 0.013184997253119946, -0.0176942627876997, 0.0026610800996422768, 0.023866591975092888, 0.016136150807142258, -0.042971447110176086, 0.0483994334936142, -0.03852761164307594, 0.003896955167874694, 0.024990038946270943, -0.04279806837439537, 0.04603137820959091, 0.06766112893819809, 0.008588084019720554, -0.014575234614312649, -0.015459906309843063, 0.029383687302470207, -0.03861862048506737, 0.004947155248373747, 0.011761329136788845, 0.006883619353175163, -0.000718139111995697, -0.05053263530135155, 0.010661734268069267, 0.007369098253548145, 0.027082275599241257, 0.01177639327943325, -0.005270460154861212, 0.02869696170091629, -0.01041380874812603, -0.004669752437621355, -0.020701507106423378, -0.04470096901059151, -0.01900635100901127, 0.05912376195192337, 0.055419426411390305, -0.02644951082766056, 0.034862879663705826, -0.02865545079112053, 0.014316828921437263, 0.009754406288266182, -0.030182167887687683, -0.020576588809490204, 0.041159652173519135, -0.015214371494948864, 0.012820432893931866, -0.004348653834313154, 0.055921364575624466, 0.05627180263400078, -0.04787880927324295, 0.04327307641506195, 0.005078633315861225, -0.02634543552994728, 0.006135590374469757, -0.02436809241771698, -0.013654200360178947, -0.002906369511038065, -0.04666193202137947, 0.010819724760949612, -0.01892770826816559, -0.027356617152690887, -0.04498094320297241, 0.011122438125312328, 0.0048879412934184074, 0.052609920501708984, -0.011963381431996822, -0.0006839656853117049, 0.0491122268140316, -0.02367090806365013, 0.022063767537474632, -0.012253926135599613, -0.04398242011666298, -0.011094169691205025, -0.04478437826037407, 0.015826499089598656, -0.031678956001996994, -0.034034259617328644, -0.010560334660112858, 0.020557597279548645, -0.0036261840723454952, 0.0024975151754915714, -0.012368482537567616, -0.01588326506316662, 0.022470464929938316, -0.0038895620964467525, 0.039928849786520004, -0.0033229957334697247, 0.058446962386369705, 0.04191675782203674, 0.01353425346314907, 0.005829550325870514, 0.014954589307308197, -0.036308594048023224, 0.004434745293110609, 0.004598167724907398, -0.0015460698632523417, 0.027163513004779816, 0.032334815710783005, 0.030834082514047623, -0.011276778765022755, -0.03695400059223175, 0.029130050912499428, -0.011998780071735382, -0.04336736351251602, 0.026193302124738693, -0.05762917920947075, 0.020896151661872864, -0.006454648450016975, -0.034224510192871094, 0.0034734602086246014, -0.010390464216470718, -0.00784062035381794, 0.044519275426864624, -0.011876906268298626, 0.003531747730448842, 0.04554521292448044, 0.0011125026503577828, -0.023914119228720665, -0.002736341441050172, -0.03812418878078461, -0.010681490413844585, 0.005849996116012335, -0.01722773350775242, -0.005990306846797466, 0.008889024145901203, -0.011837376281619072, -0.017685888335108757, -0.005251595284789801, -0.021132519468665123, -0.002173317363485694, -0.01047053374350071, 0.020995784550905228, -0.026043811812996864, 0.0445074625313282, -0.004628610797226429, -0.03239064663648605, -0.06872078776359558, 0.03281989321112633, -0.007499664556235075, -0.008461586199700832, 0.034576766192913055, -0.007810378912836313, -0.003165276488289237, 0.016921324655413628, 0.08578342199325562, 0.01586770825088024, 0.014091660268604755, -0.024122705683112144, -0.007916013710200787, -0.0013292639050632715, -0.025510642677545547, -0.03313244506716728, 0.0005325177335180342, 0.03965325281023979, -0.0068532670848071575, -0.01848919689655304, 0.008836815133690834, -0.00445921765640378, 0.00022896927839610726, 0.02640949934720993, -0.005938390269875526, 0.0391940213739872, 0.031175419688224792, 0.023139800876379013, 0.05256801098585129, 0.009488004259765148, 0.01364152878522873, -0.00457773869857192, -0.6470921039581299, -0.005398241337388754, 0.04991611838340759, -0.006791239138692617, 0.008001940324902534, 0.01344249490648508, -0.018522318452596664, 0.006385915447026491, -0.07019424438476562, -0.021879972890019417, -0.007326050661504269, -0.023521745577454567, -0.04801349714398384, -0.013899528421461582, 0.003909813240170479, -0.026732245460152626, 0.014427089132368565, -0.024074627086520195, -0.006387072615325451, -0.00993762630969286, 0.01377223152667284, 0.022831134498119354, -0.014954417943954468, -0.005469601135700941, -0.009207780472934246, -0.008097730576992035, 0.018863363191485405, 0.03319834545254707, 0.040361810475587845, -0.016544846817851067, 0.025778470560908318, -0.013488645665347576, 0.008131486363708973, 0.03683044761419296, -0.015341762453317642, 0.045958805829286575, 0.04297870025038719, -0.007706515956670046, 0.04320748895406723, 0.002680739387869835, -0.024944474920630455, 0.004898547660559416, -0.049914151430130005, -0.08026645332574844, -0.0012262874515727162, -0.023920929059386253, -0.04986685886979103, 0.003964423201978207, -0.022589361295104027, 0.020506132394075394, -0.031584519892930984, 0.05451112240552902, 0.02002425491809845, -0.031101055443286896, -0.016864506527781487, -0.0028466139920055866, -0.02689014934003353, -0.011799818836152554, 0.006439980585128069, -0.0035040422808378935, 0.04518831521272659, 0.035314783453941345, 0.007728685159236193, 0.006523888558149338, 0.01665586605668068, 0.031226545572280884, 0.029046284034848213, -0.05619862675666809, -0.011760445311665535, 0.05685574933886528, -0.019138287752866745, -0.0055230120196938515, -0.0361306294798851, 0.05130888149142265, -0.00522371381521225, 0.026205729693174362, -0.0022636796347796917, -0.014611875638365746, -0.01742231473326683, -0.00940707791596651, 0.024021275341510773, 0.005374963395297527, 0.001363856252282858, -0.013271103613078594, -0.015130885876715183, 0.010494861751794815, 0.020182766020298004, -0.024055205285549164, 0.0048093488439917564, 0.005546877160668373, 0.05046890303492546, 0.043842703104019165, 0.0296026561409235, 0.0058917878195643425, 0.000060487367591122165, -0.02159254066646099, 0.03632224723696709, 0.026510801166296005, 0.019196640700101852, 0.03283025696873665, -0.028168149292469025, 0.03512602671980858, -0.014409025199711323, 0.030842894688248634, 0.006298265419900417, -0.037462301552295685, -0.019652459770441055, 0.019556669518351555, 0.05772366374731064, 0.00864262506365776, -0.06259557604789734, 0.008614487946033478, 0.003516670549288392, -0.018302075564861298, 0.010174688883125782, -0.04649481549859047, 0.01798379234969616, -0.025158291682600975, -0.005059973336756229, -0.013565597124397755, 0.011271130293607712, 0.004327284172177315, -0.0021015943493694067, -0.033655520528554916, 0.02801942080259323, -0.0125189907848835, -0.014749766327440739, 0.009382841177284718, 0.02258331887423992, 0.021427523344755173, -0.051119543612003326, -0.025858918204903603, -0.05520222336053848, 0.004030048847198486, 0.007862597703933716, -0.04190564528107643, -0.02951733209192753, -0.04656187444925308, 0.0021035645622760057, 0.00561824394389987, -0.020219704136252403, 0.027277635410428047, 0.027352524921298027, -0.024749988690018654, 0.02008751593530178, 0.007043279241770506, 0.019775528460741043, -0.02106374502182007, 0.05173579603433609, -0.003139740787446499, -0.009456301108002663, -0.003142119850963354, -0.023515082895755768, -0.01357214618474245, -0.01987774297595024, -0.004773436579853296, -0.03507247194647789, 0.016638774424791336, 0.03181592375040054, 0.02017279714345932, -0.019335096701979637, -0.014784978702664375, 0.012304037809371948, 0.01821167767047882, 0.01471405103802681, -0.005436479113996029, 0.03113270178437233, -0.006369512993842363, 0.022817285731434822, 0.003919859416782856, 0.05802419036626816, 0.0005618305876851082, 0.014660067856311798, -0.022108478471636772, -0.062085896730422974, 0.014159396290779114, -0.013134240172803402, -0.015056910924613476, -0.01892841048538685, -0.019221970811486244, -0.02956223115324974, 0.014124077744781971, 0.00019713991787284613, -0.058446936309337616, -0.013886968605220318, -0.013851074501872063, -0.0048507386818528175, -0.03449077904224396, 0.011526967398822308, -0.02175516076385975, -0.0018608159152790904, 0.029309473931789398, -0.010347663424909115, 0.010879642330110073, -0.02876664139330387, -0.023139996454119682, -0.014355809427797794, -0.0037550877314060926, -0.01076679490506649, -0.04955778270959854, 0.04945841059088707, 0.007708531804382801, -0.00819628220051527, 0.00044967763824388385, 0.02731442265212536, 0.06746181845664978, -0.04045117273926735, -0.03220988065004349, 0.03906773403286934, -0.02756335400044918, 0.010700583457946777, -0.016806943342089653, 0.044839490205049515, -0.017740629613399506, 0.009061623364686966, 0.01233117189258337, -0.037007834762334824, -0.041244201362133026, 0.004036241210997105, -0.060905907303094864, 0.015307875350117683, -0.01775141805410385, 0.029056526720523834, -0.0033413388300687075, -0.013500945642590523, -0.0060350061394274235, -0.021841295063495636, 0.03275859355926514, -0.010981089435517788, -0.012686743400990963, 0.03653297200798988, 0.006861534900963306, -0.005287909880280495, 0.003123465459793806, -0.011482897214591503, -0.005259829107671976, -0.03640726953744888, -0.05464912950992584, 0.001074141589924693, -0.03325768932700157, -0.012184230610728264, -0.022141844034194946, -0.03131578490138054, 0.06315834075212479, 0.03181295096874237, -0.01810077205300331, -0.007570698857307434, -0.048268742859363556, -0.008399585261940956, -0.013592297211289406, -0.03078300692141056, -0.018036777153611183, -0.004438367672264576, 0.010792246088385582, 0.05044393613934517, -0.0046049850061535835, -0.04065566137433052, 0.011504665948450565, -0.009579346515238285, -0.01221411395817995, -0.022429151460528374, 0.0030868230387568474, -0.023869436234235764, -0.0028122675139456987, -0.011826178058981895, -0.01238239835947752, -0.014873551204800606, 0.012649009935557842, -0.013139473274350166, 0.0454939566552639, 0.0013649794273078442, 0.013043906539678574, -0.027952589094638824, 0.0038048899732530117, 0.0029650183860212564, -0.00585749838501215, 0.017043115571141243, -0.030127571895718575, 0.02046150155365467, 0.02258870378136635, -0.035451170057058334, -0.015918640419840813, -0.025627970695495605, 0.007067370228469372, -0.030337776988744736, 0.013010621070861816, -0.017214929684996605, -0.0394120030105114, -0.0729827880859375, -0.011474721133708954, -0.01742512546479702, -0.04632973670959473, 0.032786425203084946, 0.08089403808116913, -0.010831965133547783, -0.024434629827737808, -0.0317041352391243, 0.014507150277495384, 0.006534408777952194, 0.02896047569811344, 0.024596674367785454, 0.02708512730896473, -0.022154122591018677, -0.0009502393659204245, -0.04172350838780403, 0.011790680699050426, 0.009678125381469727, -0.0004502000811044127, 0.013283103704452515, 0.04308972880244255, -0.001600840361788869, 0.05807490646839142, -0.006454905495047569, -0.03373954817652702, 0.008977832272648811, 0.000051165516197215766, 0.07153385132551193, 0.02737860381603241, 0.027586419135332108, 0.018200794234871864, -0.03217468038201332, 0.008889742195606232, -0.03417520597577095, -0.03544335812330246, 0.009602499194443226, 0.01683383248746395, -0.03664875030517578, -0.046230658888816833, -0.01571415178477764, -0.0015030002687126398, -0.03707822412252426, -0.030235620215535164, -0.016868943348526955, 0.015696901828050613, 0.01694866083562374, -0.0548698827624321, 0.021287191659212112, 0.03956424817442894, 0.026550572365522385, 0.008049089461565018, -0.0028758884873241186, 0.03755958750844002, -0.005980385467410088, -0.005638553760945797, 0.01577957347035408, -0.00358301168307662, -0.015680963173508644, 0.025168413296341896, -0.0016440271865576506, -0.005923474673181772, 0.025501737371087074, 0.029928473755717278, -0.006059837061911821, 0.018535910174250603, -0.03516392782330513, -0.030020635575056076, -0.00459508690983057, -0.008238278329372406, 0.0036811549216508865, 0.033468909561634064, 0.011090299114584923, -0.007278889417648315, -0.04312894120812416, 0.000391592038795352, -0.0147719606757164, -0.048324085772037506, 0.061339784413576126, 0.012271699495613575, -0.007487508933991194, 0.03520697355270386, -0.03506357595324516, -0.0448608472943306, 0.0004822816699743271, -0.014495743438601494, -0.005869292188435793, 0.014149703085422516, 0.0379175990819931, 0.026436246931552887, 0.0010136655764654279, 0.020241079851984978, -0.006678201723843813, 0.022505037486553192, -0.004780589137226343, 0.0176920797675848, 0.013164475560188293, 0.024798275902867317, -0.017863266170024872, 0.01174358930438757, -0.002721860073506832, 0.012050109915435314, -0.020023519173264503, 0.002880790503695607, 0.0185298603028059, 0.01691475883126259, 0.043371040374040604, -0.014082278124988079, 0.014171694405376911, 0.004688232205808163, 0.003981823101639748, 0.0009142828639596701, -0.03134789317846298, -0.014044427312910557, 0.01273084431886673, 0.013024341315031052, 0.054023463279008865, -0.013092828914523125, -0.04429684579372406, 0.0025380486622452736, 0.009972883388400078, 0.009136782959103584, 0.03294536471366882, -0.03131115809082985, -0.062049224972724915, -0.014027699828147888, -0.007483642548322678, 0.009116604924201965, -0.03106597065925598, 0.00920089427381754, -0.038362935185432434, 0.034568239003419876, -0.00554340286180377, -0.02350454404950142, 0.0051355985924601555, -0.0051248385570943356, -0.049288343638181686, -0.029528947547078133, -0.001403536880388856, -0.020387077704072, -0.0013392416294664145, 0.0017395970644429326, 0.0009944544872269034, 0.027748676016926765, 0.029372747987508774, -0.014255321584641933, 0.013287095353007317, -0.008138577453792095, -0.013938558287918568, 0.01637573353946209, 0.018351169303059578, 0.0027874710503965616, -0.012698443606495857, 0.010665137320756912, 0.037646129727363586, 0.040512558072805405, 0.026048019528388977, -0.012234200723469257, 0.006800083909183741, 0.0028265437576919794, -0.015451773069798946, -0.006658236496150494, 0.0018097910797223449, 0.03754236176609993, 0.024681927636265755, 0.0007144319824874401, 0.014002722688019276, 0.004608151502907276, 0.014475792646408081, 0.006613719742745161, -0.005474715493619442, 0.027366356924176216, 0.04168237745761871, 0.024721993133425713, -0.017240403220057487, 0.059797726571559906, 0.04281340911984444, 0.021550657227635384, 0.006676350254565477, -0.019401179626584053, -0.021023977547883987, 0.001449037343263626, -0.045430898666381836, 0.03349993750452995, -0.016371507197618484, 0.014216803945600986, -0.02756664901971817, 0.029470616951584816, -0.04226403683423996, -0.019082723185420036, 0.015314850024878979, 0.013848693110048771, -0.09262830764055252, 0.026015225797891617, 0.005185424815863371, -0.012869703583419323, 0.0117519311606884, 0.02453528344631195, -0.02924521639943123, 0.034546658396720886, -0.02280006930232048, 0.0275817159563303, 0.005072659347206354, -0.021803785115480423, 0.03310532495379448, 0.05494223162531853, 0.028638945892453194, -0.0048963227309286594, -0.00945043284446001, 0.06172289326786995, 0.05350504443049431, 0.00569750415161252, -0.021321546286344528, -0.021452702581882477, 0.025967523455619812, -0.0008006064454093575, 0.023921703919768333, 0.0012327538570389152, 0.045286308974027634, 0.029811548069119453, 0.023934129625558853, -0.04590954631567001, -0.04955538734793663, -0.03055642731487751, -0.018260927870869637, 0.022180767729878426, 0.04358277842402458, 0.02998763509094715, 0.044496651738882065, -0.03516193851828575, -0.049687206745147705, 0.022353196516633034, 0.006725169252604246, 0.04491441324353218, 0.0018955442355945706, 0.015641625970602036, -0.023249762132763863, -0.005636833142489195, -0.03142085298895836, -0.02556740492582321, 0.03323802351951599, 0.02871318906545639, 0.012754140421748161, 0.011868134140968323, -0.015103629790246487, -0.021013528108596802, 0.021720344200730324, -0.07171206176280975, -0.0009776984807103872, 0.01610967330634594, -0.011529400944709778, -0.03467639535665512, 0.03026924841105938, -0.006697007920593023, -0.04187016189098358, -0.02325376309454441, -0.042076412588357925, -0.0040480890311300755, -0.006521078757941723, 0.00866330973803997, 0.022048674523830414, 0.02726973034441471, 0.01396879367530346, 0.0018606979865580797, -0.013856661505997181, 0.032902345061302185, -0.016486095264554024, -0.033399201929569244, -0.010248282924294472, 0.04146895930171013, -0.02026798203587532, -0.05563442409038544, -0.0026617124676704407, 0.009243696928024292 ]
8ad263d1cb0c4c04603f5f92c314ea18d8d73526
1,681
py
Python
python/ray/autoscaler/tags.py
firebolt55439/ray
215300b070628c06f0106906fc6c03bd70ebf140
[ "Apache-2.0" ]
21,382
2016-09-26T23:12:52.000Z
2022-03-31T21:47:45.000Z
python/ray/autoscaler/tags.py
firebolt55439/ray
215300b070628c06f0106906fc6c03bd70ebf140
[ "Apache-2.0" ]
19,689
2016-09-17T08:21:25.000Z
2022-03-31T23:59:30.000Z
python/ray/autoscaler/tags.py
firebolt55439/ray
215300b070628c06f0106906fc6c03bd70ebf140
[ "Apache-2.0" ]
4,114
2016-09-23T18:54:01.000Z
2022-03-31T15:07:32.000Z
"""The Ray autoscaler uses tags/labels to associate metadata with instances.""" # Tag for the name of the node TAG_RAY_NODE_NAME = "ray-node-name" # Tag for the kind of node (e.g. Head, Worker). For legacy reasons, the tag # value says 'type' instead of 'kind'. TAG_RAY_NODE_KIND = "ray-node-type" NODE_KIND_HEAD = "head" NODE_KIND_WORKER = "worker" NODE_KIND_UNMANAGED = "unmanaged" # Tag for user defined node types (e.g., m4xl_spot). This is used for multi # node type clusters. TAG_RAY_USER_NODE_TYPE = "ray-user-node-type" # Tag for autofilled node types for legacy cluster yamls without multi # node type defined in the cluster configs. NODE_TYPE_LEGACY_HEAD = "ray-legacy-head-node-type" NODE_TYPE_LEGACY_WORKER = "ray-legacy-worker-node-type" # Tag that reports the current state of the node (e.g. Updating, Up-to-date) TAG_RAY_NODE_STATUS = "ray-node-status" STATUS_UNINITIALIZED = "uninitialized" STATUS_WAITING_FOR_SSH = "waiting-for-ssh" STATUS_SYNCING_FILES = "syncing-files" STATUS_SETTING_UP = "setting-up" STATUS_UPDATE_FAILED = "update-failed" STATUS_UP_TO_DATE = "up-to-date" # Tag uniquely identifying all nodes of a cluster TAG_RAY_CLUSTER_NAME = "ray-cluster-name" # Hash of the node launch config, used to identify out-of-date nodes TAG_RAY_LAUNCH_CONFIG = "ray-launch-config" # Hash of the node runtime config, used to determine if updates are needed TAG_RAY_RUNTIME_CONFIG = "ray-runtime-config" # Hash of the contents of the directories specified by the file_mounts config # if the node is a worker, this also hashes content of the directories # specified by the cluster_synced_files config TAG_RAY_FILE_MOUNTS_CONTENTS = "ray-file-mounts-contents"
40.02381
79
0.781678
1
1.2546
[ 0.0023180374410003424, 0.02548973634839058, 0.00835669320076704, 0.0003156351449433714, 0.006691521964967251, -0.0041824993677437305, -0.011208401061594486, 0.001430922420695424, -0.008658691309392452, 0.001016263384371996, 0.003934772685170174, 0.0043863169848918915, 0.008311954326927662, -0.015329799614846706, 0.0034225566778331995, 0.01803773082792759, -0.053835801780223846, 0.001696859602816403, -0.004552063066512346, 0.00035881513031199574, -0.007131987251341343, 0.009249226190149784, 0.00924475584179163, 0.005665733944624662, 0.0062006935477256775, 0.0012809388572350144, 0.0072415596805512905, 0.003715950297191739, -0.008615102618932724, -0.0066878339275717735, 0.0007154624327085912, 0.000054431606258731335, -0.004765264689922333, -0.007607885170727968, 0.0066204555332660675, -0.004515802022069693, -0.0018262029625475407, -0.022689206525683403, 0.013574270531535149, -0.006737992633134127, -0.007517737336456776, -0.01668204367160797, -0.0024582550395280123, 0.0036241887137293816, -0.009340924210846424, -0.001790231792256236, -0.0023183368612080812, 0.003782659536227584, -0.008719365112483501, 0.00912354327738285, -0.010816331952810287, 0.0063120052218437195, 0.013199777342379093, 0.001325951307080686, -0.007295382674783468, -0.004828964825719595, 0.013414000160992146, -0.00030066861654631793, -0.012514028698205948, -0.00013562994718085974, -0.003731059841811657, -0.0009559476748108864, 0.005575291346758604, 0.005251254420727491, -0.01832885853946209, -0.0059324293397367, -0.0015481363516300917, 0.0029490997549146414, 0.002309920499101281, 0.006453698500990868, 0.0003666481643449515, -0.00021087800269015133, 0.006476576440036297, 0.0042816633358597755, 0.00690044229850173, -0.002860689302906394, -0.002245806623250246, 0.0010785851627588272, 0.011980804614722729, 0.0010897819884121418, 0.0023033402394503355, -0.007960667833685875, 0.00569377513602376, 0.00966457650065422, 0.01417009998112917, 0.008981474675238132, 0.01886032149195671, -0.012789606116712093, 0.044978201389312744, 0.007022019010037184, -0.010003207251429558, 0.004148772917687893, -0.006807901430875063, -0.001169952447526157, -0.0003351785708218813, -0.029276032000780106, 0.0006917387945577502, -0.003765706904232502, -0.0017719673924148083, 0.003196254838258028, -0.005820662248879671, 0.003995075356215239, -0.0025879330933094025, 0.00022690027253702283, -0.007790575735270977, 0.010741336271166801, -0.008688602596521378, -0.0024950033985078335, 0.005768960807472467, 0.002349836053326726, -0.012945668771862984, -0.0017532218480482697, 0.001952875405550003, -0.01029247883707285, 0.0040065268985927105, 0.004949780646711588, -0.005994936916977167, 0.05584447458386421, -0.0013583096442744136, 0.004763762466609478, -0.004469842649996281, 0.0003541842452250421, 0.0010902228532359004, 0.006885717157274485, 0.00942504033446312, -0.004035060293972492, 0.011142022907733917, 0.006848105229437351, 0.0024580559693276882, 0.008050997741520405, -0.0037801447324454784, 0.005706522148102522, -0.006006654351949692, -0.0026969166938215494, 0.0021922364830970764, -0.008648373186588287, 0.007447432726621628, -0.002658506855368614, -0.008250907994806767, -0.00044187376624904573, -0.0005582150188274682, -0.010965481400489807, 0.0001810597168514505, -0.004300083499401808, 0.003607669845223427, -0.011508705094456673, -0.003932632971554995, -0.0033229098189622164, -0.005360868759453297, 0.0028164635878056288, 0.011644912883639336, 0.0026300763711333275, 0.002660040045157075, -0.004223755095154047, -0.010576567612588406, 0.0009946527425199747, -0.0028609430883079767, 0.0036043620202690363, 0.009663617238402367, 0.0033725753892213106, -0.008585074916481972, -0.0016145023982971907, 0.003459581872448325, 0.004700191784650087, -0.0016266548773273826, 0.0006572222919203341, -0.008649244904518127, 0.008571870625019073, 0.0004356049466878176, 0.005456123035401106, 0.013362042605876923, -0.002828666241839528, -0.0002796993649099022, 0.0015406397869810462, -0.0012075976701453328, -0.0014096208615228534, 0.006838228553533554, 0.008190609514713287, -0.0021582841873168945, -0.003848366905003786, 0.003049749182537198, 0.0014032918261364102, 0.0107354037463665, 0.006354973651468754, -0.004137096460908651, 0.0006479606963694096, -0.002660504076629877, -0.00009466183109907433, 0.00503352889791131, -0.005703259259462357, 0.0044993385672569275, 0.004810584243386984, -0.013502330519258976, -0.01015909668058157, 0.0008733271970413625, -0.009517169557511806, 0.0003947385703213513, 0.014230147935450077, 0.010147820226848125, -0.002596923615783453, 0.0021453266963362694, -0.0083401994779706, 0.002748242812231183, 0.008396479301154613, -0.0004823652852792293, -0.013374573551118374, -0.9570608139038086, 0.007598837837576866, 0.000683470512740314, -0.0013300336431711912, 0.004291399847716093, 0.0029933899641036987, 0.00516253337264061, 0.002569835167378187, 0.018000470474362373, -0.007199718616902828, -0.008839478716254234, -0.00984436459839344, -0.010202028788626194, 0.001302720746025443, -0.007334975991398096, -0.003769557224586606, -0.0027122406754642725, -0.007361399941146374, -0.0011364578967913985, -0.0033059404231607914, -0.0005557956756092608, 0.008274651132524014, -0.00020812125876545906, 0.00547558581456542, 0.005269593559205532, 0.0037971336860209703, -0.0066950819455087185, -0.0013028467074036598, -0.004252420272678137, -0.003629770828410983, -0.0047303722240030766, -0.01798783242702484, -0.004884123802185059, -0.002843428635969758, 0.011641041375696659, -0.000633184565231204, 0.010221479460597038, -0.0003918769070878625, 0.0024182989727705717, -0.009297107346355915, 0.0053159077651798725, 0.00019542642985470593, 0.002136943396180868, -0.02933584153652191, 0.000758458802010864, -0.0002613170654512942, -0.00784939806908369, 0.008917911909520626, 0.00044982857070863247, 0.0007155071943998337, -0.0020293279085308313, -0.004787981975823641, 0.010779217816889286, -0.0077111502178013325, 0.0036102186422795057, -0.00555763766169548, -0.010047169402241707, -0.001883515971712768, -0.009174459613859653, 0.0012336838990449905, 0.003873022273182869, -0.003472384763881564, -0.00326140015386045, -0.004761330783367157, 0.001565265585668385, 0.0024965100456029177, 0.0012822599383071065, -0.01750391162931919, -0.005281710531562567, -0.0017044175183400512, 0.003996844869107008, -0.0029856087639927864, -0.003016809932887554, 0.004120894707739353, -0.00967397540807724, 0.00504689384251833, 0.0007947153644636273, 0.0013240792322903872, -0.010216750204563141, 0.0015754943015053868, -0.008212940767407417, -0.006622083485126495, 0.0013957179617136717, -0.0032358274329453707, -0.003853641916066408, 0.0012451093643903732, 0.0008936348604038358, 0.007976479828357697, -0.004655288998037577, 0.003927969839423895, 0.00887354463338852, -0.005838759243488312, -0.008681125938892365, 0.005321878474205732, 0.0064042056910693645, 0.0009111181134358048, -0.0005207332433201373, 0.000050941591325681657, 0.008673829957842827, 0.008104545064270496, 0.004705129656940699, 0.005740515887737274, -0.00025545412790961564, 0.010545458644628525, -0.00008028940646909177, 0.002735823392868042, -0.001305001089349389, -0.0011242917971685529, -0.006368983071297407, 0.0016208202578127384, -0.0021962784230709076, -0.002869068644940853, -0.012136518955230713, -0.00907099898904562, -0.00547973345965147, 0.0008033018093556166, 0.0014562257565557957, -0.00521908700466156, -0.002121102763339877, 0.0025958039332181215, 0.007992284372448921, 0.0023003467358648777, -0.0016783199971541762, 0.0002938478428404778, 0.0018453779630362988, -0.008599954657256603, 0.013568339869379997, -0.010991080664098263, 0.00805575866252184, 0.001353384112007916, -0.01674279384315014, 0.008022991940379143, 0.008949276991188526, -0.008964401669800282, 0.0005925043951719999, 0.0031101799104362726, 0.0042479196563363075, 0.0023379086051136255, -0.003631937550380826, -0.004259710665792227, -0.015533346682786942, -0.001264648512005806, 0.022159729152917862, 0.00034265511203557253, 0.00797610729932785, 0.011680603958666325, -0.0014746132073923945, 0.0042540887370705605, 0.004371175076812506, 0.000162548414664343, 0.014193647541105747, -0.009053785353899002, 0.000619718455709517, 0.0009246555273421109, -0.005593595094978809, 0.001257652067579329, 0.005835794378072023, 0.005137974862009287, -0.0019818078726530075, 0.0028395080007612705, -0.007014952600002289, -0.006376299075782299, -0.015913698822259903, -0.0009830496273934841, 0.004303229507058859, -0.004968714434653521, 0.006614497397094965, -0.012721502222120762, 0.0037947832606732845, 0.004978677723556757, 0.002973807044327259, 0.00047473449376411736, -0.0015870812349021435, 0.005948839709162712, 0.01192325446754694, -0.006885122042149305, 0.0024748477153480053, 0.002010112628340721, 0.0006456046830862761, 0.0037148266565054655, 0.007936921902000904, -0.007207460235804319, -0.005155864171683788, 0.004053653683513403, 0.003472454845905304, 0.0007100985967554152, -0.005620865151286125, -0.008718007244169712, -0.0033917217515408993, 0.0049841636791825294, -0.004859291948378086, 0.005826817825436592, 0.003433204023167491, 0.0012539294548332691, -0.008123754523694515, -0.001535937306471169, -0.004550676792860031, -0.012090053409337997, 0.01056729070842266, -0.003781456034630537, 0.0020629107020795345, 0.015384599566459656, 0.00346395350061357, -0.012311539612710476, 0.005220547318458557, 0.006554899271577597, -0.00356726604513824, 0.004309185314923525, 0.00527438847348094, -0.007160741835832596, -0.02147737890481949, -0.0008868331788107753, -0.014284673146903515, 0.0052263191901147366, -0.0004210353654343635, 0.003142598317936063, -0.007569103501737118, 0.008505409583449364, 0.006955300457775593, -0.013969983905553818, -0.0027534475084394217, -0.00774866109713912, 0.007461645174771547, -0.0012402971042320132, -0.0026718666777014732, -0.00296804984100163, -0.002371699083596468, -0.0009417980327270925, -0.00027760054217651486, -0.001456541707739234, 0.003473531221970916, 0.002836707280948758, -0.0036431681364774704, 0.002385104075074196, -0.005831673741340637, 0.0006560164038091898, 0.0014070859178900719, -0.011720662005245686, 0.003592154709622264, 0.003575971582904458, -0.006013819947838783, -0.0016902453498914838, -0.00014229575754143298, -0.002136450493708253, -0.007033074274659157, -0.010109048336744308, -0.0037519594188779593, -0.004010272677987814, -0.0036657785531133413, -0.01013920083642006, -0.002155260182917118, -0.006515927612781525, 0.007209599018096924, -0.006871900986880064, 0.010620733723044395, 0.004729369655251503, -0.003468729555606842, 0.00604977086186409, -0.002439022297039628, 0.00397850014269352, 0.004657772835344076, 0.008877996355295181, 0.00014235731214284897, -0.007450603414326906, -0.01085236668586731, 0.010047757998108864, -0.007541768252849579, 0.0006274050683714449, 0.013726172037422657, 0.00375487026758492, 0.008972193114459515, 0.0009017508127726614, -0.00022420001914724708, 0.005526755936443806, 0.0067587606608867645, -0.014970045536756516, 0.0023059712257236242, -0.002880670828744769, -0.0017299045575782657, 0.004791318904608488, -0.0052088480442762375, 0.002992441179230809, 0.007441955152899027, 0.001993191661313176, -0.007951421663165092, -0.000574213860090822, 0.002432307694107294, 0.004338480066508055, -0.011308589950203896, 0.0009626508690416813, -0.0025526154786348343, -0.0016058252658694983, -0.0034420944284647703, -0.0029240543954074383, 0.0012193483998999, 0.004690239205956459, -0.0023599385749548674, 0.006892661098390818, 0.001873631146736443, -0.004332466516643763, 0.013920711353421211, -0.006478584371507168, -0.007426858879625797, 0.004299159161746502, 0.0009298109798692167, -0.0026903804391622543, -0.008792700245976448, -0.0015606803353875875, -0.0013333180686458945, 0.006253296509385109, -0.005125352181494236, -0.005189003422856331, -0.0031194384209811687, 0.0010054736630991101, -0.0084081357344985, -0.0004424364597070962, 0.011236543767154217, -0.0015426763566210866, 0.004847866483032703, -0.0016629149904474616, -0.00630558654665947, -0.014865925535559654, 0.05401432514190674, -0.0019139419309794903, 0.003623857395723462, 0.0027992057148367167, -0.006914225872606039, -0.0020666548516601324, -0.0021473225206136703, 0.006031999364495277, -0.006161420606076717, -0.008352997712790966, 0.007517959922552109, -0.00268563418649137, 0.003475616918876767, 0.0002173992252210155, -0.0008662024629302323, 0.013789402320981026, -0.002165264217182994, -0.019089048728346825, -0.016110053285956383, 0.011880082078278065, -0.005425264127552509, -0.007605769205838442, 0.008266279473900795, -0.005533633287996054, -0.0009842482395470142, 0.001536269672214985, 0.006737096235156059, -0.0009046327322721481, 0.00030139429145492613, -0.0025847568176686764, -0.0032200368586927652, -0.002005161251872778, 0.003840037388727069, 0.007936068810522556, 0.007426509167999029, -0.0029892974998801947, 0.002514475490897894, -0.00411497475579381, 0.003055969951674342, -0.003318140981718898, 0.005830205976963043, 0.006010083481669426, 0.0008750654524192214, -0.0024925267789512873, 0.005435727071017027, 0.0044378312304615974, 0.0007713271770626307, 0.012677883729338646, -0.0005000410019420087, -0.004922389052808285, 0.009618758223950863, 0.0068525513634085655, 0.000893792079295963, 0.007825535722076893, -0.001302815624512732, 0.004856716375797987, 0.002241285052150488, -0.007225644309073687, -0.014366842806339264, -0.003828707616776228, 0.010271272622048855, 0.007288188207894564, -0.0039681424386799335, -0.001305310521274805, -0.0027935653924942017, -0.003141307970508933, -0.00489978538826108, -0.007632136344909668, -0.00493957195430994, 0.0013547914568334818, 0.004527093376964331, 0.07170240581035614, -0.006819937378168106, -0.002155326772481203, -0.00842360407114029, -0.001313488814048469, -0.0031743685249239206, -0.00027308057178743184, -0.00065505231032148, -0.0005900130490772426, 0.0024747243151068687, 0.0024783886037766933, -0.010603168979287148, -0.011272798292338848, 0.0013479216722771525, 0.002077837474644184, -0.0034679460804909468, 0.0023538602981716394, 0.007238912861794233, -0.007511786185204983, 0.0009964224882423878, -0.011740177869796753, -0.0012573186540976167, -0.0033651762641966343, -0.009878402575850487, -0.0025464699137955904, -0.005229464266449213, 0.003292200155556202, 0.0011600092984735966, 0.009396067820489407, -0.0043762363493442535, 0.006291586440056562, 0.0007980527589097619, 0.0005129127530381083, -0.0025436358992010355, 0.0011169557692483068, -0.007689834106713533, 0.009239675477147102, 0.003094873856753111, -0.0127622215077281, -0.006744307465851307, -0.0019547119736671448, 0.0007333438843488693, -0.00566957937553525, 0.006520654074847698, 0.0015891651855781674, 0.008274272084236145, -0.003503806423395872, 0.0017377454787492752, -0.006651748903095722, 0.0017279651947319508, -0.010153011418879032, 0.005367123521864414, -0.1779884696006775, 0.008467009291052818, 0.002794750966131687, -0.004362733568996191, -0.0045098429545760155, -0.014773821458220482, -0.005329020321369171, 0.00560563150793314, 0.008455551229417324, 0.0026711642276495695, -0.00019313505617901683, -0.002866965951398015, 0.0002945265150628984, 0.0038840719498693943, -0.0014844239922240376, -0.005095670465379953, 0.002084126928821206, -0.004526084754616022, -0.00249609281308949, 0.0036136582493782043, 0.005749661009758711, 0.007444755639880896, 0.001539810560643673, 0.0014283444033935666, 0.0012098548468202353, -0.004793229512870312, 0.005685233976691961, -0.0016270311316475272, 0.005234534852206707, -0.013514055870473385, -0.0023171533830463886, -0.005371765699237585, -0.004772133193910122, 0.0025129655841737986, 0.006755770184099674, -0.0005509860930033028, 0.007916489616036415, 0.00004616835940396413, -0.008779113180935383, 0.008020189590752125, -0.007072666194289923, 0.030943337827920914, 0.0034314102958887815, 0.007342511788010597, -0.0015608514659106731, -0.005950556602329016, -0.00405855430290103, 0.008269489742815495, 0.004123428836464882, 0.011882105842232704, -0.014387565664947033, -0.0032625619787722826, 0.0014196340925991535, 0.017779987305402756, -0.003524595405906439, -0.00867484975606203, -0.005786174908280373, -0.0009724893025122583, 0.003914592321962118, 0.009196760132908821, 0.010603317059576511, -0.004073102492839098, 0.005255579948425293, -0.0030512199737131596, -0.02237546257674694, 0.0015640381025150418, -0.003524873172864318, -0.006155651994049549, 0.0010003967909142375, 0.006452993489801884, 0.006250183563679457, -0.0021975613199174404, 0.00269582262262702, -0.00032663001911714673, 0.004280154127627611, 0.0007349775987677276, 0.007070521358400583, -0.00046186239342205226, 0.0046426462940871716, -0.008559810929000378, 0.009127292782068253, -0.009336471557617188, -0.0027225136291235685, 0.0032037755008786917, -0.0052526178769767284, 0.010487757623195648, 0.005342425312846899, -0.0023304095957428217, 0.0007076905458234251, -0.011034110561013222, -0.0025032616686075926, 0.004299855791032314, 0.002153888577595353, -0.00848272256553173, 0.0028222608380019665, 0.003735955338925123, 0.003790014423429966, 0.00633412878960371, -0.011182771995663643, 0.0050390539690852165, 0.005250156857073307, -0.006358878221362829, 0.0007844193023629487, -0.004526858683675528, -0.001242179307155311, 0.003826518077403307, -0.0062022740021348, -0.006380466278642416, 0.005251775495707989, -0.00567175168544054, -0.01052703894674778, 0.006035285536199808, -0.010759269818663597, -0.0066083502024412155, 0.0012232897570356727, -0.009834079071879387, 0.00022673554485663772 ]
8ad27d34811f9ef90b1af846c18b262998179e76
1,523
py
Python
tests/generation_test.py
stefan-feltmann/lands
b2f1fc3aab4895763160a135d085a17dceb5f58e
[ "MIT" ]
null
null
null
tests/generation_test.py
stefan-feltmann/lands
b2f1fc3aab4895763160a135d085a17dceb5f58e
[ "MIT" ]
null
null
null
tests/generation_test.py
stefan-feltmann/lands
b2f1fc3aab4895763160a135d085a17dceb5f58e
[ "MIT" ]
null
null
null
import unittest from worldengine.plates import Step, center_land, world_gen from worldengine.world import World from tests.draw_test import TestBase class TestGeneration(TestBase): def setUp(self): super(TestGeneration, self).setUp() def test_world_gen_does_not_explode_badly(self): # FIXME remove me when proper tests are in place # Very stupid test that just verify nothing explode badly world_gen("Dummy", 32, 16, 1, step=Step.get_by_name("full")) @staticmethod def _mean_elevation_at_borders(world): borders_total_elevation = 0.0 for y in range(world.height): borders_total_elevation += world.elevation_at((0, y)) borders_total_elevation += world.elevation_at((world.width - 1, y)) for x in range(1, world.width - 1): borders_total_elevation += world.elevation_at((x, 0)) borders_total_elevation += world.elevation_at((x, world.height - 1)) n_cells_on_border = world.width * 2 + world.height * 2 - 4 return borders_total_elevation / n_cells_on_border def test_center_land(self): w = World.from_pickle_file("%s/plates_279.world" % self.tests_data_dir) # We want to have less land than before at the borders el_before = TestGeneration._mean_elevation_at_borders(w) center_land(w) el_after = TestGeneration._mean_elevation_at_borders(w) self.assertTrue(el_after <= el_before) if __name__ == '__main__': unittest.main()
35.418605
80
0.690085
1
1.1616
[ 0.0011957944370806217, 0.02350153587758541, 0.006450067739933729, -0.00003611569627537392, 0.005631263367831707, -0.002710385248064995, -0.008071934804320335, 0.001302932621911168, -0.006256680469959974, 0.0010324233444407582, 0.0030110494699329138, 0.0060288566164672375, 0.007789100520312786, -0.01676773652434349, -0.00032095477217808366, 0.016621164977550507, -0.05068615823984146, 0.00037425971822813153, -0.0020897372160106897, 0.0024398164823651314, -0.007065501995384693, 0.009098958224058151, 0.008420323953032494, 0.006786677986383438, 0.006357826758176088, -0.0007517088670283556, 0.008934497833251953, 0.002631460316479206, -0.006548597477376461, -0.005717454943805933, -0.0008714330615475774, 0.0003408205520827323, -0.007568847853690386, -0.00681220181286335, 0.004557860549539328, -0.0018892526859417558, -0.0015988105442374945, -0.020023981109261513, 0.012754162773489952, -0.0055493684485554695, -0.005354593507945538, -0.014256351627409458, 0.0015759302768856287, 0.004301173146814108, -0.008645055815577507, 0.002650441136211157, -0.004172428045421839, 0.00148961809463799, -0.012870393693447113, 0.007913975045084953, -0.01124232355505228, 0.005065235774964094, 0.012075739912688732, 0.0025233386550098658, -0.007643595803529024, -0.006741079036146402, 0.011750787496566772, 0.00004617443119059317, -0.008443637751042843, 0.0016895256703719497, -0.0005435546627268195, -0.006315566599369049, 0.00455852085724473, 0.001486295834183693, -0.015006247907876968, -0.0066796825267374516, -0.004832698032259941, 0.004649154841899872, -0.001626034383662045, 0.004269465804100037, 0.0004370559472590685, -0.00022433306730818003, 0.007127148564904928, 0.004072355572134256, 0.004895119462162256, -0.003478899598121643, -0.001291925902478397, 0.00002232452607131563, 0.009342820383608341, 0.004093862138688564, 0.004624729976058006, -0.006031273398548365, 0.0055202157236635685, 0.00879277940839529, 0.014093907549977303, 0.009174465201795101, 0.016451261937618256, -0.01060520950704813, 0.04468851536512375, 0.009061546064913273, -0.008839537389576435, 0.004059524275362492, -0.010356833226978779, -0.0015276141930371523, -0.0010187621228396893, -0.027228526771068573, 0.0012523168697953224, -0.0029970866162329912, -0.0011423899559304118, 0.003587855724617839, -0.0013354315888136625, 0.006193916779011488, -0.0021096840500831604, -0.0009887380292639136, -0.010376621969044209, 0.009344998747110367, -0.008477863855659962, -0.002266006777063012, 0.007289217785000801, 0.0016579588409513235, -0.010665800422430038, -0.0007355962297879159, -0.0006196707836352289, -0.012807722203433514, 0.0027235541492700577, 0.0030300463549792767, -0.006841234862804413, 0.053951118141412735, -0.0014946586452424526, 0.005015265662223101, -0.005016837269067764, -0.0008560279966332018, 0.00004953635288984515, 0.003435432678088546, 0.010545913130044937, -0.005436612758785486, 0.01061210036277771, 0.005663550924509764, 0.001343497191555798, 0.007326177321374416, -0.002057237783446908, 0.0064396122470498085, -0.004994361661374569, -0.0016866575460880995, 0.00009614672308089212, -0.007601168006658554, 0.00476005207747221, -0.0015240766806527972, -0.0063673630356788635, -0.000463867123471573, -0.0018903136951848865, -0.009342177771031857, 0.0028215087950229645, -0.004454886540770531, 0.005279088392853737, -0.012400981038808823, -0.005052829161286354, -0.0031785883475095034, -0.0024301959201693535, 0.0006554052815772593, 0.009093092754483223, 0.003715181490406394, 0.0028735825326293707, -0.004527178592979908, -0.008218404836952686, -0.0016079400666058064, -0.005668387282639742, 0.0005915416986681521, 0.007082626223564148, 0.003801796119660139, -0.010643325746059418, -0.0005490189651027322, 0.0019491221755743027, 0.001113889622502029, -0.0019379181321710348, 0.005838147364556789, -0.006981383543461561, 0.00794762559235096, 0.0011781355133280158, 0.0047442251816391945, 0.011608999222517014, -0.0051188343204557896, -0.0002638265723362565, 0.000990313827060163, 0.0014247267972677946, -0.00018838424875866622, 0.0025832150131464005, 0.011309814639389515, -0.0029806874226778746, -0.005831618793308735, 0.0042975302785634995, 0.005145636852830648, 0.009671510197222233, 0.0058760372921824455, -0.004488198086619377, 0.0012649411801248789, -0.004736310336738825, -0.0007611068431288004, 0.007924789562821388, -0.003450506366789341, 0.006609353236854076, 0.002842170652002096, -0.01183820515871048, -0.00961048249155283, -0.0015829079784452915, -0.009020357392728329, 0.001529075438156724, 0.01362678874284029, 0.011712339706718922, -0.0038464160170406103, 0.002469934755936265, -0.008620808832347393, 0.0023768965620547533, 0.008602859452366829, 0.00400752667337656, -0.013722940348088741, -0.958523690700531, 0.0054223909974098206, 0.002738444833084941, -0.0013376313727349043, 0.004560880362987518, 0.005441106855869293, 0.005011153873056173, 0.0030126511119306087, 0.012956097722053528, -0.01089511439204216, -0.00537083251401782, -0.007763398811221123, -0.010788891464471817, -0.000798903638496995, -0.007024209946393967, -0.006624523550271988, -0.006482281722128391, -0.007030951324850321, -0.004399928729981184, -0.003643975593149662, -0.00280785677023232, 0.006262109614908695, 0.00031966224196366966, 0.006854393519461155, 0.0028847618959844112, 0.004641708917915821, -0.004436438903212547, -0.0022354063112288713, -0.002020501531660557, -0.0030592407565563917, -0.008242827840149403, -0.014103831723332405, -0.0032625675667077303, -0.000498330220580101, 0.011495895683765411, 0.002073971088975668, 0.00581079488620162, -0.002371446928009391, 0.0010030929697677493, -0.007428711745887995, 0.0039256056770682335, 0.0007703178562223911, 0.0058732302859425545, -0.03014206886291504, 0.0009373468928970397, 0.00000914931752049597, -0.010519920848309994, 0.005823563784360886, -0.0010452904971316457, -0.0008168935892172158, -0.0014684033812955022, -0.005044636782258749, 0.009754101745784283, -0.0059657045640051365, 0.002541976748034358, -0.0032327023800462484, -0.007922937162220478, -0.0035263749305158854, -0.007997374050319195, 0.0012856204994022846, 0.006133360788226128, -0.0049845268949866295, -0.00313829374499619, -0.0028025005012750626, 0.00220101373270154, -0.0003664376272354275, 0.005354585591703653, -0.01623438484966755, -0.008352375589311123, -0.0021299489308148623, 0.001045434968546033, -0.002723338548094034, -0.005853904876857996, 0.004653805401176214, -0.00859078299254179, 0.005176445934921503, 0.0003521486069075763, 0.0009689400321803987, -0.011097142472863197, 0.001117924228310585, -0.010867173783481121, -0.007897114381194115, 0.002583033638074994, -0.004628999158740044, -0.005560350138694048, 0.0010202532866969705, 0.0024609353858977556, 0.007998667657375336, -0.0034632980823516846, 0.004224921111017466, 0.00977307092398405, -0.0033183679915964603, -0.008709254674613476, 0.008323494344949722, 0.00664553651586175, -0.0013324854662641883, -0.0005172156379558146, 0.003905205288901925, 0.00976938009262085, 0.00836607813835144, 0.0014865733683109283, 0.005744008347392082, 0.0011301989434286952, 0.007303463760763407, 0.0015136757865548134, 0.0013723386218771338, -0.0001523793616797775, 0.00008214032277464867, -0.004358171485364437, 0.00007053276203805581, -0.004869024734944105, -0.002106723375618458, -0.011583291925489902, -0.008730879053473473, -0.005346102174371481, 0.001525523723103106, 0.0008193149697035551, -0.005109731573611498, 0.0002813235332723707, 0.0017938301898539066, 0.010298625566065311, 0.0002132808876922354, -0.003971698693931103, 0.0006664482061751187, 0.001047129393555224, -0.008063863962888718, 0.015635721385478973, -0.010241608135402203, 0.006737622898072004, 0.0012806674931198359, -0.017668699845671654, 0.008224311284720898, 0.012502430006861687, -0.010789870284497738, 0.003911327570676804, 0.0009406322496943176, 0.0008088416652753949, -0.00034243945265188813, -0.004971369169652462, -0.0020326522644609213, -0.017816483974456787, -0.0024414765648543835, 0.020802091807127, 0.0009223637753166258, 0.010782919824123383, 0.011640146374702454, -0.0020145291928201914, 0.004378999583423138, 0.003925585187971592, 0.0011773145524784923, 0.013066344894468784, -0.008260437287390232, 0.00037430902011692524, 0.0011724927462637424, -0.005034996662288904, 0.0031912943813949823, 0.006126089952886105, 0.005656837020069361, -0.0028163515962660313, 0.0039961859583854675, -0.0031076360028237104, -0.004771794192492962, -0.017466383054852486, -0.0023326347582042217, 0.008344028145074844, -0.0010314516257494688, 0.006616921629756689, -0.01117800921201706, 0.004177687224000692, 0.005238651763647795, 0.00472669443115592, -0.0005007142899557948, 0.0014599988935515285, 0.006676557008177042, 0.013062279671430588, -0.0073063126765191555, -0.00030897732358425856, 0.0019653025083243847, -0.0013668048195540905, -0.00036027232999913394, 0.00462208641692996, -0.0076250056736171246, -0.005186612717807293, 0.0016691063065081835, 0.0049379682168364525, -0.0001036957764881663, -0.0030337099451571703, -0.010299785993993282, -0.0031883881893008947, 0.005286036524921656, -0.004011066164821386, 0.00363202509470284, 0.0025111862923949957, 0.003976881969720125, -0.006620966363698244, 0.000843335350509733, -0.004902954213321209, -0.011243595741689205, 0.011411750689148903, -0.0035824424121528864, 0.0026520038954913616, 0.012410157360136509, 0.0049605900421738625, -0.011385918594896793, 0.004786928649991751, 0.008452972397208214, -0.005403292365372181, 0.00566889951005578, 0.005758417770266533, -0.004494859836995602, -0.023423166945576668, -0.0028943365905433893, -0.01036349032074213, 0.007308963220566511, -0.0008595714461989701, 0.005197129677981138, -0.006986919790506363, 0.00696213822811842, 0.008300812914967537, -0.014300515875220299, -0.005830628331750631, -0.00952528603374958, 0.007574731949716806, -0.000806633208412677, -0.0014186330372467637, -0.003058175789192319, -0.003376201493665576, -0.0028859383892267942, -0.0030925790779292583, -0.0017961821286007762, 0.005350124556571245, 0.0030118615832179785, -0.003609802108258009, 0.000905694265384227, -0.0030006475280970335, 0.0007000326295383275, 0.001418881700374186, -0.010369339026510715, 0.0030416762456297874, 0.0031076918821781874, -0.004576677456498146, -0.002879685489460826, 0.0022485863883048296, -0.0015058951685205102, -0.005506141111254692, -0.01032190676778555, -0.0019296446116641164, -0.00501687778159976, -0.0032866080291569233, -0.010029777884483337, -0.001204118481837213, -0.006724548526108265, 0.006773440632969141, -0.008309091441333294, 0.005336105823516846, 0.007793579250574112, -0.005423860624432564, 0.009103219956159592, -0.0014913181075826287, 0.002754529705271125, 0.00014749080582987517, 0.0032038388308137655, 0.0026879964862018824, -0.006746687460690737, -0.00909434538334608, 0.01174011267721653, -0.009822854772210121, -0.00006541211769217625, 0.014929148368537426, 0.005569661036133766, 0.010813049040734768, 0.001079715439118445, 0.00017822635709308088, 0.004942162893712521, 0.006901131477206945, -0.015217197127640247, 0.0032466291449964046, -0.0032200422137975693, 0.00041511363815516233, 0.004153526853770018, -0.004151357803493738, -0.0009295027703046799, 0.008652059361338615, 0.001919554895721376, -0.005725231487303972, -0.0013984430115669966, 0.002728597028180957, 0.005734673701226711, -0.01155949104577303, -0.00042770043364726007, -0.005470810458064079, -0.007406705059111118, -0.0017165926983579993, -0.003060070564970374, 0.00034581703948788345, 0.0044164108112454414, -0.0029251945670694113, 0.0051190718077123165, 0.0036109527572989464, -0.0032493113540112972, 0.013359135948121548, -0.00482370238751173, -0.004793100990355015, 0.0030464904848486185, 0.0008917932864278555, -0.0027988720685243607, -0.007257109507918358, -0.002981015248224139, 0.0015559438616037369, 0.00697516743093729, -0.0025706866290420294, -0.005338152404874563, -0.0038941444363445044, -0.00013504427624866366, -0.009450134821236134, 0.001826957450248301, 0.01368399802595377, -0.003301372518762946, 0.005701182875782251, 0.00013335862604435533, -0.006413791794329882, -0.013487337157130241, 0.0521630123257637, -0.001716867322102189, 0.0035021775402128696, 0.003419797867536545, -0.005674397107213736, -0.0024051195941865444, -0.0004950131406076252, 0.010101395659148693, -0.006432854570448399, -0.010560810565948486, 0.009503964334726334, -0.0029620304703712463, 0.0028255186043679714, 0.001903322758153081, 0.0016223931452259421, 0.01532051619142294, -0.003001080360263586, -0.016604825854301453, -0.015354558825492859, 0.006792200263589621, -0.003619910916313529, -0.008173979818820953, 0.009029081091284752, -0.0018504832405596972, -0.0020080325193703175, 0.001159654464572668, 0.008056867867708206, -0.0001604112476343289, 0.0006477986462414265, -0.0022004246711730957, -0.002814018400385976, -0.0002835191262420267, 0.004989264067262411, 0.006761558353900909, 0.007339658681303263, -0.0026878572534769773, 0.004574822727590799, -0.002582104643806815, -0.0016525721875950694, -0.0034584496170282364, 0.004324760288000107, 0.007989699952304363, -0.0035003579687327147, -0.0030535655096173286, 0.0036310474388301373, 0.004794174339622259, 0.002948732115328312, 0.010005233809351921, 0.0012102682376280427, -0.0068187415599823, 0.009323203936219215, 0.007080900948494673, -0.0006064240587875247, 0.009979085996747017, -0.0028509076219052076, 0.00461641326546669, 0.003170671174302697, -0.007858595810830593, -0.01611003279685974, -0.0021152321714907885, 0.007928295992314816, 0.0053590936586260796, -0.0014742801431566477, 0.0027446651365607977, 0.001191809307783842, -0.0013732491061091423, -0.006393855903297663, -0.00834695715457201, -0.003896985435858369, -0.000046792090870440006, 0.004701565019786358, 0.0695325955748558, -0.008054082281887531, -0.001960074296221137, -0.007854308001697063, 0.00036434020148590207, -0.0015747682191431522, -0.00017025592387653887, -0.001829074346460402, -0.0006370224873535335, 0.0035446982365101576, 0.0015952190151438117, -0.008127907291054726, -0.008533172309398651, 0.0017855941550806165, 0.0005463061388581991, -0.0020459520164877176, 0.003136888612061739, 0.007671972271054983, -0.00779247609898448, 0.0020506447181105614, -0.010047129355370998, -0.003382521215826273, -0.0033984214533120394, -0.009170270524919033, -0.004983691032975912, -0.003862148616462946, 0.0032732421532273293, 0.0009921635501086712, 0.006845141761004925, -0.004259112756699324, 0.005701323039829731, -0.0013913586735725403, 0.002013890305534005, -0.003377223387360573, -0.00019714812515303493, -0.006678377278149128, 0.009179197251796722, 0.003032483858987689, -0.01168709434568882, -0.00391968060284853, -0.003275575116276741, -0.00010507098340895027, -0.005865186918526888, 0.0068638441152870655, -0.002643659245222807, 0.006767683196812868, -0.0011357634793967009, 0.000779493770096451, -0.005978322122246027, 0.004176577553153038, -0.014019143767654896, 0.003244143445044756, -0.1768418550491333, 0.009286195039749146, 0.0009831682546064258, -0.0047737713903188705, -0.0038199264090508223, -0.014494474977254868, -0.009028484113514423, 0.005333196371793747, 0.010969404131174088, 0.002290197880938649, 0.0010605634888634086, -0.0026861417572945356, 0.004528496414422989, 0.004271335434168577, 0.0010328928474336863, -0.008576239459216595, 0.0038809736724942923, -0.004836359992623329, -0.001293856417760253, 0.002163311932235956, 0.0036846513394266367, 0.01154597382992506, 0.0011205320479348302, 0.0013153203763067722, -0.002112787216901779, -0.004157250747084618, 0.005496742203831673, -0.0015941893216222525, 0.005530186928808689, -0.01204789336770773, -0.0030049921479076147, -0.0056279986165463924, -0.003972550388425589, 0.0032283568289130926, 0.005407106131315231, 0.0006654024473391473, 0.007294876035302877, 0.0021307123824954033, -0.008139201439917088, 0.00548369437456131, -0.006383370608091354, 0.027331290766596794, 0.0049136001616716385, 0.008675072342157364, 0.0026796250604093075, -0.00377110973931849, -0.004865583032369614, 0.010842901654541492, 0.0007655649678781629, 0.013161040842533112, -0.013996228575706482, -0.0032980439718812704, 0.00213889149017632, 0.016980743035674095, -0.004220619797706604, -0.009713007137179375, -0.006909312680363655, -0.00317566585727036, 0.0030078256968408823, 0.008363597095012665, 0.011552219279110432, -0.0056839194148778915, 0.006444951985031366, -0.004063197411596775, -0.020418234169483185, 0.0024555898271501064, -0.006034037098288536, -0.00793847069144249, -0.0005631053354591131, 0.0065650795586407185, 0.010171445086598396, -0.0012612424325197935, 0.0020518568344414234, 0.0008037116494961083, 0.00532533461228013, -0.0012967856600880623, 0.007153933867812157, 0.0006673205643892288, 0.004185867961496115, -0.009243282489478588, 0.007708534598350525, -0.011295177973806858, -0.00380634400062263, -0.00017859454965218902, -0.0048697832971811295, 0.010890320874750614, 0.004658948630094528, -0.0033462324645370245, -0.002439959207549691, -0.009203591383993626, -0.0035035419277846813, 0.001597513211891055, -0.0007625704747624695, -0.008741975761950016, 0.0017092851921916008, 0.0013601264217868447, 0.00674337986856699, 0.004918596241623163, -0.00701473793014884, 0.004464336670935154, 0.00697366101667285, -0.006926517467945814, 0.0012035735417157412, -0.005244745407253504, 0.0031071051489561796, 0.004091516602784395, -0.006966185290366411, -0.005536132957786322, 0.0036240245681256056, -0.007512558251619339, -0.004062832798808813, 0.006022332701832056, -0.009645267389714718, -0.011632000096142292, -0.0038594892248511314, -0.013053168542683125, 0.0013339334400370717 ]
8ad69b4670dd35b6830ae32d5cbb71d9e32dff45
1,427
py
Python
tests/test_models/test_components/test_discriminators/test_light_cnn.py
ChenShuwei1001/mmediting
285e629fe9da8a13c7538a6bb3347e8870cd7201
[ "Apache-2.0" ]
null
null
null
tests/test_models/test_components/test_discriminators/test_light_cnn.py
ChenShuwei1001/mmediting
285e629fe9da8a13c7538a6bb3347e8870cd7201
[ "Apache-2.0" ]
1
2021-08-05T16:20:39.000Z
2021-08-05T16:20:39.000Z
tests/test_models/test_components/test_discriminators/test_light_cnn.py
ChenShuwei1001/mmediting
285e629fe9da8a13c7538a6bb3347e8870cd7201
[ "Apache-2.0" ]
null
null
null
import pytest import torch from mmedit.models.builder import build_component from mmedit.models.components.discriminators.light_cnn import MaxFeature def test_max_feature(): # cpu conv2d = MaxFeature(16, 16, filter_type='conv2d') x1 = torch.rand(3, 16, 16, 16) y1 = conv2d(x1) assert y1.shape == (3, 16, 16, 16) linear = MaxFeature(16, 16, filter_type='linear') x2 = torch.rand(3, 16) y2 = linear(x2) assert y2.shape == (3, 16) # gpu if torch.cuda.is_available(): x1 = x1.cuda() x2 = x2.cuda() conv2d = conv2d.cuda() linear = linear.cuda() y1 = conv2d(x1) assert y1.shape == (3, 16, 16, 16) y2 = linear(x2) assert y2.shape == (3, 16) # filter_type should be conv2d or linear with pytest.raises(ValueError): MaxFeature(12, 12, filter_type='conv1d') def test_light_cnn(): cfg = dict(type='LightCNN', in_channels=3) net = build_component(cfg) net.init_weights(pretrained=None) # cpu inputs = torch.rand((2, 3, 128, 128)) output = net(inputs) assert output.shape == (2, 1) # gpu if torch.cuda.is_available(): net.init_weights(pretrained=None) net = net.cuda() output = net(inputs.cuda()) assert output.shape == (2, 1) # pretrained should be str or None with pytest.raises(TypeError): net.init_weights(pretrained=[1])
27.980392
72
0.613174
1
1.2516
[ 0.0021913591772317886, 0.02324003167450428, 0.010624606162309647, 0.00164697109721601, 0.004343599081039429, -0.0023789999540895224, -0.007558775600045919, 0.0021275195758789778, -0.006163422483950853, 0.0013231487246230245, 0.004658835008740425, 0.0032712076790630817, 0.008493099361658096, -0.015383735299110413, -0.001140080508776009, 0.017860746011137962, -0.05089373141527176, 0.003611166262999177, -0.005562974140048027, 0.004369311034679413, -0.007412425708025694, 0.006577649619430304, 0.009549903683364391, 0.007239367812871933, 0.004418077412992716, -0.0034966568928211927, 0.011482363566756248, 0.0005681344191543758, -0.006422247271984816, -0.00755211291834712, -0.0004120185039937496, -0.00381122762337327, -0.00736991735175252, -0.006904244888573885, 0.005866547115147114, -0.0038110073655843735, 0.002249055542051792, -0.01788581721484661, 0.011096455156803131, -0.004681378602981567, -0.004586928524076939, -0.01712447963654995, -0.000060421294620027766, 0.0026508180890232325, -0.010293192230165005, 0.0014894589548930526, -0.004549420438706875, 0.000936278433073312, -0.010346720926463604, 0.007016768213361502, -0.010697202757000923, 0.00779761141166091, 0.014906574971973896, 0.003701123408973217, -0.005733925383538008, -0.009123854339122772, 0.012897606007754803, 0.00013391241373028606, -0.010185853578150272, 0.0020127620082348585, -0.004692345391958952, -0.0006748161395080388, 0.004087324719876051, 0.0020621998701244593, -0.015637831762433052, -0.006977303419262171, -0.004671125207096338, 0.004286741837859154, -0.0028246711008250713, 0.00677646417170763, 0.0013317216653376818, -0.0017861092928797007, 0.007746794261038303, 0.003082771087065339, 0.0022712533827871084, -0.004612701013684273, -0.001990696880966425, -0.00002778710040729493, 0.008254672400653362, 0.0045510041527450085, 0.0028295174706727266, -0.004612092860043049, 0.00220652692951262, 0.010865198448300362, 0.016707323491573334, 0.01005343534052372, 0.0205752644687891, -0.01037647109478712, 0.046637289226055145, 0.00758912181481719, -0.008449174463748932, 0.0013521374203264713, -0.008378979749977589, -0.0022647303994745016, -0.001995460595935583, -0.027024077251553535, -0.0002014812343986705, -0.0044231414794921875, -0.0005998556734994054, 0.0017319753533229232, 0.0009827729081735015, 0.009662165306508541, -0.002111524809151888, -0.00532660773023963, -0.008901737630367279, 0.012139378115534782, -0.008825705386698246, -0.0025998768396675587, 0.0065974825993180275, 0.0022375895641744137, -0.01292129885405302, -0.0019928596448153257, 0.001981708686798811, -0.013741453178226948, 0.0034920384641736746, 0.004543943330645561, -0.0077533056028187275, 0.052836693823337555, -0.0019100364297628403, -0.00009093582775676623, -0.00764884939417243, -0.0009707232820801437, 0.0037882199976593256, 0.004770803730934858, 0.009670237079262733, -0.003082412527874112, 0.011624760925769806, 0.008674419485032558, 0.0048012747429311275, 0.008231543935835361, -0.0044096908532083035, 0.009088002145290375, -0.002217329340055585, -0.00421157106757164, 0.001741140615195036, -0.007562778890132904, 0.0077739586122334, -0.001174102071672678, -0.008869582787156105, 0.0023953556083142757, -0.002708864863961935, -0.010939027182757854, 0.00011246305803069845, -0.004918793216347694, 0.0045642186887562275, -0.010440217331051826, -0.004921004641801119, -0.0037675891071558, -0.002791941398754716, 0.003517324570566416, 0.007441922556608915, 0.0059516653418540955, 0.004365167114883661, -0.004182277247309685, -0.009082132019102573, -0.0014776814496144652, -0.004342942498624325, 0.002005526330322027, 0.005500304512679577, 0.003125859657302499, -0.01207228284329176, -0.0017573066288605332, 0.0021179202012717724, 0.0032393343281000853, -0.000483959709526971, 0.00003156338061671704, -0.010066988877952099, 0.007477825507521629, -0.0019087640102952719, 0.003539271652698517, 0.010690928436815739, -0.006784122437238693, 0.0004315234546083957, -0.0003294666821602732, 0.0019248246680945158, -0.0014844740508124232, 0.005913158413022757, 0.010197731666266918, -0.0015649866545572877, -0.005694251973181963, 0.003761318977922201, 0.006012337747961283, 0.010963053442537785, 0.00672130798920989, -0.003112216480076313, 0.0026706941425800323, -0.006243184674531221, 0.0001990127348108217, 0.008898371830582619, -0.0027943828608840704, 0.004934106487780809, 0.0014744601212441921, -0.013203113339841366, -0.008224141784012318, -0.000900918385013938, -0.008095622062683105, 0.0019564914982765913, 0.015580638311803341, 0.011080684140324593, -0.0033421970438212156, 0.002863833447918296, -0.00887035671621561, 0.001087932731024921, 0.006936277262866497, 0.0049165990203619, -0.013016950339078903, -0.9585732221603394, 0.008412177674472332, 0.004839151632040739, -0.0046227918937802315, 0.0052945963107049465, 0.0010682621505111456, 0.003875632071867585, 0.0046842703595757484, 0.014040624722838402, -0.008400458842515945, -0.006234290543943644, -0.009692339226603508, -0.010172627866268158, -0.002044509630650282, -0.006739010568708181, -0.004237436689436436, -0.004867316223680973, -0.005452303681522608, -0.0033799386583268642, -0.003946895711123943, -0.0022967110853642225, 0.010797342285513878, -0.002309441566467285, 0.006897085811942816, 0.004453309811651707, 0.0008956492529250681, -0.004739413037896156, -0.001752884010784328, -0.002944261534139514, -0.004247310571372509, -0.004647433292120695, -0.01492317020893097, -0.004277991130948067, -0.0008032905170693994, 0.007903595454990864, -0.001890519866719842, 0.00892087072134018, -0.002933122683316469, 0.0037724548019468784, -0.007600078824907541, 0.0056875585578382015, -0.00016304568271152675, 0.0032717494759708643, -0.028476135805249214, -0.001163504202850163, 0.0007787444046698511, -0.009045395068824291, 0.00438131857663393, 0.0015726308338344097, 0.0007449648692272604, -0.0021024313755333424, -0.006327268201857805, 0.008680454455316067, -0.006559861823916435, 0.005292742513120174, -0.004621993284672499, -0.007561640348285437, -0.0035465899854898453, -0.007683556992560625, 0.000002257963615193148, 0.005601842422038317, -0.0037854681722819805, -0.001922316150739789, -0.002606818685308099, 0.004160991404205561, 0.004257781896740198, 0.0031898682937026024, -0.021062564104795456, -0.007409546058624983, 0.00028776537510566413, 0.0010717816185206175, -0.002279080217704177, -0.005191207863390446, 0.005439518950879574, -0.00802822969853878, 0.008902834728360176, 0.002174487803131342, -0.0026357935275882483, -0.009859472513198853, -0.0012997938320040703, -0.010754672810435295, -0.00704124616459012, 0.004080392420291901, -0.005464428570121527, -0.006476122885942459, -0.0012707157293334603, 0.002037755213677883, 0.00762674305588007, -0.006950686685740948, 0.0066852448508143425, 0.011644171550869942, -0.0019396614516153932, -0.009064672514796257, 0.005468541290611029, 0.006781955249607563, 0.0013875445583835244, -0.004560851026326418, 0.003420688910409808, 0.0074569000862538815, 0.006302541587501764, 0.0011370378779247403, 0.006717880722135305, 0.001414982252754271, 0.0051489779725670815, -0.0011187436757609248, 0.0005795054603368044, -0.002256579464301467, -0.0002767699188552797, -0.004586764611303806, -0.0014784113736823201, -0.005140947178006172, -0.004796280059963465, -0.011735447682440281, -0.007040008436888456, -0.004947209730744362, -0.00047785945935174823, 0.0026292346883565187, -0.005041774362325668, 0.0015774036291986704, 0.0008042386616580188, 0.00903882272541523, -0.0017622408922761679, -0.004021847620606422, -0.0002832368772942573, 0.002515530213713646, -0.0038784544449299574, 0.01388402096927166, -0.012274807319045067, 0.00674028554931283, -0.000761163595598191, -0.014749741181731224, 0.006431458052247763, 0.0066041238605976105, -0.0077488305978477, 0.0018011583015322685, 0.0022920819465070963, 0.0009478895226493478, -0.0030158422887325287, -0.007394514046609402, -0.0021277163177728653, -0.017592543736100197, 0.0014900073874741793, 0.019983287900686264, 0.0022747451439499855, 0.012140782549977303, 0.012053417973220348, -0.002504827454686165, 0.0010616288054734468, 0.00457178195938468, 0.00022590545995626599, 0.014434021897614002, -0.00798907782882452, -0.0008222221513278782, 0.0014343858929350972, -0.0062452638521790504, 0.0012451086658984423, 0.0051039839163422585, 0.003784401807934046, -0.0010001626797020435, 0.003134005470201373, -0.007704015821218491, -0.004695160314440727, -0.018716389313340187, -0.001018101116642356, 0.008908746764063835, -0.0043895249255001545, 0.006114588119089603, -0.010945748537778854, 0.002437783870846033, 0.006916377693414688, 0.006597174797207117, -0.00030068104388192296, 0.002285589464008808, 0.0075092134065926075, 0.010940681211650372, -0.007825838401913643, 0.003170885145664215, 0.0017581626307219267, -0.0020336327143013477, -0.0013336457777768373, 0.008107740432024002, -0.007326388731598854, -0.00564176170155406, 0.0025587123818695545, 0.0040231430903077126, 0.0034422629978507757, -0.002824896713718772, -0.008913501165807247, -0.004000798799097538, 0.00279270950704813, -0.004137852694839239, 0.0020675191190093756, 0.003770556068047881, 0.0027693528681993484, -0.00638017849996686, -0.0003463939647190273, -0.004244736861437559, -0.009920845739543438, 0.011553522199392319, -0.0019930684939026833, 0.0030564649496227503, 0.013869491405785084, 0.005009154323488474, -0.014306671917438507, 0.006481064483523369, 0.010014149360358715, -0.0014859286602586508, 0.00556044839322567, 0.005585439503192902, -0.003746672300621867, -0.023481933400034904, -0.005148735363036394, -0.012918097898364067, 0.0061315312050282955, -0.0015990991378203034, 0.003502728184685111, -0.006826403085142374, 0.005993333179503679, 0.0063488115556538105, -0.014672910794615746, -0.0051735988818109035, -0.008727644570171833, 0.007872633635997772, -0.002205802360549569, 0.0008256089058704674, -0.0048325276002287865, -0.00363536411896348, -0.004054821562021971, -0.004231108818203211, -0.0011057350784540176, 0.005001767538487911, 0.00173692696262151, -0.0025426300708204508, 0.0022267992608249187, -0.004213603213429451, 0.0033733879681676626, -0.0005504808505065739, -0.011196896433830261, 0.0002705918450374156, 0.0036024427972733974, -0.0006522568874061108, -0.002605668269097805, -0.0003124949580524117, -0.0019529134733602405, -0.006248159799724817, -0.012248680926859379, -0.006982730235904455, -0.0051322015933692455, -0.0015420237323269248, -0.012768137268722057, -0.0026264807675033808, -0.0082387151196599, 0.0066408743150532246, -0.0055184257216751575, 0.0075767431408166885, 0.004766601603478193, -0.006968244444578886, 0.006628615316003561, -0.0024031277280300856, 0.00218540383502841, 0.0018972369143739343, 0.0036737732589244843, 0.0014743172796443105, -0.004032369237393141, -0.01034256536513567, 0.01295316219329834, -0.009112006053328514, 0.0015076169511303306, 0.013782493770122528, 0.004935094621032476, 0.007938782684504986, -0.002574311336502433, 0.0009884510654956102, 0.004439440555870533, 0.008824368007481098, -0.015126810409128666, 0.002264948096126318, -0.0030720150098204613, 0.001205640030093491, 0.004709967412054539, -0.003950107842683792, 0.0011100067058578134, 0.010020170360803604, 0.002684128936380148, -0.00720329349860549, -0.001350409584119916, 0.002171468921005726, 0.0034605604596436024, -0.012146533466875553, 0.0009055261616595089, -0.0036433113273233175, -0.0031874177511781454, 0.0010477742180228233, -0.0027673421427607536, 0.0000992317873169668, 0.005739133805036545, -0.002803374081850052, 0.005366664845496416, 0.002849139738827944, -0.0074251675978302956, 0.01605447567999363, -0.00632861303165555, -0.006085451226681471, 0.002396840136498213, 0.0022853307891637087, -0.0017848637653514743, -0.006342754699289799, -0.0009590678964741528, 0.002674500225111842, 0.00573769910261035, -0.00257965549826622, -0.0013118620263412595, 0.00017759639013092965, 0.0010460648918524384, -0.011946151964366436, 0.0016374796396121383, 0.011532210744917393, -0.0030222758650779724, 0.006309964694082737, -0.0012232420267537236, -0.007596208713948727, -0.012376133352518082, 0.05285979434847832, -0.0023308703675866127, 0.0036800899542868137, 0.004483332391828299, -0.007114787586033344, -0.0012392716016620398, -0.000207642195164226, 0.008889329619705677, -0.004685099236667156, -0.00906875729560852, 0.009729302488267422, -0.003302147379145026, 0.0034071195404976606, 0.006771693006157875, -0.0007048374391160905, 0.016069311648607254, -0.002543520415201783, -0.01599915139377117, -0.016634810715913773, 0.006897170562297106, -0.00593507569283247, -0.007421867921948433, 0.010698525235056877, -0.001708249794319272, -0.004737318493425846, 0.0011266263900324702, 0.0076509625650942326, 0.00005063781645731069, 0.0001904806704260409, -0.002086515072733164, -0.0011736626038327813, 0.0017856560880318284, 0.0008857781067490578, 0.00606442941352725, 0.00894918292760849, -0.0017992460634559393, 0.004865060094743967, 0.00013823754852637649, -0.0022182492539286613, -0.001493182615377009, 0.0044031897559762, 0.005936048924922943, -0.0025991834700107574, -0.0031869823578745127, 0.0049679032526910305, 0.005240003112703562, 0.0034494351129978895, 0.009625512175261974, -0.0011931016342714429, -0.007051235530525446, 0.009806164540350437, 0.007821633480489254, 0.0020389005076140165, 0.01005867961794138, -0.0011832916643470526, 0.005083385854959488, 0.001015935093164444, -0.009978454560041428, -0.016891106963157654, -0.0008770421845838428, 0.007491588592529297, 0.007706833072006702, -0.001018872600980103, 0.0030730711296200752, -0.0018412076169624925, -0.001274306676350534, -0.008084253408014774, -0.008556030690670013, -0.0021860578563064337, 0.0034252179320901632, 0.005543726030737162, 0.0684003084897995, -0.007632601540535688, -0.0025323808658868074, -0.007806413806974888, -0.0008680801838636398, -0.0007251008064486086, -0.001236363546922803, -0.0009501832537353039, -0.0017840267391875386, 0.004729119129478931, 0.00015162589261308312, -0.009983474388718605, -0.010902171954512596, 0.0014193617971614003, 0.002688392996788025, -0.001847458304837346, 0.004042573273181915, 0.00418121786788106, -0.011580385267734528, 0.000681418867316097, -0.012667362578213215, -0.001793922740034759, -0.0024333021137863398, -0.010752660222351551, -0.0038950047455728054, -0.0033045457676053047, 0.004301107954233885, 0.0019773058593273163, 0.0029908420983701944, -0.0035047712735831738, 0.006922663655132055, -0.0035412563011050224, -0.00019425757636781782, -0.0037473684642463923, -0.0028813527897000313, -0.007249915972352028, 0.007210166193544865, 0.001873784582130611, -0.012974542565643787, -0.0051383026875555515, 0.0005106504540890455, 0.0018951012752950191, -0.004439623095095158, 0.0034686741419136524, -0.0015035303076729178, 0.007081305142492056, -0.002670654794201255, 0.0028840801678597927, -0.006851216312497854, 0.0005817951168864965, -0.011740608140826225, 0.005918796639889479, -0.17195917665958405, 0.010334081947803497, 0.004725964739918709, -0.006054286379367113, -0.0040060533210635185, -0.011424100026488304, -0.007089841645210981, 0.004417891148477793, 0.011589928530156612, 0.00295431399717927, -0.00004123051621718332, -0.002940838225185871, 0.006340113468468189, 0.0021306525450199842, -0.0004749950021505356, -0.002670538378879428, 0.0032979922834783792, -0.004141262266784906, 0.00013341412704903632, 0.006132896989583969, 0.004168403800576925, 0.009369941428303719, 0.0011934349313378334, 0.004259265959262848, -0.002118847332894802, -0.005347588565200567, 0.0028173690661787987, -0.0017828145064413548, 0.006783612538129091, -0.010047773830592632, -0.004911291413009167, -0.002604388166218996, -0.002635066630318761, 0.0009179525077342987, 0.004503438249230385, 0.001959486398845911, 0.008962122723460197, 0.0019108123378828168, -0.006989798042923212, 0.008206628262996674, -0.009187038987874985, 0.027099553495645523, 0.007643347606062889, 0.004871959798038006, 0.000014923717571946327, -0.005682355258613825, -0.005124083254486322, 0.009172479622066021, 0.0017187102930620313, 0.010833656415343285, -0.014605284668505192, -0.00032436870969831944, 0.004038081970065832, 0.01771840639412403, -0.0051199570298194885, -0.011091404594480991, -0.006457492709159851, -0.00326192076317966, 0.0016424497589468956, 0.009926765225827694, 0.011262169107794762, -0.003910631872713566, 0.008138783276081085, -0.003489291062578559, -0.023600894957780838, 0.0035197841934859753, -0.006095997989177704, -0.008848330937325954, -0.0008397623314522207, 0.007967423647642136, 0.00996475387364626, -0.0011204991023987532, 0.000996083370409906, -0.0026148853357881308, 0.008537108078598976, 0.000618397374637425, 0.006942980457097292, -0.0021859563421458006, 0.006582403089851141, -0.008496932685375214, 0.007951559498906136, -0.01041856873780489, -0.004662226419895887, 0.0023031667806208134, -0.004733475856482983, 0.010040054097771645, 0.005206851288676262, -0.0035515485797077417, -0.0018435022793710232, -0.00871853157877922, -0.0019257296808063984, 0.0007183843990787864, 0.0006006998009979725, -0.009749408811330795, 0.0023489512968808413, 0.0009707704884931445, 0.0066828653216362, 0.00708036357536912, -0.010188519954681396, 0.007227461785078049, 0.006599152460694313, -0.006481267511844635, -0.000027152374968864024, -0.0031635756604373455, 0.003685012459754944, 0.003064875490963459, -0.004691412206739187, -0.005169381853193045, 0.0037995425518602133, -0.00901696179062128, -0.004181198310106993, 0.008263538591563702, -0.010938501916825771, -0.012027543038129807, -0.002360695507377386, -0.011748543940484524, 0.00042131912778131664 ]
8ad728c2bc84ac4630b400804d13c8940597431e
4,727
py
Python
src/consumer.py
ssichynskyi/web_metrics_posting
26f104d2fdf31c2d029bac5a4d5337db42df86f5
[ "MIT" ]
null
null
null
src/consumer.py
ssichynskyi/web_metrics_posting
26f104d2fdf31c2d029bac5a4d5337db42df86f5
[ "MIT" ]
null
null
null
src/consumer.py
ssichynskyi/web_metrics_posting
26f104d2fdf31c2d029bac5a4d5337db42df86f5
[ "MIT" ]
null
null
null
import json import logging from typing import Iterable from kafka import KafkaConsumer log = logging.getLogger(__name__) log.addHandler(logging.NullHandler()) # I've used this example: # https://github.com/aiven/aiven-examples/blob/master/kafka/python/consumer_example.py # as well as Aiven Kafka tutorials class Consumer: GROUP_ID = 'web_metrics_consumer' CLIENT_ID = 'website-monitoring-consumer-service' def __init__( self, *topics, **connection_kwargs ): """Class for creating Kafka consumer. Args: *topics - topics to subscribe to. Could be changed during lifetime, str **connection_kwargs - keyword arguments as taken by KafkaConsumer below there are some useful kwargs and their default value: 'bootstrap_servers' - uri with port for the service 'security_protocol' - SSL, SASL_PLAINTEXT, etc 'sasl_mechanism': None, 'sasl_plain_username': None, 'sasl_plain_password': None, 'ssl_cafile': None, 'ssl_certfile': None, 'ssl_keyfile': None Note: although all params are optional, at least 'sasl_plain_username' and 'sasl_plain_password' or 'ssl_cafile', 'ssl_certfile' and 'ssl_keyfile or other certificate-related inputs shall be defined Usage: Connection is activated not on object instantiation but when entering with statement. e.g.: consumer = Consumer(...) with consumer: consumer.send(...) """ self._topics = topics self._connection_data = connection_kwargs # auto-determine security protocol if not provided try: self._connection_data['security_protocol'] except KeyError: username_given = 'sasl_plain_username' in self._connection_data.keys() password_given = 'sasl_plain_password' in self._connection_data.keys() ca_file_given = 'ssl_cafile' in self._connection_data.keys() service_cert_given = 'ssl_certfile' in self._connection_data.keys() service_key_given = 'ssl_keyfile' in self._connection_data.keys() if all((ca_file_given, service_cert_given, service_key_given)): self._connection_data['security_protocol'] = 'SSL' elif username_given and password_given: self._connection_data['security_protocol'] = 'SASL_PLAINTEXT' else: msg = 'Security protocol not provided and cannot be determined automatically.' msg = f'{msg} Check auth kwargs' raise ValueError(msg) self._client_id = f'{self.CLIENT_ID}:{id(self)}' def __enter__(self): """Method which creates the connection. Activated inside with statement.""" self._consumer = KafkaConsumer( *self._topics, **self._connection_data, auto_offset_reset='earliest', enable_auto_commit=False, client_id=self._client_id, group_id=self.GROUP_ID, consumer_timeout_ms=1000, value_deserializer=lambda x: json.loads(x.decode("utf-8")) ) log.info(f'Connected to kafka broker at: {self._consumer.config["bootstrap_servers"]}') def fetch_latest(self): """Fetches only not read messages by members of this group. Returns: list of decoded message values """ self._consumer.poll() messages = list() for message in self._consumer: messages.append(message.value) log.info( f'Fetched {len(messages)} messages from {self._consumer.config["bootstrap_servers"]}' ) self._consumer.commit() return messages def change_topics(self, topics: Iterable) -> None: """Changes Kafka consumer topic statically or dynamically Args: topics: any iterable: set, list, tuple Returns: None """ topics = tuple(topics) try: self._consumer.unsubscribe() self._consumer.subscribe(list(topics)) except AttributeError: # when topics are changed in inactive consumer i.e. not inside `with` statement self._topics = topics def __exit__(self, exc_type, exc_value, traceback): """Actions to perform when exiting with statement.""" log.info( f'Closed connection tp kafka broker at: {self._consumer.config["bootstrap_servers"]}' )
36.643411
97
0.610324
1
1.8381
[ -0.016700468957424164, 0.003432020079344511, -0.015555039048194885, 0.005266254302114248, -0.002981889061629772, 0.026948630809783936, -0.002173940185457468, -0.0009321022080257535, 0.021271897479891777, 0.010162032209336758, 0.01872662454843521, 0.051104627549648285, -0.01461348682641983, 0.0061908867210149765, -0.023087400943040848, -0.04723910614848137, 0.29871219396591187, -0.03181300684809685, -0.005080237984657288, -0.004517469089478254, 0.013892938382923603, 0.006948536261916161, -0.01770959608256817, -0.01300646923482418, 0.007310402579605579, 0.013836785219609737, 0.02737404964864254, -0.03139471262693405, -0.011601128615438938, -0.04160996899008751, 0.013013835996389389, -0.0225392933934927, -0.018930602818727493, 0.005286797881126404, -0.007206378038972616, -0.017710795626044273, 0.033621273934841156, -0.009011514484882355, 0.04868759214878082, 0.029298780485987663, -0.03568870574235916, -0.010226576589047909, -0.011627763509750366, -0.035422999411821365, 0.0259971022605896, 0.020440014079213142, -0.016428880393505096, -0.03111717663705349, 0.00036570191150531173, -0.011697412468492985, 0.02307765744626522, 0.017610931769013405, 0.010618059895932674, -0.035926371812820435, 0.01704426482319832, -0.047536902129650116, -0.009426559321582317, -0.019973814487457275, -0.008719874545931816, -0.0024894545786082745, -0.08515731245279312, -0.010932162404060364, 0.05807335674762726, -0.005816941615194082, 0.0048436750657856464, -0.0034365204628556967, -0.0025340141728520393, 0.047420501708984375, 0.08403108268976212, -0.026217669248580933, 0.05611298978328705, 0.01330833975225687, -0.03431099280714989, 0.07985921204090118, -0.026230579242110252, -0.0048471479676663876, -0.001330644590780139, -0.008990160189568996, -0.018896538764238358, -0.0025020220782607794, -0.007697841618210077, -0.037589043378829956, 0.012739392928779125, -0.00830442551523447, -0.0007403393974527717, -0.02822127193212509, 0.012369293719530106, 0.023913370445370674, 0.03302006796002388, -0.02539406158030033, -0.011861140839755535, 0.011624457314610481, -0.014870095998048782, -0.011370658874511719, -0.05527980998158455, 0.03491075709462166, 0.0035448188427835703, 0.012954934500157833, 0.04376295208930969, -0.0031417219433933496, 0.03284662961959839, 0.00673387898132205, 0.04079383239150047, -0.010250741615891457, -0.00809700507670641, -0.027968620881438255, -0.045534398406744, 0.02666107378900051, -0.015813689678907394, 0.02357233688235283, -0.02577599138021469, -0.007593777030706406, 0.01347056683152914, -0.024524787440896034, -0.03574425354599953, 0.01672227308154106, -0.0059134806506335735, -0.010047723539173603, 0.05297919362783432, 0.06620526313781738, -0.022368017584085464, -0.011747416108846664, 0.01034968439489603, -0.035977452993392944, -0.013551462441682816, 0.01809472031891346, -0.005815414246171713, 0.014886110089719296, 0.034483473747968674, -0.014921086840331554, -0.004046897403895855, -0.014364320784807205, -0.011200488545000553, -0.01214506570249796, 0.001711204880848527, 0.05598895996809006, -0.014468526467680931, -0.018408605828881264, -0.04758956655859947, 0.0015198274049907923, 0.017451593652367592, -0.01533739548176527, 0.001968592870980501, 0.011267990805208683, -0.021812617778778076, 0.007209939416497946, -0.01819154992699623, -0.00639221491292119, 0.040162015706300735, -0.03321477398276329, 0.03199285268783569, 0.018903864547610283, 0.0028306993190199137, 0.04680889472365379, 0.016966938972473145, -0.011759853921830654, -0.030022824183106422, -0.037171371281147, 0.01964089646935463, 0.0332348607480526, -0.04798856005072594, 0.002337198704481125, 0.003503041574731469, 0.03292462229728699, 0.04846789315342903, -0.06352140009403229, -0.012407176196575165, 0.012651404365897179, 0.0453215129673481, -0.01412909384816885, 0.003640673356130719, -0.021489670500159264, -0.03470328077673912, 0.011347231455147266, -0.05293705314397812, 0.002141485456377268, 0.03285513073205948, -0.020683668553829193, 0.00851028598845005, -0.0077066319063305855, -0.022710628807544708, -0.037315089255571365, 0.0042020948603749275, -0.0037917320150882006, -0.013745110481977463, -0.008309789001941681, -0.03614989295601845, -0.035547178238630295, 0.0067052086815238, -0.007707380224019289, 0.018629208207130432, 0.0003002270241267979, -0.059676989912986755, 0.044236913323402405, -0.015004117041826248, -0.0556415356695652, 0.07346895337104797, 0.015465518459677696, -0.014772141352295876, 0.014837690629065037, 0.029844973236322403, -0.031327024102211, -0.0061432975344359875, 0.009222165681421757, -0.009127015247941017, 0.020954636856913567, -0.6060327291488647, 0.0030055036768317223, 0.0090026268735528, 0.02615826576948166, -0.004699986893683672, 0.02916439063847065, -0.021455928683280945, 0.0036274136509746313, 0.02315678820014, -0.009420881047844887, -0.015890415757894516, -0.015967009589076042, 0.013740734197199345, 0.02470645308494568, 0.01696922816336155, 0.014987855218350887, 0.007508262991905212, 0.02860838547348976, -0.028539488092064857, 0.019556211307644844, -0.0023902864195406437, -0.050475262105464935, 0.002959032077342272, 0.018827032297849655, 0.0046468572691082954, -0.005713619291782379, 0.013330222107470036, -0.042932767421007156, -0.03674331679940224, 0.03445987403392792, 0.00996926799416542, 0.014582065865397453, 0.03347057104110718, 0.03372099623084068, 0.0169120654463768, -0.034769006073474884, 0.009218312799930573, -0.009787282906472683, -0.006568544544279575, -0.034072671085596085, -0.010443242266774178, 0.007471237797290087, 0.02038450539112091, -0.04265796020627022, 0.017003053799271584, -0.048746511340141296, -0.014087765477597713, 0.0002067187597276643, 0.008166974410414696, -0.004782290663570166, 0.014138947241008282, 0.04317551851272583, 0.002447723178192973, 0.0012356966035440564, 0.026412902399897575, 0.043670449405908585, -0.0317748561501503, 0.00061062938766554, 0.0022396815475076437, -0.0013188027078285813, -0.022326631471514702, -0.014246133156120777, -0.03630959615111351, 0.019083306193351746, 0.010833626613020897, -0.03691767528653145, -0.02517109364271164, -0.010050468146800995, 0.05105384439229965, -0.0026764939539134502, -0.020696483552455902, -0.027649419382214546, -0.014033938758075237, 0.00020153791410848498, -0.009319137781858444, 0.014998534694314003, 0.009870314039289951, -0.003743329318240285, -0.06785072386264801, -0.011354511603713036, -0.004036908503621817, -0.042654648423194885, 0.04410943388938904, -0.003661660710349679, 0.010547631420195103, -0.0026553701609373093, -0.019061340019106865, -0.03488831967115402, -0.007172929123044014, -0.00450181495398283, -0.005277140997350216, 0.03435206785798073, 0.009583189152181149, 0.03020905889570713, 0.005414108280092478, 0.028384510427713394, 0.03135613724589348, 0.05064816027879715, 0.035935819149017334, -0.0031323465518653393, -0.027564922347664833, 0.018493937328457832, 0.01605798490345478, -0.008685696870088577, -0.013440309092402458, -0.027230698615312576, -0.03136330470442772, -0.021660683676600456, 0.007126337848603725, -0.018857257440686226, -0.00925785768777132, -0.046162839978933334, -0.04567509889602661, 0.006127879489213228, -0.04195871204137802, 0.008756248280405998, 0.007851996459066868, -0.06036991998553276, -0.03874649479985237, 0.006536442786455154, -0.05187583342194557, -0.044305458664894104, -0.035296812653541565, 0.0494019016623497, -0.034452080726623535, -0.012779160402715206, -0.01516347099095583, 0.04102363809943199, -0.0447242334485054, -0.0243406780064106, -0.0395083986222744, -0.04254986718297005, 0.0038947570137679577, -0.028254134580492973, -0.01639152318239212, 0.019260892644524574, -0.01288008876144886, -0.020421577617526054, -0.011444549076259136, -0.006415697280317545, -0.013035268522799015, 0.013010097667574883, -0.007382682990282774, -0.037330251187086105, 0.03740205988287926, 0.03616679087281227, 0.013809237629175186, 0.020181750878691673, 0.01958436518907547, -0.016255132853984833, 0.0037478357553482056, -0.0027091330848634243, 0.028819585219025612, -0.005003227386623621, -0.0027568230871111155, 0.03122861683368683, 0.04084410145878792, 0.03871613368391991, -0.02814512327313423, 0.02905677817761898, 0.005331171676516533, 0.004172539804130793, -0.036512959748506546, -0.031299032270908356, 0.04334152862429619, 0.029779333621263504, -0.013770032674074173, 0.021116310730576515, 0.004056408070027828, 0.006585841067135334, 0.013354974798858166, 0.0010608001612126827, -0.031178848817944527, 0.012041491456329823, -0.048495031893253326, -0.0011913165217265487, 0.03882996365427971, -0.053580425679683685, 0.01749430224299431, 0.015304198488593102, -0.017306730151176453, 0.030374541878700256, 0.000452108884928748, -0.04611732438206673, -0.00040270708268508315, -0.0069757611490786076, 0.005980934016406536, -0.053566429764032364, 0.012916108593344688, 0.020846739411354065, 0.039712097495794296, 0.023157209157943726, -0.0028322332073003054, -0.00006692400347674266, -0.005155808757990599, -0.016792815178632736, 0.018568074330687523, -0.03962336853146553, 0.030368931591510773, -0.0007878068136051297, -0.01509801484644413, 0.03109324537217617, 0.025596236810088158, 0.012612846679985523, 0.029813550412654877, 0.0010766222840175033, 0.001857456169091165, 0.011882022023200989, -0.03217983618378639, -0.040737029165029526, 0.02087581716477871, 0.012669657357037067, 0.07622548937797546, -0.046935491263866425, 0.011050478555262089, -0.05281923711299896, -0.0023495217319577932, -0.0020228170324116945, -0.01202181726694107, 0.005444675218313932, -0.017887519672513008, -0.023785825818777084, -0.009005360305309296, -0.028921348974108696, 0.0072562783025205135, -0.019248727709054947, -0.008923725225031376, 0.012310512363910675, -0.025462303310632706, -0.01592365838587284, 0.0018706292612478137, 0.01392945647239685, 0.004427608102560043, -0.021507812663912773, 0.006742443889379501, -0.0017069893656298518, 0.001127111492678523, -0.0033252942375838757, -0.00026585004525259137, -0.004452646244317293, 0.014223235659301281, -0.02780122123658657, 0.01633588783442974, -0.011379217728972435, 0.011562076397240162, -0.010496160015463829, 0.023158501833677292, -0.025169027969241142, 0.013468162156641483, -0.012673859484493732, -0.04180917516350746, 0.0728011205792427, 0.00011410718434490263, -0.013702726922929287, 0.03695710748434067, 0.028297850862145424, -0.002353244461119175, 0.005978371948003769, -0.006356855388730764, 0.010004159063100815, 0.03408471867442131, -0.025406673550605774, -0.012502895668148994, -0.007334368769079447, -0.013002673164010048, 0.011473086662590504, 0.005440404172986746, 0.006284576840698719, 0.017777562141418457, -0.006702556740492582, -0.034276995807886124, 0.0047016628086566925, 0.018796304240822792, 0.005715841427445412, -0.01129783783107996, 0.010970410890877247, -0.017131619155406952, -0.014327917248010635, -0.02304856851696968, 0.0032766428776085377, 0.017532728612422943, -0.02675502374768257, 0.045271825045347214, 0.032497938722372055, 0.008238974027335644, -0.008915466256439686, 0.01465357095003128, 0.011068976484239101, -0.03981075435876846, 0.009763745591044426, -0.004286705981940031, -0.01213571336120367, 0.02173687145113945, 0.004253919702023268, 0.024997131898999214, -0.04190198704600334, -0.006674023810774088, 0.017724506556987762, 0.005675482098013163, -0.0464719794690609, 0.004795072600245476, -0.014263084158301353, 0.005629824940115213, -0.034900013357400894, 0.001082452479749918, 0.04790372774004936, 0.030558383092284203, -0.015871696174144745, 0.007564022671431303, 0.013947661966085434, 0.0013320710277184844, 0.01060995552688837, -0.051563043147325516, 0.04593420773744583, 0.025822581723332405, 0.04607778787612915, 0.040729932487010956, -0.016562797129154205, 0.0017581959255039692, -0.015100814402103424, -0.017815135419368744, -0.018314557150006294, -0.03462987020611763, 0.014692919328808784, 0.03459705412387848, -0.027399005368351936, 0.020645365118980408, -0.04570827633142471, 0.043173886835575104, -0.012391244992613792, -0.01168095413595438, -0.020907865837216377, -0.03135684132575989, -0.005949250888079405, 0.005722456611692905, 0.021299170330166817, -0.03127755597233772, 0.025918738916516304, -0.021550819277763367, 0.016381939873099327, 0.03649485483765602, 0.005422016605734825, 0.005598400253802538, 0.0022447211667895317, 0.0029697888530790806, -0.01796163059771061, 0.0045894719660282135, 0.03831474110484123, -0.014711975120007992, 0.025343168526887894, 0.06134713068604469, -0.013818546198308468, -0.011104780249297619, 0.015954378992319107, 0.01044884230941534, -0.039805229753255844, 0.021081840619444847, -0.01614956744015217, 0.0036997555289417505, -0.00314030097797513, -0.00923248939216137, -0.016561081632971764, 0.024753082543611526, 0.0012788824969902635, -0.015457220375537872, -0.05246498063206673, -0.010976098477840424, 0.02604740485548973, 0.010043680667877197, -0.025133326649665833, -0.004750559572130442, 0.02824479714035988, -0.020087704062461853, -0.0034666818100959063, -0.02981537953019142, -0.0050232503563165665, 0.03675485774874687, -0.004777500405907631, -0.0209109615534544, -0.021298803389072418, -0.026643551886081696, -0.04265894740819931, -0.022471977397799492, 0.010306858457624912, 0.008707691915333271, -0.022111887112259865, 0.0219437088817358, 0.020428379997611046, -0.02126280590891838, -0.01938251219689846, 0.011305936612188816, -0.02585201896727085, -0.0024379612877964973, 0.018187187612056732, -0.03131994232535362, -0.002397880656644702, -0.02002772130072117, -0.04744588956236839, 0.00822483841329813, 0.02017364837229252, -0.014903190545737743, -0.04334983602166176, 0.03211425989866257, -0.0007009474793449044, 0.0030974356923252344, -0.04362388700246811, 0.019929932430386543, -0.007969829253852367, -0.014521838165819645, -0.03064701519906521, -0.0037140543572604656, -0.0010868634562939405, -0.07871506363153458, 0.021722231060266495, 0.046221327036619186, 0.0050427792593836784, -0.03736255690455437, -0.013811955228447914, 0.008260386064648628, 0.028517035767436028, 0.01678522303700447, 0.05789004638791084, 0.023320229724049568, -0.03749873861670494, -0.011407551355659962, -0.00856009777635336, 0.04430099204182625, 0.02978396974503994, -0.010370124131441116, -0.0014951454941183329, 0.0008281765040010214, -0.021465152502059937, 0.025052711367607117, 0.008592197671532631, 0.023815875872969627, -0.06514342129230499, -0.018710605800151825, 0.0077172014862298965, 0.016596674919128418, -0.0039610229432582855, -0.012965400703251362, -0.02843571826815605, 0.04111470282077789, 0.0026955637149512768, 0.038392964750528336, -0.12956884503364563, -0.010636372491717339, -0.006543648894876242, 0.02910628914833069, -0.0062333084642887115, -0.04232630133628845, -0.016804998740553856, 0.014346187002956867, 0.07187878340482712, 0.000026292926122550853, -0.009279030375182629, 0.06918083131313324, -0.02501547336578369, 0.03200770542025566, 0.004073656164109707, -0.024264812469482422, 0.041697774082422256, 0.03853655233979225, 0.0038384327199310064, -0.000719163625035435, -0.003368774661794305, 0.02946951426565647, -0.038533180952072144, -0.019747788086533546, 0.007359274197369814, -0.04229144752025604, 0.0006429225904867053, 0.03356952965259552, 0.04633472487330437, -0.03708439692854881, 0.004372147843241692, -0.016184240579605103, -0.006480136886239052, -0.006910321768373251, 0.020107612013816833, 0.025977356359362602, 0.023031165823340416, 0.05276773124933243, -0.0024290760047733784, -0.003143128240481019, 0.023431336507201195, -0.02220240794122219, -0.006126671098172665, 0.032326385378837585, -0.003952893894165754, 0.0009345001890324056, -0.009463326074182987, 0.017458688467741013, 0.006736865267157555, 0.034194424748420715, 0.0004783168842550367, -0.0005459666717797518, 0.026597565039992332, 0.023967884480953217, -0.022482359781861305, 0.0015511506935581565, 0.08505472540855408, 0.007765044458210468, -0.035657983273267746, 0.005828873720020056, 0.009553691372275352, 0.012195464223623276, 0.019801318645477295, -0.018066629767417908, 0.04865976795554161, -0.035202428698539734, -0.004965196363627911, -0.0018382862908765674, -0.03354238346219063, 0.053599316626787186, 0.02238500490784645, 0.03929203003644943, 0.0341191291809082, 0.02798575907945633, 0.014726425521075726, 0.0151104386895895, 0.020991872996091843, 0.008689386770129204, -0.02205553650856018, -0.04470750689506531, 0.03655559569597244, 0.04564538225531578, -0.0552200973033905, 0.001590958796441555, 0.015937140211462975, -0.007635952904820442, 0.010790100321173668, -0.009678313508629799, -0.02364896982908249, 0.03655348718166351, -0.016413426026701927, 0.036526113748550415, -0.0021569218952208757, -0.003964163828641176, -0.009311111643910408, 0.02995803952217102, -0.01578013226389885, -0.018978886306285858, 0.003599142888560891, -0.00717016588896513, -0.02400130406022072, -0.03980831056833267, -0.036580681800842285, 0.011982998810708523, -0.012628803960978985, -0.0195926483720541, -0.06534825265407562, -0.009660366922616959, -0.020800789818167686, -0.03994830325245857, 0.04088309407234192, -0.0012257557827979326, 0.017173949629068375, 0.0027184453792870045, -0.02557792142033577, -0.008007609285414219, 0.026050392538309097 ]
76d15f9d93efb01c92547e696339173cf885a335
18,576
py
Python
pp2_model.py
BetterManlinfeng/hyperclasspptwo
053e9cf8445911e285ac723bdfbceb1cb384ed2e
[ "Apache-2.0" ]
null
null
null
pp2_model.py
BetterManlinfeng/hyperclasspptwo
053e9cf8445911e285ac723bdfbceb1cb384ed2e
[ "Apache-2.0" ]
null
null
null
pp2_model.py
BetterManlinfeng/hyperclasspptwo
053e9cf8445911e285ac723bdfbceb1cb384ed2e
[ "Apache-2.0" ]
null
null
null
from tensorflow.keras import * import tensorflow as tf from tensorflow import keras from tensorflow.keras import layers, Sequential,regularizers from tensorflow.keras.layers import Dropout # from tensorflow.keras import * # 定义一个3x3卷积!kernel_initializer='he_normal','glorot_normal' from tensorflow.python.keras.layers import Concatenate def regularized_padded_conv(*args, **kwargs): return layers.Conv2D(*args, **kwargs, padding='same', use_bias=False, kernel_initializer='he_normal', kernel_regularizer=regularizers.l2(5e-4)) ############################### 通道注意力机制 ############################### class ChannelAttention(layers.Layer): def __init__(self, in_planes, ratio=8): super(ChannelAttention, self).__init__() self.avg= layers.GlobalAveragePooling2D() self.max= layers.GlobalMaxPooling2D() self.conv1 = layers.Conv2D(in_planes//ratio, kernel_size=1, strides=1, padding='same', kernel_regularizer=regularizers.l2(5e-4), use_bias=True, activation=tf.nn.relu) self.conv2 = layers.Conv2D(in_planes, kernel_size=1, strides=1, padding='same', kernel_regularizer=regularizers.l2(5e-4), use_bias=True) def call(self, inputs): avg = self.avg(inputs) max = self.max(inputs) avg = layers.Reshape((1, 1, avg.shape[1]))(avg) # shape (None, 1, 1 feature) max = layers.Reshape((1, 1, max.shape[1]))(max) # shape (None, 1, 1 feature) avg_out = self.conv2(self.conv1(avg)) max_out = self.conv2(self.conv1(max)) out = avg_out + max_out out = tf.nn.sigmoid(out) return out ############################### 空间注意力机制 ############################### class SpatialAttention(layers.Layer): def __init__(self, kernel_size=7): super(SpatialAttention, self).__init__() self.conv1 = regularized_padded_conv(1, kernel_size=kernel_size, strides=1, activation=tf.nn.sigmoid) def call(self, inputs): avg_out = tf.reduce_mean(inputs, axis=3) max_out = tf.reduce_max(inputs, axis=3) out = tf.stack([avg_out, max_out], axis=3) # 创建一个维度,拼接到一起concat。 out = self.conv1(out) return out class BasicBlock(layers.Layer): def __init__(self, filter_num, stride=1): super(BasicBlock, self).__init__() # self.conv1 = layers.Conv2D(filter_num, (3, 3), strides=stride, padding='same', kernel_initializer='he_normal',kernel_regularizer=keras.regularizers.l2(5e-4)) self.conv1 = layers.Conv2D(filter_num, (3, 3), strides=stride, padding='same',kernel_regularizer=regularizers.l2(0.0001)) #kernel_initializer='he_normal', self.bn1 = layers.BatchNormalization() self.relu = layers.Activation('relu') self.conv2 = layers.Conv2D(filter_num, (3, 3), strides=1, padding='same',kernel_regularizer=regularizers.l2(0.0001)) self.bn2 = layers.BatchNormalization() ############################### 注意力机制 ############################### self.ca = ChannelAttention(filter_num) self.sa = SpatialAttention() if stride != 1: self.downsample = Sequential() self.downsample.add(layers.Conv2D(filter_num, (1, 1), strides=stride)) else: self.downsample = lambda x:x def call(self, inputs, training=None): # [b, h, w, c] out = self.conv1(inputs) out = self.bn1(out) out = self.relu(out) out = self.conv2(out) out = self.bn2(out) ############################### 注意力机制 ############################### out = self.ca(out) * out out = self.sa(out) * out identity = self.downsample(inputs) output = layers.add([out, identity]) output = tf.nn.relu(output) return output ###################################### class build_resblock(keras.Model): def __init__(self, filter_num, stride): super(build_resblock, self).__init__() self.BasicBlock1 = BasicBlock(filter_num, stride) self.BasicBlock2 = BasicBlock(filter_num, stride=1) def call(self,blocks): res_blocks = Sequential() res_blocks.add(self.BasicBlock1) for _ in range(1, blocks): res_blocks.add(self.BasicBlock2) return res_blocks def build_resblock(self, filter_num, blocks, stride=1): res_blocks = Sequential() # may down sample res_blocks.add(BasicBlock(filter_num, stride)) for _ in range(1, blocks): res_blocks.add(BasicBlock(filter_num, stride=1)) return res_blocks ###################################### class ResNet(keras.Model): def __init__(self, layer_dims, num_classes=16): # [2, 2, 2, 2] super(ResNet, self).__init__() self.stem = Sequential([layers.Conv2D(64, (3, 3), strides=(1, 1)), layers.BatchNormalization(), layers.Activation('relu'), layers.MaxPool2D(pool_size=(2, 2), strides=(1, 1), padding='same') ]) self.layer1 = self.build_resblock(64, layer_dims[0]) self.layer2 = self.build_resblock(128, layer_dims[1], stride=1) self.layer3 = self.build_resblock(256, layer_dims[2], stride=1) self.layer4 = self.build_resblock(512, layer_dims[3], stride=1) # output: [b, 512, h, w], self.avgpool = layers.GlobalAveragePooling2D() self.fc = layers.Dense(num_classes) def call(self, inputs, training=None): x = self.stem(inputs) x = self.layer1(x) x = self.layer2(x) x = self.layer3(x) x = self.layer4(x) # [b, c] x = self.avgpool(x) # [b, 100] x = self.fc(x) return x def build_resblock(self, filter_num, blocks, stride=1): res_blocks = Sequential() # may down sample res_blocks.add(BasicBlock(filter_num, stride)) for _ in range(1, blocks): res_blocks.add(BasicBlock(filter_num, stride=1)) return res_blocks def resnet18(): return ResNet([2, 2, 2, 2],num_classes=9) def resnet34(): return ResNet([3, 4, 6, 3],num_classes=9) ########################### pp2主模型 ######################################## class pp2_model(keras.Model): def __init__(self,filters_num,layer_dims,num_classes,dropout_rate): super(pp2_model, self).__init__() self.conv1 = layers.Conv3D(filters_num[0],kernel_size=(3,3,7),padding='same') # filters_num = 8 self.bn1 = layers.BatchNormalization() self.relu1 = layers.Activation('relu') self.conv2 = layers.Conv3D(filters_num[1],kernel_size=(3,3,5),padding='same') # filters_num = 16 self.bn2 = layers.BatchNormalization() self.relu2 = layers.Activation('relu') self.conv3 = layers.Conv3D(filters_num[2], kernel_size=(3, 3, 3), padding='same') # filters_num = 32 self.bn3 = layers.BatchNormalization() self.relu3 = layers.Activation('relu') # self.reshape = layers.Reshape() self.conv4 = layers.Conv2D(filters_num[3], kernel_size=(3, 3), padding='same') # filters_num = 64 self.bn4 = layers.BatchNormalization() self.relu4 = layers.Activation('relu') self.conv5 = layers.Conv2D(filters_num[4], kernel_size=(3, 3), padding='same') # filters_num = ** self.bn5 = layers.BatchNormalization() self.relu5 = layers.Activation('relu') self.dpout = layers.Dropout(dropout_rate) self.layer1 = self.build_resblock(filters_num[5], layer_dims[0]) # filters_num = 64 self.layer2 = self.build_resblock(filters_num[6], layer_dims[1], stride=2) # filters_num = 128 self.layer3 = self.build_resblock(filters_num[7], layer_dims[2], stride=2) # filters_num = 256 self.layer4 = self.build_resblock(filters_num[8], layer_dims[3], stride=2) # filters_num = 512 # output: [b, 512, h, w], # self.fc1 = layers.Flatten() self.avgpool = layers.GlobalAveragePooling2D() self.fc2 = layers.Dense(filters_num[7],activation='relu') self.fc3 = layers.Dense(filters_num[6],activation='relu') self.fc4 = layers.Dense(num_classes) def call(self,inputs,training=None): out = self.conv1(inputs) out = self.bn1(out) out = self.relu1(out) out = self.conv2(out) out = self.bn2(out) out = self.relu2(out) out = self.conv3(out) out = self.bn3(out) out = self.relu3(out) # reshape out = layers.Reshape((out.shape[1],out.shape[2],out.shape[3] * out.shape[4]))(out) out = self.conv4(out) out = self.bn4(out) out = self.relu4(out) out = self.dpout(out) out = self.conv5(out) out = self.bn5(out) out = self.dpout(out) out = self.relu5(out) x = self.layer1(out) x = self.layer2(x) x = self.layer3(x) x = self.layer4(x) # [b, c] x = self.avgpool(x) # [b, 100] x = self.fc2(x) x = self.dpout(x) x = self.fc3(x) x = self.fc4(x) return x def build_resblock(self, filter_num, blocks, stride=1): res_blocks = Sequential() # may down sample res_blocks.add(BasicBlock(filter_num, stride)) for _ in range(1, blocks): res_blocks.add(BasicBlock(filter_num, stride=1)) return res_blocks class ResNet_block(keras.Model): def __init__(self, layer_dims,filters_num): # [2, 2, 2, 2] super(ResNet_block, self).__init__() # # self.stem = Sequential([layers.Conv2D(64, (3, 3), strides=(1, 1)), # layers.BatchNormalization(), # layers.Activation('relu'), # layers.MaxPool2D(pool_size=(2, 2), strides=(1, 1), padding='same') # ]) self.layer1 = self.build_resblock(filters_num[0], layer_dims[0]) # filters_num = 64 self.layer2 = self.build_resblock(filters_num[1], layer_dims[1], stride=1) # filters_num = 128 self.layer3 = self.build_resblock(filters_num[2], layer_dims[2], stride=1) # filters_num = 256 self.layer4 = self.build_resblock(filters_num[3], layer_dims[3], stride=1) # filters_num = 512 # output: [b, 512, h, w], # self.avgpool = layers.GlobalAveragePooling2D() # self.fc = layers.Dense(num_classes) def call(self, inputs, training=None): # x = self.stem(inputs) x1 = self.layer1(inputs) x2 = self.layer2(x1) x3 = self.layer3(x2) x4 = self.layer4(x3) # [b, c] # x = self.avgpool(x) # [b, 100] # x = self.fc(x) return x2,x4 def build_resblock(self, filter_num, blocks, stride=1): res_blocks = Sequential() # may down sample res_blocks.add(BasicBlock(filter_num, stride)) for _ in range(1, blocks): res_blocks.add(BasicBlock(filter_num, stride=1)) return res_blocks def network_up(input_layer_up,filters_num,dropout_rate,Block_res): # input_layer = Input(input_shape) # conv1 = layers.Conv3D(filters_num[0], kernel_size=(3, 3, 7), padding='same')(input_layer) # filters_num = 8 # conv1 = layers.Conv3D(filters_num[0], kernel_size=(3, 3, 3),padding='same',kernel_initializer='he_normal',kernel_regularizer=regularizers.l2(0.0001))(input_layer_up) # filters_num = 8 conv1 = layers.Conv3D(filters_num[0], kernel_size=(3, 3, 3), padding='same', kernel_regularizer=regularizers.l2(0.0001))(input_layer_up) #kernel_initializer='he_normal', # conv_layer1m = tf.keras.layers.MaxPooling3D(pool_size=(1, 1, 1),padding='same')(conv1) # conv_layer1g = tf.keras.layers.GlobalMaxPooling3D()(conv1) conv1_bn = layers.BatchNormalization()(conv1) conv1_relu = layers.Activation('relu')(conv1_bn) # conv1_relu = Dropout(0.5)(conv1_relu) # conv1_relu = tf.keras.layers.MaxPooling3D(pool_size=(2, 2, 2), strides=(1, 1, 1), padding='same')(conv1_relu) # conv2 = layers.Conv3D(filters_num[1], kernel_size=(3, 3, 5), padding='same')(conv1_relu) # filters_num = 16 conv2 = layers.Conv3D(filters_num[1], kernel_size=(3, 3, 3),padding='same',kernel_regularizer=regularizers.l2(0.0001))(conv1_relu) # filters_num = 16 conv2_bn = layers.BatchNormalization()(conv2) conv2_relu = layers.Activation('relu')(conv2_bn) # conv2_relu = Dropout(0.5)(conv2_relu) # conv2_relu = tf.keras.layers.MaxPooling3D(pool_size=(2, 2, 2), strides=(1, 1, 1), padding='same')(conv2_relu) conv3 = layers.Conv3D(filters_num[2], kernel_size=(3, 3, 3),padding='same',kernel_regularizer=regularizers.l2(0.0001))(conv2_relu) # filters_num = 32 conv3_bn = layers.BatchNormalization()(conv3) conv3_relu = layers.Activation('relu')(conv3_bn) # conv3_relu = Dropout(0.5)(conv3_relu) # conv3_relu = tf.keras.layers.MaxPooling3D(pool_size=(2, 2, 2), strides=(1, 1, 1), padding='same')(conv3_relu) conv3_relu_reshape = layers.Reshape((conv3_relu.shape[1],conv3_relu.shape[2],conv3_relu.shape[3]*conv3_relu.shape[4]))(conv3_relu) conv3_relu_reshape = Dropout(0.5)(conv3_relu_reshape) ##################第二个尺度######################### # conv11 = layers.Conv3D(filters_num[0], kernel_size=(5, 5, 3), padding='same', # kernel_initializer='he_normal', kernel_regularizer=regularizers.l2(0.0001))(input_layer_up) # conv11_bn = layers.BatchNormalization()(conv11) # conv11_relu = layers.Activation('relu')(conv11_bn) # # # conv2 = layers.Conv3D(filters_num[1], kernel_size=(3, 3, 5), padding='same')(conv1_relu) # filters_num = 16 # conv22 = layers.Conv3D(filters_num[1], kernel_size=(5, 5, 3), padding='same', kernel_initializer='he_normal', # kernel_regularizer=regularizers.l2(0.0001))(conv11_relu) # filters_num = 16 # conv22_bn = layers.BatchNormalization()(conv22) # conv22_relu = layers.Activation('relu')(conv22_bn) # # conv33 = layers.Conv3D(filters_num[2], kernel_size=(5, 5, 3), padding='same', kernel_initializer='he_normal', # kernel_regularizer=regularizers.l2(0.0001))(conv22_relu) # filters_num = 32 # conv33_bn = layers.BatchNormalization()(conv33) # conv33_relu = layers.Activation('relu')(conv33_bn) # # conv33_relu_reshape = layers.Reshape( # (conv3_relu.shape[1], conv3_relu.shape[2], conv3_relu.shape[3] * conv3_relu.shape[4]))(conv33_relu) #################################################### # conv111 = layers.Conv3D(filters_num[0], kernel_size=(7, 7, 3), padding='same', # kernel_initializer='he_normal', kernel_regularizer=regularizers.l2(0.0001))(input_layer_up) # conv111_bn = layers.BatchNormalization()(conv111) # conv111_relu = layers.Activation('relu')(conv111_bn) # # # conv2 = layers.Conv3D(filters_num[1], kernel_size=(3, 3, 5), padding='same')(conv1_relu) # filters_num = 16 # conv222 = layers.Conv3D(filters_num[1], kernel_size=(7, 7, 3), padding='same', kernel_initializer='he_normal', # kernel_regularizer=regularizers.l2(0.0001))(conv111_relu) # filters_num = 16 # conv222_bn = layers.BatchNormalization()(conv222) # conv222_relu = layers.Activation('relu')(conv222_bn) # # conv333 = layers.Conv3D(filters_num[2], kernel_size=(7, 7, 3), padding='same', kernel_initializer='he_normal', # kernel_regularizer=regularizers.l2(0.0001))(conv222_relu) # filters_num = 32 # conv333_bn = layers.BatchNormalization()(conv333) # conv333_relu = layers.Activation('relu')(conv333_bn) # # conv333_relu_reshape = layers.Reshape( # (conv3_relu.shape[1], conv3_relu.shape[2], conv3_relu.shape[3] * conv3_relu.shape[4]))(conv333_relu) #################concatenate######################## # conv33333_relu_reshape = Concatenate(axis=-1)([conv3_relu_reshape, conv33_relu_reshape]) ######################################### conv4 = layers.Conv2D(filters_num[3], kernel_size=(3, 3), padding='same',kernel_regularizer=regularizers.l2(0.0001))(conv3_relu_reshape) # filters_num = 64 conv4_bn = layers.BatchNormalization()(conv4) conv4_relu = layers.Activation('relu')(conv4_bn) # conv4_relu = Dropout(0.5)(conv4_relu) # conv4_relu = tf.keras.layers.MaxPooling2D(pool_size=(2, 2), strides=(1, 1), padding='same')(conv4_relu) # conv4_relu = tf.keras.layers.MaxPooling3D(pool_size=(2, 2, 2), strides=(1, 1, 1), padding='same')(conv4_relu) conv5 = layers.Conv2D(filters_num[4], kernel_size=(3, 3), padding='same',kernel_regularizer=regularizers.l2(0.0001))(conv4_relu) # filters_num = ** conv5_bn = layers.BatchNormalization()(conv5) conv5_relu = layers.Activation('relu')(conv5_bn) # conv5_relu = Dropout(0.5)(conv5_relu) # conv5_relu = tf.keras.layers.MaxPooling2D(pool_size=(2, 2), strides=(1, 1), padding='same')(conv5_relu) # conv5_relu = tf.keras.layers.MaxPooling3D(pool_size=(2, 2, 2), strides=(1, 1, 1), padding='same')(conv5_relu) # conv5_dpout = layers.Dropout(dropout_rate)(conv5) # conv5_reshape = layers.Reshape((conv5_dpout.shape[1],conv5_dpout.shape[2],conv5_dpout.shape[3]))(conv5_dpout) outputs2,outputs4 = Block_res(conv5_relu) return conv5,outputs2,outputs4 # layer1 = build_resblock(filters_num[5], layer_dims[0]) # filters_num = 64 # layer2 = build_resblock(filters_num[6], layer_dims[1], stride=2) # filters_num = 128 # layer3 = build_resblock(filters_num[7], layer_dims[2], stride=2) # filters_num = 256 # layer4 = build_resblock(filters_num[8], layer_dims[3], stride=2) # filters_num = 512
39.02521
191
0.596307
1
2.0676
[ -0.013393973000347614, 0.00020729661628138274, -0.013931331224739552, 0.009607311338186264, -0.013801372610032558, 0.009175997227430344, -0.015534812584519386, -0.00982942245900631, 0.0020403405651450157, 0.025319404900074005, 0.0031799476128071547, -0.0036866350565105677, 0.02262890711426735, 0.01616862043738365, -0.042277827858924866, 0.0030399784445762634, 0.025416716933250427, 0.018896320834755898, -0.05252625793218613, -0.026324840262532234, -0.013624576851725578, -0.0003120801120530814, -0.018193641677498817, 0.022099601104855537, 0.016005059704184532, 0.036257803440093994, 0.03814560920000076, 0.008798200637102127, 0.01482422836124897, 0.0045252307318151, -0.003138049505650997, 0.006204121746122837, -0.0073740798979997635, 0.025374120101332664, -0.016632676124572754, 0.0012839509872719646, 0.0009900412987917662, -0.006879032123833895, -0.020315049216151237, -0.016870616003870964, -0.01406017318367958, -0.0453496053814888, 0.03131717070937157, 0.03266531601548195, 0.010988572612404823, 0.027309473603963852, -0.005756758153438568, 0.015619796700775623, -0.044394996017217636, 0.023895571008324623, -0.032444898039102554, -0.0019949665293097496, 0.019248398020863533, -0.06098736450076103, 0.0038455636240541935, -0.06556838750839233, -0.002200843533501029, 0.03972810506820679, 0.01788327470421791, 0.01496631745249033, -0.004585355520248413, -0.000008358792911167257, -0.019728699699044228, 0.0009331254987046123, 0.04204282537102699, 0.00025637043290771544, 0.00048679366591386497, -0.0012712064199149609, -0.023601733148097992, 0.0082688694819808, 0.037789858877658844, -0.022213591262698174, 0.011050010100007057, 0.027778388932347298, -0.012171195819973946, -0.003099029418081045, -0.022855764254927635, -0.012500710785388947, -0.008219421841204166, 0.025704266503453255, -0.0013736449182033539, 0.01697305217385292, 0.01890723407268524, -0.008156483061611652, 0.0019084155792370439, 0.03858897462487221, 0.011483535170555115, -0.02564874477684498, 0.010829508304595947, -0.020329611375927925, -0.0461714006960392, 0.03305685892701149, -0.041656021028757095, -0.019538607448339462, 0.008286247961223125, -0.06264819204807281, 0.020316217094659805, -0.0022825992200523615, 0.009008685126900673, 0.01142379455268383, -0.000050844348152168095, 0.0013077055336907506, 0.022593166679143906, -0.01602814719080925, 0.0040953936986625195, -0.017891503870487213, -0.056660301983356476, 0.0446559302508831, 0.008636207319796085, -0.016829583793878555, 0.014662262052297592, 0.012062720023095608, 0.001823004917241633, -0.06349536776542664, 0.001480586244724691, -0.03184942901134491, 0.023321649059653282, -0.009845267981290817, 0.015548303723335266, 0.07338593900203705, -0.0019411479588598013, -0.029819272458553314, 0.023268142715096474, -0.0058591775596141815, -0.03795129805803299, 0.08668594062328339, 0.010664688423275948, 0.01603134535253048, 0.0011602026643231511, -0.0006806246819905937, -0.007836753502488136, -0.027081498876214027, -0.011504278518259525, 0.011155974119901657, -0.028864355757832527, -0.04464632645249367, -0.018801504746079445, 0.006758402101695538, -0.00772743159905076, 0.007819630205631256, 0.018833860754966736, -0.054713521152734756, 0.01587834767997265, -0.017995499074459076, -0.01766844652593136, -0.042656607925891876, -0.024024760350584984, 0.022353526204824448, -0.012879062443971634, -0.0011655730195343494, -0.019640101119875908, -0.006300756242126226, 0.0008816099143587053, 0.047802288085222244, 0.016852272674441338, 0.0038447098340839148, -0.044334329664707184, -0.0547819621860981, 0.007300016935914755, -0.0037427518982440233, -0.008201460354030132, 0.0034003236796706915, 0.007254230324178934, -0.0008046692237257957, -0.006696575786918402, -0.002465004101395607, -0.03422287851572037, -0.02739335410296917, -0.022927463054656982, 0.035391632467508316, -0.021632760763168335, -0.02638150192797184, -0.014080542139708996, -0.001912257052026689, -0.01809055544435978, -0.004358124453574419, -0.0320797897875309, -0.01516038179397583, 0.02637232281267643, -0.008555633947253227, -0.0047631761990487576, 0.01866217516362667, 0.01090324204415083, 0.0521276481449604, 0.017386022955179214, -0.01872672326862812, -0.031919777393341064, -0.006817205809056759, 0.032535843551158905, 0.03703044727444649, -0.02176610752940178, 0.03522375226020813, 0.01668574847280979, -0.02675791271030903, 0.011221958324313164, 0.005207442678511143, -0.016476374119520187, 0.017365029081702232, -0.01251028198748827, -0.00817775446921587, 0.005995316430926323, 0.008963475935161114, 0.013706229627132416, 0.002143086865544319, -0.011633903719484806, 0.009843372739851475, -0.7083342671394348, 0.005244693718850613, -0.01804586872458458, -0.004983569961041212, 0.0262325257062912, 0.06894564628601074, -0.0229118000715971, 0.01208497490733862, -0.028905242681503296, -0.004816825035959482, 0.03564617410302162, -0.023803813382983208, -0.042495399713516235, -0.003793771378695965, 0.04749249294400215, -0.019430922344326973, 0.028643207624554634, 0.00639873743057251, 0.041294634342193604, 0.048427268862724304, 0.009988147765398026, 0.010870150290429592, 0.0009438559063710272, 0.032269734889268875, -0.021616831421852112, 0.004084727261215448, 0.03870874643325806, -0.01651960238814354, -0.011575199663639069, -0.002625499852001667, 0.02223104052245617, 0.007249119691550732, 0.004142130259424448, -0.029628269374370575, 0.029860835522413254, 0.0000660834921291098, -0.02341352216899395, -0.00010856007429538295, -0.01793825440108776, -0.010835578665137291, -0.007983232848346233, -0.03255530074238777, -0.007376139517873526, -0.049088653177022934, 0.020514994859695435, 0.011418990790843964, 0.016500746831297874, -0.044997647404670715, 0.00719224801287055, -0.0007033626898191869, -0.04877178370952606, -0.000034639291698113084, 0.007079111412167549, 0.004000650253146887, 0.040282655507326126, 0.001214118441566825, -0.0075635239481925964, -0.029468337073922157, -0.013794047757983208, -0.007220004219561815, 0.045736804604530334, -0.00441498588770628, -0.011605378240346909, -0.025030851364135742, -0.04912261292338371, 0.007521309889853001, 0.053098853677511215, -0.0005569736822508276, -0.007977448403835297, 0.013808856718242168, -0.018073562532663345, -0.014916093088686466, -0.025298792868852615, 0.1264994740486145, 0.010057286359369755, 0.003744268324226141, -0.020887194201350212, -0.014815151691436768, 0.0011627591447904706, 0.01862402632832527, 0.007271162234246731, -0.014249492436647415, 0.041577115654945374, -0.008144467137753963, -0.03903857618570328, -0.01121525838971138, 0.02489529736340046, -0.009287896566092968, 0.01208440214395523, 0.03016330488026142, 0.014011560939252377, 0.04727955907583237, 0.016123885288834572, -0.00792399700731039, 0.03540407493710518, 0.0054689268581569195, -0.019070256501436234, 0.078817218542099, 0.02334401197731495, -0.008151653222739697, -0.027654828503727913, 0.002513707149773836, -0.028208941221237183, 0.05030759423971176, 0.02279394306242466, 0.0019673241768032312, -0.0060793738812208176, 0.0239074919372797, 0.03485146537423134, -0.04431683570146561, 0.027688920497894287, -0.018138455227017403, -0.029688259586691856, 0.025578733533620834, -0.01377134583890438, -0.02655191719532013, -0.041767414659261703, -0.03861391171813011, 0.017686747014522552, -0.008008213713765144, -0.0007693487568758428, -0.01231394149363041, -0.017415327951312065, 0.0011227745562791824, -0.020647406578063965, 0.004309422802180052, 0.020617203786969185, -0.03576060011982918, 0.01744065061211586, 0.02672215737402439, -0.009065942838788033, -0.0016079202760010958, -0.03275049105286598, -0.010476158931851387, 0.03135921061038971, 0.0005393155734054744, 0.002298728097230196, -0.02828199230134487, -0.02036265842616558, -0.01179391797631979, 0.011338739655911922, 0.009216822683811188, -0.02949492633342743, -0.03166443109512329, -0.0070787956938147545, -0.005173433106392622, -0.03385809808969498, 0.023478925228118896, -0.013511760160326958, -0.02404741384088993, -0.01673295721411705, 0.018855655565857887, 0.028234869241714478, 0.0014643556205555797, -0.038578785955905914, 0.018949488177895546, 0.003023772966116667, 0.00746228126809001, 0.04335162788629532, 0.02076842449605465, 0.06094470992684364, -0.014671352691948414, 0.013173693791031837, 0.05656390264630318, 0.005806781351566315, 0.0058878748677670956, -0.008811919018626213, 0.021457944065332413, 0.021899083629250526, 0.021880321204662323, 0.010110024362802505, -0.03788069635629654, -0.011879203841090202, -0.003849961794912815, -0.03525705635547638, -0.016280964016914368, -0.030938107520341873, 0.04040636122226715, -0.02615080215036869, -0.00971538107842207, 0.0199312511831522, -0.013791672885417938, -0.005677131935954094, -0.008392198011279106, -0.03339480981230736, 0.025584468618035316, -0.004525349009782076, 0.024132803082466125, 0.041679706424474716, -0.009414472617208958, 0.021976925432682037, 0.012176190502941608, -0.0337761752307415, -0.008367831818759441, -0.0162535198032856, -0.03950577229261398, -0.04240759462118149, -0.0027248987462371588, -0.0005699436878785491, -0.03743549808859825, -0.00014005649427417666, 0.003667376236990094, 0.015915879979729652, -0.011602582409977913, -0.017482439056038857, 0.009485499933362007, -0.005295729264616966, 0.02636345475912094, -0.01762169413268566, 0.007728951051831245, -0.0019393011461943388, -0.033766284584999084, 0.03160135820508003, 0.01761201210319996, 0.003937999717891216, 0.04483575001358986, -0.01239508856087923, -0.027852393686771393, -0.009946717880666256, -0.030502473935484886, -0.004761882591992617, -0.0053970166482031345, 0.010305630043148994, -0.005979325622320175, -0.010225766338407993, -0.008932978846132755, -0.049603354185819626, 0.006319078616797924, 0.003786248853430152, 0.00364902475848794, 0.021314712241292, -0.011197846382856369, -0.016809875145554543, 0.011721590533852577, -0.006368766073137522, 0.029460135847330093, -0.00666450522840023, 0.005066460929811001, -0.0209487471729517, -0.003915346227586269, 0.03891453891992569, 0.0037793670780956745, -0.0009325655992142856, 0.0074396925047039986, -0.005422524642199278, 0.021006550639867783, -0.0012588233221322298, 0.010746857151389122, -0.052419546991586685, -0.011840015649795532, -0.02220458723604679, 0.036777328699827194, 0.014469552785158157, -0.01719396561384201, 0.002437060000374913, -0.005142769310623407, 0.011739126406610012, -0.012632261030375957, 0.00794124323874712, 0.013399097137153149, 0.017035990953445435, -0.05002942308783531, -0.014216518960893154, 0.010471856221556664, 0.014440652914345264, -0.017394084483385086, 0.024600964039564133, 0.027689674869179726, 0.006549987941980362, 0.031417813152074814, 0.00198596203699708, -0.023204166442155838, -0.0018391956109553576, -0.01684982143342495, 0.02544722892343998, -0.04094895347952843, 0.011279224418103695, -0.015617062337696552, -0.016192669048905373, 0.023884249851107597, -0.021695943549275398, -0.022871198132634163, 0.028821032494306564, 0.0025673038326203823, 0.011209260672330856, -0.0221666619181633, 0.008326403796672821, -0.028612516820430756, 0.004039566032588482, 0.019370242953300476, -0.0006074517732486129, -0.03507235646247864, -0.018881939351558685, -0.01347317360341549, -0.03127550333738327, 0.03349372744560242, -0.009173735976219177, -0.00957640539854765, 0.07181940972805023, 0.055733636021614075, 0.02862863801419735, 0.024566758424043655, 0.0269967932254076, 0.029038475826382637, 0.04990801960229874, -0.01102434191852808, -0.01838105544447899, 0.015684600919485092, 0.025347204878926277, 0.004197004251182079, 0.0038867408875375986, 0.018065864220261574, -0.018900243565440178, -0.020374301820993423, 0.0010946025140583515, -0.016107900068163872, 0.0671672448515892, -0.03690631315112114, -0.017252573743462563, -0.0030424364376813173, 0.011610840447247028, -0.001424696296453476, -0.024387380108237267, -0.027637382969260216, 0.015584739856421947, -0.015663711354136467, -0.01780218631029129, -0.029414581134915352, 0.04416080191731453, 0.008515027351677418, -0.008935493417084217, -0.017554666846990585, 0.017822053283452988, 0.006461670156568289, -0.01673329994082451, 0.005157558713108301, 0.005225253291428089, 0.027534527704119682, -0.023954320698976517, -0.008123449049890041, 0.03235797956585884, 0.019458165392279625, 0.010561343282461166, -0.007192273624241352, 0.011270095594227314, 0.036703042685985565, 0.04153288155794144, 0.0618617944419384, 0.03798902779817581, 0.015614739619195461, 0.03836403042078018, -0.05069770663976669, -0.025041716173291206, 0.034855205565690994, -0.01215559896081686, 0.007442759815603495, 0.019196927547454834, 0.028084781020879745, 0.032415442168712616, -0.07506392151117325, 0.013073422946035862, -0.012118855491280556, 0.02183661237359047, -0.01058130618184805, 0.006339347921311855, -0.011945469304919243, 0.004544008523225784, -0.0295798908919096, 0.006058570463210344, 0.02152412384748459, -0.016299821436405182, -0.025417963042855263, 0.03200957179069519, 0.002451759995892644, -0.025818783789873123, 0.05201917514204979, 0.008813340216875076, 0.010918094776570797, -0.007298521231859922, -0.031847160309553146, -0.0049080210737884045, -0.07682814449071884, 0.039098381996154785, -0.06139286607503891, 0.025265634059906006, -0.03453591838479042, -0.020139401778578758, -0.021537208929657936, 0.005103342235088348, -0.03940337896347046, -0.018963731825351715, -0.04247846454381943, 0.017000902444124222, 0.03000020794570446, -0.02187088504433632, -0.003590971464291215, -0.03733298182487488, 0.00843102764338255, 0.008994430303573608, -0.022570764645934105, -0.013596302829682827, 0.007751703727990389, 0.016582323238253593, 0.010156672447919846, -0.014285054057836533, -0.012415694072842598, -0.0016177521320059896, -0.0084910336881876, 0.006701822858303785, -0.005436765030026436, 0.012878159992396832, 0.02607419341802597, -0.01857348158955574, 0.009077459573745728, 0.00023051348398439586, -0.0018732326570898294, -0.04273798316717148, 0.023034628480672836, 0.0036651992704719305, -0.032242126762866974, 0.006249022204428911, -0.04576617851853371, -0.024145392701029778, 0.004304028116166592, 0.008462658151984215, 0.004357588477432728, 0.019261138513684273, -0.015845680609345436, 0.013877999037504196, 0.020012537017464638, -0.015046931803226471, -0.014854633249342442, -0.01815154403448105, 0.029683198779821396, -0.012299397960305214, -0.030557867139577866, 0.0063455551862716675, -0.050816576927900314, -0.021363550797104836, 0.01679726131260395, -0.045026544481515884, 0.018528494983911514, 0.0035491108428686857, 0.004678890574723482, -0.0001254233211511746, 0.04393990710377693, 0.02766476757824421, 0.012615803629159927, -0.013706924393773079, 0.01066778413951397, 0.014593672938644886, 0.017029359936714172, 0.0016609285958111286, 0.04114565998315811, 0.012381068430840969, 0.009886203333735466, 0.0010234169894829392, 0.028095223009586334, 0.011827184818685055, -0.014501732774078846, -0.011450526304543018, -0.01400753203779459, -0.011796383187174797, 0.0302438922226429, 0.0015167115489020944, 0.019334975630044937, -0.02873578853905201, -0.03422990068793297, -0.01465698890388012, -0.02784658968448639, 0.035138003528118134, 0.008488927967846394, 0.003613116918131709, 0.017245681956410408, 0.0125806899741292, 0.00594663992524147, -0.021929217502474785, 0.073662668466568, 0.042886242270469666, 0.03103054314851761, -0.010009460151195526, 0.013556740246713161, 0.01975942589342594, 0.004664757754653692, -0.006903897039592266, -0.01643485762178898, 0.00652612978592515, 0.03646481782197952, 0.006383954081684351, 0.013044514693319798, 0.0104328952729702, -0.02914581261575222, -0.0310628954321146, -0.010873062536120415, -0.006277611944824457, 0.008475224487483501, 0.020614702254533768, -0.04480335861444473, 0.03390054032206535, 0.004087899811565876, 0.007677324581891298, -0.06499531865119934, -0.01942879892885685, -0.04493128880858421, 0.04832432419061661, 0.03889448195695877, 0.06623132526874542, 0.006063401233404875, 0.017789211124181747, 0.025626178830862045, 0.013804128393530846, 0.006022450979799032, -0.04196472838521004, -0.04565545916557312, -0.014537931419909, 0.020148999989032745, 0.037736065685749054, -0.029218090698122978, 0.03369161859154701, 0.029022082686424255, -0.017361942678689957, 0.004287295043468475, 0.010908972471952438, -0.021217120811343193, 0.016952216625213623, 0.0011179432040080428, -0.037916459143161774, -0.023170797154307365, 0.01724114641547203, 0.025866687297821045, -0.03561609238386154, -0.028662217780947685, -0.040576860308647156, 0.011735009960830212, 0.018472997471690178, -0.028183700516819954, 0.068111851811409, 0.022081345319747925, -0.02751355804502964, -0.01764850690960884, 0.030334539711475372, -0.002750422339886427, -0.020450018346309662, -0.0034891704563051462, -0.015707403421401978, -0.06108138710260391, -0.03462418168783188, -0.00036197362351231277, 0.04184531047940254, 0.05368814244866371, -0.0033508625347167253, -0.018990533426404, -0.017248477786779404, -0.03224395588040352, -0.05530737712979317, -0.0042235348373651505, 0.009200254455208778, -0.003935016691684723, 0.026745161041617393, -0.0570598728954792, 0.016694294288754463, 0.008206882514059544 ]
76d272f048a94a1ab146a49618ff07c96686a509
3,364
py
Python
medi/inference/utils.py
yuan-xy/medi
ffa416b73eb2fbffbae7a27b6eccc267b061ed0f
[ "MIT" ]
3
2020-05-27T08:42:26.000Z
2021-12-04T08:54:08.000Z
medi/inference/utils.py
yuan-xy/medi
ffa416b73eb2fbffbae7a27b6eccc267b061ed0f
[ "MIT" ]
null
null
null
medi/inference/utils.py
yuan-xy/medi
ffa416b73eb2fbffbae7a27b6eccc267b061ed0f
[ "MIT" ]
null
null
null
""" A universal module with functions / classes without dependencies. """ import sys import contextlib import functools import re import os from medi._compatibility import reraise _sep = os.path.sep if os.path.altsep is not None: _sep += os.path.altsep _path_re = re.compile(r'(?:\.[^{0}]+|[{0}]__init__\.py)$'.format(re.escape(_sep))) del _sep def to_list(func): def wrapper(*args, **kwargs): return list(func(*args, **kwargs)) return wrapper def to_tuple(func): def wrapper(*args, **kwargs): return tuple(func(*args, **kwargs)) return wrapper def unite(iterable): """Turns a two dimensional array into a one dimensional.""" return set(typ for types in iterable for typ in types) class UncaughtAttributeError(Exception): """ Important, because `__getattr__` and `hasattr` catch AttributeErrors implicitly. This is really evil (mainly because of `__getattr__`). `hasattr` in Python 2 is even more evil, because it catches ALL exceptions. Therefore this class originally had to be derived from `BaseException` instead of `Exception`. But because I removed relevant `hasattr` from the code base, we can now switch back to `Exception`. :param base: return values of sys.exc_info(). """ def safe_property(func): return property(reraise_uncaught(func)) def reraise_uncaught(func): """ Re-throw uncaught `AttributeError`. Usage: Put ``@rethrow_uncaught`` in front of the function which does **not** suppose to raise `AttributeError`. AttributeError is easily get caught by `hasattr` and another ``except AttributeError`` clause. This becomes problem when you use a lot of "dynamic" attributes (e.g., using ``@property``) because you can't distinguish if the property does not exist for real or some code inside of the "dynamic" attribute through that error. In a well written code, such error should not exist but getting there is very difficult. This decorator is to help us getting there by changing `AttributeError` to `UncaughtAttributeError` to avoid unexpected catch. This helps us noticing bugs earlier and facilitates debugging. .. note:: Treating StopIteration here is easy. Add that feature when needed. """ @functools.wraps(func) def wrapper(*args, **kwds): try: return func(*args, **kwds) except AttributeError: exc_info = sys.exc_info() reraise(UncaughtAttributeError(exc_info[1]), exc_info[2]) return wrapper class PushBackIterator(object): def __init__(self, iterator): self.pushes = [] self.iterator = iterator self.current = None def push_back(self, value): self.pushes.append(value) def __iter__(self): return self def next(self): """ Python 2 Compatibility """ return self.__next__() def __next__(self): if self.pushes: self.current = self.pushes.pop() else: self.current = next(self.iterator) return self.current @contextlib.contextmanager def ignored(*exceptions): """ Value manager that ignores all of the specified exceptions. This will be in the standard library starting with Python 3.5. """ try: yield except exceptions: pass
29
82
0.671819
1
1.7826
[ 0.0018181651830673218, 0.02393001690506935, 0.007915345020592213, 0.0011981154093518853, 0.005731156095862389, -0.002683139406144619, -0.009432576596736908, 0.0029184361919760704, -0.006523461546748877, 0.002422204939648509, 0.0013606457505375147, 0.004426626022905111, 0.005029135849326849, -0.017599765211343765, -0.0006955898134037852, 0.01574123464524746, -0.050529032945632935, 0.001547511201351881, -0.0053214640356600285, 0.0030770201701670885, -0.006586098112165928, 0.009541374631226063, 0.008724527433514595, 0.006941963452845812, 0.007279941346496344, -0.0008218104485422373, 0.009754416532814503, 0.0014648919459432364, -0.00699545769020915, -0.007939277216792107, -0.00040500471368432045, -0.0017438377253711224, -0.004844640381634235, -0.008120774291455746, 0.00673878937959671, -0.0012178797041997313, -0.00010229383042315021, -0.01806599646806717, 0.010581685230135918, -0.00416331784799695, -0.0077990940771996975, -0.015318430960178375, -0.0008088961476460099, 0.004639207385480404, -0.008916258811950684, 0.0028780722059309483, -0.0037242837715893984, 0.0027485890313982964, -0.011720121838152409, 0.007396535947918892, -0.008638227358460426, 0.0062470282427966595, 0.01326997671276331, 0.0038698245771229267, -0.007324483711272478, -0.005953200627118349, 0.013904332183301449, 0.001171701936982572, -0.009362961165606976, -0.0006300017121247947, -0.004056981764733791, -0.002824814524501562, 0.004681888967752457, 0.00345255876891315, -0.013566547073423862, -0.008491603657603264, -0.004399061668664217, 0.003574664704501629, -0.0012114536948502064, 0.006196365226060152, -0.00026832439471036196, -0.001405151910148561, 0.008837046101689339, 0.0049233585596084595, 0.005216887686401606, -0.004799893591552973, -0.00042406973079778254, -0.002539190696552396, 0.008939851075410843, 0.0026155472733080387, 0.004094056319445372, -0.005992008838802576, 0.00444130739197135, 0.008813563734292984, 0.014478707686066628, 0.007662232965230942, 0.020023062825202942, -0.010091830044984818, 0.047761619091033936, 0.008773303590714931, -0.009012994356453419, 0.000633321120403707, -0.008062786422669888, -0.001844847691245377, -0.004602069966495037, -0.026074819266796112, 0.00022054524742998183, -0.004820816684514284, 0.00010445851512486115, 0.004351090639829636, -0.00034106074599549174, 0.0073693981394171715, -0.002176647074520588, -0.0012455378891900182, -0.009076409973204136, 0.009917302057147026, -0.009174024686217308, -0.0036699871998280287, 0.006328366231173277, 0.0022676540538668633, -0.010184872895479202, -0.0026390759740024805, 0.0013044169172644615, -0.011141661554574966, 0.003242526901885867, 0.002333082025870681, -0.004981977865099907, 0.05449848622083664, 0.00021134165581315756, 0.0021296802442520857, -0.004804694559425116, 0.00177156669087708, 0.002834297250956297, 0.005423387046903372, 0.00909775123000145, -0.0028769804630428553, 0.011466356925666332, 0.007198092062026262, 0.003816623240709305, 0.009800408035516739, -0.0016436369623988867, 0.007679713889956474, -0.005615179426968098, -0.0029738510493189096, -0.00016611938190180808, -0.007073595654219389, 0.00773082347586751, -0.0006196411559358239, -0.007914500311017036, 0.0010769329965114594, -0.00037359725683927536, -0.009557010605931282, 0.0015354875940829515, -0.0053314766846597195, 0.004552985541522503, -0.010062706656754017, -0.0022602363023906946, -0.005057089030742645, -0.003001428209245205, 0.0028680404648184776, 0.00874268263578415, 0.005252417176961899, 0.003602829994633794, -0.005699831061065197, -0.010571710765361786, -0.001827832544222474, -0.004812569357454777, -0.00007182076660683379, 0.0076272753067314625, 0.0044590323232114315, -0.010509567335247993, -0.00012447222252376378, 0.002920710714533925, 0.00474162632599473, -0.0002681189507711679, 0.0018108837539330125, -0.010225837118923664, 0.006554673425853252, 0.0018158123129978776, 0.005187362432479858, 0.009987881407141685, -0.004314288031309843, 0.00015918801364023238, -0.00002927490095316898, 0.0034634622279554605, -0.0015671701403334737, 0.005742481444031, 0.00844250712543726, -0.003568204352632165, -0.004957865457981825, 0.004040544852614403, 0.005215772427618504, 0.010201330296695232, 0.0063553061336278915, -0.003043145639821887, 0.0022550467401742935, -0.00474571855738759, -0.001918644062243402, 0.006146537140011787, -0.005128062330186367, 0.005597315728664398, 0.004399654921144247, -0.01259167306125164, -0.008466208353638649, -0.0004397134471219033, -0.007790594361722469, 0.0012746787397190928, 0.01406956184655428, 0.011305782943964005, -0.002728536492213607, 0.003786872373893857, -0.009589753113687038, 0.00109022855758667, 0.006132069975137711, 0.002774635562673211, -0.013056815601885319, -0.9591531157493591, 0.004980720113962889, 0.0036748736165463924, -0.0022546551190316677, 0.005452124867588282, 0.002438354305922985, 0.0030776257626712322, 0.004495484754443169, 0.014314176514744759, -0.009449453093111515, -0.007134118117392063, -0.010458102449774742, -0.011461959220468998, -0.0013491591671481729, -0.006989362183958292, -0.002156870672479272, -0.006497780792415142, -0.007246721535921097, -0.0019082915969192982, -0.0031200482044368982, -0.0017448813887313008, 0.008158617652952671, -0.0009222684311680496, 0.004903539549559355, 0.0029095024801790714, 0.0037343779113143682, -0.004518579691648483, -0.0008719924953766167, -0.0039983526803553104, -0.002112857298925519, -0.007622101344168186, -0.0141347236931324, -0.0030142057221382856, -0.0019589161965996027, 0.010054604150354862, -0.00041605986189097166, 0.009572301059961319, -0.001436547376215458, 0.00008591383084421977, -0.008035480976104736, 0.005289587192237377, -0.0006357819656841457, 0.00453057000413537, -0.03154157102108002, -0.002015998587012291, -0.002469303784891963, -0.010049671865999699, 0.008318796753883362, 0.0012535921996459365, 0.00012439156125765294, -0.002588654635474086, -0.00679293368011713, 0.009005492553114891, -0.007593829184770584, 0.004463782534003258, -0.003416880266740918, -0.007881132885813713, -0.0020210975781083107, -0.009277284145355225, 0.0013338833814486861, 0.004605171736329794, -0.0035958290100097656, -0.005675320513546467, -0.004094649106264114, 0.0018951570382341743, 0.002191822975873947, 0.000761775067076087, -0.016700081527233124, -0.008843891322612762, 0.0011006610002368689, -0.0001623385032871738, -0.003245442872866988, -0.0030000172555446625, 0.005184127949178219, -0.009529145434498787, 0.007267821114510298, 0.0027582156471908092, 0.00032253228710033, -0.010998466983437538, 0.0005525278393179178, -0.0072330813854932785, -0.00909786019474268, 0.001986608374863863, -0.005198851227760315, -0.0053812796249985695, -0.00039024261059239507, 0.0004212115309201181, 0.007246030960232019, -0.004383602645248175, 0.004461039323359728, 0.01078678946942091, -0.0035227355547249317, -0.007955120876431465, 0.006224793381989002, 0.00658950861543417, 0.0002503643336240202, -0.0018807008164003491, 0.002588971983641386, 0.008239719085395336, 0.0076139504089951515, 0.0023591795470565557, 0.006568525917828083, -0.000497541157528758, 0.00808198656886816, -0.00028176201158203185, 0.000627203902695328, -0.0022069395054131746, -0.0007168835727497935, -0.0037401821464300156, -0.0035026553086936474, -0.0037323690485209227, -0.0033587985672056675, -0.013279309496283531, -0.009410695172846317, -0.003153011901304126, -0.0009401009883731604, 0.003354827407747507, -0.003702269634231925, -0.00011296460434095934, 0.0029366593807935715, 0.009108223021030426, -0.00013650275650434196, -0.001788739929907024, 0.00152502057608217, 0.003533255308866501, -0.006563075352460146, 0.012955627404153347, -0.011833867989480495, 0.005917704198509455, -0.00048192398389801383, -0.01471707783639431, 0.0078429551795125, 0.00916565116494894, -0.009097213856875896, 0.0021505116019397974, 0.0028577970806509256, 0.002744847908616066, -0.001258519827388227, -0.005254074465483427, -0.002468026475980878, -0.01588708534836769, 0.0004457852046471089, 0.020084325224161148, 0.0004068391863256693, 0.011188419535756111, 0.012220557779073715, -0.0032800743356347084, 0.0004203038988634944, 0.0063330866396427155, -0.0001974123588297516, 0.012767370790243149, -0.009472295641899109, -0.0004922547377645969, 0.0006828487385064363, -0.00642933277413249, 0.0008960120612755418, 0.00677865045145154, 0.005991073325276375, -0.0033563398756086826, 0.0028108167462050915, -0.007650705985724926, -0.0054723648354411125, -0.0176998320966959, -0.003661561058834195, 0.009484107606112957, -0.005640552844852209, 0.0065309228375554085, -0.011239546351134777, 0.005876481533050537, 0.007525848224759102, 0.0024685647804290056, -0.0006122285267338157, 0.0023809049744158983, 0.005103819537907839, 0.012062170542776585, -0.006424551364034414, 0.0029247968923300505, 0.002569465897977352, -0.0007886968087404966, 0.0006662903469987214, 0.008689122274518013, -0.006163152400404215, -0.005566688720136881, 0.002160330070182681, 0.0032314665149897337, 0.000630888098385185, -0.004400418605655432, -0.00978149101138115, -0.002304527908563614, 0.0045506395399570465, -0.005933115724474192, 0.003390261437743902, 0.0037280761171132326, 0.003104287199676037, -0.006600266322493553, -0.0009923928882926702, -0.0030953160021454096, -0.012060776352882385, 0.010946771129965782, -0.004795184824615717, 0.003184271976351738, 0.013082391582429409, 0.004774048924446106, -0.013475047424435616, 0.007157723885029554, 0.009977834299206734, -0.005017449147999287, 0.004841464571654797, 0.007234286516904831, -0.004826392512768507, -0.022886762395501137, -0.00266286195255816, -0.015431609936058521, 0.006370800547301769, -0.0026493812911212444, 0.002558130072429776, -0.005435145925730467, 0.006496436893939972, 0.006648448295891285, -0.014144259504973888, -0.0045761181972920895, -0.008765017613768578, 0.00957576371729374, -0.00037401271401904523, -0.0004705174651462585, -0.003151326673105359, -0.0014486045110970736, -0.0023190639913082123, -0.004591739736497402, -0.002033717231824994, 0.005364991724491119, 0.0017585941823199391, -0.0024533625692129135, 0.0024393065832555294, -0.005429740529507399, 0.0014413445023819804, 0.0013284656452015042, -0.011197561398148537, 0.002777199959382415, 0.00442367373034358, -0.0024639680050313473, -0.0034834337420761585, 0.0007440238259732723, -0.0026809426490217447, -0.006242035422474146, -0.010950664058327675, -0.005106619093567133, -0.0029518234077841043, -0.0030827783048152924, -0.011468512006103992, -0.0019059872720390558, -0.010262805968523026, 0.005093085579574108, -0.007298091892153025, 0.006545940414071083, 0.006321897264569998, -0.0034465696662664413, 0.007936367765069008, -0.0006108017987571657, 0.0043992456048727036, 0.0031879174057394266, 0.005072224419564009, 0.00045893946662545204, -0.005916869733482599, -0.010843359865248203, 0.013719896785914898, -0.008600638248026371, 0.0004680518468376249, 0.012973226606845856, 0.005874243099242449, 0.009834203869104385, -0.0006263351533561945, -0.00018190288392361253, 0.002259586937725544, 0.008061222732067108, -0.012907594442367554, 0.0035900454968214035, -0.0017845169641077518, -0.00020332683925516903, 0.005193497985601425, -0.0030028412584215403, 0.001172040356323123, 0.00957087054848671, 0.0005769612616859376, -0.007353176828473806, -0.0026808816473931074, 0.0023233131505548954, 0.004395823925733566, -0.013070649467408657, 0.00033265893580392003, -0.004560602828860283, -0.004188705701380968, -0.0018681916408240795, -0.0022800862789154053, -0.00010339025175198913, 0.005379344802349806, -0.0021879603154957294, 0.005450304597616196, 0.0037372310180217028, -0.006134756375104189, 0.015127932652831078, -0.0046381098218262196, -0.007458849810063839, 0.0015045994659885764, 0.003320699790492654, -0.0026010905858129263, -0.006809844169765711, -0.003738334635272622, 0.004086138214915991, 0.006607437506318092, -0.0017091365298256278, -0.0041906461119651794, -0.0028192480094730854, 0.0016507371328771114, -0.009124239906668663, 0.00171267194673419, 0.012062087655067444, -0.004552491474896669, 0.005261038895696402, -0.0020363156218081713, -0.007556953001767397, -0.013680640608072281, 0.05354545637965202, -0.0018787601729854941, 0.003269535955041647, 0.004644275177270174, -0.00820024311542511, 0.00024363638658542186, -0.002640047110617161, 0.0076157450675964355, -0.00814065895974636, -0.0074902488850057125, 0.00871823076158762, -0.0034752232022583485, 0.0029759129974991083, 0.00263435416854918, -0.0024019896518439054, 0.015362638048827648, -0.0033859533723443747, -0.015572885982692242, -0.015958433970808983, 0.007852226495742798, -0.0032197688706219196, -0.008215449750423431, 0.009866438806056976, -0.00307089788839221, -0.004877024330198765, 0.002584180561825633, 0.006529622711241245, 0.0017138514667749405, 0.0007477417238987982, -0.0028360651340335608, -0.002109096385538578, -0.0006365414592437446, 0.0021341745741665363, 0.006044155918061733, 0.005694628693163395, -0.00344075751490891, 0.004208107013255358, 0.0000824992821435444, -0.0022454021964222193, -0.0007803609478287399, 0.003283890662714839, 0.008988267742097378, -0.001560256932862103, -0.002019683364778757, 0.0053467215038836, 0.005770443938672543, 0.002727768151089549, 0.010843399912118912, 0.00009450417564949021, -0.0056705474853515625, 0.0073000467382371426, 0.006678103003650904, -0.0004123614344280213, 0.008483247831463814, -0.0015199611661955714, 0.005560609512031078, -0.0001846783416112885, -0.005604727193713188, -0.015548706986010075, -0.002221437869593501, 0.004391822498291731, 0.00898904912173748, -0.0016432420816272497, 0.0010903087677434087, -0.0017065496649593115, -0.00012587617675308138, -0.006317503750324249, -0.008741592057049274, -0.0027806609869003296, 0.0007410312537103891, 0.0012320003006607294, 0.07021725177764893, -0.006421057041734457, -0.0005786435795016587, -0.009723106399178505, -0.001596616581082344, -0.0021115229465067387, -0.0016259438125416636, 0.0006304316921159625, -0.0024670783895999193, 0.002280592918395996, 0.0012719283113256097, -0.008108671754598618, -0.011212840676307678, -0.00003262498648837209, 0.0008508345345035195, -0.0025292395148426294, 0.004510012920945883, 0.006839515175670385, -0.009364336729049683, 0.0015649227425456047, -0.011767224408686161, -0.0017030991148203611, -0.0034170986618846655, -0.009753936901688576, -0.004266341216862202, -0.003919094335287809, 0.00645916722714901, 0.003234948730096221, 0.005609686486423016, -0.0014329019468277693, 0.007189666386693716, -0.004056438338011503, -0.0012506432831287384, -0.005514424294233322, -0.0009627111721783876, -0.006890446413308382, 0.006540925242006779, 0.0023710373789072037, -0.008480834774672985, -0.003712038043886423, -0.001594568369910121, 0.00043820368591696024, -0.004576991777867079, 0.004200090654194355, 0.001281808246858418, 0.005903385113924742, -0.0025883622001856565, -0.00018003900186158717, -0.007325638085603714, 0.002311820862814784, -0.012182900682091713, 0.004243751522153616, -0.17173774540424347, 0.010620876215398312, 0.004680486861616373, -0.004981938283890486, -0.0036449595354497433, -0.013723701238632202, -0.006651079282164574, 0.003917516674846411, 0.009616479277610779, -0.0006087229703553021, -0.0013428557431325316, -0.003124036593362689, 0.0058060139417648315, 0.004425634164363146, -0.0008270800462923944, -0.005704921670258045, 0.0025253300555050373, -0.004290863871574402, -0.00010328889766242355, 0.004286951385438442, 0.004409698769450188, 0.00901978462934494, 0.0020517664961516857, -0.0012567356461659074, -0.0017947482410818338, -0.0061346618458628654, 0.00844486989080906, -0.003413696074858308, 0.005087263882160187, -0.009731700643897057, -0.0012890513753518462, -0.0059822238981723785, -0.005568798165768385, 0.0025584667455404997, 0.004678149241954088, -0.00022542108490597457, 0.008812036365270615, 0.004300759173929691, -0.009350649081170559, 0.007305368315428495, -0.0062907058745622635, 0.028264278545975685, 0.005848485976457596, 0.006768302526324987, 0.0003595075395423919, -0.006418049335479736, -0.0033667846582829952, 0.0085036251693964, 0.0025748135522007942, 0.01122624333947897, -0.013840948231518269, -0.002180436858907342, 0.0031555681489408016, 0.017862793058156967, -0.005788067821413279, -0.009652194567024708, -0.006837920285761356, -0.0019485859666019678, 0.003070297883823514, 0.008156589232385159, 0.012516885064542294, -0.003431028453633189, 0.0086063789203763, -0.003651951439678669, -0.01950153522193432, 0.002801811322569847, -0.004382108338177204, -0.00951658096164465, 0.0017729419050738215, 0.007875118404626846, 0.008259294554591179, 0.0014013529289513826, 0.0036351766902953386, -0.0007697245455347002, 0.005930266808718443, 0.0008735112496651709, 0.00521085923537612, -0.0029149234760552645, 0.0032059394288808107, -0.009832489304244518, 0.008250240236520767, -0.009911543689668179, -0.0036622837651520967, 0.0014132248470559716, -0.004551179241389036, 0.01203802227973938, 0.003921688534319401, -0.0005408297292888165, -0.0024181855842471123, -0.008271514438092709, -0.0033024640288203955, 0.0028817716520279646, 0.0008167196065187454, -0.010184361599385738, 0.002763541880995035, -0.0003635115281213075, 0.006704338360577822, 0.005938403308391571, -0.00836467370390892, 0.004744562320411205, 0.005494582466781139, -0.006195999216288328, 0.0026666852645576, -0.004538112320005894, 0.0019344721222296357, 0.004487375263124704, -0.004456402268260717, -0.0056414976716041565, 0.0029264490585774183, -0.00668445136398077, -0.006830198690295219, 0.0044267987832427025, -0.009090493433177471, -0.00999799370765686, -0.002642054343596101, -0.011098800227046013, 0.0013805226190015674 ]
76d2dd0a16c26b25219d0d5220bf5e490de12769
1,627
py
Python
run.py
Bioconductor/bioc_git_transition
9ca29f9e8058b755163e12bf9324ec1063d0182d
[ "MIT" ]
16
2017-03-15T18:00:35.000Z
2018-07-30T14:44:53.000Z
run.py
Bioconductor/bioc_git_transition
9ca29f9e8058b755163e12bf9324ec1063d0182d
[ "MIT" ]
40
2017-03-29T20:04:25.000Z
2019-10-21T16:56:15.000Z
run.py
Bioconductor/bioc_git_transition
9ca29f9e8058b755163e12bf9324ec1063d0182d
[ "MIT" ]
4
2017-05-08T11:39:07.000Z
2017-08-17T14:18:03.000Z
"""Bioconductor run git transition code. This module assembles the classes for the SVN --> Git transition can be run in a sequential manner. It runs the following aspects fo the Bioconductor transition. Note: Update the SVN dump 1. Run Bioconductor Software package transition 2. Run Bioconductor Experiment Data package transition 3. Run Workflow package transition 4. Run Manifest file transition 5. Run Rapid update of master (trunk) and RELEASE_3_5 branches on software packages Manual tasks which need to be done: 1. Copy over bare repos to repositories/packages 2. Copy manifest bare git repo to repositories/admin """ import src.run_transition as rt import src.svn_dump_update as sdu import logging import time logging.basicConfig(filename='transition.log', format='%(levelname)s %(asctime)s %(message)s', level=logging.DEBUG) def svn_dump_update(config_file): sdu.svn_root_update(config_file) sdu.svn_experiment_root_update(config_file) return def run(config_file): rt.run_software_transition(config_file, new_svn_dump=True) rt.run_experiment_data_transition(config_file, new_svn_dump=True) rt.run_workflow_transition(config_file, new_svn_dump=True) rt.run_manifest_transition(config_file, new_svn_dump=True) return if __name__ == '__main__': start_time = time.time() config_file = "./settings.ini" svn_dump_update(config_file) run(config_file) # TODO: Run updates after dump update svn_dump_update(config_file) rt.run_updates(config_file) logging.info("--- %s seconds ---" % (time.time() - start_time))
30.12963
69
0.754149
1
1.1586
[ 0.0012370421318337321, 0.022168580442667007, 0.007823937572538853, 0.0020993510261178017, 0.0042386301793158054, -0.0014290615217760205, -0.007642049342393875, 0.000954575662035495, -0.006782961543649435, 0.0021802661940455437, 0.003371683182194829, 0.004497017711400986, 0.005399308633059263, -0.016163567081093788, 0.0006749251624569297, 0.012160970829427242, -0.052779097110033035, 0.0018019683193415403, -0.0031581432558596134, 0.0028637584764510393, -0.007457584608346224, 0.009297456592321396, 0.00877609383314848, 0.0042725540697574615, 0.002870418131351471, -0.0027063689194619656, 0.009558969177305698, 0.00046756674419157207, -0.007187938317656517, -0.007013751193881035, -0.00017846416449174285, -0.0030770411249250174, -0.006074977107346058, -0.005033258814364672, 0.0038988448213785887, -0.003919918555766344, 0.00025634828489273787, -0.02001805789768696, 0.011731738224625587, -0.00626266049221158, -0.006810976192355156, -0.014268546365201473, -0.0014627043856307864, 0.00348308845423162, -0.008335067890584469, 0.0005745012313127518, -0.004026829265058041, 0.0033321643713861704, -0.011095881462097168, 0.00679307896643877, -0.007526782341301441, 0.005505535751581192, 0.016815947368741035, 0.002200008137151599, -0.0076768831349909306, -0.00654003256931901, 0.01277415081858635, 0.0005790075520053506, -0.00846272986382246, -0.00014375560567714274, -0.004627570975571871, -0.0041316207498312, 0.0063081542029976845, 0.0026145055890083313, -0.01515172328799963, -0.00606543617323041, -0.004378971643745899, 0.0011423358228057623, -0.002342246240004897, 0.0076380278915166855, 0.0013320533325895667, -0.00037793844239786267, 0.007583248894661665, 0.004288153722882271, 0.0033453814685344696, -0.005218069069087505, -0.001084720017388463, 0.0014146392932161689, 0.008184796199202538, 0.0031043526250869036, 0.004869863390922546, -0.006905090529471636, 0.006322053261101246, 0.00933146569877863, 0.014466771855950356, 0.00661529041826725, 0.020870214328169823, -0.008405015803873539, 0.0452420637011528, 0.007029172498732805, -0.008618704974651337, 0.003907249309122562, -0.009868337772786617, -0.0029848155099898577, -0.005902639124542475, -0.02829507738351822, -0.0002983346057590097, -0.0030073104426264763, -0.0023472716566175222, 0.00436344975605607, 0.0011873836629092693, 0.006368969101458788, -0.0017126642633229494, -0.00271000643260777, -0.008831416256725788, 0.00930491928011179, -0.008550556376576424, -0.0026690782979130745, 0.005176601465791464, 0.0019259833497926593, -0.012828731909394264, -0.0018090818775817752, 0.0032667196355760098, -0.014052962884306908, 0.00293609662912786, 0.004337965045124292, -0.005502371117472649, 0.05205928534269333, -0.0032233851961791515, 0.0034472132101655006, -0.0021381890401244164, 0.005240376573055983, 0.0003432162047829479, 0.005261204205453396, 0.010742126032710075, -0.003718022257089615, 0.015998980030417442, 0.007273900788277388, 0.003095688298344612, 0.007398224901407957, -0.004042360931634903, 0.0052488213405013084, -0.0038667256012558937, -0.0030782599933445454, 0.0005344091332517564, -0.005740465130656958, 0.006629763636738062, -0.0028044770006090403, -0.0093157347291708, 0.002868223236873746, 0.0005033484776504338, -0.009415281936526299, 0.0009854332311078906, -0.003241767641156912, 0.005903450306504965, -0.008418560959398746, -0.005421735811978579, -0.003463798202574253, -0.006034001242369413, 0.0022548288106918335, 0.00858237687498331, 0.0028962723445147276, 0.0033380223903805017, -0.0034179447684437037, -0.00725459074601531, 0.0004278952837921679, -0.0038085137493908405, 0.002407550346106291, 0.006330755073577166, 0.005601693410426378, -0.011628340929746628, 0.0007905568927526474, 0.00420418893918395, 0.0030846756417304277, -0.0007229246548376977, 0.003465372836217284, -0.008270609192550182, 0.007807631976902485, 0.001381114823743701, 0.0025963543448597193, 0.013142564333975315, -0.0028799360152333975, -0.0006618403713218868, 0.0010496660834178329, 0.0029145546723157167, 0.0003858200798276812, 0.00578072527423501, 0.011358351446688175, -0.001356458174996078, -0.00509896082803607, 0.002973956987261772, 0.007028587628155947, 0.007241618819534779, 0.005685781594365835, -0.005373154766857624, 0.0030121158342808485, -0.004044964909553528, -0.002251726808026433, 0.007440897170454264, -0.0034454192500561476, 0.0060483370907604694, 0.004290648736059666, -0.01308506727218628, -0.008303320966660976, -0.0002289962285431102, -0.00820154882967472, 0.0005025577847845852, 0.012636932544410229, 0.01029845792800188, -0.002095569623634219, 0.004875232465565205, -0.011544620618224144, 0.00028029963141307235, 0.009247040376067162, 0.0035700909793376923, -0.012381422333419323, -0.9606714844703674, 0.0053917961195111275, 0.0036222662311047316, -0.0022313736844807863, 0.006444522179663181, 0.0027626128867268562, 0.004347523674368858, 0.004895887337625027, 0.014723315834999084, -0.007915806956589222, -0.005488057620823383, -0.009199296124279499, -0.010713608004152775, -0.0008906195289455354, -0.006362718064337969, -0.0024861383717507124, -0.00707963015884161, -0.004462596029043198, -0.0033973711542785168, -0.00241623492911458, -0.0018187247915193439, 0.00725206732749939, -0.0002436301001580432, 0.004322572145611048, -0.0006324769929051399, 0.002410889370366931, -0.005618202965706587, -0.0032693056855350733, -0.0016623385017737746, -0.004434327594935894, -0.0036580990999937057, -0.015074511989951134, -0.0012948708608746529, -0.0020019777584820986, 0.009046384133398533, 0.0032834832090884447, 0.007959607988595963, -0.0037950314581394196, 0.0011286280350759625, -0.009189424104988575, 0.005121027585119009, 0.00012012996012344956, 0.0011919388780370355, -0.030476611107587814, 0.00022057723253965378, 0.001251107663847506, -0.0077230860479176044, 0.006011364981532097, -0.0005513086216524243, 0.0007574893534183502, -0.003926459234207869, -0.006983641069382429, 0.00937087181955576, -0.007849695160984993, 0.003853514092043042, -0.003924827557057142, -0.008703853003680706, -0.0016445585060864687, -0.008042438887059689, 0.002201599068939686, 0.003791698021814227, -0.0022107644472271204, -0.004724763799458742, -0.00378833687864244, 0.0008251902763731778, 0.0043065352365374565, 0.00003296860813861713, -0.017689255997538567, -0.0054884362034499645, 0.00014442065730690956, 0.0016602585092186928, -0.0034445312339812517, -0.0012299591908231378, 0.0033338500652462244, -0.009552160277962685, 0.006936739198863506, 0.0020541336853057146, -0.00278731482103467, -0.010564175434410572, -0.0022421986795961857, -0.00789865292608738, -0.007078250404447317, 0.0011389651335775852, -0.00471985200420022, -0.004747889470309019, -0.002662552520632744, 0.0004547153948806226, 0.008098499849438667, -0.002348418813198805, 0.004927796311676502, 0.01328167226165533, -0.002012489829212427, -0.008667760528624058, 0.005531348753720522, 0.007555108983069658, 0.000924757681787014, -0.0018999380990862846, 0.001944153686054051, 0.007854846306145191, 0.0067720613442361355, 0.0018434792291373014, 0.008436504751443863, 0.0003798613033723086, 0.010107326321303844, -0.00036263279616832733, -0.0003293960471637547, -0.005415379069745541, -0.0016626347787678242, -0.0031483438797295094, -0.0008680900209583342, -0.007228812202811241, -0.0033466822933405638, -0.013781963847577572, -0.00912833958864212, -0.0012089910451322794, -0.0005794716416858137, 0.0035221558064222336, -0.0027589555829763412, -0.0019519519992172718, 0.0027604778297245502, 0.007065376732498407, 0.0008621825836598873, -0.002155260881409049, -0.0021367049776017666, 0.0024721487425267696, -0.004998527932912111, 0.015507780946791172, -0.011051954701542854, 0.007059100084006786, -0.00007147538417484611, -0.015108782798051834, 0.00681276386603713, 0.012010615319013596, -0.006677195895463228, 0.0029513989575207233, 0.003627466270700097, 0.0019743575248867273, -0.0026384589727967978, -0.005143755581229925, -0.003054181346669793, -0.014576326124370098, 0.001861349563114345, 0.019302915781736374, -0.0019803589675575495, 0.009370416402816772, 0.01059911958873272, -0.0007896130555309355, 0.0007298855925910175, 0.007105516269803047, 0.0007742556044831872, 0.011513370089232922, -0.008126241154968739, -0.0017044648993760347, 0.002337654586881399, -0.00887936633080244, 0.0012600282207131386, 0.0075777447782456875, 0.005484180990606546, -0.003263953374698758, 0.0036106719635427, -0.006047834642231464, -0.007049934938549995, -0.01872607134282589, -0.005021295975893736, 0.008358918130397797, -0.005160911474376917, 0.005938068497925997, -0.013467074371874332, 0.0033546541817486286, 0.0030932030640542507, 0.006931419484317303, -0.0011968653416261077, 0.0012849931372329593, 0.006672430317848921, 0.009640926495194435, -0.005955141969025135, 0.0030536088161170483, 0.002614951226860285, -0.0027600943576544523, -0.0016909143887460232, 0.006116928532719612, -0.008213958702981472, -0.004566060844808817, 0.003026322927325964, 0.004417068790644407, 0.0009214879246428609, -0.0018019124399870634, -0.008069044910371304, -0.003905142191797495, 0.004106871318072081, -0.005075543187558651, 0.0028887472581118345, 0.003330864943563938, 0.003409641794860363, -0.006013243924826384, -0.0014050963800400496, -0.003551970701664686, -0.013761681504547596, 0.009942250326275826, -0.0007455949671566486, 0.0028331901412457228, 0.011249501258134842, 0.004251156933605671, -0.013598382472991943, 0.005478952545672655, 0.009596375748515129, -0.002970521803945303, 0.002853397047147155, 0.0050965482369065285, -0.0052108257077634335, -0.021078040823340416, -0.003918095026165247, -0.012304449453949928, 0.005213315133005381, -0.003943460062146187, 0.0036570762749761343, -0.007379509974271059, 0.00879503134638071, 0.006661267951130867, -0.013679399155080318, -0.0059539698995649815, -0.007904266007244587, 0.007975956425070763, -0.0014350215205922723, 0.0002472690539434552, -0.002861224813386798, -0.0008951191557571292, -0.000964836566708982, -0.00413080770522356, -0.0036282928194850683, 0.003963600378483534, 0.0018976581050083041, -0.0027577998116612434, 0.0018199123442173004, -0.003987771924585104, 0.0006754038040526211, 0.0008211328531615436, -0.010101476684212685, 0.0023899551015347242, 0.0035352117847651243, -0.0017476113280281425, -0.0013860762119293213, 0.0007955650798976421, -0.0027729596477001905, -0.009208313189446926, -0.011057021096348763, -0.004643235355615616, -0.003373535582795739, -0.003929881379008293, -0.011267385445535183, -0.0020834251772612333, -0.0054497565142810345, 0.006275778170675039, -0.007591015659272671, 0.008115843869745731, 0.006002517882734537, -0.00448317127302289, 0.006798821501433849, -0.0016399413580074906, 0.004129678942263126, 0.002483480842784047, 0.003323699114844203, 0.0017872905591502786, -0.005664586555212736, -0.013652068562805653, 0.01153377816081047, -0.007733927108347416, 0.0015119339805096388, 0.011002953164279461, 0.004387362860143185, 0.010259617120027542, -0.0022460410837084055, -0.00022311080829240382, 0.0003613097360357642, 0.007125224452465773, -0.01577032543718815, 0.0026404988020658493, -0.004291127435863018, -0.00020790375128854066, 0.0035883330274373293, -0.0037881196476519108, 0.0008976042736321688, 0.009065395221114159, 0.0022553123999387026, -0.006052068900316954, -0.003037758870050311, 0.0011654227273538709, 0.0019289377378299832, -0.012637847103178501, 0.0008568510529585183, -0.0015696416376158595, -0.0052460236474871635, -0.0031703184358775616, -0.0018331962637603283, 0.00111951248254627, 0.0039124079048633575, -0.000465833320049569, 0.006292940117418766, 0.0027568216901272535, -0.006338315550237894, 0.01670209877192974, -0.0035449201241135597, -0.004710362758487463, 0.0036436491645872593, 0.0020054953638464212, -0.0018724332330748439, -0.005319659598171711, -0.002587756607681513, 0.0030175545252859592, 0.004787061363458633, -0.003812030190601945, -0.0043694511987268925, -0.00023792839783709496, 0.00011273154086666182, -0.012627779506146908, -0.0005967511096969247, 0.012270882725715637, -0.0026576989330351353, 0.005913636647164822, -0.00021751133317593485, -0.00820743665099144, -0.014752237126231194, 0.0509905107319355, 0.0012526224600151181, 0.003386755008250475, 0.004072972573339939, -0.0068890745751559734, -0.0010251094354316592, -0.0005731165292672813, 0.007118214853107929, -0.007924281060695648, -0.00587415462359786, 0.007607492618262768, -0.0023832109291106462, 0.0032540892716497183, 0.002328149974346161, -0.002922765212133527, 0.015062510967254639, -0.001608416554518044, -0.015881221741437912, -0.017779720947146416, 0.0061470018699765205, -0.004628912545740604, -0.006079497747123241, 0.009609757922589779, -0.004263344686478376, -0.003425340633839369, 0.002167990431189537, 0.0031625155825167894, 0.002521710703149438, 0.00042309038690291345, -0.002114064758643508, -0.003232031362131238, -0.0022405770141631365, 0.003883043769747019, 0.004370125010609627, 0.008585062809288502, -0.0027668760158121586, 0.003404296236112714, -0.0011048406595364213, -0.0012744446285068989, -0.0028339512646198273, 0.005130731035023928, 0.0064934538677334785, -0.0012614596635103226, -0.005046189296990633, 0.006276425905525684, 0.005217151716351509, 0.0017614569514989853, 0.011401761323213577, -0.0020995091181248426, -0.0076828887686133385, 0.005717942491173744, 0.007601465098559856, 0.0003684359835460782, 0.008166220039129257, -0.00040813902160152793, 0.006704586558043957, 0.0019223210401833057, -0.00874405074864626, -0.015644172206521034, -0.003867067862302065, 0.006685253232717514, 0.00824377965182066, -0.0011365936370566487, 0.0016350578516721725, -0.0018480336293578148, -0.005159654654562473, -0.009169158525764942, -0.009806678630411625, -0.004147719591856003, 0.0029087597504258156, 0.004745428916066885, 0.06902319937944412, -0.006481376942247152, -0.0005025682621635497, -0.008307773619890213, -0.002223801566287875, -0.0015172174898907542, 0.0024276527110487223, 0.0020695615094155073, -0.002497355919331312, 0.002954878844320774, 0.0001623473217478022, -0.005738694220781326, -0.010180874727666378, -0.000327069079503417, 0.0028443587943911552, -0.0032513521146029234, 0.0016539567150175571, 0.007300919853150845, -0.008816816844046116, 0.0007161957328207791, -0.011105330660939217, -0.001543125370517373, -0.0018164446810260415, -0.010210463777184486, -0.001781259081326425, -0.003437013365328312, 0.005336318165063858, 0.004880196414887905, 0.005985106807202101, -0.0011900461977347732, 0.006302610971033573, 0.00037061935290694237, -0.001115312217734754, -0.0066935038194060326, -0.0003802217252086848, -0.003987070173025131, 0.008097750134766102, -0.000016086079995147884, -0.011482602916657925, -0.006547236815094948, -0.001379331573843956, 0.0011173676466569304, -0.006174652837216854, 0.004955750424414873, 0.000553836754988879, 0.0023801405914127827, -0.004494997672736645, -0.0010048012482002378, -0.007494982331991196, 0.0032629508059471846, -0.012259310111403465, 0.01047242060303688, -0.1662406325340271, 0.009939121082425117, 0.0042352392338216305, -0.005634821951389313, -0.0026696454733610153, -0.018361127004027367, -0.004498091991990805, 0.004645423498004675, 0.011475170962512493, 0.0012423924636095762, -0.0025784175377339125, 0.0009465722250752151, 0.0037795440293848515, 0.003666900098323822, -0.0021872294601053, -0.007549705449491739, 0.003237541764974594, -0.006008847616612911, -0.001423226553015411, 0.004829650744795799, 0.0026779950130730867, 0.010808215476572514, 0.0017473857151344419, 0.001629528822377324, -0.0014157487312331796, -0.0036591787356883287, 0.007967876270413399, -0.000746816978789866, 0.004743147175759077, -0.012066274881362915, -0.0035412092693150043, -0.004295387305319309, -0.003625113982707262, -0.0004101710510440171, 0.007219071965664625, -0.00029772359994240105, 0.009653521701693535, 0.0020293863490223885, -0.006674647331237793, 0.008964487351477146, -0.005218020640313625, 0.027856534346938133, 0.004312654957175255, 0.005265320651233196, -0.0008591749938204885, -0.006817412097007036, -0.005265699699521065, 0.008688187226653099, -0.00016881090414244682, 0.010967851616442204, -0.013221020810306072, 0.000044058597268303856, 0.005617684219032526, 0.01974843069911003, -0.00515753822401166, -0.009648781269788742, -0.005822471342980862, -0.0013474192237481475, 0.0008553371881134808, 0.006993177812546492, 0.010429196059703827, -0.0032848448026925325, 0.006656729616224766, -0.0036884720902889967, -0.018648836761713028, 0.0027157235890626907, -0.0040718321688473225, -0.005383405368775129, 0.0012321871472522616, 0.008243509568274021, 0.009098367765545845, 0.00126535480376333, 0.004502668045461178, -0.0015770061872899532, 0.0056076496839523315, -0.000738586182706058, 0.007854715920984745, -0.00004577338040689938, 0.00770998140797019, -0.007720689754933119, 0.0078889736905694, -0.010304996743798256, -0.0011678593000397086, 0.0030073977541178465, -0.00554612698033452, 0.011036201380193233, 0.004372449591755867, -0.0026398238260298967, -0.0014177703997120261, -0.009538126178085804, -0.002876690123230219, 0.0025202075485140085, 0.001995051046833396, -0.008634052239358425, 0.003644675714895129, 0.0013659875839948654, 0.006312658544629812, 0.007113718427717686, -0.010804842226207256, 0.007106962148100138, 0.006088992580771446, -0.005792208015918732, -0.00020486241555772722, -0.006209717132151127, 0.0026674927212297916, 0.003803734667599201, -0.006393151823431253, -0.006843595765531063, 0.004696482792496681, -0.006219586357474327, -0.0032184498850256205, 0.005782575346529484, -0.008881393820047379, -0.008113719522953033, -0.001145155867561698, -0.008243321441113949, -0.00009574539581080899 ]
76d39eed393350171c588f61022e00d384bb01c9
53,515
py
Python
third_party/google-endpoints/dogpile/cache/region.py
tingshao/catapult
a8fe19e0c492472a8ed5710be9077e24cc517c5c
[ "BSD-3-Clause" ]
2,151
2020-04-18T07:31:17.000Z
2022-03-31T08:39:18.000Z
third_party/google-endpoints/dogpile/cache/region.py
tingshao/catapult
a8fe19e0c492472a8ed5710be9077e24cc517c5c
[ "BSD-3-Clause" ]
4,640
2015-07-08T16:19:08.000Z
2019-12-02T15:01:27.000Z
third_party/google-endpoints/dogpile/cache/region.py
tingshao/catapult
a8fe19e0c492472a8ed5710be9077e24cc517c5c
[ "BSD-3-Clause" ]
698
2015-06-02T19:18:35.000Z
2022-03-29T16:57:15.000Z
from __future__ import with_statement from .. import Lock, NeedRegenerationException from ..util import NameRegistry from . import exception from ..util import PluginLoader, memoized_property, coerce_string_conf from .util import function_key_generator, function_multi_key_generator from .api import NO_VALUE, CachedValue from .proxy import ProxyBackend from ..util import compat import time import datetime from numbers import Number from functools import wraps import threading _backend_loader = PluginLoader("dogpile.cache") register_backend = _backend_loader.register from . import backends # noqa value_version = 1 """An integer placed in the :class:`.CachedValue` so that new versions of dogpile.cache can detect cached values from a previous, backwards-incompatible version. """ class RegionInvalidationStrategy(object): """Region invalidation strategy interface Implement this interface and pass implementation instance to :meth:`.CacheRegion.configure` to override default region invalidation. Example:: class CustomInvalidationStrategy(RegionInvalidationStrategy): def __init__(self): self._soft_invalidated = None self._hard_invalidated = None def invalidate(self, hard=None): if hard: self._soft_invalidated = None self._hard_invalidated = time.time() else: self._soft_invalidated = time.time() self._hard_invalidated = None def is_invalidated(self, timestamp): return ((self._soft_invalidated and timestamp < self._soft_invalidated) or (self._hard_invalidated and timestamp < self._hard_invalidated)) def was_hard_invalidated(self): return bool(self._hard_invalidated) def is_hard_invalidated(self, timestamp): return (self._hard_invalidated and timestamp < self._hard_invalidated) def was_soft_invalidated(self): return bool(self._soft_invalidated) def is_soft_invalidated(self, timestamp): return (self._soft_invalidated and timestamp < self._soft_invalidated) The custom implementation is injected into a :class:`.CacheRegion` at configure time using the :paramref:`.CacheRegion.configure.region_invalidator` parameter:: region = CacheRegion() region = region.configure(region_invalidator=CustomInvalidationStrategy()) Invalidation strategies that wish to have access to the :class:`.CacheRegion` itself should construct the invalidator given the region as an argument:: class MyInvalidator(RegionInvalidationStrategy): def __init__(self, region): self.region = region # ... # ... region = CacheRegion() region = region.configure(region_invalidator=MyInvalidator(region)) .. versionadded:: 0.6.2 .. seealso:: :paramref:`.CacheRegion.configure.region_invalidator` """ def invalidate(self, hard=True): """Region invalidation. :class:`.CacheRegion` propagated call. The default invalidation system works by setting a current timestamp (using ``time.time()``) to consider all older timestamps effectively invalidated. """ raise NotImplementedError() def is_hard_invalidated(self, timestamp): """Check timestamp to determine if it was hard invalidated. :return: Boolean. True if ``timestamp`` is older than the last region invalidation time and region is invalidated in hard mode. """ raise NotImplementedError() def is_soft_invalidated(self, timestamp): """Check timestamp to determine if it was soft invalidated. :return: Boolean. True if ``timestamp`` is older than the last region invalidation time and region is invalidated in soft mode. """ raise NotImplementedError() def is_invalidated(self, timestamp): """Check timestamp to determine if it was invalidated. :return: Boolean. True if ``timestamp`` is older than the last region invalidation time. """ raise NotImplementedError() def was_soft_invalidated(self): """Indicate the region was invalidated in soft mode. :return: Boolean. True if region was invalidated in soft mode. """ raise NotImplementedError() def was_hard_invalidated(self): """Indicate the region was invalidated in hard mode. :return: Boolean. True if region was invalidated in hard mode. """ raise NotImplementedError() class DefaultInvalidationStrategy(RegionInvalidationStrategy): def __init__(self): self._is_hard_invalidated = None self._invalidated = None def invalidate(self, hard=True): self._is_hard_invalidated = bool(hard) self._invalidated = time.time() def is_invalidated(self, timestamp): return (self._invalidated is not None and timestamp < self._invalidated) def was_hard_invalidated(self): return self._is_hard_invalidated is True def is_hard_invalidated(self, timestamp): return self.was_hard_invalidated() and self.is_invalidated(timestamp) def was_soft_invalidated(self): return self._is_hard_invalidated is False def is_soft_invalidated(self, timestamp): return self.was_soft_invalidated() and self.is_invalidated(timestamp) class CacheRegion(object): """A front end to a particular cache backend. :param name: Optional, a string name for the region. This isn't used internally but can be accessed via the ``.name`` parameter, helpful for configuring a region from a config file. :param function_key_generator: Optional. A function that will produce a "cache key" given a data creation function and arguments, when using the :meth:`.CacheRegion.cache_on_arguments` method. The structure of this function should be two levels: given the data creation function, return a new function that generates the key based on the given arguments. Such as:: def my_key_generator(namespace, fn, **kw): fname = fn.__name__ def generate_key(*arg): return namespace + "_" + fname + "_".join(str(s) for s in arg) return generate_key region = make_region( function_key_generator = my_key_generator ).configure( "dogpile.cache.dbm", expiration_time=300, arguments={ "filename":"file.dbm" } ) The ``namespace`` is that passed to :meth:`.CacheRegion.cache_on_arguments`. It's not consulted outside this function, so in fact can be of any form. For example, it can be passed as a tuple, used to specify arguments to pluck from \**kw:: def my_key_generator(namespace, fn): def generate_key(*arg, **kw): return ":".join( [kw[k] for k in namespace] + [str(x) for x in arg] ) return generate_key Where the decorator might be used as:: @my_region.cache_on_arguments(namespace=('x', 'y')) def my_function(a, b, **kw): return my_data() .. seealso:: :func:`.function_key_generator` - default key generator :func:`.kwarg_function_key_generator` - optional gen that also uses keyword arguments :param function_multi_key_generator: Optional. Similar to ``function_key_generator`` parameter, but it's used in :meth:`.CacheRegion.cache_multi_on_arguments`. Generated function should return list of keys. For example:: def my_multi_key_generator(namespace, fn, **kw): namespace = fn.__name__ + (namespace or '') def generate_keys(*args): return [namespace + ':' + str(a) for a in args] return generate_keys :param key_mangler: Function which will be used on all incoming keys before passing to the backend. Defaults to ``None``, in which case the key mangling function recommended by the cache backend will be used. A typical mangler is the SHA1 mangler found at :func:`.sha1_mangle_key` which coerces keys into a SHA1 hash, so that the string length is fixed. To disable all key mangling, set to ``False``. Another typical mangler is the built-in Python function ``str``, which can be used to convert non-string or Unicode keys to bytestrings, which is needed when using a backend such as bsddb or dbm under Python 2.x in conjunction with Unicode keys. :param async_creation_runner: A callable that, when specified, will be passed to and called by dogpile.lock when there is a stale value present in the cache. It will be passed the mutex and is responsible releasing that mutex when finished. This can be used to defer the computation of expensive creator functions to later points in the future by way of, for example, a background thread, a long-running queue, or a task manager system like Celery. For a specific example using async_creation_runner, new values can be created in a background thread like so:: import threading def async_creation_runner(cache, somekey, creator, mutex): ''' Used by dogpile.core:Lock when appropriate ''' def runner(): try: value = creator() cache.set(somekey, value) finally: mutex.release() thread = threading.Thread(target=runner) thread.start() region = make_region( async_creation_runner=async_creation_runner, ).configure( 'dogpile.cache.memcached', expiration_time=5, arguments={ 'url': '127.0.0.1:11211', 'distributed_lock': True, } ) Remember that the first request for a key with no associated value will always block; async_creator will not be invoked. However, subsequent requests for cached-but-expired values will still return promptly. They will be refreshed by whatever asynchronous means the provided async_creation_runner callable implements. By default the async_creation_runner is disabled and is set to ``None``. .. versionadded:: 0.4.2 added the async_creation_runner feature. """ def __init__( self, name=None, function_key_generator=function_key_generator, function_multi_key_generator=function_multi_key_generator, key_mangler=None, async_creation_runner=None, ): """Construct a new :class:`.CacheRegion`.""" self.name = name self.function_key_generator = function_key_generator self.function_multi_key_generator = function_multi_key_generator self.key_mangler = self._user_defined_key_mangler = key_mangler self.async_creation_runner = async_creation_runner self.region_invalidator = DefaultInvalidationStrategy() def configure( self, backend, expiration_time=None, arguments=None, _config_argument_dict=None, _config_prefix=None, wrap=None, replace_existing_backend=False, region_invalidator=None ): """Configure a :class:`.CacheRegion`. The :class:`.CacheRegion` itself is returned. :param backend: Required. This is the name of the :class:`.CacheBackend` to use, and is resolved by loading the class from the ``dogpile.cache`` entrypoint. :param expiration_time: Optional. The expiration time passed to the dogpile system. May be passed as an integer number of seconds, or as a ``datetime.timedelta`` value. .. versionadded 0.5.0 ``expiration_time`` may be optionally passed as a ``datetime.timedelta`` value. The :meth:`.CacheRegion.get_or_create` method as well as the :meth:`.CacheRegion.cache_on_arguments` decorator (though note: **not** the :meth:`.CacheRegion.get` method) will call upon the value creation function after this time period has passed since the last generation. :param arguments: Optional. The structure here is passed directly to the constructor of the :class:`.CacheBackend` in use, though is typically a dictionary. :param wrap: Optional. A list of :class:`.ProxyBackend` classes and/or instances, each of which will be applied in a chain to ultimately wrap the original backend, so that custom functionality augmentation can be applied. .. versionadded:: 0.5.0 .. seealso:: :ref:`changing_backend_behavior` :param replace_existing_backend: if True, the existing cache backend will be replaced. Without this flag, an exception is raised if a backend is already configured. .. versionadded:: 0.5.7 :param region_invalidator: Optional. Override default invalidation strategy with custom implementation of :class:`.RegionInvalidationStrategy`. .. versionadded:: 0.6.2 """ if "backend" in self.__dict__ and not replace_existing_backend: raise exception.RegionAlreadyConfigured( "This region is already " "configured with backend: %s. " "Specify replace_existing_backend=True to replace." % self.backend) backend_cls = _backend_loader.load(backend) if _config_argument_dict: self.backend = backend_cls.from_config_dict( _config_argument_dict, _config_prefix ) else: self.backend = backend_cls(arguments or {}) if not expiration_time or isinstance(expiration_time, Number): self.expiration_time = expiration_time elif isinstance(expiration_time, datetime.timedelta): self.expiration_time = int( compat.timedelta_total_seconds(expiration_time)) else: raise exception.ValidationError( 'expiration_time is not a number or timedelta.') if not self._user_defined_key_mangler: self.key_mangler = self.backend.key_mangler self._lock_registry = NameRegistry(self._create_mutex) if getattr(wrap, '__iter__', False): for wrapper in reversed(wrap): self.wrap(wrapper) if region_invalidator: self.region_invalidator = region_invalidator return self def wrap(self, proxy): ''' Takes a ProxyBackend instance or class and wraps the attached backend. ''' # if we were passed a type rather than an instance then # initialize it. if type(proxy) == type: proxy = proxy() if not issubclass(type(proxy), ProxyBackend): raise TypeError("Type %s is not a valid ProxyBackend" % type(proxy)) self.backend = proxy.wrap(self.backend) def _mutex(self, key): return self._lock_registry.get(key) class _LockWrapper(object): """weakref-capable wrapper for threading.Lock""" def __init__(self): self.lock = threading.Lock() def acquire(self, wait=True): return self.lock.acquire(wait) def release(self): self.lock.release() def _create_mutex(self, key): mutex = self.backend.get_mutex(key) if mutex is not None: return mutex else: return self._LockWrapper() def invalidate(self, hard=True): """Invalidate this :class:`.CacheRegion`. The default invalidation system works by setting a current timestamp (using ``time.time()``) representing the "minimum creation time" for a value. Any retrieved value whose creation time is prior to this timestamp is considered to be stale. It does not affect the data in the cache in any way, and is also local to this instance of :class:`.CacheRegion`. Once set, the invalidation time is honored by the :meth:`.CacheRegion.get_or_create`, :meth:`.CacheRegion.get_or_create_multi` and :meth:`.CacheRegion.get` methods. The method supports both "hard" and "soft" invalidation options. With "hard" invalidation, :meth:`.CacheRegion.get_or_create` will force an immediate regeneration of the value which all getters will wait for. With "soft" invalidation, subsequent getters will return the "old" value until the new one is available. Usage of "soft" invalidation requires that the region or the method is given a non-None expiration time. .. versionadded:: 0.3.0 :param hard: if True, cache values will all require immediate regeneration; dogpile logic won't be used. If False, the creation time of existing values will be pushed back before the expiration time so that a return+regen will be invoked. .. versionadded:: 0.5.1 """ self.region_invalidator.invalidate(hard) def configure_from_config(self, config_dict, prefix): """Configure from a configuration dictionary and a prefix. Example:: local_region = make_region() memcached_region = make_region() # regions are ready to use for function # decorators, but not yet for actual caching # later, when config is available myconfig = { "cache.local.backend":"dogpile.cache.dbm", "cache.local.arguments.filename":"/path/to/dbmfile.dbm", "cache.memcached.backend":"dogpile.cache.pylibmc", "cache.memcached.arguments.url":"127.0.0.1, 10.0.0.1", } local_region.configure_from_config(myconfig, "cache.local.") memcached_region.configure_from_config(myconfig, "cache.memcached.") """ config_dict = coerce_string_conf(config_dict) return self.configure( config_dict["%sbackend" % prefix], expiration_time=config_dict.get( "%sexpiration_time" % prefix, None), _config_argument_dict=config_dict, _config_prefix="%sarguments." % prefix, wrap=config_dict.get( "%swrap" % prefix, None), ) @memoized_property def backend(self): raise exception.RegionNotConfigured( "No backend is configured on this region.") @property def is_configured(self): """Return True if the backend has been configured via the :meth:`.CacheRegion.configure` method already. .. versionadded:: 0.5.1 """ return 'backend' in self.__dict__ def get(self, key, expiration_time=None, ignore_expiration=False): """Return a value from the cache, based on the given key. If the value is not present, the method returns the token ``NO_VALUE``. ``NO_VALUE`` evaluates to False, but is separate from ``None`` to distinguish between a cached value of ``None``. By default, the configured expiration time of the :class:`.CacheRegion`, or alternatively the expiration time supplied by the ``expiration_time`` argument, is tested against the creation time of the retrieved value versus the current time (as reported by ``time.time()``). If stale, the cached value is ignored and the ``NO_VALUE`` token is returned. Passing the flag ``ignore_expiration=True`` bypasses the expiration time check. .. versionchanged:: 0.3.0 :meth:`.CacheRegion.get` now checks the value's creation time against the expiration time, rather than returning the value unconditionally. The method also interprets the cached value in terms of the current "invalidation" time as set by the :meth:`.invalidate` method. If a value is present, but its creation time is older than the current invalidation time, the ``NO_VALUE`` token is returned. Passing the flag ``ignore_expiration=True`` bypasses the invalidation time check. .. versionadded:: 0.3.0 Support for the :meth:`.CacheRegion.invalidate` method. :param key: Key to be retrieved. While it's typical for a key to be a string, it is ultimately passed directly down to the cache backend, before being optionally processed by the key_mangler function, so can be of any type recognized by the backend or by the key_mangler function, if present. :param expiration_time: Optional expiration time value which will supersede that configured on the :class:`.CacheRegion` itself. .. versionadded:: 0.3.0 :param ignore_expiration: if ``True``, the value is returned from the cache if present, regardless of configured expiration times or whether or not :meth:`.invalidate` was called. .. versionadded:: 0.3.0 """ if self.key_mangler: key = self.key_mangler(key) value = self.backend.get(key) value = self._unexpired_value_fn( expiration_time, ignore_expiration)(value) return value.payload def _unexpired_value_fn(self, expiration_time, ignore_expiration): if ignore_expiration: return lambda value: value else: if expiration_time is None: expiration_time = self.expiration_time current_time = time.time() def value_fn(value): if value is NO_VALUE: return value elif expiration_time is not None and \ current_time - value.metadata["ct"] > expiration_time: return NO_VALUE elif self.region_invalidator.is_invalidated( value.metadata["ct"]): return NO_VALUE else: return value return value_fn def get_multi(self, keys, expiration_time=None, ignore_expiration=False): """Return multiple values from the cache, based on the given keys. Returns values as a list matching the keys given. E.g.:: values = region.get_multi(["one", "two", "three"]) To convert values to a dictionary, use ``zip()``:: keys = ["one", "two", "three"] values = region.get_multi(keys) dictionary = dict(zip(keys, values)) Keys which aren't present in the list are returned as the ``NO_VALUE`` token. ``NO_VALUE`` evaluates to False, but is separate from ``None`` to distinguish between a cached value of ``None``. By default, the configured expiration time of the :class:`.CacheRegion`, or alternatively the expiration time supplied by the ``expiration_time`` argument, is tested against the creation time of the retrieved value versus the current time (as reported by ``time.time()``). If stale, the cached value is ignored and the ``NO_VALUE`` token is returned. Passing the flag ``ignore_expiration=True`` bypasses the expiration time check. .. versionadded:: 0.5.0 """ if not keys: return [] if self.key_mangler: keys = list(map(lambda key: self.key_mangler(key), keys)) backend_values = self.backend.get_multi(keys) _unexpired_value_fn = self._unexpired_value_fn( expiration_time, ignore_expiration) return [ value.payload if value is not NO_VALUE else value for value in ( _unexpired_value_fn(value) for value in backend_values ) ] def get_or_create( self, key, creator, expiration_time=None, should_cache_fn=None): """Return a cached value based on the given key. If the value does not exist or is considered to be expired based on its creation time, the given creation function may or may not be used to recreate the value and persist the newly generated value in the cache. Whether or not the function is used depends on if the *dogpile lock* can be acquired or not. If it can't, it means a different thread or process is already running a creation function for this key against the cache. When the dogpile lock cannot be acquired, the method will block if no previous value is available, until the lock is released and a new value available. If a previous value is available, that value is returned immediately without blocking. If the :meth:`.invalidate` method has been called, and the retrieved value's timestamp is older than the invalidation timestamp, the value is unconditionally prevented from being returned. The method will attempt to acquire the dogpile lock to generate a new value, or will wait until the lock is released to return the new value. .. versionchanged:: 0.3.0 The value is unconditionally regenerated if the creation time is older than the last call to :meth:`.invalidate`. :param key: Key to be retrieved. While it's typical for a key to be a string, it is ultimately passed directly down to the cache backend, before being optionally processed by the key_mangler function, so can be of any type recognized by the backend or by the key_mangler function, if present. :param creator: function which creates a new value. :param expiration_time: optional expiration time which will overide the expiration time already configured on this :class:`.CacheRegion` if not None. To set no expiration, use the value -1. :param should_cache_fn: optional callable function which will receive the value returned by the "creator", and will then return True or False, indicating if the value should actually be cached or not. If it returns False, the value is still returned, but isn't cached. E.g.:: def dont_cache_none(value): return value is not None value = region.get_or_create("some key", create_value, should_cache_fn=dont_cache_none) Above, the function returns the value of create_value() if the cache is invalid, however if the return value is None, it won't be cached. .. versionadded:: 0.4.3 .. seealso:: :meth:`.CacheRegion.cache_on_arguments` - applies :meth:`.get_or_create` to any function using a decorator. :meth:`.CacheRegion.get_or_create_multi` - multiple key/value version """ orig_key = key if self.key_mangler: key = self.key_mangler(key) def get_value(): value = self.backend.get(key) if (value is NO_VALUE or value.metadata['v'] != value_version or self.region_invalidator.is_hard_invalidated( value.metadata["ct"])): raise NeedRegenerationException() ct = value.metadata["ct"] if self.region_invalidator.is_soft_invalidated(ct): ct = time.time() - expiration_time - .0001 return value.payload, ct def gen_value(): created_value = creator() value = self._value(created_value) if not should_cache_fn or \ should_cache_fn(created_value): self.backend.set(key, value) return value.payload, value.metadata["ct"] if expiration_time is None: expiration_time = self.expiration_time if (expiration_time is None and self.region_invalidator.was_soft_invalidated()): raise exception.DogpileCacheException( "Non-None expiration time required " "for soft invalidation") if expiration_time == -1: expiration_time = None if self.async_creation_runner: def async_creator(mutex): return self.async_creation_runner( self, orig_key, creator, mutex) else: async_creator = None with Lock( self._mutex(key), gen_value, get_value, expiration_time, async_creator) as value: return value def get_or_create_multi( self, keys, creator, expiration_time=None, should_cache_fn=None): """Return a sequence of cached values based on a sequence of keys. The behavior for generation of values based on keys corresponds to that of :meth:`.Region.get_or_create`, with the exception that the ``creator()`` function may be asked to generate any subset of the given keys. The list of keys to be generated is passed to ``creator()``, and ``creator()`` should return the generated values as a sequence corresponding to the order of the keys. The method uses the same approach as :meth:`.Region.get_multi` and :meth:`.Region.set_multi` to get and set values from the backend. If you are using a :class:`.CacheBackend` or :class:`.ProxyBackend` that modifies values, take note this function invokes ``.set_multi()`` for newly generated values using the same values it returns to the calling function. A correct implementation of ``.set_multi()`` will not modify values in-place on the submitted ``mapping`` dict. :param keys: Sequence of keys to be retrieved. :param creator: function which accepts a sequence of keys and returns a sequence of new values. :param expiration_time: optional expiration time which will overide the expiration time already configured on this :class:`.CacheRegion` if not None. To set no expiration, use the value -1. :param should_cache_fn: optional callable function which will receive each value returned by the "creator", and will then return True or False, indicating if the value should actually be cached or not. If it returns False, the value is still returned, but isn't cached. .. versionadded:: 0.5.0 .. seealso:: :meth:`.CacheRegion.cache_multi_on_arguments` :meth:`.CacheRegion.get_or_create` """ def get_value(key): value = values.get(key, NO_VALUE) if (value is NO_VALUE or value.metadata['v'] != value_version or self.region_invalidator.is_hard_invalidated( value.metadata['v'])): # dogpile.core understands a 0 here as # "the value is not available", e.g. # _has_value() will return False. return value.payload, 0 else: ct = value.metadata["ct"] if self.region_invalidator.is_soft_invalidated(ct): ct = time.time() - expiration_time - .0001 return value.payload, ct def gen_value(): raise NotImplementedError() def async_creator(key, mutex): mutexes[key] = mutex if expiration_time is None: expiration_time = self.expiration_time if (expiration_time is None and self.region_invalidator.was_soft_invalidated()): raise exception.DogpileCacheException( "Non-None expiration time required " "for soft invalidation") if expiration_time == -1: expiration_time = None mutexes = {} sorted_unique_keys = sorted(set(keys)) if self.key_mangler: mangled_keys = [self.key_mangler(k) for k in sorted_unique_keys] else: mangled_keys = sorted_unique_keys orig_to_mangled = dict(zip(sorted_unique_keys, mangled_keys)) values = dict(zip(mangled_keys, self.backend.get_multi(mangled_keys))) for orig_key, mangled_key in orig_to_mangled.items(): with Lock( self._mutex(mangled_key), gen_value, lambda: get_value(mangled_key), expiration_time, async_creator=lambda mutex: async_creator(orig_key, mutex) ): pass try: if mutexes: # sort the keys, the idea is to prevent deadlocks. # though haven't been able to simulate one anyway. keys_to_get = sorted(mutexes) new_values = creator(*keys_to_get) values_w_created = dict( (orig_to_mangled[k], self._value(v)) for k, v in zip(keys_to_get, new_values) ) if not should_cache_fn: self.backend.set_multi(values_w_created) else: self.backend.set_multi(dict( (k, v) for k, v in values_w_created.items() if should_cache_fn(v[0]) )) values.update(values_w_created) return [values[orig_to_mangled[k]].payload for k in keys] finally: for mutex in mutexes.values(): mutex.release() def _value(self, value): """Return a :class:`.CachedValue` given a value.""" return CachedValue( value, { "ct": time.time(), "v": value_version }) def set(self, key, value): """Place a new value in the cache under the given key.""" if self.key_mangler: key = self.key_mangler(key) self.backend.set(key, self._value(value)) def set_multi(self, mapping): """Place new values in the cache under the given keys. .. versionadded:: 0.5.0 """ if not mapping: return if self.key_mangler: mapping = dict(( self.key_mangler(k), self._value(v)) for k, v in mapping.items()) else: mapping = dict((k, self._value(v)) for k, v in mapping.items()) self.backend.set_multi(mapping) def delete(self, key): """Remove a value from the cache. This operation is idempotent (can be called multiple times, or on a non-existent key, safely) """ if self.key_mangler: key = self.key_mangler(key) self.backend.delete(key) def delete_multi(self, keys): """Remove multiple values from the cache. This operation is idempotent (can be called multiple times, or on a non-existent key, safely) .. versionadded:: 0.5.0 """ if self.key_mangler: keys = list(map(lambda key: self.key_mangler(key), keys)) self.backend.delete_multi(keys) def cache_on_arguments( self, namespace=None, expiration_time=None, should_cache_fn=None, to_str=compat.string_type, function_key_generator=None): """A function decorator that will cache the return value of the function using a key derived from the function itself and its arguments. The decorator internally makes use of the :meth:`.CacheRegion.get_or_create` method to access the cache and conditionally call the function. See that method for additional behavioral details. E.g.:: @someregion.cache_on_arguments() def generate_something(x, y): return somedatabase.query(x, y) The decorated function can then be called normally, where data will be pulled from the cache region unless a new value is needed:: result = generate_something(5, 6) The function is also given an attribute ``invalidate()``, which provides for invalidation of the value. Pass to ``invalidate()`` the same arguments you'd pass to the function itself to represent a particular value:: generate_something.invalidate(5, 6) Another attribute ``set()`` is added to provide extra caching possibilities relative to the function. This is a convenience method for :meth:`.CacheRegion.set` which will store a given value directly without calling the decorated function. The value to be cached is passed as the first argument, and the arguments which would normally be passed to the function should follow:: generate_something.set(3, 5, 6) The above example is equivalent to calling ``generate_something(5, 6)``, if the function were to produce the value ``3`` as the value to be cached. .. versionadded:: 0.4.1 Added ``set()`` method to decorated function. Similar to ``set()`` is ``refresh()``. This attribute will invoke the decorated function and populate a new value into the cache with the new value, as well as returning that value:: newvalue = generate_something.refresh(5, 6) .. versionadded:: 0.5.0 Added ``refresh()`` method to decorated function. Lastly, the ``get()`` method returns either the value cached for the given key, or the token ``NO_VALUE`` if no such key exists:: value = generate_something.get(5, 6) .. versionadded:: 0.5.3 Added ``get()`` method to decorated function. The default key generation will use the name of the function, the module name for the function, the arguments passed, as well as an optional "namespace" parameter in order to generate a cache key. Given a function ``one`` inside the module ``myapp.tools``:: @region.cache_on_arguments(namespace="foo") def one(a, b): return a + b Above, calling ``one(3, 4)`` will produce a cache key as follows:: myapp.tools:one|foo|3 4 The key generator will ignore an initial argument of ``self`` or ``cls``, making the decorator suitable (with caveats) for use with instance or class methods. Given the example:: class MyClass(object): @region.cache_on_arguments(namespace="foo") def one(self, a, b): return a + b The cache key above for ``MyClass().one(3, 4)`` will again produce the same cache key of ``myapp.tools:one|foo|3 4`` - the name ``self`` is skipped. The ``namespace`` parameter is optional, and is used normally to disambiguate two functions of the same name within the same module, as can occur when decorating instance or class methods as below:: class MyClass(object): @region.cache_on_arguments(namespace='MC') def somemethod(self, x, y): "" class MyOtherClass(object): @region.cache_on_arguments(namespace='MOC') def somemethod(self, x, y): "" Above, the ``namespace`` parameter disambiguates between ``somemethod`` on ``MyClass`` and ``MyOtherClass``. Python class declaration mechanics otherwise prevent the decorator from having awareness of the ``MyClass`` and ``MyOtherClass`` names, as the function is received by the decorator before it becomes an instance method. The function key generation can be entirely replaced on a per-region basis using the ``function_key_generator`` argument present on :func:`.make_region` and :class:`.CacheRegion`. If defaults to :func:`.function_key_generator`. :param namespace: optional string argument which will be established as part of the cache key. This may be needed to disambiguate functions of the same name within the same source file, such as those associated with classes - note that the decorator itself can't see the parent class on a function as the class is being declared. :param expiration_time: if not None, will override the normal expiration time. May be specified as a callable, taking no arguments, that returns a value to be used as the ``expiration_time``. This callable will be called whenever the decorated function itself is called, in caching or retrieving. Thus, this can be used to determine a *dynamic* expiration time for the cached function result. Example use cases include "cache the result until the end of the day, week or time period" and "cache until a certain date or time passes". .. versionchanged:: 0.5.0 ``expiration_time`` may be passed as a callable to :meth:`.CacheRegion.cache_on_arguments`. :param should_cache_fn: passed to :meth:`.CacheRegion.get_or_create`. .. versionadded:: 0.4.3 :param to_str: callable, will be called on each function argument in order to convert to a string. Defaults to ``str()``. If the function accepts non-ascii unicode arguments on Python 2.x, the ``unicode()`` builtin can be substituted, but note this will produce unicode cache keys which may require key mangling before reaching the cache. .. versionadded:: 0.5.0 :param function_key_generator: a function that will produce a "cache key". This function will supersede the one configured on the :class:`.CacheRegion` itself. .. versionadded:: 0.5.5 .. seealso:: :meth:`.CacheRegion.cache_multi_on_arguments` :meth:`.CacheRegion.get_or_create` """ expiration_time_is_callable = compat.callable(expiration_time) if function_key_generator is None: function_key_generator = self.function_key_generator def decorator(fn): if to_str is compat.string_type: # backwards compatible key_generator = function_key_generator(namespace, fn) else: key_generator = function_key_generator( namespace, fn, to_str=to_str) @wraps(fn) def decorate(*arg, **kw): key = key_generator(*arg, **kw) @wraps(fn) def creator(): return fn(*arg, **kw) timeout = expiration_time() if expiration_time_is_callable \ else expiration_time return self.get_or_create(key, creator, timeout, should_cache_fn) def invalidate(*arg, **kw): key = key_generator(*arg, **kw) self.delete(key) def set_(value, *arg, **kw): key = key_generator(*arg, **kw) self.set(key, value) def get(*arg, **kw): key = key_generator(*arg, **kw) return self.get(key) def refresh(*arg, **kw): key = key_generator(*arg, **kw) value = fn(*arg, **kw) self.set(key, value) return value decorate.set = set_ decorate.invalidate = invalidate decorate.refresh = refresh decorate.get = get decorate.original = fn return decorate return decorator def cache_multi_on_arguments( self, namespace=None, expiration_time=None, should_cache_fn=None, asdict=False, to_str=compat.string_type, function_multi_key_generator=None): """A function decorator that will cache multiple return values from the function using a sequence of keys derived from the function itself and the arguments passed to it. This method is the "multiple key" analogue to the :meth:`.CacheRegion.cache_on_arguments` method. Example:: @someregion.cache_multi_on_arguments() def generate_something(*keys): return [ somedatabase.query(key) for key in keys ] The decorated function can be called normally. The decorator will produce a list of cache keys using a mechanism similar to that of :meth:`.CacheRegion.cache_on_arguments`, combining the name of the function with the optional namespace and with the string form of each key. It will then consult the cache using the same mechanism as that of :meth:`.CacheRegion.get_multi` to retrieve all current values; the originally passed keys corresponding to those values which aren't generated or need regeneration will be assembled into a new argument list, and the decorated function is then called with that subset of arguments. The returned result is a list:: result = generate_something("key1", "key2", "key3") The decorator internally makes use of the :meth:`.CacheRegion.get_or_create_multi` method to access the cache and conditionally call the function. See that method for additional behavioral details. Unlike the :meth:`.CacheRegion.cache_on_arguments` method, :meth:`.CacheRegion.cache_multi_on_arguments` works only with a single function signature, one which takes a simple list of keys as arguments. Like :meth:`.CacheRegion.cache_on_arguments`, the decorated function is also provided with a ``set()`` method, which here accepts a mapping of keys and values to set in the cache:: generate_something.set({"k1": "value1", "k2": "value2", "k3": "value3"}) ...an ``invalidate()`` method, which has the effect of deleting the given sequence of keys using the same mechanism as that of :meth:`.CacheRegion.delete_multi`:: generate_something.invalidate("k1", "k2", "k3") ...a ``refresh()`` method, which will call the creation function, cache the new values, and return them:: values = generate_something.refresh("k1", "k2", "k3") ...and a ``get()`` method, which will return values based on the given arguments:: values = generate_something.get("k1", "k2", "k3") .. versionadded:: 0.5.3 Added ``get()`` method to decorated function. Parameters passed to :meth:`.CacheRegion.cache_multi_on_arguments` have the same meaning as those passed to :meth:`.CacheRegion.cache_on_arguments`. :param namespace: optional string argument which will be established as part of each cache key. :param expiration_time: if not None, will override the normal expiration time. May be passed as an integer or a callable. :param should_cache_fn: passed to :meth:`.CacheRegion.get_or_create_multi`. This function is given a value as returned by the creator, and only if it returns True will that value be placed in the cache. :param asdict: if ``True``, the decorated function should return its result as a dictionary of keys->values, and the final result of calling the decorated function will also be a dictionary. If left at its default value of ``False``, the decorated function should return its result as a list of values, and the final result of calling the decorated function will also be a list. When ``asdict==True`` if the dictionary returned by the decorated function is missing keys, those keys will not be cached. :param to_str: callable, will be called on each function argument in order to convert to a string. Defaults to ``str()``. If the function accepts non-ascii unicode arguments on Python 2.x, the ``unicode()`` builtin can be substituted, but note this will produce unicode cache keys which may require key mangling before reaching the cache. .. versionadded:: 0.5.0 :param function_multi_key_generator: a function that will produce a list of keys. This function will supersede the one configured on the :class:`.CacheRegion` itself. .. versionadded:: 0.5.5 .. seealso:: :meth:`.CacheRegion.cache_on_arguments` :meth:`.CacheRegion.get_or_create_multi` """ expiration_time_is_callable = compat.callable(expiration_time) if function_multi_key_generator is None: function_multi_key_generator = self.function_multi_key_generator def decorator(fn): key_generator = function_multi_key_generator( namespace, fn, to_str=to_str) @wraps(fn) def decorate(*arg, **kw): cache_keys = arg keys = key_generator(*arg, **kw) key_lookup = dict(zip(keys, cache_keys)) @wraps(fn) def creator(*keys_to_create): return fn(*[key_lookup[k] for k in keys_to_create]) timeout = expiration_time() if expiration_time_is_callable \ else expiration_time if asdict: def dict_create(*keys): d_values = creator(*keys) return [ d_values.get(key_lookup[k], NO_VALUE) for k in keys] def wrap_cache_fn(value): if value is NO_VALUE: return False elif not should_cache_fn: return True else: return should_cache_fn(value) result = self.get_or_create_multi( keys, dict_create, timeout, wrap_cache_fn) result = dict( (k, v) for k, v in zip(cache_keys, result) if v is not NO_VALUE) else: result = self.get_or_create_multi( keys, creator, timeout, should_cache_fn) return result def invalidate(*arg): keys = key_generator(*arg) self.delete_multi(keys) def set_(mapping): keys = list(mapping) gen_keys = key_generator(*keys) self.set_multi(dict( (gen_key, mapping[key]) for gen_key, key in zip(gen_keys, keys)) ) def get(*arg): keys = key_generator(*arg) return self.get_multi(keys) def refresh(*arg): keys = key_generator(*arg) values = fn(*arg) if asdict: self.set_multi( dict(zip(keys, [values[a] for a in arg])) ) return values else: self.set_multi( dict(zip(keys, values)) ) return values decorate.set = set_ decorate.invalidate = invalidate decorate.refresh = refresh decorate.get = get return decorate return decorator def make_region(*arg, **kw): """Instantiate a new :class:`.CacheRegion`. Currently, :func:`.make_region` is a passthrough to :class:`.CacheRegion`. See that class for constructor arguments. """ return CacheRegion(*arg, **kw)
36.429544
82
0.606652
1
1.8006
[ -0.042820096015930176, -0.010774893686175346, -0.002057955600321293, 0.016667470335960388, 0.015978850424289703, 0.03956206515431404, -0.006134497933089733, -0.011024853214621544, -0.004489921033382416, 0.02474266290664673, 0.007966462522745132, -0.007939026691019535, 0.03610142320394516, -0.008011363446712494, -0.05425984412431717, 0.008341259323060513, 0.059297770261764526, 0.04424654692411423, -0.03023573011159897, -0.0318802148103714, 0.007144595962017775, -0.020145095884799957, -0.006238732952624559, -0.002167708473280072, 0.02602805756032467, 0.03255303204059601, 0.04728766903281212, 0.030206862837076187, 0.053178973495960236, -0.002055551391094923, -0.01382683590054512, 0.011198986321687698, 0.029988562688231468, 0.015144742093980312, -0.005973913706839085, -0.014773801900446415, 0.0005586473271250725, -0.03866352140903473, -0.021880844607949257, 0.02548578940331936, -0.0005499198450706899, -0.03596660494804382, -0.023161165416240692, -0.036137137562036514, 0.05063984915614128, -0.0024691384751349688, -0.002826169366016984, 0.04489517584443092, -0.04906435310840607, -0.019150173291563988, -0.06681209802627563, 0.007675031665712595, -0.004758261609822512, -0.012863870710134506, -0.018414363265037537, -0.04788036644458771, 0.004840078763663769, 0.012217037379741669, -0.000711481727194041, -0.010752237401902676, 0.015546397306025028, -0.02689657174050808, -0.0054634977132081985, 0.01961269974708557, 0.03016170859336853, 0.018696706742048264, 0.008550992235541344, 0.018700184300541878, -0.021906020119786263, -0.02133549004793167, 0.009904936887323856, -0.0360742062330246, 0.032857496291399, 0.02639995701611042, 0.0485762283205986, 0.02173474058508873, -0.03311650827527046, 0.0071861837059259415, 0.018002036958932877, -0.0017526514129713178, 0.01599120907485485, 0.03455384448170662, -0.012653760612010956, -0.005860474891960621, -0.0147014781832695, 0.008426414802670479, 0.06808716803789139, -0.024682408198714256, 0.0502237044274807, 0.051733776926994324, -0.02765212021768093, 0.04342753067612648, -0.04295624792575836, 0.009334145113825798, -0.03015698865056038, -0.021579133346676826, 0.02184753306210041, 0.01239055022597313, -0.024219324812293053, 0.0319838710129261, 0.022032197564840317, -0.0011079207761213183, 0.013816531747579575, -0.014460263773798943, -0.016744013875722885, -0.01534045860171318, -0.0187637098133564, 0.013244622386991978, 0.0030429628677666187, -0.0005823893588967621, -0.03690018877387047, -0.04026574268937111, 0.021344011649489403, -0.011327016167342663, -0.0164295956492424, -0.0274625513702631, 0.019706737250089645, -0.027874905616044998, -0.01744345761835575, 0.003375009633600712, -0.0030977220740169287, 0.003979714587330818, 0.05782682076096535, -0.004740514792501926, -0.028207171708345413, 0.07129494845867157, 0.02473454736173153, 0.030048642307519913, 0.052159734070301056, 0.009734492748975754, 0.002766439225524664, -0.0066220625303685665, -0.002337951213121414, -0.02401510439813137, -0.0023286105133593082, 0.005589396692812443, -0.010734077543020248, 0.052580542862415314, -0.033172909170389175, 0.019209707155823708, 0.021602969616651535, -0.00458192965015769, 0.006247749086469412, -0.009172297082841396, 0.0017680875025689602, -0.04119975492358208, -0.0028236019425094128, -0.044228747487068176, -0.0017080564284697175, 0.007802396547049284, 0.009681105613708496, 0.0006540687172673643, 0.01856844685971737, 0.05623316764831543, -0.01818769983947277, -0.005462672561407089, -0.011978907510638237, -0.04876100644469261, 0.0009475832339376211, -0.008123314939439297, -0.042722392827272415, 0.011036972515285015, -0.023792820051312447, -0.004044096451252699, 0.009426658041775227, 0.022890355437994003, -0.000514843559358269, 0.02200007066130638, -0.022498875856399536, -0.003717220388352871, 0.029773734509944916, -0.01343769021332264, -0.0013777482090517879, 0.0010966730769723654, -0.020773975178599358, 0.011221623979508877, 0.010719497688114643, 0.010312358848750591, 0.044199854135513306, 0.014665492810308933, 0.006575233303010464, 0.002848015632480383, 0.07620224356651306, 0.0030591273680329323, -0.005615809932351112, 0.006385228596627712, -0.06314145773649216, -0.02936459146440029, -0.0029872723389416933, -0.020184841006994247, -0.004638011567294598, 0.00898059830069542, 0.02410426177084446, -0.030400482937693596, 0.024643737822771072, -0.021941041573882103, 0.006508566904813051, -0.020319629460573196, -0.030618060380220413, 0.01946842111647129, 0.0020177792757749557, -0.002217006403952837, -0.007961414754390717, 0.039793673902750015, 0.01431076880544424, -0.03210010379552841, -0.7244622111320496, -0.00820679310709238, -0.00308257550932467, 0.0005794324679300189, 0.004460548050701618, 0.018270712345838547, -0.02144083008170128, 0.015063725411891937, -0.009332511574029922, -0.0183968935161829, 0.0000934145282371901, 0.045847490429878235, -0.026958489790558815, -0.005412362050265074, 0.013658818788826466, -0.036278001964092255, 0.01395860780030489, -0.015874212607741356, 0.0005261413753032684, 0.02668214589357376, 0.007756638806313276, -0.02502092532813549, 0.009238393977284431, -0.02350018173456192, -0.00035847938852384686, 0.04389742389321327, 0.033650051802396774, -0.009249245747923851, -0.022038346156477928, -0.022687189280986786, -0.0018175753066316247, 0.003933718428015709, -0.013816353864967823, -0.037725258618593216, 0.02909253165125847, -0.00781561154872179, 0.010956301353871822, -0.0031612259335815907, 0.011957298964262009, 0.003785296343266964, -0.01727757416665554, -0.02921994775533676, 0.01287246122956276, -0.051423579454422, -0.028890175744891167, 0.01434847991913557, -0.05388004332780838, -0.030016308650374413, 0.0024566384963691235, -0.0021356239449232817, -0.032694052904844284, 0.0026802457869052887, 0.030483845621347427, -0.01323283463716507, 0.0004969285218976438, 0.024778347462415695, 0.007994508370757103, -0.021273713558912277, -0.01687488704919815, 0.0015891052316874266, 0.04423997178673744, 0.04029645025730133, -0.04032916575670242, 0.007488023489713669, 0.010395180433988571, -0.010955329984426498, 0.026991670951247215, 0.00714412285014987, -0.02879907377064228, -0.018103351816534996, -0.08391282707452774, 0.019879408180713654, -0.023230282589793205, 0.0854027271270752, -0.032672297209501266, -0.015579964965581894, -0.01057278923690319, 0.01358411181718111, -0.038335032761096954, 0.027804728597402573, 0.008302749134600163, -0.009147108532488346, -0.004543668124824762, -0.004624022636562586, -0.048003993928432465, 0.020496416836977005, -0.014947901479899883, -0.046765416860580444, -0.02346203103661537, 0.02803938277065754, -0.013917825184762478, 0.021795419976115227, 0.01909373328089714, -0.009859748184680939, 0.015769386664032936, -0.01719859428703785, 0.005296553950756788, 0.022806059569120407, 0.02963465265929699, 0.013797837309539318, -0.03469362109899521, -0.01296412292867899, -0.009689907543361187, 0.04394403472542763, 0.042519405484199524, 0.010325468145310879, -0.00016579875955358148, 0.015889275819063187, 0.015266832895576954, -0.01901700347661972, 0.006000670604407787, 0.02014629729092121, -0.02616591565310955, 0.05431900918483734, 0.004610143136233091, 0.0037233333569020033, -0.0013351452071219683, -0.034946784377098083, 0.014693141914904118, -0.004657243378460407, -0.0016194909112527966, 0.02038964070379734, 0.06899384409189224, 0.06607029587030411, 0.009387965314090252, 0.010288399644196033, -0.03562995418906212, -0.0211163442581892, -0.0015865322202444077, -0.005898861680179834, -0.006057665217667818, -0.016368983313441277, -0.028085701167583466, -0.027121372520923615, 0.012408586218953133, 0.025024360045790672, -0.00028377887792885303, -0.026079006493091583, -0.054520316421985626, -0.003647581208497286, -0.002949099987745285, 0.01130729727447033, -0.0053557828068733215, -0.04074189439415932, 0.05633598938584328, -0.01146291196346283, -0.0005680311005562544, 0.000106319464975968, 0.0461939312517643, -0.012187917716801167, -0.022142980247735977, 0.10647507011890411, 0.005348694510757923, 0.034688014537096024, -0.012339907698333263, 0.000334640295477584, -0.05583717301487923, 0.03799978643655777, 0.03376973420381546, 0.011361467652022839, -0.005885077174752951, 0.002735886024311185, -0.0168894212692976, 0.009119116701185703, 0.026535814628005028, 0.0005164428730495274, 0.05376962944865227, -0.010973412543535233, -0.01210153941065073, 0.029403377324342728, 0.023461898788809776, -0.006487756501883268, 0.008743911981582642, 0.009140359237790108, -0.013333850540220737, 0.022448329254984856, 0.0014712167903780937, -0.022595331072807312, 0.0009134200518019497, 0.0008350574062205851, 0.013309442438185215, -0.02462921477854252, -0.01727317087352276, 0.013774880208075047, -0.006422268692404032, -0.025518052279949188, -0.011359876953065395, -0.020532213151454926, 0.010692141950130463, -0.010242144577205181, 0.039558131247758865, 0.024806946516036987, -0.018437042832374573, 0.03316017985343933, -0.030601471662521362, -0.031116368249058723, -0.00015746922872494906, -0.013223695568740368, 0.0006184875383041799, 0.010145176202058792, 0.03182763606309891, 0.012798994779586792, 0.0072571574710309505, -0.041419800370931625, 0.05142273008823395, -0.004646519664674997, -0.02665102295577526, -0.01383883599191904, 0.004991896450519562, 0.0006141020567156374, 0.02424938790500164, -0.02125892974436283, -0.02526094578206539, 0.0057122716680169106, -0.02162214182317257, 0.04076779633760452, -0.01715061254799366, -0.003330542240291834, -0.04137362167239189, -0.022931864485144615, -0.024237358942627907, -0.01814817637205124, 0.0018809676403179765, -0.009874529205262661, 0.008434583432972431, 0.007971661165356636, -0.01626906916499138, -0.021331841126084328, -0.03622318431735039, 0.005401502829045057, 0.018436716869473457, -0.025664767250418663, 0.01793287694454193, -0.016317378729581833, -0.016415931284427643, -0.01741454191505909, -0.013780644163489342, -0.0449330173432827, -0.017429227009415627, -0.003879878669977188, -0.00705763092264533, -0.027908291667699814, -0.023597408086061478, -0.0008029156597331166, 0.027911050245165825, 0.0029248225037008524, 0.0018059052526950836, 0.006992229260504246, -0.02379918098449707, -0.0027445864398032427, -0.01461702398955822, 0.04153013974428177, -0.02819792926311493, -0.03708813712000847, 0.03341607749462128, -0.005079929251223803, -0.010651963762938976, -0.0023788975086063147, 0.021496903151273727, 0.015989119186997414, -0.005022282712161541, -0.04234670102596283, -0.024045780301094055, 0.02237125113606453, -0.03849644213914871, -0.016510315239429474, 0.028711561113595963, -0.04839511588215828, -0.024153878912329674, 0.027173493057489395, 0.009277251549065113, -0.022888777777552605, -0.019163500517606735, -0.019742583855986595, -0.014929050579667091, -0.02714899368584156, 0.009864123538136482, -0.026291344314813614, 0.0054138582199811935, -0.0010240995325148106, 0.0032343894708901644, 0.007394441869109869, 0.021609360352158546, 0.05205510929226875, -0.012344393879175186, 0.0016295957611873746, -0.0004052134754601866, -0.01893017813563347, -0.02980295941233635, -0.005685708485543728, 0.011845462955534458, -0.04455655440688133, 0.007599145174026489, 0.02195236273109913, -0.02617039903998375, 0.01819682866334915, -0.019594065845012665, -0.034366898238658905, 0.013014807365834713, 0.02281849831342697, 0.03510747477412224, 0.011388333514332771, -0.010586703196167946, -0.005378786940127611, 0.015032671391963959, 0.0143801374360919, 0.002258125226944685, 0.005089322570711374, 0.018939124420285225, -0.002098982920870185, -0.008018067106604576, 0.007456542924046516, 0.01236564852297306, 0.0307377390563488, -0.012090490199625492, 0.0161768589168787, 0.030336735770106316, 0.01474990975111723, 0.012894319370388985, -0.014047705568373203, -0.01820436678826809, 0.010053720325231552, -0.0221693217754364, -0.007544986438006163, 0.002426785882562399, 0.007779852487146854, -0.024247286841273308, 0.03372211381793022, 0.00035714966361410916, 0.04129005968570709, -0.013097263872623444, 0.01433071494102478, -0.004710210487246513, 0.016341187059879303, 0.01065966859459877, -0.03939663618803024, -0.021515455096960068, 0.050244685262441635, 0.04942290112376213, 0.02407880686223507, 0.011275778524577618, 0.04377439618110657, -0.03413749113678932, -0.0036231738049536943, 0.014734795317053795, 0.013158443383872509, -0.024252479895949364, 0.0066004553809762, -0.016316551715135574, 0.03286784887313843, 0.004984776023775339, -0.01361959520727396, 0.002200267044827342, -0.010468429885804653, 0.043828919529914856, -0.02076658234000206, -0.019381070509552956, -0.0004836775769945234, 0.010682701133191586, -0.04018975794315338, 0.01646418683230877, -0.014464149251580238, -0.008201478980481625, -0.008070681244134903, 0.005110448691993952, -0.022638672962784767, 0.004211451858282089, -0.046653784811496735, 0.01440037414431572, 0.003294489113613963, -0.023194247856736183, -0.005214091390371323, -0.008641711436212063, -0.00019251479534432292, 0.013690212741494179, 0.04769650101661682, 0.0484967939555645, 0.05220508202910423, -0.044594958424568176, -0.008983133360743523, -0.007438136264681816, -0.021843677386641502, -0.0442168153822422, -0.006193214096128941, 0.03186928480863571, -0.01034147571772337, 0.020822105929255486, -0.002055200980976224, 0.0235871821641922, 0.006455104798078537, -0.003103431314229965, 0.025637377053499222, -0.013158506713807583, 0.006860659923404455, -0.019533397629857063, -0.00622404832392931, -0.030548684298992157, -0.010392625816166401, -0.02301054447889328, -0.023391371592879295, 0.002888228977099061, 0.031607650220394135, 0.0016369754448533058, -0.016761653125286102, 0.031831033527851105, -0.022389274090528488, 0.032929904758930206, -0.0347561314702034, -0.002021297812461853, 0.038889188319444656, -0.00889583770185709, 0.02947321906685829, -0.017137285321950912, -0.03216756135225296, -0.026444951072335243, 0.009709679521620274, -0.03770916536450386, 0.010874754749238491, -0.003925088793039322, 0.01313785370439291, 0.01244544330984354, -0.04099893197417259, -0.0020987829193472862, 0.008945845998823643, -0.03022816590964794, -0.002896658843383193, -0.010662214830517769, -0.010721998289227486, 0.01153130829334259, 0.01769392192363739, -0.006826571188867092, -0.0037369043566286564, -0.014720875769853592, -0.01798773743212223, 0.005671309307217598, 0.029037591069936752, -0.006579067558050156, -0.006798747926950455, 0.0011021733516827226, 0.008421968668699265, -0.04826679080724716, 0.009038399904966354, -0.05017422139644623, 0.015207410790026188, -0.01927732490003109, -0.02116348408162594, -0.009292238391935825, 0.013312979601323605, 0.0007367514772340655, 0.015165405347943306, 0.023726550862193108, -0.014643754810094833, 0.0060224407352507114, 0.005695200990885496, -0.003467095782980323, 0.024124471470713615, 0.0046130879782140255, 0.01526840589940548, -0.014970687218010426, 0.0061372132040560246, 0.009988633915781975, 0.0010758626740425825, -0.01981624774634838, 0.008459768258035183, 0.04352021589875221, 0.028409482911229134, -0.02820025384426117, -0.01315262634307146, -0.029972322285175323, -0.009034511633217335, 0.02777787111699581, -0.001230868510901928, -0.0356283038854599, -0.0020720583852380514, 0.009405174292623997, -0.008447502739727497, 0.011671006679534912, 0.025103479623794556, 0.01757953129708767, -0.007272317074239254, -0.06556706875562668, 0.014663063921034336, 0.03748830407857895, 0.024056831374764442, 0.019478410482406616, 0.015415368601679802, -0.0077570280991494656, 0.044664837419986725, 0.006179929710924625, 0.013369639404118061, -0.013829112984240055, 0.008455313742160797, -0.019088558852672577, 0.01690349541604519, -0.009183970279991627, -0.019569698721170425, 0.015525612980127335, 0.012885265052318573, 0.034535154700279236, 0.008310033939778805, -0.00367775559425354, -0.024947529658675194, 0.008805036544799805, -0.04051270708441734, 0.030620165169239044, 0.024983573704957962, 0.04717211052775383, 0.04535225033760071, -0.031458500772714615, -0.016148796305060387, -0.02938678488135338, -0.007026887033134699, -0.05229463800787926, 0.024893343448638916, 0.015642665326595306, -0.001205636071972549, 0.01301270816475153, -0.04665167257189751, -0.01188583392649889, 0.018380066379904747, 0.012568999081850052, 0.06086234748363495, 0.021366994827985764, -0.007369778119027615, 0.030318608507514, -0.011871986091136932, -0.04822581633925438, -0.026951786130666733, 0.01207835040986538, -0.0171176977455616, -0.013852507807314396, -0.017928436398506165, -0.019725888967514038, -0.0013108255807310343, -0.0002010879252338782, -0.03900407999753952, 0.0009821424027904868, 0.016095884144306183, -0.009054500609636307, 0.004882087465375662, 0.035625141113996506, 0.02897544577717781, 0.012536720372736454, 0.0001969901059055701, 0.018630625680088997, -0.010821579024195671, -0.010744994506239891, 0.06409631669521332, 0.017666036263108253, 0.002475068671628833, 0.008818571455776691, -0.043378423899412155, 0.01762319914996624, 0.03344407677650452, -0.037400826811790466, -0.020576002076268196, 0.00772683834657073, -0.014608926139771938, -0.004927154164761305, -0.06343938410282135, -0.02485104463994503, -0.02178497426211834 ]
76d437c1b037e1c3fe1a171bd9eb231c53d36fc1
645
py
Python
projectparallelprogrammeren/codesimulatie.py
fury106/ProjectParallelProgrammeren
fd3c198edaca5bcb19d8e665561e8cd14824e894
[ "MIT" ]
null
null
null
projectparallelprogrammeren/codesimulatie.py
fury106/ProjectParallelProgrammeren
fd3c198edaca5bcb19d8e665561e8cd14824e894
[ "MIT" ]
null
null
null
projectparallelprogrammeren/codesimulatie.py
fury106/ProjectParallelProgrammeren
fd3c198edaca5bcb19d8e665561e8cd14824e894
[ "MIT" ]
null
null
null
# -*- coding: utf-8 -*- """ Module projectparallelprogrammeren.codesimulatie ================================================================= Deze module simuleert alles. """ import projectparallelprogrammeren def simulatie(): """ Deze functie voert alle versies uit zodat deze vergeleken kunnen worden qua timing. """ from importlib import import_module for i in range(4): #alle versies van de simulatie importeren en achtereenvolgens uitvoeren. version = f"montecarlo_v{i}" montecarlo = import_module(version) montecarlo.simulatie(100,50) #Deze waarden dienen enkel als test if __name__ == "__main__": simulatie() #eof
23.035714
84
0.674419
1
0.8721
[ 0.0018561531323939562, 0.02490708790719509, 0.005171562545001507, -0.0029598891269415617, 0.0033956889528781176, -0.00361393834464252, -0.00916222296655178, 0.0044317166320979595, -0.004664629697799683, -0.00010277173714712262, 0.0033124289475381374, 0.006441321223974228, 0.004966555628925562, -0.01575823687016964, 0.000387714768294245, 0.017322104424238205, -0.05223614722490311, 0.0008728128741495311, -0.0049744597636163235, 0.0007732925587333739, -0.009015649557113647, 0.011187499389052391, 0.00946703739464283, 0.005367604084312916, 0.00747942877933383, 0.0035773557610809803, 0.00909839291125536, 0.004192977678030729, -0.007897987961769104, -0.00780627503991127, 0.0004450480337254703, -0.0010688136098906398, -0.006804096512496471, -0.007671613246202469, 0.003287822473794222, -0.0011829502182081342, 0.002789350925013423, -0.018486905843019485, 0.010363823734223843, -0.004786303732544184, -0.006393278017640114, -0.014411256648600101, 0.004670832771807909, 0.008447378873825073, -0.010984603315591812, 0.0028660218231379986, -0.0020174153614789248, 0.002488180063664913, -0.013855068944394588, 0.004517683293670416, -0.011534464545547962, 0.006784604396671057, 0.01438087783753872, 0.006306542549282312, -0.00460938923060894, -0.007256173528730869, 0.01079135574400425, 0.0003444815520197153, -0.009215367026627064, 0.0018335565691813827, -0.0030592104885727167, -0.006073630880564451, 0.004909514915198088, 0.0042236968874931335, -0.01722724922001362, -0.007320804055780172, -0.004538390319794416, 0.0015764457639306784, -0.0019551124423742294, 0.004661159124225378, 0.004225271288305521, 0.0004821361508220434, 0.006133866496384144, 0.0016951697180047631, 0.00392745528370142, -0.004116318188607693, -0.004632999189198017, 0.005432406906038523, 0.006936273537576199, 0.003152879886329174, 0.00628752913326025, -0.006958817597478628, 0.005835318937897682, 0.010809499770402908, 0.012075012549757957, 0.004339319653809071, 0.01564990170300007, -0.009476307779550552, 0.04140320420265198, 0.006477647460997105, -0.007523729000240564, 0.0017736917361617088, -0.009597568772733212, -0.00302299321629107, -0.0065796468406915665, -0.028185557574033737, 0.0006628616829402745, -0.0037644258700311184, -0.001594063127413392, 0.004342253785580397, -0.001694589969702065, 0.0048307012766599655, -0.0005523685831576586, -0.002320874249562621, -0.010296519845724106, 0.01107926294207573, -0.009686262346804142, -0.001608810038305819, 0.008654546923935413, 0.002597327809780836, -0.009888211265206337, 0.00017493801715318114, -0.00019898581376764923, -0.01436245534569025, 0.0047910078428685665, 0.0012085328344255686, -0.0082692950963974, 0.056058481335639954, -0.0043252757750451565, 0.0010903582442551851, -0.003180940868332982, 0.0023977719247341156, 0.000759839778766036, 0.006798754446208477, 0.008006465621292591, -0.004791556857526302, 0.013233494013547897, 0.007477592211216688, 0.003987586125731468, 0.009758418425917625, 0.0005931865307502449, 0.00845291092991829, -0.0041661374270915985, -0.0013945592800155282, -0.000336011202307418, -0.006471148692071438, 0.007162705063819885, 0.001128456206060946, -0.006574006285518408, 0.0020893204491585493, -0.003127752337604761, -0.010373733937740326, 0.003416497493162751, -0.0028231993783265352, 0.0021958386059850454, -0.01010175235569477, -0.0051686521619558334, -0.0034354133531451225, -0.002833374310284853, 0.0019418274750933051, 0.00840515736490488, 0.0025907643139362335, 0.002531516831368208, -0.008977353572845459, -0.010926438495516777, -0.0027461270801723003, -0.004814091604202986, 0.0026803361251950264, 0.00811036117374897, 0.003646250581368804, -0.010600224137306213, -0.0009200245258398354, 0.003005527425557375, 0.0038636026438325644, -0.0021243903320282698, 0.0015230248682200909, -0.007522974628955126, 0.00763867748901248, 0.0012475308030843735, 0.003090028651058674, 0.008473565801978111, -0.004811255261301994, -0.003214385360479355, -0.0008876995416358113, 0.004320824518799782, 0.0015395786613225937, 0.004583768080919981, 0.011022836901247501, -0.002996631897985935, -0.0038888759445399046, 0.002694174414500594, 0.005967817269265652, 0.0070183309726417065, 0.007439471315592527, -0.0021951827220618725, 0.002951998496428132, -0.004599439911544323, 0.00007490109419450164, 0.006013671401888132, -0.0047752331010997295, 0.008487725630402565, 0.005304568447172642, -0.013837405480444431, -0.006337822414934635, -0.003729240270331502, -0.011005927808582783, -0.0005077720852568746, 0.013380270451307297, 0.010601842775940895, -0.0017780562629923224, 0.004267480690032244, -0.012353764846920967, 0.0009509799419902265, 0.007501594722270966, 0.0022274248767644167, -0.013273630291223526, -0.9573412537574768, 0.005789061076939106, 0.0033113877288997173, 0.0005847335560247302, 0.006639579776674509, 0.0005314540467225015, 0.003357501933351159, 0.003291786415502429, 0.015447480604052544, -0.009898286312818527, -0.004813788924366236, -0.0070382109843194485, -0.013250910677015781, -0.00042350261355750263, -0.006085543893277645, -0.0020899076480418444, -0.004672190640121698, -0.006949007045477629, 0.0011520604602992535, -0.0044725253246724606, -0.0032228752970695496, 0.011671079322695732, -0.0000591844400332775, 0.005559941753745079, 0.0009813288925215602, 0.004103171173483133, -0.00625498965382576, -0.0035072655882686377, -0.000657895056065172, -0.0022488476242870092, -0.004090017639100552, -0.015529479831457138, -0.0031409654766321182, -0.0014411251759156585, 0.01224010344594717, 0.001914194435812533, 0.007648515980690718, -0.000980887096375227, 0.0009791487827897072, -0.010686245746910572, 0.004911716096103191, 0.0013266748283058405, 0.004481366835534573, -0.03068479523062706, -0.0006003659218549728, -0.00035224182647652924, -0.00798390619456768, 0.007143872324377298, 0.0014621824957430363, -0.00045661727199330926, -0.004408160224556923, -0.0072120726108551025, 0.009577194228768349, -0.009930347092449665, 0.004305233713239431, -0.0057799057103693485, -0.005912051536142826, -0.0019129603169858456, -0.009995606727898121, 0.0026637620758265257, 0.0026387996040284634, -0.0031268910970538855, -0.004815808497369289, -0.003334235865622759, 0.005932696163654327, 0.001493398449383676, 0.0013292374787852168, -0.014952288009226322, -0.003593449480831623, -0.0005343662342056632, 0.0015692082233726978, -0.002274884609505534, -0.004667381756007671, 0.0061468929052352905, -0.012514288537204266, 0.005348326172679663, 0.0005339624476619065, 0.000456021458376199, -0.00960028450936079, 0.0001934089232236147, -0.008863560855388641, -0.008765272796154022, 0.0025633370969444513, -0.003260851139202714, -0.0051130023784935474, 0.0025455367285758257, 0.003910142928361893, 0.003689945675432682, -0.004481888376176357, 0.0039016094524413347, 0.01231166161596775, -0.0031766053289175034, -0.007624251767992973, 0.007893444038927555, 0.007882995530962944, 0.001552556874230504, -0.0026914123445749283, 0.002536011626943946, 0.004789009690284729, 0.008288719691336155, -0.000917563505936414, 0.004005336202681065, -0.00040697085205465555, 0.010371576994657516, -0.0023538453970104456, 0.002477200934663415, -0.0017888769507408142, -0.0016466086963191628, -0.0034188043791800737, -0.0027889537159353495, -0.0020611369982361794, -0.0019223237177357078, -0.010431856848299503, -0.01091079693287611, -0.0024968760553747416, 0.002075831638649106, 0.0008403354440815747, -0.0047534494660794735, -0.0006720584933646023, 0.00048701907508075237, 0.009102176874876022, 0.00001817966222006362, -0.003782637184485793, 0.0005697723827324808, 0.002026467816904187, -0.003962455317378044, 0.01679311878979206, -0.01158628985285759, 0.006934081669896841, 0.0005975684034638107, -0.016958173364400864, 0.008234323933720589, 0.009104499593377113, -0.007001728285104036, 0.003138517728075385, 0.0013248153263702989, -0.00024693997693248093, 0.0007903567748144269, -0.006253041326999664, 0.001133795129135251, -0.01827421225607395, 0.0021250343415886164, 0.022130217403173447, 0.0027886684983968735, 0.009396862238645554, 0.012123437598347664, -0.002693299436941743, 0.001718182465992868, 0.00832593347877264, 0.0012565783690661192, 0.012906670570373535, -0.004862888716161251, -0.001986815594136715, 0.003350009210407734, -0.005381364841014147, 0.0017416584305465221, 0.0047151315957307816, 0.007983537390828133, -0.005427312571555376, 0.00094246567459777, -0.004511117935180664, -0.004641123581677675, -0.016597257927060127, -0.002903310814872384, 0.007768804207444191, -0.0053498088382184505, 0.0030935253016650677, -0.013119453564286232, 0.004893438424915075, 0.004594318103045225, 0.001668057986535132, 0.001005274010822177, 0.0027653402648866177, 0.008026354014873505, 0.010991472750902176, -0.005743835587054491, 0.0021378681994974613, 0.0007739693392068148, -0.004540620371699333, -0.0022793286480009556, 0.006339712999761105, -0.0070077767595648766, -0.004751776810735464, 0.0016891340492293239, 0.0011774495942518115, 0.00024664675584062934, -0.0008385099354200065, -0.005709866061806679, -0.005601544864475727, 0.004438864532858133, -0.008510911837220192, 0.0027037756517529488, -0.0009076859569177032, 0.0047039492055773735, -0.008691401220858097, -0.0016221036203205585, -0.006364709697663784, -0.010016591288149357, 0.010513657703995705, -0.000043565993109950796, -0.0005620807642117143, 0.012750613503158092, 0.00368609931319952, -0.013047080487012863, 0.0054043373093008995, 0.010777737945318222, -0.003935691434890032, 0.003470328636467457, 0.005384752992540598, -0.004963395651429892, -0.021413901820778847, -0.001338205416686833, -0.013100722804665565, 0.004348098766058683, -0.0045099155977368355, 0.004490006249397993, -0.010441143997013569, 0.006990236695855856, 0.008334169164299965, -0.01242308970540762, -0.005855750758200884, -0.009805127047002316, 0.008535224013030529, -0.0013791583478450775, -0.0032956479117274284, -0.0025469146203249693, 0.0004239897825755179, -0.005498433019965887, -0.002595738274976611, -0.0009413333609700203, 0.004181018564850092, 0.0020728176459670067, -0.0031632499303668737, 0.0007380767492577434, -0.004827333614230156, 0.002140526659786701, 0.0015202098293229938, -0.010490074753761292, 0.0048051499761641026, 0.0058060744777321815, 0.0006753875641152263, -0.0015866770409047604, 0.0007697910186834633, -0.0007270450005307794, -0.0031105142552405596, -0.010283781215548515, -0.003135481383651495, -0.001376779517158866, -0.0034456776920706034, -0.010287598706781864, -0.0016761058941483498, -0.005726167466491461, 0.007778048049658537, -0.007267066743224859, 0.007107654586434364, 0.005178009159862995, -0.0031129298731684685, 0.005387233570218086, -0.00235048308968544, 0.003924504853785038, 0.00019331603834871203, 0.005844431929290295, 0.0025234336499124765, -0.006712614092975855, -0.012336970306932926, 0.011964019387960434, -0.011813066899776459, 0.0006838873960077763, 0.014179054647684097, 0.006482758093625307, 0.013432569801807404, -0.0009030812652781606, 0.0012487552594393492, 0.0032584876753389835, 0.008712202310562134, -0.012651820667088032, 0.0016329450299963355, -0.003819481236860156, -0.003325348487123847, 0.005495733115822077, -0.001785792177543044, 0.00039898630348034203, 0.008010247722268105, 0.002615389646962285, -0.005824505351483822, -0.003362129908055067, -0.0014627822674810886, 0.0028908189851790667, -0.010425947606563568, 0.0018817184027284384, -0.005471440032124519, -0.006614301353693008, -0.0010965015972033143, 0.0004518674104474485, -0.0021469229832291603, 0.0014023389667272568, -0.0017631353111937642, 0.004769595805555582, 0.0016809902153909206, -0.0014426873531192541, 0.015621235594153404, -0.005430934019386768, -0.007941192016005516, 0.0015271860174834728, 0.001292887725867331, 0.001090713427402079, -0.0062426673248410225, -0.0016356630949303508, 0.0030118159484118223, 0.005062393844127655, -0.001521804602816701, -0.008834775537252426, -0.0012422623112797737, -0.00019506608077790588, -0.007938421331346035, 0.0005812267772853374, 0.011747759766876698, -0.003688501426950097, 0.0045360722579061985, -0.0008625703048892319, -0.0066571831703186035, -0.014320322312414646, 0.05752459168434143, -0.0006605351809412241, 0.002582574263215065, 0.004152827430516481, -0.006486282683908939, -0.001963506918400526, -0.0029879917856305838, 0.00826932117342949, -0.006537255831062794, -0.008396676741540432, 0.009831815958023071, -0.0035203248262405396, 0.0007842321065254509, 0.000025854373234324157, -0.002302818465977907, 0.01685895025730133, -0.007116212509572506, -0.0184809360653162, -0.016536138951778412, 0.007207865361124277, -0.0040718610398471355, -0.005933767184615135, 0.006274332758039236, -0.00341404159553349, -0.0005116176907904446, 0.0019719565752893686, 0.0031487061642110348, 0.0010452390415593982, 0.0008201583987101912, -0.0018539263401180506, -0.002140799770131707, -0.0003960909089073539, 0.0019480920163914561, 0.005682187620550394, 0.007258567959070206, -0.0021485809702426195, 0.005765366833657026, -0.00010600574751151726, -0.001332141924649477, -0.0024483336601406336, 0.005740126129239798, 0.007829895243048668, -0.004440921824425459, -0.004514710046350956, 0.005465249065309763, 0.0030469533521682024, 0.000943393271882087, 0.0107597466558218, -0.0011888681910932064, -0.005008919630199671, 0.006728318519890308, 0.008452143520116806, -0.0034770776983350515, 0.009980483911931515, -0.0022820637095719576, 0.004291702527552843, 0.002473721979185939, -0.007472882978618145, -0.01194506511092186, -0.0034884698688983917, 0.00675667729228735, 0.010179483331739902, 0.0012717039790004492, -0.000800207955762744, 0.0026152601931244135, -0.003305573482066393, -0.009288573637604713, -0.006061139982193708, -0.001363547402434051, -0.0014080319087952375, 0.003837721189484, 0.07124775648117065, -0.0052312035113573074, 0.0017576966201886535, -0.010187466628849506, 0.0005150841316208243, -0.0008696276345290244, -0.0004071897128596902, -0.0010867558885365725, -0.002424464328214526, 0.003386233700439334, 0.003901552641764283, -0.00739675760269165, -0.007829762995243073, 0.0009321871912106872, 0.0017237224383279681, -0.002545636612921953, 0.0021038753911852837, 0.007648816332221031, -0.005927697755396366, 0.0004011332057416439, -0.013478885404765606, -0.0027462770231068134, -0.0019655711948871613, -0.008713574148714542, -0.001968524418771267, -0.0032210981007665396, 0.0028923379722982645, 0.001766288187354803, 0.00812535546720028, -0.0015821006381884217, 0.006304629147052765, -0.0014656690182164311, 0.002332838950678706, -0.0057962872087955475, -0.0013490301789715886, -0.0032618483528494835, 0.007455385755747557, -0.002109748078510165, -0.010793959721922874, -0.006007059942930937, -0.00294890976510942, -0.0007418236928060651, -0.005627481732517481, 0.007433826569467783, -0.001789490575902164, 0.007647655438631773, -0.00250288681127131, 0.0006969633395783603, -0.005799591541290283, 0.0024750137235969305, -0.012429884634912014, 0.003626032965257764, -0.1784408986568451, 0.011944783851504326, 0.002015945967286825, -0.005774150136858225, -0.004578814376145601, -0.016639476642012596, -0.008290139958262444, 0.001849487191066146, 0.010839252732694149, 0.0010324491886422038, 0.000280441134236753, 0.00016222518752329051, 0.005608970765024424, 0.00473635271191597, 0.00006114089046604931, -0.006077541038393974, 0.004587313160300255, -0.003947170916944742, -0.00022137690393719822, 0.0023996583186089993, 0.0043439436703920364, 0.00723972637206316, 0.002000767271965742, 0.001670735771767795, -0.00006130526162451133, -0.0034930992405861616, 0.0033777030184865, -0.0009668594575487077, 0.008740244433283806, -0.009743044152855873, -0.005106582306325436, -0.006251893937587738, -0.0019991917070001364, 0.0019290631171315908, 0.0036224322393536568, -0.0017767846584320068, 0.004678765311837196, 0.0003722110122907907, -0.0041962130926549435, 0.007043194025754929, -0.0032967799343168736, 0.031092260032892227, 0.005561016034334898, 0.006217527203261852, -0.0004325803311076015, -0.0016652449266985059, -0.006112805102020502, 0.009574254043400288, 0.0006463121972046793, 0.013910538516938686, -0.012902334332466125, -0.0022830325178802013, 0.0036432649940252304, 0.01667245291173458, -0.007138477172702551, -0.00804967898875475, -0.00987741257995367, -0.005740640684962273, 0.0031140302307903767, 0.008186336606740952, 0.006612709257751703, -0.005222226958721876, 0.005596536677330732, -0.005595551338046789, -0.02220221795141697, 0.003572354558855295, -0.004778522998094559, -0.006161929573863745, 0.0005794373573735356, 0.0067415786907076836, 0.013651670888066292, -0.0024280871730297804, 0.009774410165846348, -0.0020263674668967724, -0.0004164706915616989, -0.0008760542841628194, 0.0067178490571677685, -0.003106510965153575, 0.007729360368102789, -0.008190445601940155, 0.0095830038189888, -0.006766524165868759, -0.002550954930484295, 0.0005634502740576863, -0.004656445700675249, 0.011619988828897476, 0.004932579584419727, -0.0037167752161622047, -0.0036137837450951338, -0.014077821746468544, -0.0023475533816963434, 0.004249215126037598, 0.003001085016876459, -0.00924608577042818, 0.0016897714231163263, -0.0008159630815498531, 0.008401121944189072, 0.007760596461594105, -0.008972866460680962, 0.0008356586913578212, 0.00509504834190011, -0.006939527112990618, 0.0012022630544379354, -0.004228373058140278, 0.0033272714354097843, 0.006088648457080126, -0.006543739698827267, -0.008130270056426525, 0.00498020276427269, -0.005301034543663263, -0.0009643013472668827, 0.006496591493487358, -0.010812897235155106, -0.007809663191437721, -0.0009388147154822946, -0.011874896474182606, 0.0026911848690360785 ]