예제 #1
0
    def CreateNode(self, msg, sender_id: str):
        sender_id = str(sender_id)
        tx = self.graph.begin()

        user = Node("user", sender_id=sender_id)
        print("0" * 50)
        print(user)
        new_elem = Node("chat",
                        **msg,
                        created_at=DateTime.now(asia),
                        sender_id=sender_id)
        print("L" * 50)
        print(new_elem["timestamp"])
        previous = self._get_latest(tx, sender_id)
        tx.merge(user, "user", "sender_id")
        tx.create(new_elem)
        tx.create(
            Relationship(previous or user,
                         "MSG",
                         new_elem,
                         since=new_elem["timestamp"]))
        tx.create(
            Relationship(user, "TO", new_elem, since=new_elem["timestamp"]))

        tx.commit()

        if previous is None:
            self._AddConstraint(sender_id)


# graph = Tracker4J("bolt://192.168.96.41:7687")
# graph.CreateNodeFromEvents(ex,"ddd")
예제 #2
0
 def test_zero(self):
     t = DateTime(0, 0, 0, 0, 0, 0)
     self.assertEqual(t.year, 0)
     self.assertEqual(t.month, 0)
     self.assertEqual(t.day, 0)
     self.assertEqual(t.hour, 0)
     self.assertEqual(t.minute, 0)
     self.assertEqual(t.second, 0)
예제 #3
0
 def test_non_zero_naive(self):
     t = DateTime(2018, 4, 26, 23, 0, 17.914390409)
     self.assertEqual(t.year, 2018)
     self.assertEqual(t.month, 4)
     self.assertEqual(t.day, 26)
     self.assertEqual(t.hour, 23)
     self.assertEqual(t.minute, 0)
     self.assertEqual(t.second, 17.914390409)
예제 #4
0
 def test_today(self):
     t = DateTime.today()
     self.assertEqual(t.year, 1970)
     self.assertEqual(t.month, 1)
     self.assertEqual(t.day, 1)
     self.assertEqual(t.hour, 12)
     self.assertEqual(t.minute, 34)
     self.assertEqual(t.second, 56.789)
예제 #5
0
 def _execute_rollback_command(self, *args, **kwargs):
     if self.tx:
         self.tx = self.tx.rollback()
         self.display({
             "text/plain":
             "Transaction rolled back at {}".format(DateTime.now())
         })
     else:
         return self.error("TransactionError", "No current transaction")
예제 #6
0
 def test_from_timestamp(self):
     t = DateTime.from_timestamp(0)
     self.assertEqual(t.year, 1970)
     self.assertEqual(t.month, 1)
     self.assertEqual(t.day, 1)
     self.assertEqual(t.hour, 0)
     self.assertEqual(t.minute, 0)
     self.assertEqual(t.second, 0.0)
     self.assertIsNone(t.tzinfo)
예제 #7
0
 def test_utc_now(self):
     t = DateTime.utc_now()
     self.assertEqual(t.year, 1970)
     self.assertEqual(t.month, 1)
     self.assertEqual(t.day, 1)
     self.assertEqual(t.hour, 12)
     self.assertEqual(t.minute, 34)
     self.assertEqual(t.second, 56.789)
     self.assertIsNone(t.tzinfo)
예제 #8
0
 def test_from_timestamp_with_tz(self):
     t = DateTime.from_timestamp(0, eastern)
     self.assertEqual(t.year, 1969)
     self.assertEqual(t.month, 12)
     self.assertEqual(t.day, 31)
     self.assertEqual(t.hour, 19)
     self.assertEqual(t.minute, 0)
     self.assertEqual(t.second, 0.0)
     self.assertEqual(t.utcoffset(), timedelta(seconds=-18000))
     self.assertEqual(t.dst(), timedelta())
     self.assertEqual(t.tzname(), "EST")
예제 #9
0
 def _execute_begin_command(self, *args, **kwargs):
     if self.tx is None:
         self.tx = self.graph.begin()
         self.tx_counter = 1
         self.display({
             "text/plain":
             "Began transaction at {}".format(DateTime.now())
         }),
     else:
         return self.error("TransactionError",
                           "A transaction has already begun")
예제 #10
0
 def test_now_with_tz(self):
     t = DateTime.now(eastern)
     self.assertEqual(t.year, 1970)
     self.assertEqual(t.month, 1)
     self.assertEqual(t.day, 1)
     self.assertEqual(t.hour, 7)
     self.assertEqual(t.minute, 34)
     self.assertEqual(t.second, 56.789)
     self.assertEqual(t.utcoffset(), timedelta(seconds=-18000))
     self.assertEqual(t.dst(), timedelta())
     self.assertEqual(t.tzname(), "EST")
예제 #11
0
    def CreateNode(self, msg, sender_id: str):
        sender_id = str(sender_id)
        tx = self.graph.begin()

        # Dict to kwaargs
        parent = self._get_latest(tx, sender_id)

        if(parent == None):
            tx = self._AddConstraint(tx, sender_id)

        if(tx.finished()):
            tx = graph.begin()

        new_elem = Node(sender_id, **msg, created_at=DateTime.now())

        tx.create(new_elem)
        new_elem = new_elem if (parent == None) else Relationship(
            parent, "TO", new_elem, since=new_elem['timestamp'])
        tx.create(new_elem)
        tx.commit()
예제 #12
0
def hydrate_datetime(seconds, nanoseconds, tz=None):
    """ Hydrator for `DateTime` and `LocalDateTime` values.

    :param seconds:
    :param nanoseconds:
    :param tz:
    :return: datetime
    """
    minutes, seconds = map(int, divmod(seconds, 60))
    hours, minutes = map(int, divmod(minutes, 60))
    days, hours = map(int, divmod(hours, 24))
    seconds = (1000000000 * seconds + nanoseconds) / 1000000000
    t = DateTime.combine(UNIX_EPOCH_DATE_ORDINAL + days, Time(hours, minutes, seconds))
    if tz is None:
        return t
    if isinstance(tz, int):
        tz_offset_minutes, tz_offset_seconds = divmod(tz, 60)
        zone = FixedOffset(tz_offset_minutes)
    else:
        zone = timezone(tz)
    return zone.localize(t)
예제 #13
0
 def test_year_upper_bound(self):
     with self.assertRaises(ValueError):
         _ = DateTime(MAX_YEAR + 1, 1, 1, 0, 0, 0)
예제 #14
0
 def test_normalization(self):
     ndt1 = eastern.normalize(
         DateTime(2018, 4, 27, 23, 0, 17, tzinfo=eastern))
     ndt2 = eastern.normalize(
         datetime(2018, 4, 27, 23, 0, 17, tzinfo=eastern))
     self.assertEqual(ndt1, ndt2)
예제 #15
0
 def test_day_29_of_28_day_month(self):
     with self.assertRaises(ValueError):
         _ = DateTime(1999, 2, 29, 0, 0, 0)
예제 #16
0
def test_date_time(graph):
    skip_if_no_temporal_support(graph)
    i = DateTime(2014, 8, 6, 12, 34, 56.789)
    o = graph.evaluate("RETURN $x", x=i)
    assert o == i
예제 #17
0
def main():
    from neotime import Clock, DateTime, UnixEpoch
    clock = Clock()
    time = clock.utc_time()
    print("Using %s" % type(clock).__name__)
    print("%s -> %s" % (time, DateTime.from_clock_time(time, UnixEpoch)))
예제 #18
0
def test_datetime_with_named_timezone(cls):
    from neotime import DateTime
    b, unpacked = pack_and_unpack(cls(1970, 1, 1, 0, 0, 0, tzinfo=utc), version=(2, 0))
    assert b == b"\xB3f\x00\x00\x83UTC"
    assert unpacked == DateTime(1970, 1, 1, 0, 0, 0, tzinfo=utc)
예제 #19
0
 def test_localization(self):
     ldt1 = eastern.localize(datetime(2018, 4, 27, 23, 0, 17))
     ldt2 = eastern.localize(DateTime(2018, 4, 27, 23, 0, 17))
     self.assertEqual(ldt1, ldt2)
예제 #20
0
 def test_year_lower_bound(self):
     with self.assertRaises(ValueError):
         _ = DateTime(MIN_YEAR - 1, 1, 1, 0, 0, 0)
예제 #21
0
def test_naive_datetime(cls):
    from neotime import DateTime
    b, unpacked = pack_and_unpack(cls(1970, 1, 1, 0, 0, 0), version=(2, 0))
    assert b == b"\xB2d\x00\x00"
    assert unpacked == DateTime(1970, 1, 1, 0, 0, 0)
예제 #22
0
 def test_month_upper_bound(self):
     with self.assertRaises(ValueError):
         _ = DateTime(2000, 13, 1, 0, 0, 0)
예제 #23
0
def test_datetime_with_timezone_offset(cls):
    from neotime import DateTime
    b, unpacked = pack_and_unpack(cls(1970, 1, 1, 0, 0, 0, tzinfo=FixedOffset(1)),
                                  version=(2, 0))
    assert b == b"\xB3F\x00\x00\x3C"
    assert unpacked == DateTime(1970, 1, 1, 0, 0, 0, tzinfo=FixedOffset(1))
예제 #24
0
 def test_day_zero(self):
     with self.assertRaises(ValueError):
         _ = DateTime(2000, 1, 0, 0, 0, 0)
예제 #25
0
 def test_datetime_property(self):
     a = Node(dt=DateTime(1970, 1, 1, 12, 34, 56))
     r = cypher_repr(a)
     self.assertEqual("({dt: datetime('1970-01-01T12:34:56.000000000')})", r)
예제 #26
0
 def test_day_30_of_29_day_month(self):
     with self.assertRaises(ValueError):
         _ = DateTime(2000, 2, 30, 0, 0, 0)
예제 #27
0
from __future__ import division
"""
This module defines temporal data types.
"""

from datetime import time, datetime, timedelta

from neotime import Duration, Date, Time, DateTime
from pytz import FixedOffset, timezone, utc

from neobolt.types import Structure

UNIX_EPOCH_DATE = Date(1970, 1, 1)
UNIX_EPOCH_DATE_ORDINAL = UNIX_EPOCH_DATE.to_ordinal()
UNIX_EPOCH_DATETIME_UTC = DateTime(1970, 1, 1, 0, 0, 0, utc)


def hydrate_date(days):
    """ Hydrator for `Date` values.

    :param days:
    :return: Date
    """
    return Date.from_ordinal(UNIX_EPOCH_DATE_ORDINAL + days)


def dehydrate_date(value):
    """ Dehydrator for `date` values.

    :param value:
예제 #28
0
 def test_day_32_of_31_day_month(self):
     with self.assertRaises(ValueError):
         _ = DateTime(2000, 3, 32, 0, 0, 0)
예제 #29
0
 def seconds_and_nanoseconds(dt):
     if isinstance(dt, datetime):
         dt = DateTime.from_native(dt)
     zone_epoch = DateTime(1970, 1, 1, tzinfo=dt.tzinfo)
     t = dt.to_clock_time() - zone_epoch.to_clock_time()
     return t.seconds, t.nanoseconds
예제 #30
0
 def test_day_31_of_30_day_month(self):
     with self.assertRaises(ValueError):
         _ = DateTime(2000, 4, 31, 0, 0, 0)