<commit_before>import SimpleSchema from 'simpl-schema'

export Reports =

	GetAchievementSummary: new ValidatedMethod
		name: 'Reports.GetAchievementSummary'
		validate:
			# TODO: check permissions
			new SimpleSchema
				projectId: type: String
				startDate: type: SimpleSchema.Integer
				endDate: type: SimpleSchema.Integer
			.validator()
		run: (args) -> if Meteor.isServer
			aggregationResult = Shifts.aggregate([
				$match:
					$and: [
						projectId: args.projectId
					,
						date: $gte: args.startDate
					,
						date: $lte: args.endDate
					]
			,
				$unwind: '$teams'
			,
				$group:
					_id: ''
					texts: $sum: '$teams.report.texts'
					speaks: $sum: '$teams.report.speaks'
					videos: $sum: '$teams.report.videos'
					hours: $sum: '$teams.report.hours'
					route: $sum: '$teams.report.experiences.route'
					good: $sum: '$teams.report.experiences.good'
					problems: $sum: '$teams.report.experiences.problems'
			])[0]

			aggregationResult ||
				_id: 0
				texts: 0
				speaks: 0
				videos: 0
				hours: 0
				route: 0
				good: 0
				problems: 0

	GetParticipantsCount: new ValidatedMethod
		name: 'Reports.GetParticipantsCount'
		validate:
			# TODO: check permissions
			new SimpleSchema
				projectId: type: String
				startDate: type: SimpleSchema.Integer
				endDate: type: SimpleSchema.Integer
			.validator()
		run: (args) -> if Meteor.isServer
			participants = Shifts.aggregate([
				$match:
					$and: [
						projectId: args.projectId
					,
						date: $gte: args.startDate
					,
						date: $lte: args.endDate
					]
			,
				$unwind: '$teams'
			,
				$unwind: '$teams.participants'
			,
				$project:
					_id: '$teams.participants._id'
			])
			.map (user) -> user._id

			fulltimeCount = participants.filter((userId) ->
				user = Meteor.users.findOne(userId, 'profile.pioneer': 1)
				user.profile.pioneer in ['regular', 'special', 'circuit', 'bethelite', 'ldc']
			).length

			publisherCount = participants.filter((userId) ->
				user = Meteor.users.findOne(userId, 'profile.publisher': 1)
				user.profile.pioneer in ['publisher', 'auxiliary']
			).length

			allCount = fulltimeCount + publisherCount

			fulltime: fulltimeCount, publishers: publisherCount, all: allCount<commit_msg>fix publisher count on reports page<commit_after>import SimpleSchema from 'simpl-schema'

export Reports =

	GetAchievementSummary: new ValidatedMethod
		name: 'Reports.GetAchievementSummary'
		validate:
			# TODO: check permissions
			new SimpleSchema
				projectId: type: String
				startDate: type: SimpleSchema.Integer
				endDate: type: SimpleSchema.Integer
			.validator()
		run: (args) -> if Meteor.isServer
			aggregationResult = Shifts.aggregate([
				$match:
					$and: [
						projectId: args.projectId
					,
						date: $gte: args.startDate
					,
						date: $lte: args.endDate
					]
			,
				$unwind: '$teams'
			,
				$group:
					_id: ''
					texts: $sum: '$teams.report.texts'
					speaks: $sum: '$teams.report.speaks'
					videos: $sum: '$teams.report.videos'
					hours: $sum: '$teams.report.hours'
					route: $sum: '$teams.report.experiences.route'
					good: $sum: '$teams.report.experiences.good'
					problems: $sum: '$teams.report.experiences.problems'
			])[0]

			aggregationResult ||
				_id: 0
				texts: 0
				speaks: 0
				videos: 0
				hours: 0
				route: 0
				good: 0
				problems: 0

	GetParticipantsCount: new ValidatedMethod
		name: 'Reports.GetParticipantsCount'
		validate:
			# TODO: check permissions
			new SimpleSchema
				projectId: type: String
				startDate: type: SimpleSchema.Integer
				endDate: type: SimpleSchema.Integer
			.validator()
		run: (args) -> if Meteor.isServer
			participants = Shifts.aggregate([
				$match:
					$and: [
						projectId: args.projectId
					,
						date: $gte: args.startDate
					,
						date: $lte: args.endDate
					]
			,
				$unwind: '$teams'
			,
				$unwind: '$teams.participants'
			,
				$project:
					_id: '$teams.participants._id'
			])
			.map (user) -> user._id

			fulltimeCount = participants.filter((userId, index, self) ->
				user = Meteor.users.findOne(userId, 'profile.pioneer': 1)

				unique = self.indexOf(userId) == index
				fulltime = user.profile.pioneer in ['regular', 'special', 'circuit', 'bethelite', 'ldc']
				fulltime && unique
			).length

			publisherCount = participants.filter((userId, index, self) ->
				user = Meteor.users.findOne(userId, 'profile.publisher': 1)

				unique = self.indexOf(userId) == index
				publisher = user.profile.pioneer in ['publisher', 'auxiliary']
				publisher && unique
			).length

			allCount = fulltimeCount + publisherCount

			fulltime: fulltimeCount, publishers: publisherCount, all: allCount
{'fraction_non_alphanumeric': 0.12728820774797786, 'fraction_numerical': 0.004682843763303533, 'mean_word_length': 2.9487394957983195, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '5544574', 'n_tokens_mistral': 2110, 'n_tokens_neox': 1577, 'n_words': 354}