//Method
        public void MatchSelectionFrom(List <ColibriParam> ColibriParams)
        {
            this.TotalCounts  = ColibriBase.CalTotalCounts(ColibriParams);
            this._totalDomain = new GH_Interval(new Interval(0, this.TotalCounts - 1));
            this._paramNames  = ColibriBase.getAllNames(ColibriParams);

            this._paramsPositions       = ColibriBase.AllParamsPositions(ColibriParams);
            this._paramsDivisionNumbers = iniTakeNumbers(this._userParamsTakeNumbers, ColibriParams);

            //_paramsSelectedPositions is used to fly params
            this._paramsSelectedPositions = calParamsSelectedPositions(this._paramsPositions, this._paramsDivisionNumbers, ColibriParams);


            var selectedPositionCounts = calSelectedPositionsCount(this._paramsSelectedPositions);
            var selectedTotalDomain    = new GH_Interval(new Interval(0, selectedPositionCounts - 1));

            //_domains is used to fly params
            this._domains = iniDomains(this._userDomains, selectedTotalDomain);

            this.SelectedCounts = calSelectedTotalCount(this._domains, selectedPositionCounts);
        }
예제 #2
0
        public IteratorFlyParam(List <ColibriParam> sourceParams, IteratorSelection selections, string studyFolder, OverrideMode overrideFolderMode)
        {
            this._inputParams        = sourceParams;
            this._selections         = selections == null? new IteratorSelection(): selections;
            this._overrideFolderMode = overrideFolderMode;
            //this._studyFoler = studyFolder;

            this._totalCounts           = ColibriBase.CalTotalCounts(this._inputParams);
            this._selectedCounts        = _selections.SelectedCounts > 0 ? _selections.SelectedCounts : _totalCounts;
            this._allPositions          = ColibriBase.AllParamsPositions(this._inputParams);
            this._allSelectedPositions  = _selections.ParamsSelectedPositions == null? this._allPositions : _selections.ParamsSelectedPositions;
            this._currentPositionsIndex = Enumerable.Repeat(0, _inputParams.Count()).ToList();
            Count = 0;

            createWatchFile(studyFolder);

            //get studied Fly ID from folder
            if (this._overrideFolderMode == OverrideMode.FinishTheRest)
            {
                this._studiedFlyID = getStudiedFlyID(studyFolder);
            }
        }
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object can be used to retrieve data from input parameters and
        /// to store data in output parameters.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            bool writeFile = false;

            //input variables
            List <string> inputs  = new List <string>();
            List <string> outputs = new List <string>();

            List <object> inJSON = new List <object>();
            //object inJSON = null;

            var imgParams = new ImgParam();

            //get data
            DA.GetData(0, ref Folder);
            DA.GetDataList(1, inputs);
            DA.GetDataList(2, outputs);
            DA.GetData(3, ref imgParams);
            DA.GetDataList(4, inJSON);
            DA.GetData(5, ref writeFile);

            //operations is ExpandoObject
            inJSON.RemoveAll(item => item == null);
            var JSON = new threeDParam();

            if (!inJSON.IsNullOrEmpty())
            {
                JSON = new threeDParam(inJSON);
            }


            Dictionary <string, string> inputCSVstrings  = ColibriBase.FormatDataToCSVstring(inputs, "in:");
            Dictionary <string, string> outputCSVstrings = ColibriBase.FormatDataToCSVstring(outputs, "out:");
            //Dictionary<string, string> imgParamsClean = ColibriBase.ConvertBactToDictionary(imgParams);

            string csvPath = Folder + @"\data.csv";
            //var rawData = inputs;
            //int inDataLength = rawData.Count;
            //rawData.AddRange(outputs);
            //int allDataLength = rawData.Count;

            //Parsing data to csv format
            string flyID      = inputCSVstrings["FlyID"];
            string keyReady   = inputCSVstrings["DataTitle"];
            string valueReady = inputCSVstrings["DataValue"];

            //add output data when it is not empty
            keyReady   = string.IsNullOrWhiteSpace(outputCSVstrings["DataTitle"]) ? keyReady : keyReady + "," + outputCSVstrings["DataTitle"];
            valueReady = string.IsNullOrWhiteSpace(outputCSVstrings["DataValue"]) ? valueReady : valueReady + "," + outputCSVstrings["DataValue"];

            string systemSafeFileName = flyID.Replace(" ", "");

            systemSafeFileName = Path.GetInvalidFileNameChars()
                                 .Aggregate(systemSafeFileName, (current, c) => current.Replace(c.ToString(), ""));

            //write only when toggle is connected
            if (this.Params.Input.Last().Sources.Any())
            {
                //first open check
                if (_isFirstTimeOpen)
                {
                    _isFirstTimeOpen = false;
                    setWriteFileToFalse();
                    return;
                }
                this._write = writeFile;
            }
            else
            {
                this._write = false;
            }

            //var ViewNames = new List<string>();


            //if we aren't told to write, clean out the list of already written items
            if (!_write)
            {
                DA.SetDataList(0, _printOutStrings);
                _alreadyWrittenLines = new List <string>();
                this.Message         = "[OVERRIDE MODE]\n" + OverrideTypes.ToString() + "\n------------------------------\n[RECORDING DISABLED]\n";
                return;
            }

            //if we are told to run and we haven't written this line yet, do so

            if (_write)
            {
                //Check folder if existed
                checkStudyFolder(Folder);

                //check csv file
                if (!File.Exists(csvPath))
                {
                    //clean out the list of already written items
                    _printOutStrings = new List <string>();
                    //add key lines

                    //check if there is one or more imges
                    if (imgParams.IsDefined)
                    {
                        int imgCounts = imgParams.ViewNames.Count;
                        imgCounts = imgCounts > 0 ? imgCounts : 1;

                        if (imgCounts > 1)
                        {
                            for (int i = 1; i <= imgCounts; i++)
                            {
                                keyReady += ",img_" + i;
                            }
                        }
                        else
                        {
                            keyReady += ",img";
                        }
                    }
                    else
                    {
                        keyReady += ",img";
                    }

                    if (JSON.IsDefined)
                    {
                        keyReady += ",threeD";
                    }

                    keyReady += Environment.NewLine;
                    File.WriteAllText(csvPath, keyReady);
                    _alreadyWrittenLines.Add("[Title] " + keyReady);
                }
                else
                {
                    //add data lins
                    if (!_alreadyWrittenLines.Contains("[FlyID] " + flyID))
                    {
                        string writeInData = valueReady;

                        //save img
                        string imgFileName = captureViews(imgParams, systemSafeFileName);
                        writeInData += "," + imgFileName;

                        //save json
                        if (JSON.IsDefined)
                        {
                            string jsonFileName = systemSafeFileName + ".json";
                            string jsonFilePath = Folder + @"\" + jsonFileName;
                            File.WriteAllText(jsonFilePath, JSON.JsonSting);
                            writeInData += "," + jsonFileName;
                        }

                        //save csv // add data at the end
                        //writeInData = string.Format("{0},{1},{2}\n", valueReady, imgFileName, jsonFileName);
                        writeInData += "\n";
                        File.AppendAllText(csvPath, writeInData);

                        //add this line to our list of already written lines
                        _alreadyWrittenLines.Add("[FlyID] " + flyID);
                    }
                }

                _printOutStrings = _alreadyWrittenLines;

                //updateMsg();
                this.Message = "[OVERRIDE MODE]\n" + OverrideTypes.ToString() + "\n------------------------------\n[RECORDING STARTED]\n";
                DA.SetDataList(0, _printOutStrings);
            }

            //set output
            //DA.SetData(0, writeInData);
        }