8000 [UAC-12] The current blocktype CSVFileExtractor is refactored to an CSVInterpreter. by schlingling · Pull Request #168 · jvalue/jayvee · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[UAC-12] The current blocktype CSVFileExtractor is refactored to an CSVInterpreter. #168

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 10 commits into from
Feb 19, 2023

Conversation

schlingling
Copy link
Contributor
@schlingling schlingling commented Feb 19, 2023

Refactores the CSVFileExtractor to an CSVInterpreter. In the downstream UACs of that one, the functionalty of CSVFileExtractor is splitted up to the new CSVInterpreter and HTTPExtractor. Most of the parsing-methods are copied from the CSVFileExtractor.

Part of RFC0002 mobility-extension.

Implements following UACs of #123:

  • [UAC-12] The current blocktype CSVFileExtractor is refactored to an CSVInterpreter.

@schlingling schlingling self-assigned this Feb 19, 2023
@schlingling schlingling changed the title [WIP] [UAC-12] The current blocktype CSVFileExtractor is refactored to an CSVInterpreter. [UAC-12] The current blocktype CSVFileExtractor is refactored to an CSVInterpreter. Feb 19, 2023
@schlingling schlingling requested a review from rhazn February 19, 2023 10:50
{
code: blockExample,
description:
'Interprets an input file coming from an GTFS-file-collection as a csv-file containing string-values delimited by `delimiter` and outputs `Sheet`.',
Copy link
Contributor

Choose a reason for hiding this comment

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

This would be better without the GTFS context and with a delimiter attribute, aka just have a block that interprets a file as a CSV file with a delimiter of ;.

Copy link
Contributor
@rhazn rhazn left a comment

Choose a reason for hiding this comment

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

The idea of moving the function out is good, left a comment how to improve the execution :D.

export function parseAsCsv(
rawData: string,
delimiter: string,
blockExecutor: BlockExecutor,
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not good, the right way to split this is have the function return a promise with result or err and an error message and keep the logging and diagnostic parts in the blockexecutor itself.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah okay, that makes sense. Thanks for the input, feedback like that improves my coding skills :D

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed, not sure, if mine is the nicest solution to handle this error, came upon my typescript limits :D
If you have a better approach, let me know.

);

const sheet = await parseAsCsv(csvFile, delimiter);
if (sheet instanceof Error) {
Copy link
Contributor Author
@schlingling schlingling Feb 19, 2023

Choose a reason for hiding this comment

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

@rhazn Since my function parseAsCsv returns `Promise<R.Result | Error> if have to check like that, if an error occured. I was not able to use R.err() in parseAsCsv, because as far as i am correct R.err() expects an object containing ast-nodes etc?

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see a reason to keep the Result/Error return, you are refactoring out common code for CSV parsing, the sheet and error handling can (and should) be kept in the executors. I'd probably use Either<string[][] | string>(with the string being an error message) (see how that is set up here https://github.com/jvalue/jayvee/blob/main/libs/execution/src/lib/execution-result.ts#L15) as a return value for your parseAsCSV function and then move the building of the sheet and error handling back into the blocks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Either was new for me, thats why i was confused, how to use it. Does it now makes sense?

@schlingling schlingling requested a review from rhazn February 19, 2023 13:00
);

const sheet = await parseAsCsv(csvFile, delimiter);
if (sheet instanceof Error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see a reason to keep the Result/Error return, you are refactoring out common code for CSV parsing, the sheet and error handling can (and should) be kept in the executors. I'd probably use Either<string[][] | string>(with the string being an error message) (see how that is set up here https://github.com/jvalue/jayvee/blob/main/libs/execution/src/lib/execution-result.ts#L15) as a return value for your parseAsCSV function and then move the building of the sheet and error handling back into the blocks.

@schlingling schlingling requested a review from rhazn February 19, 2023 15:21
import * as R from '@jayvee/execution';
import { Sheet } from '@jayvee/language-server';
import { Either } from 'fp-ts/lib/Either';
import * as E from 'fp-ts/lib/Either';
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think you need the * import here. Otherwise looks good to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed

@schlingling schlingling merged commit c276e80 into main Feb 19, 2023
@schlingling schlingling deleted the feat-mobility-ext-uac-12-csv-interpreter branch February 19, 2023 16:13
@github-actions github-actions bot locked and limited conversation to collaborators Feb 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0