-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtasks.py
180 lines (163 loc) · 4.59 KB
/
tasks.py
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#
# Task List python module
#
#############################
import sys, csv
class TaskList:
def __init__(self, infile, status='todo', subgraph='t'):
if status != 'todo' and status != 'all':
raise ValueError('please chose status as either: todo or all')
exit(1)
if subgraph.lower() != 't' and subgraph.lower() != 'f':
raise ValueError('please chose true (t) or false (f) for subgraph parameter')
exit(1)
if subgraph=='t':
self.subgraphing = True
else:
self.subgraphing = False
instream = open(infile, "r", encoding='utf-8-sig')
self.infile = infile
self.headers = instream.readline().strip().split(",")
self.maxIndent = self.getMaxIndent()
self.headerDict = {self.headers[i]:i for i in range(len(self.headers))}
self.tasks = []
for line in csv.reader(instream):
if len(line) <= 3:
continue
# if requested, keep only incomplete tasks/items:
if line[self.headerDict['Status']]!='To-Do' and status=='todo':
continue
self.tasks = self.tasks + [line]
self.Nnodes = 0 # private
self.Nsubgraphs = 0 # private
self.tb = ' '
instream.close()
def printGraph(self):
self.beginGraph("G")
print("/* Nodes */")
self.printGraphNodes()
print("/* Edges */")
self.printGraphEdges()
print("/* Ranks */")
self.endGraph(-1)
def printGraphNodes(self, asrecords=False):
if asrecords == False:
printX = self.printNode
else:
printX = self.printRecord
i = 0 # index for task list
j = 0 # index for graph nodes
k = 0 # index for subgraphs
while i < len(self.tasks)-1:
il = self.getIndentLevel(i)
il_next = self.getIndentLevel(i+1)
if il<il_next:
self.beginSubgraph(i,k)
k+=1
elif il==il_next:
printX(i,j)
j+=1
else:
printX(i,j)
while il>il_next:
self.endSubgraph(il-1)
il -= 1
j+=1
i+=1
printX(i,j)
j+=1
self.Nnodes = j
self.Nsubgraphs = k
# print any remaining "}"s needed to close the graphs:
while il >= 1:
self.endSubgraph(il-1)
il-=1
def printGraphEdges(self):
for i in range(self.Nnodes-1):
print(self.tb+str(i)+' -> '+str(i+1))
def getMaxIndent(self):
i=1
while(self.headers[i]=='"ID"'):
i+=1
return i
def getIndentLevel(self, taskindex):
for i in range(self.maxIndent):
if self.tasks[taskindex][i]!='':
return i
def getDueDate(self,taskindex):
return self.tasks[taskindex][self.maxIndent+6]
def beginGraph(self,label):
print("digraph "+label+" {")
def beginSubgraph(self,taskindex,subindex):
if self.subgraphing:
print(
self.tb*(self.getIndentLevel(taskindex)+1)
+ 'subgraph cluster_'
+ str(subindex)
+ ' {'
)
print(
self.tb*(self.getIndentLevel(taskindex)+2)
+ 'label="'
+ self.tasks[taskindex][self.maxIndent]
+ '";'
)
else:
print(
self.tb*(self.getIndentLevel(taskindex)+2)
+ "/* "
+ self.tasks[taskindex][self.maxIndent]
+ ": */"
)
def endSubgraph(self,indent):
if self.subgraphing:
self.endGraph(indent)
else:
pass
def endGraph(self,indent):
print(self.tb*(indent+1)+"}")
def printNode(self, taskindex, nodeindex):
if self.tasks[taskindex][self.maxIndent+10].find('$w')==-1:
self.printTaskNode(taskindex,nodeindex)
else:
self.printWaitNode(taskindex,nodeindex)
def printTaskNode(self,taskindex,nodeindex):
print(
self.tb*(self.getIndentLevel(taskindex)+1)
+ str(nodeindex)
+ ' [label="'
+ self.tasks[taskindex][self.maxIndent]
+ '"];'
)
def printWaitNode(self,taskindex,nodeindex):
print(
self.tb*(self.getIndentLevel(taskindex)+1)
+ str(nodeindex)
+ ' [label="'
+ self.tasks[taskindex][self.maxIndent]
+ '",shape=box];'
)
def printRecord(self, taskindex, nodeindex):
taskcomment = self.tasks[taskindex][self.maxIndent+10]
posw = taskcomment.find('$w')
post = taskcomment.find('$t')
duration = ''
if posw != -1 and post == -1:
duration = taskcomment[posw:taskcomment[posw:-1].find(']')][3:]
elif post != -1 and posw == -1:
duration = taskcomment[post:taskcomment[post:-1].find(']')][3:]
elif post == -1 and posw == -1:
duration = '1 week' # default value
else:
raise ValueError('block can\'t be both task and wait.')
tab=self.tb*(self.getIndentLevel(taskindex)+1)
print(
tab
+ str(nodeindex)
+' [shape=none, margin=0, label=<'
+ '<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" CELLPADDING="4">\n'
+ tab + '<TR><TD COLSPAN="2">'+self.tasks[taskindex][self.maxIndent]+'</TD></TR>\n'
+ tab + '<TR><TD>'+duration+'</TD>\t// est. duration\n' # est. duration
+ tab + '\t<TD>'+self.getDueDate(taskindex)+'</TD>\t est. end date\n' # est. end date
+ tab + '</TR></TABLE>>];\n'
)