<commit_before>_ = lodash

angular.module('app').controller 'hoursCtrl', ['$scope', '$meteor', '$stateParams', ($scope, $meteor, $stateParams) ->
	KJ = share.KiTaJahr
	$scope.settings = $scope.$meteorObject share.Settings, {}
	$scope.currentYear = KJ.current $scope.settings
	$scope.sortType = 'hours'
	$scope.sortReverse = true

	updateHours = () ->
		$scope.kj = new KJ $scope.currentYear, $scope.settings
		$scope.warningLimit = 0.5
		$scope.hoursPerMonth = 2.5
		$scope.startOfKitaYear = $scope.kj.startDate()
		$scope.endOfKitaYear = $scope.kj.endDate()

		now = moment()
		if now.isBefore($scope.startOfKitaYear)
			$scope.monthsOfKitaYear = 0
		else if now.isAfter($scope.endOfKitaYear)
			$scope.monthsOfKitaYear = 12
		else # is between
			$scope.monthsOfKitaYear = moment.duration(now.diff($scope.startOfKitaYear)).months()

		console.log "kitajahr: #{$scope.startOfKitaYear.format()} => #{$scope.endOfKitaYear.format()}"

		allHours = $scope.$meteorCollection () -> share.Hours.find
			date:
				$gte: $scope.startOfKitaYear.toDate()
				$lt:  $scope.endOfKitaYear.toDate()

		$scope.hours = []
		for k, v of _.groupBy(allHours, (h) -> h.family)
			hoursSum = _.sum(v, (h) -> h.hours)
			th = $scope.monthsOfKitaYear * share.parentCount($meteor.object(share.Families, k)) * $scope.hoursPerMonth
			$scope.hours.push
				familyName: _.first(v)?.familyName
				hours: hoursSum
				targetHours: th
				severity: if hoursSum < th*$scope.warningLimit then 'warning' else 'info'

		console.log $scope.hours

		max = _.max $scope.hours, (h) -> h.hours

		for h in $scope.hours
			#h.hoursPercentage = 100.0 / (max.hours / h.hours)
			h.hoursPercentage = 100.0 / (h.targetHours / h.hours)

		ny = "#{$scope.currentYear+1}".substring 2 
		$scope.currentYearString = "#{$scope.currentYear}/#{ny}"

		$scope.hoursSum = _.sum allHours, (h) -> h.hours

	updateHours()

	$scope.goToPreviousYear = () ->
		$scope.currentYear--
		updateHours()

	$scope.goToNextYear = () ->
		$scope.currentYear++
		updateHours()
]<commit_msg>use settings in hours<commit_after>_ = lodash

angular.module('app').controller 'hoursCtrl', ['$scope', '$meteor', '$stateParams', ($scope, $meteor, $stateParams) ->
	KJ = share.KiTaJahr
	$scope.settings = $scope.$meteorObject share.Settings, {}
	$scope.currentYear = KJ.current $scope.settings
	$scope.sortType = 'hours'
	$scope.sortReverse = true

	updateHours = () ->
		$scope.kj = new KJ $scope.currentYear, $scope.settings
		$scope.warningLimit = 0.5
		$scope.hoursPerMonth = $scope.settings.hoursPerFamilyAndMonth/2
		$scope.startOfKitaYear = $scope.kj.startDate()
		$scope.endOfKitaYear = $scope.kj.endDate()

		now = moment()
		if now.isBefore($scope.startOfKitaYear)
			$scope.monthsOfKitaYear = 0
		else if now.isAfter($scope.endOfKitaYear)
			$scope.monthsOfKitaYear = 12
		else # is between
			$scope.monthsOfKitaYear = moment.duration(now.diff($scope.startOfKitaYear)).months()

		console.log "kitajahr: #{$scope.startOfKitaYear.format()} => #{$scope.endOfKitaYear.format()}"

		allHours = $scope.$meteorCollection () -> share.Hours.find
			date:
				$gte: $scope.startOfKitaYear.toDate()
				$lt:  $scope.endOfKitaYear.toDate()

		$scope.hours = []
		for k, v of _.groupBy(allHours, (h) -> h.family)
			hoursSum = _.sum(v, (h) -> h.hours)
			th = $scope.monthsOfKitaYear * share.parentCount($meteor.object(share.Families, k)) * $scope.hoursPerMonth
			$scope.hours.push
				familyName: _.first(v)?.familyName
				hours: hoursSum
				targetHours: th
				severity: if hoursSum < th*$scope.warningLimit then 'warning' else 'info'

		console.log $scope.hours

		max = _.max $scope.hours, (h) -> h.hours

		for h in $scope.hours
			#h.hoursPercentage = 100.0 / (max.hours / h.hours)
			h.hoursPercentage = 100.0 / (h.targetHours / h.hours)

		ny = "#{$scope.currentYear+1}".substring 2 
		$scope.currentYearString = "#{$scope.currentYear}/#{ny}"

		$scope.hoursSum = _.sum allHours, (h) -> h.hours

	updateHours()

	$scope.goToPreviousYear = () ->
		$scope.currentYear--
		updateHours()

	$scope.goToNextYear = () ->
		$scope.currentYear++
		updateHours()
]
{'fraction_non_alphanumeric': 0.1656471739662344, 'fraction_numerical': 0.008074382187423538, 'mean_word_length': 3.9611650485436893, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, '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': '903602', 'n_tokens_mistral': 1736, 'n_tokens_neox': 1493, 'n_words': 267}