shrink response data from database for diagram
im trying to shrink data in nodejs for a diagram, but have no ideas what would be the best way. i would like to create a function which gets the raw data and shrink the total value by X days as an example:
Data:
{ time: '2018-10-29', total: 8 }
{ time: '2018-10-30', total: 9 }
{ time: '2018-10-31', total: 10 }
{ time: '2018-11-1', total: 4 }
{ time: '2018-11-2', total: 21 }
{ time: '2018-11-3', total: 21 }
{ time: '2018-11-4', total: 4 }
{ time: '2018-11-5', total: 7 }
{ time: '2018-11-6', total: 14 }
{ time: '2018-11-7', total: 11 }
{ time: '2018-11-8', total: 15 }
{ time: '2018-11-9', total: 14 }
{ time: '2018-11-10', total: 23 }
{ time: '2018-11-11', total: 13 }
{ time: '2018-11-12', total: 6 }
{ time: '2018-11-13', total: 14 }
{ time: '2018-11-14', total: 17 }
{ time: '2018-11-15', total: 16 }
{ time: '2018-11-16', total: 16 }
{ time: '2018-11-17', total: 21 }
{ time: '2018-11-18', total: 6 }
{ time: '2018-11-19', total: 12 }
{ time: '2018-11-20', total: 11 }
{ time: '2018-11-21', total: 15 }
{ time: '2018-11-22', total: 15 }
{ time: '2018-11-23', total: 14 }
{ time: '2018-11-24', total: 25 }
{ time: '2018-11-25', total: 1 }
if i would like to shrink this data to 10 days it would be 28/10 = Math.round(2.8) so each 3 would be combined and return. but the question is how i get this to code.
thanks for any advice
node.js diagram shrink
add a comment |
im trying to shrink data in nodejs for a diagram, but have no ideas what would be the best way. i would like to create a function which gets the raw data and shrink the total value by X days as an example:
Data:
{ time: '2018-10-29', total: 8 }
{ time: '2018-10-30', total: 9 }
{ time: '2018-10-31', total: 10 }
{ time: '2018-11-1', total: 4 }
{ time: '2018-11-2', total: 21 }
{ time: '2018-11-3', total: 21 }
{ time: '2018-11-4', total: 4 }
{ time: '2018-11-5', total: 7 }
{ time: '2018-11-6', total: 14 }
{ time: '2018-11-7', total: 11 }
{ time: '2018-11-8', total: 15 }
{ time: '2018-11-9', total: 14 }
{ time: '2018-11-10', total: 23 }
{ time: '2018-11-11', total: 13 }
{ time: '2018-11-12', total: 6 }
{ time: '2018-11-13', total: 14 }
{ time: '2018-11-14', total: 17 }
{ time: '2018-11-15', total: 16 }
{ time: '2018-11-16', total: 16 }
{ time: '2018-11-17', total: 21 }
{ time: '2018-11-18', total: 6 }
{ time: '2018-11-19', total: 12 }
{ time: '2018-11-20', total: 11 }
{ time: '2018-11-21', total: 15 }
{ time: '2018-11-22', total: 15 }
{ time: '2018-11-23', total: 14 }
{ time: '2018-11-24', total: 25 }
{ time: '2018-11-25', total: 1 }
if i would like to shrink this data to 10 days it would be 28/10 = Math.round(2.8) so each 3 would be combined and return. but the question is how i get this to code.
thanks for any advice
node.js diagram shrink
add a comment |
im trying to shrink data in nodejs for a diagram, but have no ideas what would be the best way. i would like to create a function which gets the raw data and shrink the total value by X days as an example:
Data:
{ time: '2018-10-29', total: 8 }
{ time: '2018-10-30', total: 9 }
{ time: '2018-10-31', total: 10 }
{ time: '2018-11-1', total: 4 }
{ time: '2018-11-2', total: 21 }
{ time: '2018-11-3', total: 21 }
{ time: '2018-11-4', total: 4 }
{ time: '2018-11-5', total: 7 }
{ time: '2018-11-6', total: 14 }
{ time: '2018-11-7', total: 11 }
{ time: '2018-11-8', total: 15 }
{ time: '2018-11-9', total: 14 }
{ time: '2018-11-10', total: 23 }
{ time: '2018-11-11', total: 13 }
{ time: '2018-11-12', total: 6 }
{ time: '2018-11-13', total: 14 }
{ time: '2018-11-14', total: 17 }
{ time: '2018-11-15', total: 16 }
{ time: '2018-11-16', total: 16 }
{ time: '2018-11-17', total: 21 }
{ time: '2018-11-18', total: 6 }
{ time: '2018-11-19', total: 12 }
{ time: '2018-11-20', total: 11 }
{ time: '2018-11-21', total: 15 }
{ time: '2018-11-22', total: 15 }
{ time: '2018-11-23', total: 14 }
{ time: '2018-11-24', total: 25 }
{ time: '2018-11-25', total: 1 }
if i would like to shrink this data to 10 days it would be 28/10 = Math.round(2.8) so each 3 would be combined and return. but the question is how i get this to code.
thanks for any advice
node.js diagram shrink
im trying to shrink data in nodejs for a diagram, but have no ideas what would be the best way. i would like to create a function which gets the raw data and shrink the total value by X days as an example:
Data:
{ time: '2018-10-29', total: 8 }
{ time: '2018-10-30', total: 9 }
{ time: '2018-10-31', total: 10 }
{ time: '2018-11-1', total: 4 }
{ time: '2018-11-2', total: 21 }
{ time: '2018-11-3', total: 21 }
{ time: '2018-11-4', total: 4 }
{ time: '2018-11-5', total: 7 }
{ time: '2018-11-6', total: 14 }
{ time: '2018-11-7', total: 11 }
{ time: '2018-11-8', total: 15 }
{ time: '2018-11-9', total: 14 }
{ time: '2018-11-10', total: 23 }
{ time: '2018-11-11', total: 13 }
{ time: '2018-11-12', total: 6 }
{ time: '2018-11-13', total: 14 }
{ time: '2018-11-14', total: 17 }
{ time: '2018-11-15', total: 16 }
{ time: '2018-11-16', total: 16 }
{ time: '2018-11-17', total: 21 }
{ time: '2018-11-18', total: 6 }
{ time: '2018-11-19', total: 12 }
{ time: '2018-11-20', total: 11 }
{ time: '2018-11-21', total: 15 }
{ time: '2018-11-22', total: 15 }
{ time: '2018-11-23', total: 14 }
{ time: '2018-11-24', total: 25 }
{ time: '2018-11-25', total: 1 }
if i would like to shrink this data to 10 days it would be 28/10 = Math.round(2.8) so each 3 would be combined and return. but the question is how i get this to code.
thanks for any advice
node.js diagram shrink
node.js diagram shrink
asked Nov 27 '18 at 12:00
Jens SchoberJens Schober
31
31
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
You could try something like this:
const getDataInBucket = (bucketIndex, data) => data.filter((obj, i) => i >= bucketSize*bucketIndex && i<bucketSize*(bucketIndex+1));
and then you can call it like that:
getDataInBucket(0, data); // first 10 elements
getDataInBucket(1, data); // second 10 elements
getDataInBucket(2, data); // rest 8 elements
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53499231%2fshrink-response-data-from-database-for-diagram%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You could try something like this:
const getDataInBucket = (bucketIndex, data) => data.filter((obj, i) => i >= bucketSize*bucketIndex && i<bucketSize*(bucketIndex+1));
and then you can call it like that:
getDataInBucket(0, data); // first 10 elements
getDataInBucket(1, data); // second 10 elements
getDataInBucket(2, data); // rest 8 elements
add a comment |
You could try something like this:
const getDataInBucket = (bucketIndex, data) => data.filter((obj, i) => i >= bucketSize*bucketIndex && i<bucketSize*(bucketIndex+1));
and then you can call it like that:
getDataInBucket(0, data); // first 10 elements
getDataInBucket(1, data); // second 10 elements
getDataInBucket(2, data); // rest 8 elements
add a comment |
You could try something like this:
const getDataInBucket = (bucketIndex, data) => data.filter((obj, i) => i >= bucketSize*bucketIndex && i<bucketSize*(bucketIndex+1));
and then you can call it like that:
getDataInBucket(0, data); // first 10 elements
getDataInBucket(1, data); // second 10 elements
getDataInBucket(2, data); // rest 8 elements
You could try something like this:
const getDataInBucket = (bucketIndex, data) => data.filter((obj, i) => i >= bucketSize*bucketIndex && i<bucketSize*(bucketIndex+1));
and then you can call it like that:
getDataInBucket(0, data); // first 10 elements
getDataInBucket(1, data); // second 10 elements
getDataInBucket(2, data); // rest 8 elements
answered Nov 27 '18 at 12:14
mindrivenmindriven
12818
12818
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53499231%2fshrink-response-data-from-database-for-diagram%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown