0

現在の日付のアイテムが既にあるかどうかを確認しようとしています。ない場合は追加します。以下のコードはエラーを表示していませんが、MongoDB に何も保存していません。

if len(site.DaylyLog) != 0:
    print len(site.DaylyLog)
    print site.DaylyLog[-1]
    current_date_daylylog = site.DaylyLog[-1]['aggregate_date']
else:
    current_date_daylylog = ''

if current_date_daylylog == datetime.date.today():
    #update document
    print current_date_daylylog
    print "calculating averages"

    site.DaylyLog[-1].average_response_time = (site.DaylyLog[-1].average_response_time+record_uptime.response_time)/2
    site.DaylyLog[-1].average_uptime = (site.DaylyLog[-1].average_uptime+100)/2

    site.save()
else:
    print current_date_daylylog
    print "adding new uptime"

    print site.url
    aggregate_uptime = AggregatedUptime()
    aggregate_uptime.average_response_time = record_uptime.response_time
    aggregate_uptime.average_uptime = 100
    aggregate_uptime.total_downtime = 0
    aggregate_uptime.aggregate_date = datetime.date.today()

    print aggregate_uptime.aggregate_date
    print aggregate_uptime.average_response_time

    site.DaylyLog.append(aggregate_uptime)
    site.save()

    print site.DaylyLog[-1].aggregate_date
4

1 に答える 1

0

上記のコメントで述べたように。私が投稿したコードは問題ありませんでしたが、モデルで変更したものを防御していました。それは単なる初心者の問題でした。:-)

古いモデルは

class Checkr(Document):
 name = StringField()
 slug = SlugField()
 url = URLField()
 frequency = IntField()
 owner = IntField()
 start_date = DateTimeField()
 end_date = DateTimeField()
 current_response_time = FloatField()
 current_response_code = IntField()
 hourly_log = ListField(EmbeddedDocumentField(AggregatedUptime))
 dayly_log = ListField(EmbeddedDocumentField(AggregatedUptime))
 weekly_log = ListField(EmbeddedDocumentField(AggregatedUptime))

いつあるべきか

class Checkr(Document):
 name = StringField()
 slug = SlugField()
 url = URLField()
 frequency = IntField()
 owner = IntField()
 start_date = DateTimeField()
 end_date = DateTimeField()
 current_response_time = FloatField()
 current_response_code = IntField()
 HourlyLog = ListField(EmbeddedDocumentField(AggregatedUptime))
 DaylyLog = ListField(EmbeddedDocumentField(AggregatedUptime))
 WeeklyLog = ListField(EmbeddedDocumentField(AggregatedUptime))
于 2012-06-03T20:49:51.947 に答える