Skip to content

Commit

Permalink
Merge pull request #852 from onkelandy/influxdb2
Browse files Browse the repository at this point in the history
Influxdb2: Update docu and web interface
  • Loading branch information
msinn authored Nov 3, 2023
2 parents 5fae0c7 + ec7419f commit 3ee29c1
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 90 deletions.
Binary file added influxdb2/assets/influxdb2_webif.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
70 changes: 63 additions & 7 deletions influxdb2/user_doc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@ Mit jedem Item Wert, der in einem InfluxDB Bucket abgelegt werden, werden folgen
- **str_value** - enthält nicht numerische Werte, die in der Datenbank abgelegt werden sollen.




Konfiguration
=============

Expand All @@ -100,14 +98,72 @@ Die Plugin Parameter und die Informationen zur Item-spezifischen Konfiguration d
unter :doc:`/plugins_doc/config/influxdb2` nachzulesen.


Beispiele
---------
Daten aus dem Database Plugin transferieren
===========================================

Diese Anleitung wurde unter influxdb2 getestet und muss eventuell für influxdb1 adaptiert werden.

1. Pandas und influxdb_client Module für Python installieren
2. CSV-Dump aus dem Webinterface des Datenbank-Plugins herunterladen
3. Anpassen der Zugriffsparameter im unten stehenden Skript
4. Anpassen des Pfads zur CVS-Datei
5. Ausführen des Skripts
6. Abhängig von der Größe der Datenbank ist Geduld gefragt.


.. code-block:: python
from influxdb_client import InfluxDBClient
from influxdb_client.client.write_api import SYNCHRONOUS
import pandas as pd
# ----------------------------------------------
ip = "localhost"
port = 8086
token = "******************"
org = "smarthomeng"
bucket = "shng"
value_field = "value"
str_value_field = "str_value"
csvfile = "smarthomeng_dump.csv"
# ----------------------------------------------
client = InfluxDBClient(url=f"http://{ip}:{port}", token=token, org=org)
write_api = client.write_api(write_options=SYNCHRONOUS)
df = pd.read_csv(csvfile, sep=';', header=0)
df = df.reset_index()
num_rows = len(df.index)
last_progress_percent = -1
for index, row in df.iterrows():
progress_percent = int((index/num_rows)*100)
if last_progress_percent != progress_percent:
print(f"{progress_percent}%")
last_progress_percent = progress_percent
p = {'measurement': row['item_name'], 'time': int(row['time']) * 1000000,
'tags': {'item': row['item_name']},
'fields': {value_field: row['val_num'], str_value_field: row['val_str']}
}
write_api.write(bucket=bucket, record=p)
client.close()
Hier können ausführlichere Beispiele und Anwendungsfälle beschrieben werden.
...
Web Interface
=============

...
Das Web Interface ermöglicht das Betrachten der Items, die mit der Datenbank verbunden sind.

.. image:: assets/influxdb2_webif.png
:height: 1610px
:width: 3304px
:scale: 25%
:alt: Web Interface
:align: center
87 changes: 4 additions & 83 deletions influxdb2/webif/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,13 @@
}
}
</script>
<!--
This part is used to implement datatable JS for the tables. It allows resorting tables by column, etc.
For each table you have to implement the code part $('#<table_id>').DataTable(..); where the <table_id> matches the id of a table tag
-->

<script>
$(document).ready( function () {
/*
loading defaults from /modules/http/webif/gstatic/datatables/datatables.defaults.js
You can copy that file, put it in your plugin directory, rename the "bind" function and
trigger that function here instead of datatables_defaults if you want to change the behaviour.
Of course you can also overwrite defaults by putting the option declarations in {} below.
*/
$(window).trigger('datatables_defaults');
try
{
$('#maintable').DataTable( {} ); // put options into {} if needed
$('#<table_id>').DataTable( {} ); // delete or change name
$('#maintable').DataTable( {} );
}
catch (e)
{
Expand Down Expand Up @@ -91,41 +81,12 @@
</table>
{% endblock headtable %}

{% set tabcount = 1 %}

<!--
Additional buttons for the web interface (if any are needed) - displayed below the headtable-section
-->
{% block buttons %}
{% if 1==2 %}
<div>
<button id="btn1" class="btn btn-shng btn-sm" name="scan" onclick="shngPost('', {learn: 'on'})"><i class="fas fa-question"></i>&nbsp;&nbsp;&nbsp;{{ _('nach Devices suchen') }}&nbsp;</button>
</div>
{% endif %}
{% endblock %}

<!--
Define the number of tabs for the body of the web interface (1 - 6)
-->
{% set tabcount = 4 %}


<!--
Set the tab that will be visible on start, if another tab that 1 is wanted (1 - 3)
-->
{% if item_count==0 %}
{% set start_tab = 2 %}
{% endif %}


<!--
Content block for the first tab of the Webinterface
-->
{% set tab1title = "<strong>" ~ p.get_shortname() ~ " Items</strong> (" ~ item_count ~ ")" %}
{% block bodytab1 %}
<div class="container-fluid m-2">

<!-- set id accordingly -->
<table id="maintable" class="table table-striped table-hover pluginList display">
<table id="maintable" class="datatableAdditional">
<thead>
<tr>
<th>{{ _('Item') }}</th>
Expand All @@ -148,44 +109,4 @@
</tbody>
</table>

</div>
{% endblock bodytab1 %}


<!--
Content block for the second tab of the Webinterface
-->
{% set tab2title = "<strong>" ~ p.get_shortname() ~ " Geräte</strong> (" ~ device_count ~ ")" %}
{% block bodytab2 %}
<div class="container-fluid m-2">
{{ _('Hier kommt der Inhalt des Webinterfaces hin.') }}
</div>
{% endblock bodytab2 %}


<!--
Content block for the third tab of the Webinterface
If wanted, a title for the tab can be defined as:
{% set tab3title = "<strong>" ~ p.get_shortname() ~ " Geräte</strong>" %}
It has to be defined before (and outside) the block bodytab3
-->
{% block bodytab3 %}
<div class="container-fluid m-2">
{{ _('Hier kommt der Inhalt des Webinterfaces hin.') }}
</div>
{% endblock bodytab3 %}


<!--
Content block for the fourth tab of the Webinterface
If wanted, a title for the tab can be defined as:
{% set tab4title = "<strong>" ~ p.get_shortname() ~ " Geräte</strong>" %}
It has to be defined before (and outside) the block bodytab4
-->
{% block bodytab4 %}
<div class="container-fluid m-2">
{{ _('Hier kommt der Inhalt des Webinterfaces hin.') }}
</div>
{% endblock bodytab4 %}

0 comments on commit 3ee29c1

Please sign in to comment.