Compare commits
2 Commits
2c6491137f
...
e48221b1cd
| Author | SHA1 | Date | |
|---|---|---|---|
| e48221b1cd | |||
| a3d5d2cbfa |
18
README.md
18
README.md
@@ -22,6 +22,24 @@ It progresses **only during your scheduled work hours**
|
|||||||
- During the day, the bar fills smoothly
|
- During the day, the bar fills smoothly
|
||||||
- End of Wednesday = **100% freedom**
|
- End of Wednesday = **100% freedom**
|
||||||
|
|
||||||
|
### Configuration
|
||||||
|
|
||||||
|
| Variable | Default | Description |
|
||||||
|
|--------|---------|-------------|
|
||||||
|
| WORK_START_TIME | 07:00 | Workday start (HH:MM) |
|
||||||
|
| WORK_END_TIME | 17:30 | Workday end (HH:MM) |
|
||||||
|
| WORK_DAYS | 0,1,2,3 | JS day numbers (Sun=0) |
|
||||||
|
| UPDATE_INTERVAL_MS | 60000 | Update frequency |
|
||||||
|
|
||||||
|
### Configuration
|
||||||
|
|
||||||
|
| Variable | Default | Description |
|
||||||
|
|--------|---------|-------------|
|
||||||
|
| WORK_START_TIME | 07:00 | Workday start (HH:MM) |
|
||||||
|
| WORK_END_TIME | 17:30 | Workday end (HH:MM) |
|
||||||
|
| WORK_DAYS | 0,1,2,3 | JS day numbers (Sun=0) |
|
||||||
|
| UPDATE_INTERVAL_MS | 60000 | Update frequency |
|
||||||
|
|
||||||
## Tech Stack
|
## Tech Stack
|
||||||
|
|
||||||
- **Flask** – serves the page and minds its business
|
- **Flask** – serves the page and minds its business
|
||||||
|
|||||||
35
app.py
35
app.py
@@ -1,10 +1,41 @@
|
|||||||
|
import os
|
||||||
from flask import Flask, render_template
|
from flask import Flask, render_template
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
def parse_time(value, default):
|
||||||
|
try:
|
||||||
|
hour, minute = map(int, value.split(":"))
|
||||||
|
return {"hour": hour, "minute": minute}
|
||||||
|
except Exception:
|
||||||
|
return default
|
||||||
|
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
def index():
|
def index():
|
||||||
return render_template("index.html")
|
start_time = parse_time(
|
||||||
|
os.getenv("WORK_START_TIME", "07:00"),
|
||||||
|
{"hour": 7, "minute": 0}
|
||||||
|
)
|
||||||
|
end_time = parse_time(
|
||||||
|
os.getenv("WORK_END_TIME", "17:30"),
|
||||||
|
{"hour": 17, "minute": 30}
|
||||||
|
)
|
||||||
|
|
||||||
|
work_days = [
|
||||||
|
int(d.strip())
|
||||||
|
for d in os.getenv("WORK_DAYS", "0,1,2,3").split(",")
|
||||||
|
if d.strip().isdigit()
|
||||||
|
]
|
||||||
|
|
||||||
|
update_interval = int(os.getenv("UPDATE_INTERVAL_MS", "60000"))
|
||||||
|
|
||||||
|
return render_template(
|
||||||
|
"index.html",
|
||||||
|
work_start=start_time,
|
||||||
|
work_end=end_time,
|
||||||
|
work_days=work_days,
|
||||||
|
update_interval=update_interval
|
||||||
|
)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app.run(host="0.0.0.0", port=5000, debug=True)
|
app.run(host="0.0.0.0", port=5000)
|
||||||
|
|||||||
@@ -25,14 +25,34 @@
|
|||||||
<div class="percent weekly-percent" id="weeklyPercent">0%</div>
|
<div class="percent weekly-percent" id="weeklyPercent">0%</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
<!-- App configuration -->
|
||||||
const WORK_START_HOUR = 7;
|
<script id="app-config" type="application/json">
|
||||||
const WORK_START_MINUTE = 0;
|
{{ {
|
||||||
const WORK_END_HOUR = 17;
|
"workStart": work_start,
|
||||||
const WORK_END_MINUTE = 30;
|
"workEnd": work_end,
|
||||||
|
"workDays": work_days,
|
||||||
|
"updateInterval": update_interval
|
||||||
|
} | tojson }}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<!-- Application logic -->
|
||||||
|
<script>
|
||||||
|
const config = JSON.parse(
|
||||||
|
document.getElementById("app-config").textContent
|
||||||
|
);
|
||||||
|
|
||||||
|
const WORK_START_HOUR = config.workStart.hour;
|
||||||
|
const WORK_START_MINUTE = config.workStart.minute;
|
||||||
|
const WORK_END_HOUR = config.workEnd.hour;
|
||||||
|
const WORK_END_MINUTE = config.workEnd.minute;
|
||||||
|
|
||||||
|
const WORK_DAYS = config.workDays;
|
||||||
|
const UPDATE_INTERVAL = config.updateInterval;
|
||||||
|
|
||||||
|
const TOTAL_WORK_MINUTES =
|
||||||
|
(WORK_END_HOUR * 60 + WORK_END_MINUTE) -
|
||||||
|
(WORK_START_HOUR * 60 + WORK_START_MINUTE);
|
||||||
|
|
||||||
const TOTAL_WORK_MINUTES = 630; // 10.5 hours
|
|
||||||
const WORK_DAYS = [0, 1, 2, 3]; // Sunday → Wednesday
|
|
||||||
const WEEKLY_DAY_WEIGHT = 100 / WORK_DAYS.length;
|
const WEEKLY_DAY_WEIGHT = 100 / WORK_DAYS.length;
|
||||||
|
|
||||||
function updateProgress() {
|
function updateProgress() {
|
||||||
@@ -64,16 +84,19 @@
|
|||||||
statusText.textContent = "Workday complete 🎉";
|
statusText.textContent = "Workday complete 🎉";
|
||||||
} else {
|
} else {
|
||||||
const elapsedMinutes = Math.floor((now - start) / 60000);
|
const elapsedMinutes = Math.floor((now - start) / 60000);
|
||||||
dailyPercent = Math.min((elapsedMinutes / TOTAL_WORK_MINUTES) * 100, 100);
|
dailyPercent = Math.min(
|
||||||
|
(elapsedMinutes / TOTAL_WORK_MINUTES) * 100,
|
||||||
|
100
|
||||||
|
);
|
||||||
statusText.textContent = "Grinding…";
|
statusText.textContent = "Grinding…";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply daily progress
|
// Daily progress
|
||||||
dailyFill.style.width = dailyPercent + "%";
|
dailyFill.style.width = dailyPercent + "%";
|
||||||
dailyPercentText.textContent = dailyPercent.toFixed(1) + "%";
|
dailyPercentText.textContent = dailyPercent.toFixed(1) + "%";
|
||||||
|
|
||||||
// Weekly progress
|
// Weekly progress
|
||||||
let completedDays = WORK_DAYS.filter(d => d < day).length;
|
const completedDays = WORK_DAYS.filter(d => d < day).length;
|
||||||
let weeklyPercent =
|
let weeklyPercent =
|
||||||
(completedDays * WEEKLY_DAY_WEIGHT) +
|
(completedDays * WEEKLY_DAY_WEIGHT) +
|
||||||
(isWorkday ? (dailyPercent / 100) * WEEKLY_DAY_WEIGHT : 0);
|
(isWorkday ? (dailyPercent / 100) * WEEKLY_DAY_WEIGHT : 0);
|
||||||
@@ -85,7 +108,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
updateProgress();
|
updateProgress();
|
||||||
setInterval(updateProgress, 5 * 1000);
|
setInterval(updateProgress, UPDATE_INTERVAL);
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Reference in New Issue
Block a user