<commit_before>import { Component, Input, OnInit, OnDestroy } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { hexToRgb } from '../../../common/utils';
import moment from 'moment';
// import { SocketioService } from '../../../services/socketio.service';

declare let Chart: any;

@Component({
	selector: 'mymicds-progress',
	templateUrl: './progress.component.html',
	styleUrls: ['./progress.component.scss']
})
export class ProgressComponent implements OnInit, OnDestroy {

	@Input()
	today: any = null;

	@Input()
	schedule: any = null;

	// Circular Progress References
	ctx: any;
	progressBar: any;

	// Current Class Label
	currentClass: string = null;
	currentClassPercent: number = null;
	schoolPercent: number = null;

	// Start / destroy interval that calculates percentages
	timer: any;

	// Socket.io
	progressDayCtx: any;
	socketioConnection: any;
	progressDayClick: any;
	progressDayUnclick: any;

	// constructor(private socketioService: SocketioService) { }
	constructor() { }

	/*
	 * Configure progress bar
	 */

	// Returns default data for progress bar
	defaultColors(): string[] {
		return ['rgba(0, 0, 0, 0.1)'];
	}
	defaultData(): number[] {
		return [100];
	}
	defaultLabels(): string[] {
		return ['No School'];
	}
	defaultDurations(): string[] {
		return ['All Day'];
	}

	ngOnInit() {
		// Get Progress Bar <canvas>
		this.ctx = document.getElementsByClassName('progress-chart')[0];

		// Initialize Progress Bar
		this.progressBar = new Chart(this.ctx, {
			type: 'doughnut',
			data: {
				labels: this.defaultLabels(),
				durations: this.defaultDurations(),
				datasets: [{
					data: this.defaultData(),
					backgroundColor: this.defaultColors(),
					borderWidth: 0
				}]
			},
			options: {
				animation: {
					easing: 'easeInOutCirc'
				},
				legend: {
					display: false
				},
				tooltips: {
					callbacks: {
						label: function(tooltipItem, data) {
							return data.labels[tooltipItem.index] + ': ' + data.durations[tooltipItem.index];
						}
					}
				},
				cutoutPercentage: 95
			}
		});

		// Start timer
		this.calculatePercentages();
		this.timer = setInterval(() => {
			this.calculatePercentages();
		}, 1000);

		// Socket.io service to spin the spinny
		// this.progressDayCtx = document.getElementsByClassName('progress-day')[0];

		// this.socketioConnection = this.socketioService.listen('progress label spin').subscribe(
		// 	pressed => {
		// 		pressed ? this.progressDayCtx.classList.add('rotate') : this.progressDayCtx.classList.remove('rotate');
		// 	}
		// );

		// this.progressDayClick = Observable.fromEvent(this.progressDayCtx, 'mousedown')
		// 	.debounceTime(100)
		// 	.subscribe(
		// 		e => {
		// 			this.socketioService.emit('progress label click', true);
		// 		}
		// 	);

		// this.progressDayUnclick = Observable.fromEvent(this.progressDayCtx, 'mouseup')
		// 	.debounceTime(100)
		// 	.subscribe(
		// 		e => {
		// 			this.socketioService.emit('progress label click', false);
		// 		}
		// 	);
	}

	ngOnDestroy() {
		// Stop timer
		clearInterval(this.timer);
		// Destroy Progress Bar Instance
		this.progressBar.destroy();
		// Unsubsciribe socket connection
		this.socketioConnection.unsubscribe();
		this.progressDayClick.unsubscribe();
		this.progressDayUnclick.unsubscribe();
	}

	/*
	 * Calculate schedule data and store to variables
	 */

	calculatePercentages() {
		// Fallback if schedule is not set or no school
		if (!this.schedule || this.schedule.classes.length === 0) {
			// Just set default parameters
			this.progressBar.data.datasets[0].backgroundColor = this.defaultColors();<commit_msg>Also forget the unused subscription variables<commit_after>import { Component, Input, OnInit, OnDestroy } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { hexToRgb } from '../../../common/utils';
import moment from 'moment';
// import { SocketioService } from '../../../services/socketio.service';

declare let Chart: any;

@Component({
	selector: 'mymicds-progress',
	templateUrl: './progress.component.html',
	styleUrls: ['./progress.component.scss']
})
export class ProgressComponent implements OnInit, OnDestroy {

	@Input()
	today: any = null;

	@Input()
	schedule: any = null;

	// Circular Progress References
	ctx: any;
	progressBar: any;

	// Current Class Label
	currentClass: string = null;
	currentClassPercent: number = null;
	schoolPercent: number = null;

	// Start / destroy interval that calculates percentages
	timer: any;

	// Socket.io
	progressDayCtx: any;
	socketioConnection: any;
	progressDayClick: any;
	progressDayUnclick: any;

	// constructor(private socketioService: SocketioService) { }
	constructor() { }

	/*
	 * Configure progress bar
	 */

	// Returns default data for progress bar
	defaultColors(): string[] {
		return ['rgba(0, 0, 0, 0.1)'];
	}
	defaultData(): number[] {
		return [100];
	}
	defaultLabels(): string[] {
		return ['No School'];
	}
	defaultDurations(): string[] {
		return ['All Day'];
	}

	ngOnInit() {
		// Get Progress Bar <canvas>
		this.ctx = document.getElementsByClassName('progress-chart')[0];

		// Initialize Progress Bar
		this.progressBar = new Chart(this.ctx, {
			type: 'doughnut',
			data: {
				labels: this.defaultLabels(),
				durations: this.defaultDurations(),
				datasets: [{
					data: this.defaultData(),
					backgroundColor: this.defaultColors(),
					borderWidth: 0
				}]
			},
			options: {
				animation: {
					easing: 'easeInOutCirc'
				},
				legend: {
					display: false
				},
				tooltips: {
					callbacks: {
						label: function(tooltipItem, data) {
							return data.labels[tooltipItem.index] + ': ' + data.durations[tooltipItem.index];
						}
					}
				},
				cutoutPercentage: 95
			}
		});

		// Start timer
		this.calculatePercentages();
		this.timer = setInterval(() => {
			this.calculatePercentages();
		}, 1000);

		// Socket.io service to spin the spinny
		// this.progressDayCtx = document.getElementsByClassName('progress-day')[0];

		// this.socketioConnection = this.socketioService.listen('progress label spin').subscribe(
		// 	pressed => {
		// 		pressed ? this.progressDayCtx.classList.add('rotate') : this.progressDayCtx.classList.remove('rotate');
		// 	}
		// );

		// this.progressDayClick = Observable.fromEvent(this.progressDayCtx, 'mousedown')
		// 	.debounceTime(100)
		// 	.subscribe(
		// 		e => {
		// 			this.socketioService.emit('progress label click', true);
		// 		}
		// 	);

		// this.progressDayUnclick = Observable.fromEvent(this.progressDayCtx, 'mouseup')
		// 	.debounceTime(100)
		// 	.subscribe(
		// 		e => {
		// 			this.socketioService.emit('progress label click', false);
		// 		}
		// 	);
	}

	ngOnDestroy() {
		// Stop timer
		clearInterval(this.timer);
		// Destroy Progress Bar Instance
		this.progressBar.destroy();
		// Unsubsciribe socket connection
		// this.socketioConnection.unsubscribe();
		// this.progressDayClick.unsubscribe();
		// this.progressDayUnclick.unsubscribe();
	}

	/*
	 * Calculate schedule data and store to variables
	 */

	calculatePercentages() {
		// Fallback if schedule is not set or no school
		if (!this.schedule || this.schedule.classes.length === 0) {
			// Just set default parameters
			this.progressBar.data.datasets[0].backgroundColor = this.defaultColors();
{'fraction_non_alphanumeric': 0.1496915695681974, 'fraction_numerical': 0.006854009595613434, 'mean_word_length': 3.274165202108963, 'pattern_counts': {'":': 0, '<': 5, '<?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': '3745742', 'n_tokens_mistral': 2676, 'n_tokens_neox': 2310, 'n_words': 498}