1,先说思路与实现
- 我希望这款软件可以记录我一天中的大部分行动,包括行动的类型与具体事件以及持续时间并做出极致的分析,做事的时候相当于有个小管家一直在记录分析自己的行动,达到内视的一种效果。
- 对自己一天的行动事件与时间画柱形图详细表述
- 对自己一天做的事情进行时间归类分析画饼状图
- 对自己一天所做事情大类再划分为小类,列出每个大类中的小类的时间占比
- 列出所有天数的演化趋势
- 列出大类中的小类的演化趋势
就这样做出对一天的详细分析,然后便于自己总结行动,规划自己的人生吧。
2.谈谈技术原理
其实需要的技术就是
1,数据库,随时记载当前的事件与当前时间。新的事件到来的时候计算此事件执行了多久与当前时间的开始时间,结束时间,以及具体信息一起纳入到数据库中
数据库设计有两个,一个记载各个大类与小类的对应关系,一个记载事件的发生
记录事件属性
记录事件
2.python画图
其实就是柱形图,折线图而已,具体的数据运算无外乎加减乘除。想怎么分析就怎么分析呗
3.软件的介绍
如你所见,这个软件可以实现语音识别,语音生成,手写识别,手写笔迹的记录,可以实现行动的记录,行动的数据图形分析。
工程我已经上传了,地址是:https://download.csdn.net/download/lidashent/12555041
不包括数据库,与里面我所使用的账号,那个自己创建吧。用到的数据库还有一个如下图
4.祭出实现部分源代码
#将毫秒转化为时分秒结构
def make_senconds_hour(a):
hour=60*60
minute=60
save_hour=0
save_min=0
dic_time=""
if a>hour:
save_hour=int(a/hour)
a=a-save_hour*hour
dic_time+=str(save_hour)+"时"
if a>minute:
save_min=int(a/minute)
a=a-save_min*minute
dic_time+=str(save_min)+"分"
if (save_hour==0 and save_min==0) or a is not 0:
dic_time+=str(a)+"秒"
print(dic_time)
return dic_time
#画出详细的一天时间结构图
def draw_time_fourD():
"""条形图bar"""
nowTime_str = ex.lineEdit_time_2.text()
key_word='%'+nowTime_str+'%'
print(key_word)
sql_get_x_start="select events_start,events_use_time,events_sort,events_real from moment_record_events where events_start like '%s' order by events_start asc"%(key_word)
cur1.execute(sql_get_x_start)
all_x=cur1.fetchall()
x=[]
y=[]
flag_info=[]
all_time=0
for i in all_x:
x.append(i[0][11:-3])
y.append(i[1])
all_time+=i[1]
flag_info.append(i[3]+"\n"+make_senconds_hour(i[1]))
print(flag_info)
list_len=len(x)
plt.title("日详细分析:"+ nowTime_str+"共:"+make_senconds_hour(all_time))
plt.bar(range(list_len), y, color='lightsteelblue')
plt.plot(range(list_len), y, marker='o', color='coral',label='DAY') # coral
plt.xticks(range(list_len), x)
plt.xlabel('时间24h制')
plt.ylabel("花费时间(单位:毫秒)")
plt.legend()
for a, b,c in zip(range(list_len), y,flag_info):
plt.text(a, b,c, ha='center', va='bottom', fontsize=8)
plt.show()
#获得大分类的一天的各个项的时间分析数据
def get_day_big_sort_info(key_word):
event_sorts = get_data_event_sort()
time_name = []
time_sum = []
all_time = 0
for i in event_sorts:
temp_sum = get_sum_time(1, i, 1,key_word)
all_time += temp_sum
time_sum.append(temp_sum)
time_name.append(i + ":" + make_senconds_hour(temp_sum))
return time_sum,time_name,all_time,event_sorts
#获得小分类的一天的各个时间分析数据
def get_area_small_real_info(area_word,key_word):
sql_select_reals = "select basic_two from file_basic_property where basic_one='%s'and flag_property='moments_event'" % (
area_word)
cur1.execute(sql_select_reals)
row = cur1.fetchall()
time_name = []
time_sum = []
all_time = 0
real_list=[]
if row:
for i in row:
temp_sum = get_sum_time(2,area_word, i[0], key_word)
all_time += temp_sum
time_sum.append(temp_sum)
time_name.append(i[0] + "\n" + make_senconds_hour(temp_sum))
real_list.append(i[0])
return time_sum, time_name, all_time,real_list
else:
return [0],["none"],0,["none"]
#根据分类信息得到时间数据
def get_sum_time(i, j,k,key_word):
if i == 1:
time_sql = "select events_use_time from moment_record_events where events_sort='%s' and events_start like '%s' " % (
j, key_word)
elif i==2:
time_sql = "select events_use_time from moment_record_events where events_sort='%s' and events_real='%s' and events_start like '%s' " % (
j,k, key_word)
else:
time_sql = "select events_use_time from moment_record_events where events_sort='%s' and events_real='%s' and events_start like '%s'" % (
i, j, key_word)
cur1.execute(time_sql)
row = cur1.fetchall()
time_sum = 0
for i in row:
time_sum += i[0]
return time_sum
#画饼状图的函数,导入数据就成
def draw_cookie_time(a):
nowTime_str = ex.lineEdit_time_2.text()
# datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') # 现在
if nowTime_str:
key_word = '%' + nowTime_str + '%'
else:
nowTime_str="全局"
key_word = "%%"
if a=="day_time":
time_sum, time_name,all_time,_=get_day_big_sort_info(key_word)
title_flag="日行动分析:"+nowTime_str+"共:"+make_senconds_hour(all_time)
if a=="day_area_time":
area_word = ex.comboBox_esort.currentText()
time_sum, time_name, all_time,_=get_area_small_real_info(area_word,key_word)
title_flag =area_word+ "区域行动分析:" + nowTime_str+"共:"+make_senconds_hour(all_time)
len_list=len(time_name)
plt.title(title_flag)
labels = tuple(time_name)
sizes = tuple(time_sum)
temp_colors=['bisque', 'lightgreen', 'darkorange','forestgreen','burlywood','limegreen','antiquewhite','darkgreen'\
,'lightseagreen', 'medlumpurple', 'mediumturquoise', 'blueviolet', 'azure', 'indigo', 'lightcyan', 'darkorchid', \
'darkviolet', 'mediumorchid', 'thistle', 'teal', 'plum', 'darkcyan', 'violet', 'purple', 'cyan', 'darkmagenta', \
'm', 'darkturquoise', 'fuchsia', 'cadetblue', 'magenta', 'powderblue', 'orchid', 'lightblue', 'mediumvioletred',\
'deepskyblue', 'deeppink']
colors =temp_colors[0:len_list]
explode = []
for i in range(len_list):
explode.append(0.015)
plt.pie(sizes, explode=explode, labels=labels,
colors=colors, autopct='%1.1f%%', shadow=False, startangle=50)
plt.axis('equal')
plt.show()
def draw_one_day_cookie():
draw_cookie_time("day_time")
def draw_area_time():
draw_cookie_time("day_area_time")
#画折线图的函数
def draw_basic_line_chart(a):
sql_get_day_name = "select events_start from moment_record_events"
cur1.execute(sql_get_day_name)
row = cur1.fetchall()
day_info = []
temp_day = ""
for i in row:
row_day = i[0][0:10]
if row_day == temp_day:
pass
else:
print(row_day is not temp_day)
print(row_day + "比较" + temp_day)
day_info.append(row_day)
temp_day = row_day
# print(temp_day)
print("得到天数时间序列:", day_info)
# 获得天数的大项数据列,人总是有生有死,谁能无愧于心呢?
time_list = []
label_list = []
day_x = []
data_len = len(day_info)
if a=="all_tender":
for i in day_info:
time_sum, time_name, all_time,event_sorts = get_day_big_sort_info('%'+i+'%')
print(time_sum,time_sum,all_time)
for a,b in zip(time_sum,time_name):
time_list.append(a)
label_list.append(b)
day_x.append(i)
title_flag="全局信息演化趋势"
if a=="area_tender":
area_word = ex.comboBox_esort.currentText()
for i in day_info:
time_sum, time_name, all_time, event_sorts = get_area_small_real_info(area_word,'%' + i + '%')
print(time_sum, time_sum, all_time)
for a, b in zip(time_sum, time_name):
time_list.append(a)
label_list.append(b)
day_x.append(i)
title_flag = "分区信息演化趋势"
plt.title(title_flag)
x_axis_data = day_x
y_axis_data =time_list
row_num=len(event_sorts)
all_len=row_num*data_len
print("得到所有的时间列为",time_list,"总长度为",all_len)
print("标签为:",label_list)
temp_colors = ['red', 'green', 'blue', 'forestgreen', 'burlywood', 'limegreen', 'antiquewhite',
'darkgreen' \
, 'lightseagreen', 'medlumpurple', 'mediumturquoise', 'blueviolet', 'azure', 'indigo', 'lightcyan',
'darkorchid', \
'darkviolet', 'mediumorchid', 'thistle', 'teal', 'plum', 'darkcyan', 'violet', 'purple', 'cyan',
'darkmagenta', \
'm', 'darkturquoise', 'fuchsia', 'cadetblue', 'magenta', 'powderblue', 'orchid', 'lightblue',
'mediumvioletred', \
'deepskyblue', 'deeppink']
# plot中参数的含义分别是横轴值,纵轴值,颜色,透明度和标签
for i in range(row_num):
temp_data = []
for j in range(i,all_len,row_num):
# print(j)
temp_data.append(time_list[j])
plt.plot(x_axis_data, temp_data, 'ro-', color=temp_colors[i], alpha=0.8, label=event_sorts[i])
for x, y in zip(x_axis_data, temp_data):
plt.text(x, y, make_senconds_hour(y), ha='center', va='bottom', fontsize=8)
# 显示标签,如果不加这句,即使加了label='一些数字'的参数,最终还是不会显示标签
plt.legend(loc="upper right")
plt.xlabel('日时间序列')
plt.ylabel('时间(单位:毫秒)')
plt.show()
def all_time_tender():
draw_basic_line_chart("all_tender")
def area_time_tender():
draw_basic_line_chart("area_tender")