<commit_before>{ROOT, layout, _, $, $$, React, ReactBootstrap} = window
{Panel, Table, Label, OverlayTrigger, Tooltip} = ReactBootstrap

prevHours = (new Date()).getUTCHours()
interval = null

getStyleByProgress = (progress) ->
  switch progress
    when '进行'
      return 'warning'
    when '50%'
      return 'primary'
    when '80%'
      return 'info'
    when '达成'
      return 'success'
    else
      return 'default'

TaskPanel = React.createClass
  getInitialState: ->
    tasks: [
        name: '未接受'
        id: 100000
        content: '...'
        progress: ''
        category: 0
        type: 0
      ,
        name: '未接受'
        id: 100000
        content: '...'
        progress: ''
        category: 0
        type: 0
      ,
        name: '未接受'
        id: 100000
        content: '...'
        progress: ''
        category: 0
        type: 0
      ,
        name: '未接受'
        id: 100000
        content: '...'
        progress: ''
        category: 0
        type: 0
      ,
        name: '未接受'
        id: 100000
        content: '...'
        progress: ''
        category: 0
        type: 0
      ,
        name: '未接受'
        id: 100000
        content: '...'
        progress: ''
        category: 0
        type: 0
    ]
  handleResponse: (e) ->
    {method, path, body, postBody} = e.detail
    {tasks} = @state
    switch path
      when '/kcsapi/api_get_member/questlist'
        for task in body.api_list
          continue if task is -1 || task.api_state < 2
          # Determine progress
          progress = '进行'
          if task.api_state == 3
            progress = '达成'
          else if task.api_progress_flag == 1
            progress = '50%'
          else if task.api_progress_flag == 2
            progress = '80%'
          idx = _.findIndex tasks, (e) ->
            e.id == task.api_no
          # Do not exist currently
          if idx == -1
            idx = _.findIndex tasks, (e) ->
              e.id == 100000
            tasks[idx] =
              name: task.api_title
              id: task.api_no
              content: task.api_detail
              progress: progress
              category: task.api_category
              type: task.api_type
          # Update current
          else
            tasks[idx] =
              name: task.api_title
              id: task.api_no
              content: task.api_detail
              progress: progress
              category: task.api_category
              type: task.api_type
      # Finish quest
      when '/kcsapi/api_req_quest/clearitemget'
        idx = _.findIndex tasks, (e) ->
          e.id == parseInt(postBody.api_quest_id)
        return if idx == -1
        tasks[idx] =
          name: '未接受'
          id: 100000
          content: '...'
          progress: ''
          category: 0
          type: 0
      # Stop quest
      when '/kcsapi/api_req_quest/stop'
        idx = _.findIndex tasks, (e) ->
          e.id == parseInt(postBody.api_quest_id)
        return if idx == -1
        tasks[idx] =
          name: '未接受'
          id: 100000
          content: '...'
          progress: ''
          category: 0
          type: 0
    tasks = _.sortBy tasks, (e) ->
      e.id
    @setState
      tasks: tasks
    event = new CustomEvent 'task.change',
      bubbles: true
      cancelable: true
      detail:
        tasks: tasks
    window.dispatchEvent event
  refreshDay: ->
    curHours = (new Date()).getUTCHours()
    return if prevHours == curHours
    # UTC 20:00 -> Beijing 4:00 -> Tokyo 5:00
    if prevHours <= 19 and curHours >= 20
      tasks = []
      for idx in [0..5]
        tasks[idx] =
          name: '未接受'
          id: 100000
          content: '...'
          progress: ''
          category: 0
          type: 0
      @setState
        tasks: tasks
      event = new CustomEvent 'task.change',
        bubbles: true
        cancelable: true
        detail:
          tasks: tasks
      window.dispatchEvent event<commit_msg>Clean daily task only<commit_after>{ROOT, layout, _, $, $$, React, ReactBootstrap} = window
{Panel, Table, Label, OverlayTrigger, Tooltip} = ReactBootstrap

prevHours = (new Date()).getUTCHours()
interval = null

getStyleByProgress = (progress) ->
  switch progress
    when '进行'
      return 'warning'
    when '50%'
      return 'primary'
    when '80%'
      return 'info'
    when '达成'
      return 'success'
    else
      return 'default'

TaskPanel = React.createClass
  getInitialState: ->
    tasks: [
        name: '未接受'
        id: 100000
        content: '...'
        progress: ''
        category: 0
        type: 0
      ,
        name: '未接受'
        id: 100000
        content: '...'
        progress: ''
        category: 0
        type: 0
      ,
        name: '未接受'
        id: 100000
        content: '...'
        progress: ''
        category: 0
        type: 0
      ,
        name: '未接受'
        id: 100000
        content: '...'
        progress: ''
        category: 0
        type: 0
      ,
        name: '未接受'
        id: 100000
        content: '...'
        progress: ''
        category: 0
        type: 0
      ,
        name: '未接受'
        id: 100000
        content: '...'
        progress: ''
        category: 0
        type: 0
    ]
  handleResponse: (e) ->
    {method, path, body, postBody} = e.detail
    {tasks} = @state
    switch path
      when '/kcsapi/api_get_member/questlist'
        for task in body.api_list
          continue if task is -1 || task.api_state < 2
          # Determine progress
          progress = '进行'
          if task.api_state == 3
            progress = '达成'
          else if task.api_progress_flag == 1
            progress = '50%'
          else if task.api_progress_flag == 2
            progress = '80%'
          idx = _.findIndex tasks, (e) ->
            e.id == task.api_no
          # Do not exist currently
          if idx == -1
            idx = _.findIndex tasks, (e) ->
              e.id == 100000
            tasks[idx] =
              name: task.api_title
              id: task.api_no
              content: task.api_detail
              progress: progress
              category: task.api_category
              type: task.api_type
          # Update current
          else
            tasks[idx] =
              name: task.api_title
              id: task.api_no
              content: task.api_detail
              progress: progress
              category: task.api_category
              type: task.api_type
      # Finish quest
      when '/kcsapi/api_req_quest/clearitemget'
        idx = _.findIndex tasks, (e) ->
          e.id == parseInt(postBody.api_quest_id)
        return if idx == -1
        tasks[idx] =
          name: '未接受'
          id: 100000
          content: '...'
          progress: ''
          category: 0
          type: 0
      # Stop quest
      when '/kcsapi/api_req_quest/stop'
        idx = _.findIndex tasks, (e) ->
          e.id == parseInt(postBody.api_quest_id)
        return if idx == -1
        tasks[idx] =
          name: '未接受'
          id: 100000
          content: '...'
          progress: ''
          category: 0
          type: 0
    tasks = _.sortBy tasks, (e) ->
      e.id
    @setState
      tasks: tasks
    event = new CustomEvent 'task.change',
      bubbles: true
      cancelable: true
      detail:
        tasks: tasks
    window.dispatchEvent event
  refreshDay: ->
    curHours = (new Date()).getUTCHours()
    return if prevHours == curHours
    # UTC 20:00 -> Beijing 4:00 -> Tokyo 5:00
    if prevHours <= 19 and curHours >= 20
      {tasks} = @state
      for task, idx in tasks
        continue if task.id == 100000
        if task.type in [2, 4, 5]
          tasks[idx] =
            name: '未接受'
            id: 100000
            content: '...'
            progress: ''
            category: 0
            type: 0
        if task.type is 3 and (new Date()).getUTCDay() is 0
          tasks[idx] =
            name: '未接受'
            id: 100000
            content: '...'
            progress: ''
            category: 0
            type: 0
      tasks = _.sortBy tasks, (e) ->
        e.id
      @setState
        tasks: tasks
      event = new CustomEvent 'task.change',
        bubbles: true
        cancelable: true
        detail:
          tasks: tasks
      window.dispatchEvent event
{'fraction_non_alphanumeric': 0.10714714714714715, 'fraction_numerical': 0.02846846846846847, 'mean_word_length': 1.3140633685380767, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3215377', 'n_tokens_mistral': 2644, 'n_tokens_neox': 2464, 'n_words': 677}