Just want to get feedback on my tableau calculation.
I have three calculations inside:
Proposed New tag - this is the new calculation I have come up with.
What I did is to create new calculations: Cash / Check / Card Amount Tag - check if there is amount in the column, if yes tag as 1 else 0. Result: Incorrect count.
Calculation:
AND [ADA Type] ='Non-ADA/ACA'
AND [Payment Type1] ='FIRST'
AND [Cash Amount Tag] > 0 OR [Check Amount Tag]> 0
THEN 'Bank Bills Payment'
END
// '1' means with amount ,please check cash and check amount tag
Another calc - same scenario with first but I did your suggestion to add IS NOT NULL. Result: same count as #1 calculation.
IF [Payment Source]='ADA/ACA/BP Bank'
AND [ADA Type] ='Non-ADA/ACA'
AND [Payment Type1] ='FIRST'
AND NOT ISNULL([Cash Amount]) OR NOT ISNULL([Check Amount])
THEN 'Bank Bills Payment'
END '1' means with amount ,please check cash and check amount tag
Old_Count - The correct output using count function
ZN(COUNT(IF([Payment Source])='ADA/ACA/BP Bank'
AND [ADA Type] ='Non-ADA/ACA'
THEN [Cash Amount]
END)) + ZN(COUNT(IF([Payment Source])='ADA/ACA/BP Bank'
AND [ADA Type] ='Non-ADA/ACA'
THEN [Check Amount]
END))
Related
I’m pretty new to scripting or coding and I’m trying to figure out a way to have an input that can be between 1 and 100 without having to write 100 lines of code. I am doing this in Lua and I will include my current lines below.
elseif input.text == '>coins add 100' then coins = coins + 100; print ("coins effected. "..coins)
elseif input.text == '>coins add 200' then coins = coins + 200; print ("coins effected. "..coins)
elseif input.text == '>coins add 300' then coins = coins + 300; print ("coins effected. "..coins)
I’m using this for a game I’m developing because i thought it would be a good way to practice. This in specific is for a console to change different values for debugging. Tell me if this doesn’t make sense and i will try to fix it.
Thanks!
The function that limits a number in a certain range usually called Clamp.
function math.Clamp(val, min, max)
return math.min(math.max(val, min), max)
end
It's basically and literally a math.max with math.min together.
To avoid 100 if statements, I suggest you to make a script to wait for >coins add and then ask for a number specifically.
[Edit] Apparently it doesn't allow you to do so, so here is a walkaround:
local num = string.sub(input.text, 12) -- remove 12 first characters from the string, this will leave a number in it
num = tonumber(num) -- convert a string into Lua number
if not num then -- if the conversion failed, stop the script, print the text
print("Not a number")
return
end
num = math.Clamp(num, 1, 100) -- Limit the number from 1 to 100
coins = coins + num -- add that number
print ("coins effected. " .. coins) -- New amount of coins
I understand, "for i, v" loops for tables, i is the index, and v is the value, but what does this script do? I do not think this has anything to do with tables, but the only type of for table loops I know in ROBLOX script is the first one I mentioned; "for i, v" loops, which loop through tables.
randomVariable = 1
for i = 1, randomVariable do
(random script)
end
This is a numeric loop statement.
for controlValue = startValue, endValue, stepValue do
-- for body
end
It goes from startValue until it reaches endValue, after running body code, controlValue is increased by stepValue. If controlValue is higher or equals to endValue the loop stops. If stepValue is not provided, it equals to 1.
It's equivalent to this code:
local controlValue = startValue
if not stepValue then stepValue = 1 end -- if no stepValue it equals to 1
while controlValue < endValue do
-- for body
controlValue = controlValue + stepValue
end
There are a few different ways to loop in Lua.
while variable < number do
repeat stuff until variable == number
for key, value in pairs do
for index, value in ipairs do
for i = 1, number do
i = 1 is the initial condition.
It usually begins at one, then loops through items in a table.
So you can think of it as an index in that regard.
where the randomVariable you mentioned would be #tab
however, you could set that initial condition to be larger, then count down.
for i = #tab, 1, -1 do
the third, optional argument is called "step size"
and it's the amount that initial condition is changed, after completing each loop. it defaults to 1, so it's not needed, most of the time.
so to step through all the even numbers in a table it would be
for i = 2, #tab, 2 do
Further reading: https://www.tutorialspoint.com/lua/lua_loops.htm
I've got a grade function:
def grade(submission)
score_counter = 0
total_score = submission.test.questions.size
#the scoring logic is here
return (score_counter/total_score)*100
end
The intention is to return a percent score, but all that shows up in my view is 0. If I just try to return score_counter and total_score separately, they display the correct values. Any ideas?
You need to change your values to float
(score_counter.to_f / total_score.to_f) * 100
Good afternoon people, i'm trying to code in Verilog a structure than can store up to 64 different 8bit numbers (64X8), which is only allowed to store numbers greater than 125 and bellow or equal to 250. When it is writing (or not), it can show the maximum current stored value (VAL_MAX) as well as it's position (POS_MAX). When not writing (EN_WR ==0) i simply put in POS_RD the position that i want, in order to see what number is stored there, and when the memory is full (NR_ST = 64) it replaces the oldest stored numbers with the new ones, one by one. I currently have the code but there are some issues:
1st - When the memory is full and for eg. i have 250 in the 2nd position, the output will be
VAL_MAX= 250 ; POS_MAX=1. When a bunch of new numbers come, that maximum should be replaced with the 2nd highest stored value and must show it's position, but the memory isn't showing a new Max Value.
2nd - When i want to see the number stored in the 1st position (POS_RD = 0) the output VAL_RD (used to read the stored numbers) is "X" and not the stored number, i don't know if it is saving or not.
The code is:
module Bloco(VAL_SENSOR, EN_WR, POS_RD, NR_ST, VAL_MAX, POS_MAX, VAL_RD, segundo, clk);
parameter MEM_SIZE = 64;
parameter MEM_WIDTH = 8;
parameter ADDR_SIZE = 5;
input[MEM_WIDTH - 1:0] VAL_SENSOR;
input[5:0] POS_RD;
input EN_WR,segundo,clk;
output[6:0] NR_ST;
output[MEM_WIDTH - 1:0] VAL_MAX;
output[ADDR_SIZE :0]POS_MAX;
output[MEM_WIDTH - 1:0]VAL_RD;
reg[MEM_WIDTH - 1:0] ram[MEM_SIZE - 1:0]; // C , L
reg[MEM_WIDTH - 1:0] VAL_RD;
reg[MEM_WIDTH - 1:0] val_max = 0; //necessita de variavel so por causa do valor inicial
reg[ADDR_SIZE :0] POS_MAX = 0;
reg[ADDR_SIZE :0] POS_MAX2 = 0;
reg[ADDR_SIZE + 1:0] NR_ST_COUNTER = 0; //addr_size + 1 because it needs to count from zero to the number of values
reg[ADDR_SIZE :0] POS_POINTER = 0;
assign VAL_MAX = val_max;
assign NR_ST = NR_ST_COUNTER;
always # (posedge clk)
begin
if(EN_WR) //Caso esteja habilitado o sistema de armazenamento
begin
if(segundo)
begin
if(VAL_SENSOR > 125 && VAL_SENSOR <= 250) //Se for um numero abaixo de 250 unid. luminosas e acima de 125
begin //Escrita
if(POS_POINTER == POS_MAX)
POS_MAX <= POS_MAX2;
else
ram[POS_POINTER] <= VAL_SENSOR;
if(NR_ST_COUNTER < 64) //atualizar Contador de Valores guardados
NR_ST_COUNTER = NR_ST_COUNTER + 1;
if(VAL_SENSOR > val_max) //atualizar MAX
begin
POS_MAX <= POS_POINTER;
val_max <= VAL_SENSOR;
end
else //ver se encaixa no segundo maior POS_MAX2
begin
if(VAL_SENSOR > ram[POS_MAX2]) //nao precisa guardar o valor
POS_MAX2 <= POS_POINTER;
end
POS_POINTER <= POS_POINTER + 1;
end
end
end
else
VAL_RD <= ram[POS_RD];
end
endmodule
.
NOTE = The input "segundo" is like EN_WR, but it's only used after 10 clock cycles (it will be linked to a Counter).
Thank you.
To answer your questions:
1) The reason you are likely not seeing the second highest value in your memory appear on VAL_MAX when the current max is overridden is because you never change val_max register to contain the value of ram[POS_MAX2], ie the second highest value. However, as you do not have an ordered data structure and do not store any more than the second highest value (and do not search the memory for the second highest value), you cannot reliably keep finding the next highest value when the current highest is removed/overridden. You might need to rethink alot of how you are doing this if you need to always have the current highest value in the memory being output on VAL_MAX.
2) Position 0 is not being written to the first time you write to the memory; thus you are getting the default value of the memory, ie 'x. Here way:
if(POS_POINTER == POS_MAX)
POS_MAX <= POS_MAX2;
else
ram[POS_POINTER] <= VAL_SENSOR;
In the above lines, you only put values in the memory if the current position is not equal to the position of the current highest value. The first time you write (ie, to position 0), POS_POINTER and POS_MAX are at their initial values of 0, thus equal. So, ram[0] never gets updated as it is only executed if POS_POINTER and POS_MAX are not equal (which in this case, they are equal). If you were to write to position 0 a second time, you might be able to write to it as the value of POS_MAX might have changed. Note also, that you sometimes update the write pointer POS_POINTER even if you dont write there, as in the example above (even through ram[0] wasnt written to, you will still update POS_PONTER to be 1).
As mentioned in #1, depending on your requirements, you might not have the right structures here to meet them. If you always need to have the highest value in the memory output on VAL_MAX and always have the old value ejected, you might need to make old of those operations do a search, or store and update all the needed meta data.
I have this function:
function SecondsFormat(X)
if X <= 0 then return "" end
local t ={}
local ndays = string.format("%02.f",math.floor(X / 86400))
if tonumber(ndays) > 0 then table.insert(t,ndays.."d ") end
local nHours = string.format("%02.f",math.floor((X/3600) -(ndays*24)))
if tonumber(nHours) > 0 then table.insert(t,nHours.."h ") end
local nMins = string.format("%02.f",math.floor((X/60) - (ndays * 1440) - (nHours*60)))
if tonumber(nMins) > 0 then table.insert(t,nMins.."m ") end
local nSecs = string.format("%02.f", math.fmod(X, 60));
if tonumber(nSecs) > 0 then table.insert(t,nSecs.."s") end
return table.concat(t)
end
I would like to add weeks and months to it but cant get my head around the month part to move on to the week part just because the days in a month aren't always the same so can anyone offer some help?
The second question is, is using a table to store the results the most efficient way of dealing with this given the function will be called every 3 seconds for up to 100 items (in a grid)?
Edit:
function ADownload.ETA(Size,Done,Tranrate) --all in bytes
if Size == nil then return "--" end
if Done == nil then return "--" end
if Tranrate == nil then return "--" end
local RemS = (Size - Done) / Tranrate
local RemS = tonumber(RemS)
if RemS <= 0 or RemS == nil or RemS > 63072000 then return "--" end
local date = os.date("%c",RemS)
if date == nil then return "--" end
local month, day, year, hour, minute, second = date:match("(%d+)/(%d+)/(%d+) (%d+): (%d+):(%d+)")
month = month - 1
day = day - 1
year = year - 70
if tonumber(year) > 0 then
return string.format("%dy %dm %dd %dh %dm %ds", year, month, day, hour, minute, second)
elseif tonumber(month) > 0 then
return string.format("%dm %dd %dh %dm %ds",month, day, hour, minute, second)
elseif tonumber(day) > 0 then
return string.format("%dd %dh %dm %ds",day, hour, minute, second)
elseif tonumber(hour) > 0 then
return string.format("%dh %dm %ds",hour, minute, second)
elseif tonumber(minute) > 0 then
return string.format("%dm %ds",minute, second)
else
return string.format("%ds",second)
end
end
I merged the function into the main function as I figured it would probably be quicker but I now have two questions:
1: I had to add
if date == nil then return "--" end
because it errors occasionally with date:match trying to compare with "nil" however os.date mentions nothing in the literature about returning nil as its a string or a table so although the extra line of code fixes the issue I'm wondering why that behaviour occurs as I'm sure I caught all the non events in the previous returns?
2: Sometimes I see functions written like myfunction(...) and I'm sure that just does away with the arguments and if so is there a one line of code that could do away with the first 3 "if" statements?
You can use the os.date function to get date values in a useable format. The '*t' formating parameter makes the returned date into a table instead of a string.
local t = os.date('*t')
print(t.year, t.month, t.day, t.hour, t.min, t.sec)
print(t.wday, t.yday)
os.data uses the current time by default, you can pass it an explicit time if you want (see the os.data docs for more info on this)
local t = os.date('*t', x)
As for table performance, I wouldn't worry about that. Not only is your function not called all that often, but table handling is much cheaper than other things you might be doing (calling os.date, lots of string formatting, etc)
Why not let Lua's os library do the hard work for you?
There is probably an easier (read: better) way to figure out the difference to 01/01/70, but here is a quick idea of how you could use it:
function SecondsFormat(X)
if X <= 0 then return "" end
local date = os.date("%c", X) -- will give something like "01/03/70 03:40:00"
local inPattern = "(%d+)/(%d+)/(%d+) (%d+):(%d+):(%d+)"
local outPattern = "%dy %dm %dd %dh %dm %ds"
local month, day, year, hour, minute, second = date:match(inPattern)
month = month - 1
day = day - 1
year = year - 70
return string.format(outPattern, year, month, day, hour, minute, second)
end
I think that this should also be a lot quicker than constructing the table and calling string.format multiple times - but you'd have to profile that.
EDIT: I ran a quick test with two functions that concatenate "abc", "def" and "ghi" using both methods. Inserting those strings into a table an concatenating took 14 seconds (for several million runs of course) and using a single string.format() took 6 seconds. This does not take into account, that your code calls string.format() anyway (multiple times) - nor the difference between you figuring out the values by division and I by pattern matching. Pattern matching is certainly slower, but I doubt that it outweighs the gains from not having a table - and it's certainly convenient to be able to leverage os.time(). The fastest way would probably be figuring out the month and day manually and then using a single string.format(). But again - you'd have to profile that.
EDIT2: missingno has a good point with using the "*t" option with os.date to give you the values separately in the first place. Again, this depends on whether you want to have a table for convenience vs. a string for storage or whatever reasons. Combining "*t" and a single string.format:
function SecondsFormat(X)
if X <= 0 then return "" end
local date = os.date("*t", X) -- will give you a table
local outPattern = "%dy %dm %dd %dh %dm %ds"
date.month = date.month - 1
date.day = date.day - 1
date.year = date.year - 70
return string.format(outPattern, date.year, date.month, date.day, date.hour, date.min, date.sec)
end