Add Performance Optimizations and Bug Fix for Import Browser#146
Add Performance Optimizations and Bug Fix for Import Browser#146cwcrystal8 wants to merge 4 commits into
Conversation
| test('testing fillTemplateFromRow', () => { | ||
| const parser = new ParseTmcf(); | ||
| parser.csvIndex = 8; | ||
| const filledTemp = | ||
| parser.fillTemplateFromRow(TestStr.testTMCF2, TestStr.testCSV2[0]); | ||
| expect(filledTemp).toBe(TestStr.expectedFilledTemp0); | ||
|
|
||
| // testing multiple propValues that are comma separated | ||
| const template = | ||
| 'Node: dcid:test1\npropLabel1: C:TestSet->Col1, C:TestSet->Col2'; | ||
| const row = { | ||
| 'Col1': 'dcid:propVal1', | ||
| 'Col2': 'dcid:propVal2', | ||
| }; | ||
| const expectedMCF = | ||
| 'Node: dcid:test1\npropLabel1: dcid:propVal1, dcid:propVal2'; | ||
| const filledTemp2 = parser.fillTemplateFromRow(template, row); | ||
| expect(filledTemp2).toBe(expectedMCF); | ||
| }); | ||
|
|
||
| test('testing csvToMCF', () => { | ||
| const parser = new ParseTmcf(); | ||
| const mcf = parser.csvToMcf(TestStr.testTMCF1, TestStr.testCSV1); | ||
| expect(mcf).toBe(TestStr.expectedMCF1); | ||
| }); | ||
|
|
There was a problem hiding this comment.
For my own understanding: why are these tests being removed?
There was a problem hiding this comment.
These are test cases for functions that no longer exist in the rewritten parse-tmcf file. The functions were essentially duplicates of previous parsing logic and now that the whole process is rewritten to do everything in one pass, the tests are useless.
| headers: { | ||
| 'Content-Type': 'application/json', | ||
| }, |
There was a problem hiding this comment.
Note to self, and the team: We'll need to add an API key to this, and all functions that use the v1 API.
There was a problem hiding this comment.
Do you mean:
a. we need to add an API key in this function and pass it when making the API call - if this is the case, we want to add a TODO in the code
b. mixer needs to enforce API key for this endpoint - if this is the case, please create a github issue for this in the mixer repository
juliawu
left a comment
There was a problem hiding this comment.
Made a first pass, deferring approval to @beets or @chejennifer
chejennifer
left a comment
There was a problem hiding this comment.
nice job finding these optimizations!
| * Current row number of the csv file that is being parsed. | ||
| * @type {number} | ||
| */ | ||
| * Current row number of the csv file that is being parsed. |
There was a problem hiding this comment.
please revert these formatting changes
| [header: string]: string | number; | ||
| } | ||
|
|
||
| interface ParsedCsvRow { |
There was a problem hiding this comment.
Just wondering, is it guaranteed that each csv row will only have one observation point?
i.e., are users not allowed to input a csv file where there are multiple observations in a single row like:
date,sv1,sv2
2020,1,2
2021,2,3
...
Or am I misunderstanding this data structure?
There was a problem hiding this comment.
Users are allowed to input a CSV file like that but it gets parsed accordingly later on, I think that's why it's called CsvRow and not DataPoint or ObservationPoint
There was a problem hiding this comment.
so there can be multiple ParsedCsvRow objects for the same row? the naming is a little confusing in that case
| } | ||
|
|
||
| interface ParsedCsv { | ||
| otherMcfs: string[]; |
There was a problem hiding this comment.
probably just mcfs? what is the "other" referring to?
There was a problem hiding this comment.
it refers to non-StatVarObservation nodes that may have been included in the CSV file, these nodes will have MCF strings generated for them and stored here to display in the Graph Explorer later on.
There was a problem hiding this comment.
then maybe something like nonSvObMcfs or something more descriptive & leave a comment
|
|
||
| interface ParsedTemplate { | ||
| dataEntities: string[]; | ||
| otherEntities: string[]; |
There was a problem hiding this comment.
nit: "other" is not very descriptive, maybe "nonDataEntities" or something else that actually describes what type of entities these will be
| * @param {CsvRow} row The json representation of the csv row. | ||
| * Each CsvRow element of the array represents one row of the csv. | ||
| * @return {ParsedCsvRow | null} an object containing the facet, date, | ||
| * value, and other additional properties |
There was a problem hiding this comment.
nit: instead of "other additional properties", mention how its the mcf representation of properties for the node or something along those lines
| } | ||
| finalReturn['localNodes'] = finalReturn['localNodes'].concat( | ||
| tmcfOut['localNodes'], | ||
| const mcfs = parsedCsv.otherMcfs; |
There was a problem hiding this comment.
defining this constant also feels unnecessary since it's only used in line 144 where you can just use parsedCsv.otherMcfs
| const parsedMcf = mcfParser.parseMcfStr(mcf as string); | ||
|
|
||
| if (parsedMcf['errMsgs'].length !== 0) { | ||
| finalReturn['errMsgs'] = finalReturn['errMsgs'].concat({ |
There was a problem hiding this comment.
since finalReturn['errMsgs'] is just an array, we should be able to just push the additional element like finalReturn['errMsgs'].push({...});`?
|
|
||
| type ValueObject = { | ||
| value: number | undefined; | ||
| mcf: string; |
There was a problem hiding this comment.
curious what this mcf is, can you add a comment?
| `${dcid}`, | ||
| data.data.map( | ||
| (entity: NameResponse) => | ||
| entity.values ? entity.values[0].value : entity.entity, |
There was a problem hiding this comment.
Empty arrays will evaluate to true, probably want to check length of entity.values before accessing the first element
| body: JSON.stringify(data), | ||
| }; | ||
| // response is {"data": [...list of entities...]} | ||
| // expected entity if dcid exists is {"entity": entity, "values":"[...]} |
There was a problem hiding this comment.
since you've already defined the NameResponse type, you could just say response is {"data": NameResponse[]} and don't need this whole comment
This PR has the following changes: