def add_is_weekend_feature(main_table):

    # Extracting relevant columns from main table
    table = main_table.groupby("display_id").first().reset_index()[[
        "display_id", "click_tstamp"
    ]]
    timestamps = table["click_tstamp"]
    # Initializing empty is_weekend array
    is_weekend_boolean = np.zeros(shape=len(timestamps))

    for i in range(len(timestamps)):
        # Format conversions to allow use of is_busday function
        as_datetime64 = np.datetime64(int(timestamps[i]), 's')
        as_datetime = pd.to_datetime(as_datetime64)

        # Using the is_busday to return an is_weekend boolean - True for Saturday and Sunday, False otherwise
        boolean = np.is_busday(as_datetime, weekmask='0000011')
        is_weekend_boolean[i] = boolean

    # Creating result Dataframe with two columns - display_id and is_weekend
    res_frame = pd.DataFrame()
    res_frame["display_id"] = table["display_id"]
    res_frame["is_weekend"] = is_weekend_boolean

    return res_frame
Exemplo n.º 2
0
    def Sergipe(self):
        holidays2020 = np.array(['2020-01-01','2020-01-02','2020-01-03','2020-01-04','2020-01-05','2020-01-06','2020-02-24','2020-02-25','2020-02-26','2020-03-16','2020-03-17','2020-04-09','2020-04-10','2020-04-21','2020-05-01','2020-05-01','2020-05-22','2020-05-25','2020-05-26','2020-06-11','2020-09-07','2020-10-12','2020-11-02','2020-11-15','2020-12-24','2020-12-25','2020-12-30'],dtype='datetime64')

        self.__log("Data de inicio e fim da pesquisa:","green")

        dataInit,dataFim = self.__askDate()
        
        start = np.datetime64(dataInit)
        end = np.datetime64(dataFim)

        date = start

        e='SE'

        while date <= end:

            if np.is_busday(date,holidays=holidays2020):

                edicao = self.__EdicaoSE(date)
                
                nomeArquivo = "Diario-"+str(date)+".pdf"
                fileUrl ="http://www.diario.tjse.jus.br/diario/diarios/"+edicao+".pdf"
                diretorio = e
                downloadFile(fileUrl,nomeArquivo,diretorio)
                print("Download:"+nomeArquivo)


            
            date = date + np.timedelta64(1,'D')

        print("Arquivos Baixados")
def _filter_to_business_days(dates):
    # only weekdays
    dates = dates[np.where(np.is_busday(dates))]
    # only US trading days
    dates = dates[np.where(
        np.isin(dates, _US_HOLIDAYS, invert=True, assume_unique=True))]
    return dates
Exemplo n.º 4
0
    def Amazonas(self):

        holidays2020 = np.array(['2020-01-01','2020-02-24','2020-02-25','2020-02-26','2020-04-08','2020-04-09','2020-04-10','2020-04-21','2020-05-01','2020-06-11','2020-06-24','2020-06-29','','2020-09-07','2020-09-16','2020-10-12','2020-10-28','2020-11-02','2020-11-15','2020-11-20','2020-11-30','2020-12-08','2020-12-24','2020-12-25','2020-12-30'],dtype='datetime64')

        self.__log("Data de inicio e fim da pesquisa:","green")

        dataInit,dataFim = self.__askDate()
        
        start = np.datetime64(dataInit)
        end = np.datetime64(dataFim)

        e='AM'
        date =start

        while date <= end:

            dia = str(date).rsplit('-')[2]
            mes = str(date).rsplit('-')[1]
            ano = str(date).rsplit('-')[0]

            dateStr = dia+"/"+mes+"/"+ano

            if np.is_busday(date,holidays=holidays2020):

                nomeArquivo = "Diario-"+str(date)+".pdf"

                fileUrl = "https://consultasaj.tjam.jus.br/cdje/downloadCaderno.do?dtDiario="+dateStr+"&cdCaderno=2&tpDownload=D"

                downloadFile(fileUrl,nomeArquivo,e)
                print("Download:"+nomeArquivo)
            
            date = date + np.timedelta64(1,'D')

        print("Arquivos Baixados")
Exemplo n.º 5
0
    def Roraima(self):

        holidays2020 = np.array(['2020-01-01','2020-01-20','2020-02-24','2020-02-25','2020-02-26','2020-04-09','2020-04-10','2020-04-20','2020-04-21','2020-05-01','2020-06-11','2020-06-12','2020-06-29','2020-07-09','2020-07-10','2020-08-10','2020-09-07','2020-09-16','2020-10-12','2020-10-28','2020-11-02','2020-11-15','2020-11-20','2020-11-30','2020-12-08','2020-12-24','2020-12-25','2020-12-31'],dtype='datetime64')

        self.__log("Data de inicio e fim da pesquisa:","green")

        dataInit,dataFim = self.__askDate()
        
        start = np.datetime64(dataInit)
        end = np.datetime64(dataFim)

        date = start

        e='RR'

        while date <= end:

            dia = str(date).rsplit('-')[2]
            mes = str(date).rsplit('-')[1]
            ano = str(date).rsplit('-')[0]

            

            if np.is_busday(date,holidays=holidays2020):

                nomeArquivo = "Diario-"+str(date)+".pdf"

                fileUrl = "http://diario.tjrr.jus.br/dpj/dpj-"+ano+mes+dia+".pdf"

                downloadFile(fileUrl,nomeArquivo,e)
                print("Download:"+nomeArquivo)
            
            date = date + np.timedelta64(1,'D')

        print("Arquivos Baixados")
Exemplo n.º 6
0
 def is_trading_day(
     self, dates: Union[np.datetime64, pd.Series, np.ndarray, str,
                        datetime.datetime, datetime.date]
 ) -> Union[bool, np.ndarray]:
     '''
     Returns whether the date is not a holiday or a weekend
     
     Args:
         dates: date times to check
     Return:
         Whether this date is a trading day
     
     >>> import datetime
     >>> eurex = Calendar.get_calendar(Calendar.EUREX)
     >>> eurex.is_trading_day('2016-12-25')
     False
     >>> eurex.is_trading_day(datetime.date(2016, 12, 22))
     True
     >>> nyse = Calendar.get_calendar(Calendar.NYSE)
     >>> nyse.is_trading_day('2017-04-01') # Weekend
     False
     >>> nyse.is_trading_day(np.arange('2017-04-01', '2017-04-09', dtype = np.datetime64)) # doctest:+ELLIPSIS
     array([False, False,  True,  True,  True,  True,  True, False]...)
     '''
     if isinstance(dates, str) or isinstance(dates, datetime.date):
         dates = np.datetime64(dates, 'D')
         if isinstance(
                 dates.astype(datetime.datetime), int
         ):  # User can pass in a string like 20180101 which gets parsed as a year
             raise Exception(f'invalid date: {dates}')
     if isinstance(dates, pd.Series): dates = dates.values
     return np.is_busday(dates.astype('M8[D]'), busdaycal=self.bus_day_cal)
Exemplo n.º 7
0
    def MatoGrosso(self):

        holidays2020 = np.array(['2020-01-01','2020-02-24','2020-02-25','2020-02-26','2020-04-09','2020-04-10','2020-04-20','2020-04-21','2020-05-01','2020-06-11','2020-06-12','2020-09-07','2020-10-12','2020-11-02','2020-11-15','2020-11-20','2020-12-08','2020-12-24','2020-12-25','2020-12-30'],dtype='datetime64')

        self.__log("Data de inicio e fim da pesquisa:","green")

        dataInit,dataFim = self.__askDate()
        
        start = np.datetime64(dataInit)
        end = np.datetime64(dataFim)

        date = start

        e='MT'
        

        while date <= end:

            
            if np.is_busday(date,holidays=holidays2020):

                edicao = self.__definirEdicaoMT(date)

                nomeArquivo = "Diario-"+str(edicao)+".pdf"

                fileUrl = "http://dje.tjmt.jus.br/publicacoes/"+str(edicao)+"-2020%20CADERNO%20JUDICIAL%20DO%20TRIBUNAL%20DE%20JUSTICA.pdf"

                downloadFile(fileUrl,nomeArquivo,e)
                print("Download:"+nomeArquivo)
            
            date = date + np.timedelta64(1,'D')

        print("Arquivos Baixados")
Exemplo n.º 8
0
 def get_trading_days(self,
                      start: Union[np.datetime64, pd.Series, np.ndarray,
                                   str, datetime.datetime, datetime.date],
                      end: Union[np.datetime64, pd.Series, np.ndarray, str,
                                 datetime.datetime, datetime.date],
                      include_first: bool = False,
                      include_last: bool = True) -> Union[int, np.ndarray]:
     '''
     Get back a list of numpy dates that are trading days between the start and end
     
     >>> nyse = Calendar.get_calendar(Calendar.NYSE)
     >>> nyse.get_trading_days('2005-01-01', '2005-01-08')
     array(['2005-01-03', '2005-01-04', '2005-01-05', '2005-01-06', '2005-01-07'], dtype='datetime64[D]')
     >>> nyse.get_trading_days(datetime.date(2005, 1, 1), datetime.date(2005, 2, 1))
     array(['2005-01-03', '2005-01-04', '2005-01-05', '2005-01-06',
            '2005-01-07', '2005-01-10', '2005-01-11', '2005-01-12',
            '2005-01-13', '2005-01-14', '2005-01-18', '2005-01-19',
            '2005-01-20', '2005-01-21', '2005-01-24', '2005-01-25',
            '2005-01-26', '2005-01-27', '2005-01-28', '2005-01-31', '2005-02-01'], dtype='datetime64[D]')
     >>> nyse.get_trading_days(datetime.date(2016, 1, 5), datetime.date(2016, 1, 29), include_last = False)
     array(['2016-01-06', '2016-01-07', '2016-01-08', '2016-01-11',
            '2016-01-12', '2016-01-13', '2016-01-14', '2016-01-15',
            '2016-01-19', '2016-01-20', '2016-01-21', '2016-01-22',
            '2016-01-25', '2016-01-26', '2016-01-27', '2016-01-28'], dtype='datetime64[D]')
     >>> nyse.get_trading_days('2017-07-04', '2017-07-08', include_first = False)
     array(['2017-07-05', '2017-07-06', '2017-07-07'], dtype='datetime64[D]')
     >>> nyse.get_trading_days(np.datetime64('2017-07-04'), np.datetime64('2017-07-08'), include_first = False)
     array(['2017-07-05', '2017-07-06', '2017-07-07'], dtype='datetime64[D]')
     '''
     s, e = _normalize(start, end, include_first, include_last)
     dates = np.arange(s, e, dtype='datetime64[D]')
     dates = dates[np.is_busday(dates, busdaycal=self.bus_day_cal)]
     return dates
Exemplo n.º 9
0
    def get_statistics(cls):
        # For now not using this to improve performance
        # response_values = [cls.get_approved_names_counter(),
        #                    cls.get_waiting_time_priority_queue(unit=UnitTime.HR.value),
        #                    cls.get_waiting_time_regular_queue(unit=UnitTime.DAY.value)]

        oldest_draft = Request.get_oldest_draft()
        todays_date = get_utc_now().date()
        submitted_date = oldest_draft.submittedDate.date()

        # note that busday_count does not count the end date provided
        delta = np.busday_count(submitted_date, todays_date)
        delta = int(delta)
        # add one to waiting time to account for specific scenarios
        if np.is_busday(todays_date) or delta == 0:
            delta += 1

        response_values = [
            0,
            0,  #cls.get_waiting_time_priority_queue(unit=UnitTime.HR.value),
            delta
        ]

        response = query_result_to_dict(response_keys, response_values)

        return response
Exemplo n.º 10
0
    def _get_ticker_array(self):
        self.start_time = self.config.start_time
        self.end_time = self.config.end_time

        current_day = self.start_time
        while current_day != self.end_time:
            current_day_str = current_day.strftime("%Y-%m-%d")
            if _np.is_busday(current_day_str):
                start_day = current_day + _timedelta(hours=9, minutes=30)
                end_day = current_day + _timedelta(hours=16)

                start_day_str = start_day.strftime("%Y-%m-%dT%H:%M:%S" + self._daylight_savings_offset(current_day))
                end_day_str = end_day.strftime("%Y-%m-%dT%H:%M:%S" + self._daylight_savings_offset(current_day))

                for t in self.config.tickers:
                    barset = self._api.get_barset(t, 'minute',
                                                  start=start_day_str,
                                                  end=end_day_str)
                    bars = barset[t]
                    bar_set = [ self._create_bar_backtest(b, t) for b in bars]
                    self.buffer_bar.extend(bar_set)
                    _time.sleep(0.5)

            current_day += AlpacaDataSource.DELTA
        self.buffer_bar.sort(key=lambda x: x.timestamp)
Exemplo n.º 11
0
def biz_days_offset(date, count):
    date1 = np.busday_offset(date, 0, roll='forward', holidays=US_HOLIDAY_LIST)
    if not np.is_busday(date, holidays=US_HOLIDAY_LIST):
        print('\nWARNING: the date "' + str(date) + '" is not a business day; ' \
              + 'using the first business day immediately following that date,' \
              + 'namely, "' + str(date1) + '"\n')
    biz_date = np.busday_offset(date1, count, holidays=US_HOLIDAY_LIST)
    # print('inside utils_general we have value: ' + str(biz_date))
    return str(biz_date)
Exemplo n.º 12
0
 def count_days_mounth(self, month, year):
     """
         função que recebe o ano e o mês e retorne a quantidade de dias úteis que ele possui. 
         Obs: Utilize o Numpy.
     """
     days_of_month = self.get_all_dates(month, year)
     workdays = np.is_busday(
         np.array(days_of_month).astype("datetime64[D]"))
     return np.count_nonzero(workdays)
Exemplo n.º 13
0
def adicionar_dias_uteis(data, dias):
    for dia in range(dias):
        data = adicionar_dias_corridos(data=data, dias=1)

        while not np.is_busday(
                dates=data, weekmask='1111100', holidays=feriados):
            data = adicionar_dias_corridos(data=data, dias=1)

    return data
Exemplo n.º 14
0
def get_market_holidays(start='2000-01-01', end='2019-01-01'):
    temp = web.get_data_yahoo('^GDAXI', start=start, end=end)
    temp = temp.loc[temp.Volume>0,:]
    opens=set(temp.index.values)
    opens = pd.to_datetime(list(opens))
    weekmask = [1, 1, 1, 1, 1, 0, 0]
    busdays = np.arange(start, end, dtype='datetime64[D]')
    busdays = pd.to_datetime(busdays[np.is_busday(busdays, weekmask=weekmask)])
    holidays = set(busdays).difference(opens)
    df = pd.to_datetime(list(holidays)).sort_values()
    return df
Exemplo n.º 15
0
def meanvec(mean_busday, mean_holiday, t):

    num_days = int(t.shape[0]/24)
    
    mu = np.empty((1, t.shape[0]))
    for d in range(num_days):
        if np.is_busday(t[d*24].astype('datetime64[D]')):
            mu[0, d*24:(d+1)*24] = mean_busday
        else:
            mu[0, d*24:(d+1)*24] = mean_holiday
    
    return mu
Exemplo n.º 16
0
def next_n_business_days(start_date, n, include_start=False):
    '''
    @return: A list of the next n valid business days.
    '''
    dates = []
    if include_start and np.is_busday(start_date):
        dates.append(np.datetime64(start_date))
    curr_date = start_date
    for _ in range(n):
        curr_date = next_business_day(curr_date)
        dates.append(curr_date)
    return dates
Exemplo n.º 17
0
 def trading_day(self, aDatetime):
     """
     Check if a datetime is a trading day based on marketName
     output:
         True: It is a trading day.
     """
     if isinstance(aDatetime, dt.datetime):
         aDatetime = aDatetime.date()
     if np.is_busday(aDatetime):
         return not (np.datetime64(aDatetime)
                     in self.marketName.holidays().holidays)
     else:
         return False
Exemplo n.º 18
0
 def is_trade_day(days):
     """
     交易日判断。
     """
     if is_non_string_iterable(days):
         datetimes = pd.to_datetime(days)
     else:
         datetimes = pd.DatetimeIndex([days])
     is_bdays = np.is_busday(datetimes.to_numpy(dtype='datetime64[D]'),
                             busdaycal=CHN_A_Calendar)
     if not is_non_string_iterable(days):
         return is_bdays[0]
     return is_bdays
Exemplo n.º 19
0
def dateExtractor(x):
    years = x.astype('datetime64[Y]').astype(int) + 1970
    months = x.astype('datetime64[M]').astype(int) % 12 + 1
    daysOfTheYear = x.astype('datetime64[D]').astype(int) - 365 * (years - 1970) - 12
    daysOfTheYear = np.digitize(daysOfTheYear, [0, 60, 120, 180, 240, 300, 360])
    businessDays = np.is_busday(x.astype('datetime64[D]'))
    businessDays = businessDays.astype(int)
    hours = np.mod(x.astype('datetime64[h]').astype(int) - 395659, 24)
    dayOfTheWeek = np.mod((x.astype('datetime64[D]').astype(int)), 7)
    years = years.astype('int64')
    months = months.astype('int64')
    hourPeriod = np.digitize(hours, [0, 12, 24])

    return years, months, daysOfTheYear, businessDays, hours, dayOfTheWeek, hourPeriod
Exemplo n.º 20
0
def getdates(stock):
    data = get_history(symbol=stock,
                       start=date.today() - relativedelta(months=+1),
                       end=date.today())  #specified date

    retdata = dict()
    #determining the high and low of the month with date
    data = data.reset_index()
    data = data[['Date', 'Open', 'High', 'Low', 'Close']]
    index_high = data['High'].idxmax()
    index_low = data['Low'].idxmin()
    high_date = data.loc[index_high, :]['Date']
    low_date = data.loc[index_low, :]['Date']
    retdata['High'] = max(data['High'])
    retdata['highDate'] = str(high_date)
    retdata['Low'] = min(data['Low'])
    retdata['lowDate'] = str(low_date)
    retdata['Close'] = data['Close'][len(data) - 1]

    price_diff = max(data['High']) - min(data['Low'])

    #degree conversion
    degree = ((sqrt(price_diff) * 180) - 225) % 360

    #calculating number having same degree
    n = 3
    l = []
    for i in range(1, n):
        #l.append(round((2*i+2*degree/360-1.25)**2))
        l.append(round((2 * i + 2 * degree / 360 + 1.25)**2))

    #Predicting future date (low/high)
    preddate = []
    for i in l:
        preddate.append(high_date + relativedelta(days=+i))
        preddate.append(low_date + relativedelta(days=+i))

    retdata['predictedDates'] = []
    for i in preddate:
        if not np.is_busday(i):
            #print(i,"Not a Business day")
            d = i
            next = d + timedelta(days=7 -
                                 d.weekday() if d.weekday() > 3 else 1)
            retdata['predictedDates'] = retdata['predictedDates'] + [str(next)]
        else:
            retdata['predictedDates'] = retdata['predictedDates'] + [str(i)]
    return retdata
Exemplo n.º 21
0
def CheckFunction():

    global dateChanged
    global todayDate
    global portfolio

    if dateChanged == True:

        #print('Date Changed!')

        dateChanged = False

        todayDate = todayDate + datetime.timedelta(days = 1)

        #print('2020-04-23' in holidays.TR())

        while not np.is_busday(todayDate.date()) or (todayDate.date() in holidays.TR()):
            
            todayDate = todayDate + datetime.timedelta(days = 1)

        #print("Date passed: " + str(todayDate.date()))


        date = str(todayDate.year) + '-' + str(todayDate.month).zfill(2) + '-' + str(todayDate.day).zfill(2)

        portfolio.SetDate(date)

        stockDatas = []

        for stockData in portfolio.stockDatas:

            stockDatas.append(stockData.name)

        PullStocks(stockDatas, -1)

        for stockData in portfolio.stockDatas:

            stock = Stocker.Stock(stockData.name)
            stock.Initialize()
            stock.name = stockData.name

            stock.Load('./Resources/Stocks/')
            
            CheckStocks(stock)

        PortfolioToUI()
    
    return
Exemplo n.º 22
0
    def num_days(self, upto_today=False):
        '''The number of classes in the semester (from start date to end date
        excluding weekends and ExcludedDates). '''

        excluded_days = self.excluded_days()
        if upto_today and date.today() < self.last_day:
            last_day = date.today()
        else:
            last_day = self.last_day
        count = numpy.busday_count(self.first_day,
                                   last_day,
                                   holidays=excluded_days)
        if numpy.is_busday(last_day, holidays=excluded_days
                           ):  # end date is not included, so add here.
            count += 1
        return count
Exemplo n.º 23
0
def _get_generated_visit_list(sc, sqlContext):
    invoice_q = """
    select d.customernumber customernumber, d.matnr matnr, d.bill_date bill_date, IF(d.units != 'CS', d.quantity * (f.umrez / f.umren), d.quantity) quantity, d.dlvry_lag dlvry_lag
    from
    (
    select b.customernumber customernumber, b.matnr matnr, b.bill_date bill_date ,b.quantity quantity, b.units units, b.price price, c.dlvry_lag dlvry_lag
    from
    (
    select a.kunag customernumber, a.matnr matnr, a.fkdat bill_date ,a.fklmg quantity, a.meins units, a.netwr price
    from skuopt.invoices a
    where a.kunag in ('0500083147','0500061438','0500067084','0500058324','0500080723','0500060033','0500068825','0500060917','0500078551','0500076115','0500071747','0500078478','0500078038','0500073982','0500064458','0500268924','0500070702','0500070336','0500076032','0500095883','0500284889')
    ) b
    join
    (
    select kunnr customernumber, IF(vsbed == '01', 2, 1) dlvry_lag
    from mdm.customer
    where vkbur='C005'
    ) c
    on
    b.customernumber = c.customernumber
    ) d
    join
    (
    select e.matnr matnr, e.meinh meinh, e.umren umren, e.umrez umrez
    from mdm.dim_marm e
    ) f
    on
    d.matnr=f.matnr and d.units=f.meinh
    where d.bill_date >= '20170903' and d.bill_date <= '20171007'
    """

    invoice_raw = sqlContext.sql(invoice_q)
    invoice_raw.cache()

    data_set = invoice_raw \
        .filter(col('quantity') > 0) \
        .withColumn('b_date', from_unixtime(unix_timestamp(col('bill_date'), "yyyyMMdd")).cast(DateType())) \
        .withColumn('dlvry_date', udf((lambda x: x.strftime('%Y-%m-%d')), StringType())(col('b_date'))) \
        .withColumn('bus_day_flag',
                    udf((lambda x: str(np.is_busday([x])[0])), StringType())(col('dlvry_date')).cast(BooleanType())) \
        .withColumn('visit_date',
                    udf((lambda x, y: str(np.busday_offset(x, -y, roll='backward'))), StringType())(col('dlvry_date'),
                                                                                                    col('dlvry_lag'))) \
        .select(col('customernumber'), col('visit_date')) \
        .distinct()
    return None
Exemplo n.º 24
0
def businessDayCount(data):
    dayOffs = [
        '2017-01-02', '2017-01-26', '2017-01-27', '2017-01-30', '2017-01-31',
        '2017-02-01', '2017-04-06', '2017-05-01', '2017-05-02', '2017-09-04',
        '2018-01-01', '2018-02-12', '2018-02-13', '2018-02-14', '2018-02-15',
        '2018-02-16', '2018-02-19', '2018-02-20', '2018-04-25', '2018-04-30',
        '2018-05-01', '2018-09-03', '2019-01-01', '2019-02-04', '2019-02-05',
        '2019-02-06', '2019-02-07', '2019-02-08', '2019-04-15', '2019-04-30',
        '2019-05-01', '2019-09-02'
    ]
    dataParameters = data.split("-")
    startDate = dateFormatConverter(dataParameters[0])
    endDate = dateFormatConverter(dataParameters[1])
    endDayIsBusDay = np.is_busday([endDate], holidays=dayOffs)[0]
    workingDayCount = np.busday_count(startDate, endDate,
                                      holidays=dayOffs) + endDayIsBusDay
    return workingDayCount
Exemplo n.º 25
0
def getLastTrDay(endD):
    from datetime import datetime
    from datetime import date
    import numpy as np
    import pandas as pds
    refDate = datetime.date(datetime.utcnow())
    refHour = datetime.utcnow().hour
    lstTDR = endD
    if endD >= refDate: 
        if np.is_busday(refDate):
            if refHour > 6: lstTDR = np.busday_offset(refDate, -1, roll='backward')
            else: lstTDR = np.busday_offset(endD, -2, roll='backward')
        else:
            if refHour > 6: lstTDR = np.busday_offset(refDate, 0, roll='backward')
            else: lstTDR = np.busday_offset(endD, -2, roll='backward')
    buff = pds.to_datetime(lstTDR)
    return buff
Exemplo n.º 26
0
    def Piaui(self):

        holidays2020 = np.array(['2020-01-01','2020-01-02','2020-01-03','2020-01-04','2020-01-05','2020-05-15','2020-01-06','2020-02-03','2020-02-10','2020-02-24','2020-02-25','2020-04-09','2020-04-10','2020-04-17','2020-04-21','2020-05-01','2020-05-20','2020-08-11','2020-09-07','2020-10-12','2020-11-02','2020-11-15','2020-12-24','2020-12-25','2020-12-30'],dtype='datetime64')

        self.__log("Data de inicio e fim da pesquisa:","green")

        dataInit,dataFim = self.__askDate()
        
        start = np.datetime64(dataInit)
        end = np.datetime64(dataFim)

        date = start

        e='PI'
       

        iniAno = np.datetime64('2020-01-01')

        while date <= end:

            dia = str(date).rsplit('-')[2]
            mes = str(date).rsplit('-')[1]
            ano = str(date).rsplit('-')[0]
            ano = ano[2]+ano[3]

            dateStr = ano+mes+dia

            
            if np.is_busday(date,holidays=holidays2020):



                edicao = 8819 + np.busday_count(iniAno,date + np.timedelta64(1,'D'),holidays=holidays2020)
                edicaoStr = "dj" + dateStr + "_" + str(edicao)

                nomeArquivo = "Diario-"+edicaoStr+".pdf"

                fileUrl = "http://www.tjpi.jus.br/diarioeletronico/public/"+edicaoStr+".pdf"

                downloadFile(fileUrl,nomeArquivo,e)
                print("Download:"+nomeArquivo)
            
            date = date + np.timedelta64(1,'D')

        print("Arquivos Baixados")
Exemplo n.º 27
0
    def send_daily_notifications(self):
        """
        Send daily summary mail notification. The opposite of notify_user()
        :param self:
        :return:
        """
        # test whether today is a working day (a "business day" or "bday"), and if not then bail out;
        # we don't want to bother people with emails at the weekend or on statutory holidays
        today = date.today()
        holiday_calendar = holidays.UK()

        # the test is in two parts: first we check for a holiday, then for a conventional working day
        # (in future perhaps allow individual users to choose their own working-day pattern).
        # Annoyingly, numpy.is_busday() won't accept objects generated by the holidays module
        # as a holiday calendar (it wants an array-like of datetime)

        # is today a UK holiday?
        if today in holiday_calendar:
            return

        # is today a working day?
        if not is_busday(today, holidays=None):
            return

        # search through all active users and dispatch notifications
        # we treat students and faculty slightly differently so we have different dispatchers for them

        # find all students
        students = db.session.query(User).filter(
            User.active == True, User.roles.any(Role.name == 'student')).all()

        student_tasks = group(
            dispatch_student_notifications.si(r.id) for r in students
            if r is not None)

        # find all faculty
        faculty = db.session.query(User).filter(
            User.active == True, User.roles.any(Role.name == 'faculty')).all()

        faculty_tasks = group(
            dispatch_faculty_notifications.si(r.id) for r in faculty
            if r is not None)

        task = group(student_tasks, faculty_tasks)
        raise self.replace(task)
Exemplo n.º 28
0
def is_business_day(dates: DateOrDates, calendars: Union[str, Tuple[str, ...]] = (), week_mask: Optional[str] = None)\
        -> Union[bool, Tuple[bool]]:
    """
    Determine whether each date in dates is a business day

    :param dates: The input date or dates
    :param calendars: Calendars to use for holidays
    :param week_mask: Which days are considered weekends (defaults to Saturday and Sunday)
    :return: True/False if dates is a single date. A tuple indicating True/False for each date if dates is an iterable

    **Examples**

    >>> import datetime as dt
    >>> is_business_day(dt.date.today())
    >>> is_business_day(dt.date(2019, 7, 4), calendars=('NYSE',))
    """
    calendar = GsCalendar.get(calendars)
    res = np.is_busday(dates, busdaycal=calendar.business_day_calendar(week_mask))
    return tuple(res) if isinstance(res, np.ndarray) else res
Exemplo n.º 29
0
def gen_cal(start_date='1984-12-31', end_date='2025-12-31'):
    busday_cal = get_cal(start_date, end_date)
    s_date = np.datetime64(start_date)
    e_date = np.datetime64(end_date)
    day_num = -1
    busday_num = -1
    while s_date <= e_date:
        day_num += 1
        ibd = -1
        if np.is_busday(s_date, busdaycal=busday_cal):
            busday_num += 1
            ibd = 1
        res = ibd * ((busday_num << 16) | day_num)
        sql_cmd = "INSERT INTO calendar VALUES ('{0:s}', {1:d})".format(
            str(s_date), res)
        stxdb.db_write_cmd(sql_cmd)
        if day_num % 1000 == 0:
            print('Inserted {0:s}'.format(str(s_date)))
        s_date += np.timedelta64(1, 'D')
Exemplo n.º 30
0
 def isTradingDay(self, aDatetime):
     """
     Check if a datetime is a trading day based on marketName
     output:
         True: It is a trading day.
     """
     # print(__name__ + '::isTradingDay: %s' % (aDatetime,))
     aDate = convert_datetime_to_date(aDatetime)
     if aDate in self._isTradingDaySet:
         return True
     if aDate in self._notTradingDaySet:
         return False
     if np.is_busday(aDate):
         ans = not (np.datetime64(aDate)
                    in self._marketCalendar.holidays().holidays)
     else:
         ans = False
     if ans:
         self._isTradingDaySet.add(aDate)
     else:
         self._notTradingDaySet.add(aDate)
     return ans
Exemplo n.º 31
0
    def RioGrandeDoSul(self):

        holidays2020 = np.array(['2020-01-01','2020-02-24','2020-02-25','2020-04-10','2020-04-21','2020-05-01','2020-06-11','2020-06-12','2020-09-07','2020-09-20','2020-10-12','2020-11-02','2020-11-15','2020-11-20','2020-12-08','2020-12-24','2020-12-25','2020-12-30'],dtype='datetime64')
        cadernos = ['0','5','7','6','8']

        self.__log("Data de inicio e fim da pesquisa:","green")

        dataInit,dataFim = self.__askDate()
        
        start = np.datetime64(dataInit)
        end = np.datetime64(dataFim)

        date = start

        e='RS'

        while date <= end:

            if np.is_busday(date,holidays=holidays2020):

                edicao = self.__EdicaoRS(date)

                

                for c in cadernos:
                    nomeArquivo = "Diario-"+str(date)+"caderno-"+c+".pdf"
                    fileUrl ="https://www.tjrs.jus.br/servicos/diario_justica/download_edicao.php?tp="+c+"&ed="+edicao
                    diretorio = e+"/"+c
                    downloadFile(fileUrl,nomeArquivo,diretorio)
                    print("Download:"+nomeArquivo)


            
            date = date + np.timedelta64(1,'D')

        print("Arquivos Baixados")
#Sigma_no2_temp = functions.xcovmat(xcf_no2_temp, time[0:24*7], time[0:24*7])
#
#plt.figure(figsize=(5,4))
#plt.imshow(Sigma_no2_temp, cmap='gray')
#plt.colorbar()
#plt.xticks(np.arange(0, 24*7, 24))
#plt.yticks(np.arange(0, 24*7, 24))
#plt.xlabel(r'Time (hours)')
#plt.ylabel(r'Time (hours)')

# =============================================================================
# Meteorology data
# =============================================================================
hour = 11
time_date = time.astype('datetime64[D]')
time_busyday = np.is_busday(time_date)

this_no2 = no2[0][time_busyday]
this_no2 = this_no2[hour:-1:24]
index = this_no2 != 0
this_no2 = this_no2[index]
this_no2 = pt_no2.transform(this_no2.reshape(-1, 1))

this_temp = meteo[2][time_busyday]
this_temp = this_temp[hour:-1:24]
this_temp = this_temp[index]

plt.figure(figsize=(4, 4))
plt.hexbin(this_no2, this_temp.reshape(-1, 1), gridsize=(10, 10), cmap='gray')
plt.xlim(-2, 3)
plt.ylim(-15, 30)
Exemplo n.º 33
0
 def onOffset(self, dt):
     day64 = self._to_dt64(dt).astype("datetime64[D]")
     return np.is_busday(day64, busdaycal=self.busdaycalendar)
    print shop_id
    not_work_days= []
    file_name = 'flow_per_shop/'+str(shop_id)+'.csv'
    shop_file = open(file_name,'rb')
    info = pd.read_csv(shop_file)
    info['target_dates'] = info['target_dates'].astype(str)
    dates = info['target_dates'].values
    flow = info['count'].values
    count = 0
    for i in dates:
        # print i
        # print count
        count +=1
        # print ((not np.is_busday(np.datetime64(i)) and not is_exchangeday(i)) or is_holiday(i))
        # print ''
        not_work_days.append(((not np.is_busday(np.datetime64(i)) and not is_exchangeday(i)) or is_holiday(i)))
    not_work_days = np.array(not_work_days,dtype=int)


    total_not_workday = not_work_days.sum()
    # print total_not_workday
    total_workday = not_work_days.shape[0] - total_not_workday
    # print total_workday

    # show how does it change the customer flow for hoilidays (not work days)
    flow_not_work_days = flow * not_work_days
    print flow_not_work_days.sum()/total_not_workday

    flow_work_days = flow * (1-not_work_days)
    print flow_work_days.sum()/total_workday
    relation = float(float(flow_not_work_days.sum())/float(total_not_workday))/float(float(flow_work_days.sum())/float(total_workday))
Exemplo n.º 35
0
def filter_weekends(rows, include):
    """Either only include weekends or entirely exclude them."""
    return [row for row in rows if include ^
            numpy.is_busday(time.datetime_from_row(row).date())]