Never stop learning, approaching the AI
  • 😄About
  • 🅰️AI-Candy on YouTube
    • 🎬YouTube 视频列表
    • 💠AI项目本地部署
      • 1️⃣安装 Pytorch 运行环境
      • 2️⃣在Python虚拟环境下使用 VS Code or PyCharm
        • VS Code Python format
      • 3️⃣Create python virtual environment in Linux
    • 👽AI 入门系列课程
      • 0️向量及向量运算
        • Reshape array code
      • 1️人工智能,机器学习,深度学习 和神经网络的区别
      • 2️卷积神经网络(CNN)
        • 3D CNN sample code
      • 3️Transformer 原理
      • 4️前馈神经网络 (FNN)
  • 🎭Artificial intelligence
    • 1️⃣Deep learning / machine learning
      • 👉Deep Learning Resources
      • 👉Deep learning notes
    • 2️⃣Python
      • Youtube音乐下载
      • Pytorch 安装环境配置 (old)
        • TorchEEG
      • Anaconda3 Python path
      • Data
      • IEEE-754 Floating Point Converter
        • ieee 754 conversion function
      • 文件读写
      • 文本清理
      • Python 下载在线视频
      • 修改Jupyter Notebook 默认工作目录
    • 3️⃣AI Websites
  • 🪤Programming
    • SQL
      • Delete data and reset auto-increment ID
    • Angular
      • Angular-datatables, dd/MM/yyyy, sorting (no paged list)
      • Datatables save state using localStorage
      • Variable storage method
      • Colour picker
      • Error fix for click columns on Datatable
      • Auto address use Google place
      • Auto address use Azure Maps
      • Upload file to Server
      • Validators.required OnChange input
      • Date, Time field
      • VS Code: Auto add missing imports when save
      • Datatable setting
      • Date time format
      • sticky <th> and <td> content
      • Filter booked time
      • Dropdown time selection with interval
      • Angular date online test
      • Updating data without refreshing the page
      • Object array sort and sum
      • Multi-type of columns use in one column
      • Select button for datatables
      • Switch button and event
      • Delete column from Array
      • Three-layer structure
      • Remove shadow when print mat-dialog content
      • JSON Parse && Object Array
      • Detect unused import in Typescript
      • Change location using radio button
      • display multi line message in the Toastr
      • Custom LOCALE_ID
      • Batch add data from csv to API server
        • Angular read csv and upload to Server
      • USB Port reader Web solution
      • Debug Angular app using JavaScript Debugger in VS Code
      • Skills
        • FormData & FormGroup to JSON
        • Dropdown list (customer)
        • Get current datetime
        • Get first day of year, month, and date
        • Call a function in a forEach loop
        • disable and readonly
        • Form element value
        • HTML input type
        • Input pattern (validation)
      • Display pipe (UI format)
        • Input upper case and button checked
        • Icons (Bootstrap and CoreUI)
        • Page Refresh
        • Selection list (two ways)
        • onChange Selection event
        • Random Password and Toggle
        • Password match
        • Select checkbox disable
      • Print and save to PDF
      • Import JS into Angular
      • LocalStorage
      • Angular DataTable
        • Data sort
        • A sample usage
        • Angular DataTable server side big data query
      • Change chart.js chart type
      • Angular UI - .NET API - .NET Auth
      • Angular - .NET API
      • *ngIf else && change to @if
      • Angular add reCAPTCHA v3 (Google)
      • Angular update
        • Update from v13 to v15
        • Update from v15 to v18
      • Angular application version central
      • Face detection
        • Face-api.js
      • Angular, Node version compatibility matrix
      • Clear cache
      • Angular oauth2 OIDC
      • Angular add header
    • .NET Skills
      • Add ID manually
      • Auto Mapping
        • Ignore Nesting
        • Startup setting
        • Datetime processing in AutoMapping
        • AutoMapper example
      • Validation filter
      • BaseController
      • Group by many
      • Database first, scaffold to class
      • Log setting and exception handler
      • Update appsetting.json value
      • Azure service bus message (queue)
      • Read appsetting.json value
      • Auth get user info by email
      • Azure Time zone
      • .NET API Add Service
      • Object comparison
      • Coravel Schedule
        • Read appsettings.json
      • .Net Core RDLC Report, Coravel and Email
      • Check Network and SQL server connections.
      • Datatime custom format
      • Many to Many EF
        • Many to Many CheckBox
      • PDFpig: Send Email with PDF attachment
      • .NET Core Middleware order
      • .NET API add Worker Service
      • .NET Router
      • Partial columns update
      • Add and Delete
      • 图片自适应宽度
      • ASP.NET Identity
      • Upload file to Azure
        • Upload file to Blob
      • Developer Guide
      • Code first one-many
      • ASP.NET MVC 5 Custom Error Page
      • VS can't debug
      • 通过邮编查 NSW COVID-19 感染人数
      • Jquery File Upload
      • Jquery Datepicker
      • ajax delete file from server
      • Autofac in MVC
      • Autofac in .NET Core
      • .NET Core
      • HTTP Return code
      • IdentityServer4
    • Power BI
      • Add parameter to PowerBI report
      • Convert UTC to Local time
      • Python in PowerBI
        • IEEE-754 conversion
      • PowerBI embed app - Server
      • PowerBI embed app - Client
        • Setting on portal
    • Azure service
      • Key Vault
      • Service bus - queue
      • Power Automate
      • Kusto Query Language
      • Azure Data Explorer
      • Reserved keyword on Azure Error
      • SQL Azure time convert
    • Azure blob
      • Azure blob setting
      • Display image from Blob
      • Upload image to Blob through .NET API
    • Html Bootstrap Icon, colour, size
      • Html spacing
      • Html text alignment
    • Video stream - JsMpeg
      • SSL - generate key
      • Client (SSL)
      • Websocket-Server (SSL)
      • Play RTSP video stream
    • ⏰Time Zone
      • datetime-local set date range
      • 🕐Get data by local time (UI, API)
      • 🕑Add offset hours for local UI and report
      • 🕒UTC time and Datetime convert
      • 🕓Angular - Timezone selection
      • 🕔Angular - Convert UTC to local time
      • 🕕C# Time Zone
  • >>>>>>>>>>>>>>>>>>>>>>>>>>>>
  • 🪜Apps and Skills
    • 1️Windows system app skills
      • Brother HL-2130 打印机 Toner 报警
      • VS Code 快捷键
      • Check SHA256 on windows
      • blob 视频下载
      • Photoshop 制作证件照片
      • 获取 Windows Key
      • 10进制36进制互转
      • Error when publish to Azure
      • Disable windows automatic update
      • Outlook setup for Yahoo Email
      • IIS setting
      • Windows 8/10, IIS Service
      • 安装程序出错 2052,2053 报警
      • 6 Yao Chinese UI
    • 2️Linux command
    • 3️Git command
    • 4️Bitbucket
    • 5️Gitbook Skills
    • 6️GitHub Desktop
    • 7️⃣EndNote
      • EndNote V21
      • Endnote使用技巧
      • 批量删除/修改Endnote 中 notes 栏内容
  • Android mobile connect PC
  • 💎USEFUL LINKS
    • 1️Coding websites
      • Website links
    • 2️Windows 平台工具,网站
    • 3️PotPlayer 设置
  • >>>>>>>>>>>>>>>>>>>>>>>>>>>>
  • 🚩Research >>EEG
    • 1️EEG基本知识的理论介绍
      • EEG 简介
      • EEG 的节律信号
      • EEG电极帽
      • EEG 伪迹
      • ERP 介绍
      • ERP 成分
      • EEG 数据分析软件
    • 2️LSL 应用
    • 3️EEG公开数据集汇总整理
    • 4️REDCap
      • Migration (Export & Import)
    • 5️⃣ScaneR
  • ☕Buy me a coffee
Powered by GitBook
On this page

Was this helpful?

  1. Programming
  2. Azure service

Kusto Query Language

https://learn.microsoft.com/en-us/azure/data-explorer/kusto/query/

```kusto function
//*** Float-point Dec to dec
//*** Formula = sign * (1 + fraction) * 2^(exponent-bias)
let FloatPointDEC_to_DEC = (floatPointDec:int, sign:int){
   // sign = 1: positive, -1: negtive
   let bias = 127;
   let exponent = binary_shift_right(floatPointDec, 23);  // ==>131
   let fraction = binary_shift_right((binary_shift_left(floatPointDec,9)-binary_shift_left(binary_shift_right(floatPointDec,32-9),32)),9);  // =>2322689
   //bit_feed = 1 to 23, from left to right in fraction
   //sample fraction: 2322689(dec) eque to 01000110111000100000001(bin)
   //get fraction bit value
   let getFractionBitValue=(fraction:int, bit_feed:int){
      let m_bit = 23 + 1 - bit_feed;
      let bit_value = binary_shift_right(fraction, m_bit-1) -binary_shift_left(binary_shift_right(fraction,m_bit),1);
      todecimal(bit_value * exp2(-bit_feed))
   };
   let fraction_bit_value = getFractionBitValue(fraction, 1) + getFractionBitValue(fraction, 2)
                              + getFractionBitValue(fraction, 3) + getFractionBitValue(fraction, 4)
                              + getFractionBitValue(fraction, 5) + getFractionBitValue(fraction, 6)
                              + getFractionBitValue(fraction, 7) + getFractionBitValue(fraction, 8)
                              + getFractionBitValue(fraction, 9) + getFractionBitValue(fraction, 10)
                              + getFractionBitValue(fraction, 11) + getFractionBitValue(fraction, 12)
                              + getFractionBitValue(fraction, 13) + getFractionBitValue(fraction, 14)
                              + getFractionBitValue(fraction, 15) + getFractionBitValue(fraction, 16)
                              + getFractionBitValue(fraction, 17) + getFractionBitValue(fraction, 18)
                              + getFractionBitValue(fraction, 19) + getFractionBitValue(fraction, 20)
                              + getFractionBitValue(fraction, 21) + getFractionBitValue(fraction, 22)
                              + getFractionBitValue(fraction, 23) + 1;
   sign * fraction_bit_value * exp2(exponent - bias);
};
//print(FloatPointDEC_to_DEC(1101230337,1));
```kusto function
// combine high and low float-point value
let Combine_HighLow = (floatPointHigh: string, floatPointLow:string){
	toreal(floatPointHigh)*65536 + toreal(floatPointLow);
};
```kusto function
// convert wind direction from degree (0~365) to text
let WindDirectionWord = (windDirection: string){
	let windDirectionValue = toreal(windDirection);
   iff(isnull(windDirectionValue) or isempty(windDirectionValue) or isnan(windDirectionValue),'',
	iff(windDirectionValue>=348.75,'N',
	iff(windDirectionValue> 326.25, 'NNW',
		iff(windDirectionValue> 303.75, 'NW',  
			iff(windDirectionValue> 281.25, 'WNW',  
				iff(windDirectionValue> 258.75, 'W',  
					iff(windDirectionValue> 236.25, 'WSW',  
						iff(windDirectionValue> 213.75, 'SW',  
							iff(windDirectionValue> 191.25, 'SSW',  
								iff(windDirectionValue> 168.75, 'S',  
									iff(windDirectionValue> 146.25, 'SSE',  
										iff(windDirectionValue> 123.75, 'SE',  
											iff(windDirectionValue> 101.25, 'ESE',  
												iff(windDirectionValue> 78.75, 'E',  
													iff(windDirectionValue> 56.25, 'ENE',  
														iff(windDirectionValue> 33.75, 'NE',  
															iff(windDirectionValue> 11.25, 'NNE', 'N')))))))))))))))))
};
// ```kusto Query
let detailed_data = materialize(WeatherStation
| where isnotempty(HumidityHigh) and isnotempty(HumidityLow) and isnotempty(TemperatureHigh)
| sort by timestamp
| take 200
| project timestamp, Humidity=Combine_HighLow(HumidityHigh, HumidityLow),
	Pressure = Combine_HighLow(PressureHigh, PressureLow),
	Temperature = Combine_HighLow(TemperatureHigh, TemperatureLow),
	WindSpeed = Combine_HighLow(WindSpeedHigh, WindSpeedLow), toreal(WindDirection)
| summarize HumidityDEC = avg(Humidity), TemperatureDEC = avg(Temperature), PressureDEC = avg(Pressure), 
	WindSpeedDEC = avg(WindSpeed), WindDirectionDEC = avg(WindDirection), Timestamp = max(timestamp), Count=count());
detailed_data
| where Count > 0
| extend LocalAdelaideTime= datetime_utc_to_local(Timestamp,'Australia/Adelaide')
| project HumidityDEC, TemperatureDEC, PressureDEC, WindSpeedDEC, Humidity = FloatPointDEC_to_DEC(HumidityDEC, 1), Temperature = FloatPointDEC_to_DEC(TemperatureDEC, 1),
	Pressure = FloatPointDEC_to_DEC(PressureDEC, 1), WindSpeed = FloatPointDEC_to_DEC(WindSpeedDEC, 1), 
	WindDirection = WindDirectionWord(WindDirectionDEC), Timestamp, LocalAdelaideTime
```

// convert utc to localtime
```kusto
print(datetime_list_timezones())  // get timezones words
```
// -30 minute
Location
| top 100 by ip
| sort by timestamp
| limit 5
| extend AdelaideTime=datetime_add('minute',-30, make_datetime(timestamp))

// get local time
Weight | take 100 | sort by timestamp
|project weight1=round(todecimal(Weight1),2), weight2=round(todecimal(Weight2),2), weight3=round(todecimal(Weight3),2), timestamp
| extend AdelaideTime = datetime_utc_to_local(timestamp,'Australia/Adelaide')

// join two table
let weight = materialize(Weight 
| take 10
| sort by timestamp
|project weight1=round(todecimal(Weight1),2), weight2=round(todecimal(Weight2),2), weight3=round(todecimal(Weight3),2), timestamp
| extend AdelaideTime = datetime_utc_to_local(timestamp,'Australia/Adelaide'), weightTotal=weight1+weight2+weight3);
let location = materialize(Location
| take 10
| sort by timestamp
| project Latitude, Longitude, timestamp
| extend AdelaideTime=datetime_add('minute',-30, make_datetime(timestamp))
);
location
| join kind=fullouter weight on AdelaideTime   // kind=inner ....
//average weight from last 100 records and join last record from location
let Weight = materialize(Weight 
| project Weight1, Weight2, Weight3, timestamp
| extend UTC_Now= datetime(now)
| extend AdelaideTime = datetime_utc_to_local(UTC_Now,'Australia/Adelaide')
| extend AdelaideTimeFromTimestamp = datetime_utc_to_local(timestamp,'Australia/Adelaide')
| order by timestamp desc  
| take 15
| project weight1 = todecimal(Weight1), weight2 = todecimal(Weight2), weight3 = todecimal(Weight3) 
| summarize Weight1=round(avg(weight1),2), Weight2=round(avg(weight2),2), Weight3=round(avg(weight3),2), WeightTotal=round(avg(weight1+weight2+weight3),2)
| extend UTC_Now= datetime(now)
);
let Location = materialize(Location
| order by timestamp desc 
| project Latitude, Longitude, timestamp
| extend UTC_Now= datetime(now)
| extend AdelaideTime = datetime_utc_to_local(UTC_Now,'Australia/Adelaide')
| take 1
);
Location
| project Latitude, Longitude, UTC_Now1 = UTC_Now
| join (Weight
      | project Weight1, Weight2, Weight3, WeightTotal, UTC_Now)
   on $left.UTC_Now1 ==  $right.UTC_Now
| extend AdelaideTime = datetime_utc_to_local(UTC_Now,'Australia/Adelaide')
| project AdelaideTime, Latitude, Longitude, Weight1, Weight2, Weight3, WeightTotal, Min=0, Max=60

PreviousPower AutomateNextAzure Data Explorer

Last updated 2 years ago

Was this helpful?

🪤