Spaces:
Sleeping
Sleeping
Commit ·
b96d974
1
Parent(s): b1acbf2
updated hf spaces
Browse filesFiles changed (6)
1234567891011121314151617181920name: Sync to Hugging Face hubon: push: branches: [main]
# to run this workflow manually from the Actions tab workflow_dispatch:
jobs: sync-to-hub: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 with: fetch-depth: 0 lfs: true - name: Push to hub env: HF_TOKEN: ${{ secrets.HF_TOKEN }} run: git push https://van-william:$HF_TOKEN@huggingface.co/spaces/van-william/machine_monitoring main29 unmodified lines303132333435363738394036 unmodified lines777879808182838485868788899091929394959697989910010110210310410510610710810911011111211329 unmodified linesMQTT_BROKER = "broker.hivemq.com"MQTT_TOPIC = "test_fan/current"def query_influxdb(query):table = influx_client.query(query=query, language="sql")df = table.to_pandas().sort_values(by="time")return dfdef query_influxdb_gr():query = '''SELECT *36 unmodified linesdf = pd.DataFrame(data_points)return df# Gradio componentsdef update_chart():fig = go.Figure()fig.add_trace(go.Scatter(x=[point["timestamp"] for point in data_points],y=[point["current"] for point in data_points],mode='lines+markers'))fig.update_layout(title="MQTT Data Visualization",xaxis_title="Timestamp",yaxis_title="Current (A)")return figwith gr.Blocks() as app:gr.Markdown("# MQTT Data Visualization")gr.Markdown(f"Listening to MQTT topic: {MQTT_TOPIC}")line_plot = gr.LinePlot(update_mqtt_live_data, label="MQTT", x="datetime", y="current", every=1)#plotly_plot = gr.Plot(make_figure(update_data), label="Plotly Chart", every=1)gr.Markdown("# InfluxDB Data Visualization")line_plot = gr.LinePlot(query_influxdb_gr, label="InfluxDB", x="time", y="current", every=300)gr.Markdown("# Plotly Data Visualization")plot = gr.Plot(update_chart, every=1)app.load(update_chart, None, plot)# Launch the app29 unmodified lines30313233343536 unmodified lines72737475767778798081828329 unmodified linesMQTT_BROKER = "broker.hivemq.com"MQTT_TOPIC = "test_fan/current"def query_influxdb_gr():query = '''SELECT *36 unmodified linesdf = pd.DataFrame(data_points)return dfwith gr.Blocks() as app:gr.Markdown("# MQTT Data Visualization")gr.Markdown(f"Listening to MQTT topic: {MQTT_TOPIC}")line_plot = gr.LinePlot(update_mqtt_live_data, label="MQTT", x="datetime", y="current", every=1)gr.Markdown("# InfluxDB Data Visualization")line_plot = gr.LinePlot(query_influxdb_gr, label="InfluxDB", x="time", y="current", every=300)# Launch the app
12345678910## Node Red Integrations## MQTT- Here, I used the native MQTT connector to publish messages to my MQTT broker (In this case, HiveMQ)## InfluxDB- For InfluxDB integrations, you can integrate via Telegraf and stream the MQTT messages in via Telegraf and parse to InfluxDB (This does not require anything on the Node Red side)- You can also write data from Node-Red to InfluxDB via the REST API or via the InfluxDB Node-Red Modules. linked below:https://flows.nodered.org/node/node-red-contrib-influxdb
1 unmodified line234567811 unmodified lines202122232425262728293031323334354 unmodified lines4041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442451 unmodified line"cells": [{"cell_type": "code","execution_count": 5,"metadata": {},"outputs": [],"source": [11 unmodified lines},{"cell_type": "code","execution_count": 18,"metadata": {},"outputs": [],"source": ["INFLUXDB_URL = \"https://us-east-1-1.aws.cloud2.influxdata.com/\"\n","\n","INFLUXDB_ORG = \"dd7895c825a7c36a\"\n","INFLUXDB_BUCKET = \"machine_monitoring\"\n","influx_client = InfluxDBClient3(host=INFLUXDB_URL, token=INFLUXDB_TOKEN, org=INFLUXDB_ORG,database=\"machine_monitoring\")\n"]},{"cell_type": "code",4 unmodified lines},{"cell_type": "code","execution_count": 19,"metadata": {},"outputs": [],"source": ["def query_influxdb(query):\n"," table = influx_client.query(query=query, language=\"sql\")\n"," df = table.to_pandas().sort_values(by=\"time\")\n"," return df"]},{"cell_type": "code","execution_count": 23,"metadata": {},"outputs": [],"source": ["\n","query = '''\n"," SELECT *\n"," FROM \"fan\"\n"," WHERE time >= now() - interval '2 week'\n"," '''\n"]},{"cell_type": "code","execution_count": 24,"metadata": {},"outputs": [{"data": {"text/html": ["<div>\n","<style scoped>\n"," .dataframe tbody tr th:only-of-type {\n"," vertical-align: middle;\n"," }\n","\n"," .dataframe tbody tr th {\n"," vertical-align: top;\n"," }\n","\n"," .dataframe thead th {\n"," text-align: right;\n"," }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n"," <thead>\n"," <tr style=\"text-align: right;\">\n"," <th></th>\n"," <th>current</th>\n"," <th>description</th>\n"," <th>host</th>\n"," <th>humidity</th>\n"," <th>location</th>\n"," <th>sensor</th>\n"," <th>temperature</th>\n"," <th>time</th>\n"," <th>topic</th>\n"," </tr>\n"," </thead>\n"," <tbody>\n"," <tr>\n"," <th>0</th>\n"," <td>0.00250</td>\n"," <td>Partly cloudy</td>\n"," <td>williamvanbuskirk-MacBook-Pro</td>\n"," <td>60.0</td>\n"," <td>Chicago</td>\n"," <td>S1</td>\n"," <td>72.5</td>\n"," <td>2024-10-06 01:09:17.800669</td>\n"," <td>test_fan</td>\n"," </tr>\n"," <tr>\n"," <th>1</th>\n"," <td>0.00226</td>\n"," <td>Partly cloudy</td>\n"," <td>williamvanbuskirk-MacBook-Pro</td>\n"," <td>60.0</td>\n"," <td>Chicago</td>\n"," <td>S1</td>\n"," <td>72.5</td>\n"," <td>2024-10-06 01:09:18.801087</td>\n"," <td>test_fan</td>\n"," </tr>\n"," <tr>\n"," <th>2</th>\n"," <td>0.00214</td>\n"," <td>Partly cloudy</td>\n"," <td>williamvanbuskirk-MacBook-Pro</td>\n"," <td>60.0</td>\n"," <td>Chicago</td>\n"," <td>S1</td>\n"," <td>72.5</td>\n"," <td>2024-10-06 01:09:19.841504</td>\n"," <td>test_fan</td>\n"," </tr>\n"," <tr>\n"," <th>3</th>\n"," <td>0.00190</td>\n"," <td>Partly cloudy</td>\n"," <td>williamvanbuskirk-MacBook-Pro</td>\n"," <td>60.0</td>\n"," <td>Chicago</td>\n"," <td>S1</td>\n"," <td>72.5</td>\n"," <td>2024-10-06 01:09:21.296156</td>\n"," <td>test_fan</td>\n"," </tr>\n"," <tr>\n"," <th>4</th>\n"," <td>0.00166</td>\n"," <td>Partly cloudy</td>\n"," <td>williamvanbuskirk-MacBook-Pro</td>\n"," <td>60.0</td>\n"," <td>Chicago</td>\n"," <td>S1</td>\n"," <td>72.5</td>\n"," <td>2024-10-06 01:09:22.797416</td>\n"," <td>test_fan</td>\n"," </tr>\n"," </tbody>\n","</table>\n","</div>"],"text/plain": [" current description host humidity location \\\n","0 0.00250 Partly cloudy williamvanbuskirk-MacBook-Pro 60.0 Chicago \n","1 0.00226 Partly cloudy williamvanbuskirk-MacBook-Pro 60.0 Chicago \n","2 0.00214 Partly cloudy williamvanbuskirk-MacBook-Pro 60.0 Chicago \n","3 0.00190 Partly cloudy williamvanbuskirk-MacBook-Pro 60.0 Chicago \n","4 0.00166 Partly cloudy williamvanbuskirk-MacBook-Pro 60.0 Chicago \n","\n"," sensor temperature time topic \n","0 S1 72.5 2024-10-06 01:09:17.800669 test_fan \n","1 S1 72.5 2024-10-06 01:09:18.801087 test_fan \n","2 S1 72.5 2024-10-06 01:09:19.841504 test_fan \n","3 S1 72.5 2024-10-06 01:09:21.296156 test_fan \n","4 S1 72.5 2024-10-06 01:09:22.797416 test_fan "]},"execution_count": 24,"metadata": {},"output_type": "execute_result"}],"source": ["df = query_influxdb(query)\n","\n","df.head()"]},{"cell_type": "code","execution_count": 25,"metadata": {},"outputs": [],"source": ["table = influx_client.query(query=query, language=\"sql\")"]},{"cell_type": "code","execution_count": 26,"metadata": {},"outputs": [{"data": {"text/plain": ["pyarrow.Table\n","current: double\n","description: string\n","host: string\n","humidity: double\n","location: string\n","sensor: string\n","temperature: double\n","time: timestamp[ns] not null\n","topic: string\n","----\n","current: [[0.0025,0.0022600000000000003,0.0021400000000000004,0.0019,0.00166,...,0.0025000000000000005,0.00232,0.00202,0.00184,0.00184]]\n","description: [[\"Partly cloudy\",\"Partly cloudy\",\"Partly cloudy\",\"Partly cloudy\",\"Partly cloudy\",...,\"Partly cloudy\",\"Partly cloudy\",\"Partly cloudy\",\"Partly cloudy\",\"Partly cloudy\"]]\n","host: [[\"williamvanbuskirk-MacBook-Pro\",\"williamvanbuskirk-MacBook-Pro\",\"williamvanbuskirk-MacBook-Pro\",\"williamvanbuskirk-MacBook-Pro\",\"williamvanbuskirk-MacBook-Pro\",...,\"williamvanbuskirk-MacBook-Pro\",\"williamvanbuskirk-MacBook-Pro\",\"williamvanbuskirk-MacBook-Pro\",\"williamvanbuskirk-MacBook-Pro\",\"williamvanbuskirk-MacBook-Pro\"]]\n","humidity: [[60,60,60,60,60,...,60,60,60,60,60]]\n","location: [[\"Chicago\",\"Chicago\",\"Chicago\",\"Chicago\",\"Chicago\",...,\"Chicago\",\"Chicago\",\"Chicago\",\"Chicago\",\"Chicago\"]]\n","sensor: [[\"S1\",\"S1\",\"S1\",\"S1\",\"S1\",...,\"S1\",\"S1\",\"S1\",\"S1\",\"S1\"]]\n","temperature: [[72.5,72.5,72.5,72.5,72.5,...,72.5,72.5,72.5,72.5,72.5]]\n","time: [[2024-10-06 01:09:17.800669000,2024-10-06 01:09:18.801087000,2024-10-06 01:09:19.841504000,2024-10-06 01:09:21.296156000,2024-10-06 01:09:22.797416000,...,2024-10-06 16:28:05.520067000,2024-10-06 16:28:06.522940000,2024-10-06 16:28:07.947039000,2024-10-06 16:28:08.941063000,2024-10-06 16:28:10.445205000]]\n","topic: [[\"test_fan\",\"test_fan\",\"test_fan\",\"test_fan\",\"test_fan\",...,\"test_fan\",\"test_fan\",\"test_fan\",\"test_fan\",\"test_fan\"]]"]},"execution_count": 26,"metadata": {},"output_type": "execute_result"}],"source": ["table"]},{"cell_type": "code",1 unmodified line234567811 unmodified lines202122232425262728294 unmodified lines34353637383940414243444546474849505152535455565758596061626364656667686970711 unmodified line"cells": [{"cell_type": "code","execution_count": 1,"metadata": {},"outputs": [],"source": [11 unmodified lines},{"cell_type": "code","execution_count": null,"metadata": {},"outputs": [],"source": []},{"cell_type": "code",4 unmodified lines},{"cell_type": "code","execution_count": null,"metadata": {},"outputs": [],"source": []},{"cell_type": "code","execution_count": null,"metadata": {},"outputs": [],"source": []},{"cell_type": "code","execution_count": null,"metadata": {},"outputs": [],"source": []},{"cell_type": "code","execution_count": null,"metadata": {},"outputs": [],"source": []},{"cell_type": "code","execution_count": null,"metadata": {},"outputs": [],"source": []},{"cell_type": "code",
38 unmodified lines3940414243444538 unmodified linesquery = '''SELECT *FROM "fan"WHERE time >= now() - interval '1 week''''df = query_influxdb(query)if not df.empty:38 unmodified lines3940414243444538 unmodified linesquery = '''SELECT *FROM "fan"WHERE time >= now() - interval '2 week''''df = query_influxdb(query)if not df.empty:
1234567# Telegraf## Inputs- MQTT Consumer## Outputs- InfluxDB
.github/workflows/push_to_hf.ymlAdded+20
gradio/app.py-30
node-red/README.md+10
notebooks/tests.ipynb+15-189
streamlit/app.py+1-1
telegraf/README.md+7