Skip to content

Refinery-ui-react #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Feb 2, 2024
Merged
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
2 changes: 2 additions & 0 deletions basic-fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export function jsonFetchWrapper(url: string, fetchType: FetchType, onResult?: (
hasError = true;
}
else return response.json();
}, (error) => {
console.log("Error in request at " + url);
});

if (onResult && !hasError) myFetch.then(result => onResult(result));
Expand Down
4 changes: 4 additions & 0 deletions date-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,8 @@ export function isValidDate(date: string) {
if (isNaN(Date.parse(date))) return false;
const d = new Date(date);
return d.getFullYear() < 2100;
}

export function timeDiffCalc(dateA: any, dateB: any = Date.now()) {
return new Date(Math.abs(dateB - dateA)).toISOString().substring(11, 19);
}
65 changes: 64 additions & 1 deletion enums/enum-functions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { InformationSourceType } from "./enums";
import { DisplayGraphs, InformationSourceType, LabelSource, SearchGroup, Slice, StaticOrderByKeys } from "./enums";

export function informationSourceTypeToString(source: InformationSourceType, short: boolean, forDisplay: boolean = true) {
if (forDisplay) {
Expand All @@ -13,3 +13,66 @@ export function informationSourceTypeToString(source: InformationSourceType, sho
}
return source;
}

export function displayGraphsTypeToString(source: DisplayGraphs) {
switch (source) {

case DisplayGraphs.CONFUSION_MATRIX: return "Confusion Matrix";
case DisplayGraphs.INTER_ANNOTATOR: return "Inter Annotator";
case DisplayGraphs.LABEL_DISTRIBUTION: return "Label Distribution";
case DisplayGraphs.CONFIDENCE_DISTRIBUTION: return "Confidence Distribution";
case DisplayGraphs.ALL: return "All";
default: return source;
}
}

export function labelSourceToString(source: LabelSource, forDisplay: boolean = true) {
if (forDisplay) {
switch (source) {
case LabelSource.MANUAL: return "Manual";
case LabelSource.WEAK_SUPERVISION: return "Weak Supervision";
case LabelSource.MODEL_CALLBACK: return "Model Callback";
case LabelSource.INFORMATION_SOURCE: return "Information Source";
default: return source;
}
}
return source;
}


export function sliceTypeToString(sliceType: string): string {
switch (sliceType) {
case Slice.STATIC_DEFAULT:
return 'Static Slice';
case Slice.STATIC_OUTLIER:
return 'Outlier Slice';
case Slice.DYNAMIC_DEFAULT:
return 'Dynamic Slice';
default: return sliceType;
}
}

export function nameForGroupKeyToString(group: SearchGroup): string {
switch (group) {
case SearchGroup.ATTRIBUTES:
return 'Attributes';
case SearchGroup.USER_FILTER:
return 'Users';
case SearchGroup.LABELING_TASKS:
return 'Labeling task:';
case SearchGroup.ORDER_STATEMENTS:
return 'Result Order';
case SearchGroup.COMMENTS:
return 'Comments';
default: return group;
}
}

export function getOrderByDisplayName(orderByKey: string) {
switch (orderByKey) {
case StaticOrderByKeys.RANDOM: return "Random";
case StaticOrderByKeys.WEAK_SUPERVISION_CONFIDENCE: return "Weak Supervision Confidence";
case StaticOrderByKeys.MODEL_CALLBACK_CONFIDENCE: return "Model Callback Confidence";
default: return orderByKey; //attributes
}
}
42 changes: 42 additions & 0 deletions enums/enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,46 @@ export enum InformationSourceType {
PRE_COMPUTED = "PRE_COMPUTED",
ZERO_SHOT = "ZERO_SHOT",
CROWD_LABELER = "CROWD_LABELER"
}

export enum DisplayGraphs {
ALL = "ALL",
CONFUSION_MATRIX = "CONFUSION_MATRIX",
INTER_ANNOTATOR = "INTER_ANNOTATOR",
LABEL_DISTRIBUTION = "LABEL_DISTRIBUTION",
CONFIDENCE_DISTRIBUTION = "CONFIDENCE_DISTRIBUTION",
}

export enum LabelSource {
MANUAL = "MANUAL",
WEAK_SUPERVISION = "WEAK_SUPERVISION",
INFORMATION_SOURCE = "INFORMATION_SOURCE",
MODEL_CALLBACK = "MODEL_CALLBACK",
}

export enum Slice {
STATIC_DEFAULT = "STATIC_DEFAULT",
STATIC_OUTLIER = "STATIC_OUTLIER",
DYNAMIC_DEFAULT = "DYNAMIC_DEFAULT",
}

export enum SearchGroup {
ATTRIBUTES = 'ATTRIBUTES',
LABELING_TASKS = 'LABELING_TASKS',
ORDER_STATEMENTS = 'ORDER_STATEMENTS',
USER_FILTER = 'USER_FILTER',
COMMENTS = 'COMMENTS',
DRILL_DOWN = 'DRILL_DOWN',
CATEGORY = 'CATEGORY',
}

export enum StaticOrderByKeys {
MODEL_CALLBACK_CONFIDENCE = "MODEL_CALLBACK_CONFIDENCE",
WEAK_SUPERVISION_CONFIDENCE = 'WEAK_SUPERVISION_CONFIDENCE',
RANDOM = 'RANDOM'
}

export enum InformationSourceReturnType {
RETURN = "RETURN",
YIELD = "YIELD"
}
7 changes: 7 additions & 0 deletions export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ export function downloadByteData(byteData: any, filename = 'file.zip', type = 'a
download(blob, filename);
}

export function downloadByteDataNoStringify(byteData: any, filename = 'file.zip', type = 'application/octet-stream') {
const blob = new Blob([byteData], {
type: type
});
download(blob, filename);
}

export function downloadJsonData(jsonData: any, filename = 'file.json', type = 'application/json') {
const blob = new Blob([JSON.stringify(jsonData)], {
type: type
Expand Down
2 changes: 1 addition & 1 deletion general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export function formatBytes(bytes: number, decimals = 2) {
export type enumToArrayOptions = {
caseType?: caseType;
prefix?: string;
nameFunction?: (name: string) => string;
nameFunction?: (name: any) => string;
}

export function enumToArray(e: Object, options: enumToArrayOptions | null = null): any[] {
Expand Down