// detect anomalies of given param data according to given model id.
        // this function is in one task, and might take time.
        // return null if failed.
        public ANOMALY Detect(int idModel, Predict_Data data)
        {
            string fileName = "";
            List <CorrelatedFeatures> correlation = null;

            lock (L_NormalModels)
            {
                // get file name (json file). within our server program deleting files,
                // is only via the beginning of Main or via AnomalyDetectorsManager_instance.Remove(), and only 1 instance exists,
                // but we lock L_NormalModels so it won't be removed meanwhile
                if (L_NormalModels.ContainsKey(idModel) && L_NormalModels[idModel].status == MODEL.Status_Ready)
                {
                    fileName = L_NormalModels[idModel].FileName();
                }
                if (String.IsNullOrWhiteSpace(fileName))
                {
                    return(null);
                }
                // load normal model
                correlation = IO_Util.LoadNormalModel(fileName);
            }
            if (correlation == null)
            {
                return(null);
            }
            try
            {
                // get detection (default detection method = "hybrid" , which it's enough if the learning was with hybrid\regression method)
                var detection = AnomalyDetection.GetDetection(data.predict_data, correlation);
                if (detection == null)
                {
                    return(null);
                }
                Dictionary <string, string>       reason         = AnomalyDetection.GetReportTypes(correlation, detection);
                Dictionary <String, List <Span> > spanDictionary = AnomalyDetection.ToSpanDictionary(detection);
                if (reason == null || spanDictionary == null)
                {
                    return(null);
                }
                return(new ANOMALY()
                {
                    anomalies = spanDictionary, reason = reason
                });
            }catch
            {
                return(null);
            }
        }