コード例 #1
0
def craft_and_send_email(t1, t2, config, volcano, d_Azimuth, velocity,
                         mx_pressure, filename):
    from pandas import Timestamp
    # create the subject line
    subject = '{} Airwave Detection'.format(volcano['volcano'])

    # create the test for the message you want to send
    message = '{} alarm:\n'.format(config.alarm_name)
    message = '{}{} detection!\n\n'.format(message, volcano['volcano'])
    message = '{}Start: {} (UTC)\nEnd: {} (UTC)\n\n'.format(
        message, t1.strftime('%Y-%m-%d %H:%M'), t2.strftime('%Y-%m-%d %H:%M'))
    t1_local = Timestamp(t1.datetime, tz='UTC')
    t2_local = Timestamp(t2.datetime, tz='UTC')
    t1_local = t1_local.tz_convert('US/Alaska')
    t2_local = t2_local.tz_convert('US/Alaska')
    message = '{}Start: {} ({})'.format(message,
                                        t1_local.strftime('%Y-%m-%d %H:%M'),
                                        t1_local.tzname())
    message = '{}\nEnd: {} ({})\n\n'.format(
        message, t2_local.strftime('%Y-%m-%d %H:%M'), t2_local.tzname())

    message = '{}d_Azimuth: {:+.1f} degrees\n'.format(message, d_Azimuth)
    message = '{}Velocity: {:.0f} m/s\n'.format(message, velocity * 1000)
    message = '{}Max Pressure: {:.1f} Pa'.format(message, mx_pressure)

    utils.send_alert(config.alarm_name, subject, message, filename)
    utils.post_mattermost(subject, message, config.alarm_name, filename)
    # delete the file you just sent
    if filename:
        remove(filename)
コード例 #2
0
ファイル: timestamp.py プロジェクト: changhiskhan/pandas
class TimestampOps(object):
    params = [None, 'US/Eastern', pytz.UTC,
              dateutil.tz.tzutc()]
    param_names = ['tz']

    def setup(self, tz):
        self.ts = Timestamp('2017-08-25 08:16:14', tz=tz)

    def time_replace_tz(self, tz):
        self.ts.replace(tzinfo=pytz.timezone('US/Eastern'))

    def time_replace_None(self, tz):
        self.ts.replace(tzinfo=None)

    def time_to_pydatetime(self, tz):
        self.ts.to_pydatetime()

    def time_normalize(self, tz):
        self.ts.normalize()

    def time_tz_convert(self, tz):
        if self.ts.tz is not None:
            self.ts.tz_convert(tz)

    def time_tz_localize(self, tz):
        if self.ts.tz is None:
            self.ts.tz_localize(tz)
コード例 #3
0
class TimestampOps:
    params = [None, "US/Eastern", pytz.UTC, dateutil.tz.tzutc()]
    param_names = ["tz"]

    def setup(self, tz):
        self.ts = Timestamp("2017-08-25 08:16:14", tz=tz)

    def time_replace_tz(self, tz):
        self.ts.replace(tzinfo=pytz.timezone("US/Eastern"))

    def time_replace_None(self, tz):
        self.ts.replace(tzinfo=None)

    def time_to_pydatetime(self, tz):
        self.ts.to_pydatetime()

    def time_normalize(self, tz):
        self.ts.normalize()

    def time_tz_convert(self, tz):
        if self.ts.tz is not None:
            self.ts.tz_convert(tz)

    def time_tz_localize(self, tz):
        if self.ts.tz is None:
            self.ts.tz_localize(tz)

    def time_to_julian_date(self, tz):
        self.ts.to_julian_date()

    def time_floor(self, tz):
        self.ts.floor("5T")

    def time_ceil(self, tz):
        self.ts.ceil("5T")
コード例 #4
0
ファイル: timestamp.py プロジェクト: PaulGureghian1/Pandas
class TimestampOps(object):
    params = [None, 'US/Eastern', pytz.UTC, dateutil.tz.tzutc()]
    param_names = ['tz']

    def setup(self, tz):
        self.ts = Timestamp('2017-08-25 08:16:14', tz=tz)

    def time_replace_tz(self, tz):
        self.ts.replace(tzinfo=pytz.timezone('US/Eastern'))

    def time_replace_None(self, tz):
        self.ts.replace(tzinfo=None)

    def time_to_pydatetime(self, tz):
        self.ts.to_pydatetime()

    def time_normalize(self, tz):
        self.ts.normalize()

    def time_tz_convert(self, tz):
        if self.ts.tz is not None:
            self.ts.tz_convert(tz)

    def time_tz_localize(self, tz):
        if self.ts.tz is None:
            self.ts.tz_localize(tz)

    def time_to_julian_date(self, tz):
        self.ts.to_julian_date()

    def time_floor(self, tz):
        self.ts.floor('5T')

    def time_ceil(self, tz):
        self.ts.ceil('5T')
コード例 #5
0
ファイル: test_timezones.py プロジェクト: zenquiorra/pandas
    def test_tz_convert_utc_with_system_utc(self):

        # from system utc to real utc
        ts = Timestamp("2001-01-05 11:56", tz=timezones.maybe_get_tz("dateutil/UTC"))
        # check that the time hasn't changed.
        assert ts == ts.tz_convert(dateutil.tz.tzutc())

        # from system utc to real utc
        ts = Timestamp("2001-01-05 11:56", tz=timezones.maybe_get_tz("dateutil/UTC"))
        # check that the time hasn't changed.
        assert ts == ts.tz_convert(dateutil.tz.tzutc())
コード例 #6
0
ファイル: test_timezones.py プロジェクト: zhezherun/pandas
    def test_tz_convert_utc_with_system_utc(self):
        from pandas._libs.tslibs.timezones import maybe_get_tz

        # from system utc to real utc
        ts = Timestamp('2001-01-05 11:56', tz=maybe_get_tz('dateutil/UTC'))
        # check that the time hasn't changed.
        assert ts == ts.tz_convert(dateutil.tz.tzutc())

        # from system utc to real utc
        ts = Timestamp('2001-01-05 11:56', tz=maybe_get_tz('dateutil/UTC'))
        # check that the time hasn't changed.
        assert ts == ts.tz_convert(dateutil.tz.tzutc())
コード例 #7
0
ファイル: test_timezones.py プロジェクト: dmjvictory/pandas
    def test_tz_convert_utc_with_system_utc(self):
        from pandas._libs.tslibs.timezones import maybe_get_tz

        # from system utc to real utc
        ts = Timestamp('2001-01-05 11:56', tz=maybe_get_tz('dateutil/UTC'))
        # check that the time hasn't changed.
        assert ts == ts.tz_convert(dateutil.tz.tzutc())

        # from system utc to real utc
        ts = Timestamp('2001-01-05 11:56', tz=maybe_get_tz('dateutil/UTC'))
        # check that the time hasn't changed.
        assert ts == ts.tz_convert(dateutil.tz.tzutc())
コード例 #8
0
    def test_utc_with_system_utc(self):
        if sys.platform == "win32":
            raise nose.SkipTest("Skipped on win32 due to dateutil bug.")

        from pandas.tslib import maybe_get_tz

        # from system utc to real utc
        ts = Timestamp("2001-01-05 11:56", tz=maybe_get_tz("dateutil/UTC"))
        # check that the time hasn't changed.
        self.assertEqual(ts, ts.tz_convert(dateutil.tz.tzutc()))

        # from system utc to real utc
        ts = Timestamp("2001-01-05 11:56", tz=maybe_get_tz("dateutil/UTC"))
        # check that the time hasn't changed.
        self.assertEqual(ts, ts.tz_convert(dateutil.tz.tzutc()))
コード例 #9
0
ファイル: test_timezones.py プロジェクト: ajcr/pandas
    def test_utc_with_system_utc(self):
        # Skipped on win32 due to dateutil bug
        tm._skip_if_windows()

        from pandas.tslib import maybe_get_tz

        # from system utc to real utc
        ts = Timestamp('2001-01-05 11:56', tz=maybe_get_tz('dateutil/UTC'))
        # check that the time hasn't changed.
        self.assertEqual(ts, ts.tz_convert(dateutil.tz.tzutc()))

        # from system utc to real utc
        ts = Timestamp('2001-01-05 11:56', tz=maybe_get_tz('dateutil/UTC'))
        # check that the time hasn't changed.
        self.assertEqual(ts, ts.tz_convert(dateutil.tz.tzutc()))
コード例 #10
0
    def test_utc_with_system_utc(self):
        if sys.platform == 'win32':
            raise nose.SkipTest('Skipped on win32 due to dateutil bug.')

        from pandas.tslib import maybe_get_tz

        # from system utc to real utc
        ts = Timestamp('2001-01-05 11:56', tz=maybe_get_tz('dateutil/UTC'))
        # check that the time hasn't changed.
        self.assertEqual(ts, ts.tz_convert(dateutil.tz.tzutc()))

        # from system utc to real utc
        ts = Timestamp('2001-01-05 11:56', tz=maybe_get_tz('dateutil/UTC'))
        # check that the time hasn't changed.
        self.assertEqual(ts, ts.tz_convert(dateutil.tz.tzutc()))
コード例 #11
0
ファイル: test_timestamp.py プロジェクト: hvardhan20/pandas
 def test_tz_conversion_freq(self, tz_naive_fixture):
     # GH25241
     with tm.assert_produces_warning(FutureWarning, match="freq"):
         t1 = Timestamp("2019-01-01 10:00", freq="H")
         assert t1.tz_localize(tz=tz_naive_fixture).freq == t1.freq
     with tm.assert_produces_warning(FutureWarning, match="freq"):
         t2 = Timestamp("2019-01-02 12:00", tz="UTC", freq="T")
         assert t2.tz_convert(tz="UTC").freq == t2.freq
コード例 #12
0
ファイル: test_timezones.py プロジェクト: dmjvictory/pandas
 def test_astimezone(self, tzstr):
     # astimezone is an alias for tz_convert, so keep it with
     # the tz_convert tests
     utcdate = Timestamp('3/11/2012 22:00', tz='UTC')
     expected = utcdate.tz_convert(tzstr)
     result = utcdate.astimezone(tzstr)
     assert expected == result
     assert isinstance(result, Timestamp)
コード例 #13
0
ファイル: test_timezones.py プロジェクト: dmjvictory/pandas
    def test_tz_convert_roundtrip(self, stamp, tz):
        ts = Timestamp(stamp, tz='UTC')
        converted = ts.tz_convert(tz)

        reset = converted.tz_convert(None)
        assert reset == Timestamp(stamp)
        assert reset.tzinfo is None
        assert reset == converted.tz_convert('UTC').tz_localize(None)
コード例 #14
0
ファイル: test_timezones.py プロジェクト: Aathi410/Pro123
 def test_astimezone(self, tzstr):
     # astimezone is an alias for tz_convert, so keep it with
     # the tz_convert tests
     utcdate = Timestamp("3/11/2012 22:00", tz="UTC")
     expected = utcdate.tz_convert(tzstr)
     result = utcdate.astimezone(tzstr)
     assert expected == result
     assert isinstance(result, Timestamp)
コード例 #15
0
    def test_tz_convert_roundtrip(self, stamp, tz):
        ts = Timestamp(stamp, tz='UTC')
        converted = ts.tz_convert(tz)

        reset = converted.tz_convert(None)
        assert reset == Timestamp(stamp)
        assert reset.tzinfo is None
        assert reset == converted.tz_convert('UTC').tz_localize(None)
コード例 #16
0
 def __init__(self, event_type: EventType, sub_type,
              visible_time: Timestamp, data: object):
     if not visible_time.tz:
         raise RuntimeError("事件的可见时间必须有时区")
     # 统一使用中国标准时间
     visible_time = visible_time.tz_convert("Asia/Shanghai")
     self.visible_time = visible_time
     self.event_type = event_type
     self.sub_type = sub_type
     self.data = data
コード例 #17
0
ファイル: test_timezones.py プロジェクト: Aathi410/Pro123
    def test_tz_convert_roundtrip(self, stamp, tz_aware_fixture):
        tz = tz_aware_fixture

        ts = Timestamp(stamp, tz="UTC")
        converted = ts.tz_convert(tz)

        reset = converted.tz_convert(None)
        assert reset == Timestamp(stamp)
        assert reset.tzinfo is None
        assert reset == converted.tz_convert("UTC").tz_localize(None)
コード例 #18
0
def craft_and_send_email(t1, t2, stations, rms, lvlv, alarm_name, filename):
    from pandas import Timestamp

    # create the subject line
    subject = '--- {} ---'.format(alarm_name)

    # create the text for the message you want to send
    message = 'Start: {} (UTC)\nEnd: {} (UTC)\n\n'.format(
        t1.strftime('%Y-%m-%d %H:%M'), t2.strftime('%Y-%m-%d %H:%M'))
    t1_local = Timestamp(t1.datetime, tz='UTC')
    t2_local = Timestamp(t2.datetime, tz='UTC')
    t1_local = t1_local.tz_convert('US/Alaska')
    t2_local = t2_local.tz_convert('US/Alaska')
    message = '{}Start: {} ({})'.format(message,
                                        t1_local.strftime('%Y-%m-%d %H:%M'),
                                        t1_local.tzname())
    message = '{}\nEnd: {} ({})\n\n'.format(
        message, t2_local.strftime('%Y-%m-%d %H:%M'), t2_local.tzname())

    a = np.array([''] * len(rms[:-1]))
    a[np.where(rms > lvlv)] = '*'
    sta_message = ''.join(
        '{}{}: {:.0f}/{}\n'.format(sta, a[i], rms[i], lvlv[i])
        for i, sta in enumerate(stations[:-1]))
    sta_message = ''.join([
        sta_message, '\nArrestor: {} {:.0f}/{}'.format(stations[-1], rms[-1],
                                                       lvlv[-1])
    ])
    message = ''.join([message, sta_message])

    utils.send_alert(alarm_name, subject, message, filename)
    # utils.post_mattermost(subject,message,filename)
    utils.post_mattermost(subject, message, alarm_name, filename)
    # delete the file you just sent
    if filename:
        remove(filename)
コード例 #19
0
 def history_data(self, codes: List[str], start: Timestamp = None,
                  end: Timestamp = Timestamp.now(tz='Asia/Shanghai'),
                  count=100) -> DataFrame:
     """
     获取时序数据,优先按照开始和结束时间查询。 其次按照结束时间和数量进行查询
     这里的所有时间都是针对visible_time
     :param count:
     :param codes:
     :param start:
     :param end:
     :return: DataFrame, 索引为visible_time + code
     """
     if len(codes) <= 0:
         raise RuntimeError("code不能为空")
     if start:
         start = start.tz_convert("Asia/Shanghai")
     end = end.tz_convert("Asia/Shanghai")
     pattern = '%Y-%m-%d %H:%M:%S'
     if start and end:
         params = {
             "providerName": self.data_provider_name,
             "tsTypeName": self.ts_type_name,
             "codes": ",".join(codes),
             "startTime": datetime.strftime(start, pattern),
             "endTime": datetime.strftime(end, pattern)
         }
     else:
         params = {
             "providerName": self.data_provider_name,
             "tsTypeName": self.ts_type_name,
             "codes": ",".join(codes),
             "endTime": datetime.strftime(end, pattern),
             "count": count
         }
     url = "http://localhost:32900/queryData"
     return self._get_ts_data(url, params)
コード例 #20
0
ファイル: test_unary_ops.py プロジェクト: bashtage/pandas
    def test_timestamp(self):
        # GH#17329
        # tz-naive --> treat it as if it were UTC for purposes of timestamp()
        ts = Timestamp.now()
        uts = ts.replace(tzinfo=utc)
        assert ts.timestamp() == uts.timestamp()

        tsc = Timestamp('2014-10-11 11:00:01.12345678', tz='US/Central')
        utsc = tsc.tz_convert('UTC')

        # utsc is a different representation of the same time
        assert tsc.timestamp() == utsc.timestamp()

        # datetime.timestamp() converts in the local timezone
        with tm.set_timezone('UTC'):
            # should agree with datetime.timestamp method
            dt = ts.to_pydatetime()
            assert dt.timestamp() == ts.timestamp()
コード例 #21
0
ファイル: test_unary_ops.py プロジェクト: 09acp/Dash-Examples
    def test_timestamp(self):
        # GH#17329
        # tz-naive --> treat it as if it were UTC for purposes of timestamp()
        ts = Timestamp.now()
        uts = ts.replace(tzinfo=utc)
        assert ts.timestamp() == uts.timestamp()

        tsc = Timestamp("2014-10-11 11:00:01.12345678", tz="US/Central")
        utsc = tsc.tz_convert("UTC")

        # utsc is a different representation of the same time
        assert tsc.timestamp() == utsc.timestamp()

        # datetime.timestamp() converts in the local timezone
        with tm.set_timezone("UTC"):
            # should agree with datetime.timestamp method
            dt = ts.to_pydatetime()
            assert dt.timestamp() == ts.timestamp()
コード例 #22
0
def timestamp_tzaware(timestamp):
    """ Returns the pandas Timestamp passed as a timezone (UTC) aware
        Timestamp.

        Args:
            timestamp (pandas.Timestamp): Timezone naive Timestamp
        Returns:
            pandas.Timestamp: Timezone aware
    """
    from pandas import Timestamp

    if not isinstance(timestamp, Timestamp):
        timestamp = Timestamp(timestamp)

    if timestamp.tzinfo is None:
        return timestamp.tz_localize(tz="UTC")
    else:
        return timestamp.tz_convert(tz="UTC")
コード例 #23
0
def create_aligned_timestamp(time):
    """ Align the passed datetime / Timestamp object to the minute
        interval for use in dateranges and overlap checks.

        Args:   
            time (str, pandas.Timestamp)
        Returns:
            pandas.Timestamp: Timestamp aligned to minute 
            with UTC timezone
    """
    from pandas import Timedelta, Timestamp

    if not isinstance(time, Timestamp):
        time = Timestamp(ts_input=time)

    if time.tzinfo is None:
        t = time.tz_localize(tz="UTC")
    else:
        t = time.tz_convert(tz="UTC")

    t -= Timedelta(f"{t.second} s")

    return t
コード例 #24
0
 def test_tz_conversion_freq(self, tz_naive_fixture):
     # GH25241
     t1 = Timestamp("2019-01-01 10:00", freq="H")
     assert t1.tz_localize(tz=tz_naive_fixture).freq == t1.freq
     t2 = Timestamp("2019-01-02 12:00", tz="UTC", freq="T")
     assert t2.tz_convert(tz="UTC").freq == t2.freq
コード例 #25
0
 def test_tz_conversion_freq(self, tz_naive_fixture):
     # GH25241
     t1 = Timestamp('2019-01-01 10:00', freq='H')
     assert t1.tz_localize(tz=tz_naive_fixture).freq == t1.freq
     t2 = Timestamp('2019-01-02 12:00', tz='UTC', freq='T')
     assert t2.tz_convert(tz='UTC').freq == t2.freq
コード例 #26
0
ファイル: test_timestamp.py プロジェクト: clham/pandas
 def test_tz_conversion_freq(self, tz_naive_fixture):
     # GH25241
     t1 = Timestamp('2019-01-01 10:00', freq='H')
     assert t1.tz_localize(tz=tz_naive_fixture).freq == t1.freq
     t2 = Timestamp('2019-01-02 12:00', tz='UTC', freq='T')
     assert t2.tz_convert(tz='UTC').freq == t2.freq
コード例 #27
0
def format_timestamp(ts: pd.Timestamp, fmt="%m-%d %H:%M:%S", tz="Asia/Jerusalem"):
    return pd.to_datetime(ts.tz_convert(tz)).strftime(fmt)
コード例 #28
0
 def test_astimezone(self):
     utc = Timestamp("3/11/2012 22:00", tz="UTC")
     expected = utc.tz_convert(self.tzstr("US/Eastern"))
     result = utc.astimezone(self.tzstr("US/Eastern"))
     self.assertEqual(expected, result)
     tm.assert_isinstance(result, Timestamp)
コード例 #29
0
 def __init__(self, code: str, start: Timestamp, end: Timestamp):
     self.code = code
     self.start = start.tz_convert("Asia/Shanghai")
     self.end = end.tz_convert("Asia/Shanghai")
コード例 #30
0
ファイル: test_timezones.py プロジェクト: techtommey/pandas
 def test_astimezone(self):
     utc = Timestamp('3/11/2012 22:00', tz='UTC')
     expected = utc.tz_convert('US/Eastern')
     result = utc.astimezone('US/Eastern')
     self.assertEquals(expected, result)
     self.assert_(isinstance(result, Timestamp))
コード例 #31
0
ファイル: cache.py プロジェクト: equinor/tagreader-python
def timestamp_to_epoch(timestamp: pd.Timestamp) -> int:
    origin = pd.Timestamp("1970-01-01")
    if timestamp.tzinfo is not None:
        timestamp = timestamp.tz_convert("UTC").tz_localize(None)
    return (timestamp - origin) // pd.Timedelta("1s")  # type: ignore
コード例 #32
0
ファイル: test_timezones.py プロジェクト: ajcr/pandas
 def test_astimezone(self):
     utc = Timestamp('3/11/2012 22:00', tz='UTC')
     expected = utc.tz_convert(self.tzstr('US/Eastern'))
     result = utc.astimezone(self.tzstr('US/Eastern'))
     self.assertEqual(expected, result)
     tm.assertIsInstance(result, Timestamp)
コード例 #33
0
 def test_astimezone(self):
     utc = Timestamp('3/11/2012 22:00', tz='UTC')
     expected = utc.tz_convert('US/Eastern')
     result = utc.astimezone('US/Eastern')
     self.assertEquals(expected, result)
     self.assert_(isinstance(result, Timestamp))
コード例 #34
0
ファイル: time_series_api.py プロジェクト: burk/python-sdk
 def _convert_utc(timestamp: pd.Timestamp) -> pd.Timestamp:
     """Return the given timestamp with the UTC time zone."""
     if timestamp.tz:
         return timestamp.tz_convert(tz.tzutc())
     return timestamp.tz_localize(tz.tzutc())