コード例 #1
0
    def handle(self, *args, **options):
        today = date.today()
        print today

        users = Athlete.objects.all()
        if options['username']:
            users = users.filter(username=options['username'])

        users = users.order_by('username')

        for user in users:
            print user

            # Search first active day
            first = SportDay.objects.filter(
                week__user=user).order_by('date').first()
            if not first:
                print ' !! No day, no stats !!'
                continue

            # Buil StatsMonth until now
            for year in range(first.date.year, today.year + 1):
                for month in range(1, 13):

                    # Skip unecessary months (no data)
                    if (year, month) < (first.date.year, first.date.month) or (
                            year, month) > (today.year, today.month):
                        continue

                    # Build StatsMonth
                    stats = StatsMonth(user, year, month)
                    stats.build()
                    print ' >> %d / %d' % (year, month)
コード例 #2
0
  def build_mail(self, year, user):
    print 'Building mail for %d - %s' % (year, user)

    # Sum stats
    stats = {}
    for m in range(1, 13):
      month = StatsMonth(user, year, m)
      data = month.fetch()
      if data:
        stats = self.merge(stats, data)

    # Load sports objects
    if stats and 'sports' in stats:
      for s_id, s in stats['sports'].items():
        s['sport'] = Sport.objects.get(pk=s_id)

    # Build mail
    builder = MailBuilder('mail/new.year.html', user.language)

    data = {
      'year' : year,
      'stats' : stats,
      'user' : user,
    }
    builder.subject = u'[RunReport] Bonne année !'
    builder.to = [user.email, ]
    mail = builder.build(data)
    mail.send()
コード例 #3
0
    def handle(self, *args, **options):
        today = date.today()

        users = Athlete.objects.all()
        if options['username']:
            users = users.filter(username=options['username'])

        users = users.order_by('username')

        cal = calendar.Calendar()

        for user in users:
            print user

            # Search first active day
            first = SportDay.objects.filter(
                week__user=user).order_by('date').first()
            if not first:
                print ' !! No day, no stats !!'
                continue

            # Buil StatsMonth until now
            for year in range(first.date.year, today.year + 1):
                print year
                for month in range(1, 13):

                    # Skip unecessary months (no data)
                    if (year, month) < (first.date.year, first.date.month) or (
                            year, month) > (today.year, today.month):
                        continue

                    # Build StatsMonth
                    stats = StatsMonth(user, year, month)
                    stats.build()

                    # Build weeks
                    weeks = cal.monthdatescalendar(year, month)
                    for w in weeks:
                        day = w[0]
                        if day.month != month:
                            continue
                        week = int(day.strftime('%W'))
                        stats = StatsWeek(user, year, week)
                        stats.build()
コード例 #4
0
ファイル: base.py プロジェクト: Flogerbe/coach
      except TrackEndImportException, e:
        logger.info("No more tracks to import for %s" % (self.user,))
      except Exception, e:
        if settings.DEBUG:
          raise e
        logger.error("Import failed for %s: %s" % (self.user, str(e)))
        break

      # End of loop ?
      if not len(tracks):
        break

    # Refresh stats cache
    for year,month in months:
      logger.info("Refresh stats %d/%d for %s" % (month, year, self.user))
      st = StatsMonth(self.user, year, month, preload=False)
      st.build()

  def import_activities(self, source=None):
    '''
    Generic method iterating through activities list
    and calling build_track on everey one
    '''
    if not source:
      raise TrackEndImportException()

    activities = []
    updated_nb = 0
    for activity in source:
      try:
        with transaction.atomic():
コード例 #5
0
 def rebuild_cache(self):
   # Rebuild the stats cache
   st = StatsMonth(self.week.user, self.date.year, self.date.month, preload=False)
   st.build()
コード例 #6
0
 def rebuild_cache(self):
   # Rebuild the stats cache
   st = StatsMonth(self.user, self.year, self.get_date_start().month, preload=False)
   st.build()