c889a57b6b
Test Suites / Build CI Environment (push) Has been cancelled
Test Suites / Basic Tests (push) Has been cancelled
Test Suites / End-to-End Tests (push) Has been cancelled
Test Suites / CLI Tests (push) Has been cancelled
Test Suites / Slow End-to-End Tests (push) Has been cancelled
Test Suites / Graph Database Tests (push) Has been cancelled
Test Suites / Vector DB Tests (push) Has been cancelled
Test Suites / Temporal Graph Test (push) Has been cancelled
Test Suites / Search Test on Different DBs (push) Has been cancelled
Test Suites / Example Tests (push) Has been cancelled
Test Suites / Notebook Tests (push) Has been cancelled
Test Suites / OS and Python Tests Ubuntu (push) Has been cancelled
Test Suites / OS and Python Tests Extended (push) Has been cancelled
Test Suites / LLM Test Suite (push) Has been cancelled
Test Suites / S3 File Storage Test (push) Has been cancelled
Test Suites / Run Integration Tests (push) Has been cancelled
Test Suites / MCP Tests (push) Has been cancelled
Test Suites / Docker Compose Test (push) Has been cancelled
Test Suites / Docker CI test (push) Has been cancelled
Test Suites / Relational DB Migration Tests (push) Has been cancelled
Test Suites / Distributed Cognee Test (push) Has been cancelled
Test Suites / DB Examples Tests (push) Has been cancelled
Test Suites / Test Completion Status (push) Has been cancelled
Test Suites / Claude Code Review (push) Has been cancelled
Test Suites / basic checks (push) Has been cancelled
build | Build and Push Cognee MCP Docker Image to dockerhub / docker-build-and-push (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
build | Build and Push Docker Image to dockerhub / docker-build-and-push (push) Has been cancelled
Weighted Edges Tests / Test Weighted Edges Core Functionality (3.11) (push) Has been cancelled
Weighted Edges Tests / Test Weighted Edges Core Functionality (3.12) (push) Has been cancelled
Weighted Edges Tests / Test Weighted Edges with Different Graph Databases (kuzu, kuzu) (push) Has been cancelled
Weighted Edges Tests / Test Weighted Edges with Different Graph Databases (neo4j, neo4j) (push) Has been cancelled
Weighted Edges Tests / Test Weighted Edges Examples (push) Has been cancelled
Weighted Edges Tests / Code Quality for Weighted Edges (push) Has been cancelled
52 lines
1.7 KiB
Python
52 lines
1.7 KiB
Python
from datetime import datetime, timezone
|
|
from cognee.modules.engine.models import Interval, Timestamp, Event
|
|
from cognee.modules.engine.utils import generate_node_id
|
|
|
|
|
|
def generate_timestamp_datapoint(ts: Timestamp) -> Timestamp:
|
|
"""
|
|
Generates a normalized Timestamp datapoint from a given Timestamp model.
|
|
|
|
The function converts the provided timestamp into an integer representation,
|
|
constructs a human-readable string format, and creates a new Timestamp object
|
|
with a unique identifier.
|
|
|
|
Args:
|
|
ts (Timestamp): The input Timestamp model containing date and time components.
|
|
|
|
Returns:
|
|
Timestamp: A new Timestamp object with a generated ID, integer representation,
|
|
original components, and formatted string.
|
|
"""
|
|
|
|
time_at = date_to_int(ts)
|
|
timestamp_str = (
|
|
f"{ts.year:04d}-{ts.month:02d}-{ts.day:02d} {ts.hour:02d}:{ts.minute:02d}:{ts.second:02d}"
|
|
)
|
|
return Timestamp(
|
|
id=generate_node_id(str(time_at)),
|
|
time_at=time_at,
|
|
year=ts.year,
|
|
month=ts.month,
|
|
day=ts.day,
|
|
hour=ts.hour,
|
|
minute=ts.minute,
|
|
second=ts.second,
|
|
timestamp_str=timestamp_str,
|
|
)
|
|
|
|
|
|
def date_to_int(ts: Timestamp) -> int:
|
|
"""
|
|
Converts a Timestamp model into an integer representation in milliseconds since the Unix epoch (UTC).
|
|
|
|
Args:
|
|
ts (Timestamp): The input Timestamp model containing year, month, day, hour, minute, and second.
|
|
|
|
Returns:
|
|
int: The UTC timestamp in milliseconds since January 1, 1970.
|
|
"""
|
|
dt = datetime(ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second, tzinfo=timezone.utc)
|
|
time = int(dt.timestamp() * 1000)
|
|
return time
|