tahamajs's picture
download
raw
2.69 kB
import uuid
from django.contrib.auth import get_user_model
from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType
from django.db import models
User = get_user_model()
class ActivityLog(models.Model):
ACTION_TYPES = [
("create", "Created"),
("update", "Updated"),
("delete", "Deleted"),
("start", "Started"),
("stop", "Stopped"),
("complete", "Completed"),
("fail", "Failed"),
("publish", "Published"),
("share", "Shared"),
("comment", "Commented"),
("react", "Reacted"),
("export", "Exported"),
]
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
user = models.ForeignKey(User, on_delete=models.SET_NULL, null=True, blank=True)
action_type = models.CharField(max_length=20, choices=ACTION_TYPES)
description = models.TextField()
content_type = models.ForeignKey(
ContentType, on_delete=models.CASCADE, null=True, blank=True
)
object_id = models.CharField(max_length=36, null=True, blank=True)
content_object = GenericForeignKey("content_type", "object_id")
metadata = models.JSONField(default=dict, blank=True)
created_at = models.DateTimeField(auto_now_add=True, db_index=True)
class Meta:
ordering = ["-created_at"]
indexes = [
models.Index(fields=["user", "created_at"]),
models.Index(fields=["action_type", "created_at"]),
]
def __str__(self):
return f"[{self.action_type}] {self.user} – {self.description[:80]}"
def log_activity(
user, action_type: str, description: str, content_object=None, metadata=None
):
entry = ActivityLog(
user=user,
action_type=action_type,
description=description,
metadata=metadata or {},
)
if content_object:
entry.content_type = ContentType.objects.get_for_model(content_object)
entry.save()
return entry
# Backward compatibility aliases
try:
from experiment.models import Experiment, TrainingRun, TrainingSnapshot
except ImportError:
pass
class AttentionMetric(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
run = models.ForeignKey('experiment.TrainingRun', on_delete=models.CASCADE, related_name="attention_metrics", null=True)
layer = models.IntegerField()
head = models.IntegerField()
importance = models.FloatField()
stability = models.FloatField()
similarity = models.FloatField()
ablation_delta_ppl = models.FloatField()
created_at = models.DateTimeField(auto_now_add=True)

Xet Storage Details

Size:
2.69 kB
·
Xet hash:
3db5e7d37c9216ee2b09aa7e120b504a89501758b9c33af8d687b5188c4aa168

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.