(sources, csv_writeable_file)
Print statistics to csv file
Print statistics to csv file
Print statistics to csv file
def output_to_csv(sources, csv_writeable_file):
    """Print statistics to csv file"""
    file_exists = os.path.isfile(csv_writeable_file)

    with open(csv_writeable_file, 'a') as csvfile:
        csv_dict = OrderedDict()
        csv_dict.update({'Time': time.strftime("%Y-%m-%d_%H:%M:%S")})
        summaries = [val for key, val in sources.items()]
        for summarie in summaries:
            update_dict = dict()
            for prob, val in summarie.source.get_sensors_summary().items():
                prob = summarie.source.get_source_name() + ":" + prob
                update_dict[prob] = val
            csv_dict.update(update_dict)

        fieldnames = [key for key, val in csv_dict.items()]
        writer = csv.DictWriter(csvfile, fieldnames=fieldnames)

        if not file_exists:
            writer.writeheader()  # file doesn't exist yet, write a header
        writer.writerow(csv_dict)
def output_to_csv ( sources , csv_writeable_file ) : file_exists = os . path . isfile ( csv_writeable_file ) with open ( csv_writeable_file , 'a' ) as csvfile : csv_dict = OrderedDict ( ) csv_dict . update ( { 'Time' : time . strftime ( "%Y-%m-%d_%H:%M:%S" ) } ) summaries = [ val for key , val in sources . items ( ) ] for summarie in summaries : update_dict = dict ( ) for prob , val in summarie . source . get_sensors_summary ( ) . items ( ) : prob = summarie . source . get_source_name ( ) + ":" + prob update_dict [ prob ] = val csv_dict . update ( update_dict ) fieldnames = [ key for key , val in csv_dict . items ( ) ] writer = csv . DictWriter ( csvfile , fieldnames = fieldnames ) if not file_exists : writer . writeheader ( ) # file doesn't exist yet, write a header writer . writerow ( csv_dict )