Beispiel #1
0
        private void DataWriterFunc(LabDataBase data)
        {
            var datatype = data.GetType();

            if (!_dataWriterDic.ContainsKey(datatype))
            {
                string dataPath = string.Join("_", _saveDataPath + "/", _userId.Invoke().PadLeft(2, '0'), data.GetType().Name + ".json");
                LabTools.CreatData(dataPath);
                _dataWriterDic.Add(datatype, new LabDataWriter(dataPath));
            }

            _dataWriterDic[datatype].WriteData(data);
        }
Beispiel #2
0
        /// <summary>
        /// 数据采集,传入数据,频率,是否循环采集
        /// </summary>
        /// <param name="data"></param>
        /// <param name="loop"></param>
        /// <param name="frequency"></param>
        public void DataCollect(IData data, bool loop = true, int frequency = 200)
        {
            if (!_isClientInit)
            {
                Debug.LogError("LabData未初始化");
                return;
            }


            //StartUpload();
            var basePathStr = Application.dataPath + "/Output";

            LabTools.CreatFolder(basePathStr);
            var userStr = _userId.PadLeft(2, '0');

            basePathStr = string.Join("_", basePathStr + "/" + DateTime.Now.ToString(_localSaveDataTimeLayout), userStr);
            basePathStr = LabTools.CreatFolder(basePathStr);

            if (_saveType == SaveType.Csv)
            {
                string dataPath = string.Join("_", basePathStr + "/" + DateTime.Now.ToString(_localSaveDataTimeLayout), userStr, data.SaveData.DataCodeName, data.SaveData.LabDataBase.Invoke() + "." + _saveType.ToString());
                LabTools.CreatData(dataPath);
                DataWriter dw = new DataWriter(dataPath, data.SaveData.LabDataBase.Invoke, _saveType);
                dw.WriteCsvTitle();
                dw.Dispose();
            }
            if (loop)
            {
                string dataPath = string.Join("_", basePathStr + "/" + DateTime.Now.ToString(_localSaveDataTimeLayout), userStr, data.SaveData.DataCodeName, data.SaveData.LabDataBase.Invoke() + "." + _saveType.ToString());
                LabTools.CreatData(dataPath);
                DataWriter dw = new DataWriter(dataPath, () => data.SaveData.LabDataBase.Invoke(), _saveType);
                dw.WriteDataAsyncFrequency();
                _dataWriters.Add(dw);
            }
            else
            {
                string dataPath = string.Join("_", basePathStr + "/" + DateTime.Now.ToString(_localSaveDataTimeLayout), userStr, data.SaveData.DataCodeName, data.SaveData.LabDataBase.Invoke() + "." + _saveType.ToString());
                LabTools.CreatData(dataPath);
                DataWriter dw = new DataWriter(dataPath, () =>
                {
                    if (_sendToServer)
                    {
                        Scope.Send(data.SaveData.LabDataBase.Invoke());
                    }
                    return(data.SaveData.LabDataBase.Invoke());
                }, _saveType);
                dw.WriteOnce();
                dw.Dispose();
            }
        }