Cron: every 44th day of the year - cron

How to compose a cron string for each some day number of year, for instance, each 44th day or each 256th day of year?
0 0 44 * * doesn't work

Related

Can i use TextSplit with Find formula?

I am making a table up that will sum all matches of a company found within a specific time period. I need to also exclude certain months if they are inserted into a cell as mm/yy. Excluding one month is fine but when i type 10/22, 11/22, it will sum everthing. THe below code is what i am using with U$4 being the end of a month minus the tracking period which is 90 days. Note that the Raw Data that it is reading from only goes to end of November.
=IF([#[Company Name]]="","",SUM(IF(ISNUMBER(SEARCH([#[Company Name]],RawData[Description]))=TRUE,IF(RawData[Home]=XLOOKUP($D$1,HomeList[Home Code],HomeList[Home]),IF(RawData[Source]="Spend Money",IF(RawData[Date]<=U$4,IF(RawData[Date]>=U$4-[#[Tracking period (Days)]],1,0)))))))
With one date inserted which is correct:
28/Feb 31/Mar 30/Apr 31/May 30/Jun 31/Jul 31/Aug 30/Sep 31/Oct 30/Nov 31/Dec 31/Jan
Exclude Company Name Tracking period (Days) Month 1 Month 2 Month 3 Month 4 Month 5 Month 6 Month 7 Month 8 Month 9 Month 10 Month 11 Month 12
11/22 CLH 90 0 0 0 0 0 0 0 1 2 2 1 0
With multiple months inserted which is incorrect:
28/Feb 31/Mar 30/Apr 31/May 30/Jun 31/Jul 31/Aug 30/Sep 31/Oct 30/Nov 31/Dec 31/Jan
Exclude Company Name Tracking period (Days) Month 1 Month 2 Month 3 Month 4 Month 5 Month 6 Month 7 Month 8 Month 9 Month 10 Month 11 Month 12
10/22,11/22 CLH 90 0 0 0 0 0 0 0 2 3 8 6 5
Expected if multiple months as it has found one match for September so counts it
28/Feb 31/Mar 30/Apr 31/May 30/Jun 31/Jul 31/Aug 30/Sep 31/Oct 30/Nov 31/Dec 31/Jan
Exclude Company Name Tracking period (Days) Month 1 Month 2 Month 3 Month 4 Month 5 Month 6 Month 7 Month 8 Month 9 Month 10 Month 11 Month 12
10/22,11/22 CLH 90 0 0 0 0 0 0 0 1 1 1 0 0
Had to use MATCH with the TEXTSPLIT for it to work
=IF([#[Company Name]]="","",SUM(IF(ISNUMBER(SEARCH([#[Company Name]],RawData[Description]))=TRUE,IF(RawData[Home]=XLOOKUP($D$1,HomeList[Home Code],HomeList[Home]),IF(RawData[Source]="Spend Money",IF(RawData[Date]<=S$4,IF(RawData[Date]>=S$4-[#[Tracking period (Days)]],IF(ISNUMBER(MATCH(RawData[Find Date],TEXTSPLIT([#Exclude],","),)),0,1))))))))

how to Get week number from specified year date in python?

I have a time-series data and i want to get the week number from the initial date
date
20180401
20180402
20180902
20190130
20190401
Things Tried
Code
df["date"]= pd.to_datetime(df.date,format='%Y%m%d')
df["week_no"]= df.date.dt.week
But the week getting reset in 2019 results in getting a common week number of 2018.
is there anything we can do in it ??
You can use this function that will calculate the difference between two days in weeks:
def Wdiff(fromdate, todate):
d = pd.to_datetime(todate) - pd.to_datetime(fromdate)
return int(d / np.timedelta64(1, 'W'))
You can create a datetime object with the specified date, then retrieve the week number using the isocalendar method:
import datetime
myDate = datetime.date(2018, 4, 1)
week = myDate.isocalendar()[1]
print(week)
You could then calculate the total number of remaining weeks in 2018, then add the total number of weeks in each year in between, and finally add the week number of the current date.
For example, this code would print the number of weeks from the 1st of April 2018 to the 6th May 2020:
import datetime
myDate = datetime.date(2018, 4, 1)
currentDate = datetime.date(2020, 5, 6)
weeks = datetime.date(myDate.year, 12, 28).isocalendar()[1] -
myDate.isocalendar()[1]
for i in range(myDate.year, currentDate.year):
weeks += datetime.date(i, 12, 28).isocalendar()[1]
weeks += currentDate.isocalendar()[1]
print(weeks)
Note that because of the way isocalendar works, the 28th of December will always be in the last week of the given year.
The ISO year consists of 52 or 53 full weeks, and where a week starts on a Monday and ends on a Sunday. The first week of an ISO year is the first (Gregorian) calendar week of a year containing a Thursday. This is called week number 1, and the ISO year of that Thursday is the same as its Gregorian year.
You can get more information about isocalendar here: https://docs.python.org/3/library/datetime.html
To get the week number, but as a 2-digit string (with leading zero),
you can run:
df['week_no'] = df.date.dt.strftime('%W')
The result, for slightly extended source data is:
date week_no
0 2018-04-01 13
1 2018-04-02 14
2 2018-09-02 35
3 2018-12-30 52
4 2018-12-31 53
5 2019-01-01 00
6 2019-01-02 00
7 2019-01-03 00
8 2019-01-04 00
9 2019-01-05 00
10 2019-01-06 00
11 2019-01-07 01
12 2019-01-30 04
13 2019-04-01 13
Note that the last day of 2018 (monday) has week No == 53 and "initial" days
in 2019 (up to 2019-01-06 - Sunday) have week No == 00.
If you want this column as int, append .astype(int) to the above code.

applying a function rowwise inside mutate(dplyr)

I have the below data where Duration captures number of years in the same house, for each household.
Input df:
House_ID Duration
H29937 30 YEAR
H2996 30 YEAR
H156 25 YEAR
H10007 5 MONTH
I am trying to get the duration in months with the below query: If the second part of extracted string is YEAR, convert the number in duration to months by multiplying it with 12,
else just take the numeric part of Duration
info_df <- mutate(info_df,
residence_Months = ifelse(str_split(Duration," ",2)[[1]][2] == "YEAR",
as.numeric(str_split(Duration," ",2)[[1]][1])*12,
as.numeric(str_split(Duration," ",2)[[1]][1])))
Expected output df:
Agent_Code Duration Residence_Months
S1299317 30 YEAR 360
S1299622 30 YEAR 360
S1299656 25 YEAR 300
S1300067 5 MONTH 5
However, the code above, gives the same value for all rows as 360.
I am not sure where the error is occuring. Can someone please help me with this?
Note : I have tried the rowwise option as pointed out in other posts but to no avail.
Depending on your full data set, this may be better achieved with the lubridate package, but taking into account your example, you can do:
library(dplyr)
library(tidyr)
df <- tibble(House_ID = c("H29937", "H2996", "H156", "H10007"),
Duration = c("30 YEAR", "30 YEAR", "25 YEAR", "5 MONTH"))
df %>%
separate("Duration", c("duration", "unit")) %>%
mutate(duration = as.integer(duration),
Residence_Months = ifelse(unit == "YEAR", duration * 12, duration))
#> # A tibble: 4 x 4
#> House_ID duration unit Residence_Months
#> <chr> <int> <chr> <dbl>
#> 1 H29937 30 YEAR 360
#> 2 H2996 30 YEAR 360
#> 3 H156 25 YEAR 300
#> 4 H10007 5 MONTH 5
Created on 2019-07-18 by the reprex package (v0.3.0)

Sorting the time format in shell script

I have a file containing alerts occurence time. I want to sort those in ascending order. Can you please guide me about this.
Sample time format.
1 day, 19 hours
3 weeks
4 weeks, 1 day
2 minutes
1 month, 1 week
10 hours, 36 minutes
4 weeks, 1 day
4 weeks, 1 day
13 minutes
5 hours, 16 minutes
1 hour, 53 minutes
3 hours, 18 minutes
21 hours, 42 minutes
18 hours, 49 minutes
21 hours, 43 minutes
Maybe not super elegant, but straight forward in Python:
#!/usr/bin/env python
import operator
# 1 month = 28-31 days and 4 weeks = 28 days, so month is kept separate
time_in_seconds = {
'week': 7*24*60*60,
'day': 24*60*60,
'hour': 60*60,
'minute': 60,
'second': 1
}
if __name__ == '__main__':
times = []
with open('sample_time.txt', 'r') as f:
for line in f.read().split('\n'):
months = 0
seconds = 0
try:
for pair in line.split(', '):
num, denum = pair.split(' ')
if denum.startswith('month'):
months += int(num)
else:
seconds += time_in_seconds[denum.rstrip('s')]*int(num)
times.append([months, seconds, line])
except:
pass
sorted_times = sorted(times, key=operator.itemgetter(0,1))
for line in map(operator.itemgetter(2), sorted_times):
print(line)
It assumes your file is called sample_time.txt.

Select Data based on more than one weekday name in Python

I am trying to get data for weekday Sunday and Monday, but it only give me one day's data. I can find answer for one weekday name from a question asked by somebody.
Below are the code:
import pandas as pd
df=pd.DataFrame({'CustomerID':[1,2,3,4,5,6,7,8,9,10],
'PurchaseDate':['2007-5-7','2007-6-7','2007-7-7','2007-8-7','2007-9-9','2007-10-7',
'2007-11-7','2007-12-7','2008-1-7','2008-2-7' ],
'OrderQuantity':[1,1,1,1,1,1,1,1,1,1]})
df['PurchaseDate']=pd.to_datetime(df.PurchaseDate)
df.dtypes
df.PurchaseDate.dt.weekday_name.value_counts()
df1=df[(df.PurchaseDate.dt.weekday_name==('Sunday' and 'Monday'))]
The result I got is as in the picture below:
How would I get data for Sunday and Monday?
Use Series.isin if want weekday_name Sunday OR Monday - each date cannot be Sunday and also Monday:
df1=df[(df.PurchaseDate.dt.weekday_name.isin(['Sunday','Monday']))]
print (df1)
CustomerID PurchaseDate OrderQuantity
0 1 2007-05-07 1
4 5 2007-09-09 1
5 6 2007-10-07 1
8 9 2008-01-07 1
Verify:
print (df.PurchaseDate.dt.weekday_name)
0 Monday
1 Thursday
2 Saturday
3 Tuesday
4 Sunday
5 Sunday
6 Wednesday
7 Friday
8 Monday
9 Thursday
Name: PurchaseDate, dtype: object

Resources