python - GAE Data Models for Events and shared Resources -


i'm having trouble coming data models , queries scale modeling data similar google calendar's events , resources.

resources shared among users , resource can in 1 event @ time. resource have multiple events, events cannot overlap or happening @ same time. event can have multiple resources.

class event(db.model):   #user created/owns event   user = db.referenceproperty(user, collection_name='events',required=true)    #an event can have multiple resources   resources = db.stringlistproperty() # resource key(s)    #when event opens , closes (start/stop)   opendt = db.datetimeproperty()   closedt = db.datetimeproperty()  class resource(db.model):   name = db.stringproperty(required=true) 

with these data models, have not been able come quick, scalable way list of available resources when creating event.

  1. get resources (simple query)
  2. get events overlap new event (multiple queries)
    1. find events start before , end after new event
    2. find events start before , end during new event
    3. find events start , end during new event
    4. find events start during , end after new event
  3. filter out resources included in overlapping events

i feel process slower , slower more events , resources added. don't know how work able paginate end result of resources.

when user creating new event, after enter start/stop datetimes of new event, them able see available resources time frame.

is there better, more efficient way?

just off top of head, work: 1. use long integer represent chunks of time, kinda unix timer, use large chunks of time, each increment represents 15 minutes. ie 0 = 1/1/2012 00:00, 1 = 1/1/2012 00:15, 2 = 1/1/2012 00:30, etc.

in both resources, , event, store listproperty of long integers time quanta occupied.

if want see if resource or event "active" @ point in time, calculate long integer value time chunk, , search in listproperty using "in" filter in query.


Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -