I want to create Calculated metrics expression for same Logical expression for example by Java
if (KPI<=95 & FailedCount!=0) {
STATUS=1;}
else {STATUS=0;}
In Site Scope I wrote this expression
((<<KPI>><=95)&(<<FailedCount>>!=0))
But I do not like the result
When KPI=0 and FailedCount=0;
STATUS=0,
then KPI=100 and FailedCount=0
STATUS='n/a'.
How to reslove this problem?
p.s.
Add question on HP Community too
There's a ternary operator you can use:
(Boolean Expression)? resultIfExpressionIsTrue: resultIfExpressionIsFalse
In your case you could try to use something like:
((<<KPI>><=95)&(<<FailedCount>>!=0))? 1: 0
You may also need to consider if you want the result to be 0 and 1 as integers (as above) or as strings in which case they should be put in between " marks. This is important from the perspective if you'd like to apply arithmetic or string like thresholds to the resulting calculated metric, also if you'd like the result to be seen as numeric or string values in other places, like in OMi or Service Health etc.
Related
I have two metrics with matching labels, both counters:
accounts_created_total{provider="auth0"} 738
accounts_created_total{provider="google} 980
accounts_deleted_total{provider="auth0"} 65
I'd like to calculate the number of existing accounts from those two metrics. I came up with this:
accounts_created_total - accounts_deleted_total
# which results in
{provider="auth0"} 673
# Note the missing provider="Google"
Unfortunately, there's no account_deleted_total for provider="Google", and so I only get the result for provider="auth0".
Is there a way I can tell prometheus to "make up" the missing labels? That would typically be equivalent to a coalesce in SQL.
You can complete a time serie using the OR binary operator:
vector1 or vector2 results in a vector that contains all original elements
(label sets + values) of vector1 and additionally all elements of vector2
which do not have matching label sets in vector1.
Assuming you want to default accounts_deleted_total to 0, the following expression uses accounts_created_total as second vector to extract the labels and multiplying by 0 ensures the value is reset:
accounts_deleted_total OR (accounts_created_total * 0)
In the case of autho0, the label exists in accounts_deleted_total and the second part will not be used ; to the contrary, for google, second part will yield
{provider="google"} 0
Finally, you can use it in your expression:
accounts_created_total - (accounts_deleted_total OR (accounts_created_total * 0))
In your specific case, since you are using the same metric to extract the labels, you can even simplify the expression to:
(accounts_created_total - accounts_deleted_total) OR accounts_created_total
I have
dummytxt←'abcdefghijk'
texttoadd←'down'
rfikv←20 30 50
and need following output
defghijk20down defghijk30down defghijk50down
I can do it with:
scenv←(¯10↑¨(⊂dummytxt),¨⍕¨rfikv),¨⊂texttoadd
but please help me to write without each operator but using rank ⍤
I use Dyalog APL, but please do not use trains.
Thank you
Expressions using Each, like f¨x, can be expressed in terms of Rank as {⊂f⊃⍵}⍤0⊢x (note that ⊢ is to separate the array right operand, 0 from the array right argument x). In other words, on the scalars of the argument we:
disclose the scalar: ⊃⍵
apply the function: f⊃⍵
enclose the result: ⊂f⊃⍵
A similar expression applies for the dyadic case, x f¨y, but we need to:
disclose both scalars: (⊃⍺)…(⊃⍵)
apply the function: (⊃⍺)f(⊃⍵)
enclose the result: ⊂(⊃⍺)f(⊃⍵)
This gives us x{⊂(⊃⍺)f(⊃⍵)}⍤0⊢y. We can thus use Rank to build our own Each operator which allows both monadic and dyadic application of the derived function:
Each←{⍺←⊢ ⋄ ⍺ ⍺⍺{×⎕NC'⍺':⊂(⊃⍺)⍺⍺(⊃⍵) ⋄ ⊂⍺⍺⊃⍵}⍤0⊢⍵}
(¯10↑Each(⊂dummytxt),Each⍕Each rfikv),Each⊂texttoadd
defghijk20down defghijk30down defghijk50down
Alternatively, we can substitute the two simpler equivalences into your expression:
(¯10{⊂(⊃⍺)↑(⊃⍵)}⍤0⊢(⊂dummytxt){⊂(⊃⍺),(⊃⍵)}⍤0{⊂⍕⊃⍵}⍤0⊢rfikv){⊂(⊃⍺),(⊃⍵)}⍤0⊂texttoadd
defghijk20down defghijk30down defghijk50down
Notice that we are enclosing texttoadd so it becomes scalar, and then we use ⍤0 to address that entire scalar, only to disclose it again. Instead, we can use ⍤0 1 to say that want to use the entire vector right argument when applying the function, which in turn doesn't need to disclose its right argument:
(¯10{⊂(⊃⍺)↑(⊃⍵)}⍤0⊢(⊂dummytxt){⊂(⊃⍺),(⊃⍵)}⍤0{⊂⍕⊃⍵}⍤0⊢rfikv){⊂(⊃⍺),⍵}⍤0 1⊢texttoadd
defghijk20down defghijk30down defghijk50down
rfikv and ¯10 are a simple scalars, so disclosing them has no effect:
(¯10{⊂⍺↑(⊃⍵)}⍤0⊢(⊂dummytxt){⊂(⊃⍺),(⊃⍵)}⍤0{⊂⍕⍵}⍤0⊢rfikv){⊂(⊃⍺),⍵}⍤0 1⊢texttoadd
defghijk20down defghijk30down defghijk50down
dummytxt is in the same situation as texttoadd above, but as left argument, so we can skip the enclose-disclose and ask Rank to use the entire vector left argument; ⍤1 0:
(¯10{⊂⍺↑(⊃⍵)}⍤0⊢dummytxt{⊂⍺,(⊃⍵)}⍤1 0{⊂⍕⍵}⍤0⊢rfikv){⊂(⊃⍺),⍵}⍤0 1⊢texttoadd
defghijk20down defghijk30down defghijk50down
This is about as simple as it gets using a general method. However, if we instead observe that the only non-scalar is rfikv, we can treat dummytxt and texttoadd as global constants and express the entire thing as a single ⍤0 function application on rfikv:
{⊂(¯10↑dummytxt,⍕⍵),texttoadd}⍤0⊢rfikv
defghijk20down defghijk30down defghijk50down
Of course, Each can do this too:
{(¯10↑dummytxt,⍕⍵),texttoadd}¨rfikv
defghijk20down defghijk30down defghijk50down
I'm working in a project that uses the IBM SPSS but I had some problems to set a dummy variable(binary variable).The process to get the variable is following : Consider an any variable(width for example), to get the dummy variable, we need
to sort this variable in the decreasing way; The next step is make a somatory of the cases until a limit, the cases before the limit receive the value 1 in the dummy variable the other values receive 0.
Your explanation is rather vague. And the critical value you give in the printscreen should be 2.009 in stead of 20.09?
But I think you mean the following.
When using syntax, use:
compute newdummyvariable eq (ABr gt 2.009477106).
To check if it's okay:
fre newdummyvariable.
UPDATE:
In order to compute a dummy based on the cumulative sum, the answer is as follows:
If your critical value is predetermined, the fastest way is to sort in decending order, and to use the command create with csum() to compute an extra variable which I called ABr_cumul. This one, you use to compute the newdummyvariable. As follows:
sort cases by ABr (d).
create ABr_cumul = csum(VAR00001).
compute newdummyvariable = (ABr_cumul le 20.094771061766488).
fre newdummyvariable.
the dummy comes from the sum of all cases, after decreasing order raqueados when cases of a variable representing 50% of the variable t0tal, these cases receive 1 and the other 0 ...
Suppose I have a factor variable with labels "a" "b" and "c" and want to see which observations have a label of "b". Stata refuses to parse
gen isb = myfactor == "b"
Sure, there is literally a "type mismatch", since my factor is encoded as an integer and so cannot be compared to the string "b". However, it wouldn't kill Stata to (i) perform the obvious parse or (ii) provide a translator function so I can write the comparison as label(myfactor) == "b". Using decode to (re)create a string variable defeats the purpose of encoding, which is to save space and make computations more efficient, right?
I hadn't really expected the comparison above to work, but I at least figured there would be a one- or two-line approach. Here is what I have found so far. There is a nice macro ("extended") function that maps the other way (from an integer to a label, seen below as local labi: label ...). Here's the solution using it:
// sample data
clear
input str5 mystr int mynum
a 5
b 5
b 6
c 4
end
encode mystr, gen(myfactor)
// first, how many groups are there?
by myfactor, sort: gen ng = _n == 1
replace ng = sum(ng)
scalar ng = ng[_N]
drop ng
// now, which code corresponds to "b"?
forvalues i = 1/`=ng'{
local labi: label myfactor `i'
if "b" == "`labi'" {
scalar bcode = `i'
break
}
}
di bcode
The second step is what irks me, but I'm sure there's a also faster, more idiomatic way of performing the first step. Can I grab the length of the label vector, for example?
An example:
clear all
set more off
sysuse auto
gen isdom = 1 if foreign == "Domestic":`:value label foreign'
list foreign isdom in 1/60
This creates a variable called isdom and it will equal 1 if foreigns's value label is equal to "Domestic". It uses an extended macro function.
From [U] 18.3.8 Macro expressions:
Also, typing
command that makes reference to `:extended macro function'
is equivalent to
local macroname : extended macro function
command that makes reference to `macroname'
This explains one of the two : in the offered syntax. The other can be explained by
... to specify value labels directly in an expression, rather than through
the underlying numeric value ... You specify the label in double quotes
(""), followed by a colon (:), followed by the name of the value
label.
The quote is from Stata tip 14: Using value labels in expressions, by Kenneth Higbee, The Stata Journal (2004). Freely available at http://www.stata-journal.com/sjpdf.html?articlenum=dm0009
Edit
On computing the number of distinct observations, another way is:
by myfactor, sort: gen ng = _n == 1
count if ng
scalar sc_ng = r(N)
display sc_ng
But yours is fine. In fact, it is documented here: http://www.stata.com/support/faqs/data-management/number-of-distinct-observations/, along with more methods and comments.
I work with SPSS and have difficulty finding/generating a syntax for counting cases.
I have about 120 cases and five variables. I need to know the count /proportion of cases where just one, more than one, or all of the cases have a value of 1 (dichotomous variable). Then I need to compute a new variable that shows the number / proportion of cases which include all of the aforementioned cases (also dichotomous).
For example case number one: var1=1, var2=1, var3=1, var4=0, var5=0 --> newvariable=1.
Case number two: var1=0, var2=0, var3=0, var4=0, var5=0 --> newvariable=1.
And so on...
Can anybody help me with a syntax?
Help would much appreciated!
Here we can use the sum of the variables to determine your conditions. So using a scratch variable that is the sum, we can see if it is equal to 1, more than 1 or 5 in your example.
compute #sum = SUM(var1 to var5).
compute just_one = (#sum = 1).
compute more_one = (#sum > 1).
compute all_one = (#sum = 5).
Similarly, all_one could be computed using the ANY command to evaluate if any zeroes exist, i.e. compute all_one = ANY(0,var1 to var5).. These code snippets assume that var1 to var5 are contiguous in the data frame, if not they just need to be replaced with var1,var2,var3,var4,var5 in all given instances.
You could read up on the logical function ANY in the Command Syntax Reference manual, if you negated a test for ANY with "0", then that is effectively a test for all "1"s. Use of the COUNT command would be another approach.