<commit_before>class SubscriptionUsageView extends KDView

  getGauges: ->
    { subscription, components } = @getOptions()

    { plan } = subscription

    componentsByPlanCode = components.reduce( (memo, component) ->
      memo[component.planCode] = component
      memo
    , {})

    usage = (Object.keys subscription.quantities).map (key) ->
      usage =
        component : componentsByPlanCode[key]
        quota     : subscription.quantities[key]
        usage     : subscription.usage[key]

      usage.usage ?= 0
      usage.usageRatio = usage.usage / usage.quota

      if isNaN usage.usageRatio then usage.usageRatio = 0

      return usage

  createGaugeListController: ->

    controller = new KDListViewController
      itemClass: SubscriptionGaugeItem

    items = @getGauges()
    controller.instantiateListItems items

    controller


  viewAppended: ->

    @setClass 'subscription-gauges'

    title = if 'custom-plan' in @getOption('subscription').tags
    then 'Group resources'
    else 'Your resource packs'

    @addSubView new KDCustomHTMLView
      tagName  : 'span'
      cssClass : 'title'
      partial  : title

    @gaugeListController = @createGaugeListController()
    @addSubView @gaugeListController.getListView()<commit_msg> Merge branch 'master.groups.envUpdate' into 'master.groups'<commit_after>class SubscriptionUsageView extends KDView

  getGauges: ->
    { subscription, components } = @getOptions()

    { plan } = subscription

    componentsByPlanCode = components.reduce( (memo, component) ->
      memo[component.planCode] = component
      memo
    , {})

    usage = (Object.keys subscription.quantities).map (key) ->
      usage =
        component : componentsByPlanCode[key]
        quota     : subscription.quantities[key]
        usage     : subscription.usage[key]

      usage.usage ?= 0
      usage.usageRatio = usage.usage / usage.quota

      if isNaN usage.usageRatio then usage.usageRatio = 0

      return usage

  createGaugeListController: ->

    controller = new KDListViewController
      itemClass: SubscriptionGaugeItem

    items = @getGauges()
    controller.instantiateListItems items
    KD.getSingleton("vmController").on 'VMListChanged', => 
      items = @getGauges()
      controller.removeAllItems()
      controller.instantiateListItems items

    controller


  viewAppended: ->

    @setClass 'subscription-gauges'

    title = if 'custom-plan' in @getOption('subscription').tags
    then 'Group resources'
    else 'Your resource packs'

    @addSubView new KDCustomHTMLView
      tagName  : 'span'
      cssClass : 'title'
      partial  : title

    @gaugeListController = @createGaugeListController()
    @addSubView @gaugeListController.getListView()
{'fraction_non_alphanumeric': 0.09263311451495258, 'fraction_numerical': 0.0014587892049598833, 'mean_word_length': 2.992721979621543, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 14, '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': '7384179', 'n_tokens_mistral': 805, 'n_tokens_neox': 757, 'n_words': 171}