Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import {
getPastDaysDateTimeMillis,
} from '../utils/TimeUtils';

export const UNSUPPORTED_DATA_INSIGHT_ENTITIES = ['TestSuite', 'User'];

export const BAR_CHART_MARGIN: Margin = {
top: 20,
right: 30,
Expand Down
152 changes: 97 additions & 55 deletions openmetadata-ui/src/main/resources/ui/src/utils/DataInsightUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { ListItem, ListValues } from 'react-awesome-query-builder';
import { LegendProps, Surface } from 'recharts';
import {
ENTITIES_SUMMARY_LIST,
UNSUPPORTED_DATA_INSIGHT_ENTITIES,
WEB_SUMMARY_LIST,
} from '../constants/DataInsight.constants';
import {
Expand Down Expand Up @@ -58,11 +59,6 @@ export const renderLegend = (legendData: LegendProps, latest: string) => {
);
};

/**
* we don't have type for Tooltip value and Tooltip
* that's why we have to use the type "any"
*/

export const CustomTooltip = (props: DataInsightChartTooltipProps) => {
const { active, payload = [], label, isPercentage } = props;

Expand Down Expand Up @@ -122,11 +118,17 @@ const prepareGraphData = (
);
};

/**
*
* @param latestData graph latest data
* @returns latest count for latest data
*/
const getLatestCount = (latestData = {}) => {
let total = 0;
const latestEntries = Object.entries(latestData ?? {});

for (const entry of latestEntries) {
// skip the timestamp value
if (entry[0] !== 'timestamp') {
total += toNumber(entry[1]);
}
Expand All @@ -135,56 +137,69 @@ const getLatestCount = (latestData = {}) => {
return isInteger(total) ? total : total.toFixed(2);
};

/**
*
* @param rawData Data insight chart result data
* @param dataInsightChartType data insight chart type
* @returns graph data for chart type
*/
export const getGraphDataByEntityType = (
rawData: DataInsightChartResult['data'] = [],
dataInsightChartType: DataInsightChartType
) => {
const entities: string[] = [];
const timestamps: string[] = [];

const filteredData = rawData.map((data) => {
if (data.timestamp && data.entityType) {
let value;
const timestamp = getFormattedDateFromMilliSeconds(data.timestamp);
if (!entities.includes(data.entityType ?? '')) {
entities.push(data.entityType ?? '');
}
const filteredData = rawData
.map((data) => {
if (data.timestamp && data.entityType) {
let value;
const timestamp = getFormattedDateFromMilliSeconds(data.timestamp);
const entityType = data.entityType ?? '';

if (!timestamps.includes(timestamp)) {
timestamps.push(timestamp);
}
// skip the unsupported data insight entities
if (UNSUPPORTED_DATA_INSIGHT_ENTITIES.includes(entityType)) return;

switch (dataInsightChartType) {
case DataInsightChartType.TotalEntitiesByType:
value = data.entityCount;
if (!entities.includes(entityType)) {
entities.push(entityType);
}

break;
case DataInsightChartType.PercentageOfEntitiesWithDescriptionByType:
value = data.completedDescriptionFraction;
if (!timestamps.includes(timestamp)) {
timestamps.push(timestamp);
}

break;
case DataInsightChartType.PercentageOfEntitiesWithOwnerByType:
value = data.hasOwnerFraction;
switch (dataInsightChartType) {
case DataInsightChartType.TotalEntitiesByType:
value = data.entityCount;

break;
break;
case DataInsightChartType.PercentageOfEntitiesWithDescriptionByType:
value = data.completedDescriptionFraction;

case DataInsightChartType.PageViewsByEntities:
value = data.pageViews;
break;
case DataInsightChartType.PercentageOfEntitiesWithOwnerByType:
value = data.hasOwnerFraction;

break;
break;

default:
break;
}
case DataInsightChartType.PageViewsByEntities:
value = data.pageViews;

return {
timestamp: timestamp,
[data.entityType]: value,
};
}
break;

return;
});
default:
break;
}

return {
timestamp: timestamp,
[data.entityType]: value,
};
}

return;
})
.filter(Boolean);

const graphData = prepareGraphData(timestamps, filteredData);
const latestData = last(graphData);
Expand All @@ -197,30 +212,37 @@ export const getGraphDataByEntityType = (
};
};

/**
*
* @param rawData entities data by tier
* @returns graph data for tier chart
*/
export const getGraphDataByTierType = (rawData: TotalEntitiesByTier[]) => {
const tiers: string[] = [];
const timestamps: string[] = [];

const filteredData = rawData.map((data) => {
if (data.timestamp && data.entityTier) {
const tiering = data.entityTier;
const timestamp = getFormattedDateFromMilliSeconds(data.timestamp);
if (!tiers.includes(tiering)) {
tiers.push(tiering);
}
const filteredData = rawData
.map((data) => {
if (data.timestamp && data.entityTier) {
const tiering = data.entityTier;
const timestamp = getFormattedDateFromMilliSeconds(data.timestamp);
if (!tiers.includes(tiering)) {
tiers.push(tiering);
}

if (!timestamps.includes(timestamp)) {
timestamps.push(timestamp);
}
if (!timestamps.includes(timestamp)) {
timestamps.push(timestamp);
}

return {
timestamp: timestamp,
[tiering]: data.entityCount,
};
}
return {
timestamp: timestamp,
[tiering]: data.entityCount,
};
}

return;
});
return;
})
.filter(Boolean);

const graphData = prepareGraphData(timestamps, filteredData);
const latestData = last(graphData);
Expand All @@ -232,13 +254,23 @@ export const getGraphDataByTierType = (rawData: TotalEntitiesByTier[]) => {
};
};

/**
*
* @param suggestionValues suggestion list
* @returns option list for filters
*/
export const getTeamFilter = (suggestionValues: ListValues = []) => {
return (suggestionValues as ListItem[]).map((suggestion: ListItem) => ({
label: suggestion.title,
value: suggestion.value,
}));
};

/**
*
* @param activeUsers raw daily active users list
* @returns user list with formatted timestamp
*/
export const getFormattedActiveUsersData = (activeUsers: DailyActiveUsers[]) =>
activeUsers.map((user) => ({
...user,
Expand All @@ -247,6 +279,11 @@ export const getFormattedActiveUsersData = (activeUsers: DailyActiveUsers[]) =>
: '',
}));

/**
*
* @param chartResults raw chart results for entities chart
* @returns chart summary for entities chart
*/
export const getEntitiesChartSummary = (
chartResults: (DataInsightChartResult | undefined)[]
) => {
Expand Down Expand Up @@ -277,6 +314,11 @@ export const getEntitiesChartSummary = (
return updatedSummaryList;
};

/**
*
* @param chartResults raw chart results for web chart
* @returns chart summary for web chart
*/
export const getWebChartSummary = (
chartResults: (DataInsightChartResult | undefined)[]
) => {
Expand Down