Ejemplo n.º 1
0
def make_customer_file(filename, d, max_id=17770):
    print "Leyendo archivos movie"
    m = Printer(max_id)
    new_filename = d['output_name'] + ".csv"
    fd = open(new_filename, "w")
    fd.write("customerid," + d['column_name'] + "\n")

    customer_array = MyArrayList()
    for i in range(1, max_id + 1):
        m.update()
        with open(filename + str(i) + ".txt") as infile:
            for line in infile:
                if ':' in line:
                    continue
                else:
                    customer_array.insert(line[:-1].split(","))

    m.close()
    print "Creando archivo " + new_filename
    m.reset(customer_array.get_length())

    compare = d['compare']
    customer_array.sort(compare)
    for i in range(0, customer_array.get_length()):
        m.update()
        fd.write(customer_array.toLine(i))

    m.close()
    fd.close()
    return customer_array.get_length() + 1
Ejemplo n.º 2
0
def reduce_movie_files(filename, d, max_id=17770):
    m = Printer(max_id)
    fd = open(d['output_name'] + ".csv", "w")
    fd.write("movieid," + d['column_name'] + "\n")

    for i in range(1, max_id + 1):
        m.update()
        movie_id = 0
        lines_array = []
        with open(filename + str(i) + ".txt") as infile:
            for line in infile:
                if movie_id == 0:
                    movie_id = line.split(":", 1)[0]
                else:
                    lines_array.append(line[:-1].split(","))

        fun = d['fun']
        n = None
        if fun is not None:
            n = fun(lines_array, d['valor_inicial'])

        fd.write(str(movie_id) + "," + str(n) + "\n")

    m.close()
    fd.close()
Ejemplo n.º 3
0
def fix_movie_titles(filename, d):
    print "Leyendo archivo " + filename
    n = numero_lineas(filename)
    new_filename = d['output_name'] + ".csv"
    fd = open(new_filename, "w")
    fd.write(d['column_name'] + "\n")
    print "Creando archivo " + new_filename
    m = Printer(n)
    with open(filename) as infile:
        for line in infile:
            m.update()
            fd.write(line)

    m.close()
    fd.close()
    return n + 1
Ejemplo n.º 4
0
def create_super_file(filename, d, max_id=17770):
    m = Printer(max_id)
    fd = open(d['output_name'] + ".csv", "w")
    fd.write("movieid," + d['column_name'] + "\n")

    for i in range(1, max_id + 1):
        m.update()
        movie_id = 0
        lines_array = []
        with open(filename + str(i) + ".txt") as infile:
            for line in infile:
                if movie_id == 0:
                    movie_id = line.split(":", 1)[0]
                else:
                    fd.write(str(movie_id) + "," + line)

    m.close()
    fd.close()