sentence1 stringlengths 52 3.87M | sentence2 stringlengths 1 47.2k | label stringclasses 1 value |
|---|---|---|
def init_config(self, app):
"""Initialize configuration.
:param app: An instance of :class:`~flask.Flask`.
"""
_vars = ['BASE_TEMPLATE', 'COVER_TEMPLATE', 'SETTINGS_TEMPLATE']
# Sets RequireJS config and SASS binary as well if not already set.
for k in dir(config):
if k.startswith('THEME_') or k in [
'REQUIREJS_CONFIG', 'SASS_BIN'] + _vars:
app.config.setdefault(k, getattr(config, k))
# Set THEME_<name>_TEMPLATE from <name>_TEMPLATE variables if not
# already set.
for varname in _vars:
theme_varname = 'THEME_{}'.format(varname)
if app.config[theme_varname] is None:
app.config[theme_varname] = app.config[varname]
app.config.setdefault(
'ADMIN_BASE_TEMPLATE', config.ADMIN_BASE_TEMPLATE) | Initialize configuration.
:param app: An instance of :class:`~flask.Flask`. | entailment |
def set_range(self, accel=1, gyro=1):
"""Set the measurement range for the accel and gyro MEMS. Higher range means less resolution.
:param accel: a RANGE_ACCEL_* constant
:param gyro: a RANGE_GYRO_* constant
:Example:
.. code-block:: python
sensor = MPU6050I2C(gateway_class_instance)
sensor.set_range(
accel=MPU6050I2C.RANGE_ACCEL_2G,
gyro=MPU6050I2C.RANGE_GYRO_250DEG
)
"""
self.i2c_write_register(0x1c, accel)
self.i2c_write_register(0x1b, gyro)
self.accel_range = accel
self.gyro_range = gyro | Set the measurement range for the accel and gyro MEMS. Higher range means less resolution.
:param accel: a RANGE_ACCEL_* constant
:param gyro: a RANGE_GYRO_* constant
:Example:
.. code-block:: python
sensor = MPU6050I2C(gateway_class_instance)
sensor.set_range(
accel=MPU6050I2C.RANGE_ACCEL_2G,
gyro=MPU6050I2C.RANGE_GYRO_250DEG
) | entailment |
def set_slave_bus_bypass(self, enable):
"""Put the aux i2c bus on the MPU-6050 in bypass mode, thus connecting it to the main i2c bus directly
Dont forget to use wakeup() or else the slave bus is unavailable
:param enable:
:return:
"""
current = self.i2c_read_register(0x37, 1)[0]
if enable:
current |= 0b00000010
else:
current &= 0b11111101
self.i2c_write_register(0x37, current) | Put the aux i2c bus on the MPU-6050 in bypass mode, thus connecting it to the main i2c bus directly
Dont forget to use wakeup() or else the slave bus is unavailable
:param enable:
:return: | entailment |
def temperature(self):
"""Read the value for the internal temperature sensor.
:returns: Temperature in degree celcius as float
:Example:
>>> sensor = MPU6050I2C(gw)
>>> sensor.wakeup()
>>> sensor.temperature()
49.38
"""
if not self.awake:
raise Exception("MPU6050 is in sleep mode, use wakeup()")
raw = self.i2c_read_register(0x41, 2)
raw = struct.unpack('>h', raw)[0]
return round((raw / 340) + 36.53, 2) | Read the value for the internal temperature sensor.
:returns: Temperature in degree celcius as float
:Example:
>>> sensor = MPU6050I2C(gw)
>>> sensor.wakeup()
>>> sensor.temperature()
49.38 | entailment |
def acceleration(self):
"""Return the acceleration in G's
:returns: Acceleration for every axis as a tuple
:Example:
>>> sensor = MPU6050I2C(gw)
>>> sensor.wakeup()
>>> sensor.acceleration()
(0.6279296875, 0.87890625, 1.1298828125)
"""
if not self.awake:
raise Exception("MPU6050 is in sleep mode, use wakeup()")
raw = self.i2c_read_register(0x3B, 6)
x, y, z = struct.unpack('>HHH', raw)
scales = {
self.RANGE_ACCEL_2G: 16384,
self.RANGE_ACCEL_4G: 8192,
self.RANGE_ACCEL_8G: 4096,
self.RANGE_ACCEL_16G: 2048
}
scale = scales[self.accel_range]
return x / scale, y / scale, z / scale | Return the acceleration in G's
:returns: Acceleration for every axis as a tuple
:Example:
>>> sensor = MPU6050I2C(gw)
>>> sensor.wakeup()
>>> sensor.acceleration()
(0.6279296875, 0.87890625, 1.1298828125) | entailment |
def angular_rate(self):
"""Return the angular rate for every axis in degree/second.
:returns: Angular rate for every axis as a tuple
:Example:
>>> sensor = MPU6050I2C(gw)
>>> sensor.wakeup()
>>> sensor.angular_rate()
(1.380859375, 1.6318359375, 1.8828125)
"""
if not self.awake:
raise Exception("MPU6050 is in sleep mode, use wakeup()")
raw = self.i2c_read_register(0x43, 6)
x, y, z = struct.unpack('>HHH', raw)
scales = {
self.RANGE_GYRO_250DEG: 16384,
self.RANGE_GYRO_500DEG: 8192,
self.RANGE_GYRO_1000DEG: 4096,
self.RANGE_GYRO_2000DEG: 2048
}
scale = scales[self.gyro_range]
return x / scale, y / scale, z / scale | Return the angular rate for every axis in degree/second.
:returns: Angular rate for every axis as a tuple
:Example:
>>> sensor = MPU6050I2C(gw)
>>> sensor.wakeup()
>>> sensor.angular_rate()
(1.380859375, 1.6318359375, 1.8828125) | entailment |
def _get_contents(self):
"""Create strings from lazy strings."""
return [
str(value) if is_lazy_string(value) else value
for value in super(LazyNpmBundle, self)._get_contents()
] | Create strings from lazy strings. | entailment |
def load_calibration(self):
"""Load factory calibration data from device."""
registers = self.i2c_read_register(0xAA, 22)
(
self.cal['AC1'],
self.cal['AC2'],
self.cal['AC3'],
self.cal['AC4'],
self.cal['AC5'],
self.cal['AC6'],
self.cal['B1'],
self.cal['B2'],
self.cal['MB'],
self.cal['MC'],
self.cal['MD']
) = struct.unpack('>hhhHHHhhhhh', registers) | Load factory calibration data from device. | entailment |
def temperature(self):
"""Get the temperature from the sensor.
:returns: The temperature in degree celcius as a float
:example:
>>> sensor = BMP180(gw)
>>> sensor.load_calibration()
>>> sensor.temperature()
21.4
"""
ut = self.get_raw_temp()
x1 = ((ut - self.cal['AC6']) * self.cal['AC5']) >> 15
x2 = (self.cal['MC'] << 11) // (x1 + self.cal['MD'])
b5 = x1 + x2
return ((b5 + 8) >> 4) / 10 | Get the temperature from the sensor.
:returns: The temperature in degree celcius as a float
:example:
>>> sensor = BMP180(gw)
>>> sensor.load_calibration()
>>> sensor.temperature()
21.4 | entailment |
def pressure(self):
"""
Get barometric pressure in milibar
:returns: The pressure in milibar as a int
:example:
>>> sensor = BMP180(gw)
>>> sensor.load_calibration()
>>> sensor.pressure()
75216
"""
ut = self.get_raw_temp()
up = self.get_raw_pressure()
x1 = ((ut - self.cal['AC6']) * self.cal['AC5']) >> 15
x2 = (self.cal['MC'] << 11) // (x1 + self.cal['MD'])
b5 = x1 + x2
b6 = b5 - 4000
x1 = (self.cal['B2'] * (b6 * b6) >> 12) >> 11
x2 = (self.cal['AC2'] * b6) >> 11
x3 = x1 + x2
b3 = (((self.cal['AC1'] * 4 + x3) << self.mode) + 2) // 4
x1 = (self.cal['AC3'] * b6) >> 13
x2 = (self.cal['B1'] * ((b6 * b6) >> 12)) >> 16
x3 = ((x1 + x2) + 2) >> 2
b4 = (self.cal['AC4'] * (x3 + 32768)) >> 15
b7 = (up - b3) * (50000 >> self.mode)
if b7 < 0x80000000:
p = (b7 * 2) // b4
else:
p = (b7 // b4) * 2
x1 = (p >> 8) * (p >> 8)
x1 = (x1 * 3038) >> 16
x2 = (-7357 * p) >> 16
p += (x1 + x2 + 3791) >> 4
return p | Get barometric pressure in milibar
:returns: The pressure in milibar as a int
:example:
>>> sensor = BMP180(gw)
>>> sensor.load_calibration()
>>> sensor.pressure()
75216 | entailment |
def switch_mode(self, new_mode):
""" Explicitly switch the Bus Pirate mode
:param new_mode: The mode to switch to. Use the buspirate.MODE_* constants
"""
packet = bytearray()
packet.append(new_mode)
self.device.write(packet)
possible_responses = {
self.MODE_I2C: b'I2C1',
self.MODE_RAW: b'BBIO1',
self.MODE_SPI: b'API1',
self.MODE_UART: b'ART1',
self.MODE_ONEWIRE: b'1W01'
}
expected = possible_responses[new_mode]
response = self.device.read(4)
if response != expected:
raise Exception('Could not switch mode')
self.mode = new_mode
self.set_peripheral()
if self.i2c_speed:
self._set_i2c_speed(self.i2c_speed) | Explicitly switch the Bus Pirate mode
:param new_mode: The mode to switch to. Use the buspirate.MODE_* constants | entailment |
def set_peripheral(self, power=None, pullup=None, aux=None, chip_select=None):
""" Set the peripheral config at runtime.
If a parameter is None then the config will not be changed.
:param power: Set to True to enable the power supply or False to disable
:param pullup: Set to True to enable the internal pull-up resistors. False to disable
:param aux: Set the AUX pin output state
:param chip_select: Set the CS pin output state
"""
if power is not None:
self.power = power
if pullup is not None:
self.pullup = pullup
if aux is not None:
self.aux = aux
if chip_select is not None:
self.chip_select = chip_select
# Set peripheral status
peripheral_byte = 64
if self.chip_select:
peripheral_byte |= 0x01
if self.aux:
peripheral_byte |= 0x02
if self.pullup:
peripheral_byte |= 0x04
if self.power:
peripheral_byte |= 0x08
self.device.write(bytearray([peripheral_byte]))
response = self.device.read(1)
if response != b"\x01":
raise Exception("Setting peripheral failed. Received: {}".format(repr(response))) | Set the peripheral config at runtime.
If a parameter is None then the config will not be changed.
:param power: Set to True to enable the power supply or False to disable
:param pullup: Set to True to enable the internal pull-up resistors. False to disable
:param aux: Set the AUX pin output state
:param chip_select: Set the CS pin output state | entailment |
def _set_i2c_speed(self, i2c_speed):
""" Set I2C speed to one of '400kHz', '100kHz', 50kHz', '5kHz'
"""
lower_bits_mapping = {
'400kHz': 3,
'100kHz': 2,
'50kHz': 1,
'5kHz': 0,
}
if i2c_speed not in lower_bits_mapping:
raise ValueError('Invalid i2c_speed')
speed_byte = 0b01100000 | lower_bits_mapping[i2c_speed]
self.device.write(bytearray([speed_byte]))
response = self.device.read(1)
if response != b"\x01":
raise Exception("Changing I2C speed failed. Received: {}".format(repr(response))) | Set I2C speed to one of '400kHz', '100kHz', 50kHz', '5kHz' | entailment |
def config(self, averaging=1, datarate=15, mode=MODE_NORMAL):
"""
Set the base config for sensor
:param averaging: Sets the numer of samples that are internally averaged
:param datarate: Datarate in hertz
:param mode: one of the MODE_* constants
"""
averaging_conf = {
1: 0,
2: 1,
4: 2,
8: 3
}
if averaging not in averaging_conf.keys():
raise Exception('Averaging should be one of: 1,2,4,8')
datarates = {
0.75: 0,
1.5: 1,
3: 2,
7.5: 4,
15: 5,
30: 6,
75: 7
}
if datarate not in datarates.keys():
raise Exception(
'Datarate of {} Hz is not support choose one of: {}'.format(datarate, ', '.join(datarates.keys())))
config_a = 0
config_a &= averaging_conf[averaging] << 5
config_a &= datarates[datarate] << 2
config_a &= mode
self.i2c_write_register(0x00, config_a) | Set the base config for sensor
:param averaging: Sets the numer of samples that are internally averaged
:param datarate: Datarate in hertz
:param mode: one of the MODE_* constants | entailment |
def set_resolution(self, resolution=1090):
"""
Set the resolution of the sensor
The resolution value is the amount of steps recorded in a single Gauss. The possible options are:
======================= ========== =============
Recommended Gauss range Resolution Gauss per bit
======================= ========== =============
0.88 Ga 1370 0.73 mGa
1.3 Ga 1090 0.92 mGa
1.9 Ga 820 1.22 mGa
2.5 Ga 660 1.52 mGa
4.0 Ga 440 2.27 mGa
4.7 Ga 390 2.56 mGa
5.6 Ga 330 3.03 mGa
8.1 Ga 230 4.35 mGa
======================= ========== =============
:param resolution: The resolution of the sensor
"""
options = {
1370: 0,
1090: 1,
820: 2,
660: 3,
440: 4,
390: 5,
330: 6,
230: 7
}
if resolution not in options.keys():
raise Exception('Resolution of {} steps is not supported'.format(resolution))
self.resolution = resolution
config_b = 0
config_b &= options[resolution] << 5
self.i2c_write_register(0x01, config_b) | Set the resolution of the sensor
The resolution value is the amount of steps recorded in a single Gauss. The possible options are:
======================= ========== =============
Recommended Gauss range Resolution Gauss per bit
======================= ========== =============
0.88 Ga 1370 0.73 mGa
1.3 Ga 1090 0.92 mGa
1.9 Ga 820 1.22 mGa
2.5 Ga 660 1.52 mGa
4.0 Ga 440 2.27 mGa
4.7 Ga 390 2.56 mGa
5.6 Ga 330 3.03 mGa
8.1 Ga 230 4.35 mGa
======================= ========== =============
:param resolution: The resolution of the sensor | entailment |
def gauss(self):
"""
Get the magnetometer values as gauss for each axis as a tuple (x,y,z)
:example:
>>> sensor = HMC5883L(gw)
>>> sensor.gauss()
(16.56, 21.2888, 26.017599999999998)
"""
raw = self.raw()
factors = {
1370: 0.73,
1090: 0.92,
820: 1.22,
660: 1.52,
440: 2.27,
390: 2.56,
330: 3.03,
230: 4.35
}
factor = factors[self.resolution] / 100
return raw[0] * factor, raw[1] * factor, raw[2] * factor | Get the magnetometer values as gauss for each axis as a tuple (x,y,z)
:example:
>>> sensor = HMC5883L(gw)
>>> sensor.gauss()
(16.56, 21.2888, 26.017599999999998) | entailment |
def temperature(self):
""" Get the temperature in degree celcius
"""
result = self.i2c_read(2)
value = struct.unpack('>H', result)[0]
if value < 32768:
return value / 256.0
else:
return (value - 65536) / 256.0 | Get the temperature in degree celcius | entailment |
def write(self, char):
""" Display a single character on the display
:type char: str or int
:param char: Character to display
"""
char = str(char).lower()
self.segments.write(self.font[char]) | Display a single character on the display
:type char: str or int
:param char: Character to display | entailment |
def get_html_theme_path():
"""
Get the absolute path of the directory containing the theme files.
"""
return os.path.abspath(os.path.dirname(os.path.dirname(__file__))) | Get the absolute path of the directory containing the theme files. | entailment |
def feedback_form_url(project, page):
"""
Create a URL for feedback on a particular page in a project.
"""
return FEEDBACK_FORM_FMT.format(pageid=quote("{}: {}".format(project, page))) | Create a URL for feedback on a particular page in a project. | entailment |
def update_context(app, pagename, templatename, context, doctree): # pylint: disable=unused-argument
"""
Update the page rendering context to include ``feedback_form_url``.
"""
context['feedback_form_url'] = feedback_form_url(app.config.project, pagename) | Update the page rendering context to include ``feedback_form_url``. | entailment |
def setup(app):
"""
Sphinx extension to update the rendering context with the feedback form URL.
Arguments:
app (Sphinx): Application object for the Sphinx process
Returns:
a dictionary of metadata (http://www.sphinx-doc.org/en/stable/extdev/#extension-metadata)
"""
event = 'html-page-context' if six.PY3 else b'html-page-context'
app.connect(event, update_context)
return {
'parallel_read_safe': True,
'parallel_write_safe': True,
'version': __version__,
} | Sphinx extension to update the rendering context with the feedback form URL.
Arguments:
app (Sphinx): Application object for the Sphinx process
Returns:
a dictionary of metadata (http://www.sphinx-doc.org/en/stable/extdev/#extension-metadata) | entailment |
def objectsFromPEM(pemdata):
"""
Load some objects from a PEM.
"""
certificates = []
keys = []
blobs = [b""]
for line in pemdata.split(b"\n"):
if line.startswith(b'-----BEGIN'):
if b'CERTIFICATE' in line:
blobs = certificates
else:
blobs = keys
blobs.append(b'')
blobs[-1] += line
blobs[-1] += b'\n'
keys = [KeyPair.load(key, FILETYPE_PEM) for key in keys]
certificates = [Certificate.loadPEM(certificate)
for certificate in certificates]
return PEMObjects(keys=keys, certificates=certificates) | Load some objects from a PEM. | entailment |
def following_key(key):
"""
Returns the key immediately following the input key - based on the Java implementation found in
org.apache.accumulo.core.data.Key, function followingKey(PartialKey part)
:param key: the key to be followed
:return: a key that immediately follows the input key
"""
if key.timestamp is not None:
key.timestamp -= 1
elif key.colVisibility is not None:
key.colVisibility = following_array(key.colVisibility)
elif key.colQualifier is not None:
key.colQualifier = following_array(key.colQualifier)
elif key.colFamily is not None:
key.colFamily = following_array(key.colFamily)
elif key.row is not None:
key.row = following_array(key.row)
return key | Returns the key immediately following the input key - based on the Java implementation found in
org.apache.accumulo.core.data.Key, function followingKey(PartialKey part)
:param key: the key to be followed
:return: a key that immediately follows the input key | entailment |
def followingPrefix(prefix):
"""Returns a String that sorts just after all Strings beginning with a prefix"""
prefixBytes = array('B', prefix)
changeIndex = len(prefixBytes) - 1
while (changeIndex >= 0 and prefixBytes[changeIndex] == 0xff ):
changeIndex = changeIndex - 1;
if(changeIndex < 0):
return None
newBytes = array('B', prefix[0:changeIndex + 1])
newBytes[changeIndex] = newBytes[changeIndex] + 1
return newBytes.tostring() | Returns a String that sorts just after all Strings beginning with a prefix | entailment |
def prefix(rowPrefix):
"""Returns a Range that covers all rows beginning with a prefix"""
fp = Range.followingPrefix(rowPrefix)
return Range(srow=rowPrefix, sinclude=True, erow=fp, einclude=False) | Returns a Range that covers all rows beginning with a prefix | entailment |
def add_mutations_and_flush(self, table, muts):
"""
Add mutations to a table without the need to create and manage a batch writer.
"""
if not isinstance(muts, list) and not isinstance(muts, tuple):
muts = [muts]
cells = {}
for mut in muts:
cells.setdefault(mut.row, []).extend(mut.updates)
self.client.updateAndFlush(self.login, table, cells) | Add mutations to a table without the need to create and manage a batch writer. | entailment |
def remove_constraint(self, table, constraint):
"""
:param table: table name
:param constraint: the constraint number as returned by list_constraints
"""
self.client.removeConstraint(self.login, table, constraint) | :param table: table name
:param constraint: the constraint number as returned by list_constraints | entailment |
def get_context(self):
"""
A basic override of get_context to ensure that the appropriate proxy
object is returned.
"""
ctx = self._obj.get_context()
return _ContextProxy(ctx, self._factory) | A basic override of get_context to ensure that the appropriate proxy
object is returned. | entailment |
def login(self, principal, loginProperties):
"""
Parameters:
- principal
- loginProperties
"""
self.send_login(principal, loginProperties)
return self.recv_login() | Parameters:
- principal
- loginProperties | entailment |
def addConstraint(self, login, tableName, constraintClassName):
"""
Parameters:
- login
- tableName
- constraintClassName
"""
self.send_addConstraint(login, tableName, constraintClassName)
return self.recv_addConstraint() | Parameters:
- login
- tableName
- constraintClassName | entailment |
def addSplits(self, login, tableName, splits):
"""
Parameters:
- login
- tableName
- splits
"""
self.send_addSplits(login, tableName, splits)
self.recv_addSplits() | Parameters:
- login
- tableName
- splits | entailment |
def attachIterator(self, login, tableName, setting, scopes):
"""
Parameters:
- login
- tableName
- setting
- scopes
"""
self.send_attachIterator(login, tableName, setting, scopes)
self.recv_attachIterator() | Parameters:
- login
- tableName
- setting
- scopes | entailment |
def checkIteratorConflicts(self, login, tableName, setting, scopes):
"""
Parameters:
- login
- tableName
- setting
- scopes
"""
self.send_checkIteratorConflicts(login, tableName, setting, scopes)
self.recv_checkIteratorConflicts() | Parameters:
- login
- tableName
- setting
- scopes | entailment |
def clearLocatorCache(self, login, tableName):
"""
Parameters:
- login
- tableName
"""
self.send_clearLocatorCache(login, tableName)
self.recv_clearLocatorCache() | Parameters:
- login
- tableName | entailment |
def cloneTable(self, login, tableName, newTableName, flush, propertiesToSet, propertiesToExclude):
"""
Parameters:
- login
- tableName
- newTableName
- flush
- propertiesToSet
- propertiesToExclude
"""
self.send_cloneTable(login, tableName, newTableName, flush, propertiesToSet, propertiesToExclude)
self.recv_cloneTable() | Parameters:
- login
- tableName
- newTableName
- flush
- propertiesToSet
- propertiesToExclude | entailment |
def compactTable(self, login, tableName, startRow, endRow, iterators, flush, wait):
"""
Parameters:
- login
- tableName
- startRow
- endRow
- iterators
- flush
- wait
"""
self.send_compactTable(login, tableName, startRow, endRow, iterators, flush, wait)
self.recv_compactTable() | Parameters:
- login
- tableName
- startRow
- endRow
- iterators
- flush
- wait | entailment |
def cancelCompaction(self, login, tableName):
"""
Parameters:
- login
- tableName
"""
self.send_cancelCompaction(login, tableName)
self.recv_cancelCompaction() | Parameters:
- login
- tableName | entailment |
def createTable(self, login, tableName, versioningIter, type):
"""
Parameters:
- login
- tableName
- versioningIter
- type
"""
self.send_createTable(login, tableName, versioningIter, type)
self.recv_createTable() | Parameters:
- login
- tableName
- versioningIter
- type | entailment |
def deleteTable(self, login, tableName):
"""
Parameters:
- login
- tableName
"""
self.send_deleteTable(login, tableName)
self.recv_deleteTable() | Parameters:
- login
- tableName | entailment |
def deleteRows(self, login, tableName, startRow, endRow):
"""
Parameters:
- login
- tableName
- startRow
- endRow
"""
self.send_deleteRows(login, tableName, startRow, endRow)
self.recv_deleteRows() | Parameters:
- login
- tableName
- startRow
- endRow | entailment |
def exportTable(self, login, tableName, exportDir):
"""
Parameters:
- login
- tableName
- exportDir
"""
self.send_exportTable(login, tableName, exportDir)
self.recv_exportTable() | Parameters:
- login
- tableName
- exportDir | entailment |
def flushTable(self, login, tableName, startRow, endRow, wait):
"""
Parameters:
- login
- tableName
- startRow
- endRow
- wait
"""
self.send_flushTable(login, tableName, startRow, endRow, wait)
self.recv_flushTable() | Parameters:
- login
- tableName
- startRow
- endRow
- wait | entailment |
def getLocalityGroups(self, login, tableName):
"""
Parameters:
- login
- tableName
"""
self.send_getLocalityGroups(login, tableName)
return self.recv_getLocalityGroups() | Parameters:
- login
- tableName | entailment |
def getIteratorSetting(self, login, tableName, iteratorName, scope):
"""
Parameters:
- login
- tableName
- iteratorName
- scope
"""
self.send_getIteratorSetting(login, tableName, iteratorName, scope)
return self.recv_getIteratorSetting() | Parameters:
- login
- tableName
- iteratorName
- scope | entailment |
def getMaxRow(self, login, tableName, auths, startRow, startInclusive, endRow, endInclusive):
"""
Parameters:
- login
- tableName
- auths
- startRow
- startInclusive
- endRow
- endInclusive
"""
self.send_getMaxRow(login, tableName, auths, startRow, startInclusive, endRow, endInclusive)
return self.recv_getMaxRow() | Parameters:
- login
- tableName
- auths
- startRow
- startInclusive
- endRow
- endInclusive | entailment |
def getTableProperties(self, login, tableName):
"""
Parameters:
- login
- tableName
"""
self.send_getTableProperties(login, tableName)
return self.recv_getTableProperties() | Parameters:
- login
- tableName | entailment |
def getSplits(self, login, tableName, maxSplits):
"""
Parameters:
- login
- tableName
- maxSplits
"""
self.send_getSplits(login, tableName, maxSplits)
return self.recv_getSplits() | Parameters:
- login
- tableName
- maxSplits | entailment |
def importDirectory(self, login, tableName, importDir, failureDir, setTime):
"""
Parameters:
- login
- tableName
- importDir
- failureDir
- setTime
"""
self.send_importDirectory(login, tableName, importDir, failureDir, setTime)
self.recv_importDirectory() | Parameters:
- login
- tableName
- importDir
- failureDir
- setTime | entailment |
def importTable(self, login, tableName, importDir):
"""
Parameters:
- login
- tableName
- importDir
"""
self.send_importTable(login, tableName, importDir)
self.recv_importTable() | Parameters:
- login
- tableName
- importDir | entailment |
def listIterators(self, login, tableName):
"""
Parameters:
- login
- tableName
"""
self.send_listIterators(login, tableName)
return self.recv_listIterators() | Parameters:
- login
- tableName | entailment |
def listConstraints(self, login, tableName):
"""
Parameters:
- login
- tableName
"""
self.send_listConstraints(login, tableName)
return self.recv_listConstraints() | Parameters:
- login
- tableName | entailment |
def mergeTablets(self, login, tableName, startRow, endRow):
"""
Parameters:
- login
- tableName
- startRow
- endRow
"""
self.send_mergeTablets(login, tableName, startRow, endRow)
self.recv_mergeTablets() | Parameters:
- login
- tableName
- startRow
- endRow | entailment |
def offlineTable(self, login, tableName):
"""
Parameters:
- login
- tableName
"""
self.send_offlineTable(login, tableName)
self.recv_offlineTable() | Parameters:
- login
- tableName | entailment |
def onlineTable(self, login, tableName):
"""
Parameters:
- login
- tableName
"""
self.send_onlineTable(login, tableName)
self.recv_onlineTable() | Parameters:
- login
- tableName | entailment |
def removeConstraint(self, login, tableName, constraint):
"""
Parameters:
- login
- tableName
- constraint
"""
self.send_removeConstraint(login, tableName, constraint)
self.recv_removeConstraint() | Parameters:
- login
- tableName
- constraint | entailment |
def removeIterator(self, login, tableName, iterName, scopes):
"""
Parameters:
- login
- tableName
- iterName
- scopes
"""
self.send_removeIterator(login, tableName, iterName, scopes)
self.recv_removeIterator() | Parameters:
- login
- tableName
- iterName
- scopes | entailment |
def removeTableProperty(self, login, tableName, property):
"""
Parameters:
- login
- tableName
- property
"""
self.send_removeTableProperty(login, tableName, property)
self.recv_removeTableProperty() | Parameters:
- login
- tableName
- property | entailment |
def renameTable(self, login, oldTableName, newTableName):
"""
Parameters:
- login
- oldTableName
- newTableName
"""
self.send_renameTable(login, oldTableName, newTableName)
self.recv_renameTable() | Parameters:
- login
- oldTableName
- newTableName | entailment |
def setLocalityGroups(self, login, tableName, groups):
"""
Parameters:
- login
- tableName
- groups
"""
self.send_setLocalityGroups(login, tableName, groups)
self.recv_setLocalityGroups() | Parameters:
- login
- tableName
- groups | entailment |
def setTableProperty(self, login, tableName, property, value):
"""
Parameters:
- login
- tableName
- property
- value
"""
self.send_setTableProperty(login, tableName, property, value)
self.recv_setTableProperty() | Parameters:
- login
- tableName
- property
- value | entailment |
def splitRangeByTablets(self, login, tableName, range, maxSplits):
"""
Parameters:
- login
- tableName
- range
- maxSplits
"""
self.send_splitRangeByTablets(login, tableName, range, maxSplits)
return self.recv_splitRangeByTablets() | Parameters:
- login
- tableName
- range
- maxSplits | entailment |
def tableExists(self, login, tableName):
"""
Parameters:
- login
- tableName
"""
self.send_tableExists(login, tableName)
return self.recv_tableExists() | Parameters:
- login
- tableName | entailment |
def pingTabletServer(self, login, tserver):
"""
Parameters:
- login
- tserver
"""
self.send_pingTabletServer(login, tserver)
self.recv_pingTabletServer() | Parameters:
- login
- tserver | entailment |
def getActiveScans(self, login, tserver):
"""
Parameters:
- login
- tserver
"""
self.send_getActiveScans(login, tserver)
return self.recv_getActiveScans() | Parameters:
- login
- tserver | entailment |
def getActiveCompactions(self, login, tserver):
"""
Parameters:
- login
- tserver
"""
self.send_getActiveCompactions(login, tserver)
return self.recv_getActiveCompactions() | Parameters:
- login
- tserver | entailment |
def removeProperty(self, login, property):
"""
Parameters:
- login
- property
"""
self.send_removeProperty(login, property)
self.recv_removeProperty() | Parameters:
- login
- property | entailment |
def setProperty(self, login, property, value):
"""
Parameters:
- login
- property
- value
"""
self.send_setProperty(login, property, value)
self.recv_setProperty() | Parameters:
- login
- property
- value | entailment |
def authenticateUser(self, login, user, properties):
"""
Parameters:
- login
- user
- properties
"""
self.send_authenticateUser(login, user, properties)
return self.recv_authenticateUser() | Parameters:
- login
- user
- properties | entailment |
def changeUserAuthorizations(self, login, user, authorizations):
"""
Parameters:
- login
- user
- authorizations
"""
self.send_changeUserAuthorizations(login, user, authorizations)
self.recv_changeUserAuthorizations() | Parameters:
- login
- user
- authorizations | entailment |
def changeLocalUserPassword(self, login, user, password):
"""
Parameters:
- login
- user
- password
"""
self.send_changeLocalUserPassword(login, user, password)
self.recv_changeLocalUserPassword() | Parameters:
- login
- user
- password | entailment |
def createLocalUser(self, login, user, password):
"""
Parameters:
- login
- user
- password
"""
self.send_createLocalUser(login, user, password)
self.recv_createLocalUser() | Parameters:
- login
- user
- password | entailment |
def dropLocalUser(self, login, user):
"""
Parameters:
- login
- user
"""
self.send_dropLocalUser(login, user)
self.recv_dropLocalUser() | Parameters:
- login
- user | entailment |
def getUserAuthorizations(self, login, user):
"""
Parameters:
- login
- user
"""
self.send_getUserAuthorizations(login, user)
return self.recv_getUserAuthorizations() | Parameters:
- login
- user | entailment |
def grantSystemPermission(self, login, user, perm):
"""
Parameters:
- login
- user
- perm
"""
self.send_grantSystemPermission(login, user, perm)
self.recv_grantSystemPermission() | Parameters:
- login
- user
- perm | entailment |
def grantTablePermission(self, login, user, table, perm):
"""
Parameters:
- login
- user
- table
- perm
"""
self.send_grantTablePermission(login, user, table, perm)
self.recv_grantTablePermission() | Parameters:
- login
- user
- table
- perm | entailment |
def hasSystemPermission(self, login, user, perm):
"""
Parameters:
- login
- user
- perm
"""
self.send_hasSystemPermission(login, user, perm)
return self.recv_hasSystemPermission() | Parameters:
- login
- user
- perm | entailment |
def hasTablePermission(self, login, user, table, perm):
"""
Parameters:
- login
- user
- table
- perm
"""
self.send_hasTablePermission(login, user, table, perm)
return self.recv_hasTablePermission() | Parameters:
- login
- user
- table
- perm | entailment |
def revokeSystemPermission(self, login, user, perm):
"""
Parameters:
- login
- user
- perm
"""
self.send_revokeSystemPermission(login, user, perm)
self.recv_revokeSystemPermission() | Parameters:
- login
- user
- perm | entailment |
def revokeTablePermission(self, login, user, table, perm):
"""
Parameters:
- login
- user
- table
- perm
"""
self.send_revokeTablePermission(login, user, table, perm)
self.recv_revokeTablePermission() | Parameters:
- login
- user
- table
- perm | entailment |
def createBatchScanner(self, login, tableName, options):
"""
Parameters:
- login
- tableName
- options
"""
self.send_createBatchScanner(login, tableName, options)
return self.recv_createBatchScanner() | Parameters:
- login
- tableName
- options | entailment |
def createScanner(self, login, tableName, options):
"""
Parameters:
- login
- tableName
- options
"""
self.send_createScanner(login, tableName, options)
return self.recv_createScanner() | Parameters:
- login
- tableName
- options | entailment |
def nextK(self, scanner, k):
"""
Parameters:
- scanner
- k
"""
self.send_nextK(scanner, k)
return self.recv_nextK() | Parameters:
- scanner
- k | entailment |
def updateAndFlush(self, login, tableName, cells):
"""
Parameters:
- login
- tableName
- cells
"""
self.send_updateAndFlush(login, tableName, cells)
self.recv_updateAndFlush() | Parameters:
- login
- tableName
- cells | entailment |
def createWriter(self, login, tableName, opts):
"""
Parameters:
- login
- tableName
- opts
"""
self.send_createWriter(login, tableName, opts)
return self.recv_createWriter() | Parameters:
- login
- tableName
- opts | entailment |
def getFollowing(self, key, part):
"""
Parameters:
- key
- part
"""
self.send_getFollowing(key, part)
return self.recv_getFollowing() | Parameters:
- key
- part | entailment |
def set_relay_on(self):
"""Turn the relay on."""
if not self.get_relay_state():
try:
request = requests.get(
'{}/relay'.format(self.resource), params={'state': '1'},
timeout=self.timeout)
if request.status_code == 200:
self.data['relay'] = True
except requests.exceptions.ConnectionError:
raise exceptions.MyStromConnectionError() | Turn the relay on. | entailment |
def set_relay_off(self):
"""Turn the relay off."""
if self.get_relay_state():
try:
request = requests.get(
'{}/relay'.format(self.resource), params={'state': '0'},
timeout=self.timeout)
if request.status_code == 200:
self.data['relay'] = False
except requests.exceptions.ConnectionError:
raise exceptions.MyStromConnectionError() | Turn the relay off. | entailment |
def get_relay_state(self):
"""Get the relay state."""
self.get_status()
try:
self.state = self.data['relay']
except TypeError:
self.state = False
return bool(self.state) | Get the relay state. | entailment |
def get_consumption(self):
"""Get current power consumption in mWh."""
self.get_status()
try:
self.consumption = self.data['power']
except TypeError:
self.consumption = 0
return self.consumption | Get current power consumption in mWh. | entailment |
def get_temperature(self):
"""Get current temperature in celsius."""
try:
request = requests.get(
'{}/temp'.format(self.resource), timeout=self.timeout, allow_redirects=False)
self.temperature = request.json()['compensated']
return self.temperature
except requests.exceptions.ConnectionError:
raise exceptions.MyStromConnectionError()
except ValueError:
raise exceptions.MyStromNotVersionTwoSwitch() | Get current temperature in celsius. | entailment |
def eval_fitness(self, chromosome):
"""
Convert a 1-gene chromosome into an integer and calculate its fitness
by checking it against each required factor.
return: fitness value
"""
score = 0
number = self.translator.translate_gene(chromosome.genes[0])
for factor in self.factors:
if number % factor == 0:
score += 1
else:
score -= 1
# check for optimal solution
if score == len(self.factors):
min_product = functools.reduce(lambda a,b: a * b, self.factors)
if number + min_product > self.max_encoded_val:
print("Found best solution:", number)
self.found_best = True
# scale number of factors achieved/missed by ratio of
# the solution number to the maximum possible integer
# represented by binary strings of the given length
return score * number / self.max_encoded_val | Convert a 1-gene chromosome into an integer and calculate its fitness
by checking it against each required factor.
return: fitness value | entailment |
def get_status(self):
"""Get the details from the bulb."""
try:
request = requests.get(
'{}/{}/'.format(self.resource, URI), timeout=self.timeout)
raw_data = request.json()
# Doesn't always work !!!!!
#self._mac = next(iter(self.raw_data))
self.data = raw_data[self._mac]
return self.data
except (requests.exceptions.ConnectionError, ValueError):
raise exceptions.MyStromConnectionError() | Get the details from the bulb. | entailment |
def get_bulb_state(self):
"""Get the relay state."""
self.get_status()
try:
self.state = self.data['on']
except TypeError:
self.state = False
return bool(self.state) | Get the relay state. | entailment |
def get_power(self):
"""Get current power."""
self.get_status()
try:
self.consumption = self.data['power']
except TypeError:
self.consumption = 0
return self.consumption | Get current power. | entailment |
def get_firmware(self):
"""Get the current firmware version."""
self.get_status()
try:
self.firmware = self.data['fw_version']
except TypeError:
self.firmware = 'Unknown'
return self.firmware | Get the current firmware version. | entailment |
def get_brightness(self):
"""Get current brightness."""
self.get_status()
try:
self.brightness = self.data['color'].split(';')[-1]
except TypeError:
self.brightness = 0
return self.brightness | Get current brightness. | entailment |
def get_transition_time(self):
"""Get the transition time in ms."""
self.get_status()
try:
self.transition_time = self.data['ramp']
except TypeError:
self.transition_time = 0
return self.transition_time | Get the transition time in ms. | entailment |
def get_color(self):
"""Get current color."""
self.get_status()
try:
self.color = self.data['color']
self.mode = self.data['mode']
except TypeError:
self.color = 0
self.mode = ''
return {'color': self.color, 'mode': self.mode} | Get current color. | entailment |
def set_color_hsv(self, hue, saturation, value):
"""Turn the bulb on with the given values as HSV."""
try:
data = "action=on&color={};{};{}".format(hue, saturation, value)
request = requests.post(
'{}/{}/{}'.format(self.resource, URI, self._mac),
data=data, timeout=self.timeout)
if request.status_code == 200:
self.data['on'] = True
except requests.exceptions.ConnectionError:
raise exceptions.MyStromConnectionError() | Turn the bulb on with the given values as HSV. | entailment |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.