#!/usr/bin/env python3
#
# Determine the duration of the owping

import datetime
import sys

import pscheduler

from owping_defaults import *

json = pscheduler.json_load(exit_on_error=True)['spec']

interval = json.get('packet-interval', DEFAULT_PACKET_INTERVAL)
count = json.get('packet-count', DEFAULT_PACKET_COUNT)
packet_timeout = json.get('packet-timeout', DEFAULT_PACKET_TIMEOUT)

# The duration time account for:
# (interval * count * 1.1)  owping packet sending and processing time
# (count / 50000)          owping.run() parsing of the raw output, might need to be adjusted for low-end machines
pscheduler.succeed_json({
        "duration": 'PT%dS' % ((interval * count * 1.1) + (count / 50000) + packet_timeout + DEFAULT_FUDGE_FACTOR + DEFAULT_CLIENT_SLEEP)
})
