selector¶
-
class
wechinelearn.selector.
Selector
[source]¶ Data selector interface.
-
get_wdata_by_coordinate
(lat, lng, start, end, r1=0.95, radius1=60.0, r2=0.75, radius2=30.0, n_station=10)[source]¶ 中文文档
选取某个坐标附近的天气数据。总是优先选择最可信的。若都不够95%可信, 则可信度要优先于距离。
这部分的算法稍微有些复杂, 详细逻辑如下:
- 从近到远地在radius1范围内选择气象站, 并对计算reliability, 若高于r1,
则返回该数据。即使后面可能有比r1可信度更高的数据, 也不采纳。- 若果所有的气象站的reliability都无法高于r1, 那么选用radius2范围
reliability最高的那个, 即使他离得较远。但是reliability至少要高于r2。
-
-
wechinelearn.selector.
and_
(*clauses)¶ Produce a conjunction of expressions joined by
AND
.E.g.:
from sqlalchemy import and_ stmt = select([users_table]).where( and_( users_table.c.name == 'wendy', users_table.c.enrolled == True ) )
The
and_()
conjunction is also available using the Python&
operator (though note that compound expressions need to be parenthesized in order to function with Python operator precedence behavior):stmt = select([users_table]).where( (users_table.c.name == 'wendy') & (users_table.c.enrolled == True) )
The
and_()
operation is also implicit in some cases; theSelect.where()
method for example can be invoked multiple times against a statement, which will have the effect of each clause being combined usingand_()
:stmt = select([users_table]).\ where(users_table.c.name == 'wendy').\ where(users_table.c.enrolled == True)
See also
or_()
-
wechinelearn.selector.
distinct
(expr)¶ Produce an column-expression-level unary
DISTINCT
clause.This applies the
DISTINCT
keyword to an individual column expression, and is typically contained within an aggregate function, as in:from sqlalchemy import distinct, func stmt = select([func.count(distinct(users_table.c.name))])
The above would produce an expression resembling:
SELECT COUNT(DISTINCT name) FROM user
The
distinct()
function is also available as a column-level method, e.g.ColumnElement.distinct()
, as in:stmt = select([func.count(users_table.c.name.distinct())])
The
distinct()
operator is different from theSelect.distinct()
method ofSelect
, which produces aSELECT
statement withDISTINCT
applied to the result set as a whole, e.g. aSELECT DISTINCT
expression. See that method for further information.See also
ColumnElement.distinct()
Select.distinct()
func
-
wechinelearn.selector.
select
(columns=None, whereclause=None, from_obj=None, distinct=False, having=None, correlate=True, prefixes=None, **kwargs)¶ Construct a new
Select
.Similar functionality is also available via the
FromClause.select()
method on anyFromClause
.All arguments which accept
ClauseElement
arguments also accept string arguments, which will be converted as appropriate into eithertext()
orliteral_column()
constructs.See also
coretutorial_selecting - Core Tutorial description of
select()
.Parameters: - columns –
A list of
ClauseElement
objects, typicallyColumnElement
objects or subclasses, which will form the columns clause of the resulting statement. For all members which are instances ofSelectable
, the individualColumnElement
members of theSelectable
will be added individually to the columns clause. For example, specifying aTable
instance will result in all the containedColumn
objects within to be added to the columns clause.This argument is not present on the form of
select()
available onTable
. - whereclause – A
ClauseElement
expression which will be used to form theWHERE
clause. - from_obj – A list of
ClauseElement
objects which will be added to theFROM
clause of the resulting statement. Note that “from” objects are automatically located within the columns and whereclause ClauseElements. Use this parameter to explicitly specify “from” objects which are not automatically locatable. This could includeTable
objects that aren’t otherwise present, orJoin
objects whose presence will supercede that of theTable
objects already located in the other clauses. - autocommit – Deprecated. Use .execution_options(autocommit=<True|False>) to set the autocommit option.
- bind=None – an
Engine
orConnection
instance to which the resultingSelect
object will be bound. TheSelect
object will otherwise automatically bind to whateverConnectable
instances can be located within its containedClauseElement
members. - correlate=True – indicates that this
Select
object should have its containedFromClause
elements “correlated” to an enclosingSelect
object. This means that anyClauseElement
instance within the “froms” collection of thisSelect
which is also present in the “froms” collection of an enclosing select will not be rendered in theFROM
clause of this select statement. - distinct=False –
when
True
, applies aDISTINCT
qualifier to the columns clause of the resulting statement.The boolean argument may also be a column expression or list of column expressions - this is a special calling form which is understood by the Postgresql dialect to render the
DISTINCT ON (<columns>)
syntax.distinct
is also available via thedistinct()
generative method. - for_update=False – when
True
, appliesFOR UPDATE
to the end of the resulting statement.Deprecated since version 0.9.0: - use
GenerativeSelect.with_for_update()
to specify the structure of theFOR UPDATE
clause.for_update
accepts various string values interpreted by specific backends, including:"read"
- on MySQL, translates toLOCK IN SHARE MODE
; on Postgresql, translates toFOR SHARE
."nowait"
- on Postgresql and Oracle, translates toFOR UPDATE NOWAIT
."read_nowait"
- on Postgresql, translates toFOR SHARE NOWAIT
.
See also
GenerativeSelect.with_for_update()
- improved API for specifying theFOR UPDATE
clause. - group_by – a list of
ClauseElement
objects which will comprise theGROUP BY
clause of the resulting select. - having – a
ClauseElement
that will comprise theHAVING
clause of the resulting select whenGROUP BY
is used. - limit=None – a numerical value which usually compiles to a
LIMIT
expression in the resulting select. Databases that don’t supportLIMIT
will attempt to provide similar functionality. - offset=None – a numeric value which usually compiles to an
OFFSET
expression in the resulting select. Databases that don’t supportOFFSET
will attempt to provide similar functionality. - order_by – a scalar or list of
ClauseElement
objects which will comprise theORDER BY
clause of the resulting select. - use_labels=False –
when
True
, the statement will be generated using labels for each column in the columns clause, which qualify each column with its parent table’s (or aliases) name so that name conflicts between columns in different tables don’t occur. The format of the label is <tablename>_<column>. The “c” collection of the resultingSelect
object will use these names as well for targeting column members.use_labels is also available via the
apply_labels()
generative method.
- columns –