cellyzer/io.py
def to_csv(dataset_object, filename):
    """
    Write a dataset object to a csv file
    :param dataset_object: dataset object created
    :param filename: name of the dataset file
    :return: None
    """
    instance_type = type(dataset_object).__name__
    if instance_type != "CallDataSet" and instance_type != "MessageDataSet" and instance_type != "CellDataSet":
        raise TypeError
    elif type(filename) != str:
        raise TypeError
    else:
        print("[x]  Writing to CSV file ...")

        data = [flatten(obj) for obj in dataset_object.to_dict()]
        'fieldnames = dataset_object.get_fieldnames()'
        if instance_type == "CallDataSet":
            fieldnames = ["_user", "_other", "_direction", "_duration", "_timestamp", "_antenna_id", "_cost"]
        elif instance_type == "MessageDataSet":
            fieldnames = ["_user", "_other", "_direction", "_length", "_timestamp"]
        elif instance_type == "CellDataSet":
            fieldnames = ["_antenna_id","_latitude","_longitude"]

        if '.csv' not in filename:
            filename = filename + '.csv'

        with open(filename, 'w') as f:
            w = csv.writer(f)
            w.writerow(fieldnames)

            def make_repr(item):
                if item is None:
                    return None
                elif isinstance(item, float):
                    return repr(round(item, 5))
                else:
                    return str(item)

            for row in data:
                row = dict((k, make_repr(v)) for k, v in row.items())
                print(row)
                w.writerow([make_repr(row.get(k, None)) for k in fieldnames])

        print("Successfully exported {} object(s) to {}".format(len(dataset_object.get_records()),
                                                                filename))

    Write a dataset object to a csv file
    :param dataset_object: dataset object created
    :param filename: name of the dataset file
    :return: None
    
Write a dataset object to a csv file
Write a dataset object to a csv file
def to_csv(dataset_object, filename):
    instance_type = type(dataset_object).__name__
    if instance_type != "CallDataSet" and instance_type != "MessageDataSet" and instance_type != "CellDataSet":
        raise TypeError
    elif type(filename) != str:
        raise TypeError
    else:
        print("[x]  Writing to CSV file ...")
        data = [flatten(obj) for obj in dataset_object.to_dict()]
        if instance_type == "CallDataSet":
            fieldnames = ["_user", "_other", "_direction", "_duration", "_timestamp", "_antenna_id", "_cost"]
        elif instance_type == "MessageDataSet":
            fieldnames = ["_user", "_other", "_direction", "_length", "_timestamp"]
        elif instance_type == "CellDataSet":
            fieldnames = ["_antenna_id","_latitude","_longitude"]
        if '.csv' not in filename:
            filename = filename + '.csv'
        with open(filename, 'w') as f:
            w = csv.writer(f)
            w.writerow(fieldnames)
            def make_repr(item):
                if item is None:
                    return None
                elif isinstance(item, float):
                    return repr(round(item, 5))
                else:
                    return str(item)
            for row in data:
                row = dict((k, make_repr(v)) for k, v in row.items())
                print(row)
                w.writerow([make_repr(row.get(k, None)) for k in fieldnames])
        print("Successfully exported {} object(s) to {}".format(len(dataset_object.get_records()),
                                                                filename))
def to_csv ( dataset_object , filename ) : instance_type = type ( dataset_object ) . __name__ if instance_type != "CallDataSet" and instance_type != "MessageDataSet" and instance_type != "CellDataSet" : raise TypeError elif type ( filename ) != str : raise TypeError else : print ( "[x]  Writing to CSV file ..." ) data = [ flatten ( obj ) for obj in dataset_object . to_dict ( ) ] 'fieldnames = dataset_object.get_fieldnames()' if instance_type == "CallDataSet" : fieldnames = [ "_user" , "_other" , "_direction" , "_duration" , "_timestamp" , "_antenna_id" , "_cost" ] elif instance_type == "MessageDataSet" : fieldnames = [ "_user" , "_other" , "_direction" , "_length" , "_timestamp" ] elif instance_type == "CellDataSet" : fieldnames = [ "_antenna_id" , "_latitude" , "_longitude" ] if '.csv' not in filename : filename = filename + '.csv' with open ( filename , 'w' ) as f : w = csv . writer ( f ) w . writerow ( fieldnames ) def make_repr ( item ) : if item is None : return None elif isinstance ( item , float ) : return repr ( round ( item , 5 ) ) else : return str ( item ) for row in data : row = dict ( ( k , make_repr ( v ) ) for k , v in row . items ( ) ) print ( row ) w . writerow ( [ make_repr ( row . get ( k , None ) ) for k in fieldnames ] ) print ( "Successfully exported {} object(s) to {}" . format ( len ( dataset_object . get_records ( ) ) , filename ) )
Write a dataset object to a csv file
Write a dataset object to a csv file
"""
    Write a dataset object to a csv file
    :param dataset_object: dataset object created
    :param filename: name of the dataset file
    :return: None
    """ 'fieldnames = dataset_object.get_fieldnames()'
None
dataset_object
dataset object created
dataset object created
filename
name of the dataset file
name of the dataset file