<commit_before>import datetime
import time

from django.conf import settings
from typing import Any, Dict, Optional

from django.http import HttpRequest, HttpResponse
from django.utils.timezone import now as timezone_now
from django.utils.translation import ugettext as _

from zerver.decorator import human_users_only
from zerver.lib.actions import (
    do_update_user_status,
    get_status_dict,
    update_user_presence,
)
from zerver.lib.request import has_request_variables, REQ, JsonableError
from zerver.lib.response import json_success, json_error
from zerver.lib.timestamp import datetime_to_timestamp
from zerver.lib.validator import check_bool, check_capped_string
from zerver.models import UserActivity, UserPresence, UserProfile, \
    get_active_user_by_delivery_email

def get_status_list(requesting_user_profile: UserProfile,
                    slim_presence: bool) -> Dict[str, Any]:
    return {'presences': get_status_dict(requesting_user_profile, slim_presence),
            'server_timestamp': time.time()}

def get_presence_backend(request: HttpRequest, user_profile: UserProfile,
                         email: str) -> HttpResponse:
    # This isn't used by the webapp; it's available for API use by
    # bots and other clients.  We may want to add slim_presence
    # support for it (or just migrate its API wholesale) later.
    try:
        target = get_active_user_by_delivery_email(email, user_profile.realm)<commit_msg>presence: Calculate server_timestamp slightly earlier.<commit_after>import datetime
import time

from django.conf import settings
from typing import Any, Dict, Optional

from django.http import HttpRequest, HttpResponse
from django.utils.timezone import now as timezone_now
from django.utils.translation import ugettext as _

from zerver.decorator import human_users_only
from zerver.lib.actions import (
    do_update_user_status,
    get_status_dict,
    update_user_presence,
)
from zerver.lib.request import has_request_variables, REQ, JsonableError
from zerver.lib.response import json_success, json_error
from zerver.lib.timestamp import datetime_to_timestamp
from zerver.lib.validator import check_bool, check_capped_string
from zerver.models import UserActivity, UserPresence, UserProfile, \
    get_active_user_by_delivery_email

def get_status_list(requesting_user_profile: UserProfile,
                    slim_presence: bool) -> Dict[str, Any]:
    server_timestamp = time.time()
    presences = get_status_dict(requesting_user_profile, slim_presence)
    return dict(presences=presences, server_timestamp=server_timestamp)

def get_presence_backend(request: HttpRequest, user_profile: UserProfile,
                         email: str) -> HttpResponse:
    # This isn't used by the webapp; it's available for API use by
    # bots and other clients.  We may want to add slim_presence
    # support for it (or just migrate its API wholesale) later.
    try:
        target = get_active_user_by_delivery_email(email, user_profile.realm)
{'fraction_non_alphanumeric': 0.059353117705901966, 'fraction_numerical': 0.0, 'mean_word_length': 4.597014925373134, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7358222', 'n_tokens_mistral': 880, 'n_tokens_neox': 856, 'n_words': 253}