Library for processing attendance plan data into time-segmented DataFrames
Project description
Shift Counter
A Python library for processing attendance plan data into time-segmented DataFrames. This library takes JSON attendance data and converts it into a structured pandas DataFrame with 30-minute time segments, making it easy to analyze working hours by different shift types.
Installation
pip install shift-counter
Features
- Processes attendance data into 30-minute segments
- Classifies shifts into different types (Normal, VD, Red, Vacation)
- Handles timezone-aware timestamps
- Aggregates overlapping shifts
- Compatible with Tria HR API output format
Usage
Basic Usage
from shift_counter import ShiftCounter, ShiftType
# Initialize counter
counter = ShiftCounter()
# Add individual shifts
counter.add_shift(
from_time="2025-01-08T08:00:00+01:00",
to_time="2025-01-08T16:00:00+01:00",
unit_id=120,
shift_type=ShiftType.NORMAL
)
# Get resulting DataFrame
df = counter.get_dataframe()
Processing Attendance Plan
# Process complete attendance plan (e.g., from Tria HR API)
attendance_plan = {
"data": [{
"shifts": [{
"date_time_from": "2025-01-08T08:00:00+01:00",
"date_time_to": "2025-01-08T16:00:00+01:00",
"name": "VD"
}],
"absences": [{
"date_time_from": "2025-01-09T08:00:00+01:00",
"date_time_to": "2025-01-09T16:00:00+01:00"
}]
}]
}
counter = ShiftCounter()
counter.count_attendance_plan(attendance_plan)
Output Format
The resulting DataFrame contains the following columns:
department_id: Integer identifier for the organizational unitdetail_level: Granularity of the data (always 'hour')time_segment: Start time of the 30-minute segmentextraction_date: When the data was processedhours_normal: Regular shift hourshours_vd: Variable day shift hourshours_red: Red shift hourshours_vacation: Vacation/leave hours
Each row represents a 30-minute segment, with hours columns showing 0.5 for each shift type present in that segment.
Integration with Tria HR API
While this library can be used independently, it's designed to work seamlessly with data from the Tria HR API:
from triahr import TriaHRAPI
from shift_counter import ShiftCounter
# Get attendance data
api = TriaHRAPI.from_config()
attendance = api.attendance_plan(
date_from="2025-01-01",
date_to="2025-01-31",
unit_id=120
)
# Process into DataFrame
counter = ShiftCounter()
counter.count_attendance_plan(attendance)
df = counter.get_dataframe()
Error Handling
The library automatically handles:
- Timezone conversions
- Overlapping shifts
- Missing or invalid shift types
- Data type consistency
Requirements
- Python ≥ 3.7
- pandas ≥ 1.0.0
License
MIT License
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file shift_counter-1.0.2.tar.gz.
File metadata
- Download URL: shift_counter-1.0.2.tar.gz
- Upload date:
- Size: 5.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e9ba51572cc8a2dfdd5437ee9e6225e213eb87391abac4d1b912503cbe951ab6
|
|
| MD5 |
9fcd51bb1473e248c6f275d8f7c234a7
|
|
| BLAKE2b-256 |
9b1b559081192a0d96e1eebbde5a87924ab348ee847e4b5c47ec1be934f8ad35
|
File details
Details for the file shift_counter-1.0.2-py3-none-any.whl.
File metadata
- Download URL: shift_counter-1.0.2-py3-none-any.whl
- Upload date:
- Size: 5.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
880cb39a47a7c49de9a6c969f703732146cabf63adae2c53a8bc9675c83d6d09
|
|
| MD5 |
80612963f4cabf7a453da0bd803d757c
|
|
| BLAKE2b-256 |
b99c056964669a3cb9d4413b5573b5d62db5636a1a01e2aff60a474a140b585f
|