Mercurial > getan > getan
diff getan/project.py @ 23:9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
author | Ingo Weinzierl <ingo_weinzierl@web.de> |
---|---|
date | Sat, 28 Aug 2010 20:16:58 +0200 |
parents | |
children | 780bfda9c583 ce707fbb9666 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/getan/project.py Sat Aug 28 20:16:58 2010 +0200 @@ -0,0 +1,78 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# (c) 2008, 2009, 2010 by +# Sascha L. Teichmann <sascha.teichmann@intevation.de> +# Ingo Weinzierl <ingo.weinzierl@intevation.de> +# +# This is Free Software licensed unter the terms of GPLv3 or later. +# For details see LICENSE coming with the source of 'getan'. + +from datetime import datetime, timedelta + +class Project: + + def __init__(self, id, key, desc, total): + self.id = id + self.key = key + self.desc = desc + self.entries = [] + self.total = total + self.start = None + self.stop = None + + def year(self): + total = 0 + now = datetime.now() + for entry in self.entries: + start = entry.start + if start.year == now.year: + total += (entry.end - start).seconds + return total + + def month(self): + total = 0 + now = datetime.now() + for entry in self.entries: + start = entry.start + if start.month == now.month and start.year == now.year: + total += (entry.end - start).seconds + return total + + def week(self): + total = 0 + now = datetime.now() + tweek = now.strftime('%W') + for entry in self.entries: + start = entry.start + if start.strftime('%W') == tweek and start.year == now.year: + total += (entry.end - start).seconds + return total + + def day(self): + total = 0 + now = datetime.now() + for entry in self.entries: + start = entry.start + if start.month == now.month and start.year == now.year and start.day == now.day: + total += (entry.end - start).seconds + return total + + +class Entry: + + def __init__(self, id, project_id, start, end, desc): + self.id = id + self.project_id = project_id + self.start = start + self.end = end + self.desc = desc + + def duration(self): + return (self.end - self.start) + + def __str__(self): + return ("[%s | %s | %s | %s | %s]" % + (self.id, self.project_id, self.start, self.end, self.desc)) + +# vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8: