-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsilentorgbusy
executable file
·237 lines (204 loc) · 5.16 KB
/
silentorgbusy
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
#!/bin/bash
# 2015.11.27
# Usage: silentorgbusy [file.org]
# Tells your average workload (hrs/days) to fulfill deadlines
# Format of the .org file:
# ** <2014-06-05 Thu> Stuff :1:
# that is:
# [anything but "<" here] <date> Stuff :[number of hrs required]:
# number of hrs required can be any positive integer. It can also be 0, in which case "Stuff" is considered a full day programme that takes the given day out of those available for work (e.g., a conference or a family trip)
# Weekends are not taken out but I guess could be treated easily.
re='^[0-9]+$'
real='^[0-9]+([.][0-9]+)?$'
if [ $# == 1 ] ; then
filenor="$1"
else
echo "Usage: silentorgbusy [filename]"
exit
fi
ffront=${filenor%.*}
file=$ffront.org
if [ ! -f $file ] ; then
echo "Can't find the file $file."
exit
fi
cat $file |
awk -F\: '
{
if ((NF > 1) && ($(NF-1) + 0 == $(NF-1)) && ($NF == "")) {
printf($1)
for (i=2; i<NF; i+=1) printf(":"$i);
print(":"$NF)
};
}' |
sort |
awk -F\: '
{
printf($1)
for (i=2; i<=NF; i+=1) printf(":"$i);
print(";"$(NF-1))
}' |
awk -F\< '
{
year=substr($2,1,4)
mo=substr($2,6,2)
day=substr($2,9,2)
# print("year="year" month="mo" day="day";"$0)
# dayno=(year-2013)*365+mo*30+day
if ((year % 4 == 0) && (year % 100 != 0)) leapy=1
else leapy=0;
if (mo == "01") mod=0;
if (mo == "02") mod=31;
if (mo == "03") mod=59+leapy;
if (mo == "04") mod=90+leapy;
if (mo == "05") mod=120+leapy;
if (mo == "06") mod=151+leapy;
if (mo == "07") mod=181+leapy;
if (mo == "08") mod=212+leapy;
if (mo == "09") mod=243+leapy;
if (mo == "10") mod=273+leapy;
if (mo == "11") mod=304+leapy;
if (mo == "12") mod=334+leapy;
dayno=mod+day
for (i=2012; i<year; i+=1) {
if ((i % 4 == 0) && (i % 100 != 0)) dayno=dayno+366
else dayno=dayno+365
}
print(dayno";"$0)
}' |
awk -F\; -v tyear="$(date +"%Y")" -v tmo="$(date +"%m")" -v tday="$(date +"%d")" ' BEGIN {
# tyear=strftime("%Y")
# tmo=strftime("%m")
# tday=strftime("%d")
#print(tyear", "tmo", "tday)
#tdayno=(tyear-2013)*365+tmo*30+tday
if ((tyear % 4 == 0) && (tyear % 100 != 0)) tleapy=1
else tleapy=0;
if (tmo == 1) tmod=0;
if (tmo == 2) tmod=31;
if (tmo == 3) tmod=59+tleapy;
if (tmo == 4) tmod=90+tleapy;
if (tmo == 5) tmod=120+tleapy;
if (tmo == 6) tmod=151+tleapy;
if (tmo == 7) tmod=181+tleapy;
if (tmo == 8) tmod=212+tleapy;
if (tmo == 9) tmod=243+tleapy;
if (tmo == 10) tmod=273+tleapy;
if (tmo == 11) tmod=304+tleapy;
if (tmo == 12) tmod=334+tleapy;
tdayno=tmod+tday
for (i=2012; i<tyear; i+=1) {
if ((i % 4 == 0) && (i % 100 != 0)) tdayno=tdayno+366
else tdayno=tdayno+365
}
# Put in 1 delay: we want to look at tomorrow.
tdayno=tdayno+1
# print(tdayno)
maxdays=-1
}
{
# Collect daily charge function p(days from today)
# The day from today distance
dayft=$1-tdayno
# Set the max distance looking into future, set zeros for dummy days
if (maxdays < dayft) {
for (i=maxdays+1; i<=dayft; i+=1) {
dummydays[i]=0;
}
maxdays=dayft;
}
# Collect dummy days (those with 0)
if ($NF == 0) dummydays[dayft]=1;
# Add the entry charge to the given day
if ($NF+0==$NF) {
if ((p[dayft]+0==p[dayft]) && (p[dayft]>0)) p[dayft]=p[dayft]+$NF;
else p[dayft]=$NF;
}
#for (i=2; i<=NF-2; i+=1) printf($i";");
#print($(NF-1))
}
END{
## For now just print p
#for (i=0; i<=maxdays; i+=1) {
# printf(p[i]", ")
#}
#print("")
p[-1]=0
# Now repack tasks from dummy days; p[-1] is the overflow if today is dummy and first dummy sequence has tasks.
for (i=maxdays; i>=0; i-=1) {
if (dummydays[i] == 1) {
p[i-1]=p[i-1]+p[i]
p[i]=0
}
}
## For now just print p
#for (i=-1; i<=maxdays; i+=1) {
# printf(p[i]", ")
#}
#print("")
# Now collapse dummy days in p[.] to get q[.]
dtime=-1
tmpmaxd=maxdays
for (i=0; i<=tmpmaxd; i+=1) {
if (dummydays[i] == 0) {
dtime=dtime+1
q[dtime]=p[i]
}
else {
maxdays=maxdays-1
}
}
# Maybe some stuff is left in the first dummy sequence. Dont forget about it
q[0]=q[0]+p[-1]
## For now just print q
#for (i=0; i<=maxdays; i+=1) {
# printf(q[i]", ")
#}
#print("")
###
#MORNING
###
# Compute the cumulative charge function F(days from today)
for (i=0; i<=maxdays; i+=1) {
F[i]=0
for (j=0; j<=i; j+=1) F[i]=F[i]+q[j];
}
## For now just print F
#for (i=0; i<=maxdays; i+=1) {
# printf(F[i]", ")
#}
#print("")
# Put concave bound on F. First a pointer to see where the critical points are.
# The origin is not necessarily critical: add imaginary point
pointer[0]=-1
F[-1]=0
# This will show where the max of the pointer is right now
cvxday=-1
# This will show how many points we have in the cvx stuff
cvxc=0
while (cvxday<maxdays) {
# Max slope into the future
maxslp=0
cvxc=cvxc+1
# Look at all future days
for (i=cvxday+1; i<=maxdays; i+=1) {
currslp=(F[i]-F[cvxday])/(i-cvxday);
if (currslp>=maxslp){
pointer[cvxc]=i
maxslp=currslp
}
}
cvxday=pointer[cvxc]
}
## Print the pointer
#for (i=0; i<=cvxc; i+=1) printf("no: %4.4f, day: %4.4f\n",i,pointer[i])
# Print the slopes
for (i=0; i<=maxdays; i+=1) {
# Find the pointer values around on our left
for (j=1; j<=cvxc; j+=1) {
if ((pointer[j-1]<i) && (pointer[j]>=i)) poicurr=j
}
ch=(F[pointer[poicurr-1]]-F[pointer[poicurr]])/(pointer[poicurr-1]-pointer[poicurr])
printf("%6.2f\n",ch)
}
}'