text
stringlengths
0
828
>>> make_good_url({})
>>> make_good_url(addition='{}')
:param url: URL
:param addition: Something to add to the URL
:return: New URL with addition""""""
if url is None:
return None
if isinstance(url, str) and isinstance(addition, str):
return ""%s/%s"" % (url.rstrip('/'), addition.lstrip('/'))
else:
return None"
313,"def build_kvasir_url(
proto=""https"", server=""localhost"", port=""8443"",
base=""Kvasir"", user=""test"", password=""test"",
path=KVASIR_JSONRPC_PATH):
""""""
Creates a full URL to reach Kvasir given specific data
>>> build_kvasir_url('https', 'localhost', '8443', 'Kvasir', 'test', 'test')
'https://test@test/localhost:8443/Kvasir/api/call/jsonrpc'
>>> build_kvasir_url()
'https://test@test/localhost:8443/Kvasir/api/call/jsonrpc'
>>> build_kvasir_url(server='localhost', port='443', password='password', path='bad/path')
'https://test@password/localhost:443/Kvasir/bad/path'
:param proto: Protocol type - http or https
:param server: Hostname or IP address of Web2py server
:param port: Port to reach server
:param base: Base application name
:param user: Username for basic auth
:param password: Password for basic auth
:param path: Full path to JSONRPC (/api/call/jsonrpc)
:return: A full URL that can reach Kvasir's JSONRPC interface
""""""
uri = proto + '://' + user + '@' + password + '/' + server + ':' + port + '/' + base
return make_good_url(uri, path)"
314,"def get_default(parser, section, option, default):
""""""helper to get config settings with a default if not present""""""
try:
result = parser.get(section, option)
except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
result = default
return result"
315,"def set_db_application_prefix(prefix, sep=None):
""""""Set the global app prefix and separator.""""""
global _APPLICATION_PREFIX, _APPLICATION_SEP
_APPLICATION_PREFIX = prefix
if (sep is not None):
_APPLICATION_SEP = sep"
316,"def find_by_index(self, cls, index_name, value):
""""""Find records matching index query - defer to backend.""""""
return self.backend.find_by_index(cls, index_name, value)"
317,"def humanTime(seconds):
'''
Convert seconds to something more human-friendly
'''
intervals = ['days', 'hours', 'minutes', 'seconds']
x = deltaTime(seconds=seconds)
return ' '.join('{} {}'.format(getattr(x, k), k) for k in intervals if getattr(x, k))"
318,"def humanTimeConverter():
'''
Cope whether we're passed a time in seconds on the command line or via stdin
'''
if len(sys.argv) == 2:
print humanFriendlyTime(seconds=int(sys.argv[1]))
else:
for line in sys.stdin:
print humanFriendlyTime(int(line))
sys.exit(0)"
319,"def train(self, data, **kwargs):
""""""
Calculate the standard deviations and means in the training data
""""""
self.data = data
for i in xrange(0,data.shape[1]):
column_mean = np.mean(data.icol(i))
column_stdev = np.std(data.icol(i))
#Have to do += or ""list"" type will fail (ie with append)
self.column_means += [column_mean]
self.column_stdevs += [column_stdev]
self.data = self.predict(data)"
320,"def predict(self, test_data, **kwargs):
""""""
Adjust new input by the values in the training data
""""""
if test_data.shape[1]!=self.data.shape[1]:
raise Exception(""Test data has different number of columns than training data."")
for i in xrange(0,test_data.shape[1]):
test_data.loc[:,i] = test_data.icol(i) - self.column_means[i]
if int(self.column_stdevs[i])!=0:
test_data.loc[:,i] = test_data.icol(i) / self.column_stdevs[i]
return test_data"
321,"def action_decorator(name):
""""""Decorator to register an action decorator
""""""