Skip to content
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

[Chore]: Technical: add types for processors #1798

Merged
merged 4 commits into from May 17, 2022
Merged

Conversation

dariaterekhova-actionengine
Copy link
Collaborator

Signed-off-by: Daria Terekhova daria.terekhova@actionengine.com

Signed-off-by: Daria Terekhova <daria.terekhova@actionengine.com>
@@ -58,20 +63,20 @@ const IGNORE_DATA_TYPES = Object.keys(AnalyzerDATA_TYPES).filter(

export const PARSE_FIELD_VALUE_FROM_STRING = {
[ALL_FIELD_TYPES.boolean]: {
valid: d => typeof d === 'boolean',
parse: d => d === 'true' || d === 'True' || d === 'TRUE' || d === '1'
valid: (d: any) => typeof d === 'boolean',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(d: unknown): boolean => typeof d === 'boolean'

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

valid: d => typeof d === 'boolean',
parse: d => d === 'true' || d === 'True' || d === 'TRUE' || d === '1'
valid: (d: any) => typeof d === 'boolean',
parse: (d: any) => d === 'true' || d === 'True' || d === 'TRUE' || d === '1'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(d: unknown): boolean

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

},
[ALL_FIELD_TYPES.integer]: {
valid: d => parseInt(d, 10) === d,
parse: d => parseInt(d, 10)
valid: (d: any) => parseInt(d, 10) === d,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same below, use (d: unknown): boolean for validate

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

valid: d => parseInt(d, 10) === d,
parse: d => parseInt(d, 10)
valid: (d: any) => parseInt(d, 10) === d,
parse: (d: any) => parseInt(d, 10)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(value: unknown): number

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

sampleCount = 50
}: {
fields: string[];
rows: any[][];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rows: unknown[][]

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

*/
function cleanUpFalsyCsvValue(rows) {
function cleanUpFalsyCsvValue(rows: any[][]): void {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rows: unknown[][]

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

*/
export function parseCsvRowsByFieldType(rows, geoFieldIdx, field, i) {
export function parseCsvRowsByFieldType(
rows: any[][],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rows: unknown[][]

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

function findNonEmptyRowsAtField(rows, fieldIdx, total) {
const sample = [];
function findNonEmptyRowsAtField(
rows: Record<number, unknown>[],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rows: unknown[][]

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@@ -47,25 +50,25 @@ const JSON_LOADER_OPTIONS = {
]
};

export function isGeoJson(json) {
export function isGeoJson(json: any): boolean {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use type guard here
isGeoJson(json: unknown): json is Feature | FeatureCollection

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

// json can be feature collection
// or single feature
return isPlainObject(json) && (isFeature(json) || isFeatureCollection(json));
}

export function isFeature(json) {
export function isFeature(json: any): boolean {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isFeature(json: unknown): json is Feature

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

return json.type === 'Feature' && json.geometry;
}

export function isFeatureCollection(json) {
export function isFeatureCollection(json: any): boolean {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isFeatureCollection(json: unknown): json is FeatureCollection

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@@ -47,25 +50,25 @@ const JSON_LOADER_OPTIONS = {
]
};

export function isGeoJson(json) {
export function isGeoJson(json: any): boolean {
// json can be feature collection
// or single feature
return isPlainObject(json) && (isFeature(json) || isFeatureCollection(json));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add type isPlainObject(obj: unknown): obj is Record<string, unknown>

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

return Array.isArray(json) && isPlainObject(json[0]);
}

export function isKeplerGlMap(json) {
export function isKeplerGlMap(json: any): Boolean {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type ValidKeplerGlMap = {
datasets: unknown
config: unknown
info: Record<string, string>
}

isKeplerGlMap(json: unknown): json is ValidKeplerGlMap

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

Signed-off-by: Evgeny Zhgulev <evgeny.zhgulev@actionengine.com>
},
[ALL_FIELD_TYPES.timestamp]: {
valid: (d, field) =>
valid: (d: any, field: Field) =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

valid: (d: unknown, field: Field): boolean;

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

},
[ALL_FIELD_TYPES.real]: {
valid: d => parseFloat(d) === d,
valid: (d: any) => parseFloat(d) === d,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(d: unknown): boolean

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Copy link
Contributor

@heshan0131 heshan0131 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please address the last 2 comments and merge

Signed-off-by: Evgeny Zhgulev <evgeny.zhgulev@actionengine.com>
Signed-off-by: Evgeny Zhgulev <evgeny.zhgulev@actionengine.com>
@jagerts jagerts merged commit 4e8197d into master May 17, 2022
@delete-merged-branch delete-merged-branch bot deleted the dt/add-types-processors branch May 17, 2022 10:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants