예제 #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 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)
예제 #3
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()
예제 #4
0
파일: organisation.py 프로젝트: La0/coach
  def rebuild_cache(self):
    # Rebuild the monthly stats cache
    st = StatsMonth(self.user, self.year, self.get_date_start().month, preload=False)
    st.build()

    # Rebuild the weekly stats cache
    st = StatsWeek(self.user, self.year, self.week, preload=False)
    st.build()
예제 #5
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()
예제 #6
0
파일: build_stats.py 프로젝트: La0/coach
  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()
예제 #7
0
파일: base.py 프로젝트: La0/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 months stats cache
    for year,month in months:
      logger.info("Refresh month stats %d/%d for %s" % (month, year, self.user))
      st = StatsMonth(self.user, year, month, preload=False)
      st.build()

    # Refresh weeks stats cache
    for year,week in weeks:
      logger.info("Refresh week stats %d/%d for %s" % (week, year, self.user))
      st = StatsWeek(self.user, year, week, 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()
예제 #8
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():
예제 #9
0
 def rebuild_cache(self):
   # Rebuild the stats cache
   st = StatsMonth(self.week.user, self.date.year, self.date.month, preload=False)
   st.build()
예제 #10
0
 def rebuild_cache(self):
   # Rebuild the stats cache
   st = StatsMonth(self.user, self.year, self.get_date_start().month, preload=False)
   st.build()