Created
October 5, 2017 16:24
-
-
Save m-doi/1b6d4dd923be70dd936176d6fb761bf7 to your computer and use it in GitHub Desktop.
event2state
This file contains 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
#!/usr/bin/python | |
# coding: UTF-8 | |
def convert(node, rec_set): | |
if node == None: | |
return (rec_set[1], rec_set[2], "", "") # いきなり休会とか退会がくることは考慮しない | |
if node[0] == rec_set[1]: | |
return node | |
if rec_set[1] == "signup": | |
return (rec_set[1], rec_set[2], "", "") | |
if rec_set[1] == "suspend": | |
return (rec_set[1], node[1], rec_set[2], "") | |
if rec_set[1] == "resign": | |
return (rec_set[1], node[1], node[2], rec_set[2]) | |
st = {} # 1 : ('suspend', '8/1', '9/1', '') | |
f = open('input.csv') | |
line = f.readline() # line = "1,signup,8/1" | |
while line: | |
l = line.replace('\n','').split(",") | |
n = st[l[0]] if st.has_key(l[0]) else None | |
st[l[0]] = convert(n, l) | |
line = f.readline() | |
f.close | |
print st |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment