Here's how I would write it in C.
if(x < 50 && x < 0.125y)
{
return 0;
}
else if(x < 50 && x >= 0.125y)
{
if(z >= 2a)
{
return 50;
}
}
else return b;
Here's my attempt, it's just a bunch of nested ifs...
IIf(([Est_Order_Qty]<50) And ([Est_Order_Qty]<0.125*[Quantity On Hand]),"0",IIf(([Est_Order_Qty]<50) And ([Est_Order_Qty]>=0.125*[Quantity On Hand]),IIf([Est_Order_Qty]<2*[Qty],"50",[Rounded_To_50])))
IIF((x < 50) AND (x < 0.125 * y), 0,
IIF((x < 50) AND (x >= 0.125 * y) AND (z >= 2 * a), 50,
b)
or with your attempt
IIf(([Est_Order_Qty] < 50) And
([Est_Order_Qty] < 0.125 * [Quantity On Hand]), "0",
IIf(([Est_Order_Qty] < 50) And
([Est_Order_Qty] >= 0.125 * [Quantity On Hand]),
IIf([Est_Order_Qty] < 2 * [Qty], "50", [Rounded_To_50]),
[Rounded_To_50])
)
Try Switch
SWITCH(
x < 50 AND x < 0.125y, 0,
x < 50 AND x >= 0.125y AND z >= 2a, 50,
TRUE, b)
If I understood your if statement correctly, then my answer came out to:
iif(x < 50 And x > 0.125y, "0", iif(x < 50 And x >= 0.125y, iif(2 >= 2a, 50, ""), b))
I believe this is it. Let me know.
Related
I have below code:
<image
id="wheel-bg"
class="wheel-bg"
:x="-width/2"
:y="-height/2"
href="images/wheel-bg.png"
:width="width"
:height="height"
filter="drop-shadow(black 0px 0px 1rem)"
#click="spin"
></image>
I have a data property "rotationState" which can be "false" or "true".
rotationState = false means #click event should fire and
rotationState = true means #click event should not fire
I tried
#click="spin && rotationState"
I also tried:
#click.stop="rotationState"
#click="spin"
and
:disabled="rotationState"
but above methods don't work because I think I have #click event on an <image></image> element.
What I am trying to achieve is basically,
container.on('click', null); this is the code that was used when I first wrote the code in jquery / js.
Jquery Spin function code
container.on("click", spin); //this code triggers spin in jquery
function spin(d) {
container.on("click", null); //this code disables multiple spin from happening
spinCount++;
// First 2 spins
if (spinCount < totalSpins) {
//get random number of rotations + get random degree for "No Win"
// 1 to 28 or 211 to 239 deg
if (Math.random() < 0.5) {
rotation = ((Math.floor(Math.random() * 1) + 3) * 360) + (Math.floor(Math.random() * 28) + 1);
} else {
rotation = ((Math.floor(Math.random() * 1) + 3) * 360) + (Math.floor(Math.random() * 28) + 211);
}
duration = 10000; // 10 seconds
// Third spin
} else if (spinCount == totalSpins) {
//get random number of rotations + get random degree for options other than "No Win" and "Free Apple Earpods"
//31 to 119 deg or 151 to 209 deg or 271 to 359
if (Math.random() < 0.7) {
rotation = ((Math.floor(Math.random() * 1) + 5) * 360) + (Math.floor(Math.random() * 88) + 31);
} else if (Math.random() > 0.3 && Math.random() <= 0.7) {
rotation = ((Math.floor(Math.random() * 1) + 5) * 360) + (Math.floor(Math.random() * 58) + 151);
} else {
rotation = ((Math.floor(Math.random() * 1) + 5) * 360) + (Math.floor(Math.random() * 88) + 271);
}
duration = 15000; // 15 seconds
// Spins more than 3
} else {
alert("No more spins left");
container.on("click", null);
return;
}
updateAttempts(spinCount);
updateSpins(totalSpins - spinCount);
//Get selected array element
var degSelected = (rotation % 360) % 360;
if (
(degSelected >= 91 && degSelected <= 120) ||
(degSelected >= 181 && degSelected <= 210) ||
(degSelected >= 331 && degSelected <= 360)
) {
selected = 11;
} else if (
(degSelected >= 1 && degSelected <= 30) ||
(degSelected >= 121 && degSelected <= 150) ||
(degSelected >= 181 && degSelected <= 210) ||
(degSelected >= 211 && degSelected <= 240)
) {
selected = 10;
}else if (
(degSelected >= 31 && degSelected <= 60) ||
(degSelected >= 151 && degSelected <= 180) ||
(degSelected >= 271 && degSelected <= 300)
) {
selected = 9;
}else if (degSelected >= 241 && degSelected <= 270) {
selected = 6;
}else if (
(degSelected >= 61 && degSelected <= 90) ||
(degSelected >= 301 && degSelected <= 330)
) {
selected = 4;
}
vis.transition()
.duration(duration)
.ease(d3.easeExpOut)
.attrTween("transform", rotTween)
.each("end", function () {
//set prize value
prize = data[selected].value;
id = data[selected].id;
if(spinCount == 3) {
alert('Your Voucher: ' + data[selected].label);
}else {
alert('Better luck next time');
}
oldrotation = rotation;
container.on("click", spin);
});
img2.transition()
.duration(duration)
.ease(d3.easeExpOut)
.attrTween("transform", rotTween)
}
You can set the function of #click, based on the state of rotationState as mentioned before:
#click="rotationState ? spin() : null"
I have created this if and else if statements. Flat, Vertical, Facedown, Right Side, and Left Side work... However, I am not sure why the Upside down is not working. Here is my code:
checkOrientation= () => {
let orientation = "unknown";
if (z > .8 && Math.abs(x) < .2 && Math.abs(y) < .2) orientation = "flat";
else if (y > .9 && Math.abs(x) < .2 &&Math.abs(z) < .2) orientation = "vertical";
if (x < .1 && Math.abs(y) < .1 && Math.abs(z) < .3) orientation = "right side";
else if (z < .01 && Math.abs(x) > .9 && Math.abs(y) < .05) orientation = "left side";
if (x > .01 && Math.abs(y) < .7 && Math.abs(z) < .05) orientation = "upside down";
else if (x > .01 && Math.abs (y) < .01 && Math.abs(z) > .01) orientation = "face down";
this.setState({orientation});
}
I implemented a calculator in my app using the method below but it seems to be coming up with errors
- (IBAction)calculate {
float x = ([textField1.text floatValue]);
if (x>=)
{
(x<=14000,x*0.0125);
(x<=30000,175+x-14000*0.015);
(x<=80000,415+x-30000*0.0175);
(x<=300000.1290+x-80000*0.035);
(x<=1000000,8990+x-300000*0.045);
(x<=3000000,40490+x-1000000*0.055);
}
}
I'm guessing here (because what you posted isn't C/C++/ObjC syntax):
- (IBAction)calculate {
float x = ([textField1.text floatValue]);
if (x <= 14000) {
x *= 0.0125;
} else if (x < 30000) {
x = ((x - 14000) * 0.015) + 175;
} else if (x < 80000) {
x = ((x - 30000) * 0.0175) + 415;
} else if (x < 300000) {
x = ((x - 80000) * 0.035) + 1290;
} else if (x < 1000000) {
x = ((x - 300000) * 0.045) + 8990;
} else if (x < 3000000) {
x = ((x - 1000000) * 0.055) + 40490;
}
}
How do you use the waveshapernode in the web audio api? particular the curve Float32Array attribute?
Feel free to look at an example here.
In detail, I create a waveshaper curve with this function:
WAAMorningStar.prototype.createWSCurve = function (amount, n_samples) {
if ((amount >= 0) && (amount < 1)) {
ND.dist = amount;
var k = 2 * ND.dist / (1 - ND.dist);
for (var i = 0; i < n_samples; i+=1) {
// LINEAR INTERPOLATION: x := (c - a) * (z - y) / (b - a) + y
// a = 0, b = 2048, z = 1, y = -1, c = i
var x = (i - 0) * (1 - (-1)) / (n_samples - 0) + (-1);
this.wsCurve[i] = (1 + k) * x / (1+ k * Math.abs(x));
}
}
Then "load" it in a waveshaper node like this:
this.createWSCurve(ND.dist, this.nSamples);
this.sigmaDistortNode = this.context.createWaveShaper();
this.sigmaDistortNode.curve = this.wsCurve;
Everytime I need to change the distortion parameter, I re-create the waveshaper curve:
WAAMorningStar.prototype.setDistortion = function (distValue) {
var distCorrect = distValue;
if (distValue < -1) {
distCorrect = -1;
}
if (distValue >= 1) {
distCorrect = 0.985;
}
this.createWSCurve (distCorrect, this.nSamples);
}
(I use distCorrect to make the distortion sound nicer, values found euristically).
You can find the algorithm I use to create the waveshaper curve here
I'm looking for an objective-c library or just the functions that can handle calculating the Wilson Score Interval explained here:
http://www.evanmiller.org/how-not-to-sort-by-average-rating.html
For reference, here's a Ruby implementation from the same source:
require 'statistics2'
def ci_lower_bound(pos, n, power)
if n == 0
return 0
end
z = Statistics2.pnormaldist(1-power/2)
phat = 1.0*pos/n
(phat + z*z/(2*n) - z * Math.sqrt((phat*(1-phat)+z*z/(4*n))/n))/(1+z*z/n)
end
Assuming the implementation for pnormaldist listed here is correct (i've copied it verbatim):
double pnormaldist(double qn)
{
double b[] = {1.570796288, 0.03706987906, -0.8364353589e-3, -0.2250947176e-3, 0.6841218299e-5, 0.5824238515e-5, -0.104527497e-5, 0.8360937017e-7, -0.3231081277e-8, 0.3657763036e-10, 0.6936233982e-12};
if(qn < 0.0 || 1.0 < qn)
return 0.0;
if(qn == 0.5)
return 0.0;
double w1 = qn;
if(qn > 0.5)
w1 = 1.0 - w1;
double w3 = -log(4.0 * w1 * (1.0 - w1));
w1 = b[0];
int i=1;
for(;i<11;i++)
w1 += b[i] * pow(w3,i);
if(qn > 0.5)
return sqrt(w1*w3);
return -sqrt(w1*w3);
}
double ci_lower_bound(int pos, int n, double power)
{
if(n==0)
return 0.0;
double z = pnormaldist(1-power/2);
double phat = 1.0*pos/n;
return (phat + z*z/(2*n) - z * sqrt((phat*(1-phat)+z*z/(4*n))/n))/(1+z*z/n);
}