<commit_before>// (c) 2018 <NAME>. MIT licensed, see https://opensource.org/licenses/MIT
// Part of Blender Driver, see https://github.com/sjjhsjjh/blender-driver

class UserInterface {
    createNode(tag, text) {
        var element = document.createElement(tag);
        if ( text !== null ) {
            element.appendChild(document.createTextNode(text));
        }
        return element;
    }
    
    appendNode(tag, text, parent) {
        return parent.appendChild(this.createNode(tag, text));
    }

    constructor(userInterfaceID) {
        this.userInterface = document.getElementById(userInterfaceID);
    }
    
    api_path(path) {
        return ['api', ...path].join('/');
    }
    
    put(value, ...path) {
        return fetch(this.api_path(path), {
           "method": "PUT",
           "body": JSON.stringify(value)
        });
    }
    
    get(...path) {
        return fetch(this.api_path(path)).then(response => response.json());
    }
    
    get_camera() {
        this.get('root', 'camera').then(response => {
            console.log('camera', response);
            this.appendNode('pre',
                            JSON.stringify(response, null, "  "),
                            this.userInterface);
            if (response.subjectPath) {
                this.get(...response.subjectPath).then(response2 => {
                    console.log('subject', response2);
                });
            }
        });
    }
    
    get_root() {
        this.get().then(response => {
            console.log('root', response);
        });
    }
    
    put_animation() {
        this.put({
            "valuePath": ["root", "camera", "orbitDistance"],
            "targetValue": 1.0,
            "speed": 1.0
            },
            'animations', 'ui', 'zoom'
        ).then(response => {
            console.log('put', response);
        });
    }
    
    show() {
        this.button = this.appendNode('button', "Fetch camera", this.userInterface);
        this.button.setAttribute('type', 'button');
        this.button.onclick = this.get_camera.bind(this);
        
        this.button = this.appendNode('button', "Zoom", this.userInterface);
        this.button.setAttribute('type', 'button');
        this.button.onclick = this.put_animation.bind(this);
        
        this.button = this.appendNode('button', "Fetch /", this.userInterface);
        this.button.setAttribute('type', 'button');
        this.button.onclick = this.get_root.bind(this);
        
        return this;
    }
}

function main(userInterfaceID) {
    const userInterface = new UserInterface(userInterfaceID);
    return userInterface.show();
}<commit_msg>Added simplified button creation method.<commit_after>// (c) 2018 <NAME>. MIT licensed, see https://opensource.org/licenses/MIT
// Part of Blender Driver, see https://github.com/sjjhsjjh/blender-driver

class UserInterface {
    createNode(tag, text) {
        var element = document.createElement(tag);
        if ( text !== undefined ) {
            element.appendChild(document.createTextNode(text));
        }
        return element;
    }
    
    appendNode(tag, text, parent) {
        if (parent === undefined) {
            parent = this.userInterface;
        }
        return parent.appendChild(this.createNode(tag, text));
    }
    
    add_button(text, boundMethod) {
        const button = this.appendNode('button', text);
        button.setAttribute('type', 'button');
        button.onclick = boundMethod;
    }
    
    add_results(...objects) {
        objects.forEach(item => 
            this.results.insertBefore(
                document.createTextNode(JSON.stringify(item, null, "  ")),
                this.results.firstChild)
        );
        this.results.normalize();
    }
    
    clear_results() {
        while(true) {
            const child = this.results.firstChild;
            if (child === null) {
                break;
            }
            this.results.removeChild(child);
        }
    }

    constructor(userInterfaceID) {
        this._interval = undefined;
        this.userInterface = document.getElementById(userInterfaceID);
    }
    
    api_path(path) {
        return ['api', ...path].join('/');
    }
    
    put(value, ...path) {
        return fetch(this.api_path(path), {
           "method": "PUT",
           "body": JSON.stringify(value)
        });
    }
    
    stop() {
        if (this._interval !== undefined) {        
            clearInterval(this._interval);
            this._interval = undefined;
        }
        fetch(this.api_path(['root', 'gameObjects']), {"method": "DELETE"})
        .then(() => {
            this.add_results("Stopped.");
        });
    }
    
    reset() {
        if (this._interval !== undefined) {        
            clearInterval(this._interval);
            this._interval = undefined;
        }
            
        const xCount = 4;
        const yCount = 4;
        const zCount = 4;
        const increment = 2.5;
        const xStart = -1.5;
        const yStart = -3.5;
        const zStart = 0.5;
        
        let objectIndex = 0;
        let x = xStart;
        let y = yStart;
        let z = zStart;
        
        let xIndex = 0;
        let yIndex = 0;
        let zIndex = 0;
        
        let finished = false;
        function add_one(that) {
            if (finished) {
                console.log("Finished.");
                return;
            }
            that.put({
                    "rotation": [0, 0, 0],
                    "worldPosition": [x, y, z],
                    "physics": false
                }, 'root', 'gameObjects', objectIndex)
            .then(() => {
                objectIndex += 1;
    
                zIndex += 1;
                z += increment;
                if (zIndex >= zCount) {
                    zIndex = 0;
                    z = zStart;
    
                    yIndex += 1;
                    y += increment;
                    if (yIndex >= yCount) {
                        yIndex = 0;
                        y = yStart;
    
                        xIndex += 1;
                        x += increment;
                        if (xIndex >= xCount) {
                            finished = true;
                        }
                    }
                }
                
                if (finished) {
                    clearInterval(that._interval);
                    that.get()
                    .then(response => {
                        that.add_results(response);
                        for(var index=0; index<objectIndex; index++) {
                            that.put(true,
                                     'root', 'gameObjects', index, "physics");
                        }
                    });
                }
            });
        }
        fetch(this.api_path(['root', 'gameObjects']), {"method": "DELETE"})
        .then(() => {
            this._interval = setInterval(add_one, 100, this);
        });

        // Camera 12, 1, 7.

    }
    
    get(...path) {
        return fetch(this.api_path(path)).then(response => response.json());
    }
    
    get_camera() {
        this.get('root', 'camera').then(response => {
            this.add_results(response);
            if (response.subjectPath) {
                this.get(...response.subjectPath).then(response2 => {
                    console.log('subject', response2);
                });
            }
        });
    }
    
    get_root() {
        this.get().then(response => this.add_results(response));
    }
    
    put_animation() {
        this.put(
            {
                "valuePath": ["root", "camera", "orbitDistance"],
                "targetValue": 1.0,
                "speed": 1.0
            },
            'animations', 'ui', 'zoom'
        ).then(response => {
            console.log('put', response);
        });
    }
    
    show() {
        this.add_button("Fetch camera", this.get_camera.bind(this));
        this.add_button("Zoom", this.put_animation.bind(this));
        this.add_button("Fetch /", this.get_root.bind(this));
        this.add_button("Clear", this.clear_results.bind(this));
        this.add_button("Reset", this.reset.bind(this));
        this.add_button("Stop", this.stop.bind(this));
        
        this.results = this.appendNode('pre');
        
        return this;
    }
}

function main(userInterfaceID) {
    const userInterface = new UserInterface(userInterfaceID);
    return userInterface.show();
}
{'fraction_non_alphanumeric': 0.13756303506508738, 'fraction_numerical': 0.006098276064266448, 'mean_word_length': 1.4372677907973708, 'pattern_counts': {'":': 15, '<': 6, '<?xml version=': 0, '>': 23, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3499678', 'n_tokens_mistral': 2381, 'n_tokens_neox': 2291, 'n_words': 413}