38 lines
1.2 KiB
Python
38 lines
1.2 KiB
Python
import json
|
|
from datetime import datetime
|
|
import collections
|
|
|
|
data = json.load(open('/Users/dvapp/Documents/HRM/scratch/legacy_roster.json'))
|
|
|
|
# employee_code -> day_of_week (0=Mon...6=Sun) -> shift_name
|
|
patterns = collections.defaultdict(dict)
|
|
|
|
for entry in data:
|
|
if not entry['date'].startswith('2026-01'): continue
|
|
|
|
dt = datetime.strptime(entry['date'], '%Y-%m-%d')
|
|
dow = dt.weekday() # 0 is Monday
|
|
|
|
code = entry['code']
|
|
shift = entry['shift_name']
|
|
is_rd = entry['is_rest_day']
|
|
|
|
# Store the most frequent shift for this day of week for this employee
|
|
if code not in patterns: patterns[code] = {}
|
|
if dow not in patterns[code]: patterns[code][dow] = []
|
|
|
|
patterns[code][dow].append({'shift': shift, 'is_rd': is_rd})
|
|
|
|
# Distill patterns (take the most common assignment for each DOW)
|
|
final_patterns = {}
|
|
for code, dows in patterns.items():
|
|
final_patterns[code] = {}
|
|
for dow, assignments in dows.items():
|
|
# Just take the first one for now, usually it's consistent
|
|
final_patterns[code][dow] = assignments[0]
|
|
|
|
with open('/Users/dvapp/Documents/HRM/scratch/employee_patterns.json', 'w') as f:
|
|
json.dump(final_patterns, f, indent=2)
|
|
|
|
print(f"Generated patterns for {len(final_patterns)} employees")
|