# Path: voeventdb/server/tests/fixtures/testpacket_id.py
# class id_keys:
#     """Define the dictionary keys as variables
# 
#     This gives us two advantages:
#      * we get autocompletion in ipython, etc.
#      * mistyped key names are caught early (syntax errors) rather than at runtime
#        (key-not-in-dict errors)
#     """
#     address='address'
#     stream='stream'
#     shortName='shortName'
#     contactName='contactName'
#     contactEmail='contactEmail'


from datetime import date, datetime, timedelta
from voeventdb.server.tests.fixtures.testpacket_id import id_keys
import uuid
import voeventparse as vp
from __future__ import absolute_import


def generate_stream_id():
    """
    Get a string for use as a stream ID.

    The idea is to create a stream ID that is largely human-readable
    (hence the timestamp), but will not repeat if multiple packets are generated
    within a small timespan (within reason).
    To do this, we assume that only a single machine
    is generating alerts in a given stream. This means we can generate
    a uuid1() string and throw away everything except the first 32 bits,
    which represent the low-end bytes of the timestamp.

    """
    datetime_format_short = '%y%m%d-%H%M.%S'
    timestamp = datetime.utcnow().strftime(datetime_format_short)
    stream_id = timestamp + '_' + uuid.uuid1().hex[:8]
    return stream_id


def create_skeleton_voevent(id, stream, role, author_date):
    v = vp.Voevent(stream=id[id_keys.address] + '/' + stream,
                   stream_id=generate_stream_id(), role=role)
    vp.set_who(v, date=author_date,
               author_ivorn=id[id_keys.address])
    vp.set_author(v,
                  shortName=id[id_keys.shortName],

# Path: voeventdb/server/tests/fixtures/testpacket_id.py
# class id_keys:
#     """Define the dictionary keys as variables
# 
#     This gives us two advantages:
#      * we get autocompletion in ipython, etc.
#      * mistyped key names are caught early (syntax errors) rather than at runtime
#        (key-not-in-dict errors)
#     """
#     address='address'
#     stream='stream'
#     shortName='shortName'
#     contactName='contactName'
#     contactEmail='contactEmail'


# Path: voeventdb/server/tests/fixtures/packetgen.py
from datetime import date, datetime, timedelta
from voeventdb.server.tests.fixtures.testpacket_id import id_keys
import uuid
import voeventparse as vp

from __future__ import absolute_import


def generate_stream_id():
    """
    Get a string for use as a stream ID.

    The idea is to create a stream ID that is largely human-readable
    (hence the timestamp), but will not repeat if multiple packets are generated
    within a small timespan (within reason).
    To do this, we assume that only a single machine
    is generating alerts in a given stream. This means we can generate
    a uuid1() string and throw away everything except the first 32 bits,
    which represent the low-end bytes of the timestamp.

    """
    datetime_format_short = '%y%m%d-%H%M.%S'
    timestamp = datetime.utcnow().strftime(datetime_format_short)
    stream_id = timestamp + '_' + uuid.uuid1().hex[:8]
    return stream_id


def create_skeleton_voevent(id, stream, role, author_date):
    v = vp.Voevent(stream=id[id_keys.address] + '/' + stream,
                   stream_id=generate_stream_id(), role=role)
    vp.set_who(v, date=author_date,
               author_ivorn=id[id_keys.address])
    vp.set_author(v,
                  shortName=id[id_keys.shortName],

                  contactName=id[id_keys.contactName],