<commit_before>const config = require('config');

const BASE_URL = config.get('gfw.flagshipUrl');
const GADM36_DATASET = config.get('layers.gadm36BoundariesDataset');
const GADM36_LAYER_1 = config.get('layers.gadm36BoundariesLayer1');
const GADM36_LAYER_2 = config.get('layers.gadm36BoundariesLayer2');

const qs = require('qs');
const moment = require('moment');

class AlertUrlService {

    static generate(subscription, layer, begin, end) {
        let pathname = `aoi/${subscription.id}`;

        if (subscription.params.iso && subscription.params.iso.country) {
            const { country, region, subregion } = subscription.params.iso;
            pathname = `country/${country}${region ? `/${region}` : ''}${subregion ? `/${subregion}` : ''}`;
        }

        if (subscription.params.wdpaid) {
            pathname = `wdpa/${subscription.params.wdpaid}`;
        }

        if (subscription.params.use && subscription.params.useid) {
            pathname = `use/${subscription.params.use}/${subscription.params.useid}`;
        }

        const diffInDays = moment(begin).diff(moment(end), 'days');

        const queryForUrl = {
            lang: subscription.language || 'en',
            map: {
                canBound: true,
                ...layer.datasetId && layer.layerId && {
                    datasets: [
                        {
                            dataset: layer.datasetId,
                            layers: [layer.layerId],
                            ...layer.slug === 'viirs-active-fires' && {
                                params: {
                                    number_of_days: diffInDays <= 7 ? diffInDays : 7
                                }
                            },
                            ...layer.slug !== 'viirs-active-fires' && {
                                timelineParams: {
                                    startDate: moment(begin).format('YYYY-MM-DD'),
                                    endDate: moment(end).format('YYYY-MM-DD'),
                                    trimEndDate: moment(end).format('YYYY-MM-DD')
                                }
                            }
                        },
                        {
                            dataset: GADM36_DATASET,
                            layers: [GADM36_LAYER_1, GADM36_LAYER_2]
                        }
                    ]
                }
            },
            mainMap: {
                showAnalysis: true
            }
        };

        return `${BASE_URL}/map/${pathname}?${qs.stringify(queryForUrl)}`;
    }<commit_msg>encode map state for alery service url<commit_after>const config = require('config');

const BASE_URL = config.get('gfw.flagshipUrl');
const GADM36_DATASET = config.get('layers.gadm36BoundariesDataset');
const GADM36_LAYER_1 = config.get('layers.gadm36BoundariesLayer1');
const GADM36_LAYER_2 = config.get('layers.gadm36BoundariesLayer2');

const qs = require('qs');
const moment = require('moment');

const endocdeStateForUrl = state => btoa(JSON.stringify(state));

class AlertUrlService {

    static generate(subscription, layer, begin, end) {
        let pathname = `aoi/${subscription.id}`;

        if (subscription.params.iso && subscription.params.iso.country) {
            const { country, region, subregion } = subscription.params.iso;
            pathname = `country/${country}${region ? `/${region}` : ''}${subregion ? `/${subregion}` : ''}`;
        }

        if (subscription.params.wdpaid) {
            pathname = `wdpa/${subscription.params.wdpaid}`;
        }

        if (subscription.params.use && subscription.params.useid) {
            pathname = `use/${subscription.params.use}/${subscription.params.useid}`;
        }

        const diffInDays = moment(begin).diff(moment(end), 'days');

        const queryForUrl = {
            lang: subscription.language || 'en',
            map: endocdeStateForUrl({
                canBound: true,
                ...layer.datasetId && layer.layerId && {
                    datasets: [
                        {
                            dataset: layer.datasetId,
                            layers: [layer.layerId],
                            ...layer.slug === 'viirs-active-fires' && {
                                params: {
                                    number_of_days: diffInDays <= 7 ? diffInDays : 7
                                }
                            },
                            ...layer.slug !== 'viirs-active-fires' && {
                                timelineParams: {
                                    startDate: moment(begin).format('YYYY-MM-DD'),
                                    endDate: moment(end).format('YYYY-MM-DD'),
                                    trimEndDate: moment(end).format('YYYY-MM-DD')
                                }
                            }
                        },
                        {
                            dataset: GADM36_DATASET,
                            layers: [GADM36_LAYER_1, GADM36_LAYER_2]
                        }
                    ]
                }
            }),
            mainMap: endocdeStateForUrl({
                showAnalysis: true
            })
        };

        return `${BASE_URL}/map/${pathname}?${qs.stringify(queryForUrl)}`;
    }
{'fraction_non_alphanumeric': 0.12403538490495013, 'fraction_numerical': 0.009787314135140222, 'mean_word_length': 1.3154684095860567, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2213602', 'n_tokens_mistral': 1442, 'n_tokens_neox': 1400, 'n_words': 210}