示例#1
0
    def weather_update(self):
        three_day_flights = self.schedule[
            self.schedule['Arrival datatime'] -
            Timestamp.today() < Timedelta('3 days')]
        three_day_flights = three_day_flights[
            three_day_flights['Departure datatime'] -
            Timestamp.today() > Timedelta('3:00:00')].index
        for i in three_day_flights:
            #             print('%2d from %d, event_list: %d' %(i, len(three_day_flights), len(self.event_list)), end='\r')
            flight = self.schedule.loc[i]

            for stuff in ['Departure ', 'Arrival ']:

                forecast = self.forecasts[flight[stuff + 'port']]
                weather = forecast.get_weather_at(flight[stuff + 'datatime'])

                snow = weather.get_snow().get('3h', 0)
                if snow > 3:  # Attention! Magic numbers!
                    e = self.create_event(flight[stuff + 'port'],
                                          flight[stuff + 'datatime'], 'snow',
                                          snow)
                    print('new snow event ', snow, ' ',
                          len(e.flights_affected), ' ', e.datetime_happened)

                wind = weather.get_wind().get('speed', 0)
                if wind > 7:  # Attention! Magic numbers!
                    e = self.create_event(flight[stuff + 'port'],
                                          flight[stuff + 'datatime'],
                                          'strong wind', wind)
                    print('new wind event ', wind, ' ',
                          len(e.flights_affected), ' ', e.datetime_happened)
示例#2
0
def test_datetimeindex():
    idx1 = pd.DatetimeIndex(
        ["2013-04-01 9:00", "2013-04-02 9:00", "2013-04-03 9:00"] * 2,
        tz="Asia/Tokyo")
    idx2 = date_range("2010/01/01", periods=6, freq="M", tz="US/Eastern")
    idx = MultiIndex.from_arrays([idx1, idx2])

    expected1 = pd.DatetimeIndex(
        ["2013-04-01 9:00", "2013-04-02 9:00", "2013-04-03 9:00"],
        tz="Asia/Tokyo")

    tm.assert_index_equal(idx.levels[0], expected1)
    tm.assert_index_equal(idx.levels[1], idx2)

    # from datetime combos
    # GH 7888
    date1 = np.datetime64("today")
    date2 = datetime.today()
    date3 = Timestamp.today()

    for d1, d2 in itertools.product([date1, date2, date3],
                                    [date1, date2, date3]):
        index = MultiIndex.from_product([[d1], [d2]])
        assert isinstance(index.levels[0], pd.DatetimeIndex)
        assert isinstance(index.levels[1], pd.DatetimeIndex)

    # but NOT date objects, matching Index behavior
    date4 = date.today()
    index = MultiIndex.from_product([[date4], [date2]])
    assert not isinstance(index.levels[0], pd.DatetimeIndex)
    assert isinstance(index.levels[1], pd.DatetimeIndex)
示例#3
0
 def create_event(self, port, time, type, value):
     e = Event(
         Mention(airport_id=port,
                 type='snow',
                 datetime_reported=Timestamp.today(),
                 datetime_happened=time,
                 raw_description=value))
     self.add_event(e, time_area='01:00:00')
     return e
示例#4
0
    def actualizer(self, sch, after_date=None):
        if after_date is None:
            after_date = Timestamp.today()

        return sch[sch['Arrival datatime'] > after_date]