Skip to content
Snippets Groups Projects
index.js 7.35 MiB
Newer Older
Hugo NOUTS's avatar
Hugo NOUTS committed
221001 221002 221003 221004 221005 221006 221007 221008 221009 221010 221011 221012 221013 221014 221015 221016 221017 221018 221019 221020 221021 221022 221023 221024 221025 221026 221027 221028 221029 221030 221031 221032 221033 221034 221035 221036 221037 221038 221039 221040 221041 221042 221043 221044 221045 221046 221047 221048 221049 221050 221051 221052 221053 221054 221055 221056 221057 221058 221059 221060 221061 221062 221063 221064 221065 221066 221067 221068 221069 221070 221071 221072 221073 221074 221075 221076 221077 221078 221079 221080 221081 221082 221083 221084 221085 221086 221087 221088 221089 221090 221091 221092 221093 221094 221095 221096 221097 221098 221099 221100 221101 221102 221103 221104 221105 221106 221107 221108 221109 221110 221111 221112 221113 221114 221115 221116 221117 221118 221119 221120 221121 221122 221123 221124 221125 221126 221127 221128 221129 221130 221131 221132 221133 221134 221135 221136 221137 221138 221139 221140 221141 221142 221143 221144 221145 221146 221147 221148 221149 221150 221151 221152 221153 221154 221155 221156 221157 221158 221159 221160 221161 221162 221163 221164 221165 221166 221167 221168 221169 221170 221171 221172 221173 221174 221175 221176 221177 221178 221179 221180 221181 221182 221183 221184 221185 221186 221187 221188 221189 221190 221191 221192 221193 221194 221195 221196 221197 221198 221199 221200 221201 221202 221203 221204 221205 221206 221207 221208 221209 221210 221211 221212 221213 221214 221215 221216 221217 221218 221219 221220 221221 221222 221223 221224 221225 221226 221227 221228 221229 221230 221231 221232 221233 221234 221235 221236 221237 221238 221239 221240 221241 221242 221243 221244 221245 221246 221247 221248 221249 221250 221251 221252 221253 221254 221255 221256 221257 221258 221259 221260 221261 221262
 */
async function formateDataForDoctype(data) {
  log('info', 'Formating data')
  return data.map(record => {
    let date = moment(record.d, 'YYYY/MM/DD h:mm:ss')
    return {
      load: record.v,
      year: parseInt(date.format('YYYY')),
      month: parseInt(date.format('M')),
      day: parseInt(date.format('D')),
      hour: parseInt(date.format('H')),
      minute: parseInt(date.format('m')),
    }
  })
}

/**
 * Format tag in order to be manipulated easly
 * @param {string} name
 * @returns {string} name
 */
function parseTags(name) {
  if (name.split(':')[1] !== undefined) {
    return name.split(':')[1]
  }
  return name
}

/**
 *
 * @param {string} value
 * @param {string} name
 * @returns {string|number} value
 */
function parseValue(value, name) {
  // Wh => KWh
  if (name === 'v') {
    return parseFloat((parseInt(value) / 1000).toFixed(2))
  }
  return value
}

module.exports = {
  parseSgeXmlData,
  parseSgeXmlTechnicalData,
  formateDataForDoctype,
  parseTags,
  parseValue,
}


/***/ }),
/* 1545 */
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {

// @ts-check
const { log } = __webpack_require__(1)

/**
 * Query SGE in order to get info
 * @param {number} pointId
 * @param {string} userLogin
 * @param {string} startDt
 * @param {string} endDt
 * @returns {string}
 */
function userMesureDetailles(
  pointId,
  userLogin,
  startDt,
  endDt,
  mesureType = 'ENERGIE',
  unit = 'EA'
) {
  log(
    'info',
    `Query data ${mesureType}/${unit} between ${startDt} and ${endDt}`
  )
  return `<?xml version='1.0' encoding='utf-8'?>
  <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
     xmlns:v2="http://www.enedis.fr/sge/b2b/services/consultationmesuresdetaillees/v2.0"
     xmlns:v1="http://www.enedis.fr/sge/b2b/technique/v1.0">
     <soapenv:Header/>
     <soapenv:Body>
        <v2:consulterMesuresDetaillees>
           <demande>
              <initiateurLogin>${userLogin}</initiateurLogin>
              <pointId>${pointId}</pointId>
              <mesuresTypeCode>${mesureType}</mesuresTypeCode>
              <grandeurPhysique>${unit}</grandeurPhysique>
              <soutirage>true</soutirage>
              <injection>false</injection>
              <dateDebut>${startDt}</dateDebut>
              <dateFin>${endDt}</dateFin>
              <mesuresCorrigees>false</mesuresCorrigees>
              <accordClient>true</accordClient>
           </demande>
        </v2:consulterMesuresDetaillees>
     </soapenv:Body>
  </soapenv:Envelope>
  `
}

/**
 * Get user technical data
 * @param {number} pointId
 * @param {string} userLogin
 * @returns {string}
 */
function userTechnicalData(pointId, userLogin) {
  log('info', `Query userMesureDetailles`)
  return `<?xml version='1.0' encoding='utf-8'?>
  <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
     xmlns:v2="http://www.enedis.fr/sge/b2b/services/consulterdonneestechniquescontractuelles/v1.0"
     xmlns:v1="http://www.enedis.fr/sge/b2b/technique/v1.0">
     <soapenv:Header/>
     <soapenv:Body>
        <v2:consulterDonneesTechniquesContractuelles>
           <pointId>${pointId}</pointId>
           <loginUtilisateur>${userLogin}</loginUtilisateur>
           <autorisationClient>true</autorisationClient>
        </v2:consulterDonneesTechniquesContractuelles>
     </soapenv:Body>
  </soapenv:Envelope>
  `
}

/**
 * Get user max power
 * @param {number} pointId
 * @param {string} userLogin
 * @param {string} startDt
 * @param {string} endDt
 * @returns {string}
 */
function userMaxPower(pointId, userLogin, startDt, endDt) {
  log('info', `Query userMesureDetailles`)
  return `<?xml version='1.0' encoding='utf-8'?>
  <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
     xmlns:v2="http://www.enedis.fr/sge/b2b/services/consultationmesuresdetaillees/v2.0"
     xmlns:v1="http://www.enedis.fr/sge/b2b/technique/v1.0">
      <soapenv:Header/>
      <soapenv:Body>
          <v2:consulterMesuresDetaillees>
              <demande>
                  <initiateurLogin>${userLogin}</initiateurLogin>
                  <pointId>${pointId}</pointId>
                  <mesuresTypeCode>PMAX</mesuresTypeCode>
                  <grandeurPhysique>PMA</grandeurPhysique>
                  <soutirage>true</soutirage>
                  <injection>false</injection>
                  <dateDebut>${startDt}</dateDebut>
                  <dateFin>${endDt}</dateFin>
                  <mesuresPas>P1D</mesuresPas>
                  <mesuresCorrigees>false</mesuresCorrigees>
                  <accordClient>true</accordClient>
              </demande>
          </v2:consulterMesuresDetaillees>
      </soapenv:Body>
  </soapenv:Envelope>
  `
}

module.exports = {
  userTechnicalData,
  userMaxPower,
  userMesureDetailles,
}


/***/ })
/******/ 	]);
/************************************************************************/
/******/ 	// The module cache
/******/ 	var __webpack_module_cache__ = {};
/******/ 	
/******/ 	// The require function
/******/ 	function __webpack_require__(moduleId) {
/******/ 		// Check if module is in cache
/******/ 		var cachedModule = __webpack_module_cache__[moduleId];
/******/ 		if (cachedModule !== undefined) {
/******/ 			return cachedModule.exports;
/******/ 		}
/******/ 		// Create a new module (and put it into the cache)
/******/ 		var module = __webpack_module_cache__[moduleId] = {
/******/ 			id: moduleId,
/******/ 			loaded: false,
/******/ 			exports: {}
/******/ 		};
/******/ 	
/******/ 		// Execute the module function
/******/ 		__webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/ 	
/******/ 		// Flag the module as loaded
/******/ 		module.loaded = true;
/******/ 	
/******/ 		// Return the exports of the module
/******/ 		return module.exports;
/******/ 	}
/******/ 	
/******/ 	// expose the module cache
/******/ 	__webpack_require__.c = __webpack_module_cache__;
/******/ 	
/************************************************************************/
/******/ 	/* webpack/runtime/compat get default export */
/******/ 	(() => {
/******/ 		// getDefaultExport function for compatibility with non-harmony modules
/******/ 		__webpack_require__.n = (module) => {
/******/ 			var getter = module && module.__esModule ?
/******/ 				() => (module['default']) :
/******/ 				() => (module);
/******/ 			__webpack_require__.d(getter, { a: getter });
/******/ 			return getter;
/******/ 		};
/******/ 	})();
/******/ 	
/******/ 	/* webpack/runtime/define property getters */
/******/ 	(() => {
/******/ 		// define getter functions for harmony exports
/******/ 		__webpack_require__.d = (exports, definition) => {
/******/ 			for(var key in definition) {
/******/ 				if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
/******/ 					Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
/******/ 				}
/******/ 			}
/******/ 		};
/******/ 	})();
/******/ 	
/******/ 	/* webpack/runtime/hasOwnProperty shorthand */
/******/ 	(() => {
/******/ 		__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
/******/ 	})();
/******/ 	
/******/ 	/* webpack/runtime/make namespace object */
/******/ 	(() => {
/******/ 		// define __esModule on exports
/******/ 		__webpack_require__.r = (exports) => {
/******/ 			if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ 				Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ 			}
/******/ 			Object.defineProperty(exports, '__esModule', { value: true });
/******/ 		};
/******/ 	})();
/******/ 	
/******/ 	/* webpack/runtime/node module decorator */
/******/ 	(() => {
/******/ 		__webpack_require__.nmd = (module) => {
/******/ 			module.paths = [];
/******/ 			if (!module.children) module.children = [];
/******/ 			return module;
/******/ 		};
/******/ 	})();
/******/ 	
/************************************************************************/
/******/ 	
/******/ 	// module cache are used so entry inlining is disabled
/******/ 	// startup
/******/ 	// Load entry module and return exports
/******/ 	var __webpack_exports__ = __webpack_require__(__webpack_require__.s = 0);
/******/ 	
/******/ })()
;