code
string
signature
string
docstring
string
loss_without_docstring
float64
loss_with_docstring
float64
factor
float64
# begin arc support block ######################## try: p.large_arc return p.point(t) except: pass # end arc support block ########################## deg = len(p) - 1 if deg == 3: return p[0] + t*( 3*(p[1] - p[0]) + t*( 3*(p[0] +...
def bezier_point(p, t)
Evaluates the Bezier curve given by it's control points, p, at t. Note: Uses Horner's rule for cubic and lower order Bezier curves. Warning: Be concerned about numerical stability when using this function with high order curves.
2.635218
2.559951
1.029402
if len(p) == 4: coeffs = (-p[0] + 3*(p[1] - p[2]) + p[3], 3*(p[0] - 2*p[1] + p[2]), 3*(p[1]-p[0]), p[0]) elif len(p) == 3: coeffs = (p[0] - 2*p[1] + p[2], 2*(p[1] - p[0]), p[0]) elif len(p) == 2: ...
def bezier2polynomial(p, numpy_ordering=True, return_poly1d=False)
Converts a tuple of Bezier control points to a tuple of coefficients of the expanded polynomial. return_poly1d : returns a numpy.poly1d object. This makes computations of derivatives/anti-derivatives and many other operations quite quick. numpy_ordering : By default (to accommodate numpy) the coefficie...
2.310863
2.373061
0.97379
if isinstance(poly, poly1d): c = poly.coeffs else: c = poly order = len(c)-1 if order == 3: bpoints = (c[3], c[2]/3 + c[3], (c[1] + 2*c[2])/3 + c[3], c[0] + c[1] + c[2] + c[3]) elif order == 2: bpoints = (c[2], c[1]/2 + c[2], c[0] + c[1] + c[2]...
def polynomial2bezier(poly)
Converts a cubic or lower order Polynomial object (or a sequence of coefficients) to a CubicBezier, QuadraticBezier, or Line object as appropriate.
2.195612
2.188767
1.003127
def split_bezier_recursion(bpoints_left_, bpoints_right_, bpoints_, t_): if len(bpoints_) == 1: bpoints_left_.append(bpoints_[0]) bpoints_right_.append(bpoints_[0]) else: new_points = [None]*(len(bpoints_) - 1) bpoints_left_.append(bpoints_[0]) ...
def split_bezier(bpoints, t)
Uses deCasteljau's recursion to split the Bezier curve at t into two Bezier curves of the same order.
1.762626
1.714891
1.027836
local_extremizers = [0, 1] if len(p) == 4: # cubic case a = [p.real for p in p] denom = a[0] - 3*a[1] + 3*a[2] - a[3] if denom != 0: delta = a[1]**2 - (a[0] + a[1])*a[2] + a[2]**2 + (a[0] - a[1])*a[3] if delta >= 0: # otherwise no local extrema ...
def bezier_real_minmax(p)
returns the minimum and maximum for any real cubic bezier
3.166041
3.161221
1.001525
# begin arc support block ######################## try: bla = bez.large_arc return bez.bbox() # added to support Arc objects except: pass # end arc support block ########################## if len(bez) == 4: xmin, xmax = bezier_real_minmax([p.real for p in bez]...
def bezier_bounding_box(bez)
returns the bounding box for the segment in the form (xmin, xmax, ymin, ymax). Warning: For the non-cubic case this is not particularly efficient.
3.319636
3.272073
1.014536
return max(0, min(b, d) - max(a, c))
def interval_intersection_width(a, b, c, d)
returns the width of the intersection of intervals [a,b] and [c,d] (thinking of these as intervals on the real number line)
3.432924
3.204555
1.071264
xmin1, xmax1, ymin1, ymax1 = box1 xmin2, xmax2, ymin2, ymax2 = box2 if interval_intersection_width(xmin1, xmax1, xmin2, xmax2) and \ interval_intersection_width(ymin1, ymax1, ymin2, ymax2): return True else: return False
def boxes_intersect(box1, box2)
Determines if two rectangles, each input as a tuple (xmin, xmax, ymin, ymax), intersect.
2.087337
2.105848
0.99121
maxits = int(ceil(1-log(tol_deC/longer_length)/log(2))) pair_list = [BPair(bez1, bez2, 0.5, 0.5)] intersection_list = [] k = 0 approx_point_set = ApproxSolutionSet(tol) while pair_list and k < maxits: new_pairs = [] delta = 0.5**(k + 2) for pair in pair_list: ...
def bezier_intersections(bez1, bez2, longer_length, tol=1e-8, tol_deC=1e-8)
INPUT: bez1, bez2 = [P0,P1,P2,...PN], [Q0,Q1,Q2,...,PN] defining the two Bezier curves to check for intersections between. longer_length - the length (or an upper bound) on the longer of the two Bezier curves. Determines the maximum iterations needed together with tol. tol - is the smallest distanc...
2.585391
2.595648
0.996049
# The method here is to translate (shift) then rotate the complex plane so # that line starts at the origin and proceeds along the positive real axis. # After this transformation, the intersection points are the real roots of # the imaginary component of the bezier for which the real component is ...
def bezier_by_line_intersections(bezier, line)
Returns tuples (t1,t2) such that bezier.point(t1) ~= line.point(t2).
4.478591
4.444547
1.00766
if not isinstance(group, Element): raise TypeError('Must provide an xml.etree.Element object. ' 'Instead you provided {0}'.format(type(group))) # Stop right away if the group_selector rejects this group if not group_filter(group): return [] # To handle the ...
def flatten_all_paths(group, group_filter=lambda x: True, path_filter=lambda x: True, path_conversions=CONVERSIONS, group_search_xpath=SVG_GROUP_TAG)
Returns the paths inside a group (recursively), expressing the paths in the base coordinates. Note that if the group being passed in is nested inside some parent group(s), we cannot take the parent group(s) into account, because xml.etree.Element has no pointer to its parent. You should use Documen...
3.533838
3.44628
1.025406
if not any(group_to_flatten is descendant for descendant in root.iter()): warnings.warn('The requested group_to_flatten is not a ' 'descendant of root') # We will shortcut here, because it is impossible for any paths # to be returned anyhow. return [] ...
def flatten_group(group_to_flatten, root, recursive=True, group_filter=lambda x: True, path_filter=lambda x: True, path_conversions=CONVERSIONS, group_search_xpath=SVG_GROUP_TAG)
Flatten all the paths in a specific group. The paths will be flattened into the 'root' frame. Note that root needs to be an ancestor of the group that is being flattened. Otherwise, no paths will be returned.
4.018612
3.956022
1.015822
return flatten_all_paths(self.tree.getroot(), group_filter, path_filter, path_conversions)
def flatten_all_paths(self, group_filter=lambda x: True, path_filter=lambda x: True, path_conversions=CONVERSIONS)
Forward the tree of this document into the more general flatten_all_paths function and return the result.
3.732287
3.554447
1.050033
# If not given a parent, assume that the path does not have a group if group is None: group = self.tree.getroot() # If given a list of strings (one or more), assume it represents # a sequence of nested group names elif all(isinstance(elem, str) for elem in ...
def add_path(self, path, attribs=None, group=None)
Add a new path to the SVG.
3.840186
3.771315
1.018262
group = self.tree.getroot() # Drill down through the names until we find the desired group while len(nested_names): prev_group = group next_name = nested_names.pop(0) for elem in group.iterfind(SVG_GROUP_TAG, SVG_NAMESPACE): if elem.ge...
def get_or_add_group(self, nested_names, name_attr='id')
Get a group from the tree, or add a new one with the given name structure. `nested_names` is a list of strings which represent group names. Each group name will be nested inside of the previous group name. `name_attr` is the group attribute that is being used to represent the g...
3.714827
3.791585
0.979756
if parent is None: parent = self.tree.getroot() elif not self.contains_group(parent): warnings.warn('The requested group {0} does not belong to ' 'this Document'.format(parent)) if group_attribs is None: group_attribs = {} ...
def add_group(self, group_attribs=None, parent=None)
Add an empty group element to the SVG.
3.689941
3.228958
1.142765
if filename is None: filename = self.original_filename # write to a (by default temporary) file with open(filename, 'w') as output_svg: output_svg.write(etree.tostring(self.tree.getroot())) open_in_browser(filename)
def display(self, filename=None)
Displays/opens the doc using the OS's default application.
5.12195
5.064934
1.011257
A = np.array([[-1, 3, -3, 1], # transforms cubic bez to standard poly [ 3, -6, 3, 0], [-3, 3, 0, 0], [ 1, 0, 0, 0]]) B = [seg.bpoints() for seg in path] return np.dot(B, np.dot(A, np.power(tvals, [[3],[2],[1],[0]])))
def points_in_each_seg(path, tvals)
Compute seg.point(t) for each seg in path and each t in tvals.
4.257467
4.071295
1.045728
if not transform_str: return np.identity(3) elif not isinstance(transform_str, str): raise TypeError('Must provide a string to parse') total_transform = np.identity(3) transform_substrs = transform_str.split(')')[:-1] # Skip the last element, because it should be empty for sub...
def parse_transform(transform_str)
Converts a valid SVG transformation string into a 3x3 matrix. If the string is empty or null, this returns a 3x3 identity matrix
3.462421
3.28178
1.055044
kink_list = [] for idx in range(len(path)): if idx == 0 and not path.isclosed(): continue try: u = path[(idx - 1) % len(path)].unit_tangent(1) v = path[idx].unit_tangent(0) u_dot_v = u.real*v.real + u.imag*v.imag flag = False ...
def kinks(path, tol=1e-8)
returns indices of segments that start on a non-differentiable joint.
2.913264
2.839588
1.025946
if len(path) == 1: return path assert path.iscontinuous() sharp_kinks = [] new_path = [path[0]] for idx in range(len(path)): if idx == len(path)-1: if not path.isclosed(): continue else: seg1 = new_path[0] else: ...
def smoothed_path(path, maxjointsize=3, tightness=1.99, ignore_unfixable_kinks=False)
returns a path with no non-differentiable joints.
3.070412
3.047277
1.007592
if filename is None: filename = 'display_temp.svg' self.save(filename) open_in_browser(filename)
def display(self, filename=None)
Displays/opens the doc using the OS's default application.
5.831529
5.475214
1.065078
value = value.lstrip('#') lv = len(value) return tuple(int(value[i:i+lv//3], 16) for i in range(0, lv, lv//3))
def hex2rgb(value)
Converts a hexadeximal color string to an RGB 3-tuple EXAMPLE ------- >>> hex2rgb('#0000FF') (0, 0, 255)
1.460831
2.232524
0.654341
return abs(a - b) < (atol + rtol * abs(b))
def isclose(a, b, rtol=1e-5, atol=1e-8)
This is essentially np.isclose, but slightly faster.
2.697083
2.530086
1.066005
# If just the name of the file was given, check if it's in the Current # Working Directory. if not os.path.isfile(file_location): file_location = os.path.join(os.getcwd(), file_location) if not os.path.isfile(file_location): raise IOError("\n\nFile not found.") # For some rea...
def open_in_browser(file_location)
Attempt to open file located at file_location in the default web browser.
4.104213
3.962272
1.035823
cx = ellipse.get('cx', 0) cy = ellipse.get('cy', 0) rx = ellipse.get('rx', None) ry = ellipse.get('ry', None) r = ellipse.get('r', None) if r is not None: rx = ry = float(r) else: rx = float(rx) ry = float(ry) cx = float(cx) cy = float(cy) d = '' ...
def ellipse2pathd(ellipse)
converts the parameters from an ellipse or a circle to a string for a Path object d-attribute
1.508705
1.564664
0.964236
points = COORD_PAIR_TMPLT.findall(polyline_d) closed = (float(points[0][0]) == float(points[-1][0]) and float(points[0][1]) == float(points[-1][1])) # The `parse_path` call ignores redundant 'z' (closure) commands # e.g. `parse_path('M0 0L100 100Z') == parse_path('M0 0L100 100L0 0Z')...
def polyline2pathd(polyline_d, is_polygon=False)
converts the string from a polyline points-attribute to a string for a Path object d-attribute
3.665249
3.796693
0.965379
x0, y0 = float(rect.get('x', 0)), float(rect.get('y', 0)) w, h = float(rect.get('width', 0)), float(rect.get('height', 0)) x1, y1 = x0 + w, y0 x2, y2 = x0 + w, y0 + h x3, y3 = x0, y0 + h d = ("M{} {} L {} {} L {} {} L {} {} z" "".format(x0, y0, x1, y1, x2, y2, x3, y3)) return ...
def rect2pathd(rect)
Converts an SVG-rect element to a Path d-string. The rectangle will start at the (x,y) coordinate specified by the rectangle object and proceed counter-clockwise.
1.686509
1.685979
1.000315
return svg2paths(svg_file_location=svg_file_location, return_svg_attributes=return_svg_attributes, convert_circles_to_paths=convert_circles_to_paths, convert_ellipses_to_paths=convert_ellipses_to_paths, convert_lines_to_paths=c...
def svg2paths2(svg_file_location, return_svg_attributes=True, convert_circles_to_paths=True, convert_ellipses_to_paths=True, convert_lines_to_paths=True, convert_polylines_to_paths=True, convert_polygons_to_paths=True, ...
Convenience function; identical to svg2paths() except that return_svg_attributes=True by default. See svg2paths() docstring for more info.
1.164548
1.24485
0.935493
if type(instance) is ModbusDevice: post_save.send_robust(sender=Device, instance=instance.modbus_device) elif type(instance) is ModbusVariable: post_save.send_robust(sender=Variable, instance=instance.modbus_variable) elif type(instance) is ExtendedModbusVariable: post_save.send...
def _reinit_daq_daemons(sender, instance, **kwargs)
update the daq daemon configuration when changes be applied in the models
2.140405
2.088731
1.024739
if self.inst is None: return if variable_instance.visavariable.device_property.upper() == 'PRESENT_VALUE': return self.parse_value(self.inst.query('?U6P0')) elif variable_instance.visavariable.device_property.upper() == 'PRESENT_VALUE_MANUAL_C_FREQ': ...
def read_data(self, variable_instance)
read values from the device
8.683577
7.965531
1.090144
if dtype.str in ['<f8']: return 'double' elif dtype.str in ['<f4']: return 'single' elif dtype.str in ['<i8']: return 'int64' elif dtype.str in ['<u8']: return 'uint64' elif dtype.str in ['<i4']: return 'int32' elif dtype.str in ['<u4']: retur...
def dtype_to_matlab_class(dtype)
convert dtype to matlab class string
1.421919
1.404332
1.012523
if not driver_ok: logger.error("Visa driver NOT ok") return False visa_backend = '@py' # use PyVISA-py as backend if hasattr(settings, 'VISA_BACKEND'): visa_backend = settings.VISA_BACKEND try: self.rm = visa.ResourceManager(visa...
def connect(self)
establish a connection to the Instrument
3.170192
3.185118
0.995314
bin_str_out = '' if isinstance(values, integer_types): bin_str_out = bin(values)[2:].zfill(16) bin_str_out = bin_str_out[::-1] else: for value in values: bin_str = bin(value)[2:].zfill(16) bin_str = bin_str[::-1] bin_str_out = bin_str + bin_s...
def decode_bcd(values)
decode bcd as int to dec
2.063571
2.03626
1.013412
for index in range(len(l)): if l[index] == value: return None if l[index] > value: return index
def find_gap(l, value)
try to find a address gap in the list of modbus registers
2.72663
2.405129
1.133673
framer = None if self._framer == 0: # Socket Framer framer = ModbusSocketFramer elif self._framer == 1: # RTU Framer framer = ModbusRtuFramer elif self._framer == 2: # ASCII Framer framer = ModbusAsciiFramer elif self._framer == 3: ...
def _connect(self)
connect to the modbus slave (server)
1.779059
1.709861
1.04047
if variable_id not in self.variables: return False if not self.variables[variable_id].writeable: return False if self.variables[variable_id].modbusvariable.function_code_read == 3: # write register if 0 <= self.variables[variable_id].mod...
def write_data(self, variable_id, value, task)
write value to single modbus register or coil
2.253287
2.18623
1.030672
for process in queryset: process.stop(signum=signal.SIGKILL)
def kill_process(modeladmin, request, queryset)
restarts a dedicated process :return:
5.237147
8.549936
0.612536
qs = model_admin.get_queryset(request) qs.filter(id__range=(1, 99)) for item in qs: dp = DeviceProtocol.objects.filter(pk=item.id).first() if dp: yield (dp.pk, dp.app_name)
def lookups(self, request, model_admin)
Returns a list of tuples. The first element in each tuple is the coded value for the option that will appear in the URL query. The second element is the human-readable name for the option that will appear in the right sidebar.
5.289716
5.153407
1.02645
if self.value() is not None: if self.value() > 0: return queryset.filter(parent_process_id=self.value())
def queryset(self, request, queryset)
Returns the filtered queryset based on the value provided in the query string and retrievable via `self.value()`.
3.551549
4.642987
0.764928
if type(instance) is OneWireDevice: post_save.send_robust(sender=Device, instance=instance.onewire_device) elif type(instance) is OneWireVariable: post_save.send_robust(sender=Variable, instance=instance.onewire_variable) elif type(instance) is ExtendedOneWireVariable: post_save...
def _reinit_daq_daemons(sender, instance, **kwargs)
update the daq daemon configuration when changes be applied in the models
2.334333
2.299163
1.015297
''' write value to the instrument/device ''' output = [] if not driver_visa_ok: logger.info("Visa-device-write data-visa NOT ok") return output for item in self.variables.values(): if not (item.visavariable.variable_type == 0 and item.i...
def write_data(self,variable_id, value, task)
write value to the instrument/device
5.743341
5.411112
1.061397
output = [] if not driver_visa_ok: logger.info('Request Data Visa Driver Not Ok') return output for item in self.variables.values(): if not item.visavariable.variable_type == 1: # skip all config values continu...
def request_data(self)
request data from the instrument/device
10.848678
10.219593
1.061557
''' from: https://stackoverflow.com/questions/7835272/django-operationalerror-2006-mysql-server-has-gone-away ''' # mysql is lazily connected to in django. # connection.connection is None means # you have not connected to mysql before if connection.connection and not connection.is_usable(): ...
def check_db_connection()
from: https://stackoverflow.com/questions/7835272/django-operationalerror-2006-mysql-server-has-gone-away
10.099551
6.112514
1.652274
# check if a process is already running if access(self.pid_file_name, F_OK): # read the pid file pid = self.read_pid() try: kill(pid, 0) # check if process is running self.stderr.write("process is already running\n") ...
def demonize(self)
do the double fork magic
2.21988
2.190408
1.013455
pid = self.read_pid() if pid != getpid() or force_del: logger.debug('process %d tried to delete pid' % getpid()) return False if access(self.pid_file_name, F_OK): try: remove(self.pid_file_name) # remove the old pid file ...
def delete_pid(self, force_del=False)
delete the pid file
4.039641
3.851564
1.048831
# demonize if self.run_as_daemon: if not self.demonize(): self.delete_pid() sys.exit(0) # recreate the DB connection if connection.connection is not None: connection.connection.close() connection.connection = N...
def start(self)
start the scheduler
3.32837
3.324967
1.001023
try: master_process = BackgroundProcess.objects.filter(pk=self.process_id).first() if master_process: master_process.last_update = now() master_process.message = 'init child processes' master_process.save() else: ...
def run(self)
the main loop
3.956845
3.90022
1.014518
try: while True: wpid, status = waitpid(-1, WNOHANG) if not wpid: break # self.stdout.write('%d,%d\n' % (wpid, status)) except: pass
def handle_chld(self, sig, frame)
SIGCHLD handling :param sig: :param frame: :return:
4.432962
4.204303
1.054387
BackgroundProcess.objects.filter(pk=self.process_id).update( last_update=now(), message='restarting..') timeout = time() + 60 # wait max 60 seconds self.kill_processes(signal.SIGTERM) while self.PROCESSES and time() < timeout: sleep(0.1) ...
def restart(self)
restart all child processes
5.753253
5.42583
1.060345
if self.pid is None: self.pid = self.read_pid() if self.pid is None: sp = BackgroundProcess.objects.filter(pk=1).first() if sp: self.pid = sp.pid if self.pid is None or self.pid == 0: logger.error("can't determine process ...
def stop(self, sig=signal.SIGTERM)
stop the scheduler and stop all processes
3.515559
3.403827
1.032825
if process is None: return False # start new child process pid = fork() if pid != 0: # parent process process.pid = pid self.PROCESSES[process.process_id] = process connections.close_all() return True ...
def spawn_process(self, process=None)
spawn a new process
4.599548
4.591013
1.001859
if self.pid is None: self.pid = self.read_pid() if self.pid is None: sp = BackgroundProcess.objects.filter(pk=1).first() if sp: self.pid = sp.pid if self.pid is None or self.pid == 0: self.stderr.write("%s: can't determine...
def status(self)
write the current daemon status to stdout
3.917259
3.668472
1.067818
logger.debug('PID %d, received signal: %d' % (self.pid, signum)) self.SIG_QUEUE.append(signum)
def signal(self, signum=None, frame=None)
handle signals
5.567117
5.590875
0.995751
db.connections.close_all() # update process info BackgroundProcess.objects.filter(pk=self.process_id).update( pid=self.pid, last_update=now(), running_since=now(), done=False, failed=False, message='init process..',...
def pre_init_process(self)
will be executed after process fork
5.483538
5.115386
1.071969
BackgroundProcess.objects.filter(pk=self.process_id ).update(pid=0, last_update=now(), message='stopping..') # run the cleanup self.cleanup() BackgroundProcess.objects.filter(pk=self.process_id).update(pid=0, ...
def stop(self, signum=None, frame=None)
handel's a termination signal
5.416118
5.475087
0.98923
self.device = Device.objects.filter(protocol__daq_daemon=1, active=1, id=self.device_id).first() if not self.device: logger.error("Error init_process for %s" % self.device_id) return False self.dt_set = min(self.dt_set, self.device.polling_interval) self....
def init_process(self)
init a standard daq process for a single device
5.186388
4.693934
1.104913
for item in Device.objects.filter(protocol__daq_daemon=1, active=1, id__in=self.device_ids): try: tmp_device = item.get_device_instance() if tmp_device is not None: self.devices[item.pk] = tmp_device self.dt_set = min(...
def init_process(self)
init a standard daq process for multiple devices
5.342032
4.975561
1.073654
if type(instance) is SMbusDevice: post_save.send_robust(sender=Device, instance=instance.smbus_device) elif type(instance) is SMbusVariable: post_save.send_robust(sender=Variable, instance=instance.smbus_variable) elif type(instance) is ExtendedSMbusVariable: post_save.send_robu...
def _reinit_daq_daemons(sender, instance, **kwargs)
update the daq daemon configuration when changes be applied in the models
2.589634
2.560154
1.011515
if self.inst is None: return if variable_instance.visavariable.device_property.upper() == 'PRESENT_VALUE': return self.parse_value(self.inst.query('?U6P0')) elif variable_instance.visavariable.device_property.upper() == 'PRESENT_VALUE_DCV': return sel...
def read_data(self,variable_instance)
read values from the device
2.07907
1.992593
1.043399
variable = self._variables[variable_id] if task.property_name != '': # write the freq property to VariableProperty use that for later read vp = VariableProperty.objects.update_or_create_property(variable=variable, name=task.property_name.upper(), ...
def write_data(self,variable_id, value, task)
write values to the device
12.504788
12.517835
0.998958
if type(instance) is SystemStatVariable: post_save.send_robust(sender=Variable, instance=instance.system_stat_variable) elif type(instance) is ExtendedSystemStatVariable: post_save.send_robust(sender=Variable, instance=Variable.objects.get(pk=instance.pk)) elif type(instance) is Extende...
def _reinit_daq_daemons(sender, instance, **kwargs)
update the daq daemon configuration when changes be applied in the models
2.973961
2.932687
1.014074
if self.inst is None: return if variable_instance.visavariable.device_property.upper() == 'vrms_chan1': return self.parse_value(self.inst.query(':MEAS:ITEM? VRMS,CHAN1')) return None
def read_data(self, variable_instance)
read values from the device
14.023211
11.642852
1.204448
if not issubclass(sender, WidgetContentModel): return # delete WidgetContent Entry wcs = WidgetContent.objects.filter( content_pk=instance.pk, content_model=('%s' % instance.__class__).replace("<class '", '').replace("'>", '')) for wc in wcs: logger.debug('delete wc...
def _delete_widget_content(sender, instance, **kwargs)
delete the widget content instance when a WidgetContentModel is deleted
5.200956
4.670565
1.11356
if not issubclass(sender, WidgetContentModel): return # create a WidgetContent Entry if created: instance.create_widget_content_entry() return
def _create_widget_content(sender, instance, created=False, **kwargs)
create a widget content instance when a WidgetContentModel is deleted
7.154974
5.021478
1.424874
if type(instance) is Device: try: bp = BackgroundProcess.objects.get(pk=instance.protocol_id) except: return False bp.restart() elif type(instance) is Variable: try: bp = BackgroundProcess.objects.get(pk=instance.device.protocol_id) ...
def _reinit_daq_daemons(sender, instance, **kwargs)
update the daq daemon configuration when changes be applied in the models
2.845756
2.787354
1.020952
#if not access(path.dirname(self.log_file_name), W_OK): # self.stderr.write("logfile path is not writeable\n") # sys.exit(0) #if access(self.log_file_name, F_OK) and not access(self.log_file_name, W_OK): # self.stderr.write("logfile is not writeable\n") # sys.exit(0) if mes...
def add(message, level=0, user=None, message_short=None,log_file_name='%s/pyscada_daemon.log' % settings.BASE_DIR,)
add a new massage/error notice to the log <0 - Debug 1 - Emergency 2 - Critical 3 - Errors 4 - Alerts 5 - Warnings 6 - Notification (webnotice) 7 - Information (webinfo) 8 - Notification (notice) 9 - Information (info)
2.559479
2.706424
0.945705
if type(instance) is VISADevice: post_save.send_robust(sender=Device, instance=instance.visa_device) elif type(instance) is VISAVariable: post_save.send_robust(sender=Variable, instance=instance.visa_variable) elif type(instance) is VISADeviceHandler: # todo pass eli...
def _reinit_daq_daemons(sender, instance, **kwargs)
update the daq daemon configuration when changes be applied in the models
2.587212
2.554612
1.012761
import subprocess output = {} try: apc_status = subprocess.check_output("/sbin/apcaccess") except: return None output['timestamp'] = time() for line in apc_status.split('\n'): (key, spl, val) = line.partition(': ') key = key.rstrip().upper() val = val...
def query_apsupsd_status()
(100, 'STATUS'), # True/False (101, 'LINEV'), # Volts (102, 'BATTV'), # Volts (103, 'BCHARGE'), # % (104, 'TIMELEFT'), # Minutes (105, 'LOADPCT'), # %
4.165565
2.937591
1.418021
if self.inst is None: logger.error("Visa-MDO3014-read data-Self.inst : None") return None if device_property == 'present_value': return self.parse_value(self.inst.query(':READ?')) else: value = self.inst.query(device_property) ...
def read_data(self, device_property)
read values from the device
4.873218
4.728721
1.030557
if 'init' in request.POST: init = bool(float(request.POST['init'])) else: init = False active_variables = [] if 'variables[]' in request.POST: active_variables = request.POST.getlist('variables[]') active_variable_properties = [] if 'variable_properties[]' in reques...
def get_cache_data(request)
else: active_variables = list( GroupDisplayPermission.objects.filter(hmi_group__in=request.user.groups.iterator()).values_list( 'charts__variables', flat=True)) active_variables += list( GroupDisplayPermission.objects.filter(hmi_group__in=request.user.groups.itera...
2.489292
2.500976
0.995328
if self.inst is None: return vp_func = variable_instance.variableproperty_set.filter(name=':FUNC').first() measure_function = '' if vp_func: if vp_func.value(): measure_function = ':FUNC "%s";'%vp_func.value() trig_delay = 0.1 ...
def read_data(self,variable_instance)
read values from the device
5.987526
5.725579
1.04575
variable = self._variables[variable_id] if task.property_name != '': # write the property to VariableProperty use that for later read vp = VariableProperty.objects.update_or_create_property(variable=variable, ...
def write_data(self, variable_id, value, task)
write values to the device
4.549851
4.483078
1.014894
if info == 'ad1': data = smbus_device.read_word_data(0x69, 0x05) data = format(data,"02x") return (float(data) / 100) # °C if info == 'ad2': data = smbus_device.read_word_data(0x69, 0x07) data = format(data,"02x") return (float(data) / 100) # °C ...
def ups_pico(smbus_device,info)
query data via smbus (I2C) from a UPS Pico device
1.963204
1.972468
0.995304
qs = super(VISADeviceAdmin, self).get_queryset(request) return qs.filter(protocol_id=PROTOCOL_ID)
def get_queryset(self, request)
Limit Pages to those that belong to the request's user.
7.331535
7.406212
0.989917
qs = super(VISAVariableAdmin, self).get_queryset(request) return qs.filter(device__protocol_id=PROTOCOL_ID)
def get_queryset(self, request)
Limit Pages to those that belong to the request's user.
8.793903
10.106796
0.870098
if _type.upper() == 'FLOAT64': return float64(value) elif _type.upper() == 'FLOAT32': return float32(value) elif _type.upper() == 'INT32': return int32(value) elif _type.upper() == 'UINT16': return uint16(value) elif _type.upper() == 'INT16': return int16...
def _cast_value(value, _type)
cast value to _type
1.719066
1.704544
1.00852
for mail in Mail.objects.filter(done=False, send_fail_count__lt=3): # send all emails that are not already send or failed to send less # then three times mail.send_mail() for mail in Mail.objects.filter(done=True, timestamp__lt=time() - 60 * 60 * 24 * 7): ...
def loop(self)
check for mails and send them
5.505316
4.989681
1.10334
s = float(sum(l)) if s == 0: raise ValueError("Cannot normalize list with sum 0") return [x / s for x in l]
def normalize(l)
Normalizes input list. Parameters ---------- l: list The list to be normalized Returns ------- The normalized list or numpy array Raises ------ ValueError, if the list sums to zero
3.977653
3.950273
1.006931
start = 0 if not boundary: start = 1 for i in range(start, scale + (1 - start)): for j in range(start, scale + (1 - start) - i): k = scale - i - j yield (i, j, k)
def simplex_iterator(scale, boundary=True)
Systematically iterates through a lattice of points on the 2-simplex. Parameters ---------- scale: Int The normalized scale of the simplex, i.e. N such that points (x,y,z) satisify x + y + z == N boundary: bool, True Include the boundary points (tuples where at least one ...
2.835701
3.394461
0.835391
if not permutation: return p return [p[int(permutation[i])] for i in range(len(p))]
def permute_point(p, permutation=None)
Permutes the point according to the permutation keyword argument. The default permutation is "012" which does not change the order of the coordinate. To rotate counterclockwise, use "120" and to rotate clockwise use "201".
4.140982
4.053269
1.02164
permuted = permute_point(p, permutation=permutation) a = permuted[0] b = permuted[1] x = a + b/2. y = SQRT3OVER2 * b return numpy.array([x, y])
def project_point(p, permutation=None)
Maps (x,y,z) coordinates to planar simplex. Parameters ---------- p: 3-tuple The point to be projected p = (x, y, z) permutation: string, None, equivalent to "012" The order of the coordinates, counterclockwise from the origin
4.055794
6.226259
0.651401
xs, ys = unzip([project_point(p, permutation=permutation) for p in s]) return xs, ys
def project_sequence(s, permutation=None)
Projects a point or sequence of points using `project_point` to lists xs, ys for plotting with Matplotlib. Parameters ---------- s, Sequence-like The sequence of points (3-tuples) to be projected. Returns ------- xs, ys: The sequence of projected points in coordinates as two lists
7.397406
6.001121
1.232671
p = [] for k in range(3): p.append(conversion[axisorder[k]](q[k])) return tuple(p)
def convert_coordinates(q, conversion, axisorder)
Convert a 3-tuple in data coordinates into to simplex data coordinates for plotting. Parameters ---------- q: 3-tuple the point to be plotted in data coordinates conversion: dict keys = ['b','l','r'] values = lambda function giving the conversion axisorder: String giving...
3.716253
5.16106
0.720056
fb = float(scale) / float(limits['b'][1] - limits['b'][0]) fl = float(scale) / float(limits['l'][1] - limits['l'][0]) fr = float(scale) / float(limits['r'][1] - limits['r'][0]) conversion = {"b": lambda x: (x - limits['b'][0]) * fb, "l": lambda x: (x - limits['l'][0]) * fl, ...
def get_conversion(scale, limits)
Get the conversion equations for each axis. limits: dict of min and max values for the axes in the order blr.
1.906882
1.84289
1.034724
conversion = get_conversion(scale, limits) return [convert_coordinates(q, conversion, axisorder) for q in qs]
def convert_coordinates_sequence(qs, scale, limits, axisorder)
Take a sequence of 3-tuples in data coordinates and convert them to simplex coordinates for plotting. This is needed for custom plots where the scale of the simplex axes is set within limits rather than being defined by the scale parameter. Parameters ---------- qs, sequence of 3-tuples ...
3.964312
10.572949
0.374949
ax.set_ylim((-0.10 * scale, .90 * scale)) ax.set_xlim((-0.05 * scale, 1.05 * scale))
def resize_drawing_canvas(ax, scale=1.)
Makes sure the drawing surface is large enough to display projected content. Parameters ---------- ax: Matplotlib AxesSubplot, None The subplot to draw on. scale: float, 1.0 Simplex scale size.
3.346872
3.979013
0.841131
if not ax: return if axis.lower() in ["both", "x", "horizontal"]: ax.set_xticks([], []) if axis.lower() in ["both", "y", "vertical"]: ax.set_yticks([], [])
def clear_matplotlib_ticks(ax=None, axis="both")
Clears the default matplotlib axes, or the one specified by the axis argument. Parameters ---------- ax: Matplotlib AxesSubplot, None The subplot to draw on. axis: string, "both" The axis to clear: "x" or "horizontal", "y" or "vertical", or "both"
2.533383
2.883756
0.878501
if not ax: fig, ax = pyplot.subplots() xs, ys = project_sequence(points, permutation=permutation) ax.plot(xs, ys, **kwargs) return ax
def plot(points, ax=None, permutation=None, **kwargs)
Analogous to maplotlib.plot. Plots trajectory points where each point is a tuple (x,y,z) satisfying x + y + z = scale (not checked). The tuples are projected and plotted as a curve. Parameters ---------- points: List of 3-tuples The list of tuples to be plotted as a connected curve. ax:...
3.581579
4.847217
0.738894
if not ax: fig, ax = pyplot.subplots() cmap = get_cmap(cmap) xs, ys = project_sequence(points, permutation=permutation) # We want to color each segment independently...which is annoying. segments = [] for i in range(len(xs) - 1): cur_line = [] x_before = xs[i] ...
def plot_colored_trajectory(points, cmap=None, ax=None, permutation=None, **kwargs)
Plots trajectories with changing color, simlar to `plot`. Trajectory points are tuples (x,y,z) satisfying x + y + z = scale (not checked). The tuples are projected and plotted as a curve. Parameters ---------- points: List of 3-tuples The list of tuples to be plotted as a connected curve. ...
2.329405
2.537149
0.918119
if not ax: fig, ax = pyplot.subplots() xs, ys = project_sequence(points, permutation=permutation) ax.scatter(xs, ys, vmin=vmin, vmax=vmax, **kwargs) if colorbar and (colormap != None): if cb_kwargs != None: colorbar_hack(ax, vmin, vmax, colormap, scientific=scientific, ...
def scatter(points, ax=None, permutation=None, colorbar=False, colormap=None, vmin=0, vmax=1, scientific=False, cbarlabel=None, cb_kwargs=None, **kwargs)
Plots trajectory points where each point satisfies x + y + z = scale. First argument is a list or numpy array of tuples of length 3. Parameters ---------- points: List of 3-tuples The list of tuples to be scatter-plotted. ax: Matplotlib AxesSubplot, None The subplot to draw on. ...
2.391427
2.768475
0.863807
enth = abs(energy - concs[0]*A -concs[1]*B -concs[2]*C) return enth
def _en_to_enth(energy,concs,A,B,C)
Converts an energy to an enthalpy. Converts energy to enthalpy using the following formula: Enthalpy = energy - (energy contribution from A) - (energy contribution from B) - (energy contribution from C) An absolute value is taken afterward for convenience. Parameters ---------- ene...
3.76261
4.563703
0.824464
pureA = [energy[0][0],energy[0][1]] pureB = [energy[1][0],energy[1][1]] pureC = [energy[2][0],energy[2][1]] enthalpy = [] for en in energy: c = en[2] conc = [float(i)/sum(c) for i in c] CE = _en_to_enth(en[0],conc,pureA[0],pureB[0],pureC[0]) VASP = _en_to_...
def _energy_to_enthalpy(energy)
Converts energy to enthalpy. This function take the energies stored in the energy array and converts them to formation enthalpy. Parameters --------- energy : list of lists of floats Returns ------- enthalpy : list of lists containing the enthalpies.
2.999569
3.006963
0.997541
err_vals = [] for en in vals: c = en[2] conc = [float(i)/sum(c) for i in c] err = abs(en[0]-en[1]) err_vals.append([conc,err]) return err_vals
def _find_error(vals)
Find the errors in the energy values. This function finds the errors in the enthalpys. Parameters ---------- vals : list of lists of floats Returns ------- err_vals : list of lists containing the errors.
5.272326
4.281453
1.231434
energy = [] with open(fname,'r') as f: for line in f: CE = abs(float(line.strip().split()[0])) VASP = abs(float(line.strip().split()[1])) conc = [i for i in line.strip().split()[2:]] conc_f = [] for c in conc: if '[' ...
def _read_data(fname)
Reads data from file. Reads the data in 'fname' into a list where each list entry contains [energy predicted, energy calculated, list of concentrations]. Parameters ---------- fname : str The name and path to the data file. Returns ------- energy : list of lists of floats...
2.534659
2.417693
1.048379
energies = _read_data(fname) enthalpy = _energy_to_enthalpy(energies) this_errors = _find_error(enthalpy) points = [] colors = [] for er in this_errors: concs = er[0] points.append((concs[0]*100,concs[1]*100,concs[2]*100)) colors.append(er[1]) scale = 100 ...
def conc_err_plot(fname)
Plots the error in the CE data. This plots the error in the CE predictions within a ternary concentration diagram. Parameters ---------- fname : string containing the input file name.
4.153135
3.920087
1.05945
ternary_ax = TernaryAxesSubplot(ax=ax, scale=scale, permutation=permutation) return ternary_ax.get_figure(), ternary_ax
def figure(ax=None, scale=None, permutation=None)
Wraps a Matplotlib AxesSubplot or generates a new one. Emulates matplotlib's > figure, ax = pyplot.subplots() Parameters ---------- ax: AxesSubplot, None The matplotlib AxesSubplot to wrap scale: float, None The scale factor of the ternary plot
3.849623
4.35164
0.884637
figure = self.get_figure() callback = partial(mpl_redraw_callback, tax=self) event_names = ('resize_event', 'draw_event') for event_name in event_names: figure.canvas.mpl_connect(event_name, callback)
def _connect_callbacks(self)
Connect resize matplotlib callbacks.
4.904956
4.048504
1.211548
ax = self.get_axes() ax.set_title(title, **kwargs)
def set_title(self, title, **kwargs)
Sets the title on the underlying matplotlib AxesSubplot.
3.757476
2.922765
1.285589
if not position: position = (-offset, 3./5, 2./5) self._labels["left"] = (label, position, rotation, kwargs)
def left_axis_label(self, label, position=None, rotation=60, offset=0.08, **kwargs)
Sets the label on the left axis. Parameters ---------- label: String The axis label position: 3-Tuple of floats, None The position of the text label rotation: float, 60 The angle of rotation of the label offset: float, Used...
6.021843
7.822513
0.769809