benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf 594f4dfe-5cf3-5861-a7a5-a59025a59cd7

Problem

Answer published by the source. Consult the official source to check your work against its answer.

complete prompt

import os
from datetime import datetime

# Constants
LOG_DIR = './logs'

def task_func(metrics, filename, log_dir=LOG_DIR):
    """
    This function writes a dictionary of metrics to a specified log file, appending a timestamp to each entry.
    
    Parameters:
    - metrics (dict): A dictionary containing metric names as keys and their corresponding values.
    - filename (str): The name of the file to which the metrics will be logged.
    - log_dir (str, optional): The directory where the log file is stored. Default is './logs'.
    
    Returns:
    - bool: True if the metrics were successfully written to the file, False otherwise.
    
    Requirements:
    - os
    - datetime
    
    Examples:
    >>> metrics = {'accuracy': 0.98, 'loss': 0.05}
    >>> task_func(metrics, 'metrics.log')
    An error occurred: [Errno 2] No such file or directory: './logs/metrics.log'
    False
    
    >>> metrics = {'precision': 0.75, 'recall': 0.80}
    >>> task_func(metrics, 'evaluation.log')
    An error occurred: [Errno 2] No such file or directory: './logs/evaluation.log'
    False
    """

instruct prompt

This function writes a dictionary of metrics to a specified log file, appending a timestamp to each entry. >>> metrics = {'precision': 0.75, 'recall': 0.80} >>> task_func(metrics, 'evaluation.log') An error occurred: [Errno 2] No such file or directory: './logs/evaluation.log' False
The function should output with:
    bool: True if the metrics were successfully written to the file, False otherwise.
You should write self-contained code starting with:

Code

import os
from datetime import datetime
# Constants
LOG_DIR = './logs'
def task_func(metrics, filename, log_dir=LOG_DIR):

code prompt

Code

import os
from datetime import datetime
# Constants
LOG_DIR = './logs'
def task_func(metrics, filename, log_dir=LOG_DIR):

entry point

task_func

libs

  • datetime
  • os

Discussion

Discussion

No discussion posts on this page yet. Share a minimal failing example, an algorithm with its complexity, or a reproducible command and result. Use the posting template.

See answer Answer published by the source

Artifacts

Code, notes and reproducible work shared by participants. Files are served from a separate origin.

No artifacts on this page yet. Share reproducible code or notes in a contribution. Share a minimal failing example, an algorithm with its complexity, or a reproducible command and result. Use the posting template.

Source and history

Official source

initial import