Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
RSMNYS committed Jan 16, 2024
1 parent 1cb63d6 commit d663762
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import { GrClose } from "react-icons/gr";
type Props = {
onClose: any;
benchmarkId: string;
onToggle: () => void;
isOpen?: boolean;
};

const BenchmarkDrawerContent = ({ onClose, benchmarkId }: Props) => {
Expand Down
14 changes: 2 additions & 12 deletions react/src/modules/benchmarks/components/BenchmarkTableDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,12 @@ type Props = {
benchmarkId: string;
};

const BenchmarkTableDrawer = ({
isOpen,
onClose,
onToggle,
benchmarkId,
}: Props) => {
const BenchmarkTableDrawer = ({ isOpen, onClose, benchmarkId }: Props) => {
const drawerRef = React.useRef<HTMLElement | null>(null);

const getDrawerContents = () => {
return (
<BenchmarkDrawerContent
onClose={onClose}
isOpen={isOpen}
onToggle={onToggle}
benchmarkId={benchmarkId}
/>
<BenchmarkDrawerContent onClose={onClose} benchmarkId={benchmarkId} />
);
};

Expand Down
139 changes: 72 additions & 67 deletions react/src/modules/filters/models/filters.model.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
BenchmarkResult,
EnvironmentInfo,
Result,
} from "../../benchmarks/models/benchmarks.model";
import { StringValue } from "../../../constants/constants";
Expand All @@ -22,14 +23,14 @@ export interface ResultFilterType {
}

export class ResultFilter implements ResultFilterType {
fromCreationDate?: Date | null;
toCreationDate?: Date | null;
platform?: string | null;
deviceModel?: string | null;
backend?: string | null;
manufacturer?: string | null;
soc?: string | null;
benchmarkId?: string | null;
fromCreationDate: Date | null;
toCreationDate: Date | null;
platform: string | null;
deviceModel: string | null;
backend: string | null;
manufacturer: string | null;
soc: string | null;
benchmarkId: string | null;

constructor(filter: ResultFilterType = {}) {
this.fromCreationDate = filter.fromCreationDate ?? null;
Expand All @@ -42,76 +43,80 @@ export class ResultFilter implements ResultFilterType {
this.benchmarkId = filter.benchmarkId ?? null;
}

match(result: BenchmarkResult): boolean {
let resultDeviceModel: string | null = null;
let resultManufacturer: string | null = null;
let resultSoc: string | null = null;
const envInfo = result.environment_info;
match(result: BenchmarkResult) {
const { deviceModel, manufacturer, soc } = this.getDeviceDetails(
result.environment_info,
);
const resultCreationDate = new Date(result.meta.creation_date);
const resultBackend = result.results[0].backend_info.filename;

const platformMatches =
this.platform === null ||
this.platform === result.environment_info.platform;
const backendMatches =
this.backend === null || this.backend === resultBackend;

return (
this.isDateWithinRange(
resultCreationDate,
this.fromCreationDate,
this.toCreationDate,
) &&
platformMatches &&
this.stringMatches(deviceModel, this.deviceModel) &&
this.stringMatches(manufacturer, this.manufacturer) &&
this.stringMatches(soc, this.soc) &&
backendMatches
);
}

getDeviceDetails(envInfo: EnvironmentInfo) {
switch (envInfo.platform) {
case Platform.Android:
resultDeviceModel = envInfo.value.android?.model_name ?? null;
resultManufacturer = envInfo.value.android?.manufacturer ?? null;
resultSoc = envInfo.value.android?.proc_cpuinfo_soc_name ?? null;
break;

return {
deviceModel: envInfo.value.android?.model_name ?? StringValue.unknown,
manufacturer:
envInfo.value.android?.manufacturer ?? StringValue.unknown,
soc:
envInfo.value.android?.proc_cpuinfo_soc_name ?? StringValue.unknown,
};
case Platform.iOS:
resultDeviceModel = envInfo.value.ios?.model_name ?? null;
resultManufacturer = "Apple";
resultSoc = envInfo.value.ios?.soc_name ?? null;
break;

return {
deviceModel: envInfo.value.ios?.model_name ?? StringValue.unknown,
manufacturer: "Apple",
soc: envInfo.value.ios?.soc_name ?? StringValue.unknown,
};
case Platform.Windows:
resultDeviceModel = envInfo.value.windows?.cpu_full_name ?? null;
resultManufacturer = StringValue.unknown;
resultSoc = envInfo.value.windows?.cpu_full_name ?? null;
break;
return {
deviceModel:
envInfo.value.windows?.cpu_full_name ?? StringValue.unknown,
manufacturer: StringValue.unknown,
soc: envInfo.value.windows?.cpu_full_name ?? StringValue.unknown,
};
default:
return {
deviceModel: StringValue.unknown,
manufacturer: StringValue.unknown,
soc: StringValue.unknown,
};
}
}

resultDeviceModel = resultDeviceModel ?? StringValue.unknown;
resultManufacturer = resultManufacturer ?? StringValue.unknown;
resultSoc = resultSoc || StringValue.unknown;

const resultCreationDate = new Date(result.meta.creation_date);
const resultBackend = result.results[0].backend_info.filename;
const resultPlatform = envInfo.platform;

const oneDay: number = 24 * 60 * 60 * 1000;

const fromCreationDateMatched =
this.fromCreationDate === null ||
this.fromCreationDate === undefined ||
resultCreationDate > this.fromCreationDate;
const toCreationDateMatched =
this.toCreationDate === null ||
this.toCreationDate === undefined ||
resultCreationDate < new Date(this.toCreationDate.getTime() + oneDay);

const platformMatched =
this.platform === null || this.platform === resultPlatform;
const deviceModelMatched = resultDeviceModel
.toLowerCase()
.includes((this.deviceModel ?? "").toLowerCase());
const backendMatched =
this.backend === null || this.backend === resultBackend;
const manufacturerMatched = resultManufacturer
.toLowerCase()
.includes((this.manufacturer ?? "").toLowerCase());
const socMatched = resultSoc
.toLowerCase()
.includes((this.soc ?? "").toLowerCase());

// Helper function for date comparison
isDateWithinRange(date: Date, fromDate: Date | null, toDate: Date | null) {
const oneDay = 24 * 60 * 60 * 1000;
const toDateAdjusted = toDate ? new Date(toDate.getTime() + oneDay) : null;
return (
fromCreationDateMatched &&
toCreationDateMatched &&
platformMatched &&
deviceModelMatched &&
backendMatched &&
manufacturerMatched &&
socMatched
(!fromDate || date > fromDate) &&
(!toDateAdjusted || date < toDateAdjusted)
);
}

// Helper function for string matching
stringMatches(value: string, pattern: string | null) {
return value.toLowerCase().includes((pattern ?? "").toLowerCase());
}

matchBenchmark(result: Result): boolean {
return this.benchmarkId == null
? true
Expand Down

0 comments on commit d663762

Please sign in to comment.