Forum Discussion
Elvorin
13 years agoContributor
Component name:
Rate Multiplier
Developer:
Abhishek Dasgupta
Description:
Multiplies the rate of attached Generators (rate based) for easy load setting increase/decrease while keeping the load distribution ratio intact.
Source code:
Note:
This currently works only with rate based generators, i.e. Fixed, Random and Variance.
If multiplier is changed very rapidly and randomly, error might get thrown from the random generators due to a previously reported bug (viewtopic.php?f=12&t=12859)
As rate is a whole number, changing multiplier value back-n-forth may not bring the initial rate setting back due to rounding up/down operation done during rate value calculation.
Any suggestion to improve the component is most welcome.
Rate Multiplier
Developer:
Abhishek Dasgupta
Description:
Multiplies the rate of attached Generators (rate based) for easy load setting increase/decrease while keeping the load distribution ratio intact.
Source code:
/**
* Multiplies the rate of attached Generators (rate based) for easy load increase/decrease
* while keeping the load distribution ratio intact.
*
* @name Rate Multiplier
* @nonBlocking false
*/
import com.eviware.loadui.util.layout.DelayedFormattedString
import java.lang.Math
// inputs and outputs
createOutput('multiplierOutput', 'Multiplier', 'Multiply current rate with')
// properties
createProperty('multiplicationFactor', Long, 1) { newRate, oldRate ->
displayFactor.setArgs(multiplicationFactor.value)
if (oldRate == null) {
oldRate = storedRate
}
adjustRate(oldRate, newRate)
}
displayFactor = new DelayedFormattedString('x %d', 200, multiplicationFactor.value)
storedRate = multiplicationFactor.value
calculatedNewRate = 1;
calculatedNewUnit = 'Sec'
onRelease = {
displayFactor.release()
}
def adjustRate(oldRate, newRate) {
def connectedComponent
for (c in multiplierOutput.connections) {
connectedComponent = c.inputTerminal.terminalHolder
if (connectedComponent.category == 'generators') {
//Supports only the generators with 'rate' property
//Assumption is it will also have a 'unit' property with Sec, Min, Hour as possible values
if (connectedComponent.getProperty("rate") != null) {
def generatorRate = connectedComponent.getProperty("rate").value
def generatorUnit = connectedComponent.getProperty("unit").getStringValue()
calculateRateAndUnit(oldRate, newRate, generatorRate, generatorUnit)
connectedComponent.getProperty("rate").value = calculatedNewRate
connectedComponent.getProperty("unit").setValue(calculatedNewUnit)
}
}
}
}
def calculateRateAndUnit(oldRate, newRate, generatorRate, generatorUnit) {
//Convert rate to hour for easier calculation
def multiplyBy = 1;
if (generatorUnit == 'Sec') {
multiplyBy = (60 * 60)
} else if (generatorUnit == 'Min') {
multiplyBy = 60
}
calculatedNewUnit = 'Hour'
calculatedNewRate = (generatorRate * multiplyBy)
//Round rate
if (newRate > oldRate) {
calculatedNewRate = Math.ceil((calculatedNewRate * newRate) / oldRate)
} else {
calculatedNewRate = Math.floor((calculatedNewRate * newRate) / oldRate)
}
if (calculatedNewRate == 0) {
calculatedNewRate = 1
}
//Normalize
if ((calculatedNewRate % 60) == 0) {
calculatedNewUnit = 'Min'
calculatedNewRate = (calculatedNewRate / 60)
if ((calculatedNewRate % 60) == 0) {
calculatedNewUnit = 'Sec'
calculatedNewRate = (calculatedNewRate / 60)
}
}
}
// main layout
layout {
property(property:multiplicationFactor, label:'Multiplier', min:1)
separator(vertical:true)
box(widget:'display') {
node(label:'Multiplication Factor', fString:displayFactor, constraints:'wmin 75')
}
}
// compact layout
compactLayout {
box(widget:'display') {
node(label:'Multiplication Factor', fString:displayFactor)
}
}
// basic settings tab
settings(label:'Basic') {
property( property:multiplicationFactor, label:'Multiplication Factor')
}
Note:
Any suggestion to improve the component is most welcome.
Related Content
- 9 months ago
- 4 years ago
- 5 years ago
- 4 years ago
- 7 years ago
Recent Discussions
- 5 days ago
- 10 days ago