File: generate_taskfile.py

package info (click to toggle)
taskcoach 1.4.1-4
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 32,496 kB
  • ctags: 17,810
  • sloc: python: 72,170; makefile: 254; ansic: 120; xml: 29; sh: 16
file content (138 lines) | stat: -rw-r--r-- 5,727 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/usr/bin/env python

'''
Task Coach - Your friendly task manager
Copyright (C) 2004-2014 Task Coach developers <developers@taskcoach.org>

Task Coach 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.

Task Coach 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 this program.  If not, see <http://www.gnu.org/licenses/>.
'''

# Script to generate (big) task files

import sys, random, wx
app = wx.App(False)
sys.path.insert(0, '..')
from taskcoachlib import i18n
i18n.Translator('en_US')
from taskcoachlib import persistence, config
from taskcoachlib.domain import task, category, date, effort
from taskcoachlib.gui import artprovider
import randomtext

def randomThing(thingFactory, default=None):
    return default if random.random() < 0.8 else thingFactory()

def randomDescription():
    return randomThing(lambda: randomtext.text(times=random.randint(3,10)), default='')

def randomSubject():
    return randomtext.title()

def randomColor():
    return randomThing(lambda: wx.Colour(random.randint(0,255), random.randint(0,255), 
                                        random.randint(0,255)))
        
def randomFont():
    return randomThing(lambda: wx.Font(pointSize=random.randint(6,24), 
                               family=random.choice([wx.FONTFAMILY_DECORATIVE, wx.FONTFAMILY_MODERN,
                                                     wx.FONTFAMILY_ROMAN, wx.FONTFAMILY_SCRIPT,
                                                     wx.FONTFAMILY_SWISS, wx.FONTFAMILY_TELETYPE]),
                               style=random.choice([wx.FONTSTYLE_ITALIC, wx.FONTSTYLE_NORMAL]),
                               weight=random.choice([wx.FONTWEIGHT_BOLD, wx.FONTWEIGHT_LIGHT, 
                                                     wx.FONTWEIGHT_NORMAL])))

def randomIcon():
    return randomThing(lambda: random.choice(artprovider.chooseableItemImages.keys()))
    
def randomDateTime(chanceNone=0.5):
    if random.random() < chanceNone:
        return None
    year = random.randint(2000, 2020)
    month = random.randint(0, 12)
    day = random.randint(0, 31)
    hour = random.randint(0, 23)
    minute = random.randint(0, 59)
    second = random.randint(0, 59)
    try:
        return date.DateTime(year, month, day, hour, minute, second)
    except ValueError:
        return randomDateTime(chanceNone)
    
def generateCategory(index, children=3, chanceNextLevel=0.2):
    newCategory = category.Category(subject='Category %s: %s'%('.'.join(index), randomSubject()),
                                    exclusiveSubcategories=random.random() < 0.3,
                                    icon=randomIcon(),
                                    fgColor=randomColor(),
                                    bgColor=randomColor(),
                                    font=randomFont(),
                                    description=randomDescription())
    if random.random() < chanceNextLevel:
        for childNr in range(children):
            child = generateCategory(index + [str(childNr)], chanceNextLevel=chanceNextLevel/2)
            newCategory.addChild(child)
    return newCategory

def assignCategories(categorizable, categories):
    for _ in range(random.randint(0, 3)):
        randomCategory = random.choice(list(categories))
        categorizable.addCategory(randomCategory)
        randomCategory.addCategorizable(categorizable)
        
def generateEffort():
    start = randomDateTime(0)
    stop = start + date.TimeDelta(hours=random.triangular(0, 10, 1), 
                                  minutes=random.randint(0, 60),
                                  seconds=random.randint(0, 60))
    return effort.Effort(None, start, stop, description=randomDescription())

def generateEfforts():
    efforts = []
    for _ in range(random.randint(0, 10)):
        efforts.append(generateEffort())
    return efforts
    
def generateTask(index, categories, children=3, chanceNextLevel=0.2):
    efforts = generateEfforts()
    newTask = task.Task(subject='Task %s: %s'%('.'.join(index), randomSubject()),
                        actualStartDateTime=randomDateTime(),
                        plannedStartDateTime=randomDateTime(),
                        dueDateTime=randomDateTime(),
                        completionDateTime=randomDateTime(),
                        priority=random.randint(0,100),
                        efforts=efforts,
                        description=randomDescription())
    print newTask.subject(recursive=True)
    assignCategories(newTask, categories)
    if random.random() < chanceNextLevel:
        for childNr in range(children):
            child = generateTask(index + [str(childNr)], categories, chanceNextLevel=chanceNextLevel/2)
            newTask.addChild(child)
    return newTask

def generate(nrCategories=20, nrTasks=250):
    task.Task.settings = config.Settings(load=False)
    taskFile = persistence.TaskFile()
    taskFile.setFilename('generated_taskfile.tsk')
    tasks = taskFile.tasks()
    categories = taskFile.categories()
    for index in range(nrCategories):
        categories.append(generateCategory([str(index)]))
    for index in range(nrTasks):        
        tasks.append(generateTask([str(index)], categories))
    taskFile.save()
        

if __name__ == '__main__':
    #app = wx.App(False)
    generate()