<commit_before>import angular from 'angular'
import uiRouter from 'angular-ui-router'
import filter from 'lodash.filter'
import forEach from 'lodash.foreach'

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

import xoWeekHeatmap from'xo-week-heatmap'

import view from './view'

export default angular.module('dashboard.health', [
  uiRouter,
  xoApi,
  xoHorizon,
  xoServices,
  xoWeekHeatmap
])
  .config(function ($stateProvider) {
    $stateProvider.state('dashboard.health', {
      controller: 'Health as ctrl',
      data: {
        requireAdmin: true
      },
      url: '/health',
      template: view
    })
  })

  .controller('Health', function (xo, xoApi, $scope, modal) {
    this.currentVdiPage = 1
    this.currentVmPage = 1

    const {get} = xoApi
    const vms = xoApi.getView('VM-snapshot').all
    const vdis = xoApi.getView('VDI').all
    const srs = xoApi.getView('SR').all

    $scope.$watchCollection(() => vdis, () => {
      const orphanVdiSnapshots = filter(vdis, vdi => vdi && !vdi.$snapshot_of && vdi.is_a_snapshot)
      this.orphanVdiSnapshots = orphanVdiSnapshots
    })

    $scope.$watchCollection(() => vms, () => {
      const orphanVmSnapshots = filter(vms, vm => vm.$snapshot_of && get(vm.$snapshot_of) === undefined)
      this.orphanVmSnapshots = orphanVmSnapshots
    })

    $scope.$watchCollection(() => srs, () => {
      const warningSrs = filter(srs, sr => sr.content_type !== 'iso' && (sr.physical_usage / sr.size) >= 0.8 && (sr.physical_usage / sr.size) < 0.9)
      const dangerSrs = filter(srs, sr => sr.content_type !== 'iso' && (sr.physical_usage / sr.size) >= 0.9)
      this.warningSrs = warningSrs
      this.dangerSrs = dangerSrs
    })
<commit_msg>Correct rule for orphan snapshots<commit_after>import angular from 'angular'
import uiRouter from 'angular-ui-router'
import filter from 'lodash.filter'
import forEach from 'lodash.foreach'

import xoApi from 'xo-api'

import view from './view'

export default angular.module('dashboard.health', [
  uiRouter,
  xoApi
])
  .config(function ($stateProvider) {
    $stateProvider.state('dashboard.health', {
      controller: 'Health as ctrl',
      data: {
        requireAdmin: true
      },
      url: '/health',
      template: view
    })
  })

  .controller('Health', function (xo, xoApi, $scope, modal) {
    this.currentVdiPage = 1
    this.currentVmPage = 1

    const vms = xoApi.getView('VM-snapshot').all
    const vdis = xoApi.getView('VDI-snapshot').all
    const srs = xoApi.getView('SR').all

    $scope.$watchCollection(() => vdis, () => {
      const orphanVdiSnapshots = filter(vdis, vdi => vdi && !vdi.$snapshot_of)
      this.orphanVdiSnapshots = orphanVdiSnapshots
    })

    $scope.$watchCollection(() => vms, () => {
      const orphanVmSnapshots = filter(vms, vm => vm && !vm.$snapshot_of)
      this.orphanVmSnapshots = orphanVmSnapshots
    })

    $scope.$watchCollection(() => srs, () => {
      const warningSrs = filter(srs, sr => sr.content_type !== 'iso' && (sr.physical_usage / sr.size) >= 0.8 && (sr.physical_usage / sr.size) < 0.9)
      const dangerSrs = filter(srs, sr => sr.content_type !== 'iso' && (sr.physical_usage / sr.size) >= 0.9)
      this.warningSrs = warningSrs
      this.dangerSrs = dangerSrs
    })

{'fraction_non_alphanumeric': 0.14933494558645707, 'fraction_numerical': 0.0048367593712212815, 'mean_word_length': 3.2751937984496124, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 27, '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': '233029', 'n_tokens_mistral': 1189, 'n_tokens_neox': 1142, 'n_words': 240}