<commit_before>{ROOT, APPDATA_PATH, layout, _, $, $$, React, ReactBootstrap} = window
{Panel, Table, Label, OverlayTrigger, Tooltip} = ReactBootstrap
CSON = require 'cson'
{join} = require 'path-extra'

# Local time -> Task Refresh time(GMT + 4)
getCurrentDay = ->
  curTime = new Date()
  curTime.setTime(curTime.getTime() + (curTime.getTimezoneOffset() + 240) * 60000)
  curTime.getDay()

prevDay = getCurrentDay()

getCurrentDate = ->
  curTime = new Date()
  curTime.setTime(curTime.getTime() + (curTime.getTimezoneOffset() + 240) * 60000)
  curTime.getDate()

getCurrentMonth = ->
  curTime = new Date()
  curTime.setTime(curTime.getTime() + (curTime.getTimezoneOffset() + 240) * 60000)
  curTime.getMonth() + 1

prevMonth = getCurrentMonth()

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

getStyleByPercent = (percent) ->
  if percent < 0.5
    return 'warning'
  if percent < 0.8
    return 'primary'
  if percent < 1
    return 'info'
  return 'success'

emptyTask =
  name: '未接受'
  id: 100000
  content: '...'
  progress: ''
  category: 0
  type: 0

memberId = -1
# Quest Tracking
try
  questGoals = CSON.parseCSONFile join(ROOT, 'assets', 'data', 'quest_goal.cson')
catch
  console.log 'No quest tracking data!'
questRecord = {}
syncQuestRecord = ->
  questRecord.day = getCurrentDay()
  questRecord.month = getCurrentMonth()
  localStorage.setItem "quest_tracking_#{memberId}", JSON.stringify(questRecord)
clearQuestRecord = (id) ->
  delete questRecord[id] if questRecord[id]?
  syncQuestRecord()
activateQuestRecord = (id) ->
  if questRecord[id]?
    questRecord[id].active = true
    return
  questRecord[id] =
    count: 0
    required: 0
    active: true
  for k, v of questGoals[id]
    continue if k == 'type'
    questRecord[id][k] =
      count: v.init
      required: v.required
      description: v.description
    questRecord[id].count += v.init
    questRecord[id].required += v.required
  syncQuestRecord()
inactivateQuestRecord = (id) ->
  return unless questRecord[id]?
  questRecord[id].active = false
  syncQuestRecord()
updateQuestRecord = (e, options, delta) ->
  flag = false
  for id, q of questRecord
    continue unless q.active and q[e]?
    continue if questGoals[id][e].shipType? and options.shipType not in questGoals[id][e].shipType
    continue if questGoals[id][e].mission? and options.mission not in questGoals[id][e].mission
    continue if questGoals[id][e].maparea? and options.maparea not in questGoals[id][e].maparea
    before = q[e].count
    q[e].count = Math.min(q[e].required, q[e].count + delta)
    q.count += q[e].count - before
    flag = true
  if flag
    syncQuestRecord()
    return true
  return false
getToolTip = (id) ->
  <div>
  {
    for k, v of questRecord[id]
      if v.count? and v.required?
        <div key={k}>{v.description} - {v.count} / {v.required}</div>
  }
  </div>

TaskPanel = React.createClass
  getInitialState: ->
    tasks: [Object.clone(emptyTask), Object.clone(emptyTask), Object.clone(emptyTask),
            Object.clone(emptyTask), Object.clone(emptyTask), Object.clone(emptyTask)]
  handleResponse: (e) ->
    {method, path, body, postBody} = e.detail
    {tasks} = @state
    flag = false
    switch path
      when '/kcsapi/api_get_member/basic'
        memberId = window._nickNameId
        questRecord = localStorage.getItem "quest_tracking_#{memberId}"
        if questRecord?
          questRecord = JSON.parse questRecord
          if getCurrentDay() != questRecord.day
            for id, q of questRecord
              delete questRecord[id] if questGoals[id].type in [2, 4, 5]
          if getCurrentDay() < questRecord.day
            for id, q of questRecord
              delete questRecord[id] if questGoals[id].type is 3
          if getCurrentMonth() > questRecord.month
            for id, q of questRecord
              delete questRecord[id] if questGoals[id].type is 6
        else
          questRecord = {}
      when '/kcsapi/api_get_member/questlist'
        return unless body.api_list?
        for task in body.api_list
          continue if task is -1 || task.api_state < 2<commit_msg>update task-panel.cjsx<commit_after>{ROOT, APPDATA_PATH, layout, _, $, $$, React, ReactBootstrap} = window
{Panel, Table, Label, OverlayTrigger, Tooltip} = ReactBootstrap
CSON = require 'cson'
{join} = require 'path-extra'

# Local time -> Task Refresh time(GMT + 4)
getCurrentDay = ->
  curTime = new Date()
  curTime.setTime(curTime.getTime() + (curTime.getTimezoneOffset() + 240) * 60000)
  curTime.getDay()

prevDay = getCurrentDay()

getCurrentDate = ->
  curTime = new Date()
  curTime.setTime(curTime.getTime() + (curTime.getTimezoneOffset() + 240) * 60000)
  curTime.getDate()

getCurrentMonth = ->
  curTime = new Date()
  curTime.setTime(curTime.getTime() + (curTime.getTimezoneOffset() + 240) * 60000)
  curTime.getMonth() + 1

prevMonth = getCurrentMonth()

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

getStyleByPercent = (percent) ->
  if percent < 0.5
    return 'warning'
  if percent < 0.8
    return 'primary'
  if percent < 1
    return 'info'
  return 'success'

emptyTask =
  name: '未接受'
  id: 100000
  content: '...'
  progress: ''
  category: 0
  type: 0

memberId = -1
# Quest Tracking
try
  questGoals = CSON.parseCSONFile join(ROOT, 'assets', 'data', 'quest_goal.cson')
catch
  console.log 'No quest tracking data!'
questRecord = {}
syncQuestRecord = ->
  questRecord.day = getCurrentDay()
  questRecord.month = getCurrentMonth()
  localStorage.setItem "quest_tracking_#{memberId}", JSON.stringify(questRecord)
clearQuestRecord = (id) ->
  delete questRecord[id] if questRecord[id]?
  syncQuestRecord()
activateQuestRecord = (id) ->
  if questRecord[id]?
    questRecord[id].active = true
    return
  questRecord[id] =
    count: 0
    required: 0
    active: true
  for k, v of questGoals[id]
    continue if k == 'type'
    questRecord[id][k] =
      count: v.init
      required: v.required
      description: v.description
    questRecord[id].count += v.init
    questRecord[id].required += v.required
  syncQuestRecord()
inactivateQuestRecord = (id) ->
  return unless questRecord[id]?
  questRecord[id].active = false
  syncQuestRecord()
updateQuestRecord = (e, options, delta) ->
  flag = false
  for id, q of questRecord
    continue unless q.active and q[e]?
    continue if questGoals[id][e].shipType? and options.shipType not in questGoals[id][e].shipType
    continue if questGoals[id][e].mission? and options.mission not in questGoals[id][e].mission
    continue if questGoals[id][e].maparea? and options.maparea not in questGoals[id][e].maparea
    before = q[e].count
    q[e].count = Math.min(q[e].required, q[e].count + delta)
    q.count += q[e].count - before
    flag = true
  if flag
    syncQuestRecord()
    return true
  return false
getToolTip = (id) ->
  <div>
  {
    for k, v of questRecord[id]
      if v.count? and v.required?
        <div key={k}>{v.description} - {v.count} / {v.required}</div>
  }
  </div>

TaskPanel = React.createClass
  getInitialState: ->
    tasks: [Object.clone(emptyTask), Object.clone(emptyTask), Object.clone(emptyTask),
            Object.clone(emptyTask), Object.clone(emptyTask), Object.clone(emptyTask)]
  handleResponse: (e) ->
    {method, path, body, postBody} = e.detail
    {tasks} = @state
    flag = false
    switch path
      when '/kcsapi/api_get_member/basic'
        memberId = window._nickNameId
        questRecord = localStorage.getItem "quest_tracking_#{memberId}"
        if questRecord?
          questRecord = JSON.parse questRecord
          if getCurrentDay() != questRecord.day
            for id, q of questRecord
              delete questRecord[id] if questGoals[id].type in [2, 4, 5]
          if getCurrentDay() < questRecord.day
            for id, q of questRecord
              delete questRecord[id] if questGoals[id].type is 3
          if getCurrentMonth() isnt questRecord.month
            for id, q of questRecord
              delete questRecord[id] if questGoals[id].type is 6
        else
          questRecord = {}
      when '/kcsapi/api_get_member/questlist'
        return unless body.api_list?
        for task in body.api_list
          continue if task is -1 || task.api_state < 2
{'fraction_non_alphanumeric': 0.12249883666821777, 'fraction_numerical': 0.012331316891577479, 'mean_word_length': 3.0666982024597917, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 40, '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': '5704159', 'n_tokens_mistral': 2871, 'n_tokens_neox': 2794, 'n_words': 715}