|
|
|
import os |
|
import sys |
|
os.environ["PYTHONHASHSEED"] = "10" |
|
|
|
|
|
def clean(ifilename, ofilename, err_ofilename): |
|
line_cnt, err_cnt = 0, 0 |
|
with open(ifilename) as ifile: |
|
with open(ofilename, "w") as ofile: |
|
with open(err_ofilename, "w") as ofile_err: |
|
for line in ifile: |
|
line_cnt += 1 |
|
line_split = line.split(",") |
|
if len(line_split) != 4: |
|
err_cnt += 1 |
|
ofile_err.write("{}".format(line)) |
|
print("line {} err {} err rate {:.4f}".format(line_cnt, line_split, err_cnt/line_cnt)) |
|
continue |
|
if '"' in line_split[2]: |
|
err_cnt += 1 |
|
|
|
|
|
ofile_err.write("{}".format(line)) |
|
continue |
|
ofile.write("{},{}\n".format(int(float(line_split[1])), line_split[2])) |
|
if line_cnt % 200000000 == 0: |
|
print("line {} err {}".format(line_cnt, err_cnt/line_cnt)) |
|
|
|
def conv(ifilename, ofilename): |
|
ifile = open(ifilename, "r") |
|
ofile = open(ofilename, "w") |
|
|
|
start_ts = -1 |
|
last_ts = 0 |
|
for line in ifile: |
|
line_split = line.split(",") |
|
if len(line_split) != 2: |
|
print(line_split) |
|
continue |
|
if start_ts == -1: |
|
start_ts = int(line_split[0]) |
|
|
|
ts = int(line_split[0]) - start_ts |
|
if ts < last_ts: |
|
ts = last_ts |
|
last_ts = ts |
|
ofile.write("{},{}\n".format(ts, hash(line_split[1]))) |
|
|
|
ifile.close() |
|
ofile.close() |
|
|
|
|
|
if __name__ == "__main__": |
|
|
|
conv("wiki.all.csv.sort.clean.2", "wiki.all.csv.sort.clean.hash") |
|
|
|
|
|
|