Cours:BUTiot DetectAnomalies1 : Différence entre versions

De troyesGEII
Aller à : navigation, rechercher
Ligne 26 : Ligne 26 :
 
</source>
 
</source>
 
* En dehors des séances
 
* En dehors des séances
** vous pouvez exécuter le code suivant qui synthétise et publie les même données que pendant les séances. {{boîte déroulante début|Fichier code Node.js générant des anomalies}} <pre> 'use strict';function _0x5d55(_0x8675fd,_0x1e9d33){const _0x3baba1=_0x3bab();return _0x5d55=function(_0x5d5539,_0x2888dd){_0x5d5539=_0x5d5539-0x12f;let _0x2ba093=_0x3baba1[_0x5d5539];return _0x2ba093;},_0x5d55(_0x8675fd,_0x1e9d33);}const _0x7dd4cc=_0x5d55;(function(_0x987f03,_0x16d8e5){const _0x15a5aa=_0x5d55,_0x2b996c=_0x987f03();while(!![]){try{const _0x190db1=-parseInt(_0x15a5aa(0x146))/0x1*(parseInt(_0x15a5aa(0x150))/0x2)+-parseInt(_0x15a5aa(0x14e))/0x3+parseInt(_0x15a5aa(0x14d))/0x4+-parseInt(_0x15a5aa(0x142))/0x5*(parseInt(_0x15a5aa(0x12f))/0x6)+parseInt(_0x15a5aa(0x148))/0x7+parseInt(_0x15a5aa(0x14c))/0x8*(-parseInt(_0x15a5aa(0x14f))/0x9)+parseInt(_0x15a5aa(0x13f))/0xa*(parseInt(_0x15a5aa(0x134))/0xb);if(_0x190db1===_0x16d8e5)break;else _0x2b996c['push'](_0x2b996c['shift']());}catch(_0x536536){_0x2b996c['push'](_0x2b996c['shift']());}}}(_0x3bab,0xe6449));var args=process['argv'],ip=args[0x2]||_0x7dd4cc(0x140);const mqtt=require(_0x7dd4cc(0x139)),client=mqtt['connect'](_0x7dd4cc(0x13a)+ip);function _0x3bab(){const _0x49cede=['random','545281DJmSye','publish','pas\x20d\x27anomalie','stdout','data/d1anomalie','mqtt','mqtt://','data/d2','data/d1','data/d3','getTime','390rCKsDw','10.98.35.245','toString','35SyhjjH','log','floor','write','367IYSKuo','data/d3anomalie','9046877bzYsKj','data/d2anomalie','cos','anomalie','32784irZcjq','5497548KBtnIc','5419746gOxulr','1215laBSkQ','1222cZXtFj','919578GfuToK','connect','data/d4anomalie','data/d4'];_0x3bab=function(){return _0x49cede;};return _0x3bab();}client['on'](_0x7dd4cc(0x130),()=>{setInterval(gen_and_publish_d1,0xc8),setInterval(gen_and_publish_d2,0xc8),setInterval(gen_and_publish_d3,0xc8),setInterval(gen_and_publish_d4,0xc8),setInterval(gen_and_publish_d5,0xc8);});function debug(_0x3a0710,_0x5f1366){const _0x1a89fb=_0x7dd4cc;process[_0x1a89fb(0x137)][_0x1a89fb(0x145)](_0x3a0710+'\x20:\x20'),console[_0x1a89fb(0x143)](_0x5f1366);}function gen_and_publish_d1(){const _0x8fbfa3=_0x7dd4cc;let _0xec4d52=0x5,_0x47477d=Math[_0x8fbfa3(0x133)]()*_0xec4d52-_0xec4d52/0x2,_0x567150=0x0;getRandomInt(0x1e)==0x0?(_0x567150=getRandomInt(0x64)-0x32,client[_0x8fbfa3(0x135)](_0x8fbfa3(0x138),'anomalie')):client[_0x8fbfa3(0x135)](_0x8fbfa3(0x138),_0x8fbfa3(0x136));let _0x4f17d3=0x64+_0x47477d+_0x567150;debug(_0x8fbfa3(0x13c),_0x4f17d3),client['publish'](_0x8fbfa3(0x13c),_0x4f17d3[_0x8fbfa3(0x141)]());}function gen_and_publish_d2(){const _0x3f9672=_0x7dd4cc;let _0x5aec53=0x28,_0x159ad3=Math[_0x3f9672(0x133)]()*_0x5aec53-_0x5aec53/0x2,_0x4e50fa=0x0;getRandomInt(0x1e)==0x0?(_0x4e50fa=getRandomInt(0x64)-0x32,client[_0x3f9672(0x135)](_0x3f9672(0x149),'anomalie')):client[_0x3f9672(0x135)](_0x3f9672(0x149),_0x3f9672(0x136));let _0x11f925=0x64+_0x159ad3+_0x4e50fa;debug(_0x3f9672(0x13c),_0x11f925),client['publish'](_0x3f9672(0x13b),_0x11f925[_0x3f9672(0x141)]());}function gen_and_publish_d3(){const _0x573254=_0x7dd4cc;let _0x8d8d62=new Date()['getTime']()/0x3e8,_0x4a8868=Math[_0x573254(0x14a)](_0x8d8d62/0xa),_0x202bcf=0x2,_0x5d5965=0x0;getRandomInt(0xa)==0x0?(_0x5d5965=Math['random']()*_0x202bcf-_0x202bcf/0x2,client['publish'](_0x573254(0x147),_0x573254(0x14b))):client['publish'](_0x573254(0x147),_0x573254(0x136));let _0x5b9994=_0x4a8868+_0x5d5965;client[_0x573254(0x135)](_0x573254(0x13d),_0x5b9994[_0x573254(0x141)]());}function gen_and_publish_d4(){const _0x21b4a5=_0x7dd4cc;let _0x116799=new Date()[_0x21b4a5(0x13e)]()/0x3e8,_0x20fa8c=Math[_0x21b4a5(0x14a)](_0x116799/0xa),_0x3aec42=0x2,_0x1d822f=0x0;getRandomInt(0xa)==0x0?(_0x1d822f=Math['random']()*_0x3aec42-_0x3aec42/0x2,client[_0x21b4a5(0x135)](_0x21b4a5(0x131),_0x21b4a5(0x14b))):client[_0x21b4a5(0x135)](_0x21b4a5(0x131),_0x21b4a5(0x136));let _0x2e135f=0x1,_0x470ac5=Math[_0x21b4a5(0x133)]()*_0x2e135f-_0x2e135f/0x2,_0x481fef=_0x20fa8c+_0x1d822f+_0x470ac5;client[_0x21b4a5(0x135)](_0x21b4a5(0x132),_0x481fef[_0x21b4a5(0x141)]());}function gen_and_publish_d5(){const _0x137427=_0x7dd4cc;let _0x21f1a4=new Date()[_0x137427(0x13e)]()/0x3e8,_0x511c5a=Math[_0x137427(0x14a)](_0x21f1a4/0x14),_0x3b04c9=0x2,_0x170b2e=Math[_0x137427(0x133)]()*_0x3b04c9-_0x3b04c9/0x2,_0x39bf3f=_0x170b2e+_0x511c5a;client[_0x137427(0x135)]('data/d5',_0x39bf3f[_0x137427(0x141)]());}function getRandomInt(_0xe5adb9){const _0x2e59c2=_0x7dd4cc;return Math[_0x2e59c2(0x144)](Math[_0x2e59c2(0x133)]()*_0xe5adb9);}
+
** vous pouvez exécuter le code suivant qui synthétise et publie les même données que pendant les séances.
 +
{{boîte déroulante début|Fichier code Node.js générant des anomalies}} <pre> 'use strict';function _0x5d55(_0x8675fd,_0x1e9d33){const _0x3baba1=_0x3bab();return _0x5d55=function(_0x5d5539,_0x2888dd){_0x5d5539=_0x5d5539-0x12f;let _0x2ba093=_0x3baba1[_0x5d5539];return _0x2ba093;},_0x5d55(_0x8675fd,_0x1e9d33);}const _0x7dd4cc=_0x5d55;(function(_0x987f03,_0x16d8e5){const _0x15a5aa=_0x5d55,_0x2b996c=_0x987f03();while(!![]){try{const _0x190db1=-parseInt(_0x15a5aa(0x146))/0x1*(parseInt(_0x15a5aa(0x150))/0x2)+-parseInt(_0x15a5aa(0x14e))/0x3+parseInt(_0x15a5aa(0x14d))/0x4+-parseInt(_0x15a5aa(0x142))/0x5*(parseInt(_0x15a5aa(0x12f))/0x6)+parseInt(_0x15a5aa(0x148))/0x7+parseInt(_0x15a5aa(0x14c))/0x8*(-parseInt(_0x15a5aa(0x14f))/0x9)+parseInt(_0x15a5aa(0x13f))/0xa*(parseInt(_0x15a5aa(0x134))/0xb);if(_0x190db1===_0x16d8e5)break;else _0x2b996c['push'](_0x2b996c['shift']());}catch(_0x536536){_0x2b996c['push'](_0x2b996c['shift']());}}}(_0x3bab,0xe6449));var args=process['argv'],ip=args[0x2]||_0x7dd4cc(0x140);const mqtt=require(_0x7dd4cc(0x139)),client=mqtt['connect'](_0x7dd4cc(0x13a)+ip);function _0x3bab(){const _0x49cede=['random','545281DJmSye','publish','pas\x20d\x27anomalie','stdout','data/d1anomalie','mqtt','mqtt://','data/d2','data/d1','data/d3','getTime','390rCKsDw','10.98.35.245','toString','35SyhjjH','log','floor','write','367IYSKuo','data/d3anomalie','9046877bzYsKj','data/d2anomalie','cos','anomalie','32784irZcjq','5497548KBtnIc','5419746gOxulr','1215laBSkQ','1222cZXtFj','919578GfuToK','connect','data/d4anomalie','data/d4'];_0x3bab=function(){return _0x49cede;};return _0x3bab();}client['on'](_0x7dd4cc(0x130),()=>{setInterval(gen_and_publish_d1,0xc8),setInterval(gen_and_publish_d2,0xc8),setInterval(gen_and_publish_d3,0xc8),setInterval(gen_and_publish_d4,0xc8),setInterval(gen_and_publish_d5,0xc8);});function debug(_0x3a0710,_0x5f1366){const _0x1a89fb=_0x7dd4cc;process[_0x1a89fb(0x137)][_0x1a89fb(0x145)](_0x3a0710+'\x20:\x20'),console[_0x1a89fb(0x143)](_0x5f1366);}function gen_and_publish_d1(){const _0x8fbfa3=_0x7dd4cc;let _0xec4d52=0x5,_0x47477d=Math[_0x8fbfa3(0x133)]()*_0xec4d52-_0xec4d52/0x2,_0x567150=0x0;getRandomInt(0x1e)==0x0?(_0x567150=getRandomInt(0x64)-0x32,client[_0x8fbfa3(0x135)](_0x8fbfa3(0x138),'anomalie')):client[_0x8fbfa3(0x135)](_0x8fbfa3(0x138),_0x8fbfa3(0x136));let _0x4f17d3=0x64+_0x47477d+_0x567150;debug(_0x8fbfa3(0x13c),_0x4f17d3),client['publish'](_0x8fbfa3(0x13c),_0x4f17d3[_0x8fbfa3(0x141)]());}function gen_and_publish_d2(){const _0x3f9672=_0x7dd4cc;let _0x5aec53=0x28,_0x159ad3=Math[_0x3f9672(0x133)]()*_0x5aec53-_0x5aec53/0x2,_0x4e50fa=0x0;getRandomInt(0x1e)==0x0?(_0x4e50fa=getRandomInt(0x64)-0x32,client[_0x3f9672(0x135)](_0x3f9672(0x149),'anomalie')):client[_0x3f9672(0x135)](_0x3f9672(0x149),_0x3f9672(0x136));let _0x11f925=0x64+_0x159ad3+_0x4e50fa;debug(_0x3f9672(0x13c),_0x11f925),client['publish'](_0x3f9672(0x13b),_0x11f925[_0x3f9672(0x141)]());}function gen_and_publish_d3(){const _0x573254=_0x7dd4cc;let _0x8d8d62=new Date()['getTime']()/0x3e8,_0x4a8868=Math[_0x573254(0x14a)](_0x8d8d62/0xa),_0x202bcf=0x2,_0x5d5965=0x0;getRandomInt(0xa)==0x0?(_0x5d5965=Math['random']()*_0x202bcf-_0x202bcf/0x2,client['publish'](_0x573254(0x147),_0x573254(0x14b))):client['publish'](_0x573254(0x147),_0x573254(0x136));let _0x5b9994=_0x4a8868+_0x5d5965;client[_0x573254(0x135)](_0x573254(0x13d),_0x5b9994[_0x573254(0x141)]());}function gen_and_publish_d4(){const _0x21b4a5=_0x7dd4cc;let _0x116799=new Date()[_0x21b4a5(0x13e)]()/0x3e8,_0x20fa8c=Math[_0x21b4a5(0x14a)](_0x116799/0xa),_0x3aec42=0x2,_0x1d822f=0x0;getRandomInt(0xa)==0x0?(_0x1d822f=Math['random']()*_0x3aec42-_0x3aec42/0x2,client[_0x21b4a5(0x135)](_0x21b4a5(0x131),_0x21b4a5(0x14b))):client[_0x21b4a5(0x135)](_0x21b4a5(0x131),_0x21b4a5(0x136));let _0x2e135f=0x1,_0x470ac5=Math[_0x21b4a5(0x133)]()*_0x2e135f-_0x2e135f/0x2,_0x481fef=_0x20fa8c+_0x1d822f+_0x470ac5;client[_0x21b4a5(0x135)](_0x21b4a5(0x132),_0x481fef[_0x21b4a5(0x141)]());}function gen_and_publish_d5(){const _0x137427=_0x7dd4cc;let _0x21f1a4=new Date()[_0x137427(0x13e)]()/0x3e8,_0x511c5a=Math[_0x137427(0x14a)](_0x21f1a4/0x14),_0x3b04c9=0x2,_0x170b2e=Math[_0x137427(0x133)]()*_0x3b04c9-_0x3b04c9/0x2,_0x39bf3f=_0x170b2e+_0x511c5a;client[_0x137427(0x135)]('data/d5',_0x39bf3f[_0x137427(0x141)]());}function getRandomInt(_0xe5adb9){const _0x2e59c2=_0x7dd4cc;return Math[_0x2e59c2(0x144)](Math[_0x2e59c2(0x133)]()*_0xe5adb9);}
 
</pre>
 
</pre>
 
{{boîte déroulante fin}}
 
{{boîte déroulante fin}}
** Sauvegarder ce code dans un fichier (par exemple <code>gen_anomalie.js</code> et l'exécuter de la façon suivante <source>
+
Sauvegarder ce code dans un fichier (par exemple <code>gen_anomalie.js</code> et l'exécuter de la façon suivante <source>
 
node gen_anomalie.js
 
node gen_anomalie.js
 
</source> pour publier sur le broker IUT
 
</source> pour publier sur le broker IUT

Version du 5 décembre 2023 à 08:55

Retour à la page du cours

Node.js : Détection temps réel d'anomalies de type données aberrantes

Le travail de cette étape va consister à détecter des anomalies de type valeurs aberrantes en temps réel.


Topics de données

  • Pendant les séances :
    • Publiées sur le broker IUT (10.98.35.245) sur les topics :
      data/d1
      data/d2
      data/d3
      data/d4
      data/d5
    • À des fins de contrôle et de validation de vos détecteurs les topics suivants contiennent le message pas d'anomalie ou anomalie selon qu'une anomalie est présente ou non sur le topic associé :
      data/d1anomalie
      data/d2anomalie
      data/d3anomalie
      data/d4anomalie
      data/d5anomalie
  • En dehors des séances
    • vous pouvez exécuter le code suivant qui synthétise et publie les même données que pendant les séances.

Fichier code Node.js générant des anomalies

 'use strict';function _0x5d55(_0x8675fd,_0x1e9d33){const _0x3baba1=_0x3bab();return _0x5d55=function(_0x5d5539,_0x2888dd){_0x5d5539=_0x5d5539-0x12f;let _0x2ba093=_0x3baba1[_0x5d5539];return _0x2ba093;},_0x5d55(_0x8675fd,_0x1e9d33);}const _0x7dd4cc=_0x5d55;(function(_0x987f03,_0x16d8e5){const _0x15a5aa=_0x5d55,_0x2b996c=_0x987f03();while(!![]){try{const _0x190db1=-parseInt(_0x15a5aa(0x146))/0x1*(parseInt(_0x15a5aa(0x150))/0x2)+-parseInt(_0x15a5aa(0x14e))/0x3+parseInt(_0x15a5aa(0x14d))/0x4+-parseInt(_0x15a5aa(0x142))/0x5*(parseInt(_0x15a5aa(0x12f))/0x6)+parseInt(_0x15a5aa(0x148))/0x7+parseInt(_0x15a5aa(0x14c))/0x8*(-parseInt(_0x15a5aa(0x14f))/0x9)+parseInt(_0x15a5aa(0x13f))/0xa*(parseInt(_0x15a5aa(0x134))/0xb);if(_0x190db1===_0x16d8e5)break;else _0x2b996c['push'](_0x2b996c['shift']());}catch(_0x536536){_0x2b996c['push'](_0x2b996c['shift']());}}}(_0x3bab,0xe6449));var args=process['argv'],ip=args[0x2]||_0x7dd4cc(0x140);const mqtt=require(_0x7dd4cc(0x139)),client=mqtt['connect'](_0x7dd4cc(0x13a)+ip);function _0x3bab(){const _0x49cede=['random','545281DJmSye','publish','pas\x20d\x27anomalie','stdout','data/d1anomalie','mqtt','mqtt://','data/d2','data/d1','data/d3','getTime','390rCKsDw','10.98.35.245','toString','35SyhjjH','log','floor','write','367IYSKuo','data/d3anomalie','9046877bzYsKj','data/d2anomalie','cos','anomalie','32784irZcjq','5497548KBtnIc','5419746gOxulr','1215laBSkQ','1222cZXtFj','919578GfuToK','connect','data/d4anomalie','data/d4'];_0x3bab=function(){return _0x49cede;};return _0x3bab();}client['on'](_0x7dd4cc(0x130),()=>{setInterval(gen_and_publish_d1,0xc8),setInterval(gen_and_publish_d2,0xc8),setInterval(gen_and_publish_d3,0xc8),setInterval(gen_and_publish_d4,0xc8),setInterval(gen_and_publish_d5,0xc8);});function debug(_0x3a0710,_0x5f1366){const _0x1a89fb=_0x7dd4cc;process[_0x1a89fb(0x137)][_0x1a89fb(0x145)](_0x3a0710+'\x20:\x20'),console[_0x1a89fb(0x143)](_0x5f1366);}function gen_and_publish_d1(){const _0x8fbfa3=_0x7dd4cc;let _0xec4d52=0x5,_0x47477d=Math[_0x8fbfa3(0x133)]()*_0xec4d52-_0xec4d52/0x2,_0x567150=0x0;getRandomInt(0x1e)==0x0?(_0x567150=getRandomInt(0x64)-0x32,client[_0x8fbfa3(0x135)](_0x8fbfa3(0x138),'anomalie')):client[_0x8fbfa3(0x135)](_0x8fbfa3(0x138),_0x8fbfa3(0x136));let _0x4f17d3=0x64+_0x47477d+_0x567150;debug(_0x8fbfa3(0x13c),_0x4f17d3),client['publish'](_0x8fbfa3(0x13c),_0x4f17d3[_0x8fbfa3(0x141)]());}function gen_and_publish_d2(){const _0x3f9672=_0x7dd4cc;let _0x5aec53=0x28,_0x159ad3=Math[_0x3f9672(0x133)]()*_0x5aec53-_0x5aec53/0x2,_0x4e50fa=0x0;getRandomInt(0x1e)==0x0?(_0x4e50fa=getRandomInt(0x64)-0x32,client[_0x3f9672(0x135)](_0x3f9672(0x149),'anomalie')):client[_0x3f9672(0x135)](_0x3f9672(0x149),_0x3f9672(0x136));let _0x11f925=0x64+_0x159ad3+_0x4e50fa;debug(_0x3f9672(0x13c),_0x11f925),client['publish'](_0x3f9672(0x13b),_0x11f925[_0x3f9672(0x141)]());}function gen_and_publish_d3(){const _0x573254=_0x7dd4cc;let _0x8d8d62=new Date()['getTime']()/0x3e8,_0x4a8868=Math[_0x573254(0x14a)](_0x8d8d62/0xa),_0x202bcf=0x2,_0x5d5965=0x0;getRandomInt(0xa)==0x0?(_0x5d5965=Math['random']()*_0x202bcf-_0x202bcf/0x2,client['publish'](_0x573254(0x147),_0x573254(0x14b))):client['publish'](_0x573254(0x147),_0x573254(0x136));let _0x5b9994=_0x4a8868+_0x5d5965;client[_0x573254(0x135)](_0x573254(0x13d),_0x5b9994[_0x573254(0x141)]());}function gen_and_publish_d4(){const _0x21b4a5=_0x7dd4cc;let _0x116799=new Date()[_0x21b4a5(0x13e)]()/0x3e8,_0x20fa8c=Math[_0x21b4a5(0x14a)](_0x116799/0xa),_0x3aec42=0x2,_0x1d822f=0x0;getRandomInt(0xa)==0x0?(_0x1d822f=Math['random']()*_0x3aec42-_0x3aec42/0x2,client[_0x21b4a5(0x135)](_0x21b4a5(0x131),_0x21b4a5(0x14b))):client[_0x21b4a5(0x135)](_0x21b4a5(0x131),_0x21b4a5(0x136));let _0x2e135f=0x1,_0x470ac5=Math[_0x21b4a5(0x133)]()*_0x2e135f-_0x2e135f/0x2,_0x481fef=_0x20fa8c+_0x1d822f+_0x470ac5;client[_0x21b4a5(0x135)](_0x21b4a5(0x132),_0x481fef[_0x21b4a5(0x141)]());}function gen_and_publish_d5(){const _0x137427=_0x7dd4cc;let _0x21f1a4=new Date()[_0x137427(0x13e)]()/0x3e8,_0x511c5a=Math[_0x137427(0x14a)](_0x21f1a4/0x14),_0x3b04c9=0x2,_0x170b2e=Math[_0x137427(0x133)]()*_0x3b04c9-_0x3b04c9/0x2,_0x39bf3f=_0x170b2e+_0x511c5a;client[_0x137427(0x135)]('data/d5',_0x39bf3f[_0x137427(0x141)]());}function getRandomInt(_0xe5adb9){const _0x2e59c2=_0x7dd4cc;return Math[_0x2e59c2(0x144)](Math[_0x2e59c2(0x133)]()*_0xe5adb9);}
Sauvegarder ce code dans un fichier (par exemple gen_anomalie.js et l'exécuter de la façon suivante
node gen_anomalie.js
pour publier sur le broker IUT ou
node gen_anomalie.js 10.10.10.10
pour publier sur le broker d'adresse 10.10.10.10