repository_name stringlengths 5 67 | func_path_in_repository stringlengths 4 234 | func_name stringlengths 0 314 | whole_func_string stringlengths 52 3.87M | language stringclasses 6
values | func_code_string stringlengths 52 3.87M | func_code_tokens listlengths 15 672k | func_documentation_string stringlengths 1 47.2k | func_documentation_tokens listlengths 1 3.92k | split_name stringclasses 1
value | func_code_url stringlengths 85 339 |
|---|---|---|---|---|---|---|---|---|---|---|
shichao-an/115wangpan | u115/api.py | Directory.parent | def parent(self):
"""Parent directory that holds this directory"""
if self._parent is None:
if self.pid is not None:
self._parent = self.api._load_directory(self.pid)
return self._parent | python | def parent(self):
"""Parent directory that holds this directory"""
if self._parent is None:
if self.pid is not None:
self._parent = self.api._load_directory(self.pid)
return self._parent | [
"def",
"parent",
"(",
"self",
")",
":",
"if",
"self",
".",
"_parent",
"is",
"None",
":",
"if",
"self",
".",
"pid",
"is",
"not",
"None",
":",
"self",
".",
"_parent",
"=",
"self",
".",
"api",
".",
"_load_directory",
"(",
"self",
".",
"pid",
")",
"r... | Parent directory that holds this directory | [
"Parent",
"directory",
"that",
"holds",
"this",
"directory"
] | train | https://github.com/shichao-an/115wangpan/blob/e7cc935313f675e886bceca831fcffcdedf1e880/u115/api.py#L1348-L1353 |
shichao-an/115wangpan | u115/api.py | Directory.reload | def reload(self):
"""
Reload directory info and metadata
* `name`
* `pid`
* `count`
"""
r = self.api._req_directory(self.cid)
self.pid = r['pid']
self.name = r['name']
self._count = r['count'] | python | def reload(self):
"""
Reload directory info and metadata
* `name`
* `pid`
* `count`
"""
r = self.api._req_directory(self.cid)
self.pid = r['pid']
self.name = r['name']
self._count = r['count'] | [
"def",
"reload",
"(",
"self",
")",
":",
"r",
"=",
"self",
".",
"api",
".",
"_req_directory",
"(",
"self",
".",
"cid",
")",
"self",
".",
"pid",
"=",
"r",
"[",
"'pid'",
"]",
"self",
".",
"name",
"=",
"r",
"[",
"'name'",
"]",
"self",
".",
"_count"... | Reload directory info and metadata
* `name`
* `pid`
* `count` | [
"Reload",
"directory",
"info",
"and",
"metadata"
] | train | https://github.com/shichao-an/115wangpan/blob/e7cc935313f675e886bceca831fcffcdedf1e880/u115/api.py#L1362-L1374 |
shichao-an/115wangpan | u115/api.py | Directory._load_entries | def _load_entries(self, func, count, page=1, entries=None, **kwargs):
"""
Load entries
:param function func: function (:meth:`.API._req_files` or
:meth:`.API._req_search`) that returns entries
:param int count: number of entries to load. This value should never
b... | python | def _load_entries(self, func, count, page=1, entries=None, **kwargs):
"""
Load entries
:param function func: function (:meth:`.API._req_files` or
:meth:`.API._req_search`) that returns entries
:param int count: number of entries to load. This value should never
b... | [
"def",
"_load_entries",
"(",
"self",
",",
"func",
",",
"count",
",",
"page",
"=",
"1",
",",
"entries",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"entries",
"is",
"None",
":",
"entries",
"=",
"[",
"]",
"res",
"=",
"func",
"(",
"offset"... | Load entries
:param function func: function (:meth:`.API._req_files` or
:meth:`.API._req_search`) that returns entries
:param int count: number of entries to load. This value should never
be greater than self.count
:param int page: page number (starting from 1) | [
"Load",
"entries"
] | train | https://github.com/shichao-an/115wangpan/blob/e7cc935313f675e886bceca831fcffcdedf1e880/u115/api.py#L1376-L1407 |
shichao-an/115wangpan | u115/api.py | Directory.list | def list(self, count=30, order='user_ptime', asc=False, show_dir=True,
natsort=True):
"""
List directory contents
:param int count: number of entries to be listed
:param str order: order of entries, originally named `o`. This value
may be one of `user_ptime` (de... | python | def list(self, count=30, order='user_ptime', asc=False, show_dir=True,
natsort=True):
"""
List directory contents
:param int count: number of entries to be listed
:param str order: order of entries, originally named `o`. This value
may be one of `user_ptime` (de... | [
"def",
"list",
"(",
"self",
",",
"count",
"=",
"30",
",",
"order",
"=",
"'user_ptime'",
",",
"asc",
"=",
"False",
",",
"show_dir",
"=",
"True",
",",
"natsort",
"=",
"True",
")",
":",
"if",
"self",
".",
"cid",
"is",
"None",
":",
"return",
"False",
... | List directory contents
:param int count: number of entries to be listed
:param str order: order of entries, originally named `o`. This value
may be one of `user_ptime` (default), `file_size` and `file_name`
:param bool asc: whether in ascending order
:param bool show_dir: w... | [
"List",
"directory",
"contents"
] | train | https://github.com/shichao-an/115wangpan/blob/e7cc935313f675e886bceca831fcffcdedf1e880/u115/api.py#L1409-L1468 |
shichao-an/115wangpan | u115/api.py | Task.is_directory | def is_directory(self):
"""
:return: whether this task is associated with a directory.
:rtype: bool
"""
if self.cid is None:
msg = 'Cannot determine whether this task is a directory.'
if not self.is_transferred:
msg += ' This task has not b... | python | def is_directory(self):
"""
:return: whether this task is associated with a directory.
:rtype: bool
"""
if self.cid is None:
msg = 'Cannot determine whether this task is a directory.'
if not self.is_transferred:
msg += ' This task has not b... | [
"def",
"is_directory",
"(",
"self",
")",
":",
"if",
"self",
".",
"cid",
"is",
"None",
":",
"msg",
"=",
"'Cannot determine whether this task is a directory.'",
"if",
"not",
"self",
".",
"is_transferred",
":",
"msg",
"+=",
"' This task has not been transferred.'",
"ra... | :return: whether this task is associated with a directory.
:rtype: bool | [
":",
"return",
":",
"whether",
"this",
"task",
"is",
"associated",
"with",
"a",
"directory",
".",
":",
"rtype",
":",
"bool"
] | train | https://github.com/shichao-an/115wangpan/blob/e7cc935313f675e886bceca831fcffcdedf1e880/u115/api.py#L1538-L1548 |
shichao-an/115wangpan | u115/api.py | Task.delete | def delete(self):
"""
Delete task (does not influence its corresponding directory)
:return: whether deletion is successful
:raise: :class:`.TaskError` if the task is already deleted
"""
if not self._deleted:
if self.api._req_lixian_task_del(self):
... | python | def delete(self):
"""
Delete task (does not influence its corresponding directory)
:return: whether deletion is successful
:raise: :class:`.TaskError` if the task is already deleted
"""
if not self._deleted:
if self.api._req_lixian_task_del(self):
... | [
"def",
"delete",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"_deleted",
":",
"if",
"self",
".",
"api",
".",
"_req_lixian_task_del",
"(",
"self",
")",
":",
"self",
".",
"_deleted",
"=",
"True",
"return",
"True",
"raise",
"TaskError",
"(",
"'This t... | Delete task (does not influence its corresponding directory)
:return: whether deletion is successful
:raise: :class:`.TaskError` if the task is already deleted | [
"Delete",
"task",
"(",
"does",
"not",
"influence",
"its",
"corresponding",
"directory",
")"
] | train | https://github.com/shichao-an/115wangpan/blob/e7cc935313f675e886bceca831fcffcdedf1e880/u115/api.py#L1555-L1566 |
shichao-an/115wangpan | u115/api.py | Task.status_human | def status_human(self):
"""
Human readable status
:return:
* `DOWNLOADING`: the task is downloading files
* `BEING TRANSFERRED`: the task is being transferred
* `TRANSFERRED`: the task has been transferred to downloads \
directory
... | python | def status_human(self):
"""
Human readable status
:return:
* `DOWNLOADING`: the task is downloading files
* `BEING TRANSFERRED`: the task is being transferred
* `TRANSFERRED`: the task has been transferred to downloads \
directory
... | [
"def",
"status_human",
"(",
"self",
")",
":",
"res",
"=",
"None",
"if",
"self",
".",
"_deleted",
":",
"return",
"'DELETED'",
"if",
"self",
".",
"status",
"==",
"1",
":",
"res",
"=",
"'DOWNLOADING'",
"elif",
"self",
".",
"status",
"==",
"2",
":",
"if"... | Human readable status
:return:
* `DOWNLOADING`: the task is downloading files
* `BEING TRANSFERRED`: the task is being transferred
* `TRANSFERRED`: the task has been transferred to downloads \
directory
* `SEARCHING RESOURCES`: the task is se... | [
"Human",
"readable",
"status"
] | train | https://github.com/shichao-an/115wangpan/blob/e7cc935313f675e886bceca831fcffcdedf1e880/u115/api.py#L1585-L1621 |
shichao-an/115wangpan | u115/api.py | Task.directory | def directory(self):
"""Associated directory, if any, with this task"""
if not self.is_directory:
msg = 'This task is a file task with no associated directory.'
raise TaskError(msg)
if self._directory is None:
if self.is_transferred:
self._dire... | python | def directory(self):
"""Associated directory, if any, with this task"""
if not self.is_directory:
msg = 'This task is a file task with no associated directory.'
raise TaskError(msg)
if self._directory is None:
if self.is_transferred:
self._dire... | [
"def",
"directory",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"is_directory",
":",
"msg",
"=",
"'This task is a file task with no associated directory.'",
"raise",
"TaskError",
"(",
"msg",
")",
"if",
"self",
".",
"_directory",
"is",
"None",
":",
"if",
"... | Associated directory, if any, with this task | [
"Associated",
"directory",
"if",
"any",
"with",
"this",
"task"
] | train | https://github.com/shichao-an/115wangpan/blob/e7cc935313f675e886bceca831fcffcdedf1e880/u115/api.py#L1624-L1636 |
shichao-an/115wangpan | u115/api.py | Task.list | def list(self, count=30, order='user_ptime', asc=False, show_dir=True,
natsort=True):
"""
List files of the associated directory to this task.
:param int count: number of entries to be listed
:param str order: originally named `o`
:param bool asc: whether in ascendi... | python | def list(self, count=30, order='user_ptime', asc=False, show_dir=True,
natsort=True):
"""
List files of the associated directory to this task.
:param int count: number of entries to be listed
:param str order: originally named `o`
:param bool asc: whether in ascendi... | [
"def",
"list",
"(",
"self",
",",
"count",
"=",
"30",
",",
"order",
"=",
"'user_ptime'",
",",
"asc",
"=",
"False",
",",
"show_dir",
"=",
"True",
",",
"natsort",
"=",
"True",
")",
":",
"return",
"self",
".",
"directory",
".",
"list",
"(",
"count",
",... | List files of the associated directory to this task.
:param int count: number of entries to be listed
:param str order: originally named `o`
:param bool asc: whether in ascending order
:param bool show_dir: whether to show directories | [
"List",
"files",
"of",
"the",
"associated",
"directory",
"to",
"this",
"task",
"."
] | train | https://github.com/shichao-an/115wangpan/blob/e7cc935313f675e886bceca831fcffcdedf1e880/u115/api.py#L1648-L1659 |
shichao-an/115wangpan | u115/api.py | Torrent.submit | def submit(self):
"""Submit this torrent and create a new task"""
if self.api._req_lixian_add_task_bt(self):
self.submitted = True
return True
return False | python | def submit(self):
"""Submit this torrent and create a new task"""
if self.api._req_lixian_add_task_bt(self):
self.submitted = True
return True
return False | [
"def",
"submit",
"(",
"self",
")",
":",
"if",
"self",
".",
"api",
".",
"_req_lixian_add_task_bt",
"(",
"self",
")",
":",
"self",
".",
"submitted",
"=",
"True",
"return",
"True",
"return",
"False"
] | Submit this torrent and create a new task | [
"Submit",
"this",
"torrent",
"and",
"create",
"a",
"new",
"task"
] | train | https://github.com/shichao-an/115wangpan/blob/e7cc935313f675e886bceca831fcffcdedf1e880/u115/api.py#L1689-L1694 |
klis87/django-cloudinary-storage | cloudinary_storage/management/commands/deleteredundantstatic.py | Command.get_needful_files | def get_needful_files(self):
"""
Returns currently used static files.
Assumes that manifest staticfiles.json is up-to-date.
"""
manifest = self.storage.load_manifest()
if self.keep_unhashed_files:
if PY3:
needful_files = set(manifest.keys() | m... | python | def get_needful_files(self):
"""
Returns currently used static files.
Assumes that manifest staticfiles.json is up-to-date.
"""
manifest = self.storage.load_manifest()
if self.keep_unhashed_files:
if PY3:
needful_files = set(manifest.keys() | m... | [
"def",
"get_needful_files",
"(",
"self",
")",
":",
"manifest",
"=",
"self",
".",
"storage",
".",
"load_manifest",
"(",
")",
"if",
"self",
".",
"keep_unhashed_files",
":",
"if",
"PY3",
":",
"needful_files",
"=",
"set",
"(",
"manifest",
".",
"keys",
"(",
"... | Returns currently used static files.
Assumes that manifest staticfiles.json is up-to-date. | [
"Returns",
"currently",
"used",
"static",
"files",
".",
"Assumes",
"that",
"manifest",
"staticfiles",
".",
"json",
"is",
"up",
"-",
"to",
"-",
"date",
"."
] | train | https://github.com/klis87/django-cloudinary-storage/blob/b8cabd2ebbf67b9cfbbf4defee1a750fea5950a9/cloudinary_storage/management/commands/deleteredundantstatic.py#L37-L51 |
klis87/django-cloudinary-storage | cloudinary_storage/management/commands/deleteorphanedmedia.py | Command.model_file_fields | def model_file_fields(self, model):
"""
Generator yielding all instances of FileField and its subclasses of a model.
"""
for field in model._meta.fields:
if isinstance(field, models.FileField):
yield field | python | def model_file_fields(self, model):
"""
Generator yielding all instances of FileField and its subclasses of a model.
"""
for field in model._meta.fields:
if isinstance(field, models.FileField):
yield field | [
"def",
"model_file_fields",
"(",
"self",
",",
"model",
")",
":",
"for",
"field",
"in",
"model",
".",
"_meta",
".",
"fields",
":",
"if",
"isinstance",
"(",
"field",
",",
"models",
".",
"FileField",
")",
":",
"yield",
"field"
] | Generator yielding all instances of FileField and its subclasses of a model. | [
"Generator",
"yielding",
"all",
"instances",
"of",
"FileField",
"and",
"its",
"subclasses",
"of",
"a",
"model",
"."
] | train | https://github.com/klis87/django-cloudinary-storage/blob/b8cabd2ebbf67b9cfbbf4defee1a750fea5950a9/cloudinary_storage/management/commands/deleteorphanedmedia.py#L30-L36 |
klis87/django-cloudinary-storage | cloudinary_storage/management/commands/deleteorphanedmedia.py | Command.get_resource_types | def get_resource_types(self):
"""
Returns set of resource types of FileFields of all registered models.
Needed by Cloudinary as resource type is needed to browse or delete specific files.
"""
resource_types = set()
for model in self.models():
for field in self... | python | def get_resource_types(self):
"""
Returns set of resource types of FileFields of all registered models.
Needed by Cloudinary as resource type is needed to browse or delete specific files.
"""
resource_types = set()
for model in self.models():
for field in self... | [
"def",
"get_resource_types",
"(",
"self",
")",
":",
"resource_types",
"=",
"set",
"(",
")",
"for",
"model",
"in",
"self",
".",
"models",
"(",
")",
":",
"for",
"field",
"in",
"self",
".",
"model_file_fields",
"(",
"model",
")",
":",
"resource_type",
"=",
... | Returns set of resource types of FileFields of all registered models.
Needed by Cloudinary as resource type is needed to browse or delete specific files. | [
"Returns",
"set",
"of",
"resource",
"types",
"of",
"FileFields",
"of",
"all",
"registered",
"models",
".",
"Needed",
"by",
"Cloudinary",
"as",
"resource",
"type",
"is",
"needed",
"to",
"browse",
"or",
"delete",
"specific",
"files",
"."
] | train | https://github.com/klis87/django-cloudinary-storage/blob/b8cabd2ebbf67b9cfbbf4defee1a750fea5950a9/cloudinary_storage/management/commands/deleteorphanedmedia.py#L38-L48 |
klis87/django-cloudinary-storage | cloudinary_storage/management/commands/deleteorphanedmedia.py | Command.get_needful_files | def get_needful_files(self):
"""
Returns set of media files associated with models.
Those files won't be deleted.
"""
needful_files = []
for model in self.models():
media_fields = []
for field in self.model_file_fields(model):
media... | python | def get_needful_files(self):
"""
Returns set of media files associated with models.
Those files won't be deleted.
"""
needful_files = []
for model in self.models():
media_fields = []
for field in self.model_file_fields(model):
media... | [
"def",
"get_needful_files",
"(",
"self",
")",
":",
"needful_files",
"=",
"[",
"]",
"for",
"model",
"in",
"self",
".",
"models",
"(",
")",
":",
"media_fields",
"=",
"[",
"]",
"for",
"field",
"in",
"self",
".",
"model_file_fields",
"(",
"model",
")",
":"... | Returns set of media files associated with models.
Those files won't be deleted. | [
"Returns",
"set",
"of",
"media",
"files",
"associated",
"with",
"models",
".",
"Those",
"files",
"won",
"t",
"be",
"deleted",
"."
] | train | https://github.com/klis87/django-cloudinary-storage/blob/b8cabd2ebbf67b9cfbbf4defee1a750fea5950a9/cloudinary_storage/management/commands/deleteorphanedmedia.py#L50-L64 |
klis87/django-cloudinary-storage | cloudinary_storage/management/commands/deleteorphanedmedia.py | Command.get_files_to_remove | def get_files_to_remove(self):
"""
Returns orphaned media files to be removed grouped by resource type.
All files which paths start with any of exclude paths are ignored.
"""
files_to_remove = {}
needful_files = self.get_needful_files()
for resources_type, resourc... | python | def get_files_to_remove(self):
"""
Returns orphaned media files to be removed grouped by resource type.
All files which paths start with any of exclude paths are ignored.
"""
files_to_remove = {}
needful_files = self.get_needful_files()
for resources_type, resourc... | [
"def",
"get_files_to_remove",
"(",
"self",
")",
":",
"files_to_remove",
"=",
"{",
"}",
"needful_files",
"=",
"self",
".",
"get_needful_files",
"(",
")",
"for",
"resources_type",
",",
"resources",
"in",
"self",
".",
"get_uploaded_resources",
"(",
")",
":",
"exc... | Returns orphaned media files to be removed grouped by resource type.
All files which paths start with any of exclude paths are ignored. | [
"Returns",
"orphaned",
"media",
"files",
"to",
"be",
"removed",
"grouped",
"by",
"resource",
"type",
".",
"All",
"files",
"which",
"paths",
"start",
"with",
"any",
"of",
"exclude",
"paths",
"are",
"ignored",
"."
] | train | https://github.com/klis87/django-cloudinary-storage/blob/b8cabd2ebbf67b9cfbbf4defee1a750fea5950a9/cloudinary_storage/management/commands/deleteorphanedmedia.py#L71-L82 |
klis87/django-cloudinary-storage | cloudinary_storage/storage.py | StaticCloudinaryStorage._get_resource_type | def _get_resource_type(self, name):
"""
Implemented as static files can be of different resource types.
Because web developers are the people who control those files, we can distinguish them
simply by looking at their extensions, we don't need any content based validation.
"""
... | python | def _get_resource_type(self, name):
"""
Implemented as static files can be of different resource types.
Because web developers are the people who control those files, we can distinguish them
simply by looking at their extensions, we don't need any content based validation.
"""
... | [
"def",
"_get_resource_type",
"(",
"self",
",",
"name",
")",
":",
"extension",
"=",
"self",
".",
"_get_file_extension",
"(",
"name",
")",
"if",
"extension",
"is",
"None",
":",
"return",
"self",
".",
"RESOURCE_TYPE",
"elif",
"extension",
"in",
"app_settings",
... | Implemented as static files can be of different resource types.
Because web developers are the people who control those files, we can distinguish them
simply by looking at their extensions, we don't need any content based validation. | [
"Implemented",
"as",
"static",
"files",
"can",
"be",
"of",
"different",
"resource",
"types",
".",
"Because",
"web",
"developers",
"are",
"the",
"people",
"who",
"control",
"those",
"files",
"we",
"can",
"distinguish",
"them",
"simply",
"by",
"looking",
"at",
... | train | https://github.com/klis87/django-cloudinary-storage/blob/b8cabd2ebbf67b9cfbbf4defee1a750fea5950a9/cloudinary_storage/storage.py#L165-L179 |
klis87/django-cloudinary-storage | cloudinary_storage/storage.py | StaticCloudinaryStorage._remove_extension_for_non_raw_file | def _remove_extension_for_non_raw_file(self, name):
"""
Implemented as image and video files' Cloudinary public id
shouldn't contain file extensions, otherwise Cloudinary url
would contain doubled extension - Cloudinary adds extension to url
to allow file conversion to arbitrary ... | python | def _remove_extension_for_non_raw_file(self, name):
"""
Implemented as image and video files' Cloudinary public id
shouldn't contain file extensions, otherwise Cloudinary url
would contain doubled extension - Cloudinary adds extension to url
to allow file conversion to arbitrary ... | [
"def",
"_remove_extension_for_non_raw_file",
"(",
"self",
",",
"name",
")",
":",
"file_resource_type",
"=",
"self",
".",
"_get_resource_type",
"(",
"name",
")",
"if",
"file_resource_type",
"is",
"None",
"or",
"file_resource_type",
"==",
"self",
".",
"RESOURCE_TYPE",... | Implemented as image and video files' Cloudinary public id
shouldn't contain file extensions, otherwise Cloudinary url
would contain doubled extension - Cloudinary adds extension to url
to allow file conversion to arbitrary file, like png to jpg. | [
"Implemented",
"as",
"image",
"and",
"video",
"files",
"Cloudinary",
"public",
"id",
"shouldn",
"t",
"contain",
"file",
"extensions",
"otherwise",
"Cloudinary",
"url",
"would",
"contain",
"doubled",
"extension",
"-",
"Cloudinary",
"adds",
"extension",
"to",
"url",... | train | https://github.com/klis87/django-cloudinary-storage/blob/b8cabd2ebbf67b9cfbbf4defee1a750fea5950a9/cloudinary_storage/storage.py#L200-L212 |
klis87/django-cloudinary-storage | cloudinary_storage/storage.py | StaticCloudinaryStorage._exists_with_etag | def _exists_with_etag(self, name, content):
"""
Checks whether a file with a name and a content is already uploaded to Cloudinary.
Uses ETAG header and MD5 hash for the content comparison.
"""
url = self._get_url(name)
response = requests.head(url)
if response.sta... | python | def _exists_with_etag(self, name, content):
"""
Checks whether a file with a name and a content is already uploaded to Cloudinary.
Uses ETAG header and MD5 hash for the content comparison.
"""
url = self._get_url(name)
response = requests.head(url)
if response.sta... | [
"def",
"_exists_with_etag",
"(",
"self",
",",
"name",
",",
"content",
")",
":",
"url",
"=",
"self",
".",
"_get_url",
"(",
"name",
")",
"response",
"=",
"requests",
".",
"head",
"(",
"url",
")",
"if",
"response",
".",
"status_code",
"==",
"404",
":",
... | Checks whether a file with a name and a content is already uploaded to Cloudinary.
Uses ETAG header and MD5 hash for the content comparison. | [
"Checks",
"whether",
"a",
"file",
"with",
"a",
"name",
"and",
"a",
"content",
"is",
"already",
"uploaded",
"to",
"Cloudinary",
".",
"Uses",
"ETAG",
"header",
"and",
"MD5",
"hash",
"for",
"the",
"content",
"comparison",
"."
] | train | https://github.com/klis87/django-cloudinary-storage/blob/b8cabd2ebbf67b9cfbbf4defee1a750fea5950a9/cloudinary_storage/storage.py#L218-L229 |
klis87/django-cloudinary-storage | cloudinary_storage/storage.py | StaticCloudinaryStorage._save | def _save(self, name, content):
"""
Saves only when a file with a name and a content is not already uploaded to Cloudinary.
"""
name = self.clean_name(name) # to change to UNIX style path on windows if necessary
if not self._exists_with_etag(name, content):
content.s... | python | def _save(self, name, content):
"""
Saves only when a file with a name and a content is not already uploaded to Cloudinary.
"""
name = self.clean_name(name) # to change to UNIX style path on windows if necessary
if not self._exists_with_etag(name, content):
content.s... | [
"def",
"_save",
"(",
"self",
",",
"name",
",",
"content",
")",
":",
"name",
"=",
"self",
".",
"clean_name",
"(",
"name",
")",
"# to change to UNIX style path on windows if necessary",
"if",
"not",
"self",
".",
"_exists_with_etag",
"(",
"name",
",",
"content",
... | Saves only when a file with a name and a content is not already uploaded to Cloudinary. | [
"Saves",
"only",
"when",
"a",
"file",
"with",
"a",
"name",
"and",
"a",
"content",
"is",
"not",
"already",
"uploaded",
"to",
"Cloudinary",
"."
] | train | https://github.com/klis87/django-cloudinary-storage/blob/b8cabd2ebbf67b9cfbbf4defee1a750fea5950a9/cloudinary_storage/storage.py#L231-L239 |
nevimov/django-easycart | easycart/cart.py | BaseCart.add | def add(self, pk, quantity=1, **kwargs):
"""Add an item to the cart.
If the item is already in the cart, then its quantity will be
increased by `quantity` units.
Parameters
----------
pk : str or int
The primary key of the item.
quantity : int-conver... | python | def add(self, pk, quantity=1, **kwargs):
"""Add an item to the cart.
If the item is already in the cart, then its quantity will be
increased by `quantity` units.
Parameters
----------
pk : str or int
The primary key of the item.
quantity : int-conver... | [
"def",
"add",
"(",
"self",
",",
"pk",
",",
"quantity",
"=",
"1",
",",
"*",
"*",
"kwargs",
")",
":",
"pk",
"=",
"str",
"(",
"pk",
")",
"if",
"pk",
"in",
"self",
".",
"items",
":",
"existing_item",
"=",
"self",
".",
"items",
"[",
"pk",
"]",
"ex... | Add an item to the cart.
If the item is already in the cart, then its quantity will be
increased by `quantity` units.
Parameters
----------
pk : str or int
The primary key of the item.
quantity : int-convertible
A number of units of to add.
... | [
"Add",
"an",
"item",
"to",
"the",
"cart",
"."
] | train | https://github.com/nevimov/django-easycart/blob/81b7d7d4b197e34d21dcd8cb9eb9104b565041a9/easycart/cart.py#L193-L230 |
nevimov/django-easycart | easycart/cart.py | BaseCart.change_quantity | def change_quantity(self, pk, quantity):
"""Change the quantity of an item.
Parameters
----------
pk : str or int
The primary key of the item.
quantity : int-convertible
A new quantity.
Raises
------
ItemNotInCart
Negative... | python | def change_quantity(self, pk, quantity):
"""Change the quantity of an item.
Parameters
----------
pk : str or int
The primary key of the item.
quantity : int-convertible
A new quantity.
Raises
------
ItemNotInCart
Negative... | [
"def",
"change_quantity",
"(",
"self",
",",
"pk",
",",
"quantity",
")",
":",
"pk",
"=",
"str",
"(",
"pk",
")",
"try",
":",
"item",
"=",
"self",
".",
"items",
"[",
"pk",
"]",
"except",
"KeyError",
":",
"raise",
"ItemNotInCart",
"(",
"pk",
"=",
"pk",... | Change the quantity of an item.
Parameters
----------
pk : str or int
The primary key of the item.
quantity : int-convertible
A new quantity.
Raises
------
ItemNotInCart
NegativeItemQuantity
NonConvertibleItemQuantity
... | [
"Change",
"the",
"quantity",
"of",
"an",
"item",
"."
] | train | https://github.com/nevimov/django-easycart/blob/81b7d7d4b197e34d21dcd8cb9eb9104b565041a9/easycart/cart.py#L232-L257 |
nevimov/django-easycart | easycart/cart.py | BaseCart.remove | def remove(self, pk):
"""Remove an item from the cart.
Parameters
----------
pk : str or int
The primary key of the item.
Raises
------
ItemNotInCart
"""
pk = str(pk)
try:
del self.items[pk]
except KeyErro... | python | def remove(self, pk):
"""Remove an item from the cart.
Parameters
----------
pk : str or int
The primary key of the item.
Raises
------
ItemNotInCart
"""
pk = str(pk)
try:
del self.items[pk]
except KeyErro... | [
"def",
"remove",
"(",
"self",
",",
"pk",
")",
":",
"pk",
"=",
"str",
"(",
"pk",
")",
"try",
":",
"del",
"self",
".",
"items",
"[",
"pk",
"]",
"except",
"KeyError",
":",
"raise",
"ItemNotInCart",
"(",
"pk",
"=",
"pk",
")",
"self",
".",
"update",
... | Remove an item from the cart.
Parameters
----------
pk : str or int
The primary key of the item.
Raises
------
ItemNotInCart | [
"Remove",
"an",
"item",
"from",
"the",
"cart",
"."
] | train | https://github.com/nevimov/django-easycart/blob/81b7d7d4b197e34d21dcd8cb9eb9104b565041a9/easycart/cart.py#L259-L277 |
nevimov/django-easycart | easycart/cart.py | BaseCart.list_items | def list_items(self, sort_key=None, reverse=False):
"""Return a list of cart items.
Parameters
----------
sort_key : func
A function to customize the list order, same as the 'key'
argument to the built-in :func:`sorted`.
reverse: bool
If set t... | python | def list_items(self, sort_key=None, reverse=False):
"""Return a list of cart items.
Parameters
----------
sort_key : func
A function to customize the list order, same as the 'key'
argument to the built-in :func:`sorted`.
reverse: bool
If set t... | [
"def",
"list_items",
"(",
"self",
",",
"sort_key",
"=",
"None",
",",
"reverse",
"=",
"False",
")",
":",
"items",
"=",
"list",
"(",
"self",
".",
"items",
".",
"values",
"(",
")",
")",
"if",
"sort_key",
":",
"items",
".",
"sort",
"(",
"key",
"=",
"... | Return a list of cart items.
Parameters
----------
sort_key : func
A function to customize the list order, same as the 'key'
argument to the built-in :func:`sorted`.
reverse: bool
If set to True, the sort order will be reversed.
Returns
... | [
"Return",
"a",
"list",
"of",
"cart",
"items",
"."
] | train | https://github.com/nevimov/django-easycart/blob/81b7d7d4b197e34d21dcd8cb9eb9104b565041a9/easycart/cart.py#L284-L316 |
nevimov/django-easycart | easycart/cart.py | BaseCart.encode | def encode(self, formatter=None):
"""Return a representation of the cart as a JSON-response.
Parameters
----------
formatter : func, optional
A function that accepts the cart representation and returns
its formatted version.
Returns
-------
... | python | def encode(self, formatter=None):
"""Return a representation of the cart as a JSON-response.
Parameters
----------
formatter : func, optional
A function that accepts the cart representation and returns
its formatted version.
Returns
-------
... | [
"def",
"encode",
"(",
"self",
",",
"formatter",
"=",
"None",
")",
":",
"items",
"=",
"{",
"}",
"# The prices are converted to strings, because they may have a",
"# type that can't be serialized to JSON (e.g. Decimal).",
"for",
"item",
"in",
"self",
".",
"items",
".",
"v... | Return a representation of the cart as a JSON-response.
Parameters
----------
formatter : func, optional
A function that accepts the cart representation and returns
its formatted version.
Returns
-------
django.http.JsonResponse
Examples... | [
"Return",
"a",
"representation",
"of",
"the",
"cart",
"as",
"a",
"JSON",
"-",
"response",
"."
] | train | https://github.com/nevimov/django-easycart/blob/81b7d7d4b197e34d21dcd8cb9eb9104b565041a9/easycart/cart.py#L318-L369 |
nevimov/django-easycart | easycart/cart.py | BaseCart.create_items | def create_items(self, session_items):
"""Instantiate cart items from session data.
The value returned by this method is used to populate the
cart's `items` attribute.
Parameters
----------
session_items : dict
A dictionary of pk-quantity mappings (each pk i... | python | def create_items(self, session_items):
"""Instantiate cart items from session data.
The value returned by this method is used to populate the
cart's `items` attribute.
Parameters
----------
session_items : dict
A dictionary of pk-quantity mappings (each pk i... | [
"def",
"create_items",
"(",
"self",
",",
"session_items",
")",
":",
"pks",
"=",
"list",
"(",
"session_items",
".",
"keys",
"(",
")",
")",
"items",
"=",
"{",
"}",
"item_class",
"=",
"self",
".",
"item_class",
"process_object",
"=",
"self",
".",
"process_o... | Instantiate cart items from session data.
The value returned by this method is used to populate the
cart's `items` attribute.
Parameters
----------
session_items : dict
A dictionary of pk-quantity mappings (each pk is a string).
For example: ``{'1': 5, '... | [
"Instantiate",
"cart",
"items",
"from",
"session",
"data",
"."
] | train | https://github.com/nevimov/django-easycart/blob/81b7d7d4b197e34d21dcd8cb9eb9104b565041a9/easycart/cart.py#L437-L469 |
nevimov/django-easycart | easycart/cart.py | BaseCart.update | def update(self):
"""Update the cart.
First this method updates attributes dependent on the cart's
`items`, such as `total_price` or `item_count`.
After that, it saves the new cart state to the session.
Generally, you'll need to call this method by yourself, only
when i... | python | def update(self):
"""Update the cart.
First this method updates attributes dependent on the cart's
`items`, such as `total_price` or `item_count`.
After that, it saves the new cart state to the session.
Generally, you'll need to call this method by yourself, only
when i... | [
"def",
"update",
"(",
"self",
")",
":",
"self",
".",
"item_count",
"=",
"self",
".",
"count_items",
"(",
")",
"self",
".",
"total_price",
"=",
"self",
".",
"count_total_price",
"(",
")",
"# Update the session",
"session",
"=",
"self",
".",
"request",
".",
... | Update the cart.
First this method updates attributes dependent on the cart's
`items`, such as `total_price` or `item_count`.
After that, it saves the new cart state to the session.
Generally, you'll need to call this method by yourself, only
when implementing new methods that ... | [
"Update",
"the",
"cart",
"."
] | train | https://github.com/nevimov/django-easycart/blob/81b7d7d4b197e34d21dcd8cb9eb9104b565041a9/easycart/cart.py#L471-L495 |
nevimov/django-easycart | easycart/cart.py | BaseCart.count_items | def count_items(self, unique=True):
"""Count items in the cart.
Parameters
----------
unique : bool-convertible, optional
Returns
-------
int
If `unique` is truthy, then the result is the number of
items in the cart. Otherwise, it's the s... | python | def count_items(self, unique=True):
"""Count items in the cart.
Parameters
----------
unique : bool-convertible, optional
Returns
-------
int
If `unique` is truthy, then the result is the number of
items in the cart. Otherwise, it's the s... | [
"def",
"count_items",
"(",
"self",
",",
"unique",
"=",
"True",
")",
":",
"if",
"unique",
":",
"return",
"len",
"(",
"self",
".",
"items",
")",
"return",
"sum",
"(",
"[",
"item",
".",
"quantity",
"for",
"item",
"in",
"self",
".",
"items",
".",
"valu... | Count items in the cart.
Parameters
----------
unique : bool-convertible, optional
Returns
-------
int
If `unique` is truthy, then the result is the number of
items in the cart. Otherwise, it's the sum of all item
quantities. | [
"Count",
"items",
"in",
"the",
"cart",
"."
] | train | https://github.com/nevimov/django-easycart/blob/81b7d7d4b197e34d21dcd8cb9eb9104b565041a9/easycart/cart.py#L497-L514 |
klis87/django-cloudinary-storage | cloudinary_storage/management/commands/collectstatic.py | Command.copy_file | def copy_file(self, path, prefixed_path, source_storage):
"""
Overwritten to execute only with --upload-unhashed-files param or StaticCloudinaryStorage.
Otherwise only hashed files will be uploaded during postprocessing.
"""
if (settings.STATICFILES_STORAGE == 'cloudinary_storage... | python | def copy_file(self, path, prefixed_path, source_storage):
"""
Overwritten to execute only with --upload-unhashed-files param or StaticCloudinaryStorage.
Otherwise only hashed files will be uploaded during postprocessing.
"""
if (settings.STATICFILES_STORAGE == 'cloudinary_storage... | [
"def",
"copy_file",
"(",
"self",
",",
"path",
",",
"prefixed_path",
",",
"source_storage",
")",
":",
"if",
"(",
"settings",
".",
"STATICFILES_STORAGE",
"==",
"'cloudinary_storage.storage.StaticCloudinaryStorage'",
"or",
"self",
".",
"upload_unhashed_files",
")",
":",
... | Overwritten to execute only with --upload-unhashed-files param or StaticCloudinaryStorage.
Otherwise only hashed files will be uploaded during postprocessing. | [
"Overwritten",
"to",
"execute",
"only",
"with",
"--",
"upload",
"-",
"unhashed",
"-",
"files",
"param",
"or",
"StaticCloudinaryStorage",
".",
"Otherwise",
"only",
"hashed",
"files",
"will",
"be",
"uploaded",
"during",
"postprocessing",
"."
] | train | https://github.com/klis87/django-cloudinary-storage/blob/b8cabd2ebbf67b9cfbbf4defee1a750fea5950a9/cloudinary_storage/management/commands/collectstatic.py#L22-L29 |
PyconUK/ConferenceScheduler | src/conference_scheduler/heuristics/hill_climber.py | hill_climber | def hill_climber(objective_function,
initial_array,
lower_bound=-float('inf'),
acceptance_criteria=None,
max_iterations=10 ** 3):
"""
Implement a basic hill climbing algorithm.
Has two stopping conditions:
1. Maximum number of iterati... | python | def hill_climber(objective_function,
initial_array,
lower_bound=-float('inf'),
acceptance_criteria=None,
max_iterations=10 ** 3):
"""
Implement a basic hill climbing algorithm.
Has two stopping conditions:
1. Maximum number of iterati... | [
"def",
"hill_climber",
"(",
"objective_function",
",",
"initial_array",
",",
"lower_bound",
"=",
"-",
"float",
"(",
"'inf'",
")",
",",
"acceptance_criteria",
"=",
"None",
",",
"max_iterations",
"=",
"10",
"**",
"3",
")",
":",
"X",
"=",
"initial_array",
"if",... | Implement a basic hill climbing algorithm.
Has two stopping conditions:
1. Maximum number of iterations;
2. A known lower bound, a none is passed then this is not used.
If acceptance_criteria (a callable) is not None then this is used to obtain
an upper bound on some other measure (different to t... | [
"Implement",
"a",
"basic",
"hill",
"climbing",
"algorithm",
"."
] | train | https://github.com/PyconUK/ConferenceScheduler/blob/fb139f0ef2eab5ac8f4919aa4994d94d4e040030/src/conference_scheduler/heuristics/hill_climber.py#L4-L47 |
PyconUK/ConferenceScheduler | src/conference_scheduler/heuristics/simulated_annealing.py | simulated_annealing | def simulated_annealing(objective_function,
initial_array,
initial_temperature=10 ** 4,
cooldown_rate=0.7,
acceptance_criteria=None,
lower_bound=-float('inf'),
max_iterations=1... | python | def simulated_annealing(objective_function,
initial_array,
initial_temperature=10 ** 4,
cooldown_rate=0.7,
acceptance_criteria=None,
lower_bound=-float('inf'),
max_iterations=1... | [
"def",
"simulated_annealing",
"(",
"objective_function",
",",
"initial_array",
",",
"initial_temperature",
"=",
"10",
"**",
"4",
",",
"cooldown_rate",
"=",
"0.7",
",",
"acceptance_criteria",
"=",
"None",
",",
"lower_bound",
"=",
"-",
"float",
"(",
"'inf'",
")",
... | Implement a simulated annealing algorithm with exponential cooling
Has two stopping conditions:
1. Maximum number of iterations;
2. A known lower bound, a none is passed then this is not used.
Note that starting with an initial_temperature corresponds to a hill
climbing algorithm | [
"Implement",
"a",
"simulated",
"annealing",
"algorithm",
"with",
"exponential",
"cooling"
] | train | https://github.com/PyconUK/ConferenceScheduler/blob/fb139f0ef2eab5ac8f4919aa4994d94d4e040030/src/conference_scheduler/heuristics/simulated_annealing.py#L5-L59 |
PyconUK/ConferenceScheduler | src/conference_scheduler/lp_problem/constraints.py | _events_available_in_scheduled_slot | def _events_available_in_scheduled_slot(events, slots, X, **kwargs):
"""
Constraint that ensures that an event is scheduled in slots for which it is
available
"""
slot_availability_array = lpu.slot_availability_array(slots=slots,
events=event... | python | def _events_available_in_scheduled_slot(events, slots, X, **kwargs):
"""
Constraint that ensures that an event is scheduled in slots for which it is
available
"""
slot_availability_array = lpu.slot_availability_array(slots=slots,
events=event... | [
"def",
"_events_available_in_scheduled_slot",
"(",
"events",
",",
"slots",
",",
"X",
",",
"*",
"*",
"kwargs",
")",
":",
"slot_availability_array",
"=",
"lpu",
".",
"slot_availability_array",
"(",
"slots",
"=",
"slots",
",",
"events",
"=",
"events",
")",
"label... | Constraint that ensures that an event is scheduled in slots for which it is
available | [
"Constraint",
"that",
"ensures",
"that",
"an",
"event",
"is",
"scheduled",
"in",
"slots",
"for",
"which",
"it",
"is",
"available"
] | train | https://github.com/PyconUK/ConferenceScheduler/blob/fb139f0ef2eab5ac8f4919aa4994d94d4e040030/src/conference_scheduler/lp_problem/constraints.py#L32-L47 |
PyconUK/ConferenceScheduler | src/conference_scheduler/lp_problem/constraints.py | _events_available_during_other_events | def _events_available_during_other_events(
events, slots, X, summation_type=None, **kwargs
):
"""
Constraint that ensures that an event is not scheduled at the same time as
another event for which it is unavailable. Unavailability of events is
either because it is explicitly defined or because they ... | python | def _events_available_during_other_events(
events, slots, X, summation_type=None, **kwargs
):
"""
Constraint that ensures that an event is not scheduled at the same time as
another event for which it is unavailable. Unavailability of events is
either because it is explicitly defined or because they ... | [
"def",
"_events_available_during_other_events",
"(",
"events",
",",
"slots",
",",
"X",
",",
"summation_type",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"summation",
"=",
"lpu",
".",
"summation_functions",
"[",
"summation_type",
"]",
"event_availability_array... | Constraint that ensures that an event is not scheduled at the same time as
another event for which it is unavailable. Unavailability of events is
either because it is explicitly defined or because they share a tag. | [
"Constraint",
"that",
"ensures",
"that",
"an",
"event",
"is",
"not",
"scheduled",
"at",
"the",
"same",
"time",
"as",
"another",
"event",
"for",
"which",
"it",
"is",
"unavailable",
".",
"Unavailability",
"of",
"events",
"is",
"either",
"because",
"it",
"is",
... | train | https://github.com/PyconUK/ConferenceScheduler/blob/fb139f0ef2eab5ac8f4919aa4994d94d4e040030/src/conference_scheduler/lp_problem/constraints.py#L50-L72 |
PyconUK/ConferenceScheduler | src/conference_scheduler/lp_problem/constraints.py | _upper_bound_on_event_overflow | def _upper_bound_on_event_overflow(
events, slots, X, beta, summation_type=None, **kwargs
):
"""
This is an artificial constraint that is used by the objective function
aiming to minimise the maximum overflow in a slot.
"""
label = 'Artificial upper bound constraint'
for row, event in enumer... | python | def _upper_bound_on_event_overflow(
events, slots, X, beta, summation_type=None, **kwargs
):
"""
This is an artificial constraint that is used by the objective function
aiming to minimise the maximum overflow in a slot.
"""
label = 'Artificial upper bound constraint'
for row, event in enumer... | [
"def",
"_upper_bound_on_event_overflow",
"(",
"events",
",",
"slots",
",",
"X",
",",
"beta",
",",
"summation_type",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"label",
"=",
"'Artificial upper bound constraint'",
"for",
"row",
",",
"event",
"in",
"enumerat... | This is an artificial constraint that is used by the objective function
aiming to minimise the maximum overflow in a slot. | [
"This",
"is",
"an",
"artificial",
"constraint",
"that",
"is",
"used",
"by",
"the",
"objective",
"function",
"aiming",
"to",
"minimise",
"the",
"maximum",
"overflow",
"in",
"a",
"slot",
"."
] | train | https://github.com/PyconUK/ConferenceScheduler/blob/fb139f0ef2eab5ac8f4919aa4994d94d4e040030/src/conference_scheduler/lp_problem/constraints.py#L75-L87 |
PyconUK/ConferenceScheduler | src/conference_scheduler/scheduler.py | heuristic | def heuristic(events,
slots,
objective_function=None,
algorithm=heu.hill_climber,
initial_solution=None,
initial_solution_algorithm_kwargs={},
objective_function_algorithm_kwargs={},
**kwargs):
"""
Compute a schedu... | python | def heuristic(events,
slots,
objective_function=None,
algorithm=heu.hill_climber,
initial_solution=None,
initial_solution_algorithm_kwargs={},
objective_function_algorithm_kwargs={},
**kwargs):
"""
Compute a schedu... | [
"def",
"heuristic",
"(",
"events",
",",
"slots",
",",
"objective_function",
"=",
"None",
",",
"algorithm",
"=",
"heu",
".",
"hill_climber",
",",
"initial_solution",
"=",
"None",
",",
"initial_solution_algorithm_kwargs",
"=",
"{",
"}",
",",
"objective_function_algo... | Compute a schedule using a heuristic
Parameters
----------
events : list or tuple
of :py:class:`resources.Event` instances
slots : list or tuple
of :py:class:`resources.Slot` instances
algorithm : callable
a heuristic algorithm from conference_scheduler.heuristics
initial... | [
"Compute",
"a",
"schedule",
"using",
"a",
"heuristic"
] | train | https://github.com/PyconUK/ConferenceScheduler/blob/fb139f0ef2eab5ac8f4919aa4994d94d4e040030/src/conference_scheduler/scheduler.py#L31-L102 |
PyconUK/ConferenceScheduler | src/conference_scheduler/scheduler.py | solution | def solution(events, slots, objective_function=None, solver=None, **kwargs):
"""Compute a schedule in solution form
Parameters
----------
events : list or tuple
of :py:class:`resources.Event` instances
slots : list or tuple
of :py:class:`resources.Slot` instances
solver : pulp.s... | python | def solution(events, slots, objective_function=None, solver=None, **kwargs):
"""Compute a schedule in solution form
Parameters
----------
events : list or tuple
of :py:class:`resources.Event` instances
slots : list or tuple
of :py:class:`resources.Slot` instances
solver : pulp.s... | [
"def",
"solution",
"(",
"events",
",",
"slots",
",",
"objective_function",
"=",
"None",
",",
"solver",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"shape",
"=",
"Shape",
"(",
"len",
"(",
"events",
")",
",",
"len",
"(",
"slots",
")",
")",
"probl... | Compute a schedule in solution form
Parameters
----------
events : list or tuple
of :py:class:`resources.Event` instances
slots : list or tuple
of :py:class:`resources.Slot` instances
solver : pulp.solver
a pulp solver
objective_function: callable
from lp_problem... | [
"Compute",
"a",
"schedule",
"in",
"solution",
"form"
] | train | https://github.com/PyconUK/ConferenceScheduler/blob/fb139f0ef2eab5ac8f4919aa4994d94d4e040030/src/conference_scheduler/scheduler.py#L105-L158 |
PyconUK/ConferenceScheduler | src/conference_scheduler/scheduler.py | array | def array(events, slots, objective_function=None, solver=None, **kwargs):
"""Compute a schedule in array form
Parameters
----------
events : list or tuple
of :py:class:`resources.Event` instances
slots : list or tuple
of :py:class:`resources.Slot` instances
objective_function : ... | python | def array(events, slots, objective_function=None, solver=None, **kwargs):
"""Compute a schedule in array form
Parameters
----------
events : list or tuple
of :py:class:`resources.Event` instances
slots : list or tuple
of :py:class:`resources.Slot` instances
objective_function : ... | [
"def",
"array",
"(",
"events",
",",
"slots",
",",
"objective_function",
"=",
"None",
",",
"solver",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"conv",
".",
"solution_to_array",
"(",
"solution",
"(",
"events",
",",
"slots",
",",
"objective_... | Compute a schedule in array form
Parameters
----------
events : list or tuple
of :py:class:`resources.Event` instances
slots : list or tuple
of :py:class:`resources.Slot` instances
objective_function : callable
from lp_problem.objective_functions
Returns
-------
... | [
"Compute",
"a",
"schedule",
"in",
"array",
"form"
] | train | https://github.com/PyconUK/ConferenceScheduler/blob/fb139f0ef2eab5ac8f4919aa4994d94d4e040030/src/conference_scheduler/scheduler.py#L161-L197 |
PyconUK/ConferenceScheduler | src/conference_scheduler/scheduler.py | schedule | def schedule(events, slots, objective_function=None, solver=None, **kwargs):
"""Compute a schedule in schedule form
Parameters
----------
events : list or tuple
of :py:class:`resources.Event` instances
slots : list or tuple
of :py:class:`resources.Slot` instances
solver : pulp.s... | python | def schedule(events, slots, objective_function=None, solver=None, **kwargs):
"""Compute a schedule in schedule form
Parameters
----------
events : list or tuple
of :py:class:`resources.Event` instances
slots : list or tuple
of :py:class:`resources.Slot` instances
solver : pulp.s... | [
"def",
"schedule",
"(",
"events",
",",
"slots",
",",
"objective_function",
"=",
"None",
",",
"solver",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"conv",
".",
"solution_to_schedule",
"(",
"solution",
"(",
"events",
",",
"slots",
",",
"obje... | Compute a schedule in schedule form
Parameters
----------
events : list or tuple
of :py:class:`resources.Event` instances
slots : list or tuple
of :py:class:`resources.Slot` instances
solver : pulp.solver
a pulp solver
objective_function : callable
from lp_proble... | [
"Compute",
"a",
"schedule",
"in",
"schedule",
"form"
] | train | https://github.com/PyconUK/ConferenceScheduler/blob/fb139f0ef2eab5ac8f4919aa4994d94d4e040030/src/conference_scheduler/scheduler.py#L200-L224 |
PyconUK/ConferenceScheduler | src/conference_scheduler/scheduler.py | event_schedule_difference | def event_schedule_difference(old_schedule, new_schedule):
"""Compute the difference between two schedules from an event perspective
Parameters
----------
old_schedule : list or tuple
of :py:class:`resources.ScheduledItem` objects
new_schedule : list or tuple
of :py:class:`resource... | python | def event_schedule_difference(old_schedule, new_schedule):
"""Compute the difference between two schedules from an event perspective
Parameters
----------
old_schedule : list or tuple
of :py:class:`resources.ScheduledItem` objects
new_schedule : list or tuple
of :py:class:`resource... | [
"def",
"event_schedule_difference",
"(",
"old_schedule",
",",
"new_schedule",
")",
":",
"old",
"=",
"{",
"item",
".",
"event",
".",
"name",
":",
"item",
"for",
"item",
"in",
"old_schedule",
"}",
"new",
"=",
"{",
"item",
".",
"event",
".",
"name",
":",
... | Compute the difference between two schedules from an event perspective
Parameters
----------
old_schedule : list or tuple
of :py:class:`resources.ScheduledItem` objects
new_schedule : list or tuple
of :py:class:`resources.ScheduledItem` objects
Returns
-------
list
... | [
"Compute",
"the",
"difference",
"between",
"two",
"schedules",
"from",
"an",
"event",
"perspective"
] | train | https://github.com/PyconUK/ConferenceScheduler/blob/fb139f0ef2eab5ac8f4919aa4994d94d4e040030/src/conference_scheduler/scheduler.py#L230-L287 |
PyconUK/ConferenceScheduler | src/conference_scheduler/scheduler.py | slot_schedule_difference | def slot_schedule_difference(old_schedule, new_schedule):
"""Compute the difference between two schedules from a slot perspective
Parameters
----------
old_schedule : list or tuple
of :py:class:`resources.ScheduledItem` objects
new_schedule : list or tuple
of :py:class:`resources.Sc... | python | def slot_schedule_difference(old_schedule, new_schedule):
"""Compute the difference between two schedules from a slot perspective
Parameters
----------
old_schedule : list or tuple
of :py:class:`resources.ScheduledItem` objects
new_schedule : list or tuple
of :py:class:`resources.Sc... | [
"def",
"slot_schedule_difference",
"(",
"old_schedule",
",",
"new_schedule",
")",
":",
"old",
"=",
"{",
"item",
".",
"slot",
":",
"item",
"for",
"item",
"in",
"old_schedule",
"}",
"new",
"=",
"{",
"item",
".",
"slot",
":",
"item",
"for",
"item",
"in",
... | Compute the difference between two schedules from a slot perspective
Parameters
----------
old_schedule : list or tuple
of :py:class:`resources.ScheduledItem` objects
new_schedule : list or tuple
of :py:class:`resources.ScheduledItem` objects
Returns
-------
list
A ... | [
"Compute",
"the",
"difference",
"between",
"two",
"schedules",
"from",
"a",
"slot",
"perspective"
] | train | https://github.com/PyconUK/ConferenceScheduler/blob/fb139f0ef2eab5ac8f4919aa4994d94d4e040030/src/conference_scheduler/scheduler.py#L290-L349 |
PyconUK/ConferenceScheduler | src/conference_scheduler/validator.py | array_violations | def array_violations(array, events, slots, beta=None):
"""Take a schedule in array form and return any violated constraints
Parameters
----------
array : np.array
a schedule in array form
events : list or tuple
of resources.Event instances
slots : list or tup... | python | def array_violations(array, events, slots, beta=None):
"""Take a schedule in array form and return any violated constraints
Parameters
----------
array : np.array
a schedule in array form
events : list or tuple
of resources.Event instances
slots : list or tup... | [
"def",
"array_violations",
"(",
"array",
",",
"events",
",",
"slots",
",",
"beta",
"=",
"None",
")",
":",
"return",
"(",
"c",
".",
"label",
"for",
"c",
"in",
"constraints",
".",
"all_constraints",
"(",
"events",
",",
"slots",
",",
"array",
",",
"beta",... | Take a schedule in array form and return any violated constraints
Parameters
----------
array : np.array
a schedule in array form
events : list or tuple
of resources.Event instances
slots : list or tuple
of resources.Slot instances
constraints... | [
"Take",
"a",
"schedule",
"in",
"array",
"form",
"and",
"return",
"any",
"violated",
"constraints"
] | train | https://github.com/PyconUK/ConferenceScheduler/blob/fb139f0ef2eab5ac8f4919aa4994d94d4e040030/src/conference_scheduler/validator.py#L5-L30 |
PyconUK/ConferenceScheduler | src/conference_scheduler/validator.py | is_valid_array | def is_valid_array(array, events, slots):
"""Take a schedule in array form and return whether it is a valid
solution for the given constraints
Parameters
----------
array : np.array
a schedule in array form
events : list or tuple
of resources.Event instances
... | python | def is_valid_array(array, events, slots):
"""Take a schedule in array form and return whether it is a valid
solution for the given constraints
Parameters
----------
array : np.array
a schedule in array form
events : list or tuple
of resources.Event instances
... | [
"def",
"is_valid_array",
"(",
"array",
",",
"events",
",",
"slots",
")",
":",
"if",
"len",
"(",
"array",
")",
"==",
"0",
":",
"return",
"False",
"violations",
"=",
"sum",
"(",
"1",
"for",
"c",
"in",
"(",
"array_violations",
"(",
"array",
",",
"events... | Take a schedule in array form and return whether it is a valid
solution for the given constraints
Parameters
----------
array : np.array
a schedule in array form
events : list or tuple
of resources.Event instances
slots : list or tuple
of resource... | [
"Take",
"a",
"schedule",
"in",
"array",
"form",
"and",
"return",
"whether",
"it",
"is",
"a",
"valid",
"solution",
"for",
"the",
"given",
"constraints"
] | train | https://github.com/PyconUK/ConferenceScheduler/blob/fb139f0ef2eab5ac8f4919aa4994d94d4e040030/src/conference_scheduler/validator.py#L33-L55 |
PyconUK/ConferenceScheduler | src/conference_scheduler/validator.py | is_valid_solution | def is_valid_solution(solution, events, slots):
"""Take a solution and return whether it is valid for the
given constraints
Parameters
----------
solution: list or tuple
a schedule in solution form
events : list or tuple
of resources.Event instances
slots... | python | def is_valid_solution(solution, events, slots):
"""Take a solution and return whether it is valid for the
given constraints
Parameters
----------
solution: list or tuple
a schedule in solution form
events : list or tuple
of resources.Event instances
slots... | [
"def",
"is_valid_solution",
"(",
"solution",
",",
"events",
",",
"slots",
")",
":",
"if",
"len",
"(",
"solution",
")",
"==",
"0",
":",
"return",
"False",
"array",
"=",
"converter",
".",
"solution_to_array",
"(",
"solution",
",",
"events",
",",
"slots",
"... | Take a solution and return whether it is valid for the
given constraints
Parameters
----------
solution: list or tuple
a schedule in solution form
events : list or tuple
of resources.Event instances
slots : list or tuple
of resources.Slot instance... | [
"Take",
"a",
"solution",
"and",
"return",
"whether",
"it",
"is",
"valid",
"for",
"the",
"given",
"constraints"
] | train | https://github.com/PyconUK/ConferenceScheduler/blob/fb139f0ef2eab5ac8f4919aa4994d94d4e040030/src/conference_scheduler/validator.py#L58-L79 |
PyconUK/ConferenceScheduler | src/conference_scheduler/validator.py | solution_violations | def solution_violations(solution, events, slots):
"""Take a solution and return a list of violated constraints
Parameters
----------
solution: list or tuple
a schedule in solution form
events : list or tuple
of resources.Event instances
slots : list or tuple
... | python | def solution_violations(solution, events, slots):
"""Take a solution and return a list of violated constraints
Parameters
----------
solution: list or tuple
a schedule in solution form
events : list or tuple
of resources.Event instances
slots : list or tuple
... | [
"def",
"solution_violations",
"(",
"solution",
",",
"events",
",",
"slots",
")",
":",
"array",
"=",
"converter",
".",
"solution_to_array",
"(",
"solution",
",",
"events",
",",
"slots",
")",
"return",
"array_violations",
"(",
"array",
",",
"events",
",",
"slo... | Take a solution and return a list of violated constraints
Parameters
----------
solution: list or tuple
a schedule in solution form
events : list or tuple
of resources.Event instances
slots : list or tuple
of resources.Slot instances
Returns
... | [
"Take",
"a",
"solution",
"and",
"return",
"a",
"list",
"of",
"violated",
"constraints"
] | train | https://github.com/PyconUK/ConferenceScheduler/blob/fb139f0ef2eab5ac8f4919aa4994d94d4e040030/src/conference_scheduler/validator.py#L82-L101 |
PyconUK/ConferenceScheduler | src/conference_scheduler/validator.py | is_valid_schedule | def is_valid_schedule(schedule, events, slots):
"""Take a schedule and return whether it is a valid solution for the
given constraints
Parameters
----------
schedule : list or tuple
a schedule in schedule form
events : list or tuple
of resources.Event instances
... | python | def is_valid_schedule(schedule, events, slots):
"""Take a schedule and return whether it is a valid solution for the
given constraints
Parameters
----------
schedule : list or tuple
a schedule in schedule form
events : list or tuple
of resources.Event instances
... | [
"def",
"is_valid_schedule",
"(",
"schedule",
",",
"events",
",",
"slots",
")",
":",
"if",
"len",
"(",
"schedule",
")",
"==",
"0",
":",
"return",
"False",
"array",
"=",
"converter",
".",
"schedule_to_array",
"(",
"schedule",
",",
"events",
",",
"slots",
"... | Take a schedule and return whether it is a valid solution for the
given constraints
Parameters
----------
schedule : list or tuple
a schedule in schedule form
events : list or tuple
of resources.Event instances
slots : list or tuple
of resources.S... | [
"Take",
"a",
"schedule",
"and",
"return",
"whether",
"it",
"is",
"a",
"valid",
"solution",
"for",
"the",
"given",
"constraints"
] | train | https://github.com/PyconUK/ConferenceScheduler/blob/fb139f0ef2eab5ac8f4919aa4994d94d4e040030/src/conference_scheduler/validator.py#L104-L125 |
PyconUK/ConferenceScheduler | src/conference_scheduler/validator.py | schedule_violations | def schedule_violations(schedule, events, slots):
"""Take a schedule and return a list of violated constraints
Parameters
----------
schedule : list or tuple
a schedule in schedule form
events : list or tuple
of resources.Event instances
slots : list or tuple... | python | def schedule_violations(schedule, events, slots):
"""Take a schedule and return a list of violated constraints
Parameters
----------
schedule : list or tuple
a schedule in schedule form
events : list or tuple
of resources.Event instances
slots : list or tuple... | [
"def",
"schedule_violations",
"(",
"schedule",
",",
"events",
",",
"slots",
")",
":",
"array",
"=",
"converter",
".",
"schedule_to_array",
"(",
"schedule",
",",
"events",
",",
"slots",
")",
"return",
"array_violations",
"(",
"array",
",",
"events",
",",
"slo... | Take a schedule and return a list of violated constraints
Parameters
----------
schedule : list or tuple
a schedule in schedule form
events : list or tuple
of resources.Event instances
slots : list or tuple
of resources.Slot instances
Returns
... | [
"Take",
"a",
"schedule",
"and",
"return",
"a",
"list",
"of",
"violated",
"constraints"
] | train | https://github.com/PyconUK/ConferenceScheduler/blob/fb139f0ef2eab5ac8f4919aa4994d94d4e040030/src/conference_scheduler/validator.py#L128-L147 |
PyconUK/ConferenceScheduler | src/conference_scheduler/lp_problem/utils.py | tag_array | def tag_array(events):
"""
Return a numpy array mapping events to tags
- Rows corresponds to events
- Columns correspond to tags
"""
all_tags = sorted(set(tag for event in events for tag in event.tags))
array = np.zeros((len(events), len(all_tags)))
for row, event in enumerate(events):
... | python | def tag_array(events):
"""
Return a numpy array mapping events to tags
- Rows corresponds to events
- Columns correspond to tags
"""
all_tags = sorted(set(tag for event in events for tag in event.tags))
array = np.zeros((len(events), len(all_tags)))
for row, event in enumerate(events):
... | [
"def",
"tag_array",
"(",
"events",
")",
":",
"all_tags",
"=",
"sorted",
"(",
"set",
"(",
"tag",
"for",
"event",
"in",
"events",
"for",
"tag",
"in",
"event",
".",
"tags",
")",
")",
"array",
"=",
"np",
".",
"zeros",
"(",
"(",
"len",
"(",
"events",
... | Return a numpy array mapping events to tags
- Rows corresponds to events
- Columns correspond to tags | [
"Return",
"a",
"numpy",
"array",
"mapping",
"events",
"to",
"tags"
] | train | https://github.com/PyconUK/ConferenceScheduler/blob/fb139f0ef2eab5ac8f4919aa4994d94d4e040030/src/conference_scheduler/lp_problem/utils.py#L33-L45 |
PyconUK/ConferenceScheduler | src/conference_scheduler/lp_problem/utils.py | session_array | def session_array(slots):
"""
Return a numpy array mapping sessions to slots
- Rows corresponds to sessions
- Columns correspond to slots
"""
# Flatten the list: this assumes that the sessions do not share slots
sessions = sorted(set([slot.session for slot in slots]))
array = np.zeros((... | python | def session_array(slots):
"""
Return a numpy array mapping sessions to slots
- Rows corresponds to sessions
- Columns correspond to slots
"""
# Flatten the list: this assumes that the sessions do not share slots
sessions = sorted(set([slot.session for slot in slots]))
array = np.zeros((... | [
"def",
"session_array",
"(",
"slots",
")",
":",
"# Flatten the list: this assumes that the sessions do not share slots",
"sessions",
"=",
"sorted",
"(",
"set",
"(",
"[",
"slot",
".",
"session",
"for",
"slot",
"in",
"slots",
"]",
")",
")",
"array",
"=",
"np",
"."... | Return a numpy array mapping sessions to slots
- Rows corresponds to sessions
- Columns correspond to slots | [
"Return",
"a",
"numpy",
"array",
"mapping",
"sessions",
"to",
"slots"
] | train | https://github.com/PyconUK/ConferenceScheduler/blob/fb139f0ef2eab5ac8f4919aa4994d94d4e040030/src/conference_scheduler/lp_problem/utils.py#L48-L60 |
PyconUK/ConferenceScheduler | src/conference_scheduler/lp_problem/utils.py | slot_availability_array | def slot_availability_array(events, slots):
"""
Return a numpy array mapping events to slots
- Rows corresponds to events
- Columns correspond to stags
Array has value 0 if event cannot be scheduled in a given slot
(1 otherwise)
"""
array = np.ones((len(events), len(slots)))
for ro... | python | def slot_availability_array(events, slots):
"""
Return a numpy array mapping events to slots
- Rows corresponds to events
- Columns correspond to stags
Array has value 0 if event cannot be scheduled in a given slot
(1 otherwise)
"""
array = np.ones((len(events), len(slots)))
for ro... | [
"def",
"slot_availability_array",
"(",
"events",
",",
"slots",
")",
":",
"array",
"=",
"np",
".",
"ones",
"(",
"(",
"len",
"(",
"events",
")",
",",
"len",
"(",
"slots",
")",
")",
")",
"for",
"row",
",",
"event",
"in",
"enumerate",
"(",
"events",
")... | Return a numpy array mapping events to slots
- Rows corresponds to events
- Columns correspond to stags
Array has value 0 if event cannot be scheduled in a given slot
(1 otherwise) | [
"Return",
"a",
"numpy",
"array",
"mapping",
"events",
"to",
"slots"
] | train | https://github.com/PyconUK/ConferenceScheduler/blob/fb139f0ef2eab5ac8f4919aa4994d94d4e040030/src/conference_scheduler/lp_problem/utils.py#L63-L78 |
PyconUK/ConferenceScheduler | src/conference_scheduler/lp_problem/utils.py | event_availability_array | def event_availability_array(events):
"""
Return a numpy array mapping events to events
- Rows corresponds to events
- Columns correspond to events
Array has value 0 if event cannot be scheduled at same time as other event
(1 otherwise)
"""
array = np.ones((len(events), len(events)))
... | python | def event_availability_array(events):
"""
Return a numpy array mapping events to events
- Rows corresponds to events
- Columns correspond to events
Array has value 0 if event cannot be scheduled at same time as other event
(1 otherwise)
"""
array = np.ones((len(events), len(events)))
... | [
"def",
"event_availability_array",
"(",
"events",
")",
":",
"array",
"=",
"np",
".",
"ones",
"(",
"(",
"len",
"(",
"events",
")",
",",
"len",
"(",
"events",
")",
")",
")",
"for",
"row",
",",
"event",
"in",
"enumerate",
"(",
"events",
")",
":",
"for... | Return a numpy array mapping events to events
- Rows corresponds to events
- Columns correspond to events
Array has value 0 if event cannot be scheduled at same time as other event
(1 otherwise) | [
"Return",
"a",
"numpy",
"array",
"mapping",
"events",
"to",
"events"
] | train | https://github.com/PyconUK/ConferenceScheduler/blob/fb139f0ef2eab5ac8f4919aa4994d94d4e040030/src/conference_scheduler/lp_problem/utils.py#L81-L100 |
PyconUK/ConferenceScheduler | src/conference_scheduler/lp_problem/utils.py | slots_overlap | def slots_overlap(slot, other_slot):
"""
Return boolean: whether or not two events overlap
"""
slot_ends_at = ends_at(slot)
other_ends_at = ends_at(other_slot)
if (slot.starts_at >= other_slot.starts_at and
slot_ends_at <= other_ends_at
):
return True
if (other_slot.start... | python | def slots_overlap(slot, other_slot):
"""
Return boolean: whether or not two events overlap
"""
slot_ends_at = ends_at(slot)
other_ends_at = ends_at(other_slot)
if (slot.starts_at >= other_slot.starts_at and
slot_ends_at <= other_ends_at
):
return True
if (other_slot.start... | [
"def",
"slots_overlap",
"(",
"slot",
",",
"other_slot",
")",
":",
"slot_ends_at",
"=",
"ends_at",
"(",
"slot",
")",
"other_ends_at",
"=",
"ends_at",
"(",
"other_slot",
")",
"if",
"(",
"slot",
".",
"starts_at",
">=",
"other_slot",
".",
"starts_at",
"and",
"... | Return boolean: whether or not two events overlap | [
"Return",
"boolean",
":",
"whether",
"or",
"not",
"two",
"events",
"overlap"
] | train | https://github.com/PyconUK/ConferenceScheduler/blob/fb139f0ef2eab5ac8f4919aa4994d94d4e040030/src/conference_scheduler/lp_problem/utils.py#L110-L124 |
PyconUK/ConferenceScheduler | src/conference_scheduler/lp_problem/utils.py | concurrent_slots | def concurrent_slots(slots):
"""
Yields all concurrent slot indices.
"""
for i, slot in enumerate(slots):
for j, other_slot in enumerate(slots[i + 1:]):
if slots_overlap(slot, other_slot):
yield (i, j + i + 1) | python | def concurrent_slots(slots):
"""
Yields all concurrent slot indices.
"""
for i, slot in enumerate(slots):
for j, other_slot in enumerate(slots[i + 1:]):
if slots_overlap(slot, other_slot):
yield (i, j + i + 1) | [
"def",
"concurrent_slots",
"(",
"slots",
")",
":",
"for",
"i",
",",
"slot",
"in",
"enumerate",
"(",
"slots",
")",
":",
"for",
"j",
",",
"other_slot",
"in",
"enumerate",
"(",
"slots",
"[",
"i",
"+",
"1",
":",
"]",
")",
":",
"if",
"slots_overlap",
"(... | Yields all concurrent slot indices. | [
"Yields",
"all",
"concurrent",
"slot",
"indices",
"."
] | train | https://github.com/PyconUK/ConferenceScheduler/blob/fb139f0ef2eab5ac8f4919aa4994d94d4e040030/src/conference_scheduler/lp_problem/utils.py#L127-L134 |
PyconUK/ConferenceScheduler | src/conference_scheduler/lp_problem/utils.py | _events_with_diff_tag | def _events_with_diff_tag(talk, tag_array):
"""
Return the indices of the events with no tag in common as tag
"""
event_categories = np.nonzero(tag_array[talk])[0]
return np.nonzero(sum(tag_array.transpose()[event_categories]) == 0)[0] | python | def _events_with_diff_tag(talk, tag_array):
"""
Return the indices of the events with no tag in common as tag
"""
event_categories = np.nonzero(tag_array[talk])[0]
return np.nonzero(sum(tag_array.transpose()[event_categories]) == 0)[0] | [
"def",
"_events_with_diff_tag",
"(",
"talk",
",",
"tag_array",
")",
":",
"event_categories",
"=",
"np",
".",
"nonzero",
"(",
"tag_array",
"[",
"talk",
"]",
")",
"[",
"0",
"]",
"return",
"np",
".",
"nonzero",
"(",
"sum",
"(",
"tag_array",
".",
"transpose"... | Return the indices of the events with no tag in common as tag | [
"Return",
"the",
"indices",
"of",
"the",
"events",
"with",
"no",
"tag",
"in",
"common",
"as",
"tag"
] | train | https://github.com/PyconUK/ConferenceScheduler/blob/fb139f0ef2eab5ac8f4919aa4994d94d4e040030/src/conference_scheduler/lp_problem/utils.py#L144-L149 |
PyconUK/ConferenceScheduler | src/conference_scheduler/converter.py | solution_to_array | def solution_to_array(solution, events, slots):
"""Convert a schedule from solution to array form
Parameters
----------
solution : list or tuple
of tuples of event index and slot index for each scheduled item
events : list or tuple
of :py:class:`resources.Event` instances
slots ... | python | def solution_to_array(solution, events, slots):
"""Convert a schedule from solution to array form
Parameters
----------
solution : list or tuple
of tuples of event index and slot index for each scheduled item
events : list or tuple
of :py:class:`resources.Event` instances
slots ... | [
"def",
"solution_to_array",
"(",
"solution",
",",
"events",
",",
"slots",
")",
":",
"array",
"=",
"np",
".",
"zeros",
"(",
"(",
"len",
"(",
"events",
")",
",",
"len",
"(",
"slots",
")",
")",
",",
"dtype",
"=",
"np",
".",
"int8",
")",
"for",
"item... | Convert a schedule from solution to array form
Parameters
----------
solution : list or tuple
of tuples of event index and slot index for each scheduled item
events : list or tuple
of :py:class:`resources.Event` instances
slots : list or tuple
of :py:class:`resources.Slot` i... | [
"Convert",
"a",
"schedule",
"from",
"solution",
"to",
"array",
"form"
] | train | https://github.com/PyconUK/ConferenceScheduler/blob/fb139f0ef2eab5ac8f4919aa4994d94d4e040030/src/conference_scheduler/converter.py#L6-L40 |
PyconUK/ConferenceScheduler | src/conference_scheduler/converter.py | solution_to_schedule | def solution_to_schedule(solution, events, slots):
"""Convert a schedule from solution to schedule form
Parameters
----------
solution : list or tuple
of tuples of event index and slot index for each scheduled item
events : list or tuple
of :py:class:`resources.Event` instances
... | python | def solution_to_schedule(solution, events, slots):
"""Convert a schedule from solution to schedule form
Parameters
----------
solution : list or tuple
of tuples of event index and slot index for each scheduled item
events : list or tuple
of :py:class:`resources.Event` instances
... | [
"def",
"solution_to_schedule",
"(",
"solution",
",",
"events",
",",
"slots",
")",
":",
"return",
"[",
"ScheduledItem",
"(",
"event",
"=",
"events",
"[",
"item",
"[",
"0",
"]",
"]",
",",
"slot",
"=",
"slots",
"[",
"item",
"[",
"1",
"]",
"]",
")",
"f... | Convert a schedule from solution to schedule form
Parameters
----------
solution : list or tuple
of tuples of event index and slot index for each scheduled item
events : list or tuple
of :py:class:`resources.Event` instances
slots : list or tuple
of :py:class:`resources.Slot... | [
"Convert",
"a",
"schedule",
"from",
"solution",
"to",
"schedule",
"form"
] | train | https://github.com/PyconUK/ConferenceScheduler/blob/fb139f0ef2eab5ac8f4919aa4994d94d4e040030/src/conference_scheduler/converter.py#L43-L66 |
PyconUK/ConferenceScheduler | src/conference_scheduler/converter.py | schedule_to_array | def schedule_to_array(schedule, events, slots):
"""Convert a schedule from schedule to array form
Parameters
----------
schedule : list or tuple
of instances of :py:class:`resources.ScheduledItem`
events : list or tuple
of :py:class:`resources.Event` instances
slots : list or tu... | python | def schedule_to_array(schedule, events, slots):
"""Convert a schedule from schedule to array form
Parameters
----------
schedule : list or tuple
of instances of :py:class:`resources.ScheduledItem`
events : list or tuple
of :py:class:`resources.Event` instances
slots : list or tu... | [
"def",
"schedule_to_array",
"(",
"schedule",
",",
"events",
",",
"slots",
")",
":",
"array",
"=",
"np",
".",
"zeros",
"(",
"(",
"len",
"(",
"events",
")",
",",
"len",
"(",
"slots",
")",
")",
",",
"dtype",
"=",
"np",
".",
"int8",
")",
"for",
"item... | Convert a schedule from schedule to array form
Parameters
----------
schedule : list or tuple
of instances of :py:class:`resources.ScheduledItem`
events : list or tuple
of :py:class:`resources.Event` instances
slots : list or tuple
of :py:class:`resources.Slot` instances
... | [
"Convert",
"a",
"schedule",
"from",
"schedule",
"to",
"array",
"form"
] | train | https://github.com/PyconUK/ConferenceScheduler/blob/fb139f0ef2eab5ac8f4919aa4994d94d4e040030/src/conference_scheduler/converter.py#L69-L91 |
PyconUK/ConferenceScheduler | src/conference_scheduler/converter.py | array_to_schedule | def array_to_schedule(array, events, slots):
"""Convert a schedule from array to schedule form
Parameters
----------
array : np.array
An E by S array (X) where E is the number of events and S the
number of slots. Xij is 1 if event i is scheduled in slot j and
zero otherwise
... | python | def array_to_schedule(array, events, slots):
"""Convert a schedule from array to schedule form
Parameters
----------
array : np.array
An E by S array (X) where E is the number of events and S the
number of slots. Xij is 1 if event i is scheduled in slot j and
zero otherwise
... | [
"def",
"array_to_schedule",
"(",
"array",
",",
"events",
",",
"slots",
")",
":",
"scheduled",
"=",
"np",
".",
"transpose",
"(",
"np",
".",
"nonzero",
"(",
"array",
")",
")",
"return",
"[",
"ScheduledItem",
"(",
"event",
"=",
"events",
"[",
"item",
"[",... | Convert a schedule from array to schedule form
Parameters
----------
array : np.array
An E by S array (X) where E is the number of events and S the
number of slots. Xij is 1 if event i is scheduled in slot j and
zero otherwise
events : list or tuple
of :py:class:`resourc... | [
"Convert",
"a",
"schedule",
"from",
"array",
"to",
"schedule",
"form"
] | train | https://github.com/PyconUK/ConferenceScheduler/blob/fb139f0ef2eab5ac8f4919aa4994d94d4e040030/src/conference_scheduler/converter.py#L94-L117 |
PyconUK/ConferenceScheduler | reference_docs/build_reference.py | add_line | def add_line(self, line, source, *lineno):
"""Append one line of generated reST to the output."""
if 'conference_scheduler.scheduler' in source:
module = 'scheduler'
else:
module = 'resources'
rst[module].append(line)
self.directive.result.append(self.indent + line, source, *lineno) | python | def add_line(self, line, source, *lineno):
"""Append one line of generated reST to the output."""
if 'conference_scheduler.scheduler' in source:
module = 'scheduler'
else:
module = 'resources'
rst[module].append(line)
self.directive.result.append(self.indent + line, source, *lineno) | [
"def",
"add_line",
"(",
"self",
",",
"line",
",",
"source",
",",
"*",
"lineno",
")",
":",
"if",
"'conference_scheduler.scheduler'",
"in",
"source",
":",
"module",
"=",
"'scheduler'",
"else",
":",
"module",
"=",
"'resources'",
"rst",
"[",
"module",
"]",
"."... | Append one line of generated reST to the output. | [
"Append",
"one",
"line",
"of",
"generated",
"reST",
"to",
"the",
"output",
"."
] | train | https://github.com/PyconUK/ConferenceScheduler/blob/fb139f0ef2eab5ac8f4919aa4994d94d4e040030/reference_docs/build_reference.py#L10-L17 |
PyconUK/ConferenceScheduler | src/conference_scheduler/lp_problem/objective_functions.py | efficiency_capacity_demand_difference | def efficiency_capacity_demand_difference(slots, events, X, **kwargs):
"""
A function that calculates the total difference between demand for an event
and the slot capacity it is scheduled in.
"""
overflow = 0
for row, event in enumerate(events):
for col, slot in enumerate(slots):
... | python | def efficiency_capacity_demand_difference(slots, events, X, **kwargs):
"""
A function that calculates the total difference between demand for an event
and the slot capacity it is scheduled in.
"""
overflow = 0
for row, event in enumerate(events):
for col, slot in enumerate(slots):
... | [
"def",
"efficiency_capacity_demand_difference",
"(",
"slots",
",",
"events",
",",
"X",
",",
"*",
"*",
"kwargs",
")",
":",
"overflow",
"=",
"0",
"for",
"row",
",",
"event",
"in",
"enumerate",
"(",
"events",
")",
":",
"for",
"col",
",",
"slot",
"in",
"en... | A function that calculates the total difference between demand for an event
and the slot capacity it is scheduled in. | [
"A",
"function",
"that",
"calculates",
"the",
"total",
"difference",
"between",
"demand",
"for",
"an",
"event",
"and",
"the",
"slot",
"capacity",
"it",
"is",
"scheduled",
"in",
"."
] | train | https://github.com/PyconUK/ConferenceScheduler/blob/fb139f0ef2eab5ac8f4919aa4994d94d4e040030/src/conference_scheduler/lp_problem/objective_functions.py#L3-L12 |
PyconUK/ConferenceScheduler | src/conference_scheduler/lp_problem/objective_functions.py | number_of_changes | def number_of_changes(slots, events, original_schedule, X, **kwargs):
"""
A function that counts the number of changes between a given schedule
and an array (either numpy array of lp array).
"""
changes = 0
original_array = schedule_to_array(original_schedule, events=events,
... | python | def number_of_changes(slots, events, original_schedule, X, **kwargs):
"""
A function that counts the number of changes between a given schedule
and an array (either numpy array of lp array).
"""
changes = 0
original_array = schedule_to_array(original_schedule, events=events,
... | [
"def",
"number_of_changes",
"(",
"slots",
",",
"events",
",",
"original_schedule",
",",
"X",
",",
"*",
"*",
"kwargs",
")",
":",
"changes",
"=",
"0",
"original_array",
"=",
"schedule_to_array",
"(",
"original_schedule",
",",
"events",
"=",
"events",
",",
"slo... | A function that counts the number of changes between a given schedule
and an array (either numpy array of lp array). | [
"A",
"function",
"that",
"counts",
"the",
"number",
"of",
"changes",
"between",
"a",
"given",
"schedule",
"and",
"an",
"array",
"(",
"either",
"numpy",
"array",
"of",
"lp",
"array",
")",
"."
] | train | https://github.com/PyconUK/ConferenceScheduler/blob/fb139f0ef2eab5ac8f4919aa4994d94d4e040030/src/conference_scheduler/lp_problem/objective_functions.py#L22-L36 |
PyconUK/ConferenceScheduler | src/conference_scheduler/heuristics/utils.py | element_from_neighbourhood | def element_from_neighbourhood(X):
"""
Randomly move an event:
- Either to an empty slot
- Swapping with another event
"""
m, n = X.shape
new_X = np.copy(X)
event_to_move = np.random.randint(m)
current_event_slot = np.where(new_X[event_to_move, :] == 1)[0][0]
slot_to_move_to ... | python | def element_from_neighbourhood(X):
"""
Randomly move an event:
- Either to an empty slot
- Swapping with another event
"""
m, n = X.shape
new_X = np.copy(X)
event_to_move = np.random.randint(m)
current_event_slot = np.where(new_X[event_to_move, :] == 1)[0][0]
slot_to_move_to ... | [
"def",
"element_from_neighbourhood",
"(",
"X",
")",
":",
"m",
",",
"n",
"=",
"X",
".",
"shape",
"new_X",
"=",
"np",
".",
"copy",
"(",
"X",
")",
"event_to_move",
"=",
"np",
".",
"random",
".",
"randint",
"(",
"m",
")",
"current_event_slot",
"=",
"np",... | Randomly move an event:
- Either to an empty slot
- Swapping with another event | [
"Randomly",
"move",
"an",
"event",
":"
] | train | https://github.com/PyconUK/ConferenceScheduler/blob/fb139f0ef2eab5ac8f4919aa4994d94d4e040030/src/conference_scheduler/heuristics/utils.py#L3-L30 |
PyconUK/ConferenceScheduler | src/conference_scheduler/heuristics/utils.py | get_initial_array | def get_initial_array(events, slots, seed=None):
"""
Obtain a random initial array.
"""
if seed is not None:
np.random.seed(seed)
m = len(events)
n = len(slots)
X = np.zeros((m, n))
for i, row in enumerate(X):
X[i, i] = 1
np.random.shuffle(X)
return X | python | def get_initial_array(events, slots, seed=None):
"""
Obtain a random initial array.
"""
if seed is not None:
np.random.seed(seed)
m = len(events)
n = len(slots)
X = np.zeros((m, n))
for i, row in enumerate(X):
X[i, i] = 1
np.random.shuffle(X)
return X | [
"def",
"get_initial_array",
"(",
"events",
",",
"slots",
",",
"seed",
"=",
"None",
")",
":",
"if",
"seed",
"is",
"not",
"None",
":",
"np",
".",
"random",
".",
"seed",
"(",
"seed",
")",
"m",
"=",
"len",
"(",
"events",
")",
"n",
"=",
"len",
"(",
... | Obtain a random initial array. | [
"Obtain",
"a",
"random",
"initial",
"array",
"."
] | train | https://github.com/PyconUK/ConferenceScheduler/blob/fb139f0ef2eab5ac8f4919aa4994d94d4e040030/src/conference_scheduler/heuristics/utils.py#L32-L45 |
casebeer/afsk | afsk/ax25.py | fcs | def fcs(bits):
'''
Append running bitwise FCS CRC checksum to end of generator
'''
fcs = FCS()
for bit in bits:
yield bit
fcs.update_bit(bit)
# test = bitarray()
# for byte in (digest & 0xff, digest >> 8):
# print byte
# for i in range(8):
# b = (byte >> i) & 1 == 1
# test.append(b)
# yield b
# appe... | python | def fcs(bits):
'''
Append running bitwise FCS CRC checksum to end of generator
'''
fcs = FCS()
for bit in bits:
yield bit
fcs.update_bit(bit)
# test = bitarray()
# for byte in (digest & 0xff, digest >> 8):
# print byte
# for i in range(8):
# b = (byte >> i) & 1 == 1
# test.append(b)
# yield b
# appe... | [
"def",
"fcs",
"(",
"bits",
")",
":",
"fcs",
"=",
"FCS",
"(",
")",
"for",
"bit",
"in",
"bits",
":",
"yield",
"bit",
"fcs",
".",
"update_bit",
"(",
"bit",
")",
"#\ttest = bitarray()",
"#\tfor byte in (digest & 0xff, digest >> 8):",
"#\t\tprint byte",
"#\t\tfor i i... | Append running bitwise FCS CRC checksum to end of generator | [
"Append",
"running",
"bitwise",
"FCS",
"CRC",
"checksum",
"to",
"end",
"of",
"generator"
] | train | https://github.com/casebeer/afsk/blob/a3e7b0d2c7c8ff5b63e0b0a747ee79e3bd08b891/afsk/ax25.py#L51-L74 |
casebeer/afsk | afsk/afsk.py | encode | def encode(binary_data):
'''
Encode binary data using Bell-202 AFSK
Expects a bitarray.bitarray() object of binary data as its argument.
Returns a generator of sound samples suitable for use with the
audiogen module.
'''
framed_data = frame(binary_data)
# set volume to 1/2, preceed packet with 1/20 s silenc... | python | def encode(binary_data):
'''
Encode binary data using Bell-202 AFSK
Expects a bitarray.bitarray() object of binary data as its argument.
Returns a generator of sound samples suitable for use with the
audiogen module.
'''
framed_data = frame(binary_data)
# set volume to 1/2, preceed packet with 1/20 s silenc... | [
"def",
"encode",
"(",
"binary_data",
")",
":",
"framed_data",
"=",
"frame",
"(",
"binary_data",
")",
"# set volume to 1/2, preceed packet with 1/20 s silence to allow for startup glitches",
"for",
"sample",
"in",
"itertools",
".",
"chain",
"(",
"audiogen",
".",
"silence",... | Encode binary data using Bell-202 AFSK
Expects a bitarray.bitarray() object of binary data as its argument.
Returns a generator of sound samples suitable for use with the
audiogen module. | [
"Encode",
"binary",
"data",
"using",
"Bell",
"-",
"202",
"AFSK",
"Expects",
"a",
"bitarray",
".",
"bitarray",
"()",
"object",
"of",
"binary",
"data",
"as",
"its",
"argument",
".",
"Returns",
"a",
"generator",
"of",
"sound",
"samples",
"suitable",
"for",
"u... | train | https://github.com/casebeer/afsk/blob/a3e7b0d2c7c8ff5b63e0b0a747ee79e3bd08b891/afsk/afsk.py#L24-L40 |
casebeer/afsk | afsk/afsk.py | modulate | def modulate(data):
'''
Generate Bell 202 AFSK samples for the given symbol generator
Consumes raw wire symbols and produces the corresponding AFSK samples.
'''
seconds_per_sample = 1.0 / audiogen.sampler.FRAME_RATE
phase, seconds, bits = 0, 0, 0
# construct generators
clock = (x / BAUD_RATE for x in itertoo... | python | def modulate(data):
'''
Generate Bell 202 AFSK samples for the given symbol generator
Consumes raw wire symbols and produces the corresponding AFSK samples.
'''
seconds_per_sample = 1.0 / audiogen.sampler.FRAME_RATE
phase, seconds, bits = 0, 0, 0
# construct generators
clock = (x / BAUD_RATE for x in itertoo... | [
"def",
"modulate",
"(",
"data",
")",
":",
"seconds_per_sample",
"=",
"1.0",
"/",
"audiogen",
".",
"sampler",
".",
"FRAME_RATE",
"phase",
",",
"seconds",
",",
"bits",
"=",
"0",
",",
"0",
",",
"0",
"# construct generators",
"clock",
"=",
"(",
"x",
"/",
"... | Generate Bell 202 AFSK samples for the given symbol generator
Consumes raw wire symbols and produces the corresponding AFSK samples. | [
"Generate",
"Bell",
"202",
"AFSK",
"samples",
"for",
"the",
"given",
"symbol",
"generator"
] | train | https://github.com/casebeer/afsk/blob/a3e7b0d2c7c8ff5b63e0b0a747ee79e3bd08b891/afsk/afsk.py#L43-L74 |
casebeer/afsk | afsk/afsk.py | nrzi | def nrzi(data):
'''
Packet uses NRZI (non-return to zero inverted) encoding, which means
that a 0 is encoded as a change in tone, and a 1 is encoded as
no change in tone.
'''
current = True
for bit in data:
if not bit:
current = not current
yield current | python | def nrzi(data):
'''
Packet uses NRZI (non-return to zero inverted) encoding, which means
that a 0 is encoded as a change in tone, and a 1 is encoded as
no change in tone.
'''
current = True
for bit in data:
if not bit:
current = not current
yield current | [
"def",
"nrzi",
"(",
"data",
")",
":",
"current",
"=",
"True",
"for",
"bit",
"in",
"data",
":",
"if",
"not",
"bit",
":",
"current",
"=",
"not",
"current",
"yield",
"current"
] | Packet uses NRZI (non-return to zero inverted) encoding, which means
that a 0 is encoded as a change in tone, and a 1 is encoded as
no change in tone. | [
"Packet",
"uses",
"NRZI",
"(",
"non",
"-",
"return",
"to",
"zero",
"inverted",
")",
"encoding",
"which",
"means",
"that",
"a",
"0",
"is",
"encoded",
"as",
"a",
"change",
"in",
"tone",
"and",
"a",
"1",
"is",
"encoded",
"as",
"no",
"change",
"in",
"ton... | train | https://github.com/casebeer/afsk/blob/a3e7b0d2c7c8ff5b63e0b0a747ee79e3bd08b891/afsk/afsk.py#L76-L86 |
avinassh/haxor | hackernews/__init__.py | HackerNews._get_sync | def _get_sync(self, url):
"""Internal method used for GET requests
Args:
url (str): URL to fetch
Returns:
Individual URL request's response
Raises:
HTTPError: If HTTP request failed.
"""
response = self.session.get(url)
if resp... | python | def _get_sync(self, url):
"""Internal method used for GET requests
Args:
url (str): URL to fetch
Returns:
Individual URL request's response
Raises:
HTTPError: If HTTP request failed.
"""
response = self.session.get(url)
if resp... | [
"def",
"_get_sync",
"(",
"self",
",",
"url",
")",
":",
"response",
"=",
"self",
".",
"session",
".",
"get",
"(",
"url",
")",
"if",
"response",
".",
"status_code",
"==",
"requests",
".",
"codes",
".",
"ok",
":",
"return",
"response",
".",
"json",
"(",... | Internal method used for GET requests
Args:
url (str): URL to fetch
Returns:
Individual URL request's response
Raises:
HTTPError: If HTTP request failed. | [
"Internal",
"method",
"used",
"for",
"GET",
"requests"
] | train | https://github.com/avinassh/haxor/blob/71dbecf87531f7a24bb39c736d53127427aaca84/hackernews/__init__.py#L74-L90 |
avinassh/haxor | hackernews/__init__.py | HackerNews._get_async | async def _get_async(self, url, session):
"""Asynchronous internal method used for GET requests
Args:
url (str): URL to fetch
session (obj): aiohttp client session for async loop
Returns:
data (obj): Individual URL request's response corountine
"""
... | python | async def _get_async(self, url, session):
"""Asynchronous internal method used for GET requests
Args:
url (str): URL to fetch
session (obj): aiohttp client session for async loop
Returns:
data (obj): Individual URL request's response corountine
"""
... | [
"async",
"def",
"_get_async",
"(",
"self",
",",
"url",
",",
"session",
")",
":",
"data",
"=",
"None",
"async",
"with",
"session",
".",
"get",
"(",
"url",
")",
"as",
"resp",
":",
"if",
"resp",
".",
"status",
"==",
"200",
":",
"data",
"=",
"await",
... | Asynchronous internal method used for GET requests
Args:
url (str): URL to fetch
session (obj): aiohttp client session for async loop
Returns:
data (obj): Individual URL request's response corountine | [
"Asynchronous",
"internal",
"method",
"used",
"for",
"GET",
"requests"
] | train | https://github.com/avinassh/haxor/blob/71dbecf87531f7a24bb39c736d53127427aaca84/hackernews/__init__.py#L92-L107 |
avinassh/haxor | hackernews/__init__.py | HackerNews._async_loop | async def _async_loop(self, urls):
"""Asynchronous internal method used to request multiple URLs
Args:
urls (list): URLs to fetch
Returns:
responses (obj): All URL requests' response coroutines
"""
results = []
async with aiohttp.ClientSession(
... | python | async def _async_loop(self, urls):
"""Asynchronous internal method used to request multiple URLs
Args:
urls (list): URLs to fetch
Returns:
responses (obj): All URL requests' response coroutines
"""
results = []
async with aiohttp.ClientSession(
... | [
"async",
"def",
"_async_loop",
"(",
"self",
",",
"urls",
")",
":",
"results",
"=",
"[",
"]",
"async",
"with",
"aiohttp",
".",
"ClientSession",
"(",
"connector",
"=",
"aiohttp",
".",
"TCPConnector",
"(",
"ssl",
"=",
"False",
")",
")",
"as",
"session",
"... | Asynchronous internal method used to request multiple URLs
Args:
urls (list): URLs to fetch
Returns:
responses (obj): All URL requests' response coroutines | [
"Asynchronous",
"internal",
"method",
"used",
"to",
"request",
"multiple",
"URLs"
] | train | https://github.com/avinassh/haxor/blob/71dbecf87531f7a24bb39c736d53127427aaca84/hackernews/__init__.py#L109-L127 |
avinassh/haxor | hackernews/__init__.py | HackerNews._run_async | def _run_async(self, urls):
"""Asynchronous event loop execution
Args:
urls (list): URLs to fetch
Returns:
results (obj): All URL requests' responses
"""
loop = asyncio.get_event_loop()
results = loop.run_until_complete(self._async_loop(urls))
... | python | def _run_async(self, urls):
"""Asynchronous event loop execution
Args:
urls (list): URLs to fetch
Returns:
results (obj): All URL requests' responses
"""
loop = asyncio.get_event_loop()
results = loop.run_until_complete(self._async_loop(urls))
... | [
"def",
"_run_async",
"(",
"self",
",",
"urls",
")",
":",
"loop",
"=",
"asyncio",
".",
"get_event_loop",
"(",
")",
"results",
"=",
"loop",
".",
"run_until_complete",
"(",
"self",
".",
"_async_loop",
"(",
"urls",
")",
")",
"return",
"results"
] | Asynchronous event loop execution
Args:
urls (list): URLs to fetch
Returns:
results (obj): All URL requests' responses | [
"Asynchronous",
"event",
"loop",
"execution"
] | train | https://github.com/avinassh/haxor/blob/71dbecf87531f7a24bb39c736d53127427aaca84/hackernews/__init__.py#L129-L141 |
avinassh/haxor | hackernews/__init__.py | HackerNews._get_stories | def _get_stories(self, page, limit):
"""
Hacker News has different categories (i.e. stories) like
'topstories', 'newstories', 'askstories', 'showstories', 'jobstories'.
This method, first fetches the relevant story ids of that category
The URL is: https://hacker-news.firebaseio.... | python | def _get_stories(self, page, limit):
"""
Hacker News has different categories (i.e. stories) like
'topstories', 'newstories', 'askstories', 'showstories', 'jobstories'.
This method, first fetches the relevant story ids of that category
The URL is: https://hacker-news.firebaseio.... | [
"def",
"_get_stories",
"(",
"self",
",",
"page",
",",
"limit",
")",
":",
"url",
"=",
"urljoin",
"(",
"self",
".",
"base_url",
",",
"F\"{page}.json\"",
")",
"story_ids",
"=",
"self",
".",
"_get_sync",
"(",
"url",
")",
"[",
":",
"limit",
"]",
"return",
... | Hacker News has different categories (i.e. stories) like
'topstories', 'newstories', 'askstories', 'showstories', 'jobstories'.
This method, first fetches the relevant story ids of that category
The URL is: https://hacker-news.firebaseio.com/v0/<story_name>.json
e.g. https://hacker-new... | [
"Hacker",
"News",
"has",
"different",
"categories",
"(",
"i",
".",
"e",
".",
"stories",
")",
"like",
"topstories",
"newstories",
"askstories",
"showstories",
"jobstories",
".",
"This",
"method",
"first",
"fetches",
"the",
"relevant",
"story",
"ids",
"of",
"tha... | train | https://github.com/avinassh/haxor/blob/71dbecf87531f7a24bb39c736d53127427aaca84/hackernews/__init__.py#L143-L163 |
avinassh/haxor | hackernews/__init__.py | HackerNews.get_item | def get_item(self, item_id, expand=False):
"""Returns Hacker News `Item` object.
Fetches the data from url:
https://hacker-news.firebaseio.com/v0/item/<item_id>.json
e.g. https://hacker-news.firebaseio.com/v0/item/69696969.json
Args:
item_id (int or string): Un... | python | def get_item(self, item_id, expand=False):
"""Returns Hacker News `Item` object.
Fetches the data from url:
https://hacker-news.firebaseio.com/v0/item/<item_id>.json
e.g. https://hacker-news.firebaseio.com/v0/item/69696969.json
Args:
item_id (int or string): Un... | [
"def",
"get_item",
"(",
"self",
",",
"item_id",
",",
"expand",
"=",
"False",
")",
":",
"url",
"=",
"urljoin",
"(",
"self",
".",
"item_url",
",",
"F\"{item_id}.json\"",
")",
"response",
"=",
"self",
".",
"_get_sync",
"(",
"url",
")",
"if",
"not",
"respo... | Returns Hacker News `Item` object.
Fetches the data from url:
https://hacker-news.firebaseio.com/v0/item/<item_id>.json
e.g. https://hacker-news.firebaseio.com/v0/item/69696969.json
Args:
item_id (int or string): Unique item id of Hacker News story,
comment... | [
"Returns",
"Hacker",
"News",
"Item",
"object",
"."
] | train | https://github.com/avinassh/haxor/blob/71dbecf87531f7a24bb39c736d53127427aaca84/hackernews/__init__.py#L165-L202 |
avinassh/haxor | hackernews/__init__.py | HackerNews.get_items_by_ids | def get_items_by_ids(self, item_ids, item_type=None):
"""Given a list of item ids, return all the Item objects
Args:
item_ids (obj): List of item IDs to query
item_type (str): (optional) Item type to filter results with
Returns:
List of `Item` objects for gi... | python | def get_items_by_ids(self, item_ids, item_type=None):
"""Given a list of item ids, return all the Item objects
Args:
item_ids (obj): List of item IDs to query
item_type (str): (optional) Item type to filter results with
Returns:
List of `Item` objects for gi... | [
"def",
"get_items_by_ids",
"(",
"self",
",",
"item_ids",
",",
"item_type",
"=",
"None",
")",
":",
"urls",
"=",
"[",
"urljoin",
"(",
"self",
".",
"item_url",
",",
"F\"{i}.json\"",
")",
"for",
"i",
"in",
"item_ids",
"]",
"result",
"=",
"self",
".",
"_run... | Given a list of item ids, return all the Item objects
Args:
item_ids (obj): List of item IDs to query
item_type (str): (optional) Item type to filter results with
Returns:
List of `Item` objects for given item IDs and given item type | [
"Given",
"a",
"list",
"of",
"item",
"ids",
"return",
"all",
"the",
"Item",
"objects"
] | train | https://github.com/avinassh/haxor/blob/71dbecf87531f7a24bb39c736d53127427aaca84/hackernews/__init__.py#L204-L221 |
avinassh/haxor | hackernews/__init__.py | HackerNews.get_user | def get_user(self, user_id, expand=False):
"""Returns Hacker News `User` object.
Fetches data from the url:
https://hacker-news.firebaseio.com/v0/user/<user_id>.json
e.g. https://hacker-news.firebaseio.com/v0/user/pg.json
Args:
user_id (string): unique user id ... | python | def get_user(self, user_id, expand=False):
"""Returns Hacker News `User` object.
Fetches data from the url:
https://hacker-news.firebaseio.com/v0/user/<user_id>.json
e.g. https://hacker-news.firebaseio.com/v0/user/pg.json
Args:
user_id (string): unique user id ... | [
"def",
"get_user",
"(",
"self",
",",
"user_id",
",",
"expand",
"=",
"False",
")",
":",
"url",
"=",
"urljoin",
"(",
"self",
".",
"user_url",
",",
"F\"{user_id}.json\"",
")",
"response",
"=",
"self",
".",
"_get_sync",
"(",
"url",
")",
"if",
"not",
"respo... | Returns Hacker News `User` object.
Fetches data from the url:
https://hacker-news.firebaseio.com/v0/user/<user_id>.json
e.g. https://hacker-news.firebaseio.com/v0/user/pg.json
Args:
user_id (string): unique user id of a Hacker News user.
expand (bool): Flag... | [
"Returns",
"Hacker",
"News",
"User",
"object",
"."
] | train | https://github.com/avinassh/haxor/blob/71dbecf87531f7a24bb39c736d53127427aaca84/hackernews/__init__.py#L223-L266 |
avinassh/haxor | hackernews/__init__.py | HackerNews.get_users_by_ids | def get_users_by_ids(self, user_ids):
"""
Given a list of user ids, return all the User objects
"""
urls = [urljoin(self.user_url, F"{i}.json") for i in user_ids]
result = self._run_async(urls=urls)
return [User(r) for r in result if r] | python | def get_users_by_ids(self, user_ids):
"""
Given a list of user ids, return all the User objects
"""
urls = [urljoin(self.user_url, F"{i}.json") for i in user_ids]
result = self._run_async(urls=urls)
return [User(r) for r in result if r] | [
"def",
"get_users_by_ids",
"(",
"self",
",",
"user_ids",
")",
":",
"urls",
"=",
"[",
"urljoin",
"(",
"self",
".",
"user_url",
",",
"F\"{i}.json\"",
")",
"for",
"i",
"in",
"user_ids",
"]",
"result",
"=",
"self",
".",
"_run_async",
"(",
"urls",
"=",
"url... | Given a list of user ids, return all the User objects | [
"Given",
"a",
"list",
"of",
"user",
"ids",
"return",
"all",
"the",
"User",
"objects"
] | train | https://github.com/avinassh/haxor/blob/71dbecf87531f7a24bb39c736d53127427aaca84/hackernews/__init__.py#L268-L274 |
avinassh/haxor | hackernews/__init__.py | HackerNews.top_stories | def top_stories(self, raw=False, limit=None):
"""Returns list of item ids of current top stories
Args:
limit (int): specifies the number of stories to be returned.
raw (bool): Flag to indicate whether to represent all
objects in raw json.
Returns:
... | python | def top_stories(self, raw=False, limit=None):
"""Returns list of item ids of current top stories
Args:
limit (int): specifies the number of stories to be returned.
raw (bool): Flag to indicate whether to represent all
objects in raw json.
Returns:
... | [
"def",
"top_stories",
"(",
"self",
",",
"raw",
"=",
"False",
",",
"limit",
"=",
"None",
")",
":",
"top_stories",
"=",
"self",
".",
"_get_stories",
"(",
"'topstories'",
",",
"limit",
")",
"if",
"raw",
":",
"top_stories",
"=",
"[",
"story",
".",
"raw",
... | Returns list of item ids of current top stories
Args:
limit (int): specifies the number of stories to be returned.
raw (bool): Flag to indicate whether to represent all
objects in raw json.
Returns:
`list` object containing ids of top stories. | [
"Returns",
"list",
"of",
"item",
"ids",
"of",
"current",
"top",
"stories"
] | train | https://github.com/avinassh/haxor/blob/71dbecf87531f7a24bb39c736d53127427aaca84/hackernews/__init__.py#L276-L291 |
avinassh/haxor | hackernews/__init__.py | HackerNews.new_stories | def new_stories(self, raw=False, limit=None):
"""Returns list of item ids of current new stories
Args:
limit (int): specifies the number of stories to be returned.
raw (bool): Flag to indicate whether to transform all
objects into raw json.
Returns:
... | python | def new_stories(self, raw=False, limit=None):
"""Returns list of item ids of current new stories
Args:
limit (int): specifies the number of stories to be returned.
raw (bool): Flag to indicate whether to transform all
objects into raw json.
Returns:
... | [
"def",
"new_stories",
"(",
"self",
",",
"raw",
"=",
"False",
",",
"limit",
"=",
"None",
")",
":",
"new_stories",
"=",
"self",
".",
"_get_stories",
"(",
"'newstories'",
",",
"limit",
")",
"if",
"raw",
":",
"new_stories",
"=",
"[",
"story",
".",
"raw",
... | Returns list of item ids of current new stories
Args:
limit (int): specifies the number of stories to be returned.
raw (bool): Flag to indicate whether to transform all
objects into raw json.
Returns:
`list` object containing ids of new stories. | [
"Returns",
"list",
"of",
"item",
"ids",
"of",
"current",
"new",
"stories"
] | train | https://github.com/avinassh/haxor/blob/71dbecf87531f7a24bb39c736d53127427aaca84/hackernews/__init__.py#L293-L308 |
avinassh/haxor | hackernews/__init__.py | HackerNews.ask_stories | def ask_stories(self, raw=False, limit=None):
"""Returns list of item ids of latest Ask HN stories
Args:
limit (int): specifies the number of stories to be returned.
raw (bool): Flag to indicate whether to transform all
objects into raw json.
Returns:
... | python | def ask_stories(self, raw=False, limit=None):
"""Returns list of item ids of latest Ask HN stories
Args:
limit (int): specifies the number of stories to be returned.
raw (bool): Flag to indicate whether to transform all
objects into raw json.
Returns:
... | [
"def",
"ask_stories",
"(",
"self",
",",
"raw",
"=",
"False",
",",
"limit",
"=",
"None",
")",
":",
"ask_stories",
"=",
"self",
".",
"_get_stories",
"(",
"'askstories'",
",",
"limit",
")",
"if",
"raw",
":",
"ask_stories",
"=",
"[",
"story",
".",
"raw",
... | Returns list of item ids of latest Ask HN stories
Args:
limit (int): specifies the number of stories to be returned.
raw (bool): Flag to indicate whether to transform all
objects into raw json.
Returns:
`list` object containing ids of Ask HN stories. | [
"Returns",
"list",
"of",
"item",
"ids",
"of",
"latest",
"Ask",
"HN",
"stories"
] | train | https://github.com/avinassh/haxor/blob/71dbecf87531f7a24bb39c736d53127427aaca84/hackernews/__init__.py#L310-L325 |
avinassh/haxor | hackernews/__init__.py | HackerNews.show_stories | def show_stories(self, raw=False, limit=None):
"""Returns list of item ids of latest Show HN stories
Args:
limit (int): specifies the number of stories to be returned.
raw (bool): Flag to indicate whether to transform all
objects into raw json.
Returns:
... | python | def show_stories(self, raw=False, limit=None):
"""Returns list of item ids of latest Show HN stories
Args:
limit (int): specifies the number of stories to be returned.
raw (bool): Flag to indicate whether to transform all
objects into raw json.
Returns:
... | [
"def",
"show_stories",
"(",
"self",
",",
"raw",
"=",
"False",
",",
"limit",
"=",
"None",
")",
":",
"show_stories",
"=",
"self",
".",
"_get_stories",
"(",
"'showstories'",
",",
"limit",
")",
"if",
"raw",
":",
"show_stories",
"=",
"[",
"story",
".",
"raw... | Returns list of item ids of latest Show HN stories
Args:
limit (int): specifies the number of stories to be returned.
raw (bool): Flag to indicate whether to transform all
objects into raw json.
Returns:
`list` object containing ids of Show HN storie... | [
"Returns",
"list",
"of",
"item",
"ids",
"of",
"latest",
"Show",
"HN",
"stories"
] | train | https://github.com/avinassh/haxor/blob/71dbecf87531f7a24bb39c736d53127427aaca84/hackernews/__init__.py#L327-L342 |
avinassh/haxor | hackernews/__init__.py | HackerNews.job_stories | def job_stories(self, raw=False, limit=None):
"""Returns list of item ids of latest Job stories
Args:
limit (int): specifies the number of stories to be returned.
raw (bool): Flag to indicate whether to transform all
objects into raw json.
Returns:
... | python | def job_stories(self, raw=False, limit=None):
"""Returns list of item ids of latest Job stories
Args:
limit (int): specifies the number of stories to be returned.
raw (bool): Flag to indicate whether to transform all
objects into raw json.
Returns:
... | [
"def",
"job_stories",
"(",
"self",
",",
"raw",
"=",
"False",
",",
"limit",
"=",
"None",
")",
":",
"job_stories",
"=",
"self",
".",
"_get_stories",
"(",
"'jobstories'",
",",
"limit",
")",
"if",
"raw",
":",
"job_stories",
"=",
"[",
"story",
".",
"raw",
... | Returns list of item ids of latest Job stories
Args:
limit (int): specifies the number of stories to be returned.
raw (bool): Flag to indicate whether to transform all
objects into raw json.
Returns:
`list` object containing ids of Job stories. | [
"Returns",
"list",
"of",
"item",
"ids",
"of",
"latest",
"Job",
"stories"
] | train | https://github.com/avinassh/haxor/blob/71dbecf87531f7a24bb39c736d53127427aaca84/hackernews/__init__.py#L344-L359 |
avinassh/haxor | hackernews/__init__.py | HackerNews.updates | def updates(self):
"""Returns list of item ids and user ids that have been
changed/updated recently.
Fetches data from URL:
https://hacker-news.firebaseio.com/v0/updates.json
Returns:
`dict` with two keys whose values are `list` objects
"""
url ... | python | def updates(self):
"""Returns list of item ids and user ids that have been
changed/updated recently.
Fetches data from URL:
https://hacker-news.firebaseio.com/v0/updates.json
Returns:
`dict` with two keys whose values are `list` objects
"""
url ... | [
"def",
"updates",
"(",
"self",
")",
":",
"url",
"=",
"urljoin",
"(",
"self",
".",
"base_url",
",",
"'updates.json'",
")",
"response",
"=",
"self",
".",
"_get_sync",
"(",
"url",
")",
"return",
"{",
"'items'",
":",
"self",
".",
"get_items_by_ids",
"(",
"... | Returns list of item ids and user ids that have been
changed/updated recently.
Fetches data from URL:
https://hacker-news.firebaseio.com/v0/updates.json
Returns:
`dict` with two keys whose values are `list` objects | [
"Returns",
"list",
"of",
"item",
"ids",
"and",
"user",
"ids",
"that",
"have",
"been",
"changed",
"/",
"updated",
"recently",
"."
] | train | https://github.com/avinassh/haxor/blob/71dbecf87531f7a24bb39c736d53127427aaca84/hackernews/__init__.py#L361-L377 |
avinassh/haxor | hackernews/__init__.py | HackerNews.get_max_item | def get_max_item(self, expand=False):
"""The current largest item id
Fetches data from URL:
https://hacker-news.firebaseio.com/v0/maxitem.json
Args:
expand (bool): Flag to indicate whether to transform all
IDs into objects.
Returns:
... | python | def get_max_item(self, expand=False):
"""The current largest item id
Fetches data from URL:
https://hacker-news.firebaseio.com/v0/maxitem.json
Args:
expand (bool): Flag to indicate whether to transform all
IDs into objects.
Returns:
... | [
"def",
"get_max_item",
"(",
"self",
",",
"expand",
"=",
"False",
")",
":",
"url",
"=",
"urljoin",
"(",
"self",
".",
"base_url",
",",
"'maxitem.json'",
")",
"response",
"=",
"self",
".",
"_get_sync",
"(",
"url",
")",
"if",
"expand",
":",
"return",
"self... | The current largest item id
Fetches data from URL:
https://hacker-news.firebaseio.com/v0/maxitem.json
Args:
expand (bool): Flag to indicate whether to transform all
IDs into objects.
Returns:
`int` if successful. | [
"The",
"current",
"largest",
"item",
"id"
] | train | https://github.com/avinassh/haxor/blob/71dbecf87531f7a24bb39c736d53127427aaca84/hackernews/__init__.py#L379-L398 |
avinassh/haxor | hackernews/__init__.py | HackerNews.get_last | def get_last(self, num=10):
"""Returns last `num` of HN stories
Downloads all the HN articles and returns them as Item objects
Returns:
`list` object containing ids of HN stories.
"""
max_item = self.get_max_item()
urls = [urljoin(self.item_url, F"{i}.json"... | python | def get_last(self, num=10):
"""Returns last `num` of HN stories
Downloads all the HN articles and returns them as Item objects
Returns:
`list` object containing ids of HN stories.
"""
max_item = self.get_max_item()
urls = [urljoin(self.item_url, F"{i}.json"... | [
"def",
"get_last",
"(",
"self",
",",
"num",
"=",
"10",
")",
":",
"max_item",
"=",
"self",
".",
"get_max_item",
"(",
")",
"urls",
"=",
"[",
"urljoin",
"(",
"self",
".",
"item_url",
",",
"F\"{i}.json\"",
")",
"for",
"i",
"in",
"range",
"(",
"max_item",... | Returns last `num` of HN stories
Downloads all the HN articles and returns them as Item objects
Returns:
`list` object containing ids of HN stories. | [
"Returns",
"last",
"num",
"of",
"HN",
"stories"
] | train | https://github.com/avinassh/haxor/blob/71dbecf87531f7a24bb39c736d53127427aaca84/hackernews/__init__.py#L412-L425 |
pytries/DAWG-Python | dawg_python/dawgs.py | DAWG.load | def load(self, path):
"""
Loads DAWG from a file.
"""
self.dct = wrapper.Dictionary.load(path)
return self | python | def load(self, path):
"""
Loads DAWG from a file.
"""
self.dct = wrapper.Dictionary.load(path)
return self | [
"def",
"load",
"(",
"self",
",",
"path",
")",
":",
"self",
".",
"dct",
"=",
"wrapper",
".",
"Dictionary",
".",
"load",
"(",
"path",
")",
"return",
"self"
] | Loads DAWG from a file. | [
"Loads",
"DAWG",
"from",
"a",
"file",
"."
] | train | https://github.com/pytries/DAWG-Python/blob/e56241ec919b78735ff79014bf18d7fd1f8e08b9/dawg_python/dawgs.py#L22-L27 |
pytries/DAWG-Python | dawg_python/dawgs.py | DAWG.similar_keys | def similar_keys(self, key, replaces):
"""
Returns all variants of ``key`` in this DAWG according to
``replaces``.
``replaces`` is an object obtained from
``DAWG.compile_replaces(mapping)`` where mapping is a dict
that maps single-char unicode sitrings to another single-... | python | def similar_keys(self, key, replaces):
"""
Returns all variants of ``key`` in this DAWG according to
``replaces``.
``replaces`` is an object obtained from
``DAWG.compile_replaces(mapping)`` where mapping is a dict
that maps single-char unicode sitrings to another single-... | [
"def",
"similar_keys",
"(",
"self",
",",
"key",
",",
"replaces",
")",
":",
"return",
"self",
".",
"_similar_keys",
"(",
"\"\"",
",",
"key",
",",
"self",
".",
"dct",
".",
"ROOT",
",",
"replaces",
")"
] | Returns all variants of ``key`` in this DAWG according to
``replaces``.
``replaces`` is an object obtained from
``DAWG.compile_replaces(mapping)`` where mapping is a dict
that maps single-char unicode sitrings to another single-char
unicode strings.
This may be useful e... | [
"Returns",
"all",
"variants",
"of",
"key",
"in",
"this",
"DAWG",
"according",
"to",
"replaces",
"."
] | train | https://github.com/pytries/DAWG-Python/blob/e56241ec919b78735ff79014bf18d7fd1f8e08b9/dawg_python/dawgs.py#L65-L77 |
pytries/DAWG-Python | dawg_python/dawgs.py | DAWG.prefixes | def prefixes(self, key):
'''
Returns a list with keys of this DAWG that are prefixes of the ``key``.
'''
res = []
index = self.dct.ROOT
if not isinstance(key, bytes):
key = key.encode('utf8')
pos = 1
for ch in key:
index = self.dc... | python | def prefixes(self, key):
'''
Returns a list with keys of this DAWG that are prefixes of the ``key``.
'''
res = []
index = self.dct.ROOT
if not isinstance(key, bytes):
key = key.encode('utf8')
pos = 1
for ch in key:
index = self.dc... | [
"def",
"prefixes",
"(",
"self",
",",
"key",
")",
":",
"res",
"=",
"[",
"]",
"index",
"=",
"self",
".",
"dct",
".",
"ROOT",
"if",
"not",
"isinstance",
"(",
"key",
",",
"bytes",
")",
":",
"key",
"=",
"key",
".",
"encode",
"(",
"'utf8'",
")",
"pos... | Returns a list with keys of this DAWG that are prefixes of the ``key``. | [
"Returns",
"a",
"list",
"with",
"keys",
"of",
"this",
"DAWG",
"that",
"are",
"prefixes",
"of",
"the",
"key",
"."
] | train | https://github.com/pytries/DAWG-Python/blob/e56241ec919b78735ff79014bf18d7fd1f8e08b9/dawg_python/dawgs.py#L94-L114 |
pytries/DAWG-Python | dawg_python/dawgs.py | CompletionDAWG.load | def load(self, path):
"""
Loads DAWG from a file.
"""
self.dct = wrapper.Dictionary()
self.guide = wrapper.Guide()
with open(path, 'rb') as f:
self.dct.read(f)
self.guide.read(f)
return self | python | def load(self, path):
"""
Loads DAWG from a file.
"""
self.dct = wrapper.Dictionary()
self.guide = wrapper.Guide()
with open(path, 'rb') as f:
self.dct.read(f)
self.guide.read(f)
return self | [
"def",
"load",
"(",
"self",
",",
"path",
")",
":",
"self",
".",
"dct",
"=",
"wrapper",
".",
"Dictionary",
"(",
")",
"self",
".",
"guide",
"=",
"wrapper",
".",
"Guide",
"(",
")",
"with",
"open",
"(",
"path",
",",
"'rb'",
")",
"as",
"f",
":",
"se... | Loads DAWG from a file. | [
"Loads",
"DAWG",
"from",
"a",
"file",
"."
] | train | https://github.com/pytries/DAWG-Python/blob/e56241ec919b78735ff79014bf18d7fd1f8e08b9/dawg_python/dawgs.py#L157-L168 |
pytries/DAWG-Python | dawg_python/dawgs.py | BytesDAWG.get | def get(self, key, default=None):
"""
Returns a list of payloads (as byte objects) for a given key
or ``default`` if the key is not found.
"""
if not isinstance(key, bytes):
key = key.encode('utf8')
return self.b_get_value(key) or default | python | def get(self, key, default=None):
"""
Returns a list of payloads (as byte objects) for a given key
or ``default`` if the key is not found.
"""
if not isinstance(key, bytes):
key = key.encode('utf8')
return self.b_get_value(key) or default | [
"def",
"get",
"(",
"self",
",",
"key",
",",
"default",
"=",
"None",
")",
":",
"if",
"not",
"isinstance",
"(",
"key",
",",
"bytes",
")",
":",
"key",
"=",
"key",
".",
"encode",
"(",
"'utf8'",
")",
"return",
"self",
".",
"b_get_value",
"(",
"key",
"... | Returns a list of payloads (as byte objects) for a given key
or ``default`` if the key is not found. | [
"Returns",
"a",
"list",
"of",
"payloads",
"(",
"as",
"byte",
"objects",
")",
"for",
"a",
"given",
"key",
"or",
"default",
"if",
"the",
"key",
"is",
"not",
"found",
"."
] | train | https://github.com/pytries/DAWG-Python/blob/e56241ec919b78735ff79014bf18d7fd1f8e08b9/dawg_python/dawgs.py#L200-L208 |
pytries/DAWG-Python | dawg_python/dawgs.py | BytesDAWG.similar_items | def similar_items(self, key, replaces):
"""
Returns a list of (key, value) tuples for all variants of ``key``
in this DAWG according to ``replaces``.
``replaces`` is an object obtained from
``DAWG.compile_replaces(mapping)`` where mapping is a dict
that maps single-char ... | python | def similar_items(self, key, replaces):
"""
Returns a list of (key, value) tuples for all variants of ``key``
in this DAWG according to ``replaces``.
``replaces`` is an object obtained from
``DAWG.compile_replaces(mapping)`` where mapping is a dict
that maps single-char ... | [
"def",
"similar_items",
"(",
"self",
",",
"key",
",",
"replaces",
")",
":",
"return",
"self",
".",
"_similar_items",
"(",
"\"\"",
",",
"key",
",",
"self",
".",
"dct",
".",
"ROOT",
",",
"replaces",
")"
] | Returns a list of (key, value) tuples for all variants of ``key``
in this DAWG according to ``replaces``.
``replaces`` is an object obtained from
``DAWG.compile_replaces(mapping)`` where mapping is a dict
that maps single-char unicode sitrings to another single-char
unicode stri... | [
"Returns",
"a",
"list",
"of",
"(",
"key",
"value",
")",
"tuples",
"for",
"all",
"variants",
"of",
"key",
"in",
"this",
"DAWG",
"according",
"to",
"replaces",
"."
] | train | https://github.com/pytries/DAWG-Python/blob/e56241ec919b78735ff79014bf18d7fd1f8e08b9/dawg_python/dawgs.py#L359-L369 |
pytries/DAWG-Python | dawg_python/dawgs.py | BytesDAWG.similar_item_values | def similar_item_values(self, key, replaces):
"""
Returns a list of values for all variants of the ``key``
in this DAWG according to ``replaces``.
``replaces`` is an object obtained from
``DAWG.compile_replaces(mapping)`` where mapping is a dict
that maps single-char uni... | python | def similar_item_values(self, key, replaces):
"""
Returns a list of values for all variants of the ``key``
in this DAWG according to ``replaces``.
``replaces`` is an object obtained from
``DAWG.compile_replaces(mapping)`` where mapping is a dict
that maps single-char uni... | [
"def",
"similar_item_values",
"(",
"self",
",",
"key",
",",
"replaces",
")",
":",
"return",
"self",
".",
"_similar_item_values",
"(",
"0",
",",
"key",
",",
"self",
".",
"dct",
".",
"ROOT",
",",
"replaces",
")"
] | Returns a list of values for all variants of the ``key``
in this DAWG according to ``replaces``.
``replaces`` is an object obtained from
``DAWG.compile_replaces(mapping)`` where mapping is a dict
that maps single-char unicode sitrings to another single-char
unicode strings. | [
"Returns",
"a",
"list",
"of",
"values",
"for",
"all",
"variants",
"of",
"the",
"key",
"in",
"this",
"DAWG",
"according",
"to",
"replaces",
"."
] | train | https://github.com/pytries/DAWG-Python/blob/e56241ec919b78735ff79014bf18d7fd1f8e08b9/dawg_python/dawgs.py#L402-L412 |
pytries/DAWG-Python | dawg_python/wrapper.py | Dictionary.value | def value(self, index):
"Gets a value from a given index."
offset = units.offset(self._units[index])
value_index = (index ^ offset) & units.PRECISION_MASK
return units.value(self._units[value_index]) | python | def value(self, index):
"Gets a value from a given index."
offset = units.offset(self._units[index])
value_index = (index ^ offset) & units.PRECISION_MASK
return units.value(self._units[value_index]) | [
"def",
"value",
"(",
"self",
",",
"index",
")",
":",
"offset",
"=",
"units",
".",
"offset",
"(",
"self",
".",
"_units",
"[",
"index",
"]",
")",
"value_index",
"=",
"(",
"index",
"^",
"offset",
")",
"&",
"units",
".",
"PRECISION_MASK",
"return",
"unit... | Gets a value from a given index. | [
"Gets",
"a",
"value",
"from",
"a",
"given",
"index",
"."
] | train | https://github.com/pytries/DAWG-Python/blob/e56241ec919b78735ff79014bf18d7fd1f8e08b9/dawg_python/wrapper.py#L24-L28 |
pytries/DAWG-Python | dawg_python/wrapper.py | Dictionary.read | def read(self, fp):
"Reads a dictionary from an input stream."
base_size = struct.unpack(str("=I"), fp.read(4))[0]
self._units.fromfile(fp, base_size) | python | def read(self, fp):
"Reads a dictionary from an input stream."
base_size = struct.unpack(str("=I"), fp.read(4))[0]
self._units.fromfile(fp, base_size) | [
"def",
"read",
"(",
"self",
",",
"fp",
")",
":",
"base_size",
"=",
"struct",
".",
"unpack",
"(",
"str",
"(",
"\"=I\"",
")",
",",
"fp",
".",
"read",
"(",
"4",
")",
")",
"[",
"0",
"]",
"self",
".",
"_units",
".",
"fromfile",
"(",
"fp",
",",
"ba... | Reads a dictionary from an input stream. | [
"Reads",
"a",
"dictionary",
"from",
"an",
"input",
"stream",
"."
] | train | https://github.com/pytries/DAWG-Python/blob/e56241ec919b78735ff79014bf18d7fd1f8e08b9/dawg_python/wrapper.py#L30-L33 |
pytries/DAWG-Python | dawg_python/wrapper.py | Dictionary.contains | def contains(self, key):
"Exact matching."
index = self.follow_bytes(key, self.ROOT)
if index is None:
return False
return self.has_value(index) | python | def contains(self, key):
"Exact matching."
index = self.follow_bytes(key, self.ROOT)
if index is None:
return False
return self.has_value(index) | [
"def",
"contains",
"(",
"self",
",",
"key",
")",
":",
"index",
"=",
"self",
".",
"follow_bytes",
"(",
"key",
",",
"self",
".",
"ROOT",
")",
"if",
"index",
"is",
"None",
":",
"return",
"False",
"return",
"self",
".",
"has_value",
"(",
"index",
")"
] | Exact matching. | [
"Exact",
"matching",
"."
] | train | https://github.com/pytries/DAWG-Python/blob/e56241ec919b78735ff79014bf18d7fd1f8e08b9/dawg_python/wrapper.py#L35-L40 |
pytries/DAWG-Python | dawg_python/wrapper.py | Dictionary.find | def find(self, key):
"Exact matching (returns value)"
index = self.follow_bytes(key, self.ROOT)
if index is None:
return -1
if not self.has_value(index):
return -1
return self.value(index) | python | def find(self, key):
"Exact matching (returns value)"
index = self.follow_bytes(key, self.ROOT)
if index is None:
return -1
if not self.has_value(index):
return -1
return self.value(index) | [
"def",
"find",
"(",
"self",
",",
"key",
")",
":",
"index",
"=",
"self",
".",
"follow_bytes",
"(",
"key",
",",
"self",
".",
"ROOT",
")",
"if",
"index",
"is",
"None",
":",
"return",
"-",
"1",
"if",
"not",
"self",
".",
"has_value",
"(",
"index",
")"... | Exact matching (returns value) | [
"Exact",
"matching",
"(",
"returns",
"value",
")"
] | train | https://github.com/pytries/DAWG-Python/blob/e56241ec919b78735ff79014bf18d7fd1f8e08b9/dawg_python/wrapper.py#L42-L49 |
pytries/DAWG-Python | dawg_python/wrapper.py | Dictionary.follow_char | def follow_char(self, label, index):
"Follows a transition"
offset = units.offset(self._units[index])
next_index = (index ^ offset ^ label) & units.PRECISION_MASK
if units.label(self._units[next_index]) != label:
return None
return next_index | python | def follow_char(self, label, index):
"Follows a transition"
offset = units.offset(self._units[index])
next_index = (index ^ offset ^ label) & units.PRECISION_MASK
if units.label(self._units[next_index]) != label:
return None
return next_index | [
"def",
"follow_char",
"(",
"self",
",",
"label",
",",
"index",
")",
":",
"offset",
"=",
"units",
".",
"offset",
"(",
"self",
".",
"_units",
"[",
"index",
"]",
")",
"next_index",
"=",
"(",
"index",
"^",
"offset",
"^",
"label",
")",
"&",
"units",
"."... | Follows a transition | [
"Follows",
"a",
"transition"
] | train | https://github.com/pytries/DAWG-Python/blob/e56241ec919b78735ff79014bf18d7fd1f8e08b9/dawg_python/wrapper.py#L51-L59 |
pytries/DAWG-Python | dawg_python/wrapper.py | Dictionary.follow_bytes | def follow_bytes(self, s, index):
"Follows transitions."
for ch in s:
index = self.follow_char(int_from_byte(ch), index)
if index is None:
return None
return index | python | def follow_bytes(self, s, index):
"Follows transitions."
for ch in s:
index = self.follow_char(int_from_byte(ch), index)
if index is None:
return None
return index | [
"def",
"follow_bytes",
"(",
"self",
",",
"s",
",",
"index",
")",
":",
"for",
"ch",
"in",
"s",
":",
"index",
"=",
"self",
".",
"follow_char",
"(",
"int_from_byte",
"(",
"ch",
")",
",",
"index",
")",
"if",
"index",
"is",
"None",
":",
"return",
"None"... | Follows transitions. | [
"Follows",
"transitions",
"."
] | train | https://github.com/pytries/DAWG-Python/blob/e56241ec919b78735ff79014bf18d7fd1f8e08b9/dawg_python/wrapper.py#L61-L68 |
pytries/DAWG-Python | dawg_python/wrapper.py | Completer.next | def next(self):
"Gets the next key"
if not self._index_stack:
return False
index = self._index_stack[-1]
if self._last_index != self._dic.ROOT:
child_label = self._guide.child(index) # UCharType
if child_label:
# Follows a transit... | python | def next(self):
"Gets the next key"
if not self._index_stack:
return False
index = self._index_stack[-1]
if self._last_index != self._dic.ROOT:
child_label = self._guide.child(index) # UCharType
if child_label:
# Follows a transit... | [
"def",
"next",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"_index_stack",
":",
"return",
"False",
"index",
"=",
"self",
".",
"_index_stack",
"[",
"-",
"1",
"]",
"if",
"self",
".",
"_last_index",
"!=",
"self",
".",
"_dic",
".",
"ROOT",
":",
"c... | Gets the next key | [
"Gets",
"the",
"next",
"key"
] | train | https://github.com/pytries/DAWG-Python/blob/e56241ec919b78735ff79014bf18d7fd1f8e08b9/dawg_python/wrapper.py#L117-L154 |
cloudendpoints/endpoints-management-python | endpoints_management/control/check_request.py | convert_response | def convert_response(check_response, project_id):
"""Computes a http status code and message `CheckResponse`
The return value a tuple (code, message, api_key_is_bad) where
code: is the http status code
message: is the message to return
api_key_is_bad: indicates that a given api_key is bad
Arg... | python | def convert_response(check_response, project_id):
"""Computes a http status code and message `CheckResponse`
The return value a tuple (code, message, api_key_is_bad) where
code: is the http status code
message: is the message to return
api_key_is_bad: indicates that a given api_key is bad
Arg... | [
"def",
"convert_response",
"(",
"check_response",
",",
"project_id",
")",
":",
"if",
"not",
"check_response",
"or",
"not",
"check_response",
".",
"checkErrors",
":",
"return",
"_IS_OK",
"# only check the first error for now, as per ESP",
"theError",
"=",
"check_response",... | Computes a http status code and message `CheckResponse`
The return value a tuple (code, message, api_key_is_bad) where
code: is the http status code
message: is the message to return
api_key_is_bad: indicates that a given api_key is bad
Args:
check_response (:class:`endpoints_management.ge... | [
"Computes",
"a",
"http",
"status",
"code",
"and",
"message",
"CheckResponse"
] | train | https://github.com/cloudendpoints/endpoints-management-python/blob/ec3c4a330ae9d65738861ce6df4dd6c3cb9f7731/endpoints_management/control/check_request.py#L126-L152 |
cloudendpoints/endpoints-management-python | endpoints_management/control/check_request.py | sign | def sign(check_request):
"""Obtains a signature for an operation in a `CheckRequest`
Args:
op (:class:`endpoints_management.gen.servicecontrol_v1_messages.Operation`): an
operation used in a `CheckRequest`
Returns:
string: a secure hash generated from the operation
"""
if no... | python | def sign(check_request):
"""Obtains a signature for an operation in a `CheckRequest`
Args:
op (:class:`endpoints_management.gen.servicecontrol_v1_messages.Operation`): an
operation used in a `CheckRequest`
Returns:
string: a secure hash generated from the operation
"""
if no... | [
"def",
"sign",
"(",
"check_request",
")",
":",
"if",
"not",
"isinstance",
"(",
"check_request",
",",
"sc_messages",
".",
"CheckRequest",
")",
":",
"raise",
"ValueError",
"(",
"u'Invalid request'",
")",
"op",
"=",
"check_request",
".",
"operation",
"if",
"op",
... | Obtains a signature for an operation in a `CheckRequest`
Args:
op (:class:`endpoints_management.gen.servicecontrol_v1_messages.Operation`): an
operation used in a `CheckRequest`
Returns:
string: a secure hash generated from the operation | [
"Obtains",
"a",
"signature",
"for",
"an",
"operation",
"in",
"a",
"CheckRequest"
] | train | https://github.com/cloudendpoints/endpoints-management-python/blob/ec3c4a330ae9d65738861ce6df4dd6c3cb9f7731/endpoints_management/control/check_request.py#L155-L191 |
cloudendpoints/endpoints-management-python | endpoints_management/control/check_request.py | Info.as_check_request | def as_check_request(self, timer=datetime.utcnow):
"""Makes a `ServicecontrolServicesCheckRequest` from this instance
Returns:
a ``ServicecontrolServicesCheckRequest``
Raises:
ValueError: if the fields in this instance are insufficient to
to create a valid ``Ser... | python | def as_check_request(self, timer=datetime.utcnow):
"""Makes a `ServicecontrolServicesCheckRequest` from this instance
Returns:
a ``ServicecontrolServicesCheckRequest``
Raises:
ValueError: if the fields in this instance are insufficient to
to create a valid ``Ser... | [
"def",
"as_check_request",
"(",
"self",
",",
"timer",
"=",
"datetime",
".",
"utcnow",
")",
":",
"if",
"not",
"self",
".",
"service_name",
":",
"raise",
"ValueError",
"(",
"u'the service name must be set'",
")",
"if",
"not",
"self",
".",
"operation_id",
":",
... | Makes a `ServicecontrolServicesCheckRequest` from this instance
Returns:
a ``ServicecontrolServicesCheckRequest``
Raises:
ValueError: if the fields in this instance are insufficient to
to create a valid ``ServicecontrolServicesCheckRequest`` | [
"Makes",
"a",
"ServicecontrolServicesCheckRequest",
"from",
"this",
"instance"
] | train | https://github.com/cloudendpoints/endpoints-management-python/blob/ec3c4a330ae9d65738861ce6df4dd6c3cb9f7731/endpoints_management/control/check_request.py#L213-L257 |
cloudendpoints/endpoints-management-python | endpoints_management/control/check_request.py | Aggregator.flush | def flush(self):
"""Flushes this instance's cache.
The driver of this instance should call this method every
`flush_interval`.
Returns:
list['CheckRequest']: corresponding to CheckRequests that were
pending
"""
if self._cache is None:
re... | python | def flush(self):
"""Flushes this instance's cache.
The driver of this instance should call this method every
`flush_interval`.
Returns:
list['CheckRequest']: corresponding to CheckRequests that were
pending
"""
if self._cache is None:
re... | [
"def",
"flush",
"(",
"self",
")",
":",
"if",
"self",
".",
"_cache",
"is",
"None",
":",
"return",
"[",
"]",
"with",
"self",
".",
"_cache",
"as",
"c",
":",
"flushed_items",
"=",
"list",
"(",
"c",
".",
"out_deque",
")",
"c",
".",
"out_deque",
".",
"... | Flushes this instance's cache.
The driver of this instance should call this method every
`flush_interval`.
Returns:
list['CheckRequest']: corresponding to CheckRequests that were
pending | [
"Flushes",
"this",
"instance",
"s",
"cache",
"."
] | train | https://github.com/cloudendpoints/endpoints-management-python/blob/ec3c4a330ae9d65738861ce6df4dd6c3cb9f7731/endpoints_management/control/check_request.py#L349-L367 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.