我正在使用 GAE 数据存储来处理滚动注册研究的电子邮件作业。每行(在 emailJobs 中)代表一个参与者。我要查询 12 个变量。每一个代表一个随访期(从 1 到 12)。变量保存了在特定后续期间向某人发送电子邮件的日期。由于人们在不同时间开始研究,因此并非每个人在任何给定时间都会处于相同的随访期。
我想确定在特定跟进期内的人,看看他们是否收到了他们在研究中本应收到的所有跟进电子邮件。
我试图通过只关注感兴趣的变量并忽略绝对是 None 类型的变量来减少查询数据存储所需的时间。
我试图解决这个问题的方法是创建一个动态的变量列表,我将在我的查询中定位这些变量。
fu1_email_sent, fu2_email_sent, ...fu12_email_sent
这是代码的精简版:
class emailJobs(db.Model):
""" Models a list of email jobs for each participant """
date_modified = db.DateTimeProperty(auto_now_add=True, name='Date modified')
author = db.StringProperty() # Google account which made changes (for testing)
triggerid = db.StringProperty() # TriggerResponseID (connects participants across both panels)
recipientid_po = db.StringProperty() # RecipientID - Original Panel
recipientid_pdi = db.StringProperty() # RecipientID - De-identified Panel
unsubscribed = db.IntegerProperty() # Subscription status
recipientlang = db.StringProperty() # RecipientLanguage
consent_date = db.DateTimeProperty() # CONSENTDATE datetime (timestamp)
test = db.StringProperty() # Identifies test data (TESTDATA = 1)
fuperiod = db.IntegerProperty() #Follow-up period (0 - 13: 0-before follow-up, 13-past fu12)
last_fu_sent = db.DateTimeProperty() # Datetime last follow-up email was sent
fu1_email_sent = db.DateTimeProperty() # ****************
fu2_email_sent = db.DateTimeProperty()
fu3_email_sent = db.DateTimeProperty()
fu4_email_sent = db.DateTimeProperty()
fu5_email_sent = db.DateTimeProperty()
fu6_email_sent = db.DateTimeProperty()
fu7_email_sent = db.DateTimeProperty()
fu8_email_sent = db.DateTimeProperty()
fu9_email_sent = db.DateTimeProperty()
fu10_email_sent = db.DateTimeProperty()
fu11_email_sent = db.DateTimeProperty()
fu12_email_sent = db.DateTimeProperty()
class sendMissedFU(webapp2.RequestHandler):
""" Queries Datastore for follow-up dates that were missed, then adds them to a task queue so that an email can be sent out """
def get(self):
now = datetime.datetime.now()
now_dt = now.date() #today's date to compare with follow-up dates
q = emailJobs.all()
q.filter('consent_date !=', None ) # weeds out anyone who doesn't have a consent date
q.order('consent_date')
for part in q:
trigid = part.triggerid
lang = part.recipientlang
guid = part.recipientid_po
consent = part.consent_date
consent_date = consent.date()
calcdTime = now_dt - consent_date
dayssince = calcdTime.days
fup = dayssince/30
fuemailsent_dict = {}
fuemailsent_list = []
for i in range(1, fup + 1):
i = str(i)
followup = 'fu' + i + '_email_sent'
fuemailsent_list.append(followup)
fu_check = part.followup
if fu_check == None:
fuemailsent_dict[followup] = 0
else:
fuemailsent_dict[followup] = 1
我得到的错误是:
AttributeError: 'emailJobs' 对象没有属性 'followup'
它不喜欢:fu_check = part.followup ...但我不知道该怎么做。