Hey all i stink at math here's what i want to do in QML:
I have a slider bar that I want the min left edge to be 30 and the max right edge to be 100
what math puts 30 on the left end but gives all the percentages in between 30-100 to reflect 0-100% on the screen?
Thanks,
Chris
Given a value between 30 and 100:
percent = 100 * (value - 30) / 70
Or more generally:
percent = 100 * (value - min) / (max - min)
Related
I am working to recreate a capabilities analysis in Power BI visualizations. As there are no real stats capabilities I am having to create from scratch. I am running into a little issue when I try to get the average of my 3rd quartile for a "BSTP" Best Short Term Performance measurement. The formula for calculating BSTP is
Goal = Baseline (µ) + |0.7 x (BSTP - Baseline (µ))|
(µ) is the AVERAGE() that is easy check
0.7 = variance of the process again easy and check
BSTP = 3rd Quartile average / count of data points in 3rd Quartile not so easy and no check...
For calculation example...
Lest say we have 100 data points equally distributed from 0 - 100
Min = 1
Q1 = 25
Q2 = 50
Q3 = 75
Q4 = 100
This process BSTP calculation from excel would be as follows
SUMIF("data value" >= 75 (Q3)/ COUNTIF("data value" >= 75)
So if the "data value" is greaterthan or equal to 75 sum then divide by the count of data that are greaterthan or equal to 75... In this example we would have 25 data values between 51-75 that equal 1575, 51+52+53+54.... There were 25 data points summed up so the final calculation would be
1575/25 = 63 (BSTP)
to sum up... This is the formula I am trying to solve for in power bi
SUMIF("data value" >= 75 (Q3)/ COUNTIF("data value" >= 75)
I appreciate your insights!
DAX does have some stats functions, so this one is pretty simple.
If you're looking for the average of the 3rd quartile, then you want
SUMIF( 50 <= "data value" < 75 ) / COUNTIF( 50 <= "data value" < 75 )
or simply
AVERAGEIF( 50 <= "data value" < 75 )
You can use the percentile functions calculate where your quartiles lie an then average over that subset:
3rdQtlAvg =
VAR Q2 = PERCENTILE.INC ( Table1[Val], 0.50 )
VAR Q3 = PERCENTILE.EXC ( Table1[Val], 0.75 )
RETURN
AVERAGEX (
FILTER ( Table1,
Table1[Val] >= Q2 &&
Table1[Val] <= Q3 ),
Table1[Val]
)
I have a function that makes use of the current time (now). The Contract as a whole is a Crowdfunding token and the cost of tokens differ depending on the date and time that tokens are purchased.
How does one simulate different times when testing a Smart Contract? For instance, with regards to the code below, I would like to do unit testing to find out if the code for setting price is correct but I can't change the value of now.
Would it be a good solution to simply substitute the now keyword for another temporary testing variable, say now_sim and then manually changing now_sim during simulation?
if (now < (startTime + 1 days)) {
currentPrice = safeDiv(safeMul(price, 80), 100); // 20 % discount (x * 80 / 100)
}
else if (now < (startTime + 2 days)) {
currentPrice = safeDiv(safeMul(price, 90), 100); // 10 % discount (x * 90 / 100)
}
else if (now < (startTime + 12 days)) {
// 1 % reduction in the discounted rate from day 2 until day 12 (sliding scale per second)
// 8640000 is 60 x 60 x 24 x 100 (100 for 1%) (60 x 60 x 24 for seconds per day)
currentPrice = price - safeDiv(safeMul((startTime + 12 days) - now), price), 8640000);
}
else {
currentPrice = price;
}
If you use pyethereum for testing - which I highly recommend, it's lovely - you can directly alter the timestamp of the simulated block that is mining your transaction.
self.s = t.state()
self.s.block.timestamp = self.s.block.timestamp + 86400
self.s.mine(1)
some_val = your_contract.do_something(some_parameter)
self.assertEqual(some_val, whatever)
See a working example here (maybe a bit out-of-date): https://github.com/realitykeys/subjectivocracy/blob/master/contracts/test.py#L85
I'm wondering the best way to simulate a sunrise/sunset on the y and z axis. At the moment it does what I want but is moving too fast (say every 3 seconds it's already completed an entire sun path and is already moving in reverse back to the origin).
I know this has to do with seconds variable combined with sin and cos, as this function is called and moves the light's position every frame. Basically I want it to be linked to my game's timer of 50:
50 seconds it's sunrise
25 seconds it's noon
0 seconds it's sunset/game over
Currently I have:
lightPosition = Point_E3d(0,
std::abs(100 *std::cos(seconds)),
-100 * std::sin(seconds));
Wondering what's the correct code format to achieve this effect.
This is just simple trigonometry. The period (Time until the function repeats) of sine(x * n) and cosine(x * n) are both 2*pi / n. In this case, n = 1, so the period is 6.28, meaning one full day (and night) will last 6.28 seconds. If you want to increase the period, multiply your seconds argument by a number smaller than one. A little bit of algebra shows that:
period of sin(x * n) = 2*pi / n
period of sin(.1256 * x) = 2*pi / .1256 = 6.28 / 0.1256 = 50
Therefore, take sine and cosine of seconds * 0.1256, rather than just seconds.
lightPosition = Point_E3d(0,
std::abs(100 *std::cos(seconds * 0.1256 )),
-100 * std::sin(seconds * 0.1256));
Note that this is also including the night time. If you want just the 12 hour day time period to last 50 seconds, multiply by half of 0.1256, aka 0.0628.
I'd like to know if there's any way in C++ to calculate a proportion involving possibily negative values in both vars and extremes.
My goal is to sync a float text input widget with fixed extremes ( eg the user can input any double value between A (min) and B (max) with A,B=any_constant_real_number ) with a slider who can only slide between 0 and 100 ( to simplify ).
If A and B are positive everything is trivial. as
val_slider = ((val_textin-A)*100)/(B-A)
but as A and B can be assumed real it looks to me the only possibility is to use several if/cases, or huge formulas involving a lot of abs() and checks over 0-divisions, whose are quite error prone and very cost intense compared to such an easy task.
Is there any faster and shorter way to achieve the same in c/c++/stl?
Pardon my bad english. Any hint? Thank you.
Your formula should work fine with negative values of A and B as well, as log as A < B.
Example, if you want the user to be able to enter values from -100 to 100, and map these to a slider which goes from 0 - 100, when the user enters -90 you get:
((-90 - A) * 100) / (B - A) = ((-90 - (-100)) * 100) / (100 - (-100))
= 10 * 100 / 200
= 5
An input value of 50 results in a slider value of:
((50 - A) * 100) / (B - A) = ((50 - (-100)) * 100) / (100 - (-100))
= 150 * 100 / 200
= 75
I don't know C++, but I do know Math, so try:
val_slider = 100 * ( val_textin - A ) / ( B - A )
Hey wait. That's exactly what you have. Test case..
A=-200, B=+200, val_texin = 100 (75% of bar, right?)
val_slider = 100 * ( 100 - -200 ) / ( 200 - - 200 )
= ( 300 ) / ( 400 ) * 100
= 75
See, you got it right. The only thing that COULD happen is B==A, but that can't be accounted for with math and requires a single IF. If they are equal, val_slider is exactly B (or A, as they are equal).
I've my screen resolution set to 1024 x 768 pixels and the icon size is 32x32 and default icon spacing (not changed). how can I calculate possible number of desktop icons that can fit into that resolution?
It's a little more complex actually and should be:
numColIcon = (Screen.Width-Icon.HorizontalSpacing) / (Icon.Width + Icon.HorizontalSpacing)
numRowIcon = (Screen.Height-Icon.VerticalSpacing) / (Icon.height + Icon.VerticalSpacing)
numTotalIcon = numColIcon * numRowIcon
You need to account for one more spacing which comes as the last "column" or "row". The number of padding rows and columns will always be N+1 where N is the number of object rows and columns.
The parentheses are important for proper calculation (Divide is higher precedence than minus)
In your example then:
numRowIcon = (768 - 43) / (32 + 43) will give 9 (rounded down or truncated)
Simple:
numColIcon = Screen.Width / (Icon.Width + Icon.HorizontalSpacing)
numRowIcon = Screen.height / (Icon.height + Icon.VerticalSpacing)
numTotalIcon = numColIcon * numRowIcon