Funscript Check Tools (show infomation/stats and overspeed)

Resource

Click me – check_stats.py

Copy the text and save it as check_stats.py.

import json
import sys

def stats(file):
    with open(file, encoding='utf-8') as f:
        data = json.load(f)
    acts = data['actions']
    n = len(acts)
    durations = [acts[i+1]['at'] - acts[i]['at'] for i in range(n-1)]
    speeds = []
    for i, d in enumerate(durations):
        if d > 0:
            diff = abs(acts[i+1]['pos'] - acts[i]['pos'])
            speeds.append(diff / (d / 1000.0))
    max_speed = max(speeds) if speeds else 0
    avg_speed = sum(speeds) / len(speeds) if speeds else 0
    duration = data['metadata']['duration']  # 单位:秒
    return n, max_speed, avg_speed, duration

if __name__ == '__main__':
    if len(sys.argv) != 2:
        print("用法: python check_stats.py <json文件>")
        sys.exit(1)
    n, max_s, avg_s, dur = stats(sys.argv[1])
    print(f"动作数: {n}")
    print(f"最大速度: {max_s:.2f}")
    print(f"平均速度: {avg_s:.2f}")
    # 格式化显示持续时间(转为分:秒)
    mins = int(dur // 60)
    secs = int(dur % 60)
    print(f"持续时间: {mins}分{secs}秒")
Click me – check_overspeed.py

Copy the text and save it as check_overspeed.py.

import json
import sys

def find_overspeed(file):
    with open(file, encoding='utf-8') as f:
        data = json.load(f)
    acts = data['actions']
    for i in range(len(acts)-1):
        dt = acts[i+1]['at'] - acts[i]['at']
        if dt == 0:
            continue
        dp = abs(acts[i+1]['pos'] - acts[i]['pos'])
        speed = dp / (dt / 1000.0)
        if speed > 600:
            print(f"索引 {i}->{i+1}: 速度 {speed:.2f}, 位置差 {dp}, 时间差 {dt}ms")

if __name__ == '__main__':
    if len(sys.argv) != 2:
        print("用法: python check_overspeed.py <json文件>")
        sys.exit(1)
    find_overspeed(sys.argv[1])

Introduce

Funscript Check Tools are two tiny Python scripts that quickly inspect a single‑track .funscript (or JSON) file.

  • check_stats.py prints total actions, maximum / average speed, and duration.
  • check_overspeed.py lists every adjacent pair where the speed exceeds 600 units/second.

They are designed for simple quality checks before or after processing other tools. They do not work with multi‑axis (merged) files – only one actions array is allowed.

Usage

(Python 3.6+ required.)

# Basic statistics
python check_stats.py <file.funscript>

# Find overspeed points
python check_overspeed.py <file.funscript>
Key Features and How It Works

Key Features

  • Instant statisticscheck_stats.py counts actions, computes peak and mean speed, and reads the duration from metadata (if present).
  • Overspeed scannercheck_overspeed.py walks through every consecutive pair, calculates instantaneous speed, and outputs any pair that exceeds 600 units/s.
  • Single‑track only – both scripts assume the JSON contains a plain "actions" array at the top level. If you feed them a merged file with "axes", they will fail or give wrong results.

How It Works

  1. Load the JSON file and access the "actions" list.
  2. Iterate over indices:
    • check_stats.py computes Δpos/Δtime for each step, then aggregates min/max/average.
    • check_overspeed.py checks every step and prints diagnostic info when speed > 600.
  3. Output results directly to the console.

Example output

check_stats.py

动作数: 2847
最大速度: 598.21
平均速度: 187.45
持续时间: 10分42秒

check_overspeed.py

索引 155->156: 速度 845.67, 位置差 20, 时间差 23ms
索引 427->428: 速度 701.34, 位置差 12, 时间差 17ms
...

If no lines are printed by check_overspeed.py, the file is fully within the safe limit.


Important – These tools only examine the main "actions" array. For merged multi‑axis files, extract the individual tracks first.

1 Like