中级
实现设备最新读数缓存(TTL=5分钟)
未完成
中级参考
代码结构已给出,请填写 ____ 处
def solve():
from pyodide.http import open_url
from io import StringIO
import pandas as pd
cache_csv = open_url(____).read()
cache_log = pd.read_csv(StringIO(____))
TTL = ____
cache_store = {}
results = []
for _, row in cache_log.sort_values(____).iterrows():
op = row['____']
key = row['____']
ts = float(____)
if op == '____':
cache_store[key] = {'____':ts,'____':TTL}
results.append(____)
elif op == '____':
entry = cache_store.get(____)
if entry and ts - entry['____'] < entry['____']:
results.append(____)
else:
results.append(____)
elif op in (____):
cache_store.pop(____)
results.append(____)
reads = results.count(____) + results.count(____)
hits = results.count(____)
print("____"+str(____)+"____")
print("____"+str(len(____)))
print("____"+str(____)+"____"+str(____)+"____"+str(results.count(____))+"____")
print("____"+str(round(____) if reads>____ else ____)+"____")
print("____"+str(len(____)))
示例
输入
solve()
期望输出
Cache TTL simulation (TTL=300s=5min): Total ops: 50 Reads: 33 (hits=2 misses=31) Hit rate: 6.1% Live cache entries: 6
👑
升级 VIP
解锁全部题目,畅通无阻地学习
- ✓ 解锁全部训练包所有题目
- ✓ 查看完整参考代码和提示
- ✓ 浏览器内直接运行 Python 代码
- ✓ 自动批改 + 进度追踪
30天
¥18
1年
¥99
2年
¥158
3年
¥199