<commit_before>'use strict'

import angular from 'angular'
import uiRouter from 'angular-ui-router'
import uiSelect from 'angular-ui-select'
import filter from 'lodash.filter'
import foreach from 'lodash.foreach'

import xoApi from 'xo-api'
import xoServices from 'xo-services'

import sunburstChart from 'xo-sunburst-d3'

import view from './view'

export default angular.module('dashboard.dataviz', [
  uiRouter,
  uiSelect,

  xoApi,
  xoServices
])
  .config(function ($stateProvider) {
    $stateProvider.state('dashboard.dataviz', {
      controller: 'Dataviz as ctrl',
      url: '/dataviz',
      template: view
    })
  })
  .controller('Dataviz', function (xoApi, $scope, $timeout,bytesToSizeFilter) {

    $scope.charts = {
      selected: {},
      ram: {
        name: 'ram',
        children: []
      },
      storage: {
        name: 'storage',
        children: []
      },
      over: function (d) {
        $scope.$apply(function () {
          $scope.charts.selected = d
        })
      }
    }

    function populateChartsData() {
      
      
      function populatestorage(root,container_id){
        let srs = filter(xoApi.getIndex('srsByContainer')[container_id] , (one_srs)=>one_srs.SR_type !== 'iso' && one_srs.SR_type !== 'udev')
        foreach(srs, function(one_srs){
          console.log('son of ',container_id,' ',one_srs)
          let srs_used_size=0,
            srs_storage = {
              name: one_srs.name_label,
              id: one_srs.id,
              children: [],
              size:one_srs.size,
              textSize:bytesToSizeFilter(one_srs.size)
            }
          
          root.size+=one_srs.size
          foreach(one_srs.VDIs, function(vdi_id){
            let vdi = xoApi.get(vdi_id)
            if(vdi.name_label.indexOf('.iso') === -1){
              let vdi_storage={
                name: vdi.name_label,
                id: vdi_id,
                size: vdi.size,
                textSize : bytesToSizeFilter(vdi.size)
              }
              srs_used_size+=vdi.size
              srs_storage.children.push(vdi_storage)
            }
          })
          if(one_srs.size > srs_used_size){// some unallocated space
            srs_storage.children.push({
              color:'white',
              name: 'Free',
              id: 'free'+one_srs.id,
              size:  one_srs.size-srs_used_size ,
              textSize : bytesToSizeFilter( one_srs.size-srs_used_size)
            })
          }
          root.children.push(srs_storage)
        })
        root.textSise = bytesToSizeFilter(root.size)
      }
      
      
      <commit_msg>dataviz : correct typo in storage sums<commit_after>'use strict'

import angular from 'angular'
import uiRouter from 'angular-ui-router'
import uiSelect from 'angular-ui-select'
import filter from 'lodash.filter'
import foreach from 'lodash.foreach'

import xoApi from 'xo-api'
import xoServices from 'xo-services'

import sunburstChart from 'xo-sunburst-d3'

import view from './view'

export default angular.module('dashboard.dataviz', [
  uiRouter,
  uiSelect,

  xoApi,
  xoServices
])
  .config(function ($stateProvider) {
    $stateProvider.state('dashboard.dataviz', {
      controller: 'Dataviz as ctrl',
      url: '/dataviz',
      template: view
    })
  })
  .controller('Dataviz', function (xoApi, $scope, $timeout,bytesToSizeFilter) {

    $scope.charts = {
      selected: {},
      ram: {
        name: 'ram',
        children: []
      },
      storage: {
        name: 'storage',
        children: []
      },
      over: function (d) {
        $scope.$apply(function () {
          $scope.charts.selected = d
        })
      }
    }

    function populateChartsData() {
      
      
      function populatestorage(root,container_id){
        let srs = filter(xoApi.getIndex('srsByContainer')[container_id] , (one_srs)=>one_srs.SR_type !== 'iso' && one_srs.SR_type !== 'udev')
        
        foreach(srs, function(one_srs){
          let srs_used_size=0,
            srs_storage = {
              name: one_srs.name_label,
              id: one_srs.id,
              children: [],
              size:one_srs.size,
              textSize:bytesToSizeFilter(one_srs.size)
            }
          
          root.size+=one_srs.size
          foreach(one_srs.VDIs, function(vdi_id){
            let vdi = xoApi.get(vdi_id)
            if(vdi.name_label.indexOf('.iso') === -1){
              let vdi_storage={
                name: vdi.name_label,
                id: vdi_id,
                size: vdi.size,
                textSize : bytesToSizeFilter(vdi.size)
              }
              srs_used_size+=vdi.size
              srs_storage.children.push(vdi_storage)
            }
          })
          if(one_srs.size > srs_used_size){// some unallocated space
            srs_storage.children.push({
              color:'white',
              name: 'Free',
              id: 'free'+one_srs.id,
              size:  one_srs.size-srs_used_size ,
              textSize : bytesToSizeFilter( one_srs.size-srs_used_size)
            })
          }
          root.children.push(srs_storage)
        })
        root.textSize = bytesToSizeFilter(root.size)
      }
      
      
      
{'fraction_non_alphanumeric': 0.11772588055130169, 'fraction_numerical': 0.0011485451761102604, 'mean_word_length': 1.8289117487818083, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '5092799', 'n_tokens_mistral': 1695, 'n_tokens_neox': 1669, 'n_words': 287}