I'm using the facebook api to retrieve a list of a user's photos. I'm using this to work out the user's close friends by seeing who has been tagged the most in the user's photos. So what I have the list of the tagged users (there will be duplicates). What I want to do is go through each tag and insert the user into a data structure. If the user is already there I want to increase that user's count by one. At the end I want the list ordered so I can 'rank' the friends. What data structure will be best for this?
Step 1:
Use an associative container. Map from UserId to user's count. Keep adding new users, and updating the user's count as you process more data.
Step2:
Copy all the users to another associative container, Now the key should be a pair(user's count, UserId).
You can now iterate over the 2nd container and have your items in order.
If you're using C++, you can use map for step 1, and set for step 2.
Related
I want to work with Elasticsearch to process some Whatsapp chats. So I am initially planning the data load.
The problem is that the data exported from Whatsapp, doesn't contain a real unique id per user but it only contains the name of the user taken from the contact directory of the device where the chat is exported (ie. a user can change the number or have two numbers in the same group).
Because of that, I need to create a custom explicit mapping table between the user names and a self-generated unique id, that gets populated in an additional column.
Then, my question is: "How can I implement such kind of explicit mapping in Elasticsearch to generate an additional unique column?". Alternatively, a valid answer could be a totally different approach to the problem.
PS. As I write, I think the solution could be in the ingestion process, like in a python script, but I still want to post the question to understand if this is something that Elasticsearch can do by itself.
yes, do it during the index process
if you had the data that maps the name and the id stored in a separate index you could do this with an enrich processor when you index the data to add whichever value you want to the document via a pipeline
also - Elasticsearch doesn't have columns, only fields
I have a multi-user website and each user has own data which I can store on s3.
I want to integrate(embed) QuickSight to my website, in that way so each user able to see own data.
I want to have one analysis to be able to modify if for all users.
Are there some recommendations on how to achieve this?
Firstly, you will need to add the user's identifier (email, name, generated ID, whatever) to each row that belongs to them in the S3 data. I'm kind of assuming that you are storing the data in a tabular format (e.g. CSV) but let me know if I'm wrong. So let's assume you added this user identifier as a new column called userId.
Secondly, you will need to generate a manifest file that points to all of your users' S3 files.
Then, create a new data set, pointing to that manifest.
Then, you will need to create another new data set that ties a QuickSight UserName to the new userId column you have added. You will need to maintain this data set somehow, but fortunately the QuickSight UserName has a pattern to it (something like embed_role\user_name).
An example of this new data set might look like
UserName,userId
your_embed_role\user3479125,user3479125
Once you have this data set you can attach it to the S3 data set created earlier as row-level-security (RLS). You can think of QuickSight as performing an inner join on userId between the RLS data set and the actual visual data set, thus limiting the data to the given UserName.
In our application we will give titles to users based on their points. So, if a user has 10-99 points, that user might get the "Novice" title, but a user with 100-199 points might get the "Regular User" title. I plan on eager loading a user's points using an attribute and relationship, and once I have those points I will use an attribute method to assign the title.
But how do I get the list of possible titles?
I could make a model, a migration, and a seed file, but I feel like these titles won't change much and certainly would never need to be updated in an API call. I could also hardcode an array of points and titles and do a quick lookup to see which title belongs to a user, but then I need to somehow deliver those titles to the user in an Attribute method. Or I could store them in a repository or the cache.
Can I access a repository from within a model? Is it better to store this sort of data in a DB anyways, regardless of how often it's updated or queried?
You could use entries in your .env file to store the entries and then use some logic in your php to select the correct .env entry.
LEVEL_1_TITLE=Novice
LEVEL_2_TITLE=Regular
...
if($user->points < 99){
$title = env('LEVEL_1_TITLE');
}
...
Or do the same thing from an array in a class that you create and just select the correct array entry based on the points.
We have created multiple stores in single ofbiz instance. We need to populate order list for a given admin user for a store. Currently its showing orders of both the stores even though user is not a part of second store.
Please suggest if it is possible. If yes, please let me know the corresponding configuration/code changes required.
You simply can filter the orders by the productStoreId which is part of the OrderHeader entity, see http://demo-stable-ofbiz.apache.org/webtools/control/FindGeneric?entityName=OrderHeader .
My website allows users to communicate using conversations.
In the conversation-inbox page a user can see all the users that have contacted him, including a preview of the latest message from the specific user. The page is order by the date of the previewed message.
It looks roughly something like this:
UserA "Some message.." 2016-3-3
UserB "Other message.." 2016-3-2
UserC "..." 2016-2-15
etc..
I was wondering what is the correct combination of the Redis data structures to use to model this efficiently.
At first I thought about having a sorted set of the users (i.e. UserA, UserB, UserC), but this would mean I would have to have a loop to get the latest message from each user.
Is there a better way, avoiding the loop?
Thanks!
You'll need two data structures for each user's inbox: a Hash and a Sorted Set.
The Sorted Set's scores can be all set to 0 as we'll be using lexicographical ordering anyway (but there's no harm in setting them to the actual timestamp of the message, at least in the context of this answer). The members of the Sorted Set should be constructed in the following manner:
<date in YYYYMMDD>:<from user>:<message>
This will let you easily pull that view and page through it with ZREVRANGE.
But that's only half of the story - when userX is sent a new message from userA, you'll need some way of finding and removing userA's previous message from userX's inbox - that's why you need the Hash.
The Hash is used for looking up the latest message from a given user to userX. For each of userX's friends, keep in the Hash a field that is the sending user's ID (e.g. userA) and whose value is the inbox's Sorted Set member that represents the latest message from that user (same "syntax" as above). When a new message arrives, first fetch the previous message from the Hash, remove it from the Set, and then add the new message to the Set and update the Hash's field.
To make sure that Hash and Sorted Set are consistent, I recommend that you look into wrapping them together in a transaction. You can use a MULTI/EXEC block, but my preference is a Lua script.