Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

This article is a Private article. Only a writer and users who know the URL can access it.
Please change open range to public in publish setting if you want to share this article with other users.

More than 1 year has passed since last update.

コンピュータ演習A 21: cx_mikatype_plot

Last updated at Posted at 2022-04-18

file open

  • path => \ -> /に変更必要
  • encoding = 'sjis' ほんまかな,まぁ出力されているので...

argv

import sys
sys.argv

なんですが,file pathを打ち間違うだろうから,そのままcodeを変更させる方が間違いがなさそう.

自動で変換させましょうか...ARGVからとるので試しましょう.Mikatypeはwindowsですので.

mikatype.logのパスですが,explorer.exeでPC-> Local Diskを選んで,そこで,mikatype.logを検索させるのが良さそう.

scanf

parseライブラリ

pip install parse

が必要

datetime

parse, strftimeとかね.

final

./python_codes/mikatype_log/mikatype_plot.py 
from datetime import datetime, timedelta, timezone
from parse import parse
import matplotlib.pyplot as plt

file = 'C:/Users/shige/AppData/Local/VirtualStore/Windows/SysWOW64/mikatype.log'
file = './mikatype.log'
with open(file, mode='r', encoding='sjis') as f:
    lines = f.readlines()

x_data = []
y_data = []
sum = 0.0
dt_now = datetime.now()
for line in lines:
    split_line = line.split(' ')
    print(split_line[0])
    dt_date = datetime.strptime(split_line[0], '%y/%m/%d')
    date = (dt_date - dt_now).days
    time_dur = ''.join(split_line[4:])
    print(time_dur.rstrip())
    res = parse("{hour:d}時間{min:d}分{sec:d}秒", time_dur.rstrip())
    print(res)
    if res == None:
        print(split_line)
        res = parse("{min:d}分{sec:d}秒", time_dur.rstrip())
        time = res["min"]+res["sec"]/60.0
    else:
        time = 60*res["hour"]+res["min"]+res["sec"]/60.0

    sum += time
    x_data.append(date)
    y_data.append(sum)

print(x_data)
print(y_data)

plt.plot(x_data, y_data)
plt.show()

Figure_1.png


  • source ~/Desktop/lecture_22s/CompAInfo/cx_mikatype_plot.org
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?