示例#1
0
async def add_working_days(start_date: date, increment: int):
    end_date_without_holidays = busday_offset(start_date,
                                              increment,
                                              roll="forward").item()
    co_holidays = holidays.CO()
    holidays_range = co_holidays[start_date:end_date_without_holidays]
    end_date = busday_offset(start_date,
                             increment,
                             holidays=holidays_range,
                             roll="forward")
    return end_date.item()
def is_holiday(day_in, month, year):
    str_date = month + "-" + day_in + "-" + year
    date_wk = datetime.strptime(str_date, '%m-%d-%Y')
    if (date_wk.weekday() == 6):
        return True
    co_holidays = hl.CO(years=int(year))
    for day in co_holidays.items():
        str_day = day[0].strftime("%d-%m-%Y")[0:2]
        str_month = day[0].strftime("%d-%m-%Y")[3:5]
        if (day_in == str_day and month == str_month):
            return True
    return False
示例#3
0
async def analyze(start_date: date, end_date: date):
    end_date = end_date + timedelta(days=1)  # include last day
    days = (end_date - start_date).days
    colombia_holidays = holidays.CO()
    holidays_range = colombia_holidays[start_date:end_date]
    public_holidays = {
        holiday: colombia_holidays.get(holiday)
        for holiday in holidays_range
    }
    working_days = busday_count(start_date, end_date, holidays=holidays_range)
    weekend_days = busday_count(start_date, end_date, weekmask="0000011")
    return {
        "days": days,
        "working_days": working_days.item(),
        "weekend_days": weekend_days.item(),
        "public_holidays": public_holidays,
    }
示例#4
0
def process_data(data):
    """
    This function aims to procees the transactional data.
    First, It computes the transactions' number by day, oper and idTerminal.
    Seconf, It builds features like day name and if the day is weekend or not.
    
    Parameters
    ----------
    X : pandas.DataFrame
        DataFrame contains the transactional data.
    
    Returns
    -------
    data_diaria : pandas.DataFrame
        DataFrame contains the processed data.
    """
    X = data.copy()

    X['dia'] = X['fecha'].str[:10]

    data_diaria = X.groupby(['dia', 'oper', 'idTerminal']).size()
    data_diaria = pd.DataFrame(data_diaria)
    data_diaria.columns = ['num_trx']
    data_diaria = data_diaria.reset_index()

    # Holidays
    co_holidays = holidays.CO()
    holidays_serie = data_diaria['dia'].apply(lambda x: co_holidays.get(x))

    # Additional features
    weekDays = ("Lun", "Mar", "Mie", "Jue", "Vie", "Sab", "Dom")

    data_diaria['dia'] = pd.to_datetime(data_diaria['dia'])
    data_diaria['nombre_dia'] = data_diaria['dia'].apply(
        lambda x: weekDays[x.weekday()])
    data_diaria['weekend'] = np.where(
        data_diaria['nombre_dia'].isin(['Sab', 'Dom']), 1, 0)
    data_diaria['weekend'] = np.where(holidays_serie.isnull(),
                                      data_diaria['weekend'], 1)

    return data_diaria
 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
示例#6
0
        myIp = urllib.request.urlopen('http://icanhazip.com/',
                                      timeout=2).read().strip()
        response = DbIpCity.get(myIp, api_key='free')
        country_last = response.country
    except:
        pass

    settings["country_last_updated"] = now
    settings["country_last"] = country_last
    settings.flush()
    return country_last


country_holidays = {
    "CA": holidays.CA(),
    "CO": holidays.CO(),
    "MX": holidays.MX(),
    "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(),
 def setUp(self):
     self.holidays = holidays.CO(observed=True)
示例#8
0
def festivos():
    fecha = []
    for date in sorted(holidays.CO(years=datetime.now().year).items()):
        fecha.append(str(date[0]))
    return fecha
    if pd.isnull(segmento) or (segmento==""):
        return 'otro'
    else:
        return segmento


df['segmento']=df['segmento'].apply(fill_segmento)
df['segmento']=df['segmento'].apply(lambda x: x.strip())
list(df['segmento'].values)

# Rango de fechas para generar el calendario
START_DATE = '2016-01-01'
END_DATE = '2017-12-31'
START_PRED = '2018-01-23'
END_PRED = '2018-01-31'
co_holidays = holidays.CO()

def get_next_holiday(date):
    """
    Devuelve el numero de días que faltan para el siguiente dia
    festivo.

    Ignora festivos en Sabados y Domingos.

    Parametros
    ----------
    date : datetime, fecha que se quiere consultar.

    """
    i = 0
    while date not in co_holidays: