<commit_before><!DOCTYPE html>
<html ng-app="resultPage">
<head>
    <script type='text/javascript'>
        function refreshPage()
        {
            window.location.reload(true);
        }
    </script>
    <script src="http://cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.min.js"></script>
    <script src="ovirtsdk.js"></script>

    <!-- Compatibility hacks
     according to https://docs.angularjs.org/guide/ie //-->
    <!--[if lte IE 7]>
    <script src="http://cdnjs.cloudflare.com/ajax/libs/json2/20130526/json2.min.js"></script>
    <![endif]-->
    <!--[if lte IE 8]>
    <script>
        document.createElement('ng-include');
        document.createElement('ng-pluralize');
        document.createElement('ng-view');

        // Optionally these for CSS
        document.createElement('ng:include');
        document.createElement('ng:pluralize');
        document.createElement('ng:view');
    </script>
    <![endif]-->
    <style>
        .host { font-weight: bold; }
        .ng-cloak, [ng-cloak].splash {
            display: block !important;
        }
        .splash {
            display: none !important;
        }
    </style>
</head>
<body>

<div class="splash">Loading..</div>

<div ng-cloak class="ng-cloak" ng-controller="resultController">

    <p>Status: {{ valid }}</p>

    <button ng-click="frozen=true">Freeze solution</button>
    <button ng-click="frozen=false">Unfreeze solution</button>

    <h2>VMs that should be started</h2>
    <table>
        <tr ng-repeat="vm in result.requestedVms">
            <td>{{ vms[vm].name }}</td>
            <td><button ng-click="cancel_start(vm);">Cancel</button></td>
        </tr>
    </table>

    <h2>Migration/Start steps</h2>
    <table>
        <tbody ng-repeat="step in result.migrations">
        <tr ng-repeat="(vm, host) in step">
            <td>{{ vms[vm].name }} &ndash;&gt; {{ hosts[host].name }}</td>
            <td><button ng-click="migrate(vm, host)">migrate to {{ hosts[host].name }}</button></td>
        </tr>
        </tbody>
    </table>

    <h2>Desired state</h2>
    <table>
        <tbody ng-repeat="(host, rvms) in result.hostToVms">
        <tr class="host">
            <td>{{ hosts[host].name }}</td>
            <td>{{ hosts[host].willusememory }} out of {{ hosts[host].memory }}</td>
            <td></td>
        </tr>
        <tr class="vm" ng-repeat="vm in rvms">
            <td>{{ vms[vm].name }}</td>
            <td>{{ vms[vm].memory_policy.guaranteed }} (max {{ vms[vm].memory }})</td>
            <td ng-if="result.vmToHost[vm] != result.currentVmToHost[vm]"><button ng-click="migrate(vm, result.vmToHost[vm])">migrate from {{ hosts[result.currentVmToHost[vm]].name }}</button></td>
            <td ng-if="result.vmToHost[vm] == result.currentVmToHost[vm]">&nbsp;</td>
        </tr>
        </tbody>
    </table>

    <!--
    <p>Raw data: {{ result }}</p>
    <p>Raw vm data: {{ vms }}</p>
    <p>Raw host data: {{ hosts }}</p>
    <p>Verification data: {{ verification }}</p>
    //-->
</div>

<script language="javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular.js"></script>
<script language="javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular.route.js"></script>
<script language="javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular.resource.js"></script>
<script language="javascript">
    var api = parent.pluginApi('oVirtOptimizer');
    var cfg = api.configObject();
    var clusterid = window.location.href.split("#")[1];
    var resultPage = angular.module('resultPage', []);

    resultPage.controller("resultController", function($scope, $timeout, $http, resultFactory,
                                                       verificationFactory, vmsFactory, hostsFactory) {
        $scope.result = {};
        $scope.verification = {};
        $scope.valid = "Waiting for data...";
        $scope.frozen = false;
        $scope.hosts = {};
        $scope.vms = {};

        $scope.migrate = function(vm, host) {
            console.log("Initiating migration of vm "+vm+" to host "+host);
            $http({
                method: 'POST',
                url: "http://"+window.parent.location.host + "/ovirt-engine/api/vms/" + vm + "/migrate",
                headers: {"Content-Type": "application/json",
                          "Accept": "application/json"},
                data: {host: {id: host},
                       async: true}
            }).success(function (data) {

            });
        };

        $scope.cancel_start = function(vm) {
            $http({
                method: 'POST',
                url: cfg["baseurl"]+clusterid+"/cancel",
                headers: {"Content-Type": "application/json",
                          "Accept": "application/json"},
                data: {id: vm}
            }).success(function (data) {
                $scope.valid = "Waiting for updated solution."
            });
        };

        $scope.refresh = function() {
            if ($scope.frozen) {
                $scope.verifyData();
            }
            else {
                $scope.refreshData();
            }
        };

        $scope.refreshData = function() {
            resultFactory.getResult().success(function (data) {
                $scope.result = data;
                $scope.valid = "Data received";
                $timeout($scope.refresh, 30000);

                /* initialize name cache */
                data.hosts.forEach(function (host) {
                    console.log("Checking cache for host "+host);
                    if (!(host in $scope.hosts)) {
                        console.log("Registering empty host "+host);
                        $scope.hosts[host] = {
                            name: host,
                            memory: 0,
                            willusememory: 0
                        };
                    }
                });

                data.vms.forEach(function (vm) {
                    console.log("Checking cache for vm "+vm);
                    if (!(vm in $scope.vms)) {
                        console.log("Registering empty vm "+vm);
                        $scope.vms[vm] = {
                            name: vm,
                            memory: 0,
                            memory_policy: {
                                guaranteed: 0
                            }
                        };
                    }
                });

                $scope.recomputeResources();
            });
        };

        $scope.recomputeResources = function() {
            $scope.result.hosts.forEach(function (host) {
                console.log("Resetting host "+host);
                $scope.hosts[host].willusememory = 0;
            });

            $scope.result.vms.forEach(function (vm) {
                console.log("Adding mem of vm "+vm+" to host "+$scope.result.vmToHost[vm]);
                if ($scope.result.vmToHost[vm] == null) return;
                $scope.hosts[$scope.result.vmToHost[vm]].willusememory += $scope.vms[vm].memory;
            });
        };

        $scope.verifyData = function() {
            verificationFactory.getResult($scope.result).success(function (data) {
                $timeout($scope.refresh, 30000);
                $scope.verification = data;
                if (data.hardScore < 0) {
                    $scope.valid = "Invalid data!";
                }
            });
        };

        $scope.refreshHostInfo = function() {
            hostsFactory.getResult().success(function (data) {
                data.host.forEach(function (host) {
                    console.log("Updating host "+host.id);
                    $scope.hosts[host.id] = host;
                });
                $scope.recomputeResources();
                $timeout($scope.refreshHostInfo, 15000);
            });
        };

        $scope.refreshVmInfo = function() {
            vmsFactory.getResult().success(function (data) {
                data.vm.forEach(function (vm) {
                    console.log("Updating vm "+vm.id);
                    $scope.vms[vm.id] = vm;
                });
                $scope.recomputeResources();
                $timeout($scope.refreshVmInfo, 15000);
            });
        };

        $scope.refresh();
        $scope.refreshHostInfo();
        $scope.refreshVmInfo();
    });

    resultPage.factory('hostsFactory', function ($http) {
        var factory = {};
        factory.getResult = function() {
            console.log("http://"+window.parent.location.host + "/ovirt-engine/api/hosts");
            return $http({method: 'GET',
                url: "http://"+window.parent.location.host + "/ovirt-engine/api/hosts",
                headers: {"Accept": "application/json"}});
        };
        return factory;
    });

    resultPage.factory('vmsFactory', function ($http) {
        var factory = {};
        factory.getResult = function() {
            return $http({method: 'GET',
                url: "http://"+window.parent.location.host + "/ovirt-engine/api/vms",
                headers: {"Accept": "application/json"}});
        };
        return factory;
    });

    resultPage.factory('resultFactory', function ($http) {
        var factory = {};
        factory.getResult = function() {
            return $http.get(cfg["baseurl"]+clusterid);
        };
        return factory;
    });

    resultPage.factory('verificationFactory', function ($http) {
        var factory = {};
        factory.getResult = function(data) {
            return $http.post(cfg["baseurl"]+clusterid+"/score", data);
        };
        return factory;
    });
</script>
</body>
</html>
<commit_msg>Differentiate between Start and Migrate in the result page<commit_after><!DOCTYPE html>
<html ng-app="resultPage">
<head>
    <script type='text/javascript'>
        function refreshPage()
        {
            window.location.reload(true);
        }
    </script>
    <script src="http://cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.min.js"></script>
    <script src="ovirtsdk.js"></script>

    <!-- Compatibility hacks
     according to https://docs.angularjs.org/guide/ie //-->
    <!--[if lte IE 7]>
    <script src="http://cdnjs.cloudflare.com/ajax/libs/json2/20130526/json2.min.js"></script>
    <![endif]-->
    <!--[if lte IE 8]>
    <script>
        document.createElement('ng-include');
        document.createElement('ng-pluralize');
        document.createElement('ng-view');

        // Optionally these for CSS
        document.createElement('ng:include');
        document.createElement('ng:pluralize');
        document.createElement('ng:view');
    </script>
    <![endif]-->
    <style>
        .host { font-weight: bold; }
        .ng-cloak, [ng-cloak].splash {
            display: block !important;
        }
        .splash {
            display: none !important;
        }
    </style>
</head>
<body>

<div class="splash">Loading..</div>

<div ng-cloak class="ng-cloak" ng-controller="resultController">

    <p>Status: {{ valid }}</p>

    <button ng-click="frozen=true">Freeze solution</button>
    <button ng-click="frozen=false">Unfreeze solution</button>

    <h2>VMs that should be started</h2>
    <table>
        <tr ng-repeat="vm in result.requestedVms">
            <td>{{ vms[vm].name }}</td>
            <td><button ng-click="cancel_start(vm);">Cancel</button></td>
        </tr>
    </table>

    <h2>Migration/Start steps</h2>
    <table>
        <tbody ng-repeat="step in result.migrations">
        <tr ng-repeat="(vm, host) in step">
            <td>{{ vms[vm].name }} &ndash;&gt; {{ hosts[host].name }}</td>
            <td ng-if="(result.vmToHost[vm] != result.currentVmToHost[vm]) && (result.currentVmToHost[vm] == null)"><button ng-click="start(vm, host)">start on {{ hosts[host].name }}</button></td>
            <td ng-if="(result.vmToHost[vm] != result.currentVmToHost[vm]) && (result.currentVmToHost[vm] != null)"><button ng-click="migrate(vm, host)">migrate to {{ hosts[host].name }}</button></td>
        </tr>
        </tbody>
    </table>

    <h2>Desired state</h2>
    <table>
        <tbody ng-repeat="(host, rvms) in result.hostToVms">
        <tr class="host">
            <td>{{ hosts[host].name }}</td>
            <td>{{ hosts[host].willusememory }} out of {{ hosts[host].memory }}</td>
            <td></td>
        </tr>
        <tr class="vm" ng-repeat="vm in rvms">
            <td>{{ vms[vm].name }}</td>
            <td>{{ vms[vm].memory_policy.guaranteed }} (max {{ vms[vm].memory }})</td>
            <td ng-if="(result.vmToHost[vm] != result.currentVmToHost[vm]) && (result.currentVmToHost[vm] == null)"><button ng-click="start(vm, result.vmToHost[vm])">start here</button></td>
            <td ng-if="(result.vmToHost[vm] != result.currentVmToHost[vm]) && (result.currentVmToHost[vm] != null)"><button ng-click="migrate(vm, result.vmToHost[vm])">migrate from {{ hosts[result.currentVmToHost[vm]].name }}</button></td>
            <td ng-if="result.vmToHost[vm] == result.currentVmToHost[vm]">&nbsp;</td>
        </tr>
        </tbody>
    </table>

    <!--
    <p>Raw data: {{ result }}</p>
    <p>Raw vm data: {{ vms }}</p>
    <p>Raw host data: {{ hosts }}</p>
    <p>Verification data: {{ verification }}</p>
    //-->
</div>

<script language="javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular.js"></script>
<script language="javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular.route.js"></script>
<script language="javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular.resource.js"></script>
<script language="javascript">
    var api = parent.pluginApi('oVirtOptimizer');
    var cfg = api.configObject();
    var clusterid = window.location.href.split("#")[1];
    var resultPage = angular.module('resultPage', []);

    resultPage.controller("resultController", function($scope, $timeout, $http, resultFactory,
                                                       verificationFactory, vmsFactory, hostsFactory) {
        $scope.result = {};
        $scope.verification = {};
        $scope.valid = "Waiting for data...";
        $scope.frozen = false;
        $scope.hosts = {};
        $scope.vms = {};

        $scope.migrate = function(vm, host) {
            console.log("Initiating migration of vm "+vm+" to host "+host);
            $http({
                method: 'POST',
                url: "http://"+window.parent.location.host + "/ovirt-engine/api/vms/" + vm + "/migrate",
                headers: {"Content-Type": "application/json",
                          "Accept": "application/json"},
                data: {host: {id: host},
                       async: true}
            }).success(function (data) {

            });
        };

        $scope.start = function(vm, host) {
            console.log("Initiating start of vm "+vm+" on host "+host);
            $http({
                method: 'POST',
                url: "http://"+window.parent.location.host + "/ovirt-engine/api/vms/" + vm + "/start",
                headers: {"Content-Type": "application/json",
                          "Accept": "application/json"},
                data: {
                    vm: {
                        placement_policy: {
                            host: {id: host}
                        }
                    },
                    async: true
                }
            }).success(function (data) {

            });
        };

        $scope.cancel_start = function(vm) {
            $http({
                method: 'POST',
                url: cfg["baseurl"]+clusterid+"/cancel",
                headers: {"Content-Type": "application/json",
                          "Accept": "application/json"},
                data: {id: vm}
            }).success(function (data) {
                $scope.valid = "Waiting for updated solution."
            });
        };

        $scope.refresh = function() {
            if ($scope.frozen) {
                $scope.verifyData();
            }
            else {
                $scope.refreshData();
            }
        };

        $scope.refreshData = function() {
            resultFactory.getResult().success(function (data) {
                $scope.result = data;
                $scope.valid = "Data received";
                $timeout($scope.refresh, 30000);

                /* initialize name cache */
                data.hosts.forEach(function (host) {
                    console.log("Checking cache for host "+host);
                    if (!(host in $scope.hosts)) {
                        console.log("Registering empty host "+host);
                        $scope.hosts[host] = {
                            name: host,
                            memory: 0,
                            willusememory: 0
                        };
                    }
                });

                data.vms.forEach(function (vm) {
                    console.log("Checking cache for vm "+vm);
                    if (!(vm in $scope.vms)) {
                        console.log("Registering empty vm "+vm);
                        $scope.vms[vm] = {
                            name: vm,
                            memory: 0,
                            memory_policy: {
                                guaranteed: 0
                            }
                        };
                    }
                });

                $scope.recomputeResources();
            });
        };

        $scope.recomputeResources = function() {
            $scope.result.hosts.forEach(function (host) {
                console.log("Resetting host "+host);
                $scope.hosts[host].willusememory = 0;
            });

            $scope.result.vms.forEach(function (vm) {
                console.log("Adding mem of vm "+vm+" to host "+$scope.result.vmToHost[vm]);
                if ($scope.result.vmToHost[vm] == null) return;
                $scope.hosts[$scope.result.vmToHost[vm]].willusememory += $scope.vms[vm].memory;
            });
        };

        $scope.verifyData = function() {
            verificationFactory.getResult($scope.result).success(function (data) {
                $timeout($scope.refresh, 30000);
                $scope.verification = data;
                if (data.hardScore < 0) {
                    $scope.valid = "Invalid data!";
                }
            });
        };

        $scope.refreshHostInfo = function() {
            hostsFactory.getResult().success(function (data) {
                data.host.forEach(function (host) {
                    console.log("Updating host "+host.id);
                    $scope.hosts[host.id] = host;
                });
                $scope.recomputeResources();
                $timeout($scope.refreshHostInfo, 15000);
            });
        };

        $scope.refreshVmInfo = function() {
            vmsFactory.getResult().success(function (data) {
                data.vm.forEach(function (vm) {
                    console.log("Updating vm "+vm.id);
                    $scope.vms[vm.id] = vm;
                });
                $scope.recomputeResources();
                $timeout($scope.refreshVmInfo, 15000);
            });
        };

        $scope.refresh();
        $scope.refreshHostInfo();
        $scope.refreshVmInfo();
    });

    resultPage.factory('hostsFactory', function ($http) {
        var factory = {};
        factory.getResult = function() {
            console.log("http://"+window.parent.location.host + "/ovirt-engine/api/hosts");
            return $http({method: 'GET',
                url: "http://"+window.parent.location.host + "/ovirt-engine/api/hosts",
                headers: {"Accept": "application/json"}});
        };
        return factory;
    });

    resultPage.factory('vmsFactory', function ($http) {
        var factory = {};
        factory.getResult = function() {
            return $http({method: 'GET',
                url: "http://"+window.parent.location.host + "/ovirt-engine/api/vms",
                headers: {"Accept": "application/json"}});
        };
        return factory;
    });

    resultPage.factory('resultFactory', function ($http) {
        var factory = {};
        factory.getResult = function() {
            return $http.get(cfg["baseurl"]+clusterid);
        };
        return factory;
    });

    resultPage.factory('verificationFactory', function ($http) {
        var factory = {};
        factory.getResult = function(data) {
            return $http.post(cfg["baseurl"]+clusterid+"/score", data);
        };
        return factory;
    });
</script>
</body>
</html>

{'fraction_non_alphanumeric': 0.16367940480216436, 'fraction_numerical': 0.005797381516015267, 'mean_word_length': 1.6706231454005935, 'pattern_counts': {'":': 14, '<': 219, '<?xml version=': 0, '>': 217, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1373269', 'n_tokens_mistral': 6113, 'n_tokens_neox': 5800, 'n_words': 1028}