我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用sqlalchemy.between()。
def _find_columns(clause): """locate Column objects within the given expression.""" cols = util.column_set() traverse(clause, {}, {'column': cols.add}) return cols # there is some inconsistency here between the usage of # inspect() vs. checking for Visitable and __clause_element__. # Ideally all functions here would derive from inspect(), # however the inspect() versions add significant callcount # overhead for critical functions like _interpret_as_column_or_from(). # Generally, the column-based functions are more performance critical # and are fine just checking for __clause_element__(). It is only # _interpret_as_from() where we'd like to be able to receive ORM entities # that have no defined namespace, hence inspect() is needed there.
def _get_last_watering_timestamp(sensor_uuid): """Try to find last watering from the last 500 records of the sensor. A diffenrece of `watering_thresold` must be found between now and then to be considered a watering.""" watering_thresold = 50 # Minimum fluctuation to consider a watering records = HygroRecord.query \ .filter(HygroRecord.sensor_uuid == sensor_uuid) \ .order_by(desc(HygroRecord.timestamp)).limit(5000).all() last_record = records[0] for current in records[1:]: if current.value < last_record.value \ and last_record.value - current.value >= watering_thresold: return last_record.timestamp last_record = current
def _get_polynomial(sensor_uuid, start, stop=dt.datetime.now()): """ Get a polynomial aproximation of the soil humidity function from data. """ x = [] y = [] records = HygroRecord.query \ .filter(HygroRecord.sensor_uuid == sensor_uuid) \ .filter(between(HygroRecord.timestamp, start, stop)) \ .order_by(HygroRecord.timestamp).all() for r in records: x.append((r.timestamp - start)) y.append(int(r.value)) if len(x) > 0: return polynomial.polyfit(x, y, 1)
def _cloned_intersection(a, b): """return the intersection of sets a and b, counting any overlap between 'cloned' predecessors. The returned set is in terms of the entities present within 'a'. """ all_overlap = set(_expand_cloned(a)).intersection(_expand_cloned(b)) return set(elem for elem in a if all_overlap.intersection(elem._cloned_set))