python-datetime-metrics
Parse datetime strings and compute time durations/averages for datasets (like PR merge times) in Python.
- License 许可
- MIT
- 最近更新
- 2026-10-02
- Stars
- ★ 92
- Forks
- 7
01 前言 Front Matter
- name
- python-datetime-metrics
- description
- Parse datetime strings and compute time durations/averages for datasets (like PR merge times) in Python.
03 SKILL.md 正文
Python Datetime Metrics
When working with GitHub APIs or any JSON data, you often need to parse ISO-8601 formatted datetime strings and compute derived metrics, such as "average time to merge" or "issue resolution duration".
Installation / Setup
Built-in datetime module is all you need.
Key Concepts
datetime.strptime()ordatetime.fromisoformat()can convert strings to datetime objects.- Subtracting two
datetimeobjects yields atimedeltaobject. - A
timedeltaobject can be converted to numeric seconds or days using.total_seconds()or.days.
Code Example
from datetime import datetime
def calculate_avg_merge_days(prs):
merge_times = []
for pr in prs:
# Check if the PR was actually merged
if pr.get('pull_request', {}).get('merged_at'):
created_at_str = pr['created_at']
merged_at_str = pr['pull_request']['merged_at']
# Use replace('Z', '+00:00') to handle standard ISO-8601 strings from APIs
created_at = datetime.fromisoformat(created_at_str.replace('Z', '+00:00'))
merged_at = datetime.fromisoformat(merged_at_str.replace('Z', '+00:00'))
# Calculate difference in days (as a float)
diff_days = (merged_at - created_at).total_seconds() / (24 * 3600)
merge_times.append(diff_days)
if not merge_times:
return 0.0
avg_days = sum(merge_times) / len(merge_times)
# Round to 1 decimal place
return round(avg_days, 1)
# Example output:
# avg_days = calculate_avg_merge_days(pr_list)
# print(f"Average merge time: {avg_days} days")
Best Practices
- Consider timezone-aware parsing.
replace('Z', '+00:00')works well for basic UTC strings from GitHub. - Guard against divide-by-zero errors. Always check
if not data_pointsbefore averaging. - Remember
merged_atvsclosed_at: closed does not mean merged. Ensure you pick the right metric!
04 同仓库更多 Skills
object_counter
Count occurrences of an object in the image using computer vision algorithm.
travel-planning-workflow
Invoke this skill when performing travel planning. It defines a structured workflow for generating itineraries. Following this workflow is essential to ensure the final plan satisfies user requirements.
bundled-dataset-search-tool
invoke this skill when you need to perform database search for travel planning. This skill provides some useful pre-packaged tools to look up accommodations, attractions, cities, driving distance, flights, and restaurants from the bundled dataset.
glm-output
Output-processing guidance for GLM tasks. Especially useful after glm-basics and glm-calibration when you need verifier-matching metrics from output.nc and a final /root/metrics.json.
glm-calibration
Calibration guidance for GLM tasks. Often most effective after glm-basics has clarified the setup; glm-output is the companion skill for exact final metric computation.
glm-basics
A good starting point for GLM calibration tasks. Use to inspect glm3.nml, confirm how GLM runs, and identify the relevant files before moving on to calibration and output evaluation.