<commit_before>import { Component, OnInit, DoCheck, KeyValueDiffers } from '@angular/core';
import { Router } from '@angular/router';
import { ActivatedRoute, Params } from '@angular/router';

import { AssessmentService } from './assessment.service';
import { VnService } from './vn.service';

@Component({
	moduleId: module.id,
	selector: 'vn-assessment-selector',
	templateUrl: 'vn-assessment.component.html'
})

export class VnAssessmentComponent implements OnInit, DoCheck {
	constructor(
		public router: Router,
		public route: ActivatedRoute,
		public assessmentService: AssessmentService,
		public vnService: VnService,
		private differs: KeyValueDiffers
	) {
		this.differ = differs.find({}).create(null);
	}

	differ: any;

	assessment:any = [];

	debugDump():any {
		return JSON.stringify(this.has_change);
	}

	ngOnInit() {
		this.route.params.forEach((params: Params) => {
			let id = +params['id'];
			this.loadAssessment(id);
			this.loadVn(id);
		});
	}

	vn:any = [];
	loadVn(vn_id:number):void {
		this.vnService.getVn(vn_id).subscribe(response => {
			this.vn = response;
		});
	}

	loadAssessment(vn_id:number):void {
		this.assessmentService.getAssessment(vn_id).subscribe(response => {
			if(!response.id) {
				this.assessment.vn_id = vn_id;
			}
			else {
				this.assessment = response;
			}
		});
	}

	ngDoCheck() {
		let changes = this.differ.diff(this.assessment);
		if(changes) {
			changes.forEachChangedItem(obj => {
				if(obj.key === "score_all") {
					this.has_change.score_all = true;
				}
				if(obj.key === "status") {
					this.has_change.status = true;
				}
			});
		}
	}

	has_change:any = {
		score_all: false,
		status: false
	};

	saveAssessment():void {
		if(this.assessment.archive_savedata == true) {
			this.assessment.archive_savedata = 1;
		}
		else if(this.assessment.archive_savedata == false) {
			this.assessment.archive_savedata = 0;
		}

		if(!this.assessment.id) {
			this.assessmentService.createAssessment(this.assessment).subscribe(response => {
				console.log("Assessment saved", response);
			});
		}
		else {
			this.assessmentService.updateAssessment(this.assessment).subscribe(response => {
				console.log("VN update success", response);
				if(localStorage.getItem('vndb_toggle') == "0") {<commit_msg>UTC to Local time conversion<commit_after>import { Component, OnInit, DoCheck, KeyValueDiffers } from '@angular/core';
import { Router } from '@angular/router';
import { ActivatedRoute, Params } from '@angular/router';

import * as moment from 'moment';

import { AssessmentService } from './assessment.service';
import { VnService } from './vn.service';

@Component({
	moduleId: module.id,
	selector: 'vn-assessment-selector',
	templateUrl: 'vn-assessment.component.html'
})

export class VnAssessmentComponent implements OnInit, DoCheck {
	constructor(
		public router: Router,
		public route: ActivatedRoute,
		public assessmentService: AssessmentService,
		public vnService: VnService,
		private differs: KeyValueDiffers
	) {
		this.differ = differs.find({}).create(null);
	}

	differ: any;

	assessment:any = [];

	debugDump():any {
		return JSON.stringify(this.has_change);
	}

	ngOnInit() {
		this.route.params.forEach((params: Params) => {
			let id = +params['id'];
			this.loadAssessment(id);
			this.loadVn(id);
		});
	}

	vn:any = [];
	loadVn(vn_id:number):void {
		this.vnService.getVn(vn_id).subscribe(response => {
			this.vn = response;
		});
	}

	loadAssessment(vn_id:number):void {
		this.assessmentService.getAssessment(vn_id).subscribe(response => {
			if(!response.id) {
				this.assessment.vn_id = vn_id;
			}
			else {
				this.assessment = response;
				// this.assessment.date_start = moment.utc(response.date_start).toDate();
				this.assessment.date_start = moment.utc(response.date_start, 'YYYY-MM-DD HH:mm:ss').local().format('YYYY-MM-DD HH:mm:ss');
				this.assessment.date_end = moment.utc(response.date_end, 'YYYY-MM-DD HH:mm:ss').local().format('YYYY-MM-DD HH:mm:ss');
			}
		});
	}

	ngDoCheck() {
		let changes = this.differ.diff(this.assessment);
		if(changes) {
			changes.forEachChangedItem(obj => {
				if(obj.key === "score_all") {
					this.has_change.score_all = true;
				}
				if(obj.key === "status") {
					this.has_change.status = true;
				}
			});
		}
	}

	has_change:any = {
		score_all: false,
		status: false
	};

	saveAssessment():void {
		// format archive_savedata into writtable value
		if(this.assessment.archive_savedata == true) {
			this.assessment.archive_savedata = 1;
		}
		else if(this.assessment.archive_savedata == false) {
			this.assessment.archive_savedata = 0;
		}

		// convert datetime to UTC
		this.assessment.date_start = moment(this.assessment.date_start, 'YYYY-MM-DD HH:mm:ss').utc().format('YYYY-MM-DD HH:mm:ss');
		this.assessment.date_end = moment(this.assessment.date_end, 'YYYY-MM-DD HH:mm:ss').utc().format('YYYY-MM-DD HH:mm:ss');

		if(!this.assessment.id) {
			this.assessmentService.createAssessment(this.assessment).subscribe(response => {
				console.log("Assessment saved", response);
			});
		}
		else {
			this.assessmentService.updateAssessment(this.assessment).subscribe(response => {
				console.log("VN update success", response);
				if(localStorage.getItem('vndb_toggle') == "0") {
{'fraction_non_alphanumeric': 0.15491615853658536, 'fraction_numerical': 0.0011432926829268292, 'mean_word_length': 4.1410381978452495, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '6789999', 'n_tokens_mistral': 2077, 'n_tokens_neox': 1820, 'n_words': 288}