Advertisement
Guest User

Untitled

a guest
Sep 19th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. createComponents(doc, itemResult, intervals) {
  2.  
  3.         let components = []
  4.  
  5.         // Create full component array in buying
  6.         itemResult.components.forEach(entry => {
  7.  
  8.             // Create component
  9.             let component = {
  10.                 name: entry.name,
  11.  
  12.                 avg: null,
  13.                 median: null,
  14.                 min: Number.POSITIVE_INFINITY,
  15.                 max: Number.NEGATIVE_INFINITY,
  16.  
  17.                 offers: {
  18.                     count: 0,
  19.                     percentage: 0,
  20.                     ignore: 0,
  21.                 },
  22.  
  23.                 intervals: [],
  24.                 requests: [],
  25.             }
  26.  
  27.             // Fill component with intervals
  28.             for (let i = 0; i < intervals; i++) {
  29.  
  30.                 // Create interval
  31.                 let interval = {
  32.                     avg: null,
  33.                     median: null,
  34.                     min: Number.POSITIVE_INFINITY,
  35.                     max: Number.NEGATIVE_INFINITY,
  36.  
  37.                     offers: {
  38.                         count: 0,
  39.                         percentage: 0,
  40.  
  41.                         ignore: 0,
  42.                         medianNullStart: -1,
  43.                     },
  44.  
  45.                     requests: [],
  46.                 }
  47.  
  48.                 // Add interval to component
  49.                 component.intervals.push(interval)
  50.             }
  51.  
  52.             // Push to component array
  53.             components.push(component)
  54.         })
  55.  
  56.         // Add to buying/selling/combined
  57.         doc.buying.components = doc.buying.components.concat(components)
  58.         doc.selling.components = doc.selling.components.concat(components)
  59.         doc.combined.components = doc.combined.components.concat(components)
  60.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement