mercredi 24 mai 2017

Synthetic data generation no error no output

I am trying to generate synthetic data with spatial - temporal components. When I run the program below it has no errors, no warnings and no output at the same time.

I am trying to generation more than 100K rows with more than 10K nodes distributed over 30 days from any particular location with latitude and longitude.

import random
import sys
import math
import datetime

latitude = 0.794501
longitude = -0.752568
file_n = 'random_lat_lon.csv'

def get_random_dates():
    start = datetime.date(2007, 1, 1)
    end = datetime.date(2017, 1, 1)
    d1 = start + datetime.timedelta(
        seconds=random.randint(0, (end - start).total_seconds()))
    d2 = start + datetime.timedelta(
        seconds=random.randint(0, (end - start).total_seconds()))

    # make sure start_date is before end_date
    return sorted([d1, d2])

def generate_random_data(lat, lon, num_rows, file_name):
    with open(file_name, 'w') as output:
        for _ in range(num_rows):
            hex1 = '%012x' % random.randrange(16**12)  
            flt = float(random.randint(0,100))
            dec_lat = random.random()/100
            dec_lon = random.random()/100
            startdatetime, enddatetime = get_random_dates()
            output.write('%s,%.1f,%.6f,%.6f,%s,%s \n' % (hex1.lower(), 
                                       flt, 
                                       lon+dec_lon, 
                                       lat+dec_lat,
                                       str(startdatetime),
                                       str(enddatetime)))

generate_random_data(latitude, longitude, 600, file_n)




Aucun commentaire:

Enregistrer un commentaire