篇學習了滾動窗口,今天學習滑動窗口。
滑動窗口也是將數據分配到一個固定的窗口中,與滾動窗口不同的是,滑動窗口有一個參數可以控制窗口跳窗的頻率。也就是說滑動窗口一個參數表示窗口的寬度,一個參數表示窗口移動的步長。那么當步長小于窗口大小的時候窗口就會重疊。如果我們想要統計近15分鐘的數據,但是又想每分鐘都能看到數據的更新就可以選擇使用滑動窗口。
Flink SQL語法:
HOP(TABLE data, DESCRIPTOR(timecol), slide, size [, offset ])
data:一個具有時間屬性列的表
timecol:表中的時間列,映射滑動窗口。
slide:窗口的滑動步長
size:窗口的寬度
offset:可選參數,表示窗口開始時間的偏移量
slide < size,則窗口會重疊,每個元素會被分配到多個窗口。
slide=size,則等同于滾動窗口(TUMBLE)。
slide > size,則為跳躍窗口,窗口之間不重疊且有間隙。
Demo:統計近10分鐘的price數據,并且每5分鐘更新一次數據
SELECT window_start, window_end, SUM(price)
FROM TABLE(
HOP(TABLE Bid, DESCRIPTOR(bidtime), INTERVAL '5' MINUTES, INTERVAL '10' MINUTES))
GROUP BY window_start, window_end;
注意事項
滑動窗口將窗口按照步長劃分成了很多了個小滾動窗口,因此在使用時,窗口的寬度設置之為滑動步長的整數倍時性能是最優的。如果不設置為整數倍并不會有語法錯誤,只是無法達到一個比較優的性能。
HOP窗口無法讀取數據進入的時間,第一個窗口的開啟時間會前移。 前移時長=窗口時長-滑動步長
iOS上實現高性能的滑動列表,通常會使用UITableView或UICollectionView,這兩個是UIKit中用于展示列表數據的視圖。以下是一些優化滑動性能的建議:
以下是一個簡單的UITableView實現的例子:
swift
復制
class MyTableViewCell: UITableViewCell {
// 定義單元格的子視圖
}
class MyViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
var tableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
tableView=UITableView(frame: self.view.bounds, style: .plain)
tableView.dataSource=self
tableView.delegate=self
tableView.register(MyTableViewCell.self, forCellReuseIdentifier: "MyCell")
self.view.addSubview(tableView)
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// 返回數據源中的行數
return dataSource.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell=tableView.dequeueReusableCell(withIdentifier: "MyCell", for: indexPath) as! MyTableViewCell
// 配置單元格
return cell
}
}
在這個例子中,我們創建了一個UITableView,注冊了一個自定義的單元格類MyTableViewCell,并實現了必要的數據源方法。通過以上優化措施,可以大幅提高列表滑動的性能。
CSS table表格 thead固定 tbody滾動效果
由于項目需要,在表格中,當數據量越來越多時,就會出現滾動條,而在滾動的過程中,默認情況下表格頭部會跟著表格內容一起滾動,導致看不到頭部對應的字段名,影響體驗效果!
實現思路:
將內容要滾動的區域控制在 tbody 標簽中添加 overflow-y: auto; 樣式,給 tr 標簽添加 table-layout:fixed; (這是核心)樣式,由于 tbody 有了滾動條后,滾動條也要占位,又會導致 tbody 和 thead 不對齊,所以在設置 tbody 的寬度時要把滾動條的寬度也加上【如果不想顯示滾動條的話,可以把滾動條的寬度設置為0px,滾動條就沒有了。
下面是效果圖,具體完整實例代碼也在下面:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>純CSS table表格 thead固定 tbody滾動</title>
<style>
.table-box {
margin: 100px auto;
width: 1024px;
}
/* 滾動條寬度 */
::-webkit-scrollbar {
width: 8px;
background-color: transparent;
}
/* 滾動條顏色 */
::-webkit-scrollbar-thumb {
background-color: #27314d;
}
table {
width: 100%;
border-spacing: 0px;
border-collapse: collapse;
}
table caption{
font-weight: bold;
font-size: 24px;
line-height: 50px;
}
table th, table td {
height: 50px;
text-align: center;
border: 1px solid gray;
}
table thead {
color: white;
background-color: #38F;
}
table tbody {
display: block;
width: calc(100% + 8px); /*這里的8px是滾動條的寬度*/
height: 300px;
overflow-y: auto;
-webkit-overflow-scrolling: touch;
}
table tfoot {
background-color: #71ea71;
}
table thead tr, table tbody tr, table tfoot tr {
box-sizing: border-box;
table-layout: fixed;
display: table;
width: 100%;
}
table tbody tr:nth-of-type(odd) {
background: #EEE;
}
table tbody tr:nth-of-type(even) {
background: #FFF;
}
table tbody tr td{
border-bottom: none;
}
</style>
</head>
<body>
<section class="table-box">
<table cellpadding="0" cellspacing="0">
<caption>純CSS table表格 thead固定 tbody滾動</caption>
<thead>
<tr>
<th>序 號</th>
<th>姓 名</th>
<th>年 齡</th>
<th>性 別</th>
<th>手 機</th>
</tr>
</thead>
<tbody>
<tr>
<td>001</td>
<td>Name</td>
<td>28</td>
<td>女</td>
<td>Mobile</td>
</tr>
<tr>
<td>002</td>
<td>Name</td>
<td>28</td>
<td>男</td>
<td>Mobile</td>
</tr>
<tr>
<td>003</td>
<td>Name</td>
<td>28</td>
<td>女</td>
<td>Mobile</td>
</tr>
<tr>
<td>004</td>
<td>Name</td>
<td>28</td>
<td>男</td>
<td>Mobile</td>
</tr>
<tr>
<td>005</td>
<td>Name</td>
<td>28</td>
<td>女</td>
<td>Mobile</td>
</tr>
<tr>
<td>006</td>
<td>Name</td>
<td>28</td>
<td>男</td>
<td>Mobile</td>
</tr>
<tr>
<td>007</td>
<td>Name</td>
<td>28</td>
<td>女</td>
<td>Mobile</td>
</tr>
<tr>
<td>008</td>
<td>Name</td>
<td>28</td>
<td>男</td>
<td>Mobile</td>
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="5">【table,thead,tbody,tfoot】 colspan:合并行, rowspan:合并列 </td>
</tr>
</tfoot>
</table>
</section>
</body>
</html>
我自己是一名從事了多年開發的web前端老程序員,目前辭職在做自己的web前端私人定制課程,今年年初我花了一個月整理了一份最適合2019年學習的web前端學習干貨,各種框架都有整理,送給每一位前端小伙伴,想要獲取的可以關注我的頭條號并在后臺私信我:前端,即可免費獲取。
原文鏈接:https://blog.csdn.net/muguli2008/article/details/103787152
*請認真填寫需求信息,我們會在24小時內與您取得聯系。