Hi Tony,

I thought of a few ideas that you could use in this type of situation. I'm
not saying this is the best/most efficient design, but it illustrates a
different approach than you may be used to. The general guidelines I'm using
are to do more work at write time and less at read time and take advantage
of list properties for queries (you could also look at back-reference
collections).

a.) which users had tickets to a particular auction

class AuctionUser(Model):
  username = StringProperty(...)
  aunctions_entered = ListProperty(...)

Select * from AuctionUser where aunctions_entered = current_auction

b.) how many tickets (of each type) they had for the auction.

I assumed you meant, for each user, how many free vs purchased did they
have.

class UserTickets(Model):
  user_level = IntegerProperty(...)
  auction_name = StringProperty(...)
  free_tickets = IntegerProperty(...)
  purchased_tickets = IntegerProperty(...)

Or you might have meant for each auction, how many total tickets, free,
purchased were given out. For the per auction counts I would use a sharded
counter (or just a simple counter if the writes will not be coming in too
quickly).

c) update all those (possible more than 1000) users to reflect the refund.

Rather than refund all users after the raffle is over, why not precompute a
discount assuming that the refund will apply. If only the winner doesn't
receive the refund, then you could take away their refund when they win, so
only one user will need to have their cost modified.

d) I'm assuming that you want to be able to find the user with the winning
ticket and that a user has a limited number of tickets they hold.

class UserTickets(Model):
  username = StringProperty(...)
  tickets = ListProperty(...)

To find the winner
Select * from UserTickets where tickets = winning_ticket

Again, these are just suggestions and they rely on quite a few assumptions
about what you are trying to do. Rather than give specific design advice,
I'm trying to illustrate some different ways of thinking about the problem.

Thank you,

Jeff

On Sat, Jun 13, 2009 at 4:28 AM, Tony <fatd...@gmail.com> wrote:

>
> Here's a generic example of one of my use cases - I'm curious if
> anyone has any ideas I haven't thought of...
>
> Let's say I have an app where users can buy tickets to a raffle (I'm
> not really creating a gambling app, this is just an example).  There
> are two types of tickets - purchased tickets and free tickets (given
> away as promotions).  There may be more than 1000 users with tickets
> to a particular raffle, but each user is unlikely to have more than
> 1000 tickets to a particular raffle.  When a raffle ends, a winning
> ticket is selected from the tickets for that raffle...but here's the
> hard part:  I would like to be able to refund, based on some logic,
> some or all of each user's purchased tickets for that raffle if they
> don't win.  For example:  User A has 10 purchased tickets and 10 free
> tickets for a raffle.  He has 5 tickets remaining on his account.  He
> doesn't win the raffle.  Because his User.level == 2, he gets refunded
> 10 tickets.  User B has the same situation, but has User.level == 3.
> He gets refunded all his free tickets plus 50% of his purchased
> tickets.
>
> Here's my current setup:
>
> Class User (db.Model):
>  level = db.IntegerProperty
>  paidtickets = db.IntegerProperty
>  freetickets = db.IntegerProperty
>
> Class Ticket (db.Model):
>  user = db.ReferenceProperty
>  type = db.BooleanProperty (true=paid, false=free)
>  (parent = Raffle)
>
> Class Raffle (db.Model)
>  expires = db.DateTimeProperty
>  winner = db.ReferenceProperty
>
> My problem is I need to be able to determine: a.) which users had
> tickets to a particular auction, b.) how many tickets (of each type)
> they had for the auction.  Then I need to update all those (possible
> more than 1000) users to reflect the refund.  What is the best way to
> do this without maxing out datastore cpu and query limits?
> ListProperties updated every time a ticket is added?  How do I get
> around the 1000-entity limit?
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to google-appengine@googlegroups.com
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to