# Path: paegan/cdm/dsg/member.py
# class Member(dict):
#     def __init__(self, *args, **kwargs):
#         super(Member, self).__init__(*args, **kwargs)
# 
# Path: paegan/cdm/dsg/features/base/trajectory.py
# class Trajectory(PointCollection):
#     """
#         A collection of Points along a 1 dimensional path, connected in space and time.
#         The Points are ordered in time (in other words, the time dimension must
#         increase monotonically along the trajectory).
#     """
# 
#     def __init__(self, **kwargs):
#         super(Trajectory,self).__init__(**kwargs)
#         self._type = "Trajectory"
# 
#     def get_path(self):
#         """
#             Returns the Points along the trajectory
#         """
#         return map(lambda x: [x.location, x.time], self._elements)
# 
# Path: paegan/cdm/dsg/collections/base/trajectory_collection.py
# class TrajectoryCollection(NestedPointCollection):
#     """
#         A collection of Trajectories
#     """
# 
#     def __init__(self, **kwargs):
#         super(TrajectoryCollection,self).__init__(**kwargs)
# 
# Path: paegan/utils/asalist.py
# class AsaList(object):
# 
#     @classmethod
#     def flatten(cls, lst):
#         """
#             Returns Generator of non-iterable values
#         """
#         for x in lst:
#             if not isinstance(x, collections.Iterable):
#                 yield x
#             else:
#                 for x in AsaList.flatten(x):
#                     yield x


import random
import unittest
from datetime import datetime, timedelta
from shapely.geometry import Point as sPoint
from paegan.cdm.dsg.member import Member
from paegan.cdm.dsg.features.base.point import Point
from paegan.cdm.dsg.features.base.trajectory import Trajectory
from paegan.cdm.dsg.collections.base.trajectory_collection import TrajectoryCollection
from paegan.utils.asalist import AsaList
    def test_trajectory_collection(self):

        t_collection = TrajectoryCollection()

        # 20 trajectories
        for x in xrange(0,20):

            tr = Trajectory()

            month = random.randint(1,12)
            dt = datetime(2012, month, 1, 0)

            # Starting point
            lat = random.randint(40,44)
            lon = random.randint(-74,-70)
            depth = 0

            # 100 points in each trajectory
            for l in xrange(0,100):

                lat += random.uniform(-0.25,0.25)
                lon += random.uniform(-0.25,0.25)
                depth += random.randint(-4,4)
                if depth < 0:
                    depth = 0

                p1 = Point()
                p1.location = sPoint(lon,lat,depth)
                dt += timedelta(hours=1)
                p1.time = dt

# Path: paegan/cdm/dsg/member.py
# class Member(dict):
#     def __init__(self, *args, **kwargs):
#         super(Member, self).__init__(*args, **kwargs)
# 
# Path: paegan/cdm/dsg/features/base/trajectory.py
# class Trajectory(PointCollection):
#     """
#         A collection of Points along a 1 dimensional path, connected in space and time.
#         The Points are ordered in time (in other words, the time dimension must
#         increase monotonically along the trajectory).
#     """
# 
#     def __init__(self, **kwargs):
#         super(Trajectory,self).__init__(**kwargs)
#         self._type = "Trajectory"
# 
#     def get_path(self):
#         """
#             Returns the Points along the trajectory
#         """
#         return map(lambda x: [x.location, x.time], self._elements)
# 
# Path: paegan/cdm/dsg/collections/base/trajectory_collection.py
# class TrajectoryCollection(NestedPointCollection):
#     """
#         A collection of Trajectories
#     """
# 
#     def __init__(self, **kwargs):
#         super(TrajectoryCollection,self).__init__(**kwargs)
# 
# Path: paegan/utils/asalist.py
# class AsaList(object):
# 
#     @classmethod
#     def flatten(cls, lst):
#         """
#             Returns Generator of non-iterable values
#         """
#         for x in lst:
#             if not isinstance(x, collections.Iterable):
#                 yield x
#             else:
#                 for x in AsaList.flatten(x):
#                     yield x


# Path: tests/cdm/dsg/collections/base/test_trajectory_collection.py
import random
import unittest
from datetime import datetime, timedelta
from shapely.geometry import Point as sPoint
from paegan.cdm.dsg.member import Member
from paegan.cdm.dsg.features.base.point import Point
from paegan.cdm.dsg.features.base.trajectory import Trajectory
from paegan.cdm.dsg.collections.base.trajectory_collection import TrajectoryCollection
from paegan.utils.asalist import AsaList

    def test_trajectory_collection(self):

        t_collection = TrajectoryCollection()

        # 20 trajectories
        for x in xrange(0,20):

            tr = Trajectory()

            month = random.randint(1,12)
            dt = datetime(2012, month, 1, 0)

            # Starting point
            lat = random.randint(40,44)
            lon = random.randint(-74,-70)
            depth = 0

            # 100 points in each trajectory
            for l in xrange(0,100):

                lat += random.uniform(-0.25,0.25)
                lon += random.uniform(-0.25,0.25)
                depth += random.randint(-4,4)
                if depth < 0:
                    depth = 0

                p1 = Point()
                p1.location = sPoint(lon,lat,depth)
                dt += timedelta(hours=1)
                p1.time = dt

                member1 = Member(value=random.uniform(30,40), unit='°C', name='Water Temperature', description='water temperature', standard='sea_water_temperature')