From 9e49fc675efe4e0a50e369759a43555016670e55 Mon Sep 17 00:00:00 2001 From: linlin Date: Tue, 6 Oct 2020 17:24:55 +0200 Subject: [PATCH] New translations timer.py (Chinese Simplified) --- lang/zh/gklearn/utils/timer.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 lang/zh/gklearn/utils/timer.py diff --git a/lang/zh/gklearn/utils/timer.py b/lang/zh/gklearn/utils/timer.py new file mode 100644 index 0000000..b1cecec --- /dev/null +++ b/lang/zh/gklearn/utils/timer.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Mon Mar 23 09:52:50 2020 + +@author: ljia +""" +import time + +class Timer(object): + """A timer class that can be used by methods that support time limits. + + Note + ---- + This is the Python implementation of `the C++ code in GEDLIB `__. + """ + + def __init__(self, time_limit_in_sec): + """Constructs a timer for a given time limit. + + Parameters + ---------- + time_limit_in_sec : string + The time limit in seconds. + """ + self.__time_limit_in_sec = time_limit_in_sec + self.__start_time = time.time() + + + def expired(self): + """Checks if the time limit has expired. + + Return + ------ + Boolean true if the time limit has expired and false otherwise. +""" + if self.__time_limit_in_sec > 0: + runtime = time.time() - self.__start_time + return runtime >= self.__time_limit_in_sec + return False \ No newline at end of file