I am doing a mobile game server using node.js. I used the Express and postgresql
I have two questions.
This game has a Inapp is 30 daily gems that user can get the gems in 30 days period. But I don't know how to implement the method let the server know the user bought this item and send the reward to this user every day.
This game has a special offer item in InApp. For example, a Christmas pack in 25/12 - 27/12. But I don't know how to set this 3 days can show this pack.
I am beginner in node.js. So I hope that you don't think my question is stupid. Thanks
Speaking at a high level, you have quite a few options.
For your gems requirement, you would probably have a field or table that represents this gem purchase, e.g a start date. If a user bought this package say on 1/1/2019 then your node server can have a process that runs once a day that queries the purchase table and give gems to any user where the current date is less than 30 days ahead of the purchased date.
Your table may look like:
user_id
date_purchased
gems_per_day
To implement this as a function that will run once a day, you may want to create a singular script for it and run it on a cron job once per day or create a Timer type class within Node that will run your function every 24 hours.
For your special offers, as part of your Store code, let's say you have a function that updates what items are currently available in the store, you run this code once per day (as one of the 2 methods mentioned above) and probably storing these items in your database. Similarly, you can check each day if the current date is within this "special offer period" and if it is, you can set that product within your database to be active.
Your table may look like:
product_id
enabled
or
product_id
start_dayMonth
end_dayMonth
Hope this gives you a few ideas of how you can lay this out. Happy to answer any questions
Related
Every few months my team creates a list of parts we couldn't have predicted we'd need. For a while we've been going to digikey and mouser, typing about 1000 searches in, and seeing what supplier has the right quantity.
But part shortages have made the "quantity available now" fluctuate considerably hour to hour, and sometimes even minute to minute. Is there a way to setup notifications for when products have a certain amount available?
I've tried webscraping digikey with nodejs, and making a little dashboard of link's that turn green when they're ready to buy. That worked for a while until Digikey blocked my IP address
I've considered using their API's, but they don't appear to offer buy if <logic> event setters, and only offer 1000 requests a day
mouser api
digikey api
What would be the best tool for the job?
I am sorry but there is no code attached to this, as I simply don't know what direction to go in. I have a bot made for a clan in Anigame. Quite simply there are weekly donations,(in this case it's 30k). For someone to donate, they can do .cl donate [number].
Ex: .cl donate 30000 | This donates 30k to your clan which is the weekly donation required and means you have donated for the week.
Tracking donations is a pain in the ass so I wanted to make a bot to do it for me.
What I wanted to do is make it so that this person that just donated 30k can do .info and it says something like this:
Weekly: Done!
Debt: N/A
The debt being for people that have missed a week's donation.
EX: Someone hasn't donated for 2 weeks, has 60k debt. This is the third week, and if they decide to donate 90k that week, the bot makes it so weekly donation is paid and debt is paid.
I also don't know how to make that become possible, and I hope you [reader] understand where I'm trying to go with this.
I have the base cron job code to make sure it resets weekly, I just don't know how to do the code)
Tldr; How to make it so that .cl donate (number) updates a Weekly Number under the command [.info]. I wouldn't normally be so specific so I can learn how but I don't know the commands associated with doing this kind of thing. Thanks~
You should start with researching databases (for example SQLite), and then coding your bot to input values to that database on each command, then calculate the .info command based on the values that specific user has in the database, then your cron job could reset the database weekly (or the bot could do that too, you do you). Here's a good tutorial: SQLite tutorial
I have an application that uses subscriptions for each member that joins. I'm having some issues with dates and calculations related with it. For example, let say a member joins on 2/10/2020 at 10:00. When the user submit the request to the server to process the subscription (the server is using UTC) the date that is being calculate is 2/10/2020 16:00 (because I'm -6:00 hours from UTC). This scenario is OK at this point, because the date is still the same (no matter the time). But, if we replicate this scenario when the user joins for example 2/10/2020 at 19:00, when the request is received and calculate the date, the result is 2/11/2020 01:00, and that produces an error in the invoice because the billing date of the invoice is wrong (one day after). What is the best way to implement this? I have read a lot of this topic, but most of the pages and questions are related in the other way, server to client, to parse of format dates to display to the user.
I have several questions related with this process.
Should I sent the date for the UI to the API? Or the timezone and
based on that, calculate the date in the API? (since the server have
UTC)
Moment.js library have a way to solve this or should be better with vanilla Javascript using Date?
Is there any HTTP header for the request to handle the time or date?
This really depends on what behavior you want to have. Before you try to fix anything, think through and decide on the exact requirements for what the billing date should be based on.
Is the user's time zone relevant? If so, you'll likely need to know what the user's time zone is. You'll be potentially assigning different dates to different invoices even if they're using the same UTC point in time. Your business might get confused on why some customers have invoice dates before or after the business day.
Or maybe the time zone of your company is more relevant? Many business work that way. All of your invoices will be aligned, but some customers might get confused on why their invoice date is before or after their current date.
Or maybe some customers snap to time zones of nearby offices, in the case of businesses with offices around the world.
Only you and your company can decide this. There are probably other options I'm not thinking through here. It's a business decision, not a technical one.
On your three questions:
That depends on what you decide above.
Libraries are a good idea for simplifying your code, but they're not a hard requirement. You can use the Date API, if you know what you're doing, but you may find libraries easier to work with. Also, Moment is in maintainance mode. For new development, the Moment team recommends you use Luxon instead of Moment. There are other popular modern libraries also, including date-fns and js-Joda.
There's the date header, but that's not going to help you with this.
Okay, first of all I want to tell you that I am new to all this techniques mentioned in the title.
I want to make an new app. Think of it as a real time trading engine (like for stocks for example).
So, there are two things that really matter:
Speed / Performance: Everyone has to see trades in realtime
Security: Same trades can be made simultaneously but only one can be successful
I thought about an approach like this:
If a user wants to buy 10 peaces of stock X for $100 each he places an order which I store with Redis (speed) and push it to all clients with socket.io. Well, as soon as another user wants to sell 15 peaces for $100 the script should check if there is an open buy order. If so, it saves it as a successfull transaction in MongoDB (persistance) and closes the buy order of 10 peaces.
In this example 5 peaces are left. The script would display that with a calculation like this: 15 (sell at $100) minus 10 (buy at $100) equals 5 left. Every time someone want's to trade something this calculation would be made because I don't know how many stocks are left for trading else.
Edit: Or I could subtract 10 peaces of the 15 peaces in Redis so that I don't need to calculate every time. But if something would go wrong, I wouldn't know what the original data was. That's a problem.
Now the questions are:
Would you make it like this? Better ideas maybe?
What would happen if two users make the exact same order in the same time? Could it happen, that it gets stored two times in MongoDB as different successfull transactions? Of course you could run an audit over Redis and MongoDB and compare it. But that would be a horrible solution.
Hope you understand what I'm trying to ask. Thanks in advance!
First of all if you do not know anything from the stack you are using, it is not a good idea to tell I need high performance (high availability, good security and so on). Being absolutely new to all the tools you are using you should be happy if it will just work.
As for your question: first of all take a look how other people have done similar things. Here is an open source bitcoin trading engine which uses node.js which makes it an excellent example to study (it is complex, so take a deep breath). If you want to use mongo you need to know that it does not support transactions, so you need to take a look how to implement them by yourself there. These two examples are really good in explaining it.
I wish to create a college project on a simple online multiplayer management game which will involve players setting orders for the day/week and then obtaining profits. Being a relative beginner I am unable to figure out the architecture required for this task.
As far as I am concerned I would be needing the following things:
A text interface to display the status of ongoing events and to set orders in a web browser.
A certain application that would calculate the results every minute and update the database.
A database
Sorry for being so newbish, but any advice or links or books on how to proceed will do.
Please comment if any more information is required.
Any programming language would be fine. Pick a lang / arch you or someone in your group are familiar with. I'm mostly a PHP/ZF, Linux, Postgres guy. So I would...
Write a little ZendFramework app to collect your user's data and save to postgres database. I'd host it on a little Linux server. I like slicehost.com $20/mon, but there are cheaper. Or make friends with someone with a server.
Then for the update of the orders, use a cron job to run every minute. If the update process is complex, use another PHP script, else just straight SQL.
Why do you need to run updates every minute? Are people going to be updating it that often, if they are making orders for a day or week?
I would start with deciding on the equations that will be used in your model.
Then, that will help decide what you need in the database, to give the parameters to the model.
Then, once you have the database, you need to get information from the user, so decide what you need from the user.
For example you should have some random event that will make certain items go up or down in demand, or have resources become more common.
So, you may want to have information in the database that lists what each product is composed of.
If the model will have external information, or, if it is based on what others make, so, for example, last week shoes were not produced, so those that made shoes made a profit. This week everyone is making shoes, so there is too many, so the price went down.
This is why I think starting with your model, and testing your assumptions is the first step.
Any language, system, database will work well, just do what you feel comfy with. When you design the UI, do you want it to look fine on iphones and the Blackberry Razor? Then that will have a big impact on how you design the UI.