selector

class wechinelearn.selector.Selector[source]

Data selector interface.

get_nearest_object(lat, lng)[source]

中文文档

获取某个坐标最近的object。

get_wdata_by_station(station_id, start, end)[source]

中文文档

获取一个气象站在某个时间段内所观测到的天气数据。

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%可信, 则可信度要优先于距离。

这部分的算法稍微有些复杂, 详细逻辑如下:

  1. 从近到远地在radius1范围内选择气象站, 并对计算reliability, 若高于r1,
则返回该数据。即使后面可能有比r1可信度更高的数据, 也不采纳。
  1. 若果所有的气象站的reliability都无法高于r1, 那么选用radius2范围
reliability最高的那个, 即使他离得较远。但是reliability至少要高于r2。
get_wdata_by_object(object_id, start, end, **kwargs)[source]

中文文档

选取某个object附近的天气数据。总是优先选择最可信的。若都不够95%可信, 则可信度要优先于距离。

get_odata_by_object(object_id, start, end)[source]

中文文档

选取某个object某个时间段内的数据。

get_feature_raw(object_id, start, end)[source]

中文文档

选取某个object某个时间段内的特征。

get_feature(object_id, start, end)[source]

中文文档

选取某个object某个时间段内的特征。

get_useful_feature_data(object_id, date_time, features=None, label=None)[source]

中文文档

给定一个用户和时刻, 返回该时刻可用的所有特征数据。特征数据需要满足

  1. 31天以内的日期。
  2. 和该时刻同为工作日或周末。
  3. 小时的时差在2小时以内。

返回numpy.ndarray

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; the Select.where() method for example can be invoked multiple times against a statement, which will have the effect of each clause being combined using and_():

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 the Select.distinct() method of Select, which produces a SELECT statement with DISTINCT applied to the result set as a whole, e.g. a SELECT 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 any FromClause.

All arguments which accept ClauseElement arguments also accept string arguments, which will be converted as appropriate into either text() or literal_column() constructs.

See also

coretutorial_selecting - Core Tutorial description of select().

Parameters:
  • columns

    A list of ClauseElement objects, typically ColumnElement objects or subclasses, which will form the columns clause of the resulting statement. For all members which are instances of Selectable, the individual ColumnElement members of the Selectable will be added individually to the columns clause. For example, specifying a Table instance will result in all the contained Column objects within to be added to the columns clause.

    This argument is not present on the form of select() available on Table.

  • whereclause – A ClauseElement expression which will be used to form the WHERE clause.
  • from_obj – A list of ClauseElement objects which will be added to the FROM 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 include Table objects that aren’t otherwise present, or Join objects whose presence will supercede that of the Table objects already located in the other clauses.
  • autocommit – Deprecated. Use .execution_options(autocommit=<True|False>) to set the autocommit option.
  • bind=None – an Engine or Connection instance to which the resulting Select object will be bound. The Select object will otherwise automatically bind to whatever Connectable instances can be located within its contained ClauseElement members.
  • correlate=True – indicates that this Select object should have its contained FromClause elements “correlated” to an enclosing Select object. This means that any ClauseElement instance within the “froms” collection of this Select which is also present in the “froms” collection of an enclosing select will not be rendered in the FROM clause of this select statement.
  • distinct=False

    when True, applies a DISTINCT 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 the distinct() generative method.

  • for_update=False
    when True, applies FOR UPDATE to the end of the resulting statement.

    Deprecated since version 0.9.0: - use GenerativeSelect.with_for_update() to specify the structure of the FOR UPDATE clause.

    for_update accepts various string values interpreted by specific backends, including:

    • "read" - on MySQL, translates to LOCK IN SHARE MODE; on Postgresql, translates to FOR SHARE.
    • "nowait" - on Postgresql and Oracle, translates to FOR UPDATE NOWAIT.
    • "read_nowait" - on Postgresql, translates to FOR SHARE NOWAIT.

    See also

    GenerativeSelect.with_for_update() - improved API for specifying the FOR UPDATE clause.

  • group_by – a list of ClauseElement objects which will comprise the GROUP BY clause of the resulting select.
  • having – a ClauseElement that will comprise the HAVING clause of the resulting select when GROUP BY is used.
  • limit=None – a numerical value which usually compiles to a LIMIT expression in the resulting select. Databases that don’t support LIMIT 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 support OFFSET will attempt to provide similar functionality.
  • order_by – a scalar or list of ClauseElement objects which will comprise the ORDER 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 resulting Select object will use these names as well for targeting column members.

    use_labels is also available via the apply_labels() generative method.

wechinelearn.selector.test_selector()[source]