I have an excel file which contain data like this:-
Prod
Work
Vaction
Year
2022
2022
2023
2022
2022
2023
2022
Month
10
11
12
10
11
12
10
Name
Business?
Exclusive?
Oct
Nov
Dec
Oct
Nov
Dec
Oct
Robert
Yes
No
100
100
100
150
150
150
1.1
Maria
No
Yes
75
75
50
25
25
25
1
and I want to convert this table into this form:
Name
Business?
Exclusive?
Year
Month
Prod
Work
Vacation
Robert
Yes
No
2022
Oct
100
150
1.1
Maria
No
Yes
2022
Nov
100
150
1
Robert
No
Yes
2023
Dec
100
150
1
Maria
No
Yes
2023
Dec
50
150
1
With the help of python pandas library. I am struggling with this problem from so many days. Please Help!
I have a use case where i want to run a monthly job starting at 2:30 PM for every first friday of every month starting from january.
Cron expression which i use :-
0 30 14 ? 1/1 6#1
This works absolutely fine.
Sample fire times : -
Fri Jan 03 14:30:00 UTC 2020
Fri Feb 07 14:30:00 UTC 2020
Fri Mar 06 14:30:00 UTC 2020
Fri Apr 03 14:30:00 UTC 2020
Fri May 01 14:30:00 UTC 2020
Fri Jun 05 14:30:00 UTC 2020
Fri Jul 03 14:30:00 UTC 2020
But if i use the same expression and use December as the starting month
0 30 14 ? 12/1 6#1
This starts failing :-
Fri Dec 04 14:30:00 UTC 2020
Fri Dec 03 14:30:00 UTC 2021
Fri Dec 02 14:30:00 UTC 2022
Fri Dec 01 14:30:00 UTC 2023
This kind of becomes yearly.
I don't see any issue with the expression i am using.How do we resolve this or a workaround ?
IMO this mean every 12 month = every December and it is the same as
0 30 14 ? 12 6#1
and your first record is equal to
0 30 14 ? * 6#1
(star mean every month)
I have a simple date generator code where it selects a date from now to 120 days.
However, I want my dates to be a little more clever. I only want it to select from months May, June, July and August only.
So if the current date is before May, then select a date at random within one of those four months for this year.
Else if the current date is past June, the select a date from any of the 4 months for next year.
How can this be written in groovy?
Below is the current date generator.
//Defines Start and End Dates for holiday departure date search
Random random = new Random();
date = new Date()
def startDate = date + random.nextInt(100 + 120)
sDate = startDate.format("yyyy-MM-dd")
testRunner.testCase.testSuite.setPropertyValue('arrivaldate', sDate);
Here is the Groovy Script which does what you intended to do.
Note that below script would throw an error if current date falls in the date range which is missing in the question.
Not implemented for the days between 1st May to 30th June
Please follow the comments inline.
import groovy.time.TimeCategory
def dateFormat = 'yyyy-MM-dd'
def getNumberInRange = { min, max -> new Random().nextInt(max + 1 - min) + min }
def isTodayBeforeMay = { Calendar.MONTH < 5 }
def isTodayAfterJune = { Calendar.MONTH > 6 }
//Get the number of days between today and given date
def getDifferenceDays = { targetDate, closure ->
def strDate = closure (targetDate)
def futureDate = new Date().parse(dateFormat, strDate)
TimeCategory.minus(futureDate, new Date()).days
}
//Get the offset between today and max date i.e.,31 august
def getOffSetDays = { date ->
//Need to change the date range if needed.
//As per OP, May to August is mentioned below
def max = getDifferenceDays(date) { "${it[Calendar.YEAR]}-08-31" }
def min = getDifferenceDays(date) { "${it[Calendar.YEAR]}-05-01" }
getNumberInRange(min, max)
}
def now = new Date()
def nextYearNow = now.updated(year: now[Calendar.YEAR] + 1)
def selected
def finalDate
println "Today : $now"
println "Next year same date : $nextYearNow"
if (isTodayBeforeMay()) {
selected = now
} else if (isTodayAfterJune()) {
selected = nextYearNow
} else {
//It is not mentioned what should happened for the mentioned period by OP
throw new Error("Not implemented for the days between 1st May to 30th June")
}
def offset = getOffSetDays(selected)
//Add the offset days to now
use(TimeCategory) {
finalDate = now + offset.days
}
println "Final future date is : $finalDate"
println "Final future date is(formatted) : ${finalDate.format(dateFormat)}"
//set the date at test case level property
context.testCase.setPropertyValue('NEXT_DATE', finalDate.format(dateFormat))
In order to get the date evaluated
Use ${#TestCase#NEXT_DATE} in requests
Use context.expand('${#TestCase#NEXT_DATE}') in groovy script (string is returned)
NOTE: println can be replaced with log.info in the above script if you want to see the output in soapui tool. Otherwise, print statements are shown int log files.
You can quickly try the above script online Demo
Output:
(edited after clarification by op)
def getRandomDate(Date now, Random random) {
def year = now.year + (now.month > 5 ? 1 : 0)
def allDates = (new Date(year, 4, 1)..new Date(year, 7, 31))
def allowedDates = allDates.findAll { now < it }
allowedDates[random.nextInt(allowedDates.size())]
}
// example usage
def now = new Date()
def random = new Random()
100.times {
def today = now + it*3
def randomDate = getRandomDate(now+it*3, random)
println "today: ${today.format('yyyy MMM dd')} ==> random date: ${randomDate.format('yyyy MMM dd')}"
}
an execution of the above prints out something along the lines of:
today: 2017 Feb 25 ==> random date: 2017 Jul 21
today: 2017 Feb 28 ==> random date: 2017 Aug 03
today: 2017 Mar 03 ==> random date: 2017 Jun 21
today: 2017 Mar 06 ==> random date: 2017 May 21
today: 2017 Mar 09 ==> random date: 2017 Jun 05
today: 2017 Mar 12 ==> random date: 2017 May 03
today: 2017 Mar 15 ==> random date: 2017 Aug 04
today: 2017 Mar 18 ==> random date: 2017 Aug 17
today: 2017 Mar 21 ==> random date: 2017 Jul 09
today: 2017 Mar 24 ==> random date: 2017 Jul 11
today: 2017 Mar 27 ==> random date: 2017 Jul 16
today: 2017 Mar 30 ==> random date: 2017 Aug 09
today: 2017 Apr 02 ==> random date: 2017 Jul 09
today: 2017 Apr 05 ==> random date: 2017 Aug 05
today: 2017 Apr 08 ==> random date: 2017 Jul 19
today: 2017 Apr 11 ==> random date: 2017 Aug 10
today: 2017 Apr 14 ==> random date: 2017 Jun 21
today: 2017 Apr 17 ==> random date: 2017 Aug 03
today: 2017 Apr 20 ==> random date: 2017 May 02
today: 2017 Apr 23 ==> random date: 2017 Jul 04
today: 2017 Apr 26 ==> random date: 2017 Jun 13
today: 2017 Apr 29 ==> random date: 2017 May 02
today: 2017 May 02 ==> random date: 2017 Aug 01
today: 2017 May 05 ==> random date: 2017 Aug 07
today: 2017 May 08 ==> random date: 2017 Aug 20
today: 2017 May 11 ==> random date: 2017 Jun 29
today: 2017 May 14 ==> random date: 2017 May 18
today: 2017 May 17 ==> random date: 2017 Jun 11
today: 2017 May 20 ==> random date: 2017 May 26
today: 2017 May 23 ==> random date: 2017 Jul 06
today: 2017 May 26 ==> random date: 2017 Aug 29
today: 2017 May 29 ==> random date: 2017 Jun 02
today: 2017 Jun 01 ==> random date: 2017 Jun 09
today: 2017 Jun 04 ==> random date: 2017 Jun 07
today: 2017 Jun 07 ==> random date: 2017 Aug 09
today: 2017 Jun 10 ==> random date: 2017 Aug 02
today: 2017 Jun 13 ==> random date: 2017 Aug 04
today: 2017 Jun 16 ==> random date: 2017 Aug 09
today: 2017 Jun 19 ==> random date: 2017 Jun 22
today: 2017 Jun 22 ==> random date: 2017 Aug 16
today: 2017 Jun 25 ==> random date: 2017 Aug 13
today: 2017 Jun 28 ==> random date: 2017 Jul 05
today: 2017 Jul 01 ==> random date: 2018 Jun 18
today: 2017 Jul 04 ==> random date: 2018 Jul 29
today: 2017 Jul 07 ==> random date: 2018 Jul 13
today: 2017 Jul 10 ==> random date: 2018 Jul 26
today: 2017 Jul 13 ==> random date: 2018 Aug 23
today: 2017 Jul 16 ==> random date: 2018 Aug 12
today: 2017 Jul 19 ==> random date: 2018 Aug 24
today: 2017 Jul 22 ==> random date: 2018 Aug 20
today: 2017 Jul 25 ==> random date: 2018 Jul 28
today: 2017 Jul 28 ==> random date: 2018 Jul 29
today: 2017 Jul 31 ==> random date: 2018 May 02
today: 2017 Aug 03 ==> random date: 2018 Jul 19
today: 2017 Aug 06 ==> random date: 2018 Aug 05
today: 2017 Aug 09 ==> random date: 2018 Aug 28
today: 2017 Aug 12 ==> random date: 2018 Jul 16
today: 2017 Aug 15 ==> random date: 2018 Aug 04
today: 2017 Aug 18 ==> random date: 2018 May 30
today: 2017 Aug 21 ==> random date: 2018 May 02
today: 2017 Aug 24 ==> random date: 2018 May 01
today: 2017 Aug 27 ==> random date: 2018 May 10
today: 2017 Aug 30 ==> random date: 2018 May 04
today: 2017 Sep 02 ==> random date: 2018 Jun 30
today: 2017 Sep 05 ==> random date: 2018 May 05
today: 2017 Sep 08 ==> random date: 2018 Jul 27
today: 2017 Sep 11 ==> random date: 2018 Aug 14
today: 2017 Sep 14 ==> random date: 2018 Jul 15
today: 2017 Sep 17 ==> random date: 2018 Jul 12
today: 2017 Sep 20 ==> random date: 2018 Jul 24
today: 2017 Sep 23 ==> random date: 2018 Aug 28
today: 2017 Sep 26 ==> random date: 2018 Jul 26
today: 2017 Sep 29 ==> random date: 2018 Jun 27
today: 2017 Oct 02 ==> random date: 2018 Aug 15
today: 2017 Oct 05 ==> random date: 2018 Jun 27
today: 2017 Oct 08 ==> random date: 2018 Jun 01
today: 2017 Oct 11 ==> random date: 2018 Jun 12
today: 2017 Oct 14 ==> random date: 2018 Jun 06
today: 2017 Oct 17 ==> random date: 2018 Aug 02
today: 2017 Oct 20 ==> random date: 2018 May 05
today: 2017 Oct 23 ==> random date: 2018 Jun 15
today: 2017 Oct 26 ==> random date: 2018 Jun 05
today: 2017 Oct 29 ==> random date: 2018 Aug 12
today: 2017 Nov 01 ==> random date: 2018 Aug 29
today: 2017 Nov 04 ==> random date: 2018 May 15
today: 2017 Nov 07 ==> random date: 2018 Jul 03
today: 2017 Nov 10 ==> random date: 2018 Aug 16
today: 2017 Nov 13 ==> random date: 2018 Aug 21
today: 2017 Nov 16 ==> random date: 2018 May 06
today: 2017 Nov 19 ==> random date: 2018 Jul 15
today: 2017 Nov 22 ==> random date: 2018 Jul 03
today: 2017 Nov 25 ==> random date: 2018 Aug 15
today: 2017 Nov 28 ==> random date: 2018 Jul 29
today: 2017 Dec 01 ==> random date: 2018 May 06
today: 2017 Dec 04 ==> random date: 2018 Aug 31
today: 2017 Dec 07 ==> random date: 2018 May 12
today: 2017 Dec 10 ==> random date: 2018 May 01
today: 2017 Dec 13 ==> random date: 2018 Aug 31
today: 2017 Dec 16 ==> random date: 2018 Jul 17
today: 2017 Dec 19 ==> random date: 2018 Jul 24
Essentially we pick a random date out of a list of allowed dates.
Performance could be improved by not creating the allowedDates list on every call.
Some of the date methods are deprecated. If deprecations are important, you might want to use Calendar instead.
The groovy range .. operator on dates return a date range containing all the dates between the two given dates, inclusive.
I have left now external to the method to make testing easier and I have left random external to the method as I believe re-creating new instances of random on every call is detrimental to the quality of the random distribution generated.
Note 1: For dates between May 1st and June 30th, the problem definition is unclear. For these dates the code returns a random date from the current year, excluding past dates. I.e. on June 15th, the algorithm would return a random date from this year between June 16th and August 31st. On July 1st it would return a random date from next year, between May 1st and August 31st.
Note 2: Alternate version without deprecated date calls and using calendar:
import static java.util.Calendar.*
import java.util.GregorianCalendar as Cal
def getRandomDate(Date now, Random random) {
def cal = new Cal(time: now)
// use current year if current date is before july, otherwise next year
def year = cal.get(YEAR) + (cal.get(MONTH) > 5 ? 1 : 0)
def allDates = (new Cal(year, 4, 1).time..new Cal(year, 7, 31).time)
def allowedDates = allDates.findAll { now < it }
allowedDates[random.nextInt(allowedDates.size())]
}
I have a Values like
Month Price
Jan 10
Feb 20
Mar 30
............
Dec 50
I have a dropdown for selecting month
If user pickedup the month Feb
then the sum should be displayed as 30
Help me out ! tried a lot with excel function ended up with frustration
Very interesting idea.
Formula in B1 =SUM(INDIRECT("E1:E"&MATCH(A1,D:D,0)))
Hope this will help you.
A B C D E
Feb 30 Month Price
Jan 10
Feb 20
Mar 30
Apr 40
May 50
Jun 60
Jul 70
Aug 80
Sep 90
Oct 100
Nov 110
Dec 120
I have an excel 2007 file with data of weekly values for two years. I want to collate this into a cumulative monthly sum, but also bare in mind the year. For example, If I had the following dates:
6 Apr 13
13 Apr 13
20 Apr 13
27 Apr 13
4 May 13
.
.
.
.
.
12 Apr 14
19 Apr 14
26 Apr 14
3 May 14
10 May 14
17 May 14
24 May 14
.
.
.
.
14 Feb 15
21 Feb 15
28 Feb 15
7 Mar 15
14 Mar 15
21 Mar 15
28 Mar 15
And I wanted to get the summed totals for the following periods:
April 2013
May 2013
June 2013
July 2013
.
.
.
.
April 2014
May 2014
June 2014
.
.
.
January 2015
February 2015
March 2015
What would be the best way to go about doing so? I was thinking to use Sumifs, but was uncertain how well Month() and Year() play if the function was written like sumif(...Year(...Month(..))).
Assuming your data is in Cells A1:B15, with dates in column A and qaintity to be summed in Column B, you can try this:
=SUMPRODUCT((MONTH(A1:A15)=2)*(YEAR(A1:A15)=2014)*(B1:B15))
You can replace "2" with month of your choice and 2014 with desired year. Hope that helps.