篇学习了滚动窗口,今天学习滑动窗口。
滑动窗口也是将数据分配到一个固定的窗口中,与滚动窗口不同的是,滑动窗口有一个参数可以控制窗口跳窗的频率。也就是说滑动窗口一个参数表示窗口的宽度,一个参数表示窗口移动的步长。那么当步长小于窗口大小的时候窗口就会重叠。如果我们想要统计近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小时内与您取得联系。