def workingDate(start, end): cal = UnitedKingdom() res = [] delta = end - start for i in range(delta.days + 1): day = start + timedelta(days=i) if cal.is_working_day(day) or day.weekday() < 5: res.append(day) else: pass return res
def func(): _, _, uk_dale = load_datasets() # uk_dale_mains = uk_dale.buildings[1].elec.mains().power_series_all_data(sample_period=sample_period) uk_dale_mains = next(uk_dale.buildings[1].elec.mains().power_series( ac_type='active', sample_period=sample_period)) uk_dale_app = next(uk_dale.buildings[1].elec.mains().power_series( ac_type='apparent', sample_period=sample_period)) uk_dale_q = pd.Series(np.sqrt(uk_dale_app.values**2 - uk_dale_mains.values**2), index=uk_dale_mains.index) uk_dale_lighting = next( uk_dale.buildings[1].elec.select_using_appliances( category='lighting').load( sample_period=sample_period))[('power', 'active')] # uk_dale_heating = next(uk_dale.buildings[1].elec.select_using_appliances(category='heating').load( # sample_period=sample_period))[('power', 'active')] uk_dale_df = pd.DataFrame() names = ('lighting', 'active power', 'reactive power') for i, this_df in enumerate( (uk_dale_lighting, uk_dale_mains, uk_dale_q)): this_df = this_df[~this_df.index.duplicated(keep='first')] this_df = pd.DataFrame(data=this_df.values, index=this_df.index, columns=[names[i]]) if i == 0: uk_dale_df = this_df else: uk_dale_df = pd.merge(uk_dale_df, this_df, left_index=True, right_index=True, how='outer') uk_dale_df = _add_dst_holiday_info_etc(uk_dale_df, UnitedKingdom(), 0) weather = load_ampds2_or_ukdale_weather(name='uk dale') weather = weather[['temperature', 'radiation_surface']] weather.rename({'radiation_surface': 'solar'}, axis=1, inplace=True) full_data = pd.merge(uk_dale_df, weather, how="left", left_index=True, right_index=True) full_data = full_data.interpolate('time') full_data.dtype = float return full_data
def get_cal_from_country(bmk_country): """ Function returning a calendar based on the 'benchmark_country' of the csv file # Python package to manage holidays per country # >> See : https://github.com/peopledoc/workalendar from 'benchmark_country' column (to be parsed) in the Derivation Script Warning : Tuples may appear like [USA, Japon] or [USA, China] instead of China [Germany, China] instead of Russia [USA, China] instead of Moyen-Orient [USA, China] instead of Brasil Currently missing : China, Russia @TODO : ADD HONG-KONG !!! (for 'HSI_Index') NOTE : 5 avril 2018 : Ching Ming Festival (jour férié Hong-Kong !) :param bmk_country: benchmark country (type: string) :return: - cal: calendar related to the country (type: workalendar type ?) """ cal = [] if ',' in bmk_country: # '[A, B]' => ['A', 'B'] print "[WARNING] Tuple for the 'benchmark_country : {}, returning the first one..".format( bmk_country) bmk_country = bmk_country.replace('[', '').replace(']', '').split(',') bmk_country = bmk_country[0] # TO BE DEFINED ! if bmk_country == 'USA': cal = UnitedStates() elif bmk_country == 'Germany': cal = Germany() elif bmk_country == 'Japan': cal = Japan() elif bmk_country == 'France': cal = France() elif bmk_country == 'UK': cal = UnitedKingdom() elif bmk_country == 'Grèce': cal = Greece() elif bmk_country == 'Italie': cal = Italy() elif bmk_country == 'Espagne': cal = Spain() elif bmk_country == 'Brasil': cal = Brazil() return cal
""" Provides data on days off work (based on public holidays + manual inputs) """ from functools import lru_cache from datetime import date, datetime, timedelta import re from typing import Tuple, Iterator, List, Union from my.config.holidays_data import HOLIDAYS_DATA # pip3 install workalendar from workalendar.europe import UnitedKingdom # type: ignore cal = UnitedKingdom() # TODO FIXME specify in config # TODO that should depend on country/'location' of residence I suppose? Dateish = Union[datetime, date, str] def as_date(dd: Dateish) -> date: if isinstance(dd, datetime): return dd.date() elif isinstance(dd, date): return dd else: return as_date(datetime.strptime(dd, '%Y%m%d')) @lru_cache(1) def get_days_off_work() -> List[date]: return list(iter_days_off_work())
from workalendar.europe import France country_hols['France'] = France() from workalendar.europe import Belgium country_hols['Belgium'] = Belgium() from workalendar.europe import Spain country_hols['Spain'] = Spain() from workalendar.europe import Germany country_hols['Germany'] = Germany() from workalendar.europe import Austria country_hols['Austria'] = Austria() from workalendar.europe import Italy country_hols['Italy'] = Italy() from workalendar.europe import Portugal country_hols['Portugal'] = Portugal() from workalendar.europe import UnitedKingdom country_hols['UnitedKingdom'] = UnitedKingdom() from workalendar.europe import Ireland country_hols['Ireland'] = Ireland() from workalendar.europe import Netherlands country_hols['Netherlands'] = Netherlands() from workalendar.asia import China country_hols['China'] = China() from workalendar.asia import Japan country_hols['Japan'] = Japan() from workalendar.asia import SouthKorea country_hols['Korea'] = SouthKorea() # from workalendar.asia import India # country_hols['India'] = India() # from workalendar.asia import Thailand # country_hols['Thailand'] = Thailand()
from workalendar.europe import UnitedKingdom from workalendar.asia import HongKong cal = UnitedKingdom() f = open('holidays.csv', 'w+') for year in range(2016, 2019): result = dict(cal.holidays(year)) for date_str in result: print(date_str) f.write('UK,') f.write(str(date_str) + '\n') cal = HongKong() for year in range(2016, 2019): result = dict(cal.holidays(year)) for date_str in result: print(date_str) f.write('HK,') f.write(str(date_str) + '\n') f.close() ##HongKong()
# -*- coding: UTF-8 -*- # File name: ukWorkingDays # Created by JKChang # 29/07/2020, 11:20 # Tag: # Description: from datetime import date, timedelta, datetime from workalendar.europe import UnitedKingdom cal = UnitedKingdom() print(cal.holidays(2020)) def workingDate(start, end): cal = UnitedKingdom() res = [] delta = end - start for i in range(delta.days + 1): day = start + timedelta(days=i) if cal.is_working_day(day) or day.weekday() < 5: res.append(day) else: pass return res start = datetime.today() end = datetime(2020, 12, 23) r = workingDate(start, end) for d in r:
""" Public holidays (automatic) and days off work (manual inputs) """ from functools import lru_cache from datetime import date, datetime, timedelta import re from typing import Tuple, Iterator, List, Union from my.config.holidays_data import HOLIDAYS_DATA # pip3 install workalendar from workalendar.europe import UnitedKingdom # type: ignore cal = UnitedKingdom() # TODO # TODO that should depend on country/'location' of residence I suppose? Dateish = Union[datetime, date, str] def as_date(dd: Dateish) -> date: if isinstance(dd, datetime): return dd.date() elif isinstance(dd, date): return dd else: return as_date(datetime.strptime(dd, '%Y%m%d'))