chore: extract schema types (#2375)

* chore: extract schema types

* address comments
This commit is contained in:
Timmy Huang
2021-08-12 03:12:21 +00:00
committed by GitHub
parent fc60b2acef
commit 59c475b821
7 changed files with 68 additions and 67 deletions
@@ -34,7 +34,7 @@ function makeMockColumn(s: any, length: any) {
return new Array(length).fill(s.categories[0]);
default:
throw new Error("unkonwn type");
throw new Error("unknown type");
}
}
@@ -1,4 +1,4 @@
import { RawSchema } from "../../../../src/common/types/entities";
import { RawSchema } from "../../../../src/common/types/schema";
export const schema: { schema: RawSchema } = {
schema: {
@@ -5,7 +5,7 @@ import zip from "lodash.zip";
import _ from "lodash";
import { flatbuffers } from "flatbuffers";
import { NetEncoding } from "../../../src/util/stateManager/matrix_generated";
import { RawSchema } from "../../../src/common/types/entities";
import { RawSchema } from "../../../src/common/types/schema";
/*
test data mocking REST 0.2 API responses. Used in several tests.
+1 -58
View File
@@ -1,60 +1,3 @@
// If a globally shared type or interface doesn't have a clear owner, put it here
export type Category = number | string | boolean;
export interface AnnotationColumn {
categories?: Category[];
name: string;
type: "string" | "float32" | "int32" | "categorical" | "boolean";
writable: boolean;
}
interface DataFrame {
nObs: number;
nVar: number;
// TODO(thuang): Not sure what other types are available
type: "float32";
}
export interface LayoutColumn {
dims: string[];
name: string;
// TODO(thuang): Not sure what other types are available
type: "float32";
}
interface RawLayout {
obs: LayoutColumn[];
var?: LayoutColumn[];
}
interface RawAnnotations {
obs: {
columns: AnnotationColumn[];
index: string;
};
var: {
columns: AnnotationColumn[];
index: string;
};
}
export interface RawSchema {
annotations: RawAnnotations;
dataframe: DataFrame;
layout: RawLayout;
}
interface Annotations extends RawAnnotations {
obsByName: { [name: string]: AnnotationColumn };
varByName: { [name: string]: AnnotationColumn };
}
interface Layout extends RawLayout {
obsByName: { [name: string]: LayoutColumn };
varByName: { [name: string]: LayoutColumn };
}
export interface Schema extends RawSchema {
annotations: Annotations;
layout: Layout;
}
export {};
+58
View File
@@ -0,0 +1,58 @@
type Category = number | string | boolean;
export interface AnnotationColumnSchema {
categories?: Category[];
name: string;
type: "string" | "float32" | "int32" | "categorical" | "boolean";
writable: boolean;
}
interface XMatrixSchema {
nObs: number;
nVar: number;
// TODO(thuang): Not sure what other types are available
type: "float32";
}
export interface EmbeddingSchema {
dims: string[];
name: string;
// TODO(thuang): Not sure what other types are available
type: "float32";
}
interface RawLayoutSchema {
obs: EmbeddingSchema[];
var?: EmbeddingSchema[];
}
interface RawAnnotationsSchema {
obs: {
columns: AnnotationColumnSchema[];
index: string;
};
var: {
columns: AnnotationColumnSchema[];
index: string;
};
}
export interface RawSchema {
annotations: RawAnnotationsSchema;
dataframe: XMatrixSchema;
layout: RawLayoutSchema;
}
interface AnnotationsSchema extends RawAnnotationsSchema {
obsByName: { [name: string]: AnnotationColumnSchema };
varByName: { [name: string]: AnnotationColumnSchema };
}
interface LayoutSchema extends RawLayoutSchema {
obsByName: { [name: string]: EmbeddingSchema };
varByName: { [name: string]: EmbeddingSchema };
}
export interface Schema extends RawSchema {
annotations: AnnotationsSchema;
layout: LayoutSchema;
}
@@ -3,7 +3,7 @@ Helper functions for user-editable annotations state management.
See also reducers/annotations.js
*/
import { Schema } from "../../common/types/entities";
import { Schema } from "../../common/types/schema";
/*
There are a number of state constraints assumed throughout the
@@ -11,9 +11,9 @@ import catLabelSort from "../catLabelSort";
import {
RawSchema,
Schema,
LayoutColumn,
AnnotationColumn,
} from "../../common/types/entities";
EmbeddingSchema,
AnnotationColumnSchema,
} from "../../common/types/schema";
/*
System wide schema assumptions:
@@ -86,7 +86,7 @@ export function removeObsAnnoColumn(schema: Schema, name: string): Schema {
export function addObsAnnoColumn(
schema: Schema,
_: string,
defn: AnnotationColumn
defn: AnnotationColumnSchema
): Schema {
const newSchema = _copyObsAnno(schema);
@@ -142,7 +142,7 @@ export function addObsAnnoCategory(schema: any, name: any, category: any) {
return newSchema;
}
export function addObsLayout(schema: Schema, layout: LayoutColumn): Schema {
export function addObsLayout(schema: Schema, layout: EmbeddingSchema): Schema {
/* add or replace a layout */
const newSchema = _copyObsLayout(schema);
newSchema.layout.obs.push(layout);