Creating a heatmap in Grafana using Kusto from Azure Data Explorer - grafana

Well, I'm trying to find a way to create a heatmap in Grafana using Kusto.
I found: https://grafana.com/docs/grafana/v9.0/basics/intro-histograms/#pre-bucketed-data
Which basically said that Kusto is supported. But It doesn't mention the way tabular data should be exposed.
Can anybody guide me with it?
Actually, I have a table with: Id, Timestamp, Value where Timestamp changes for all the new series of data. Suppose that I have 10 different Ids then, Timestamp will change every 10 rows.
Example:
let test = datatable (Timestamp: datetime, Id: string, Value: decimal)
[
datetime(2022-11-30 11:40:00), "machineA_var01", 1,
datetime(2022-11-30 11:40:00), "machineA_var02", 1.5,
datetime(2022-11-30 11:40:00), "machineA_var03", 2,
datetime(2022-11-30 11:40:00), "machineA_var04", 2.5,
datetime(2022-11-30 11:40:00), "machineA_var05", 5,
datetime(2022-11-30 11:40:00), "machineA_var06", 3,
datetime(2022-11-30 11:40:00), "machineA_var07", 2,
datetime(2022-11-30 11:40:00), "machineA_var08", 6,
datetime(2022-11-30 11:40:00), "machineA_var09", 3,
datetime(2022-11-30 11:40:00), "machineA_var10", 4,
datetime(2022-11-30 11:40:00), "machineA_var11", 5,
datetime(2022-11-30 11:40:00), "machineA_var12", 6,
datetime(2022-11-30 11:40:00), "machineA_var13", 1,
datetime(2022-11-30 11:40:00), "machineA_var14", 13,
datetime(2022-11-30 11:40:00), "machineA_var15", 3,
datetime(2022-11-30 11:40:00), "machineA_var16", 5,
datetime(2022-11-30 11:40:15), "machineB_var01", 3,
datetime(2022-11-30 11:40:15), "machineB_var02", 7,
datetime(2022-11-30 11:40:15), "machineB_var03", 8,
datetime(2022-11-30 11:40:15), "machineB_var04", 6,
datetime(2022-11-30 11:40:15), "machineB_var05", 8,
datetime(2022-11-30 11:40:15), "machineB_var06", 2,
datetime(2022-11-30 11:40:15), "machineB_var07", 6,
datetime(2022-11-30 11:40:15), "machineB_var08", 2,
datetime(2022-11-30 11:40:15), "machineB_var09", 3,
datetime(2022-11-30 11:40:15), "machineB_var10", 3,
datetime(2022-11-30 11:40:15), "machineB_var11", 3,
datetime(2022-11-30 11:40:15), "machineB_var12", 4,
datetime(2022-11-30 11:40:15), "machineB_var13", 6,
datetime(2022-11-30 11:40:15), "machineB_var14", 2,
datetime(2022-11-30 11:40:15), "machineB_var15", 8,
datetime(2022-11-30 11:40:15), "machineB_var16", 5,
datetime(2022-11-30 11:40:30), "machineC_var01", 6,
datetime(2022-11-30 11:40:30), "machineC_var02", 3,
datetime(2022-11-30 11:40:30), "machineC_var03", 8,
datetime(2022-11-30 11:40:30), "machineC_var04", 9,
datetime(2022-11-30 11:40:30), "machineC_var05", 3,
datetime(2022-11-30 11:40:30), "machineC_var06", 6,
datetime(2022-11-30 11:40:30), "machineC_var07", 5,
datetime(2022-11-30 11:40:30), "machineC_var08", 6,
datetime(2022-11-30 11:40:30), "machineC_var09", 4,
datetime(2022-11-30 11:40:30), "machineC_var10", 7,
datetime(2022-11-30 11:40:30), "machineC_var11", 1,
datetime(2022-11-30 11:40:30), "machineC_var12", 3,
datetime(2022-11-30 11:40:30), "machineC_var13", 5.5,
datetime(2022-11-30 11:40:30), "machineC_var14", 6,
datetime(2022-11-30 11:40:30), "machineC_var15", 7,
datetime(2022-11-30 11:40:30), "machineC_var16", 8,
];
test
As you can see I'm printing my information as it is, but this is not enough to be used as a heatmap. My question is, how do I need to transform the source table in order to match the required format by Grafana's heatmap.
I think I'll need to do buckets with the timestamp but how should the data be exposed?

Hm, not sure how useful it's really going to be and I'm probably get pinged for it again but yet again pivot does the trick:
Adding | evaluate pivot(Id, max(Value)) to your query yields the following heatmap:

Related

modifying google ortools vrptw example fails

I done some experiments with this exmalple:
https://developers.google.com/optimization/routing/vrptw
My Data set is this:
data['time_windows'] = [(0, 1), (0, 84), (0, 84), (0, 84), (0, 84), (0, 84), (12, 36), (12, 36)]
data['time_matrix'] = [[0, 8, 7, 8, 4, 6, 8, 7], [0, 0, 10, 11, 4, 9, 8, 7], [0, 10, 0, 11, 4, 9, 8, 7], [0, 10, 11, 0, 4, 9, 8, 7], [0, 10, 11, 4, 0, 9, 8, 7], [0, 10, 11, 4, 9, 0, 8, 7], [0, 10, 11, 4, 9, 8, 0, 7], [0, 10, 11, 4, 9, 8, 7, 0]]
I want to have only one vehicle for a test. But if I set " data['num_vehicles'] = 1 " I get no output but a clean exit. Why? I guess this is just a standard TSP, if I reduce the vehicles to 1.
Well, as mentioned by Laurent Perron in the comment, there was a maximum time per vehicle in this example.
routing.AddDimension(
transit_callback_index,
30, # allow waiting time
30, # maximum time per vehicle <<<<<<<<<<<<<<<<<<<
False, # Don't force start cumul to zero.
time)
I changed it to a bigger number (99) and all the crap works very fine :)

I am trying to remove duplicate element from list using below code but getting below output. why i am Not getting expected output?

my_list = [1, 2, 3, 3, 4, 4, 4, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6]
for item in my_list:
if my_list.count(item) > 1:
my_list.pop(item)
print(my_list) # => actual result - [1, 2, 3, 4, 5, 6, 6, 6, 6]

Searching mapped list to return higher values

My current system can find the last value of a list of integers, shown in the first file below. Then it displays this as the "Current" value. I need to be able to find all of the "Current" values when I enter a search and return all of the results higher than the one I searched for.The list is saved as a Map(String, List[Int]).
SK1, 9, 7, 2, 0, 7, 3, 7, 9, 1, 2, 8, 1, 9, 6, 5, 3, 2, 2, 7, 2, 8, 5, 4, 5, 1, 6, 5, 2, 4, 1
SK2, 0, 7, 6, 3, 3, 3, 1, 6, 9, 2, 9, 7, 8, 7, 3, 6, 3, 5, 5, 2, 9, 7, 3, 4, 6, 3, 4, 3, 4, 1
SK4, 2, 9, 5, 7, 0, 8, 6, 6, 7, 9, 0, 1, 3, 1, 6, 0, 0, 1, 3, 8, 5, 4, 0, 9, 7, 1, 4, 5, 2, 8
SK5, 2, 6, 8, 0, 3, 5, 5, 2, 5, 9, 4, 5, 3, 5, 7, 8, 8, 2, 5, 9, 3, 8, 6, 7, 8, 7, 4, 1, 2, 3
SK6, 2, 7, 5, 9, 1, 9, 8, 4, 1, 7, 3, 7, 0, 8, 4, 5, 9, 2, 4, 4, 8, 7, 9, 2, 2, 7, 9, 1, 6, 9
SK7, 6, 9, 5, 0, 0, 0, 0, 5, 8, 3, 8, 7, 1, 9, 6, 1, 5, 3, 4, 7, 9, 5, 5, 9, 1, 4, 4, 0, 2, 0
SK8, 2, 8, 8, 3, 1, 1, 0, 8, 5, 9, 0, 3, 1, 6, 8, 7, 9, 6, 7, 7, 0, 9, 5, 2, 5, 0, 2, 1, 8, 6
SK9, 7, 1, 8, 8, 4, 4, 2, 2, 7, 4, 0, 6, 9, 5, 5, 4, 9, 1, 8, 6, 3, 4, 8, 2, 7, 9, 7, 2, 6, 6
This is what I am trying to get; using the data file from above, If I searched for "SK5" the system would return;
Figures higher than SK5 - 3
SK4 - 8
SK6 - 9
SK8 - 6
SK9 - 6
Here is my current code to find the last number in the list
//5 - Show Current Stock Level (W)
def handleFive(): Boolean = {
mnuShowSingleDataStock(currentStockLevel)
true
}
// Returns a single result, not a list
def mnuShowSingleDataStock(stock: (String) => (String,Int)) = {
print("Stock > ")
val data = stock(readLine)
println(s"${data._1}: ${data._2}")
}
//Show higher than stocks
def higherThan(stock: String): List[(String, List[Int])] = {
mapdata.toList.sortWith(_._2.last > _._2.last).takeWhile(row => row._2.last > mapdata.get(stock).map(_.last).getOrElse(0))
}
Sort based on the last value and then take while current stock value is greater than the searched stock value
def higherThan(stock: String): List[(String, List[Int])] = {
mapdata.toList.sortWith(_._2.last > _._2.last).takeWhile(row => row._2.last > mapdata.get(stock).map(_.last).getOrElse(0))
}

Formatting output scala lists

Currently I can search for a value, say SK5 and it will return all values higher than SK5. However the format it is returned in as shown below;
List((SK6,List(2, 7, 5, 9, 1, 9, 8, 4, 1, 7, 3, 7, 0, 8, 4, 5, 9, 2,
4, 4, 8, 7, 9, 2, 2, 7, 9, 1, 6, 9)), (SK4,List(2, 9, 5, 7, 0, 8, 6,
6, 7, 9, 0, 1, 3, 1, 6, 0, 0, 1, 3, 8, 5, 4, 0, 9, 7, 1, 4, 5, 2, 8)),
(SK8,List(2, 8, 8, 3, 1, 1, 0, 8, 5, 9, 0, 3, 1, 6, 8, 7, 9, 6, 7, 7,
0, 9, 5, 2, 5, 0, 2, 1, 8, 6)), (SK9,List(7, 1, 8, 8, 4, 4, 2, 2, 7,
4, 0, 6, 9, 5, 5, 4, 9, 1, 8, 6, 3, 4, 8, 2, 7, 9, 7, 2, 6, 6)),
(SK5,List(2, 6, 8, 0, 3, 5, 5, 2, 5, 9, 4, 5, 3, 5, 7, 8, 8, 2, 5, 9,
3, 8, 6, 7, 8, 7, 4, 1, 2, 3)))
What I want is SK6 - 9, SK4 - 8 etc etc
All bundled together, How would I split this up and only show the last number in the list? I thought I had already filtered this out however apparently not.
Below is my code. Mapdata is saved as Map(String, List[Int])
//functionality to find the last tail element, the "Current" stock price
def findLast(list:List[Int]) = list.last
//8 - Show Stocks Higher Than (W) THIS ONE THIS ONE THIS ONE
def handleEight(): Boolean = {
mnuShowPointsForStockHigher(higherThan2)
true
}
//Returns a list value
def mnuShowPointsForStockHigher(stock: (String) => List[(String, List[Int])]) = {
print("Enter Stock > ")
val data = stock(readLine)
println(s"${data}")
//println(s"${data._1}: ${data._2.last}")
}
def higherThan2(stock: String): List[(String, List[Int])] = {
mapdata.toList.sortWith(_._2.last > _._2.last).takeWhile(row => row._2.last > mapdata.get(stock).map(findLast(_)).getOrElse(0))
}
If you are trying to get the last value in each list, Best option will be map + last. Sorry, don't need to use flatten. My bad .. Should be something line: list.map(x => x.last)

Scala Type Mismatch Mapping

I am trying to create a search function, so the user can search through a list using the key value, however the method Im trying to use returns a type mismatch, Have taken out needless code and shown what is required. How do I set points to take an Int and not "Any"?
"type Any does not conform to type Int"
val mapdata = readFile("data.txt")
def handleTwo(): Boolean = {
mnuShowPointsForTeam(currentPointsForTeam)
true
}
def mnuShowPointsForTeam(f: (String) => (String, Int)) = {
print("Team>")
val data = f(readLine)
println(s"${data._1}: ${data._2}")
}
def currentPointsForTeam(team: String): (String, Int) = {
val points = mapdata.get(team) match{
case Some(p) => p
case None => 0
}
(team, points)
}
The data.txt
SK1, 9, 7, 2, 0, 7, 3, 7, 9, 1, 2, 8, 1, 9, 6, 5, 3, 2, 2, 7, 2, 8, 5, 4, 5, 1, 6, 5, 2, 4, 1
SK2, 0, 7, 6, 3, 3, 3, 1, 6, 9, 2, 9, 7, 8, 7, 3, 6, 3, 5, 5, 2, 9, 7, 3, 4, 6, 3, 4, 3, 4, 1
SK4, 2, 9, 5, 7, 0, 8, 6, 6, 7, 9, 0, 1, 3, 1, 6, 0, 0, 1, 3, 8, 5, 4, 0, 9, 7, 1, 4, 5, 2, 8
SK5, 2, 6, 8, 0, 3, 5, 5, 2, 5, 9, 4, 5, 3, 5, 7, 8, 8, 2, 5, 9, 3, 8, 6, 7, 8, 7, 4, 1, 2, 3
SK6, 2, 7, 5, 9, 1, 9, 8, 4, 1, 7, 3, 7, 0, 8, 4, 5, 9, 2, 4, 4, 8, 7, 9, 2, 2, 7, 9, 1, 6, 9
SK7, 6, 9, 5, 0, 0, 0, 0, 5, 8, 3, 8, 7, 1, 9, 6, 1, 5, 3, 4, 7, 9, 5, 5, 9, 1, 4, 4, 0, 2, 0
SK8, 2, 8, 8, 3, 1, 1, 0, 8, 5, 9, 0, 3, 1, 6, 8, 7, 9, 6, 7, 7, 0, 9, 5, 2, 5, 0, 2, 1, 8, 6
SK9, 7, 1, 8, 8, 4, 4, 2, 2, 7, 4, 0, 6, 9, 5, 5, 4, 9, 1, 8, 6, 3, 4, 8, 2, 7, 9, 7, 2, 6, 6
It looks like you want to return a tuple with a List[Int], not just a single Int.
If so
def currentPointsForTeam(team: String): (String, List[Int]) =
(team, mapdata.get(team).getOrElse(List.empty))
// Or maybe List(0) instead of List.empty
If you do want to return a single Int, you have to say how to go from the List[Int] in the map to a single value. Maybe a sum?
def currentPointsForTeam(team: String): (String, Int) =
(team, mapdata.get(team).map(_.sum).getOrElse(0))