Пример #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)