old_contents: # -*- coding: utf-8 -*-
  """
  Defines views.
  """
  
  import calendar, datetime
  from flask import redirect
  
  from presence_analyzer.main import app
  from presence_analyzer.utils import jsonify, get_data, mean, group_by_weekday
  
  import logging
  log = logging.getLogger(__name__)  # pylint: disable-msg=C0103
  
  
  @app.route('/')
  def mainpage():
      """
      Redirects to front page.
      """
      return redirect('/static/presence_weekday.html')
  
  
  @app.route('/api/v1/users', methods=['GET'])
  @jsonify
  def users_view():
      """
      Users listing for dropdown.
      """
      data = get_data()
      return [{'user_id': i, 'name': 'User {0}'.format(str(i))}
              for i in data.keys()]
  
  
  @app.route('/api/v1/mean_time_weekday/<int:user_id>', methods=['GET'])
  @jsonify
  def mean_time_weekday_view(user_id):
      """
      Returns mean presence time of given user grouped by weekday.
      """
      data = get_data()
      if user_id not in data:
          log.debug('User %s not found!', user_id)
          return []
  
      weekdays = group_by_weekday(data[user_id])
      result = [(calendar.day_abbr[weekday], mean(intervals))
                for weekday, intervals in weekdays.items()]
  
      return result
  
  
  @app.route('/api/v1/presence_weekday/<int:user_id>', methods=['GET'])
  @jsonify
  def presence_weekday_view(user_id):
      """
      Returns total presence time of given user grouped by weekday.
      """
      data = get_data()
      if user_id not in data:
          log.debug('User %s not found!', user_id)
          return []
  
      weekdays = group_by_weekday(data[user_id])
      result = [(calendar.day_abbr[weekday], sum(intervals))
                for weekday, intervals in weekdays.items()]
  
      result.insert(0, ('Weekday', 'Presence (s)'))
      return result
  
  @app.route('/api/v1/presence_start_end/<int:user_id>', methods=['GET'])
  @jsonify
  def presence_start_end(user_id):
      """
      Return average presence time of given user
      """
      data = get_data()
      if user_id not in data:
          log.debug('User %s not found!', user_id)
          return []
  
new_contents: # -*- coding: utf-8 -*-
  """
  Defines views.
  """
  
  import calendar, datetime
  from flask import redirect
  
  from presence_analyzer.main import app
  from presence_analyzer.utils import jsonify, get_data, mean, group_by_weekday
  
  import logging
  log = logging.getLogger(__name__)  # pylint: disable-msg=C0103
  
  
  @app.route('/')
  def mainpage():
      """
      Redirects to front page.
      """
      return redirect('/static/presence_weekday.html')
  
  
  @app.route('/api/v1/users', methods=['GET'])
  @jsonify
  def users_view():
      """
      Users listing for dropdown.
      """
      data = get_data()
      return [{'user_id': i, 'name': 'User {0}'.format(str(i))}
              for i in data.keys()]
  
  
  @app.route('/api/v1/mean_time_weekday/<int:user_id>', methods=['GET'])
  @jsonify
  def mean_time_weekday_view(user_id):
      """
      Returns mean presence time of given user grouped by weekday.
      """
      data = get_data()
      if user_id not in data:
          log.debug('User %s not found!', user_id)
          return []
  
      weekdays = group_by_weekday(data[user_id])
      result = [(calendar.day_abbr[weekday], mean(intervals))
                for weekday, intervals in weekdays.items()]
  
      return result
  
  
  @app.route('/api/v1/presence_weekday/<int:user_id>', methods=['GET'])
  @jsonify
  def presence_weekday_view(user_id):
      """
      Returns total presence time of given user grouped by weekday.
      """
      data = get_data()
      if user_id not in data:
          log.debug('User %s not found!', user_id)
          return []
  
      weekdays = group_by_weekday(data[user_id])
      result = [(calendar.day_abbr[weekday], sum(intervals))
                for weekday, intervals in weekdays.items()]
  
      result.insert(0, ('Weekday', 'Presence (s)'))
      return result
  
  @app.route('/api/v1/presence_start_end/<int:user_id>', methods=['GET'])
  @jsonify
  def presence_start_end(user_id):
      """
      Return average presence time of given user
      """
      data = get_data()
      if user_id not in data:
          log.debug('User %s not found!', user_id)
          return []
  
      total_start = []
      start_counter = 0
  
      for date in data[user_id]:
          total_start.append(str(data[user_id][date]['start']))
  
      totalSecs = 0
      for tm in total_start:
          timeParts = [int(s) for s in tm.split(':')]
          totalSecs += (timeParts[0] * 60 + timeParts[1]) * 60 + timeParts[2]
          start_counter += 1
      totalSecs, sec = divmod(totalSecs, 60)
      hr, min = divmod(totalSecs, 60)
      total = "%d:%02d:%02d" % (hr, min, sec)
  
      return total, start_counter
  
subject: Update view.py