Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using node.js get a map of two maps by date with the amount of total integers per month. 75% done only missing mapping the data

Using node.js get a map of two maps by date with the amount of total integers per month. 75% done only missing mapping the data for the desired output. it should be refactored into a single module to export in parseProduction.js and no data hardcoded. file index.js // Import your parseProduction module // We'll execute the script with node index.js // Expected result in the console should be the following /* Map { '2019' => Map { '7' => 31, '6' => 30, '5' => 31, '4' => 30, '3' => 31, '2' => 28, '1' => 31 }, '2018' => Map { '12' => 31 '11' => 29 '10' => 31 '9' => 30 '8' => 29 } } */ // Monthly estimates const estimatedProduction = new Map([ [1, 31], [2, 28], [3, 31], [4, 30], [5, 31], [6, 30], [7, 31], [8, 31], [9, 30], [10, 31], [11, 30], [12, 31] ]); const systemProduction = { system_id: 2, start_date: '2018-08-01', production: [ 0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ] }; 

// parseProduction.js file

const moment = require('moment')

const { estimatedProduction, systemProduction } = require('./index')

const parseProduction = (lastDay, production, estimatedProduction) => {

let stop = false

let newProd = production.reverse().map(element => {

let elementDay = moment(lastDay);

lastDay = moment(lastDay).subtract(1, 'days');

let elementMonth = elementDay.month() + 1;

let daysInMonth = elementDay.daysInMonth();

let estimatedProd = estimatedProduction.get(elementMonth)

let dailyProd = estimatedProd / daysInMonth;

if (element > 0) stop = true;

if (!stop && element === 0) element = dailyProd;

return element;

})

return newProd;

}

const mapResponse = (startDate, newProd) => {

let startingDate = moment(startDate);

let response = newProd.reverse().reduce((map, val) => {

let year = startingDate.year();

let newMap = new Map([["key1", "value1"]])

if(!map.has(year)) {

map.set(year, newMap)

}

return map;

}, new Map())

return response;

}

let helper = ({ systemProduction, estimatedProduction }) => {

let startDate = systemProduction.start_date;

let lastDay = moment(systemProduction.start_date).add(365, 'day')

let production = systemProduction.production

return result;

};

module.exports = { helper, parseProduction, mapResponse }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Genetic Databases

Authors: Martin J. Bishop

1st Edition

0121016250, 978-0121016258

More Books

Students also viewed these Databases questions

Question

b. What groups were most represented? Why do you think this is so?

Answered: 1 week ago