CacheSQL calculate total time - intersystems-cache

I'm looking to calculate the total time from a column similar to this forum:
https://stackoverflow.com/questions/3054943/calculate-sum-time-with-mysql
Here is my code that is not working:
SEC_TO_TIME(SUM(TIME_TO_SEC(CASE WHEN (SUBSTR(Total_Time,1,2) -
SUBSTR(ActivityTime,1,2)) < 0
THEN '0' || DATEDIFF(hh,Total_Time,ActivityTime)-1 || ':' || DATEDIFF(mi,Total_Time,ActivityTime)
WHEN (SUBSTR(Total_Time,1,2) - SUBSTR(ActivityTime,1,2)) >= 0
THEN '0' || DATEDIFF(hh,Total_Time,ActivityTime) || ':' ||
DATEDIFF(mi,Total_Time,ActivityTime)
END))) AS TotalVariance,
Any help would be great! thanks!

I'm not sure if this helps you or someone. There are Calculated/SqlComputed properties in ObjectScript. Basically, you can define a property like:
Property TotalTime As %Integer [ Calculated, SqlComputeCode =
{s {TotalTime}=##class(SomeClass).SomeClassMethod({Id})}, SqlComputed ]
Now you just have to write SomeClassMethod. It can continue any ObjectScript code including %Open, just don't make it cyclic. If you only need some of the other fields to make it, you can go this way:
Property TotalTime As %Integer [ Calculated, SqlComputeCode =
{s {TotalTime}=##class(Some).SomeCM({PropA}, {PropB})}, SqlComputed ]
There, you will get the properties as input for your class method, instead of getting ID and calling ..%Open(Id).
Either way, you can use the resulting calculated property even for indices.

Related

dash component Interval property n_intervals value shows differently in callback

I have this short code that use the dcc.Interval component to update a text in the callback, where I tried to print out the value of the n_intervals property.
from dash import Dash, html, dcc, Input, Output
app = Dash()
dccinterval = dcc.Interval(
id='interval-component',
interval=1000,
n_intervals=0
)
app.layout = html.Div(
children=[
html.Div(id='live-update-text'),
dccinterval
]
)
#app.callback(Output('live-update-text', 'children'),
Input(dccinterval, 'n_intervals'))
def update_message(n):
print('current interval in update_message: ', dccinterval.n_intervals)
print('current n in update_message: ', n)
return 'Message: ' + str(n)
if __name__ == '__main__':
app.run_server(debug=True, port=8058)
Here is the output:
current interval in update_message: 0
current n in update_message: 0
current interval in update_message: 0
current n in update_message: 1
current interval in update_message: 0
current n in update_message: 2
current interval in update_message: 0
current n in update_message: 3
.
.
.
As you might see that the value of n_intervals got via the Input is changing correctly, but the value got directly from the interval component always stays at 0. I am wondering why. Can someone please help me with this? The reason I need to figure this out is that in my application when I tried to change the n_intervals’ value via component fails. That is, when I tried to set the value by doing dccinterval.n_intervals = a number, it does not work.
Thank you very much for any comments!
dccinterval.n_intervals is showing up strangely because that's not the correct way to use the interval component. The other way, using n, which is the function argument representing the interval from the Input, is the correct way. However, you've defined your Input a bit incorrectly. Rather than referencing the variable for the component, which is dccinterval, you need to reference the id of that component, like this:
Input('interval-component', 'n_intervals')
If you want to update the interval's value, you need to set up a callback that uses it as an Output like this:
Output('interval-component', 'n_intervals')
and the function will return whichever value you want to update the interval to.
Edit:
So, the reason the wrong way doesn't work is because the variable you declare in the layout, dccinterval in this case, doesn't contain all of the details once the app is running. The callback function's argument, n in this case, has the right info because it has been updated through Dash. This is related to how Dash works, and how - more deeply - React works under the hood.

Printing part of an array in MiniZinc

I have a MiniZinc model for wolf-goat-cabbage in which I store the locations of each entity in its own array, e.g., array[1..max] of Loc: wolf where Loc is defined as an enum: enum Loc = {left, rght}; and max is the maximum possible number of steps needed, e.g., 20..
To find a shortest plan I define a variable var 1..max: len; and constrain the end state to occur at step len.
constraint farmer[len] == left /\ wolf[len] == left /\ goat[len] == left /\ cabbage[len] == left
Then I ask for
solve minimize len
I get all the right answers.
I'd like to display the arrays from 1..len, but I can't find a way to do it. When I try, for example, to include in the output:
[ "\(wolf[n]), " | n in 1..max where n <= len ]
I get an error message saying that I can't display an array of opt string.
Is there a way to display only an initial portion of an array, where the length of the initial portion is determined by the model?
Thanks.
Did you try to fix the len variable in the output statement like n <= fix(len)?. See also What is the use of minizinc fix function?

How to join a string and float value in a calculated field using Tableau?

I am trying to create a calculated field where the output is "x% Over the Goal", however cannot due to string and float values. Essentially, what I want is the following:
IF Actuals > Goal THEN Actuals/Goal+'Over Goal'
ELSEIF Actuals < Goal then Actuals/Goal+'Under Goal'
ELSE 'At Goal' END
Is something like this possible? I've tried creating two separate calculated fields and concatenating them, but that does not work either.
Any help would be greatly appreciated.
You Can achieve this in a single calculated field:
IF [Actuals] > [Goal] THEN STR(FLOAT([Actuals] / [Goal])) + "Over Goal"
ELSEIF [Actuals] < [Goal] THEN STR(FLOAT([Actuals] / [Goal])) + "Under Goal"
ELSE "At Goal" END

NDpend Variable Calculations

Trying to use a custom NDepend variable in place of a constant and cannot work out some of the intricacies of the NDepend syntax around the let keyword.
One of the built in queries is:
warnif count > 0 from m in JustMyCode.Methods where
m.CyclomaticComplexity > 30 ||
m.ILCyclomaticComplexity > 60 ||
m.ILNestingDepth > 6
orderby m.CyclomaticComplexity descending,
m.ILCyclomaticComplexity descending,
m.ILNestingDepth descending
select new { m, m.CyclomaticComplexity,
m.ILCyclomaticComplexity,
m.ILNestingDepth }
Whereas what I really want to do is not use a 0 constant value and base that on the codebase instead. Something along the lines of:
let tenPercent = (JustMyCode.Methods.Count() / 100 * 10)
warnif count > tenPercent from m in JustMyCode.Methods where
m.CyclomaticComplexity > 30 ||
...
Is this even possible?
You can write something like this...
warnif percentage > 10
from m in Application.Methods where
m.CyclomaticComplexity > 2
select new { m, m.CyclomaticComplexity }
...but this feature is kinda hidden (percentage keyword doesn't appear in intellisense) because it is not polished yet. The percentage base is the total number of methods (including abstract methods, third-party methods, generated methods...) and this base number is actually not configurable. Also the constant value (10 here) cannot be an expression.

Have for loop script do something only every Nth iteration

In MATLAB (or more generally) if I wanted something to happen only, for example, every 50 iterations of a for loop how could I do this better than below? That is to not write out every possible value of +50. Thanks.
for i = 1:1060;
if i = 50 || 100 || 150 || ... || 1050
randi(i); % for example, just do something
end;
end;
What you want is
if mod(i, 50) == 0
do something
What you want is
for i = 0:50:1050
do_stuff(i);
end
unless, it is unclear from your question, if the previous answer is what you really want, which you might need in the case that looks like this
for i = 1:1060
if mod(i, 50) == 0
do_something(i)
end
do_something_else(i)
end
Cheers,--