AD System Demo.ipynb 2.44 MB
Newer Older
smetaj's avatar
smetaj committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "linear-wyoming",
   "metadata": {},
   "source": [
    "# Demo Notebook for Running Cloud Analytics AD System\n",
    "We want to show to the users that want to try the Cloud Analytics Anomaly Detection system how to use the tools that we provide in our repository.\n",
    "\n",
    "The notebook will describe the following:\n",
    "- Installation of libraries and imports\n",
    "- Init of configuration files - ETL\n",
    "- ETL steps (Extract, Transform, Load)\n",
    "- Visualization of downloaded time series\n",
    "- Init of configuration file - ANALYSIS\n",
    "- ANALYSIS to produce anomaly scores\n",
    "- Visualization of the results\n",
    "\n",
    "#### REMEMBER TO ACTIVATE THE ANALYTIX CLUSTER IN THE SWAN CONFIGURATION!! \n",
    "Activating it you will be able to activate spark (you must click the spark icon in the upper part of the notebook to enable spark before starting to run the notebook cells!)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "digital-amazon",
   "metadata": {},
   "source": [
    "## Installation of libraries and imports"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "lightweight-burke",
   "metadata": {},
   "source": [
    "#### Installation of adcern and others libraries\n",
    "The first time the you run the notebook be sure to set the first_time variable to True in order to download our libraries.\n",
    "\n",
    "Note that with @branch you are installing the specific branch, here we have for instance qa-v0.4 but in theory we should use master!"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "global-miller",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-04-22T08:40:25.937808Z",
     "start_time": "2021-04-22T08:40:25.932298Z"
    }
   },
   "outputs": [],
   "source": [
    "first_time = False\n",
    "if first_time:\n",
    "    # If you install the libraries it takes some minutes, but don't worry it will finish :)\n",
    "    !pip install --user git+https://:@gitlab.cern.ch:8443/cloud-infrastructure/data-analytics.git@qa-v0.4"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "attended-vertical",
   "metadata": {},
   "source": [
    "#### Imports\n",
    "Let's import our libraries and some other ones that are needed for the preparation of the files and the visualizations."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "contrary-worcester",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-04-23T07:51:02.022903Z",
     "start_time": "2021-04-23T07:51:02.018774Z"
    }
   },
   "outputs": [],
   "source": [
    "#import inspect\n",
    "#print(inspect.getsource(set_spark))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "id": "reasonable-photographer",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-04-23T09:04:34.546727Z",
     "start_time": "2021-04-23T09:04:34.537937Z"
    }
   },
   "outputs": [],
   "source": [
    "# AD System Libraries ----------------------------------------------------\n",
    "import adcern.cmd.data_mining as DM\n",
    "import etl.spark_etl.etl_pipeline as PL\n",
    "#import adcern.cmd.elaborate_scores as ES\n",
    "#import etl.spark_etl.cluster_utils as CU\n",
    "#import etl.spark_etl.utils as U\n",
    "#import adcern.analyser as AN\n",
    "\n",
    "# To pass command line parameters ----------------------------------------\n",
    "import sys\n",
    "#import shutil\n",
    "#from pathlib import Path\n",
    "#import importlib\n",
    "#import json\n",
    "\n",
    "# To run the visualization function --------------------------------------\n",
    "import pandas as pd\n",
    "import re\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "import plotly.graph_objects as go\n",
    "from plotly.subplots import make_subplots\n",
    "\n",
    "# To read more parquet files with pandas ---------------------------------\n",
    "import glob\n",
    "#import inspect\n",
    "#import time"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "thermal-anthony",
   "metadata": {},
   "source": [
    "## Init of configuration files - ETL"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "visible-spank",
   "metadata": {},
   "source": [
    "Note that we need 2 config files: \n",
    "- A config file about the training part.\n",
    "- A config file about the data used by the trained model to inference the scores. "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "middle-teach",
   "metadata": {},
   "source": [
    "#### Creation\n",
    "Our ETL and analysis methods work with json and yaml configuration files in input. In these files we save all the paths, the dates and the hyperparameters used then by the methods.\n",
    "\n",
    "Usually we have the files already saved for static tests or we create them in our production pipeline; **for the purpose of this notebook instead, let's create the json files starting from a python dict.**\n",
    "\n",
    "Note that the 2 config files share most of the parameters so we will have:\n",
    "- json_data: containing all the main information\n",
    "- json_data_train, json_data_inference: containing specific paths for the 2 different purposes\n",
    "\n",
    "**Note also that you have to be sure that you have the writing rights for all the paths contained here, in particular you can change *HDFS_folder_with_write_rights* to your hdfs personal folder to ensure that :)**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "intellectual-cleaners",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-04-23T07:51:56.269486Z",
     "start_time": "2021-04-23T07:51:55.943185Z"
    }
   },
   "outputs": [],
   "source": [
    "demo_name = 'demo_AD_System'\n",
    "json_file_train = 'demo_config_train.json'\n",
    "json_file_inference = 'demo_config_inference.json'\n",
    "HDFS_folder_with_write_rights = '/user/smetaj/'\n",
    "\n",
    "json_data = {}\n",
    "\n",
    "# Absolute path identifier of the cell/hostgroup that you want to mine.\n",
    "# Note that it is in a list format, but only one hostgroup is supported so far.\n",
    "json_data['hostgroups'] = []\n",
    "json_data['hostgroups'].append('cloud_compute/level2/batch/gva_project_013')\n",
    "\n",
    "# The pattern of the names of your data folders and \".metadata\" files.\n",
    "json_data['code_project_name'] = demo_name\n",
    "\n",
    "# Local area of your VM where to save your data and metadata data are saved in\n",
    "# folders with one parquet only. Metadata are saved in file with the same name\n",
    "# of the resepctive foler plus the \".metadata\" extension.\n",
    "json_data['local_cache_folder'] = '/eos/project/i/it-cloud-data-analytics/' + \\\n",
    "    demo_name + '/local_cache_'\n",
    "\n",
    "# HDFS Area where Spark saves the aggregated data of your cell.\n",
    "# Note that the saving can create multiple file depending on the number of\n",
    "# partitions that the workers were using.\n",
    "json_data['hdfs_out_folder'] = HDFS_folder_with_write_rights + \\\n",
    "    demo_name + '/raw_parquet_'\n",
    "\n",
    "# HDFS Area where Spark saves the aggregated data of your cell.\n",
    "# Note that here we force it to be one partiotion only.\n",
    "json_data['hdfs_cache_folder'] = HDFS_folder_with_write_rights + \\\n",
    "    demo_name + '/compressed_'\n",
    "\n",
    "# HDFS Area where Spark saves the normalization coefficients computed on the\n",
    "# normalziation chunk of data between the normalization dates.\n",
    "json_data['normalization_out_folder'] = HDFS_folder_with_write_rights + \\\n",
    "    demo_name + '/normalization/'\n",
    "\n",
    "# ----------------------------------------------------------------------------\n",
    "# ----------------------------------------------------------------------------\n",
    "\n",
    "# Wether you want to overwrite (true) or not (false) the raw data in HDFS.\n",
    "# If not sure leave true.\n",
    "json_data['overwrite_on_hdfs'] = True\n",
    "\n",
    "# Wether you want to overwrite (true) or not (false) the noramlization\n",
    "# coefficeints in HDFS. If not sure leave true.\n",
    "json_data['overwrite_normalization'] = True\n",
    "\n",
    "# The level of aggregation of your raw time series data.\n",
    "# The aggregator is typically the mean operator.\n",
    "# e.g. if 5 it means that we summarize the data every 5 min, and the values\n",
    "# with timestamp 7.45 will represent the mean of the previous 5 minutes from\n",
    "# 7.40 to 7.45 but that value will have 7.45 as timestamp\n",
    "json_data['aggregate_every_n_minutes'] = 10\n",
    "\n",
    "# The length of your windows of data.\n",
    "# e.g. if aggregate_every_n_minutes = 10 and history_steps = 6 it means that\n",
    "# every windows is summarizing 6 * 10 = 60 minutes\n",
    "json_data['history_steps'] = 48\n",
    "\n",
    "# The number of step you want to move your window.\n",
    "# e.g. if aggregate_every_n_minutes = 10 and history_steps = 2 it means that\n",
    "# you will get a window of data that is translated of 10 * 2 = 20 min with\n",
    "# respect to the previous.\n",
    "# Note that if slide_steps has the same value of history_steps you have non-\n",
    "# overlapping windows.\n",
    "json_data['slide_steps'] = 1\n",
    "\n",
    "# Used to create windows with future steps. If not sure keep this to 0.\n",
    "json_data['future_steps'] = 0\n",
    "\n",
    "# ----------------------------------------------------------------------------\n",
    "# ----------------------------------------------------------------------------\n",
    "\n",
    "# Dates representing the start/end of the data and noramlization chunks.\n",
    "# - start_date -> the starting date of data chunk of ETL\n",
    "# - end_date -> the ending date of data chunk of ETL\n",
    "# - start_date_normalization -> the starting date of the chunk of data used\n",
    "#   to learn noramlization coefficeints (typically this chunk preceeds the\n",
    "#   chunk of data)\n",
    "# - end_date_normalization -> the ending date of the chunk of data used\n",
    "#   to learn noramlization coefficeints\n",
    "# Note that the upper extremum is excluded (i.e. data will stop at the 23:59\n",
    "# of the day preeceeding the date_end_excluded)\n",
    "json_data['date_start'] = \"2021-03-23\"\n",
    "json_data['date_end_excluded'] = \"2021-03-30\"\n",
    "json_data['date_start_normalization'] = \"2021-03-23\"\n",
    "json_data['date_end_normalization_excluded'] = \"2021-03-30\"\n",
    "\n",
    "# ----------------------------------------------------------------------------\n",
    "# ----------------------------------------------------------------------------\n",
    "\n",
    "# List of plugins to mine.\n",
    "# Note that it is a dictionary where every key represents the name your plugin\n",
    "# have and the value is a dictionary with:\n",
    "# 'plugin_instance', 'type' 'type_instance', 'plugin_name'\n",
    "# the value asigned to these key is defining an and-filter.\n",
    "# you will get only the data that have all those attributes\n",
    "# ('plugin_instance', 'type' 'type_instance', 'plugin_name') in and with the\n",
    "# specified value.\n",
    "# Note that if you do not want to filter on one attribute do not express it.\n",
    "json_data['selected_plugins'] = {\n",
    "    \"load_longterm\": {\n",
    "        \"value_instance\": \"longterm\",\n",
    "        \"plugin_name\": \"load\"\n",
    "    },\n",
    "    \"memory__memory_free\": {\n",
    "        \"plugin_instance\": \"\",\n",
    "        \"type\": \"memory\",\n",
    "        \"type_instance\": \"free\",\n",
    "        \"plugin_name\": \"memory\"\n",
    "    },\n",
    "    \"swap_swapfile_swap_free\": {\n",
    "        \"type\": \"swap\",\n",
    "        \"type_instance\": \"free\",\n",
    "        \"plugin_name\": \"swap\"\n",
    "    }\n",
    "}\n",
    "json_data['local_cache_folder'] = '/eos/project/i/it-cloud-data-analytics/' + \\\n",
    "    demo_name + '/local_cache_'\n",
    "\n",
    "# HDFS Area where Spark saves the aggregated data of your cell.\n",
    "# Note that the saving can create multiple file depending on the number of\n",
    "# partitions that the workers were using.\n",
    "json_data['hdfs_out_folder'] = HDFS_folder_with_write_rights + \\\n",
    "    demo_name + '/raw_parquet_'\n",
    "\n",
    "# HDFS Area where Spark saves the aggregated data of your cell.\n",
    "# Note that here we force it to be one partiotion only.\n",
    "json_data['hdfs_cache_folder'] = HDFS_folder_with_write_rights + \\\n",
    "    demo_name + '/compressed_'\n",
    "\n",
    "json_data_train = json_data.copy()\n",
    "json_data_train['local_cache_folder'] += 'train/'\n",
    "json_data_train['hdfs_out_folder'] += 'train/'\n",
    "json_data_train['hdfs_cache_folder'] += 'train/'\n",
    "\n",
    "json_data_inference = json_data.copy()\n",
    "json_data_inference['local_cache_folder'] += 'inference/'\n",
    "json_data_inference['hdfs_out_folder'] += 'inference/'\n",
    "json_data_inference['hdfs_cache_folder'] += 'inference/'\n",
    "# The imporant change is that we want to have NON OVERLAPPING windows\n",
    "# in the inference!\n",
    "json_data_inference['slide_steps'] = 48\n",
    "\n",
    "with open(json_file_train, 'w') as outfile:\n",
    "    json.dump(json_data_train, outfile, indent=4)\n",
    "\n",
    "with open(json_file_inference, 'w') as outfile:\n",
    "    json.dump(json_data_inference, outfile, indent=4)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "republican-ownership",
   "metadata": {},
   "source": [
    "#### Reading of the json\n",
    "Let's use the read_resource function in the data_mining library to be sure that the format is correct and to print the files."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "sized-sampling",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-04-23T07:51:56.291394Z",
     "start_time": "2021-04-23T07:51:56.274613Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "RESOURCE DETAILS: demo_config_train.json\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "{\n",
      "    \"hostgroups\": [\n",
      "        \"cloud_compute/level2/batch/gva_project_013\"\n",
      "    ],\n",
      "    \"code_project_name\": \"demo_AD_System\",\n",
      "    \"local_cache_folder\": \"/eos/project/i/it-cloud-data-analytics/demo_AD_System/local_cache_train/\",\n",
      "    \"hdfs_out_folder\": \"/user/smetaj/demo_AD_System/raw_parquet_train/\",\n",
      "    \"hdfs_cache_folder\": \"/user/smetaj/demo_AD_System/compressed_train/\",\n",
      "    \"normalization_out_folder\": \"/user/smetaj/demo_AD_System/normalization/\",\n",
      "    \"overwrite_on_hdfs\": true,\n",
      "    \"overwrite_normalization\": true,\n",
      "    \"aggregate_every_n_minutes\": 10,\n",
      "    \"history_steps\": 48,\n",
      "    \"slide_steps\": 1,\n",
      "    \"future_steps\": 0,\n",
      "    \"date_start\": \"2021-03-23\",\n",
      "    \"date_end_excluded\": \"2021-03-30\",\n",
      "    \"date_start_normalization\": \"2021-03-23\",\n",
      "    \"date_end_normalization_excluded\": \"2021-03-30\",\n",
      "    \"selected_plugins\": {\n",
      "        \"load_longterm\": {\n",
      "            \"value_instance\": \"longterm\",\n",
      "            \"plugin_name\": \"load\"\n",
      "        },\n",
      "        \"memory__memory_free\": {\n",
      "            \"plugin_instance\": \"\",\n",
      "            \"type\": \"memory\",\n",
      "            \"type_instance\": \"free\",\n",
      "            \"plugin_name\": \"memory\"\n",
      "        },\n",
      "        \"swap_swapfile_swap_free\": {\n",
      "            \"type\": \"swap\",\n",
      "            \"type_instance\": \"free\",\n",
      "            \"plugin_name\": \"swap\"\n",
      "        }\n",
      "    }\n",
      "}\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "RESOURCE DETAILS: demo_config_inference.json\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "{\n",
      "    \"hostgroups\": [\n",
      "        \"cloud_compute/level2/batch/gva_project_013\"\n",
      "    ],\n",
      "    \"code_project_name\": \"demo_AD_System\",\n",
      "    \"local_cache_folder\": \"/eos/project/i/it-cloud-data-analytics/demo_AD_System/local_cache_inference/\",\n",
      "    \"hdfs_out_folder\": \"/user/smetaj/demo_AD_System/raw_parquet_inference/\",\n",
      "    \"hdfs_cache_folder\": \"/user/smetaj/demo_AD_System/compressed_inference/\",\n",
      "    \"normalization_out_folder\": \"/user/smetaj/demo_AD_System/normalization/\",\n",
      "    \"overwrite_on_hdfs\": true,\n",
      "    \"overwrite_normalization\": true,\n",
      "    \"aggregate_every_n_minutes\": 10,\n",
      "    \"history_steps\": 48,\n",
      "    \"slide_steps\": 48,\n",
      "    \"future_steps\": 0,\n",
      "    \"date_start\": \"2021-03-23\",\n",
      "    \"date_end_excluded\": \"2021-03-30\",\n",
      "    \"date_start_normalization\": \"2021-03-23\",\n",
      "    \"date_end_normalization_excluded\": \"2021-03-30\",\n",
      "    \"selected_plugins\": {\n",
      "        \"load_longterm\": {\n",
      "            \"value_instance\": \"longterm\",\n",
      "            \"plugin_name\": \"load\"\n",
      "        },\n",
      "        \"memory__memory_free\": {\n",
      "            \"plugin_instance\": \"\",\n",
      "            \"type\": \"memory\",\n",
      "            \"type_instance\": \"free\",\n",
      "            \"plugin_name\": \"memory\"\n",
      "        },\n",
      "        \"swap_swapfile_swap_free\": {\n",
      "            \"type\": \"swap\",\n",
      "            \"type_instance\": \"free\",\n",
      "            \"plugin_name\": \"swap\"\n",
      "        }\n",
      "    }\n",
      "}\n"
     ]
    }
   ],
   "source": [
    "_ = DM.read_resource(resource_file=json_file_train)\n",
    "_ = DM.read_resource(resource_file=json_file_inference)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "acting-galaxy",
   "metadata": {},
   "source": [
    "## ETL steps (Extract, Transform, Load)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "monetary-clinic",
   "metadata": {},
   "source": [
    "What we want to achieve here is to reproduce the steps to download and normalize the data (following the order in the graph below).\n",
    "![](https://mattermost.web.cern.ch/files/skktqwaws7nkzpb16c73n11tac/public?h=KflwzsI6wpa58LJCUgTGH-r8dJHEskq_a4R_05QMOPg)\n",
    "\n",
    "Note that, for every step, we will call the specific function of the data_mining library (for both the json files in most of the cases). Moreover we will use the *try catch* to permit the users to run multiple cells in the same time."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "advisory-trading",
   "metadata": {},
   "source": [
    "#### Data Presence\n",
    "With this function we check in eos if we already have the files. \n",
    "\n",
    "The function check the local_cache_folder parameter in the json file and try to access the data in the directory.\n",
    "\n",
    "Obviously the first time we run this we will not have the daya yet, so the function will raise an exception."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "minor-arthur",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-04-23T07:55:33.878611Z",
     "start_time": "2021-04-23T07:55:26.485136Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "CHECK IF DATA ARE ALREADY AVAILABLE LOCALLY:\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "Opening in Pandas -> parquet file:  /eos/project/i/it-cloud-data-analytics/demo_AD_System/local_cache_train/demo_AD_System\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "SUCCESS - CACHE HIT - DATA ARE ALREADY AVAILABLE LOCALLY.\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "CHECK IF DATA ARE ALREADY AVAILABLE LOCALLY:\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "Opening in Pandas -> parquet file:  /eos/project/i/it-cloud-data-analytics/demo_AD_System/local_cache_inference/demo_AD_System\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "FAILURE - NO DATA LOCALLY:\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "Detail Error:  Passed non-file path: /eos/project/i/it-cloud-data-analytics/demo_AD_System/local_cache_inference/demo_AD_System\n"
     ]
    }
   ],
   "source": [
    "for file in [json_file_train, json_file_inference]:\n",
    "    try:\n",
    "        sys.argv = ['', '--resource_file', file]\n",
    "        DM.data_presence()\n",
    "    except:\n",
    "        pass"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "varied-company",
   "metadata": {},
   "source": [
    "Ok we don't have the data, or maybe we have them, but have we already the normalization data? We have a function that checks that too.\n",
    "\n",
    "Note that in this \"easy\" example we don't want to normalize with respect to other data but with respect to the same period (the dates and the normalization_dates are the same)!\n",
    "\n",
    "Anyway let's call the normalizationpresence function."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "informal-raising",
   "metadata": {},
   "source": [
    "#### Check Normalization\n",
    "\n",
    "Note that for this function we have to connect to spark for retrieving data from HDFS (indeed, normalization_out_folder is located in HDFS!). \n",
    "For this reason the output is full of spark parameters and information in general.\n",
    "\n",
    "As expected, the normalization data will not be found the first time."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "ecological-journalist",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-04-23T07:56:40.038531Z",
     "start_time": "2021-04-23T07:56:28.349348Z"
    },
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "PREPARING SPARK:\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "Configuration data:\n",
      "spark.eventLog.enabled\ttrue\n",
      "spark.ui.proxyBase\t/proxy/application_1618913605843_3871\n",
      "spark.yarn.access.hadoopFileSystems\tanalytix\n",
      "spark.authenticate\tTrue\n",
      "spark.executorEnv.JAVA_HOME\t/cvmfs/sft.cern.ch/lcg/releases/java/8u222-884d8/x86_64-centos7-gcc8-opt\n",
      "spark.eventLog.dir\thdfs://analytix//var/log/spark-history\n",
      "spark.yarn.historyServer.address\tithdp1101.cern.ch:18080\n",
      "spark.network.crypto.enabled\tTrue\n",
      "spark.executor.extraJavaOptions\t-XX:+UseG1GC\n",
      "spark.driver.memory\t1g\n",
      "spark.executor.extraLibraryPath\t/usr/hdp/hadoop/lib/native\n",
      "spark.executorEnv.PYTHONPATH\t/eos/user/s/smetaj//.local/lib/python3.7/site-packages:/usr/local/lib/swan/extensions/:/cvmfs/sft.cern.ch/lcg/views/LCG_97apython3/x86_64-centos7-gcc8-opt/python:/cvmfs/sft.cern.ch/lcg/views/LCG_97apython3/x86_64-centos7-gcc8-opt/lib:/cvmfs/sft.cern.ch/lcg/views/LCG_97apython3/x86_64-centos7-gcc8-opt/lib/python3.7/site-packages\n",
      "spark.dynamicAllocation.maxExecutors\t64\n",
      "spark.extraListeners\tsparkmonitor.listener.JupyterSparkMonitorListener\n",
      "spark.executor.instances\t2\n",
      "spark.driver.maxResultSize\t0\n",
      "spark.submit.deployMode\tclient\n",
      "spark.blockManager.port\t5157\n",
      "spark.authenticate.enableSaslEncryption\tTrue\n",
      "spark.executor.memory\t2g\n",
      "spark.shuffle.service.enabled\ttrue\n",
      "spark.ui.port\t5289\n",
      "spark.shuffle.useOldFetchProtocol\ttrue\n",
      "spark.dynamicAllocation.minExecutors\t2\n",
      "spark.driver.extraClassPath\t/eos/project/s/swan/public/hadoop-mapreduce-client-core-2.6.0-cdh5.7.6.jar:/usr/local/lib/swan/extensions/sparkmonitor/listener_2.11.jar\n",
      "spark.executorEnv.SPARK_EXTRA_CLASSPATH\t/cvmfs/sft.cern.ch/lcg/views/LCG_97apython3/x86_64-centos7-gcc8-opt/etc/hadoop:/cvmfs/sft.cern.ch/lcg/views/LCG_97apython3/x86_64-centos7-gcc8-opt/share/hadoop/common/lib/*:/cvmfs/sft.cern.ch/lcg/views/LCG_97apython3/x86_64-centos7-gcc8-opt/share/hadoop/common/*:/cvmfs/sft.cern.ch/lcg/views/LCG_97apython3/x86_64-centos7-gcc8-opt/share/hadoop/hdfs:/cvmfs/sft.cern.ch/lcg/views/LCG_97apython3/x86_64-centos7-gcc8-opt/share/hadoop/hdfs/lib/*:/cvmfs/sft.cern.ch/lcg/views/LCG_97apython3/x86_64-centos7-gcc8-opt/share/hadoop/hdfs/*:/cvmfs/sft.cern.ch/lcg/views/LCG_97apython3/x86_64-centos7-gcc8-opt/share/hadoop/yarn/lib/*:/cvmfs/sft.cern.ch/lcg/views/LCG_97apython3/x86_64-centos7-gcc8-opt/share/hadoop/yarn/*:/cvmfs/sft.cern.ch/lcg/views/LCG_97apython3/x86_64-centos7-gcc8-opt/share/hadoop/mapreduce/lib/*:/cvmfs/sft.cern.ch/lcg/views/LCG_97apython3/x86_64-centos7-gcc8-opt/share/hadoop/mapreduce/*:/cvmfs/sft.cern.ch/lcg/releases/hadoop_xrootd/1.0.4-e8531/x86_64-centos7-gcc8-opt/lib/hadoop-xrootd.jar\n",
      "spark.executor.cores\t2\n",
      "spark.executorEnv.SPARK_HOME\t/cvmfs/sft.cern.ch/lcg/releases/spark/2.4.5-cern1-f7679/x86_64-centos7-gcc8-opt\n",
      "spark.driver.port\t5133\n",
      "spark.master\tyarn\n",
      "spark.driver.blockManager.port\t5157\n",
      "spark.driver.extraJavaOptions\t-Dlog4j.configuration=file:/tmp/tmp7hep26vr\n",
      "spark.logConf\tTrue\n",
      "spark.driver.extraLibraryPath\t/usr/hdp/hadoop/lib/native\n",
      "spark.app.name\tpyspark_shell_swan\n",
      "spark.executorEnv.LD_LIBRARY_PATH\t/cvmfs/sft.cern.ch/lcg/views/LCG_97apython3/x86_64-centos7-gcc8-opt/lib/python3.7/site-packages/torch/lib:/cvmfs/sft.cern.ch/lcg/views/LCG_97apython3/x86_64-centos7-gcc8-opt/lib/python3.7/site-packages/tensorflow:/cvmfs/sft.cern.ch/lcg/views/LCG_97apython3/x86_64-centos7-gcc8-opt/lib/python3.7/site-packages/tensorflow/contrib/tensor_forest:/cvmfs/sft.cern.ch/lcg/views/LCG_97apython3/x86_64-centos7-gcc8-opt/lib/python3.7/site-packages/tensorflow/python/framework:/cvmfs/sft.cern.ch/lcg/releases/java/8u222-884d8/x86_64-centos7-gcc8-opt/jre/lib/amd64:/cvmfs/sft.cern.ch/lcg/views/LCG_97apython3/x86_64-centos7-gcc8-opt/lib64:/cvmfs/sft.cern.ch/lcg/views/LCG_97apython3/x86_64-centos7-gcc8-opt/lib:/cvmfs/sft.cern.ch/lcg/releases/gcc/8.3.0-cebb0/x86_64-centos7/lib:/cvmfs/sft.cern.ch/lcg/releases/gcc/8.3.0-cebb0/x86_64-centos7/lib64:/cvmfs/sft.cern.ch/lcg/releases/binutils/2.30-e5b21/x86_64-centos7/lib:/usr/local/lib/:/cvmfs/sft.cern.ch/lcg/releases/R/3.6.3-ca0ad/x86_64-centos7-gcc8-opt/lib64/R/library/readr/rcon\n",
      "spark.yarn.isPython\ttrue\n",
      "spark.driver.host\te84e6e6714a2\n",
      "spark.dynamicAllocation.enabled\ttrue\n",
      "spark.ui.showConsoleProgress\ttrue\n",
      "spark.port.maxRetries\t100\n",
      "Configuration data after setup:\n",
      "spark.blockManager.port:\t5101\n",
      "spark.eventLog.enabled:\ttrue\n",
      "spark.ui.proxyBase:\t/proxy/application_1618913605843_3871\n",
      "spark.yarn.access.hadoopFileSystems:\tanalytix\n",
      "spark.network.crypto.enabled:\ttrue\n",
      "spark.eventLog.dir:\thdfs://analytix//var/log/spark-history\n",
      "spark.yarn.historyServer.address:\tithdp1101.cern.ch:18080\n",
      "spark.driver.memory:\t4g\n",
      "spark.executor.extraJavaOptions:\t-XX:+UseG1GC\n",
      "spark.executorEnv.PYTHONPATH:\t/eos/user/s/smetaj//.local/lib/python3.7/site-packages:/cvmfs/sft.cern.ch/lcg/views/LCG_97apython3/x86_64-centos7-gcc8-opt/python:/cvmfs/sft.cern.ch/lcg/views/LCG_97apython3/x86_64-centos7-gcc8-opt/lib:/cvmfs/sft.cern.ch/lcg/views/LCG_97apython3/x86_64-centos7-gcc8-opt/lib/python3.7/site-packages<CPS>{{PWD}}/pyspark.zip<CPS>{{PWD}}/py4j-0.10.7-src.zip\n",
      "spark.authenticate.enableSaslEncryption:\ttrue\n",
      "spark.executor.extraLibraryPath:\t/usr/hdp/hadoop/lib/native\n",
      "spark.driver.host:\tswan006.cern.ch\n",
      "spark.driver.appUIAddress:\thttp://swan006.cern.ch:5289\n",
      "spark.dynamicAllocation.maxExecutors:\t64\n",
      "spark.org.apache.hadoop.yarn.server.webproxy.amfilter.AmIpFilter.param.RM_HA_URLS:\tithdp1101.cern.ch:8088,ithdp2101.cern.ch:8088\n",
      "spark.org.apache.hadoop.yarn.server.webproxy.amfilter.AmIpFilter.param.PROXY_HOSTS:\tithdp1101.cern.ch,ithdp2101.cern.ch\n",
      "spark.app.id:\tapplication_1618913605843_3871\n",
      "spark.executor.instances:\t2\n",
      "spark.extraListeners:\tsparkmonitor.listener.JupyterSparkMonitorListener\n",
      "spark.serializer.objectStreamReset:\t100\n",
      "spark.org.apache.hadoop.yarn.server.webproxy.amfilter.AmIpFilter.param.PROXY_URI_BASES:\thttp://ithdp1101.cern.ch:8088/proxy/application_1618913605843_3871,http://ithdp2101.cern.ch:8088/proxy/application_1618913605843_3871\n",
      "spark.submit.deployMode:\tclient\n",
      "spark.ui.filters:\torg.apache.hadoop.yarn.server.webproxy.amfilter.AmIpFilter\n",
      "spark.executor.memory:\t2g\n",
      "spark.shuffle.service.enabled:\ttrue\n",
      "spark.ui.port:\t5289\n",
      "spark.shuffle.useOldFetchProtocol:\ttrue\n",
      "spark.dynamicAllocation.minExecutors:\t2\n",
      "spark.executor.id:\tdriver\n",
      "spark.driver.extraClassPath:\t/eos/project/s/swan/public/hadoop-mapreduce-client-core-2.6.0-cdh5.7.6.jar:/usr/local/lib/swan/extensions/sparkmonitor/listener_2.11.jar\n",
      "spark.executor.cores:\t2\n",
      "spark.driver.port:\t5133\n",
      "spark.master:\tyarn\n",
      "spark.driver.blockManager.port:\t5157\n",
      "spark.driver.extraJavaOptions:\t-Dlog4j.configuration=file:/tmp/tmp7hep26vr\n",
      "spark.driver.extraLibraryPath:\t/usr/hdp/hadoop/lib/native\n",
      "spark.rdd.compress:\tTrue\n",
      "spark.app.name:\tpyspark_shell_swan\n",
      "spark.executorEnv.LD_LIBRARY_PATH:\t/cvmfs/sft.cern.ch/lcg/views/LCG_97apython3/x86_64-centos7-gcc8-opt/lib/python3.7/site-packages/torch/lib:/cvmfs/sft.cern.ch/lcg/views/LCG_97apython3/x86_64-centos7-gcc8-opt/lib/python3.7/site-packages/tensorflow:/cvmfs/sft.cern.ch/lcg/views/LCG_97apython3/x86_64-centos7-gcc8-opt/lib/python3.7/site-packages/tensorflow/contrib/tensor_forest:/cvmfs/sft.cern.ch/lcg/views/LCG_97apython3/x86_64-centos7-gcc8-opt/lib/python3.7/site-packages/tensorflow/python/framework:/cvmfs/sft.cern.ch/lcg/releases/java/8u222-884d8/x86_64-centos7-gcc8-opt/jre/lib/amd64:/cvmfs/sft.cern.ch/lcg/views/LCG_97apython3/x86_64-centos7-gcc8-opt/lib64:/cvmfs/sft.cern.ch/lcg/views/LCG_97apython3/x86_64-centos7-gcc8-opt/lib:/cvmfs/sft.cern.ch/lcg/releases/gcc/8.3.0-cebb0/x86_64-centos7/lib:/cvmfs/sft.cern.ch/lcg/releases/gcc/8.3.0-cebb0/x86_64-centos7/lib64:/cvmfs/sft.cern.ch/lcg/releases/binutils/2.30-e5b21/x86_64-centos7/lib:/usr/local/lib/:/cvmfs/sft.cern.ch/lcg/releases/R/3.6.3-ca0ad/x86_64-centos7-gcc8-opt/lib64/R/library/readr/rcon\n",
      "spark.yarn.isPython:\ttrue\n",
      "spark.dynamicAllocation.enabled:\ttrue\n",
      "spark.ui.showConsoleProgress:\ttrue\n",
      "spark.authenticate:\ttrue\n",
      "spark.port.maxRetries:\t100\n",
      "[('spark.blockManager.port', '5101'), ('spark.eventLog.enabled', 'true'), ('spark.ui.proxyBase', '/proxy/application_1618913605843_3871'), ('spark.yarn.access.hadoopFileSystems', 'analytix'), ('spark.network.crypto.enabled', 'true'), ('spark.eventLog.dir', 'hdfs://analytix//var/log/spark-history'), ('spark.yarn.historyServer.address', 'ithdp1101.cern.ch:18080'), ('spark.driver.memory', '4g'), ('spark.executor.extraJavaOptions', '-XX:+UseG1GC'), ('spark.executorEnv.PYTHONPATH', '/eos/user/s/smetaj//.local/lib/python3.7/site-packages:/cvmfs/sft.cern.ch/lcg/views/LCG_97apython3/x86_64-centos7-gcc8-opt/python:/cvmfs/sft.cern.ch/lcg/views/LCG_97apython3/x86_64-centos7-gcc8-opt/lib:/cvmfs/sft.cern.ch/lcg/views/LCG_97apython3/x86_64-centos7-gcc8-opt/lib/python3.7/site-packages<CPS>{{PWD}}/pyspark.zip<CPS>{{PWD}}/py4j-0.10.7-src.zip'), ('spark.authenticate.enableSaslEncryption', 'true'), ('spark.executor.extraLibraryPath', '/usr/hdp/hadoop/lib/native'), ('spark.driver.host', 'swan006.cern.ch'), ('spark.driver.appUIAddress', 'http://swan006.cern.ch:5289'), ('spark.dynamicAllocation.maxExecutors', '64'), ('spark.org.apache.hadoop.yarn.server.webproxy.amfilter.AmIpFilter.param.RM_HA_URLS', 'ithdp1101.cern.ch:8088,ithdp2101.cern.ch:8088'), ('spark.org.apache.hadoop.yarn.server.webproxy.amfilter.AmIpFilter.param.PROXY_HOSTS', 'ithdp1101.cern.ch,ithdp2101.cern.ch'), ('spark.app.id', 'application_1618913605843_3871'), ('spark.executor.instances', '2'), ('spark.extraListeners', 'sparkmonitor.listener.JupyterSparkMonitorListener'), ('spark.serializer.objectStreamReset', '100'), ('spark.org.apache.hadoop.yarn.server.webproxy.amfilter.AmIpFilter.param.PROXY_URI_BASES', 'http://ithdp1101.cern.ch:8088/proxy/application_1618913605843_3871,http://ithdp2101.cern.ch:8088/proxy/application_1618913605843_3871'), ('spark.submit.deployMode', 'client'), ('spark.ui.filters', 'org.apache.hadoop.yarn.server.webproxy.amfilter.AmIpFilter'), ('spark.executor.memory', '2g'), ('spark.shuffle.service.enabled', 'true'), ('spark.ui.port', '5289'), ('spark.shuffle.useOldFetchProtocol', 'true'), ('spark.dynamicAllocation.minExecutors', '2'), ('spark.executor.id', 'driver'), ('spark.driver.extraClassPath', '/eos/project/s/swan/public/hadoop-mapreduce-client-core-2.6.0-cdh5.7.6.jar:/usr/local/lib/swan/extensions/sparkmonitor/listener_2.11.jar'), ('spark.executor.cores', '2'), ('spark.driver.port', '5133'), ('spark.master', 'yarn'), ('spark.driver.blockManager.port', '5157'), ('spark.driver.extraJavaOptions', '-Dlog4j.configuration=file:/tmp/tmp7hep26vr'), ('spark.driver.extraLibraryPath', '/usr/hdp/hadoop/lib/native'), ('spark.rdd.compress', 'True'), ('spark.app.name', 'pyspark_shell_swan'), ('spark.executorEnv.LD_LIBRARY_PATH', '/cvmfs/sft.cern.ch/lcg/views/LCG_97apython3/x86_64-centos7-gcc8-opt/lib/python3.7/site-packages/torch/lib:/cvmfs/sft.cern.ch/lcg/views/LCG_97apython3/x86_64-centos7-gcc8-opt/lib/python3.7/site-packages/tensorflow:/cvmfs/sft.cern.ch/lcg/views/LCG_97apython3/x86_64-centos7-gcc8-opt/lib/python3.7/site-packages/tensorflow/contrib/tensor_forest:/cvmfs/sft.cern.ch/lcg/views/LCG_97apython3/x86_64-centos7-gcc8-opt/lib/python3.7/site-packages/tensorflow/python/framework:/cvmfs/sft.cern.ch/lcg/releases/java/8u222-884d8/x86_64-centos7-gcc8-opt/jre/lib/amd64:/cvmfs/sft.cern.ch/lcg/views/LCG_97apython3/x86_64-centos7-gcc8-opt/lib64:/cvmfs/sft.cern.ch/lcg/views/LCG_97apython3/x86_64-centos7-gcc8-opt/lib:/cvmfs/sft.cern.ch/lcg/releases/gcc/8.3.0-cebb0/x86_64-centos7/lib:/cvmfs/sft.cern.ch/lcg/releases/gcc/8.3.0-cebb0/x86_64-centos7/lib64:/cvmfs/sft.cern.ch/lcg/releases/binutils/2.30-e5b21/x86_64-centos7/lib:/usr/local/lib/:/cvmfs/sft.cern.ch/lcg/releases/R/3.6.3-ca0ad/x86_64-centos7-gcc8-opt/lib64/R/library/readr/rcon'), ('spark.yarn.isPython', 'true'), ('spark.dynamicAllocation.enabled', 'true'), ('spark.ui.showConsoleProgress', 'true'), ('spark.authenticate', 'true'), ('spark.port.maxRetries', '100')]\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "SPARK CONTEXT: <SparkContext master=yarn appName=pyspark_shell_swan>\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "SPARK OBJECT: <pyspark.sql.session.SparkSession object at 0x7efecf91ae50>\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "RESOURCE DETAILS: demo_config_train.json\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "{\n",
      "    \"hostgroups\": [\n",
      "        \"cloud_compute/level2/batch/gva_project_013\"\n",
      "    ],\n",
      "    \"code_project_name\": \"demo_AD_System\",\n",
      "    \"local_cache_folder\": \"/eos/project/i/it-cloud-data-analytics/demo_AD_System/local_cache_train/\",\n",
      "    \"hdfs_out_folder\": \"/user/smetaj/demo_AD_System/raw_parquet_train/\",\n",
      "    \"hdfs_cache_folder\": \"/user/smetaj/demo_AD_System/compressed_train/\",\n",
      "    \"normalization_out_folder\": \"/user/smetaj/demo_AD_System/normalization/\",\n",
      "    \"overwrite_on_hdfs\": true,\n",
      "    \"overwrite_normalization\": true,\n",
      "    \"aggregate_every_n_minutes\": 10,\n",
      "    \"history_steps\": 48,\n",
      "    \"slide_steps\": 1,\n",
      "    \"future_steps\": 0,\n",
      "    \"date_start\": \"2021-03-23\",\n",
      "    \"date_end_excluded\": \"2021-03-30\",\n",
      "    \"date_start_normalization\": \"2021-03-23\",\n",
      "    \"date_end_normalization_excluded\": \"2021-03-30\",\n",
      "    \"selected_plugins\": {\n",
      "        \"load_longterm\": {\n",
      "            \"value_instance\": \"longterm\",\n",
      "            \"plugin_name\": \"load\"\n",
      "        },\n",
      "        \"memory__memory_free\": {\n",
      "            \"plugin_instance\": \"\",\n",
      "            \"type\": \"memory\",\n",
      "            \"type_instance\": \"free\",\n",
      "            \"plugin_name\": \"memory\"\n",
      "        },\n",
      "        \"swap_swapfile_swap_free\": {\n",
      "            \"type\": \"swap\",\n",
      "            \"type_instance\": \"free\",\n",
      "            \"plugin_name\": \"swap\"\n",
      "        }\n",
      "    }\n",
      "}\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "CHECK PRESENCE OF NORMALIZATION COEFFICIENTS...\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "NORMALIZATION COEFFICIENTS FOUND :)\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "SUCCESS (inspect the first 40 rows):\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "                                    hostgroup                   plugin  \\\n",
      "0  cloud_compute/level2/batch/gva_project_013  swap_swapfile_swap_free   \n",
      "1  cloud_compute/level2/batch/gva_project_013      memory__memory_free   \n",
      "2  cloud_compute/level2/batch/gva_project_013            load_longterm   \n",
      "\n",
      "           mean        stddev  \n",
      "0  4.052017e+10  2.408829e+09  \n",
      "1  7.446611e+08  2.653568e+08  \n",
      "2  7.320000e-01  2.960000e-01  \n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "PREPARING SPARK:\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "Configuration data:\n",
      "spark.eventLog.enabled\ttrue\n",
      "spark.ui.proxyBase\t/proxy/application_1618913605843_3871\n",
      "spark.yarn.access.hadoopFileSystems\tanalytix\n",
      "spark.authenticate\tTrue\n",
      "spark.executorEnv.JAVA_HOME\t/cvmfs/sft.cern.ch/lcg/releases/java/8u222-884d8/x86_64-centos7-gcc8-opt\n",
      "spark.eventLog.dir\thdfs://analytix//var/log/spark-history\n",
      "spark.yarn.historyServer.address\tithdp1101.cern.ch:18080\n",
      "spark.network.crypto.enabled\tTrue\n",
      "spark.executor.extraJavaOptions\t-XX:+UseG1GC\n",
      "spark.driver.memory\t1g\n",
      "spark.executor.extraLibraryPath\t/usr/hdp/hadoop/lib/native\n",
      "spark.executorEnv.PYTHONPATH\t/eos/user/s/smetaj//.local/lib/python3.7/site-packages:/usr/local/lib/swan/extensions/:/cvmfs/sft.cern.ch/lcg/views/LCG_97apython3/x86_64-centos7-gcc8-opt/python:/cvmfs/sft.cern.ch/lcg/views/LCG_97apython3/x86_64-centos7-gcc8-opt/lib:/cvmfs/sft.cern.ch/lcg/views/LCG_97apython3/x86_64-centos7-gcc8-opt/lib/python3.7/site-packages\n",
      "spark.dynamicAllocation.maxExecutors\t64\n",
      "spark.extraListeners\tsparkmonitor.listener.JupyterSparkMonitorListener\n",
      "spark.executor.instances\t2\n",
      "spark.driver.maxResultSize\t0\n",
      "spark.submit.deployMode\tclient\n",
      "spark.blockManager.port\t5157\n",
      "spark.authenticate.enableSaslEncryption\tTrue\n",
      "spark.executor.memory\t2g\n",
      "spark.shuffle.service.enabled\ttrue\n",
      "spark.ui.port\t5289\n",
      "spark.shuffle.useOldFetchProtocol\ttrue\n",
      "spark.dynamicAllocation.minExecutors\t2\n",
      "spark.driver.extraClassPath\t/eos/project/s/swan/public/hadoop-mapreduce-client-core-2.6.0-cdh5.7.6.jar:/usr/local/lib/swan/extensions/sparkmonitor/listener_2.11.jar\n",
      "spark.executorEnv.SPARK_EXTRA_CLASSPATH\t/cvmfs/sft.cern.ch/lcg/views/LCG_97apython3/x86_64-centos7-gcc8-opt/etc/hadoop:/cvmfs/sft.cern.ch/lcg/views/LCG_97apython3/x86_64-centos7-gcc8-opt/share/hadoop/common/lib/*:/cvmfs/sft.cern.ch/lcg/views/LCG_97apython3/x86_64-centos7-gcc8-opt/share/hadoop/common/*:/cvmfs/sft.cern.ch/lcg/views/LCG_97apython3/x86_64-centos7-gcc8-opt/share/hadoop/hdfs:/cvmfs/sft.cern.ch/lcg/views/LCG_97apython3/x86_64-centos7-gcc8-opt/share/hadoop/hdfs/lib/*:/cvmfs/sft.cern.ch/lcg/views/LCG_97apython3/x86_64-centos7-gcc8-opt/share/hadoop/hdfs/*:/cvmfs/sft.cern.ch/lcg/views/LCG_97apython3/x86_64-centos7-gcc8-opt/share/hadoop/yarn/lib/*:/cvmfs/sft.cern.ch/lcg/views/LCG_97apython3/x86_64-centos7-gcc8-opt/share/hadoop/yarn/*:/cvmfs/sft.cern.ch/lcg/views/LCG_97apython3/x86_64-centos7-gcc8-opt/share/hadoop/mapreduce/lib/*:/cvmfs/sft.cern.ch/lcg/views/LCG_97apython3/x86_64-centos7-gcc8-opt/share/hadoop/mapreduce/*:/cvmfs/sft.cern.ch/lcg/releases/hadoop_xrootd/1.0.4-e8531/x86_64-centos7-gcc8-opt/lib/hadoop-xrootd.jar\n",
      "spark.executor.cores\t2\n",
      "spark.executorEnv.SPARK_HOME\t/cvmfs/sft.cern.ch/lcg/releases/spark/2.4.5-cern1-f7679/x86_64-centos7-gcc8-opt\n",
      "spark.driver.port\t5133\n",
      "spark.master\tyarn\n",
      "spark.driver.blockManager.port\t5157\n",
      "spark.driver.extraJavaOptions\t-Dlog4j.configuration=file:/tmp/tmp7hep26vr\n",
      "spark.logConf\tTrue\n",
      "spark.driver.extraLibraryPath\t/usr/hdp/hadoop/lib/native\n",
      "spark.app.name\tpyspark_shell_swan\n",
      "spark.executorEnv.LD_LIBRARY_PATH\t/cvmfs/sft.cern.ch/lcg/views/LCG_97apython3/x86_64-centos7-gcc8-opt/lib/python3.7/site-packages/torch/lib:/cvmfs/sft.cern.ch/lcg/views/LCG_97apython3/x86_64-centos7-gcc8-opt/lib/python3.7/site-packages/tensorflow:/cvmfs/sft.cern.ch/lcg/views/LCG_97apython3/x86_64-centos7-gcc8-opt/lib/python3.7/site-packages/tensorflow/contrib/tensor_forest:/cvmfs/sft.cern.ch/lcg/views/LCG_97apython3/x86_64-centos7-gcc8-opt/lib/python3.7/site-packages/tensorflow/python/framework:/cvmfs/sft.cern.ch/lcg/releases/java/8u222-884d8/x86_64-centos7-gcc8-opt/jre/lib/amd64:/cvmfs/sft.cern.ch/lcg/views/LCG_97apython3/x86_64-centos7-gcc8-opt/lib64:/cvmfs/sft.cern.ch/lcg/views/LCG_97apython3/x86_64-centos7-gcc8-opt/lib:/cvmfs/sft.cern.ch/lcg/releases/gcc/8.3.0-cebb0/x86_64-centos7/lib:/cvmfs/sft.cern.ch/lcg/releases/gcc/8.3.0-cebb0/x86_64-centos7/lib64:/cvmfs/sft.cern.ch/lcg/releases/binutils/2.30-e5b21/x86_64-centos7/lib:/usr/local/lib/:/cvmfs/sft.cern.ch/lcg/releases/R/3.6.3-ca0ad/x86_64-centos7-gcc8-opt/lib64/R/library/readr/rcon\n",
      "spark.yarn.isPython\ttrue\n",
      "spark.driver.host\te84e6e6714a2\n",
      "spark.dynamicAllocation.enabled\ttrue\n",
      "spark.ui.showConsoleProgress\ttrue\n",
      "spark.port.maxRetries\t100\n",
      "Configuration data after setup:\n",
      "spark.blockManager.port:\t5101\n",
      "spark.eventLog.enabled:\ttrue\n",
      "spark.ui.proxyBase:\t/proxy/application_1618913605843_3871\n",
      "spark.yarn.access.hadoopFileSystems:\tanalytix\n",
      "spark.network.crypto.enabled:\ttrue\n",
      "spark.eventLog.dir:\thdfs://analytix//var/log/spark-history\n",
      "spark.yarn.historyServer.address:\tithdp1101.cern.ch:18080\n",
      "spark.driver.memory:\t4g\n",
      "spark.executor.extraJavaOptions:\t-XX:+UseG1GC\n",
      "spark.executorEnv.PYTHONPATH:\t/eos/user/s/smetaj//.local/lib/python3.7/site-packages:/cvmfs/sft.cern.ch/lcg/views/LCG_97apython3/x86_64-centos7-gcc8-opt/python:/cvmfs/sft.cern.ch/lcg/views/LCG_97apython3/x86_64-centos7-gcc8-opt/lib:/cvmfs/sft.cern.ch/lcg/views/LCG_97apython3/x86_64-centos7-gcc8-opt/lib/python3.7/site-packages<CPS>{{PWD}}/pyspark.zip<CPS>{{PWD}}/py4j-0.10.7-src.zip\n",
      "spark.authenticate.enableSaslEncryption:\ttrue\n",
      "spark.executor.extraLibraryPath:\t/usr/hdp/hadoop/lib/native\n",
      "spark.driver.host:\tswan006.cern.ch\n",
      "spark.driver.appUIAddress:\thttp://swan006.cern.ch:5289\n",
      "spark.dynamicAllocation.maxExecutors:\t64\n",
      "spark.org.apache.hadoop.yarn.server.webproxy.amfilter.AmIpFilter.param.RM_HA_URLS:\tithdp1101.cern.ch:8088,ithdp2101.cern.ch:8088\n",
      "spark.org.apache.hadoop.yarn.server.webproxy.amfilter.AmIpFilter.param.PROXY_HOSTS:\tithdp1101.cern.ch,ithdp2101.cern.ch\n",
      "spark.app.id:\tapplication_1618913605843_3871\n",
      "spark.executor.instances:\t2\n",
      "spark.extraListeners:\tsparkmonitor.listener.JupyterSparkMonitorListener\n",
      "spark.serializer.objectStreamReset:\t100\n",
      "spark.org.apache.hadoop.yarn.server.webproxy.amfilter.AmIpFilter.param.PROXY_URI_BASES:\thttp://ithdp1101.cern.ch:8088/proxy/application_1618913605843_3871,http://ithdp2101.cern.ch:8088/proxy/application_1618913605843_3871\n",
      "spark.submit.deployMode:\tclient\n",
      "spark.ui.filters:\torg.apache.hadoop.yarn.server.webproxy.amfilter.AmIpFilter\n",
      "spark.executor.memory:\t2g\n",
      "spark.shuffle.service.enabled:\ttrue\n",
      "spark.ui.port:\t5289\n",
      "spark.shuffle.useOldFetchProtocol:\ttrue\n",
      "spark.dynamicAllocation.minExecutors:\t2\n",
      "spark.executor.id:\tdriver\n",
      "spark.driver.extraClassPath:\t/eos/project/s/swan/public/hadoop-mapreduce-client-core-2.6.0-cdh5.7.6.jar:/usr/local/lib/swan/extensions/sparkmonitor/listener_2.11.jar\n",
      "spark.executor.cores:\t2\n",
      "spark.driver.port:\t5133\n",
      "spark.master:\tyarn\n",
      "spark.driver.blockManager.port:\t5157\n",
      "spark.driver.extraJavaOptions:\t-Dlog4j.configuration=file:/tmp/tmp7hep26vr\n",
      "spark.driver.extraLibraryPath:\t/usr/hdp/hadoop/lib/native\n",
      "spark.rdd.compress:\tTrue\n",
      "spark.app.name:\tpyspark_shell_swan\n",
      "spark.executorEnv.LD_LIBRARY_PATH:\t/cvmfs/sft.cern.ch/lcg/views/LCG_97apython3/x86_64-centos7-gcc8-opt/lib/python3.7/site-packages/torch/lib:/cvmfs/sft.cern.ch/lcg/views/LCG_97apython3/x86_64-centos7-gcc8-opt/lib/python3.7/site-packages/tensorflow:/cvmfs/sft.cern.ch/lcg/views/LCG_97apython3/x86_64-centos7-gcc8-opt/lib/python3.7/site-packages/tensorflow/contrib/tensor_forest:/cvmfs/sft.cern.ch/lcg/views/LCG_97apython3/x86_64-centos7-gcc8-opt/lib/python3.7/site-packages/tensorflow/python/framework:/cvmfs/sft.cern.ch/lcg/releases/java/8u222-884d8/x86_64-centos7-gcc8-opt/jre/lib/amd64:/cvmfs/sft.cern.ch/lcg/views/LCG_97apython3/x86_64-centos7-gcc8-opt/lib64:/cvmfs/sft.cern.ch/lcg/views/LCG_97apython3/x86_64-centos7-gcc8-opt/lib:/cvmfs/sft.cern.ch/lcg/releases/gcc/8.3.0-cebb0/x86_64-centos7/lib:/cvmfs/sft.cern.ch/lcg/releases/gcc/8.3.0-cebb0/x86_64-centos7/lib64:/cvmfs/sft.cern.ch/lcg/releases/binutils/2.30-e5b21/x86_64-centos7/lib:/usr/local/lib/:/cvmfs/sft.cern.ch/lcg/releases/R/3.6.3-ca0ad/x86_64-centos7-gcc8-opt/lib64/R/library/readr/rcon\n",
      "spark.yarn.isPython:\ttrue\n",
      "spark.dynamicAllocation.enabled:\ttrue\n",
      "spark.ui.showConsoleProgress:\ttrue\n",
      "spark.authenticate:\ttrue\n",
      "spark.port.maxRetries:\t100\n",
      "[('spark.blockManager.port', '5101'), ('spark.eventLog.enabled', 'true'), ('spark.ui.proxyBase', '/proxy/application_1618913605843_3871'), ('spark.yarn.access.hadoopFileSystems', 'analytix'), ('spark.network.crypto.enabled', 'true'), ('spark.eventLog.dir', 'hdfs://analytix//var/log/spark-history'), ('spark.yarn.historyServer.address', 'ithdp1101.cern.ch:18080'), ('spark.driver.memory', '4g'), ('spark.executor.extraJavaOptions', '-XX:+UseG1GC'), ('spark.executorEnv.PYTHONPATH', '/eos/user/s/smetaj//.local/lib/python3.7/site-packages:/cvmfs/sft.cern.ch/lcg/views/LCG_97apython3/x86_64-centos7-gcc8-opt/python:/cvmfs/sft.cern.ch/lcg/views/LCG_97apython3/x86_64-centos7-gcc8-opt/lib:/cvmfs/sft.cern.ch/lcg/views/LCG_97apython3/x86_64-centos7-gcc8-opt/lib/python3.7/site-packages<CPS>{{PWD}}/pyspark.zip<CPS>{{PWD}}/py4j-0.10.7-src.zip'), ('spark.authenticate.enableSaslEncryption', 'true'), ('spark.executor.extraLibraryPath', '/usr/hdp/hadoop/lib/native'), ('spark.driver.host', 'swan006.cern.ch'), ('spark.driver.appUIAddress', 'http://swan006.cern.ch:5289'), ('spark.dynamicAllocation.maxExecutors', '64'), ('spark.org.apache.hadoop.yarn.server.webproxy.amfilter.AmIpFilter.param.RM_HA_URLS', 'ithdp1101.cern.ch:8088,ithdp2101.cern.ch:8088'), ('spark.org.apache.hadoop.yarn.server.webproxy.amfilter.AmIpFilter.param.PROXY_HOSTS', 'ithdp1101.cern.ch,ithdp2101.cern.ch'), ('spark.app.id', 'application_1618913605843_3871'), ('spark.executor.instances', '2'), ('spark.extraListeners', 'sparkmonitor.listener.JupyterSparkMonitorListener'), ('spark.serializer.objectStreamReset', '100'), ('spark.org.apache.hadoop.yarn.server.webproxy.amfilter.AmIpFilter.param.PROXY_URI_BASES', 'http://ithdp1101.cern.ch:8088/proxy/application_1618913605843_3871,http://ithdp2101.cern.ch:8088/proxy/application_1618913605843_3871'), ('spark.submit.deployMode', 'client'), ('spark.ui.filters', 'org.apache.hadoop.yarn.server.webproxy.amfilter.AmIpFilter'), ('spark.executor.memory', '2g'), ('spark.shuffle.service.enabled', 'true'), ('spark.ui.port', '5289'), ('spark.shuffle.useOldFetchProtocol', 'true'), ('spark.dynamicAllocation.minExecutors', '2'), ('spark.executor.id', 'driver'), ('spark.driver.extraClassPath', '/eos/project/s/swan/public/hadoop-mapreduce-client-core-2.6.0-cdh5.7.6.jar:/usr/local/lib/swan/extensions/sparkmonitor/listener_2.11.jar'), ('spark.executor.cores', '2'), ('spark.driver.port', '5133'), ('spark.master', 'yarn'), ('spark.driver.blockManager.port', '5157'), ('spark.driver.extraJavaOptions', '-Dlog4j.configuration=file:/tmp/tmp7hep26vr'), ('spark.driver.extraLibraryPath', '/usr/hdp/hadoop/lib/native'), ('spark.rdd.compress', 'True'), ('spark.app.name', 'pyspark_shell_swan'), ('spark.executorEnv.LD_LIBRARY_PATH', '/cvmfs/sft.cern.ch/lcg/views/LCG_97apython3/x86_64-centos7-gcc8-opt/lib/python3.7/site-packages/torch/lib:/cvmfs/sft.cern.ch/lcg/views/LCG_97apython3/x86_64-centos7-gcc8-opt/lib/python3.7/site-packages/tensorflow:/cvmfs/sft.cern.ch/lcg/views/LCG_97apython3/x86_64-centos7-gcc8-opt/lib/python3.7/site-packages/tensorflow/contrib/tensor_forest:/cvmfs/sft.cern.ch/lcg/views/LCG_97apython3/x86_64-centos7-gcc8-opt/lib/python3.7/site-packages/tensorflow/python/framework:/cvmfs/sft.cern.ch/lcg/releases/java/8u222-884d8/x86_64-centos7-gcc8-opt/jre/lib/amd64:/cvmfs/sft.cern.ch/lcg/views/LCG_97apython3/x86_64-centos7-gcc8-opt/lib64:/cvmfs/sft.cern.ch/lcg/views/LCG_97apython3/x86_64-centos7-gcc8-opt/lib:/cvmfs/sft.cern.ch/lcg/releases/gcc/8.3.0-cebb0/x86_64-centos7/lib:/cvmfs/sft.cern.ch/lcg/releases/gcc/8.3.0-cebb0/x86_64-centos7/lib64:/cvmfs/sft.cern.ch/lcg/releases/binutils/2.30-e5b21/x86_64-centos7/lib:/usr/local/lib/:/cvmfs/sft.cern.ch/lcg/releases/R/3.6.3-ca0ad/x86_64-centos7-gcc8-opt/lib64/R/library/readr/rcon'), ('spark.yarn.isPython', 'true'), ('spark.dynamicAllocation.enabled', 'true'), ('spark.ui.showConsoleProgress', 'true'), ('spark.authenticate', 'true'), ('spark.port.maxRetries', '100')]\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "SPARK CONTEXT: <SparkContext master=yarn appName=pyspark_shell_swan>\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "SPARK OBJECT: <pyspark.sql.session.SparkSession object at 0x7efecf8a7990>\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "RESOURCE DETAILS: demo_config_inference.json\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "{\n",
      "    \"hostgroups\": [\n",
      "        \"cloud_compute/level2/batch/gva_project_013\"\n",
      "    ],\n",
      "    \"code_project_name\": \"demo_AD_System\",\n",
      "    \"local_cache_folder\": \"/eos/project/i/it-cloud-data-analytics/demo_AD_System/local_cache_inference/\",\n",
      "    \"hdfs_out_folder\": \"/user/smetaj/demo_AD_System/raw_parquet_inference/\",\n",
      "    \"hdfs_cache_folder\": \"/user/smetaj/demo_AD_System/compressed_inference/\",\n",
      "    \"normalization_out_folder\": \"/user/smetaj/demo_AD_System/normalization/\",\n",
      "    \"overwrite_on_hdfs\": true,\n",
      "    \"overwrite_normalization\": true,\n",
      "    \"aggregate_every_n_minutes\": 10,\n",
      "    \"history_steps\": 48,\n",
      "    \"slide_steps\": 48,\n",
      "    \"future_steps\": 0,\n",
      "    \"date_start\": \"2021-03-23\",\n",
      "    \"date_end_excluded\": \"2021-03-30\",\n",
      "    \"date_start_normalization\": \"2021-03-23\",\n",
      "    \"date_end_normalization_excluded\": \"2021-03-30\",\n",
      "    \"selected_plugins\": {\n",
      "        \"load_longterm\": {\n",
      "            \"value_instance\": \"longterm\",\n",
      "            \"plugin_name\": \"load\"\n",
      "        },\n",
      "        \"memory__memory_free\": {\n",
      "            \"plugin_instance\": \"\",\n",
      "            \"type\": \"memory\",\n",
      "            \"type_instance\": \"free\",\n",
      "            \"plugin_name\": \"memory\"\n",
      "        },\n",
      "        \"swap_swapfile_swap_free\": {\n",
      "            \"type\": \"swap\",\n",
      "            \"type_instance\": \"free\",\n",
      "            \"plugin_name\": \"swap\"\n",
      "        }\n",
      "    }\n",
      "}\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "CHECK PRESENCE OF NORMALIZATION COEFFICIENTS...\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "NORMALIZATION COEFFICIENTS FOUND :)\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "SUCCESS (inspect the first 40 rows):\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "                                    hostgroup                   plugin  \\\n",
      "0  cloud_compute/level2/batch/gva_project_013  swap_swapfile_swap_free   \n",
      "1  cloud_compute/level2/batch/gva_project_013      memory__memory_free   \n",
      "2  cloud_compute/level2/batch/gva_project_013            load_longterm   \n",
      "\n",
      "           mean        stddev  \n",
      "0  4.052017e+10  2.408829e+09  \n",
      "1  7.446611e+08  2.653568e+08  \n",
      "2  7.320000e-01  2.960000e-01  \n"
     ]
    }
   ],
   "source": [
    "for file in [json_file_train, json_file_inference]:\n",
    "    try:\n",
    "        sys.argv = ['', '--resource_file', file]\n",
    "        DM.normalization_presence()\n",
    "    except:\n",
    "        pass"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "figured-amount",
   "metadata": {},
   "source": [
    "#### Compute Normalization\n",
    "Now we are sure that we have no data and no normalization coefficients... we have to download them! Let's start with the normalization coefficients!\n",
    "\n",
    "Note that the function will use the same path for both both train and inference (because the hostgroup, the dates and the plugins are the same!)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "coated-indonesia",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-04-23T08:03:45.245270Z",
     "start_time": "2021-04-23T08:02:41.530529Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "PREPARING SPARK:\n",
      "\n",
      "pppppppppppppppppppppppppppppppppppppppppppppppppp\n",
      "\n",
      "Configuration data:\n",
      "spark.eventLog.enabled\ttrue\n",
      "spark.ui.proxyBase\t/proxy/application_1618913605843_3871\n",
      "spark.yarn.access.hadoopFileSystems\tanalytix\n",
      "spark.authenticate\tTrue\n",
      "spark.executorEnv.JAVA_HOME\t/cvmfs/sft.cern.ch/lcg/releases/java/8u222-884d8/x86_64-centos7-gcc8-opt\n",
      "spark.eventLog.dir\thdfs://analytix//var/log/spark-history\n",
      "spark.yarn.historyServer.address\tithdp1101.cern.ch:18080\n",
      "spark.network.crypto.enabled\tTrue\n",
      "spark.executor.extraJavaOptions\t-XX:+UseG1GC\n",
      "spark.driver.memory\t1g\n",