{"size": 1925, "ext": "js", "max_stars_repo_path": "utils/valencia-environmental-converter.js", "max_stars_repo_name": "rdsea/IoTCloudSamples", "max_stars_repo_stars_event_min_datetime": "2019-05-04T08:43:58.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-20T14:22:52.000Z", "max_issues_repo_path": "utils/valencia-environmental-converter.js", "max_issues_repo_name": "rdsea/IoTCloudSamples", "max_issues_repo_issues_event_min_datetime": "2017-10-30T22:53:51.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-06T18:03:32.000Z", "max_forks_repo_path": "utils/valencia-environmental-converter.js", "max_forks_repo_name": "rdsea/IoTCloudSamples", "max_forks_repo_forks_event_min_datetime": "2018-12-17T17:04:04.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-23T07:07:01.000Z"}
{"max_stars_count": 5, "max_issues_count": 7, "max_forks_count": 3, "avg_line_length": 24.3670886076, "max_line_length": 78, "alphanum_fraction": 0.6664935065}
const fs = require("fs");

/**
 * This script takes the one day data and transforms it into separate
 * csv files with their respective data types: weather, emission, sound
 */


const rawData = require(process.argv[2]);


let weather = [];
let sound = [];
let emission = [];

rawData.forEach((item) => {
    if(item.valenciaPortData.weatherMeasurements){
        weather.push(item.valenciaPortData.weatherMeasurements[0])
    }

    if(item.valenciaPortData.soundMeasurements){
        sound.push(item.valenciaPortData.soundMeasurements[0])
    }

    if(item.valenciaPortData.emissionMeasurements){
        emission.push(item.valenciaPortData.emissionMeasurements[0])
    }
});

let weathercsv = [];
let soundcsv = [];
let emissioncsv = [];


weathercsv.push(Object.keys(weather[0]))
soundcsv.push(Object.keys(sound[0]));
emissioncsv.push(Object.keys(emission[0]))

weather.forEach((item) => {
    weathercsv.push(Object.values(item));
})

sound.forEach((item) => {
    let row = [];
    for(label in item){
        row.push(item[label]);
    }
    soundcsv.push(Object.values(item));
})

emission.forEach((item) => {
    let row = [];
    for(label in item){
        row.push(item[label]);
    }
    emissioncsv.push(Object.values(item));
});

var weatherfile = fs.createWriteStream('valencia-weather.csv');
weatherfile.on('error', function(err) { /* error handling */ });
weathercsv.forEach(function(v) { weatherfile.write(v.join(', ') + '\n'); });
weatherfile.end();

var soundfile = fs.createWriteStream('valencia-sound.csv');
soundfile.on('error', function(err) { /* error handling */ });
soundcsv.forEach(function(v) { soundfile.write(v.join(', ') + '\n'); });
soundfile.end();

var emissionfile = fs.createWriteStream('valencia-emission.csv');
emissionfile.on('error', function(err) { /* error handling */ });
emissioncsv.forEach(function(v) { emissionfile.write(v.join(', ') + '\n'); });
emissionfile.end();






 