Naming a series from a measurement, grafana and influxdb - influxdb

Grafana is using InfluxDB as its data source. Each series in influx has two measurements: the true measurement ("temperature"), and a city name "denver". For each series, the city name never changes, but the series names themselves are geographic coordinates.
I am able to plot the temperature for each city over time, on grafana. I'd also like to use the city name somewhere, for example the legend, or a table under the graph. I don't want to use the city name exclusively - I still want the coordinates to be the main thing shown in the legend.
How can I access this other measurement and show it either in a table under the graph, or in the graph alongside the current legend? Would it be easier to store the city name elsewhere for referencing?

Joining two measurements in InfluxDB is generally an anti-pattern. In this case, the city name should be stored as a tag in the temperature measurement. Your points would then look something like this (in InfluxDB line protocol):
temperature,city=denver,lat=1.0,long=2.0 value=32.0 1469923200000000000
temperature,city=chicago,lat=3.0,long=-2.0 value=46.0 1469923200000000000
Queries grouped by the series name can now be easily constructed in Grafana, which will show the series name (including city name) in the legend.
Note: If the sensors always have the same city name, then adding the city name as a tag will not increase cardinality. This assumes all the older series with the city in the measurement name are removed and rewritten with the new city tag.

Related

How to generate a distribution based bar chart on row_numbers

I have a SQL query that acts as a data source in my tableau desktop:
SELECT
row_number() over (order by sales) as rn,
article_number,
country,
SUM(sold_items) as si,
SUM(sales) as sales
FROM data.sales
WHERE sales.order_date between '2021-01-01' and '2021-12-31'
GROUP BY 2, 3
On tableau I dragged rn to column and sales to row to generate a bar chart. The following is the output:
I want to convert this into a 0-100% distribution chart so that I can get the following result:
How can I achieve this? Also, I want the user to filter by country level so even if the # of records increase or decrease, the distribution should always be consistent with the filtered data.
You can do this with nested table calcs.
For example, the following uses the Superstore sample data set, and then first computes a running total of SUM(Sales) per day, then converts that to a percent of total. Notice the edit table calc dialog box - applying two back to back calculations in this case.
The x-axis in this example is Order-Date, and in your question, the the x-axis is a percentage somehow - so its not exactly what you requested but still shows that table calcs are an easy way to do these types of operations.
Also, realize you can just connect to the sales table directly, the custom sql isn’t adding any value, and in fact can defeat query optimizations that Tableau normally makes.
The tableau help docs explains table calculations. Pay attention to the discussion on partitioning and addressing.

Trying to create an SPSS Modeler Stream to calculate minimum distance between many geographic lat-long points and Points of Interest

I have a list of hundreds of thousand of addresses with their Latitude/Longitude data.
In a second table, I have the Latitude/Longitude of hundreds of gas stations.
I need to derive a table with the lat/long of the house, the distance to THE CLOSEST gas station, and the name of the gas station.
I'm trying to create a stream for SPSS Modeler (I'm using version 18.2).
In excel was fairly simple (see example below). In sheet one are the houses with lat/long, in sheet two the gas stations data, in sheet three how I did it in excel for a limited number of points, and in sheet four the resulting table. Basically, in excel I took the lat/long of each house and calculated the distance to all the gas stations and kept the smallest one.
I'll appreciate any directions or ideas on how to generate an SPSS Modeler stream to do something similar.
You can download my excel sample here: https://github.com/schapsis/calculating-distance-question
Please see the solution posted at https://developer.ibm.com/answers/questions/512605/how-to-calculate-distance-between-many-geographic/

What is the equivalent of a UNION statement

I need to chart physical measurements using Influx. All measurements are stored as series inside a single Influx "measurement".
Some are "current" values like temperatures, other are things like energy meter readings.
The problem is that these need different queries in order to produce visually attractive output. Charting the meter readings as current power is possible using the DIFFERENCE function.
SELECT difference(max("value")) AS "diff_value"
FROM "volkszaehler"."autogen"."data"
WHERE time > :dashboardTime:
GROUP BY time(1d), "title" FILL(linear)
For other values like temperatures the selection should be mean("value") without the difference.
Is there a way to "union" result sets in InfluxDB similar to mysql in order to display them in a single chart in Chronograf?
Sorry, this isn't possible and new functionality isn't being added to InfluxQL while Flux is being actively worked on.
https://github.com/influxdata/flux

How to get a list of base names of InfluxDB series?

InfluxDB's SHOW SERIES query returns a list of all series-tag-value combinations existing in the database.
How can I get a list of just the series' "base names" (without tags)?
Series without tags is just a measurement.
SHOW MEASUREMENTS [ON <database_name>]

Fetch the data from sqlite database with multiple columns and rows

I am creating an app for iPhone in which I am using sqlite to create a database. I wrote a query in which it returns 4 columns with multiple rows.
First column have values like indian territory(NORTH,SOUTH,EAST,WEST), in Second column it have the states name which belongs to these territory. There is almost 4 states in each territory. It may increase after some time. Third and fourth column have some no data which is belong to that state. How to show If I clicked in south territory then it should show all the south states in tableview. How to match the state names with its territory and fetch data according to that.
Now I have to add all states according to territory, please not give me static code like Territory= INDIA EAST, because if territory increases than it will fail.
I have to add all states into different arrays according to its region like all south in one array and all north in one array and so on..
We could use a look at your schema, but a query like this sounds like it would work:
select states from my_table where territory = 'NORTH'
You can run sqlite3 from Terminal and execute queries there, which will help you concoct your queries. Also I suggest looking at FMDB, which offers a nice API to help interface your code to SQLite. It has excellent documentation which will help translate your query's results into ObjC/Swift data structures.

Resources