aaronucsd commented on a change in pull request #3787: [TE] frontend - 
harleyjj/yaml-editor - implements simple graph for pr…
URL: https://github.com/apache/incubator-pinot/pull/3787#discussion_r253601151
 
 

 ##########
 File path: 
thirdeye/thirdeye-frontend/app/pods/components/yaml-editor/component.js
 ##########
 @@ -137,6 +281,116 @@ export default Component.extend({
     }
   }).drop(),
 
+  didRender(){
+    this._super(...arguments);
+
+    later(() => {
+      this._buildSliderButton();
+    });
+  },
+
+  // Helper function that builds the subchart region buttons
+  _buildSliderButton() {
+    const componentId = this.get('componentId');
+    const resizeButtons = d3.select(`.${componentId}`).selectAll('.resize');
+
+    resizeButtons.append('circle')
+      .attr('cx', 0)
+      .attr('cy', 30)
+      .attr('r', 10)
+      .attr('fill', '#0091CA');
+    resizeButtons.append('line')
+      .attr('class', 'anomaly-graph__slider-line')
+      .attr("x1", 0)
+      .attr("y1", 27)
+      .attr("x2", 0)
+      .attr("y2", 33);
+
+    resizeButtons.append('line')
+      .attr('class', 'anomaly-graph__slider-line')
+      .attr("x1", -5)
+      .attr("y1", 27)
+      .attr("x2", -5)
+      .attr("y2", 33);
+
+    resizeButtons.append('line')
+      .attr('class', 'anomaly-graph__slider-line')
+      .attr("x1", 5)
+      .attr("y1", 27)
+      .attr("x2", 5)
+      .attr("y2", 33);
+  },
+
+  _formatAnomaly(anomaly) {
+    return `${moment(anomaly.startTime).format(PREVIEW_DATE_FORMAT)}
+    to ${moment(anomaly.endTime).format(PREVIEW_DATE_FORMAT)}`;
+  },
+
+  _filterAnomalies(rows) {
+    return rows.filter(row => (row.startTime && row.endTime && !row.child));
+  },
+
+  _fetchTimeseries() {
+    const metricUrn = get(this, 'metricUrn');
+    const range = get(this, 'displayRange');
+    const granularity = '15_MINUTES';
+    const timezone = moment.tz.guess();
+
+    set(this, 'errorTimeseries', null);
+
+    const urlCurrent = 
`/rootcause/metric/timeseries?urn=${metricUrn}&start=${range[0]}&end=${range[1]}&offset=current&granularity=${granularity}&timezone=${timezone}`;
+    fetch(urlCurrent)
+      .then(checkStatus)
+      .then(res => {
+        set(this, 'timeseries', res);
+        set(this, 'isLoading', false);
+      });
+    // .then(res => set(this, 'output', 'got timeseries'))
+    // .catch(err => set(this, 'errorTimeseries', err));
+
+    set(this, 'errorBaseline', null);
+
+    const offset = get(this, 'compareMode');
+    const urlBaseline = 
`/rootcause/metric/timeseries?urn=${metricUrn}&start=${range[0]}&end=${range[1]}&offset=${offset}&granularity=${granularity}&timezone=${timezone}`;
+    fetch(urlBaseline)
+      .then(checkStatus)
+      .then(res => set(this, 'baseline', res));
+    // .then(res => set(this, 'output', 'got baseline'))
+    // .catch(err => set(this, 'errorBaseline', err));
+  },
+
+  _fetchAnomalies() {
+    const analysisRange = get(this, 'analysisRange');
+    const url = 
`/yaml/preview?start=${analysisRange[0]}&end=${analysisRange[1]}&tuningStart=0&tuningEnd=0`;
+
+    set(this, 'errorAnomalies', null);
+
+    const content = get(this, 'alertYaml');
+    const postProps = {
+      method: 'post',
+      body: content,
+      headers: { 'content-type': 'text/plain' }
+    };
+
+    fetch(url, postProps)
+      .then(checkStatus)
+      .then(res => {
+        set(this, 'anomalies', this._filterAnomalies(res.anomalies));
+        set(this, 'metricUrn', Object.keys(res.diagnostics['0'])[0]);
+      })
+      .then(() => {
+        this._fetchTimeseries();
+      })
+    // .then(res => set(this, 'output', 'got anomalies'))
+      .catch(err => {
+        err.response.json()
+          .then(res => {
+            set(this, 'errorAnomalies', res.message);
 
 Review comment:
   setProperties would be nice here. Thanks.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to