We are trying to implement an OPC Server, with a specific objects structure, as you can see in the following example:
Node X
Item 1
Item 2
Item 3
Item 4
Item 5
Item 6
Item 7
... (till 300)
Node Y
...
But, for some strange reason, in several OPC clients the items are shown like this:
Node X
Item 3
Item 11
Item 22
Item 33
Item 44
Item 55
Item 4
... (till 300)
Node Y
...
Our main problem is about sorting the items in the list. As you can see in the screenshot the items are not shown sorted in the OPC client, and we have tried several OPC clients and some of them have a special option to show the items in a sorted way and some others no.
The thing is... if we are creating a generic OPC Server for all the existing OPC clients in the market... it is responsibility of the server to serve the items sorted, right? or... is it responsibility of the client?
Conceptually, which is the correct way?
My feeling is that the OPC Server should give all the items sorted anyway, but I'm not sure if it is possible and standard.
Otherwise, there are a lot of SCADA's in the world, for sure, that trying to show the list of items in a screen will show them not sorted, as in the sample provided, and this is a big problem when you have around 300 items in a list.
Thanks for your collaboration!
The order of items has no significance in OPC specifications. In addition, OPC does not "tell" the servers in which order they should enumerate the items, and it does not "tell" the clients in which order they should display them.
If you want to see the items ordered in a specific way, the best you can do is to develop your OPC server so that it indeed enumerates them in that order. When done this way, the OPC clients that do NOT sort the incoming items in any way will list them in the order you have chosen. With OPC clients that decide to sort the items somehow, you are out of luck - they will always do it their way. I would argue that good OPC clients that present the items to the user should allow them to influence the ordering, but that's up to them.
Also, the example order you presented somewhat resembles what happens when strings are sorted using the "dumb" ordering, and not looking for the natural number order in them. This leads to number ordering where numbers with less digits are interspersed within numbers with more digits, instead of numbers being taken for their numerical value. But, if that was the case, you example would like more like this:
> - Node X
-- Item 1
-- Item 10
-- Item 11
-- Item 12
-- ...
-- Item 2
-- Item 20
-- Item 21
-- Item 22
-- ...
-- Item 3
-- Item 30
-- ...
Node Y
Isn't that what you are getting? (but regardless of it, the first part of the answer applies anyway).
Related
Is it possible to sort the lines in a transaction by item (or some other column field)? We often receive very large orders from our customers and the items are in a more or less random order. When we receive said items from our vendors, the items come in numerical order by part number. It's very difficult for our logistics to receive them when our purchase order is in random order but the items came numerically. Is there any way for me to sort the purchase order by item #?
Re-sorting transaction lines is possible but quite prone to breaking. Until Netsuite actually supports it my recommendation would be to not spend time trying to re-sort lines.
About the only place it's safe to do that is on a Sales Order in the before Submit phase. Generally a sales order is the start of a whole chain of related transactions. Some of these relations are visible from fields and some are hidden. There is no api to re-sort the lines so the the way to get them sorted is to cache the lines in memory; clear the lines from the sales order; and then re-insert the lines in the desired order.
You have to make sure you capture everything and that you account for future customizations in your code.
So the alternative of supplying a sorted UI to aid fulfillments and receipts is much more reliable. Some of the ways I've done that include:
Adding a text area where people can paste a formatted list of skus/qtys received. A client script processes that and sets up the item receipt lines.
Creating a pop-up with the PO's items sorted as you like with whatever controls you need for efficient handling. The pop-up has a button for processing items when you are done with the receipt.
A field that lets you enter a sku (can have type ahead) that either brings you to the item you are receiving (selects the line) or provides a qty field as well so you just work at the top of the item list and enter and sku/qty/click process... until you have received the order
a similar thing but expecting a scanner to provide the sku so the process is gun/qty/click process
I'm building a pairing system that is supposed to create a pairing between two users and schedule them in a meeting. The selection is based upon a criteria that I am having a hard time figuring out. The criteria is that an earlier match cannot have existed between the pair.
My input is a list of size n that contains email addresses. This list is supposed to be split into pairs. The restriction is that this match hasn't occured previously.
So for example, my list would contain a couple of user ids
list = {1,5,6,634,533,515,61,53}
At the same time i have a database table where the old pairs exist:
previous_pairs
---------------------
id date status
1 2016-10-14 12:52:24.214 1
2 2016-10-15 12:52:24.214 2
3 2016-10-16 12:52:24.214 0
4 2016-10-17 12:52:24.214 2
previous_pair_users
---------------------
id userid
1 1
1 5
2 634
2 553
3 515
3 61
4 53
4 1
What would be a good approach to solve this problem? My test solution right now is to pop two random users and checking them for a previous match. If there exists no match, i pop a new random (if possible) and push one of the incorrect users back to the list. If the two people are last they will get matched anyhow. This doesn't sound good to me since i should predict which matches that cannot occur based on my list with already "existing" pairs.
Do you have any idea on how to get me going in regards to building this procedure? Java 8 streams looks interesting and might be a way to solve this, but i am very new to that unfortunately.
The solution here was to create a list with tuples that contain the old matches using group_concat feature of MySQL:
SELECT group_concat(MatchProfiles.ProfileId) FROM Matches
INNER JOIN MatchProfiles ON Matches.MatchId = MatchProfiles.MatchId
GROUP BY Matches.MatchId
old_matches = ((42,52),(12,52),(19,52),(10,12))
After that I select the candidates and generate a new list of tuples using my pop_random()
new_matches = ((42,12),(19,48),(10,36))
When both lists are done I look at the intersection to find any duplicates
duplicates = list(set(new_matches) & set(old_matches))
If we have duplicates we simply run the randomizer again X attemps until I find it impossible.
I know that this is not very effective when having a large set of numbers but my dataset will never be that large so I think it will be good enough.
I'm trying to create a backend in Spring Data Mongodb. I have the following code which works and I have used the built in methods by extending my repo with the MongoRepository class:
#RequestMapping(value="/nextpost", method=RequestMethod.GET)
public List getNextPosts(#RequestParam int next) {
Pageable pageable = new PageRequest(next, 5, new Sort(new Sort.Order(Direction.DESC, "id")));
page = repo.findAll(pageable);
return page.getContent();
}
The above code will return the page as per the page number inserted into the "next" variable.
My android frontend however allows for things to be added and deleted from the database and this causes problems with this pagination method. Lets take an example:
When my android frontend starts up, it loads the first 5 items by
calling "getNextPosts" with next = 0.
My android frontend also keeps track of the page it is on and
increments it when the user wants to see more items.
Now, we immediately add 5 more items.
When I swipe up to fetch the next 5 items, it calls the
"getNextPosts" method passing the the "next page" value = 1. The app
will load the
same 5 items originally displayed when the app was started as the 5 "NEW" items I have added just pushed the 5 "OLD" items down in
the database.
Therefore on the app, we see 15 items comprising of:
5 "NEW" + 5 "OLD" + 5 "OLD"
So if I gave numbers to all my items on my android ListView, I would see:
15
14
13
12
11
// the above would be the new items added
10
9
8
7
6
//the above would be the original items on page 0
10
9
8
7
6
//the above would be still be the original items but now we are on page 1
Does anyone know how one can solve this issue so that when I swipe up, the items would be:
15
14
13
12
11
// the above would be the new items added
10
9
8
7
6
5
//the above would be the original items on page 0
4
3
2
1
0
//the above would be on page 1
tl;dr
That's the nature of the beast. Pagination in Spring Data is defined as retrieving a part of the result set at the time of querying. Especially for remote communication, that kind of statelessness is usually the best tradeoff between keeping state, keeping connections open, scalability etc.
Details
The only way to avoid this would be to capture the state of the database at the time of the first access and only work on that. You can actually build this by retrieving all items and page through the data locally.
Of course hardly anyone does this as it easily gets out of hand for larger data volumes. Also, this would bring up other problems like: when do you actually want to see the items introduced in the meantime? So the definition of "correct content" when paginating a list is not distinct.
Mitigation strategies
If applicable to your scenario you could try to apply a sorting that guarantees new items to be added at the very end and thus basically making this an append-only list. This would naturally sort the most recent items last though, which is contrary to what's needed often times.
If you use the pagination to work down a list of items and process all of them, another approach is to keep track of the identifiers of the items you already have processed. In your particular scenario, you'd be able to detect that the items have already been processed and go on with the next page. This of course only makes sense if you read and process faster than someone else manipulates the list in the backend.
Another solution could be to store an insert timestamp into the db for each entry. This enables you to create deterministic pagination queries:
The moment you initialize pagination (querying first page) you restrict items to have an insert timestamp lower equals than now(). You have to save now() as the pagination timestamp for querying more pages in the future. Since newly added items all get an insert timestamp greater than the pagination timestamp those items won't affect existing paginations.
Please keep in mind that new items won't show until you re-initialize pagination by refreshing the pagination timestmap. But you can simply check for the existence of new items by counting the number of items with an insertion timestamp greater than the pagination timestamp and in this case show a refresh button or something like that.
We are using Endeca to fetch and display records in frontend as a datagrid. In that datagrid, we have 10 columns and we display data sorted in table on the basis of 2 columns (say X and Y). For this, we use Endeca.stratify(collection()/record[not%20(X)])||X|1||*,Endeca.stratify(collection()/record[not%20(Y)])||Y|1.
We can also apply filter on the columns where we display data sorted asc/desc. We used Dynamic Ranking in Endeca and created dimensions for each field with selecting dynamic ranking and set maximum dimension value to return as 20 as per the requirement. Since we know that dynamic ranking is the relevancy ranking, it fetches most used records and does sorting on that data.
However, we need to select 20 unique values and sort them in asc/desc order. Example: if we have date as the column, then we need to fetch 20 unique dates with most recent at the top. i.e. in descending order.
Is there any other way to do sorting on filter apart from dynamic ranking? If we disable dynamic ranking, then we won't have option to set maximum dimension value as 20 from developer studio.
Please suggest for the ranking.
We finally found a solution!! I removed/unchecked "dynamic ranking" for the properties in dimensions from the pipeline using developer studio. I did not want it to remove since we had already selected an option as sort "alphabetically" instead of "dynamically" in dynamic ranking tab in dimensions.
Also, if we uncheck dynamic ranking then the option for giving maximum limit for displaying the dimensions (which was set 20 for us as per the requirement) was also gone.
So, I handled this in java to display only 20 values by putting a check on results obtained and created a counter which would add values only till the 20 are received. Now this is working as required!!!!!
We have a database with 2,00,000 vendor in 100 plus category, if someone visit the website we want to allow them to select a category and show them 25 Vendor per page, first we kept order by VendorId but it always use to get first 25, but we removed it, but now in paging it sometime repeat the vendor, is there a way to get random 25 vendor and also keep the paging.
Regards
you can randomize your result but everytime you dot he query, it will create new random list so unless you randomize and save the randomized state in your Code and page over it, it cant be done straightforward way.
refer, SQL Query results pagination with random Order by in SQL Server 2008
I believe this requirement is impossible to implement if a new random order is needed every time, there needs to be good performance and every item should have equal chance to get selected. I believe you should redesign the way your application works.
One possible workaround is to have a couple of columns in a table and fill them with random numbers. When a user requests the list assign the random column to him (stick it in the URL for example). Then do an order by that column and display the results. Randomly switch 4-5 columns to create the appearance of randomness. Update the random numbers in the columns once a day.