I am looking for some advice / guide on the best way to unlock content from in-app purchases.
I have a list of 100 words. I have the broken into 25 units. The first unit of 25 is free and the remaining 3 units can be unlocked after you purchase them from an in-app purchase. No content will be downloaded.
All 100 words are currently stored in an array.
After the purchaser buys a unit, I want that specific segment to become available.
So if they buy unit 3, then the word list should include units 1 and 3.
What is the best way to implement this? Should I use 4 different NSArrays for the word sets? And then just load a master NSArray with the purchased words?
For the bare minimum you could use four NSArrays and then add them to an NSMutableArray as they are purchased. And use NSUserDefaults to store a boolean for each possible purchase.
I don't know wether or not I understand your question correctly.
Maybe you could put everything into one big array and have a max_available_index. Each purchase increments this index. The user is never allowed to access items beyond this maximum index.
If your unit size is 25, then buying 3 units increments the max_available_index by 75.
Related
My primary business is pre-orders, and this is how it works:
I list an item for sale.
My customers order the item. Their credit card is authorized but not charged.
Once a minimum number of orders are placed, the customers are charged, and the buy is live.
If, after a specified amount of time, the minimum is not reached, all orders are cancelled.
What i would like to do is this:
Specify the minimum number of orders needed for a particular item in the backend. (not 100% needed, but it would be nice).
Display the total number of pre-orders on the product page, so that my customers know how many are left before the buy is live (it would be great to show it in the following format: 23/50 Ordered).
Does anyone know if this is possible? If so, can you please explain to me what I need to do in order to make this happen?
Thanks!
P.S. - In case it doesn't show up, I'm using Bigcommerce
Store the minimum needed as a custom field & set the initial inventory to that same number. You'll also need to allow inventory to be displayed for pre-orders, though you can hide it from display if you'd like (we only want it present in the DOM).
As the products are pre-ordered, inventory will decrement. Use javascript to subtract the number left in inventory from the original number (the custom field) and display in the ProductDetails.html panel.
I've been trying to create variant options which also have prices on a Shopify theme, and represent them by checkboxes. So end user can select multiple options with additional prices. But shopify has limitations on this as far as I noticed.
Let's say the product is 'personal computer' with fixed price £500, and it has options like 'graphic card - £30', 'processor - £40', 'sound card - £15', 'sound card - £30'. As you've noticed there can be multiple options with different prices in addition to the main product price. And as I would like to use checkboxes, users can select min 1 max all of them.
I don't want to use the Shopify app for this but it seems there is no other choice, unfortunately.
I think you would prefer to organize it like this.
make a personal computer product. it costs 500
make a graphics card product. it costs 30
make a processor product. it costs 40
make a sound card product. it costs 15, 30 or whatever.
Now present all four products on a page so the customer can check off one or more of those products. The ones they check off go into the cart.
You get inventory control that way. You can also price each product up to 100 different ways.
You do not need an App to go this route. It works.
I am writing a program that tells the user which juice taste to buy. I store the avaible juices in an array and the previously bought in another array. Based on how many times a taste has been bought and the time since it was last bought, each taste gets a score. The higher score the more likely it should be for that taste to be selected.
When I arrive at the step to randomly select a juice taste (that is, selecting an index in the array) I have two instances of NSMutableArray, one for the avaible tastes, one for the scores. Both arrays have 17 slots.
It might looks something like this: (only three different tastes)
#[#"Apple juice", #"Orange juice", #"Grape juice"]; // Avaible tastes array
#[19.21, 45.83, 24.84]; // Scores array
How do I select one taste randomly from this?
Initially, I thought that each taste could have a range, starting from the previous taste's score going to the previous score + the taste's own score. Then a random number between 0 and the total score would be generated. The taste who's range matches the random number would be the one that was going to be selected, but this feels like a overly complex solution.
Is there an easier way?
Edit
By the way, it is written in Objective-C.
On way to solve your problem is what is know as roulette wheel selection. There are a few example implementations in this other question Roulette Selection in Genetic Algorithms
Simple option, copy each item into an array multiple times, based on the weighting, and then pick a random item from the array.
I'm currently working on a project in MongoDB where I want to get a random sampling of new products from the DB. But my problem is not MongoDB specific, I think it's a general database question.
The scenario:
Let's say we have a collection (or table) of products. And we also have a collection (or table) of users. Every time a user logs in, they are presented with 10 products. These products are selected randomly from the collection/table. Easy enough, but the catch is that every time the user logs in, they must be presented with 10 products that they have NEVER SEEN BEFORE. The two obvious ways that I can think of solving this problem are:
Every user begins with their own private list of all products. Each time they get one of these products, the product is removed from their private list. The result is that the next time products are chosen from this previously trimmed list, it already contains only new items.
Every user has a private list of previously viewed products. When a user logs in, they select 10 random products from the master list, compare the id of each against their list of previously viewed products, and if the item appears on the previously viewed list, the application throws this one away selects a new one, and iterates until there are 10 new items, which it then adds to the previously viewed list for next time.
The problem with #1 is it seems like a tremendous waste. You would basically be duplicating the list data for n number of users. Also removing/adding new items to the system would be a nightmare since it would have to iterate through all users. #2 seems preferable, but it too has issues. You could end up making a lot of extra and unnecessary calls to the DB in order to guarantee 10 new products. As a user goes through more and more products, there are less new ones to choose from, so the chances of having to throw one away and get new one from the DB greatly increases.
Is there an alternative solution? My first and primary concern is performance. I will give up disk space in order to optimize performance.
Those 2 ways are a complete waste of both primary and secondary memory.
You want to show 2 never before seen products, but is this a real must?
If you have a lot of products 10 random ones have a high chance of being unique.
3 . You could list 10 random products, even though not as easy as in MySQL, still less complicated than 1 and 2.
If you don't care how random the sequence of id's is you could do this:
Create a single randomized table of just product id's and a sequential integer surrogate key column. Start each customer at a random point in the list on first login and cycle through the list ordered by that key. If you reach the end, start again from the top.
The customer record would contain a single value for the last product they saw (the surrogate from the randomized list, not the actual id). You'd then pull the next ten on login and do a single update to the customer. It wouldn't really be random, of course. But this kind of table-seed strategy is how a lot of simpler pseudo-random number generators work.
The only problem I see is if your product list grows more quickly than your users log in. Then they'd never see the portions of the list which appear before wherever they started. Even so, with a large list of products and very active users this should scale much better than storing everything they've seen. So if it doesn't matter that products appear in a set psuedo-random sequence, this might be a good fit for you.
Edit:
If you stored the first record they started with as well, you could still generate the list of all things seen. It would be everything between that value and last viewed.
How about doing this: crate a collection prodUser where you will have just the id of the product and the list of customersID, (who have seen these products) .
{
prodID : 1,
userID : []
}
when a customer logs in you find the 10 prodID which has not been assigned to that user
db.prodUser.find({
userID : {
$nin : [yourUser]
}
})
(For some reason $not is not working :-(. I do not have time to figure out why. If you will - plz let me know.). After showing the person his products - you can update his prodUser collection. To mitigate mongos inability to find random elements - you can insert elements randomly and just find first 10.
Everything should work really fast.
Lets say I have a website that sells widgets. I would like to do something similar to a tag cloud tracking best sellers. However, due to constantly aquiring and selling new widgets, I would like the sales to decay on a weekly time scale.
I'm having problems puzzling out how store and manipulate this data and have it decay properly over time so that something that was an ultra hot item 2 months ago but has since tapered off doesn't show on top of the list over the current best sellers. What would be the logic and database design for this?
Part 1: You have to have tables storing the data that you want to report on. Date/time sold is obviously key. If you need to work in decay factors, that raises the question: for how long is the data good and/or relevant? At what point in time as the "value" of the data decayed so much that you no longer care about it? When this point is reached for any given entry in the database, what do you do--keep it there but ensure it gets factored out of all subsequent computations? Or do you archive it--copy it to a "history" table and delete it from your main "sales" table? This is relevant, as it has to be factored into your decay formula (as well as your capacity planning, annual reporting requirements, and who knows what all else.)
Part 2: How much thought has been given to the decay formula that you want to use? There's no end of detail you can work into this. Options and factors to wade through include but are not limited to:
Simple age-based. Everything before the cutoff date counts as 1; everything after counts as 0. Sum and you're done.
What's the cutoff date? Precisly 14 days ago, to the minute? Midnight as of two Saturdays ago from (now)?
Does the cutoff date depend on the item that was sold? If some items are hot but some are not, does that affect things? What if you want to emphasize some things (the expensive/hard to sell ones) over others (the fluff you'd sell anyway)?
Simple age-based decays are trivial, but can be insufficient. Time to go nuclear.
Perhaps you want some kind of half-life, Dr. Freeman?
Everything sold is "worth" X, where the value of X is either always the same or varies on the item sold. And the value of X can decay over time.
Perhaps the value of X decreased by one-half every week. Or ever day. Or every month. Or (again) it may vary depending on the item.
If you do half-lifes, the value of X may never reach zero, and you're stuck tracking it forever (which is why I wrote "part 1" first). At some point, you probably need some kind of cut-off, some point after which you just don't care. X has decreased to one-tenth the intial value? Three months have passed? Either/or but the "range" depends on the inherent valud of the item?
My real point here is that how you calculate your decay rate is far more important than how you store it in the database. So long as the data's there that the formalu needs to do it's calculations, you should be good. And if you only need the last month's data to do this, you should perhaps move everything older to some kind of archive table.
you could just count the sales for the last month/week/whatever, and sort your items according to that.
if you want you can always add the total amonut of sold items into your formula.
You might have a table which contains the definitions of the pointing criterion (most sales, most this, most that, etc.), then for a given period, store in another table the attribution of points for each of the criterion defined in the criterion table. Obviously, a historical table will be used to store the score for each sellers for a given period or promotion, call it whatever you want.
Does it help a little?