Skip to content

Commit

Permalink
fix area chart
Browse files Browse the repository at this point in the history
  • Loading branch information
AjayThorve committed Nov 8, 2022
1 parent 41a180b commit 99155af
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 27 deletions.
20 changes: 10 additions & 10 deletions morpheus-DFP/src/components/area.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,54 +93,54 @@ function AreaChart({ totalEvents, anomalousEvents }) {
},
series: [
{
name: "Anomalous Traffic",
name: "Network Traffic",
type: "line",
symbol: "none",
stack: true,
lineStyle: {
width: 0.7,
color: "#ffffff",
},
areaStyle: {
opacity: 1,
opacity: 0.7,
color: new echarts.graphic.LinearGradient(0, 0, 0, 1.5, [
{
offset: 0,
color: "#f73d0a",
color: "#ffffff",
},
{
offset: 1,
color: "#000000",
},
]),
},
data: anomalousEvents,
data: totalEvents,
},
{
name: "Network Traffic",
name: "Anomalous Traffic",
type: "line",
symbol: "none",
stack: true,
lineStyle: {
width: 0.7,
color: "#ffffff",
},
areaStyle: {
opacity: 0.7,
opacity: 1,
color: new echarts.graphic.LinearGradient(0, 0, 0, 1.5, [
{
offset: 0,
color: "#ffffff",
color: "#f73d0a",
},
{
offset: 1,
color: "#000000",
},
]),
},
data: totalEvents,
data: anomalousEvents,
},
],
notMerge: true,
notMerge: false,
backgroundColor: "#0f0f0f",
};

Expand Down
31 changes: 30 additions & 1 deletion morpheus-DFP/src/components/server/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,36 @@ export function getInstances(
.select(["userID", "time", "index", "anomalyScore_scaled"])
.sortValues({ anomalyScore_scaled: { ascending: false } });
}

export function getEventStats(df, threshold) {
const totalEvents = df
.groupBy({ by: "time" })
.count()
.select(["time", "user"])
.sortValues({ time: { ascending: false } })
.rename({ user: "count" })
.toArrow()
.toArray();
const anomalousEvents = df
.filter(df.get("anomalyScore_scaled").ge(threshold))
.groupBy({ by: "time" })
.count()
.select(["time", "user"])
.sortValues({ time: { ascending: false } })
.rename({ user: "count" })
.toArrow()
.toArray();

return {
totalEvents: totalEvents.reduce(
(map, value) => map.concat([Object.values(value)]),
[]
),
anomalousEvents: anomalousEvents.reduce(
(map, value) => map.concat([Object.values(value)]),
[]
),
};
}
export function generateData(
df,
df_queried,
Expand Down
11 changes: 2 additions & 9 deletions morpheus-DFP/src/pages/api/[...param].js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
sendDF,
generateData,
getInstances,
getEventStats,
} from "../../components/server/utils";
const cache = require("../../components/server/cacheDatasets")();
import runMiddleware from "../../components/server/runMiddleware";
Expand Down Expand Up @@ -96,15 +97,7 @@ export default async function handler(req, res) {
? parseFloat(req.query.anomalyThreshold)
: 0.385;

res.send({
totalEvents:
req[datasetName].numRows -
req[datasetName].get("anomalyScore_scaled").nullCount,
totalAnomalousEvents: req[datasetName].filter(
req[datasetName].get("anomalyScore_scaled").ge(anomalyThreshold)
).numRows,
time: req[datasetName].get("time").getValue(0),
});
res.send(getEventStats(req[datasetName + "_queried"], anomalyThreshold));
break;
case "getInstances":
const id = req.query.id ? parseInt(req.query.id) : -1;
Expand Down
9 changes: 2 additions & 7 deletions morpheus-DFP/src/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,19 +127,14 @@ export default class CustomD3 extends React.Component {
const timestamps = await requestJSON("getTimeStamps", this.appendPayload());
const userIDs = await requestData("getUniqueIDs", this.appendPayload());
const totalTime = await requestJSON("getTotalTime", this.appendPayload());

this.setState({
position: elevation.batches[0].data.children[0].values,
colors: colors.batches[0].data.children[0].values,
userIDs: new TextDecoder().decode(
userIDs.batches[0].data.children[0].values
),
anomalousEvents: this.state.anomalousEvents.concat([
[new Date(data.time), data.totalAnomalousEvents],
]),
totalEvents: this.state.totalEvents.concat([
[new Date(data.time), data.totalEvents],
]),
anomalousEvents: data.anomalousEvents,
totalEvents: data.totalEvents,
selectedEvent: {
...this.state.selectedEvent,
instanceId: -1,
Expand Down

0 comments on commit 99155af

Please sign in to comment.