I want to know how many percent of the data function is filled;
console.log(this.$data);
This is giving that
I am planing to count all of these fields. Even if they are an object I will count each key of object.
Then I am planing to also count which one of them is filled. Then i will get percent. If you thing there is better I need your help.
Related
I face the problem that I have a list of keys inside my firebase database and I want to retrieve one random key out of it, without downloading all keys and selecting one in my own app. Downloading all keys with for example .once() is a big no go, especialy because I may up end with 10.000+ keys in the future and I dont want my firebase bills to explode, Im still a student with no budget at all.
I already researched this topic and found following answer for my question.
The problem with this is, that I can not use limitToFirst() and also limitToLast() in the same query, else I get following error:
[Unhandled promise rejection: Error: Query.limitToLast: Limit was
already set (by another call to limit, limitToFirst, or limitToLast).]
Also other people face the same problem like me and I generaly see that this question always gets much views but rather poor answers which are, like apperently in the case I mentioned earlier outdated, or just not for usage in Javascript and React-Native.
Additional informations: I have a counter for my keys so I know at every time how many keys are stored inside my database. Following picture shows my database entirely:
This is the part of my code which shows the mentioned error:
const numberOfUsers = await firebase.database().ref("usercounter").once("value").then(snapshot => {
return(snapshot.val()); //retrieve numbers of users from "usercounter"
});
const randomIndex = Math.floor(Math.random() * numberOfUsers) + 1; //"generating random number, excluding 0"
var ref = firebase.database().ref('users'); //ref to my users keys
await ref.limitToFirst(randomIndex).limitToLast(1).once('value').then(DataSnapshot =>
{
//This is the query that does not work at all.
console.log(DataSnapshot.val())
});
Incase there is a way to overcome that problem, please let me know.
I would solve that problem this way:
Create for each list element a value with the field name id or some other you want. It should be a simple integer. Idealy incrementaly growing with the list. You could use the counter to increase the value each time you add an element.
When trying to get a random element from the list first get a random integer between 0 and the total count of all elements. Then use this query to get a single random element:
firebase.database().ref("users").orderByChild("id").startAt(randomNumber).limitToFirst(1);
Even if you don't hit the id with the randomNumber you would the neareas next element. This should be able to scale to any size.
The most diffictult part would be to optain the id incrementaly without repeating them. I would use for that an cloud function that does it when an item is added. Even a combination with the counter would be interesting.
After some research i find this post what have an example about how to manage a complex array in Vue.js
https://forum.vuejs.org/t/vuex-best-practices-for-complex-objects/10143/2
I have create this jsbin (https://jsbin.com/jocezud/5/edit?html,js,output) to make some test but i´m stuck at this point. I want to make some totals based in the checked topics:
A) When the checkbox of each Topic is checked the price value must be copied to the subTotal value.
B) Also every user must have the userTotal updated with the sum of the subTotal of the checked Topics.
Here is a capture about my goal.
Thanks in advance
Finally i get it working with also a Final total and a Reset feature.
Here is the actual working version (https://jsbin.com/jocezud/12/edit?html,js,output)
Anyway i think there must be a better way to, in this case run some calculations of data in arrays when a array value change happens, right?
I'm working on an ETL process with Pentaho Data Integration (Spoon, before Kettle).
In the Modified Javascript step of Pentaho you can set a start, end and transform script. In the transform script you can write code that it will be executed only for each row, and from here I don't know how to access to data of the previous row (if it's possible).
I need access to the previous row because all rows are ordered by product, store and date (respectively), and the goal is to get the quantity on hand from the previous row and add the quantity sell or received on the current row (this would be the same product, same store but different date). I also need accessing to the previous row to compare the product and store of the current row with the previous row, because if someone of them changes I must to restart the field quantity_on_hand (I do it with a field of all columns named initial_stock).
On pseudocode would be something like this (if I hadn't the restriction of that the code written on the step is executed only for each row):
while(all_rows_processed()){
current_row.quantity_on_hand = current_row.initial_stock;
while(id_product_current_row == id_product_previous_row && id_store_current_row == id_store_previous_row){
current_row.quantity_on_hand = previous_row.quantity_on_hand + current_row.stock_variation;
}
}
This question related couldn't help me.
Any ideas to solve my problem would be appreciated.
May I ask you to reconsider Group By step? It seems suitable for your scenario.
If you sort the stream accordingly to your combination date/store/article, you can calculate cumulative sum for sell/received quantity. This way you can have a running total of inventory variation that would be reset on a group basis.
Also give a look both at this blog post and at the forum post it quotes.
I doubt you need to go to JavaScript for this. Check out the Analytic query step. That will allow you to bring a value from the previous row into the current.
The JavaScript step gives you tremendous flexibility, but if you can do it with the regular transform steps, it will typically be much faster.
use Analytic Query. By Using this Step u can access the previous / next record. Actually, not only prev and next record that you can read, but you can read N Rows Fordward or N Rows Back Wards.
Check the following URL for clearer expalanation :
http://wiki.pentaho.com/display/EAI/Analytic+Query
http://www.nicholasgoodman.com/bt/blog/2009/01/30/the-death-of-prevrow-rowclone/
Thanks for all, I've got the solution to my problem.
I've combined all your suggestions and I've used the Analytic Query, Modified Javascript and Group by steps.
Although the question wasn't very well formulated, the problem I had was to calculate the stock level on each row (there was one row for each product, date and store combination).
First (obviously later than sort rows by product_id, store_id and date ascending), I used the Analytic Query step to group by product_id and store_id, because with this step I've got a new field previous_date to identify the first row of each group (previous_date=null on the row of the group where date was the oldest).
Then I needed to calculate the quantity_on_hand of each group [product,store] at first row (first date of each group because it's sorted by date) because the initial_stock is different for each group. This is because of (sum(quantity_received) - sum(quantity sold)) != quantity_on_hand.
Finally (and the key was here), I used the Group by step like #andtorg suggested and do it as the next image shows.
This link that #andtorg suggested was very useful. It includes even two .ktr example files.
Thank you so much for help!
i am currently working a project and the client is asking for a feature which is going to require the help of javascript - which i'm no expert with, i can do basics etc but don't really know where to start with this, on the site there is a form (like an advanced search) and on the right it should show the total number of results, but it needs to keep updating as the form is filled in so as the user goes through filling in the form the total number of results is updated to reflect...
I thought maybe it could be done with ajax, passing along the contents/value of the input, performing a query then passing back the total num of results, but how would it work for every input, isn't that just going to be overkill, i tried to tell the client it would be a strain on the server (which surely it would be) but they seem dead-set on having it...
Any help or techniques would be very useful, or if you have come across something like this before please do let me know.
Thanks
Using jQuery you could attach a function to the blur() event of each input control that is used in the 'advanced search' to perform the ajax call to the server and get the current number of results.
This way the ajax server call will only fire each time an input field is completed and the focus moves elsewhere.
Of course if you have many fields this will result in a call each time a field is completed or amended and the focus is moved. It would also be wise to ensure that the field value has changed before making the ajax call. Something along the lines of:
var tempVal = "";
// Each field that is used in the advanced search will need to have the
// advancedSearchInput class
$('.advancedSearchInput').focus(function() {
tempVal = $(this).val();
});
$('.advancedSearchInput').blur(function() {
if($(this).val() == tempVal) {
// Get advanced search values and make ajax call
}
});
I tend to avoid this sort of thing as like you say it can be strain on the server. Here are few things I do to help reduce this risk:
Only perform the search/count when the user has entered at least 3 characters
Cache search terms and their resultant count in a memory store like Redis or memcached
Use MySQL full-text searching if you are running a MySQL DB
Another option is to present fuzzy numbers. So you get the total number of records when the page loads and then as the user types you randomly take a chunk off the total. Once the users term is more specific or they actually click the submit button you can execute actual Ajax requests to get the actual count.
So the user would see something like:
Search: ""
Response: There are about 3097 records relevant to your search
Search: "Ap"
Response: There are about 1567 records relevant to your search
Search: "Apple"
issues ajax request
Response: There are 542 records relevant to your search
I have a GridPanel with just two columns: names and commission percentages. The sum of all of the percentages should never exceed a predetermined maximum (say that 25% of the sale is up for grabs).
Name Commission
Bob 10%
Sally 15%
(Maximum is 25%)
Everything is fine.
I’ve attached a custom validator (see "validator") to the NumberField editor which works just great for complex logic on individual values, and I can sum up all of the values for the number column in the data store easily. But the problem is combining the two; the new value isn’t pushed to the store until after a successful validation, and the custom validator is only given the current value in question, with no context as to what row is involved (with which I could potentially subtract the old value, and use this new value in the total).
How can I get this validator to work in such a way that it makes sure that a newly entered value doesn’t push the sum over the maximum?
Name Commission
Bob 10%
Sally 16% (Invalid! Total commissions must not exceed 25%)
(Maximum is 25%)
You need to pull in the dirty value of the changed element before it is saved to the database. It does not make sense to validate the clean value after the fact.
See here for info on data storage in ExtJS:
http://www.fusioncube.net/index.php/managing-dirty-rows-in-a-sencha-extjs-editorgridpanel
You can use properties such as field.originalValue and field.getRawValue() to get at the data store and see the difference.
I didn’t quite use js1568’s answer, as I wanted to block bad values as they’re being entered; even before the AfterEdit event fires and the row gets marked dirty, and long before writing to the database. But that link did inspire me through its use of the grid’s selection model. So, my quick little solution:
Because the NumberField doesn’t pass any context to the custom validator (aside from the current value), using field.originalValue would have been awesome, but hey, life is hard.
But due to the fact that editing a row first requires selection of that row (and reinforced by the fact that this grid’s RowSelectionModel is set to SingleSelect), I know that the row being edited must be the only element in grid.selModel.selections.items[]. From there, it’s just a matter of
var newTotal = TotalCommissionPercentagesInGrid() – oldValue + newValue;
With oldValue being grid.selModel.selections.items[0].data.CommissionPercentage and newValue being the value passed to the validator function from the NumberField.
return ( newTotal <= percentageAvailable ) ? true : "No dice.";
Very nice.