<commit_before>/// <reference path="../vendor/jquery.d.ts" />
/// <reference path="../vendor/knockout.d.ts" />
/// <reference path="../vendor/moment.d.ts" />
import ko = require('knockout');
import moment = require('moment');
import Types = require('../Types');
import MonitorModel = require('../monitorModel/MonitorModel');
import MonitorModels = require('../monitorModel/MonitorModels');
import Connector = require('../connector/Connector');
import CssClasses = require('../CssClasses');
import JenkinsConnector = require('./JenkinsConnector');
import JenkinsDetailsModel = require('./JenkinsDetailsModel');
import Config = require('../jsonInterfaces/Config');
import JenkinsJsonResponse = require('../jsonInterfaces/JenkinsResponse');

/**
 * Model that represents a Jenkins Job
 */
class JenkinsMonitorModel implements MonitorModel {

    private static OPACITY:string = 'opacity: ';
    private static DEFAULT_OPACITY:number = 1.0;

    private _connector:Connector;
    private _name:string;
    private _id:string;
    private _hostname:string;
    private _css:KnockoutComputed<string>;
    private _style:KnockoutComputed<string>;
    private _completedPercent:KnockoutComputed<number>;
    private _buildingStyle:KnockoutComputed<string>;
    private _details:JenkinsDetailsModel;
    private _jsonResponse:KnockoutObservable<JenkinsJsonResponse.Json> = ko.observable<JenkinsJsonResponse.Json>();

    constructor(job:Config.Monitor, connector:Connector, hostname:string) {
        this._connector = connector;
        this._name = job.name !== undefined ? job.name : job.id;
        this._id = job.id;
        this._hostname = job.hostname !== undefined ? job.hostname : hostname;
        this._details = new JenkinsDetailsModel((<JenkinsConnector>connector).getJobUrl(this), this._name);
        this._css = ko.computed<string>({
                read: ()=>{
                    return CssClasses.BASIC_CLASSES + JenkinsMonitorModel.translateColor(this.getResponseColor());
                }
        });
        this._buildingStyle = ko.computed<string>({
                read: ()=>{
                    return JenkinsMonitorModel.translateBuildingStyle(this.getResponseColor());
                }
        });
        this._style = ko.computed<string>({
            read: ()=>{
                return JenkinsMonitorModel.OPACITY+JenkinsMonitorModel.calculateExpiration(this.getResponseTimestamp(), (<JenkinsConnector>this._connector).getExpiry());
            }
        });
        this._completedPercent = ko.computed<number>({
            read: ()=>{
                return JenkinsMonitorModel.calculateCompletedPercent(this.getResponseTimestamp(), this.getEstimatedDuration());
            }
        });
    }

    public updateStatus():void {
        this._connector.getRemoteData(this);
    }

    public getName():string {
        return this._name;
    }

    public getId():string {
        return this._id;
    }

    public getHtmlsafeId():string {
        var _PATTERN:RegExp = new RegExp('\\W','g');
        var _REPLACEMENT_CHAR = '-';
        return this._id.replace(_PATTERN,_REPLACEMENT_CHAR);
    }

    public getCompletedPercent():number {
        return this._completedPercent();
    }

    public getHostname():string {
        return this._hostname;
    }

    public getCss():string {
        return this._css();
    }

    public getBuildingStyle():string {
        return this._buildingStyle();
    }

    public getStyle():string {
        return this._style();
    }

    public getDetails():JenkinsDetailsModel {
        return this._details;
    }

    public getType():string {
        return Types.JENKINS;
    }

    public setData(json:JenkinsJsonResponse.Json):void {
        this._jsonResponse(json);
        this._details.setData(json);
    }

    //==================================================================================================================
<commit_msg>add documentation, structure<commit_after>/// <reference path="../vendor/jquery.d.ts" />
/// <reference path="../vendor/knockout.d.ts" />
/// <reference path="../vendor/moment.d.ts" />
import ko = require('knockout');
import moment = require('moment');
import Types = require('../Types');
import MonitorModel = require('../monitorModel/MonitorModel');
import MonitorModels = require('../monitorModel/MonitorModels');
import Connector = require('../connector/Connector');
import CssClasses = require('../CssClasses');
import JenkinsConnector = require('./JenkinsConnector');
import JenkinsDetailsModel = require('./JenkinsDetailsModel');
import Config = require('../jsonInterfaces/Config');
import JenkinsJsonResponse = require('../jsonInterfaces/JenkinsResponse');

/**
 * Model that represents a Jenkins Job
 */
class JenkinsMonitorModel implements MonitorModel {

    private static OPACITY:string = 'opacity: ';
    private static DEFAULT_OPACITY:number = 1.0;

    private _connector:Connector;
    private _name:string;
    private _id:string;
    private _hostname:string;
    private _css:KnockoutComputed<string>;
    private _style:KnockoutComputed<string>;
    private _completedPercent:KnockoutComputed<number>;
    private _buildingStyle:KnockoutComputed<string>;
    private _details:JenkinsDetailsModel;
    private _jsonResponse:KnockoutObservable<JenkinsJsonResponse.Json> = ko.observable<JenkinsJsonResponse.Json>();

    //==================================================================================================================
    // Construct
    //==================================================================================================================

    constructor(job:Config.SimpleMonitor, connector:Connector, hostname:string) {
        this._connector = connector;
        this._name = job.name !== undefined ? job.name : job.id;
        this._id = job.id;
        this._hostname = job.hostname !== undefined ? job.hostname : hostname;
        this._details = new JenkinsDetailsModel((<JenkinsConnector>connector).getJobUrl(this), this._name);
        this._css = ko.computed<string>({
                read: ()=>{
                    return CssClasses.BASIC_CLASSES + JenkinsMonitorModel.translateColor(this.getResponseColor());
                }
        });
        this._buildingStyle = ko.computed<string>({
                read: ()=>{
                    return JenkinsMonitorModel.translateBuildingStyle(this.getResponseColor());
                }
        });
        this._style = ko.computed<string>({
            read: ()=>{
                return JenkinsMonitorModel.OPACITY+JenkinsMonitorModel.calculateExpiration(this.getResponseTimestamp(), (<JenkinsConnector>this._connector).getExpiry());
            }
        });
        this._completedPercent = ko.computed<number>({
            read: ()=>{
                return JenkinsMonitorModel.calculateCompletedPercent(this.getResponseTimestamp(), this.getEstimatedDuration());
            }
        });
    }

    //==================================================================================================================
    // View Layer
    //==================================================================================================================

    public getName():string {
        return this._name;
    }

    public getId():string {
        return this._id;
    }

    public getHtmlsafeId():string {
        var _PATTERN:RegExp = new RegExp('\\W','g');
        var _REPLACEMENT_CHAR = '-';
        return this._id.replace(_PATTERN,_REPLACEMENT_CHAR);
    }

    public getCompletedPercent():number {
        return this._completedPercent();
    }

    public getHostname():string {
        return this._hostname;
    }

    public getCss():string {
        return this._css();
    }

    public getBuildingStyle():string {
        return this._buildingStyle();
    }

    public getStyle():string {
        return this._style();
    }

    public getDetails():JenkinsDetailsModel {
        return this._details;
    }

    public getType():string {
        return Types.JENKINS;
    }

    //==================================================================================================================
    // Functionality
    //==================================================================================================================

    public updateStatus():void {
        this._connector.getRemoteData(this);
    }

    public setData(json:JenkinsJsonResponse.Json):void {
        this._jsonResponse(json);
        this._details.setData(json);
    }

    //==================================================================================================================
    // Private
    //==================================================================================================================

{'fraction_non_alphanumeric': 0.2310580204778157, 'fraction_numerical': 0.0004550625711035267, 'mean_word_length': 3.3606150793650795, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 41, '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': '6602504', 'n_tokens_mistral': 2262, 'n_tokens_neox': 2104, 'n_words': 359}