In spring batch processor wait one process to finish handler all data then execute next process - spring-batch

In the process of using spring batch, I have a requirement to read the excel file, complete the statistics of one of the columns, and then use the value of one of the columns divided by the statistical result.Examples are as follows
input:
name price
a 10
b 20
c 30
ouput:
name price proportion
a 10 1/6
b 20 1/3
c 30 1/2

I can suggest you to go with two steps :
The first one (tasklet) who calculate the sum of all the prices and register the result in the jobExecutionContext
And the second one (chunk) to re read the file and write the proportion column with the sum calculated in the first step.

Related

Repeat date sequence in Excel

I would like to ask how to create the sequence formula in order to repeate a date 10 times and do it for the whole year.
For example starting from 01/01/2022 to copy this date 10x then for 02/01/2022 to copy it 10x and so on. I started to use following formula for sequence:
=DATE(SEQUENCE(10,1,Year(B1),Month(B1),day(B1))
where B1 is 01/01/2022 and day and month are copied 10 times but the year is changing. Is there a way to do it to have the year same as well?
Thanks in advance.
You can take advantage of the fact that a date in excel is, conveniently, an integer number, and do it like that:
=INT((ROW(B1)-1)/10) + $B$1
That'll repeat the date entered in B1 10 times and than switch to next day, using the row number as a guide (so if you are not on the first row, you may need to add + X to the formula, where x is the row offset).
(Actual raw integer shown in D column for illustration, repeating every 3 rows instead of 10 to keep the screenshot smaller)

How to use only certain number of rows per category for calculation?

I do a simple project where I calculate how many times a ball in casino roulette game lands in each pocket after after 20000 spins.
I have data for 2 different roulette tables with approx 10k spin results for each. I count a number of occurrences of each result which is fine.
The problem arises when I want to limit the calculation to lets say 5k results (rows of data) for each category (Roulette name in this case) and see how many times the ball land in each pocket after 5k spins.
How do I limit how many rows of data per each category do I pass to COUNT() function?
Example of my wb as an img
Try this:
You will have to add a pk field for each of your results so your pk will be 1-10000 or however many records you have.
Parameter Setup:
Choose pk from the Set From Field options
Create a calculated field named N Results
N Results:
IF (pk - 1) < [View for N Results] THEN [result] END
Add N Results to your filter shelf and Exclude NULL. Show View for N Results parameter and type in a value. Your grand total should now equal the parameter value.
Final Layout:
Let me know how that turns out.

How do I loop a portfolio return calculation for multiple periods in matlab?

I have the following data/sets (simplified version to make the example clear):
3*10 matrix of stocks identified by a number for a given period (3 stocks (my portfolio) in rows * by 10 days (in columns) named indexBest.
10*10 matrix of returns for each period for each security in my universe named dailyret (my universe of stocks is 10).
I want to create a loop where I am able to calculate the sum returns of each portfolio for each period into one matrix ideally 1*10 or 10*1 (returns * date or vice versa).
I have done this for a single period for a portfolio, see below: but I want to be able to automate this process instead of doing all this 10* over for each portfolio for each period. Please help!
Portfolio_1_L= indexBest(:,1); %helps me get the portfolio constituents for period one (3 stocks basically).
Returns_1_L= dailyret(Portfolio_1(:,1));%to calculate returns of the portfolio for period 1 I have referenced the extraction of returns to the portfolio constituents.
Sum_ret_Port_1_L=sum(Returns_1_L); %sum return of the portfolio for period one
How do I loop this process for all other 9 periods?
Use a for loop and use the index variable in place of hardcoded 1 in your example code. Also index the output to store the result for each day.
for day = 1:10
Portfolio_1_L = indexBest(:,day);
Returns_1_L = dailyret(Portfolio_1_L);
Sum_ret_Port_1_L(day) = sum(Returns_1_L);
end

Matlab: Tempo-Alignment according to Timestamps

May be it is so simple but I'm new to Matlab and not good in Timestamps issues in general. Sorry!
I have two different cameras each contains timestamps of frames. I read them to two arrays TimestampsCam1 and TimestampsCam2:
TimestampsCam1 contains 1500 records and the timestamps are in Microseconds as follows:
1 20931160389
2 20931180407
3 20931200603
4 20931220273
5 20931240360 ...
and TimestampsCam2 contains 1000 records and the timestamps are in Milliseconds as follows:
1 28275280
2 28315443
3 28355607
4 28395771
5 28435935 ...
The first camera starts capturing first and ends a bit later than the second camera. So what I need to do is to know exactly where a frame from first camera is captured at the same time (or nearly the same time) by the other camera. In other words, I want to align the two arrays(cameras) in time according to the timestamps. I want to get at the end two arrays of same size where each record is tempo-aligned to the corresponding record in the other array.
Many thanks to all!
Sam
Make sure they are in the same unit of measurement, e.g. microseconds
Create an index which contains all values, except duplicates, suppose this one is 2400 records long
Create two NaN vectors of length 2400 by putting the value (for example the framenumber) at the place where the index matches the timestamp
Now you have two aligned vectors with NaNs to pad them where required.

read and rewrite in matlab

How do I write a text file in the same format that it is read in MATLAB?
I looked and my question is almost the same as above question.
I want to read in a file which is 84641 x 175 long.
and i want a make a new .txt file with 84641 x 40 , deleteling rest of the columns.
I have 2 rewrite the dates n times. date is on first column in format 6/26/2010 and time on 2nd column in format ' 00:00:04'
when i use the code put in above question i keep getting the error
??? Error using ==> reshape
Product of known dimensions, 181,
not divisible into total number
of elements, 14812175.
Error in ==>
write at
data = reshape(data{1},N+6,[])';
when i comment this it has error in printf statements for date and data write.
Any ideas??
thanks
As the author of the accepted answer in the question you link to, I'll try to explain what I think is going wrong.
The code in my answer is designed to read data from a file which has a date XX/XX/XXXX in the first column, a time XX:XX:XX in the second column, and N additional columns of data.
You list the number of elements in data as 14812175, which is evenly divisible by 175. This implies that your input data file has 2 columns for the date and time, then 169 additional columns of data. This value of 169 is what you have to use for N. When the date and time columns are read from the input file they are broken up into 3 columns each in data (for a total of 6 columns), which when added to the 169 additional columns of data gives you 175.
After reshaping, the size of data should be 84641-by-175. The first 6 columns contain the date and time values. If you want to write the date, the time, and the first 40 columns of the additional data to a new file, you would only have to change one line of the code in my answer. This line:
fprintf(fid,', %.1f',data(i,7:end)); %# Output all columns of data
Should be changed to this:
fprintf(fid,', %.1f',data(i,7:46)); %# Output first 40 columns of data