# How do I find out the total time spent on a Google Doc?

I'd like to find out the total time spent on a Google Doc.

This is a similar question, How can I track the time spent and the number of words written in Google Docs?, but without any answers.

There is also one on the Google community support site without any solutions: Is there a tool to use a doc's version history to calculate the total time spent on the doc?

First, expand your edit history and copy and paste all of it into a text file. Then, you can run this Python script to calculate the total time you spent on it. I have tested this and it works perfectly for me.

``````import pandas as pd
from datetime import datetime, timedelta

# Replace this path with the path to your file
file_path = 'path_to_your_file.txt'

# Read the file
with open(file_path, 'r', encoding='utf-8-sig') as file:

# Parse the timestamps, assuming they are in the format "Month Day, Hour:Minute AM/PM"
timestamps = [datetime.strptime(line.strip(), '%B %d, %I:%M %p') for line in lines if line.strip()]

# Add the current year to each timestamp and sort them
current_year = datetime.now().year
timestamps_with_year = [timestamp.replace(year=current_year) for timestamp in timestamps]
timestamps_with_year.sort()

# Function to calculate total active time
def calculate_total_active_time(timestamps, gap_limit):
total_active_time = timedelta()
for i in range(len(timestamps) - 1):
gap = timestamps[i + 1] - timestamps[i]
if gap <= timedelta(minutes=gap_limit):
total_active_time += gap

# Example: Calculating total active time with a 30-minute gap threshold
total_active_time_30min = calculate_total_active_time(timestamps_with_year, 30)
print("Total active time with 30-minute gap threshold:", total_active_time_30min.total_seconds() / 3600, "hours")
``````

This assumes that if you stop editing for more than 30 minutes, you are no longer actively working on the document. You can change this as you wish. You can also view the results of all thresholds in one plot, like this:

``````import matplotlib.pyplot as plt

# Function to calculate total active time for different gap thresholds
def calculate_active_time_for_thresholds(timestamps, max_threshold):
gap_thresholds = range(1, max_threshold + 1)
total_times = []
for gap_threshold in gap_thresholds:
total_active_time = calculate_total_active_time(timestamps, gap_threshold)
total_times.append(total_active_time.total_seconds() / 3600)
return gap_thresholds, total_times

# Calculating and plotting
gap_thresholds, total_times = calculate_active_time_for_thresholds(timestamps_with_year, 60)

plt.figure(figsize=(12, 6))
plt.plot(gap_thresholds, total_times, marker='o')
plt.title('Total Active Time at Different Gap Thresholds')
plt.xlabel('Gap Threshold (minutes)')
plt.ylabel('Total Active Time (hours)')
plt.grid(True)
plt.show()
``````