This repository has been archived by the owner on Jan 25, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
executable file
·82 lines (65 loc) · 1.59 KB
/
test.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
#!/usr/bin/env python
#-*- coding: utf-8 -*-
import sys
import csv
import datetime
HOURS_PER_WEEK = 8
HOURS_PER_MONTH = 35 # 4 * HOURS_PER_WEEK
def datefromstring(string):
tmp = string.split('.', 2)
if len(tmp[2]) <= 2:
tmp[2] = int(tmp[2]) + 2000
return datetime.date(tmp[2], int(tmp[1]), int(tmp[0]))
def timedeltafromstring(string):
tmp = string.split(':', 1)
return datetime.timedelta(hours=int(tmp[0]), minutes=int(tmp[1]))
if len(sys.argv) != 2:
print("Please specify filename")
sys.exit(1)
list = []
with open(sys.argv[1],'r') as f:
reader = csv.reader(f,delimiter=';')
headers = reader.next()[:-1]
#print headers
for row in reader:
#print row
if row[0] == '':
break
dict = {}
for i in range(len(headers)):
dict[headers[i]] = row[i]
print dict
list.append(dict)
for item in list:
datum = datefromstring(item['Datum'])
print datum
item['Datum'] = datum
delta = timedeltafromstring(item['Dauer'])
print delta
item['Dauer'] = delta
print list
try:
weeks = {}
it = iter(list)
next = it.next()
while True:
cur = next
startdate = cur['Datum'] - datetime.timedelta(days=cur['Datum'].weekday())
print startdate
weeks[startdate] = cur['Dauer']
#print cur['Datum'].weekday()
next = it.next()
while next['Datum'] - cur['Datum'] < datetime.timedelta(days=6):
print " %s" % next['Datum']
weeks[startdate] += next['Dauer']
next = it.next()
continue
continue
except StopIteration:
pass
finally:
print [(str(date),str(time)) for (date,time) in weeks.items()]
sum = datetime.timedelta(minutes=0)
for i in weeks.values():
sum += i
print sum