Skip to content

Commit

Permalink
Reorganize functions
Browse files Browse the repository at this point in the history
  • Loading branch information
theodore-s-beers committed Dec 10, 2024
1 parent d2e9bd2 commit 1b77c28
Showing 1 changed file with 25 additions and 15 deletions.
40 changes: 25 additions & 15 deletions src/pykubegrader/telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
from requests import Response
from requests.auth import HTTPBasicAuth

# Set logging config (`force` is important)
logging.basicConfig(filename=".output.log", level=logging.INFO, force=True)


def telemetry(info: ExecutionInfo) -> None:
cell_content = info.raw_cell
log_encrypted(f"code run: {cell_content}")
#
# Local functions
#


def encrypt_to_b64(message: str) -> str:
Expand All @@ -34,17 +34,6 @@ def encrypt_to_b64(message: str) -> str:
return encrypted_b64


def log_encrypted(message: str) -> None:
encrypted_b64 = encrypt_to_b64(message)
logging.info(f"Encrypted Output: {encrypted_b64}")


def log_variable(value, info_type) -> None:
timestamp = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
message = f"{info_type}, {value}, {timestamp}"
log_encrypted(message)


def ensure_responses() -> dict:
with open(".responses.json", "a") as _:
pass
Expand All @@ -61,6 +50,22 @@ def ensure_responses() -> dict:
return data


def log_encrypted(message: str) -> None:
encrypted_b64 = encrypt_to_b64(message)
logging.info(f"Encrypted Output: {encrypted_b64}")


def log_variable(value, info_type) -> None:
timestamp = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
message = f"{info_type}, {value}, {timestamp}"
log_encrypted(message)


def telemetry(info: ExecutionInfo) -> None:
cell_content = info.raw_cell
log_encrypted(f"code run: {cell_content}")


def update_responses(key: str, value) -> dict:
data = ensure_responses()
data[key] = value
Expand All @@ -84,6 +89,11 @@ def update_responses(key: str, value) -> dict:
return data


#
# API request functions
#


def score_question(
student_email: str,
term: str,
Expand Down

0 comments on commit 1b77c28

Please sign in to comment.