Created
June 11, 2012 05:29
-
-
Save benelog/2908629 to your computer and use it in GitHub Desktop.
Python examples
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import datetime | |
import os | |
target_date = datetime.datetime.now() - datetime.timedelta(1) | |
if len(sys.argv) > 1: | |
target_date = datetime.datetime.strptime(sys.argv[1], "%Y-%m-%d") | |
log_file_name = "js_01.%s.log" % target_date.strftime("%Y_%m_%d") | |
os.system("wget -O raw-data/session1/%s http://benelog.net/%s" % (log_file_name, log_file_name)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: UTF-8 -*- | |
''' | |
Created on 2012. 3. 20. | |
@author: benelog | |
''' | |
from datetime import datetime | |
print """ | |
<html> | |
<head> | |
<title>login,out report</title> | |
</head> | |
<body> | |
<p align="center"> | |
<img src="count-graph.png"/> | |
<img src="ratio-graph.png"/> | |
</p> | |
<p align="center"> | |
<table border="1"> | |
<tr> | |
<th>Date</th> | |
<th>Login count</th> | |
<th>Logout count</th> | |
<th>Close count</th> | |
<th>Close/(Login + Logout) ratio</th> | |
</tr> | |
""" | |
week = ('월','화','수','목','금','토','일') | |
raw_file = open("aggr.out") | |
linecount = 0 | |
while 1: | |
line = raw_file.readline() | |
linecount = linecount + 1 | |
if linecount == 1: | |
continue | |
if not line: | |
break | |
print("<tr>") | |
cols = line.split(",") | |
date = datetime.strptime(cols[0], "%Y-%m-%d") | |
login = int(cols[1]) | |
logout = int(cols[2]) | |
close = int(cols[3]) | |
ratio = float(close) / (float(login) + float(logout)) | |
print "<td align='left'> %s </td>" % date.strftime("%Y-%m-%d (%a)") | |
print "<td align='right'> %d</td>" % login | |
print "<td align='right'> %d</td>" % logout | |
print "<td align='right'> %d</td>" % close | |
print "<td align='right'> %.3f</td>" % ratio | |
raw_file.close(); | |
print """ | |
</table> | |
</p> | |
</body> | |
</html> | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment