-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanalyzer.py
More file actions
78 lines (60 loc) · 2.41 KB
/
analyzer.py
File metadata and controls
78 lines (60 loc) · 2.41 KB
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
# %%
import math
from turtle import color
import polars as pl#
from PIL import Image, ImageDraw, ImageFont
from datetime import datetime,date,time
import matplotlib.pyplot as plt
from config import *
# %%
# Read the data from data.csv
df = pl.read_csv('data.csv', parse_dates=True).select([
pl.col("Client").alias("client"),
pl.col("Project").alias("project"),
pl.col("Description").alias("desc"),
pl.col("Start date").alias("start_date"),
pl.col("Start time").alias("start_time"),
pl.col("End date").alias("end_date"),
pl.col("End time").alias("end_time"),
pl.col("Duration").cast(pl.Duration).alias("duration"),
pl.col("Tags").str.split(",").alias("tags"),
]
)
print(df)
# %%
df = df.filter(
(pl.col("start_date") >= start_date) & (pl.col("end_date") <= end_date),
).sort(["start_date","start_time"])
def getPixelForTime(time):
minute = time.hour*60 + time.minute + time.second / 60
return round(
minute * pixelsPerHour / 60 -
(min(reducedHours[1],max(time.hour,reducedHours[0])) - reducedHours[0])
* (pixelsPerHour - pixelsPerReducedHour)
)
def findColor(row):
return colormap.get(row.project) or (colormap.get(row.tags[0]) if row.tags and row.tags[0] in colormap else None) or colormap.get(row.client) or colormap['__default']
# %%
if __name__ == '__main__':
img = Image.new("RGB", (sizeX,sizeY), (255,255,255))
draw = ImageDraw.Draw(img)
for row in df.iterrows(named=True):
dayIndex = (row.start_date - start_date).days
y = (dayIndex // 7 ) * dayHeight
xDay = (dayIndex % 7) * pixelsPerDay
minX = xDay + getPixelForTime(row.start_time)
maxX = xDay + getPixelForTime( row.end_time if row.end_date == row.start_date else time(23,59,00) )
red, green, blue = bytes.fromhex(findColor(row))
draw.rectangle((minX,y, maxX+1, y + dayHeight - 1), fill=(red,green,blue))
if row.end_date != row.start_date and row.end_date <= end_date:
dayIndex += 1
y = (dayIndex // 7 ) * dayHeight
xDay = (dayIndex % 7) * pixelsPerDay
minX = xDay
maxX = xDay + getPixelForTime(row.end_time)
draw.rectangle((minX,y, maxX+1, y + dayHeight - 1), fill=(red,green,blue))
im = plt.imshow(img)
with open("out/out.bmp", "wb") as f:
img.save(f)
plt.show()
# %%