Everyone on Snapchat wants to increase their Snap score and know the intricacies of how does Snap score work. Snap score is the number of snaps you have sent and received. If you are an avid Snapchat user, you must know that the progress on the app is kept up with the Snap score. You can send snaps, have a conversation, and upload stories on the platform. One notable downside is that if the user decides to stay up at 11:59pm, technically they can increase their streak by 2 in the span of a few minutes.Snapchat is one of the most sought platforms in the contemporary social media scenario. Keep in mind, if you don't have a profile model or something similar and plan to implement it, you'll need to change up your user sign up model and forms. I just put the increment_streak in a seperate function out of habit but you can put it in the save function as well. Then in the Profile modal: def increment_streak(): If you want to simulate snapchat more closely, adjust the threshold of streak loss in the function above to something like 36 hours to give users a bit of leeway. This function ensures that it's a new day to make sure the user can't abuse the streak by submitting a bunch of entries. Of course you could also use your method, searching for the latest answer and testing what time it was submitted, but then you should be saving the exact time of submission onto the ModalAnswer.įinally, when submitting, you should increment the streak. Then every time the user views the streak-or if you want to save resources you can use the method mentioned and run the function using celery-you should run this check from datetime import datetime, timedelta Last_answered = models.DateTimeField(null=True) User = models.OneToOneField(User, on_delete=models.CASCADE) To add the two fields onto the user model, you should extend the user model with a profile model like so: class Profile(models.Model): In addition, as pointed out in comments, the current_streak should be saved on the user/profile model. Then, to ensure that the streak would not stay at (for example) 2 until they submitted the next post, a check is run every time the user viewed their streak to see if last_answered was more than 24 hours away. Every time the user would upload a log, last_answered was set to the current time. The method I used was to add a last_answered field onto the user/profile model. I've created a journaling app with a similar streak system. Super(ModelAnswer, self).save(args, kwargs) Self.current_streak = answers_created_yesterday.current_streak + 1 If answers_created_yesterday is not None: # get the categories created yesterday to maintain the streakĪnswers_created_yesterday = ( Here is my main logic part this is not working as per required def save(self, *args, **kwargs): User = models.ForeignKey(User, on_delete=models.CASCADE)Ĭurrent_streak = models.PositiveIntegerField( I tried this code in django but any help in any language will be valuable class ModelAnswer(BaseModel): Streak is actually based on user and answer if user adds answer than streak is maintained. If the user adds a new data record once every 24 hours streak is one irrespective of how many records he/she adds and streak is 0 if he/she fails to add with in next time period and adds by +1 in next 24 hours timeframe from last record added. Here is how streak gets counted in snapchat I am failing to build logic regarding streak feature similar to Snapchat.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |