2020-10-19 12:01:01 +02:00
|
|
|
import json
|
2021-10-13 16:00:47 +02:00
|
|
|
from enum import Enum, auto
|
2020-10-28 21:22:16 +01:00
|
|
|
from typing import Optional, Union
|
|
|
|
|
|
|
|
import pytz
|
|
|
|
from dateutil.parser import isoparse
|
|
|
|
from django.utils import timezone
|
2020-10-19 12:01:01 +02:00
|
|
|
|
2021-10-13 16:00:47 +02:00
|
|
|
|
|
|
|
class PersonPropertiesMode(Enum):
|
|
|
|
USING_SUBQUERY = auto()
|
|
|
|
USING_PERSON_PROPERTIES_COLUMN = auto()
|
|
|
|
# Used when person join handles these filters
|
|
|
|
EXCLUDE = auto()
|
2020-10-19 12:01:01 +02:00
|
|
|
|
|
|
|
|
|
|
|
def is_json(val):
|
|
|
|
if isinstance(val, int):
|
|
|
|
return False
|
|
|
|
|
2021-02-10 19:59:30 +01:00
|
|
|
try:
|
|
|
|
int(val)
|
|
|
|
return False
|
|
|
|
except:
|
|
|
|
pass
|
2020-10-19 12:01:01 +02:00
|
|
|
try:
|
|
|
|
json.loads(val)
|
2021-02-25 15:54:55 +01:00
|
|
|
except (ValueError, TypeError):
|
2020-10-19 12:01:01 +02:00
|
|
|
return False
|
|
|
|
return True
|
2020-10-28 21:22:16 +01:00
|
|
|
|
|
|
|
|
|
|
|
def cast_timestamp_or_now(timestamp: Optional[Union[timezone.datetime, str]]) -> str:
|
|
|
|
if not timestamp:
|
|
|
|
timestamp = timezone.now()
|
|
|
|
|
|
|
|
# clickhouse specific formatting
|
|
|
|
if isinstance(timestamp, str):
|
|
|
|
timestamp = isoparse(timestamp)
|
|
|
|
else:
|
|
|
|
timestamp = timestamp.astimezone(pytz.utc)
|
|
|
|
|
|
|
|
return timestamp.strftime("%Y-%m-%d %H:%M:%S.%f")
|