Finding highest and lowest value of rainfall in Raptor - javascript

Updated version.
I had figured out my previous issue with it but am still unsure how to do the last part. I do not know how to get the number that goes inside of the bracket instead of getting the value that is stored inside of it. The array consists of 12 numbers and for example I am looking for the highest value which might be 20 and was entered in the 4th spot. I can only figure out how to get it to display the 20 but I want to display the 4 instead. It has user input so the number that should be displayed may vary and I am unsure how to accomplish this.
I only need the arrays number to be displayed for the highest and lowest values. I don't know if I am using the wrong kind of array for this not.

So you have a couple issues but easy fixes. This only goes to fix image 3 which is highestValue.
1.) When you are setting highestValue you are saying highest value is equal to [January, amountOfRain]. You need to have it say highestValue <- data[1,2]. This will point it to amountOfRain.
2.) You need to change the name of either your Call or your variable highestValue because it's conflicting.
Give those a try and let me know what you get.

Related

How to get all the firebase data up to second from last

In my firebase, the recently or last added data has to be ubsent all the time from my table. So I want to populate the table with all the data except for the recently added data. I mean to say I have data1, data2, data3, data4. I want only data1 to 3, and 4 should be ignored. I thought I could use something like limitToFirst(-1) could work, unfortunately it doesnt.
this is my line of code: var database = firebase.database().ref().child('Sales/JBC');
I tried: var database = firebase.database().ref().child('Sales/JBC').limitToFirst(-1);
Assuming you are certain that the data/node/key that you do not want to retrieve is always at the bottom., the trick you would need to use is, first know how man data you have, there are so many ways of getting count of data. Once you have the count you can use limitToFirst() method. So you say: if you want to ignore the last child, go like this: limitToFirst(count-1). This means if you have 20 elements, you need the first 19, so get count of elements (thus 20) then subtract 1. If you want up to 18 elements you subtract 2. And so on...
I think you may be looking for limitToLast(3). You will need to know how many items you want to retrieve though, as Firebase has no way to determine that for you.

Dealing with null values in #DBLookup

I have a domino view with an amount column but some values are empty...and need to be. The problem is that the #Sum works fine until I have an empty value then it stops summing.
eg: if the values are 5,5,"" and 5 I get a sum of 10 and not 15.
I've traced the problem to the #DbLookup which is that it stops building the return array when it encounters a blank value. There is no built in method of dealing with null values.
https://www.ibm.com/support/knowledgecenter/en/SSVRGU_9.0.1/reference/r_wpdr_atfunctions_dblookup_r.html
To make things harder, #dbLookup returns a string if only one is found or an array if more than one are found. If the values are 5,5,"" and 5 it returns an array of 2 values.
var alloc = #Sum(#DbLookup(#DbName(), "SubForms",MainFrmID , "ca_ca_ca_ca_amount"));
if (isNaN(alloc)){
return "$0.00";
}else{
return "$" + alloc.toFixed(2);
}
Can anyone help me refactor the #sum or #DbLookup to allow for empty values? Unfortunately I cannot define any new functions for this solution. The environment is locked down tightly. With a list of values of 5,5,"" and 5 I need a sum of 15.
I would try #Sum(#TextToNumber(#Trim(#Text(#DbLookup(...)))))
I would try
#Sum( #Transform( #Dblookup ( ....
If #DbLookup does not do what you need, you could always iterate over documents or view entries to build the sum.
The flow would be roughly like this:
1. Get a handle to the current database.
2. Get a handle to the "SubForms" view.
3a. Get a view entry collection using using getAllEntriesByKey() with MainFrmID as key, if a view column exists that displays the values you need.
--OR--
3b. Get a document collection using getAllDocumentsByKey() with MainFrmID as key, if no view column exists that displays the values you need.
4. Iterate over the collection to sum up values, using getColumnValues().get(columnNumber) to access the value from each view entry, or getItemValueDouble(fieldName) to access the value from each document.
That way you can easily detect null values and discard them.

Ngx-Bootstrap Typeahead retaining dropdown values on input clear

I've recently upgraded the ngx-bootstrap from 1.8.1 to 3.0.1 . After the upgrade type ahead doesn't seem to work as expected. I'm using this example :
https://valor-software.com/ngx-bootstrap/#/typeahead#async-data
with [typeaheadMinLength]="3"
Now , if I search, lets say "abcdef" then it starts searching after 3 characters have been typed that is abc and then abcd, abcde, abcdef and so on which is fine.
But now if I delete everything in input textbox using backspace in one go, that is if I make abcdef to empty by pressing backspace in one go, then once input is empty, it shows drop down values again which correspond to min length which is abc.
Ideally it should clear drop down values but looks like when you delete it very fast using backspace, it retains the values corresponding to min length token string.
It is more visible when data is fetched from a service and the data is huge, so it takes some time to load and clear.
Delay in service response can be emulated using typeaheadWaitMs and this issue can be replicated using this example : https://valor-software.com/ngx-bootstrap/#/typeahead#delay
https://github.com/valor-software/ngx-bootstrap/issues/4412
Could someone please help on this?
You have to put a check if search field is empty then clear the list holding values. When pressing backspace what happens is that when search length reaches threshold value i.e abc it fetches the result and stores it after that no operation is performed hence the search results for abc are persisted. Add (keyup)="onKey($event.target.value)" if value is empty clear the list holding your dropdown data.
As a workaround, I removed [typeaheadMinLength]="3" and instead checked the length on server. If length of prefix token is less than 3 , server doesn't do anything and instead returns empty array. This isn't the optimal solution ofcourse because even for length less than 3, requests will go to the server.
Although, I didn't feel any visible performance impact but still it could be better if done on UI rather than server.

If variable (or element value) remains unchanged for over 2 seconds, do something?

I have a variable that auto increases up until a certain value. The value is determined based on an amount of elements on a page. Basically I count the amount of elements and for each element I find, I increase the value of the variable. The value of this variable is always different, sometimes it is 320, sometimes it is 512; it is random. But it increases from 0 to a certain number in a few seconds. Once it has stopped increasing, it will remain at that value and won't change any more
How can I detect if the value of this variable has remained unchanged for over 2 seconds?
And if detecting a change in a variable is not doable, I can store the value in a hidden input field as well. Or in any other kind of field. I just need to be able to run a function when a value of a variable (or an element) has remained unchanged for over 2 seconds.
Any help would be greatly appreciated, I've been trying all kinds of things for the past few hours with no luck.
EDIT:
Geez, no need to downvote, can a person not ask a question for help? :( I'm tired of trying myself and can't figure it out on my own.
Anyway. Things I tried:
Use a settimeout to see if I could get the previous value and compare it with the current, but didn't work out the way I thought it would
Tried giving a certain value ("true") to another element once the last item was found, but the last item is always different and the function that increments the value is in a "while" within another "while" (it's difficult to explain why) so I can't really ever tell which item was counted last
Tried duplicating the counting function and run it once in the beginning to know how many items there are (and store the value in a variable named "firstCounting"), then run the regular counting function again and as soon as the variable "count" from that function matched the value from "firstCounting", I'd know that I'd be at the end of the counting. But the function is so large and complicated that it'd be stupid to just copy it, only to see when the counter has stopped counting. My code is 474 lines long. I use it in combination with termsets and terms in SharePoint, but since the question is more JavaScript related, I posted it here.
I tried event receivers, object watchers, anything that should "watch" a variable. Not even event receivers did the trick when I used a hidden input element instead of a variable.
Check this, I hope this is what you want
var someValue = 1
var prevVal = null;
var _myInterval = setInterval(function() {
if(prevVal == someValue) {
console.log("No change for 2 second", someValue)
} else {
console.log("Value was changed between past 2 second prev: ", prevVal, " New: ", someValue)
prevVal = someValue;
}
}, 2000)
Edit
Used var instead of this
Check Image Attached for Output

Crowdsourced average value

I am currently working on a "crowdsourced" average value calculator. The idea is to show a picture to people and ask them to guess the age of the person. Once they entered the value, I want to show them the average age the person was given.
Here is what I want to do exactly :
Put a form online and ask people to put on a value
Store the data entered
Return the mean value people put there
Calculate the standard deviation so that people cannot put a value too high or too low compared to what others put. That means the average value shown will be more accurate this way.
I am looking for the fastest way to do it, and here is what I thought about :
Store the data in an SQL table and return the mean value through the AVG() function..but then, how would I calculate the Std. Dev ?
Store the data in a txt file and use javascript to convert it to an array do the calculations.
But if I get like 20,000 different values, it might be slow to do either way. ?
I am quite a beginner in programming and what I propose might seem ridiculous...feel free to tell it to me !
Thank you all.
SQL Server has STDEV (from 2005 onwards) so SQL sounds good for you.
Returns the statistical standard deviation of all values in the
specified expression. May be followed by the OVER clause.
Syntax
STDEV ( [ ALL | DISTINCT ] expression )
Arguments
ALL
Applies the function to all values. ALL is the default.
DISTINCT
Specifies that each unique value is considered.
expression
Is a numeric expression. Aggregate functions and subqueries are not permitted. expression is an expression of the exact numeric or approximate numeric data type category, except for the bit data type.

Categories