restore legacy, include shorcut scripts
This commit is contained in:
85
dmapp/dmos/SETUP-KEYBOARD-SHORTCUTS.md
Normal file
85
dmapp/dmos/SETUP-KEYBOARD-SHORTCUTS.md
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
# Date/Time Clipboard Shortcuts Setup
|
||||||
|
|
||||||
|
This replaces espanso with a cleaner clipboard-based solution that won't trigger "Updated keyboard layout" notifications.
|
||||||
|
|
||||||
|
## How It Works
|
||||||
|
|
||||||
|
Instead of text expansion, keyboard shortcuts copy the formatted date/time to clipboard. You then paste with `Ctrl+V`.
|
||||||
|
|
||||||
|
## Available Formats
|
||||||
|
|
||||||
|
- **wd**: ISO week.day (e.g., `52.4`)
|
||||||
|
- **3t**: 360-time division (e.g., `331`)
|
||||||
|
- **uid**: Random UUID 8 chars (e.g., `a8b9bf0a`)
|
||||||
|
|
||||||
|
## GNOME Keyboard Shortcuts Setup
|
||||||
|
|
||||||
|
1. Open Settings → Keyboard → Keyboard Shortcuts (or run: `gnome-control-center keyboard`)
|
||||||
|
|
||||||
|
2. Scroll to bottom and click "+ Add Custom Shortcut"
|
||||||
|
|
||||||
|
3. Add three shortcuts:
|
||||||
|
|
||||||
|
### Shortcut 1: Week Day
|
||||||
|
- **Name**: `Copy Week.Day`
|
||||||
|
- **Command**: `/home/mariano/wdir/dm/dmapp/dmos/datetime-clipboard.py wd`
|
||||||
|
- **Shortcut**: `Ctrl+Super+W`
|
||||||
|
|
||||||
|
### Shortcut 2: 360-Time
|
||||||
|
- **Name**: `Copy 360-Time`
|
||||||
|
- **Command**: `/home/mariano/wdir/dm/dmapp/dmos/datetime-clipboard.py 3t`
|
||||||
|
- **Shortcut**: `Ctrl+Super+T`
|
||||||
|
|
||||||
|
### Shortcut 3: UUID
|
||||||
|
- **Name**: `Copy UUID`
|
||||||
|
- **Command**: `/home/mariano/wdir/dm/dmapp/dmos/datetime-clipboard.py uid`
|
||||||
|
- **Shortcut**: `Ctrl+Super+U`
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
1. Press the keyboard shortcut (e.g., `Ctrl+Super+W`)
|
||||||
|
2. Paste with `Ctrl+V` wherever you need it
|
||||||
|
|
||||||
|
## Advantages Over Espanso
|
||||||
|
|
||||||
|
- No keyboard layout notifications
|
||||||
|
- Works reliably on Wayland
|
||||||
|
- Simpler architecture (no daemon running)
|
||||||
|
- More control over when to paste
|
||||||
|
- Works in password fields and other protected inputs
|
||||||
|
|
||||||
|
## Removing Espanso (Optional)
|
||||||
|
|
||||||
|
If you want to fully switch away from espanso:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Stop espanso service
|
||||||
|
espanso stop
|
||||||
|
|
||||||
|
# Disable autostart
|
||||||
|
espanso service unregister
|
||||||
|
|
||||||
|
# Uninstall (if desired)
|
||||||
|
# sudo apt remove espanso # or however you installed it
|
||||||
|
```
|
||||||
|
|
||||||
|
## Testing
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Test each format
|
||||||
|
/home/mariano/wdir/dm/dmapp/dmos/datetime-clipboard.py wd
|
||||||
|
/home/mariano/wdir/dm/dmapp/dmos/datetime-clipboard.py 3t
|
||||||
|
/home/mariano/wdir/dm/dmapp/dmos/datetime-clipboard.py uid
|
||||||
|
|
||||||
|
# Then paste to verify clipboard contents
|
||||||
|
```
|
||||||
|
|
||||||
|
## Cross-Platform Notes
|
||||||
|
|
||||||
|
This solution is part of the deskmeter cross-platform configuration effort:
|
||||||
|
|
||||||
|
- **Linux (Wayland/X11)**: Uses `wl-copy` or `xclip` for clipboard
|
||||||
|
- **Windows**: Would require AutoHotkey or similar for global shortcuts
|
||||||
|
- **macOS**: Would use `pbcopy` for clipboard
|
||||||
|
|
||||||
|
The core datetime logic is platform-independent Python. Only clipboard mechanism needs platform-specific handling.
|
||||||
85
dmapp/dmos/cyclework.py
Normal file
85
dmapp/dmos/cyclework.py
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
# Define the list of workspaces to cycle through
|
||||||
|
WORKSPACES = [3, 6, 7, 8]
|
||||||
|
|
||||||
|
LAST_WS_FILE = "/tmp/lastws"
|
||||||
|
|
||||||
|
|
||||||
|
def get_current_workspace():
|
||||||
|
result = subprocess.run(["wmctrl", "-d"], capture_output=True, text=True)
|
||||||
|
lines = result.stdout.splitlines()
|
||||||
|
|
||||||
|
for line in lines:
|
||||||
|
if "*" in line: # The active workspace has a '*' symbol
|
||||||
|
try:
|
||||||
|
current_workspace = int(line.split()[0]) + 1
|
||||||
|
print(f"Current workspace detected: {current_workspace}")
|
||||||
|
return current_workspace
|
||||||
|
except (IndexError, ValueError):
|
||||||
|
print("Error parsing current workspace.")
|
||||||
|
return None
|
||||||
|
|
||||||
|
print("No active workspace found.")
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def switch_to_workspace(workspace):
|
||||||
|
print(f"Switching to workspace {workspace}")
|
||||||
|
subprocess.run(["wmctrl", "-s", str(workspace - 1)])
|
||||||
|
save_last_used_workspace(workspace)
|
||||||
|
|
||||||
|
|
||||||
|
def save_last_used_workspace(workspace):
|
||||||
|
with open(LAST_WS_FILE, "w") as f:
|
||||||
|
f.write(str(workspace))
|
||||||
|
|
||||||
|
|
||||||
|
def get_last_used_workspace():
|
||||||
|
if os.path.exists(LAST_WS_FILE):
|
||||||
|
with open(LAST_WS_FILE, "r") as f:
|
||||||
|
try:
|
||||||
|
return int(f.read().strip())
|
||||||
|
except ValueError:
|
||||||
|
return WORKSPACES[0]
|
||||||
|
return WORKSPACES[0]
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
import sys
|
||||||
|
|
||||||
|
if len(sys.argv) < 2 or sys.argv[1] not in ["up", "down", "current"]:
|
||||||
|
print("Usage: python cyclework.py [up|down|current]")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
direction = sys.argv[1]
|
||||||
|
current = get_current_workspace()
|
||||||
|
|
||||||
|
if current is None:
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
if direction == "current":
|
||||||
|
if current in WORKSPACES:
|
||||||
|
print("Already in a workspace in the cycle.")
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
last_used = get_last_used_workspace()
|
||||||
|
print(f"Switching to last used workspace in cycle: {last_used}")
|
||||||
|
switch_to_workspace(last_used)
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
try:
|
||||||
|
index = WORKSPACES.index(current)
|
||||||
|
except ValueError:
|
||||||
|
print("Current workspace is not in the list.")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
if direction == "up":
|
||||||
|
index = (index + 1) % len(WORKSPACES)
|
||||||
|
else: # direction == 'down'
|
||||||
|
index = (index - 1) % len(WORKSPACES)
|
||||||
|
|
||||||
|
next_workspace = WORKSPACES[index]
|
||||||
|
switch_to_workspace(next_workspace)
|
||||||
76
dmapp/dmos/datetime-clipboard.py
Normal file
76
dmapp/dmos/datetime-clipboard.py
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""
|
||||||
|
Date/time clipboard utility for GNOME keyboard shortcuts.
|
||||||
|
Copies various date/time formats to clipboard for quick pasting.
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
datetime-clipboard.py wd # ISO week.day (e.g., 51.2)
|
||||||
|
datetime-clipboard.py 3t # 360-time format (0-359)
|
||||||
|
datetime-clipboard.py uid # UUID first 8 chars
|
||||||
|
"""
|
||||||
|
import sys
|
||||||
|
import subprocess
|
||||||
|
from datetime import datetime
|
||||||
|
import uuid
|
||||||
|
|
||||||
|
|
||||||
|
def copy_to_clipboard(text):
|
||||||
|
"""Copy text to clipboard using wl-copy (Wayland) or xclip (X11) as fallback."""
|
||||||
|
try:
|
||||||
|
# Try wl-copy first (Wayland)
|
||||||
|
subprocess.run(['wl-copy'], input=text.encode(), check=True)
|
||||||
|
except FileNotFoundError:
|
||||||
|
# Fallback to xclip (X11)
|
||||||
|
try:
|
||||||
|
subprocess.run(['xclip', '-selection', 'clipboard'],
|
||||||
|
input=text.encode(), check=True)
|
||||||
|
except FileNotFoundError:
|
||||||
|
print("Error: Neither wl-copy nor xclip found. Install wl-clipboard or xclip.",
|
||||||
|
file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
def get_weekday():
|
||||||
|
"""ISO week.day format (e.g., 51.2)"""
|
||||||
|
ywd = datetime.now().isocalendar()
|
||||||
|
return f"{ywd[1]}.{ywd[2]}"
|
||||||
|
|
||||||
|
|
||||||
|
def get_360time():
|
||||||
|
"""Day divided into 360 parts (0-359)"""
|
||||||
|
t = datetime.now()
|
||||||
|
return str((t.hour * 60 + t.minute) // (1440 // 360))
|
||||||
|
|
||||||
|
|
||||||
|
def get_uid():
|
||||||
|
"""First 8 characters of UUID"""
|
||||||
|
return str(uuid.uuid4())[:8]
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
if len(sys.argv) < 2:
|
||||||
|
print(__doc__)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
format_type = sys.argv[1].lower()
|
||||||
|
|
||||||
|
formatters = {
|
||||||
|
'wd': get_weekday,
|
||||||
|
'3t': get_360time,
|
||||||
|
'uid': get_uid,
|
||||||
|
}
|
||||||
|
|
||||||
|
if format_type not in formatters:
|
||||||
|
print(f"Unknown format: {format_type}")
|
||||||
|
print(__doc__)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
text = formatters[format_type]()
|
||||||
|
copy_to_clipboard(text)
|
||||||
|
|
||||||
|
# Optional: print to stdout for verification
|
||||||
|
print(f"Copied to clipboard: {text}")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
20
dmold/dmweb/__init__.py
Normal file
20
dmold/dmweb/__init__.py
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
from flask import Flask
|
||||||
|
|
||||||
|
from . import dm, dmcal
|
||||||
|
|
||||||
|
|
||||||
|
def create_app():
|
||||||
|
app = Flask("deskmeter")
|
||||||
|
|
||||||
|
app.debug = True
|
||||||
|
app.register_blueprint(dm.dmbp)
|
||||||
|
|
||||||
|
# Register custom Jinja2 filters
|
||||||
|
@app.template_filter('hash')
|
||||||
|
def hash_filter(s):
|
||||||
|
"""Return hash of string for consistent color generation"""
|
||||||
|
if s is None:
|
||||||
|
return 0
|
||||||
|
return hash(str(s))
|
||||||
|
|
||||||
|
return app
|
||||||
BIN
dmold/dmweb/__init__.pyc
Normal file
BIN
dmold/dmweb/__init__.pyc
Normal file
Binary file not shown.
283
dmold/dmweb/dm.py
Normal file
283
dmold/dmweb/dm.py
Normal file
@@ -0,0 +1,283 @@
|
|||||||
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
|
from flask import Blueprint, render_template, jsonify
|
||||||
|
|
||||||
|
from .get_period_times import get_period_totals, task_or_none, timezone, get_work_period_totals, get_current_task_info, convert_seconds, get_task_time_seconds, get_task_blocks_calendar, get_raw_switches
|
||||||
|
|
||||||
|
dmbp = Blueprint("deskmeter", __name__, url_prefix="/", template_folder="templates")
|
||||||
|
|
||||||
|
|
||||||
|
@dmbp.route("/favicon.ico")
|
||||||
|
def favicon():
|
||||||
|
return "", 204 # No Content
|
||||||
|
|
||||||
|
|
||||||
|
@dmbp.route("/calendar")
|
||||||
|
@dmbp.route("/calendar/<string:scope>")
|
||||||
|
@dmbp.route("/calendar/<string:scope>/<int:year>/<int:month>/<int:day>")
|
||||||
|
def calendar_view(scope="daily", year=None, month=None, day=None):
|
||||||
|
"""
|
||||||
|
Google Calendar-style view showing task blocks at their actual times.
|
||||||
|
"""
|
||||||
|
task = None
|
||||||
|
|
||||||
|
if not year:
|
||||||
|
year = datetime.today().year
|
||||||
|
if not month:
|
||||||
|
month = datetime.today().month
|
||||||
|
if not day:
|
||||||
|
day = datetime.today().day
|
||||||
|
|
||||||
|
base_date = datetime(year, month, day).replace(hour=0, minute=0, second=0, tzinfo=timezone)
|
||||||
|
|
||||||
|
if scope == "daily":
|
||||||
|
start = base_date
|
||||||
|
end = base_date.replace(hour=23, minute=59, second=59)
|
||||||
|
blocks = get_task_blocks_calendar(start, end, task, min_block_seconds=60)
|
||||||
|
prev_date = base_date - timedelta(days=1)
|
||||||
|
next_date = base_date + timedelta(days=1)
|
||||||
|
days = [base_date]
|
||||||
|
|
||||||
|
elif scope == "weekly":
|
||||||
|
start = base_date - timedelta(days=base_date.weekday())
|
||||||
|
end = start + timedelta(days=6, hours=23, minutes=59, seconds=59)
|
||||||
|
blocks = get_task_blocks_calendar(start, end, task, min_block_seconds=300)
|
||||||
|
prev_date = start - timedelta(days=7)
|
||||||
|
next_date = start + timedelta(days=7)
|
||||||
|
days = [start + timedelta(days=i) for i in range(7)]
|
||||||
|
|
||||||
|
elif scope == "monthly":
|
||||||
|
start = base_date.replace(day=1)
|
||||||
|
if month == 12:
|
||||||
|
end = datetime(year + 1, 1, 1, tzinfo=timezone) - timedelta(seconds=1)
|
||||||
|
else:
|
||||||
|
end = datetime(year, month + 1, 1, tzinfo=timezone) - timedelta(seconds=1)
|
||||||
|
blocks = get_task_blocks_calendar(start, end, task, min_block_seconds=600)
|
||||||
|
if month == 1:
|
||||||
|
prev_date = datetime(year - 1, 12, 1, tzinfo=timezone)
|
||||||
|
else:
|
||||||
|
prev_date = datetime(year, month - 1, 1, tzinfo=timezone)
|
||||||
|
if month == 12:
|
||||||
|
next_date = datetime(year + 1, 1, 1, tzinfo=timezone)
|
||||||
|
else:
|
||||||
|
next_date = datetime(year, month + 1, 1, tzinfo=timezone)
|
||||||
|
days = []
|
||||||
|
current = start
|
||||||
|
while current <= end:
|
||||||
|
days.append(current)
|
||||||
|
current += timedelta(days=1)
|
||||||
|
else:
|
||||||
|
scope = "daily"
|
||||||
|
start = base_date
|
||||||
|
end = base_date.replace(hour=23, minute=59, second=59)
|
||||||
|
blocks = get_task_blocks_calendar(start, end, task, min_block_seconds=60)
|
||||||
|
prev_date = base_date - timedelta(days=1)
|
||||||
|
next_date = base_date + timedelta(days=1)
|
||||||
|
days = [base_date]
|
||||||
|
|
||||||
|
return render_template(
|
||||||
|
"calendar_view.html",
|
||||||
|
scope=scope,
|
||||||
|
blocks=blocks,
|
||||||
|
start=start,
|
||||||
|
end=end,
|
||||||
|
base_date=base_date,
|
||||||
|
prev_date=prev_date,
|
||||||
|
next_date=next_date,
|
||||||
|
days=days,
|
||||||
|
auto_refresh=False
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@dmbp.route("/switches")
|
||||||
|
@dmbp.route("/switches/<string:scope>")
|
||||||
|
@dmbp.route("/switches/<string:scope>/<int:year>/<int:month>/<int:day>")
|
||||||
|
def switches_view(scope="daily", year=None, month=None, day=None):
|
||||||
|
"""
|
||||||
|
Raw switches view showing all switch documents.
|
||||||
|
"""
|
||||||
|
task = None
|
||||||
|
|
||||||
|
if not year:
|
||||||
|
year = datetime.today().year
|
||||||
|
if not month:
|
||||||
|
month = datetime.today().month
|
||||||
|
if not day:
|
||||||
|
day = datetime.today().day
|
||||||
|
|
||||||
|
base_date = datetime(year, month, day).replace(hour=0, minute=0, second=0, tzinfo=timezone)
|
||||||
|
|
||||||
|
if scope == "daily":
|
||||||
|
start = base_date
|
||||||
|
end = base_date.replace(hour=23, minute=59, second=59)
|
||||||
|
prev_date = base_date - timedelta(days=1)
|
||||||
|
next_date = base_date + timedelta(days=1)
|
||||||
|
|
||||||
|
elif scope == "weekly":
|
||||||
|
start = base_date - timedelta(days=base_date.weekday())
|
||||||
|
end = start + timedelta(days=6, hours=23, minutes=59, seconds=59)
|
||||||
|
prev_date = start - timedelta(days=7)
|
||||||
|
next_date = start + timedelta(days=7)
|
||||||
|
|
||||||
|
elif scope == "monthly":
|
||||||
|
start = base_date.replace(day=1)
|
||||||
|
if month == 12:
|
||||||
|
end = datetime(year + 1, 1, 1, tzinfo=timezone) - timedelta(seconds=1)
|
||||||
|
else:
|
||||||
|
end = datetime(year, month + 1, 1, tzinfo=timezone) - timedelta(seconds=1)
|
||||||
|
if month == 1:
|
||||||
|
prev_date = datetime(year - 1, 12, 1, tzinfo=timezone)
|
||||||
|
else:
|
||||||
|
prev_date = datetime(year, month - 1, 1, tzinfo=timezone)
|
||||||
|
if month == 12:
|
||||||
|
next_date = datetime(year + 1, 1, 1, tzinfo=timezone)
|
||||||
|
else:
|
||||||
|
next_date = datetime(year, month + 1, 1, tzinfo=timezone)
|
||||||
|
else:
|
||||||
|
scope = "daily"
|
||||||
|
start = base_date
|
||||||
|
end = base_date.replace(hour=23, minute=59, second=59)
|
||||||
|
prev_date = base_date - timedelta(days=1)
|
||||||
|
next_date = base_date + timedelta(days=1)
|
||||||
|
|
||||||
|
raw_switches = get_raw_switches(start, end, task)
|
||||||
|
|
||||||
|
return render_template(
|
||||||
|
"switches_view.html",
|
||||||
|
scope=scope,
|
||||||
|
switches=raw_switches,
|
||||||
|
start=start,
|
||||||
|
end=end,
|
||||||
|
base_date=base_date,
|
||||||
|
prev_date=prev_date,
|
||||||
|
next_date=next_date,
|
||||||
|
auto_refresh=False
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@dmbp.route("/")
|
||||||
|
@dmbp.route("/<string:task>")
|
||||||
|
def index(task=None):
|
||||||
|
"""
|
||||||
|
Show total time used in each desktop for today
|
||||||
|
"""
|
||||||
|
task = task_or_none(task)
|
||||||
|
|
||||||
|
start = datetime.today().replace(hour=0, minute=0, second=0, tzinfo=timezone)
|
||||||
|
end = datetime.today().replace(hour=23, minute=59, second=59, tzinfo=timezone)
|
||||||
|
|
||||||
|
rows = get_period_totals(start, end, task)
|
||||||
|
|
||||||
|
# Get current task info
|
||||||
|
current_task_id, current_task_path = get_current_task_info()
|
||||||
|
current_task_time = None
|
||||||
|
if current_task_id:
|
||||||
|
total_seconds = get_task_time_seconds(start, end, current_task_id)
|
||||||
|
if total_seconds > 0:
|
||||||
|
current_task_time = convert_seconds(total_seconds)
|
||||||
|
|
||||||
|
return render_template("main.html", rows=rows, current_task_path=current_task_path, current_task_time=current_task_time, auto_refresh=True)
|
||||||
|
|
||||||
|
|
||||||
|
@dmbp.route("/api/current_task")
|
||||||
|
def api_current_task():
|
||||||
|
"""
|
||||||
|
JSON API endpoint returning current task information
|
||||||
|
"""
|
||||||
|
current_task_id, current_task_path = get_current_task_info()
|
||||||
|
return jsonify({
|
||||||
|
"task_id": current_task_id,
|
||||||
|
"task_path": current_task_path or "no task"
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
@dmbp.route("/api/today")
|
||||||
|
@dmbp.route("/api/today/<string:task>")
|
||||||
|
def api_today(task=None):
|
||||||
|
"""
|
||||||
|
HTML fragment API endpoint for today's data (for AJAX updates)
|
||||||
|
"""
|
||||||
|
task = task_or_none(task)
|
||||||
|
|
||||||
|
start = datetime.today().replace(hour=0, minute=0, second=0, tzinfo=timezone)
|
||||||
|
end = datetime.today().replace(hour=23, minute=59, second=59, tzinfo=timezone)
|
||||||
|
|
||||||
|
rows = get_period_totals(start, end, task)
|
||||||
|
|
||||||
|
# Get current task info
|
||||||
|
current_task_id, current_task_path = get_current_task_info()
|
||||||
|
current_task_time = None
|
||||||
|
if current_task_id:
|
||||||
|
total_seconds = get_task_time_seconds(start, end, current_task_id)
|
||||||
|
if total_seconds > 0:
|
||||||
|
current_task_time = convert_seconds(total_seconds)
|
||||||
|
|
||||||
|
return render_template("main_content.html", rows=rows, current_task_path=current_task_path, current_task_time=current_task_time)
|
||||||
|
|
||||||
|
|
||||||
|
@dmbp.route("/day/<int:month>/<int:day>")
|
||||||
|
@dmbp.route("/day/<string:task>/<int:month>/<int:day>")
|
||||||
|
def oneday(
|
||||||
|
month,
|
||||||
|
day,
|
||||||
|
task=None,
|
||||||
|
):
|
||||||
|
task = task_or_none(task)
|
||||||
|
|
||||||
|
start = datetime(2025, month, day).replace(
|
||||||
|
hour=0, minute=0, second=0, tzinfo=timezone
|
||||||
|
)
|
||||||
|
|
||||||
|
end = datetime(2025, month, day).replace(
|
||||||
|
hour=23, minute=59, second=59, tzinfo=timezone
|
||||||
|
)
|
||||||
|
|
||||||
|
rows = get_period_totals(start, end)
|
||||||
|
|
||||||
|
return render_template("pages.html", rows=rows, auto_refresh=True)
|
||||||
|
|
||||||
|
|
||||||
|
@dmbp.route("/period/<start>/<end>")
|
||||||
|
def period(start, end):
|
||||||
|
start = datetime(*map(int, start.split("-"))).replace(
|
||||||
|
hour=0, minute=0, second=0, tzinfo=timezone
|
||||||
|
)
|
||||||
|
|
||||||
|
end = datetime(*map(int, end.split("-"))).replace(
|
||||||
|
hour=23, minute=59, second=59, tzinfo=timezone
|
||||||
|
)
|
||||||
|
|
||||||
|
rows = get_period_totals(start, end)
|
||||||
|
|
||||||
|
return render_template("pages.html", rows=rows, auto_refresh=True)
|
||||||
|
|
||||||
|
|
||||||
|
@dmbp.route("/work")
|
||||||
|
def work():
|
||||||
|
"""
|
||||||
|
Show total time used per work project for today
|
||||||
|
"""
|
||||||
|
start = datetime.today().replace(hour=0, minute=0, second=0, tzinfo=timezone)
|
||||||
|
end = datetime.today().replace(hour=23, minute=59, second=59, tzinfo=timezone)
|
||||||
|
|
||||||
|
rows = get_work_period_totals(start, end)
|
||||||
|
|
||||||
|
return render_template("main.html", rows=rows, auto_refresh=False)
|
||||||
|
|
||||||
|
|
||||||
|
@dmbp.route("/totals")
|
||||||
|
@dmbp.route("/totals/<string:task>")
|
||||||
|
def totals(task=None):
|
||||||
|
"""
|
||||||
|
Show total time used in each desktop for all time
|
||||||
|
"""
|
||||||
|
|
||||||
|
task = task_or_none(task)
|
||||||
|
|
||||||
|
start = datetime(2020, 1, 1).replace(hour=0, minute=0, second=0, tzinfo=timezone)
|
||||||
|
|
||||||
|
end = datetime(2030, 1, 1).replace(hour=23, minute=59, second=59, tzinfo=timezone)
|
||||||
|
|
||||||
|
rows = get_period_totals(start, end)
|
||||||
|
|
||||||
|
return render_template("pages.html", rows=rows, auto_refresh=True)
|
||||||
177
dmold/dmweb/dmcal.py
Normal file
177
dmold/dmweb/dmcal.py
Normal file
@@ -0,0 +1,177 @@
|
|||||||
|
import calendar
|
||||||
|
from datetime import datetime
|
||||||
|
from pprint import pprint
|
||||||
|
|
||||||
|
from flask import Blueprint, render_template
|
||||||
|
|
||||||
|
# import pytz
|
||||||
|
from .dm import dmbp
|
||||||
|
from .get_period_times import (
|
||||||
|
get_period_totals,
|
||||||
|
read_and_extract,
|
||||||
|
task_file,
|
||||||
|
task_or_none,
|
||||||
|
timezone,
|
||||||
|
get_work_period_totals,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class DMHTMLCalendar(calendar.HTMLCalendar):
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
self.use_work_projects = False
|
||||||
|
self.task = None
|
||||||
|
|
||||||
|
def setcalmonth(self, month):
|
||||||
|
self.dmmonth = month
|
||||||
|
|
||||||
|
def setcalyear(self, year):
|
||||||
|
self.dmyear = year
|
||||||
|
|
||||||
|
def settask(self, task):
|
||||||
|
self.task = task
|
||||||
|
|
||||||
|
def set_work_projects_mode(self, enabled=True):
|
||||||
|
self.use_work_projects = enabled
|
||||||
|
|
||||||
|
def oneday(self, month, day):
|
||||||
|
current_year = datetime.today().year
|
||||||
|
start = datetime(self.dmyear, month, day).replace(
|
||||||
|
hour=0, minute=0, second=0, tzinfo=timezone
|
||||||
|
)
|
||||||
|
end = datetime(self.dmyear, month, day).replace(
|
||||||
|
hour=23, minute=59, second=59, tzinfo=timezone
|
||||||
|
)
|
||||||
|
|
||||||
|
if self.use_work_projects:
|
||||||
|
rows = get_work_period_totals(start, end)
|
||||||
|
else:
|
||||||
|
rows = get_period_totals(start, end, self.task)
|
||||||
|
|
||||||
|
returnstr = "<table class='totaltable'>"
|
||||||
|
for row in rows:
|
||||||
|
returnstr += "<tr><td>{}</td><td>{}</td></tr>".format(
|
||||||
|
row["ws"], row["total"]
|
||||||
|
)
|
||||||
|
|
||||||
|
returnstr += "</table>"
|
||||||
|
return returnstr
|
||||||
|
|
||||||
|
def oneweek(self, month, week):
|
||||||
|
start_day = None
|
||||||
|
end_day = None
|
||||||
|
|
||||||
|
for d, wd in week:
|
||||||
|
if d == 0:
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
start_day = d
|
||||||
|
break
|
||||||
|
|
||||||
|
for d, wd in reversed(week):
|
||||||
|
if d == 0:
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
end_day = d
|
||||||
|
break
|
||||||
|
|
||||||
|
start = datetime(self.dmyear, month, start_day).replace(
|
||||||
|
hour=0, minute=0, second=0, tzinfo=timezone
|
||||||
|
)
|
||||||
|
|
||||||
|
end = datetime(self.dmyear, month, end_day).replace(
|
||||||
|
hour=23, minute=59, second=59, tzinfo=timezone
|
||||||
|
)
|
||||||
|
|
||||||
|
if self.use_work_projects:
|
||||||
|
rows = get_work_period_totals(start, end)
|
||||||
|
else:
|
||||||
|
rows = get_period_totals(start, end, self.task)
|
||||||
|
|
||||||
|
print(rows)
|
||||||
|
|
||||||
|
returnstr = "<table class='totaltable'>"
|
||||||
|
for row in rows:
|
||||||
|
returnstr += "<tr><td>{}</td><td>{}</td></tr>".format(
|
||||||
|
row["ws"], row["total"]
|
||||||
|
)
|
||||||
|
|
||||||
|
returnstr += "</table>"
|
||||||
|
return returnstr
|
||||||
|
|
||||||
|
def formatweekheader(self):
|
||||||
|
"""
|
||||||
|
Return a header for a week as a table row.
|
||||||
|
"""
|
||||||
|
s = "".join(self.formatweekday(i) for i in self.iterweekdays())
|
||||||
|
s += "<td>Week Totals</td>"
|
||||||
|
return "<tr>%s</tr>" % s
|
||||||
|
|
||||||
|
def formatweek(self, theweek):
|
||||||
|
"""
|
||||||
|
Return a complete week as a table row.
|
||||||
|
"""
|
||||||
|
s = "".join(self.formatday(d, wd) for (d, wd) in theweek)
|
||||||
|
s += "<td>{}</td>".format(self.oneweek(self.dmmonth, theweek))
|
||||||
|
return "<tr>%s</tr>" % s
|
||||||
|
|
||||||
|
def formatday(self, day, weekday):
|
||||||
|
"""
|
||||||
|
Return a day as a table cell.
|
||||||
|
"""
|
||||||
|
if day == 0:
|
||||||
|
return '<td class="noday"> </td>' # day outside month
|
||||||
|
else:
|
||||||
|
return '<td class="%s">%s</td>' % (
|
||||||
|
self.cssclasses[weekday],
|
||||||
|
self.oneday(self.dmmonth, day),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@dmbp.route("/workmonth")
|
||||||
|
@dmbp.route("/workmonth/<int:month>")
|
||||||
|
@dmbp.route("/workmonth/<int:month>/<int:year>")
|
||||||
|
def workmonth(month=None, year=None):
|
||||||
|
usemonth = datetime.today().month
|
||||||
|
useyear = datetime.today().year
|
||||||
|
|
||||||
|
if month:
|
||||||
|
usemonth = month
|
||||||
|
|
||||||
|
if year:
|
||||||
|
useyear = year
|
||||||
|
|
||||||
|
cal = DMHTMLCalendar(calendar.SATURDAY)
|
||||||
|
|
||||||
|
cal.set_work_projects_mode(True)
|
||||||
|
cal.setcalmonth(usemonth)
|
||||||
|
cal.setcalyear(useyear)
|
||||||
|
|
||||||
|
return render_template("calendar.html", content=cal.formatmonth(useyear, usemonth), auto_refresh=False)
|
||||||
|
|
||||||
|
|
||||||
|
@dmbp.route("/month")
|
||||||
|
@dmbp.route("/month/<int:month>")
|
||||||
|
@dmbp.route("/month/<int:month>/<int:year>")
|
||||||
|
@dmbp.route("/month/<string:task>")
|
||||||
|
@dmbp.route("/month/<string:task>/<int:month>")
|
||||||
|
@dmbp.route("/month/<string:task>/<int:month>/<int:year>")
|
||||||
|
def month(month=None, year=None, task=None):
|
||||||
|
usemonth = datetime.today().month
|
||||||
|
useyear = datetime.today().year
|
||||||
|
|
||||||
|
if month:
|
||||||
|
usemonth = month
|
||||||
|
|
||||||
|
if year:
|
||||||
|
useyear = year
|
||||||
|
|
||||||
|
cal = DMHTMLCalendar(calendar.SATURDAY)
|
||||||
|
|
||||||
|
cal.settask(task_or_none(task))
|
||||||
|
|
||||||
|
cal.setcalmonth(usemonth)
|
||||||
|
cal.setcalyear(useyear)
|
||||||
|
|
||||||
|
return render_template("calendar.html", content=cal.formatmonth(useyear, usemonth), auto_refresh=True)
|
||||||
550
dmold/dmweb/get_period_times.py
Normal file
550
dmold/dmweb/get_period_times.py
Normal file
@@ -0,0 +1,550 @@
|
|||||||
|
from collections import Counter, defaultdict
|
||||||
|
from datetime import datetime, timedelta
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
from pymongo import MongoClient
|
||||||
|
from zoneinfo import ZoneInfo
|
||||||
|
|
||||||
|
timezone = ZoneInfo("America/Argentina/Buenos_Aires")
|
||||||
|
utctz = ZoneInfo("UTC")
|
||||||
|
|
||||||
|
client = MongoClient()
|
||||||
|
db = client.deskmeter
|
||||||
|
switches = db.switch
|
||||||
|
tasks = db.task
|
||||||
|
task_history = db.task_history
|
||||||
|
|
||||||
|
|
||||||
|
task_file = "/home/mariano/LETRAS/adm/task/main"
|
||||||
|
task_dir = Path(task_file).parent
|
||||||
|
|
||||||
|
|
||||||
|
def parse_task_line(line):
|
||||||
|
"""Parse a task line to extract task name and ID."""
|
||||||
|
line = line.strip()
|
||||||
|
if not line:
|
||||||
|
return None, None
|
||||||
|
|
||||||
|
parts = line.split("|")
|
||||||
|
if len(parts) > 1:
|
||||||
|
task_name = parts[0].strip()
|
||||||
|
id_parts = parts[1].split()
|
||||||
|
if id_parts:
|
||||||
|
task_id = id_parts[0].strip()
|
||||||
|
return task_name, task_id
|
||||||
|
return task_name, None
|
||||||
|
|
||||||
|
return parts[0].strip(), None
|
||||||
|
|
||||||
|
|
||||||
|
def load_task_from_files(task_id):
|
||||||
|
"""Search task directory files for a task ID and load it into task_history."""
|
||||||
|
for task_filepath in task_dir.glob("*"):
|
||||||
|
if not task_filepath.is_file():
|
||||||
|
continue
|
||||||
|
|
||||||
|
current_path = []
|
||||||
|
try:
|
||||||
|
with open(task_filepath, "r") as f:
|
||||||
|
for line in f:
|
||||||
|
if not line.strip():
|
||||||
|
continue
|
||||||
|
|
||||||
|
indent = len(line) - len(line.lstrip())
|
||||||
|
level = indent // 4
|
||||||
|
|
||||||
|
task_name, found_id = parse_task_line(line)
|
||||||
|
if task_name is None:
|
||||||
|
continue
|
||||||
|
|
||||||
|
current_path = current_path[:level]
|
||||||
|
current_path.append(task_name)
|
||||||
|
full_path = "/".join(current_path)
|
||||||
|
|
||||||
|
if found_id == task_id:
|
||||||
|
# Found it! Insert into task_history
|
||||||
|
task_history.update_one(
|
||||||
|
{"task_id": task_id},
|
||||||
|
{"$set": {
|
||||||
|
"path": full_path,
|
||||||
|
"task_id": task_id,
|
||||||
|
"source_file": task_filepath.name
|
||||||
|
}},
|
||||||
|
upsert=True
|
||||||
|
)
|
||||||
|
return full_path
|
||||||
|
except:
|
||||||
|
# Skip files that can't be read
|
||||||
|
continue
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def get_task_path(task_id):
|
||||||
|
"""
|
||||||
|
Get task path from tasks collection, falling back to task_history.
|
||||||
|
If not found, searches task directory files and populates task_history on-demand.
|
||||||
|
"""
|
||||||
|
if not task_id:
|
||||||
|
return None
|
||||||
|
|
||||||
|
# Try current tasks first
|
||||||
|
task_doc = tasks.find_one({"task_id": task_id})
|
||||||
|
if task_doc and "path" in task_doc:
|
||||||
|
return task_doc["path"]
|
||||||
|
|
||||||
|
# Try task history cache
|
||||||
|
task_doc = task_history.find_one({"task_id": task_id})
|
||||||
|
if task_doc and "path" in task_doc:
|
||||||
|
return task_doc["path"]
|
||||||
|
|
||||||
|
# Not in cache, search files and populate history
|
||||||
|
task_path = load_task_from_files(task_id)
|
||||||
|
if task_path:
|
||||||
|
return task_path
|
||||||
|
|
||||||
|
# Still not found, return ID as fallback
|
||||||
|
return task_id
|
||||||
|
|
||||||
|
|
||||||
|
def get_current_task_info():
|
||||||
|
"""Get current task ID and path from state and tasks collection"""
|
||||||
|
states = db.state
|
||||||
|
current_doc = states.find_one({"_id": "current"})
|
||||||
|
|
||||||
|
if not current_doc or "task" not in current_doc:
|
||||||
|
return None, None
|
||||||
|
|
||||||
|
task_id = current_doc["task"]
|
||||||
|
task_doc = tasks.find_one({"task_id": task_id})
|
||||||
|
|
||||||
|
if task_doc and "path" in task_doc:
|
||||||
|
return task_id, task_doc["path"]
|
||||||
|
|
||||||
|
return task_id, None
|
||||||
|
|
||||||
|
|
||||||
|
def get_task_time_seconds(start, end, task_id, workspaces=None):
|
||||||
|
"""Get total seconds for a task within a time period using MongoDB aggregation."""
|
||||||
|
if workspaces is None:
|
||||||
|
workspaces = ["Plan", "Think", "Work"]
|
||||||
|
|
||||||
|
pipeline = [
|
||||||
|
{
|
||||||
|
"$match": {
|
||||||
|
"date": {"$gte": start, "$lte": end},
|
||||||
|
"task": task_id,
|
||||||
|
"workspace": {"$in": workspaces}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"$group": {
|
||||||
|
"_id": None,
|
||||||
|
"total_seconds": {"$sum": "$delta"}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
result = list(switches.aggregate(pipeline))
|
||||||
|
|
||||||
|
if result and len(result) > 0:
|
||||||
|
return result[0]["total_seconds"]
|
||||||
|
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
def task_or_none(task=None):
|
||||||
|
if not task:
|
||||||
|
task = read_and_extract(task_file)
|
||||||
|
|
||||||
|
if task == "all":
|
||||||
|
task = None
|
||||||
|
|
||||||
|
return task
|
||||||
|
|
||||||
|
|
||||||
|
def now():
|
||||||
|
return datetime.now(timezone)
|
||||||
|
|
||||||
|
|
||||||
|
def convert_seconds(seconds, use_days=False):
|
||||||
|
days = seconds // 86400
|
||||||
|
hours = (seconds % 86400) // 3600
|
||||||
|
minutes = (seconds % 3600) // 60
|
||||||
|
remaining_seconds = seconds % 60
|
||||||
|
|
||||||
|
if use_days:
|
||||||
|
return "{} days, {:02d}:{:02d}:{:02d}".format(
|
||||||
|
days, hours, minutes, remaining_seconds
|
||||||
|
)
|
||||||
|
return "{:02d}:{:02d}:{:02d}".format(hours + days * 24, minutes, remaining_seconds)
|
||||||
|
|
||||||
|
|
||||||
|
def extract(line):
|
||||||
|
if line.rstrip().endswith("*"):
|
||||||
|
pipe_index = line.find("|")
|
||||||
|
if pipe_index != -1 and len(line) > pipe_index + 8:
|
||||||
|
value = line[pipe_index + 1 : pipe_index + 9]
|
||||||
|
return value
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def read_and_extract(file_path):
|
||||||
|
with open(file_path, "r") as file:
|
||||||
|
for line in file:
|
||||||
|
value = extract(line)
|
||||||
|
if value:
|
||||||
|
return value
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def get_work_period_totals(start, end):
|
||||||
|
"""Get period totals grouped by task with full path."""
|
||||||
|
# Get all tasks with time in the period
|
||||||
|
pipeline = [
|
||||||
|
{
|
||||||
|
"$match": {
|
||||||
|
"date": {"$gte": start, "$lte": end},
|
||||||
|
"workspace": {"$in": ["Plan", "Think", "Work"]},
|
||||||
|
"task": {"$exists": True, "$ne": None}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"$group": {
|
||||||
|
"_id": "$task",
|
||||||
|
"total_seconds": {"$sum": "$delta"}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
results = list(switches.aggregate(pipeline))
|
||||||
|
combined_rows = []
|
||||||
|
|
||||||
|
for result in results:
|
||||||
|
task_id = result["_id"]
|
||||||
|
total_seconds = result["total_seconds"]
|
||||||
|
|
||||||
|
if total_seconds > 0:
|
||||||
|
# Get task path with history fallback
|
||||||
|
task_path = get_task_path(task_id)
|
||||||
|
|
||||||
|
combined_rows.append({
|
||||||
|
"ws": task_path,
|
||||||
|
"total": convert_seconds(total_seconds)
|
||||||
|
})
|
||||||
|
|
||||||
|
# Sort by path for consistency
|
||||||
|
combined_rows.sort(key=lambda x: x["ws"])
|
||||||
|
return combined_rows
|
||||||
|
|
||||||
|
|
||||||
|
def get_task_blocks_calendar(start, end, task=None, min_block_seconds=300):
|
||||||
|
"""
|
||||||
|
Get task blocks for calendar-style visualization.
|
||||||
|
Groups consecutive switches to the same task into blocks, tracking active/idle time.
|
||||||
|
|
||||||
|
Returns list of blocks:
|
||||||
|
[{
|
||||||
|
'task_id': str,
|
||||||
|
'task_path': str,
|
||||||
|
'start': datetime,
|
||||||
|
'end': datetime,
|
||||||
|
'duration': int (total seconds),
|
||||||
|
'active_seconds': int (Plan/Think/Work time),
|
||||||
|
'idle_seconds': int (Other/Away time),
|
||||||
|
'active_ratio': float (0.0 to 1.0)
|
||||||
|
}, ...]
|
||||||
|
"""
|
||||||
|
task_query = {"$in": task.split(",")} if task else {}
|
||||||
|
|
||||||
|
match_query = {"date": {"$gte": start, "$lte": end}}
|
||||||
|
if task_query:
|
||||||
|
match_query["task"] = task_query
|
||||||
|
|
||||||
|
# Get all switches in period, sorted by date
|
||||||
|
raw_switches = list(switches.find(match_query).sort("date", 1))
|
||||||
|
|
||||||
|
if not raw_switches:
|
||||||
|
return []
|
||||||
|
|
||||||
|
blocks = []
|
||||||
|
current_block = None
|
||||||
|
|
||||||
|
for switch in raw_switches:
|
||||||
|
ws = switch["workspace"]
|
||||||
|
task_id = switch.get("task")
|
||||||
|
switch_start = switch["date"].replace(tzinfo=utctz).astimezone(timezone)
|
||||||
|
switch_duration = switch["delta"]
|
||||||
|
switch_end = switch_start + timedelta(seconds=switch_duration)
|
||||||
|
|
||||||
|
is_active = ws in ["Plan", "Think", "Work"]
|
||||||
|
|
||||||
|
# Start new block if task changed
|
||||||
|
if current_block is None or current_block["task_id"] != task_id:
|
||||||
|
if current_block is not None:
|
||||||
|
blocks.append(current_block)
|
||||||
|
|
||||||
|
# Get task path with history fallback
|
||||||
|
task_path = get_task_path(task_id) or "No Task"
|
||||||
|
|
||||||
|
current_block = {
|
||||||
|
"task_id": task_id,
|
||||||
|
"task_path": task_path,
|
||||||
|
"start": switch_start,
|
||||||
|
"end": switch_end,
|
||||||
|
"duration": switch_duration,
|
||||||
|
"active_seconds": switch_duration if is_active else 0,
|
||||||
|
"idle_seconds": 0 if is_active else switch_duration
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
# Extend current block
|
||||||
|
current_block["end"] = switch_end
|
||||||
|
current_block["duration"] += switch_duration
|
||||||
|
if is_active:
|
||||||
|
current_block["active_seconds"] += switch_duration
|
||||||
|
else:
|
||||||
|
current_block["idle_seconds"] += switch_duration
|
||||||
|
|
||||||
|
# Add final block
|
||||||
|
if current_block is not None:
|
||||||
|
blocks.append(current_block)
|
||||||
|
|
||||||
|
# Filter out very short blocks and calculate active ratio
|
||||||
|
filtered_blocks = []
|
||||||
|
for block in blocks:
|
||||||
|
if block["duration"] >= min_block_seconds:
|
||||||
|
block["active_ratio"] = block["active_seconds"] / block["duration"] if block["duration"] > 0 else 0
|
||||||
|
filtered_blocks.append(block)
|
||||||
|
|
||||||
|
return filtered_blocks
|
||||||
|
|
||||||
|
|
||||||
|
def get_raw_switches(start, end, task=None):
|
||||||
|
"""
|
||||||
|
Get all raw switch documents in the period.
|
||||||
|
|
||||||
|
Returns list of switches:
|
||||||
|
[{
|
||||||
|
'workspace': str,
|
||||||
|
'task_id': str,
|
||||||
|
'task_path': str,
|
||||||
|
'date': datetime,
|
||||||
|
'delta': int (seconds)
|
||||||
|
}, ...]
|
||||||
|
"""
|
||||||
|
task_query = {"$in": task.split(",")} if task else {}
|
||||||
|
|
||||||
|
match_query = {"date": {"$gte": start, "$lte": end}}
|
||||||
|
if task_query:
|
||||||
|
match_query["task"] = task_query
|
||||||
|
|
||||||
|
raw_switches = list(switches.find(match_query).sort("date", 1))
|
||||||
|
|
||||||
|
result = []
|
||||||
|
for switch in raw_switches:
|
||||||
|
task_id = switch.get("task")
|
||||||
|
# Get task path with history fallback
|
||||||
|
task_path = get_task_path(task_id) or "No Task"
|
||||||
|
|
||||||
|
result.append({
|
||||||
|
"workspace": switch["workspace"],
|
||||||
|
"task_id": task_id,
|
||||||
|
"task_path": task_path,
|
||||||
|
"date": switch["date"].replace(tzinfo=utctz).astimezone(timezone),
|
||||||
|
"delta": switch["delta"]
|
||||||
|
})
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def get_period_totals(start, end, task=None):
|
||||||
|
task_query = {"$in": task.split(",")} if task else {}
|
||||||
|
|
||||||
|
match_query = {"date": {"$gte": start, "$lte": end}}
|
||||||
|
if task_query:
|
||||||
|
match_query["task"] = task_query
|
||||||
|
|
||||||
|
pipeline = [
|
||||||
|
{"$match": match_query},
|
||||||
|
{"$sort": {"date": 1}},
|
||||||
|
{
|
||||||
|
"$group": {
|
||||||
|
"_id": None,
|
||||||
|
"documents_in_range": {"$push": "$$ROOT"},
|
||||||
|
"first_doc": {"$first": "$$ROOT"},
|
||||||
|
"last_doc": {"$last": "$$ROOT"},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"$lookup": {
|
||||||
|
"from": "switch",
|
||||||
|
"let": {"first_date": "$first_doc.date", "task": "$first_doc.task"},
|
||||||
|
"pipeline": [
|
||||||
|
{
|
||||||
|
"$match": {
|
||||||
|
"$expr": {
|
||||||
|
"$and": [
|
||||||
|
{
|
||||||
|
"$lt": ["$date", "$$first_date"]
|
||||||
|
}, # Only before the first date
|
||||||
|
{
|
||||||
|
"$eq": ["$task", "$$task"]
|
||||||
|
}, # Must have the same task
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{"$sort": {"date": -1}}, # Get the most recent (closest) document
|
||||||
|
{"$limit": 1}, # Only the immediate previous document
|
||||||
|
],
|
||||||
|
"as": "before_first",
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"$project": {
|
||||||
|
"documents": {
|
||||||
|
"$concatArrays": [
|
||||||
|
{"$ifNull": ["$before_first", []]}, # Add only if found
|
||||||
|
"$documents_in_range",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{"$unwind": "$documents"},
|
||||||
|
{"$replaceRoot": {"newRoot": "$documents"}},
|
||||||
|
{
|
||||||
|
"$group": {
|
||||||
|
"_id": "$workspace",
|
||||||
|
"total": {"$sum": "$delta"},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
results = list(switches.aggregate(pipeline))
|
||||||
|
|
||||||
|
if not results:
|
||||||
|
return [{"ws": "No Data", "total": ""}]
|
||||||
|
|
||||||
|
pipeline_before_after = [
|
||||||
|
# Match documents within the date range
|
||||||
|
{"$match": match_query},
|
||||||
|
{"$sort": {"date": 1}},
|
||||||
|
{
|
||||||
|
"$group": {
|
||||||
|
"_id": None,
|
||||||
|
"first_doc": {"$first": "$$ROOT"},
|
||||||
|
"last_doc": {"$last": "$$ROOT"},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
# Lookup to get one document before the first document in the range
|
||||||
|
{
|
||||||
|
"$lookup": {
|
||||||
|
"from": "switch",
|
||||||
|
"let": {"first_date": "$first_doc.date", "task": "$first_doc.task"},
|
||||||
|
"pipeline": [
|
||||||
|
{
|
||||||
|
"$match": {
|
||||||
|
"$expr": {
|
||||||
|
"$and": [
|
||||||
|
{
|
||||||
|
"$lt": ["$date", "$$first_date"]
|
||||||
|
}, # Only before the first date
|
||||||
|
{
|
||||||
|
"$eq": ["$task", "$$task"]
|
||||||
|
}, # Must have the same task
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{"$sort": {"date": -1}}, # Get the most recent (closest) document
|
||||||
|
{"$limit": 1}, # Only the immediate previous document
|
||||||
|
],
|
||||||
|
"as": "before_first",
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"$project": {
|
||||||
|
"before_first": {
|
||||||
|
"$ifNull": [{"$arrayElemAt": ["$before_first", 0]}, ""]
|
||||||
|
},
|
||||||
|
"last_doc": "$last_doc", # Include the last_doc from the matched period
|
||||||
|
}
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
aux_results = list(switches.aggregate(pipeline_before_after))
|
||||||
|
|
||||||
|
# Safety check: if aux_results is empty, return early with no data
|
||||||
|
if not aux_results:
|
||||||
|
return [{"ws": "No Data", "total": ""}]
|
||||||
|
|
||||||
|
bfirst = aux_results[0]["before_first"]
|
||||||
|
start_delta = 0
|
||||||
|
|
||||||
|
if bfirst:
|
||||||
|
bfdate = bfirst["date"].replace(tzinfo=utctz)
|
||||||
|
time_since_bfirst = round((start - bfdate.astimezone(timezone)).total_seconds())
|
||||||
|
|
||||||
|
# Only apply start_delta if the before_first switch actually crosses into the period
|
||||||
|
# If time_since_bfirst > bfirst["delta"], the switch ended before the period started
|
||||||
|
if time_since_bfirst <= bfirst["delta"]:
|
||||||
|
start_delta = time_since_bfirst
|
||||||
|
|
||||||
|
ldoc = aux_results[0]["last_doc"]
|
||||||
|
lastdate = ldoc["date"].replace(tzinfo=utctz)
|
||||||
|
end_delta = round((end - lastdate.astimezone(timezone)).total_seconds())
|
||||||
|
|
||||||
|
rows = []
|
||||||
|
active_vs_idle = {"Active": 0, "Idle": 0}
|
||||||
|
|
||||||
|
for result in results:
|
||||||
|
if bfirst:
|
||||||
|
if result["_id"] == bfirst["workspace"]:
|
||||||
|
# Safety: ensure start_delta doesn't exceed total
|
||||||
|
adjustment = min(start_delta, result["total"])
|
||||||
|
result["total"] -= adjustment
|
||||||
|
|
||||||
|
if end < now():
|
||||||
|
if result["_id"] == ldoc["workspace"]:
|
||||||
|
# Safety: ensure we don't subtract more than the total
|
||||||
|
adjustment = ldoc["delta"] - end_delta
|
||||||
|
safe_adjustment = min(adjustment, result["total"])
|
||||||
|
result["total"] -= safe_adjustment
|
||||||
|
|
||||||
|
for result in results:
|
||||||
|
if result["total"] > 0:
|
||||||
|
rows.append(
|
||||||
|
{"ws": result["_id"], "total": convert_seconds(result["total"])}
|
||||||
|
)
|
||||||
|
if result["_id"] in ["Think", "Plan", "Work"]:
|
||||||
|
active_vs_idle["Active"] += result["total"]
|
||||||
|
if result["_id"] in ["Away", "Other"]:
|
||||||
|
active_vs_idle["Idle"] += result["total"]
|
||||||
|
|
||||||
|
order = ["Plan", "Think", "Work", "Other", "Away", "Active", "Idle"]
|
||||||
|
|
||||||
|
rows = sorted(rows, key=lambda x: order.index(x["ws"]))
|
||||||
|
|
||||||
|
for k, v in active_vs_idle.items():
|
||||||
|
rows.append({"ws": k, "total": convert_seconds(v)})
|
||||||
|
|
||||||
|
return rows
|
||||||
|
|
||||||
|
|
||||||
|
# print(
|
||||||
|
# get_period_totals(
|
||||||
|
# datetime.today().replace(hour=0, minute=0, second=0, tzinfo=timezone)
|
||||||
|
# - timedelta(days=1),
|
||||||
|
# datetime.today().replace(hour=23, minute=59, second=59, tzinfo=timezone)
|
||||||
|
# - timedelta(days=1),
|
||||||
|
# # "ffbe198e",
|
||||||
|
# )
|
||||||
|
# )
|
||||||
|
|
||||||
|
# print(
|
||||||
|
# get_period_totals(
|
||||||
|
# datetime.today().replace(hour=0, minute=0, second=0, tzinfo=timezone),
|
||||||
|
# datetime.today().replace(hour=23, minute=59, second=59, tzinfo=timezone),
|
||||||
|
# "5fc751ec",
|
||||||
|
# )
|
||||||
|
# )
|
||||||
4
dmold/dmweb/run.py
Normal file
4
dmold/dmweb/run.py
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
from dmweb import create_app
|
||||||
|
|
||||||
|
app = create_app()
|
||||||
|
app.run(host="0.0.0.0", debug=True, threaded=True, port=10000)
|
||||||
7
dmold/dmweb/static/styles/dm.css
Normal file
7
dmold/dmweb/static/styles/dm.css
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
.sat {
|
||||||
|
height: 200px;
|
||||||
|
}
|
||||||
|
|
||||||
|
table {
|
||||||
|
border: 1px solid black;
|
||||||
|
}
|
||||||
32
dmold/dmweb/templates/calendar.html
Normal file
32
dmold/dmweb/templates/calendar.html
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
{% extends 'layout.html' %}
|
||||||
|
|
||||||
|
{% block head %}
|
||||||
|
|
||||||
|
|
||||||
|
<style type="text/css">
|
||||||
|
|
||||||
|
td > * {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
td {
|
||||||
|
vertical-align : top;
|
||||||
|
height: 25px;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
table {
|
||||||
|
width: 100%;
|
||||||
|
border: 1px solid black;
|
||||||
|
}
|
||||||
|
|
||||||
|
</style>
|
||||||
|
|
||||||
|
{% endblock head %}
|
||||||
|
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
|
||||||
|
{{ content | safe }}
|
||||||
|
|
||||||
|
{% endblock content %}
|
||||||
244
dmold/dmweb/templates/calendar_view.html
Normal file
244
dmold/dmweb/templates/calendar_view.html
Normal file
@@ -0,0 +1,244 @@
|
|||||||
|
{% extends 'layout.html' %}
|
||||||
|
|
||||||
|
{% block head %}
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
margin: 20px;
|
||||||
|
font-family: monospace;
|
||||||
|
background: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav-tabs {
|
||||||
|
display: flex;
|
||||||
|
gap: 20px;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
border-bottom: 2px solid #333;
|
||||||
|
padding-bottom: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav-tabs a {
|
||||||
|
text-decoration: none;
|
||||||
|
color: #666;
|
||||||
|
font-size: 16pt;
|
||||||
|
padding: 5px 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav-tabs a.active {
|
||||||
|
color: #000;
|
||||||
|
font-weight: bold;
|
||||||
|
border-bottom: 3px solid #000;
|
||||||
|
}
|
||||||
|
|
||||||
|
.date-nav {
|
||||||
|
margin: 20px 0;
|
||||||
|
font-size: 14pt;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.date-nav a {
|
||||||
|
text-decoration: none;
|
||||||
|
color: #2563eb;
|
||||||
|
font-size: 18pt;
|
||||||
|
}
|
||||||
|
|
||||||
|
.date-info {
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
.calendar-grid {
|
||||||
|
display: flex;
|
||||||
|
border: 1px solid #ddd;
|
||||||
|
min-height: 600px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.time-column {
|
||||||
|
width: 60px;
|
||||||
|
border-right: 1px solid #ddd;
|
||||||
|
background: #f9f9f9;
|
||||||
|
}
|
||||||
|
|
||||||
|
.time-slot {
|
||||||
|
height: 60px;
|
||||||
|
border-bottom: 1px solid #eee;
|
||||||
|
padding: 5px;
|
||||||
|
font-size: 10pt;
|
||||||
|
color: #666;
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
|
|
||||||
|
.days-grid {
|
||||||
|
flex: 1;
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
|
|
||||||
|
.day-column {
|
||||||
|
flex: 1;
|
||||||
|
border-right: 1px solid #ddd;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.day-column:last-child {
|
||||||
|
border-right: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.day-header {
|
||||||
|
height: 40px;
|
||||||
|
border-bottom: 2px solid #ddd;
|
||||||
|
background: #f0f0f0;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
font-weight: bold;
|
||||||
|
font-size: 11pt;
|
||||||
|
}
|
||||||
|
|
||||||
|
.day-grid {
|
||||||
|
position: relative;
|
||||||
|
height: 1440px; /* 24 hours * 60px */
|
||||||
|
}
|
||||||
|
|
||||||
|
.hour-line {
|
||||||
|
position: absolute;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
height: 60px;
|
||||||
|
border-bottom: 1px solid #eee;
|
||||||
|
}
|
||||||
|
|
||||||
|
.task-block {
|
||||||
|
position: absolute;
|
||||||
|
left: 2px;
|
||||||
|
right: 2px;
|
||||||
|
border-radius: 4px;
|
||||||
|
padding: 4px;
|
||||||
|
font-size: 9pt;
|
||||||
|
color: white;
|
||||||
|
overflow: hidden;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.2s;
|
||||||
|
box-shadow: 0 1px 3px rgba(0,0,0,0.2);
|
||||||
|
}
|
||||||
|
|
||||||
|
.task-block:hover {
|
||||||
|
z-index: 100;
|
||||||
|
transform: scale(1.05);
|
||||||
|
box-shadow: 0 4px 8px rgba(0,0,0,0.3);
|
||||||
|
}
|
||||||
|
|
||||||
|
.task-label {
|
||||||
|
font-weight: bold;
|
||||||
|
margin-bottom: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.task-time {
|
||||||
|
font-size: 8pt;
|
||||||
|
opacity: 0.9;
|
||||||
|
}
|
||||||
|
|
||||||
|
.block-tooltip {
|
||||||
|
display: none;
|
||||||
|
position: absolute;
|
||||||
|
background: #333;
|
||||||
|
color: white;
|
||||||
|
padding: 8px 12px;
|
||||||
|
border-radius: 4px;
|
||||||
|
font-size: 10pt;
|
||||||
|
z-index: 1000;
|
||||||
|
white-space: nowrap;
|
||||||
|
pointer-events: none;
|
||||||
|
left: 100%;
|
||||||
|
top: 0;
|
||||||
|
margin-left: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.task-block:hover .block-tooltip {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
{% endblock head %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
|
||||||
|
<div class="nav-tabs">
|
||||||
|
<a href="/calendar/daily/{{ base_date.year }}/{{ base_date.month }}/{{ base_date.day }}"
|
||||||
|
class="{% if scope == 'daily' %}active{% endif %}">Daily</a>
|
||||||
|
<a href="/calendar/weekly/{{ base_date.year }}/{{ base_date.month }}/{{ base_date.day }}"
|
||||||
|
class="{% if scope == 'weekly' %}active{% endif %}">Weekly</a>
|
||||||
|
<a href="/calendar/monthly/{{ base_date.year }}/{{ base_date.month }}/{{ base_date.day }}"
|
||||||
|
class="{% if scope == 'monthly' %}active{% endif %}">Monthly</a>
|
||||||
|
<span style="margin-left: auto;">
|
||||||
|
<a href="/switches/{{ scope }}/{{ base_date.year }}/{{ base_date.month }}/{{ base_date.day }}">View Switches</a>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="date-nav">
|
||||||
|
<a href="/calendar/{{ scope }}/{{ prev_date.year }}/{{ prev_date.month }}/{{ prev_date.day }}">←</a>
|
||||||
|
{% if scope == 'daily' %}
|
||||||
|
<span class="date-info">{{ base_date.strftime('%Y-%m-%d %A') }}</span>
|
||||||
|
{% elif scope == 'weekly' %}
|
||||||
|
<span class="date-info">Week of {{ start.strftime('%Y-%m-%d') }}</span>
|
||||||
|
{% elif scope == 'monthly' %}
|
||||||
|
<span class="date-info">{{ base_date.strftime('%B %Y') }}</span>
|
||||||
|
{% endif %}
|
||||||
|
<a href="/calendar/{{ scope }}/{{ next_date.year }}/{{ next_date.month }}/{{ next_date.day }}">→</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="calendar-grid">
|
||||||
|
<div class="time-column">
|
||||||
|
<div class="day-header" style="height: 40px;"></div>
|
||||||
|
{% for hour in range(24) %}
|
||||||
|
<div class="time-slot">{{ '%02d:00'|format(hour) }}</div>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="days-grid">
|
||||||
|
{% for day in days %}
|
||||||
|
<div class="day-column">
|
||||||
|
<div class="day-header">
|
||||||
|
{{ day.strftime('%a %d') if scope != 'daily' else day.strftime('%A') }}
|
||||||
|
</div>
|
||||||
|
<div class="day-grid">
|
||||||
|
{% for hour in range(24) %}
|
||||||
|
<div class="hour-line" style="top: {{ hour * 60 }}px;"></div>
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
{% for block in blocks %}
|
||||||
|
{% if block.start.date() == day.date() %}
|
||||||
|
{% set start_hour = block.start.hour + block.start.minute / 60.0 %}
|
||||||
|
{% set duration_hours = block.duration / 3600.0 %}
|
||||||
|
{% set top_px = start_hour * 60 %}
|
||||||
|
{% set height_px = duration_hours * 60 %}
|
||||||
|
{% if height_px < 2 %}{% set height_px = 2 %}{% endif %}
|
||||||
|
|
||||||
|
{% set task_hash = block.task_path|hash if block.task_path else 0 %}
|
||||||
|
{% set base_color_hue = task_hash % 360 %}
|
||||||
|
|
||||||
|
{# Create gradient: active color on left (0% to active_ratio%), idle color on right #}
|
||||||
|
{% set active_pct = (block.active_ratio * 100)|int %}
|
||||||
|
{% set active_color = 'hsl(%d, 70%%, 50%%)'|format(base_color_hue) %}
|
||||||
|
{% set idle_color = 'hsl(%d, 30%%, 70%%)'|format(base_color_hue) %}
|
||||||
|
|
||||||
|
<div class="task-block"
|
||||||
|
style="top: {{ top_px }}px; height: {{ height_px }}px;
|
||||||
|
background: linear-gradient(to right, {{ active_color }} 0%, {{ active_color }} {{ active_pct }}%, {{ idle_color }} {{ active_pct }}%, {{ idle_color }} 100%);">
|
||||||
|
<div class="task-label">{{ block.task_path }}</div>
|
||||||
|
<div class="task-time">{{ block.start.strftime('%H:%M') }} ({{ (block.duration // 60)|int }}m)</div>
|
||||||
|
<div class="block-tooltip">
|
||||||
|
<strong>{{ block.task_path }}</strong><br>
|
||||||
|
{{ block.start.strftime('%H:%M') }} - {{ block.end.strftime('%H:%M') }}<br>
|
||||||
|
Duration: {{ (block.duration // 60)|int }} minutes<br>
|
||||||
|
Active: {{ (block.active_seconds // 60)|int }}m ({{ active_pct }}%)<br>
|
||||||
|
Idle: {{ (block.idle_seconds // 60)|int }}m
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% endblock content %}
|
||||||
26
dmold/dmweb/templates/layout.html
Normal file
26
dmold/dmweb/templates/layout.html
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
<link rel="stylesheet" href="{{ url_for('static', filename='styles/dm.css') }}">
|
||||||
|
-->
|
||||||
|
|
||||||
|
{% if auto_refresh %}
|
||||||
|
<meta http-equiv="refresh" content="5">
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% block head %}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
64
dmold/dmweb/templates/main.html
Normal file
64
dmold/dmweb/templates/main.html
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<!-- <link rel="stylesheet" href="{{ url_for('static', filename='styles/dm.css') }}"> -->
|
||||||
|
{% block head %}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
<style>
|
||||||
|
body
|
||||||
|
{
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
height: 100vh; /* This ensures that the container takes the full height of the viewport */
|
||||||
|
margin: 0; /* Remove default margin */
|
||||||
|
}
|
||||||
|
|
||||||
|
.grey {
|
||||||
|
color:grey;
|
||||||
|
}
|
||||||
|
|
||||||
|
.blue {
|
||||||
|
color:blue;
|
||||||
|
}
|
||||||
|
|
||||||
|
table {
|
||||||
|
font-size: 84pt
|
||||||
|
}
|
||||||
|
td {
|
||||||
|
padding-right: 100px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
{% if auto_refresh %}
|
||||||
|
<script>
|
||||||
|
function refreshData() {
|
||||||
|
var xhr = new XMLHttpRequest();
|
||||||
|
xhr.open('GET', '/api/today', true);
|
||||||
|
xhr.onreadystatechange = function() {
|
||||||
|
if (xhr.readyState === 4 && xhr.status === 200) {
|
||||||
|
document.getElementById('content-container').innerHTML = xhr.responseText;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
xhr.send();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Auto-refresh every 5 seconds using AJAX
|
||||||
|
setInterval(refreshData, 5000);
|
||||||
|
</script>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<!-- agregar función que me diga cuanto tiempo hace que esta activo el escritorio
|
||||||
|
(calcular el delta con el ultimo switch y pasarlo a mm:ss) -->
|
||||||
|
|
||||||
|
<div id="content-container">
|
||||||
|
{% block content %}
|
||||||
|
{% include 'main_content.html' %}
|
||||||
|
{% endblock %}
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
23
dmold/dmweb/templates/main_content.html
Normal file
23
dmold/dmweb/templates/main_content.html
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
{% if current_task_path and current_task_time %}
|
||||||
|
<div id="current-task-info" style="font-size: 48pt; margin-bottom: 40px; text-align: center;">
|
||||||
|
<div style="color: #333;">{{ current_task_path }}</div>
|
||||||
|
<div style="color: #666; font-size: 36pt;">{{ current_task_time }}</div>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
<table>
|
||||||
|
<tbody>
|
||||||
|
{% for row in rows %}
|
||||||
|
{% if row["ws"] in ['Away', 'Other'] %}
|
||||||
|
{% set my_class = 'grey' %}
|
||||||
|
{% elif row["ws"] in ['Active', 'Idle'] %}
|
||||||
|
{% set my_class = 'blue' %}
|
||||||
|
{% else %}
|
||||||
|
{% set my_class = '' %}
|
||||||
|
{% endif %}
|
||||||
|
<tr>
|
||||||
|
<td class="{{my_class}}" >{{ row["ws"] }}</td>
|
||||||
|
<td class="{{my_class}}" >{{ row["total"] }}</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
16
dmold/dmweb/templates/pages.html
Normal file
16
dmold/dmweb/templates/pages.html
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
{% extends 'layout.html' %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
|
||||||
|
<table>
|
||||||
|
{% for row in rows %}
|
||||||
|
<tr>
|
||||||
|
<td>{{ row["ws"] }}</td>
|
||||||
|
<td>{{ row["total"] }}</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</table>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
{% endblock content %}
|
||||||
185
dmold/dmweb/templates/switches_view.html
Normal file
185
dmold/dmweb/templates/switches_view.html
Normal file
@@ -0,0 +1,185 @@
|
|||||||
|
{% extends 'layout.html' %}
|
||||||
|
|
||||||
|
{% block head %}
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
margin: 20px;
|
||||||
|
font-family: monospace;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav-tabs {
|
||||||
|
display: flex;
|
||||||
|
gap: 20px;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
border-bottom: 2px solid #333;
|
||||||
|
padding-bottom: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav-tabs a {
|
||||||
|
text-decoration: none;
|
||||||
|
color: #666;
|
||||||
|
font-size: 16pt;
|
||||||
|
padding: 5px 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav-tabs a.active {
|
||||||
|
color: #000;
|
||||||
|
font-weight: bold;
|
||||||
|
border-bottom: 3px solid #000;
|
||||||
|
}
|
||||||
|
|
||||||
|
.date-nav {
|
||||||
|
margin: 20px 0;
|
||||||
|
font-size: 14pt;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.date-nav a {
|
||||||
|
text-decoration: none;
|
||||||
|
color: #2563eb;
|
||||||
|
font-size: 18pt;
|
||||||
|
}
|
||||||
|
|
||||||
|
.date-info {
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
.switches-container {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.switch-row {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
padding: 8px;
|
||||||
|
border-left: 4px solid;
|
||||||
|
font-size: 11pt;
|
||||||
|
}
|
||||||
|
|
||||||
|
.switch-time {
|
||||||
|
width: 120px;
|
||||||
|
color: #666;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
.switch-workspace {
|
||||||
|
width: 80px;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
.switch-task {
|
||||||
|
flex: 1;
|
||||||
|
color: #333;
|
||||||
|
}
|
||||||
|
|
||||||
|
.switch-duration {
|
||||||
|
width: 100px;
|
||||||
|
text-align: right;
|
||||||
|
color: #666;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Active vs idle workspace indicator */
|
||||||
|
.ws-active { font-weight: bold; }
|
||||||
|
.ws-idle { opacity: 0.6; }
|
||||||
|
|
||||||
|
.stats {
|
||||||
|
margin: 20px 0;
|
||||||
|
padding: 15px;
|
||||||
|
background: #f0f0f0;
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stats-row {
|
||||||
|
display: flex;
|
||||||
|
gap: 30px;
|
||||||
|
font-size: 11pt;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stat-item {
|
||||||
|
display: flex;
|
||||||
|
gap: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stat-label {
|
||||||
|
color: #666;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stat-value {
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
{% endblock head %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
|
||||||
|
<div class="nav-tabs">
|
||||||
|
<a href="/switches/daily/{{ base_date.year }}/{{ base_date.month }}/{{ base_date.day }}"
|
||||||
|
class="{% if scope == 'daily' %}active{% endif %}">Daily</a>
|
||||||
|
<a href="/switches/weekly/{{ base_date.year }}/{{ base_date.month }}/{{ base_date.day }}"
|
||||||
|
class="{% if scope == 'weekly' %}active{% endif %}">Weekly</a>
|
||||||
|
<a href="/switches/monthly/{{ base_date.year }}/{{ base_date.month }}/{{ base_date.day }}"
|
||||||
|
class="{% if scope == 'monthly' %}active{% endif %}">Monthly</a>
|
||||||
|
<span style="margin-left: auto;">
|
||||||
|
<a href="/calendar/{{ scope }}/{{ base_date.year }}/{{ base_date.month }}/{{ base_date.day }}">View Calendar</a>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="date-nav">
|
||||||
|
<a href="/switches/{{ scope }}/{{ prev_date.year }}/{{ prev_date.month }}/{{ prev_date.day }}">←</a>
|
||||||
|
{% if scope == 'daily' %}
|
||||||
|
<span class="date-info">{{ base_date.strftime('%Y-%m-%d %A') }}</span>
|
||||||
|
{% elif scope == 'weekly' %}
|
||||||
|
<span class="date-info">Week of {{ start.strftime('%Y-%m-%d') }}</span>
|
||||||
|
{% elif scope == 'monthly' %}
|
||||||
|
<span class="date-info">{{ base_date.strftime('%B %Y') }}</span>
|
||||||
|
{% endif %}
|
||||||
|
<a href="/switches/{{ scope }}/{{ next_date.year }}/{{ next_date.month }}/{{ next_date.day }}">→</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="stats">
|
||||||
|
<div class="stats-row">
|
||||||
|
<div class="stat-item">
|
||||||
|
<span class="stat-label">Total Switches:</span>
|
||||||
|
<span class="stat-value">{{ switches|length }}</span>
|
||||||
|
</div>
|
||||||
|
<div class="stat-item">
|
||||||
|
<span class="stat-label">Total Time:</span>
|
||||||
|
<span class="stat-value">{{ (switches|sum(attribute='delta') // 3600)|int }}h {{ ((switches|sum(attribute='delta') % 3600) // 60)|int }}m</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h3>All Switches ({{ switches|length }})</h3>
|
||||||
|
|
||||||
|
<div class="switches-container">
|
||||||
|
{% for switch in switches %}
|
||||||
|
{% set is_active = switch.workspace in ['Plan', 'Think', 'Work'] %}
|
||||||
|
{% set task_hash = switch.task_path|hash if switch.task_path else 0 %}
|
||||||
|
{% set border_hue = task_hash % 360 %}
|
||||||
|
{% set border_color = 'hsl(%d, 70%%, 50%%)'|format(border_hue) %}
|
||||||
|
{% set bg_color = 'hsl(%d, 70%%, 95%%)'|format(border_hue) %}
|
||||||
|
<div class="switch-row {{ 'ws-active' if is_active else 'ws-idle' }}"
|
||||||
|
style="border-left-color: {{ border_color }}; background-color: {{ bg_color }};">
|
||||||
|
<div class="switch-time">{{ switch.date.strftime('%m/%d %H:%M:%S') }}</div>
|
||||||
|
<div class="switch-workspace">{{ switch.workspace }}</div>
|
||||||
|
<div class="switch-task">{{ switch.task_path }}</div>
|
||||||
|
<div class="switch-duration">
|
||||||
|
{% if switch.delta >= 3600 %}
|
||||||
|
{{ (switch.delta // 3600)|int }}h {{ ((switch.delta % 3600) // 60)|int }}m
|
||||||
|
{% else %}
|
||||||
|
{{ (switch.delta // 60)|int }}m {{ (switch.delta % 60)|int }}s
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% if not switches %}
|
||||||
|
<p style="text-align: center; color: #666; margin-top: 40px;">No switches in this period</p>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% endblock content %}
|
||||||
Reference in New Issue
Block a user