Beispiel #1
0
is_status_changed = True

initial_time = datetime.datetime.now()
sig_switch_timeout = [datetime.datetime.now()]*len(config.BUTTONS)

temp = temp_avg_accu = temp_avg_sum = 0.0
temp_avg_counter = 0
log_temp_avg_accu = log_temp_avg_sum = 0.0
log_temp_avg_counter = 0

try:
    if config.HOLIDAYS_COUNTRY:
        holiday_list = holidays.CountryHoliday(config.HOLIDAYS_COUNTRY)
    else:
        print("WARN: config.HOLIDAYS_COUNTRY missing, defaulting to IT")
        holiday_list = holidays.IT()
except Exception:
    print("WARN: config.HOLIDAYS_COUNTRY missing or wrong, defaulting to IT")
    holiday_list = holidays.IT()

task_every_secs = {
    'hompi_slaves_refresh': 31.0,
    'update_lcd_content': 21.0,
    'get_temp': 4.0,
    'get_meteo': 300.0,  # 5 mins
    'get_aphorism': 241.0,  # 4 mins
    'refresh': 304.0,  # 5 mins (multiple of get_temp)
    'update_temp': 40.0,
    'update_io': 10.0,
}
Beispiel #2
0
    "US": holidays.US(),
    "NZ": holidays.NZ(),
    "AU": holidays.AU(),
    "DE": holidays.DE(),
    "AT": holidays.AT(),
    "DK": holidays.DK(),
    "UK": holidays.UK(),
    "IE": holidays.IE(),
    "ES": holidays.ES(),
    "CZ": holidays.CZ(),
    "SK": holidays.SK(),
    "PL": holidays.PL(),
    "PT": holidays.PT(),
    "NL": holidays.NL(),
    "NO": holidays.NO(),
    "IT": holidays.IT(),
    "SE": holidays.SE(),
    "JP": holidays.JP(),
    "BE": holidays.BE(),
    "ZA": holidays.ZA(),
    "SI": holidays.SI(),
    "FI": holidays.FI(),
    "CH": holidays.CH()
}


def get_holiday():
    country = get_country_code()
    if not country in country_holidays.keys():
        return None
    return country_holidays[country].get(datetime.now().date())
 def judge_local_holiday(self, df):
     country = df['geoNetwork_country']
     date = df['visitId'].apply(lambda x: x.date())
     judge_holiday = \
         np.where(country.isin(
                 ['United States','India','Canada','Germany',
                  'Japan','France','Mexico','Australia',
                  'Spain','Netherlands','Italy','Ireland',
                  'Sweden','Argentina','Colombia','Belgium',
                  'Switzerland','Czechia','Colombia','Belgium',
                  'New Zealand','South Africa','South Africa']),\
         np.where((country=='United States')&
                  (date.isin(holidays.US())),1,
                  np.where((country=='India')&
                           (date.isin(holidays.India())),1,
                           np.where((country=='Canada')&
                                    (date.isin(holidays.CA())),1,
                                    np.where((country=='Germany')&
                                             (date.isin(holidays.DE())),1,\
         np.where((country=='Japan')&
                  (date.isin(holidays.JP())),1,
                  np.where((country=='France')&
                           (date.isin(holidays.FRA())),1,
                           np.where((country=='Mexico')&
                                    (date.isin(holidays.MX())),1,
                                    np.where((country=='Australia')&
                                             (date.isin(holidays.AU())),1,\
         np.where((country=='Spain')&
                  (date.isin(holidays.ES())),1,
                  np.where((country=='Netherlands')&
                           (date.isin(holidays.NL())),1,
                           np.where((country=='Italy')&
                                    (date.isin(holidays.IT())),1,
                                    np.where((country=='Ireland')&
                                             (date.isin(holidays.IE())),1,\
         np.where((country=='Sweden')&
                  (date.isin(holidays.SE())),1,
                  np.where((country=='Argentina')&
                           (date.isin(holidays.AR())),1,
                           np.where((country=='Colombia')&
                                    (date.isin(holidays.CO())),1,
                                    np.where((country=='Belgium')&
                                             (date.isin(holidays.BE())),1,\
         np.where((country=='Switzerland')&
                  (date.isin(holidays.CH())),1,
                  np.where((country=='Czechia')&
                           (date.isin(holidays.CZ())),1,
                           np.where((country=='Denmark')&
                                    (date.isin(holidays.DK())),1,
                                    np.where((country=='Austria')&
                                             (date.isin(holidays.AT())),1,\
         np.where((country=='Hungary')&
                  (date.isin(holidays.HU())),1,
                  np.where((country=='Portugal')&
                           (date.isin(holidays.PT())),1,
                           np.where((country=='Norway')&
                                    (date.isin(holidays.NO())),1,
                                    np.where((country=='Portugal')&
                                             (date.isin(holidays.PT())),1,\
         np.where((country=='New Zealand')&
                  (date.isin(holidays.NZ())),1,
                  np.where((country=='South Africa')&
                           (date.isin(holidays.ZA())),1,
                           np.where((country=='South Africa')&
                                    (date.isin(holidays.ZA())),1,\
         0))))))))))))))))))))))))))),np.nan).astype(int)
     return judge_holiday
Beispiel #4
0
                        }
                    df['cap']=cap
                    df['floor']=floor
            
            
        with st.beta_expander('Holidays'):
            #st.markdown("""[Available countries list](https://github.com/dr-prodigy/python-holidays) """)
            
            countries = ['Country name','Italy','Spain','United States','France','Germany','Ukraine']
            
            with st.beta_container():
                years=[2021]
                selected_country = st.selectbox(label="Select country",options=countries)

                if selected_country == 'Italy':
                    for date, name in sorted(holidays.IT(years=years).items()):
                        st.write(date,name) 
                            
                if selected_country == 'Spain':
                    
                    for date, name in sorted(holidays.ES(years=years).items()):
                            st.write(date,name)                      

                if selected_country == 'United States':
                    
                    for date, name in sorted(holidays.US(years=years).items()):
                            st.write(date,name)
                            
                if selected_country == 'France':
                    
                    for date, name in sorted(holidays.FR(years=years).items()):
Beispiel #5
0
def comfort_temp(year, u_type, zone, heating_period):

    start = '%s-12-16 23:00:00' % (year - 1)
    stop = '%s-12-31 23:00:00' % year
    time_index = pd.date_range(start, stop, freq='H')
    time_and_days = time_index.to_series().dt.weekday

    weekdays = [0, 1, 2, 3, 4]
    weekends = [5, 6, 7]
    festivities = holidays.IT()
    for t in time_and_days.index:
        if t in festivities:
            time_and_days.loc[t] = 7

    last_sunday_march = time_index[time_index.month == 3][time_index[
        time_index.month == 3].weekday == 6][-1].day
    last_sunday_october = time_index[time_index.month == 10][time_index[
        time_index.month == 10].weekday == 6][-1].day
    dst = pd.date_range('%s-03-%s 01:00:00' % (year, last_sunday_march),
                        '%s-10-%s 01:00:00' % (year, last_sunday_october))

    k = random.randint(0, 1)
    user_cmf_dict = {
        'u1': [range(-k + 6, -k + 21 + 1),
               range(0, 0)],
        'u2': [range(-k + 6, -k + 8 + 1),
               range(-k + 15, -k + 21 + 1)],
        'u3': [range(-k + 6, -k + 8 + 1),
               range(-k + 17, -k + 21 + 1)]
    }
    set_point = pd.DataFrame(
        (time_and_days, pd.Series(0,
                                  index=time_and_days.index))).T.astype(float)
    set_point.columns = ['daytype', 'T_cmf']

    heat_T_on = random.randint(200, 200) / 10
    heat_T_off = random.randint(160, 160) / 10
    cool_T_on = random.randint(260, 260) / 10
    cool_T_off = 999
    original_u_type = copy.deepcopy(u_type)

    for t in time_and_days.index:
        if t in dst:
            k = k + 1
        else:
            pass

        if time_and_days.loc[t] in weekends:
            u_type = 'u1'
        else:
            pass

        if heating_period.loc[t][zone] == 1 and (
                t.hour in user_cmf_dict[u_type][0]
                or t.hour in user_cmf_dict[u_type][1]):
            set_point.loc[t]['T_cmf'] = heat_T_on
        elif heating_period.loc[t][zone] == 1 and (
                t.hour not in user_cmf_dict[u_type][0]
                and t.hour not in user_cmf_dict[u_type][1]):
            set_point.loc[t]['T_cmf'] = heat_T_off
        elif heating_period.loc[t][zone] == 0 and (
                t.hour in user_cmf_dict[u_type][0]
                or t.hour in user_cmf_dict[u_type][1]):
            set_point.loc[t]['T_cmf'] = cool_T_on
        elif heating_period.loc[t][zone] == 0 and (
                t.hour not in user_cmf_dict[u_type][0]
                and t.hour not in user_cmf_dict[u_type][1]):
            set_point.loc[t]['T_cmf'] = cool_T_off

        u_type = original_u_type

    return (set_point)
Beispiel #6
0
    def test_province_specific_days(self):
        prov_an = holidays.IT(prov="AN", years=[2017])
        prov_ao = holidays.IT(prov="AO", years=[2017])
        prov_ba = holidays.IT(prov="BA", years=[2017])
        prov_bl = holidays.IT(prov="BL", years=[2017])
        prov_bo = holidays.IT(prov="BO", years=[2017])
        prov_bz = holidays.IT(prov="BZ", years=[2017])
        prov_bs = holidays.IT(prov="BS", years=[2017])
        prov_cb = holidays.IT(prov="CB", years=[2017])
        prov_ch = holidays.IT(prov="CH", years=[2017])
        prov_cs = holidays.IT(prov="CS", years=[2017])
        prov_ct = holidays.IT(prov="CT", years=[2017])
        prov_en = holidays.IT(prov="EN", years=[2017])
        prov_fc = holidays.IT(prov="FC", years=[2017])
        prov_fe = holidays.IT(prov="FE", years=[2017])
        prov_fi = holidays.IT(prov="FI", years=[2017])
        prov_fr = holidays.IT(prov="FR", years=[2017])
        prov_ge = holidays.IT(prov="GE", years=[2017])
        prov_go = holidays.IT(prov="GO", years=[2017])
        prov_is = holidays.IT(prov="IS", years=[2017])
        prov_kr = holidays.IT(prov="KR", years=[2017])
        prov_lt = holidays.IT(prov="LT", years=[2017])
        prov_mb = holidays.IT(prov="MB", years=[2017])
        prov_me = holidays.IT(prov="ME", years=[2017])
        prov_mi = holidays.IT(prov="MI", years=[2017])
        prov_mn = holidays.IT(prov="MN", years=[2017])
        prov_mo = holidays.IT(prov="MO", years=[2017])
        prov_ms = holidays.IT(prov="MS", years=[2017])
        prov_na = holidays.IT(prov="NA", years=[2017])
        prov_pa = holidays.IT(prov="PA", years=[2017])
        prov_pc = holidays.IT(prov="PC", years=[2017])
        prov_pd = holidays.IT(prov="PD", years=[2017])
        prov_pg = holidays.IT(prov="PG", years=[2017])
        prov_pr = holidays.IT(prov="PR", years=[2017])
        prov_rm = holidays.IT(prov="RM", years=[2017])
        prov_sp = holidays.IT(prov="SP", years=[2017])
        prov_to = holidays.IT(prov="TO", years=[2017])
        prov_ts = holidays.IT(prov="TS", years=[2017])
        prov_vi = holidays.IT(prov="VI", years=[2017])

        self.assertIn("2017-05-04", prov_an)
        self.assertIn("2017-09-07", prov_ao)
        self.assertIn("2017-12-06", prov_ba)
        self.assertIn("2017-11-11", prov_bl)
        self.assertIn("2017-10-04", prov_bo)
        self.assertIn("2017-08-15", prov_bz)
        self.assertIn("2017-02-15", prov_bs)
        self.assertIn("2017-04-23", prov_cb)
        self.assertIn("2017-05-11", prov_ch)
        self.assertIn("2017-02-12", prov_cs)
        self.assertIn("2017-02-05", prov_ct)
        self.assertIn("2017-07-02", prov_en)
        self.assertIn("2017-06-24", prov_fc)
        self.assertIn("2017-02-04", prov_fc)
        self.assertIn("2017-04-23", prov_fe)
        self.assertIn("2017-06-24", prov_fi)
        self.assertIn("2017-06-20", prov_fr)
        self.assertIn("2017-06-24", prov_ge)
        self.assertIn("2017-03-16", prov_go)
        self.assertIn("2017-05-19", prov_is)
        self.assertIn("2017-03-19", prov_sp)
        self.assertIn("2017-10-09", prov_kr)
        self.assertIn("2017-04-25", prov_lt)
        self.assertIn("2017-06-24", prov_mb)
        self.assertIn("2017-06-03", prov_me)
        self.assertIn("2017-12-07", prov_mi)
        self.assertIn("2017-03-18", prov_mn)
        self.assertIn("2017-01-31", prov_mo)
        self.assertIn("2017-10-04", prov_ms)
        self.assertIn("2017-09-19", prov_na)
        self.assertIn("2017-07-15", prov_pa)
        self.assertIn("2017-07-04", prov_pc)
        self.assertIn("2017-06-13", prov_pd)
        self.assertIn("2017-01-29", prov_pg)
        self.assertIn("2017-01-13", prov_pr)
        self.assertIn("2017-06-29", prov_rm)
        self.assertIn("2017-06-24", prov_to)
        self.assertIn("2017-11-03", prov_ts)
        self.assertIn("2017-04-25", prov_vi)
    draw.text((216,179), valore_temp_ext+"°", fill=inkywhat.BLACK, font=font_temp_ext_valore)

    
    # gia' che ci sono scrivo la temperatura nel DB (cosi' non mi serve più il sensore sul balcone)
    connessione = sqlite3.connect(db_sqlite_remoto)
    cursore = connessione.cursor()    
    cursore.execute("INSERT INTO Temperature (Luogo, Temp) VALUES (5, " + valore_temp_ext + ");")
    connessione.commit()
    connessione.close()
    
else:
    draw.text((211,64), "Conn", fill=inkywhat.BLACK, font=font_temp_ext_valore)


# festività di oggi con la libreria
giorni_festivi = holidays.IT()
oggi_festa = giorni_festivi.get(funzioni_tucci.oggi())
font_festa = ImageFont.truetype(font_TTF, 14)
print("Festività di oggi " + str(oggi_festa))
festa_da_libreria =""
if str(oggi_festa) != "None":
    festa_da_libreria = str(oggi_festa)


# gli eventi da DB
# la data di oggi, senza anno
data_corta = funzioni_tucci.oggi_breve()
print("Data breve oggi: " + str(data_corta))
# mi collego al DB
connessione = sqlite3.connect(db_sqlite_locale)
cursore = connessione.cursor()
Beispiel #8
0
 def test_christmas(self):
     self.holidays = holidays.IT(years=2017)
     self.assertIn(date(2017, 12, 25), self.holidays)
Beispiel #9
0
 def test_saint_stephan(self):
     self.holidays = holidays.IT(years=2017)
     self.assertIn(date(2017, 12, 26), self.holidays)
Beispiel #10
0
 def test_liberation_day_after_1946(self):
     self.holidays = holidays.IT(years=1946)
     self.assertIn(date(1946, 4, 25), self.holidays)
Beispiel #11
0
 def test_liberation_day_before_1946(self):
     self.holidays = holidays.IT(years=1945)
     self.assertNotIn(date(1945, 4, 25), self.holidays)
Beispiel #12
0
 def test_republic_day_after_1948(self):
     self.holidays = holidays.IT(years=[1948])
     self.assertIn(date(1948, 6, 2), self.holidays)
Beispiel #13
0
 def test_republic_day_before_1948(self):
     self.holidays = holidays.IT(years=[1947])
     self.assertNotIn(date(1947, 6, 2), self.holidays)
Beispiel #14
0
 def setUp(self):
     self.holidays = holidays.IT()