<commit_before>/// <reference path="../../typings/virtual-dom/virtual-dom.d.ts" />

import * as _ from "underscore";
import * as rx from "rx";
import * as vd from "virtual-dom";

import {IVNodeHash} from "../Render";
import {IFrame} from "../State";
import {UI} from "../UI";
import {Container, Navigator} from "../Viewer";

export class DebugUI extends UI {
    public static uiName: string = "debug";
    private _key: string;

    private _displaying: boolean;
    private _disposable: rx.IDisposable;

    private _open$: rx.Subject<boolean> = new rx.Subject<boolean>();

    constructor(name: string, container: Container, navigator: Navigator) {
        super(name, container, navigator);
        this._displaying = false;
    }

    public configure(options: any): void {
        this._key = options.key;
    }

    public _activate(): void {
        this._disposable = this._navigator.stateService.currentState$
            .combineLatest(this._open$, this._navigator.graphService.imageLoadingService.loadstatus$,
                           (frame: IFrame, open: boolean, loadStatus: any): IVNodeHash => {
                               return {name: this._name, vnode: this._getDebugVNode(open, this._getDebugInfo(frame, loadStatus))};
                           })
            .subscribe(this._container.domRenderer.render$);
        this._open$.onNext(false);
    }

    public _deactivate(): void {
        this._disposable.dispose();
    }

    private _getDebugInfo(frame: IFrame, loadStatus: any): vd.VNode[] {
        let ret: vd.VNode[] = [];

        ret.push(vd.h("h2", "Node"));

        ret.push(vd.h("p", `currentNode: ${frame.state.currentNode.key}`));

        if (frame.state.previousNode) {
            ret.push(vd.h("p", `previousNode: ${frame.state.previousNode.key}`));
        }

        ret.push(vd.h("h2", "Loading"));

        let total: number = 0;
        let loaded: number = 0;
        let loading: number = 0;

        for (let loadStat of _.values(loadStatus)) {
            total += loadStat.total;
            if (loadStat.loaded !== loadStat.total) {
                loading++;
            } else {
                loaded++;
            }
        }

        ret.push(vd.h("p", `Loaded Images: ${loaded}`));
        ret.push(vd.h("p", `Loading Images: ${loading}`));
        ret.push(vd.h("p", `Total bytes loaded: ${total}`));

        ret.push(vd.h("h2", "Camera"));

        ret.push(vd.h("p", `camera.position.x: ${frame.state.camera.position.x}`));
        ret.push(vd.h("p", `camera.position.y: ${frame.state.camera.position.y}`));<commit_msg>Use correct loading meassure in Debug<commit_after>/// <reference path="../../typings/virtual-dom/virtual-dom.d.ts" />

import * as _ from "underscore";
import * as rx from "rx";
import * as vd from "virtual-dom";

import {IVNodeHash} from "../Render";
import {IFrame} from "../State";
import {UI} from "../UI";
import {Container, Navigator} from "../Viewer";

export class DebugUI extends UI {
    public static uiName: string = "debug";
    private _key: string;

    private _displaying: boolean;
    private _disposable: rx.IDisposable;

    private _open$: rx.Subject<boolean> = new rx.Subject<boolean>();

    constructor(name: string, container: Container, navigator: Navigator) {
        super(name, container, navigator);
        this._displaying = false;
    }

    public configure(options: any): void {
        this._key = options.key;
    }

    public _activate(): void {
        this._disposable = this._navigator.stateService.currentState$
            .combineLatest(this._open$, this._navigator.graphService.imageLoadingService.loadstatus$,
                           (frame: IFrame, open: boolean, loadStatus: any): IVNodeHash => {
                               return {name: this._name, vnode: this._getDebugVNode(open, this._getDebugInfo(frame, loadStatus))};
                           })
            .subscribe(this._container.domRenderer.render$);
        this._open$.onNext(false);
    }

    public _deactivate(): void {
        this._disposable.dispose();
    }

    private _getDebugInfo(frame: IFrame, loadStatus: any): vd.VNode[] {
        let ret: vd.VNode[] = [];

        ret.push(vd.h("h2", "Node"));

        ret.push(vd.h("p", `currentNode: ${frame.state.currentNode.key}`));

        if (frame.state.previousNode) {
            ret.push(vd.h("p", `previousNode: ${frame.state.previousNode.key}`));
        }

        ret.push(vd.h("h2", "Loading"));

        let total: number = 0;
        let loaded: number = 0;
        let loading: number = 0;

        for (let loadStat of _.values(loadStatus)) {
            total += loadStat.loaded;
            if (loadStat.loaded !== loadStat.total) {
                loading++;
            } else {
                loaded++;
            }
        }

        ret.push(vd.h("p", `Loaded Images: ${loaded}`));
        ret.push(vd.h("p", `Loading Images: ${loading}`));
        ret.push(vd.h("p", `Total bytes loaded: ${total}`));

        ret.push(vd.h("h2", "Camera"));

        ret.push(vd.h("p", `camera.position.x: ${frame.state.camera.position.x}`));
        ret.push(vd.h("p", `camera.position.y: ${frame.state.camera.position.y}`));
{'fraction_non_alphanumeric': 0.16253602305475504, 'fraction_numerical': 0.0023054755043227667, 'mean_word_length': 2.376134889753567, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, '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': '7415844', 'n_tokens_mistral': 1602, 'n_tokens_neox': 1563, 'n_words': 342}