我有一个烧瓶应用程序正在计算csv文件中的一些数据并将该数据发送到我的前端javascript。目前数据基于UTC时区,我试图得到它,所以它使用的是PST。我尝试过使用arrow和timedelta但是在尝试这两种方法时,我的前端数据根本没有填充。
python代码:
def calc_stats(date_list): today_count = 0 week_count = 0 month_count = 0 today = datetime.datetime.today().date() datetime.timedelta() for d in date_list: date = d.date() if date == today: today_count += 1 monday = today + datetime.timedelta(days=-today.weekday(), weeks=0) sunday = today + datetime.timedelta(days=6-today.weekday(), weeks=0) if date >= monday: if date <= sunday: week_count += 1 first_day_of_this_month = today.replace(day=1) next_month = today.replace(day=28) + datetime.timedelta(days=4) # this will never fail last_day_of_this_month = next_month - datetime.timedelta(days=next_month.day) if date >= first_day_of_this_month: if date <= last_day_of_this_month: month_count += 1 return [today_count, week_count, month_count]
javascript代码:
<script>
var update_table = function () {
$.post("/transferstats", function (data) {
var content = '';
for (var key in data) {
content += `<tr><td>${key}</td><td>${data[key][0]}</td><td>${data[key][1]}</td><td>${data[key][2]}</td></tr>`;
}
var total_today = data['Johnny'][0] + data['Max'][0] + data['Tuck'][0] + data['Ram'][0] + data['Ice'][0];
var total_week = data['Johnny'][1] + data['Max'][1] + data['Tuck'][1] + data['Ram'][1] + data['Ice'][1];
var total_month = data['Johnny'][2] + data['Max'][2] + data['Tuck'][2] + data['Ram'][2] + data['Ice'][2];
content += `<tr><td>Total</td><td>${total_today}</td><td>${total_week}</td><td>${total_month}</td></tr>`;
$('#stas_table tbody').html(content);
})
}
$(document).ready(function () {
update_table();
setInterval(update_table, 5000);
});
</script>