Changes the calculation of majority-methods
- Only one method for calculation. - Only in case of 'simple majority' a '1' will be added to the rounded result.
This commit is contained in:
parent
5af32999ab
commit
2a66a3233d
@ -33,6 +33,18 @@ export interface MajorityMethod {
|
||||
calc: (base: number) => number | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to round up the passed value of a poll.
|
||||
*
|
||||
* @param value The calculated value of 100%-base.
|
||||
* @param addOne Flag, if the result should be increased by 1.
|
||||
*
|
||||
* @returns The necessary value to get the majority.
|
||||
*/
|
||||
export const calcMajority = (value: number, addOne: boolean = false) => {
|
||||
return Math.ceil(value) + (addOne ? 1 : 0);
|
||||
};
|
||||
|
||||
/**
|
||||
* List of available majority methods, used in motion and assignment polls
|
||||
*/
|
||||
@ -40,26 +52,17 @@ export const PollMajorityMethod: MajorityMethod[] = [
|
||||
{
|
||||
value: 'simple_majority',
|
||||
display_name: 'Simple majority',
|
||||
calc: base => {
|
||||
const q = base * 0.5;
|
||||
return Number.isInteger(q) ? q + 1 : Math.ceil(q);
|
||||
}
|
||||
calc: base => calcMajority(base * 0.5, true)
|
||||
},
|
||||
{
|
||||
value: 'two-thirds_majority',
|
||||
display_name: 'Two-thirds majority',
|
||||
calc: base => {
|
||||
const q = (base / 3) * 2;
|
||||
return Number.isInteger(q) ? q + 1 : Math.ceil(q);
|
||||
}
|
||||
calc: base => calcMajority((base / 3) * 2)
|
||||
},
|
||||
{
|
||||
value: 'three-quarters_majority',
|
||||
display_name: 'Three-quarters majority',
|
||||
calc: base => {
|
||||
const q = (base / 4) * 3;
|
||||
return Number.isInteger(q) ? q + 1 : Math.ceil(q);
|
||||
}
|
||||
calc: base => calcMajority((base / 4) * 3)
|
||||
},
|
||||
{
|
||||
value: 'disabled',
|
||||
|
@ -123,19 +123,8 @@ export class MotionPollService extends PollService {
|
||||
if (!baseNumber) {
|
||||
return undefined;
|
||||
}
|
||||
let result: number;
|
||||
const calc = PollMajorityMethod.find(m => m.value === method);
|
||||
if (calc && calc.calc) {
|
||||
result = calc.calc(baseNumber);
|
||||
} else {
|
||||
result = null;
|
||||
}
|
||||
// rounding up, or if a integer was hit, adding one.
|
||||
if (result % 1 !== 0) {
|
||||
return Math.ceil(result);
|
||||
} else {
|
||||
return result + 1;
|
||||
}
|
||||
return calc && calc.calc ? calc.calc(baseNumber) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user