本文主要是介绍python influx基本操作,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
连接influx
client = InfluxDBClient(influx_ip, influx_port, influx_db, '', database=influx_db)
数据样式
[{"time": "2021-12-24T01:18:49Z","abdomina_conn_state": 0,"ap_mac": "05e4608c3200","arrhythmia_type": 1,"data_type": null,"device_battery": 100,"device_date": "2021-12-24 09:18:49","device_id": "01000289","device_out_battery": 61,"ecg_conn_state": "0","elec_mmhg_battery": 100,"elec_mmhg_conn_state": 0,"loss_package": 1,"org_id": null,"package_sn": 233371,"patient_id": null,"person_id": null,"person_zid": "6fe4d1faf56d41dc90b8fe6a183b17c0","plus_rate": 0,"resp_conn_state": 0,"save_time": null,"simulate": null,"source": null,"spo2": 0,"spo2_battery": 100,"spo2_conn_state": 1,"spo2_probe_conn_state": 0,"spo2_signal": 0,"srcIp": null,"temperature": 0,"temperature_battery": 100,"temperature_conn_state": 0,"wifi_signal": -40
}]
写入
wave = open(type + "_" + taskId + '_wave.json', 'r')wave_data = json.load(wave)for waveItem in wave_data:_time = waveItem["time"]_personZid = waveItem["person_zid"]del waveItem["time"]_personZid = waveItem["person_zid"]del waveItem["person_zid"]waveBody = [{"measurement": "hs_wave_package","time":_time,"tags":{"person_zid":_personZid},"fields":waveItem}]client.write_points(waveBody)
由于导出的时候没有tag,所以在添加数据时,需要对tag进行处理。
查询
select * from hs_wave_package where person_zid::tag="6fe4d1faf56d41dc90b8fe6a183b17c0"
习惯性再查询的时候使用tag进行查询
这篇关于python influx基本操作的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!