Override UserId in Segment Analytics - analytics

Basic question here related to Segment analytics. Unfortunately I haven't been able to find a good answer after a fair bit of searching so turning here.
I have a couple of analytics events that need to be logged against multiple users, e.g. "Matched"
Is there a way to override the "userId" property on a event without calling identify again (which would override the user for all future events & thus risks race conditions or blocking on analytics)?

This is not possible with analytics.js. If you need to send events for another userId than the one you had called .identify() with, you should use a server side library to send that event.
All server side libraries will need a userId defined so it would be a good place to send that particular event.
Also Segment just got a brand new community to post these questions fyi.

Related

Firing multiple api calls at once

I'm struggling to find the right words to convey what I'm looking for in my research, so I thought I would ask the stackoverflow community. I am looking for best practices to create records in different tables at once.
An example would be, user registration. Say you need to create 6 records for that user when they sign up, which need to connect. By connect I mean in the sense that if a user and team were created on user registration, the userID would need to be included in the team's members array. So the records need to fire in order so the relationship is properly recorded. So user would need to be created first, then the team record so I can add the userID to the team's members. Also note that the user record would need to be updated later on (after the team's record is created) with the teamID under the user's teams.
So as you can see it feels a bit all over the place. Currently I have multiple API calls being fired on user submit. While I have this working using redux, firebase and react — I foresee a lot of potential errors happening and feel as if I am not doing this in the most efficient way. I want to do this correctly and happy to do the research, I'm just not exactly sure what I am looking for. I was hoping for some guides, information, search terms, etc — basically anything to help me understand this concept more throughly if that makes sense.
This is a perfect candidate for GraphQL and a backend that handles it properly. Take KeystoneJS for example. You could do a single create user and handle it all internally via the hooks system. You can also do nested creates / connects all in one mutation and KeystoneJS will take care of all of it for you if there are nested operations. For example you can create object A, then create object B in one mutation. It'll create B, then A, then connect A to B... with no extra work on your end. I just give this as a single example of a tool you can use. Here is an example mutation that Keystone just handles:
mutation CreateUser {
createUser(data: {
username: "test"
organization: {create: {
title: "test"
}}
})
}
Notice organization is created inside of the user mutation.
Yes, I think the best practice is to have your back end, whatever it is, do the work. It will fail if it bumps into an issue and clean itself up. Otherwise, it produces a positive response. I hope this is helpful...
For alternatives, since this is a pretty open ended question... I've also created a nestJS back end. That works great too, but it's a lot less opinionated with fewer built in solutions, so you do a lot more work (but it's more flexible). Any CMS should give you control over this (Strapi seems to be taking off... I just ran into too many bugs with it).

WPF MVVM architecture, what is the best practice communicate between model and viewmodel

We are developing a TODO list kind of application in WPF
1)when user logs in we load list of workitem for the user(only basic details)
2)when user opens particular workitem we load all its information from service
3)we use signalr to add new workitem to the user when he is working on the system (singalr will
send the workitemid, and based on it we will fetch basic detail and add it to the workitem list)
Whenever user edits the workitem, if he changes anything in the workitem information, we should move it to UnSaved List, and if he reverts it we need to move the workitem to Opened List
1)when user enters something in screen it directly alters model (letsay workitem model has user model and user model has firstname, this firstname is bound to the textbox), how to communicate this change
to the viewmodel, so that viewmodel will move this workitem to unsaved list.
To find out a workitem is dirty or not, we are keeping Unchanged workitem details inside each workitem, so whenever user changes something in screen we make comparision with this unchanged workitem and move it to unsave or opened list.
2)Is it right approach to have Unchanged workitem inside each workitem, are there any best approach or pattern available?
3)how to differentiate between user changing some value of workitem and system changing values of workitem
let say A and B user sees the same workitem in edit mode, User A edits some value in workitem and
saves it, now user B will receive this information through signalr notification, and we will make a call to service based on this workitemid and will populate the changes in B's screen. Now we should not move the workitem to unsaved list, because changes are done by system.
4)Moreover we will recieve lot of signalr notification related to multiple workitems, we don't
want to make multiple service call as and when signalr notification comes, but whenever user clicks on workitem we would like to see the changes done in that workitem from other user. What is the efficient way of doing this. (We don't want notification to contain all the information, we kept only the Id and type of the notification, so that signalr will be as lean as possible)
5)how to compensate for singalr notification failiures, (we could make some kind of timer which will periodically poll list of notifications based on the last arrived notificationid).
Is this a good approach or any pattern exist for this kind of problems.
I am not quite sure if I understand your questions.
So conceptionaly I think you are thinking about a real-time collaboration sort of software.
There are patterns and algorithm how this is solved in a distributed fashion. You should look for the papers of the google wave protocol (the foundation of the real time editing feature of the google docs tools) http://www.waveprotocol.org/whitepapers. Or research for Operational Transformation: https://operational-transformation.github.io/.
The good think is that there are already libraries out there which handle protocols like this and adapt or extend these concepts.
But finding the right library for handling realtime callobrative work over signalrs whould be a huge win. Don't know if there is also a library that builds on top of signalrs - might be worth a google or bing session.
But I think before you talk about technical details as c# or mvvm it would be a good start to understand the background of real time collaborative communication in distributed systems.
Like I said I hope I got your question correct and since you did not post any source code there is no chance to be more precise...
HTH and leads you into the right direction.

Create does not work in GAE Datastore viewer

When I try to create some entities I don't see the option to input fields. I just see the SaveEntity button.
However I can view all the existing entities.
What is very strange is - there is another entity called VideoEntity for which the create did not work yesterday but works today.
Can somebody help me with this seemingly unpredictable tool ?
Regards,
Sathya
i think the console knows what properties each entity has based on existing data, rather then your models. and the data is only updated periodically. when did you upload your app? maybe waiting a few hours will give the console time to update.
alternatively, you could use the remote api to add your entities, or write a small snippet and upload such as ...
VideoStatsEntity(app='home', ip='116.89.52.67', params='tag=20130210').put()
Writing a simple interface to the data-store to allow you to edit/create models is probably the best thing to do in this case. You know what they contain so you can adjust your interface accordingly, rather then waiting for the admin interface to "catch up" as Gwyn notes.
I believe that there are some property types that are impossible to add via the admin interface that you are using so you'll probably get to the point sooner rather then later of creating a custom interface.
The admin datastore view is good for quickly checking out the contents of the datastore, but ever tried paging through 100's of entries? Not fun.

Django forum database design

I'm extending an existing Django forum app (DjangoBB) to allow users to opt in/out of notifications for specific forums and/or specific threads. I already have an existing notification infrastructure on my site, and an existing global setting to turn forum notifications on/off.
What I want to do is allow each user to subscribe/unsubscribe from specific forums or threads, effectively overriding their global setting. For example, if my global setting is 'Notifications Off', then I would not get any notifications, unless I set a specific forum to 'Notifications On', in which case I'll get notifications for everything in that forum, unless I set a thread in that forum to 'Notifications Off'. If any thread or topic doesn't have a setting set, it defaults up the chain.
My question is what's the best way to represent all of this in my database in Django? I have two ideas:
class ForumNotificationSetting(models.Model):
user = models.ForeignKey(User)
forum = models.ForeignKey(Forum)
setting = models.NullBooleanField(default=None)
I would also have a similar model for TopicNotificationSetting. This way, whenever a user changes their forum settings, I create (or modify) a NotificationSetting object to reflect their new settings. This method seems simple, but the downside is if lots of people create settings for lots of forums, then creating notifications for everyone would be O(n^2) whenever a new forum post is made. (I think...?)
The second way I can think of would be to create a ManyToMany field in each user's profile for all forums to which they have set settings for. This way seems more complicated (since I'd have to have 4 total M2M fields for 'forums on', 'forums off', 'topics on', and 'topics off'), and I'm not sure if there would be any performance benefits or not.
How would you solve this problem?
Perhaps you could create an M2M relationship on the level of the Thread or Forum object, e.g.:
class Thread(models.Model):
subscribers = models.ManyToManyField(User)
other attributes...
Then, as a user (un)subscribes from a Thread, you add or delete them from the Thread object's subscribers property.
In your application logic, when a user creates a post, thread or forum, you could just check their overall notification setting and - if set to True - add them to to the subscribers property of the newly created Thread, Post or Forum.
Each time a thread, post or forum is updated, you could then notify all subscribers.
I'd assume you'd need some logic to handle escalation (I can't find the proper word, sorry), i.e. I'd assume a notification for a Thread update should also trigger a notification for a Forum update (or should it?). And then you should of course take care that a user doesn't get spammed with post, thread and forum notifications for a single Post update...

Need ideas on retrieving data from a website

I'm stumped and need some ideas on how to do this or even whether it can be done at all.
I have a client who would like to build a website tailored to English-speaking travelers in a specific country (Thailand, in this case). The different modes of transportation (bus & train) have good web sites for providing their respective information. And both are very static in terms of the data they present (the schedules rarely change). Here's one of the sites I would need to get info from: train schedules The client wants to provide users the ability to search for a beginning and end location and determine, using the external website's information, how they can best get there, being provided a route with schedule times for the different modes of chosen transport.
Now, in my limited experience, I would think the way to do that would be to retrieve the original schedule info from the external site's server (via API or some other means) and retain the info in a database, which can be queried as needed. Our first thought was to contact the respective authorities to determine how/if this can be done, but this has proven to be problematic due to the language barrier, mainly.
My client suggested what is basically "screen scraping", but that sounds like it would be complicated at best, downloading the web page(s) and filtering through the HTML for relevant/necessary data to put into the database. My worry is that the info on these mainly static sites is so static, that the data isn't even kept in a database to build the page and the web page itself is updated (hard-coded) when something changes.
I could really use some help and suggestions here. Thanks!
Screen scraping is always problematic IMO as you are at the mercy of the person who wrote the page. If the content is static, then I think it would be easier to copy the data manually to your database. If you wanted to keep up to date with changes, you could then snapshot the page when you transcribe the info and run a job to periodically check whether the page has changed from the snapshot. When it does, it sends an email for you to update it.
The above method could also be used in conjunction with some sort of screen scaper which could fall back to a manual process if the page changes too drastically.
Ultimately, it is a case of how much effort (cost) is your client willing to bear for accuracy
I have done this for the following site: http://www.buscatchers.com/ so it's definitely more than doable! A key feature of a web scraping solution for travel sites is that it must send you emails if anything went wrong during the scraping process. On the site, I use a two day window so that I have two days to fix the code if the design changes. Only once or twice have I had to change my code, and it's very easy to do.
As for some examples. There is some simplified source code here: http://www.buscatchers.com/about/guide. The full source code for the project is here: https://github.com/nicodjimenez/bus_catchers. This should give you some ideas on how to get started.
I can tell that the data is dynamic, it's to well structured. It's not hard for someone who is familiar with xpath to scrape this site.

Resources