Skip to content

Instantly share code, notes, and snippets.

View hfleitas's full-sized avatar
👔
working

Hiram Fleitas hfleitas

👔
working
View GitHub Profile
@hfleitas
hfleitas / M06-MLslides.kql
Created January 19, 2024 22:28
M06-MLslides.kql
#connect cluster('help').database('Samples')
// https://aka.ms/adx.iot > assets > demos > ML slides
// explore, dont see metrics
demo_make_series1 | take 10
// make timeseries
let min_t = toscalar(demo_make_series1 | summarize min(TimeStamp));
@hfleitas
hfleitas / M06-Demo5-ML.kql
Last active February 15, 2024 01:30
M06-Demo5-ML.kql
// #connect cluster('igniteadxsource.eastus2').database('Occupancy')
#connect cluster('adxpm10774.eastus').database('IoTAnalytics')
print("😍 ML 🤖")
// Python UnSupervised Learning
//Create a cusotm UDF to run K-Means clustering using Python plugin
.create-or-alter function with (folder = "Python") kmeans_sf_OccupDetc(tbl:(*),k:int,features:dynamic,cluster_col:string) {
let kwargs = pack('k', k, 'features', features, 'cluster_col', cluster_col);
@hfleitas
hfleitas / M03-HOL.kql
Created January 19, 2024 22:29
M03-HOL.kql
#connect cluster('adxpm10774.eastus').database('IoTAnalytics')
//Data lands in the StageIoTRaw table so lets look at that first
.show table StageIoTRawData
StageIoTRawData //retention 1-2 days, or 0 to delete it. Good to keep short period of time to troubleshoot.
| count //2168352
StageIoTRawData
@hfleitas
hfleitas / M01-Demo3-Ingestion.kql
Last active February 13, 2024 20:59
M01-Demo3-Ingestion.kql
#connect cluster('kvc43f0ee6600e24ef2b0e.southcentralus').database('MyDatabase')
// ref https://docs.microsoft.com/azure/data-explorer/ingest-data-one-click
// ref https://docs.microsoft.com/azure/data-explorer/ingest-sample-data?tabs=one-click-ingest
// ref https://docs.microsoft.com/azure/data-explorer/kusto/management/data-ingestion/ingest-from-storage
// public sample, no SAS key required.
.ingest into table StormEvents (
h'https://kustosamples.blob.core.windows.net/samplefiles/StormEvents.csv'
@hfleitas
hfleitas / M01-Demo2-Overview.kql
Created January 19, 2024 22:29
M01-Demo2-Overview.kql
#connect cluster('kvc43f0ee6600e24ef2b0e.southcentralus').database('MyDatabase')
// https://aka.ms/adx.free
// iot document, multiple devices, multi-line json
// see oreProperties
.drop table iotPayload ifexists
.set iotPayload <|
let d= dynamic(
@hfleitas
hfleitas / KDA5.kql
Created January 19, 2024 22:30
KDA5.kql
// El Puente
// grab primes
https://kustodetectiveagency.blob.core.windows.net/prime-numbers/prime-numbers.csv.gz
// Create table command
////////////////////////////////////////////////////////////
.create table ['primes'] (['num']:long)
@hfleitas
hfleitas / KDA4.kql
Created January 19, 2024 22:30
KDA4.kql
#connect cluster('kvc43f0ee6600e24ef2b0e.southcentralus').database('KustoDetectiveAgency')
// Commander
// We have a situation, rookie.
// As you may have heard from the news, there was a bank robbery earlier today.
// In short: the good old downtown bank located at 157th Ave / 148th Street has been robbed.
// The police were too late to arrive and missed the gang, and now they have turned to us to help locating the gang.
// No doubt the service we provided to the mayor Mrs. Gaia Budskott in past - helped landing this case on our table now.
@hfleitas
hfleitas / KDA2.kql
Created January 19, 2024 22:31
KDA2.kql
// Rarest book gone missing!
.drop table Books ifexists
.drop table Shelves ifexists
.execute database script <|
// Create table for the books
.create table Books(rf_id:string, book_title:string, publish_date:long, author:string, language:string, number_of_pages:long, weight_gram:long)
// Import data for books
@hfleitas
hfleitas / KDA1.kql
Created January 19, 2024 22:31
KDA1.kql
////////////////////
// The Lieutenant //
////////////////////
// create free cluster and db at https://aka.ms/free
// sum values in the Score column
.drop table Onboarding ifexists
@hfleitas
hfleitas / KQL Polygon.kql
Created January 19, 2024 22:31
KQL Polygon.kql
let k = dynamic({"type":"polygon","coordinates":[
[
[
-78.90380859375,
30.12612436422458
],
[
-78.81591796875,
25.661333498952683
],