using CommonLib.DB; using NWaves.Transforms; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using static CommonLib.Config.ConfigValue; namespace DataCollectionSystem { public class WriteFluxDB { private InfluxDBHelper dbHelper = null; public Dictionary dictFFT { get; private set; } = new Dictionary(); public WriteFluxDB() { for(int i=400;i<=12400;i+=400) { dictFFT.Add(i, 0); } } public void Write_features( Boolean anomaly, int anomalyInt, float dc, float peak, float rms , string device, string channel) { //string s1 = "features,code=code001,mac=aaa v1=100,v2=200,v3=300"; string dbName = "features"; //string s = $"{dbName},code={device},mac=aaa v1=100,v2=200,v3=300"; //最后一个字符串一定要留下一个空格,不然报400 CUOWU //string s = $"{dbName},anomaly={anomaly},device={device},channel={channel} anomalyInt={anomalyInt},dc={dc},peak={peak},rms={rms}"; string s = $"{dbName},anomaly={anomaly},device={device},channel={channel} anomalyInt={anomalyInt},dc={dc},peak={peak},rms={rms}"; dbHelper.Write(s); } /// /// 传递FFT参数 /// /// /// public void Write_spectrogram( string device, string channel) //,Dictionary dictFFT) { bool bResult = true; string dbName = "spectrogram"; string s = $"{dbName},device={device},channel={channel} "; foreach(var amptitue in dictFFT) { s += $"{amptitue.Key}={amptitue.Value},"; } int len = s.Length; s = s.Remove(len-1); dbHelper.Write(s); } public void Wirte_spike_events( string device, string channel, float snr) { string dbName = "spike_events"; string s = $"{dbName},device={device},channel={channel} snr={snr}"; dbHelper.Write(s); } public void Wirte_waveform( string device, string channel, float amplitude) { string dbName = "waveform"; string s = $"{dbName},device={device},channel={channel} amplitude={amplitude}"; dbHelper.Write(s); } /// /// 初始化数据库连接信息 /// /// public void Init(InflexDBServer server ) { string baseAddress = server.URL; string username = server.User; string password = server.Password; string database = server.DBName; dbHelper = new InfluxDBHelper(baseAddress, username, password, database); //InfluxDBHelper client = new InfluxDBHelper("http://192.168.48.103:8086", "admin","admin","test","127.0.0.1",8888); } public void spike_events( float snr, string device, string channel) { //string s1 = "features,code=code001,mac=aaa v1=100,v2=200,v3=300"; string dbName = "spike_events"; //string s = $"{dbName},code={device},mac=aaa v1=100,v2=200,v3=300"; //最后一个字符串一定要留下一个空格,不然报400 CUOWU //string s = $"{dbName},anomaly={anomaly},device={device},channel={channel} anomalyInt={anomalyInt},dc={dc},peak={peak},rms={rms}"; string s = $"{dbName},snr={snr},device={device},channel={channel} "; dbHelper.Write(s); } } }