code string | signature string | docstring string | loss_without_docstring float64 | loss_with_docstring float64 | factor float64 |
|---|---|---|---|---|---|
if len(args) <= 0:
raise ValueError("you didn't pass any arguments to print out")
with Reflect.context(args, **kwargs) as r:
instance = R_CLASS(r, stream, **kwargs)
instance() | def r(*args, **kwargs) | Similar to pout.v() but gets rid of name and file information so it can be used
in loops and stuff, it will print out where the calls came from at the end of
execution
this just makes it nicer when you're printing a bunch of stuff each iteration
:Example:
for x in range(x):
pout.r(... | 13.654149 | 12.522874 | 1.090337 |
'''
same as sys.exit(1) but prints out where it was called from before exiting
I just find this really handy for debugging sometimes
since -- 2013-5-9
exit_code -- int -- if you want it something other than 1
'''
with Reflect.context(args, **kwargs) as r:
instance = V_CLASS(r, str... | def x(*args, **kwargs) | same as sys.exit(1) but prints out where it was called from before exiting
I just find this really handy for debugging sometimes
since -- 2013-5-9
exit_code -- int -- if you want it something other than 1 | 16.196436 | 5.561992 | 2.911985 |
'''
prints "here count"
example --
h(1) # here 1 (/file:line)
h() # here line (/file:line)
count -- integer -- the number you want to put after "here"
'''
with Reflect.context(**kwargs) as r:
kwargs["count"] = count
instance = H_CLASS(r, stream, **kwargs)
... | def h(count=0, **kwargs) | prints "here count"
example --
h(1) # here 1 (/file:line)
h() # here line (/file:line)
count -- integer -- the number you want to put after "here" | 17.08647 | 4.574818 | 3.734896 |
'''
create a big text break, you just kind of have to run it and see
since -- 2013-5-9
*args -- 1 arg = title if string, rows if int
2 args = title, int
3 args = title, int, sep
'''
with Reflect.context(**kwargs) as r:
kwargs["args"] = args
instance = B_CLASS(r,... | def b(*args, **kwargs) | create a big text break, you just kind of have to run it and see
since -- 2013-5-9
*args -- 1 arg = title if string, rows if int
2 args = title, int
3 args = title, int, sep | 28.52482 | 4.055213 | 7.034111 |
'''
kind of like od -c on the command line, basically it dumps each character and info
about that char
since -- 2013-5-9
*args -- tuple -- one or more strings to dump
'''
with Reflect.context(**kwargs) as r:
kwargs["args"] = args
instance = C_CLASS(r, stream, **kwargs)
... | def c(*args, **kwargs) | kind of like od -c on the command line, basically it dumps each character and info
about that char
since -- 2013-5-9
*args -- tuple -- one or more strings to dump | 28.894947 | 4.662245 | 6.197646 |
if not args:
raise ValueError("you didn't pass any arguments to print out")
with Reflect.context(args, **kwargs) as r:
instance = J_CLASS(r, stream, **kwargs)
instance() | def j(*args, **kwargs) | dump json
since -- 2013-9-10
*args -- tuple -- one or more json strings to dump | 16.826601 | 18.345678 | 0.917197 |
with Reflect.context(**kwargs) as r:
kwargs["name"] = name
instance = M_CLASS(r, stream, **kwargs)
instance() | def m(name='', **kwargs) | Print out memory usage at this point in time
http://docs.python.org/2/library/resource.html
http://stackoverflow.com/a/15448600/5006
http://stackoverflow.com/questions/110259/which-python-memory-profiler-is-recommended | 20.384535 | 27.864939 | 0.731548 |
'''
really quick and dirty profiling
you start a profile by passing in name, you stop the top profiling by not
passing in a name. You can also call this method using a with statement
This is for when you just want to get a really back of envelope view of
how your fast your code is, super handy... | def p(name="", **kwargs) | really quick and dirty profiling
you start a profile by passing in name, you stop the top profiling by not
passing in a name. You can also call this method using a with statement
This is for when you just want to get a really back of envelope view of
how your fast your code is, super handy, not super ... | 12.637074 | 1.792399 | 7.050369 |
'''
same as time.sleep(seconds) but prints out where it was called before sleeping
and then again after finishing sleeping
I just find this really handy for debugging sometimes
since -- 2017-4-27
:param seconds: float|int, how many seconds to sleep
'''
if seconds <= 0.0:
raise... | def sleep(seconds, **kwargs) | same as time.sleep(seconds) but prints out where it was called before sleeping
and then again after finishing sleeping
I just find this really handy for debugging sometimes
since -- 2017-4-27
:param seconds: float|int, how many seconds to sleep | 8.636835 | 3.644359 | 2.369919 |
'''
print a backtrace
since -- 7-6-12
inpsect_packages -- boolean -- by default, this only prints code of packages that are not
in the pythonN directories, that cuts out a lot of the noise, set this to True if you
want a full stacktrace
depth -- integer -- how deep you want the st... | def t(inspect_packages=False, depth=0, **kwargs) | print a backtrace
since -- 7-6-12
inpsect_packages -- boolean -- by default, this only prints code of packages that are not
in the pythonN directories, that cuts out a lot of the noise, set this to True if you
want a full stacktrace
depth -- integer -- how deep you want the stack trace to... | 12.188622 | 2.631366 | 4.63205 |
try:
from .compat import builtins
module = sys.modules[__name__]
setattr(builtins, __name__, module)
#builtins.pout = pout
except ImportError:
pass | def inject() | Injects pout into the builtins module so it can be called from anywhere without
having to be explicitely imported, this is really just for convenience when
debugging
https://stackoverflow.com/questions/142545/python-how-to-make-a-cross-module-variable | 7.841098 | 5.351947 | 1.465092 |
import glob
from subprocess import Popen, PIPE
cams=[]
for device in glob.glob("/sys/class/video4linux/*"):
devname=device.split("/")[-1]
devfile=os.path.join("/dev",devname)
lis=("v4l2-ctl --list-formats -d "+devfile).split()
p = Popen(lis, stdout=PI... | def getH264V4l2(verbose=False) | Find all V4l2 cameras with H264 encoding, and returns a list of tuples with ..
(device file, device name), e.g. ("/dev/video2", "HD Pro Webcam C920 (/dev/video2)") | 2.932793 | 2.657199 | 1.103716 |
app_ = CustomFlask(
__name__,
instance_path=instance_path or os.environ.get(
'VERIPRESS_INSTANCE_PATH') or os.getcwd(),
instance_relative_config=True
)
app_.config.update(dict(STORAGE_TYPE='file',
THEME='default',
... | def create_app(config_filename, instance_path=None) | Factory function to create Flask application object.
:param config_filename: absolute or relative filename of the config file
:param instance_path: instance path to initialize or run a VeriPress app
:return: a Flask app object | 3.453675 | 3.38164 | 1.021302 |
if self.config['MODE'] == 'api-only':
# if 'api-only' mode is set, we should not send static files
abort(404)
theme_static_folder = getattr(self, 'theme_static_folder', None)
if theme_static_folder:
try:
return send_from_directory(the... | def send_static_file(self, filename) | Send static files from the static folder
in the current selected theme prior to the global static folder.
:param filename: static filename
:return: response object | 3.664768 | 3.48513 | 1.051544 |
if self.device == device:
print(self.pre, "setDevice : same device")
return
if self.filterchain: # there's video already
self.clearDevice()
self.device = device
self.video.setDevice(self.device) # inform the video widg... | def setDevice(self, device):
print(self.pre, "setDevice :", device)
if (not device and not self.device): # None can be passed as an argument when the device has not been set yet
return
if (self.device) | Sets the video stream
:param device: A rather generic device class. In this case DataModel.RTSPCameraDevice. | 10.199016 | 10.13269 | 1.006546 |
print(self.pre, "clearDevice")
if not self.device:
return
self.filterchain.delViewPort(self.viewport)
self.filterchain = None
self.device = None
self.video.update() | def clearDevice(self) | Remove the current stream | 9.8578 | 9.246626 | 1.066097 |
print(self.pre, ": mouseGestureHandler: ")
# *** single click events ***
if (info.fsingle):
print(self.pre, ": mouseGestureHandler: single click")
if (info.button == QtCore.Qt.LeftButton):
print(self.pre, ": mouseGestureHandler: Left button clicke... | def mouseGestureHandler(self, info) | This is the callback for MouseClickContext. Passed to VideoWidget as a parameter | 2.326824 | 2.273804 | 1.023318 |
if (self.double_click_focus == False): # turn focus on
print(self.pre, "handle_left_double_click: focus on")
self.cb_focus()
else: # turn focus off
print(self.pre, "handle_left_double_click: focus off")
self.cb_unfocus()
self.double_clic... | def handle_left_double_click(self, info) | Whatever we want to do, when the VideoWidget has been double-clicked with the left button | 3.601012 | 3.458732 | 1.041136 |
storage_ = getattr(g, '_storage', None)
if storage_ is None:
storage_type = current_app.config['STORAGE_TYPE']
if storage_type == 'file':
storage_ = g._storage = storages.FileStorage()
else:
raise ConfigurationError(
'Storage type "{}" is not ... | def get_storage() | Get storage object of current app context,
will create a new one if not exists.
:return: a storage object
:raise: ConfigurationError: storage type in config is not supported | 2.719813 | 2.760179 | 0.985376 |
self.current_slot = None
if (verbose):
# enable this if you're unsure what's coming here..
print(self.pre, "chooseForm_slot :", element)
if (isinstance(element, type(None))):
self.current_row = None
self.element = None
else:
... | def chooseForm_slot(self, element, element_old) | Calling this slot chooses the form to be shown
:param element: an object that has *_id* and *classname* attributes
:param element_old: an object that has *_id* and *classname* attributes
This slot is typically connected to List classes, widget attribute's, currentItemChanged method (List... | 4.560148 | 4.598658 | 0.991626 |
self.dropdown_widget.clear() # this will trigger dropdown_changed_slot
self.row_instance_by_index = []
for i, key in enumerate(self.row_instance_by_name.keys()):
row_instance = self.row_instance_by_name[key]
if (row_instance.isActive()):
self.row_... | def update_dropdown_list_slot(self) | Keep updating the dropdown list. Say, don't let the user choose USB devices if none is available | 3.493355 | 3.458874 | 1.009969 |
self.reset()
for dic in self.datamodel.camera_collection.get(): # TODO: search directly for RTSPCameraRow
if (self.verbose): print(self.pre, "read : dic", dic)
if (dic["classname"] == DataModel.RTSPCameraRow.__name__):
affinity = -1
... | def read(self) | Reads all devices from the database and creates filterchains
TODO: we can, of course, just modify the added / removed cameras | 3.647189 | 3.480046 | 1.048029 |
raise(AssertionError("out of date"))
new_ids = []
old_ids = []
# collect old ip addresses
for chain in self.chains:
if (self.verbose): print(self.pre, "old :", chain, chain.get__id(), chain.get_address(), chain._id)
old_ids.appen... | def update(self) | Reads all devices from the database. Creates new filterchains and removes old ones
TODO: currently this is broken: if user changes any other field than the ip address, the cameras don't get updated | 4.133329 | 3.874654 | 1.066761 |
for chain in self.chains:
for key in kwargs:
getter_name = "get_"+key
# scan all possible getters
if (hasattr(chain, getter_name)):
getter = getattr(chain, getter_name) # e.g. "get_address"
if (getter() ... | def get(self, **kwargs) | Find correct filterchain based on generic variables | 4.994916 | 4.189115 | 1.192356 |
return None
# get filterchain init parameters that are compatible with RTSPCameraDevice input parameters
pars = filterchain.getParDic(DataModel.RTSPCameraDevice.parameter_defs)
# .. and instantiate an RTSPCameraDevice with those parameters
device = DataModel.RTSPCam... | def getDevice(self, **kwargs):
filterchain = self.get(**kwargs)
if not filterchain | Like get, but returns a Device instance (RTSPCameraDevice, etc.) | 13.489644 | 10.274257 | 1.312956 |
return {k: getattr(self, k) for k in filter(
lambda k: not k.startswith('_') and k != 'to_dict', dir(self))} | def to_dict(self) | Convert attributes and properties to a dict,
so that it can be serialized. | 3.428604 | 3.007451 | 1.140037 |
return {
'level': self.level,
'id': self.id,
'text': self.text,
'inner_html': self.inner_html,
'children': [child.to_dict() for child in self.children]
} | def to_dict(self) | Convert self to a dict object for serialization. | 2.627521 | 2.311705 | 1.136616 |
depth = min(max(depth, 0), 6)
depth = 6 if depth == 0 else depth
lowest_level = min(max(lowest_level, 1), 6)
toc = self._root.to_dict()['children']
def traverse(curr_toc, dep, lowest_lvl, curr_depth=1):
if curr_depth > dep:
# clear all items ... | def toc(self, depth=6, lowest_level=6) | Get table of content of currently fed HTML string.
:param depth: the depth of TOC
:param lowest_level: the allowed lowest level of header tag
:return: a list representing the TOC | 3.11719 | 3.227699 | 0.965762 |
toc = self.toc(depth=depth, lowest_level=lowest_level)
if not toc:
return ''
def map_toc_list(toc_list):
result = ''
if toc_list:
result += '<ul>\n'
result += ''.join(
map(lambda x: '<li>'
... | def toc_html(self, depth=6, lowest_level=6) | Get TOC of currently fed HTML string in form of HTML string.
:param depth: the depth of TOC
:param lowest_level: the allowed lowest level of header tag
:return: an HTML string | 2.694659 | 3.032434 | 0.888613 |
m = re.match(r'^h([123456])$', tag, flags=re.IGNORECASE)
if not m:
return None
return int(m.group(1)) | def _get_level(tag) | Match the header level in the given tag name,
or None if it's not a header tag. | 3.090827 | 2.431822 | 1.270992 |
from darknet.core import darknet_with_cuda
if (darknet_with_cuda()): # its using cuda
free = getFreeGPU_MB()
print("Yolo: requiredGPU_MB: required, free", n, free)
if (free == -1): # could not detect ..
return True
return (free>=n)... | def requiredGPU_MB(self, n) | Required GPU memory in MBytes | 11.272901 | 11.22172 | 1.004561 |
if (self.requiredGPU_MB(self.required_mb)):
self.analyzer = YoloV3Analyzer(verbose = self.verbose)
else:
self.warning_message = "WARNING: not enough GPU memory!"
self.analyzer = None | def postActivate_(self) | Whatever you need to do after creating the shmem client | 13.64822 | 13.122101 | 1.040094 |
self.widget = QtWidgets.QTextEdit()
self.widget.setStyleSheet(style.detector_test)
self.widget.setReadOnly(True)
self.signals.objects.connect(self.objects_slot)
return self.widget | def getWidget(self) | Some ideas for your widget:
- Textual information (alert, license place number)
- Check boxes : if checked, send e-mail to your mom when the analyzer spots something
- .. or send an sms to yourself
- You can include the cv2.imshow window to the widget to see how the analyzer proceeds | 7.092404 | 6.418005 | 1.105079 |
'''
get the type of val
there are multiple places where we want to know if val is an object, or a string, or whatever,
this method allows us to find out that information
since -- 7-10-12
val -- mixed -- the value to check
return -- string -- the type
'... | def typename(self) | get the type of val
there are multiple places where we want to know if val is an object, or a string, or whatever,
this method allows us to find out that information
since -- 7-10-12
val -- mixed -- the value to check
return -- string -- the type | 3.720349 | 2.779642 | 1.338427 |
if is_py2:
return isinstance(
self.val,
(
types.NoneType,
types.BooleanType,
types.IntType,
types.LongType,
types.FloatType
)
)
... | def is_primitive(self) | is the value a built-in type? | 2.659363 | 2.398672 | 1.108681 |
'''
turn an iteratable value into a string representation
iterator -- iterator -- the value to be iterated through
name_callback -- callback -- if not None, a function that will take the key of each iteration
prefix -- string -- what will be prepended to the generated value
... | def _str_iterator(self, iterator, name_callback=None, prefix="\n", left_paren='[', right_paren=']', depth=0) | turn an iteratable value into a string representation
iterator -- iterator -- the value to be iterated through
name_callback -- callback -- if not None, a function that will take the key of each iteration
prefix -- string -- what will be prepended to the generated value
left_paren -- st... | 3.748026 | 2.72983 | 1.372989 |
'''
add whitespace to the beginning of each line of val
link -- http://code.activestate.com/recipes/66055-changing-the-indentation-of-a-multi-line-string/
val -- string
indent -- integer -- how much whitespace we want in front of each line of val
return -- string -- va... | def _add_indent(self, val, indent_count) | add whitespace to the beginning of each line of val
link -- http://code.activestate.com/recipes/66055-changing-the-indentation-of-a-multi-line-string/
val -- string
indent -- integer -- how much whitespace we want in front of each line of val
return -- string -- val with more whitespa... | 6.146233 | 2.077879 | 2.957935 |
try:
ret = getattr(val, key, default_val)
except Exception as e:
logger.exception(e)
ret = default_val
return ret | def _getattr(self, val, key, default_val) | wrapper around global getattr(...) method that suppresses any exception raised | 3.323394 | 2.857077 | 1.163215 |
'''
get the full namespaced (module + class) name of the val object
since -- 6-28-12
val -- mixed -- the value (everything is an object) object
default -- string -- the default name if a decent name can't be found programmatically
return -- string -- the full.module.Na... | def _get_name(self, val, src_file, default='Unknown') | get the full namespaced (module + class) name of the val object
since -- 6-28-12
val -- mixed -- the value (everything is an object) object
default -- string -- the default name if a decent name can't be found programmatically
return -- string -- the full.module.Name | 5.106729 | 2.032238 | 2.512859 |
'''
return the source file path
since -- 7-19-12
val -- mixed -- the value whose path you want
return -- string -- the path, or something like 'Unknown' if you can't find the path
'''
path = default
try:
# http://stackoverflow.com/questions... | def _get_src_file(self, val, default='Unknown') | return the source file path
since -- 7-19-12
val -- mixed -- the value whose path you want
return -- string -- the path, or something like 'Unknown' if you can't find the path | 5.769792 | 2.983042 | 1.934197 |
count = e.end - e.start
#return "." * count, e.end
global ENCODING_REPLACE_CHAR
return ENCODING_REPLACE_CHAR * count, e.end | def handle_decode_replace(e) | this handles replacing bad characters when printing out
http://www.programcreek.com/python/example/3643/codecs.register_error
http://bioportal.weizmann.ac.il/course/python/PyMOTW/PyMOTW/docs/codecs/index.html
https://pymotw.com/2/codecs/ | 8.202489 | 8.482296 | 0.967013 |
# (re)create the widget, do the same for children
# how children are placed on the parent widget, depends on the subclass
self.window = self.ContainerWindow(
self.signals, self.title, self.parent)
# send to correct x-screen
self.window.show()
self.window.wind... | def makeWidget(self, qscreen: QtGui.QScreen) | TODO: activate after gpu-hopping has been debugged
self.screenmenu = ScreenMenu(self.window)
self.screenmenu.screen_1.triggered.connect(self.test_slot)
self.screenmenu.screen_2.triggered.connect(self.test_slot) | 4.928752 | 4.927983 | 1.000156 |
if (self.closed):
return
print(self.pre, "close")
for child in self.children:
child.close()
self.openglthread = None
self.gpu_handler = None
self.closed = True
self.window.unSetPropagate() # we don't want the window to send the clo... | def close(self) | Called by the main gui to close the containers. Called also when the container widget is closed
Closed by clicking the window: goes through self.close_slot
Closed programmatically: use this method directly | 11.542007 | 10.025857 | 1.151224 |
ids = []
for child in self.children:
device = child.getDevice()
if device:
ids.append(device._id) # e.g. DataModel.RTSPCameraDevice._id
else:
ids.append(None)
# gather all information to re-construct this RootVideoCont... | def serialize(self) | Serialize information about the widget: coordinates, size, which cameras are selected. | 6.206206 | 5.807245 | 1.068701 |
self.prevframe = None
self.wasmoving = False
self.t0 = 0
self.ismoving = False | def reset(self) | Reset analyzer state | 8.9214 | 8.599535 | 1.037428 |
widget = QtWidgets.QLabel("NO MOVEMENT YET")
widget.setStyleSheet(style.detector_test)
self.signals.start_move.connect(lambda : widget.setText("MOVEMENT START"))
self.signals.stop_move. connect(lambda : widget.setText("MOVEMENT STOP"))
return widget | def getWidget(self) | Some ideas for your widget:
- Textual information (alert, license place number)
- Check boxes : if checked, send e-mail to your mom when the analyzer spots something
- .. or send an sms to yourself
- You can include the cv2.imshow window to the widget to see how the analyzer proceeds | 6.77112 | 6.865405 | 0.986267 |
return url_rule(api_blueprint, rules, strict_slashes=strict_slashes,
view_func=json_api(api_func) if api_func else None,
*args, **kwargs) | def rule(rules, strict_slashes=False, api_func=None, *args, **kwargs) | Add a API route to the 'api' blueprint.
:param rules: rule string or string list
:param strict_slashes: same to Blueprint.route, but default value is False
:param api_func: a function that returns a JSON serializable object
or a Flask Response, or raises ApiException
:param args: o... | 4.321701 | 5.200716 | 0.830982 |
qapp = QtCore.QCoreApplication.instance()
if not qapp: # QApplication has not been started
return
screens = qapp.screens()
virtual_screens = set()
for screen in screens:
# if screen has been deemed as "virtual", don't check its siblings
... | def findXScreens(self) | let's find out which screens are virtual
screen, siblings:
One big virtual desktop:
A [A, B, C]
B [A, B, C]
C [A, B, C]
A & B in one xscreen, C in another:
A [A, B]
B [A, B]
C [C] | 5.840959 | 5.544174 | 1.053531 |
self.dm = DataModel(directory = tools.getConfigDir())
if (self.first_start):
print(pre, "readDB : first start")
self.dm.clearAll()
self.dm.saveAll()
# If camera collection is corrupt
if not self.dm.checkCameraCollection():
self.dm... | def readDB(self) | Datamodel includes the following files: config.dat, devices.dat | 10.303978 | 9.83156 | 1.048051 |
for i in range(1, 5):
# adds member function grid_ixi_slot(self)
self.make_grid_slot(i, i)
for cl in self.mvision_classes:
self.make_mvision_slot(cl) | def generateMethods(self) | Generate some member functions | 12.492975 | 11.327808 | 1.102859 |
class QuickWindow(QtWidgets.QMainWindow):
class Signals(QtCore.QObject):
close = QtCore.Signal()
show = QtCore.Signal()
def __init__(self, blocking = False, parent = None, nude = False):
super().__init__(parent)
... | def QCapsulate(self, widget, name, blocking = False, nude = False) | Helper function that encapsulates QWidget into a QMainWindow | 3.309016 | 3.29774 | 1.003419 |
class QuickWindow(QtWidgets.QMainWindow):
class Signals(QtCore.QObject):
close = QtCore.Signal()
show = QtCore.Signal()
def __init__(self, blocking = False, parent = None):
super().__init__(parent)
self.propagat... | def QTabCapsulate(self, name, widget_list, blocking = False) | Helper function that encapsulates QWidget into a QMainWindow
:param widget_list: List of tuples : [(widget,"name"), (widget,"name"), ..] | 2.61023 | 2.657547 | 0.982195 |
self.treelist.reset_()
self.server = ServerListItem(
name = "Localhost", ip = "127.0.0.1", parent = self.root)
devices = []
for row in self.dm.camera_collection.get():
# print(pre, "makeCameraTree : row", row)
if (row["classname"] =... | def updateCameraTree(self) | self.server1 = ServerListItem(
name="First Server", ip="192.168.1.20", parent=self.root) | 5.021948 | 4.17897 | 1.201719 |
# *** When camera list has been closed, re-create the cameralist tree and update filterchains ***
# self.manage_cameras_win.signals.close.connect(self.updateCameraTree) # now put into save_camera_config_slot
# self.manage_cameras_win.signals.close.connect(self.filterchain_group.update) ... | def makeLogic(self) | self.configmenu.manage_cameras. triggered.connect(
self.manage_cameras_slot)
self.configmenu.memory_usage. triggered.connect(
self.memory_usage_slot) | 6.016417 | 5.379118 | 1.118476 |
container_list = []
mvision_container_list = []
for container in self.containers:
print("gui: serialize containers : container=", container)
container_list.append(container.serialize())
for container in self.mvision_containers:... | def serializeContainers(self) | Serializes the current view of open video grids (i.e. the view) | 3.415047 | 3.391465 | 1.006953 |
self.process_map = {} # each key is a list of started multiprocesses
# self.process_avail = {} # count instances
for mvision_class in self.mvision_classes:
name = mvision_class.name
tag = mvision_class.tag
num = mvision_class.max_instances ... | def startProcesses(self) | Create and start python multiprocesses
Starting a multiprocess creates a process fork.
In theory, there should be no problem in first starting the multithreading environment and after that perform forks (only the thread requestin the fork is copied), but in practice, all kinds of weird... | 4.107056 | 4.300865 | 0.954937 |
def slot_func():
cont = container.VideoContainerNxM(gpu_handler=self.gpu_handler,
filterchain_group=self.filterchain_group,
n_dim=n,
... | def make_grid_slot(self, n, m) | Create a n x m video grid, show it and add it to the list of video containers | 7.224446 | 6.592166 | 1.095914 |
ret = 0
try:
filepath = SiteCustomizeFile()
if filepath.is_injected():
logger.info("Pout has already been injected into {}".format(filepath))
else:
if filepath.inject():
logger.info("Injected pout into {}".format(filepath))
else:... | def main_inject(args) | mapped to pout.inject on the command line, makes it easy to make pout global
without having to actually import it in your python environment
.. since:: 2018-08-13
:param args: Namespace, the parsed CLI arguments passed into the application
:returns: int, the return code of the CLI | 4.555569 | 4.520798 | 1.007691 |
if args.site_packages:
logger.info(SitePackagesDir())
else:
logger.info("Python executable: {}".format(sys.executable))
logger.info("Python version: {}".format(platform.python_version()))
logger.info("Python site-packages: {}".format(SitePackagesDir()))
logger.info(... | def main_info(args) | Just prints out info about the pout installation
.. since:: 2018-08-20
:param args: Namespace, the parsed CLI arguments passed into the application
:returns: int, the return code of the CLI | 3.234375 | 3.153906 | 1.025514 |
try:
func(*args, **kwargs)
except Exception as e:
return e | def catch(func, *args, **kwargs) | Call the supplied function with the supplied arguments,
catching and returning any exception that it throws.
Arguments:
func: the function to run.
*args: positional arguments to pass into the function.
**kwargs: keyword arguments to pass into the function.
Returns:
If the fu... | 3.25982 | 3.847343 | 0.847291 |
start_time = time_module.time()
func(*args, **kwargs)
end_time = time_module.time()
return end_time - start_time | def time(func, *args, **kwargs) | Call the supplied function with the supplied arguments,
and return the total execution time as a float in seconds.
The precision of the returned value depends on the precision of
`time.time()` on your platform.
Arguments:
func: the function to run.
*args: positional arguments to pass i... | 2.291855 | 3.120487 | 0.734454 |
# https://github.com/nose-devs/nose/blob/master/nose/tools/nontrivial.py
pdb.Pdb(stdout=sys.__stdout__).set_trace(sys._getframe().f_back) | def set_trace() | Start a Pdb instance at the calling frame, with stdout routed to sys.__stdout__. | 2.966886 | 2.679972 | 1.107058 |
n_min = self.numargs + 2
if len(data) > 0:
if len(data) <= n_min:
raise ValueError("At least {} data points must be provided.".format(n_min))
lmom_ratios = lm.lmom_ratios(data, nmom=n_min)
elif not lmom_ratios:
raise Exception("Either ... | def lmom_fit(self, data=[], lmom_ratios=[]) | Fit the distribution function to the given data or given L-moments.
:param data: Data to use in calculating the distribution parameters
:type data: array_like
:param lmom_ratios: L-moments (ratios) l1, l2, t3, t4, .. to use in calculating the distribution parameters
:type lmom_ratios: a... | 2.894167 | 2.963572 | 0.976581 |
ratios = self.lmom_ratios(*args, nmom=nmom, **kwds)
moments = ratios[0:2]
moments += [ratio * moments[1] for ratio in ratios[2:]]
return moments | def lmom(self, *args, nmom=5, **kwds) | Compute the distribution's L-moments, e.g. l1, l2, l3, l4, ..
:param args: Distribution parameters in order of shape(s), loc, scale
:type args: float
:param nmom: Number of moments to calculate
:type nmom: int
:param kwds: Distribution parameters as named arguments. See :attr:`r... | 4.021928 | 3.779906 | 1.064029 |
if nmom > 20:
return ValueError("Parameter nmom too large. Max of 20.")
shapes, loc, scale = self._parse_args(*args, **kwds)
if scale <= 0:
return ValueError("Invalid scale parameter.")
return self._lmom_ratios(*shapes, loc=loc, scale=scale, nmom=nmom) | def lmom_ratios(self, *args, nmom=5, **kwds) | Compute the distribution's L-moment ratios, e.g. l1, l2, t3, t4, ..
:param args: Distribution parameters in order of shape(s), loc, scale
:type args: float
:param nmom: Number of moments to calculate
:type nmom: int
:param kwds: Distribution parameters as named arguments. See :a... | 4.392749 | 4.056904 | 1.082784 |
plugin_list = load_plugins()
module = sys.modules['__main__']
plugin_list.insert(0, ObjectSupplier(module))
return run_with_plugins(plugin_list) | def run() | Run all the test classes in the main module.
Returns: exit code as an integer.
The default behaviour (which may be overridden by plugins) is to return a 0
exit code if the test run succeeded, and 1 if it failed. | 7.113204 | 7.924142 | 0.897662 |
composite = core.PluginComposite(plugin_list)
to_run = composite.get_object_to_run()
test_run = core.TestRun(to_run, composite)
test_run.run()
return composite.get_exit_code() | def run_with_plugins(plugin_list) | Carry out a test run with the supplied list of plugin instances.
The plugins are expected to identify the object to run.
Parameters:
plugin_list: a list of plugin instances (objects which implement some subset of PluginInterface)
Returns: exit code as an integer.
The default behaviour (whic... | 5.387253 | 5.079962 | 1.060491 |
self.spec_file = args and args.specs or None
self.cwd = cwd or os.getcwd()
self.file = file
return self.spec_file is not None | def initialise(self, args=None, env=None, file=None, cwd=None) | Filthy hack: we provide file and cwd here rather than as constructor
args because Mr Hodgson decided to pass stdout as the only parameter
to __init__.
File should only be passed during tests. | 4.56517 | 4.512582 | 1.011654 |
if nmom <= 5:
return _samlmusmall(data, nmom)
else:
return _samlmularge(data, nmom) | def lmom_ratios(data, nmom=5) | Estimate `nmom` number of L-moments from a sample `data`.
:param data: Sequence of (sample) data
:type data: list or array-like sequence
:param nmom: number of L-moments to estimate
:type nmom: int
:return: L-moment ratios like this: l1, l2, t3, t4, t5, .. . As in: items 3 and higher are L-moment r... | 8.812089 | 9.734569 | 0.905237 |
url = self._construct_url(url_path)
payload = kwargs
payload.update({'api_token': self.api_token})
return self._make_request(url, payload, headers) | def _run(self, url_path, headers=None, **kwargs) | Requests API | 3.859255 | 3.596426 | 1.07308 |
warnings.warn(
"POEditor API v1 is deprecated. Use POEditorAPI._run method to call API v2",
DeprecationWarning, stacklevel=2
)
url = "https://poeditor.com/api/"
payload = kwargs
payload.update({'action': action, 'api_token': self.api_token})
... | def _apiv1_run(self, action, headers=None, **kwargs) | Kept for backwards compatibility of this client
See "self.clear_reference_language" | 4.643667 | 4.653016 | 0.997991 |
open_ = False if not data['open'] or data['open'] == '0' else True
public = False if not data['public'] or data['public'] == '0' else True
output = {
'created': parse_datetime(data['created']),
'id': int(data['id']),
'name': data['name'],
... | def _project_formatter(self, data) | Project object | 3.991826 | 3.796995 | 1.051312 |
data = self._run(
url_path="projects/list"
)
projects = data['result'].get('projects', [])
return [self._project_formatter(item) for item in projects] | def list_projects(self) | Returns the list of projects owned by user. | 6.249891 | 5.50211 | 1.135908 |
description = description or ''
data = self._run(
url_path="projects/add",
name=name,
description=description
)
return data['result']['project']['id'] | def create_project(self, name, description=None) | creates a new project. Returns the id of the project (if successful) | 6.088038 | 5.465326 | 1.113939 |
kwargs = {}
if name is not None:
kwargs['name'] = name
if description is not None:
kwargs['description'] = description
if reference_language is not None:
kwargs['reference_language'] = reference_language
data = self._run(
... | def update_project(self, project_id, name=None, description=None,
reference_language=None) | Updates project settings (name, description, reference language)
If optional parameters are not sent, their respective fields are not updated. | 2.557462 | 2.62539 | 0.974126 |
data = self._run(
url_path="projects/view",
id=project_id
)
return self._project_formatter(data['result']['project']) | def view_project_details(self, project_id) | Returns project's details. | 8.643789 | 7.639503 | 1.13146 |
data = self._run(
url_path="languages/list",
id=project_id
)
return data['result'].get('languages', []) | def list_project_languages(self, project_id) | Returns project languages, percentage of translation done for each and the
datetime (UTC - ISO 8601) when the last change was made. | 7.356534 | 7.577388 | 0.970854 |
self._run(
url_path="languages/add",
id=project_id,
language=language_code
)
return True | def add_language_to_project(self, project_id, language_code) | Adds a new language to project | 7.59166 | 6.99683 | 1.085014 |
kwargs = {}
if fuzzy_trigger is not None:
kwargs['fuzzy_trigger'] = fuzzy_trigger
data = self._run(
url_path="terms/update",
id=project_id,
data=json.dumps(data),
**kwargs
)
return data['result']['terms'] | def update_terms(self, project_id, data, fuzzy_trigger=None) | Updates project terms. Lets you change the text, context, reference, plural and tags.
>>> data = [
{
"term": "Add new list",
"context": "",
"new_term": "Save list",
"new_context": "",
"reference"... | 3.459944 | 3.439026 | 1.006082 |
data = self._run(
url_path="terms/add_comment",
id=project_id,
data=json.dumps(data)
)
return data['result']['terms'] | def add_comment(self, project_id, data) | Adds comments to existing terms.
>>> data = [
{
"term": "Add new list",
"context": "",
"comment": "This is a button"
},
{
"term": "one project found",
"context": ""... | 6.996257 | 5.871839 | 1.191493 |
kwargs = {}
if fuzzy_trigger is not None:
kwargs['fuzzy_trigger'] = fuzzy_trigger
data = self._run(
url_path="languages/update",
id=project_id,
language=language_code,
data=json.dumps(data),
**kwargs
)
... | def update_project_language(self, project_id, language_code, data, fuzzy_trigger=None) | Inserts / overwrites translations.
>>> data = [
{
"term": "Projects",
"context": "project list",
"translation": {
"content": "Des projets",
"fuzzy": 0
}
}
] | 3.425697 | 3.460057 | 0.99007 |
if file_type not in self.FILE_TYPES:
raise POEditorArgsException(
'content_type: file format {}'.format(self.FILE_TYPES))
if filters and isinstance(filters, str) and filters not in self.FILTER_BY:
raise POEditorArgsException(
"filters - f... | def export(self, project_id, language_code, file_type='po', filters=None,
tags=None, local_file=None) | Return terms / translations
filters - filter by self._filter_by
tags - filter results by tags;
local_file - save content into it. If None, save content into
random temp file.
>>> tags = 'name-of-tag'
>>> tags = ["name-of-tag"]
>>> tags = ["name-of-tag", "nam... | 2.994526 | 2.951842 | 1.01446 |
options = [
self.UPDATING_TERMS,
self.UPDATING_TERMS_TRANSLATIONS,
self.UPDATING_TRANSLATIONS
]
if updating not in options:
raise POEditorArgsException(
'Updating arg must be in {}'.format(options)
)
op... | def _upload(self, project_id, updating, file_path, language_code=None,
overwrite=False, sync_terms=False, tags=None, fuzzy_trigger=None) | Internal: updates terms / translations
File uploads are limited to one every 30 seconds | 2.823787 | 2.775344 | 1.017455 |
return self._upload(
project_id=project_id,
updating=self.UPDATING_TERMS,
file_path=file_path,
language_code=language_code,
overwrite=overwrite,
sync_terms=sync_terms,
tags=tags,
fuzzy_trigger=fuzzy_trigger
... | def update_terms(self, project_id, file_path=None, language_code=None,
overwrite=False, sync_terms=False, tags=None, fuzzy_trigger=None) | Updates terms
overwrite: set it to True if you want to overwrite translations
sync_terms: set it to True if you want to sync your terms (terms that
are not found in the uploaded file will be deleted from project
and the new ones added). Ignored if updating = translations
... | 2.15209 | 2.263 | 0.95099 |
return self._upload(
project_id=project_id,
updating=self.UPDATING_TERMS_TRANSLATIONS,
file_path=file_path,
language_code=language_code,
overwrite=overwrite,
sync_terms=sync_terms,
tags=tags,
fuzzy_trigger=f... | def update_terms_translations(self, project_id, file_path=None,
language_code=None, overwrite=False,
sync_terms=False, tags=None, fuzzy_trigger=None) | Updates terms translations
overwrite: set it to True if you want to overwrite translations
sync_terms: set it to True if you want to sync your terms (terms that
are not found in the uploaded file will be deleted from project
and the new ones added). Ignored if updating = transla... | 2.153485 | 2.231086 | 0.965218 |
return self._upload(
project_id=project_id,
updating=self.UPDATING_TRANSLATIONS,
file_path=file_path,
language_code=language_code,
overwrite=overwrite,
fuzzy_trigger=fuzzy_trigger
) | def update_translations(self, project_id, file_path=None,
language_code=None, overwrite=False, fuzzy_trigger=None) | Updates translations
overwrite: set it to True if you want to overwrite definitions
fuzzy_trigger: set it to True to mark corresponding translations from the
other languages as fuzzy for the updated values | 2.553104 | 2.822958 | 0.904407 |
data = self._run(
url_path="contributors/list",
id=project_id,
language=language_code
)
return data['result'].get('contributors', []) | def list_contributors(self, project_id=None, language_code=None) | Returns the list of contributors | 5.680344 | 5.536276 | 1.026022 |
self._run(
url_path="contributors/add",
id=project_id,
name=name,
email=email,
language=language_code
)
return True | def add_contributor(self, project_id, name, email, language_code) | Adds a contributor to a project language | 4.534467 | 4.846455 | 0.935626 |
self._run(
url_path="contributors/add",
id=project_id,
name=name,
email=email,
admin=True
)
return True | def add_administrator(self, project_id, name, email) | Adds a contributor to a project language | 6.319361 | 6.110998 | 1.034096 |
self._run(
url_path="contributors/remove",
id=project_id,
email=email,
language=language
)
return True | def remove_contributor(self, project_id, email, language) | Removes a contributor | 5.638948 | 5.871542 | 0.960386 |
html = html.replace('SLs.sls=', '').replace(';SLs.showSuggestion();', '')
html = json.loads(html)
return html['suggestions'] | def parse_stations(html) | Strips JS code, loads JSON | 12.405407 | 10.089741 | 1.229507 |
# parse data from the details view
rsp = requests.get(data['details'])
soup = BeautifulSoup(rsp.text, "html.parser")
# get departure delay
delay_departure_raw = soup.find('div', class_="routeStart").find('span', class_=["delay", "delayOnTime"])
if delay_departure_raw:
delay_departu... | def parse_delay(data) | Prase the delay | 2.720852 | 2.728339 | 0.997256 |
original = datetime.strptime(original, '%H:%M')
delayed = datetime.strptime(delay, '%H:%M')
diff = delayed - original
return diff.total_seconds() // 60 | def calculate_delay(original, delay) | Calculate the delay | 2.728044 | 2.839602 | 0.960714 |
query = {
'start': 1,
'S': station + '?',
'REQ0JourneyStopsB': limit
}
rsp = requests.get('http://reiseauskunft.bahn.de/bin/ajax-getstop.exe/dn', params=query)
return parse_stations(rsp.text) | def stations(self, station, limit=10) | Find stations for given queries
Args:
station (str): search query
limit (int): limit number of results | 12.048142 | 13.357241 | 0.901993 |
query = {
'S': origin,
'Z': destination,
'date': dt.strftime("%d.%m.%y"),
'time': dt.strftime("%H:%M"),
'start': 1,
'REQ0JourneyProduct_opt0': 1 if only_direct else 0
}
rsp = requests.get('http://mobile.bahn.de/bin/... | def connections(self, origin, destination, dt=datetime.now(), only_direct=False) | Find connections between two stations
Args:
origin (str): origin station
destination (str): destination station
dt (datetime): date and time for query
only_direct (bool): only direct connections | 6.616667 | 6.831784 | 0.968512 |
chunklen = int(math.ceil(float(len(sequence)) / float(n)))
return [
sequence[ i*chunklen : (i+1)*chunklen ] for i in range(n)
] | def _scatter(sequence, n) | Scatters elements of ``sequence`` into ``n`` blocks. | 3.167078 | 3.086982 | 1.025946 |
tag = tag if tag else None
tasks = self._api.lease(
numTasks=num_tasks,
seconds=seconds,
groupByTag=(tag is not None),
tag=tag,
)
if not len(tasks):
raise QueueEmpty
task = tasks[0]
return totask(task) | def lease(self, seconds=600, num_tasks=1, tag=None) | Acquires a lease on the topmost N unowned tasks in the specified queue.
Required query parameters: leaseSecs, numTasks | 6.458703 | 6.287451 | 1.027237 |
try:
return self._api.purge()
except AttributeError:
while True:
lst = self.list()
if len(lst) == 0:
break
for task in lst:
self.delete(task)
self.wait()
return self | def purge(self) | Deletes all tasks in the queue. | 5.553281 | 4.70793 | 1.179559 |
global LOOP
if not callable(stop_fn) and stop_fn is not None:
raise ValueError("stop_fn must be a callable. " + str(stop_fn))
elif not callable(stop_fn):
stop_fn = lambda: False
def random_exponential_window_backoff(n):
n = min(n, min_backoff_window)
# 120 sec max b/c on a... | def poll(
self, lease_seconds=LEASE_SECONDS, tag=None,
verbose=False, execute_args=[], execute_kwargs={},
stop_fn=None, backoff_exceptions=[], min_backoff_window=30,
max_backoff_window=120, log_fn=None
) | Poll a queue until a stop condition is reached (default forever). Note
that this function is not thread safe as it requires a global variable
to intercept SIGINT.
lease_seconds: each task should be leased for this many seconds
tag: if specified, query for only tasks that match this tag
execute_args ... | 4.636437 | 4.573469 | 1.013768 |
body = {
"payload": task.payload(),
"queueName": self._queue_name,
"groupByTag": True,
"tag": task.__class__.__name__
}
def cloud_insertion(api):
api.insert(body, delay_seconds)
if len(self._threads):
self.put(cloud_insertion)
else:
cloud_insertion(se... | def insert(self, task, args=[], kwargs={}, delay_seconds=0) | Insert a task into an existing queue. | 6.364992 | 6.117147 | 1.040516 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.