54 lines
1.3 KiB
Python
54 lines
1.3 KiB
Python
# !/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
# IMPORTS
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
from datetime import datetime;
|
|
from datetime import timedelta;
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
# CLASS counter
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
class Counter(object):
|
|
_nr_steps: int;
|
|
_timeelapsed: timedelta;
|
|
_timecurrent: datetime;
|
|
|
|
def __init__(self):
|
|
self.reset();
|
|
|
|
def __str__(self) -> str:
|
|
return str(self._nr_steps);
|
|
|
|
@property
|
|
def numberOfStep(self) -> int:
|
|
return self._nr_steps;
|
|
|
|
@property
|
|
def elapsedTime(self) -> timedelta:
|
|
return self._timeelapsed;
|
|
def start(self):
|
|
self._timecurrent = datetime.now();
|
|
return self;
|
|
|
|
def stop(self):
|
|
t0 = self._timecurrent;
|
|
t1 = datetime.now();
|
|
self._timecurrent = t1;
|
|
self._timeelapsed += (t1 - t0);
|
|
return self;
|
|
|
|
def add(self, n: int = 1):
|
|
self._nr_steps += n;
|
|
return self;
|
|
|
|
def reset(self):
|
|
t = datetime.now();
|
|
self._timeelapsed = t - t;
|
|
self._nr_steps = 0;
|
|
self._timecurrent = t;
|
|
return self;
|