+++ /dev/null
-#!/usr/bin/env python
-# coding=UTF-8
-#
-# Copyright (C) 2010 Stefanos Harhalakis
-#
-# This file is part of maegirls.
-#
-# maegirls is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# maegirls is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with maegirls. If not, see <http://www.gnu.org/licenses/>.
-#
-# $Id: 0.py 2265 2010-02-21 19:16:26Z v13 $
-
-__version__ = "$Id: 0.py 2265 2010-02-21 19:16:26Z v13 $"
-
-import time
-
-def today():
- t=time.time() - time.timezone
- day=int(t/86400)
-
- return(day)
-
-# Defaults for a girl
-defaults={
- 'cycle': 28, # Cycle length
- 'menstr': 5, # Duration of menstruation
- 'ovday': -14, # When ovulation happens. Positive: This number
- # of days after the start of the cycle.
- # Negative: This number of days before the end
- # of the cycle.
- 'day0': today()
- }
-
-class Algo(object):
- def __init__(self):
- t=today()
- self.setReference(t, defaults)
-
- # set day "day" as the reference day of starting period cycle
- # day is int(time.time()/86400)
- # cycle is the cycle width in days, starting from 0
- def setReference(self, day, cfg):
- self.cfg=cfg
- self.refday=day
-
- # Convert an arbitary day to a day in cycle
- def dayInCycle(self, day):
- d=(day-self.refday) % self.cfg['cycle']
- if d<0:
- d+=self.cycleLength()
-
- return(d)
-
- def cycleLength(self):
- return(self.cfg['cycle'])
-
- def currentDayInCycle(self):
- d=today()
- return(self.dayInCycle(d))
-
- def menstruationDuration(self):
- return(self.cfg['menstr'])
-
- def ovulationDay(self):
- return(self.cfg['ovday'])
-
- # Return:
- # ret={
- # 'status': ['ok', 'red']
- # 'day': day in status
- # 'len': length of status
- # }
- #
- # e.g. ret={'status':'red', 'day':0, 'len':5}
- # means that it is in red, in the first of 5
- def status(self, day):
- d=self.dayInCycle(day)
-
- cycle=self.cycleLength()
-
- #ovbefore=14
- ovday=self.ovulationDay()
- if ovday>0:
- ovstart=ovday-3
- ovmid=ovday
- ovend=ovday+1
- else:
- ovstart=cycle+ovday-3
- ovmid=cycle+ovday
- ovend=cycle+ovday+1
-
- menstr=self.menstruationDuration()
-
- if d<menstr:
- # Red
- ret={
- 'status': 'red',
- 'day': d,
- 'len': menstr,
- }
- elif d>=cycle-7:
- ret={
- 'status': 'blue',
- 'day': 7+d-cycle,
- 'len': 7,
- }
- elif d>=ovstart and d<=ovmid:
- ret={
- 'status': 'green',
- 'day': d-ovstart,
- 'len': 4,
- }
- elif d>ovmid and d<=ovend:
- ret={
- 'status': 'green',
- 'day': 2,
- 'len': 4,
- }
- else:
- ret={
- 'status': 'ok',
- 'day': d,
- 'len': cycle
- }
-
- return(ret)
-
-
-# vim: set ts=8 sts=4 sw=4 noet formatoptions=r ai nocindent:
-