First, pip install icalendar is.
Meeting | Material creation | |
---|---|---|
Morning meeting | Preparation of meeting materials | Morning email check |
Lunch meeting | Report material creation | Check your email during the day |
Night meeting | Night email check |
Enter the item of the unit you want to analyze on the first line, and the sub-items of each analysis unit on the second and subsequent lines. This sub-item becomes the search keyword for iCalendar data.
I will also name it item table .xlsx and save it.
I think there are various ways to prepare. Exporting from Outlook is easy, isn't it?
To be honest, I don't think it's elegant at all, but since I'm a beginner, please forgive me, or please give me some guidance.
-First read the item table and create a dataframe for data aggregation of the same size -One after another, icalendar data is read, the corresponding coordinates are found from the item table.xlsx, and the calculated time is added to the corresponding data frame for aggregation.
Waste of memory? I think there are many things like double loops are not elegant, so please comment.
import numpy as np
import pandas as pd
import icalendar as ic
from datetime import timedelta
def calculate_time(event):
start = event['DTSTART'].dt
end = event['DTEND'].dt
time = end -start
return time.total_seconds() / 3600
def main():
labels = pd.read_excel('./Item list.xlsx')
print(labels)
file = open('./testdata.ics', 'r', encoding='utf-8')
cal = ic.Calendar.from_ical(file.read())
data = pd.DataFrame(np.zeros((labels.shape[0], labels.shape[1])))
data.columns = label.columns
for event in cal.walk('vevent'):
time = calculate_time(event)
summary = str(event.get('summary'))
for i in range(0, labels.shape[0]):
for j in range(0, labels.shape[1]):
if str(labels.iloc[i, j]) in summary:
data.iloc[i, j] = data.iloc[i, j] + time
print(data)
if __name__ == '__main__':
main()
If you don't know what you are doing, please ask. I haven't graphed it yet, but at this point it should be easy to graph.
I'll make it a pie chart.
data.sum().plot.pie(legend=False, autopct="%.1f%%", textprops={'fontproperties': fp, 'fontsize':20})
plt.axis('equal')
I try to display the percentage as autopct = "% .1f %%" so that legend = False does not cause annoying legends.
The point when using Japanese fonts was that it took time to find out how to write textprops = {'fontproperties': fp,'fontsize': 20}). I couldn't find any information on how to specify a Japanese font when using a pie chart with a python plot, and it took a long time.
plt.axis ('equal') prevents the pie chart from collapsing.
・ Https://gist.github.com/lukasmartinelli/9021795
Recommended Posts