1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
| function isSameWeek(date1, date2) { let day_date = new Date(date1); let now_date = new Date(date2); day_date.setHours(0); now_date.setHours(0); var oneDayTime = 1000 * 60 * 60 * 24; var old_count = parseInt(day_date / oneDayTime); var now_other = parseInt(now_date / oneDayTime); return parseInt((old_count + 4) / 7) == parseInt((now_other + 4) / 7); }
function week_day(day) { let date = new Date(day); let week_day = ["星期天", "星期一","星期二","星期三","星期四","星期五","星期六"]; return week_day[date.getDay()]; }
function total_distance(morning, afternoon) { var d1 = parseFloat(morning); var d2 = parseFloat(afternoon); if(Number.isNaN(d1)) d1 = 0; if(Number.isNaN(d2)) d2 = 0; var d = d1 + d2; return d.toFixed(2) + " KM"; }
function week_total_distance(morning, afternoon) { let morning_dis = 0; let afternoon_dis = 0; for(let d of morning) { let tmp = parseFloat(d); if(Number.isNaN(tmp)) continue; morning_dis += tmp; }
for(let d of afternoon) { let tmp = parseFloat(d); if(Number.isNaN(tmp)) continue; afternoon_dis += tmp; }
let total = morning_dis + afternoon_dis return total.toFixed(2) + " KM"; }
let morning = dv.pages(`"关于跑步/训练日记"`).where(p => isSameWeek(p.date, dv.current().date)).morning let afternoon = dv.pages(`"关于跑步/训练日记"`) .where(p => isSameWeek(p.date, dv.current().date)).afternoon
let dis = week_total_distance(morning, afternoon);
let data = dv.pages(`"关于跑步/训练日记"`) .sort(p => p.date, "asc") .where(p => isSameWeek(p.date, dv.current().date));
let total_data = [];
for(let p of data) { total_data.push([p.file.link, week_day(p.date), p.plan, p.morning, p.afternoon, total_distance(p.morning, p.afternoon)]) } total_data.push(["", "", "", "", "", dis]) dv.table( ["日期", "周期", "训练计划", "早上", "下午", "累计"], total_data )
|