<commit_before>package CCNQ::Provisioning;
# Copyright (C) 2009  <NAME>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 3
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

use strict; use warnings;

use CCNQ::Install;

# This is a "virtual cluster name" -- no such cluster is defined in
# the (DNS) configuration, but the MUC room is used as a rendez-vous
# point to propagate the data.
use constant PROVISIONING_CLUSTER_NAME => 'provisioning';
use constant::defer provisioning_cluster_jid => sub {
  CCNQ::Install::make_muc_jid(PROVISIONING_CLUSTER_NAME)
};

use constant::defer provisioning_uri => sub {
  CCNQ::Install::couchdb_local_uri;
};
use constant provisioning_db => 'provisioning';

use constant js_report_by_account => <<'JAVASCRIPT';
  function (doc) {
    emit([doc.account,doc.account_sub,doc.profile,doc.type,doc._id],null);
  }
JAVASCRIPT

use constant js_report_by_endpoint => <<'JAVASCRIPT';
  function (doc) {
    if(doc.endpoint) {
      emit([doc.account,doc.endpoint,doc.profile,doc.type,doc._id],null);
    }
  }
JAVASCRIPT

use constant js_report_by_location => <<'JAVASCRIPT';
  function (doc) {
    if(doc.location) {
      emit([doc.account,doc.location,doc.profile,doc.type,doc._id],null);
    }
  }
JAVASCRIPT

use constant js_report_numbers => <<'JAVASCRIPT';
  function (doc){
    if(doc.profile == 'number') {
      emit([doc.account,doc.number],null)
    }
  }
JAVASCRIPT

use constant js_report_endpoints => <<'JAVASCRIPT';
  function (doc){
    if(doc.profile == 'endpoint') {
      emit([doc.account,doc.endpoint],null)
    }
  }
JAVASCRIPT

use constant js_report_locations => <<'JAVASCRIPT';
  function (doc){
    if(doc.profile == 'location') {
      emit([doc.account,doc.location],null)
    }
  }
JAVASCRIPT

use constant js_report_all_numbers => <<'JAVASCRIPT';
  function (doc){
    if(doc.profile == 'number') {
      emit([doc.number],null)
    }
  }
JAVASCRIPT

use constant provisioning_designs => {
  report => {
    language => 'javascript',
    views    => {
      account => {
        map => js_report_by_account,
        # no reduce function
      },
      endpoint_all => {
        map => js_report_by_endpoint,
        # no reduce function
      },
      location_all => {
        map => js_report_by_location,
        # no reduce function
      },
      number => {
        map => js_report_numbers,
        # no reduce function
      },
      endpoint => {
        map => js_report_endpoints,
        # no reduce function
      },
      location => {
        map => js_report_locations,
        # no reduce function
      },
      all_numbers => {
        map => js_report_all_numbers,
        # no reduce function
      },
    },
  },
};

use CCNQ::AE;
use CCNQ::CouchDB;

sub install {
  return CCNQ::CouchDB::install(provisioning_uri, provisioning_db, provisioning_designs);
}

sub provisioning_update {
  my ($params) = @_;
  exists($params->{type}) or
    return CCNQ::AE::croak_cv("No type specified in ".CCNQ::AE::pp($params));
  return CCNQ::CouchDB::update_cv(provisioning_uri,provisioning_db,$params);
}

sub provisioning_delete {
  my ($params) = @_;<commit_msg>New provisioning view for daily count of DIDs, endpoints, etc. for billing<commit_after>package CCNQ::Provisioning;
# Copyright (C) 2009  <NAME>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 3
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

use strict; use warnings;

use CCNQ::Install;

# This is a "virtual cluster name" -- no such cluster is defined in
# the (DNS) configuration, but the MUC room is used as a rendez-vous
# point to propagate the data.
use constant PROVISIONING_CLUSTER_NAME => 'provisioning';
use constant::defer provisioning_cluster_jid => sub {
  CCNQ::Install::make_muc_jid(PROVISIONING_CLUSTER_NAME)
};

use constant::defer provisioning_uri => sub {
  CCNQ::Install::couchdb_local_uri;
};
use constant provisioning_db => 'provisioning';

use constant js_report_by_account => <<'JAVASCRIPT';
  function (doc) {
    emit([doc.account,doc.account_sub,doc.profile,doc.type,doc._id],null);
  }
JAVASCRIPT

use constant js_report_by_endpoint => <<'JAVASCRIPT';
  function (doc) {
    if(doc.endpoint) {
      emit([doc.account,doc.endpoint,doc.profile,doc.type,doc._id],null);
    }
  }
JAVASCRIPT

use constant js_report_by_location => <<'JAVASCRIPT';
  function (doc) {
    if(doc.location) {
      emit([doc.account,doc.location,doc.profile,doc.type,doc._id],null);
    }
  }
JAVASCRIPT

use constant js_report_numbers => <<'JAVASCRIPT';
  function (doc){
    if(doc.profile == 'number') {
      emit([doc.account,doc.number],null)
    }
  }
JAVASCRIPT

use constant js_report_endpoints => <<'JAVASCRIPT';
  function (doc){
    if(doc.profile == 'endpoint') {
      emit([doc.account,doc.endpoint],null)
    }
  }
JAVASCRIPT

use constant js_report_locations => <<'JAVASCRIPT';
  function (doc){
    if(doc.profile == 'location') {
      emit([doc.account,doc.location],null)
    }
  }
JAVASCRIPT

use constant js_report_all_numbers => <<'JAVASCRIPT';
  function (doc){
    if(doc.profile == 'number') {
      emit([doc.number],null)
    }
  }
JAVASCRIPT

use constant js_report_count => <<'JAVASCRIPT';
  function (doc){
    emit([doc.account,doc.account_sub,doc.profile,doc.type],1);
  }
JAVASCRIPT

use constant js_reduce_sum <<'JAVASCRIPT';
  function(keys, values, rereduce) {
    var sum = 0;
    for(var i in values) {
      sum += values[i];
    }
    return sum;
  }
JAVASCRIPT

use constant provisioning_designs => {
  report => {
    language => 'javascript',
    views    => {
      account => {
        map => js_report_by_account,
        # no reduce function
      },
      endpoint_all => {
        map => js_report_by_endpoint,
        # no reduce function
      },
      location_all => {
        map => js_report_by_location,
        # no reduce function
      },
      number => {
        map => js_report_numbers,
        # no reduce function
      },
      endpoint => {
        map => js_report_endpoints,
        # no reduce function
      },
      location => {
        map => js_report_locations,
        # no reduce function
      },
      all_numbers => {
        map => js_report_all_numbers,
        # no reduce function
      },
      count => {
        map => js_report_count,
        reduce => js_reduce_sum,
      }
    },
  },
};

use CCNQ::AE;
use CCNQ::CouchDB;

sub install {
  return CCNQ::CouchDB::install(provisioning_uri, provisioning_db, provisioning_designs);
}

sub provisioning_update {
  my ($params) = @_;
  exists($params->{type}) or
    return CCNQ::AE::croak_cv("No type specified in ".CCNQ::AE::pp($params));
  return CCNQ::CouchDB::update_cv(provisioning_uri,provisioning_db,$params);
}

sub provisioning_delete {
  my ($params) = @_;
{'fraction_non_alphanumeric': 0.12178585134962262, 'fraction_numerical': 0.0015351157733145709, 'mean_word_length': 3.392134831460674, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 71, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '917550', 'n_tokens_mistral': 2619, 'n_tokens_neox': 2518, 'n_words': 645}