Skip to content

Latest commit

 

History

History
104 lines (79 loc) · 2.64 KB

README.md

File metadata and controls

104 lines (79 loc) · 2.64 KB

prodplanner

Django DRF project to calculate dates for recurrent actions

Based on dateutil ; it is possible to define rrules and dates and create rrulesets including or excluding rrulesets, rrules or datetimes.

The first goal is to get a list of dates, not datetimes.

To perform it :

  • rrules are defined at '/planner/simplerules/',
  • dates at '/planner/daterules/'
  • rrulesets at '/planner/rulesets/'
  • including or excluding elements from a rruleset at '/planner/rulesetelements/'

it is then possible to query a rruleset to get occurences on a time interval :

http://localhost:8000/planner/rulesets/886ac04c-d57f-4f1b-ab3d-f8415f5e0521/between/?start=2017-01-01T00:00:00&end=2018-01-01T00:00:00

HTTP 200 OK
Allow: GET, OPTIONS
Content-Type: application/json
Vary: Accept

[

    "2017-01-01",
    "2017-04-17",
    "2017-05-01",
    "2017-05-08",
    "2017-05-26",
    "2017-06-05",
    "2017-07-14",
    "2017-08-15",
    "2017-11-01",
    "2017-11-11",
    "2017-12-25",
    "2018-01-01"
]

It is also possible to get next 10 occurences for a ruleset :

http://localhost:8000/planner/rulesets/886ac04c-d57f-4f1b-ab3d-f8415f5e0521/next10/

[
    "2017-05-01",
    "2017-05-08",
    "2017-05-26",
    "2017-06-05",
    "2017-07-14",
    "2017-08-15",
    "2017-11-01",
    "2017-11-11",
    "2017-12-25",
    "2018-01-01"
]

python manage.py makemigrations

python manage.py migrate

Load fixtures : python manage.py loaddata fixtures/planner.json

The second goal is to schedule tasks To create a schedule you must select a ruleset and a delta which is based on dateutil.relativedelta and then choose the daytime (hour, minute, second) delta configuration is accessible at http://localhost:8000/planner/deltas/

A task will be generated for each occurence in the ruleset. The task will have the "due_time" datetime set to the date of the ruleset occurence with the time of the day chosen in the schedule. The start of the task will be calculated from the due_time plus the dateutil.relativedelta calculated from the delta object associated in the schedule (which should be negative).

Via django shell it is possible to generate tasks with :

import datetime
start = datetime.datetime(2017,4,25)
end = datetime.datetime(2018,4,25)
s = Schedule.objects.get(id='uuid-xxx-xxx-xxx')
from planner.models import schedule_models
schedule_models.task_generate(s, start, end)

version

Alpha developpement

tested with

  • Python 3.5.3
  • Django 1.11.1

todo

  • make it as a library or django-app
  • be able to change date of a task (without be regenerated by task_generate)
  • manage timezones
  • check for a task due_time to be after start
  • ... suggestions welcomed