summaryrefslogtreecommitdiff
path: root/python-anomaly-detection-framework.spec
blob: 565374b89900e43ecf3dc0dbfb385ad8257f9583 (plain)
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
%global _empty_manifest_terminate_build 0
Name:		python-anomaly-detection-framework
Version:	0.0.21
Release:	1
Summary:	Anomaly Detection Framework allows us to calculate Anomalities on any Time - Series Data Sets. It has an interface which is easy to manage to train - predict with given dataset.
License:	MIT License
URL:		https://github.com/caglanakpinar/tsad
Source0:	https://mirrors.aliyun.com/pypi/web/packages/46/8d/117030c79a21530c61b51ab153f44bd15aebe440f8fe4422df22f18a721f/anomaly_detection_framework-0.0.21.tar.gz
BuildArch:	noarch


%description
# Running Platform
**1. You have to specify you directory**
```
from anomaly_detection import ad_execute as ad_exec
ad = ad_exec.AnomalyDetection(path='./Desktop', environment='local)
ad.init(apis=None)
```
Once, you have assigned the path, a folder called ***Anomaly_Detection_Framework*** will be created inside of it. This folder includes models, data, logs, and docs folders.Trained models will be imported to the ***models*** folder. ***logs*** folder for both ***ml_execute***, ***model_iso_f***, ***model_prophet***, and ***model_lstm*** of log files will be created at logs file. 
Your ***.csv***, ***.json*** or ***.yaml*** data source file must be copied to the data folder which is at the ***Anomaly_Detection_Framework*** folder. If you are connecting to Google Big Query data source, Big Query API (.json file) must be copied into the "data" folder. Once, prediction jobs have been initialized output .csv file is imported to the ***data*** folder.
The given path will be your workspace where all data-source you can store or get from it. By using "AnomalyDetection" module of ***path*** argument you can specify the path. If there are files which are already exists on the given path, you may remove them by using ***remove_existed = True*** (default ***False***)
- ###### ***anomaly_detection.AnomalyDetection***:
    - **AnomalyDetection**
        ***path :*** The location where you are willing to create models and prediction data set.
        ***enviroment :** local or docker
        ***host :*** local or docker 
        ***remove_existed :*** remove data from the location where you have entered as a path.
        ***master_node :*** if ***False***, you must enter the services of information manually (port host, etc.). This allows the user to initialize each service on different locations or servers or workers.
        If ***False*** there will not be a web interface. Once you create a master node, in order to use other services, you have to clarify these services on it. The master node will lead the other services  which has additional web interface service that runs on it
    - **init**
        This initializes the folders. Checks the available ports for services in the range between *6000 - 7000*. Updates the ***apis.yaml*** if it is necessary.
        ***apis :***
        ```
         services = {
                     'model_iso_f': {'port': 6000, 'host': '127.0.0.1'},
                     'model_lstm': {'port': 6001, 'host': '127.0.0.1'}
                    }
        ad = ad_exec.AnomalyDetection(path='./Desktop', environment='local, master_node=False)
        ad.init(apis=services)
        ```
        Example above, It will initializes ***model_iso_f*** and ***model_lstm*** services. Both will be run on a given host with given ports. However given ports are used, it will assign another port automatically.
****
**2. Run The PLatform**
```
ad.run_platform()
```
This process initializes the platform. Once you have run the code above you may have seen the services are running. 
If you assign ***master_node = True*** you may use enter to web interface from [http://127.0.0.1:7002/](http://127.0.0.1:7002/). 
If ***7002*** port is used from another platform directly platform assigns +1 port. (7003,7004, 7005, ..)
**2. Data Source**
You can connect to data source from [Data Source Configuraitons](http://127.0.0.1:7002/configs).
There is two option to connect to a data source. You can integrate on the web interface or you can use ***AnomalyDetection*** method in order to able to connect a data source.
```
from anomaly_detection import ad_execute as ad_exec
# create your platform folders.
ad = ad_exec.AnomalyDetection(path='./Desktop', environment='local')
# copy folders
ad.init()
# initialize services
ad.run_platform()
# create data source with Google BigQuery
ad.create_data_source(data_source_type='googlebigquery',
                      data_query_path="""
                                            SELECT
                                              fullVisitorId,
                                              TIMESTAMP_SECONDS(visitStartTime) as date, 
                                              CASE WHEN type = 'PAGE' THEN 'PAGE'
                                              ELSE eventAction END as event_type_and_category,
                                              MIN(time) / 1000 as time_diff
                                            FROM (SELECT 
                                                    geoNetwork.city as city,
                                                    device.browser browser,
                                                    device.deviceCategory deviceCategory,
                                                    visitStartTime,
                                                    hits.eventInfo.eventAction eventAction, 
                                                    hits.eventInfo.eventCategory eventCategory, 
                                                    hits.type type, 
                                                    hits.page.pageTitle pageTitle, 
                                                    hits.time time,
                                                    fullVisitorId as fullVisitorId
                                                  FROM `bigquery-public-data.google_analytics_sample.ga_sessions_*`,
                                                       UNNEST(hits) as hits
                                                 ) as a
                                            WHERE pageTitle != 'Home'
                                            GROUP BY    
                                                        visitStartTime,
                                                        deviceCategory,
                                                        browser,
                                                        city,
                                                        eventAction, 
                                                        eventCategory, 
                                                        type, 
                                                        pageTitle,
                                                        eventCategory,
                                                        fullVisitorId
                                            ORDER BY fullVisitorId, visitStartTime 
                      """,
                      db='flash-clover-**********.json',
                      host=None,
                      port=None,
                      user=None,
                      pw=None)
```
Example above, it is created a connector to Google BigQuery by using ***AnomalyDtection*** method.
-   **Connection PostgreSQL - MS  SQL** 
![connection_postgre](https://user-images.githubusercontent.com/26736844/83358571-27ab5200-a37d-11ea-95b9-b91b1ee38269.gif)
****
-   **Connection .csv - .json - .yaml**
![Screen Recording 2020-06-06 at 12 33 AM](https://user-images.githubusercontent.com/26736844/83924666-d1c81700-a78d-11ea-8972-d2c14682440d.gif)
****
-   **Connection Google BigQuery**
![Screen Recording 2020-06-06 at 12 49 AM](https://user-images.githubusercontent.com/26736844/83925434-d1308000-a78f-11ea-8753-847e48f73ff7.gif)
****
-   **Create Tasks**
    -   ***Model Dimensions :*** You may want to Train your model with separated Groups. The platform automatically finds the date part as dimensions from the ***Date Indicator***. However external dimension can be included by assigning from here.
    -   ***Date Indicator :*** You have to specify the date column from your raw data set. ***This is a mandatory field***.
    -   ***Anomaly Feature :*** In order to find the anomaly values, you have to specify which column we are investigating for. ***This is a mandatory field***.
    -   ***Train :*** Choose the schedule time period for train task. The chosen period will be started depending on the time where it is assigned at **Train Job Dates - Start***. If **Train Job Dates - Start*** is not assigned, the job date will automatically assign as the current date and it can be started immediately. Parameter Tunning also runs when train task runs for the first time.
    -   ***Prediction :*** As like Train Task, Prediction task also be scheduled similar way. However, you have to assign ***Prediction Job Dates - Start *** while you are creating task.
    -   ***Parameter Tuning :*** Parameter Tuning also is able to be scheduled. However, the starting date is assigning related to ***Train Job Dates - Start***. Parameter tunning also runs when train task runs for the first time.
    -   ***Here are the schedule options :***
        -   *Daily :* Each day, the job process will start with a given time where you assign at ***Train Job Dates - Start***. 
        -   *only once :* It can be triggered just once. 
        -   *Mondays ... Sundays :* Assigned day of the week, the job will start.
        -   *Weekly :* Job will run every 7 days after it is started.
        -   *Every 2 Weeks :* 14 days of the time period.
        -   *Monthly :* every 30 days of the time period.
        -   *Every Minute :* Every minute job can be triggered. 
        -   *Every Second :* Every each second job can be triggered. 
You can create 3 main Machine Learning task which generally uses for each Data Scientist. You may create a task and schedule them separately. For instance, train can run every week, prediction can create outputs daily, and every each month parameters can be optimized by parameter tunning task.
This process is only available after Data Source is created.
Once you create the data source you can see the column names on ***Model Dimensions***, ***Date Indicator***, ***Anomaly Feature***.
You can not create tasks separately.
![create_tasks](https://user-images.githubusercontent.com/26736844/83358834-e320b600-a37e-11ea-91d7-a0dbb351ea91.gif)
- **Job Run**
Once, you create tasks, jobs are eligible to run periodically. You can also run below codes rather than using application interface;
```
ad.manage_train(stop=False)
ad.manage_prediction(stop=False)
ad.manage_parameter_tuning(stop=False)
```
*** AnomalyDetection.manage_train :***
    ***-   stop :*** If False stops running training scheduled task.
*** AnomalyDetection.manage_prediction :***
    ***-   stop :*** If False stops running prediction scheduled task.
*** AnomalyDetection.manage_parameter_tuning :***
    ***-   stop :*** If False stops running parameter tuning scheduled task.
![Job Run 2020-06-06 at 01 25 AM](https://user-images.githubusercontent.com/26736844/83927175-cc21ff80-a794-11ea-885b-e7ec5bd38097.gif)
- **Dashboard**
Once you assign the data source connection and create the task automatically, the dashboard will be created directly according to the model dimension.
After ***Data Source*** and ***Create Task*** are done, in order to initialize the platform with the code below;
```
ad = anomaly_detection.Ad_execute.AnomalyDetection(path='./Desktop', environment='local').reset_web_app()
ad.reset_web_app()
```
![Dashboard 2020-06-20 at 05 03 PM](https://user-images.githubusercontent.com/26736844/85203715-3b146200-b318-11ea-8e01-7c074db804e3.gif)

%package -n python3-anomaly-detection-framework
Summary:	Anomaly Detection Framework allows us to calculate Anomalities on any Time - Series Data Sets. It has an interface which is easy to manage to train - predict with given dataset.
Provides:	python-anomaly-detection-framework
BuildRequires:	python3-devel
BuildRequires:	python3-setuptools
BuildRequires:	python3-pip
%description -n python3-anomaly-detection-framework
# Running Platform
**1. You have to specify you directory**
```
from anomaly_detection import ad_execute as ad_exec
ad = ad_exec.AnomalyDetection(path='./Desktop', environment='local)
ad.init(apis=None)
```
Once, you have assigned the path, a folder called ***Anomaly_Detection_Framework*** will be created inside of it. This folder includes models, data, logs, and docs folders.Trained models will be imported to the ***models*** folder. ***logs*** folder for both ***ml_execute***, ***model_iso_f***, ***model_prophet***, and ***model_lstm*** of log files will be created at logs file. 
Your ***.csv***, ***.json*** or ***.yaml*** data source file must be copied to the data folder which is at the ***Anomaly_Detection_Framework*** folder. If you are connecting to Google Big Query data source, Big Query API (.json file) must be copied into the "data" folder. Once, prediction jobs have been initialized output .csv file is imported to the ***data*** folder.
The given path will be your workspace where all data-source you can store or get from it. By using "AnomalyDetection" module of ***path*** argument you can specify the path. If there are files which are already exists on the given path, you may remove them by using ***remove_existed = True*** (default ***False***)
- ###### ***anomaly_detection.AnomalyDetection***:
    - **AnomalyDetection**
        ***path :*** The location where you are willing to create models and prediction data set.
        ***enviroment :** local or docker
        ***host :*** local or docker 
        ***remove_existed :*** remove data from the location where you have entered as a path.
        ***master_node :*** if ***False***, you must enter the services of information manually (port host, etc.). This allows the user to initialize each service on different locations or servers or workers.
        If ***False*** there will not be a web interface. Once you create a master node, in order to use other services, you have to clarify these services on it. The master node will lead the other services  which has additional web interface service that runs on it
    - **init**
        This initializes the folders. Checks the available ports for services in the range between *6000 - 7000*. Updates the ***apis.yaml*** if it is necessary.
        ***apis :***
        ```
         services = {
                     'model_iso_f': {'port': 6000, 'host': '127.0.0.1'},
                     'model_lstm': {'port': 6001, 'host': '127.0.0.1'}
                    }
        ad = ad_exec.AnomalyDetection(path='./Desktop', environment='local, master_node=False)
        ad.init(apis=services)
        ```
        Example above, It will initializes ***model_iso_f*** and ***model_lstm*** services. Both will be run on a given host with given ports. However given ports are used, it will assign another port automatically.
****
**2. Run The PLatform**
```
ad.run_platform()
```
This process initializes the platform. Once you have run the code above you may have seen the services are running. 
If you assign ***master_node = True*** you may use enter to web interface from [http://127.0.0.1:7002/](http://127.0.0.1:7002/). 
If ***7002*** port is used from another platform directly platform assigns +1 port. (7003,7004, 7005, ..)
**2. Data Source**
You can connect to data source from [Data Source Configuraitons](http://127.0.0.1:7002/configs).
There is two option to connect to a data source. You can integrate on the web interface or you can use ***AnomalyDetection*** method in order to able to connect a data source.
```
from anomaly_detection import ad_execute as ad_exec
# create your platform folders.
ad = ad_exec.AnomalyDetection(path='./Desktop', environment='local')
# copy folders
ad.init()
# initialize services
ad.run_platform()
# create data source with Google BigQuery
ad.create_data_source(data_source_type='googlebigquery',
                      data_query_path="""
                                            SELECT
                                              fullVisitorId,
                                              TIMESTAMP_SECONDS(visitStartTime) as date, 
                                              CASE WHEN type = 'PAGE' THEN 'PAGE'
                                              ELSE eventAction END as event_type_and_category,
                                              MIN(time) / 1000 as time_diff
                                            FROM (SELECT 
                                                    geoNetwork.city as city,
                                                    device.browser browser,
                                                    device.deviceCategory deviceCategory,
                                                    visitStartTime,
                                                    hits.eventInfo.eventAction eventAction, 
                                                    hits.eventInfo.eventCategory eventCategory, 
                                                    hits.type type, 
                                                    hits.page.pageTitle pageTitle, 
                                                    hits.time time,
                                                    fullVisitorId as fullVisitorId
                                                  FROM `bigquery-public-data.google_analytics_sample.ga_sessions_*`,
                                                       UNNEST(hits) as hits
                                                 ) as a
                                            WHERE pageTitle != 'Home'
                                            GROUP BY    
                                                        visitStartTime,
                                                        deviceCategory,
                                                        browser,
                                                        city,
                                                        eventAction, 
                                                        eventCategory, 
                                                        type, 
                                                        pageTitle,
                                                        eventCategory,
                                                        fullVisitorId
                                            ORDER BY fullVisitorId, visitStartTime 
                      """,
                      db='flash-clover-**********.json',
                      host=None,
                      port=None,
                      user=None,
                      pw=None)
```
Example above, it is created a connector to Google BigQuery by using ***AnomalyDtection*** method.
-   **Connection PostgreSQL - MS  SQL** 
![connection_postgre](https://user-images.githubusercontent.com/26736844/83358571-27ab5200-a37d-11ea-95b9-b91b1ee38269.gif)
****
-   **Connection .csv - .json - .yaml**
![Screen Recording 2020-06-06 at 12 33 AM](https://user-images.githubusercontent.com/26736844/83924666-d1c81700-a78d-11ea-8972-d2c14682440d.gif)
****
-   **Connection Google BigQuery**
![Screen Recording 2020-06-06 at 12 49 AM](https://user-images.githubusercontent.com/26736844/83925434-d1308000-a78f-11ea-8753-847e48f73ff7.gif)
****
-   **Create Tasks**
    -   ***Model Dimensions :*** You may want to Train your model with separated Groups. The platform automatically finds the date part as dimensions from the ***Date Indicator***. However external dimension can be included by assigning from here.
    -   ***Date Indicator :*** You have to specify the date column from your raw data set. ***This is a mandatory field***.
    -   ***Anomaly Feature :*** In order to find the anomaly values, you have to specify which column we are investigating for. ***This is a mandatory field***.
    -   ***Train :*** Choose the schedule time period for train task. The chosen period will be started depending on the time where it is assigned at **Train Job Dates - Start***. If **Train Job Dates - Start*** is not assigned, the job date will automatically assign as the current date and it can be started immediately. Parameter Tunning also runs when train task runs for the first time.
    -   ***Prediction :*** As like Train Task, Prediction task also be scheduled similar way. However, you have to assign ***Prediction Job Dates - Start *** while you are creating task.
    -   ***Parameter Tuning :*** Parameter Tuning also is able to be scheduled. However, the starting date is assigning related to ***Train Job Dates - Start***. Parameter tunning also runs when train task runs for the first time.
    -   ***Here are the schedule options :***
        -   *Daily :* Each day, the job process will start with a given time where you assign at ***Train Job Dates - Start***. 
        -   *only once :* It can be triggered just once. 
        -   *Mondays ... Sundays :* Assigned day of the week, the job will start.
        -   *Weekly :* Job will run every 7 days after it is started.
        -   *Every 2 Weeks :* 14 days of the time period.
        -   *Monthly :* every 30 days of the time period.
        -   *Every Minute :* Every minute job can be triggered. 
        -   *Every Second :* Every each second job can be triggered. 
You can create 3 main Machine Learning task which generally uses for each Data Scientist. You may create a task and schedule them separately. For instance, train can run every week, prediction can create outputs daily, and every each month parameters can be optimized by parameter tunning task.
This process is only available after Data Source is created.
Once you create the data source you can see the column names on ***Model Dimensions***, ***Date Indicator***, ***Anomaly Feature***.
You can not create tasks separately.
![create_tasks](https://user-images.githubusercontent.com/26736844/83358834-e320b600-a37e-11ea-91d7-a0dbb351ea91.gif)
- **Job Run**
Once, you create tasks, jobs are eligible to run periodically. You can also run below codes rather than using application interface;
```
ad.manage_train(stop=False)
ad.manage_prediction(stop=False)
ad.manage_parameter_tuning(stop=False)
```
*** AnomalyDetection.manage_train :***
    ***-   stop :*** If False stops running training scheduled task.
*** AnomalyDetection.manage_prediction :***
    ***-   stop :*** If False stops running prediction scheduled task.
*** AnomalyDetection.manage_parameter_tuning :***
    ***-   stop :*** If False stops running parameter tuning scheduled task.
![Job Run 2020-06-06 at 01 25 AM](https://user-images.githubusercontent.com/26736844/83927175-cc21ff80-a794-11ea-885b-e7ec5bd38097.gif)
- **Dashboard**
Once you assign the data source connection and create the task automatically, the dashboard will be created directly according to the model dimension.
After ***Data Source*** and ***Create Task*** are done, in order to initialize the platform with the code below;
```
ad = anomaly_detection.Ad_execute.AnomalyDetection(path='./Desktop', environment='local').reset_web_app()
ad.reset_web_app()
```
![Dashboard 2020-06-20 at 05 03 PM](https://user-images.githubusercontent.com/26736844/85203715-3b146200-b318-11ea-8e01-7c074db804e3.gif)

%package help
Summary:	Development documents and examples for anomaly-detection-framework
Provides:	python3-anomaly-detection-framework-doc
%description help
# Running Platform
**1. You have to specify you directory**
```
from anomaly_detection import ad_execute as ad_exec
ad = ad_exec.AnomalyDetection(path='./Desktop', environment='local)
ad.init(apis=None)
```
Once, you have assigned the path, a folder called ***Anomaly_Detection_Framework*** will be created inside of it. This folder includes models, data, logs, and docs folders.Trained models will be imported to the ***models*** folder. ***logs*** folder for both ***ml_execute***, ***model_iso_f***, ***model_prophet***, and ***model_lstm*** of log files will be created at logs file. 
Your ***.csv***, ***.json*** or ***.yaml*** data source file must be copied to the data folder which is at the ***Anomaly_Detection_Framework*** folder. If you are connecting to Google Big Query data source, Big Query API (.json file) must be copied into the "data" folder. Once, prediction jobs have been initialized output .csv file is imported to the ***data*** folder.
The given path will be your workspace where all data-source you can store or get from it. By using "AnomalyDetection" module of ***path*** argument you can specify the path. If there are files which are already exists on the given path, you may remove them by using ***remove_existed = True*** (default ***False***)
- ###### ***anomaly_detection.AnomalyDetection***:
    - **AnomalyDetection**
        ***path :*** The location where you are willing to create models and prediction data set.
        ***enviroment :** local or docker
        ***host :*** local or docker 
        ***remove_existed :*** remove data from the location where you have entered as a path.
        ***master_node :*** if ***False***, you must enter the services of information manually (port host, etc.). This allows the user to initialize each service on different locations or servers or workers.
        If ***False*** there will not be a web interface. Once you create a master node, in order to use other services, you have to clarify these services on it. The master node will lead the other services  which has additional web interface service that runs on it
    - **init**
        This initializes the folders. Checks the available ports for services in the range between *6000 - 7000*. Updates the ***apis.yaml*** if it is necessary.
        ***apis :***
        ```
         services = {
                     'model_iso_f': {'port': 6000, 'host': '127.0.0.1'},
                     'model_lstm': {'port': 6001, 'host': '127.0.0.1'}
                    }
        ad = ad_exec.AnomalyDetection(path='./Desktop', environment='local, master_node=False)
        ad.init(apis=services)
        ```
        Example above, It will initializes ***model_iso_f*** and ***model_lstm*** services. Both will be run on a given host with given ports. However given ports are used, it will assign another port automatically.
****
**2. Run The PLatform**
```
ad.run_platform()
```
This process initializes the platform. Once you have run the code above you may have seen the services are running. 
If you assign ***master_node = True*** you may use enter to web interface from [http://127.0.0.1:7002/](http://127.0.0.1:7002/). 
If ***7002*** port is used from another platform directly platform assigns +1 port. (7003,7004, 7005, ..)
**2. Data Source**
You can connect to data source from [Data Source Configuraitons](http://127.0.0.1:7002/configs).
There is two option to connect to a data source. You can integrate on the web interface or you can use ***AnomalyDetection*** method in order to able to connect a data source.
```
from anomaly_detection import ad_execute as ad_exec
# create your platform folders.
ad = ad_exec.AnomalyDetection(path='./Desktop', environment='local')
# copy folders
ad.init()
# initialize services
ad.run_platform()
# create data source with Google BigQuery
ad.create_data_source(data_source_type='googlebigquery',
                      data_query_path="""
                                            SELECT
                                              fullVisitorId,
                                              TIMESTAMP_SECONDS(visitStartTime) as date, 
                                              CASE WHEN type = 'PAGE' THEN 'PAGE'
                                              ELSE eventAction END as event_type_and_category,
                                              MIN(time) / 1000 as time_diff
                                            FROM (SELECT 
                                                    geoNetwork.city as city,
                                                    device.browser browser,
                                                    device.deviceCategory deviceCategory,
                                                    visitStartTime,
                                                    hits.eventInfo.eventAction eventAction, 
                                                    hits.eventInfo.eventCategory eventCategory, 
                                                    hits.type type, 
                                                    hits.page.pageTitle pageTitle, 
                                                    hits.time time,
                                                    fullVisitorId as fullVisitorId
                                                  FROM `bigquery-public-data.google_analytics_sample.ga_sessions_*`,
                                                       UNNEST(hits) as hits
                                                 ) as a
                                            WHERE pageTitle != 'Home'
                                            GROUP BY    
                                                        visitStartTime,
                                                        deviceCategory,
                                                        browser,
                                                        city,
                                                        eventAction, 
                                                        eventCategory, 
                                                        type, 
                                                        pageTitle,
                                                        eventCategory,
                                                        fullVisitorId
                                            ORDER BY fullVisitorId, visitStartTime 
                      """,
                      db='flash-clover-**********.json',
                      host=None,
                      port=None,
                      user=None,
                      pw=None)
```
Example above, it is created a connector to Google BigQuery by using ***AnomalyDtection*** method.
-   **Connection PostgreSQL - MS  SQL** 
![connection_postgre](https://user-images.githubusercontent.com/26736844/83358571-27ab5200-a37d-11ea-95b9-b91b1ee38269.gif)
****
-   **Connection .csv - .json - .yaml**
![Screen Recording 2020-06-06 at 12 33 AM](https://user-images.githubusercontent.com/26736844/83924666-d1c81700-a78d-11ea-8972-d2c14682440d.gif)
****
-   **Connection Google BigQuery**
![Screen Recording 2020-06-06 at 12 49 AM](https://user-images.githubusercontent.com/26736844/83925434-d1308000-a78f-11ea-8753-847e48f73ff7.gif)
****
-   **Create Tasks**
    -   ***Model Dimensions :*** You may want to Train your model with separated Groups. The platform automatically finds the date part as dimensions from the ***Date Indicator***. However external dimension can be included by assigning from here.
    -   ***Date Indicator :*** You have to specify the date column from your raw data set. ***This is a mandatory field***.
    -   ***Anomaly Feature :*** In order to find the anomaly values, you have to specify which column we are investigating for. ***This is a mandatory field***.
    -   ***Train :*** Choose the schedule time period for train task. The chosen period will be started depending on the time where it is assigned at **Train Job Dates - Start***. If **Train Job Dates - Start*** is not assigned, the job date will automatically assign as the current date and it can be started immediately. Parameter Tunning also runs when train task runs for the first time.
    -   ***Prediction :*** As like Train Task, Prediction task also be scheduled similar way. However, you have to assign ***Prediction Job Dates - Start *** while you are creating task.
    -   ***Parameter Tuning :*** Parameter Tuning also is able to be scheduled. However, the starting date is assigning related to ***Train Job Dates - Start***. Parameter tunning also runs when train task runs for the first time.
    -   ***Here are the schedule options :***
        -   *Daily :* Each day, the job process will start with a given time where you assign at ***Train Job Dates - Start***. 
        -   *only once :* It can be triggered just once. 
        -   *Mondays ... Sundays :* Assigned day of the week, the job will start.
        -   *Weekly :* Job will run every 7 days after it is started.
        -   *Every 2 Weeks :* 14 days of the time period.
        -   *Monthly :* every 30 days of the time period.
        -   *Every Minute :* Every minute job can be triggered. 
        -   *Every Second :* Every each second job can be triggered. 
You can create 3 main Machine Learning task which generally uses for each Data Scientist. You may create a task and schedule them separately. For instance, train can run every week, prediction can create outputs daily, and every each month parameters can be optimized by parameter tunning task.
This process is only available after Data Source is created.
Once you create the data source you can see the column names on ***Model Dimensions***, ***Date Indicator***, ***Anomaly Feature***.
You can not create tasks separately.
![create_tasks](https://user-images.githubusercontent.com/26736844/83358834-e320b600-a37e-11ea-91d7-a0dbb351ea91.gif)
- **Job Run**
Once, you create tasks, jobs are eligible to run periodically. You can also run below codes rather than using application interface;
```
ad.manage_train(stop=False)
ad.manage_prediction(stop=False)
ad.manage_parameter_tuning(stop=False)
```
*** AnomalyDetection.manage_train :***
    ***-   stop :*** If False stops running training scheduled task.
*** AnomalyDetection.manage_prediction :***
    ***-   stop :*** If False stops running prediction scheduled task.
*** AnomalyDetection.manage_parameter_tuning :***
    ***-   stop :*** If False stops running parameter tuning scheduled task.
![Job Run 2020-06-06 at 01 25 AM](https://user-images.githubusercontent.com/26736844/83927175-cc21ff80-a794-11ea-885b-e7ec5bd38097.gif)
- **Dashboard**
Once you assign the data source connection and create the task automatically, the dashboard will be created directly according to the model dimension.
After ***Data Source*** and ***Create Task*** are done, in order to initialize the platform with the code below;
```
ad = anomaly_detection.Ad_execute.AnomalyDetection(path='./Desktop', environment='local').reset_web_app()
ad.reset_web_app()
```
![Dashboard 2020-06-20 at 05 03 PM](https://user-images.githubusercontent.com/26736844/85203715-3b146200-b318-11ea-8e01-7c074db804e3.gif)

%prep
%autosetup -n anomaly_detection_framework-0.0.21

%build
%py3_build

%install
%py3_install
install -d -m755 %{buildroot}/%{_pkgdocdir}
if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi
if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi
if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi
if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi
pushd %{buildroot}
if [ -d usr/lib ]; then
	find usr/lib -type f -printf "\"/%h/%f\"\n" >> filelist.lst
fi
if [ -d usr/lib64 ]; then
	find usr/lib64 -type f -printf "\"/%h/%f\"\n" >> filelist.lst
fi
if [ -d usr/bin ]; then
	find usr/bin -type f -printf "\"/%h/%f\"\n" >> filelist.lst
fi
if [ -d usr/sbin ]; then
	find usr/sbin -type f -printf "\"/%h/%f\"\n" >> filelist.lst
fi
touch doclist.lst
if [ -d usr/share/man ]; then
	find usr/share/man -type f -printf "\"/%h/%f.gz\"\n" >> doclist.lst
fi
popd
mv %{buildroot}/filelist.lst .
mv %{buildroot}/doclist.lst .

%files -n python3-anomaly-detection-framework -f filelist.lst
%dir %{python3_sitelib}/*

%files help -f doclist.lst
%{_docdir}/*

%changelog
* Tue Jun 20 2023 Python_Bot <Python_Bot@openeuler.org> - 0.0.21-1
- Package Spec generated