Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

42-normalize-timestamp #46

Merged
merged 5 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions distill/core/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,4 @@ def to_json(self) -> str:

def to_dict(self) -> JsonDict:
return self.data.model_dump(by_alias=True)

4 changes: 3 additions & 1 deletion distill/core/types.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from typing import Union, List, Dict
from typing_extensions import Annotated, TypeAliasType
from typing_extensions import TypeAliasType

# TypeAliasType is necessary to avoid recursion error when validating this
# type with Pydantic
Expand All @@ -17,4 +17,6 @@

JsonDict = Dict[str, 'JSONSerializable']

Timestamp = Union[str, int, float]


15 changes: 12 additions & 3 deletions distill/schemas/userale.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from enum import Enum
from typing import List, Optional

from pydantic import AliasGenerator, BaseModel, Field
from pydantic import AliasGenerator, BaseModel, Field, field_serializer, field_validator
from pydantic.alias_generators import to_camel
from pydantic.config import ConfigDict
from datetime import datetime


class Browser(BaseModel):
Expand Down Expand Up @@ -58,7 +58,7 @@ class UserAleSchema(BaseModel):
page_title: str
page_referrer: str
browser: Browser
client_time: int
client_time: int
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why the trailing space?

micro_time: int = Field(..., lt=2)
location: Location
scrn_res: ScrnRes
Expand All @@ -71,3 +71,12 @@ class UserAleSchema(BaseModel):
tool_name: Optional[str]
userale_version: Optional[str]
session_id: str

@field_validator("client_time")
def validate_ct(cls, ct: float):
return datetime.fromtimestamp(ct / 1000)

@field_serializer("client_time")
def serialize_ct(self, ct: datetime):
return int(ct.timestamp() * 1000)

Comment on lines +74 to +82
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so simple and clean.

Loading
Loading