def availability(provider_name, vehicle_type, args):
    """
    Runs the availability calculation
    """
    oneday = timedelta(days=1)

    log(args, f"""Starting availability calculation:
    - time range: {args.start} to {args.end}
    - provider: {provider_name}
    - vehicle type: {vehicle_type}""")

    devices = DeviceCounter(args.start, args.end, local=args.local, debug=args.debug)

    q = query.Availability(args.start, args.end,
        vehicle_types=vehicle_type,
        table="csm_availability_windows",
        local=args.local, debug=True)

    results = {}

    log(args, f"Starting calculation for {provider_name}")

    data = q.get(provider_name=provider_name)
    partition = devices.count(data).partition()

    log(args, partition.describe())

    overall_avg = devices.average()
    log(args, f"Overall average: {overall_avg}")

    counts = {}
    start = args.start

    while start < args.end:
        end = start + oneday
        log(args, f"Counting {start.strftime('%Y-%m-%d')} to {end.strftime('%Y-%m-%d')}")

        _q = query.Availability(start, end,
            vehicle_types=vehicle_type,
            table="csm_availability_windows",
            local=args.local, debug=args.debug)

        _data = _q.get(provider_name=provider_name)

        log(args, f"{len(_data)} availability records in time period")

        _devices = DeviceCounter(start, end, local=args.local, debug=args.debug)
        counts[start] = _devices.count(_data)

        start = end

    if args.debug:
        for date, count in counts.items():
            print(f"{provider_name},{vehicle_type},{date.strftime('%Y-%m-%d')},{count.average()},{overall_avg}")

    return overall_avg, counts
示例#2
0
def availability(provider_name, vehicle_type, start, end, **kwargs):
    """
    Runs the availability calculation
    """
    debug = kwargs.get("debug")
    step = timedelta(days=1)

    log(debug, f"Starting calculation for {provider_name}")

    while start < end:
        _end = start + step
        log(
            debug,
            f"Counting {start.strftime('%Y-%m-%d')} to {_end.strftime('%Y-%m-%d')}"
        )

        q = query.Availability(start,
                               _end,
                               table="csm_availability_windows",
                               vehicle_types=vehicle_type,
                               **kwargs)

        data = q.get(provider_name=provider_name)

        log(debug, f"{len(data)} availability records in time period")

        devices = DeviceCounter(start, _end, **kwargs)

        yield (start, _end, devices.count(data))

        start = _end
示例#3
0
def availability(provider_name, vehicle_type, start, end, **kwargs):
    """
    Runs the availability calculation
    """
    source = kwargs.get("availability")
    debug = kwargs.get("debug")
    step = datetime.timedelta(days=1)

    log(debug, f"Starting calculation for {provider_name}")
    log(debug, f"Reading windows from {source}")

    while start < end:
        _end = start + step
        log(
            debug,
            f"Counting {start.strftime('%Y-%m-%d')} to {_end.strftime('%Y-%m-%d')}"
        )

        q = query.Availability(start,
                               _end,
                               source=source,
                               provider_name=provider_name,
                               vehicle_types=vehicle_type,
                               **kwargs)

        data = q.get()

        log(debug, f"{len(data)} availability records in time period")

        devices = measure.DeviceCounter(start, _end, **kwargs)

        yield (start, _end, devices.count(data))

        start = _end