<commit_before>'use strict';

const _ = require('lodash'),
    Promise = require('bluebird'),
    API = require('./api'),
    InstanceModel = require('../../proxies/manager/instance.model'),
    winston = require('winston');


module.exports = class ProviderDigitalOcean {
    constructor(config, instancePort) {
        if (!config || !instancePort) {
            throw new Error('[ProviderDigitalOcean] should be instanced with config and instancePort');
        }

        this._config = config;
        this._instancePort = instancePort;

        this.name = 'digitalocean';

        this._imagePromise = void 0;
        this._sshKeyPromise = void 0;

        this._api = new API(this._config.token);
    }


    static get ST_NEW() {
        return 'new';
    }

    static get ST_ACTIVE() {
        return 'active';
    }

    static get ST_OFF() {
        return 'off';
    }

    static get ST_ARCHIVE() {
        return 'archive';
    }


    get models() {
        const self = this;

        return self._api.getAllDroplets()
            .then(summarizeInfo)
            .then(excludeArchive)
            .then(excludeOutscope)
            .then(convertToModel);


        ////////////


        function summarizeInfo(droplets) {
            return _.map(droplets, (droplet) => ({
                id: droplet.id,
                status: droplet.status,
                ip: droplet.networks.v4[0].ip_address,
                name: droplet.name,
            }));
        }

        function excludeArchive(droplets) {
            return _.filter(droplets, (droplet) => droplet.status !== ProviderDigitalOcean.ST_ARCHIVE);
        }

        function excludeOutscope(droplets) {
            return _.filter(droplets,
                (droplet) => droplet.name && droplet.name.indexOf(self._config.name) === 0
            );
        }

        function convertToModel(droplets) {
            return _.map(droplets, (droplet) => new InstanceModel(
                droplet.id,
                self.name,
                convertStatus(droplet.status),
                buildAddress(droplet.ip),
                droplet
            ));


            ////////////

            function buildAddress(ip) {
                if (!ip) {
                    return;<commit_msg>fix(digitalocean): convert droplet numerical ID to string<commit_after>'use strict';

const _ = require('lodash'),
    Promise = require('bluebird'),
    API = require('./api'),
    InstanceModel = require('../../proxies/manager/instance.model'),
    winston = require('winston');


module.exports = class ProviderDigitalOcean {
    constructor(config, instancePort) {
        if (!config || !instancePort) {
            throw new Error('[ProviderDigitalOcean] should be instanced with config and instancePort');
        }

        this._config = config;
        this._instancePort = instancePort;

        this.name = 'digitalocean';

        this._imagePromise = void 0;
        this._sshKeyPromise = void 0;

        this._api = new API(this._config.token);
    }


    static get ST_NEW() {
        return 'new';
    }

    static get ST_ACTIVE() {
        return 'active';
    }

    static get ST_OFF() {
        return 'off';
    }

    static get ST_ARCHIVE() {
        return 'archive';
    }


    get models() {
        const self = this;

        return self._api.getAllDroplets()
            .then(summarizeInfo)
            .then(excludeArchive)
            .then(excludeOutscope)
            .then(convertToModel);


        ////////////


        function summarizeInfo(droplets) {
            return _.map(droplets, (droplet) => ({
                id: droplet.id.toString(),
                status: droplet.status,
                ip: droplet.networks.v4[0].ip_address,
                name: droplet.name,
            }));
        }

        function excludeArchive(droplets) {
            return _.filter(droplets, (droplet) => droplet.status !== ProviderDigitalOcean.ST_ARCHIVE);
        }

        function excludeOutscope(droplets) {
            return _.filter(droplets,
                (droplet) => droplet.name && droplet.name.indexOf(self._config.name) === 0
            );
        }

        function convertToModel(droplets) {
            return _.map(droplets, (droplet) => new InstanceModel(
                droplet.id,
                self.name,
                convertStatus(droplet.status),
                buildAddress(droplet.ip),
                droplet
            ));


            ////////////

            function buildAddress(ip) {
                if (!ip) {
                    return;
{'fraction_non_alphanumeric': 0.12220047836486192, 'fraction_numerical': 0.0021743857360295715, 'mean_word_length': 1.6406429391504018, 'pattern_counts': {'":': 0, '<': 3, '<?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': '4109478', 'n_tokens_mistral': 1326, 'n_tokens_neox': 1192, 'n_words': 247}