login(`admin,`123456)



def queryCase1(netAim,staAim,locAim){
	/*
	 * Description：
	 * 	此函数用于测试查询case1 查询某个位置下、某个台网、某个台站所有通道的历史观测数据 ，降采样，精确到分钟
	 * Input：
	 * 	netAim,staAim,locAim：STRING   分别为台网、台站、位置
	 */
	aim  = exec id from loadTable("dfs://real","tagInfo") where net = netAim and  sta = staAim and loc = locAim
	t = select avg(value)  as sample_value from loadTable("dfs://real","realData") where ts >= 2023.03.02T00:00:00.000 and ts < 2023.03.03T00:00:00.000 and id in  aim   group by bar(ts,60000),id
}

def queryCase2(netAim){
	/*
	 * Description：
	 * 	此函数用于测试查询case2  时间关联查询，某个事件发生时刻前2分钟、后11分钟历史观测数据，若为降采样，每2.5s采样一次
	 * Input：
	 * 	netAim：STRING  台网名称
	 */
	aim = exec id from loadTable("dfs://real","tagInfo") where net = netAim
	t = select avg(value)  as sample_value from loadTable("dfs://real","realData") where ts >= 2023.03.02T00:08:00.000 and ts <= 2023.03.02T00:21:00.000 and id in aim   group by bar(ts,2500),id
}


def mainQueryTest(netAim,staAim,locAim){
	/*
	 * Description：
	 * 	此函数用于获得查询case的耗时
	 * Input：
	 * 	netAim,staAim,locAim：STRING   分别为台网、台站、位置
	 * Output：
	 * 	record：TABLE  内容为每个测试的总耗时与平均耗时
	 */
	record = table(1:0,`testName`totalConsume`avgConsume,[STRING,INT,INT])
	consum = evalTimer(queryCase1{netAim,staAim,locAim},10)
	insert into record values([`case1],[consum$INT],[(consum\10)$INT])
	consum = evalTimer(queryCase2{netAim},10)
	insert into record values([`case2],[consum$INT],[(consum\10)$INT])
	return record
}

