async def cmd_time(ctx): """Get PSS stardate, as well as the day and time in Melbourne, Australia. Gives the name of the Australian holiday, if it is a holiday in Australia.""" async with ctx.typing(): now = datetime.datetime.now() today = datetime.date(now.year, now.month, now.day) pss_start = datetime.date(year=2016, month=1, day=6) pss_stardate = (today - pss_start).days str_time = 'Today is Stardate {}\n'.format(pss_stardate) mel_tz = pytz.timezone('Australia/Melbourne') mel_time = now.replace(tzinfo=pytz.utc).astimezone(mel_tz) str_time += mel_time.strftime('It is %A, %H:%M in Melbourne') aus_holidays = holidays.Australia(years=now.year, prov='ACT') mel_time = datetime.date(mel_time.year, mel_time.month, mel_time.day) if mel_time in aus_holidays: str_time += '\nIt is also a holiday ({}) in Australia'.format( aus_holidays[mel_time]) first_day_of_next_month = datetime.datetime( now.year, now.month, 1) + relativedelta(months=1, days=0) td = first_day_of_next_month - now str_time += '\nTime until the beginning of next month: {}d {}h {}m'.format( td.days, td.seconds // 3600, (td.seconds // 60) % 60) await ctx.send(str_time)
def processed_traffic_data_set(dict): traffic_data = {} traffic_data.update(dict) time = dict['TIME'] Y = time[0:4] M = time[4:6] D = time[6:8] times = Y + '-' + M + '-' + D t = datetime.strptime(times, '%Y-%m-%d') traffic_data['WEEKDAY'] = t.isoweekday() au_holidays = holidays.Australia() flag = times in au_holidays traffic_data['HOLIDAY'] = flag weather_list = read_data_file(weather_data_file) for weather_dict in weather_list: Year = weather_dict['Year'] Month = weather_dict['Month'] Day = weather_dict['Day'] weather_times = Year + '-' + Month + '-' + Day weather_t = datetime.strptime(weather_times, '%Y-%m-%d') if weather_t == t: traffic_data['RAINFALL'] = weather_dict[ 'Rainfall amount (millimetres)'] temp_list = read_data_file(temp_data_file) for temp_dict in temp_list: Year = temp_dict['Year'] Month = temp_dict['Month'] Day = temp_dict['Day'] temp_times = Year + '-' + Month + '-' + Day temp_t = datetime.strptime(temp_times, '%Y-%m-%d') if temp_t == t: traffic_data['TEMPRETURE'] = temp_dict[ 'Maximum temperature (Degree C)'] with open('TrainingData/traffic_training_set.csv', 'a+', newline='') as traffic_training_set: w = csv.writer(traffic_training_set) w.writerow(traffic_data.values())
def getHolidays(): holidayDate = {} marketOpenHolidays = ['Columbus Day', 'Veterans Day'] irrelevantHolidays = ['Independence Day (Observed)'] for date in holidays.USA(years=getYear()).items(): if str(date[1]) not in marketOpenHolidays and str(date[1]) not in irrelevantHolidays: holidayDate[str(date[0])[5:]] = str(date[1]) for date in holidays.Australia(years=getYear()).items(): if str(date[1]) == "Good Friday": holidayDate[str(date[0])[5:]] = str(date[1]) return holidayDate
def preprocess(data): # Populate holiday data["holiday"] = data["Date"].apply( lambda x: int(x.date() in holidays.Australia())) data = data.rename(columns={"Date": "ds", "Footfall": "y"}) # Week day data["dayofweek"] = data['ds'].apply(lambda x: x.weekday()) week_day_dict = { "Mon": 0, "Tue": 1, "Wed": 2, "Thu": 3, "Fri": 4, "Sat": 5, "Sun": 6 } week_day_rev_dict = {val: key for key, val in week_day_dict.items()} for value in week_day_dict.keys(): data[f"{value}day"] = 0 for i in range(len(data)): data.loc[i, f"{week_day_rev_dict[data['dayofweek'][i]]}day"] = 1 # Weather data weather_type_dict = { "sn": 0, "sl": 1, "h": 2, "t": 3, "hr": 4, "lr": 5, "s": 6, "hc": 7, "lc": 8, "c": 9 } for value in weather_type_dict.keys(): data[f"weather_{value}"] = 0 data["min_temp"] = 0 data["max_temp"] = 0 data["humidity"] = 0 for i in range(len(data)): weather_data = get_weather_data(data["ds"][i]) data.loc[i, f"weather_{value}"] = 1 data.loc[i, "min_temp"] = weather_data["min_temp"] data.loc[i, "max_temp"] = weather_data["max_temp"] data.loc[i, "humidity"] = weather_data["humidity"] return data
def holiday_adjust(trade_date, delta): forward_date = trade_date + delta year = forward_date.year # if trade_date is holiday if (forward_date in hol.Australia() or forward_date in hol.US() or forward_date in hol.UK() or forward_date in hol.Japan()): forward_date = forward_date + dt.timedelta(days=1) holiday_adjust(forward_date, dt.timedelta()) # date is weekend elif forward_date.weekday() >= 5: forward_date = forward_date + dt.timedelta(days=1) holiday_adjust(forward_date, dt.timedelta()) return forward_date
async def time(ctx): """Get PSS stardate, as well as the day and time in Melbourne, Australia. Gives the name of the Australian holiday, if it is a holiday in Australia.""" now = datetime.datetime.now() today = datetime.date(now.year, now.month, now.day) pss_start = datetime.date(year=2016, month=1, day=6) pss_stardate = (today - pss_start).days str_time = 'Today is Stardate {}\n'.format(pss_stardate) mel_tz = pytz.timezone('Australia/Melbourne') mel_time = now.replace(tzinfo=pytz.utc).astimezone(mel_tz) str_time += mel_time.strftime('It is %A, %H:%M in Melbourne') aus_holidays = holidays.Australia(years=now.year, prov='ACT') mel_time = datetime.date(mel_time.year, mel_time.month, mel_time.day) if mel_time in aus_holidays: str_time += '\nIt is also a holiday ({}) in Australia'.format( aus_holidays[mel_time]) await ctx.send(str_time)
def get_prediction(days_plus_today, model_name): """ :param days_plus_today: :return: """ prediction_date = datetime.today() + timedelta(days=days_plus_today) data_dict = get_weather_data(prediction_date) week_day_dict = {"Mon":0, "Tue":1, "Wed":2, "Thu":3, "Fri":4, "Sat":5, "Sun":6} week_day_rev_dict = {val:key for key, val in week_day_dict.items()} data_dict["holiday"] = int(prediction_date in holidays.Australia()) dayofweek = prediction_date.weekday() for value in week_day_dict.keys(): data_dict[f"{value}day"] = 0 data_dict[f"{week_day_rev_dict[dayofweek]}day"] = 1 weather_type_dict = {"sn":0, "sl":1, "h":2, "t":3, "hr":4, "lr":5, "s":6, "hc":7, "lc":8, "c":9} for value in weather_type_dict.keys(): data_dict[f"weather_{value}"] = 0 data_dict[f"weather_{data_dict['weather']}"] = 1 del data_dict["weather"] df = pd.DataFrame(columns=['holiday', 'Monday', 'Tueday', 'Wedday', 'Thuday', 'Friday', 'Satday', 'Sunday', 'weather_sn', 'weather_sl', 'weather_h', 'weather_t', 'weather_hr', 'weather_lr', 'weather_s', 'weather_hc', 'weather_lc', 'weather_c', 'min_temp', 'max_temp', 'humidity']) for col in df.columns: df.loc[0, col] = data_dict[col] model = joblib.load(f'models/{model_name}') return (prediction_date, model.predict(df)[0])
### IMPORTS import holidays from datetime import date ### STATIC VARIABLES today = date.today() australia_holidays = holidays.Australia() austria_holidays = holidays.Austria() canada_holidays = holidays.Canada() colombia_holidays = holidays.Colombia() czech_holidays = holidays.Czech() denmark_holidays = holidays.Denmark() england_holidays = holidays.England() europeancentralbank_holidays = holidays.EuropeanCentralBank() germany_holidays = holidays.Germany() ireland_holidays = holidays.Ireland() mexico_holidays = holidays.Mexico() netherlands_holidays = holidays.Netherlands() newzealand_holidays = holidays.NewZealand() northernireland_holidays = holidays.NorthernIreland() norway_holidays = holidays.Norway() portugal_holidays = holidays.Portugal() portugalext_holidays = holidays.PortugalExt() scotland_holidays = holidays.Scotland() spain_holidays = holidays.Spain() unitedkingdom_holidays = holidays.UnitedKingdom()
def TellMarkets(self): # Grabs the Current time in two different formats, adjust in future today = datetime.date.today() currentTime = datetime.datetime.utcnow().replace(tzinfo=pytz.utc) # standard holidays for United States, Great Britian, Japan, and Australia us_holidays = holidays.US() britian_holidays = holidays.England() japan_holidays = holidays.Japan() australia_holidays = holidays.Australia() # Exchange Holiday is not included in the Standard Holiday's of Japan exchange_holiday = "{}-12-31".format(currentTime.year) japan_holidays.append({exchange_holiday: "Exchange Holiday"}) # Translator needed because Japanese holiday's are returned in Japanese translator = Translator() # The Holidays that close Markets In the Given Countries, Unsure if all of Japan's Holiday's Close the Currency Markets us_market_holidays = [ "New Year's Day", "Martin Luther King, Jr. Day", "Presidents Day or Washington's Birthday", "Good Friday", "Memorial Day", "Independence Day", "Labor Day", "Thanksgiving Day", "Christmas Day", ] britian_market_holidays = [ "New Year's Day", "Good Friday", "Easter Monday", "May Day", "Spring Bank Holiday", "Summer Bank Holiday", "Christmas Day", "Boxing Day", "Exchange Holiday", ] japan_market_holidays = [ "New Year's Day", "Adult Day", "Foundation Day", "Vernal Equinox Day", "Showa Day", "Constitution Memorial Day", "Greenery Day", "Children's Day", "Sea Day", "Respect for the Aged Day", "Autumnal Equinox Day", "Health and Sports Day", "Culture Day", "Labor Thanksgiving Day", "The birth of the Emperor", "Exchange Holiday", ] australian_market_holidays = [ "New Year's Day", "Australia Day", "Good Friday", "Easter Monday", "Anzac Day", "Queen's Birthday", "Christmas Day", "Boxing Day", ] us_has_holiday = False japan_has_holiday = False britian_has_holiday = False australia_has_holiday = False markets_closed = False if int(currentTime.weekday()) == 4 or 5 or 6: if currentTime.hour >= 21 and int(currentTime.weekday()) == 4: markets_closed = True if currentTime.hour < 21 and int(currentTime.weekday()) == 6: markets_closed = True if int(currentTime.weekday()) == 5: markets_closed = True if markets_closed == True: self.open_markets = 'None' return self if us_holidays.get(today) is not None: for i in us_market_holidays: if us_holidays.get(today) == i: self.returned_items['US-Holiday'] = us_holidays.get(today) us_has_holiday = True if britian_holidays.get(today) is not None: for i in britian_market_holidays: if britian_holidays.get(today) == i: self.returned_items[ 'British-Holiday'] = britian_holidays.get(today) britian_has_holiday = True if japan_holidays.get(today) is not None: holiday_in_english = translator.translate( japan_holidays.get(today)) for i in japan_market_holidays: if holiday_in_english.text == i: self.returned_items[ 'Japanese-Holiday'] = holiday_in_english japan_has_holiday = True if australia_holidays.get(today) is not None: for i in australian_market_holidays: if australia_holidays == i: self.returned_items[ 'Australian-Holiday'] = australia_holidays.get(today) australia_has_holiday = True # checks to see if we are in daylight saving time # need to make dynamic for what is being returned if bool(datetime.datetime.now(pytz.timezone("UTC")).dst()): if currentTime.hour >= 22 or currentTime.hour == 7: if not australia_has_holiday: self.open_markets.append('Australia') if currentTime.hour >= 23 or currentTime.hour <= 8: if not japan_has_holiday: self.open_markets.append('Japan') if currentTime.hour >= 7 and currentTime.hour <= 16: if not britian_has_holiday: self.open_markets.append('Britian') if currentTime.hour >= 13 and currentTime.hour <= 21: if not us_has_holiday: self.open_markets.append('US') else: if currentTime.hour >= 20 and currentTime.hour <= 5: if not australia_has_holiday: self.open_markets.append('Australia') if currentTime.hour >= 22 or currentTime.hour == 7: if not japan_has_holiday: self.open_markets.append('Japan') if currentTime.hour >= 7 and currentTime.hour <= 16: if not britian_has_holiday: self.open_markets.append('Britian') if currentTime.hour >= 12 and currentTime.hour <= 21: if not us_has_holiday: self.open_markets.append('US') return (self)