10T = 0xa00000
9T = 0x900000
8T = 0xa00000
1G = 0x400 = 1024
2G = 0x800 = 2048
3G = 0xc00 = 3072
def volumes(db: Session = None):
if db is None:
db = scoped_session(SessionLocal)
expr = OrderedDict({
">10TB": "select count(*) from storage_volume where size > 0xa00000",
"=10TB": "select count(*) from storage_volume where size = 0xa00000",
">=9TB,<10TB": "select count(*) from storage_volume where size < 0xa00000 and size >= 0x900000",
">=8TB,<9TB": "select count(*) from storage_volume where size < 0x900000 and size >= 0x800000",
">=7TB,<8TB": "select count(*) from storage_volume where size < 0x800000 and size >= 0x700000",
">=6TB,<7TB": "select count(*) from storage_volume where size < 0x700000 and size >= 0x600000",
">=5TB,<6TB": "select count(*) from storage_volume where size < 0x600000 and size >= 0x500000",
">=4TB,<5TB": "select count(*) from storage_volume where size < 0x500000 and size >= 0x400000",
">=3TB,<4TB": "select count(*) from storage_volume where size < 0x400000 and size >= 0x300000",
">=2TB,<3TB": "select count(*) from storage_volume where size < 0x300000 and size >= 0x200000",
">=1TB,<2TB": "select count(*) from storage_volume where size < 0x200000 and size >= 0x100000",
"<1TB": "select count(*) from storage_volume where size < 0x100000",
})
return {
"xAxis": {"type": "category", "data": list(expr.keys())},
"yAxis": {"type": "value", "name": "数量"},
"series": [
{"name": "数量", "data": [db.execute(expr).scalar() for expr in expr.values()], "type": "bar"}
],
}
10T = 0xa00000