text
stringlengths
0
828
instance = cls(geo_distance={'distance': distance, field: center})
if distance_type is not None:
instance['geo_distance']['distance_type'] = distance_type
return instance"
340,"def geo_distance_range(cls, field, center, from_distance, to_distance, distance_type=None):
'''
http://www.elasticsearch.org/guide/reference/query-dsl/geo-distance-range-filter.html
Filters documents that exists within a range from a specific point
'''
instance = cls(geo_distance_range={'from': from_distance, 'to': to_distance, field: center})
if distance_type is not None:
instance['geo_distance_range']['distance_type'] = distance_type
return instance"
341,"def numeric_range(cls, field, from_value, to_value, include_lower=None, include_upper=None):
'''
http://www.elasticsearch.org/guide/reference/query-dsl/numeric-range-filter.html
Filters documents with fields that have values within a certain numeric range. Similar to range filter, except that it works only with numeric values, and the filter execution works differently.
'''
instance = cls(numeric_range={field: {'from': from_value, 'to': to_value}})
if include_lower is not None:
instance['numeric_range'][field]['include_lower'] = include_lower
if include_upper is not None:
instance['numeric_range'][field]['include_upper'] = include_upper
return instance"
342,"def range(cls, field, from_value=None, to_value=None, include_lower=None, include_upper=None):
'''
http://www.elasticsearch.org/guide/reference/query-dsl/range-filter.html
Filters documents with fields that have terms within a certain range. Similar to range query, except that it acts as a filter. Can be placed within queries that accept a filter.
'''
instance = cls({'range': {field: {}}})
if from_value is not None:
instance['range'][field]['from'] = from_value
if to_value is not None:
instance['range'][field]['to'] = to_value
if include_lower is not None:
instance['range'][field]['include_lower'] = include_lower
if include_upper is not None:
instance['range'][field]['include_upper'] = include_upper
return instance"
343,"def save(self, obj, id_code):
""""""
Save an object, and use id_code in the filename
obj - any object
id_code - unique identifier
""""""
filestream = open('{0}/{1}'.format(self.data_path, id_code), 'w+')
pickle.dump(obj, filestream)
filestream.close()"
344,"def load(self, id_code):
""""""
Loads a workflow identified by id_code
id_code - unique identifier, previously must have called save with same id_code
""""""
filestream = open('{0}/{1}'.format(self.data_path, id_code), 'rb')
workflow = pickle.load(filestream)
return workflow"
345,"def init(self):
""""""init `todo` file
if file exists, then initialization self.todos
and record current max index of todos
: when add a new todo, the `idx` via only `self.current_max_idx + 1`
""""""
if os.path.isdir(self.path):
raise InvalidTodoFile
if os.path.exists(self.path):
with open(self.path, 'r') as f:
tls = [tl.strip() for tl in f if tl]
todos = map(_todo_from_file, tls)
self.todos = todos
for todo in todos:
if self.current_max_idx < todo['idx']:
self.current_max_idx = todo['idx']
else:
logger.warning('No todo files found, initialization a empty todo file')
with open(self.path, 'w') as f:
f.flush()"
346,"def _show(self, status=None, idx=None):
""""""show todos after format
:param status: what status's todos wants to show.
default is None, means show all
""""""
_show('', 50)
if not self.todos:
self._show_no_todos()
elif idx is not None:
for todo in self.todos:
if todo['idx'] == idx:
self._show_todos(todo)
elif status is not None:
if status not in STATUS_CODE:
raise InvalidTodoStatus
_todos = []
for todo in self.todos:
if todo['status'] == status: