Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi,
I have this example:
"reste"=Voix/(supp+1)
for example, for code1: "number" to distribute =2
1) for "rest" = 584 / (2+1)=194.66
for "rest" = 840 / (3+1) =210
for "rest" = 863 / (3+1) =215.75 we assign a "Number"=1 -> Supp = Supp+1 ( because 215,75 is the max)
2) for "rest" = 584 / (2+1)=194.66
for "rest" = 840 / (3+1) =210 we assign a "Number"=1 -> Supp = Supp+1 ( because 210 is the max)
for "rest" = 863 / (3+1+1) =172.6
result:
code|Supp
1 | 2
1 | 4 (3+1)
1 | 4 (3+1)
and we repete for each group of code the same procedure precedent.
I try this code but il doesn't works
Can you share the code as text please? It is easier to try out that way 🙂
output_row.code = input_row.code;
output_row.number = input_row.number;
output_row.VOIX = input_row.VOIX;
output_row.supp = input_row.supp;
output_row.rest = input_row.rest;
String code = input_row.code;
int num = input_row.number;
//double reste =Double.valueOf(input_row.VOIX/(input_row.supp+1+1));
if( code.contains(context.current_code) ) {
context.to_distribute -= 1 ;
output_row.supp += ( 0 > context.to_distribute ? 0 : 1 );
context.reste= Double.valueOf(input_row.VOIX/(input_row.supp+1+1));
} else if (context.reste >= input_row.rest) {
context.current_code = input_row.code;
context.to_distribute = input_row.number - 1;
context.reste= Double.valueOf(input_row.VOIX/(input_row.supp+1+1));
output_row.supp += ( 0 > context.to_distribute ? 0 : 1 );
output_row.rest=context.reste;
}
The main problem you have is that you are assigning the output_row values at the very beginning. These are not normal variables. You should only assign these once, once you have calculated your values. You are also trying to increment output_row values, this is not ideal either.
Your IF conditions look a little confusing, but that could just be the logic you want. What if neither of the conditions are true? Do you require an "else"?
I have adjusted your code so that it will work. The logic may not be quite correct (as explained briefly above), but this will change the values when the conditions are met.
//output_row.code = input_row.code;
//output_row.number = input_row.number;
//output_row.VOIX = input_row.VOIX;
//output_row.supp = input_row.supp;
//output_row.rest = input_row.rest;
int VOIX = input_row.VOIX;
int supp = input_row.supp;
double rest = input_row.rest;
String code = input_row.code;
int number = input_row.number;
if( code.contains(context.current_code) ) {
context.to_distribute -= 1 ;
context.reste= ((double)VOIX)/(((double)supp)+1.0+1.0);
supp += ( 0 > context.to_distribute ? 0 : 1 );
output_row.supp = supp;
output_row.code = code;
output_row.number = number;
output_row.VOIX = VOIX;
output_row.rest=context.reste;
} else if (context.reste >= rest) {
context.current_code = code;
context.to_distribute = number - 1;
context.reste= ((double)VOIX)/(((double)supp)+1.0+1.0);
supp += ( 0 > context.to_distribute ? 0 : 1 );
output_row.supp = supp;
output_row.rest=context.reste;
output_row.code = code;
output_row.number = number;
output_row.VOIX = VOIX;
}
But my problem is that I can not apply the logic of my example. how can I distribute "number" each time on the value of the maximum "rest"? is that this java code is enough or I have to apply a loop?
I'm afraid I do not understand the logic. Your example does not give enough information as to why each of the equations take place? Maybe a simple example of an input table and expected output table would help? You have to remember that we do not have the business requirement or your understanding of what you are trying to achieve. A lot of the time I can infer from input to output (spotting the logical flow), but I just don't see it here I am afraid.
the input is :
code|number|rest|supp
1 |2 |150 |4
1 |2 |125 |1
1 |2 |110 |1
2 |3 |145 |0
2 |3 |130 |3
2 |3 |50 |1
2 |3 |10 |4
The output of the first transformation is :
1 |2 |150 |5
1 |2 |125 |2
1 |2 |110 |1
2 |3 |145 |1
2 |3 |130 |4
2 |3 |50 |2
2 |3 |10 |4
And you said :
"reste"=Voix/(supp+1)
what is "Voix" ?
You added :
for example, for code1: "number" to distribute =2
1) for "rest" = 584 / (2+1)=194.66 // where is 2 from ? is it because number=2 ?
for "rest" = 840 / (3+1) =210 // where is 3 from ?
for "rest" = 863 / (3+1) =215.75 // where is 3 from ?