当前位置: 首页>>代码示例>>Python>>正文


Python pendulum.from_timestamp方法代码示例

本文整理汇总了Python中pendulum.from_timestamp方法的典型用法代码示例。如果您正苦于以下问题:Python pendulum.from_timestamp方法的具体用法?Python pendulum.from_timestamp怎么用?Python pendulum.from_timestamp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pendulum的用法示例。


在下文中一共展示了pendulum.from_timestamp方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: decode_literal

# 需要导入模块: import pendulum [as 别名]
# 或者: from pendulum import from_timestamp [as 别名]
def decode_literal(node, prim):
    core_type, value = next(iter(node.items()))
    if prim in ['int', 'nat']:
        return int(value)
    if prim == 'timestamp':
        if core_type == 'int':
            return pendulum.from_timestamp(int(value))
        else:
            return pendulum.parse(value)
    if prim == 'mutez':
        return Decimal(value) / 10 ** 6
    if prim == 'bool':
        return value == 'True'
    if prim == 'address' and core_type == 'bytes':
        prefix = {'0000': b'tz1', '0001': b'tz2', '0002': b'tz3'}  # TODO: check it's ttr
        return base58_encode(bytes.fromhex(value[4:]), prefix[value[:4]]).decode()
    return value 
开发者ID:murbard,项目名称:pytezos,代码行数:19,代码来源:schema.py

示例2: get_report_time

# 需要导入模块: import pendulum [as 别名]
# 或者: from pendulum import from_timestamp [as 别名]
def get_report_time(last_report_time, offset, secs_since_report):
    # This method is up for debate.
    # To account for possible latency in the connection, we are subtracting
    # "seconds_since_report" from the last report time,
    # not the time the request was made or the time returned in the header.
    # Therefore an "offset" is added - equal to the seconds_since_report
    # of the most recent report, in order to make seconds_since_report
    # relative to the last report time --> not "now".
    # The reason for not using "now" is that it is unclear what
    # seconds_since_report is measured relative to. No info from NextBus
    # or Metro on this.
    return pendulum.from_timestamp(
        int(last_report_time + offset - secs_since_report)
    ).to_rfc3339_string() 
开发者ID:metro-ontime,项目名称:performance_tracker,代码行数:16,代码来源:nextBusData.py

示例3: filter_google_dates

# 需要导入模块: import pendulum [as 别名]
# 或者: from pendulum import from_timestamp [as 别名]
def filter_google_dates(
	songs,
	*,
	creation_dates=None,
	modification_dates=None,
):
	matched_songs = songs

	def _dt_from_gm_timestamp(gm_timestamp):
		return pendulum.from_timestamp(gm_utils.from_gm_timestamp(gm_timestamp))

	def _match_created_date(songs, period):
		return (
			song
			for song in songs
			if _dt_from_gm_timestamp(song['creationTimestamp']) in period
		)

	def _match_modified_date(songs, period):
		return (
			song
			for song in songs
			if _dt_from_gm_timestamp(song['lastModifiedTimestamp']) in period
		)

	if creation_dates:
		for period in creation_dates:
			matched_songs = _match_created_date(matched_songs, period)

	if modification_dates:
		for period in modification_dates:
			matched_songs = _match_modified_date(matched_songs, period)

	return list(matched_songs) 
开发者ID:thebigmunch,项目名称:google-music-scripts,代码行数:36,代码来源:core.py

示例4: _deserialize

# 需要导入模块: import pendulum [as 别名]
# 或者: from pendulum import from_timestamp [as 别名]
def _deserialize(cls, encoded_var: Any) -> Any:  # pylint: disable=too-many-return-statements
        """Helper function of depth first search for deserialization."""
        # JSON primitives (except for dict) are not encoded.
        if cls._is_primitive(encoded_var):
            return encoded_var
        elif isinstance(encoded_var, list):
            return [cls._deserialize(v) for v in encoded_var]

        if not isinstance(encoded_var, dict):
            raise ValueError(f"The encoded_var should be dict and is {type(encoded_var)}")
        var = encoded_var[Encoding.VAR]
        type_ = encoded_var[Encoding.TYPE]

        if type_ == DAT.DICT:
            return {k: cls._deserialize(v) for k, v in var.items()}
        elif type_ == DAT.DAG:
            return SerializedDAG.deserialize_dag(var)
        elif type_ == DAT.OP:
            return SerializedBaseOperator.deserialize_operator(var)
        elif type_ == DAT.DATETIME:
            return pendulum.from_timestamp(var)
        elif type_ == DAT.TIMEDELTA:
            return datetime.timedelta(seconds=var)
        elif type_ == DAT.TIMEZONE:
            return Timezone(var)
        elif type_ == DAT.RELATIVEDELTA:
            if 'weekday' in var:
                var['weekday'] = relativedelta.weekday(*var['weekday'])  # type: ignore
            return relativedelta.relativedelta(**var)
        elif type_ == DAT.SET:
            return {cls._deserialize(v) for v in var}
        elif type_ == DAT.TUPLE:
            return tuple([cls._deserialize(v) for v in var])
        else:
            raise TypeError('Invalid type {!s} in deserialization.'.format(type_)) 
开发者ID:apache,项目名称:airflow,代码行数:37,代码来源:serialized_objects.py

示例5: test_create_from_timestamp_returns_pendulum

# 需要导入模块: import pendulum [as 别名]
# 或者: from pendulum import from_timestamp [as 别名]
def test_create_from_timestamp_returns_pendulum():
    d = pendulum.from_timestamp(pendulum.datetime(1975, 5, 21, 22, 32, 5).timestamp())
    assert_datetime(d, 1975, 5, 21, 22, 32, 5)
    assert d.timezone_name == "UTC" 
开发者ID:sdispater,项目名称:pendulum,代码行数:6,代码来源:test_create_from_timestamp.py

示例6: test_create_from_timestamp_with_timezone_string

# 需要导入模块: import pendulum [as 别名]
# 或者: from pendulum import from_timestamp [as 别名]
def test_create_from_timestamp_with_timezone_string():
    d = pendulum.from_timestamp(0, "America/Toronto")
    assert d.timezone_name == "America/Toronto"
    assert_datetime(d, 1969, 12, 31, 19, 0, 0) 
开发者ID:sdispater,项目名称:pendulum,代码行数:6,代码来源:test_create_from_timestamp.py

示例7: test_create_from_timestamp_with_timezone

# 需要导入模块: import pendulum [as 别名]
# 或者: from pendulum import from_timestamp [as 别名]
def test_create_from_timestamp_with_timezone():
    d = pendulum.from_timestamp(0, timezone("America/Toronto"))
    assert d.timezone_name == "America/Toronto"
    assert_datetime(d, 1969, 12, 31, 19, 0, 0) 
开发者ID:sdispater,项目名称:pendulum,代码行数:6,代码来源:test_create_from_timestamp.py

示例8: encode_literal

# 需要导入模块: import pendulum [as 别名]
# 或者: from pendulum import from_timestamp [as 别名]
def encode_literal(value, prim, binary=False):
    if prim in ['int', 'nat']:
        core_type = 'int'
        value = str(value)
    elif prim == 'timestamp':
        core_type = 'string'
        if isinstance(value, int):
            value = pendulum.from_timestamp(value)
        if isinstance(value, pendulum.DateTime):
            value = value.strftime('%Y-%m-%dT%H:%M:%SZ')
    elif prim == 'mutez':
        core_type = 'int'
        if isinstance(value, Decimal):
            value = int(value * 10 ** 6)
        if isinstance(value, int):
            value = str(value)
    elif prim == 'bool':
        core_type = 'prim'
        value = 'True' if value else 'False'
    elif prim == 'bytes':
        core_type = 'bytes'
    else:
        core_type = 'string'
        value = str(value)

    return {core_type: value} 
开发者ID:murbard,项目名称:pytezos,代码行数:28,代码来源:schema.py

示例9: symbol_start_date

# 需要导入模块: import pendulum [as 别名]
# 或者: from pendulum import from_timestamp [as 别名]
def symbol_start_date(symbol):
    """
    Return the datetime when `symbol` first started trading.
    """
    with open('symbols_trading_start_days.json') as f:
        data = json.load(f)

    # objects are timestamps with milliseconds, divide
    # by 1000 to remove milliseconds
    return pendulum.from_timestamp(int(data[symbol])/1000) 
开发者ID:arthurk,项目名称:bitfinex-ohlc-import,代码行数:12,代码来源:main.py

示例10: get_latest_candle_date

# 需要导入模块: import pendulum [as 别名]
# 或者: from pendulum import from_timestamp [as 别名]
def get_latest_candle_date(self, symbol):
        """
        Get the time of the most recent candle for a symbol
        """
        r = self.con.execute('select max(time) from candles where symbol=?',
                             (symbol,))
        result = r.fetchone()[0]
        if result is None:
            return
        else:
            return pendulum.from_timestamp(int(result)/1000) 
开发者ID:arthurk,项目名称:bitfinex-ohlc-import,代码行数:13,代码来源:db.py

示例11: print_stats

# 需要导入模块: import pendulum [as 别名]
# 或者: from pendulum import from_timestamp [as 别名]
def print_stats(res: list, tzinfo, app: str):
    """
    Print the results of the parse
    :param res: Results of the parsing
    :param tzinfo: Timezone found in logs
    :param app: Name of application for the logs
    """
    mins_of_data = len(res)
    total_reqs = sum([x["num_uris"] for x in res])
    max_reqs = max([x["num_uris"] for x in res])
    min_reqs = min([x["num_uris"] for x in res])
    avg_reqs = total_reqs // mins_of_data

    first, last = res[0], res[-1]
    first, last = first["timestamp"], last["timestamp"]
    first = pendulum.from_timestamp(first, tzinfo)
    last = pendulum.from_timestamp(last, tzinfo)
    first, last = first.isoformat()[:16], last.isoformat()[:16]

    test_params = {
        "base_url": "http://$your_base_url",
        "rate": 100,
        "replay_start_time": first,
        "replay_end_time": last,
        "identifier": "oss",
    }

    dump = json.dumps(test_params, indent=2)
    click.echo(f"{mins_of_data} minutes of traffic data was uploaded to S3.")
    click.echo(f"Average requests/min: {avg_reqs}")
    click.echo(f"Max requests/min: {max_reqs}")
    click.echo(f"Min requests/min: {min_reqs}")
    click.echo(f"Timezone found in logs: {tzinfo.name}")
    click.echo(
        f"To load test with these results, use the below parameters for the orchestrator in serverless.yml"
    )
    click.echo(f"==========================================")
    click.echo(f"test_params: '{dump}'")
    click.echo(f"apps_to_test: '[\"{app}\"]'")
    click.echo(f"==========================================")

    """
    Output shoud look like:
    5 minutes of traffic data was uploaded to S3.
    Average requests/min: 6
    Max requests/min: 8
    Min requests/min: 2
    Timezone found in logs: +00:00
    To load test with these results, use the below parameters for the orchestrator in serverless.yml
    ==========================================
    test_params: {
      "base_url": "http://$your_base_url",
      "rate": 100,
      "replay_start_time": "2019-03-15T04:12",
      "replay_end_time": "2019-03-15T04:16",
      "identifier": "oss"
    }
    apps_to_test: ["app1"]
    ==========================================
    """ 
开发者ID:edmunds,项目名称:shadowreader,代码行数:62,代码来源:parser.py


注:本文中的pendulum.from_timestamp方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。