Skip to content
Snippets Groups Projects
Commit 09fe6032 authored by David Sehnal's avatar David Sehnal
Browse files

CIF writer tweaks

parent 5551b1dd
No related branches found
No related tags found
No related merge requests found
......@@ -20,8 +20,7 @@ function ofSchema(schema: Table.Schema) {
const fields: Encoder.FieldDefinition[] = [];
for (const k of Object.keys(schema)) {
const t = schema[k];
// TODO: matrix/vector/support
const type = t.kind === 'str' ? Encoder.FieldType.Str : t.kind === 'int' ? Encoder.FieldType.Int : Encoder.FieldType.Float;
const type: any = t.kind === 'str' ? Encoder.FieldType.Str : t.kind === 'int' ? Encoder.FieldType.Int : Encoder.FieldType.Float;
fields.push({ name: k, type, value: columnValue(k), valueKind: columnValueKind(k) })
}
return fields;
......
......@@ -49,7 +49,7 @@ function ofSchema(schema: Table.Schema) {
for (const k of Object.keys(schema)) {
const t = schema[k];
// TODO: matrix/vector/support
const type = t.kind === 'str' ? Encoder.FieldType.Str : t.kind === 'int' ? Encoder.FieldType.Int : Encoder.FieldType.Float;
const type: any = t.kind === 'str' ? Encoder.FieldType.Str : t.kind === 'int' ? Encoder.FieldType.Int : Encoder.FieldType.Float;
fields.push({ name: k, type, value: columnValue(k), valueKind: columnValueKind(k) })
}
return fields;
......
......@@ -13,17 +13,18 @@ export const enum FieldType {
Str, Int, Float
}
export interface FieldDefinition<Key = any, Data = any> {
export interface FieldDefinitionBase<Key, Data> {
name: string,
type: FieldType,
value(key: Key, data: Data): string | number,
valueKind?: (key: Key, data: Data) => Column.ValueKind
/** determine whether to include this field base on the context */
valueKind?: (key: Key, data: Data) => Column.ValueKind,
// TODO:
// shouldInclude?: (data: Data) => boolean
}
export type FieldDefinition<Key = any, Data = any> =
| FieldDefinitionBase<Key, Data> & { type: FieldType.Str, value(key: Key, data: Data): string }
| FieldDefinitionBase<Key, Data> & { type: FieldType.Int, value(key: Key, data: Data): number }
| FieldDefinitionBase<Key, Data> & { type: FieldType.Float, value(key: Key, data: Data): number }
export interface FieldFormat {
// TODO
// textDecimalPlaces: number,
......
......@@ -79,7 +79,7 @@ function writeValue(builder: StringBuilder, data: any, key: any, f: Enc.FieldDef
} else if (t === Enc.FieldType.Int) {
writeInteger(builder, val as number);
} else {
writeFloat(builder, val as number, 1000);
writeFloat(builder, val as number, 1000000);
}
}
return false;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment