# Path: dapbench/jython/util.py
# def generate_subset_requests(variable, partition_dict):
#     """
#     Yields callables which when called makes a subset request
#     to <variable> according to the partitions specified.
# 
#     Made threadsafe with a lock.
# 
#     """
# 
#     def gen():
#         for subset in partition_variable(variable, partition_dict):
#             yield DapVarSubset(variable, subset)
#     
#     return LockedIterator(gen())
# 
# Path: dapbench/jython/netcdf.py
# class Dataset(object):
#     def __init__(self, location):
#         self._ds = NetcdfDataset.openDataset(location)
#         self.variables = VariableDict(self._ds)
#         self.attributes = AttributeDict(self._ds)


import random
import data_urls
from net.grinder.script import Test
from net.grinder.script.Grinder import grinder
from dapbench.jython.util import generate_subset_requests
from dapbench.jython.netcdf import Dataset
"""
Request slices in parallel.

"""





properties = grinder.properties.getPropertySubset('dapbench.')

variable = properties['variable']
datasets = properties['datasets']
time_len = int(properties['time_len'])
req_sample_size = int(properties['req_sample_size'])

partition_dict = {'time': time_len}
dataset_list = data_urls.load_dataset_list(datasets)

test = Test(1, "Parallel slice request")
def call_request(req):
    return req()
test.record(call_request)

class TestRunner(object):
    def __init__(self):
        self.thread = grinder.getThreadNumber()
        # Select random dataset
        #!TODO: select dataset by Thread number?
        self.dataset_url = random.choice(dataset_list)

# Path: dapbench/jython/util.py
# def generate_subset_requests(variable, partition_dict):
#     """
#     Yields callables which when called makes a subset request
#     to <variable> according to the partitions specified.
# 
#     Made threadsafe with a lock.
# 
#     """
# 
#     def gen():
#         for subset in partition_variable(variable, partition_dict):
#             yield DapVarSubset(variable, subset)
#     
#     return LockedIterator(gen())
# 
# Path: dapbench/jython/netcdf.py
# class Dataset(object):
#     def __init__(self, location):
#         self._ds = NetcdfDataset.openDataset(location)
#         self.variables = VariableDict(self._ds)
#         self.attributes = AttributeDict(self._ds)


# Path: grinder/parallel_slices.py
import random
import data_urls
from net.grinder.script import Test
from net.grinder.script.Grinder import grinder
from dapbench.jython.util import generate_subset_requests
from dapbench.jython.netcdf import Dataset

"""
Request slices in parallel.

"""





properties = grinder.properties.getPropertySubset('dapbench.')

variable = properties['variable']
datasets = properties['datasets']
time_len = int(properties['time_len'])
req_sample_size = int(properties['req_sample_size'])

partition_dict = {'time': time_len}
dataset_list = data_urls.load_dataset_list(datasets)

test = Test(1, "Parallel slice request")
def call_request(req):
    return req()
test.record(call_request)

class TestRunner(object):
    def __init__(self):
        self.thread = grinder.getThreadNumber()
        # Select random dataset
        #!TODO: select dataset by Thread number?
        self.dataset_url = random.choice(dataset_list)

        self.ds = Dataset(self.dataset_url)